Skip to content

Commit

Permalink
Merge pull request #1 from sCrypt-Inc/add-shpreimage
Browse files Browse the repository at this point in the history
version 1.0.3: add transaction.shPreimageForWitnessV1 function
  • Loading branch information
zhfnjust authored Jan 10, 2025
2 parents d071a76 + d1d8bc4 commit 1e78908
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypt-inc/bitcoinjs-lib",
"version": "1.0.2",
"version": "1.0.3",
"description": "Client-side Bitcoin JavaScript library",
"type": "module",
"main": "./dist/cjs/index.js",
Expand Down
30 changes: 26 additions & 4 deletions ts_src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,27 @@ export class Transaction {
leafHash?: Uint8Array,
annex?: Uint8Array,
codeseparatorPos?: number,
): Uint8Array {
const preimage = this.shPreimageForWitnessV1(
inIndex,
prevOutScripts,
values,
hashType,
leafHash,
annex,
codeseparatorPos,
);
return sha256(preimage);
}

shPreimageForWitnessV1(
inIndex: number,
prevOutScripts: Uint8Array[],
values: bigint[],
hashType: number,
leafHash?: Uint8Array,
annex?: Uint8Array,
codeseparatorPos?: number,
): Uint8Array {
// https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#common-signature-message
v.parse(
Expand Down Expand Up @@ -517,10 +538,11 @@ export class Transaction {

// Extra zero byte because:
// https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-19
return bcrypto.taggedHash(
'TapSighash',
tools.concat([Uint8Array.from([0x00]), sigMsgWriter.end()]),
);
return tools.concat([
bcrypto.TAGGED_HASH_PREFIXES.TapSighash,
Uint8Array.from([0x00]),
sigMsgWriter.end(),
]);
}

hashForWitnessV0(
Expand Down

0 comments on commit 1e78908

Please sign in to comment.