Skip to content

Commit 5a1a6dd

Browse files
committed
feat: allow passing in tapLeafHashToSign when calling signPsbt
1 parent 50e30a4 commit 5a1a6dd

File tree

5 files changed

+372
-31
lines changed

5 files changed

+372
-31
lines changed

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"_prettier": "prettier --write .",
2626
"fix:modules": "node scripts/fix-modules.js",
2727
"format": "prettier --write \"src/**/*.{js,jsx,json,md,ts,tsx}\" --plugin-search-dir=./node_modules/ --plugin=./node_modules/@trivago/prettier-plugin-sort-imports/ ",
28+
"postinstall": "patch-package",
2829
"prepare": "npm run fix:modules"
2930
},
3031
"dependencies": {
@@ -52,7 +53,7 @@
5253
"@types/react": "^18.0.9",
5354
"@types/react-cache": "^2.0.1",
5455
"@types/react-dom": "^18.0.4",
55-
"@unisat/wallet-sdk": "1.7.1",
56+
"@unisat/wallet-sdk": "1.7.3",
5657
"antd": "^4.20.4",
5758
"antd-dayjs-webpack-plugin": "1.0.6",
5859
"assert": "^2.0.0",
@@ -248,6 +249,8 @@
248249
"less": "^4.1.2",
249250
"less-loader": "^11.0.0",
250251
"minimist": "^1.2.6",
252+
"patch-package": "^8.0.0",
253+
"postinstall": "^0.11.0",
251254
"prettier": "^2.6.2",
252255
"sass-loader": "^12.6.0",
253256
"stylus": "^0.57.0",

patches/bitcoinjs-lib+6.1.6.patch

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/node_modules/bitcoinjs-lib/src/psbt.js b/node_modules/bitcoinjs-lib/src/psbt.js
2+
index b071f37..1eded75 100644
3+
--- a/node_modules/bitcoinjs-lib/src/psbt.js
4+
+++ b/node_modules/bitcoinjs-lib/src/psbt.js
5+
@@ -1342,7 +1342,7 @@ function getTaprootHashesForSig(
6+
}
7+
}
8+
const tapLeafHashes = (input.tapLeafScript || [])
9+
- .filter(tapLeaf => (0, psbtutils_1.pubkeyInScript)(pubkey, tapLeaf.script))
10+
+ // .filter(tapLeaf => (0, psbtutils_1.pubkeyInScript)(pubkey, tapLeaf.script))
11+
.map(tapLeaf => {
12+
const hash = (0, bip341_1.tapleafHash)({
13+
output: tapLeaf.script,

src/background/controller/wallet.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,20 @@ export class WalletController extends BaseController {
487487
const sighashTypes = input.sighashTypes?.map(Number);
488488
if (sighashTypes?.some(isNaN)) throw new Error('invalid sighash type in toSignInput');
489489

490+
let tapLeafHashToSign: Buffer | undefined;
491+
if (input.tapLeafHashToSign) {
492+
if (typeof input.tapLeafHashToSign === 'string') {
493+
tapLeafHashToSign = Buffer.from(input.tapLeafHashToSign, 'hex');
494+
} else {
495+
tapLeafHashToSign = input.tapLeafHashToSign;
496+
}
497+
}
490498
return {
491499
index,
492500
publicKey: account.pubkey,
493501
sighashTypes,
494-
disableTweakSigner: input.disableTweakSigner
502+
disableTweakSigner: input.disableTweakSigner,
503+
tapLeafHashToSign
495504
};
496505
});
497506
} else {

src/shared/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ interface BaseUserToSignInput {
209209
index: number;
210210
sighashTypes: number[] | undefined;
211211
disableTweakSigner?: boolean;
212+
tapLeafHashToSign?: string;
212213
}
213214

214215
export interface AddressUserToSignInput extends BaseUserToSignInput {
@@ -230,6 +231,7 @@ export interface ToSignInput {
230231
index: number;
231232
publicKey: string;
232233
sighashTypes?: number[];
234+
tapLeafHashToSign?: Buffer;
233235
}
234236

235237
export type WalletKeyring = {

0 commit comments

Comments
 (0)