Skip to content

Commit

Permalink
feat: allow passing in tapLeafHashToSign when calling signPsbt
Browse files Browse the repository at this point in the history
  • Loading branch information
slient-coder committed Sep 20, 2024
1 parent 50e30a4 commit 5a1a6dd
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 31 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"_prettier": "prettier --write .",
"fix:modules": "node scripts/fix-modules.js",
"format": "prettier --write \"src/**/*.{js,jsx,json,md,ts,tsx}\" --plugin-search-dir=./node_modules/ --plugin=./node_modules/@trivago/prettier-plugin-sort-imports/ ",
"postinstall": "patch-package",
"prepare": "npm run fix:modules"
},
"dependencies": {
Expand Down Expand Up @@ -52,7 +53,7 @@
"@types/react": "^18.0.9",
"@types/react-cache": "^2.0.1",
"@types/react-dom": "^18.0.4",
"@unisat/wallet-sdk": "1.7.1",
"@unisat/wallet-sdk": "1.7.3",
"antd": "^4.20.4",
"antd-dayjs-webpack-plugin": "1.0.6",
"assert": "^2.0.0",
Expand Down Expand Up @@ -248,6 +249,8 @@
"less": "^4.1.2",
"less-loader": "^11.0.0",
"minimist": "^1.2.6",
"patch-package": "^8.0.0",
"postinstall": "^0.11.0",
"prettier": "^2.6.2",
"sass-loader": "^12.6.0",
"stylus": "^0.57.0",
Expand Down
13 changes: 13 additions & 0 deletions patches/bitcoinjs-lib+6.1.6.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/bitcoinjs-lib/src/psbt.js b/node_modules/bitcoinjs-lib/src/psbt.js
index b071f37..1eded75 100644
--- a/node_modules/bitcoinjs-lib/src/psbt.js
+++ b/node_modules/bitcoinjs-lib/src/psbt.js
@@ -1342,7 +1342,7 @@ function getTaprootHashesForSig(
}
}
const tapLeafHashes = (input.tapLeafScript || [])
- .filter(tapLeaf => (0, psbtutils_1.pubkeyInScript)(pubkey, tapLeaf.script))
+ // .filter(tapLeaf => (0, psbtutils_1.pubkeyInScript)(pubkey, tapLeaf.script))
.map(tapLeaf => {
const hash = (0, bip341_1.tapleafHash)({
output: tapLeaf.script,
11 changes: 10 additions & 1 deletion src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,20 @@ export class WalletController extends BaseController {
const sighashTypes = input.sighashTypes?.map(Number);
if (sighashTypes?.some(isNaN)) throw new Error('invalid sighash type in toSignInput');

let tapLeafHashToSign: Buffer | undefined;
if (input.tapLeafHashToSign) {
if (typeof input.tapLeafHashToSign === 'string') {
tapLeafHashToSign = Buffer.from(input.tapLeafHashToSign, 'hex');
} else {
tapLeafHashToSign = input.tapLeafHashToSign;
}
}
return {
index,
publicKey: account.pubkey,
sighashTypes,
disableTweakSigner: input.disableTweakSigner
disableTweakSigner: input.disableTweakSigner,
tapLeafHashToSign
};
});
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ interface BaseUserToSignInput {
index: number;
sighashTypes: number[] | undefined;
disableTweakSigner?: boolean;
tapLeafHashToSign?: string;
}

export interface AddressUserToSignInput extends BaseUserToSignInput {
Expand All @@ -230,6 +231,7 @@ export interface ToSignInput {
index: number;
publicKey: string;
sighashTypes?: number[];
tapLeafHashToSign?: Buffer;
}

export type WalletKeyring = {
Expand Down
Loading

0 comments on commit 5a1a6dd

Please sign in to comment.