@btc-vision/bitcoin 6.3.6 → 6.4.0
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/.mocharc.json +13 -0
- package/browser/address.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/index.js.LICENSE.txt +3 -3
- package/browser/networks.d.ts +1 -0
- package/build/address.d.ts +1 -1
- package/build/address.js +12 -5
- package/build/block.js +2 -2
- package/build/bufferutils.js +5 -5
- package/build/networks.d.ts +1 -0
- package/build/networks.js +11 -0
- package/build/psbt/psbtutils.js +2 -2
- package/build/psbt.js +3 -7
- package/package.json +26 -26
- package/src/address.ts +20 -6
- package/src/block.ts +233 -233
- package/src/bufferutils.ts +188 -180
- package/src/index.ts +86 -86
- package/src/networks.ts +12 -0
- package/src/psbt/bip371.ts +441 -441
- package/src/psbt/psbtutils.ts +4 -3
- package/src/psbt.ts +2187 -2187
- package/test/address.spec.ts +155 -177
- package/test/bitcoin.core.spec.ts +212 -234
- package/test/block.spec.ts +171 -194
- package/test/bufferutils.spec.ts +450 -513
- package/test/crypto.spec.ts +49 -55
- package/test/fixtures/address.json +3 -3
- package/test/integration/addresses.spec.ts +142 -154
- package/test/integration/bip32.spec.ts +130 -151
- package/test/integration/blocks.spec.ts +28 -28
- package/test/integration/cltv.spec.ts +241 -283
- package/test/integration/csv.spec.ts +452 -527
- package/test/integration/payments.spec.ts +110 -135
- package/test/integration/taproot.spec.ts +663 -707
- package/test/integration/transactions.spec.ts +668 -769
- package/test/payments.spec.ts +114 -125
- package/test/payments.utils.ts +165 -208
- package/test/psbt.spec.ts +1285 -1414
- package/test/script.spec.ts +186 -210
- package/test/script_number.spec.ts +26 -29
- package/test/script_signature.spec.ts +66 -66
- package/test/transaction.spec.ts +337 -387
- package/test/ts-node-register.js +7 -5
- package/test/tsconfig.json +4 -1
- package/test/types.spec.ts +53 -58
- package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
- package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/test/address.spec.js +0 -124
- package/test/bitcoin.core.spec.js +0 -170
- package/test/block.spec.js +0 -141
- package/test/bufferutils.spec.js +0 -427
- package/test/crypto.spec.js +0 -41
- package/test/integration/_regtest.js +0 -7
- package/test/integration/addresses.spec.js +0 -116
- package/test/integration/bip32.spec.js +0 -85
- package/test/integration/blocks.spec.js +0 -26
- package/test/integration/cltv.spec.js +0 -199
- package/test/integration/csv.spec.js +0 -362
- package/test/integration/payments.spec.js +0 -98
- package/test/integration/taproot.spec.js +0 -532
- package/test/integration/transactions.spec.js +0 -561
- package/test/payments.spec.js +0 -97
- package/test/payments.utils.js +0 -190
- package/test/psbt.spec.js +0 -1044
- package/test/script.spec.js +0 -151
- package/test/script_number.spec.js +0 -24
- package/test/script_signature.spec.js +0 -52
- package/test/transaction.spec.js +0 -269
- package/test/types.spec.js +0 -46
package/src/bufferutils.ts
CHANGED
|
@@ -1,180 +1,188 @@
|
|
|
1
|
-
import * as varuint from 'varuint-bitcoin';
|
|
2
|
-
import * as types from './types.js';
|
|
3
|
-
|
|
4
|
-
const { typeforce } = types;
|
|
5
|
-
|
|
6
|
-
export { varuint };
|
|
7
|
-
|
|
8
|
-
// https://github.com/feross/buffer/blob/master/index.js#L1127
|
|
9
|
-
function verifuint(value: number, max: number): void {
|
|
10
|
-
if (typeof value !== 'number') throw new Error('cannot write a non-number as a number');
|
|
11
|
-
if (value < 0) throw new Error('specified a negative value for writing an unsigned value');
|
|
12
|
-
if (value > max) throw new Error('RangeError: value out of range');
|
|
13
|
-
if (Math.floor(value) !== value) throw new Error('value has a fractional component');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function readUInt64LE(buffer: Buffer, offset: number): number {
|
|
17
|
-
const a = buffer.readUInt32LE(offset);
|
|
18
|
-
let b = buffer.readUInt32LE(offset + 4);
|
|
19
|
-
b *= 0x100000000;
|
|
20
|
-
|
|
21
|
-
verifuint(b + a, 0x001fffffffffffff);
|
|
22
|
-
return b + a;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Writes a 64-bit unsigned integer in little-endian format to the specified buffer at the given offset.
|
|
27
|
-
*
|
|
28
|
-
* @param buffer - The buffer to write the value to.
|
|
29
|
-
* @param value - The 64-bit unsigned integer value to write.
|
|
30
|
-
* @param offset - The offset in the buffer where the value should be written.
|
|
31
|
-
* @returns The new offset after writing the value.
|
|
32
|
-
*/
|
|
33
|
-
export function writeUInt64LE(buffer: Buffer, value: number, offset: number): number {
|
|
34
|
-
verifuint(value, 0x001fffffffffffff);
|
|
35
|
-
|
|
36
|
-
buffer.writeInt32LE(value & -1, offset);
|
|
37
|
-
buffer.writeUInt32LE(Math.floor(value / 0x100000000), offset + 4);
|
|
38
|
-
return offset + 8;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Reverses the order of bytes in a buffer.
|
|
43
|
-
* @param buffer - The buffer to reverse.
|
|
44
|
-
* @returns A new buffer with the bytes reversed.
|
|
45
|
-
*/
|
|
46
|
-
export function reverseBuffer(buffer: Buffer): Buffer {
|
|
47
|
-
if (buffer.length < 1) return buffer;
|
|
48
|
-
let j = buffer.length - 1;
|
|
49
|
-
let tmp = 0;
|
|
50
|
-
for (let i = 0; i < buffer.length / 2; i++) {
|
|
51
|
-
tmp = buffer[i];
|
|
52
|
-
buffer[i] = buffer[j];
|
|
53
|
-
buffer[j] = tmp;
|
|
54
|
-
j--;
|
|
55
|
-
}
|
|
56
|
-
return buffer;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function cloneBuffer(buffer: Buffer): Buffer {
|
|
60
|
-
const clone = Buffer.allocUnsafe(buffer.length);
|
|
61
|
-
buffer.copy(clone);
|
|
62
|
-
return clone;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Helper class for serialization of bitcoin data types into a pre-allocated buffer.
|
|
67
|
-
*/
|
|
68
|
-
export class BufferWriter {
|
|
69
|
-
constructor(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const result = this.buffer.
|
|
139
|
-
this.offset
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const result = this.buffer.
|
|
145
|
-
this.offset += 4;
|
|
146
|
-
return result;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const result =
|
|
151
|
-
this.offset +=
|
|
152
|
-
return result;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
this.offset +=
|
|
158
|
-
return
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
1
|
+
import * as varuint from 'varuint-bitcoin';
|
|
2
|
+
import * as types from './types.js';
|
|
3
|
+
|
|
4
|
+
const { typeforce } = types;
|
|
5
|
+
|
|
6
|
+
export { varuint };
|
|
7
|
+
|
|
8
|
+
// https://github.com/feross/buffer/blob/master/index.js#L1127
|
|
9
|
+
function verifuint(value: number, max: number): void {
|
|
10
|
+
if (typeof value !== 'number') throw new Error('cannot write a non-number as a number');
|
|
11
|
+
if (value < 0) throw new Error('specified a negative value for writing an unsigned value');
|
|
12
|
+
if (value > max) throw new Error('RangeError: value out of range');
|
|
13
|
+
if (Math.floor(value) !== value) throw new Error('value has a fractional component');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function readUInt64LE(buffer: Buffer, offset: number): number {
|
|
17
|
+
const a = buffer.readUInt32LE(offset);
|
|
18
|
+
let b = buffer.readUInt32LE(offset + 4);
|
|
19
|
+
b *= 0x100000000;
|
|
20
|
+
|
|
21
|
+
verifuint(b + a, 0x001fffffffffffff);
|
|
22
|
+
return b + a;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Writes a 64-bit unsigned integer in little-endian format to the specified buffer at the given offset.
|
|
27
|
+
*
|
|
28
|
+
* @param buffer - The buffer to write the value to.
|
|
29
|
+
* @param value - The 64-bit unsigned integer value to write.
|
|
30
|
+
* @param offset - The offset in the buffer where the value should be written.
|
|
31
|
+
* @returns The new offset after writing the value.
|
|
32
|
+
*/
|
|
33
|
+
export function writeUInt64LE(buffer: Buffer, value: number, offset: number): number {
|
|
34
|
+
verifuint(value, 0x001fffffffffffff);
|
|
35
|
+
|
|
36
|
+
buffer.writeInt32LE(value & -1, offset);
|
|
37
|
+
buffer.writeUInt32LE(Math.floor(value / 0x100000000), offset + 4);
|
|
38
|
+
return offset + 8;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Reverses the order of bytes in a buffer.
|
|
43
|
+
* @param buffer - The buffer to reverse.
|
|
44
|
+
* @returns A new buffer with the bytes reversed.
|
|
45
|
+
*/
|
|
46
|
+
export function reverseBuffer(buffer: Buffer): Buffer {
|
|
47
|
+
if (buffer.length < 1) return buffer;
|
|
48
|
+
let j = buffer.length - 1;
|
|
49
|
+
let tmp = 0;
|
|
50
|
+
for (let i = 0; i < buffer.length / 2; i++) {
|
|
51
|
+
tmp = buffer[i];
|
|
52
|
+
buffer[i] = buffer[j];
|
|
53
|
+
buffer[j] = tmp;
|
|
54
|
+
j--;
|
|
55
|
+
}
|
|
56
|
+
return buffer;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function cloneBuffer(buffer: Buffer): Buffer {
|
|
60
|
+
const clone = Buffer.allocUnsafe(buffer.length);
|
|
61
|
+
buffer.copy(clone);
|
|
62
|
+
return clone;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Helper class for serialization of bitcoin data types into a pre-allocated buffer.
|
|
67
|
+
*/
|
|
68
|
+
export class BufferWriter {
|
|
69
|
+
constructor(
|
|
70
|
+
public buffer: Buffer,
|
|
71
|
+
public offset: number = 0,
|
|
72
|
+
) {
|
|
73
|
+
typeforce(types.tuple(types.Buffer, types.UInt32), [buffer, offset]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static withCapacity(size: number): BufferWriter {
|
|
77
|
+
return new BufferWriter(Buffer.alloc(size));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
writeUInt8(i: number): void {
|
|
81
|
+
this.offset = this.buffer.writeUInt8(i, this.offset);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
writeInt32(i: number): void {
|
|
85
|
+
this.offset = this.buffer.writeInt32LE(i, this.offset);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
writeUInt32(i: number): void {
|
|
89
|
+
this.offset = this.buffer.writeUInt32LE(i, this.offset);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
writeUInt64(i: number): void {
|
|
93
|
+
this.offset = writeUInt64LE(this.buffer, i, this.offset);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
writeVarInt(i: number): void {
|
|
97
|
+
const encode = varuint.encode(i, this.buffer, this.offset);
|
|
98
|
+
this.offset += encode.bytes;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
writeSlice(slice: Buffer): void {
|
|
102
|
+
if (this.buffer.length < this.offset + slice.length) {
|
|
103
|
+
throw new Error('Cannot write slice out of bounds');
|
|
104
|
+
}
|
|
105
|
+
this.offset += slice.copy(this.buffer, this.offset);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
writeVarSlice(slice: Buffer): void {
|
|
109
|
+
this.writeVarInt(slice.length);
|
|
110
|
+
this.writeSlice(slice);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
writeVector(vector: Buffer[]): void {
|
|
114
|
+
this.writeVarInt(vector.length);
|
|
115
|
+
vector.forEach((buf: Buffer) => this.writeVarSlice(buf));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
end(): Buffer {
|
|
119
|
+
if (this.buffer.length === this.offset) {
|
|
120
|
+
return this.buffer;
|
|
121
|
+
}
|
|
122
|
+
throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Helper class for reading of bitcoin data types from a buffer.
|
|
128
|
+
*/
|
|
129
|
+
export class BufferReader {
|
|
130
|
+
constructor(
|
|
131
|
+
public buffer: Buffer,
|
|
132
|
+
public offset: number = 0,
|
|
133
|
+
) {
|
|
134
|
+
typeforce(types.tuple(types.Buffer, types.UInt32), [buffer, offset]);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
readUInt8(): number {
|
|
138
|
+
const result = this.buffer.readUInt8(this.offset);
|
|
139
|
+
this.offset++;
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
readInt32(): number {
|
|
144
|
+
const result = this.buffer.readInt32LE(this.offset);
|
|
145
|
+
this.offset += 4;
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
readUInt32(): number {
|
|
150
|
+
const result = this.buffer.readUInt32LE(this.offset);
|
|
151
|
+
this.offset += 4;
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
readUInt64(): number {
|
|
156
|
+
const result = readUInt64LE(this.buffer, this.offset);
|
|
157
|
+
this.offset += 8;
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
readVarInt(): number {
|
|
162
|
+
const vi = varuint.decode(this.buffer, this.offset);
|
|
163
|
+
this.offset += vi.bytes;
|
|
164
|
+
|
|
165
|
+
return vi.numberValue || 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
readSlice(n: number): Buffer {
|
|
169
|
+
if (this.buffer.length < this.offset + n) {
|
|
170
|
+
throw new Error('Cannot read slice out of bounds');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const result = this.buffer.subarray(this.offset, this.offset + n);
|
|
174
|
+
this.offset += n;
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
readVarSlice(): Buffer {
|
|
179
|
+
return this.readSlice(this.readVarInt());
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
readVector(): Buffer[] {
|
|
183
|
+
const count = this.readVarInt();
|
|
184
|
+
const vector: Buffer[] = [];
|
|
185
|
+
for (let i = 0; i < count; i++) vector.push(this.readVarSlice());
|
|
186
|
+
return vector;
|
|
187
|
+
}
|
|
188
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PsbtInput as _PsbtInput,
|
|
3
|
-
PsbtInputUpdate as _PsbtInputUpdate,
|
|
4
|
-
PsbtOutput as _PsbtOutput,
|
|
5
|
-
TapBip32Derivation as _TapBip32Derivation,
|
|
6
|
-
TapInternalKey as _TapInternalKey,
|
|
7
|
-
TapKeySig as _TapKeySig,
|
|
8
|
-
TapLeaf as _TapLeaf,
|
|
9
|
-
TapLeafScript as _TapLeafScript,
|
|
10
|
-
TapMerkleRoot as _TapMerkleRoot,
|
|
11
|
-
TapScriptSig as _TapScriptSig,
|
|
12
|
-
TapTree as _TapTree,
|
|
13
|
-
} from 'bip174/src/lib/interfaces.js';
|
|
14
|
-
import * as networks from './networks.js';
|
|
15
|
-
import * as address from './address.js';
|
|
16
|
-
import * as payments from './payments/index.js';
|
|
17
|
-
import * as script from './script.js';
|
|
18
|
-
import * as crypto from './crypto.js';
|
|
19
|
-
import * as Transaction from './transaction.js';
|
|
20
|
-
|
|
21
|
-
export * as address from './address.js';
|
|
22
|
-
export * as crypto from './crypto.js';
|
|
23
|
-
export * as networks from './networks.js';
|
|
24
|
-
export * as payments from './payments/index.js';
|
|
25
|
-
export * as script from './script.js';
|
|
26
|
-
|
|
27
|
-
export { Block } from './block.js';
|
|
28
|
-
/** @hidden */
|
|
29
|
-
export * from './crypto.js';
|
|
30
|
-
export * from './psbt.js';
|
|
31
|
-
/** @hidden */
|
|
32
|
-
export { OPS as opcodes } from './ops.js';
|
|
33
|
-
export { Transaction } from './transaction.js';
|
|
34
|
-
/** @hidden */
|
|
35
|
-
export { Network } from './networks.js';
|
|
36
|
-
/** @hidden */
|
|
37
|
-
export { initEccLib } from './ecc_lib.js';
|
|
38
|
-
export { Payment, PaymentCreator, PaymentOpts, Stack, StackElement } from './payments/index.js';
|
|
39
|
-
export { Input as TxInput, Output as TxOutput } from './transaction.js';
|
|
40
|
-
|
|
41
|
-
export interface PsbtInput extends _PsbtInput {}
|
|
42
|
-
|
|
43
|
-
export interface PsbtOutput extends _PsbtOutput {}
|
|
44
|
-
|
|
45
|
-
export interface TapInternalKey extends _TapInternalKey {}
|
|
46
|
-
|
|
47
|
-
export interface TapLeaf extends _TapLeaf {}
|
|
48
|
-
|
|
49
|
-
export interface TapScriptSig extends _TapScriptSig {}
|
|
50
|
-
|
|
51
|
-
export interface TapKeySig extends _TapKeySig {}
|
|
52
|
-
|
|
53
|
-
export interface TapTree extends _TapTree {}
|
|
54
|
-
|
|
55
|
-
export interface TapMerkleRoot extends _TapMerkleRoot {}
|
|
56
|
-
|
|
57
|
-
export interface TapLeafScript extends _TapLeafScript {}
|
|
58
|
-
|
|
59
|
-
export interface TapBip32Derivation extends _TapBip32Derivation {}
|
|
60
|
-
|
|
61
|
-
export interface PsbtInputUpdate extends _PsbtInputUpdate {}
|
|
62
|
-
|
|
63
|
-
export * from './psbt/bip371.js';
|
|
64
|
-
export * from './address.js';
|
|
65
|
-
export * from './bufferutils.js';
|
|
66
|
-
export * from './payments/bip341.js';
|
|
67
|
-
export * from './psbt/psbtutils.js';
|
|
68
|
-
|
|
69
|
-
export {
|
|
70
|
-
Taptree,
|
|
71
|
-
XOnlyPointAddTweakResult,
|
|
72
|
-
Tapleaf,
|
|
73
|
-
TinySecp256k1Interface,
|
|
74
|
-
TAPLEAF_VERSION_MASK,
|
|
75
|
-
} from './types.js';
|
|
76
|
-
|
|
77
|
-
const bitcoin = {
|
|
78
|
-
networks,
|
|
79
|
-
address,
|
|
80
|
-
payments,
|
|
81
|
-
script,
|
|
82
|
-
crypto,
|
|
83
|
-
Transaction,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export default bitcoin;
|
|
1
|
+
import {
|
|
2
|
+
PsbtInput as _PsbtInput,
|
|
3
|
+
PsbtInputUpdate as _PsbtInputUpdate,
|
|
4
|
+
PsbtOutput as _PsbtOutput,
|
|
5
|
+
TapBip32Derivation as _TapBip32Derivation,
|
|
6
|
+
TapInternalKey as _TapInternalKey,
|
|
7
|
+
TapKeySig as _TapKeySig,
|
|
8
|
+
TapLeaf as _TapLeaf,
|
|
9
|
+
TapLeafScript as _TapLeafScript,
|
|
10
|
+
TapMerkleRoot as _TapMerkleRoot,
|
|
11
|
+
TapScriptSig as _TapScriptSig,
|
|
12
|
+
TapTree as _TapTree,
|
|
13
|
+
} from 'bip174/src/lib/interfaces.js';
|
|
14
|
+
import * as networks from './networks.js';
|
|
15
|
+
import * as address from './address.js';
|
|
16
|
+
import * as payments from './payments/index.js';
|
|
17
|
+
import * as script from './script.js';
|
|
18
|
+
import * as crypto from './crypto.js';
|
|
19
|
+
import * as Transaction from './transaction.js';
|
|
20
|
+
|
|
21
|
+
export * as address from './address.js';
|
|
22
|
+
export * as crypto from './crypto.js';
|
|
23
|
+
export * as networks from './networks.js';
|
|
24
|
+
export * as payments from './payments/index.js';
|
|
25
|
+
export * as script from './script.js';
|
|
26
|
+
|
|
27
|
+
export { Block } from './block.js';
|
|
28
|
+
/** @hidden */
|
|
29
|
+
export * from './crypto.js';
|
|
30
|
+
export * from './psbt.js';
|
|
31
|
+
/** @hidden */
|
|
32
|
+
export { OPS as opcodes } from './ops.js';
|
|
33
|
+
export { Transaction } from './transaction.js';
|
|
34
|
+
/** @hidden */
|
|
35
|
+
export { Network } from './networks.js';
|
|
36
|
+
/** @hidden */
|
|
37
|
+
export { initEccLib } from './ecc_lib.js';
|
|
38
|
+
export { Payment, PaymentCreator, PaymentOpts, Stack, StackElement } from './payments/index.js';
|
|
39
|
+
export { Input as TxInput, Output as TxOutput } from './transaction.js';
|
|
40
|
+
|
|
41
|
+
export interface PsbtInput extends _PsbtInput {}
|
|
42
|
+
|
|
43
|
+
export interface PsbtOutput extends _PsbtOutput {}
|
|
44
|
+
|
|
45
|
+
export interface TapInternalKey extends _TapInternalKey {}
|
|
46
|
+
|
|
47
|
+
export interface TapLeaf extends _TapLeaf {}
|
|
48
|
+
|
|
49
|
+
export interface TapScriptSig extends _TapScriptSig {}
|
|
50
|
+
|
|
51
|
+
export interface TapKeySig extends _TapKeySig {}
|
|
52
|
+
|
|
53
|
+
export interface TapTree extends _TapTree {}
|
|
54
|
+
|
|
55
|
+
export interface TapMerkleRoot extends _TapMerkleRoot {}
|
|
56
|
+
|
|
57
|
+
export interface TapLeafScript extends _TapLeafScript {}
|
|
58
|
+
|
|
59
|
+
export interface TapBip32Derivation extends _TapBip32Derivation {}
|
|
60
|
+
|
|
61
|
+
export interface PsbtInputUpdate extends _PsbtInputUpdate {}
|
|
62
|
+
|
|
63
|
+
export * from './psbt/bip371.js';
|
|
64
|
+
export * from './address.js';
|
|
65
|
+
export * from './bufferutils.js';
|
|
66
|
+
export * from './payments/bip341.js';
|
|
67
|
+
export * from './psbt/psbtutils.js';
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
Taptree,
|
|
71
|
+
XOnlyPointAddTweakResult,
|
|
72
|
+
Tapleaf,
|
|
73
|
+
TinySecp256k1Interface,
|
|
74
|
+
TAPLEAF_VERSION_MASK,
|
|
75
|
+
} from './types.js';
|
|
76
|
+
|
|
77
|
+
const bitcoin = {
|
|
78
|
+
networks,
|
|
79
|
+
address,
|
|
80
|
+
payments,
|
|
81
|
+
script,
|
|
82
|
+
crypto,
|
|
83
|
+
Transaction,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default bitcoin;
|
package/src/networks.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface Network {
|
|
|
17
17
|
bip32: Bip32;
|
|
18
18
|
messagePrefix: string;
|
|
19
19
|
bech32: string;
|
|
20
|
+
bech32Opnet?: string;
|
|
20
21
|
pubKeyHash: number;
|
|
21
22
|
scriptHash: number;
|
|
22
23
|
}
|
|
@@ -33,6 +34,7 @@ export const bitcoin: Network = {
|
|
|
33
34
|
* The Bech32 prefix used for Bitcoin addresses.
|
|
34
35
|
*/
|
|
35
36
|
bech32: 'bc',
|
|
37
|
+
bech32Opnet: 'opnet',
|
|
36
38
|
/**
|
|
37
39
|
* The BIP32 key prefixes for Bitcoin.
|
|
38
40
|
*/
|
|
@@ -65,6 +67,7 @@ export const bitcoin: Network = {
|
|
|
65
67
|
export const regtest: Network = {
|
|
66
68
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
67
69
|
bech32: 'bcrt',
|
|
70
|
+
bech32Opnet: 'opreg',
|
|
68
71
|
bip32: {
|
|
69
72
|
public: 0x043587cf,
|
|
70
73
|
private: 0x04358394,
|
|
@@ -79,6 +82,7 @@ export const regtest: Network = {
|
|
|
79
82
|
export const testnet: Network = {
|
|
80
83
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
81
84
|
bech32: 'tb',
|
|
85
|
+
bech32Opnet: 'optest',
|
|
82
86
|
bip32: {
|
|
83
87
|
public: 0x043587cf,
|
|
84
88
|
private: 0x04358394,
|
|
@@ -104,6 +108,7 @@ export const testnet: Network = {
|
|
|
104
108
|
export const dogecoin: Network = {
|
|
105
109
|
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
|
106
110
|
bech32: '', // Dogecoin does not currently use Bech32
|
|
111
|
+
bech32Opnet: '',
|
|
107
112
|
bip32: {
|
|
108
113
|
public: 0x02facafd,
|
|
109
114
|
private: 0x02fac398,
|
|
@@ -129,6 +134,7 @@ export const dogecoin: Network = {
|
|
|
129
134
|
export const dogecoinTestnet: Network = {
|
|
130
135
|
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
|
131
136
|
bech32: '', // Dogecoin testnet does not currently use Bech32
|
|
137
|
+
bech32Opnet: '',
|
|
132
138
|
bip32: {
|
|
133
139
|
public: 0x0432a9a8,
|
|
134
140
|
private: 0x0432a243,
|
|
@@ -144,6 +150,7 @@ export const dogecoinTestnet: Network = {
|
|
|
144
150
|
export const litecoin: Network = {
|
|
145
151
|
messagePrefix: '\x19Litecoin Signed Message:\n',
|
|
146
152
|
bech32: 'ltc',
|
|
153
|
+
bech32Opnet: 'opltc',
|
|
147
154
|
bip32: {
|
|
148
155
|
public: 0x019da462,
|
|
149
156
|
private: 0x019d9cfe,
|
|
@@ -159,6 +166,7 @@ export const litecoin: Network = {
|
|
|
159
166
|
export const litecoinTestnet: Network = {
|
|
160
167
|
messagePrefix: '\x19Litecoin Signed Message:\n',
|
|
161
168
|
bech32: 'tltc',
|
|
169
|
+
bech32Opnet: 'opltct',
|
|
162
170
|
bip32: {
|
|
163
171
|
public: 0x0436ef7d,
|
|
164
172
|
private: 0x0436f6e1,
|
|
@@ -178,6 +186,7 @@ export const bitcoinCash: Network = {
|
|
|
178
186
|
// Cashaddr prefix differs from bech32 for general usage, but we can set it similarly.
|
|
179
187
|
// Actual cashaddr prefix is "bitcoincash", but this field is for bech32 which BCH doesn't fully use for segwit (it doesn't have segwit).
|
|
180
188
|
bech32: 'bitcoincash',
|
|
189
|
+
bech32Opnet: 'opbch',
|
|
181
190
|
bip32: {
|
|
182
191
|
public: 0x0488b21e,
|
|
183
192
|
private: 0x0488ade4,
|
|
@@ -193,6 +202,7 @@ export const bitcoinCash: Network = {
|
|
|
193
202
|
export const bitcoinCashTestnet: Network = {
|
|
194
203
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
195
204
|
bech32: 'bchtest',
|
|
205
|
+
bech32Opnet: 'opbchtest',
|
|
196
206
|
bip32: {
|
|
197
207
|
public: 0x043587cf,
|
|
198
208
|
private: 0x04358394,
|
|
@@ -210,6 +220,7 @@ export const dash: Network = {
|
|
|
210
220
|
// As of Dash Core 0.17, this has not changed in code.
|
|
211
221
|
messagePrefix: '\x19DarkCoin Signed Message:\n',
|
|
212
222
|
bech32: '', // Dash does not use Bech32
|
|
223
|
+
bech32Opnet: '',
|
|
213
224
|
bip32: {
|
|
214
225
|
public: 0x02fe52cc,
|
|
215
226
|
private: 0x02fe52f8,
|
|
@@ -225,6 +236,7 @@ export const dash: Network = {
|
|
|
225
236
|
export const dashTestnet: Network = {
|
|
226
237
|
messagePrefix: '\x19DarkCoin Signed Message:\n',
|
|
227
238
|
bech32: '', // Dash testnet does not use Bech32
|
|
239
|
+
bech32Opnet: '',
|
|
228
240
|
bip32: {
|
|
229
241
|
public: 0x3a8061a0,
|
|
230
242
|
private: 0x3a805837,
|