@btc-vision/bitcoin 6.3.1 → 6.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +4 -0
- package/.gitattributes +2 -0
- package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +1 -0
- package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/.prettierrc.json +12 -0
- package/CHANGELOG.md +403 -0
- package/CONTRIBUTING.md +83 -0
- package/browser/address.d.ts +16 -0
- package/{src → browser}/bip66.d.ts +6 -7
- package/{src → browser}/block.d.ts +29 -30
- package/{src → browser}/bufferutils.d.ts +34 -54
- package/browser/crypto/crypto.d.ts +1 -0
- package/{src → browser}/crypto.d.ts +13 -18
- package/browser/ecc_lib.d.ts +3 -0
- package/browser/hooks/AdvancedSignatureManager.d.ts +16 -0
- package/{src → browser}/hooks/HookedSigner.d.ts +4 -4
- package/browser/hooks/SignatureManager.d.ts +13 -0
- package/browser/index.d.ts +58 -0
- package/browser/index.js +2 -0
- package/browser/index.js.LICENSE.txt +14 -0
- package/browser/merkle.d.ts +1 -0
- package/browser/networks.d.ts +23 -0
- package/{src → browser}/ops.d.ts +126 -126
- package/browser/payments/bip341.d.ts +23 -0
- package/browser/payments/embed.d.ts +2 -0
- package/browser/payments/index.d.ts +41 -0
- package/{src → browser}/payments/lazy.d.ts +2 -2
- package/browser/payments/p2ms.d.ts +2 -0
- package/browser/payments/p2pk.d.ts +2 -0
- package/browser/payments/p2pkh.d.ts +2 -0
- package/browser/payments/p2sh.d.ts +2 -0
- package/browser/payments/p2tr.d.ts +2 -0
- package/browser/payments/p2wpkh.d.ts +2 -0
- package/browser/payments/p2wsh.d.ts +2 -0
- package/browser/psbt/bip371.d.ts +16 -0
- package/browser/psbt/psbtutils.d.ts +26 -0
- package/{src → browser}/psbt.d.ts +167 -238
- package/browser/push_data.d.ts +7 -0
- package/browser/script.d.ts +17 -0
- package/browser/script_number.d.ts +2 -0
- package/browser/script_signature.d.ts +7 -0
- package/{src → browser}/transaction.d.ts +48 -60
- package/{src → browser}/types.d.ts +37 -54
- package/build/address.d.ts +16 -0
- package/build/address.js +148 -0
- package/build/bip66.d.ts +6 -0
- package/build/bip66.js +99 -0
- package/build/block.d.ts +29 -0
- package/build/block.js +181 -0
- package/build/bufferutils.d.ts +34 -0
- package/build/bufferutils.js +141 -0
- package/build/crypto/crypto.d.ts +1 -0
- package/build/crypto/crypto.js +1 -0
- package/build/crypto.d.ts +13 -0
- package/build/crypto.js +87 -0
- package/build/ecc_lib.d.ts +3 -0
- package/build/ecc_lib.js +61 -0
- package/build/hooks/AdvancedSignatureManager.d.ts +16 -0
- package/build/hooks/AdvancedSignatureManager.js +52 -0
- package/build/hooks/HookedSigner.d.ts +4 -0
- package/build/hooks/HookedSigner.js +64 -0
- package/build/hooks/SignatureManager.d.ts +13 -0
- package/build/hooks/SignatureManager.js +45 -0
- package/build/index.d.ts +58 -0
- package/build/index.js +32 -0
- package/build/merkle.d.ts +1 -0
- package/build/merkle.js +19 -0
- package/build/networks.d.ts +23 -0
- package/build/networks.js +121 -0
- package/build/ops.d.ts +126 -0
- package/{src → build}/ops.js +127 -131
- package/build/payments/bip341.d.ts +23 -0
- package/build/payments/bip341.js +82 -0
- package/build/payments/embed.d.ts +2 -0
- package/build/payments/embed.js +39 -0
- package/build/payments/index.d.ts +41 -0
- package/build/payments/index.js +10 -0
- package/build/payments/lazy.d.ts +2 -0
- package/{src → build}/payments/lazy.js +28 -32
- package/build/payments/p2ms.d.ts +2 -0
- package/{src → build}/payments/p2ms.js +128 -158
- package/build/payments/p2pk.d.ts +2 -0
- package/build/payments/p2pk.js +68 -0
- package/build/payments/p2pkh.d.ts +2 -0
- package/build/payments/p2pkh.js +135 -0
- package/build/payments/p2sh.d.ts +2 -0
- package/build/payments/p2sh.js +175 -0
- package/build/payments/p2tr.d.ts +2 -0
- package/build/payments/p2tr.js +254 -0
- package/build/payments/p2wpkh.d.ts +2 -0
- package/build/payments/p2wpkh.js +130 -0
- package/build/payments/p2wsh.d.ts +2 -0
- package/build/payments/p2wsh.js +180 -0
- package/build/psbt/bip371.d.ts +16 -0
- package/build/psbt/bip371.js +246 -0
- package/build/psbt/psbtutils.d.ts +26 -0
- package/build/psbt/psbtutils.js +170 -0
- package/build/psbt.d.ts +167 -0
- package/build/psbt.js +1305 -0
- package/build/push_data.d.ts +7 -0
- package/build/push_data.js +57 -0
- package/build/script.d.ts +17 -0
- package/build/script.js +167 -0
- package/build/script_number.d.ts +2 -0
- package/build/script_number.js +49 -0
- package/build/script_signature.d.ts +7 -0
- package/build/script_signature.js +49 -0
- package/build/transaction.d.ts +48 -0
- package/build/transaction.js +445 -0
- package/build/types.d.ts +37 -0
- package/build/types.js +73 -0
- package/cjs/package.json +3 -0
- package/eslint.config.js +56 -0
- package/gulpfile.js +42 -0
- package/package.json +105 -50
- package/src/{address.js → address.ts} +93 -73
- package/src/{bip66.js → bip66.ts} +23 -19
- package/src/{block.js → block.ts} +114 -105
- package/src/{bufferutils.js → bufferutils.ts} +65 -67
- package/src/crypto/crypto-browser.js +75 -0
- package/src/crypto/crypto.ts +1 -0
- package/src/crypto.ts +108 -0
- package/src/{ecc_lib.js → ecc_lib.ts} +25 -53
- package/src/hooks/{AdvancedSignatureManager.js → AdvancedSignatureManager.ts} +34 -18
- package/src/hooks/HookedSigner.ts +108 -0
- package/src/hooks/{SignatureManager.js → SignatureManager.ts} +26 -14
- package/src/index.ts +86 -0
- package/src/{merkle.js → merkle.ts} +8 -7
- package/src/{networks.js → networks.ts} +44 -29
- package/src/ops.ts +282 -0
- package/src/payments/bip341.ts +140 -0
- package/src/payments/embed.ts +55 -0
- package/src/payments/{index.d.ts → index.ts} +20 -10
- package/src/payments/lazy.ts +28 -0
- package/src/payments/p2ms.ts +150 -0
- package/src/payments/{p2pk.js → p2pk.ts} +32 -29
- package/src/payments/{p2pkh.js → p2pkh.ts} +53 -47
- package/src/payments/{p2sh.js → p2sh.ts} +72 -71
- package/src/payments/{p2tr.js → p2tr.ts} +114 -125
- package/src/payments/{p2wpkh.js → p2wpkh.ts} +51 -56
- package/src/payments/{p2wsh.js → p2wsh.ts} +69 -81
- package/src/psbt/{bip371.js → bip371.ts} +191 -174
- package/src/psbt/psbtutils.ts +299 -0
- package/src/{psbt.js → psbt.ts} +1025 -679
- package/src/{push_data.js → push_data.ts} +35 -21
- package/src/{script.js → script.ts} +93 -77
- package/src/{script_number.js → script_number.ts} +15 -21
- package/src/{script_signature.js → script_signature.ts} +26 -14
- package/src/{transaction.js → transaction.ts} +247 -167
- package/src/types.ts +122 -0
- package/test/address.spec.js +124 -0
- package/test/address.spec.ts +177 -0
- package/test/bitcoin.core.spec.js +170 -0
- package/test/bitcoin.core.spec.ts +234 -0
- package/test/block.spec.js +141 -0
- package/test/block.spec.ts +194 -0
- package/test/bufferutils.spec.js +427 -0
- package/test/bufferutils.spec.ts +513 -0
- package/test/crypto.spec.js +41 -0
- package/test/crypto.spec.ts +55 -0
- package/test/fixtures/address.json +329 -0
- package/test/fixtures/block.json +148 -0
- package/test/fixtures/bufferutils.json +102 -0
- package/test/fixtures/core/README.md +26 -0
- package/test/fixtures/core/base58_encode_decode.json +50 -0
- package/test/fixtures/core/base58_keys_invalid.json +152 -0
- package/test/fixtures/core/base58_keys_valid.json +452 -0
- package/test/fixtures/core/blocks.json +27 -0
- package/test/fixtures/core/sig_canonical.json +7 -0
- package/test/fixtures/core/sig_noncanonical.json +33 -0
- package/test/fixtures/core/sighash.json +3505 -0
- package/test/fixtures/core/tx_valid.json +2023 -0
- package/test/fixtures/crypto.json +43 -0
- package/test/fixtures/ecdsa.json +217 -0
- package/test/fixtures/ecpair.json +141 -0
- package/test/fixtures/embed.json +108 -0
- package/test/fixtures/p2ms.json +434 -0
- package/test/fixtures/p2pk.json +179 -0
- package/test/fixtures/p2pkh.json +276 -0
- package/test/fixtures/p2sh.json +508 -0
- package/test/fixtures/p2tr.json +1198 -0
- package/test/fixtures/p2wpkh.json +290 -0
- package/test/fixtures/p2wsh.json +489 -0
- package/test/fixtures/psbt.json +924 -0
- package/test/fixtures/script.json +465 -0
- package/test/fixtures/script_number.json +225 -0
- package/test/fixtures/signature.json +140 -0
- package/test/fixtures/transaction.json +916 -0
- package/test/integration/_regtest.js +7 -0
- package/test/integration/_regtest.ts +6 -0
- package/test/integration/addresses.spec.js +116 -0
- package/test/integration/addresses.spec.ts +154 -0
- package/test/integration/bip32.spec.js +85 -0
- package/test/integration/bip32.spec.ts +151 -0
- package/test/integration/blocks.spec.js +26 -0
- package/test/integration/blocks.spec.ts +28 -0
- package/test/integration/cltv.spec.js +199 -0
- package/test/integration/cltv.spec.ts +283 -0
- package/test/integration/csv.spec.js +362 -0
- package/test/integration/csv.spec.ts +527 -0
- package/test/integration/payments.spec.js +98 -0
- package/test/integration/payments.spec.ts +135 -0
- package/test/integration/taproot.spec.js +532 -0
- package/test/integration/taproot.spec.ts +707 -0
- package/test/integration/transactions.spec.js +561 -0
- package/test/integration/transactions.spec.ts +769 -0
- package/test/payments.spec.js +97 -0
- package/test/payments.spec.ts +125 -0
- package/test/payments.utils.js +190 -0
- package/test/payments.utils.ts +208 -0
- package/test/psbt.spec.js +1044 -0
- package/test/psbt.spec.ts +1414 -0
- package/test/script.spec.js +151 -0
- package/test/script.spec.ts +210 -0
- package/test/script_number.spec.js +24 -0
- package/test/script_number.spec.ts +29 -0
- package/test/script_signature.spec.js +52 -0
- package/test/script_signature.spec.ts +66 -0
- package/test/transaction.spec.js +269 -0
- package/test/transaction.spec.ts +387 -0
- package/test/ts-node-register.js +5 -0
- package/test/tsconfig.json +45 -0
- package/test/types.spec.js +46 -0
- package/test/types.spec.ts +58 -0
- package/tsconfig.base.json +27 -0
- package/tsconfig.json +19 -0
- package/tsconfig.webpack.json +18 -0
- package/webpack.config.js +79 -0
- package/src/address.d.ts +0 -42
- package/src/crypto.js +0 -128
- package/src/ecc_lib.d.ts +0 -17
- package/src/hooks/AdvancedSignatureManager.d.ts +0 -44
- package/src/hooks/HookedSigner.js +0 -90
- package/src/hooks/SignatureManager.d.ts +0 -35
- package/src/index.d.ts +0 -42
- package/src/index.js +0 -87
- package/src/merkle.d.ts +0 -10
- package/src/networks.d.ts +0 -83
- package/src/payments/bip341.d.ts +0 -49
- package/src/payments/bip341.js +0 -124
- package/src/payments/embed.d.ts +0 -9
- package/src/payments/embed.js +0 -54
- package/src/payments/index.js +0 -69
- package/src/payments/p2ms.d.ts +0 -9
- package/src/payments/p2pk.d.ts +0 -10
- package/src/payments/p2pkh.d.ts +0 -10
- package/src/payments/p2sh.d.ts +0 -10
- package/src/payments/p2tr.d.ts +0 -10
- package/src/payments/p2wpkh.d.ts +0 -10
- package/src/payments/p2wsh.d.ts +0 -10
- package/src/psbt/bip371.d.ts +0 -42
- package/src/psbt/psbtutils.d.ts +0 -64
- package/src/psbt/psbtutils.js +0 -191
- package/src/push_data.d.ts +0 -29
- package/src/script.d.ts +0 -42
- package/src/script_number.d.ts +0 -19
- package/src/script_signature.d.ts +0 -21
- package/src/types.js +0 -106
package/src/psbt/psbtutils.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { PartialSig, PsbtInput } from 'bip174/src/lib/interfaces';
|
|
3
|
-
export declare const isP2MS: (script: Buffer) => boolean;
|
|
4
|
-
export declare const isP2PK: (script: Buffer) => boolean;
|
|
5
|
-
export declare const isP2PKH: (script: Buffer) => boolean;
|
|
6
|
-
export declare const isP2WPKH: (script: Buffer) => boolean;
|
|
7
|
-
export declare const isP2WSHScript: (script: Buffer) => boolean;
|
|
8
|
-
export declare const isP2SHScript: (script: Buffer) => boolean;
|
|
9
|
-
export declare const isP2TR: (script: Buffer) => boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Converts a witness stack to a script witness.
|
|
12
|
-
* @param witness The witness stack to convert.
|
|
13
|
-
* @returns The script witness as a Buffer.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Converts a witness stack to a script witness.
|
|
17
|
-
* @param witness The witness stack to convert.
|
|
18
|
-
* @returns The converted script witness.
|
|
19
|
-
*/
|
|
20
|
-
export declare function witnessStackToScriptWitness(witness: Buffer[]): Buffer;
|
|
21
|
-
/**
|
|
22
|
-
* Finds the position of a public key in a script.
|
|
23
|
-
* @param pubkey The public key to search for.
|
|
24
|
-
* @param script The script to search in.
|
|
25
|
-
* @returns The index of the public key in the script, or -1 if not found.
|
|
26
|
-
* @throws {Error} If there is an unknown script error.
|
|
27
|
-
*/
|
|
28
|
-
export declare function pubkeyPositionInScript(pubkey: Buffer, script: Buffer): number;
|
|
29
|
-
/**
|
|
30
|
-
* Checks if a public key is present in a script.
|
|
31
|
-
* @param pubkey The public key to check.
|
|
32
|
-
* @param script The script to search in.
|
|
33
|
-
* @returns A boolean indicating whether the public key is present in the script.
|
|
34
|
-
*/
|
|
35
|
-
export declare function pubkeyInScript(pubkey: Buffer, script: Buffer): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Checks if an input contains a signature for a specific action.
|
|
38
|
-
* @param input - The input to check.
|
|
39
|
-
* @param action - The action to check for.
|
|
40
|
-
* @returns A boolean indicating whether the input contains a signature for the specified action.
|
|
41
|
-
*/
|
|
42
|
-
export declare function checkInputForSig(input: PsbtInput, action: string): boolean;
|
|
43
|
-
type SignatureDecodeFunc = (buffer: Buffer) => {
|
|
44
|
-
signature: Buffer;
|
|
45
|
-
hashType: number;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Determines if a given action is allowed for a signature block.
|
|
49
|
-
* @param signature - The signature block.
|
|
50
|
-
* @param signatureDecodeFn - The function used to decode the signature.
|
|
51
|
-
* @param action - The action to be checked.
|
|
52
|
-
* @returns True if the action is allowed, false otherwise.
|
|
53
|
-
*/
|
|
54
|
-
export declare function signatureBlocksAction(signature: Buffer, signatureDecodeFn: SignatureDecodeFunc, action: string): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Retrieves the partial signatures (Psigs) from the input's final scripts.
|
|
57
|
-
* Psigs are extracted from both the final scriptSig and final scriptWitness of the input.
|
|
58
|
-
* Only canonical script signatures are considered.
|
|
59
|
-
*
|
|
60
|
-
* @param input - The PsbtInput object representing the input.
|
|
61
|
-
* @returns An array of PartialSig objects containing the extracted Psigs.
|
|
62
|
-
*/
|
|
63
|
-
export declare function getPsigsFromInputFinalScripts(input: PsbtInput): PartialSig[];
|
|
64
|
-
export {};
|
package/src/psbt/psbtutils.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.getPsigsFromInputFinalScripts =
|
|
4
|
-
exports.signatureBlocksAction =
|
|
5
|
-
exports.checkInputForSig =
|
|
6
|
-
exports.pubkeyInScript =
|
|
7
|
-
exports.pubkeyPositionInScript =
|
|
8
|
-
exports.witnessStackToScriptWitness =
|
|
9
|
-
exports.isP2TR =
|
|
10
|
-
exports.isP2SHScript =
|
|
11
|
-
exports.isP2WSHScript =
|
|
12
|
-
exports.isP2WPKH =
|
|
13
|
-
exports.isP2PKH =
|
|
14
|
-
exports.isP2PK =
|
|
15
|
-
exports.isP2MS =
|
|
16
|
-
void 0;
|
|
17
|
-
const varuint = require('bip174/src/lib/converter/varint');
|
|
18
|
-
const bscript = require('../script');
|
|
19
|
-
const transaction_1 = require('../transaction');
|
|
20
|
-
const crypto_1 = require('../crypto');
|
|
21
|
-
const payments = require('../payments');
|
|
22
|
-
function isPaymentFactory(payment) {
|
|
23
|
-
return script => {
|
|
24
|
-
try {
|
|
25
|
-
payment({ output: script });
|
|
26
|
-
return true;
|
|
27
|
-
} catch (err) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
exports.isP2MS = isPaymentFactory(payments.p2ms);
|
|
33
|
-
exports.isP2PK = isPaymentFactory(payments.p2pk);
|
|
34
|
-
exports.isP2PKH = isPaymentFactory(payments.p2pkh);
|
|
35
|
-
exports.isP2WPKH = isPaymentFactory(payments.p2wpkh);
|
|
36
|
-
exports.isP2WSHScript = isPaymentFactory(payments.p2wsh);
|
|
37
|
-
exports.isP2SHScript = isPaymentFactory(payments.p2sh);
|
|
38
|
-
exports.isP2TR = isPaymentFactory(payments.p2tr);
|
|
39
|
-
/**
|
|
40
|
-
* Converts a witness stack to a script witness.
|
|
41
|
-
* @param witness The witness stack to convert.
|
|
42
|
-
* @returns The script witness as a Buffer.
|
|
43
|
-
*/
|
|
44
|
-
/**
|
|
45
|
-
* Converts a witness stack to a script witness.
|
|
46
|
-
* @param witness The witness stack to convert.
|
|
47
|
-
* @returns The converted script witness.
|
|
48
|
-
*/
|
|
49
|
-
function witnessStackToScriptWitness(witness) {
|
|
50
|
-
let buffer = Buffer.allocUnsafe(0);
|
|
51
|
-
function writeSlice(slice) {
|
|
52
|
-
buffer = Buffer.concat([buffer, Buffer.from(slice)]);
|
|
53
|
-
}
|
|
54
|
-
function writeVarInt(i) {
|
|
55
|
-
const currentLen = buffer.length;
|
|
56
|
-
const varintLen = varuint.encodingLength(i);
|
|
57
|
-
buffer = Buffer.concat([buffer, Buffer.allocUnsafe(varintLen)]);
|
|
58
|
-
varuint.encode(i, buffer, currentLen);
|
|
59
|
-
}
|
|
60
|
-
function writeVarSlice(slice) {
|
|
61
|
-
writeVarInt(slice.length);
|
|
62
|
-
writeSlice(slice);
|
|
63
|
-
}
|
|
64
|
-
function writeVector(vector) {
|
|
65
|
-
writeVarInt(vector.length);
|
|
66
|
-
vector.forEach(writeVarSlice);
|
|
67
|
-
}
|
|
68
|
-
writeVector(witness);
|
|
69
|
-
return buffer;
|
|
70
|
-
}
|
|
71
|
-
exports.witnessStackToScriptWitness = witnessStackToScriptWitness;
|
|
72
|
-
/**
|
|
73
|
-
* Finds the position of a public key in a script.
|
|
74
|
-
* @param pubkey The public key to search for.
|
|
75
|
-
* @param script The script to search in.
|
|
76
|
-
* @returns The index of the public key in the script, or -1 if not found.
|
|
77
|
-
* @throws {Error} If there is an unknown script error.
|
|
78
|
-
*/
|
|
79
|
-
function pubkeyPositionInScript(pubkey, script) {
|
|
80
|
-
const pubkeyHash = (0, crypto_1.hash160)(pubkey);
|
|
81
|
-
const pubkeyXOnly = pubkey.slice(1, 33); // slice before calling?
|
|
82
|
-
const decompiled = bscript.decompile(script);
|
|
83
|
-
if (decompiled === null) throw new Error('Unknown script error');
|
|
84
|
-
return decompiled.findIndex(element => {
|
|
85
|
-
if (typeof element === 'number') return false;
|
|
86
|
-
return (
|
|
87
|
-
element.equals(pubkey) ||
|
|
88
|
-
element.equals(pubkeyHash) ||
|
|
89
|
-
element.equals(pubkeyXOnly)
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
exports.pubkeyPositionInScript = pubkeyPositionInScript;
|
|
94
|
-
/**
|
|
95
|
-
* Checks if a public key is present in a script.
|
|
96
|
-
* @param pubkey The public key to check.
|
|
97
|
-
* @param script The script to search in.
|
|
98
|
-
* @returns A boolean indicating whether the public key is present in the script.
|
|
99
|
-
*/
|
|
100
|
-
function pubkeyInScript(pubkey, script) {
|
|
101
|
-
return pubkeyPositionInScript(pubkey, script) !== -1;
|
|
102
|
-
}
|
|
103
|
-
exports.pubkeyInScript = pubkeyInScript;
|
|
104
|
-
/**
|
|
105
|
-
* Checks if an input contains a signature for a specific action.
|
|
106
|
-
* @param input - The input to check.
|
|
107
|
-
* @param action - The action to check for.
|
|
108
|
-
* @returns A boolean indicating whether the input contains a signature for the specified action.
|
|
109
|
-
*/
|
|
110
|
-
function checkInputForSig(input, action) {
|
|
111
|
-
const pSigs = extractPartialSigs(input);
|
|
112
|
-
return pSigs.some(pSig =>
|
|
113
|
-
signatureBlocksAction(pSig, bscript.signature.decode, action),
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
exports.checkInputForSig = checkInputForSig;
|
|
117
|
-
/**
|
|
118
|
-
* Determines if a given action is allowed for a signature block.
|
|
119
|
-
* @param signature - The signature block.
|
|
120
|
-
* @param signatureDecodeFn - The function used to decode the signature.
|
|
121
|
-
* @param action - The action to be checked.
|
|
122
|
-
* @returns True if the action is allowed, false otherwise.
|
|
123
|
-
*/
|
|
124
|
-
function signatureBlocksAction(signature, signatureDecodeFn, action) {
|
|
125
|
-
const { hashType } = signatureDecodeFn(signature);
|
|
126
|
-
const whitelist = [];
|
|
127
|
-
const isAnyoneCanPay =
|
|
128
|
-
hashType & transaction_1.Transaction.SIGHASH_ANYONECANPAY;
|
|
129
|
-
if (isAnyoneCanPay) whitelist.push('addInput');
|
|
130
|
-
const hashMod = hashType & 0x1f;
|
|
131
|
-
switch (hashMod) {
|
|
132
|
-
case transaction_1.Transaction.SIGHASH_ALL:
|
|
133
|
-
break;
|
|
134
|
-
case transaction_1.Transaction.SIGHASH_SINGLE:
|
|
135
|
-
case transaction_1.Transaction.SIGHASH_NONE:
|
|
136
|
-
whitelist.push('addOutput');
|
|
137
|
-
whitelist.push('setInputSequence');
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
if (whitelist.indexOf(action) === -1) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
exports.signatureBlocksAction = signatureBlocksAction;
|
|
146
|
-
/**
|
|
147
|
-
* Extracts the signatures from a PsbtInput object.
|
|
148
|
-
* If the input has partial signatures, it returns an array of the signatures.
|
|
149
|
-
* If the input does not have partial signatures, it checks if it has a finalScriptSig or finalScriptWitness.
|
|
150
|
-
* If it does, it extracts the signatures from the final scripts and returns them.
|
|
151
|
-
* If none of the above conditions are met, it returns an empty array.
|
|
152
|
-
*
|
|
153
|
-
* @param input - The PsbtInput object from which to extract the signatures.
|
|
154
|
-
* @returns An array of signatures extracted from the PsbtInput object.
|
|
155
|
-
*/
|
|
156
|
-
function extractPartialSigs(input) {
|
|
157
|
-
let pSigs = [];
|
|
158
|
-
if ((input.partialSig || []).length === 0) {
|
|
159
|
-
if (!input.finalScriptSig && !input.finalScriptWitness) return [];
|
|
160
|
-
pSigs = getPsigsFromInputFinalScripts(input);
|
|
161
|
-
} else {
|
|
162
|
-
pSigs = input.partialSig;
|
|
163
|
-
}
|
|
164
|
-
return pSigs.map(p => p.signature);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Retrieves the partial signatures (Psigs) from the input's final scripts.
|
|
168
|
-
* Psigs are extracted from both the final scriptSig and final scriptWitness of the input.
|
|
169
|
-
* Only canonical script signatures are considered.
|
|
170
|
-
*
|
|
171
|
-
* @param input - The PsbtInput object representing the input.
|
|
172
|
-
* @returns An array of PartialSig objects containing the extracted Psigs.
|
|
173
|
-
*/
|
|
174
|
-
function getPsigsFromInputFinalScripts(input) {
|
|
175
|
-
const scriptItems = !input.finalScriptSig
|
|
176
|
-
? []
|
|
177
|
-
: bscript.decompile(input.finalScriptSig) || [];
|
|
178
|
-
const witnessItems = !input.finalScriptWitness
|
|
179
|
-
? []
|
|
180
|
-
: bscript.decompile(input.finalScriptWitness) || [];
|
|
181
|
-
return scriptItems
|
|
182
|
-
.concat(witnessItems)
|
|
183
|
-
.filter(item => {
|
|
184
|
-
return (
|
|
185
|
-
Buffer.isBuffer(item) &&
|
|
186
|
-
bscript.isCanonicalScriptSignature(item)
|
|
187
|
-
);
|
|
188
|
-
})
|
|
189
|
-
.map(sig => ({ signature: sig }));
|
|
190
|
-
}
|
|
191
|
-
exports.getPsigsFromInputFinalScripts = getPsigsFromInputFinalScripts;
|
package/src/push_data.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/**
|
|
3
|
-
* Calculates the encoding length of a number used for push data in Bitcoin transactions.
|
|
4
|
-
* @param i The number to calculate the encoding length for.
|
|
5
|
-
* @returns The encoding length of the number.
|
|
6
|
-
*/
|
|
7
|
-
export declare function encodingLength(i: number): number;
|
|
8
|
-
/**
|
|
9
|
-
* Encodes a number into a buffer using a variable-length encoding scheme.
|
|
10
|
-
* The encoded buffer is written starting at the specified offset.
|
|
11
|
-
* Returns the size of the encoded buffer.
|
|
12
|
-
*
|
|
13
|
-
* @param buffer - The buffer to write the encoded data into.
|
|
14
|
-
* @param num - The number to encode.
|
|
15
|
-
* @param offset - The offset at which to start writing the encoded buffer.
|
|
16
|
-
* @returns The size of the encoded buffer.
|
|
17
|
-
*/
|
|
18
|
-
export declare function encode(buffer: Buffer, num: number, offset: number): number;
|
|
19
|
-
/**
|
|
20
|
-
* Decodes a buffer and returns information about the opcode, number, and size.
|
|
21
|
-
* @param buffer - The buffer to decode.
|
|
22
|
-
* @param offset - The offset within the buffer to start decoding.
|
|
23
|
-
* @returns An object containing the opcode, number, and size, or null if decoding fails.
|
|
24
|
-
*/
|
|
25
|
-
export declare function decode(buffer: Buffer, offset: number): {
|
|
26
|
-
opcode: number;
|
|
27
|
-
number: number;
|
|
28
|
-
size: number;
|
|
29
|
-
} | null;
|
package/src/script.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { OPS } from './ops';
|
|
3
|
-
import { Stack } from './payments';
|
|
4
|
-
import * as scriptNumber from './script_number';
|
|
5
|
-
import * as scriptSignature from './script_signature';
|
|
6
|
-
export { OPS };
|
|
7
|
-
export declare function isPushOnly(value: Stack): boolean;
|
|
8
|
-
export declare function countNonPushOnlyOPs(value: Stack): number;
|
|
9
|
-
/**
|
|
10
|
-
* Compiles an array of chunks into a Buffer.
|
|
11
|
-
*
|
|
12
|
-
* @param chunks - The array of chunks to compile.
|
|
13
|
-
* @returns The compiled Buffer.
|
|
14
|
-
* @throws Error if the compilation fails.
|
|
15
|
-
*/
|
|
16
|
-
export declare function compile(chunks: Buffer | Stack): Buffer;
|
|
17
|
-
export declare function decompile(buffer: Buffer | Array<number | Buffer>): Array<number | Buffer> | null;
|
|
18
|
-
/**
|
|
19
|
-
* Converts the given chunks into an ASM (Assembly) string representation.
|
|
20
|
-
* If the chunks parameter is a Buffer, it will be decompiled into a Stack before conversion.
|
|
21
|
-
* @param chunks - The chunks to convert into ASM.
|
|
22
|
-
* @returns The ASM string representation of the chunks.
|
|
23
|
-
*/
|
|
24
|
-
export declare function toASM(chunks: Buffer | Array<number | Buffer>): string;
|
|
25
|
-
/**
|
|
26
|
-
* Converts an ASM string to a Buffer.
|
|
27
|
-
* @param asm The ASM string to convert.
|
|
28
|
-
* @returns The converted Buffer.
|
|
29
|
-
*/
|
|
30
|
-
export declare function fromASM(asm: string): Buffer;
|
|
31
|
-
/**
|
|
32
|
-
* Converts the given chunks into a stack of buffers.
|
|
33
|
-
*
|
|
34
|
-
* @param chunks - The chunks to convert.
|
|
35
|
-
* @returns The stack of buffers.
|
|
36
|
-
*/
|
|
37
|
-
export declare function toStack(chunks: Buffer | Array<number | Buffer>): Buffer[];
|
|
38
|
-
export declare function isCanonicalPubKey(buffer: Buffer): boolean;
|
|
39
|
-
export declare function isDefinedHashType(hashType: number): boolean;
|
|
40
|
-
export declare function isCanonicalScriptSignature(buffer: Buffer): boolean;
|
|
41
|
-
export declare const number: typeof scriptNumber;
|
|
42
|
-
export declare const signature: typeof scriptSignature;
|
package/src/script_number.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/**
|
|
3
|
-
* Decodes a script number from a buffer.
|
|
4
|
-
*
|
|
5
|
-
* @param buffer - The buffer containing the script number.
|
|
6
|
-
* @param maxLength - The maximum length of the script number. Defaults to 4.
|
|
7
|
-
* @param minimal - Whether the script number should be minimal. Defaults to true.
|
|
8
|
-
* @returns The decoded script number.
|
|
9
|
-
* @throws {TypeError} If the script number overflows the maximum length.
|
|
10
|
-
* @throws {Error} If the script number is not minimally encoded when minimal is true.
|
|
11
|
-
*/
|
|
12
|
-
export declare function decode(buffer: Buffer, maxLength?: number, minimal?: boolean): number;
|
|
13
|
-
/**
|
|
14
|
-
* Encodes a number into a Buffer using a specific format.
|
|
15
|
-
*
|
|
16
|
-
* @param _number - The number to encode.
|
|
17
|
-
* @returns The encoded number as a Buffer.
|
|
18
|
-
*/
|
|
19
|
-
export declare function encode(_number: number): Buffer;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
interface ScriptSignature {
|
|
3
|
-
signature: Buffer;
|
|
4
|
-
hashType: number;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Decodes a buffer into a ScriptSignature object.
|
|
8
|
-
* @param buffer - The buffer to decode.
|
|
9
|
-
* @returns The decoded ScriptSignature object.
|
|
10
|
-
* @throws Error if the hashType is invalid.
|
|
11
|
-
*/
|
|
12
|
-
export declare function decode(buffer: Buffer): ScriptSignature;
|
|
13
|
-
/**
|
|
14
|
-
* Encodes a signature and hash type into a buffer.
|
|
15
|
-
* @param signature - The signature to encode.
|
|
16
|
-
* @param hashType - The hash type to encode.
|
|
17
|
-
* @returns The encoded buffer.
|
|
18
|
-
* @throws Error if the hashType is invalid.
|
|
19
|
-
*/
|
|
20
|
-
export declare function encode(signature: Buffer, hashType: number): Buffer;
|
|
21
|
-
export {};
|
package/src/types.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.oneOf =
|
|
4
|
-
exports.Null =
|
|
5
|
-
exports.BufferN =
|
|
6
|
-
exports.Function =
|
|
7
|
-
exports.UInt32 =
|
|
8
|
-
exports.UInt8 =
|
|
9
|
-
exports.tuple =
|
|
10
|
-
exports.maybe =
|
|
11
|
-
exports.Hex =
|
|
12
|
-
exports.Buffer =
|
|
13
|
-
exports.String =
|
|
14
|
-
exports.Boolean =
|
|
15
|
-
exports.Array =
|
|
16
|
-
exports.Number =
|
|
17
|
-
exports.Hash256bit =
|
|
18
|
-
exports.Hash160bit =
|
|
19
|
-
exports.Buffer256bit =
|
|
20
|
-
exports.isTaptree =
|
|
21
|
-
exports.isTapleaf =
|
|
22
|
-
exports.TAPLEAF_VERSION_MASK =
|
|
23
|
-
exports.Satoshi =
|
|
24
|
-
exports.isPoint =
|
|
25
|
-
exports.stacksEqual =
|
|
26
|
-
exports.typeforce =
|
|
27
|
-
void 0;
|
|
28
|
-
const buffer_1 = require('buffer');
|
|
29
|
-
exports.typeforce = require('typeforce');
|
|
30
|
-
const ZERO32 = buffer_1.Buffer.alloc(32, 0);
|
|
31
|
-
const EC_P = buffer_1.Buffer.from(
|
|
32
|
-
'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
|
|
33
|
-
'hex',
|
|
34
|
-
);
|
|
35
|
-
/**
|
|
36
|
-
* Checks if two arrays of Buffers are equal.
|
|
37
|
-
* @param a - The first array of Buffers.
|
|
38
|
-
* @param b - The second array of Buffers.
|
|
39
|
-
* @returns True if the arrays are equal, false otherwise.
|
|
40
|
-
*/
|
|
41
|
-
function stacksEqual(a, b) {
|
|
42
|
-
if (a.length !== b.length) return false;
|
|
43
|
-
return a.every((x, i) => {
|
|
44
|
-
return x.equals(b[i]);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
exports.stacksEqual = stacksEqual;
|
|
48
|
-
/**
|
|
49
|
-
* Checks if the given value is a valid elliptic curve point.
|
|
50
|
-
* @param p - The value to check.
|
|
51
|
-
* @returns True if the value is a valid elliptic curve point, false otherwise.
|
|
52
|
-
*/
|
|
53
|
-
function isPoint(p) {
|
|
54
|
-
if (!buffer_1.Buffer.isBuffer(p)) return false;
|
|
55
|
-
if (p.length < 33) return false;
|
|
56
|
-
const t = p[0];
|
|
57
|
-
const x = p.slice(1, 33);
|
|
58
|
-
if (x.compare(ZERO32) === 0) return false;
|
|
59
|
-
if (x.compare(EC_P) >= 0) return false;
|
|
60
|
-
if ((t === 0x02 || t === 0x03) && p.length === 33) {
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
const y = p.slice(33);
|
|
64
|
-
if (y.compare(ZERO32) === 0) return false;
|
|
65
|
-
if (y.compare(EC_P) >= 0) return false;
|
|
66
|
-
if (t === 0x04 && p.length === 65) return true;
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
exports.isPoint = isPoint;
|
|
70
|
-
const SATOSHI_MAX = 21 * 1e14;
|
|
71
|
-
function Satoshi(value) {
|
|
72
|
-
return exports.typeforce.UInt53(value) && value <= SATOSHI_MAX;
|
|
73
|
-
}
|
|
74
|
-
exports.Satoshi = Satoshi;
|
|
75
|
-
exports.TAPLEAF_VERSION_MASK = 0xfe;
|
|
76
|
-
function isTapleaf(o) {
|
|
77
|
-
if (!o || !('output' in o)) return false;
|
|
78
|
-
if (!buffer_1.Buffer.isBuffer(o.output)) return false;
|
|
79
|
-
if (o.version !== undefined)
|
|
80
|
-
return (o.version & exports.TAPLEAF_VERSION_MASK) === o.version;
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
exports.isTapleaf = isTapleaf;
|
|
84
|
-
function isTaptree(scriptTree) {
|
|
85
|
-
if (!(0, exports.Array)(scriptTree)) return isTapleaf(scriptTree);
|
|
86
|
-
if (scriptTree.length !== 2) return false;
|
|
87
|
-
return scriptTree.every(t => isTaptree(t));
|
|
88
|
-
}
|
|
89
|
-
exports.isTaptree = isTaptree;
|
|
90
|
-
exports.Buffer256bit = exports.typeforce.BufferN(32);
|
|
91
|
-
exports.Hash160bit = exports.typeforce.BufferN(20);
|
|
92
|
-
exports.Hash256bit = exports.typeforce.BufferN(32);
|
|
93
|
-
exports.Number = exports.typeforce.Number;
|
|
94
|
-
exports.Array = exports.typeforce.Array;
|
|
95
|
-
exports.Boolean = exports.typeforce.Boolean;
|
|
96
|
-
exports.String = exports.typeforce.String;
|
|
97
|
-
exports.Buffer = exports.typeforce.Buffer;
|
|
98
|
-
exports.Hex = exports.typeforce.Hex;
|
|
99
|
-
exports.maybe = exports.typeforce.maybe;
|
|
100
|
-
exports.tuple = exports.typeforce.tuple;
|
|
101
|
-
exports.UInt8 = exports.typeforce.UInt8;
|
|
102
|
-
exports.UInt32 = exports.typeforce.UInt32;
|
|
103
|
-
exports.Function = exports.typeforce.Function;
|
|
104
|
-
exports.BufferN = exports.typeforce.BufferN;
|
|
105
|
-
exports.Null = exports.typeforce.Null;
|
|
106
|
-
exports.oneOf = exports.typeforce.oneOf;
|