@btc-vision/bitcoin 6.5.2 → 6.5.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/address.d.ts +2 -6
- package/browser/bech32utils.d.ts +6 -0
- package/browser/chunks/{crypto-0PweVewC.js → crypto-BhCpKpek.js} +4 -4
- package/browser/chunks/{payments-CgasufRS.js → payments-Ngcm87h_.js} +670 -626
- package/browser/chunks/{psbt-BIwOrKer.js → psbt-CcM4rw3q.js} +1259 -1316
- package/browser/chunks/{script-CROJPzz_.js → script-DyPItFEl.js} +33 -33
- package/browser/chunks/{transaction-DchBu35N.js → transaction-C_UbhMGn.js} +3 -3
- package/browser/chunks/{utils-CO5kmxe9.js → utils-DNZi-T5W.js} +26 -26
- package/browser/index.d.ts +3 -1
- package/browser/index.js +102 -90
- package/browser/payments/embed.d.ts +1 -1
- package/browser/payments/index.d.ts +12 -104
- package/browser/payments/p2ms.d.ts +1 -1
- package/browser/payments/p2op.d.ts +1 -1
- package/browser/payments/p2pk.d.ts +1 -1
- package/browser/payments/p2pkh.d.ts +1 -1
- package/browser/payments/p2sh.d.ts +1 -1
- package/browser/payments/p2tr.d.ts +1 -1
- package/browser/payments/p2wpkh.d.ts +1 -1
- package/browser/payments/p2wsh.d.ts +1 -1
- package/browser/payments/types.d.ts +93 -0
- package/browser/psbt/bip371.d.ts +0 -1
- package/browser/psbt/psbtutils.d.ts +0 -7
- package/browser/pubkey.d.ts +8 -0
- package/browser/script.d.ts +1 -2
- package/browser/script_signature.d.ts +1 -0
- package/browser/types.d.ts +3 -0
- package/build/address.d.ts +2 -6
- package/build/address.js +19 -37
- package/build/bech32utils.d.ts +6 -0
- package/build/bech32utils.js +26 -0
- package/build/index.d.ts +3 -1
- package/build/index.js +1 -0
- package/build/payments/embed.d.ts +1 -1
- package/build/payments/embed.js +1 -1
- package/build/payments/index.d.ts +12 -104
- package/build/payments/index.js +12 -24
- package/build/payments/p2ms.d.ts +1 -1
- package/build/payments/p2ms.js +1 -1
- package/build/payments/p2op.d.ts +1 -1
- package/build/payments/p2op.js +2 -2
- package/build/payments/p2pk.d.ts +1 -1
- package/build/payments/p2pk.js +1 -1
- package/build/payments/p2pkh.d.ts +1 -1
- package/build/payments/p2pkh.js +2 -2
- package/build/payments/p2sh.d.ts +1 -1
- package/build/payments/p2sh.js +1 -1
- package/build/payments/p2tr.d.ts +1 -1
- package/build/payments/p2tr.js +2 -2
- package/build/payments/p2wpkh.d.ts +1 -1
- package/build/payments/p2wpkh.js +1 -1
- package/build/payments/p2wsh.d.ts +1 -1
- package/build/payments/p2wsh.js +2 -2
- package/build/payments/types.d.ts +93 -0
- package/build/payments/types.js +13 -0
- package/build/psbt/bip371.d.ts +0 -1
- package/build/psbt/bip371.js +2 -6
- package/build/psbt/psbtutils.d.ts +0 -7
- package/build/psbt/psbtutils.js +2 -54
- package/build/psbt.js +3 -2
- package/build/pubkey.d.ts +8 -0
- package/build/pubkey.js +56 -0
- package/build/script.d.ts +1 -2
- package/build/script.js +1 -4
- package/build/script_signature.d.ts +1 -0
- package/build/script_signature.js +4 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types.d.ts +3 -0
- package/package.json +13 -6
- package/src/address.ts +20 -50
- package/src/bech32utils.ts +43 -0
- package/src/index.ts +2 -3
- package/src/payments/embed.ts +2 -2
- package/src/payments/index.ts +40 -164
- package/src/payments/p2ms.ts +2 -2
- package/src/payments/p2op.ts +2 -2
- package/src/payments/p2pk.ts +2 -2
- package/src/payments/p2pkh.ts +3 -3
- package/src/payments/p2sh.ts +2 -10
- package/src/payments/p2tr.ts +2 -2
- package/src/payments/p2wpkh.ts +1 -1
- package/src/payments/p2wsh.ts +8 -2
- package/src/payments/types.ts +154 -0
- package/src/psbt/bip371.ts +6 -13
- package/src/psbt/psbtutils.ts +2 -104
- package/src/psbt.ts +3 -2
- package/src/pubkey.ts +99 -0
- package/src/script.ts +2 -7
- package/src/script_signature.ts +10 -1
- package/src/types.ts +5 -0
- package/test/address.spec.ts +3 -2
- package/test/integration/taproot.spec.ts +2 -1
package/src/payments/index.ts
CHANGED
|
@@ -6,167 +6,43 @@
|
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
witness?: Buffer[];
|
|
50
|
-
|
|
51
|
-
/** Script template for P2SH, P2WSH, P2TR, etc. */
|
|
52
|
-
redeem?: ScriptRedeem;
|
|
53
|
-
|
|
54
|
-
/** Non-standard options used by some wallets. */
|
|
55
|
-
useHybrid?: boolean;
|
|
56
|
-
useUncompressed?: boolean;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Helper used by redeeming script-template outputs (P2SH, P2WSH). */
|
|
60
|
-
export interface ScriptRedeem extends BasePayment {
|
|
61
|
-
output?: Buffer; // script template
|
|
62
|
-
redeemVersion?: number; // tapscript leaves etc.
|
|
63
|
-
network?: Network; // network parameters (mainnet if omitted)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface P2PKPayment extends BasePayment {
|
|
67
|
-
name: PaymentType.P2PK;
|
|
68
|
-
pubkey?: Buffer;
|
|
69
|
-
/** DER-encoded sig – empty until signed. */
|
|
70
|
-
signature?: Buffer;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface P2PKHPayment extends BasePayment {
|
|
74
|
-
name: PaymentType.P2PKH;
|
|
75
|
-
/** RIPEMD-160(SHA-256(pubkey)) – 20 bytes. */
|
|
76
|
-
hash?: Buffer;
|
|
77
|
-
pubkey?: Buffer;
|
|
78
|
-
signature?: Buffer;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface P2SHPayment extends BasePayment {
|
|
82
|
-
name: PaymentType.P2SH;
|
|
83
|
-
/** Hash160 of a redeem script. */
|
|
84
|
-
hash?: Buffer;
|
|
85
|
-
|
|
86
|
-
/** The entire signature stack when spending a P2SH (non-segwit). */
|
|
87
|
-
signatures?: Buffer[];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface P2MSPayment extends BasePayment {
|
|
91
|
-
name: PaymentType.P2MS;
|
|
92
|
-
/** M-of-N parameters. */
|
|
93
|
-
m?: number;
|
|
94
|
-
n?: number;
|
|
95
|
-
pubkeys?: Buffer[];
|
|
96
|
-
signatures?: Buffer[];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface P2WPKHPayment extends BasePayment {
|
|
100
|
-
name: PaymentType.P2WPKH;
|
|
101
|
-
/** 20-byte witness program. */
|
|
102
|
-
hash?: Buffer;
|
|
103
|
-
pubkey?: Buffer;
|
|
104
|
-
signature?: Buffer;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface P2WSHPayment extends BasePayment {
|
|
108
|
-
name: PaymentType.P2WSH;
|
|
109
|
-
/** 32-byte witness program. */
|
|
110
|
-
hash?: Buffer;
|
|
111
|
-
redeem?: ScriptRedeem;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface P2TRPayment extends BasePayment {
|
|
115
|
-
name: PaymentType.P2TR;
|
|
116
|
-
/** x-only pubkey that commits to the tree. */
|
|
117
|
-
pubkey?: Buffer;
|
|
118
|
-
/** Internal (untweaked) x-only pubkey. */
|
|
119
|
-
internalPubkey?: Buffer;
|
|
120
|
-
/** Merkle-root tweak, present when a script path exists. */
|
|
121
|
-
hash?: Buffer;
|
|
122
|
-
/** Full taptree description (optional, dev-side). */
|
|
123
|
-
scriptTree?: Taptree;
|
|
124
|
-
/** Key-path sig or leading stack elem. */
|
|
125
|
-
signature?: Buffer;
|
|
126
|
-
|
|
127
|
-
redeemVersion?: number; // tapscript leaves etc.
|
|
128
|
-
redeem?: ScriptRedeem;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface P2OPPayment extends BasePayment {
|
|
132
|
-
name: PaymentType.P2OP;
|
|
133
|
-
/** <deploymentVersion || HASH160(payload)> (2–40 bytes). */
|
|
134
|
-
program?: Buffer;
|
|
135
|
-
deploymentVersion: number | undefined;
|
|
136
|
-
/** Convenience slice of `program` (20 bytes for current spec). */
|
|
137
|
-
hash160?: Buffer;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** OP_RETURN data-carrying output */
|
|
141
|
-
export interface EmbedPayment extends BasePayment {
|
|
142
|
-
name: PaymentType.Embed;
|
|
143
|
-
/** Raw pushed chunks after OP_RETURN. */
|
|
144
|
-
data: Buffer[];
|
|
145
|
-
// `output` is automatically derived from `data` (or vice-versa)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export type Payment =
|
|
149
|
-
| P2PKPayment
|
|
150
|
-
| P2PKHPayment
|
|
151
|
-
| P2SHPayment
|
|
152
|
-
| P2MSPayment
|
|
153
|
-
| P2WPKHPayment
|
|
154
|
-
| P2WSHPayment
|
|
155
|
-
| P2TRPayment
|
|
156
|
-
| P2OPPayment
|
|
157
|
-
| EmbedPayment
|
|
158
|
-
| ScriptRedeem;
|
|
159
|
-
|
|
160
|
-
export type PaymentCreator = <T extends BasePayment>(a: T, opts?: PaymentOpts) => T;
|
|
161
|
-
|
|
162
|
-
export interface PaymentOpts {
|
|
163
|
-
validate?: boolean;
|
|
164
|
-
allowIncomplete?: boolean;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export type StackElement = Buffer | number;
|
|
168
|
-
export type Stack = StackElement[];
|
|
169
|
-
export type StackFunction = () => Stack;
|
|
170
|
-
|
|
171
|
-
// TODO
|
|
172
|
-
// witness commitment
|
|
9
|
+
export {
|
|
10
|
+
PaymentType,
|
|
11
|
+
type BasePayment,
|
|
12
|
+
type ScriptRedeem,
|
|
13
|
+
type P2PKPayment,
|
|
14
|
+
type P2PKHPayment,
|
|
15
|
+
type P2SHPayment,
|
|
16
|
+
type P2MSPayment,
|
|
17
|
+
type P2WPKHPayment,
|
|
18
|
+
type P2WSHPayment,
|
|
19
|
+
type P2TRPayment,
|
|
20
|
+
type P2OPPayment,
|
|
21
|
+
type P2OPPaymentParams,
|
|
22
|
+
type EmbedPayment,
|
|
23
|
+
type Payment,
|
|
24
|
+
type PaymentCreator,
|
|
25
|
+
type PaymentOpts,
|
|
26
|
+
} from './types.js';
|
|
27
|
+
|
|
28
|
+
export { p2data } from './embed.js';
|
|
29
|
+
export { prop, value } from './lazy.js';
|
|
30
|
+
export { p2ms } from './p2ms.js';
|
|
31
|
+
export { p2pk } from './p2pk.js';
|
|
32
|
+
export { p2pkh } from './p2pkh.js';
|
|
33
|
+
export { p2sh } from './p2sh.js';
|
|
34
|
+
export { p2tr } from './p2tr.js';
|
|
35
|
+
export { p2wpkh } from './p2wpkh.js';
|
|
36
|
+
export { p2wsh } from './p2wsh.js';
|
|
37
|
+
export { p2op } from './p2op.js';
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
findScriptPath,
|
|
41
|
+
LEAF_VERSION_TAPSCRIPT,
|
|
42
|
+
MAX_TAPTREE_DEPTH,
|
|
43
|
+
rootHashFromPath,
|
|
44
|
+
tapleafHash,
|
|
45
|
+
toHashTree,
|
|
46
|
+
tweakKey,
|
|
47
|
+
type HashTree,
|
|
48
|
+
} from './bip341.js';
|
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
|
-
import { isPoint, stacksEqual, typeforce as typef } from '../types.js';
|
|
4
|
-
import { P2MSPayment, PaymentOpts, PaymentType
|
|
3
|
+
import { isPoint, stacksEqual, typeforce as typef, type Stack } from '../types.js';
|
|
4
|
+
import { P2MSPayment, PaymentOpts, PaymentType } from './types.js';
|
|
5
5
|
import * as lazy from './lazy.js';
|
|
6
6
|
|
|
7
7
|
const OPS = bscript.opcodes;
|
package/src/payments/p2op.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { bech32m } from 'bech32';
|
|
2
2
|
import { Buffer as NBuffer } from 'buffer';
|
|
3
|
-
import { fromBech32 } from '../
|
|
3
|
+
import { fromBech32 } from '../bech32utils.js';
|
|
4
4
|
import { bitcoin as BITCOIN_NETWORK, Network } from '../networks.js';
|
|
5
5
|
import * as bscript from '../script.js';
|
|
6
6
|
import { typeforce as typef } from '../types.js';
|
|
7
|
+
import { BasePayment, P2OPPayment, PaymentOpts, PaymentType } from './types.js';
|
|
7
8
|
import * as lazy from './lazy.js';
|
|
8
|
-
import { BasePayment, P2OPPayment, PaymentOpts, PaymentType } from './index.js';
|
|
9
9
|
|
|
10
10
|
const OPS = bscript.opcodes;
|
|
11
11
|
const P2OP_WITNESS_VERSION = 0x10;
|
package/src/payments/p2pk.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
|
-
import { isPoint, typeforce as typef } from '../types.js';
|
|
4
|
-
import { P2PKPayment, PaymentOpts, PaymentType
|
|
3
|
+
import { isPoint, typeforce as typef, type StackFunction } from '../types.js';
|
|
4
|
+
import { P2PKPayment, PaymentOpts, PaymentType } from './types.js';
|
|
5
5
|
import * as lazy from './lazy.js';
|
|
6
6
|
|
|
7
7
|
const OPS = bscript.opcodes;
|
package/src/payments/p2pkh.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as bs58check from 'bs58check';
|
|
2
2
|
import * as bcrypto from '../crypto.js';
|
|
3
3
|
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
4
|
+
import { decompressPublicKey } from '../pubkey.js';
|
|
4
5
|
import * as bscript from '../script.js';
|
|
5
|
-
import { isPoint, typeforce as typef } from '../types.js';
|
|
6
|
-
import { P2PKHPayment, PaymentOpts, PaymentType
|
|
6
|
+
import { isPoint, typeforce as typef, type StackFunction } from '../types.js';
|
|
7
|
+
import { P2PKHPayment, PaymentOpts, PaymentType } from './types.js';
|
|
7
8
|
import * as lazy from './lazy.js';
|
|
8
|
-
import { decompressPublicKey } from '../psbt/psbtutils.js';
|
|
9
9
|
|
|
10
10
|
const OPS = bscript.opcodes;
|
|
11
11
|
|
package/src/payments/p2sh.ts
CHANGED
|
@@ -2,16 +2,8 @@ import * as bs58check from 'bs58check';
|
|
|
2
2
|
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
|
-
import { stacksEqual, typeforce as typef } from '../types.js';
|
|
6
|
-
import {
|
|
7
|
-
P2SHPayment,
|
|
8
|
-
Payment,
|
|
9
|
-
PaymentOpts,
|
|
10
|
-
PaymentType,
|
|
11
|
-
ScriptRedeem,
|
|
12
|
-
Stack,
|
|
13
|
-
StackFunction,
|
|
14
|
-
} from './index.js';
|
|
5
|
+
import { stacksEqual, typeforce as typef, type Stack, type StackFunction } from '../types.js';
|
|
6
|
+
import { P2SHPayment, Payment, PaymentOpts, PaymentType, ScriptRedeem } from './types.js';
|
|
15
7
|
import * as lazy from './lazy.js';
|
|
16
8
|
|
|
17
9
|
const OPS = bscript.opcodes;
|
package/src/payments/p2tr.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { bech32m } from 'bech32';
|
|
2
2
|
import { Buffer as NBuffer } from 'buffer';
|
|
3
|
-
import { fromBech32 } from '../
|
|
3
|
+
import { fromBech32 } from '../bech32utils.js';
|
|
4
4
|
import { getEccLib } from '../ecc_lib.js';
|
|
5
5
|
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
6
6
|
import * as bscript from '../script.js';
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
toHashTree,
|
|
14
14
|
tweakKey,
|
|
15
15
|
} from './bip341.js';
|
|
16
|
-
import { P2TRPayment, PaymentOpts, PaymentType } from './
|
|
16
|
+
import { P2TRPayment, PaymentOpts, PaymentType } from './types.js';
|
|
17
17
|
import * as lazy from './lazy.js';
|
|
18
18
|
|
|
19
19
|
const OPS = bscript.opcodes;
|
package/src/payments/p2wpkh.ts
CHANGED
|
@@ -3,7 +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 { P2WPKHPayment, PaymentOpts, PaymentType } from './
|
|
6
|
+
import { P2WPKHPayment, PaymentOpts, PaymentType } from './types.js';
|
|
7
7
|
import * as lazy from './lazy.js';
|
|
8
8
|
|
|
9
9
|
const OPS = bscript.opcodes;
|
package/src/payments/p2wsh.ts
CHANGED
|
@@ -2,8 +2,14 @@ import { bech32 } from 'bech32';
|
|
|
2
2
|
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
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
isPoint,
|
|
7
|
+
stacksEqual,
|
|
8
|
+
typeforce as typef,
|
|
9
|
+
type StackElement,
|
|
10
|
+
type StackFunction,
|
|
11
|
+
} from '../types.js';
|
|
12
|
+
import { P2WSHPayment, PaymentOpts, PaymentType } from './types.js';
|
|
7
13
|
import * as lazy from './lazy.js';
|
|
8
14
|
|
|
9
15
|
const OPS = bscript.opcodes;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment types and interfaces
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Network } from '../networks.js';
|
|
7
|
+
import type { Taptree } from '../types.js';
|
|
8
|
+
|
|
9
|
+
export enum PaymentType {
|
|
10
|
+
P2PK = 'p2pk',
|
|
11
|
+
P2PKH = 'p2pkh',
|
|
12
|
+
P2SH = 'p2sh',
|
|
13
|
+
P2MS = 'p2ms',
|
|
14
|
+
P2WPKH = 'p2wpkh',
|
|
15
|
+
P2WSH = 'p2wsh',
|
|
16
|
+
P2TR = 'p2tr',
|
|
17
|
+
P2OP = 'p2op',
|
|
18
|
+
Embed = 'embed',
|
|
19
|
+
ScriptRedeem = 'scriptRedeem',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface BasePayment {
|
|
23
|
+
/** Convenience label, also the discriminant for the union. */
|
|
24
|
+
name?: PaymentType;
|
|
25
|
+
/** Network parameters (mainnet if omitted). */
|
|
26
|
+
network?: Network;
|
|
27
|
+
/** Fully-assembled scriptPubKey (if already known). */
|
|
28
|
+
output?: Buffer;
|
|
29
|
+
/** Raw scriptSig (legacy script types only). */
|
|
30
|
+
input?: Buffer;
|
|
31
|
+
/** Human-readable address (if already known). */
|
|
32
|
+
address?: string;
|
|
33
|
+
/** Segwit stack (empty for legacy). */
|
|
34
|
+
witness?: Buffer[];
|
|
35
|
+
|
|
36
|
+
/** Script template for P2SH, P2WSH, P2TR, etc. */
|
|
37
|
+
redeem?: ScriptRedeem;
|
|
38
|
+
|
|
39
|
+
/** Non-standard options used by some wallets. */
|
|
40
|
+
useHybrid?: boolean;
|
|
41
|
+
useUncompressed?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Helper used by redeeming script-template outputs (P2SH, P2WSH). */
|
|
45
|
+
export interface ScriptRedeem extends BasePayment {
|
|
46
|
+
output?: Buffer; // script template
|
|
47
|
+
redeemVersion?: number; // tapscript leaves etc.
|
|
48
|
+
network?: Network; // network parameters (mainnet if omitted)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface P2PKPayment extends BasePayment {
|
|
52
|
+
name: PaymentType.P2PK;
|
|
53
|
+
pubkey?: Buffer;
|
|
54
|
+
/** DER-encoded sig – empty until signed. */
|
|
55
|
+
signature?: Buffer;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface P2PKHPayment extends BasePayment {
|
|
59
|
+
name: PaymentType.P2PKH;
|
|
60
|
+
/** RIPEMD-160(SHA-256(pubkey)) – 20 bytes. */
|
|
61
|
+
hash?: Buffer;
|
|
62
|
+
pubkey?: Buffer;
|
|
63
|
+
signature?: Buffer;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface P2SHPayment extends BasePayment {
|
|
67
|
+
name: PaymentType.P2SH;
|
|
68
|
+
/** Hash160 of a redeem script. */
|
|
69
|
+
hash?: Buffer;
|
|
70
|
+
|
|
71
|
+
/** The entire signature stack when spending a P2SH (non-segwit). */
|
|
72
|
+
signatures?: Buffer[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface P2MSPayment extends BasePayment {
|
|
76
|
+
name: PaymentType.P2MS;
|
|
77
|
+
/** M-of-N parameters. */
|
|
78
|
+
m?: number;
|
|
79
|
+
n?: number;
|
|
80
|
+
pubkeys?: Buffer[];
|
|
81
|
+
signatures?: Buffer[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface P2WPKHPayment extends BasePayment {
|
|
85
|
+
name: PaymentType.P2WPKH;
|
|
86
|
+
/** 20-byte witness program. */
|
|
87
|
+
hash?: Buffer;
|
|
88
|
+
pubkey?: Buffer;
|
|
89
|
+
signature?: Buffer;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface P2WSHPayment extends BasePayment {
|
|
93
|
+
name: PaymentType.P2WSH;
|
|
94
|
+
/** 32-byte witness program. */
|
|
95
|
+
hash?: Buffer;
|
|
96
|
+
redeem?: ScriptRedeem;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface P2TRPayment extends BasePayment {
|
|
100
|
+
name: PaymentType.P2TR;
|
|
101
|
+
/** x-only pubkey that commits to the tree. */
|
|
102
|
+
pubkey?: Buffer;
|
|
103
|
+
/** Internal (untweaked) x-only pubkey. */
|
|
104
|
+
internalPubkey?: Buffer;
|
|
105
|
+
/** Merkle-root tweak, present when a script path exists. */
|
|
106
|
+
hash?: Buffer;
|
|
107
|
+
/** Full taptree description (optional, dev-side). */
|
|
108
|
+
scriptTree?: Taptree;
|
|
109
|
+
/** Key-path sig or leading stack elem. */
|
|
110
|
+
signature?: Buffer;
|
|
111
|
+
|
|
112
|
+
redeemVersion?: number; // tapscript leaves etc.
|
|
113
|
+
redeem?: ScriptRedeem;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface P2OPPayment extends BasePayment {
|
|
117
|
+
name: PaymentType.P2OP;
|
|
118
|
+
/** <deploymentVersion || HASH160(payload)> (2–40 bytes). */
|
|
119
|
+
program?: Buffer;
|
|
120
|
+
deploymentVersion: number | undefined;
|
|
121
|
+
/** Convenience slice of `program` (20 bytes for current spec). */
|
|
122
|
+
hash160?: Buffer;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface P2OPPaymentParams extends Omit<P2OPPayment, 'name' | 'deploymentVersion'> {
|
|
126
|
+
deploymentVersion?: number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** OP_RETURN data-carrying output */
|
|
130
|
+
export interface EmbedPayment extends BasePayment {
|
|
131
|
+
name: PaymentType.Embed;
|
|
132
|
+
/** Raw pushed chunks after OP_RETURN. */
|
|
133
|
+
data: Buffer[];
|
|
134
|
+
// `output` is automatically derived from `data` (or vice-versa)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export type Payment =
|
|
138
|
+
| P2PKPayment
|
|
139
|
+
| P2PKHPayment
|
|
140
|
+
| P2SHPayment
|
|
141
|
+
| P2MSPayment
|
|
142
|
+
| P2WPKHPayment
|
|
143
|
+
| P2WSHPayment
|
|
144
|
+
| P2TRPayment
|
|
145
|
+
| P2OPPayment
|
|
146
|
+
| EmbedPayment
|
|
147
|
+
| ScriptRedeem;
|
|
148
|
+
|
|
149
|
+
export type PaymentCreator = <T extends BasePayment>(a: T, opts?: PaymentOpts) => T;
|
|
150
|
+
|
|
151
|
+
export interface PaymentOpts {
|
|
152
|
+
validate?: boolean;
|
|
153
|
+
allowIncomplete?: boolean;
|
|
154
|
+
}
|
package/src/psbt/bip371.ts
CHANGED
|
@@ -7,14 +7,6 @@ import {
|
|
|
7
7
|
TapScriptSig,
|
|
8
8
|
TapTree,
|
|
9
9
|
} from 'bip174/src/lib/interfaces.js';
|
|
10
|
-
import { isTapleaf, isTaptree, Tapleaf, Taptree } from '../types.js';
|
|
11
|
-
|
|
12
|
-
interface PsbtOutputWithScript extends PsbtOutput {
|
|
13
|
-
script?: Buffer;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
import { Transaction } from '../transaction.js';
|
|
17
|
-
|
|
18
10
|
import {
|
|
19
11
|
LEAF_VERSION_TAPSCRIPT,
|
|
20
12
|
MAX_TAPTREE_DEPTH,
|
|
@@ -23,6 +15,9 @@ import {
|
|
|
23
15
|
tweakKey,
|
|
24
16
|
} from '../payments/bip341.js';
|
|
25
17
|
import { p2tr } from '../payments/p2tr.js';
|
|
18
|
+
import { toXOnly } from '../pubkey.js';
|
|
19
|
+
import { Transaction } from '../transaction.js';
|
|
20
|
+
import { isTapleaf, isTaptree, Tapleaf, Taptree } from '../types.js';
|
|
26
21
|
import {
|
|
27
22
|
isP2TR,
|
|
28
23
|
pubkeyPositionInScript,
|
|
@@ -30,11 +25,9 @@ import {
|
|
|
30
25
|
witnessStackToScriptWitness,
|
|
31
26
|
} from './psbtutils.js';
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
|
|
37
|
-
};
|
|
28
|
+
interface PsbtOutputWithScript extends PsbtOutput {
|
|
29
|
+
script?: Buffer;
|
|
30
|
+
}
|
|
38
31
|
|
|
39
32
|
/**
|
|
40
33
|
* Default tapscript finalizer. It searches for the `tapLeafHashToFinalize` if provided.
|
package/src/psbt/psbtutils.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ProjectivePoint } from '@noble/secp256k1';
|
|
2
1
|
import * as varuint from 'bip174/src/lib/converter/varint.js';
|
|
3
2
|
import { PartialSig, PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
4
3
|
import { hash160 } from '../crypto.js';
|
|
@@ -9,10 +8,10 @@ import { p2sh } from '../payments/p2sh.js';
|
|
|
9
8
|
import { p2tr } from '../payments/p2tr.js';
|
|
10
9
|
import { p2wpkh } from '../payments/p2wpkh.js';
|
|
11
10
|
import { p2wsh } from '../payments/p2wsh.js';
|
|
11
|
+
import { p2op } from '../payments/p2op.js';
|
|
12
|
+
import { decompressPublicKey, pubkeysMatch, toXOnly } from '../pubkey.js';
|
|
12
13
|
import * as bscript from '../script.js';
|
|
13
14
|
import { Transaction } from '../transaction.js';
|
|
14
|
-
import { toXOnly } from './bip371.js';
|
|
15
|
-
import { p2op } from '../payments/p2op.js';
|
|
16
15
|
|
|
17
16
|
type PaymentFunction = (opts: { output: Buffer }) => unknown;
|
|
18
17
|
|
|
@@ -85,107 +84,6 @@ export function witnessStackToScriptWitness(witness: Buffer[]): Buffer {
|
|
|
85
84
|
return buffer;
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
export interface UncompressedPublicKey {
|
|
89
|
-
hybrid: Buffer;
|
|
90
|
-
uncompressed: Buffer;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Converts an existing real Bitcoin public key (compressed or uncompressed)
|
|
95
|
-
* to its "hybrid" form (prefix 0x06/0x07), then derives a P2PKH address from it.
|
|
96
|
-
*
|
|
97
|
-
* @param realPubKey - 33-byte compressed (0x02/0x03) or 65-byte uncompressed (0x04) pubkey
|
|
98
|
-
* @returns Buffer | undefined
|
|
99
|
-
*/
|
|
100
|
-
export function decompressPublicKey(
|
|
101
|
-
realPubKey: Uint8Array | Buffer,
|
|
102
|
-
): UncompressedPublicKey | undefined {
|
|
103
|
-
if (realPubKey.length === 32) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (![33, 65].includes(realPubKey.length)) {
|
|
108
|
-
console.warn(
|
|
109
|
-
`Unsupported key length=${realPubKey.length}. Must be 33 (compressed) or 65 (uncompressed).`,
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
/*throw new Error(
|
|
113
|
-
`Unsupported key length=${realPubKey.length}. Must be 33 (compressed) or 65 (uncompressed).`,
|
|
114
|
-
);*/
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 1) Parse the public key to get an actual Point on secp256k1
|
|
119
|
-
// If it fails, the pubkey is invalid/corrupted.
|
|
120
|
-
let point: ProjectivePoint;
|
|
121
|
-
try {
|
|
122
|
-
point = ProjectivePoint.fromHex(realPubKey);
|
|
123
|
-
} catch (err) {
|
|
124
|
-
throw new Error('Invalid secp256k1 public key bytes. Cannot parse.');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// 2) Extract X and Y as 32-byte big-endian buffers
|
|
128
|
-
const xBuf = bigIntTo32Bytes(point.x);
|
|
129
|
-
const yBuf = bigIntTo32Bytes(point.y);
|
|
130
|
-
|
|
131
|
-
// 3) Determine if Y is even or odd. That decides the hybrid prefix:
|
|
132
|
-
// - 0x06 => "uncompressed + even Y"
|
|
133
|
-
// - 0x07 => "uncompressed + odd Y"
|
|
134
|
-
const isEven = point.y % 2n === 0n;
|
|
135
|
-
const prefix = isEven ? 0x06 : 0x07;
|
|
136
|
-
|
|
137
|
-
// 4) Construct 65-byte hybrid pubkey
|
|
138
|
-
// [prefix(1) || X(32) || Y(32)]
|
|
139
|
-
const hybridPubKey = Buffer.alloc(65);
|
|
140
|
-
hybridPubKey[0] = prefix;
|
|
141
|
-
xBuf.copy(hybridPubKey, 1);
|
|
142
|
-
yBuf.copy(hybridPubKey, 33);
|
|
143
|
-
|
|
144
|
-
const uncompressedPubKey = Buffer.concat([Buffer.from([0x04]), xBuf, yBuf]);
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
hybrid: hybridPubKey,
|
|
148
|
-
uncompressed: uncompressedPubKey,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/****************************************
|
|
153
|
-
* Convert bigint -> 32-byte Buffer
|
|
154
|
-
****************************************/
|
|
155
|
-
export function bigIntTo32Bytes(num: bigint): Buffer {
|
|
156
|
-
let hex = num.toString(16);
|
|
157
|
-
// Pad to 64 hex chars => 32 bytes
|
|
158
|
-
hex = hex.padStart(64, '0');
|
|
159
|
-
// In case it's bigger than 64 chars, slice the rightmost 64 (mod 2^256)
|
|
160
|
-
if (hex.length > 64) {
|
|
161
|
-
hex = hex.slice(-64);
|
|
162
|
-
}
|
|
163
|
-
return Buffer.from(hex, 'hex');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Compare two potential pubkey Buffers, treating hybrid keys (0x06/0x07)
|
|
168
|
-
* as equivalent to uncompressed (0x04).
|
|
169
|
-
*/
|
|
170
|
-
export function pubkeysMatch(a: Buffer, b: Buffer): boolean {
|
|
171
|
-
// If they’re literally the same bytes, no further check needed
|
|
172
|
-
if (a.equals(b)) return true;
|
|
173
|
-
|
|
174
|
-
// If both are 65 bytes, see if one is hybrid and the other is uncompressed
|
|
175
|
-
if (a.length === 65 && b.length === 65) {
|
|
176
|
-
const aCopy = Buffer.from(a);
|
|
177
|
-
const bCopy = Buffer.from(b);
|
|
178
|
-
|
|
179
|
-
// Convert 0x06/0x07 to 0x04
|
|
180
|
-
if (aCopy[0] === 0x06 || aCopy[0] === 0x07) aCopy[0] = 0x04;
|
|
181
|
-
if (bCopy[0] === 0x06 || bCopy[0] === 0x07) bCopy[0] = 0x04;
|
|
182
|
-
|
|
183
|
-
return aCopy.equals(bCopy);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
87
|
/**
|
|
190
88
|
* Finds the position of a public key in a script.
|
|
191
89
|
* @param pubkey The public key to search for.
|
package/src/psbt.ts
CHANGED
|
@@ -26,8 +26,9 @@ import { BIP32Interface } from '@btc-vision/bip32';
|
|
|
26
26
|
import { ECPairInterface } from 'ecpair';
|
|
27
27
|
import { fromOutputScript, isUnknownSegwitVersion, toOutputScript } from './address.js';
|
|
28
28
|
import { cloneBuffer, reverseBuffer } from './bufferutils.js';
|
|
29
|
-
import { P2WSHPayment, payments } from './index.js';
|
|
30
29
|
import { bitcoin as btcNetwork, Network } from './networks.js';
|
|
30
|
+
import * as payments from './payments/index.js';
|
|
31
|
+
import type { P2WSHPayment } from './payments/index.js';
|
|
31
32
|
import { tapleafHash } from './payments/bip341.js';
|
|
32
33
|
import { P2SHPayment, Payment, PaymentOpts } from './payments/index.js';
|
|
33
34
|
import {
|
|
@@ -37,8 +38,8 @@ import {
|
|
|
37
38
|
isTaprootInput,
|
|
38
39
|
serializeTaprootSignature,
|
|
39
40
|
tapScriptFinalizer,
|
|
40
|
-
toXOnly,
|
|
41
41
|
} from './psbt/bip371.js';
|
|
42
|
+
import { toXOnly } from './pubkey.js';
|
|
42
43
|
import {
|
|
43
44
|
checkInputForSig,
|
|
44
45
|
isP2MS,
|