@btc-vision/bitcoin 6.4.3 → 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/index.d.ts +22 -10
- package/browser/payments/p2op.d.ts +2 -2
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -0
- package/build/payments/embed.js +2 -1
- package/build/payments/index.d.ts +22 -10
- package/build/payments/index.js +13 -0
- package/build/payments/p2ms.js +2 -1
- package/build/payments/p2op.d.ts +2 -2
- package/build/payments/p2op.js +25 -4
- package/build/payments/p2pk.js +2 -1
- package/build/payments/p2pkh.js +2 -1
- package/build/payments/p2sh.js +2 -2
- package/build/payments/p2tr.js +2 -1
- package/build/payments/p2wpkh.js +3 -3
- package/build/payments/p2wsh.js +2 -2
- package/build/psbt.js +2 -1
- package/package.json +1 -1
- package/src/index.ts +20 -1
- package/src/payments/embed.ts +2 -2
- package/src/payments/index.ts +23 -10
- package/src/payments/p2ms.ts +2 -2
- package/src/payments/p2op.ts +195 -170
- package/src/payments/p2pk.ts +2 -2
- package/src/payments/p2pkh.ts +2 -2
- package/src/payments/p2sh.ts +2 -3
- package/src/payments/p2tr.ts +2 -2
- package/src/payments/p2wpkh.ts +3 -4
- package/src/payments/p2wsh.ts +2 -3
- package/src/psbt.ts +5 -4
|
@@ -11,8 +11,20 @@ export * from './p2tr.js';
|
|
|
11
11
|
export * from './p2wpkh.js';
|
|
12
12
|
export * from './p2wsh.js';
|
|
13
13
|
export * from './p2op.js';
|
|
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
|
+
}
|
|
14
26
|
export interface BasePayment {
|
|
15
|
-
name?:
|
|
27
|
+
name?: PaymentType;
|
|
16
28
|
network?: Network;
|
|
17
29
|
output?: Buffer;
|
|
18
30
|
input?: Buffer;
|
|
@@ -28,41 +40,41 @@ export interface ScriptRedeem extends BasePayment {
|
|
|
28
40
|
network?: Network;
|
|
29
41
|
}
|
|
30
42
|
export interface P2PKPayment extends BasePayment {
|
|
31
|
-
name:
|
|
43
|
+
name: PaymentType.P2PK;
|
|
32
44
|
pubkey?: Buffer;
|
|
33
45
|
signature?: Buffer;
|
|
34
46
|
}
|
|
35
47
|
export interface P2PKHPayment extends BasePayment {
|
|
36
|
-
name:
|
|
48
|
+
name: PaymentType.P2PKH;
|
|
37
49
|
hash?: Buffer;
|
|
38
50
|
pubkey?: Buffer;
|
|
39
51
|
signature?: Buffer;
|
|
40
52
|
}
|
|
41
53
|
export interface P2SHPayment extends BasePayment {
|
|
42
|
-
name:
|
|
54
|
+
name: PaymentType.P2SH;
|
|
43
55
|
hash?: Buffer;
|
|
44
56
|
signatures?: Buffer[];
|
|
45
57
|
}
|
|
46
58
|
export interface P2MSPayment extends BasePayment {
|
|
47
|
-
name:
|
|
59
|
+
name: PaymentType.P2MS;
|
|
48
60
|
m?: number;
|
|
49
61
|
n?: number;
|
|
50
62
|
pubkeys?: Buffer[];
|
|
51
63
|
signatures?: Buffer[];
|
|
52
64
|
}
|
|
53
65
|
export interface P2WPKHPayment extends BasePayment {
|
|
54
|
-
name:
|
|
66
|
+
name: PaymentType.P2WPKH;
|
|
55
67
|
hash?: Buffer;
|
|
56
68
|
pubkey?: Buffer;
|
|
57
69
|
signature?: Buffer;
|
|
58
70
|
}
|
|
59
71
|
export interface P2WSHPayment extends BasePayment {
|
|
60
|
-
name:
|
|
72
|
+
name: PaymentType.P2WSH;
|
|
61
73
|
hash?: Buffer;
|
|
62
74
|
redeem?: ScriptRedeem;
|
|
63
75
|
}
|
|
64
76
|
export interface P2TRPayment extends BasePayment {
|
|
65
|
-
name:
|
|
77
|
+
name: PaymentType.P2TR;
|
|
66
78
|
pubkey?: Buffer;
|
|
67
79
|
internalPubkey?: Buffer;
|
|
68
80
|
hash?: Buffer;
|
|
@@ -72,13 +84,13 @@ export interface P2TRPayment extends BasePayment {
|
|
|
72
84
|
redeem?: ScriptRedeem;
|
|
73
85
|
}
|
|
74
86
|
export interface P2OPPayment extends BasePayment {
|
|
75
|
-
name:
|
|
87
|
+
name: PaymentType.P2OP;
|
|
76
88
|
program?: Buffer;
|
|
77
89
|
deploymentVersion: number | undefined;
|
|
78
90
|
hash160?: Buffer;
|
|
79
91
|
}
|
|
80
92
|
export interface EmbedPayment extends BasePayment {
|
|
81
|
-
name:
|
|
93
|
+
name: PaymentType.Embed;
|
|
82
94
|
data: Buffer[];
|
|
83
95
|
}
|
|
84
96
|
export type Payment = P2PKPayment | P2PKHPayment | P2SHPayment | P2MSPayment | P2WPKHPayment | P2WSHPayment | P2TRPayment | P2OPPayment | EmbedPayment | ScriptRedeem;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BasePayment, P2OPPayment, PaymentOpts } from './index.js';
|
|
1
|
+
import { BasePayment, P2OPPayment, PaymentOpts, PaymentType } from './index.js';
|
|
2
2
|
interface P2OPBase extends BasePayment {
|
|
3
|
-
name:
|
|
3
|
+
name: PaymentType.P2OP;
|
|
4
4
|
}
|
|
5
5
|
interface P2OP_fromOutput extends P2OPBase {
|
|
6
6
|
output: Buffer;
|
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';
|
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;
|
|
@@ -11,8 +11,20 @@ export * from './p2tr.js';
|
|
|
11
11
|
export * from './p2wpkh.js';
|
|
12
12
|
export * from './p2wsh.js';
|
|
13
13
|
export * from './p2op.js';
|
|
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
|
+
}
|
|
14
26
|
export interface BasePayment {
|
|
15
|
-
name?:
|
|
27
|
+
name?: PaymentType;
|
|
16
28
|
network?: Network;
|
|
17
29
|
output?: Buffer;
|
|
18
30
|
input?: Buffer;
|
|
@@ -28,41 +40,41 @@ export interface ScriptRedeem extends BasePayment {
|
|
|
28
40
|
network?: Network;
|
|
29
41
|
}
|
|
30
42
|
export interface P2PKPayment extends BasePayment {
|
|
31
|
-
name:
|
|
43
|
+
name: PaymentType.P2PK;
|
|
32
44
|
pubkey?: Buffer;
|
|
33
45
|
signature?: Buffer;
|
|
34
46
|
}
|
|
35
47
|
export interface P2PKHPayment extends BasePayment {
|
|
36
|
-
name:
|
|
48
|
+
name: PaymentType.P2PKH;
|
|
37
49
|
hash?: Buffer;
|
|
38
50
|
pubkey?: Buffer;
|
|
39
51
|
signature?: Buffer;
|
|
40
52
|
}
|
|
41
53
|
export interface P2SHPayment extends BasePayment {
|
|
42
|
-
name:
|
|
54
|
+
name: PaymentType.P2SH;
|
|
43
55
|
hash?: Buffer;
|
|
44
56
|
signatures?: Buffer[];
|
|
45
57
|
}
|
|
46
58
|
export interface P2MSPayment extends BasePayment {
|
|
47
|
-
name:
|
|
59
|
+
name: PaymentType.P2MS;
|
|
48
60
|
m?: number;
|
|
49
61
|
n?: number;
|
|
50
62
|
pubkeys?: Buffer[];
|
|
51
63
|
signatures?: Buffer[];
|
|
52
64
|
}
|
|
53
65
|
export interface P2WPKHPayment extends BasePayment {
|
|
54
|
-
name:
|
|
66
|
+
name: PaymentType.P2WPKH;
|
|
55
67
|
hash?: Buffer;
|
|
56
68
|
pubkey?: Buffer;
|
|
57
69
|
signature?: Buffer;
|
|
58
70
|
}
|
|
59
71
|
export interface P2WSHPayment extends BasePayment {
|
|
60
|
-
name:
|
|
72
|
+
name: PaymentType.P2WSH;
|
|
61
73
|
hash?: Buffer;
|
|
62
74
|
redeem?: ScriptRedeem;
|
|
63
75
|
}
|
|
64
76
|
export interface P2TRPayment extends BasePayment {
|
|
65
|
-
name:
|
|
77
|
+
name: PaymentType.P2TR;
|
|
66
78
|
pubkey?: Buffer;
|
|
67
79
|
internalPubkey?: Buffer;
|
|
68
80
|
hash?: Buffer;
|
|
@@ -72,13 +84,13 @@ export interface P2TRPayment extends BasePayment {
|
|
|
72
84
|
redeem?: ScriptRedeem;
|
|
73
85
|
}
|
|
74
86
|
export interface P2OPPayment extends BasePayment {
|
|
75
|
-
name:
|
|
87
|
+
name: PaymentType.P2OP;
|
|
76
88
|
program?: Buffer;
|
|
77
89
|
deploymentVersion: number | undefined;
|
|
78
90
|
hash160?: Buffer;
|
|
79
91
|
}
|
|
80
92
|
export interface EmbedPayment extends BasePayment {
|
|
81
|
-
name:
|
|
93
|
+
name: PaymentType.Embed;
|
|
82
94
|
data: Buffer[];
|
|
83
95
|
}
|
|
84
96
|
export type Payment = P2PKPayment | P2PKHPayment | P2SHPayment | P2MSPayment | P2WPKHPayment | P2WSHPayment | P2TRPayment | P2OPPayment | EmbedPayment | ScriptRedeem;
|
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/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;
|
|
@@ -24,7 +25,7 @@ export function p2ms(a, opts) {
|
|
|
24
25
|
const network = a.network || BITCOIN_NETWORK;
|
|
25
26
|
const o = {
|
|
26
27
|
network,
|
|
27
|
-
name:
|
|
28
|
+
name: PaymentType.P2MS,
|
|
28
29
|
};
|
|
29
30
|
let chunks = [];
|
|
30
31
|
let decoded = false;
|
package/build/payments/p2op.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BasePayment, P2OPPayment, PaymentOpts } from './index.js';
|
|
1
|
+
import { BasePayment, P2OPPayment, PaymentOpts, PaymentType } from './index.js';
|
|
2
2
|
interface P2OPBase extends BasePayment {
|
|
3
|
-
name:
|
|
3
|
+
name: PaymentType.P2OP;
|
|
4
4
|
}
|
|
5
5
|
interface P2OP_fromOutput extends P2OPBase {
|
|
6
6
|
output: Buffer;
|
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,16 +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
41
|
const o = {
|
|
27
|
-
name:
|
|
42
|
+
name: PaymentType.P2OP,
|
|
28
43
|
network,
|
|
29
44
|
deploymentVersion: 0,
|
|
30
45
|
};
|
|
31
46
|
lazy.prop(o, 'program', () => {
|
|
32
47
|
if (a.program)
|
|
33
48
|
return a.program;
|
|
49
|
+
const fromParts = makeProgramFromParts();
|
|
50
|
+
if (fromParts)
|
|
51
|
+
return fromParts;
|
|
34
52
|
if (a.output) {
|
|
35
53
|
if (a.output[0] !== OPS.OP_16)
|
|
36
54
|
throw new TypeError('Invalid P2OP script');
|
|
@@ -95,6 +113,9 @@ export function p2op(a, opts) {
|
|
|
95
113
|
throw new TypeError('Program mismatch');
|
|
96
114
|
prog = a.program;
|
|
97
115
|
}
|
|
116
|
+
if (!prog.length && a.deploymentVersion !== undefined && a.hash160) {
|
|
117
|
+
prog = makeProgramFromParts();
|
|
118
|
+
}
|
|
98
119
|
if (a.output) {
|
|
99
120
|
const outProg = o.program;
|
|
100
121
|
if (prog.length && !prog.equals(outProg))
|
|
@@ -102,7 +123,7 @@ export function p2op(a, opts) {
|
|
|
102
123
|
prog = outProg;
|
|
103
124
|
}
|
|
104
125
|
if (prog.length < MIN_SIZE || prog.length > MAX_SIZE)
|
|
105
|
-
throw new TypeError(
|
|
126
|
+
throw new TypeError(`Witness program must be 2–40 bytes. Was ${prog.length} bytes`);
|
|
106
127
|
if (a.deploymentVersion !== undefined && a.deploymentVersion !== prog[0])
|
|
107
128
|
throw new TypeError('deploymentVersion mismatch');
|
|
108
129
|
if (a.hash160 && !a.hash160.equals(prog.slice(1)))
|
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) {
|
|
@@ -19,7 +20,7 @@ export function p2pk(a, opts) {
|
|
|
19
20
|
});
|
|
20
21
|
const network = a.network || BITCOIN_NETWORK;
|
|
21
22
|
const o = {
|
|
22
|
-
name:
|
|
23
|
+
name: PaymentType.P2PK,
|
|
23
24
|
network,
|
|
24
25
|
pubkey: undefined,
|
|
25
26
|
};
|
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;
|
|
@@ -31,7 +32,7 @@ export function p2pkh(a, opts) {
|
|
|
31
32
|
});
|
|
32
33
|
const network = a.network || BITCOIN_NETWORK;
|
|
33
34
|
const o = {
|
|
34
|
-
name:
|
|
35
|
+
name: PaymentType.P2PKH,
|
|
35
36
|
network,
|
|
36
37
|
hash: undefined,
|
|
37
38
|
};
|
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) {
|
|
@@ -30,8 +31,7 @@ export function p2sh(a, opts) {
|
|
|
30
31
|
}
|
|
31
32
|
const o = {
|
|
32
33
|
network,
|
|
33
|
-
name:
|
|
34
|
-
hash: undefined,
|
|
34
|
+
name: PaymentType.P2SH
|
|
35
35
|
};
|
|
36
36
|
const _address = lazy.value(() => {
|
|
37
37
|
const payload = Buffer.from(bs58check.default.decode(a.address));
|
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;
|
|
@@ -56,7 +57,7 @@ export function p2tr(a, opts) {
|
|
|
56
57
|
});
|
|
57
58
|
const network = a.network || BITCOIN_NETWORK;
|
|
58
59
|
const o = {
|
|
59
|
-
name:
|
|
60
|
+
name: PaymentType.P2TR,
|
|
60
61
|
network,
|
|
61
62
|
};
|
|
62
63
|
lazy.prop(o, 'address', () => {
|
package/build/payments/p2wpkh.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
|
const OPS = bscript.OPS;
|
|
8
9
|
const EMPTY_BUFFER = Buffer.alloc(0);
|
|
@@ -32,9 +33,8 @@ export function p2wpkh(a, opts) {
|
|
|
32
33
|
});
|
|
33
34
|
const network = a.network || BITCOIN_NETWORK;
|
|
34
35
|
const o = {
|
|
35
|
-
name:
|
|
36
|
-
network
|
|
37
|
-
hash: undefined,
|
|
36
|
+
name: PaymentType.P2WPKH,
|
|
37
|
+
network
|
|
38
38
|
};
|
|
39
39
|
lazy.prop(o, 'address', () => {
|
|
40
40
|
if (!o.hash)
|
package/build/payments/p2wsh.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, 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
|
const EMPTY_BUFFER = Buffer.alloc(0);
|
|
@@ -51,8 +52,7 @@ export function p2wsh(a, opts) {
|
|
|
51
52
|
}
|
|
52
53
|
const o = {
|
|
53
54
|
network,
|
|
54
|
-
name:
|
|
55
|
-
hash: undefined,
|
|
55
|
+
name: PaymentType.P2WSH
|
|
56
56
|
};
|
|
57
57
|
lazy.prop(o, 'address', () => {
|
|
58
58
|
if (!o.hash)
|
package/build/psbt.js
CHANGED
|
@@ -983,13 +983,14 @@ function checkSighashTypeAllowed(sighashType, sighashTypes) {
|
|
|
983
983
|
function getPayment(script, scriptType, partialSig) {
|
|
984
984
|
let payment;
|
|
985
985
|
switch (scriptType) {
|
|
986
|
-
case 'multisig':
|
|
986
|
+
case 'multisig': {
|
|
987
987
|
const sigs = getSortedSigs(script, partialSig);
|
|
988
988
|
payment = payments.p2ms({
|
|
989
989
|
output: script,
|
|
990
990
|
signatures: sigs,
|
|
991
991
|
});
|
|
992
992
|
break;
|
|
993
|
+
}
|
|
993
994
|
case 'pubkey':
|
|
994
995
|
payment = payments.p2pk({
|
|
995
996
|
output: script,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -35,7 +35,26 @@ export { Transaction } from './transaction.js';
|
|
|
35
35
|
export { Network } from './networks.js';
|
|
36
36
|
/** @hidden */
|
|
37
37
|
export { initEccLib } from './ecc_lib.js';
|
|
38
|
-
export {
|
|
38
|
+
export {
|
|
39
|
+
Payment,
|
|
40
|
+
PaymentCreator,
|
|
41
|
+
PaymentOpts,
|
|
42
|
+
Stack,
|
|
43
|
+
StackElement,
|
|
44
|
+
P2WSHPayment,
|
|
45
|
+
P2PKPayment,
|
|
46
|
+
BasePayment,
|
|
47
|
+
P2SHPayment,
|
|
48
|
+
P2TRPayment,
|
|
49
|
+
P2WPKHPayment,
|
|
50
|
+
P2PKHPayment,
|
|
51
|
+
P2MSPayment,
|
|
52
|
+
EmbedPayment,
|
|
53
|
+
P2OPPayment,
|
|
54
|
+
P2OPPaymentParams,
|
|
55
|
+
StackFunction,
|
|
56
|
+
PaymentType,
|
|
57
|
+
} from './payments/index.js';
|
|
39
58
|
export { Input as TxInput, Output as TxOutput } from './transaction.js';
|
|
40
59
|
|
|
41
60
|
export interface PsbtInput extends _PsbtInput {}
|
package/src/payments/embed.ts
CHANGED
|
@@ -1,7 +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 { EmbedPayment, PaymentOpts, Stack } from './index.js';
|
|
4
|
+
import { EmbedPayment, PaymentOpts, PaymentType, Stack } from './index.js';
|
|
5
5
|
import * as lazy from './lazy.js';
|
|
6
6
|
|
|
7
7
|
const OPS = bscript.OPS;
|
|
@@ -28,7 +28,7 @@ export function p2data(a: Omit<EmbedPayment, 'name'>, opts?: PaymentOpts): Embed
|
|
|
28
28
|
);
|
|
29
29
|
|
|
30
30
|
const network = a.network || BITCOIN_NETWORK;
|
|
31
|
-
const o: EmbedPayment = { name:
|
|
31
|
+
const o: EmbedPayment = { name: PaymentType.Embed, network, data: [] };
|
|
32
32
|
|
|
33
33
|
lazy.prop(o, 'output', () => {
|
|
34
34
|
if (!a.data) return;
|
package/src/payments/index.ts
CHANGED
|
@@ -21,9 +21,22 @@ export * from './p2wpkh.js';
|
|
|
21
21
|
export * from './p2wsh.js';
|
|
22
22
|
export * from './p2op.js';
|
|
23
23
|
|
|
24
|
+
export enum PaymentType {
|
|
25
|
+
P2PK = 'p2pk',
|
|
26
|
+
P2PKH = 'p2pkh',
|
|
27
|
+
P2SH = 'p2sh',
|
|
28
|
+
P2MS = 'p2ms',
|
|
29
|
+
P2WPKH = 'p2wpkh',
|
|
30
|
+
P2WSH = 'p2wsh',
|
|
31
|
+
P2TR = 'p2tr',
|
|
32
|
+
P2OP = 'p2op',
|
|
33
|
+
Embed = 'embed',
|
|
34
|
+
ScriptRedeem = 'scriptRedeem',
|
|
35
|
+
}
|
|
36
|
+
|
|
24
37
|
export interface BasePayment {
|
|
25
38
|
/** Convenience label, also the discriminant for the union. */
|
|
26
|
-
name?:
|
|
39
|
+
name?: PaymentType;
|
|
27
40
|
/** Network parameters (mainnet if omitted). */
|
|
28
41
|
network?: Network;
|
|
29
42
|
/** Fully-assembled scriptPubKey (if already known). */
|
|
@@ -51,14 +64,14 @@ export interface ScriptRedeem extends BasePayment {
|
|
|
51
64
|
}
|
|
52
65
|
|
|
53
66
|
export interface P2PKPayment extends BasePayment {
|
|
54
|
-
name:
|
|
67
|
+
name: PaymentType.P2PK;
|
|
55
68
|
pubkey?: Buffer;
|
|
56
69
|
/** DER-encoded sig – empty until signed. */
|
|
57
70
|
signature?: Buffer;
|
|
58
71
|
}
|
|
59
72
|
|
|
60
73
|
export interface P2PKHPayment extends BasePayment {
|
|
61
|
-
name:
|
|
74
|
+
name: PaymentType.P2PKH;
|
|
62
75
|
/** RIPEMD-160(SHA-256(pubkey)) – 20 bytes. */
|
|
63
76
|
hash?: Buffer;
|
|
64
77
|
pubkey?: Buffer;
|
|
@@ -66,7 +79,7 @@ export interface P2PKHPayment extends BasePayment {
|
|
|
66
79
|
}
|
|
67
80
|
|
|
68
81
|
export interface P2SHPayment extends BasePayment {
|
|
69
|
-
name:
|
|
82
|
+
name: PaymentType.P2SH;
|
|
70
83
|
/** Hash160 of a redeem script. */
|
|
71
84
|
hash?: Buffer;
|
|
72
85
|
|
|
@@ -75,7 +88,7 @@ export interface P2SHPayment extends BasePayment {
|
|
|
75
88
|
}
|
|
76
89
|
|
|
77
90
|
export interface P2MSPayment extends BasePayment {
|
|
78
|
-
name:
|
|
91
|
+
name: PaymentType.P2MS;
|
|
79
92
|
/** M-of-N parameters. */
|
|
80
93
|
m?: number;
|
|
81
94
|
n?: number;
|
|
@@ -84,7 +97,7 @@ export interface P2MSPayment extends BasePayment {
|
|
|
84
97
|
}
|
|
85
98
|
|
|
86
99
|
export interface P2WPKHPayment extends BasePayment {
|
|
87
|
-
name:
|
|
100
|
+
name: PaymentType.P2WPKH;
|
|
88
101
|
/** 20-byte witness program. */
|
|
89
102
|
hash?: Buffer;
|
|
90
103
|
pubkey?: Buffer;
|
|
@@ -92,14 +105,14 @@ export interface P2WPKHPayment extends BasePayment {
|
|
|
92
105
|
}
|
|
93
106
|
|
|
94
107
|
export interface P2WSHPayment extends BasePayment {
|
|
95
|
-
name:
|
|
108
|
+
name: PaymentType.P2WSH;
|
|
96
109
|
/** 32-byte witness program. */
|
|
97
110
|
hash?: Buffer;
|
|
98
111
|
redeem?: ScriptRedeem;
|
|
99
112
|
}
|
|
100
113
|
|
|
101
114
|
export interface P2TRPayment extends BasePayment {
|
|
102
|
-
name:
|
|
115
|
+
name: PaymentType.P2TR;
|
|
103
116
|
/** x-only pubkey that commits to the tree. */
|
|
104
117
|
pubkey?: Buffer;
|
|
105
118
|
/** Internal (untweaked) x-only pubkey. */
|
|
@@ -116,7 +129,7 @@ export interface P2TRPayment extends BasePayment {
|
|
|
116
129
|
}
|
|
117
130
|
|
|
118
131
|
export interface P2OPPayment extends BasePayment {
|
|
119
|
-
name:
|
|
132
|
+
name: PaymentType.P2OP;
|
|
120
133
|
/** <deploymentVersion || HASH160(payload)> (2–40 bytes). */
|
|
121
134
|
program?: Buffer;
|
|
122
135
|
deploymentVersion: number | undefined;
|
|
@@ -126,7 +139,7 @@ export interface P2OPPayment extends BasePayment {
|
|
|
126
139
|
|
|
127
140
|
/** OP_RETURN data-carrying output */
|
|
128
141
|
export interface EmbedPayment extends BasePayment {
|
|
129
|
-
name:
|
|
142
|
+
name: PaymentType.Embed;
|
|
130
143
|
/** Raw pushed chunks after OP_RETURN. */
|
|
131
144
|
data: Buffer[];
|
|
132
145
|
// `output` is automatically derived from `data` (or vice-versa)
|
package/src/payments/p2ms.ts
CHANGED
|
@@ -1,7 +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 { P2MSPayment, PaymentOpts, Stack } from './index.js';
|
|
4
|
+
import { P2MSPayment, PaymentOpts, PaymentType, Stack } from './index.js';
|
|
5
5
|
import * as lazy from './lazy.js';
|
|
6
6
|
|
|
7
7
|
const OPS = bscript.OPS;
|
|
@@ -46,7 +46,7 @@ export function p2ms(a: Omit<P2MSPayment, 'name'>, opts?: PaymentOpts): P2MSPaym
|
|
|
46
46
|
const network = a.network || BITCOIN_NETWORK;
|
|
47
47
|
const o: P2MSPayment = {
|
|
48
48
|
network,
|
|
49
|
-
name:
|
|
49
|
+
name: PaymentType.P2MS,
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
let chunks: Stack = [];
|