@btc-vision/bitcoin 6.4.1 → 6.4.3
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 -0
- package/browser/index.js +1 -1
- package/browser/payments/embed.d.ts +2 -2
- package/browser/payments/index.d.ts +61 -12
- package/browser/payments/lazy.d.ts +1 -1
- package/browser/payments/p2ms.d.ts +2 -2
- package/browser/payments/p2op.d.ts +25 -0
- 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/browser/psbt/psbtutils.d.ts +1 -0
- package/build/address.js +4 -5
- package/build/payments/embed.d.ts +2 -2
- package/build/payments/embed.js +6 -2
- package/build/payments/index.d.ts +61 -12
- package/build/payments/index.js +1 -0
- package/build/payments/lazy.d.ts +1 -1
- package/build/payments/p2ms.d.ts +2 -2
- package/build/payments/p2ms.js +8 -2
- package/build/payments/p2op.d.ts +25 -0
- package/build/payments/p2op.js +112 -0
- package/build/payments/p2pk.d.ts +2 -2
- package/build/payments/p2pk.js +5 -1
- package/build/payments/p2pkh.d.ts +2 -2
- package/build/payments/p2pkh.js +5 -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 +5 -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/psbtutils.d.ts +1 -0
- package/build/psbt/psbtutils.js +2 -0
- package/build/psbt.js +3 -1
- package/package.json +1 -1
- package/src/address.ts +283 -287
- package/src/payments/embed.ts +61 -55
- package/src/payments/index.ts +110 -13
- package/src/payments/lazy.ts +28 -28
- package/src/payments/p2ms.ts +11 -5
- package/src/payments/p2op.ts +170 -0
- package/src/payments/p2pk.ts +93 -85
- package/src/payments/p2pkh.ts +214 -210
- package/src/payments/p2sh.ts +211 -206
- package/src/payments/p2tr.ts +9 -4
- package/src/payments/p2wpkh.ts +7 -3
- package/src/payments/p2wsh.ts +7 -3
- package/src/psbt/psbtutils.ts +322 -320
- package/src/psbt.ts +5 -3
- 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;
|
|
@@ -10,30 +10,79 @@ export * from './p2sh.js';
|
|
|
10
10
|
export * from './p2tr.js';
|
|
11
11
|
export * from './p2wpkh.js';
|
|
12
12
|
export * from './p2wsh.js';
|
|
13
|
-
export
|
|
13
|
+
export * from './p2op.js';
|
|
14
|
+
export interface BasePayment {
|
|
14
15
|
name?: string;
|
|
15
16
|
network?: Network;
|
|
16
17
|
output?: Buffer;
|
|
17
|
-
|
|
18
|
+
input?: Buffer;
|
|
19
|
+
address?: string;
|
|
20
|
+
witness?: Buffer[];
|
|
21
|
+
redeem?: ScriptRedeem;
|
|
22
|
+
useHybrid?: boolean;
|
|
23
|
+
useUncompressed?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ScriptRedeem extends BasePayment {
|
|
26
|
+
output?: Buffer;
|
|
27
|
+
redeemVersion?: number;
|
|
28
|
+
network?: Network;
|
|
29
|
+
}
|
|
30
|
+
export interface P2PKPayment extends BasePayment {
|
|
31
|
+
name: 'p2pk';
|
|
32
|
+
pubkey?: Buffer;
|
|
33
|
+
signature?: Buffer;
|
|
34
|
+
}
|
|
35
|
+
export interface P2PKHPayment extends BasePayment {
|
|
36
|
+
name: 'p2pkh';
|
|
37
|
+
hash?: Buffer;
|
|
38
|
+
pubkey?: Buffer;
|
|
39
|
+
signature?: Buffer;
|
|
40
|
+
}
|
|
41
|
+
export interface P2SHPayment extends BasePayment {
|
|
42
|
+
name: 'p2sh';
|
|
43
|
+
hash?: Buffer;
|
|
44
|
+
signatures?: Buffer[];
|
|
45
|
+
}
|
|
46
|
+
export interface P2MSPayment extends BasePayment {
|
|
47
|
+
name: 'p2ms';
|
|
18
48
|
m?: number;
|
|
19
49
|
n?: number;
|
|
20
50
|
pubkeys?: Buffer[];
|
|
21
|
-
input?: Buffer;
|
|
22
51
|
signatures?: Buffer[];
|
|
23
|
-
|
|
52
|
+
}
|
|
53
|
+
export interface P2WPKHPayment extends BasePayment {
|
|
54
|
+
name: 'p2wpkh';
|
|
55
|
+
hash?: Buffer;
|
|
24
56
|
pubkey?: Buffer;
|
|
25
57
|
signature?: Buffer;
|
|
26
|
-
|
|
58
|
+
}
|
|
59
|
+
export interface P2WSHPayment extends BasePayment {
|
|
60
|
+
name: 'p2wsh';
|
|
61
|
+
hash?: Buffer;
|
|
62
|
+
redeem?: ScriptRedeem;
|
|
63
|
+
}
|
|
64
|
+
export interface P2TRPayment extends BasePayment {
|
|
65
|
+
name: 'p2tr';
|
|
66
|
+
pubkey?: Buffer;
|
|
67
|
+
internalPubkey?: Buffer;
|
|
27
68
|
hash?: Buffer;
|
|
28
|
-
redeem?: Payment;
|
|
29
|
-
redeemVersion?: number;
|
|
30
69
|
scriptTree?: Taptree;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
70
|
+
signature?: Buffer;
|
|
71
|
+
redeemVersion?: number;
|
|
72
|
+
redeem?: ScriptRedeem;
|
|
73
|
+
}
|
|
74
|
+
export interface P2OPPayment extends BasePayment {
|
|
75
|
+
name: 'p2op';
|
|
76
|
+
program?: Buffer;
|
|
77
|
+
deploymentVersion: number | undefined;
|
|
78
|
+
hash160?: Buffer;
|
|
79
|
+
}
|
|
80
|
+
export interface EmbedPayment extends BasePayment {
|
|
81
|
+
name: 'embed';
|
|
82
|
+
data: Buffer[];
|
|
34
83
|
}
|
|
35
|
-
export type
|
|
36
|
-
export type
|
|
84
|
+
export type Payment = P2PKPayment | P2PKHPayment | P2SHPayment | P2MSPayment | P2WPKHPayment | P2WSHPayment | P2TRPayment | P2OPPayment | EmbedPayment | ScriptRedeem;
|
|
85
|
+
export type PaymentCreator = <T extends BasePayment>(a: T, opts?: PaymentOpts) => T;
|
|
37
86
|
export interface PaymentOpts {
|
|
38
87
|
validate?: boolean;
|
|
39
88
|
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;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BasePayment, P2OPPayment, PaymentOpts } from './index.js';
|
|
2
|
+
interface P2OPBase extends BasePayment {
|
|
3
|
+
name: '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;
|
|
@@ -6,6 +6,7 @@ export declare const isP2WPKH: (script: Buffer) => boolean;
|
|
|
6
6
|
export declare const isP2WSHScript: (script: Buffer) => boolean;
|
|
7
7
|
export declare const isP2SHScript: (script: Buffer) => boolean;
|
|
8
8
|
export declare const isP2TR: (script: Buffer) => boolean;
|
|
9
|
+
export declare const isP2OP: (script: Buffer) => boolean;
|
|
9
10
|
export declare function witnessStackToScriptWitness(witness: Buffer[]): Buffer;
|
|
10
11
|
export interface UncompressedPublicKey {
|
|
11
12
|
hybrid: Buffer;
|
package/build/address.js
CHANGED
|
@@ -179,11 +179,10 @@ export function toOutputScript(address, network) {
|
|
|
179
179
|
else if (decodeBech32.version === FUTURE_OPNET_VERSION) {
|
|
180
180
|
if (!network.bech32Opnet)
|
|
181
181
|
throw new Error(address + ' has an invalid prefix');
|
|
182
|
-
|
|
183
|
-
decodeBech32.data
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
return bscript.compile([opcodes.OP_16, decodeBech32.data]);
|
|
182
|
+
return payments.p2op({
|
|
183
|
+
program: decodeBech32.data,
|
|
184
|
+
network,
|
|
185
|
+
}).output;
|
|
187
186
|
}
|
|
188
187
|
else if (decodeBech32.version >= FUTURE_SEGWIT_MIN_VERSION &&
|
|
189
188
|
decodeBech32.version <= FUTURE_SEGWIT_MAX_VERSION &&
|
|
@@ -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
|
@@ -13,7 +13,7 @@ export function p2data(a, opts) {
|
|
|
13
13
|
data: typef.maybe(typef.arrayOf(typef.Buffer)),
|
|
14
14
|
}, a);
|
|
15
15
|
const network = a.network || BITCOIN_NETWORK;
|
|
16
|
-
const o = { name: 'embed', network };
|
|
16
|
+
const o = { name: 'embed', network, data: [] };
|
|
17
17
|
lazy.prop(o, 'output', () => {
|
|
18
18
|
if (!a.data)
|
|
19
19
|
return;
|
|
@@ -22,7 +22,11 @@ export function p2data(a, opts) {
|
|
|
22
22
|
lazy.prop(o, 'data', () => {
|
|
23
23
|
if (!a.output)
|
|
24
24
|
return;
|
|
25
|
-
|
|
25
|
+
const script = bscript.decompile(a.output);
|
|
26
|
+
if (script === null || script === undefined) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
return script.slice(1);
|
|
26
30
|
});
|
|
27
31
|
if (opts.validate) {
|
|
28
32
|
if (a.output) {
|
|
@@ -10,30 +10,79 @@ export * from './p2sh.js';
|
|
|
10
10
|
export * from './p2tr.js';
|
|
11
11
|
export * from './p2wpkh.js';
|
|
12
12
|
export * from './p2wsh.js';
|
|
13
|
-
export
|
|
13
|
+
export * from './p2op.js';
|
|
14
|
+
export interface BasePayment {
|
|
14
15
|
name?: string;
|
|
15
16
|
network?: Network;
|
|
16
17
|
output?: Buffer;
|
|
17
|
-
|
|
18
|
+
input?: Buffer;
|
|
19
|
+
address?: string;
|
|
20
|
+
witness?: Buffer[];
|
|
21
|
+
redeem?: ScriptRedeem;
|
|
22
|
+
useHybrid?: boolean;
|
|
23
|
+
useUncompressed?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ScriptRedeem extends BasePayment {
|
|
26
|
+
output?: Buffer;
|
|
27
|
+
redeemVersion?: number;
|
|
28
|
+
network?: Network;
|
|
29
|
+
}
|
|
30
|
+
export interface P2PKPayment extends BasePayment {
|
|
31
|
+
name: 'p2pk';
|
|
32
|
+
pubkey?: Buffer;
|
|
33
|
+
signature?: Buffer;
|
|
34
|
+
}
|
|
35
|
+
export interface P2PKHPayment extends BasePayment {
|
|
36
|
+
name: 'p2pkh';
|
|
37
|
+
hash?: Buffer;
|
|
38
|
+
pubkey?: Buffer;
|
|
39
|
+
signature?: Buffer;
|
|
40
|
+
}
|
|
41
|
+
export interface P2SHPayment extends BasePayment {
|
|
42
|
+
name: 'p2sh';
|
|
43
|
+
hash?: Buffer;
|
|
44
|
+
signatures?: Buffer[];
|
|
45
|
+
}
|
|
46
|
+
export interface P2MSPayment extends BasePayment {
|
|
47
|
+
name: 'p2ms';
|
|
18
48
|
m?: number;
|
|
19
49
|
n?: number;
|
|
20
50
|
pubkeys?: Buffer[];
|
|
21
|
-
input?: Buffer;
|
|
22
51
|
signatures?: Buffer[];
|
|
23
|
-
|
|
52
|
+
}
|
|
53
|
+
export interface P2WPKHPayment extends BasePayment {
|
|
54
|
+
name: 'p2wpkh';
|
|
55
|
+
hash?: Buffer;
|
|
24
56
|
pubkey?: Buffer;
|
|
25
57
|
signature?: Buffer;
|
|
26
|
-
|
|
58
|
+
}
|
|
59
|
+
export interface P2WSHPayment extends BasePayment {
|
|
60
|
+
name: 'p2wsh';
|
|
61
|
+
hash?: Buffer;
|
|
62
|
+
redeem?: ScriptRedeem;
|
|
63
|
+
}
|
|
64
|
+
export interface P2TRPayment extends BasePayment {
|
|
65
|
+
name: 'p2tr';
|
|
66
|
+
pubkey?: Buffer;
|
|
67
|
+
internalPubkey?: Buffer;
|
|
27
68
|
hash?: Buffer;
|
|
28
|
-
redeem?: Payment;
|
|
29
|
-
redeemVersion?: number;
|
|
30
69
|
scriptTree?: Taptree;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
70
|
+
signature?: Buffer;
|
|
71
|
+
redeemVersion?: number;
|
|
72
|
+
redeem?: ScriptRedeem;
|
|
73
|
+
}
|
|
74
|
+
export interface P2OPPayment extends BasePayment {
|
|
75
|
+
name: 'p2op';
|
|
76
|
+
program?: Buffer;
|
|
77
|
+
deploymentVersion: number | undefined;
|
|
78
|
+
hash160?: Buffer;
|
|
79
|
+
}
|
|
80
|
+
export interface EmbedPayment extends BasePayment {
|
|
81
|
+
name: 'embed';
|
|
82
|
+
data: Buffer[];
|
|
34
83
|
}
|
|
35
|
-
export type
|
|
36
|
-
export type
|
|
84
|
+
export type Payment = P2PKPayment | P2PKHPayment | P2SHPayment | P2MSPayment | P2WPKHPayment | P2WSHPayment | P2TRPayment | P2OPPayment | EmbedPayment | ScriptRedeem;
|
|
85
|
+
export type PaymentCreator = <T extends BasePayment>(a: T, opts?: PaymentOpts) => T;
|
|
37
86
|
export interface PaymentOpts {
|
|
38
87
|
validate?: boolean;
|
|
39
88
|
allowIncomplete?: boolean;
|
package/build/payments/index.js
CHANGED
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
|
@@ -22,7 +22,10 @@ export function p2ms(a, opts) {
|
|
|
22
22
|
input: typef.maybe(typef.Buffer),
|
|
23
23
|
}, a);
|
|
24
24
|
const network = a.network || BITCOIN_NETWORK;
|
|
25
|
-
const o = {
|
|
25
|
+
const o = {
|
|
26
|
+
network,
|
|
27
|
+
name: 'p2ms',
|
|
28
|
+
};
|
|
26
29
|
let chunks = [];
|
|
27
30
|
let decoded = false;
|
|
28
31
|
function decode(output) {
|
|
@@ -63,7 +66,10 @@ export function p2ms(a, opts) {
|
|
|
63
66
|
lazy.prop(o, 'signatures', () => {
|
|
64
67
|
if (!a.input)
|
|
65
68
|
return;
|
|
66
|
-
|
|
69
|
+
const decompiled = bscript.decompile(a.input);
|
|
70
|
+
if (decompiled === null || decompiled === undefined)
|
|
71
|
+
return;
|
|
72
|
+
return decompiled.slice(1);
|
|
67
73
|
});
|
|
68
74
|
lazy.prop(o, 'input', () => {
|
|
69
75
|
if (!a.signatures)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BasePayment, P2OPPayment, PaymentOpts } from './index.js';
|
|
2
|
+
interface P2OPBase extends BasePayment {
|
|
3
|
+
name: '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 {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { bech32m } from 'bech32';
|
|
2
|
+
import { Buffer as NBuffer } from 'buffer';
|
|
3
|
+
import { fromBech32 } from '../address.js';
|
|
4
|
+
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
5
|
+
import * as bscript from '../script.js';
|
|
6
|
+
import { typeforce as typef } from '../types.js';
|
|
7
|
+
import * as lazy from './lazy.js';
|
|
8
|
+
const OPS = bscript.OPS;
|
|
9
|
+
const P2OP_WITNESS_VERSION = 0x10;
|
|
10
|
+
const MIN_SIZE = 2;
|
|
11
|
+
const MAX_SIZE = 40;
|
|
12
|
+
export function p2op(a, opts) {
|
|
13
|
+
if (!a.address && !a.output && !a.program)
|
|
14
|
+
throw new TypeError('Not enough data for p2op');
|
|
15
|
+
opts = Object.assign({ validate: true }, opts || {});
|
|
16
|
+
typef({
|
|
17
|
+
address: typef.maybe(typef.String),
|
|
18
|
+
output: typef.maybe(typef.Buffer),
|
|
19
|
+
program: typef.maybe(typef.Buffer),
|
|
20
|
+
network: typef.maybe(typef.Object),
|
|
21
|
+
deploymentVersion: typef.maybe(typef.Number),
|
|
22
|
+
hash160: typef.maybe(typef.BufferN(20)),
|
|
23
|
+
}, a);
|
|
24
|
+
const _address = lazy.value(() => fromBech32(a.address));
|
|
25
|
+
const network = a.network || BITCOIN_NETWORK;
|
|
26
|
+
const o = {
|
|
27
|
+
name: 'p2op',
|
|
28
|
+
network,
|
|
29
|
+
deploymentVersion: 0,
|
|
30
|
+
};
|
|
31
|
+
lazy.prop(o, 'program', () => {
|
|
32
|
+
if (a.program)
|
|
33
|
+
return a.program;
|
|
34
|
+
if (a.output) {
|
|
35
|
+
if (a.output[0] !== OPS.OP_16)
|
|
36
|
+
throw new TypeError('Invalid P2OP script');
|
|
37
|
+
let pushPos = 1, progLen;
|
|
38
|
+
if (a.output[1] < 0x4c) {
|
|
39
|
+
progLen = a.output[1];
|
|
40
|
+
pushPos = 2;
|
|
41
|
+
}
|
|
42
|
+
else if (a.output[1] === 0x4c) {
|
|
43
|
+
progLen = a.output[2];
|
|
44
|
+
pushPos = 3;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw new TypeError('Unsupported push opcode in P2OP script');
|
|
48
|
+
}
|
|
49
|
+
return a.output.slice(pushPos, pushPos + progLen);
|
|
50
|
+
}
|
|
51
|
+
if (a.address) {
|
|
52
|
+
const dec = _address();
|
|
53
|
+
return dec.data;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
lazy.prop(o, 'deploymentVersion', () => {
|
|
57
|
+
if (!o.program)
|
|
58
|
+
return;
|
|
59
|
+
return o.program[0];
|
|
60
|
+
});
|
|
61
|
+
lazy.prop(o, 'hash160', () => {
|
|
62
|
+
if (!o.program)
|
|
63
|
+
return;
|
|
64
|
+
return o.program.slice(1);
|
|
65
|
+
});
|
|
66
|
+
lazy.prop(o, 'output', () => {
|
|
67
|
+
if (!o.program)
|
|
68
|
+
return;
|
|
69
|
+
return bscript.compile([OPS.OP_16, o.program]);
|
|
70
|
+
});
|
|
71
|
+
lazy.prop(o, 'address', () => {
|
|
72
|
+
if (!o.program)
|
|
73
|
+
return;
|
|
74
|
+
if (!network.bech32Opnet) {
|
|
75
|
+
throw new TypeError('Network does not support opnet');
|
|
76
|
+
}
|
|
77
|
+
const words = bech32m.toWords(o.program);
|
|
78
|
+
words.unshift(P2OP_WITNESS_VERSION);
|
|
79
|
+
return bech32m.encode(network.bech32Opnet, words);
|
|
80
|
+
});
|
|
81
|
+
if (opts.validate) {
|
|
82
|
+
let prog = NBuffer.alloc(0);
|
|
83
|
+
if (a.address) {
|
|
84
|
+
const dec = _address();
|
|
85
|
+
if (network.bech32Opnet !== dec.prefix)
|
|
86
|
+
throw new TypeError('Invalid prefix or network mismatch');
|
|
87
|
+
if (dec.version !== P2OP_WITNESS_VERSION)
|
|
88
|
+
throw new TypeError('Invalid witness version for p2op');
|
|
89
|
+
if (dec.data.length < MIN_SIZE || dec.data.length > MAX_SIZE)
|
|
90
|
+
throw new TypeError('Invalid witness program length');
|
|
91
|
+
prog = dec.data;
|
|
92
|
+
}
|
|
93
|
+
if (a.program) {
|
|
94
|
+
if (prog.length && !prog.equals(a.program))
|
|
95
|
+
throw new TypeError('Program mismatch');
|
|
96
|
+
prog = a.program;
|
|
97
|
+
}
|
|
98
|
+
if (a.output) {
|
|
99
|
+
const outProg = o.program;
|
|
100
|
+
if (prog.length && !prog.equals(outProg))
|
|
101
|
+
throw new TypeError('Program mismatch (output vs other source)');
|
|
102
|
+
prog = outProg;
|
|
103
|
+
}
|
|
104
|
+
if (prog.length < MIN_SIZE || prog.length > MAX_SIZE)
|
|
105
|
+
throw new TypeError('Witness program must be 2–40 bytes');
|
|
106
|
+
if (a.deploymentVersion !== undefined && a.deploymentVersion !== prog[0])
|
|
107
|
+
throw new TypeError('deploymentVersion mismatch');
|
|
108
|
+
if (a.hash160 && !a.hash160.equals(prog.slice(1)))
|
|
109
|
+
throw new TypeError('hash160 mismatch');
|
|
110
|
+
}
|
|
111
|
+
return Object.assign(o, a);
|
|
112
|
+
}
|
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
|
@@ -18,7 +18,11 @@ export function p2pk(a, opts) {
|
|
|
18
18
|
return bscript.decompile(a.input);
|
|
19
19
|
});
|
|
20
20
|
const network = a.network || BITCOIN_NETWORK;
|
|
21
|
-
const o = {
|
|
21
|
+
const o = {
|
|
22
|
+
name: 'p2pk',
|
|
23
|
+
network,
|
|
24
|
+
pubkey: undefined,
|
|
25
|
+
};
|
|
22
26
|
lazy.prop(o, 'output', () => {
|
|
23
27
|
if (!a.pubkey)
|
|
24
28
|
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
|
@@ -30,7 +30,11 @@ export function p2pkh(a, opts) {
|
|
|
30
30
|
return bscript.decompile(a.input);
|
|
31
31
|
});
|
|
32
32
|
const network = a.network || BITCOIN_NETWORK;
|
|
33
|
-
const o = {
|
|
33
|
+
const o = {
|
|
34
|
+
name: 'p2pkh',
|
|
35
|
+
network,
|
|
36
|
+
hash: undefined,
|
|
37
|
+
};
|
|
34
38
|
lazy.prop(o, 'address', () => {
|
|
35
39
|
if (!o.hash)
|
|
36
40
|
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
|
@@ -28,7 +28,11 @@ export function p2sh(a, opts) {
|
|
|
28
28
|
if (!network) {
|
|
29
29
|
network = (a.redeem && a.redeem.network) || BITCOIN_NETWORK;
|
|
30
30
|
}
|
|
31
|
-
const o = {
|
|
31
|
+
const o = {
|
|
32
|
+
network,
|
|
33
|
+
name: 'p2sh',
|
|
34
|
+
hash: undefined,
|
|
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
|
@@ -55,7 +55,10 @@ export function p2tr(a, opts) {
|
|
|
55
55
|
return;
|
|
56
56
|
});
|
|
57
57
|
const network = a.network || BITCOIN_NETWORK;
|
|
58
|
-
const o = {
|
|
58
|
+
const o = {
|
|
59
|
+
name: 'p2tr',
|
|
60
|
+
network,
|
|
61
|
+
};
|
|
59
62
|
lazy.prop(o, 'address', () => {
|
|
60
63
|
if (!o.pubkey)
|
|
61
64
|
return;
|
|
@@ -78,7 +81,7 @@ export function p2tr(a, opts) {
|
|
|
78
81
|
});
|
|
79
82
|
return rootHashFromPath(controlBlock, leafHash);
|
|
80
83
|
}
|
|
81
|
-
return
|
|
84
|
+
return undefined;
|
|
82
85
|
});
|
|
83
86
|
lazy.prop(o, 'output', () => {
|
|
84
87
|
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;
|
package/build/payments/p2wpkh.js
CHANGED
|
@@ -31,7 +31,11 @@ export function p2wpkh(a, opts) {
|
|
|
31
31
|
};
|
|
32
32
|
});
|
|
33
33
|
const network = a.network || BITCOIN_NETWORK;
|
|
34
|
-
const o = {
|
|
34
|
+
const o = {
|
|
35
|
+
name: 'p2wpkh',
|
|
36
|
+
network,
|
|
37
|
+
hash: undefined,
|
|
38
|
+
};
|
|
35
39
|
lazy.prop(o, 'address', () => {
|
|
36
40
|
if (!o.hash)
|
|
37
41
|
return;
|
|
@@ -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/payments/p2wsh.js
CHANGED
|
@@ -49,7 +49,11 @@ export function p2wsh(a, opts) {
|
|
|
49
49
|
if (!network) {
|
|
50
50
|
network = (a.redeem && a.redeem.network) || BITCOIN_NETWORK;
|
|
51
51
|
}
|
|
52
|
-
const o = {
|
|
52
|
+
const o = {
|
|
53
|
+
network,
|
|
54
|
+
name: 'p2wsh',
|
|
55
|
+
hash: undefined,
|
|
56
|
+
};
|
|
53
57
|
lazy.prop(o, 'address', () => {
|
|
54
58
|
if (!o.hash)
|
|
55
59
|
return;
|
|
@@ -6,6 +6,7 @@ export declare const isP2WPKH: (script: Buffer) => boolean;
|
|
|
6
6
|
export declare const isP2WSHScript: (script: Buffer) => boolean;
|
|
7
7
|
export declare const isP2SHScript: (script: Buffer) => boolean;
|
|
8
8
|
export declare const isP2TR: (script: Buffer) => boolean;
|
|
9
|
+
export declare const isP2OP: (script: Buffer) => boolean;
|
|
9
10
|
export declare function witnessStackToScriptWitness(witness: Buffer[]): Buffer;
|
|
10
11
|
export interface UncompressedPublicKey {
|
|
11
12
|
hybrid: Buffer;
|