@btc-vision/bitcoin 6.3.6 → 6.4.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/.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 +2 -1
- package/build/address.js +68 -13
- 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 +91 -15
- package/src/block.ts +2 -2
- package/src/bufferutils.ts +15 -7
- package/src/index.ts +86 -86
- package/src/networks.ts +12 -0
- package/src/psbt/bip371.ts +441 -441
- package/src/psbt/psbtutils.ts +320 -319
- package/src/psbt.ts +8 -8
- package/test/address.spec.ts +55 -77
- package/test/bitcoin.core.spec.ts +47 -69
- package/test/block.spec.ts +23 -46
- package/test/bufferutils.spec.ts +32 -95
- package/test/crypto.spec.ts +9 -15
- package/test/fixtures/address.json +3 -3
- package/test/integration/addresses.spec.ts +12 -24
- package/test/integration/bip32.spec.ts +10 -31
- package/test/integration/blocks.spec.ts +2 -2
- package/test/integration/cltv.spec.ts +21 -63
- package/test/integration/csv.spec.ts +30 -105
- package/test/integration/payments.spec.ts +16 -41
- package/test/integration/taproot.spec.ts +31 -75
- package/test/integration/transactions.spec.ts +37 -138
- package/test/payments.spec.ts +95 -106
- package/test/payments.utils.ts +20 -63
- package/test/psbt.spec.ts +100 -229
- package/test/script.spec.ts +26 -50
- package/test/script_number.spec.ts +6 -9
- package/test/script_signature.spec.ts +7 -7
- package/test/transaction.spec.ts +46 -96
- package/test/ts-node-register.js +3 -1
- package/test/tsconfig.json +4 -1
- package/test/types.spec.ts +7 -12
- 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/address.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { bech32, bech32m } from 'bech32';
|
|
11
11
|
import * as bs58check from 'bs58check';
|
|
12
|
-
import { payments } from './index.js';
|
|
12
|
+
import { opcodes, payments } from './index.js';
|
|
13
13
|
import * as networks from './networks.js';
|
|
14
14
|
import { Network } from './networks.js';
|
|
15
15
|
import * as bscript from './script.js';
|
|
@@ -35,7 +35,9 @@ export interface Bech32Result {
|
|
|
35
35
|
|
|
36
36
|
const FUTURE_SEGWIT_MAX_SIZE: number = 40;
|
|
37
37
|
const FUTURE_SEGWIT_MIN_SIZE: number = 2;
|
|
38
|
-
const FUTURE_SEGWIT_MAX_VERSION: number =
|
|
38
|
+
const FUTURE_SEGWIT_MAX_VERSION: number = 15;
|
|
39
|
+
const FUTURE_MAX_VERSION: number = 16;
|
|
40
|
+
const FUTURE_OPNET_VERSION: number = 16;
|
|
39
41
|
const FUTURE_SEGWIT_MIN_VERSION: number = 2;
|
|
40
42
|
const FUTURE_SEGWIT_VERSION_DIFF: number = 0x50;
|
|
41
43
|
const FUTURE_SEGWIT_VERSION_WARNING: string =
|
|
@@ -44,22 +46,68 @@ const FUTURE_SEGWIT_VERSION_WARNING: string =
|
|
|
44
46
|
'with caution. Wallets should verify the segwit version from the output of fromBech32, ' +
|
|
45
47
|
'then decide when it is safe to use which version of segwit.';
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Encode a future Taproot-style segwit address (SegWit v2 - v16) using bech32m.
|
|
51
|
+
* Only for versions not yet assigned specific meanings (future use).
|
|
52
|
+
*
|
|
53
|
+
* @param output - Output script buffer containing the version and witness program
|
|
54
|
+
* @param network - Network object containing bech32 and optional bech32Opnet prefix
|
|
55
|
+
* @returns Bech32m-encoded future Taproot-style address
|
|
56
|
+
*/
|
|
57
|
+
export function toFutureOPNetAddress(output: Buffer, network: Network): string {
|
|
58
|
+
if (!Buffer.isBuffer(output)) throw new TypeError('output must be a Buffer');
|
|
59
|
+
if (!network.bech32Opnet) throw new Error('Network does not support opnet');
|
|
60
|
+
|
|
61
|
+
const opcode = output[0];
|
|
62
|
+
|
|
63
|
+
// work out where the push-data really starts
|
|
64
|
+
let pushPos = 1,
|
|
65
|
+
progLen: number;
|
|
66
|
+
if (output[1] < 0x4c) {
|
|
67
|
+
progLen = output[1];
|
|
68
|
+
pushPos = 2;
|
|
69
|
+
} else if (output[1] === 0x4c) {
|
|
70
|
+
progLen = output[2];
|
|
71
|
+
pushPos = 3;
|
|
72
|
+
} else {
|
|
73
|
+
throw new TypeError('Unsupported push opcode in script');
|
|
74
|
+
}
|
|
49
75
|
|
|
50
|
-
|
|
76
|
+
const program = output.subarray(pushPos, pushPos + progLen);
|
|
77
|
+
|
|
78
|
+
if (program.length < FUTURE_SEGWIT_MIN_SIZE || program.length > FUTURE_SEGWIT_MAX_SIZE)
|
|
51
79
|
throw new TypeError('Invalid program length for segwit address');
|
|
52
80
|
|
|
53
|
-
const version =
|
|
81
|
+
const version =
|
|
82
|
+
opcode === opcodes.OP_0
|
|
83
|
+
? 0
|
|
84
|
+
: opcode >= opcodes.OP_1 && opcode <= opcodes.OP_16
|
|
85
|
+
? opcode - (opcodes.OP_1 - 1)
|
|
86
|
+
: -1;
|
|
54
87
|
|
|
55
|
-
if (version <
|
|
56
|
-
throw new TypeError(
|
|
88
|
+
if (version < FUTURE_SEGWIT_MAX_VERSION || version > FUTURE_MAX_VERSION)
|
|
89
|
+
throw new TypeError(`Invalid segwit version ${version}`);
|
|
57
90
|
|
|
58
|
-
|
|
91
|
+
const words = [version, ...bech32m.toWords(program)];
|
|
92
|
+
return bech32m.encode(network.bech32Opnet, words);
|
|
93
|
+
}
|
|
59
94
|
|
|
60
|
-
|
|
95
|
+
function _toFutureSegwitAddress(output: Buffer, network: Network): string {
|
|
96
|
+
const data = output.subarray(2);
|
|
97
|
+
if (data.length < FUTURE_SEGWIT_MIN_SIZE || data.length > FUTURE_SEGWIT_MAX_SIZE) {
|
|
98
|
+
throw new TypeError('Invalid program length for segwit address');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const version = output[0] - FUTURE_SEGWIT_VERSION_DIFF;
|
|
102
|
+
if (version < FUTURE_SEGWIT_MIN_VERSION || version > FUTURE_SEGWIT_MAX_VERSION) {
|
|
103
|
+
throw new TypeError('Invalid version for segwit address');
|
|
104
|
+
}
|
|
61
105
|
|
|
62
|
-
|
|
106
|
+
if (output[1] !== data.length) {
|
|
107
|
+
throw new TypeError(`Invalid script for segwit address ${output[1]} !== ${data.length}`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return toBech32(data, version, network.bech32, network.bech32Opnet);
|
|
63
111
|
}
|
|
64
112
|
|
|
65
113
|
/**
|
|
@@ -73,7 +121,7 @@ export function fromBase58Check(address: string): Base58CheckResult {
|
|
|
73
121
|
if (payload.length > 21) throw new TypeError(address + ' is too long');
|
|
74
122
|
|
|
75
123
|
const version = payload.readUInt8(0);
|
|
76
|
-
const hash = payload.
|
|
124
|
+
const hash = payload.subarray(1);
|
|
77
125
|
|
|
78
126
|
return { version, hash };
|
|
79
127
|
}
|
|
@@ -122,10 +170,19 @@ export function toBase58Check(hash: Buffer, version: number): string {
|
|
|
122
170
|
/**
|
|
123
171
|
* encode address hash to bech32 address with version and prefix
|
|
124
172
|
*/
|
|
125
|
-
export function toBech32(
|
|
173
|
+
export function toBech32(
|
|
174
|
+
data: Buffer,
|
|
175
|
+
version: number,
|
|
176
|
+
prefix: string,
|
|
177
|
+
prefixOpnet?: string,
|
|
178
|
+
): string {
|
|
126
179
|
const words = bech32.toWords(data);
|
|
127
180
|
words.unshift(version);
|
|
128
181
|
|
|
182
|
+
if (version === FUTURE_OPNET_VERSION && prefixOpnet) {
|
|
183
|
+
return bech32m.encode(prefixOpnet, words);
|
|
184
|
+
}
|
|
185
|
+
|
|
129
186
|
return version === 0 ? bech32.encode(prefix, words) : bech32m.encode(prefix, words);
|
|
130
187
|
}
|
|
131
188
|
|
|
@@ -151,6 +208,9 @@ export function fromOutputScript(output: Buffer, network?: Network): string {
|
|
|
151
208
|
try {
|
|
152
209
|
return payments.p2tr({ output, network }).address as string;
|
|
153
210
|
} catch (e) {}
|
|
211
|
+
try {
|
|
212
|
+
return toFutureOPNetAddress(output, network);
|
|
213
|
+
} catch (e) {}
|
|
154
214
|
try {
|
|
155
215
|
return _toFutureSegwitAddress(output, network);
|
|
156
216
|
} catch (e) {}
|
|
@@ -181,7 +241,11 @@ export function toOutputScript(address: string, network?: Network): Buffer {
|
|
|
181
241
|
} catch (e) {}
|
|
182
242
|
|
|
183
243
|
if (decodeBech32) {
|
|
184
|
-
if (
|
|
244
|
+
if (
|
|
245
|
+
decodeBech32.prefix !== network.bech32 &&
|
|
246
|
+
network.bech32Opnet &&
|
|
247
|
+
decodeBech32.prefix !== network.bech32Opnet
|
|
248
|
+
)
|
|
185
249
|
throw new Error(address + ' has an invalid prefix');
|
|
186
250
|
if (decodeBech32.version === 0) {
|
|
187
251
|
if (decodeBech32.data.length === 20)
|
|
@@ -191,13 +255,25 @@ export function toOutputScript(address: string, network?: Network): Buffer {
|
|
|
191
255
|
} else if (decodeBech32.version === 1) {
|
|
192
256
|
if (decodeBech32.data.length === 32)
|
|
193
257
|
return payments.p2tr({ pubkey: decodeBech32.data }).output as Buffer;
|
|
258
|
+
} else if (decodeBech32.version === FUTURE_OPNET_VERSION) {
|
|
259
|
+
if (!network.bech32Opnet) throw new Error(address + ' has an invalid prefix');
|
|
260
|
+
if (
|
|
261
|
+
decodeBech32.data.length < FUTURE_SEGWIT_MIN_SIZE ||
|
|
262
|
+
decodeBech32.data.length > FUTURE_SEGWIT_MAX_SIZE
|
|
263
|
+
) {
|
|
264
|
+
throw new Error('Invalid program length for opnet address');
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return bscript.compile([opcodes.OP_16, decodeBech32.data]);
|
|
194
268
|
} else if (
|
|
195
269
|
decodeBech32.version >= FUTURE_SEGWIT_MIN_VERSION &&
|
|
196
270
|
decodeBech32.version <= FUTURE_SEGWIT_MAX_VERSION &&
|
|
197
271
|
decodeBech32.data.length >= FUTURE_SEGWIT_MIN_SIZE &&
|
|
198
272
|
decodeBech32.data.length <= FUTURE_SEGWIT_MAX_SIZE
|
|
199
273
|
) {
|
|
200
|
-
|
|
274
|
+
if (decodeBech32.version !== FUTURE_OPNET_VERSION) {
|
|
275
|
+
console.warn(FUTURE_SEGWIT_VERSION_WARNING);
|
|
276
|
+
}
|
|
201
277
|
|
|
202
278
|
return bscript.compile([
|
|
203
279
|
decodeBech32.version + FUTURE_SEGWIT_VERSION_DIFF,
|
package/src/block.ts
CHANGED
|
@@ -155,8 +155,8 @@ export class Block {
|
|
|
155
155
|
|
|
156
156
|
if (headersOnly || !this.transactions) return buffer;
|
|
157
157
|
|
|
158
|
-
varuint.encode(this.transactions.length, buffer, bufferWriter.offset);
|
|
159
|
-
bufferWriter.offset +=
|
|
158
|
+
const encoded = varuint.encode(this.transactions.length, buffer, bufferWriter.offset);
|
|
159
|
+
bufferWriter.offset += encoded.bytes;
|
|
160
160
|
|
|
161
161
|
this.transactions.forEach((tx) => {
|
|
162
162
|
const txSize = tx.byteLength(); // TODO: extract from toBuffer?
|
package/src/bufferutils.ts
CHANGED
|
@@ -66,7 +66,10 @@ export function cloneBuffer(buffer: Buffer): Buffer {
|
|
|
66
66
|
* Helper class for serialization of bitcoin data types into a pre-allocated buffer.
|
|
67
67
|
*/
|
|
68
68
|
export class BufferWriter {
|
|
69
|
-
constructor(
|
|
69
|
+
constructor(
|
|
70
|
+
public buffer: Buffer,
|
|
71
|
+
public offset: number = 0,
|
|
72
|
+
) {
|
|
70
73
|
typeforce(types.tuple(types.Buffer, types.UInt32), [buffer, offset]);
|
|
71
74
|
}
|
|
72
75
|
|
|
@@ -91,8 +94,8 @@ export class BufferWriter {
|
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
writeVarInt(i: number): void {
|
|
94
|
-
varuint.encode(i, this.buffer, this.offset);
|
|
95
|
-
this.offset +=
|
|
97
|
+
const encode = varuint.encode(i, this.buffer, this.offset);
|
|
98
|
+
this.offset += encode.bytes;
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
writeSlice(slice: Buffer): void {
|
|
@@ -124,7 +127,10 @@ export class BufferWriter {
|
|
|
124
127
|
* Helper class for reading of bitcoin data types from a buffer.
|
|
125
128
|
*/
|
|
126
129
|
export class BufferReader {
|
|
127
|
-
constructor(
|
|
130
|
+
constructor(
|
|
131
|
+
public buffer: Buffer,
|
|
132
|
+
public offset: number = 0,
|
|
133
|
+
) {
|
|
128
134
|
typeforce(types.tuple(types.Buffer, types.UInt32), [buffer, offset]);
|
|
129
135
|
}
|
|
130
136
|
|
|
@@ -154,15 +160,17 @@ export class BufferReader {
|
|
|
154
160
|
|
|
155
161
|
readVarInt(): number {
|
|
156
162
|
const vi = varuint.decode(this.buffer, this.offset);
|
|
157
|
-
this.offset +=
|
|
158
|
-
|
|
163
|
+
this.offset += vi.bytes;
|
|
164
|
+
|
|
165
|
+
return vi.numberValue || 0;
|
|
159
166
|
}
|
|
160
167
|
|
|
161
168
|
readSlice(n: number): Buffer {
|
|
162
169
|
if (this.buffer.length < this.offset + n) {
|
|
163
170
|
throw new Error('Cannot read slice out of bounds');
|
|
164
171
|
}
|
|
165
|
-
|
|
172
|
+
|
|
173
|
+
const result = this.buffer.subarray(this.offset, this.offset + n);
|
|
166
174
|
this.offset += n;
|
|
167
175
|
return result;
|
|
168
176
|
}
|
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: 'op',
|
|
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: 'opr',
|
|
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: 'opt',
|
|
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: 'opl',
|
|
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: 'oplt',
|
|
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: 'opbcht',
|
|
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,
|