@btc-vision/bitcoin 6.4.2 → 6.4.4
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/index.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/payments/embed.d.ts +2 -2
- package/browser/payments/index.d.ts +71 -14
- package/browser/payments/lazy.d.ts +1 -1
- package/browser/payments/p2ms.d.ts +2 -2
- package/browser/payments/p2op.d.ts +25 -2
- package/browser/payments/p2pk.d.ts +2 -2
- package/browser/payments/p2pkh.d.ts +2 -2
- package/browser/payments/p2sh.d.ts +2 -2
- package/browser/payments/p2tr.d.ts +2 -2
- package/browser/payments/p2wpkh.d.ts +2 -2
- package/browser/payments/p2wsh.d.ts +2 -2
- package/build/address.js +0 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -0
- package/build/payments/embed.d.ts +2 -2
- package/build/payments/embed.js +7 -2
- package/build/payments/index.d.ts +71 -14
- package/build/payments/index.js +13 -0
- package/build/payments/lazy.d.ts +1 -1
- package/build/payments/p2ms.d.ts +2 -2
- package/build/payments/p2ms.js +9 -2
- package/build/payments/p2op.d.ts +25 -2
- package/build/payments/p2op.js +29 -4
- package/build/payments/p2pk.d.ts +2 -2
- package/build/payments/p2pk.js +6 -1
- package/build/payments/p2pkh.d.ts +2 -2
- package/build/payments/p2pkh.js +6 -1
- package/build/payments/p2sh.d.ts +2 -2
- package/build/payments/p2sh.js +5 -1
- package/build/payments/p2tr.d.ts +2 -2
- package/build/payments/p2tr.js +6 -2
- package/build/payments/p2wpkh.d.ts +2 -2
- package/build/payments/p2wpkh.js +5 -1
- package/build/payments/p2wsh.d.ts +2 -2
- package/build/payments/p2wsh.js +5 -1
- package/build/psbt.js +5 -2
- package/package.json +1 -1
- package/src/address.ts +283 -284
- package/src/index.ts +20 -1
- package/src/payments/embed.ts +61 -55
- package/src/payments/index.ts +172 -68
- package/src/payments/lazy.ts +28 -28
- package/src/payments/p2ms.ts +11 -5
- package/src/payments/p2op.ts +64 -5
- package/src/payments/p2pk.ts +93 -85
- package/src/payments/p2pkh.ts +214 -210
- package/src/payments/p2sh.ts +210 -206
- package/src/payments/p2tr.ts +9 -4
- package/src/payments/p2wpkh.ts +6 -3
- package/src/payments/p2wsh.ts +6 -3
- package/src/psbt.ts +10 -7
- package/test/payments.spec.ts +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2data(a:
|
|
1
|
+
import { EmbedPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2data(a: Omit<EmbedPayment, 'name'>, opts?: PaymentOpts): EmbedPayment;
|
|
@@ -11,33 +11,90 @@ export * from './p2tr.js';
|
|
|
11
11
|
export * from './p2wpkh.js';
|
|
12
12
|
export * from './p2wsh.js';
|
|
13
13
|
export * from './p2op.js';
|
|
14
|
-
export
|
|
15
|
-
|
|
14
|
+
export declare enum PaymentType {
|
|
15
|
+
P2PK = "p2pk",
|
|
16
|
+
P2PKH = "p2pkh",
|
|
17
|
+
P2SH = "p2sh",
|
|
18
|
+
P2MS = "p2ms",
|
|
19
|
+
P2WPKH = "p2wpkh",
|
|
20
|
+
P2WSH = "p2wsh",
|
|
21
|
+
P2TR = "p2tr",
|
|
22
|
+
P2OP = "p2op",
|
|
23
|
+
Embed = "embed",
|
|
24
|
+
ScriptRedeem = "scriptRedeem"
|
|
25
|
+
}
|
|
26
|
+
export interface BasePayment {
|
|
27
|
+
name?: PaymentType;
|
|
16
28
|
network?: Network;
|
|
17
29
|
output?: Buffer;
|
|
18
|
-
|
|
30
|
+
input?: Buffer;
|
|
31
|
+
address?: string;
|
|
32
|
+
witness?: Buffer[];
|
|
33
|
+
redeem?: ScriptRedeem;
|
|
34
|
+
useHybrid?: boolean;
|
|
35
|
+
useUncompressed?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface ScriptRedeem extends BasePayment {
|
|
38
|
+
output?: Buffer;
|
|
39
|
+
redeemVersion?: number;
|
|
40
|
+
network?: Network;
|
|
41
|
+
}
|
|
42
|
+
export interface P2PKPayment extends BasePayment {
|
|
43
|
+
name: PaymentType.P2PK;
|
|
44
|
+
pubkey?: Buffer;
|
|
45
|
+
signature?: Buffer;
|
|
46
|
+
}
|
|
47
|
+
export interface P2PKHPayment extends BasePayment {
|
|
48
|
+
name: PaymentType.P2PKH;
|
|
49
|
+
hash?: Buffer;
|
|
50
|
+
pubkey?: Buffer;
|
|
51
|
+
signature?: Buffer;
|
|
52
|
+
}
|
|
53
|
+
export interface P2SHPayment extends BasePayment {
|
|
54
|
+
name: PaymentType.P2SH;
|
|
55
|
+
hash?: Buffer;
|
|
56
|
+
signatures?: Buffer[];
|
|
57
|
+
}
|
|
58
|
+
export interface P2MSPayment extends BasePayment {
|
|
59
|
+
name: PaymentType.P2MS;
|
|
19
60
|
m?: number;
|
|
20
61
|
n?: number;
|
|
21
62
|
pubkeys?: Buffer[];
|
|
22
|
-
input?: Buffer;
|
|
23
63
|
signatures?: Buffer[];
|
|
24
|
-
|
|
64
|
+
}
|
|
65
|
+
export interface P2WPKHPayment extends BasePayment {
|
|
66
|
+
name: PaymentType.P2WPKH;
|
|
67
|
+
hash?: Buffer;
|
|
25
68
|
pubkey?: Buffer;
|
|
26
69
|
signature?: Buffer;
|
|
27
|
-
|
|
70
|
+
}
|
|
71
|
+
export interface P2WSHPayment extends BasePayment {
|
|
72
|
+
name: PaymentType.P2WSH;
|
|
73
|
+
hash?: Buffer;
|
|
74
|
+
redeem?: ScriptRedeem;
|
|
75
|
+
}
|
|
76
|
+
export interface P2TRPayment extends BasePayment {
|
|
77
|
+
name: PaymentType.P2TR;
|
|
78
|
+
pubkey?: Buffer;
|
|
79
|
+
internalPubkey?: Buffer;
|
|
28
80
|
hash?: Buffer;
|
|
29
|
-
redeem?: Payment;
|
|
30
|
-
redeemVersion?: number;
|
|
31
81
|
scriptTree?: Taptree;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
82
|
+
signature?: Buffer;
|
|
83
|
+
redeemVersion?: number;
|
|
84
|
+
redeem?: ScriptRedeem;
|
|
85
|
+
}
|
|
86
|
+
export interface P2OPPayment extends BasePayment {
|
|
87
|
+
name: PaymentType.P2OP;
|
|
35
88
|
program?: Buffer;
|
|
36
|
-
deploymentVersion
|
|
89
|
+
deploymentVersion: number | undefined;
|
|
37
90
|
hash160?: Buffer;
|
|
38
91
|
}
|
|
39
|
-
export
|
|
40
|
-
|
|
92
|
+
export interface EmbedPayment extends BasePayment {
|
|
93
|
+
name: PaymentType.Embed;
|
|
94
|
+
data: Buffer[];
|
|
95
|
+
}
|
|
96
|
+
export type Payment = P2PKPayment | P2PKHPayment | P2SHPayment | P2MSPayment | P2WPKHPayment | P2WSHPayment | P2TRPayment | P2OPPayment | EmbedPayment | ScriptRedeem;
|
|
97
|
+
export type PaymentCreator = <T extends BasePayment>(a: T, opts?: PaymentOpts) => T;
|
|
41
98
|
export interface PaymentOpts {
|
|
42
99
|
validate?: boolean;
|
|
43
100
|
allowIncomplete?: boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function prop(object:
|
|
1
|
+
export declare function prop<T extends {}>(object: T, name: string, f: () => T[keyof T]): void;
|
|
2
2
|
export declare function value<T>(f: () => T): () => T;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2ms(a:
|
|
1
|
+
import { P2MSPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2ms(a: Omit<P2MSPayment, 'name'>, opts?: PaymentOpts): P2MSPayment;
|
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BasePayment, P2OPPayment, PaymentOpts, PaymentType } from './index.js';
|
|
2
|
+
interface P2OPBase extends BasePayment {
|
|
3
|
+
name: PaymentType.P2OP;
|
|
4
|
+
}
|
|
5
|
+
interface P2OP_fromOutput extends P2OPBase {
|
|
6
|
+
output: Buffer;
|
|
7
|
+
program?: undefined;
|
|
8
|
+
deploymentVersion?: undefined;
|
|
9
|
+
hash160?: undefined;
|
|
10
|
+
}
|
|
11
|
+
interface P2OP_fromProgram extends P2OPBase {
|
|
12
|
+
program: Buffer;
|
|
13
|
+
output?: undefined;
|
|
14
|
+
deploymentVersion?: never;
|
|
15
|
+
hash160?: never;
|
|
16
|
+
}
|
|
17
|
+
interface P2OP_fromParts extends P2OPBase {
|
|
18
|
+
deploymentVersion: number;
|
|
19
|
+
hash160: Buffer;
|
|
20
|
+
output?: undefined;
|
|
21
|
+
program?: undefined;
|
|
22
|
+
}
|
|
23
|
+
export type P2OPPaymentParams = P2OP_fromOutput | P2OP_fromProgram | P2OP_fromParts;
|
|
24
|
+
export declare function p2op(a: Omit<P2OPPaymentParams, 'name'>, opts?: PaymentOpts): P2OPPayment;
|
|
25
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2pk(a:
|
|
1
|
+
import { P2PKPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2pk(a: Omit<P2PKPayment, 'name'>, opts?: PaymentOpts): P2PKPayment;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2pkh(a:
|
|
1
|
+
import { P2PKHPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2pkh(a: Omit<P2PKHPayment, 'name'>, opts?: PaymentOpts): P2PKHPayment;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2sh(a:
|
|
1
|
+
import { P2SHPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2sh(a: Omit<P2SHPayment, 'name'>, opts?: PaymentOpts): P2SHPayment;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2tr(a:
|
|
1
|
+
import { P2TRPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2tr(a: Omit<P2TRPayment, 'name'>, opts?: PaymentOpts): P2TRPayment;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2wpkh(a:
|
|
1
|
+
import { P2WPKHPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2wpkh(a: Omit<P2WPKHPayment, 'name'>, opts?: PaymentOpts): P2WPKHPayment;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2wsh(a:
|
|
1
|
+
import { P2WSHPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2wsh(a: Omit<P2WSHPayment, 'name'>, opts?: PaymentOpts): P2WSHPayment;
|
package/build/address.js
CHANGED
package/build/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export { OPS as opcodes } from './ops.js';
|
|
|
17
17
|
export { Transaction } from './transaction.js';
|
|
18
18
|
export { Network } from './networks.js';
|
|
19
19
|
export { initEccLib } from './ecc_lib.js';
|
|
20
|
-
export { Payment, PaymentCreator, PaymentOpts, Stack, StackElement } from './payments/index.js';
|
|
20
|
+
export { Payment, PaymentCreator, PaymentOpts, Stack, StackElement, P2WSHPayment, P2PKPayment, BasePayment, P2SHPayment, P2TRPayment, P2WPKHPayment, P2PKHPayment, P2MSPayment, EmbedPayment, P2OPPayment, P2OPPaymentParams, StackFunction, PaymentType, } from './payments/index.js';
|
|
21
21
|
export { Input as TxInput, Output as TxOutput } from './transaction.js';
|
|
22
22
|
export interface PsbtInput extends _PsbtInput {
|
|
23
23
|
}
|
package/build/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from './psbt.js';
|
|
|
15
15
|
export { OPS as opcodes } from './ops.js';
|
|
16
16
|
export { Transaction } from './transaction.js';
|
|
17
17
|
export { initEccLib } from './ecc_lib.js';
|
|
18
|
+
export { PaymentType, } from './payments/index.js';
|
|
18
19
|
export * from './psbt/bip371.js';
|
|
19
20
|
export * from './address.js';
|
|
20
21
|
export * from './bufferutils.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2data(a:
|
|
1
|
+
import { EmbedPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2data(a: Omit<EmbedPayment, 'name'>, opts?: PaymentOpts): EmbedPayment;
|
package/build/payments/embed.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
2
2
|
import * as bscript from '../script.js';
|
|
3
3
|
import { stacksEqual, typeforce as typef } from '../types.js';
|
|
4
|
+
import { PaymentType } from './index.js';
|
|
4
5
|
import * as lazy from './lazy.js';
|
|
5
6
|
const OPS = bscript.OPS;
|
|
6
7
|
export function p2data(a, opts) {
|
|
@@ -13,7 +14,7 @@ export function p2data(a, opts) {
|
|
|
13
14
|
data: typef.maybe(typef.arrayOf(typef.Buffer)),
|
|
14
15
|
}, a);
|
|
15
16
|
const network = a.network || BITCOIN_NETWORK;
|
|
16
|
-
const o = { name:
|
|
17
|
+
const o = { name: PaymentType.Embed, network, data: [] };
|
|
17
18
|
lazy.prop(o, 'output', () => {
|
|
18
19
|
if (!a.data)
|
|
19
20
|
return;
|
|
@@ -22,7 +23,11 @@ export function p2data(a, opts) {
|
|
|
22
23
|
lazy.prop(o, 'data', () => {
|
|
23
24
|
if (!a.output)
|
|
24
25
|
return;
|
|
25
|
-
|
|
26
|
+
const script = bscript.decompile(a.output);
|
|
27
|
+
if (script === null || script === undefined) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
return script.slice(1);
|
|
26
31
|
});
|
|
27
32
|
if (opts.validate) {
|
|
28
33
|
if (a.output) {
|
|
@@ -11,33 +11,90 @@ export * from './p2tr.js';
|
|
|
11
11
|
export * from './p2wpkh.js';
|
|
12
12
|
export * from './p2wsh.js';
|
|
13
13
|
export * from './p2op.js';
|
|
14
|
-
export
|
|
15
|
-
|
|
14
|
+
export declare enum PaymentType {
|
|
15
|
+
P2PK = "p2pk",
|
|
16
|
+
P2PKH = "p2pkh",
|
|
17
|
+
P2SH = "p2sh",
|
|
18
|
+
P2MS = "p2ms",
|
|
19
|
+
P2WPKH = "p2wpkh",
|
|
20
|
+
P2WSH = "p2wsh",
|
|
21
|
+
P2TR = "p2tr",
|
|
22
|
+
P2OP = "p2op",
|
|
23
|
+
Embed = "embed",
|
|
24
|
+
ScriptRedeem = "scriptRedeem"
|
|
25
|
+
}
|
|
26
|
+
export interface BasePayment {
|
|
27
|
+
name?: PaymentType;
|
|
16
28
|
network?: Network;
|
|
17
29
|
output?: Buffer;
|
|
18
|
-
|
|
30
|
+
input?: Buffer;
|
|
31
|
+
address?: string;
|
|
32
|
+
witness?: Buffer[];
|
|
33
|
+
redeem?: ScriptRedeem;
|
|
34
|
+
useHybrid?: boolean;
|
|
35
|
+
useUncompressed?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface ScriptRedeem extends BasePayment {
|
|
38
|
+
output?: Buffer;
|
|
39
|
+
redeemVersion?: number;
|
|
40
|
+
network?: Network;
|
|
41
|
+
}
|
|
42
|
+
export interface P2PKPayment extends BasePayment {
|
|
43
|
+
name: PaymentType.P2PK;
|
|
44
|
+
pubkey?: Buffer;
|
|
45
|
+
signature?: Buffer;
|
|
46
|
+
}
|
|
47
|
+
export interface P2PKHPayment extends BasePayment {
|
|
48
|
+
name: PaymentType.P2PKH;
|
|
49
|
+
hash?: Buffer;
|
|
50
|
+
pubkey?: Buffer;
|
|
51
|
+
signature?: Buffer;
|
|
52
|
+
}
|
|
53
|
+
export interface P2SHPayment extends BasePayment {
|
|
54
|
+
name: PaymentType.P2SH;
|
|
55
|
+
hash?: Buffer;
|
|
56
|
+
signatures?: Buffer[];
|
|
57
|
+
}
|
|
58
|
+
export interface P2MSPayment extends BasePayment {
|
|
59
|
+
name: PaymentType.P2MS;
|
|
19
60
|
m?: number;
|
|
20
61
|
n?: number;
|
|
21
62
|
pubkeys?: Buffer[];
|
|
22
|
-
input?: Buffer;
|
|
23
63
|
signatures?: Buffer[];
|
|
24
|
-
|
|
64
|
+
}
|
|
65
|
+
export interface P2WPKHPayment extends BasePayment {
|
|
66
|
+
name: PaymentType.P2WPKH;
|
|
67
|
+
hash?: Buffer;
|
|
25
68
|
pubkey?: Buffer;
|
|
26
69
|
signature?: Buffer;
|
|
27
|
-
|
|
70
|
+
}
|
|
71
|
+
export interface P2WSHPayment extends BasePayment {
|
|
72
|
+
name: PaymentType.P2WSH;
|
|
73
|
+
hash?: Buffer;
|
|
74
|
+
redeem?: ScriptRedeem;
|
|
75
|
+
}
|
|
76
|
+
export interface P2TRPayment extends BasePayment {
|
|
77
|
+
name: PaymentType.P2TR;
|
|
78
|
+
pubkey?: Buffer;
|
|
79
|
+
internalPubkey?: Buffer;
|
|
28
80
|
hash?: Buffer;
|
|
29
|
-
redeem?: Payment;
|
|
30
|
-
redeemVersion?: number;
|
|
31
81
|
scriptTree?: Taptree;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
82
|
+
signature?: Buffer;
|
|
83
|
+
redeemVersion?: number;
|
|
84
|
+
redeem?: ScriptRedeem;
|
|
85
|
+
}
|
|
86
|
+
export interface P2OPPayment extends BasePayment {
|
|
87
|
+
name: PaymentType.P2OP;
|
|
35
88
|
program?: Buffer;
|
|
36
|
-
deploymentVersion
|
|
89
|
+
deploymentVersion: number | undefined;
|
|
37
90
|
hash160?: Buffer;
|
|
38
91
|
}
|
|
39
|
-
export
|
|
40
|
-
|
|
92
|
+
export interface EmbedPayment extends BasePayment {
|
|
93
|
+
name: PaymentType.Embed;
|
|
94
|
+
data: Buffer[];
|
|
95
|
+
}
|
|
96
|
+
export type Payment = P2PKPayment | P2PKHPayment | P2SHPayment | P2MSPayment | P2WPKHPayment | P2WSHPayment | P2TRPayment | P2OPPayment | EmbedPayment | ScriptRedeem;
|
|
97
|
+
export type PaymentCreator = <T extends BasePayment>(a: T, opts?: PaymentOpts) => T;
|
|
41
98
|
export interface PaymentOpts {
|
|
42
99
|
validate?: boolean;
|
|
43
100
|
allowIncomplete?: boolean;
|
package/build/payments/index.js
CHANGED
|
@@ -9,3 +9,16 @@ export * from './p2tr.js';
|
|
|
9
9
|
export * from './p2wpkh.js';
|
|
10
10
|
export * from './p2wsh.js';
|
|
11
11
|
export * from './p2op.js';
|
|
12
|
+
export var PaymentType;
|
|
13
|
+
(function (PaymentType) {
|
|
14
|
+
PaymentType["P2PK"] = "p2pk";
|
|
15
|
+
PaymentType["P2PKH"] = "p2pkh";
|
|
16
|
+
PaymentType["P2SH"] = "p2sh";
|
|
17
|
+
PaymentType["P2MS"] = "p2ms";
|
|
18
|
+
PaymentType["P2WPKH"] = "p2wpkh";
|
|
19
|
+
PaymentType["P2WSH"] = "p2wsh";
|
|
20
|
+
PaymentType["P2TR"] = "p2tr";
|
|
21
|
+
PaymentType["P2OP"] = "p2op";
|
|
22
|
+
PaymentType["Embed"] = "embed";
|
|
23
|
+
PaymentType["ScriptRedeem"] = "scriptRedeem";
|
|
24
|
+
})(PaymentType || (PaymentType = {}));
|
package/build/payments/lazy.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function prop(object:
|
|
1
|
+
export declare function prop<T extends {}>(object: T, name: string, f: () => T[keyof T]): void;
|
|
2
2
|
export declare function value<T>(f: () => T): () => T;
|
package/build/payments/p2ms.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2ms(a:
|
|
1
|
+
import { P2MSPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2ms(a: Omit<P2MSPayment, 'name'>, opts?: PaymentOpts): P2MSPayment;
|
package/build/payments/p2ms.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
2
2
|
import * as bscript from '../script.js';
|
|
3
3
|
import { isPoint, stacksEqual, typeforce as typef } from '../types.js';
|
|
4
|
+
import { PaymentType } from './index.js';
|
|
4
5
|
import * as lazy from './lazy.js';
|
|
5
6
|
const OPS = bscript.OPS;
|
|
6
7
|
const OP_INT_BASE = OPS.OP_RESERVED;
|
|
@@ -22,7 +23,10 @@ export function p2ms(a, opts) {
|
|
|
22
23
|
input: typef.maybe(typef.Buffer),
|
|
23
24
|
}, a);
|
|
24
25
|
const network = a.network || BITCOIN_NETWORK;
|
|
25
|
-
const o = {
|
|
26
|
+
const o = {
|
|
27
|
+
network,
|
|
28
|
+
name: PaymentType.P2MS,
|
|
29
|
+
};
|
|
26
30
|
let chunks = [];
|
|
27
31
|
let decoded = false;
|
|
28
32
|
function decode(output) {
|
|
@@ -63,7 +67,10 @@ export function p2ms(a, opts) {
|
|
|
63
67
|
lazy.prop(o, 'signatures', () => {
|
|
64
68
|
if (!a.input)
|
|
65
69
|
return;
|
|
66
|
-
|
|
70
|
+
const decompiled = bscript.decompile(a.input);
|
|
71
|
+
if (decompiled === null || decompiled === undefined)
|
|
72
|
+
return;
|
|
73
|
+
return decompiled.slice(1);
|
|
67
74
|
});
|
|
68
75
|
lazy.prop(o, 'input', () => {
|
|
69
76
|
if (!a.signatures)
|
package/build/payments/p2op.d.ts
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BasePayment, P2OPPayment, PaymentOpts, PaymentType } from './index.js';
|
|
2
|
+
interface P2OPBase extends BasePayment {
|
|
3
|
+
name: PaymentType.P2OP;
|
|
4
|
+
}
|
|
5
|
+
interface P2OP_fromOutput extends P2OPBase {
|
|
6
|
+
output: Buffer;
|
|
7
|
+
program?: undefined;
|
|
8
|
+
deploymentVersion?: undefined;
|
|
9
|
+
hash160?: undefined;
|
|
10
|
+
}
|
|
11
|
+
interface P2OP_fromProgram extends P2OPBase {
|
|
12
|
+
program: Buffer;
|
|
13
|
+
output?: undefined;
|
|
14
|
+
deploymentVersion?: never;
|
|
15
|
+
hash160?: never;
|
|
16
|
+
}
|
|
17
|
+
interface P2OP_fromParts extends P2OPBase {
|
|
18
|
+
deploymentVersion: number;
|
|
19
|
+
hash160: Buffer;
|
|
20
|
+
output?: undefined;
|
|
21
|
+
program?: undefined;
|
|
22
|
+
}
|
|
23
|
+
export type P2OPPaymentParams = P2OP_fromOutput | P2OP_fromProgram | P2OP_fromParts;
|
|
24
|
+
export declare function p2op(a: Omit<P2OPPaymentParams, 'name'>, opts?: PaymentOpts): P2OPPayment;
|
|
25
|
+
export {};
|
package/build/payments/p2op.js
CHANGED
|
@@ -5,13 +5,18 @@ import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
|
5
5
|
import * as bscript from '../script.js';
|
|
6
6
|
import { typeforce as typef } from '../types.js';
|
|
7
7
|
import * as lazy from './lazy.js';
|
|
8
|
+
import { PaymentType } from './index.js';
|
|
8
9
|
const OPS = bscript.OPS;
|
|
9
10
|
const P2OP_WITNESS_VERSION = 0x10;
|
|
10
11
|
const MIN_SIZE = 2;
|
|
11
12
|
const MAX_SIZE = 40;
|
|
12
13
|
export function p2op(a, opts) {
|
|
13
|
-
if (!a.address &&
|
|
14
|
-
|
|
14
|
+
if (!a.address &&
|
|
15
|
+
!a.output &&
|
|
16
|
+
!a.program &&
|
|
17
|
+
(typeof a.deploymentVersion === 'undefined' || !a.hash160)) {
|
|
18
|
+
throw new TypeError('At least one of address, output or program must be provided');
|
|
19
|
+
}
|
|
15
20
|
opts = Object.assign({ validate: true }, opts || {});
|
|
16
21
|
typef({
|
|
17
22
|
address: typef.maybe(typef.String),
|
|
@@ -21,12 +26,29 @@ export function p2op(a, opts) {
|
|
|
21
26
|
deploymentVersion: typef.maybe(typef.Number),
|
|
22
27
|
hash160: typef.maybe(typef.BufferN(20)),
|
|
23
28
|
}, a);
|
|
29
|
+
const makeProgramFromParts = () => {
|
|
30
|
+
if (typeof a.deploymentVersion !== 'undefined' && typeof a.hash160 !== 'undefined') {
|
|
31
|
+
if (a.hash160.length !== 20)
|
|
32
|
+
throw new TypeError('hash160 must be exactly 20 bytes');
|
|
33
|
+
if (a.deploymentVersion < 0 || a.deploymentVersion > 0xff)
|
|
34
|
+
throw new TypeError('deploymentVersion must fit in one byte');
|
|
35
|
+
return Buffer.concat([Buffer.of(a.deploymentVersion), a.hash160]);
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
};
|
|
24
39
|
const _address = lazy.value(() => fromBech32(a.address));
|
|
25
40
|
const network = a.network || BITCOIN_NETWORK;
|
|
26
|
-
const o = {
|
|
41
|
+
const o = {
|
|
42
|
+
name: PaymentType.P2OP,
|
|
43
|
+
network,
|
|
44
|
+
deploymentVersion: 0,
|
|
45
|
+
};
|
|
27
46
|
lazy.prop(o, 'program', () => {
|
|
28
47
|
if (a.program)
|
|
29
48
|
return a.program;
|
|
49
|
+
const fromParts = makeProgramFromParts();
|
|
50
|
+
if (fromParts)
|
|
51
|
+
return fromParts;
|
|
30
52
|
if (a.output) {
|
|
31
53
|
if (a.output[0] !== OPS.OP_16)
|
|
32
54
|
throw new TypeError('Invalid P2OP script');
|
|
@@ -91,6 +113,9 @@ export function p2op(a, opts) {
|
|
|
91
113
|
throw new TypeError('Program mismatch');
|
|
92
114
|
prog = a.program;
|
|
93
115
|
}
|
|
116
|
+
if (!prog.length && a.deploymentVersion !== undefined && a.hash160) {
|
|
117
|
+
prog = makeProgramFromParts();
|
|
118
|
+
}
|
|
94
119
|
if (a.output) {
|
|
95
120
|
const outProg = o.program;
|
|
96
121
|
if (prog.length && !prog.equals(outProg))
|
|
@@ -98,7 +123,7 @@ export function p2op(a, opts) {
|
|
|
98
123
|
prog = outProg;
|
|
99
124
|
}
|
|
100
125
|
if (prog.length < MIN_SIZE || prog.length > MAX_SIZE)
|
|
101
|
-
throw new TypeError(
|
|
126
|
+
throw new TypeError(`Witness program must be 2–40 bytes. Was ${prog.length} bytes`);
|
|
102
127
|
if (a.deploymentVersion !== undefined && a.deploymentVersion !== prog[0])
|
|
103
128
|
throw new TypeError('deploymentVersion mismatch');
|
|
104
129
|
if (a.hash160 && !a.hash160.equals(prog.slice(1)))
|
package/build/payments/p2pk.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2pk(a:
|
|
1
|
+
import { P2PKPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2pk(a: Omit<P2PKPayment, 'name'>, opts?: PaymentOpts): P2PKPayment;
|
package/build/payments/p2pk.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
2
2
|
import * as bscript from '../script.js';
|
|
3
3
|
import { isPoint, typeforce as typef } from '../types.js';
|
|
4
|
+
import { PaymentType } from './index.js';
|
|
4
5
|
import * as lazy from './lazy.js';
|
|
5
6
|
const OPS = bscript.OPS;
|
|
6
7
|
export function p2pk(a, opts) {
|
|
@@ -18,7 +19,11 @@ export function p2pk(a, opts) {
|
|
|
18
19
|
return bscript.decompile(a.input);
|
|
19
20
|
});
|
|
20
21
|
const network = a.network || BITCOIN_NETWORK;
|
|
21
|
-
const o = {
|
|
22
|
+
const o = {
|
|
23
|
+
name: PaymentType.P2PK,
|
|
24
|
+
network,
|
|
25
|
+
pubkey: undefined,
|
|
26
|
+
};
|
|
22
27
|
lazy.prop(o, 'output', () => {
|
|
23
28
|
if (!a.pubkey)
|
|
24
29
|
return;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2pkh(a:
|
|
1
|
+
import { P2PKHPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2pkh(a: Omit<P2PKHPayment, 'name'>, opts?: PaymentOpts): P2PKHPayment;
|
package/build/payments/p2pkh.js
CHANGED
|
@@ -3,6 +3,7 @@ import * as bcrypto from '../crypto.js';
|
|
|
3
3
|
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
4
4
|
import * as bscript from '../script.js';
|
|
5
5
|
import { isPoint, typeforce as typef } from '../types.js';
|
|
6
|
+
import { PaymentType } from './index.js';
|
|
6
7
|
import * as lazy from './lazy.js';
|
|
7
8
|
import { decompressPublicKey } from '../psbt/psbtutils.js';
|
|
8
9
|
const OPS = bscript.OPS;
|
|
@@ -30,7 +31,11 @@ export function p2pkh(a, opts) {
|
|
|
30
31
|
return bscript.decompile(a.input);
|
|
31
32
|
});
|
|
32
33
|
const network = a.network || BITCOIN_NETWORK;
|
|
33
|
-
const o = {
|
|
34
|
+
const o = {
|
|
35
|
+
name: PaymentType.P2PKH,
|
|
36
|
+
network,
|
|
37
|
+
hash: undefined,
|
|
38
|
+
};
|
|
34
39
|
lazy.prop(o, 'address', () => {
|
|
35
40
|
if (!o.hash)
|
|
36
41
|
return;
|
package/build/payments/p2sh.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2sh(a:
|
|
1
|
+
import { P2SHPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2sh(a: Omit<P2SHPayment, 'name'>, opts?: PaymentOpts): P2SHPayment;
|
package/build/payments/p2sh.js
CHANGED
|
@@ -3,6 +3,7 @@ import * as bcrypto from '../crypto.js';
|
|
|
3
3
|
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
4
4
|
import * as bscript from '../script.js';
|
|
5
5
|
import { stacksEqual, typeforce as typef } from '../types.js';
|
|
6
|
+
import { PaymentType } from './index.js';
|
|
6
7
|
import * as lazy from './lazy.js';
|
|
7
8
|
const OPS = bscript.OPS;
|
|
8
9
|
export function p2sh(a, opts) {
|
|
@@ -28,7 +29,10 @@ export function p2sh(a, opts) {
|
|
|
28
29
|
if (!network) {
|
|
29
30
|
network = (a.redeem && a.redeem.network) || BITCOIN_NETWORK;
|
|
30
31
|
}
|
|
31
|
-
const o = {
|
|
32
|
+
const o = {
|
|
33
|
+
network,
|
|
34
|
+
name: PaymentType.P2SH
|
|
35
|
+
};
|
|
32
36
|
const _address = lazy.value(() => {
|
|
33
37
|
const payload = Buffer.from(bs58check.default.decode(a.address));
|
|
34
38
|
const version = payload.readUInt8(0);
|
package/build/payments/p2tr.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2tr(a:
|
|
1
|
+
import { P2TRPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2tr(a: Omit<P2TRPayment, 'name'>, opts?: PaymentOpts): P2TRPayment;
|
package/build/payments/p2tr.js
CHANGED
|
@@ -6,6 +6,7 @@ import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
|
6
6
|
import * as bscript from '../script.js';
|
|
7
7
|
import { isTaptree, stacksEqual, TAPLEAF_VERSION_MASK, typeforce as typef } from '../types.js';
|
|
8
8
|
import { findScriptPath, LEAF_VERSION_TAPSCRIPT, rootHashFromPath, tapleafHash, toHashTree, tweakKey, } from './bip341.js';
|
|
9
|
+
import { PaymentType } from './index.js';
|
|
9
10
|
import * as lazy from './lazy.js';
|
|
10
11
|
const OPS = bscript.OPS;
|
|
11
12
|
const TAPROOT_WITNESS_VERSION = 0x01;
|
|
@@ -55,7 +56,10 @@ export function p2tr(a, opts) {
|
|
|
55
56
|
return;
|
|
56
57
|
});
|
|
57
58
|
const network = a.network || BITCOIN_NETWORK;
|
|
58
|
-
const o = {
|
|
59
|
+
const o = {
|
|
60
|
+
name: PaymentType.P2TR,
|
|
61
|
+
network,
|
|
62
|
+
};
|
|
59
63
|
lazy.prop(o, 'address', () => {
|
|
60
64
|
if (!o.pubkey)
|
|
61
65
|
return;
|
|
@@ -78,7 +82,7 @@ export function p2tr(a, opts) {
|
|
|
78
82
|
});
|
|
79
83
|
return rootHashFromPath(controlBlock, leafHash);
|
|
80
84
|
}
|
|
81
|
-
return
|
|
85
|
+
return undefined;
|
|
82
86
|
});
|
|
83
87
|
lazy.prop(o, 'output', () => {
|
|
84
88
|
if (!o.pubkey)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function p2wpkh(a:
|
|
1
|
+
import { P2WPKHPayment, PaymentOpts } from './index.js';
|
|
2
|
+
export declare function p2wpkh(a: Omit<P2WPKHPayment, 'name'>, opts?: PaymentOpts): P2WPKHPayment;
|