@btc-vision/bitcoin 7.0.0-beta.0 → 7.0.0-beta.1
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/README.md +112 -13
- package/benchmark-compare/BENCHMARK.md +74 -59
- package/benchmark-compare/compare.bench.ts +249 -96
- package/benchmark-compare/harness.ts +23 -25
- package/benchmark-compare/package.json +1 -0
- package/browser/address.d.ts +4 -4
- package/browser/address.d.ts.map +1 -1
- package/browser/chunks/{psbt-parallel-B-dfm5GZ.js → psbt-parallel-jZ6QcCnM.js} +3128 -2731
- package/browser/index.d.ts +1 -1
- package/browser/index.d.ts.map +1 -1
- package/browser/index.js +603 -585
- package/browser/io/base58check.d.ts +1 -25
- package/browser/io/base58check.d.ts.map +1 -1
- package/browser/io/base64.d.ts.map +1 -1
- package/browser/networks.d.ts +1 -0
- package/browser/networks.d.ts.map +1 -1
- package/browser/payments/bip341.d.ts +17 -0
- package/browser/payments/bip341.d.ts.map +1 -1
- package/browser/payments/index.d.ts +3 -2
- package/browser/payments/index.d.ts.map +1 -1
- package/browser/payments/p2mr.d.ts +169 -0
- package/browser/payments/p2mr.d.ts.map +1 -0
- package/browser/payments/types.d.ts +11 -1
- package/browser/payments/types.d.ts.map +1 -1
- package/browser/psbt/bip371.d.ts +30 -0
- package/browser/psbt/bip371.d.ts.map +1 -1
- package/browser/psbt/psbtutils.d.ts +1 -0
- package/browser/psbt/psbtutils.d.ts.map +1 -1
- package/browser/psbt.d.ts.map +1 -1
- package/browser/workers/index.js +9 -9
- package/build/address.d.ts +4 -4
- package/build/address.d.ts.map +1 -1
- package/build/address.js +11 -1
- package/build/address.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/build/io/base58check.d.ts +1 -25
- package/build/io/base58check.d.ts.map +1 -1
- package/build/io/base58check.js +1 -31
- package/build/io/base58check.js.map +1 -1
- package/build/io/base64.d.ts.map +1 -1
- package/build/io/base64.js +3 -0
- package/build/io/base64.js.map +1 -1
- package/build/networks.d.ts +1 -0
- package/build/networks.d.ts.map +1 -1
- package/build/networks.js +12 -0
- package/build/networks.js.map +1 -1
- package/build/payments/bip341.d.ts +17 -0
- package/build/payments/bip341.d.ts.map +1 -1
- package/build/payments/bip341.js +32 -1
- package/build/payments/bip341.js.map +1 -1
- package/build/payments/index.d.ts +3 -2
- package/build/payments/index.d.ts.map +1 -1
- package/build/payments/index.js +2 -1
- package/build/payments/index.js.map +1 -1
- package/build/payments/p2mr.d.ts +178 -0
- package/build/payments/p2mr.d.ts.map +1 -0
- package/build/payments/p2mr.js +555 -0
- package/build/payments/p2mr.js.map +1 -0
- package/build/payments/types.d.ts +11 -1
- package/build/payments/types.d.ts.map +1 -1
- package/build/payments/types.js +1 -0
- package/build/payments/types.js.map +1 -1
- package/build/psbt/bip371.d.ts +30 -0
- package/build/psbt/bip371.d.ts.map +1 -1
- package/build/psbt/bip371.js +80 -15
- package/build/psbt/bip371.js.map +1 -1
- package/build/psbt/psbtutils.d.ts +1 -0
- package/build/psbt/psbtutils.d.ts.map +1 -1
- package/build/psbt/psbtutils.js +2 -0
- package/build/psbt/psbtutils.js.map +1 -1
- package/build/psbt.d.ts.map +1 -1
- package/build/psbt.js +3 -2
- package/build/psbt.js.map +1 -1
- package/build/pubkey.js +1 -1
- package/build/pubkey.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/documentation/README.md +122 -0
- package/documentation/address.md +820 -0
- package/documentation/block.md +679 -0
- package/documentation/crypto.md +461 -0
- package/documentation/ecc.md +584 -0
- package/documentation/errors.md +656 -0
- package/documentation/io.md +942 -0
- package/documentation/networks.md +625 -0
- package/documentation/p2mr.md +380 -0
- package/documentation/payments.md +1485 -0
- package/documentation/psbt.md +1400 -0
- package/documentation/script.md +730 -0
- package/documentation/taproot.md +670 -0
- package/documentation/transaction.md +943 -0
- package/documentation/types.md +587 -0
- package/documentation/workers.md +1007 -0
- package/eslint.config.js +3 -0
- package/package.json +17 -14
- package/src/address.ts +22 -10
- package/src/index.ts +1 -0
- package/src/io/base58check.ts +1 -35
- package/src/io/base64.ts +5 -0
- package/src/networks.ts +13 -0
- package/src/payments/bip341.ts +36 -1
- package/src/payments/index.ts +4 -0
- package/src/payments/p2mr.ts +660 -0
- package/src/payments/types.ts +12 -0
- package/src/psbt/bip371.ts +84 -13
- package/src/psbt/psbtutils.ts +2 -0
- package/src/psbt.ts +4 -2
- package/src/pubkey.ts +1 -1
- package/test/bitcoin.core.spec.ts +1 -1
- package/test/fixtures/p2mr.json +270 -0
- package/test/integration/taproot.spec.ts +7 -3
- package/test/opnetTestnet.spec.ts +302 -0
- package/test/payments.spec.ts +3 -1
- package/test/psbt.spec.ts +297 -2
- package/test/tsconfig.json +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared benchmark infrastructure for comparison benchmarks.
|
|
3
|
-
*
|
|
4
3
|
* Provides consistent measurement (warmup + iterations), statistics,
|
|
5
4
|
* and ASCII table formatting.
|
|
6
5
|
*/
|
|
7
6
|
|
|
7
|
+
/** Statistical results from a single benchmark measurement. */
|
|
8
8
|
export interface BenchResult {
|
|
9
9
|
name: string;
|
|
10
10
|
mean: number;
|
|
@@ -16,6 +16,7 @@ export interface BenchResult {
|
|
|
16
16
|
samples: number;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/** Options for controlling warmup and iteration counts. */
|
|
19
20
|
export interface MeasureOpts {
|
|
20
21
|
warmup?: number;
|
|
21
22
|
iterations?: number;
|
|
@@ -24,9 +25,7 @@ export interface MeasureOpts {
|
|
|
24
25
|
const DEFAULT_WARMUP = 5;
|
|
25
26
|
const DEFAULT_ITERATIONS = 50;
|
|
26
27
|
|
|
27
|
-
/**
|
|
28
|
-
* Force GC if --expose-gc is available.
|
|
29
|
-
*/
|
|
28
|
+
/** Forces garbage collection if `--expose-gc` is available. */
|
|
30
29
|
function tryGC(): void {
|
|
31
30
|
if (typeof globalThis.gc === 'function') {
|
|
32
31
|
globalThis.gc();
|
|
@@ -34,7 +33,10 @@ function tryGC(): void {
|
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
/**
|
|
37
|
-
*
|
|
36
|
+
* Runs a function with warmup + measurement iterations and returns statistical results.
|
|
37
|
+
* @param name - Display name for the benchmark.
|
|
38
|
+
* @param fn - The function to benchmark (sync or async).
|
|
39
|
+
* @param opts - Optional warmup and iteration overrides.
|
|
38
40
|
*/
|
|
39
41
|
export async function measure(
|
|
40
42
|
name: string,
|
|
@@ -44,14 +46,12 @@ export async function measure(
|
|
|
44
46
|
const warmup = opts.warmup ?? DEFAULT_WARMUP;
|
|
45
47
|
const iterations = opts.iterations ?? DEFAULT_ITERATIONS;
|
|
46
48
|
|
|
47
|
-
// Warmup
|
|
48
49
|
for (let i = 0; i < warmup; i++) {
|
|
49
50
|
await fn();
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
tryGC();
|
|
53
54
|
|
|
54
|
-
// Measure
|
|
55
55
|
const times: number[] = [];
|
|
56
56
|
for (let i = 0; i < iterations; i++) {
|
|
57
57
|
const t0 = performance.now();
|
|
@@ -74,7 +74,7 @@ export async function measure(
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Measures a synchronous function. Convenience wrapper around {@link measure}.
|
|
78
78
|
*/
|
|
79
79
|
export async function measureSync(
|
|
80
80
|
name: string,
|
|
@@ -84,9 +84,7 @@ export async function measureSync(
|
|
|
84
84
|
return measure(name, fn, opts);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
/**
|
|
88
|
-
* Format milliseconds nicely.
|
|
89
|
-
*/
|
|
87
|
+
/** Formats milliseconds into a human-readable string (ns/us/ms/s). */
|
|
90
88
|
export function fmt(ms: number): string {
|
|
91
89
|
if (ms < 0.001) return `${(ms * 1_000_000).toFixed(0)}ns`;
|
|
92
90
|
if (ms < 1) return `${(ms * 1000).toFixed(0)}us`;
|
|
@@ -94,41 +92,43 @@ export function fmt(ms: number): string {
|
|
|
94
92
|
return `${(ms / 1000).toFixed(2)}s`;
|
|
95
93
|
}
|
|
96
94
|
|
|
95
|
+
/** A row in the comparison table with results from all libraries. */
|
|
97
96
|
export interface ComparisonRow {
|
|
98
97
|
scenario: string;
|
|
99
98
|
detail: string;
|
|
100
99
|
fork: BenchResult | null;
|
|
101
100
|
forkNoble: BenchResult | null;
|
|
101
|
+
scure: BenchResult | null;
|
|
102
102
|
official: BenchResult | null;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
/**
|
|
106
|
-
* Print an aligned ASCII comparison table.
|
|
107
|
-
*/
|
|
105
|
+
/** Prints an aligned ASCII comparison table to stdout. */
|
|
108
106
|
export function printComparison(title: string, rows: ComparisonRow[]): void {
|
|
107
|
+
const W = 130;
|
|
109
108
|
console.log();
|
|
110
|
-
console.log('='.repeat(
|
|
109
|
+
console.log('='.repeat(W));
|
|
111
110
|
console.log(` ${title}`);
|
|
112
|
-
console.log('='.repeat(
|
|
111
|
+
console.log('='.repeat(W));
|
|
113
112
|
|
|
114
113
|
const header = [
|
|
115
114
|
pad('Scenario', 28),
|
|
116
115
|
pad('Detail', 12),
|
|
117
116
|
pad('Fork (Noble)', 14),
|
|
118
117
|
pad('Fork (tiny)', 14),
|
|
118
|
+
pad('Scure', 14),
|
|
119
119
|
pad('Official', 14),
|
|
120
120
|
pad('Improvement', 14),
|
|
121
121
|
].join(' | ');
|
|
122
122
|
|
|
123
123
|
console.log(header);
|
|
124
|
-
console.log('-'.repeat(
|
|
124
|
+
console.log('-'.repeat(W));
|
|
125
125
|
|
|
126
126
|
for (const row of rows) {
|
|
127
127
|
const forkNobleMs = row.forkNoble ? fmt(row.forkNoble.median) : '-';
|
|
128
128
|
const forkMs = row.fork ? fmt(row.fork.median) : '-';
|
|
129
|
+
const scureMs = row.scure ? fmt(row.scure.median) : '-';
|
|
129
130
|
const officialMs = row.official ? fmt(row.official.median) : '-';
|
|
130
131
|
|
|
131
|
-
// Calculate improvement: official vs best fork (smallest median wins)
|
|
132
132
|
let improvement = '-';
|
|
133
133
|
const candidates = [row.forkNoble, row.fork].filter(Boolean) as BenchResult[];
|
|
134
134
|
const bestFork = candidates.length > 0
|
|
@@ -150,6 +150,7 @@ export function printComparison(title: string, rows: ComparisonRow[]): void {
|
|
|
150
150
|
pad(row.detail, 12),
|
|
151
151
|
pad(forkNobleMs, 14),
|
|
152
152
|
pad(forkMs, 14),
|
|
153
|
+
pad(scureMs, 14),
|
|
153
154
|
pad(officialMs, 14),
|
|
154
155
|
pad(improvement, 14),
|
|
155
156
|
].join(' | ');
|
|
@@ -157,7 +158,7 @@ export function printComparison(title: string, rows: ComparisonRow[]): void {
|
|
|
157
158
|
console.log(line);
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
console.log('='.repeat(
|
|
161
|
+
console.log('='.repeat(W));
|
|
161
162
|
console.log();
|
|
162
163
|
}
|
|
163
164
|
|
|
@@ -165,9 +166,7 @@ function pad(s: string, n: number): string {
|
|
|
165
166
|
return s.length >= n ? s.slice(0, n) : s + ' '.repeat(n - s.length);
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
/**
|
|
169
|
-
* Print a simple results table for fork-only scenarios (e.g., parallel signing).
|
|
170
|
-
*/
|
|
169
|
+
/** Prints a simple results table for fork-only scenarios (e.g., parallel signing). */
|
|
171
170
|
export function printForkOnly(title: string, rows: { scenario: string; detail: string; result: BenchResult }[]): void {
|
|
172
171
|
console.log();
|
|
173
172
|
console.log('='.repeat(80));
|
|
@@ -198,9 +197,7 @@ export function printForkOnly(title: string, rows: { scenario: string; detail: s
|
|
|
198
197
|
console.log();
|
|
199
198
|
}
|
|
200
199
|
|
|
201
|
-
/**
|
|
202
|
-
* Summary JSON record for machine-readable output.
|
|
203
|
-
*/
|
|
200
|
+
/** Machine-readable JSON summary of all benchmark results. */
|
|
204
201
|
export interface BenchSummary {
|
|
205
202
|
timestamp: string;
|
|
206
203
|
node: string;
|
|
@@ -209,6 +206,7 @@ export interface BenchSummary {
|
|
|
209
206
|
scenarios: Record<string, BenchResult>;
|
|
210
207
|
}
|
|
211
208
|
|
|
209
|
+
/** Builds a {@link BenchSummary} from collected results. */
|
|
212
210
|
export function buildSummary(results: Record<string, BenchResult>): BenchSummary {
|
|
213
211
|
return {
|
|
214
212
|
timestamp: new Date().toISOString(),
|
package/browser/address.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Bech32Result, fromBech32 } from './bech32utils.js';
|
|
2
2
|
import { Network } from './networks.js';
|
|
3
|
-
import { Bytes20 } from './types.js';
|
|
3
|
+
import { Bytes20, Script } from './types.js';
|
|
4
4
|
export { fromBech32, type Bech32Result };
|
|
5
5
|
/** base58check decode result */
|
|
6
6
|
export interface Base58CheckResult {
|
|
@@ -46,7 +46,7 @@ export declare function toBech32(data: Uint8Array, version: number, prefix: stri
|
|
|
46
46
|
* P2WPKH, P2WSH, P2TR) to avoid constructing payment objects and catching
|
|
47
47
|
* exceptions. Falls back to payment constructors for exotic types.
|
|
48
48
|
*/
|
|
49
|
-
export declare function fromOutputScript(output: Uint8Array, network?: Network): string;
|
|
49
|
+
export declare function fromOutputScript(output: Uint8Array | Script, network?: Network): string;
|
|
50
50
|
/**
|
|
51
51
|
* Options for toOutputScript function.
|
|
52
52
|
*/
|
|
@@ -67,7 +67,7 @@ export interface ToOutputScriptOptions {
|
|
|
67
67
|
* Encodes address to output script with network, return output script if address matched.
|
|
68
68
|
* @param address - The address to encode
|
|
69
69
|
* @param networkOrOptions - Network or options object
|
|
70
|
-
* @returns The output script
|
|
70
|
+
* @returns The output script
|
|
71
71
|
*/
|
|
72
|
-
export declare function toOutputScript(address: string, networkOrOptions?: Network | ToOutputScriptOptions):
|
|
72
|
+
export declare function toOutputScript(address: string, networkOrOptions?: Network | ToOutputScriptOptions): Script;
|
|
73
73
|
//# sourceMappingURL=address.d.ts.map
|
package/browser/address.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAW7C,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,MAAM,EAMd,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,CAAC;AAEzC,gCAAgC;AAChC,MAAM,WAAW,iBAAiB;IAC9B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,sBAAsB,EAAE,MAAW,CAAC;AACjD,eAAO,MAAM,sBAAsB,EAAE,MAAU,CAAC;AAChD,eAAO,MAAM,yBAAyB,EAAE,MAAW,CAAC;AACpD,eAAO,MAAM,kBAAkB,EAAE,MAAW,CAAC;AAC7C,eAAO,MAAM,oBAAoB,EAAE,MAAW,CAAC;AAC/C,eAAO,MAAM,yBAAyB,EAAE,MAAU,CAAC;AACnD,eAAO,MAAM,0BAA0B,EAAE,MAAa,CAAC;AAOvD,eAAO,MAAM,sBAAsB,GAAI,QAAQ,UAAU,KAAG,OAoB3D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAuCjF;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAkBnF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAWlE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CASpE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACpB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,GACrB,MAAM,CASR;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAsDvF;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,OAAO,GAAG,qBAAqB,GACnD,MAAM,CA0ER"}
|