@btc-vision/bitcoin 7.0.0-alpha.0 → 7.0.0-alpha.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/browser/address.d.ts +1 -1
- package/browser/address.d.ts.map +1 -1
- package/browser/block.d.ts.map +1 -1
- package/browser/crypto.d.ts +1 -1
- package/browser/ecc/context.d.ts +4 -4
- package/browser/ecc/context.d.ts.map +1 -1
- package/browser/ecc/types.d.ts +1 -1
- package/browser/ecc/types.d.ts.map +1 -1
- package/browser/index.d.ts +1 -1
- package/browser/index.d.ts.map +1 -1
- package/browser/index.js +648 -653
- package/browser/io/BinaryReader.d.ts +15 -15
- package/browser/io/BinaryReader.d.ts.map +1 -1
- package/browser/io/BinaryWriter.d.ts +17 -17
- package/browser/io/BinaryWriter.d.ts.map +1 -1
- package/browser/io/MemoryPool.d.ts +20 -20
- package/browser/io/MemoryPool.d.ts.map +1 -1
- package/browser/payments/bip341.d.ts +1 -1
- package/browser/payments/bip341.d.ts.map +1 -1
- package/browser/payments/embed.d.ts +1 -1
- package/browser/payments/embed.d.ts.map +1 -1
- package/browser/payments/p2ms.d.ts.map +1 -1
- package/browser/payments/p2op.d.ts +1 -1
- package/browser/payments/p2op.d.ts.map +1 -1
- package/browser/payments/p2pk.d.ts +1 -1
- package/browser/payments/p2pk.d.ts.map +1 -1
- package/browser/payments/p2pkh.d.ts +1 -1
- package/browser/payments/p2pkh.d.ts.map +1 -1
- package/browser/payments/p2sh.d.ts.map +1 -1
- package/browser/payments/p2tr.d.ts +2 -2
- package/browser/payments/p2tr.d.ts.map +1 -1
- package/browser/payments/p2wpkh.d.ts +1 -1
- package/browser/payments/p2wpkh.d.ts.map +1 -1
- package/browser/payments/p2wsh.d.ts.map +1 -1
- package/browser/payments/types.d.ts +1 -1
- package/browser/payments/types.d.ts.map +1 -1
- package/browser/psbt/bip371.d.ts.map +1 -1
- package/browser/psbt/types.d.ts +2 -2
- package/browser/psbt/types.d.ts.map +1 -1
- package/browser/psbt/validation.d.ts.map +1 -1
- package/browser/psbt.d.ts +1 -1
- package/browser/psbt.d.ts.map +1 -1
- package/browser/script.d.ts.map +1 -1
- package/browser/transaction.d.ts.map +1 -1
- package/browser/types.d.ts +1 -1
- package/browser/types.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.d.ts +17 -17
- package/browser/workers/WorkerSigningPool.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.node.d.ts +12 -12
- package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/browser/workers/psbt-parallel.d.ts +1 -1
- package/browser/workers/psbt-parallel.d.ts.map +1 -1
- package/browser/workers/types.d.ts.map +1 -1
- package/build/address.d.ts +1 -1
- package/build/address.d.ts.map +1 -1
- package/build/address.js +3 -2
- package/build/address.js.map +1 -1
- package/build/block.d.ts.map +1 -1
- package/build/block.js +2 -4
- package/build/block.js.map +1 -1
- package/build/crypto.d.ts +1 -1
- package/build/ecc/context.d.ts +4 -4
- package/build/ecc/context.d.ts.map +1 -1
- package/build/ecc/context.js +7 -7
- package/build/ecc/context.js.map +1 -1
- package/build/ecc/types.d.ts +1 -1
- package/build/ecc/types.d.ts.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/io/BinaryReader.d.ts +15 -15
- package/build/io/BinaryReader.d.ts.map +1 -1
- package/build/io/BinaryReader.js +17 -17
- package/build/io/BinaryReader.js.map +1 -1
- package/build/io/BinaryWriter.d.ts +17 -17
- package/build/io/BinaryWriter.d.ts.map +1 -1
- package/build/io/BinaryWriter.js +39 -39
- package/build/io/BinaryWriter.js.map +1 -1
- package/build/io/MemoryPool.d.ts +20 -20
- package/build/io/MemoryPool.d.ts.map +1 -1
- package/build/io/MemoryPool.js +28 -28
- package/build/io/MemoryPool.js.map +1 -1
- package/build/payments/bip341.d.ts +1 -2
- package/build/payments/bip341.d.ts.map +1 -1
- package/build/payments/bip341.js +1 -2
- package/build/payments/bip341.js.map +1 -1
- package/build/payments/embed.d.ts +1 -1
- package/build/payments/embed.d.ts.map +1 -1
- package/build/payments/embed.js +14 -14
- package/build/payments/embed.js.map +1 -1
- package/build/payments/p2ms.d.ts.map +1 -1
- package/build/payments/p2ms.js +21 -21
- package/build/payments/p2ms.js.map +1 -1
- package/build/payments/p2op.d.ts +1 -1
- package/build/payments/p2op.d.ts.map +1 -1
- package/build/payments/p2op.js +18 -18
- package/build/payments/p2op.js.map +1 -1
- package/build/payments/p2pk.d.ts +1 -1
- package/build/payments/p2pk.d.ts.map +1 -1
- package/build/payments/p2pk.js +17 -17
- package/build/payments/p2pk.js.map +1 -1
- package/build/payments/p2pkh.d.ts +1 -1
- package/build/payments/p2pkh.d.ts.map +1 -1
- package/build/payments/p2pkh.js +20 -20
- package/build/payments/p2pkh.js.map +1 -1
- package/build/payments/p2sh.d.ts.map +1 -1
- package/build/payments/p2sh.js +22 -20
- package/build/payments/p2sh.js.map +1 -1
- package/build/payments/p2tr.d.ts +2 -2
- package/build/payments/p2tr.d.ts.map +1 -1
- package/build/payments/p2tr.js +23 -23
- package/build/payments/p2tr.js.map +1 -1
- package/build/payments/p2wpkh.d.ts +1 -1
- package/build/payments/p2wpkh.d.ts.map +1 -1
- package/build/payments/p2wpkh.js +20 -20
- package/build/payments/p2wpkh.js.map +1 -1
- package/build/payments/p2wsh.d.ts.map +1 -1
- package/build/payments/p2wsh.js +22 -22
- package/build/payments/p2wsh.js.map +1 -1
- package/build/payments/types.d.ts +1 -1
- package/build/payments/types.d.ts.map +1 -1
- package/build/psbt/bip371.d.ts.map +1 -1
- package/build/psbt/bip371.js +6 -2
- package/build/psbt/bip371.js.map +1 -1
- package/build/psbt/psbtutils.js +1 -1
- package/build/psbt/psbtutils.js.map +1 -1
- package/build/psbt/types.d.ts +2 -2
- package/build/psbt/types.d.ts.map +1 -1
- package/build/psbt/validation.d.ts.map +1 -1
- package/build/psbt/validation.js +1 -1
- package/build/psbt/validation.js.map +1 -1
- package/build/psbt.d.ts +1 -1
- package/build/psbt.d.ts.map +1 -1
- package/build/psbt.js +6 -12
- package/build/psbt.js.map +1 -1
- package/build/script.d.ts.map +1 -1
- package/build/script.js +2 -2
- package/build/script.js.map +1 -1
- package/build/transaction.d.ts.map +1 -1
- package/build/transaction.js +1 -1
- package/build/transaction.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.d.ts +1 -1
- package/build/types.d.ts.map +1 -1
- package/build/types.js +3 -9
- package/build/types.js.map +1 -1
- package/build/workers/WorkerSigningPool.d.ts +17 -17
- package/build/workers/WorkerSigningPool.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.js +25 -25
- package/build/workers/WorkerSigningPool.js.map +1 -1
- package/build/workers/WorkerSigningPool.node.d.ts +12 -12
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.node.js +23 -23
- package/build/workers/WorkerSigningPool.node.js.map +1 -1
- package/build/workers/psbt-parallel.d.ts +1 -1
- package/build/workers/psbt-parallel.d.ts.map +1 -1
- package/build/workers/psbt-parallel.js.map +1 -1
- package/build/workers/types.d.ts.map +1 -1
- package/build/workers/types.js.map +1 -1
- package/package.json +3 -2
- package/src/address.ts +13 -4
- package/src/block.ts +15 -8
- package/src/crypto.ts +1 -1
- package/src/ecc/context.ts +12 -9
- package/src/ecc/types.ts +1 -8
- package/src/index.ts +12 -13
- package/src/io/BinaryReader.ts +18 -18
- package/src/io/BinaryWriter.ts +43 -43
- package/src/io/MemoryPool.ts +32 -32
- package/src/payments/bip341.ts +2 -4
- package/src/payments/embed.ts +18 -18
- package/src/payments/p2ms.ts +32 -25
- package/src/payments/p2op.ts +22 -22
- package/src/payments/p2pk.ts +20 -20
- package/src/payments/p2pkh.ts +25 -25
- package/src/payments/p2sh.ts +30 -27
- package/src/payments/p2tr.ts +31 -31
- package/src/payments/p2wpkh.ts +25 -25
- package/src/payments/p2wsh.ts +27 -27
- package/src/payments/types.ts +1 -1
- package/src/psbt/bip371.ts +7 -3
- package/src/psbt/psbtutils.ts +1 -1
- package/src/psbt/types.ts +2 -9
- package/src/psbt/validation.ts +4 -11
- package/src/psbt.ts +107 -83
- package/src/script.ts +4 -7
- package/src/transaction.ts +9 -6
- package/src/types.ts +15 -17
- package/src/workers/WorkerSigningPool.node.ts +31 -31
- package/src/workers/WorkerSigningPool.ts +35 -39
- package/src/workers/psbt-parallel.ts +2 -7
- package/src/workers/types.ts +5 -1
- package/typedoc.json +29 -0
package/src/index.ts
CHANGED
|
@@ -17,6 +17,18 @@ import * as payments from './payments/index.js';
|
|
|
17
17
|
import * as script from './script.js';
|
|
18
18
|
import * as crypto from './crypto.js';
|
|
19
19
|
import * as Transaction from './transaction.js';
|
|
20
|
+
// Custom error types
|
|
21
|
+
import {
|
|
22
|
+
AddressError,
|
|
23
|
+
BitcoinError,
|
|
24
|
+
EccError,
|
|
25
|
+
InvalidInputError,
|
|
26
|
+
InvalidOutputError,
|
|
27
|
+
PsbtError,
|
|
28
|
+
ScriptError,
|
|
29
|
+
SignatureError,
|
|
30
|
+
ValidationError,
|
|
31
|
+
} from './errors.js';
|
|
20
32
|
|
|
21
33
|
export * as address from './address.js';
|
|
22
34
|
export * as crypto from './crypto.js';
|
|
@@ -140,19 +152,6 @@ export {
|
|
|
140
152
|
} from './types.js';
|
|
141
153
|
export type { XOnlyPointAddTweakResult } from './ecc/types.js';
|
|
142
154
|
|
|
143
|
-
// Custom error types
|
|
144
|
-
import {
|
|
145
|
-
BitcoinError,
|
|
146
|
-
ValidationError,
|
|
147
|
-
InvalidInputError,
|
|
148
|
-
InvalidOutputError,
|
|
149
|
-
ScriptError,
|
|
150
|
-
PsbtError,
|
|
151
|
-
EccError,
|
|
152
|
-
AddressError,
|
|
153
|
-
SignatureError,
|
|
154
|
-
} from './errors.js';
|
|
155
|
-
|
|
156
155
|
export {
|
|
157
156
|
BitcoinError,
|
|
158
157
|
ValidationError,
|
package/src/io/BinaryReader.ts
CHANGED
|
@@ -70,24 +70,6 @@ export class BinaryReader {
|
|
|
70
70
|
this.#offset = offset;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
/**
|
|
74
|
-
* Creates a BinaryReader from a hex string.
|
|
75
|
-
*
|
|
76
|
-
* @param hex - Hex string (with or without 0x prefix)
|
|
77
|
-
* @returns A new BinaryReader instance
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* import { BinaryReader } from '@btc-vision/bitcoin';
|
|
82
|
-
*
|
|
83
|
-
* const reader = BinaryReader.fromHex('01000000');
|
|
84
|
-
* const version = reader.readInt32LE(); // 1
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
public static fromHex(hex: string): BinaryReader {
|
|
88
|
-
return new BinaryReader(fromHex(hex));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
73
|
/**
|
|
92
74
|
* Current read position in the buffer.
|
|
93
75
|
*/
|
|
@@ -129,6 +111,24 @@ export class BinaryReader {
|
|
|
129
111
|
return this.#data;
|
|
130
112
|
}
|
|
131
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Creates a BinaryReader from a hex string.
|
|
116
|
+
*
|
|
117
|
+
* @param hex - Hex string (with or without 0x prefix)
|
|
118
|
+
* @returns A new BinaryReader instance
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* import { BinaryReader } from '@btc-vision/bitcoin';
|
|
123
|
+
*
|
|
124
|
+
* const reader = BinaryReader.fromHex('01000000');
|
|
125
|
+
* const version = reader.readInt32LE(); // 1
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
public static fromHex(hex: string): BinaryReader {
|
|
129
|
+
return new BinaryReader(fromHex(hex));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
132
|
/**
|
|
133
133
|
* Reads an 8-bit unsigned integer.
|
|
134
134
|
*
|
package/src/io/BinaryWriter.ts
CHANGED
|
@@ -91,26 +91,6 @@ export class BinaryWriter {
|
|
|
91
91
|
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset, this.#data.byteLength);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/**
|
|
95
|
-
* Creates a BinaryWriter with automatic capacity management.
|
|
96
|
-
*
|
|
97
|
-
* Initial capacity is 256 bytes, grows as needed.
|
|
98
|
-
*
|
|
99
|
-
* @returns A new GrowableBinaryWriter instance
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* import { BinaryWriter } from '@btc-vision/bitcoin';
|
|
104
|
-
*
|
|
105
|
-
* const writer = BinaryWriter.growable();
|
|
106
|
-
* writer.writeUInt32LE(1);
|
|
107
|
-
* writer.writeBytes(new Uint8Array(1000)); // Automatically grows
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
public static growable(initialCapacity: number = 256): GrowableBinaryWriter {
|
|
111
|
-
return new GrowableBinaryWriter(initialCapacity);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
94
|
/**
|
|
115
95
|
* Current write position in the buffer.
|
|
116
96
|
*/
|
|
@@ -152,6 +132,26 @@ export class BinaryWriter {
|
|
|
152
132
|
return this.#data;
|
|
153
133
|
}
|
|
154
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Creates a BinaryWriter with automatic capacity management.
|
|
137
|
+
*
|
|
138
|
+
* Initial capacity is 256 bytes, grows as needed.
|
|
139
|
+
*
|
|
140
|
+
* @returns A new GrowableBinaryWriter instance
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* import { BinaryWriter } from '@btc-vision/bitcoin';
|
|
145
|
+
*
|
|
146
|
+
* const writer = BinaryWriter.growable();
|
|
147
|
+
* writer.writeUInt32LE(1);
|
|
148
|
+
* writer.writeBytes(new Uint8Array(1000)); // Automatically grows
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
public static growable(initialCapacity: number = 256): GrowableBinaryWriter {
|
|
152
|
+
return new GrowableBinaryWriter(initialCapacity);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
155
|
/**
|
|
156
156
|
* Writes an 8-bit unsigned integer.
|
|
157
157
|
*
|
|
@@ -583,29 +583,6 @@ export class GrowableBinaryWriter {
|
|
|
583
583
|
return this.#data.length;
|
|
584
584
|
}
|
|
585
585
|
|
|
586
|
-
/**
|
|
587
|
-
* Ensures the buffer has enough space for additional bytes.
|
|
588
|
-
*
|
|
589
|
-
* @param additionalBytes - Number of additional bytes needed
|
|
590
|
-
*/
|
|
591
|
-
#ensureCapacity(additionalBytes: number): void {
|
|
592
|
-
const required = this.#offset + additionalBytes;
|
|
593
|
-
if (required <= this.#data.length) {
|
|
594
|
-
return;
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// Grow by at least 2x or to required size
|
|
598
|
-
let newCapacity = this.#data.length * 2;
|
|
599
|
-
while (newCapacity < required) {
|
|
600
|
-
newCapacity *= 2;
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
const newData = new Uint8Array(newCapacity);
|
|
604
|
-
newData.set(this.#data.subarray(0, this.#offset));
|
|
605
|
-
this.#data = newData;
|
|
606
|
-
this.#view = new DataView(this.#data.buffer);
|
|
607
|
-
}
|
|
608
|
-
|
|
609
586
|
public writeUInt8(value: number): this {
|
|
610
587
|
this.#ensureCapacity(1);
|
|
611
588
|
this.#data[this.#offset++] = value & 0xff;
|
|
@@ -693,4 +670,27 @@ export class GrowableBinaryWriter {
|
|
|
693
670
|
public toHex(): string {
|
|
694
671
|
return toHex(this.finish());
|
|
695
672
|
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Ensures the buffer has enough space for additional bytes.
|
|
676
|
+
*
|
|
677
|
+
* @param additionalBytes - Number of additional bytes needed
|
|
678
|
+
*/
|
|
679
|
+
#ensureCapacity(additionalBytes: number): void {
|
|
680
|
+
const required = this.#offset + additionalBytes;
|
|
681
|
+
if (required <= this.#data.length) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// Grow by at least 2x or to required size
|
|
686
|
+
let newCapacity = this.#data.length * 2;
|
|
687
|
+
while (newCapacity < required) {
|
|
688
|
+
newCapacity *= 2;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const newData = new Uint8Array(newCapacity);
|
|
692
|
+
newData.set(this.#data.subarray(0, this.#offset));
|
|
693
|
+
this.#data = newData;
|
|
694
|
+
this.#view = new DataView(this.#data.buffer);
|
|
695
|
+
}
|
|
696
696
|
}
|
package/src/io/MemoryPool.ts
CHANGED
|
@@ -77,6 +77,38 @@ export class MemoryPool {
|
|
|
77
77
|
this.#maxSize = size;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Total capacity of the pool in bytes.
|
|
82
|
+
*/
|
|
83
|
+
public get capacity(): number {
|
|
84
|
+
return this.#maxSize;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Current allocation offset (bytes used).
|
|
89
|
+
*
|
|
90
|
+
* Uses Atomics for thread-safe reading.
|
|
91
|
+
*/
|
|
92
|
+
public get used(): number {
|
|
93
|
+
return Atomics.load(this.#control, 0);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Remaining available bytes.
|
|
98
|
+
*/
|
|
99
|
+
public get available(): number {
|
|
100
|
+
return this.#maxSize - this.used;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The underlying SharedArrayBuffer.
|
|
105
|
+
*
|
|
106
|
+
* Can be transferred to Workers for shared memory access.
|
|
107
|
+
*/
|
|
108
|
+
public get sharedBuffer(): SharedArrayBuffer {
|
|
109
|
+
return this.#buffer;
|
|
110
|
+
}
|
|
111
|
+
|
|
80
112
|
/**
|
|
81
113
|
* Creates a MemoryPool from an existing SharedArrayBuffer.
|
|
82
114
|
*
|
|
@@ -111,38 +143,6 @@ export class MemoryPool {
|
|
|
111
143
|
return pool;
|
|
112
144
|
}
|
|
113
145
|
|
|
114
|
-
/**
|
|
115
|
-
* Total capacity of the pool in bytes.
|
|
116
|
-
*/
|
|
117
|
-
public get capacity(): number {
|
|
118
|
-
return this.#maxSize;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Current allocation offset (bytes used).
|
|
123
|
-
*
|
|
124
|
-
* Uses Atomics for thread-safe reading.
|
|
125
|
-
*/
|
|
126
|
-
public get used(): number {
|
|
127
|
-
return Atomics.load(this.#control, 0);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Remaining available bytes.
|
|
132
|
-
*/
|
|
133
|
-
public get available(): number {
|
|
134
|
-
return this.#maxSize - this.used;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* The underlying SharedArrayBuffer.
|
|
139
|
-
*
|
|
140
|
-
* Can be transferred to Workers for shared memory access.
|
|
141
|
-
*/
|
|
142
|
-
public get sharedBuffer(): SharedArrayBuffer {
|
|
143
|
-
return this.#buffer;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
146
|
/**
|
|
147
147
|
* Allocates memory from the pool.
|
|
148
148
|
*
|
package/src/payments/bip341.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as bcrypto from '../crypto.js';
|
|
2
2
|
import { getEccLib } from '../ecc/context.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { alloc, compare, concat, equals, varuint } from '../io/index.js';
|
|
4
|
+
import type { Bytes32, Tapleaf, Taptree, XOnlyPublicKey } from '../types.js';
|
|
5
5
|
import { isTapleaf } from '../types.js';
|
|
6
|
-
import type { Tapleaf, Taptree } from '../types.js';
|
|
7
|
-
import type { Bytes32, XOnlyPublicKey } from '../types.js';
|
|
8
6
|
|
|
9
7
|
export const LEAF_VERSION_TAPSCRIPT = 0xc0;
|
|
10
8
|
export const MAX_TAPTREE_DEPTH = 128;
|
package/src/payments/embed.ts
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
11
11
|
import * as bscript from '../script.js';
|
|
12
|
-
import { stacksEqual, type Stack } from '../types.js';
|
|
13
12
|
import type { Script } from '../types.js';
|
|
14
|
-
import {
|
|
13
|
+
import { type Stack, stacksEqual } from '../types.js';
|
|
14
|
+
import { type EmbedPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
15
15
|
|
|
16
16
|
const OPS = bscript.opcodes;
|
|
17
17
|
|
|
@@ -162,6 +162,20 @@ export class Embed {
|
|
|
162
162
|
|
|
163
163
|
// Private computation methods
|
|
164
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Converts to a plain EmbedPayment object for backwards compatibility.
|
|
167
|
+
*
|
|
168
|
+
* @returns An EmbedPayment object
|
|
169
|
+
*/
|
|
170
|
+
toPayment(): EmbedPayment {
|
|
171
|
+
return {
|
|
172
|
+
name: this.name,
|
|
173
|
+
network: this.network,
|
|
174
|
+
data: this.data,
|
|
175
|
+
output: this.output,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
165
179
|
#computeData(): Uint8Array[] | undefined {
|
|
166
180
|
if (this.#inputData) {
|
|
167
181
|
return this.#inputData;
|
|
@@ -176,6 +190,8 @@ export class Embed {
|
|
|
176
190
|
return undefined;
|
|
177
191
|
}
|
|
178
192
|
|
|
193
|
+
// Validation
|
|
194
|
+
|
|
179
195
|
#computeOutput(): Uint8Array | undefined {
|
|
180
196
|
if (this.#inputOutput) {
|
|
181
197
|
return this.#inputOutput;
|
|
@@ -186,8 +202,6 @@ export class Embed {
|
|
|
186
202
|
return bscript.compile(([OPS.OP_RETURN] as Stack).concat(this.#inputData)) as Script;
|
|
187
203
|
}
|
|
188
204
|
|
|
189
|
-
// Validation
|
|
190
|
-
|
|
191
205
|
#validate(): void {
|
|
192
206
|
if (this.#inputOutput) {
|
|
193
207
|
const chunks = bscript.decompile(this.#inputOutput);
|
|
@@ -206,20 +220,6 @@ export class Embed {
|
|
|
206
220
|
}
|
|
207
221
|
}
|
|
208
222
|
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Converts to a plain EmbedPayment object for backwards compatibility.
|
|
212
|
-
*
|
|
213
|
-
* @returns An EmbedPayment object
|
|
214
|
-
*/
|
|
215
|
-
toPayment(): EmbedPayment {
|
|
216
|
-
return {
|
|
217
|
-
name: this.name,
|
|
218
|
-
network: this.network,
|
|
219
|
-
data: this.data,
|
|
220
|
-
output: this.output,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
/**
|
package/src/payments/p2ms.ts
CHANGED
|
@@ -9,8 +9,15 @@
|
|
|
9
9
|
|
|
10
10
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
11
11
|
import * as bscript from '../script.js';
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import {
|
|
13
|
+
isPoint,
|
|
14
|
+
type PublicKey,
|
|
15
|
+
type Script,
|
|
16
|
+
type Signature,
|
|
17
|
+
type Stack,
|
|
18
|
+
stacksEqual,
|
|
19
|
+
} from '../types.js';
|
|
20
|
+
import { type P2MSPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
14
21
|
|
|
15
22
|
const OPS = bscript.opcodes;
|
|
16
23
|
const OP_INT_BASE = OPS.OP_RESERVED; // OP_1 - 1
|
|
@@ -274,6 +281,27 @@ export class P2MS {
|
|
|
274
281
|
|
|
275
282
|
// Private helper methods
|
|
276
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Converts to a plain P2MSPayment object for backwards compatibility.
|
|
286
|
+
*
|
|
287
|
+
* @returns A P2MSPayment object
|
|
288
|
+
*/
|
|
289
|
+
toPayment(): P2MSPayment {
|
|
290
|
+
return {
|
|
291
|
+
name: this.name,
|
|
292
|
+
network: this.network,
|
|
293
|
+
m: this.m,
|
|
294
|
+
n: this.n,
|
|
295
|
+
pubkeys: this.pubkeys,
|
|
296
|
+
signatures: this.signatures,
|
|
297
|
+
output: this.output,
|
|
298
|
+
input: this.input,
|
|
299
|
+
witness: this.witness,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Private computation methods
|
|
304
|
+
|
|
277
305
|
#decode(output: Uint8Array | Stack): void {
|
|
278
306
|
if (this.#decoded) return;
|
|
279
307
|
this.#decoded = true;
|
|
@@ -286,8 +314,6 @@ export class P2MS {
|
|
|
286
314
|
this.#pubkeysComputed = true;
|
|
287
315
|
}
|
|
288
316
|
|
|
289
|
-
// Private computation methods
|
|
290
|
-
|
|
291
317
|
#computeM(): number | undefined {
|
|
292
318
|
if (this.#inputM !== undefined) {
|
|
293
319
|
return this.#inputM;
|
|
@@ -364,6 +390,8 @@ export class P2MS {
|
|
|
364
390
|
return bscript.compile(([OPS.OP_0] as Stack).concat(this.#inputSignatures)) as Script;
|
|
365
391
|
}
|
|
366
392
|
|
|
393
|
+
// Validation
|
|
394
|
+
|
|
367
395
|
#computeWitness(): Uint8Array[] | undefined {
|
|
368
396
|
if (this.input) {
|
|
369
397
|
return [];
|
|
@@ -371,8 +399,6 @@ export class P2MS {
|
|
|
371
399
|
return undefined;
|
|
372
400
|
}
|
|
373
401
|
|
|
374
|
-
// Validation
|
|
375
|
-
|
|
376
402
|
#isAcceptableSignature(x: Uint8Array | number): boolean {
|
|
377
403
|
return (
|
|
378
404
|
bscript.isCanonicalScriptSignature(x as Uint8Array) ||
|
|
@@ -465,25 +491,6 @@ export class P2MS {
|
|
|
465
491
|
}
|
|
466
492
|
}
|
|
467
493
|
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Converts to a plain P2MSPayment object for backwards compatibility.
|
|
471
|
-
*
|
|
472
|
-
* @returns A P2MSPayment object
|
|
473
|
-
*/
|
|
474
|
-
toPayment(): P2MSPayment {
|
|
475
|
-
return {
|
|
476
|
-
name: this.name,
|
|
477
|
-
network: this.network,
|
|
478
|
-
m: this.m,
|
|
479
|
-
n: this.n,
|
|
480
|
-
pubkeys: this.pubkeys,
|
|
481
|
-
signatures: this.signatures,
|
|
482
|
-
output: this.output,
|
|
483
|
-
input: this.input,
|
|
484
|
-
witness: this.witness,
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
494
|
}
|
|
488
495
|
|
|
489
496
|
/**
|
package/src/payments/p2op.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
|
13
13
|
import * as bscript from '../script.js';
|
|
14
14
|
import { alloc, concat, equals } from '../io/index.js';
|
|
15
15
|
import type { Bytes20, Script } from '../types.js';
|
|
16
|
-
import {
|
|
16
|
+
import { type P2OPPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
17
17
|
|
|
18
18
|
const OPS = bscript.opcodes;
|
|
19
19
|
const P2OP_WITNESS_VERSION = 0x10;
|
|
@@ -241,6 +241,23 @@ export class P2OP {
|
|
|
241
241
|
|
|
242
242
|
// Private helper methods
|
|
243
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Converts to a plain P2OPPayment object for backwards compatibility.
|
|
246
|
+
*
|
|
247
|
+
* @returns A P2OPPayment object
|
|
248
|
+
*/
|
|
249
|
+
toPayment(): P2OPPayment {
|
|
250
|
+
return {
|
|
251
|
+
name: this.name,
|
|
252
|
+
network: this.network,
|
|
253
|
+
address: this.address,
|
|
254
|
+
program: this.program,
|
|
255
|
+
deploymentVersion: this.deploymentVersion,
|
|
256
|
+
hash160: this.hash160,
|
|
257
|
+
output: this.output as Script | undefined,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
244
261
|
#getDecodedAddress(): { version: number; prefix: string; data: Uint8Array } | undefined {
|
|
245
262
|
if (!this.#decodedAddressComputed) {
|
|
246
263
|
if (this.#inputAddress) {
|
|
@@ -258,6 +275,8 @@ export class P2OP {
|
|
|
258
275
|
return this.#decodedAddress;
|
|
259
276
|
}
|
|
260
277
|
|
|
278
|
+
// Private computation methods
|
|
279
|
+
|
|
261
280
|
#makeProgramFromParts(): Uint8Array | undefined {
|
|
262
281
|
if (
|
|
263
282
|
typeof this.#inputDeploymentVersion !== 'undefined' &&
|
|
@@ -274,8 +293,6 @@ export class P2OP {
|
|
|
274
293
|
return undefined;
|
|
275
294
|
}
|
|
276
295
|
|
|
277
|
-
// Private computation methods
|
|
278
|
-
|
|
279
296
|
#computeAddress(): string | undefined {
|
|
280
297
|
if (this.#inputAddress) {
|
|
281
298
|
return this.#inputAddress;
|
|
@@ -346,6 +363,8 @@ export class P2OP {
|
|
|
346
363
|
return prog.subarray(1) as Bytes20;
|
|
347
364
|
}
|
|
348
365
|
|
|
366
|
+
// Validation
|
|
367
|
+
|
|
349
368
|
#computeOutput(): Uint8Array | undefined {
|
|
350
369
|
if (this.#inputOutput) {
|
|
351
370
|
return this.#inputOutput;
|
|
@@ -356,8 +375,6 @@ export class P2OP {
|
|
|
356
375
|
return bscript.compile([OPS.OP_16, prog]);
|
|
357
376
|
}
|
|
358
377
|
|
|
359
|
-
// Validation
|
|
360
|
-
|
|
361
378
|
#validate(): void {
|
|
362
379
|
let prog: Uint8Array = alloc(0);
|
|
363
380
|
|
|
@@ -416,23 +433,6 @@ export class P2OP {
|
|
|
416
433
|
throw new TypeError('hash160 mismatch');
|
|
417
434
|
}
|
|
418
435
|
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Converts to a plain P2OPPayment object for backwards compatibility.
|
|
422
|
-
*
|
|
423
|
-
* @returns A P2OPPayment object
|
|
424
|
-
*/
|
|
425
|
-
toPayment(): P2OPPayment {
|
|
426
|
-
return {
|
|
427
|
-
name: this.name,
|
|
428
|
-
network: this.network,
|
|
429
|
-
address: this.address,
|
|
430
|
-
program: this.program,
|
|
431
|
-
deploymentVersion: this.deploymentVersion,
|
|
432
|
-
hash160: this.hash160,
|
|
433
|
-
output: this.output as Script | undefined,
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
/**
|
package/src/payments/p2pk.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
|
11
11
|
import * as bscript from '../script.js';
|
|
12
12
|
import { isPoint, type PublicKey, type Script, type Signature } from '../types.js';
|
|
13
13
|
import { equals } from '../io/index.js';
|
|
14
|
-
import {
|
|
14
|
+
import { type P2PKPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
15
15
|
|
|
16
16
|
const OPS = bscript.opcodes;
|
|
17
17
|
|
|
@@ -238,6 +238,23 @@ export class P2PK {
|
|
|
238
238
|
|
|
239
239
|
// Private computation methods
|
|
240
240
|
|
|
241
|
+
/**
|
|
242
|
+
* Converts to a plain P2PKPayment object for backwards compatibility.
|
|
243
|
+
*
|
|
244
|
+
* @returns A P2PKPayment object
|
|
245
|
+
*/
|
|
246
|
+
toPayment(): P2PKPayment {
|
|
247
|
+
return {
|
|
248
|
+
name: this.name,
|
|
249
|
+
network: this.network,
|
|
250
|
+
pubkey: this.pubkey,
|
|
251
|
+
signature: this.signature,
|
|
252
|
+
output: this.output,
|
|
253
|
+
input: this.input,
|
|
254
|
+
witness: this.witness,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
241
258
|
#computePubkey(): PublicKey | undefined {
|
|
242
259
|
if (this.#inputPubkey) {
|
|
243
260
|
return this.#inputPubkey as PublicKey;
|
|
@@ -284,6 +301,8 @@ export class P2PK {
|
|
|
284
301
|
return undefined;
|
|
285
302
|
}
|
|
286
303
|
|
|
304
|
+
// Validation
|
|
305
|
+
|
|
287
306
|
#computeWitness(): Uint8Array[] | undefined {
|
|
288
307
|
if (this.input) {
|
|
289
308
|
return [];
|
|
@@ -291,8 +310,6 @@ export class P2PK {
|
|
|
291
310
|
return undefined;
|
|
292
311
|
}
|
|
293
312
|
|
|
294
|
-
// Validation
|
|
295
|
-
|
|
296
313
|
#validate(): void {
|
|
297
314
|
if (this.#inputOutput) {
|
|
298
315
|
if (this.#inputOutput[this.#inputOutput.length - 1] !== OPS.OP_CHECKSIG) {
|
|
@@ -329,23 +346,6 @@ export class P2PK {
|
|
|
329
346
|
}
|
|
330
347
|
}
|
|
331
348
|
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Converts to a plain P2PKPayment object for backwards compatibility.
|
|
335
|
-
*
|
|
336
|
-
* @returns A P2PKPayment object
|
|
337
|
-
*/
|
|
338
|
-
toPayment(): P2PKPayment {
|
|
339
|
-
return {
|
|
340
|
-
name: this.name,
|
|
341
|
-
network: this.network,
|
|
342
|
-
pubkey: this.pubkey,
|
|
343
|
-
signature: this.signature,
|
|
344
|
-
output: this.output,
|
|
345
|
-
input: this.input,
|
|
346
|
-
witness: this.witness,
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
/**
|