@btc-vision/bitcoin 6.4.11 → 6.5.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/browser/chunks/crypto-0PweVewC.js +2033 -0
- package/browser/chunks/payments-CgasufRS.js +1047 -0
- package/browser/chunks/psbt-BIwOrKer.js +4096 -0
- package/browser/chunks/script-CROJPzz_.js +318 -0
- package/browser/chunks/transaction-DchBu35N.js +432 -0
- package/browser/chunks/utils-CO5kmxe9.js +761 -0
- package/browser/crypto/crypto.d.ts +1 -1
- package/browser/crypto.d.ts +1 -1
- package/browser/hooks/HookedSigner.d.ts +1 -1
- package/browser/index.d.ts +6 -4
- package/browser/index.js +92 -2
- package/browser/payments/index.d.ts +2 -2
- package/browser/payments/lazy.d.ts +1 -1
- package/browser/psbt/bip371.d.ts +5 -1
- package/browser/psbt.d.ts +1 -1
- package/browser/typeforce.d.ts +38 -0
- package/browser/types.d.ts +22 -20
- package/build/address.js +2 -2
- package/build/bip66.js +2 -2
- package/build/block.js +2 -2
- package/build/crypto.d.ts +1 -1
- package/build/crypto.js +2 -3
- package/build/hooks/HookedSigner.d.ts +1 -1
- package/build/index.d.ts +6 -4
- package/build/index.js +2 -2
- package/build/payments/bip341.js +1 -1
- package/build/payments/index.d.ts +2 -2
- package/build/payments/lazy.d.ts +1 -1
- package/build/payments/p2op.js +3 -3
- package/build/payments/p2pk.js +1 -1
- package/build/payments/p2pkh.js +3 -3
- package/build/payments/p2sh.js +3 -3
- package/build/payments/p2tr.js +9 -5
- package/build/payments/p2wpkh.js +3 -3
- package/build/payments/p2wsh.js +2 -2
- package/build/psbt/bip371.d.ts +5 -1
- package/build/psbt/bip371.js +10 -7
- package/build/psbt/psbtutils.js +5 -4
- package/build/psbt.d.ts +1 -1
- package/build/psbt.js +78 -45
- package/build/script.js +2 -2
- package/build/script_signature.js +7 -7
- package/build/transaction.js +22 -10
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/types.d.ts +22 -20
- package/build/types.js +10 -9
- package/package.json +37 -63
- package/src/address.ts +2 -2
- package/src/bip66.ts +2 -2
- package/src/block.ts +8 -5
- package/src/crypto.ts +3 -4
- package/src/ecc_lib.ts +1 -1
- package/src/hooks/HookedSigner.ts +1 -1
- package/src/index.ts +6 -6
- package/src/payments/bip341.ts +1 -1
- package/src/payments/embed.ts +1 -2
- package/src/payments/index.ts +4 -4
- package/src/payments/lazy.ts +3 -3
- package/src/payments/p2op.ts +4 -3
- package/src/payments/p2pk.ts +1 -1
- package/src/payments/p2pkh.ts +3 -3
- package/src/payments/p2sh.ts +13 -5
- package/src/payments/p2tr.ts +8 -9
- package/src/payments/p2wpkh.ts +3 -3
- package/src/payments/p2wsh.ts +4 -4
- package/src/psbt/bip371.ts +22 -13
- package/src/psbt/psbtutils.ts +8 -5
- package/src/psbt.ts +127 -80
- package/src/script.ts +4 -4
- package/src/script_signature.ts +7 -7
- package/src/transaction.ts +31 -18
- package/src/typeforce.d.ts +38 -0
- package/src/types.ts +34 -29
- package/test/address.spec.ts +12 -4
- package/test/bitcoin.core.spec.ts +1 -1
- package/test/block.spec.ts +1 -1
- package/test/bufferutils.spec.ts +1 -1
- package/test/crypto.spec.ts +3 -2
- package/test/fixtures/address.json +1 -1
- package/test/integration/addresses.spec.ts +1 -1
- package/test/integration/bip32.spec.ts +2 -2
- package/test/integration/blocks.spec.ts +1 -1
- package/test/integration/cltv.spec.ts +3 -3
- package/test/integration/csv.spec.ts +3 -3
- package/test/integration/payments.spec.ts +1 -1
- package/test/integration/taproot.spec.ts +8 -7
- package/test/integration/transactions.spec.ts +2 -2
- package/test/payments.spec.ts +4 -3
- package/test/psbt.spec.ts +106 -74
- package/test/script.spec.ts +73 -7
- package/test/script_number.spec.ts +1 -1
- package/test/script_signature.spec.ts +1 -1
- package/test/transaction.spec.ts +1 -1
- package/test/tsconfig.json +1 -1
- package/test/types.spec.ts +1 -1
- package/vite.config.browser.ts +93 -0
- package/vitest.config.ts +16 -0
- package/.babelrc +0 -4
- package/.mocharc.json +0 -13
- package/browser/index.js.LICENSE.txt +0 -14
- package/cjs/package.json +0 -3
- package/gulpfile.js +0 -42
- package/src/crypto/crypto-browser.js +0 -75
- package/test/ts-node-register.js +0 -7
- package/webpack.config.js +0 -79
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function prop<T extends
|
|
1
|
+
export declare function prop<T extends object>(object: T, name: string, f: () => T[keyof T]): void;
|
|
2
2
|
export declare function value<T>(f: () => T): () => T;
|
package/browser/psbt/bip371.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { PsbtInput, PsbtOutput, TapLeaf } from 'bip174/src/lib/interfaces.js';
|
|
2
2
|
import { Taptree } from '../types.js';
|
|
3
|
+
interface PsbtOutputWithScript extends PsbtOutput {
|
|
4
|
+
script?: Buffer;
|
|
5
|
+
}
|
|
3
6
|
export declare const toXOnly: (pubKey: Buffer | Uint8Array) => Buffer;
|
|
4
7
|
export declare function tapScriptFinalizer(inputIndex: number, input: PsbtInput, tapLeafHashToFinalize?: Buffer): {
|
|
5
8
|
finalScriptWitness: Buffer | undefined;
|
|
@@ -8,9 +11,10 @@ export declare function serializeTaprootSignature(sig: Buffer, sighashType?: num
|
|
|
8
11
|
export declare function isTaprootInput(input: PsbtInput): boolean;
|
|
9
12
|
export declare function isTaprootOutput(output: PsbtOutput, script?: Buffer): boolean;
|
|
10
13
|
export declare function checkTaprootInputFields(inputData: PsbtInput, newInputData: PsbtInput, action: string): void;
|
|
11
|
-
export declare function checkTaprootOutputFields(outputData:
|
|
14
|
+
export declare function checkTaprootOutputFields(outputData: PsbtOutputWithScript, newOutputData: PsbtOutput, action: string): void;
|
|
12
15
|
export declare function tweakInternalPubKey(inputIndex: number, input: PsbtInput): Buffer;
|
|
13
16
|
export declare function tapTreeToList(tree: Taptree): TapLeaf[];
|
|
14
17
|
export declare function tapTreeFromList(leaves?: TapLeaf[]): Taptree;
|
|
15
18
|
export declare function checkTaprootInputForSigs(input: PsbtInput, action: string): boolean;
|
|
16
19
|
export declare function getTapKeySigFromWitness(finalScriptWitness?: Buffer): Buffer | undefined;
|
|
20
|
+
export {};
|
package/browser/psbt.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Psbt as PsbtBase } from 'bip174';
|
|
2
2
|
import { KeyValue, PartialSig, PsbtGlobal, PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, PsbtOutput, PsbtOutputUpdate } from 'bip174/src/lib/interfaces.js';
|
|
3
|
-
import { BIP32Interface } from 'bip32';
|
|
3
|
+
import { BIP32Interface } from '@btc-vision/bip32';
|
|
4
4
|
import { ECPairInterface } from 'ecpair';
|
|
5
5
|
import { Network } from './networks.js';
|
|
6
6
|
import { Transaction } from './transaction.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for typeforce library
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Typeforce type validator - validates that a value matches a given type.
|
|
7
|
+
*/
|
|
8
|
+
type TypeforceValidator = (value: unknown) => boolean;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Interface representing the typeforce library's API.
|
|
12
|
+
*/
|
|
13
|
+
interface TypeforceLib {
|
|
14
|
+
(type: unknown, value: unknown): void;
|
|
15
|
+
Number: TypeforceValidator;
|
|
16
|
+
Array: TypeforceValidator;
|
|
17
|
+
Boolean: TypeforceValidator;
|
|
18
|
+
String: TypeforceValidator;
|
|
19
|
+
Buffer: TypeforceValidator;
|
|
20
|
+
Hex: TypeforceValidator;
|
|
21
|
+
Null: TypeforceValidator;
|
|
22
|
+
Function: TypeforceValidator;
|
|
23
|
+
UInt8: TypeforceValidator;
|
|
24
|
+
UInt32: TypeforceValidator;
|
|
25
|
+
UInt53: TypeforceValidator;
|
|
26
|
+
BufferN: (n: number) => TypeforceValidator;
|
|
27
|
+
maybe: (type: unknown) => TypeforceValidator;
|
|
28
|
+
tuple: (...types: unknown[]) => TypeforceValidator;
|
|
29
|
+
oneOf: (...types: unknown[]) => TypeforceValidator;
|
|
30
|
+
arrayOf: (type: unknown) => TypeforceValidator;
|
|
31
|
+
Object: TypeforceValidator;
|
|
32
|
+
anyOf: (...types: unknown[]) => TypeforceValidator;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare module 'typeforce' {
|
|
36
|
+
const typeforce: TypeforceLib;
|
|
37
|
+
export = typeforce;
|
|
38
|
+
}
|
package/browser/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { default as typeforce } from 'typeforce';
|
|
2
|
+
export { typeforce };
|
|
3
|
+
export type TypeforceValidator = (value: unknown) => boolean;
|
|
2
4
|
export declare function stacksEqual(a: Buffer[], b: Buffer[]): boolean;
|
|
3
5
|
export declare function isPoint(p: Buffer | number | undefined | null): boolean;
|
|
4
6
|
export declare function Satoshi(value: number): boolean;
|
|
@@ -11,27 +13,27 @@ export interface Tapleaf {
|
|
|
11
13
|
version?: number;
|
|
12
14
|
}
|
|
13
15
|
export declare const TAPLEAF_VERSION_MASK = 254;
|
|
14
|
-
export declare function isTapleaf(o:
|
|
16
|
+
export declare function isTapleaf(o: unknown): o is Tapleaf;
|
|
15
17
|
export type Taptree = [Taptree | Tapleaf, Taptree | Tapleaf] | Tapleaf;
|
|
16
|
-
export declare function isTaptree(scriptTree:
|
|
18
|
+
export declare function isTaptree(scriptTree: unknown): scriptTree is Taptree;
|
|
17
19
|
export interface TinySecp256k1Interface {
|
|
18
20
|
isXOnlyPoint(p: Uint8Array): boolean;
|
|
19
21
|
xOnlyPointAddTweak(p: Uint8Array, tweak: Uint8Array): XOnlyPointAddTweakResult | null;
|
|
20
22
|
}
|
|
21
|
-
export declare const Buffer256bit:
|
|
22
|
-
export declare const Hash160bit:
|
|
23
|
-
export declare const Hash256bit:
|
|
24
|
-
export declare const Number:
|
|
25
|
-
export declare const Array:
|
|
26
|
-
export declare const Boolean:
|
|
27
|
-
export declare const String:
|
|
28
|
-
export declare const Buffer:
|
|
29
|
-
export declare const Hex:
|
|
30
|
-
export declare const maybe:
|
|
31
|
-
export declare const tuple:
|
|
32
|
-
export declare const UInt8:
|
|
33
|
-
export declare const UInt32:
|
|
34
|
-
export declare const Function:
|
|
35
|
-
export declare const BufferN:
|
|
36
|
-
export declare const Null:
|
|
37
|
-
export declare const oneOf:
|
|
23
|
+
export declare const Buffer256bit: TypeforceValidator;
|
|
24
|
+
export declare const Hash160bit: TypeforceValidator;
|
|
25
|
+
export declare const Hash256bit: TypeforceValidator;
|
|
26
|
+
export declare const Number: TypeforceValidator;
|
|
27
|
+
export declare const Array: TypeforceValidator;
|
|
28
|
+
export declare const Boolean: TypeforceValidator;
|
|
29
|
+
export declare const String: TypeforceValidator;
|
|
30
|
+
export declare const Buffer: TypeforceValidator;
|
|
31
|
+
export declare const Hex: TypeforceValidator;
|
|
32
|
+
export declare const maybe: (type: unknown) => TypeforceValidator;
|
|
33
|
+
export declare const tuple: (...types: unknown[]) => TypeforceValidator;
|
|
34
|
+
export declare const UInt8: TypeforceValidator;
|
|
35
|
+
export declare const UInt32: TypeforceValidator;
|
|
36
|
+
export declare const Function: TypeforceValidator;
|
|
37
|
+
export declare const BufferN: (n: number) => TypeforceValidator;
|
|
38
|
+
export declare const Null: TypeforceValidator;
|
|
39
|
+
export declare const oneOf: (...types: unknown[]) => TypeforceValidator;
|
package/build/address.js
CHANGED
|
@@ -114,7 +114,7 @@ export function fromBech32(address) {
|
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
export function toBase58Check(hash, version) {
|
|
117
|
-
typeforce(tuple(Hash160bit, UInt8),
|
|
117
|
+
typeforce(tuple(Hash160bit, UInt8), [hash, version]);
|
|
118
118
|
const payload = Buffer.allocUnsafe(21);
|
|
119
119
|
payload.writeUInt8(version, 0);
|
|
120
120
|
hash.copy(payload, 1);
|
|
@@ -216,5 +216,5 @@ export function toOutputScript(address, network) {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
|
|
219
|
+
throw new TypeError(address + ' has no matching Script');
|
|
220
220
|
}
|
package/build/bip66.js
CHANGED
|
@@ -63,8 +63,8 @@ export function decode(buffer) {
|
|
|
63
63
|
if (lenS > 1 && buffer[lenR + 6] === 0x00 && !(buffer[lenR + 7] & 0x80))
|
|
64
64
|
throw new Error('S value excessively padded');
|
|
65
65
|
return {
|
|
66
|
-
r: buffer.
|
|
67
|
-
s: buffer.
|
|
66
|
+
r: buffer.subarray(4, 4 + lenR),
|
|
67
|
+
s: buffer.subarray(6 + lenR),
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
export function encode(r, s) {
|
package/build/block.js
CHANGED
|
@@ -31,7 +31,7 @@ export class Block {
|
|
|
31
31
|
if (buffer.length === 80)
|
|
32
32
|
return block;
|
|
33
33
|
const readTransaction = () => {
|
|
34
|
-
const tx = Transaction.fromBuffer(bufferReader.buffer.
|
|
34
|
+
const tx = Transaction.fromBuffer(bufferReader.buffer.subarray(bufferReader.offset), true);
|
|
35
35
|
bufferReader.offset += tx.byteLength();
|
|
36
36
|
return tx;
|
|
37
37
|
};
|
|
@@ -71,7 +71,7 @@ export class Block {
|
|
|
71
71
|
getWitnessCommit() {
|
|
72
72
|
if (!txesHaveWitnessCommit(this.transactions))
|
|
73
73
|
return null;
|
|
74
|
-
const witnessCommits = this.transactions[0].outs.filter((out) => out.script.
|
|
74
|
+
const witnessCommits = this.transactions[0].outs.filter((out) => out.script.subarray(0, 6).equals(Buffer.from('6a24aa21a9ed', 'hex'))).map((out) => out.script.subarray(6, 38));
|
|
75
75
|
if (witnessCommits.length === 0)
|
|
76
76
|
return null;
|
|
77
77
|
const result = witnessCommits[witnessCommits.length - 1];
|
package/build/crypto.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare function sha256(buffer: Buffer): Buffer;
|
|
|
4
4
|
export declare function hash160(buffer: Buffer): Buffer;
|
|
5
5
|
export declare function hash256(buffer: Buffer): Buffer;
|
|
6
6
|
export declare const TAGS: readonly ["BIP0340/challenge", "BIP0340/aux", "BIP0340/nonce", "TapLeaf", "TapBranch", "TapSighash", "TapTweak", "KeyAgg list", "KeyAgg coefficient"];
|
|
7
|
-
export type TaggedHashPrefix = typeof TAGS[number];
|
|
7
|
+
export type TaggedHashPrefix = (typeof TAGS)[number];
|
|
8
8
|
type TaggedHashPrefixes = {
|
|
9
9
|
[key in TaggedHashPrefix]: Buffer;
|
|
10
10
|
};
|
package/build/crypto.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ripemd160 as _ripemd160 } from '@noble/hashes/
|
|
2
|
-
import {
|
|
3
|
-
import { sha256 as _sha256 } from '@noble/hashes/sha256';
|
|
1
|
+
import { ripemd160 as _ripemd160, sha1 as _sha1 } from '@noble/hashes/legacy.js';
|
|
2
|
+
import { sha256 as _sha256 } from '@noble/hashes/sha2.js';
|
|
4
3
|
export function ripemd160(buffer) {
|
|
5
4
|
return Buffer.from(_ripemd160(Uint8Array.from(buffer)));
|
|
6
5
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BIP32Interface } from 'bip32';
|
|
1
|
+
import { BIP32Interface } from '@btc-vision/bip32';
|
|
2
2
|
import { ECPairInterface } from 'ecpair';
|
|
3
3
|
import { Signer, SignerAlternative, SignerAsync } from '../psbt.js';
|
|
4
4
|
export declare function hookSigner(keyPair: Signer | SignerAlternative | SignerAsync | BIP32Interface | ECPairInterface): void;
|
package/build/index.d.ts
CHANGED
|
@@ -15,10 +15,11 @@ export * from './crypto.js';
|
|
|
15
15
|
export * from './psbt.js';
|
|
16
16
|
export { opcodes } from './opcodes.js';
|
|
17
17
|
export { Transaction } from './transaction.js';
|
|
18
|
-
export { Network } from './networks.js';
|
|
18
|
+
export type { Network } from './networks.js';
|
|
19
19
|
export { initEccLib } from './ecc_lib.js';
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
20
|
+
export { PaymentType } from './payments/index.js';
|
|
21
|
+
export type { Payment, PaymentCreator, PaymentOpts, Stack, StackElement, P2WSHPayment, P2PKPayment, BasePayment, P2SHPayment, P2TRPayment, P2WPKHPayment, P2PKHPayment, P2MSPayment, EmbedPayment, P2OPPayment, P2OPPaymentParams, StackFunction, } from './payments/index.js';
|
|
22
|
+
export type { Input as TxInput, Output as TxOutput } from './transaction.js';
|
|
22
23
|
export interface PsbtInput extends _PsbtInput {
|
|
23
24
|
}
|
|
24
25
|
export interface PsbtOutput extends _PsbtOutput {
|
|
@@ -46,7 +47,8 @@ export * from './address.js';
|
|
|
46
47
|
export * from './bufferutils.js';
|
|
47
48
|
export * from './payments/bip341.js';
|
|
48
49
|
export * from './psbt/psbtutils.js';
|
|
49
|
-
export {
|
|
50
|
+
export { TAPLEAF_VERSION_MASK } from './types.js';
|
|
51
|
+
export type { Taptree, XOnlyPointAddTweakResult, Tapleaf, TinySecp256k1Interface, } from './types.js';
|
|
50
52
|
declare const bitcoin: {
|
|
51
53
|
networks: typeof networks;
|
|
52
54
|
address: typeof address;
|
package/build/index.js
CHANGED
|
@@ -15,13 +15,13 @@ export * from './psbt.js';
|
|
|
15
15
|
export { opcodes } from './opcodes.js';
|
|
16
16
|
export { Transaction } from './transaction.js';
|
|
17
17
|
export { initEccLib } from './ecc_lib.js';
|
|
18
|
-
export { PaymentType
|
|
18
|
+
export { PaymentType } from './payments/index.js';
|
|
19
19
|
export * from './psbt/bip371.js';
|
|
20
20
|
export * from './address.js';
|
|
21
21
|
export * from './bufferutils.js';
|
|
22
22
|
export * from './payments/bip341.js';
|
|
23
23
|
export * from './psbt/psbtutils.js';
|
|
24
|
-
export { TAPLEAF_VERSION_MASK
|
|
24
|
+
export { TAPLEAF_VERSION_MASK } from './types.js';
|
|
25
25
|
const bitcoin = {
|
|
26
26
|
networks,
|
|
27
27
|
address,
|
package/build/payments/bip341.js
CHANGED
|
@@ -12,7 +12,7 @@ export function rootHashFromPath(controlBlock, leafHash) {
|
|
|
12
12
|
const m = (controlBlock.length - 33) / 32;
|
|
13
13
|
let kj = leafHash;
|
|
14
14
|
for (let j = 0; j < m; j++) {
|
|
15
|
-
const ej = controlBlock.
|
|
15
|
+
const ej = controlBlock.subarray(33 + 32 * j, 65 + 32 * j);
|
|
16
16
|
if (kj.compare(ej) < 0) {
|
|
17
17
|
kj = tapBranchHash(kj, ej);
|
|
18
18
|
}
|
package/build/payments/lazy.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function prop<T extends
|
|
1
|
+
export declare function prop<T extends object>(object: T, name: string, f: () => T[keyof T]): void;
|
|
2
2
|
export declare function value<T>(f: () => T): () => T;
|
package/build/payments/p2op.js
CHANGED
|
@@ -64,7 +64,7 @@ export function p2op(a, opts) {
|
|
|
64
64
|
else {
|
|
65
65
|
throw new TypeError('Unsupported push opcode in P2OP script');
|
|
66
66
|
}
|
|
67
|
-
return a.output.
|
|
67
|
+
return a.output.subarray(pushPos, pushPos + progLen);
|
|
68
68
|
}
|
|
69
69
|
if (a.address) {
|
|
70
70
|
const dec = _address();
|
|
@@ -79,7 +79,7 @@ export function p2op(a, opts) {
|
|
|
79
79
|
lazy.prop(o, 'hash160', () => {
|
|
80
80
|
if (!o.program)
|
|
81
81
|
return;
|
|
82
|
-
return o.program.
|
|
82
|
+
return o.program.subarray(1);
|
|
83
83
|
});
|
|
84
84
|
lazy.prop(o, 'output', () => {
|
|
85
85
|
if (!o.program)
|
|
@@ -126,7 +126,7 @@ export function p2op(a, opts) {
|
|
|
126
126
|
throw new TypeError(`Witness program must be 2–40 bytes. Was ${prog.length} bytes`);
|
|
127
127
|
if (a.deploymentVersion !== undefined && a.deploymentVersion !== prog[0])
|
|
128
128
|
throw new TypeError('deploymentVersion mismatch');
|
|
129
|
-
if (a.hash160 && !a.hash160.equals(prog.
|
|
129
|
+
if (a.hash160 && !a.hash160.equals(prog.subarray(1)))
|
|
130
130
|
throw new TypeError('hash160 mismatch');
|
|
131
131
|
}
|
|
132
132
|
return Object.assign(o, a);
|
package/build/payments/p2pk.js
CHANGED
package/build/payments/p2pkh.js
CHANGED
|
@@ -24,7 +24,7 @@ export function p2pkh(a, opts) {
|
|
|
24
24
|
const _address = lazy.value(() => {
|
|
25
25
|
const payload = Buffer.from(bs58check.default.decode(a.address));
|
|
26
26
|
const version = payload.readUInt8(0);
|
|
27
|
-
const hash = payload.
|
|
27
|
+
const hash = payload.subarray(1);
|
|
28
28
|
return { version, hash };
|
|
29
29
|
});
|
|
30
30
|
const _chunks = lazy.value(() => {
|
|
@@ -46,7 +46,7 @@ export function p2pkh(a, opts) {
|
|
|
46
46
|
});
|
|
47
47
|
lazy.prop(o, 'hash', () => {
|
|
48
48
|
if (a.output)
|
|
49
|
-
return a.output.
|
|
49
|
+
return a.output.subarray(3, 23);
|
|
50
50
|
if (a.address)
|
|
51
51
|
return _address().hash;
|
|
52
52
|
if (a.pubkey || o.pubkey)
|
|
@@ -125,7 +125,7 @@ export function p2pkh(a, opts) {
|
|
|
125
125
|
a.output[24] !== OPS.OP_CHECKSIG) {
|
|
126
126
|
throw new TypeError('Output is invalid');
|
|
127
127
|
}
|
|
128
|
-
const hash2 = a.output.
|
|
128
|
+
const hash2 = a.output.subarray(3, 23);
|
|
129
129
|
if (hash.length > 0 && !hash.equals(hash2))
|
|
130
130
|
throw new TypeError('Hash mismatch');
|
|
131
131
|
else
|
package/build/payments/p2sh.js
CHANGED
|
@@ -36,7 +36,7 @@ export function p2sh(a, opts) {
|
|
|
36
36
|
const _address = lazy.value(() => {
|
|
37
37
|
const payload = Buffer.from(bs58check.default.decode(a.address));
|
|
38
38
|
const version = payload.readUInt8(0);
|
|
39
|
-
const hash = payload.
|
|
39
|
+
const hash = payload.subarray(1);
|
|
40
40
|
return { version, hash };
|
|
41
41
|
});
|
|
42
42
|
const _chunks = lazy.value(() => {
|
|
@@ -62,7 +62,7 @@ export function p2sh(a, opts) {
|
|
|
62
62
|
});
|
|
63
63
|
lazy.prop(o, 'hash', () => {
|
|
64
64
|
if (a.output)
|
|
65
|
-
return a.output.
|
|
65
|
+
return a.output.subarray(2, 22);
|
|
66
66
|
if (a.address)
|
|
67
67
|
return _address().hash;
|
|
68
68
|
if (o.redeem && o.redeem.output)
|
|
@@ -116,7 +116,7 @@ export function p2sh(a, opts) {
|
|
|
116
116
|
a.output[1] !== 0x14 ||
|
|
117
117
|
a.output[22] !== OPS.OP_EQUAL)
|
|
118
118
|
throw new TypeError('Output is invalid');
|
|
119
|
-
const hash2 = a.output.
|
|
119
|
+
const hash2 = a.output.subarray(2, 22);
|
|
120
120
|
if (hash.length > 0 && !hash.equals(hash2))
|
|
121
121
|
throw new TypeError('Hash mismatch');
|
|
122
122
|
else
|
package/build/payments/p2tr.js
CHANGED
|
@@ -111,7 +111,7 @@ export function p2tr(a, opts) {
|
|
|
111
111
|
if (a.pubkey)
|
|
112
112
|
return a.pubkey;
|
|
113
113
|
if (a.output)
|
|
114
|
-
return a.output.
|
|
114
|
+
return a.output.subarray(2);
|
|
115
115
|
if (a.address)
|
|
116
116
|
return _address().data;
|
|
117
117
|
if (o.internalPubkey) {
|
|
@@ -125,7 +125,7 @@ export function p2tr(a, opts) {
|
|
|
125
125
|
return a.internalPubkey;
|
|
126
126
|
const witness = _witness();
|
|
127
127
|
if (witness && witness.length > 1)
|
|
128
|
-
return witness[witness.length - 1].
|
|
128
|
+
return witness[witness.length - 1].subarray(1, 33);
|
|
129
129
|
});
|
|
130
130
|
lazy.prop(o, 'signature', () => {
|
|
131
131
|
if (a.signature)
|
|
@@ -176,10 +176,10 @@ export function p2tr(a, opts) {
|
|
|
176
176
|
if (a.output) {
|
|
177
177
|
if (a.output.length !== 34 || a.output[0] !== OPS.OP_1 || a.output[1] !== 0x20)
|
|
178
178
|
throw new TypeError('Output is invalid');
|
|
179
|
-
if (pubkey.length > 0 && !pubkey.equals(a.output.
|
|
179
|
+
if (pubkey.length > 0 && !pubkey.equals(a.output.subarray(2)))
|
|
180
180
|
throw new TypeError('Pubkey mismatch');
|
|
181
181
|
else
|
|
182
|
-
pubkey = a.output.
|
|
182
|
+
pubkey = a.output.subarray(2);
|
|
183
183
|
}
|
|
184
184
|
if (a.internalPubkey) {
|
|
185
185
|
const tweakedKey = tweakKey(a.internalPubkey, o.hash);
|
|
@@ -188,6 +188,10 @@ export function p2tr(a, opts) {
|
|
|
188
188
|
else
|
|
189
189
|
pubkey = tweakedKey.x;
|
|
190
190
|
}
|
|
191
|
+
if (pubkey && pubkey.length) {
|
|
192
|
+
if (!getEccLib().isXOnlyPoint(pubkey))
|
|
193
|
+
throw new TypeError('Invalid pubkey for p2tr');
|
|
194
|
+
}
|
|
191
195
|
const hashTree = _hashTree();
|
|
192
196
|
if (a.hash && hashTree) {
|
|
193
197
|
if (!a.hash.equals(hashTree.hash))
|
|
@@ -232,7 +236,7 @@ export function p2tr(a, opts) {
|
|
|
232
236
|
const m = (controlBlock.length - 33) / 32;
|
|
233
237
|
if (m > 128)
|
|
234
238
|
throw new TypeError(`The script path is too long. Got ${m}, expected max 128.`);
|
|
235
|
-
const internalPubkey = controlBlock.
|
|
239
|
+
const internalPubkey = controlBlock.subarray(1, 33);
|
|
236
240
|
if (a.internalPubkey && !a.internalPubkey.equals(internalPubkey))
|
|
237
241
|
throw new TypeError('Internal pubkey mismatch');
|
|
238
242
|
if (!getEccLib().isXOnlyPoint(internalPubkey))
|
package/build/payments/p2wpkh.js
CHANGED
|
@@ -45,7 +45,7 @@ export function p2wpkh(a, opts) {
|
|
|
45
45
|
});
|
|
46
46
|
lazy.prop(o, 'hash', () => {
|
|
47
47
|
if (a.output)
|
|
48
|
-
return a.output.
|
|
48
|
+
return a.output.subarray(2, 22);
|
|
49
49
|
if (a.address)
|
|
50
50
|
return _address().data;
|
|
51
51
|
if (a.pubkey || o.pubkey)
|
|
@@ -100,10 +100,10 @@ export function p2wpkh(a, opts) {
|
|
|
100
100
|
if (a.output) {
|
|
101
101
|
if (a.output.length !== 22 || a.output[0] !== OPS.OP_0 || a.output[1] !== 0x14)
|
|
102
102
|
throw new TypeError('Output is invalid');
|
|
103
|
-
if (hash.length > 0 && !hash.equals(a.output.
|
|
103
|
+
if (hash.length > 0 && !hash.equals(a.output.subarray(2)))
|
|
104
104
|
throw new TypeError('Hash mismatch');
|
|
105
105
|
else
|
|
106
|
-
hash = a.output.
|
|
106
|
+
hash = a.output.subarray(2);
|
|
107
107
|
}
|
|
108
108
|
if (a.pubkey) {
|
|
109
109
|
const pkh = bcrypto.hash160(a.pubkey);
|
package/build/payments/p2wsh.js
CHANGED
|
@@ -63,7 +63,7 @@ export function p2wsh(a, opts) {
|
|
|
63
63
|
});
|
|
64
64
|
lazy.prop(o, 'hash', () => {
|
|
65
65
|
if (a.output)
|
|
66
|
-
return a.output.
|
|
66
|
+
return a.output.subarray(2);
|
|
67
67
|
if (a.address)
|
|
68
68
|
return _address().data;
|
|
69
69
|
if (o.redeem && o.redeem.output)
|
|
@@ -133,7 +133,7 @@ export function p2wsh(a, opts) {
|
|
|
133
133
|
if (a.output) {
|
|
134
134
|
if (a.output.length !== 34 || a.output[0] !== OPS.OP_0 || a.output[1] !== 0x20)
|
|
135
135
|
throw new TypeError('Output is invalid');
|
|
136
|
-
const hash2 = a.output.
|
|
136
|
+
const hash2 = a.output.subarray(2);
|
|
137
137
|
if (hash.length > 0 && !hash.equals(hash2))
|
|
138
138
|
throw new TypeError('Hash mismatch');
|
|
139
139
|
else
|
package/build/psbt/bip371.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { PsbtInput, PsbtOutput, TapLeaf } from 'bip174/src/lib/interfaces.js';
|
|
2
2
|
import { Taptree } from '../types.js';
|
|
3
|
+
interface PsbtOutputWithScript extends PsbtOutput {
|
|
4
|
+
script?: Buffer;
|
|
5
|
+
}
|
|
3
6
|
export declare const toXOnly: (pubKey: Buffer | Uint8Array) => Buffer;
|
|
4
7
|
export declare function tapScriptFinalizer(inputIndex: number, input: PsbtInput, tapLeafHashToFinalize?: Buffer): {
|
|
5
8
|
finalScriptWitness: Buffer | undefined;
|
|
@@ -8,9 +11,10 @@ export declare function serializeTaprootSignature(sig: Buffer, sighashType?: num
|
|
|
8
11
|
export declare function isTaprootInput(input: PsbtInput): boolean;
|
|
9
12
|
export declare function isTaprootOutput(output: PsbtOutput, script?: Buffer): boolean;
|
|
10
13
|
export declare function checkTaprootInputFields(inputData: PsbtInput, newInputData: PsbtInput, action: string): void;
|
|
11
|
-
export declare function checkTaprootOutputFields(outputData:
|
|
14
|
+
export declare function checkTaprootOutputFields(outputData: PsbtOutputWithScript, newOutputData: PsbtOutput, action: string): void;
|
|
12
15
|
export declare function tweakInternalPubKey(inputIndex: number, input: PsbtInput): Buffer;
|
|
13
16
|
export declare function tapTreeToList(tree: Taptree): TapLeaf[];
|
|
14
17
|
export declare function tapTreeFromList(leaves?: TapLeaf[]): Taptree;
|
|
15
18
|
export declare function checkTaprootInputForSigs(input: PsbtInput, action: string): boolean;
|
|
16
19
|
export declare function getTapKeySigFromWitness(finalScriptWitness?: Buffer): Buffer | undefined;
|
|
20
|
+
export {};
|
package/build/psbt/bip371.js
CHANGED
|
@@ -4,7 +4,7 @@ import { LEAF_VERSION_TAPSCRIPT, MAX_TAPTREE_DEPTH, rootHashFromPath, tapleafHas
|
|
|
4
4
|
import { p2tr } from '../payments/p2tr.js';
|
|
5
5
|
import { isP2TR, pubkeyPositionInScript, signatureBlocksAction, witnessStackToScriptWitness, } from './psbtutils.js';
|
|
6
6
|
export const toXOnly = (pubKey) => {
|
|
7
|
-
const buffer = pubKey.length === 32 ? pubKey : pubKey.
|
|
7
|
+
const buffer = pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33);
|
|
8
8
|
return Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
|
|
9
9
|
};
|
|
10
10
|
export function tapScriptFinalizer(inputIndex, input, tapLeafHashToFinalize) {
|
|
@@ -51,7 +51,7 @@ function checkTaprootScriptPubkey(outputData, newOutputData) {
|
|
|
51
51
|
const tapInternalKey = newOutputData.tapInternalKey || outputData.tapInternalKey;
|
|
52
52
|
const tapTree = newOutputData.tapTree || outputData.tapTree;
|
|
53
53
|
if (tapInternalKey) {
|
|
54
|
-
const
|
|
54
|
+
const scriptPubkey = outputData.script;
|
|
55
55
|
const script = getTaprootScripPubkey(tapInternalKey, tapTree);
|
|
56
56
|
if (scriptPubkey && !scriptPubkey.equals(script))
|
|
57
57
|
throw new Error('Error adding output. Script or address missmatch.');
|
|
@@ -63,6 +63,8 @@ function getTaprootScripPubkey(tapInternalKey, tapTree) {
|
|
|
63
63
|
internalPubkey: tapInternalKey,
|
|
64
64
|
scriptTree,
|
|
65
65
|
});
|
|
66
|
+
if (!output)
|
|
67
|
+
throw new Error('Failed to generate taproot script pubkey');
|
|
66
68
|
return output;
|
|
67
69
|
}
|
|
68
70
|
export function tweakInternalPubKey(inputIndex, input) {
|
|
@@ -91,8 +93,8 @@ export function checkTaprootInputForSigs(input, action) {
|
|
|
91
93
|
}
|
|
92
94
|
function decodeSchnorrSignature(signature) {
|
|
93
95
|
return {
|
|
94
|
-
signature: signature.
|
|
95
|
-
hashType: signature.
|
|
96
|
+
signature: signature.subarray(0, 64),
|
|
97
|
+
hashType: signature.subarray(64)[0] || Transaction.SIGHASH_DEFAULT,
|
|
96
98
|
};
|
|
97
99
|
}
|
|
98
100
|
function extractTaprootSigs(input) {
|
|
@@ -111,7 +113,7 @@ function extractTaprootSigs(input) {
|
|
|
111
113
|
export function getTapKeySigFromWitness(finalScriptWitness) {
|
|
112
114
|
if (!finalScriptWitness)
|
|
113
115
|
return;
|
|
114
|
-
const witness = finalScriptWitness.
|
|
116
|
+
const witness = finalScriptWitness.subarray(2);
|
|
115
117
|
if (witness.length === 64 || witness.length === 65)
|
|
116
118
|
return witness;
|
|
117
119
|
}
|
|
@@ -223,11 +225,12 @@ function addPubkeyPositionInScript(script, tss) {
|
|
|
223
225
|
}, tss);
|
|
224
226
|
}
|
|
225
227
|
function findTapLeafToFinalize(input, inputIndex, leafHashToFinalize) {
|
|
226
|
-
|
|
228
|
+
const { tapScriptSig } = input;
|
|
229
|
+
if (!tapScriptSig || !tapScriptSig.length)
|
|
227
230
|
throw new Error(`Can not finalize taproot input #${inputIndex}. No tapleaf script signature provided.`);
|
|
228
231
|
const tapLeaf = (input.tapLeafScript || [])
|
|
229
232
|
.sort((a, b) => a.controlBlock.length - b.controlBlock.length)
|
|
230
|
-
.find((leaf) => canFinalizeLeaf(leaf,
|
|
233
|
+
.find((leaf) => canFinalizeLeaf(leaf, tapScriptSig, leafHashToFinalize));
|
|
231
234
|
if (!tapLeaf)
|
|
232
235
|
throw new Error(`Can not finalize taproot input #${inputIndex}. Signature for tapleaf script not found.`);
|
|
233
236
|
return tapLeaf;
|
package/build/psbt/psbtutils.js
CHANGED
|
@@ -18,7 +18,7 @@ function isPaymentFactory(payment) {
|
|
|
18
18
|
payment({ output: script });
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
|
-
catch
|
|
21
|
+
catch {
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
};
|
|
@@ -170,14 +170,15 @@ export function signatureBlocksAction(signature, signatureDecodeFn, action) {
|
|
|
170
170
|
return whitelist.indexOf(action) === -1;
|
|
171
171
|
}
|
|
172
172
|
function extractPartialSigs(input) {
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
const { partialSig } = input;
|
|
174
|
+
let pSigs;
|
|
175
|
+
if (!partialSig || partialSig.length === 0) {
|
|
175
176
|
if (!input.finalScriptSig && !input.finalScriptWitness)
|
|
176
177
|
return [];
|
|
177
178
|
pSigs = getPsigsFromInputFinalScripts(input);
|
|
178
179
|
}
|
|
179
180
|
else {
|
|
180
|
-
pSigs =
|
|
181
|
+
pSigs = partialSig;
|
|
181
182
|
}
|
|
182
183
|
return pSigs.map((p) => p.signature);
|
|
183
184
|
}
|
package/build/psbt.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Psbt as PsbtBase } from 'bip174';
|
|
2
2
|
import { KeyValue, PartialSig, PsbtGlobal, PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, PsbtOutput, PsbtOutputUpdate } from 'bip174/src/lib/interfaces.js';
|
|
3
|
-
import { BIP32Interface } from 'bip32';
|
|
3
|
+
import { BIP32Interface } from '@btc-vision/bip32';
|
|
4
4
|
import { ECPairInterface } from 'ecpair';
|
|
5
5
|
import { Network } from './networks.js';
|
|
6
6
|
import { Transaction } from './transaction.js';
|