@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/payments/p2pkh.ts
CHANGED
|
@@ -13,9 +13,9 @@ import * as bcrypto from '../crypto.js';
|
|
|
13
13
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
14
14
|
import { decompressPublicKey } from '../pubkey.js';
|
|
15
15
|
import * as bscript from '../script.js';
|
|
16
|
-
import {
|
|
16
|
+
import { type Bytes20, isPoint, type PublicKey, type Script, type Signature } from '../types.js';
|
|
17
17
|
import { alloc, equals } from '../io/index.js';
|
|
18
|
-
import {
|
|
18
|
+
import { type P2PKHPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
19
19
|
|
|
20
20
|
const OPS = bscript.opcodes;
|
|
21
21
|
|
|
@@ -303,6 +303,25 @@ export class P2PKH {
|
|
|
303
303
|
|
|
304
304
|
// Private helper methods
|
|
305
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Converts to a plain P2PKHPayment object for backwards compatibility.
|
|
308
|
+
*
|
|
309
|
+
* @returns A P2PKHPayment object
|
|
310
|
+
*/
|
|
311
|
+
toPayment(): P2PKHPayment {
|
|
312
|
+
return {
|
|
313
|
+
name: this.name,
|
|
314
|
+
network: this.network,
|
|
315
|
+
address: this.address,
|
|
316
|
+
hash: this.hash,
|
|
317
|
+
pubkey: this.pubkey,
|
|
318
|
+
signature: this.signature,
|
|
319
|
+
output: this.output,
|
|
320
|
+
input: this.input,
|
|
321
|
+
witness: this.witness,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
306
325
|
#getDecodedAddress(): { version: number; hash: Uint8Array } | undefined {
|
|
307
326
|
if (!this.#decodedAddressComputed) {
|
|
308
327
|
if (this.#inputAddress) {
|
|
@@ -317,6 +336,8 @@ export class P2PKH {
|
|
|
317
336
|
return this.#decodedAddress;
|
|
318
337
|
}
|
|
319
338
|
|
|
339
|
+
// Private computation methods
|
|
340
|
+
|
|
320
341
|
#getInputChunks(): (Uint8Array | number)[] | undefined {
|
|
321
342
|
if (!this.#inputChunksComputed) {
|
|
322
343
|
if (this.#inputInput) {
|
|
@@ -327,8 +348,6 @@ export class P2PKH {
|
|
|
327
348
|
return this.#inputChunks;
|
|
328
349
|
}
|
|
329
350
|
|
|
330
|
-
// Private computation methods
|
|
331
|
-
|
|
332
351
|
#computeAddress(): string | undefined {
|
|
333
352
|
if (this.#inputAddress) {
|
|
334
353
|
return this.#inputAddress;
|
|
@@ -425,6 +444,8 @@ export class P2PKH {
|
|
|
425
444
|
return bscript.compile([this.#inputSignature, pubKey]) as Script;
|
|
426
445
|
}
|
|
427
446
|
|
|
447
|
+
// Validation
|
|
448
|
+
|
|
428
449
|
#computeWitness(): Uint8Array[] | undefined {
|
|
429
450
|
if (this.input) {
|
|
430
451
|
return [];
|
|
@@ -432,8 +453,6 @@ export class P2PKH {
|
|
|
432
453
|
return undefined;
|
|
433
454
|
}
|
|
434
455
|
|
|
435
|
-
// Validation
|
|
436
|
-
|
|
437
456
|
#validate(): void {
|
|
438
457
|
let hash: Uint8Array = new Uint8Array(0);
|
|
439
458
|
|
|
@@ -540,25 +559,6 @@ export class P2PKH {
|
|
|
540
559
|
}
|
|
541
560
|
}
|
|
542
561
|
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Converts to a plain P2PKHPayment object for backwards compatibility.
|
|
546
|
-
*
|
|
547
|
-
* @returns A P2PKHPayment object
|
|
548
|
-
*/
|
|
549
|
-
toPayment(): P2PKHPayment {
|
|
550
|
-
return {
|
|
551
|
-
name: this.name,
|
|
552
|
-
network: this.network,
|
|
553
|
-
address: this.address,
|
|
554
|
-
hash: this.hash,
|
|
555
|
-
pubkey: this.pubkey,
|
|
556
|
-
signature: this.signature,
|
|
557
|
-
output: this.output,
|
|
558
|
-
input: this.input,
|
|
559
|
-
witness: this.witness,
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
562
|
}
|
|
563
563
|
|
|
564
564
|
/**
|
package/src/payments/p2sh.ts
CHANGED
|
@@ -12,13 +12,13 @@ import * as bs58check from 'bs58check';
|
|
|
12
12
|
import * as bcrypto from '../crypto.js';
|
|
13
13
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
14
14
|
import * as bscript from '../script.js';
|
|
15
|
-
import {
|
|
15
|
+
import { type Bytes20, type Script, type Stack, stacksEqual } from '../types.js';
|
|
16
16
|
import { alloc, equals } from '../io/index.js';
|
|
17
17
|
import {
|
|
18
|
-
PaymentType,
|
|
19
18
|
type P2SHPayment,
|
|
20
19
|
type Payment,
|
|
21
20
|
type PaymentOpts,
|
|
21
|
+
PaymentType,
|
|
22
22
|
type ScriptRedeem,
|
|
23
23
|
} from './types.js';
|
|
24
24
|
|
|
@@ -282,6 +282,24 @@ export class P2SH {
|
|
|
282
282
|
|
|
283
283
|
// Private helper methods
|
|
284
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Converts to a plain P2SHPayment object for backwards compatibility.
|
|
287
|
+
*
|
|
288
|
+
* @returns A P2SHPayment object
|
|
289
|
+
*/
|
|
290
|
+
toPayment(): P2SHPayment {
|
|
291
|
+
return {
|
|
292
|
+
name: this.name,
|
|
293
|
+
network: this.network,
|
|
294
|
+
address: this.address,
|
|
295
|
+
hash: this.hash,
|
|
296
|
+
output: this.output,
|
|
297
|
+
input: this.input,
|
|
298
|
+
redeem: this.redeem,
|
|
299
|
+
witness: this.witness,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
285
303
|
#getDecodedAddress(): { version: number; hash: Uint8Array } | undefined {
|
|
286
304
|
if (!this.#decodedAddressComputed) {
|
|
287
305
|
if (this.#inputAddress) {
|
|
@@ -306,6 +324,8 @@ export class P2SH {
|
|
|
306
324
|
return this.#inputChunks;
|
|
307
325
|
}
|
|
308
326
|
|
|
327
|
+
// Private computation methods
|
|
328
|
+
|
|
309
329
|
#getDerivedRedeem(): ScriptRedeem | undefined {
|
|
310
330
|
if (!this.#derivedRedeemComputed) {
|
|
311
331
|
const chunks = this.#getInputChunks();
|
|
@@ -313,8 +333,9 @@ export class P2SH {
|
|
|
313
333
|
const lastChunk = chunks[chunks.length - 1];
|
|
314
334
|
this.#derivedRedeem = {
|
|
315
335
|
network: this.#network,
|
|
316
|
-
output:
|
|
317
|
-
|
|
336
|
+
output: (lastChunk === OPS.OP_FALSE
|
|
337
|
+
? new Uint8Array(0)
|
|
338
|
+
: (lastChunk as Uint8Array)) as Script,
|
|
318
339
|
input: bscript.compile(chunks.slice(0, -1)) as Script,
|
|
319
340
|
witness: this.#inputWitness || [],
|
|
320
341
|
};
|
|
@@ -324,8 +345,6 @@ export class P2SH {
|
|
|
324
345
|
return this.#derivedRedeem;
|
|
325
346
|
}
|
|
326
347
|
|
|
327
|
-
// Private computation methods
|
|
328
|
-
|
|
329
348
|
#computeAddress(): string | undefined {
|
|
330
349
|
if (this.#inputAddress) {
|
|
331
350
|
return this.#inputAddress;
|
|
@@ -374,7 +393,9 @@ export class P2SH {
|
|
|
374
393
|
if (!r || !r.input || !r.output) {
|
|
375
394
|
return undefined;
|
|
376
395
|
}
|
|
377
|
-
return bscript.compile(
|
|
396
|
+
return bscript.compile(
|
|
397
|
+
([] as Stack).concat(bscript.decompile(r.input) as Stack, r.output),
|
|
398
|
+
) as Script;
|
|
378
399
|
}
|
|
379
400
|
|
|
380
401
|
#computeRedeem(): ScriptRedeem | undefined {
|
|
@@ -387,6 +408,8 @@ export class P2SH {
|
|
|
387
408
|
return undefined;
|
|
388
409
|
}
|
|
389
410
|
|
|
411
|
+
// Validation
|
|
412
|
+
|
|
390
413
|
#computeWitness(): Uint8Array[] | undefined {
|
|
391
414
|
if (this.#inputWitness) {
|
|
392
415
|
return this.#inputWitness;
|
|
@@ -401,8 +424,6 @@ export class P2SH {
|
|
|
401
424
|
return undefined;
|
|
402
425
|
}
|
|
403
426
|
|
|
404
|
-
// Validation
|
|
405
|
-
|
|
406
427
|
#checkRedeem(redeem: Payment): void {
|
|
407
428
|
// Is the redeem output empty/invalid?
|
|
408
429
|
if (redeem.output) {
|
|
@@ -547,24 +568,6 @@ export class P2SH {
|
|
|
547
568
|
}
|
|
548
569
|
}
|
|
549
570
|
}
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
* Converts to a plain P2SHPayment object for backwards compatibility.
|
|
553
|
-
*
|
|
554
|
-
* @returns A P2SHPayment object
|
|
555
|
-
*/
|
|
556
|
-
toPayment(): P2SHPayment {
|
|
557
|
-
return {
|
|
558
|
-
name: this.name,
|
|
559
|
-
network: this.network,
|
|
560
|
-
address: this.address,
|
|
561
|
-
hash: this.hash,
|
|
562
|
-
output: this.output,
|
|
563
|
-
input: this.input,
|
|
564
|
-
redeem: this.redeem,
|
|
565
|
-
witness: this.witness,
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
571
|
}
|
|
569
572
|
|
|
570
573
|
/**
|
package/src/payments/p2tr.ts
CHANGED
|
@@ -13,25 +13,25 @@ import { getEccLib } from '../ecc/context.js';
|
|
|
13
13
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
14
14
|
import * as bscript from '../script.js';
|
|
15
15
|
import {
|
|
16
|
-
stacksEqual,
|
|
17
|
-
TAPLEAF_VERSION_MASK,
|
|
18
16
|
type Bytes32,
|
|
19
|
-
type Script,
|
|
20
17
|
type SchnorrSignature,
|
|
18
|
+
type Script,
|
|
19
|
+
stacksEqual,
|
|
20
|
+
TAPLEAF_VERSION_MASK,
|
|
21
21
|
type Taptree,
|
|
22
22
|
type XOnlyPublicKey,
|
|
23
23
|
} from '../types.js';
|
|
24
24
|
import {
|
|
25
25
|
findScriptPath,
|
|
26
|
+
type HashTree,
|
|
26
27
|
LEAF_VERSION_TAPSCRIPT,
|
|
27
28
|
rootHashFromPath,
|
|
28
29
|
tapleafHash,
|
|
29
30
|
toHashTree,
|
|
30
31
|
tweakKey,
|
|
31
|
-
type HashTree,
|
|
32
32
|
} from './bip341.js';
|
|
33
33
|
import { concat, equals } from '../io/index.js';
|
|
34
|
-
import {
|
|
34
|
+
import { type P2TRPayment, type PaymentOpts, PaymentType, type ScriptRedeem } from './types.js';
|
|
35
35
|
|
|
36
36
|
const OPS = bscript.opcodes;
|
|
37
37
|
const TAPROOT_WITNESS_VERSION = 0x01;
|
|
@@ -362,6 +362,28 @@ export class P2TR {
|
|
|
362
362
|
|
|
363
363
|
// Private helper methods
|
|
364
364
|
|
|
365
|
+
/**
|
|
366
|
+
* Converts to a plain P2TRPayment object for backwards compatibility.
|
|
367
|
+
*
|
|
368
|
+
* @returns A P2TRPayment object
|
|
369
|
+
*/
|
|
370
|
+
toPayment(): P2TRPayment {
|
|
371
|
+
return {
|
|
372
|
+
name: this.name,
|
|
373
|
+
network: this.network,
|
|
374
|
+
address: this.address,
|
|
375
|
+
pubkey: this.pubkey,
|
|
376
|
+
internalPubkey: this.internalPubkey,
|
|
377
|
+
hash: this.hash,
|
|
378
|
+
scriptTree: this.#inputScriptTree,
|
|
379
|
+
signature: this.signature,
|
|
380
|
+
output: this.output,
|
|
381
|
+
redeem: this.redeem,
|
|
382
|
+
redeemVersion: this.redeemVersion,
|
|
383
|
+
witness: this.witness,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
365
387
|
#getDecodedAddress(): { version: number; prefix: string; data: Uint8Array } | undefined {
|
|
366
388
|
if (!this.#decodedAddressComputed) {
|
|
367
389
|
if (this.#inputAddress) {
|
|
@@ -397,6 +419,8 @@ export class P2TR {
|
|
|
397
419
|
return this.#witnessWithoutAnnex;
|
|
398
420
|
}
|
|
399
421
|
|
|
422
|
+
// Private computation methods
|
|
423
|
+
|
|
400
424
|
#getHashTree(): HashTree | undefined {
|
|
401
425
|
if (!this.#hashTreeComputed) {
|
|
402
426
|
if (this.#inputScriptTree) {
|
|
@@ -409,8 +433,6 @@ export class P2TR {
|
|
|
409
433
|
return this.#hashTree;
|
|
410
434
|
}
|
|
411
435
|
|
|
412
|
-
// Private computation methods
|
|
413
|
-
|
|
414
436
|
#computeAddress(): string | undefined {
|
|
415
437
|
if (this.#inputAddress) {
|
|
416
438
|
return this.#inputAddress;
|
|
@@ -525,6 +547,8 @@ export class P2TR {
|
|
|
525
547
|
return LEAF_VERSION_TAPSCRIPT;
|
|
526
548
|
}
|
|
527
549
|
|
|
550
|
+
// Validation
|
|
551
|
+
|
|
528
552
|
#computeWitness(): Uint8Array[] | undefined {
|
|
529
553
|
if (this.#inputWitness) {
|
|
530
554
|
return this.#inputWitness;
|
|
@@ -558,8 +582,6 @@ export class P2TR {
|
|
|
558
582
|
return undefined;
|
|
559
583
|
}
|
|
560
584
|
|
|
561
|
-
// Validation
|
|
562
|
-
|
|
563
585
|
#validate(): void {
|
|
564
586
|
let pubkey: Uint8Array = new Uint8Array(0);
|
|
565
587
|
|
|
@@ -722,28 +744,6 @@ export class P2TR {
|
|
|
722
744
|
}
|
|
723
745
|
}
|
|
724
746
|
}
|
|
725
|
-
|
|
726
|
-
/**
|
|
727
|
-
* Converts to a plain P2TRPayment object for backwards compatibility.
|
|
728
|
-
*
|
|
729
|
-
* @returns A P2TRPayment object
|
|
730
|
-
*/
|
|
731
|
-
toPayment(): P2TRPayment {
|
|
732
|
-
return {
|
|
733
|
-
name: this.name,
|
|
734
|
-
network: this.network,
|
|
735
|
-
address: this.address,
|
|
736
|
-
pubkey: this.pubkey,
|
|
737
|
-
internalPubkey: this.internalPubkey,
|
|
738
|
-
hash: this.hash,
|
|
739
|
-
scriptTree: this.#inputScriptTree,
|
|
740
|
-
signature: this.signature,
|
|
741
|
-
output: this.output,
|
|
742
|
-
redeem: this.redeem,
|
|
743
|
-
redeemVersion: this.redeemVersion,
|
|
744
|
-
witness: this.witness,
|
|
745
|
-
};
|
|
746
|
-
}
|
|
747
747
|
}
|
|
748
748
|
|
|
749
749
|
/**
|
package/src/payments/p2wpkh.ts
CHANGED
|
@@ -12,10 +12,10 @@ import { bech32 } from 'bech32';
|
|
|
12
12
|
import * as bcrypto from '../crypto.js';
|
|
13
13
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
14
14
|
import * as bscript from '../script.js';
|
|
15
|
-
import { isPoint } from '../types.js';
|
|
16
15
|
import type { Bytes20, PublicKey, Script, Signature } from '../types.js';
|
|
16
|
+
import { isPoint } from '../types.js';
|
|
17
17
|
import { equals } from '../io/index.js';
|
|
18
|
-
import {
|
|
18
|
+
import { type P2WPKHPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
19
19
|
|
|
20
20
|
const OPS = bscript.opcodes;
|
|
21
21
|
const EMPTY_BUFFER = new Uint8Array(0);
|
|
@@ -279,6 +279,27 @@ export class P2WPKH {
|
|
|
279
279
|
|
|
280
280
|
// Private helper methods
|
|
281
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Converts to a plain P2WPKHPayment object for backwards compatibility.
|
|
284
|
+
*
|
|
285
|
+
* @returns A P2WPKHPayment object
|
|
286
|
+
*/
|
|
287
|
+
toPayment(): P2WPKHPayment {
|
|
288
|
+
return {
|
|
289
|
+
name: this.name,
|
|
290
|
+
network: this.network,
|
|
291
|
+
address: this.address,
|
|
292
|
+
hash: this.hash,
|
|
293
|
+
pubkey: this.pubkey,
|
|
294
|
+
signature: this.signature,
|
|
295
|
+
output: this.output,
|
|
296
|
+
input: this.input,
|
|
297
|
+
witness: this.witness,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Private computation methods
|
|
302
|
+
|
|
282
303
|
#getDecodedAddress(): { version: number; prefix: string; data: Uint8Array } | undefined {
|
|
283
304
|
if (!this.#decodedAddressComputed) {
|
|
284
305
|
if (this.#inputAddress) {
|
|
@@ -296,8 +317,6 @@ export class P2WPKH {
|
|
|
296
317
|
return this.#decodedAddress;
|
|
297
318
|
}
|
|
298
319
|
|
|
299
|
-
// Private computation methods
|
|
300
|
-
|
|
301
320
|
#computeAddress(): string | undefined {
|
|
302
321
|
if (this.#inputAddress) {
|
|
303
322
|
return this.#inputAddress;
|
|
@@ -364,6 +383,8 @@ export class P2WPKH {
|
|
|
364
383
|
return undefined;
|
|
365
384
|
}
|
|
366
385
|
|
|
386
|
+
// Validation
|
|
387
|
+
|
|
367
388
|
#computeWitness(): Uint8Array[] | undefined {
|
|
368
389
|
if (this.#inputWitness) {
|
|
369
390
|
return this.#inputWitness;
|
|
@@ -374,8 +395,6 @@ export class P2WPKH {
|
|
|
374
395
|
return [this.#inputSignature, this.#inputPubkey];
|
|
375
396
|
}
|
|
376
397
|
|
|
377
|
-
// Validation
|
|
378
|
-
|
|
379
398
|
#validate(): void {
|
|
380
399
|
let hash: Uint8Array = new Uint8Array(0);
|
|
381
400
|
|
|
@@ -455,25 +474,6 @@ export class P2WPKH {
|
|
|
455
474
|
}
|
|
456
475
|
}
|
|
457
476
|
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* Converts to a plain P2WPKHPayment object for backwards compatibility.
|
|
461
|
-
*
|
|
462
|
-
* @returns A P2WPKHPayment object
|
|
463
|
-
*/
|
|
464
|
-
toPayment(): P2WPKHPayment {
|
|
465
|
-
return {
|
|
466
|
-
name: this.name,
|
|
467
|
-
network: this.network,
|
|
468
|
-
address: this.address,
|
|
469
|
-
hash: this.hash,
|
|
470
|
-
pubkey: this.pubkey,
|
|
471
|
-
signature: this.signature,
|
|
472
|
-
output: this.output,
|
|
473
|
-
input: this.input,
|
|
474
|
-
witness: this.witness,
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
477
|
}
|
|
478
478
|
|
|
479
479
|
/**
|
package/src/payments/p2wsh.ts
CHANGED
|
@@ -12,10 +12,10 @@ import { bech32 } from 'bech32';
|
|
|
12
12
|
import * as bcrypto from '../crypto.js';
|
|
13
13
|
import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
|
|
14
14
|
import * as bscript from '../script.js';
|
|
15
|
-
import { isPoint, stacksEqual, type StackElement } from '../types.js';
|
|
16
15
|
import type { Bytes32, Script } from '../types.js';
|
|
16
|
+
import { isPoint, type StackElement, stacksEqual } from '../types.js';
|
|
17
17
|
import { equals } from '../io/index.js';
|
|
18
|
-
import {
|
|
18
|
+
import { type P2WSHPayment, type PaymentOpts, PaymentType, type ScriptRedeem } from './types.js';
|
|
19
19
|
|
|
20
20
|
const OPS = bscript.opcodes;
|
|
21
21
|
const EMPTY_BUFFER = new Uint8Array(0);
|
|
@@ -278,6 +278,27 @@ export class P2WSH {
|
|
|
278
278
|
|
|
279
279
|
// Private helper methods
|
|
280
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Converts to a plain P2WSHPayment object for backwards compatibility.
|
|
283
|
+
*
|
|
284
|
+
* @returns A P2WSHPayment object
|
|
285
|
+
*/
|
|
286
|
+
toPayment(): P2WSHPayment {
|
|
287
|
+
// Access witness first as it may modify redeem (transform input to witness)
|
|
288
|
+
const witness = this.witness;
|
|
289
|
+
const redeem = this.redeem;
|
|
290
|
+
return {
|
|
291
|
+
name: this.name,
|
|
292
|
+
network: this.network,
|
|
293
|
+
address: this.address,
|
|
294
|
+
hash: this.hash,
|
|
295
|
+
output: this.output,
|
|
296
|
+
input: this.input,
|
|
297
|
+
redeem,
|
|
298
|
+
witness,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
281
302
|
#getDecodedAddress(): { version: number; prefix: string; data: Uint8Array } | undefined {
|
|
282
303
|
if (!this.#decodedAddressComputed) {
|
|
283
304
|
if (this.#inputAddress) {
|
|
@@ -295,6 +316,8 @@ export class P2WSH {
|
|
|
295
316
|
return this.#decodedAddress;
|
|
296
317
|
}
|
|
297
318
|
|
|
319
|
+
// Private computation methods
|
|
320
|
+
|
|
298
321
|
#getRedeemChunks(): (Uint8Array | number)[] | undefined {
|
|
299
322
|
if (!this.#redeemChunksComputed) {
|
|
300
323
|
if (this.#inputRedeem?.input) {
|
|
@@ -305,8 +328,6 @@ export class P2WSH {
|
|
|
305
328
|
return this.#redeemChunks;
|
|
306
329
|
}
|
|
307
330
|
|
|
308
|
-
// Private computation methods
|
|
309
|
-
|
|
310
331
|
#computeAddress(): string | undefined {
|
|
311
332
|
if (this.#inputAddress) {
|
|
312
333
|
return this.#inputAddress;
|
|
@@ -367,6 +388,8 @@ export class P2WSH {
|
|
|
367
388
|
return undefined;
|
|
368
389
|
}
|
|
369
390
|
|
|
391
|
+
// Validation
|
|
392
|
+
|
|
370
393
|
#computeWitness(): Uint8Array[] | undefined {
|
|
371
394
|
if (this.#inputWitness) {
|
|
372
395
|
return this.#inputWitness;
|
|
@@ -394,8 +417,6 @@ export class P2WSH {
|
|
|
394
417
|
return undefined;
|
|
395
418
|
}
|
|
396
419
|
|
|
397
|
-
// Validation
|
|
398
|
-
|
|
399
420
|
#validate(): void {
|
|
400
421
|
let hash: Uint8Array = new Uint8Array(0);
|
|
401
422
|
|
|
@@ -518,27 +539,6 @@ export class P2WSH {
|
|
|
518
539
|
}
|
|
519
540
|
}
|
|
520
541
|
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Converts to a plain P2WSHPayment object for backwards compatibility.
|
|
524
|
-
*
|
|
525
|
-
* @returns A P2WSHPayment object
|
|
526
|
-
*/
|
|
527
|
-
toPayment(): P2WSHPayment {
|
|
528
|
-
// Access witness first as it may modify redeem (transform input to witness)
|
|
529
|
-
const witness = this.witness;
|
|
530
|
-
const redeem = this.redeem;
|
|
531
|
-
return {
|
|
532
|
-
name: this.name,
|
|
533
|
-
network: this.network,
|
|
534
|
-
address: this.address,
|
|
535
|
-
hash: this.hash,
|
|
536
|
-
output: this.output,
|
|
537
|
-
input: this.input,
|
|
538
|
-
redeem,
|
|
539
|
-
witness,
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
542
|
}
|
|
543
543
|
|
|
544
544
|
/**
|
package/src/payments/types.ts
CHANGED
package/src/psbt/bip371.ts
CHANGED
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
} from '../payments/bip341.js';
|
|
17
17
|
import { p2tr } from '../payments/p2tr.js';
|
|
18
18
|
import { Transaction } from '../transaction.js';
|
|
19
|
+
import type { Bytes32, Tapleaf, Taptree, XOnlyPublicKey } from '../types.js';
|
|
19
20
|
import { isTapleaf, isTaptree } from '../types.js';
|
|
20
|
-
import type { Tapleaf, Taptree, XOnlyPublicKey, Bytes32 } from '../types.js';
|
|
21
21
|
import { concat, equals } from '../io/index.js';
|
|
22
22
|
import {
|
|
23
23
|
isP2TR,
|
|
@@ -137,8 +137,12 @@ function getTaprootScripPubkey(tapInternalKey: TapInternalKey, tapTree?: TapTree
|
|
|
137
137
|
|
|
138
138
|
export function tweakInternalPubKey(inputIndex: number, input: PsbtInput): Uint8Array {
|
|
139
139
|
const tapInternalKey = input.tapInternalKey;
|
|
140
|
-
const tapInternalKeyBuf = tapInternalKey
|
|
141
|
-
|
|
140
|
+
const tapInternalKeyBuf = tapInternalKey
|
|
141
|
+
? (new Uint8Array(tapInternalKey) as XOnlyPublicKey)
|
|
142
|
+
: undefined;
|
|
143
|
+
const tapMerkleRootBuf = input.tapMerkleRoot
|
|
144
|
+
? (new Uint8Array(input.tapMerkleRoot) as Bytes32)
|
|
145
|
+
: undefined;
|
|
142
146
|
const outputKey = tapInternalKeyBuf && tweakKey(tapInternalKeyBuf, tapMerkleRootBuf);
|
|
143
147
|
|
|
144
148
|
if (!outputKey)
|
package/src/psbt/psbtutils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PartialSig, PsbtInput } from 'bip174';
|
|
2
|
-
import {
|
|
2
|
+
import { alloc, concat, equals, varuint } from '../io/index.js';
|
|
3
3
|
import { hash160 } from '../crypto.js';
|
|
4
4
|
import { p2ms } from '../payments/p2ms.js';
|
|
5
5
|
import { p2pk } from '../payments/p2pk.js';
|
package/src/psbt/types.ts
CHANGED
|
@@ -5,15 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
import type { Psbt as PsbtBase, PsbtGlobal, PsbtInput, PsbtOutput } from 'bip174';
|
|
7
7
|
import type { Network } from '../networks.js';
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
Bytes32,
|
|
11
|
-
PublicKey,
|
|
12
|
-
Satoshi,
|
|
13
|
-
Script,
|
|
14
|
-
Signature,
|
|
15
|
-
SchnorrSignature,
|
|
16
|
-
} from '../types.js';
|
|
8
|
+
import type { TaprootHashCache, Transaction } from '../transaction.js';
|
|
9
|
+
import type { Bytes32, PublicKey, Satoshi, SchnorrSignature, Script, Signature } from '../types.js';
|
|
17
10
|
|
|
18
11
|
/**
|
|
19
12
|
* Transaction input interface for PSBT.
|
package/src/psbt/validation.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { PsbtInput } from 'bip174';
|
|
7
|
-
import {
|
|
8
|
-
import * as payments from '../payments/index.js';
|
|
7
|
+
import { equals, reverse, toHex } from '../io/index.js';
|
|
9
8
|
import type { P2SHPayment, Payment, PaymentOpts } from '../payments/index.js';
|
|
9
|
+
import * as payments from '../payments/index.js';
|
|
10
10
|
import { checkTaprootInputForSigs, isTaprootInput } from './bip371.js';
|
|
11
11
|
import { checkInputForSig, pubkeyInScript } from './psbtutils.js';
|
|
12
12
|
import * as bscript from '../script.js';
|
|
@@ -142,9 +142,7 @@ export function checkPartialSigSighashes(input: PsbtInput): void {
|
|
|
142
142
|
*/
|
|
143
143
|
export function checkScriptForPubkey(pubkey: PublicKey, script: Script, action: string): void {
|
|
144
144
|
if (!pubkeyInScript(pubkey, script)) {
|
|
145
|
-
throw new Error(
|
|
146
|
-
`Can not ${action} for this input with the key ${toHex(pubkey)}`,
|
|
147
|
-
);
|
|
145
|
+
throw new Error(`Can not ${action} for this input with the key ${toHex(pubkey)}`);
|
|
148
146
|
}
|
|
149
147
|
}
|
|
150
148
|
|
|
@@ -157,12 +155,7 @@ export function checkScriptForPubkey(pubkey: PublicKey, script: Script, action:
|
|
|
157
155
|
export function scriptCheckerFactory(
|
|
158
156
|
payment: (a: Omit<Payment, 'name'>, opts?: PaymentOpts) => Payment,
|
|
159
157
|
paymentScriptName: string,
|
|
160
|
-
): (
|
|
161
|
-
idx: number,
|
|
162
|
-
scriptPubKey: Script,
|
|
163
|
-
redeemScript: Script,
|
|
164
|
-
ioType: 'input' | 'output',
|
|
165
|
-
) => void {
|
|
158
|
+
): (idx: number, scriptPubKey: Script, redeemScript: Script, ioType: 'input' | 'output') => void {
|
|
166
159
|
return (
|
|
167
160
|
inputIndex: number,
|
|
168
161
|
scriptPubKey: Script,
|