@btc-vision/bitcoin 6.5.1 → 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-BE4vwHhV.js → payments-CgasufRS.js} +410 -408
- package/browser/chunks/psbt-BIwOrKer.js +4096 -0
- package/browser/chunks/{script-COWGdiOo.js → script-CROJPzz_.js} +96 -96
- package/browser/chunks/{transaction-BiXwH2v4.js → transaction-DchBu35N.js} +158 -147
- package/browser/chunks/{utils-BKmkTzNZ.js → utils-CO5kmxe9.js} +225 -223
- package/browser/crypto.d.ts +1 -1
- package/browser/hooks/HookedSigner.d.ts +1 -1
- package/browser/index.d.ts +23 -1
- package/browser/index.js +6 -6
- 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 +23 -1
- 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 +30 -59
- 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 +34 -12
- 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/vitest.config.ts +16 -0
- package/.babelrc +0 -13
- package/.mocharc.json +0 -13
- package/browser/chunks/crypto-C6FlKKmp.js +0 -2006
- package/browser/chunks/psbt-Dlosf9CT.js +0 -3853
- 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
package/src/transaction.ts
CHANGED
|
@@ -34,13 +34,13 @@ const ONE: Buffer = Buffer.from(
|
|
|
34
34
|
'hex',
|
|
35
35
|
);
|
|
36
36
|
const VALUE_UINT64_MAX: Buffer = Buffer.from('ffffffffffffffff', 'hex');
|
|
37
|
-
const BLANK_OUTPUT = {
|
|
37
|
+
const BLANK_OUTPUT: BlankOutput = {
|
|
38
38
|
script: EMPTY_BUFFER,
|
|
39
39
|
valueBuffer: VALUE_UINT64_MAX,
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
function isOutput(out: Output):
|
|
43
|
-
return
|
|
42
|
+
function isOutput(out: Output | BlankOutput): out is Output {
|
|
43
|
+
return 'value' in out;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export interface Output {
|
|
@@ -48,6 +48,11 @@ export interface Output {
|
|
|
48
48
|
value: number;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
interface BlankOutput {
|
|
52
|
+
script: Buffer;
|
|
53
|
+
valueBuffer: Buffer;
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
export interface Input {
|
|
52
57
|
hash: Buffer;
|
|
53
58
|
index: number;
|
|
@@ -164,7 +169,7 @@ export class Transaction {
|
|
|
164
169
|
types.maybe(types.UInt32),
|
|
165
170
|
types.maybe(types.Buffer),
|
|
166
171
|
),
|
|
167
|
-
|
|
172
|
+
[hash, index, sequence, scriptSig],
|
|
168
173
|
);
|
|
169
174
|
|
|
170
175
|
if (types.Null(sequence)) {
|
|
@@ -184,7 +189,7 @@ export class Transaction {
|
|
|
184
189
|
}
|
|
185
190
|
|
|
186
191
|
addOutput(scriptPubKey: Buffer, value: number): number {
|
|
187
|
-
typeforce(types.tuple(types.Buffer, types.Satoshi),
|
|
192
|
+
typeforce(types.tuple(types.Buffer, types.Satoshi), [scriptPubKey, value]);
|
|
188
193
|
|
|
189
194
|
// Add the output and return the output's index
|
|
190
195
|
return (
|
|
@@ -266,17 +271,20 @@ export class Transaction {
|
|
|
266
271
|
* This hash can then be used to sign the provided transaction input.
|
|
267
272
|
*/
|
|
268
273
|
hashForSignature(inIndex: number, prevOutScript: Buffer, hashType: number): Buffer {
|
|
269
|
-
typeforce(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
274
|
+
typeforce(types.tuple(types.UInt32, types.Buffer, /* types.UInt8 */ types.Number), [
|
|
275
|
+
inIndex,
|
|
276
|
+
prevOutScript,
|
|
277
|
+
hashType,
|
|
278
|
+
]);
|
|
273
279
|
|
|
274
280
|
// https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L29
|
|
275
281
|
if (inIndex >= this.ins.length) return ONE;
|
|
276
282
|
|
|
277
283
|
// ignore OP_CODESEPARATOR
|
|
284
|
+
const decompiled = bscript.decompile(prevOutScript);
|
|
285
|
+
if (!decompiled) throw new Error('Could not decompile prevOutScript');
|
|
278
286
|
const ourScript = bscript.compile(
|
|
279
|
-
|
|
287
|
+
decompiled.filter((x) => {
|
|
280
288
|
return x !== opcodes.OP_CODESEPARATOR;
|
|
281
289
|
}),
|
|
282
290
|
);
|
|
@@ -304,7 +312,7 @@ export class Transaction {
|
|
|
304
312
|
|
|
305
313
|
// "blank" outputs before
|
|
306
314
|
for (let i = 0; i < inIndex; i++) {
|
|
307
|
-
(txTmp.outs as
|
|
315
|
+
(txTmp.outs as (Output | BlankOutput)[])[i] = BLANK_OUTPUT;
|
|
308
316
|
}
|
|
309
317
|
|
|
310
318
|
// ignore sequence numbers (except at inIndex)
|
|
@@ -353,7 +361,7 @@ export class Transaction {
|
|
|
353
361
|
typeforce.arrayOf(types.Satoshi),
|
|
354
362
|
types.UInt32,
|
|
355
363
|
),
|
|
356
|
-
|
|
364
|
+
[inIndex, prevOutScripts, values, hashType],
|
|
357
365
|
);
|
|
358
366
|
|
|
359
367
|
if (values.length !== this.ins.length || prevOutScripts.length !== this.ins.length) {
|
|
@@ -490,7 +498,12 @@ export class Transaction {
|
|
|
490
498
|
value: number,
|
|
491
499
|
hashType: number,
|
|
492
500
|
): Buffer {
|
|
493
|
-
typeforce(types.tuple(types.UInt32, types.Buffer, types.Satoshi, types.UInt32),
|
|
501
|
+
typeforce(types.tuple(types.UInt32, types.Buffer, types.Satoshi, types.UInt32), [
|
|
502
|
+
inIndex,
|
|
503
|
+
prevOutScript,
|
|
504
|
+
value,
|
|
505
|
+
hashType,
|
|
506
|
+
]);
|
|
494
507
|
|
|
495
508
|
let tbuffer: Buffer = Buffer.from([]);
|
|
496
509
|
let bufferWriter: BufferWriter;
|
|
@@ -592,13 +605,13 @@ export class Transaction {
|
|
|
592
605
|
}
|
|
593
606
|
|
|
594
607
|
setInputScript(index: number, scriptSig: Buffer): void {
|
|
595
|
-
typeforce(types.tuple(types.Number, types.Buffer),
|
|
608
|
+
typeforce(types.tuple(types.Number, types.Buffer), [index, scriptSig]);
|
|
596
609
|
|
|
597
610
|
this.ins[index].script = scriptSig;
|
|
598
611
|
}
|
|
599
612
|
|
|
600
613
|
setWitness(index: number, witness: Buffer[]): void {
|
|
601
|
-
typeforce(types.tuple(types.Number, [types.Buffer]),
|
|
614
|
+
typeforce(types.tuple(types.Number, [types.Buffer]), [index, witness]);
|
|
602
615
|
|
|
603
616
|
this.ins[index].witness = witness;
|
|
604
617
|
}
|
|
@@ -631,11 +644,11 @@ export class Transaction {
|
|
|
631
644
|
});
|
|
632
645
|
|
|
633
646
|
bufferWriter.writeVarInt(this.outs.length);
|
|
634
|
-
this.outs.forEach((txOut) => {
|
|
647
|
+
(this.outs as (Output | BlankOutput)[]).forEach((txOut) => {
|
|
635
648
|
if (isOutput(txOut)) {
|
|
636
649
|
bufferWriter.writeUInt64(txOut.value);
|
|
637
650
|
} else {
|
|
638
|
-
bufferWriter.writeSlice(
|
|
651
|
+
bufferWriter.writeSlice(txOut.valueBuffer);
|
|
639
652
|
}
|
|
640
653
|
|
|
641
654
|
bufferWriter.writeVarSlice(txOut.script);
|
|
@@ -650,7 +663,7 @@ export class Transaction {
|
|
|
650
663
|
bufferWriter.writeUInt32(this.locktime);
|
|
651
664
|
|
|
652
665
|
// avoid slicing unless necessary
|
|
653
|
-
if (initialOffset !== undefined) return buffer.
|
|
666
|
+
if (initialOffset !== undefined) return buffer.subarray(initialOffset, bufferWriter.offset);
|
|
654
667
|
return buffer;
|
|
655
668
|
}
|
|
656
669
|
}
|
|
@@ -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/src/types.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Buffer as NBuffer } from 'buffer';
|
|
2
|
+
import typeforce from 'typeforce';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
import * as _typeforce from 'typeforce';
|
|
4
|
+
export { typeforce };
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Typeforce type validator - validates that a value matches a given type.
|
|
8
|
+
*/
|
|
9
|
+
export type TypeforceValidator = (value: unknown) => boolean;
|
|
7
10
|
|
|
8
11
|
const ZERO32 = NBuffer.alloc(32, 0);
|
|
9
12
|
const EC_P = NBuffer.from(
|
|
@@ -35,7 +38,7 @@ export function isPoint(p: Buffer | number | undefined | null): boolean {
|
|
|
35
38
|
if (p.length < 33) return false;
|
|
36
39
|
|
|
37
40
|
const t = p[0]; // First byte = point format indicator
|
|
38
|
-
const x = p.
|
|
41
|
+
const x = p.subarray(1, 33); // Next 32 bytes = X coordinate
|
|
39
42
|
|
|
40
43
|
// Validate X coordinate
|
|
41
44
|
if (x.compare(ZERO32) === 0) return false; // X cannot be zero
|
|
@@ -49,7 +52,7 @@ export function isPoint(p: Buffer | number | undefined | null): boolean {
|
|
|
49
52
|
// For uncompressed (0x04) or hybrid (0x06 or 0x07) formats, must be 65 bytes total
|
|
50
53
|
if (p.length !== 65) return false;
|
|
51
54
|
|
|
52
|
-
const y = p.
|
|
55
|
+
const y = p.subarray(33); // Last 32 bytes = Y coordinate
|
|
53
56
|
|
|
54
57
|
// Validate Y coordinate
|
|
55
58
|
if (y.compare(ZERO32) === 0) return false; // Y cannot be zero
|
|
@@ -77,10 +80,12 @@ export interface Tapleaf {
|
|
|
77
80
|
|
|
78
81
|
export const TAPLEAF_VERSION_MASK = 0xfe;
|
|
79
82
|
|
|
80
|
-
export function isTapleaf(o:
|
|
81
|
-
if (!o || !('output' in o)) return false;
|
|
82
|
-
|
|
83
|
-
if (
|
|
83
|
+
export function isTapleaf(o: unknown): o is Tapleaf {
|
|
84
|
+
if (!o || typeof o !== 'object' || !('output' in o)) return false;
|
|
85
|
+
const obj = o as Record<string, unknown>;
|
|
86
|
+
if (!NBuffer.isBuffer(obj.output)) return false;
|
|
87
|
+
if (obj.version !== undefined)
|
|
88
|
+
return ((obj.version as number) & TAPLEAF_VERSION_MASK) === obj.version;
|
|
84
89
|
return true;
|
|
85
90
|
}
|
|
86
91
|
|
|
@@ -91,10 +96,10 @@ export function isTapleaf(o: any): o is Tapleaf {
|
|
|
91
96
|
*/
|
|
92
97
|
export type Taptree = [Taptree | Tapleaf, Taptree | Tapleaf] | Tapleaf;
|
|
93
98
|
|
|
94
|
-
export function isTaptree(scriptTree:
|
|
95
|
-
if (!Array(scriptTree)) return isTapleaf(scriptTree);
|
|
99
|
+
export function isTaptree(scriptTree: unknown): scriptTree is Taptree {
|
|
100
|
+
if (!globalThis.Array.isArray(scriptTree)) return isTapleaf(scriptTree);
|
|
96
101
|
if (scriptTree.length !== 2) return false;
|
|
97
|
-
return scriptTree.every((t:
|
|
102
|
+
return scriptTree.every((t: unknown) => isTaptree(t));
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
export interface TinySecp256k1Interface {
|
|
@@ -103,20 +108,20 @@ export interface TinySecp256k1Interface {
|
|
|
103
108
|
xOnlyPointAddTweak(p: Uint8Array, tweak: Uint8Array): XOnlyPointAddTweakResult | null;
|
|
104
109
|
}
|
|
105
110
|
|
|
106
|
-
export const Buffer256bit = typeforce.BufferN(32);
|
|
107
|
-
export const Hash160bit = typeforce.BufferN(20);
|
|
108
|
-
export const Hash256bit = typeforce.BufferN(32);
|
|
109
|
-
export const Number = typeforce.Number;
|
|
110
|
-
export const Array = typeforce.Array;
|
|
111
|
-
export const Boolean = typeforce.Boolean;
|
|
112
|
-
export const String = typeforce.String;
|
|
113
|
-
export const Buffer = typeforce.Buffer;
|
|
114
|
-
export const Hex = typeforce.Hex;
|
|
115
|
-
export const maybe = typeforce.maybe;
|
|
116
|
-
export const tuple = typeforce.tuple;
|
|
117
|
-
export const UInt8 = typeforce.UInt8;
|
|
118
|
-
export const UInt32 = typeforce.UInt32;
|
|
119
|
-
export const Function = typeforce.Function;
|
|
120
|
-
export const BufferN = typeforce.BufferN;
|
|
121
|
-
export const Null = typeforce.Null;
|
|
122
|
-
export const oneOf = typeforce.oneOf;
|
|
111
|
+
export const Buffer256bit: TypeforceValidator = typeforce.BufferN(32);
|
|
112
|
+
export const Hash160bit: TypeforceValidator = typeforce.BufferN(20);
|
|
113
|
+
export const Hash256bit: TypeforceValidator = typeforce.BufferN(32);
|
|
114
|
+
export const Number: TypeforceValidator = typeforce.Number;
|
|
115
|
+
export const Array: TypeforceValidator = typeforce.Array;
|
|
116
|
+
export const Boolean: TypeforceValidator = typeforce.Boolean;
|
|
117
|
+
export const String: TypeforceValidator = typeforce.String;
|
|
118
|
+
export const Buffer: TypeforceValidator = typeforce.Buffer;
|
|
119
|
+
export const Hex: TypeforceValidator = typeforce.Hex;
|
|
120
|
+
export const maybe: (type: unknown) => TypeforceValidator = typeforce.maybe;
|
|
121
|
+
export const tuple: (...types: unknown[]) => TypeforceValidator = typeforce.tuple;
|
|
122
|
+
export const UInt8: TypeforceValidator = typeforce.UInt8;
|
|
123
|
+
export const UInt32: TypeforceValidator = typeforce.UInt32;
|
|
124
|
+
export const Function: TypeforceValidator = typeforce.Function;
|
|
125
|
+
export const BufferN: (n: number) => TypeforceValidator = typeforce.BufferN;
|
|
126
|
+
export const Null: TypeforceValidator = typeforce.Null;
|
|
127
|
+
export const oneOf: (...types: unknown[]) => TypeforceValidator = typeforce.oneOf;
|
package/test/address.spec.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
|
-
import { describe, it } from '
|
|
2
|
+
import { describe, it } from 'vitest';
|
|
3
3
|
import * as ecc from 'tiny-secp256k1';
|
|
4
4
|
import * as baddress from '../src/address.js';
|
|
5
5
|
import * as bscript from '../src/script.js';
|
|
6
6
|
import fixtures from './fixtures/address.json' with { type: 'json' };
|
|
7
7
|
|
|
8
|
-
import { initEccLib
|
|
9
|
-
|
|
8
|
+
import { initEccLib } from '../src/index.js';
|
|
10
9
|
import * as networks from '../src/networks.js';
|
|
10
|
+
import type { Network } from '../src/networks.js';
|
|
11
11
|
|
|
12
12
|
const NETWORKS: Record<string, Network> = Object.assign(
|
|
13
13
|
{
|
|
@@ -20,6 +20,8 @@ const NETWORKS: Record<string, Network> = Object.assign(
|
|
|
20
20
|
pubKeyHash: 0x30,
|
|
21
21
|
scriptHash: 0x32,
|
|
22
22
|
wif: 0xb0,
|
|
23
|
+
bech32: 'ltc',
|
|
24
|
+
bech32Opnet: 'opl',
|
|
23
25
|
},
|
|
24
26
|
},
|
|
25
27
|
networks,
|
|
@@ -58,7 +60,13 @@ describe('address', () => {
|
|
|
58
60
|
const actual = baddress.fromBech32(f.bech32);
|
|
59
61
|
|
|
60
62
|
assert.strictEqual(actual.version, f.version);
|
|
61
|
-
|
|
63
|
+
// Support both bech32 and bech32Opnet prefixes
|
|
64
|
+
const network = NETWORKS[f.network];
|
|
65
|
+
const validPrefixes = [network.bech32, network.bech32Opnet].filter(Boolean);
|
|
66
|
+
assert.ok(
|
|
67
|
+
validPrefixes.includes(actual.prefix),
|
|
68
|
+
`Expected prefix to be one of [${validPrefixes.join(', ')}], got ${actual.prefix}`,
|
|
69
|
+
);
|
|
62
70
|
assert.strictEqual(actual.data.toString('hex'), f.data);
|
|
63
71
|
});
|
|
64
72
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
2
|
import base58 from 'bs58';
|
|
3
|
-
import { describe, it } from '
|
|
3
|
+
import { describe, it } from 'vitest';
|
|
4
4
|
import * as bitcoin from '../src/index.js';
|
|
5
5
|
import base58EncodeDecode from './fixtures/core/base58_encode_decode.json' with { type: 'json' };
|
|
6
6
|
import base58KeysInvalid from './fixtures/core/base58_keys_invalid.json' with { type: 'json' };
|
package/test/block.spec.ts
CHANGED
package/test/bufferutils.spec.ts
CHANGED
package/test/crypto.spec.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
|
-
import { describe, it } from '
|
|
3
|
-
import { crypto as bcrypto
|
|
2
|
+
import { describe, it } from 'vitest';
|
|
3
|
+
import { crypto as bcrypto } from '../src/index.js';
|
|
4
|
+
import type { TaggedHashPrefix } from '../src/crypto.js';
|
|
4
5
|
import fixtures from './fixtures/crypto.json' with { type: 'json' };
|
|
5
6
|
import { sha256, TAGGED_HASH_PREFIXES, TAGS } from '../src/crypto.js';
|
|
6
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
2
|
import { ECPairFactory } from 'ecpair';
|
|
3
3
|
import * as ecc from 'tiny-secp256k1';
|
|
4
|
-
import { describe, it } from '
|
|
4
|
+
import { describe, it } from 'vitest';
|
|
5
5
|
import * as bitcoin from '../../src/index.js';
|
|
6
6
|
import { regtestUtils } from './_regtest.js';
|
|
7
7
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
|
-
import { BIP32Factory } from 'bip32';
|
|
2
|
+
import { BIP32Factory } from '@btc-vision/bip32';
|
|
3
3
|
import * as ecc from 'tiny-secp256k1';
|
|
4
4
|
import * as bip39 from 'bip39';
|
|
5
|
-
import { describe, it } from '
|
|
5
|
+
import { describe, it } from 'vitest';
|
|
6
6
|
import * as bitcoin from '../../src/index.js';
|
|
7
7
|
|
|
8
8
|
const bip32 = BIP32Factory(ecc);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
2
|
import { ECPairFactory } from 'ecpair';
|
|
3
3
|
import * as ecc from 'tiny-secp256k1';
|
|
4
|
-
import {
|
|
4
|
+
import { beforeAll, describe, it } from 'vitest';
|
|
5
5
|
import * as bitcoin from '../../src/index.js';
|
|
6
6
|
import { regtestUtils } from './_regtest.js';
|
|
7
7
|
|
|
@@ -24,7 +24,7 @@ const bob = ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x
|
|
|
24
24
|
|
|
25
25
|
describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
|
|
26
26
|
// force update MTP
|
|
27
|
-
|
|
27
|
+
beforeAll(async () => {
|
|
28
28
|
await regtestUtils.mine(11);
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -231,7 +231,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
|
|
|
231
231
|
}).input;
|
|
232
232
|
tx.setInputScript(0, redeemScriptSig!);
|
|
233
233
|
|
|
234
|
-
await regtestUtils.broadcast(tx.toHex()).catch((err) => {
|
|
234
|
+
await regtestUtils.broadcast(tx.toHex()).catch((err: unknown) => {
|
|
235
235
|
assert.throws(() => {
|
|
236
236
|
if (err) throw err;
|
|
237
237
|
}, /Error: non-final/);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
|
-
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
3
2
|
import { ECPairFactory } from 'ecpair';
|
|
4
3
|
import * as ecc from 'tiny-secp256k1';
|
|
5
|
-
import {
|
|
4
|
+
import { beforeAll, describe, it } from 'vitest';
|
|
6
5
|
import * as bitcoin from '../../src/index.js';
|
|
6
|
+
import type { PsbtInput } from '../../src/index.js';
|
|
7
7
|
import { regtestUtils } from './_regtest.js';
|
|
8
8
|
|
|
9
9
|
// @ts-ignore
|
|
@@ -28,7 +28,7 @@ const dave = ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsMwS4pqn
|
|
|
28
28
|
|
|
29
29
|
describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
30
30
|
// force update MTP
|
|
31
|
-
|
|
31
|
+
beforeAll(async () => {
|
|
32
32
|
await regtestUtils.mine(11);
|
|
33
33
|
});
|
|
34
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ECPairFactory } from 'ecpair';
|
|
2
2
|
import * as ecc from 'tiny-secp256k1';
|
|
3
|
-
import { describe, it } from '
|
|
3
|
+
import { describe, it } from 'vitest';
|
|
4
4
|
import * as bitcoin from '../../src/index.js';
|
|
5
5
|
import { regtestUtils } from './_regtest.js';
|
|
6
6
|
import * as fs from 'node:fs';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
|
-
import { BIP32Factory } from 'bip32';
|
|
2
|
+
import { BIP32Factory } from '@btc-vision/bip32';
|
|
3
3
|
import * as bip39 from 'bip39';
|
|
4
4
|
import * as ecc from 'tiny-secp256k1';
|
|
5
|
-
import { describe, it } from '
|
|
6
|
-
import { PsbtInput, TapLeaf, TapLeafScript } from 'bip174/src/lib/interfaces.js';
|
|
5
|
+
import { describe, it } from 'vitest';
|
|
7
6
|
import { regtestUtils } from './_regtest.js';
|
|
8
7
|
import * as bitcoin from '../../src/index.js';
|
|
9
|
-
import { Taptree } from '../../src/
|
|
8
|
+
import type { PsbtInput, TapLeaf, TapLeafScript, Taptree } from '../../src/index.js';
|
|
10
9
|
import { LEAF_VERSION_TAPSCRIPT } from '../../src/payments/bip341.js';
|
|
11
10
|
import { tapTreeFromList, tapTreeToList, toXOnly } from '../../src/psbt/bip371.js';
|
|
12
11
|
import { witnessStackToScriptWitness } from '../../src/psbt/psbtutils.js';
|
|
@@ -652,9 +651,11 @@ function buildLeafIndexFinalizer(
|
|
|
652
651
|
} => {
|
|
653
652
|
try {
|
|
654
653
|
const scriptSolution = [Buffer.from([leafIndex]), Buffer.from([leafIndex])];
|
|
655
|
-
const witness =
|
|
656
|
-
|
|
657
|
-
|
|
654
|
+
const witness: Buffer[] = [
|
|
655
|
+
...scriptSolution,
|
|
656
|
+
tapLeafScript.script,
|
|
657
|
+
tapLeafScript.controlBlock,
|
|
658
|
+
];
|
|
658
659
|
return { finalScriptWitness: witnessStackToScriptWitness(witness) };
|
|
659
660
|
} catch (err) {
|
|
660
661
|
throw new Error(`Can not finalize taproot input #${inputIndex}: ${err}`);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
|
-
import { BIP32Factory } from 'bip32';
|
|
2
|
+
import { BIP32Factory } from '@btc-vision/bip32';
|
|
3
3
|
import * as ecc from 'tiny-secp256k1';
|
|
4
4
|
import { ECPairFactory } from 'ecpair';
|
|
5
|
-
import { describe, it } from '
|
|
5
|
+
import { describe, it } from 'vitest';
|
|
6
6
|
import * as bitcoin from '../../src/index.js';
|
|
7
7
|
import { regtestUtils } from './_regtest.js';
|
|
8
8
|
|
package/test/payments.spec.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
2
|
import * as ecc from 'tiny-secp256k1';
|
|
3
|
-
import { describe, it } from '
|
|
4
|
-
import { initEccLib
|
|
3
|
+
import { beforeEach, describe, it } from 'vitest';
|
|
4
|
+
import { initEccLib } from '../src/index.js';
|
|
5
|
+
import type { PaymentCreator, P2SHPayment } from '../src/payments/index.js';
|
|
5
6
|
import * as u from './payments.utils.js';
|
|
6
7
|
import fs from 'node:fs';
|
|
7
|
-
import { p2pk,
|
|
8
|
+
import { p2pk, p2wsh } from '../src/payments/index.js';
|
|
8
9
|
|
|
9
10
|
const require = async (name: string) => {
|
|
10
11
|
const mod = await import(name);
|