Skip to content

Commit 1e78908

Browse files
authored
Merge pull request #1 from sCrypt-Inc/add-shpreimage
version 1.0.3: add transaction.shPreimageForWitnessV1 function
2 parents d071a76 + d1d8bc4 commit 1e78908

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scrypt-inc/bitcoinjs-lib",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Client-side Bitcoin JavaScript library",
55
"type": "module",
66
"main": "./dist/cjs/index.js",

ts_src/transaction.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,27 @@ export class Transaction {
374374
leafHash?: Uint8Array,
375375
annex?: Uint8Array,
376376
codeseparatorPos?: number,
377+
): Uint8Array {
378+
const preimage = this.shPreimageForWitnessV1(
379+
inIndex,
380+
prevOutScripts,
381+
values,
382+
hashType,
383+
leafHash,
384+
annex,
385+
codeseparatorPos,
386+
);
387+
return sha256(preimage);
388+
}
389+
390+
shPreimageForWitnessV1(
391+
inIndex: number,
392+
prevOutScripts: Uint8Array[],
393+
values: bigint[],
394+
hashType: number,
395+
leafHash?: Uint8Array,
396+
annex?: Uint8Array,
397+
codeseparatorPos?: number,
377398
): Uint8Array {
378399
// https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#common-signature-message
379400
v.parse(
@@ -517,10 +538,11 @@ export class Transaction {
517538

518539
// Extra zero byte because:
519540
// https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-19
520-
return bcrypto.taggedHash(
521-
'TapSighash',
522-
tools.concat([Uint8Array.from([0x00]), sigMsgWriter.end()]),
523-
);
541+
return tools.concat([
542+
bcrypto.TAGGED_HASH_PREFIXES.TapSighash,
543+
Uint8Array.from([0x00]),
544+
sigMsgWriter.end(),
545+
]);
524546
}
525547

526548
hashForWitnessV0(

0 commit comments

Comments
 (0)