@bitcoinerlab/descriptors 2.3.6 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +173 -77
- package/dist/applyPR2137.js +36 -17
- package/dist/bitcoinjs-lib-internals.d.ts +10 -0
- package/dist/bitcoinjs-lib-internals.js +18 -0
- package/dist/descriptors.d.ts +161 -392
- package/dist/descriptors.js +608 -283
- package/dist/index.d.ts +2 -29
- package/dist/index.js +0 -14
- package/dist/keyExpressions.d.ts +4 -13
- package/dist/keyExpressions.js +15 -18
- package/dist/ledger.d.ts +14 -37
- package/dist/ledger.js +147 -119
- package/dist/miniscript.d.ts +20 -6
- package/dist/miniscript.js +64 -17
- package/dist/multipath.d.ts +13 -0
- package/dist/multipath.js +76 -0
- package/dist/networkUtils.d.ts +3 -0
- package/dist/networkUtils.js +16 -0
- package/dist/parseUtils.d.ts +7 -0
- package/dist/parseUtils.js +46 -0
- package/dist/psbt.d.ts +17 -13
- package/dist/psbt.js +34 -50
- package/dist/resourceLimits.d.ts +25 -0
- package/dist/resourceLimits.js +89 -0
- package/dist/scriptExpressions.d.ts +29 -77
- package/dist/scriptExpressions.js +19 -16
- package/dist/signers.d.ts +1 -21
- package/dist/signers.js +85 -129
- package/dist/tapMiniscript.d.ts +215 -0
- package/dist/tapMiniscript.js +515 -0
- package/dist/tapTree.d.ts +86 -0
- package/dist/tapTree.js +167 -0
- package/dist/types.d.ts +52 -6
- package/package.json +13 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,8 @@
|
|
|
1
|
-
export type { KeyInfo,
|
|
2
|
-
|
|
3
|
-
import type { DescriptorInstance, OutputInstance } from './descriptors';
|
|
4
|
-
export { DescriptorsFactory, DescriptorInstance, DescriptorConstructor, OutputInstance, OutputConstructor } from './descriptors';
|
|
1
|
+
export type { Expansion, ExpansionMap, KeyExpressionParser, KeyInfo, Preimage, TimeConstraints } from './types';
|
|
2
|
+
export { DescriptorsFactory, OutputInstance, OutputConstructor } from './descriptors';
|
|
5
3
|
export { DescriptorChecksum as checksum } from './checksum';
|
|
6
4
|
import * as signers from './signers';
|
|
7
5
|
export { signers };
|
|
8
|
-
/**
|
|
9
|
-
* @hidden @deprecated
|
|
10
|
-
* To finalize the `psbt`, you can either call the method
|
|
11
|
-
* `output.finalizePsbtInput({ index, psbt })` on each descriptor, passing as
|
|
12
|
-
* arguments the `psbt` and its input `index`, or call this helper function:
|
|
13
|
-
* `finalizePsbt({psbt, outputs })`. In the latter case, `outputs` is an
|
|
14
|
-
* array of {@link _Internal_.Output | Output elements} ordered in the array by
|
|
15
|
-
* their respective input index in the `psbt`.
|
|
16
|
-
*/
|
|
17
|
-
declare function finalizePsbt(params: {
|
|
18
|
-
psbt: Psbt;
|
|
19
|
-
outputs: OutputInstance[];
|
|
20
|
-
validate?: boolean | undefined;
|
|
21
|
-
}): void;
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated
|
|
24
|
-
* @hidden
|
|
25
|
-
* To be removed in version 3.0
|
|
26
|
-
*/
|
|
27
|
-
declare function finalizePsbt(params: {
|
|
28
|
-
psbt: Psbt;
|
|
29
|
-
descriptors: DescriptorInstance[];
|
|
30
|
-
validate?: boolean | undefined;
|
|
31
|
-
}): void;
|
|
32
|
-
export { finalizePsbt };
|
|
33
6
|
export { keyExpressionBIP32, keyExpressionLedger } from './keyExpressions';
|
|
34
7
|
import * as scriptExpressions from './scriptExpressions';
|
|
35
8
|
export { scriptExpressions };
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
})();
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.ledger = exports.scriptExpressions = exports.keyExpressionLedger = exports.keyExpressionBIP32 = exports.signers = exports.checksum = exports.DescriptorsFactory = void 0;
|
|
39
|
-
exports.finalizePsbt = finalizePsbt;
|
|
40
39
|
// Some dependencies (like hash-base) assume process.version exists.
|
|
41
40
|
// In React Native / Hermes, process is defined but version is not.
|
|
42
41
|
// Note: we only polyfill if process already exists but is incomplete.
|
|
@@ -67,19 +66,6 @@ var checksum_1 = require("./checksum");
|
|
|
67
66
|
Object.defineProperty(exports, "checksum", { enumerable: true, get: function () { return checksum_1.DescriptorChecksum; } });
|
|
68
67
|
const signers = __importStar(require("./signers"));
|
|
69
68
|
exports.signers = signers;
|
|
70
|
-
/**
|
|
71
|
-
* @hidden
|
|
72
|
-
* To be removed in v3.0 and replaced by the version with the signature that
|
|
73
|
-
* does not accept descriptors
|
|
74
|
-
*/
|
|
75
|
-
function finalizePsbt({ psbt, outputs, descriptors, validate = true }) {
|
|
76
|
-
if (descriptors && outputs)
|
|
77
|
-
throw new Error(`descriptors param has been deprecated`);
|
|
78
|
-
outputs = descriptors || outputs;
|
|
79
|
-
if (!outputs)
|
|
80
|
-
throw new Error(`outputs not provided`);
|
|
81
|
-
outputs.forEach((output, inputIndex) => output.finalizePsbtInput({ index: inputIndex, psbt, validate }));
|
|
82
|
-
}
|
|
83
69
|
var keyExpressions_1 = require("./keyExpressions");
|
|
84
70
|
Object.defineProperty(exports, "keyExpressionBIP32", { enumerable: true, get: function () { return keyExpressions_1.keyExpressionBIP32; } });
|
|
85
71
|
Object.defineProperty(exports, "keyExpressionLedger", { enumerable: true, get: function () { return keyExpressions_1.keyExpressionLedger; } });
|
package/dist/keyExpressions.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Network } from 'bitcoinjs-lib';
|
|
|
2
2
|
import type { ECPairAPI } from 'ecpair';
|
|
3
3
|
import type { BIP32API, BIP32Interface } from 'bip32';
|
|
4
4
|
import type { KeyInfo } from './types';
|
|
5
|
-
import {
|
|
5
|
+
import { LedgerManager } from './ledger';
|
|
6
6
|
/**
|
|
7
7
|
* Parses a key expression (xpub, xprv, pubkey or wif) into {@link KeyInfo | `KeyInfo`}.
|
|
8
8
|
*
|
|
@@ -49,7 +49,7 @@ export declare function parseKeyExpression({ keyExpression, isSegwit, isTaproot,
|
|
|
49
49
|
*
|
|
50
50
|
* For detailed understanding and examples of terms like `originPath`,
|
|
51
51
|
* `change`, and `keyPath`, refer to the documentation of
|
|
52
|
-
* {@link _Internal_.
|
|
52
|
+
* {@link _Internal_.KeyExpressionParser | KeyExpressionParser}, which consists
|
|
53
53
|
* of the reverse procedure.
|
|
54
54
|
*
|
|
55
55
|
* @returns {string} - The formed key expression for the Ledger device.
|
|
@@ -61,22 +61,13 @@ export declare function keyExpressionLedger({ ledgerManager, originPath, keyPath
|
|
|
61
61
|
index?: number | undefined | '*';
|
|
62
62
|
keyPath?: string | undefined;
|
|
63
63
|
}): Promise<string>;
|
|
64
|
-
/** @hidden */
|
|
65
|
-
export declare function keyExpressionLedger({ ledgerClient, ledgerState, originPath, keyPath, change, index }: {
|
|
66
|
-
ledgerClient: unknown;
|
|
67
|
-
ledgerState: LedgerState;
|
|
68
|
-
originPath: string;
|
|
69
|
-
change?: number | undefined;
|
|
70
|
-
index?: number | undefined | '*';
|
|
71
|
-
keyPath?: string | undefined;
|
|
72
|
-
}): Promise<string>;
|
|
73
64
|
/**
|
|
74
65
|
* Constructs a key expression string from its constituent components.
|
|
75
66
|
*
|
|
76
67
|
* This function essentially performs the reverse operation of
|
|
77
|
-
* {@link _Internal_.
|
|
68
|
+
* {@link _Internal_.KeyExpressionParser | KeyExpressionParser}. For detailed
|
|
78
69
|
* explanations and examples of the terms used here, refer to
|
|
79
|
-
* {@link _Internal_.
|
|
70
|
+
* {@link _Internal_.KeyExpressionParser | KeyExpressionParser}.
|
|
80
71
|
*/
|
|
81
72
|
export declare function keyExpressionBIP32({ masterNode, originPath, keyPath, change, index, isPublic }: {
|
|
82
73
|
masterNode: BIP32Interface;
|
package/dist/keyExpressions.js
CHANGED
|
@@ -40,6 +40,7 @@ exports.keyExpressionLedger = keyExpressionLedger;
|
|
|
40
40
|
exports.keyExpressionBIP32 = keyExpressionBIP32;
|
|
41
41
|
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
42
42
|
const ledger_1 = require("./ledger");
|
|
43
|
+
const uint8array_tools_1 = require("uint8array-tools");
|
|
43
44
|
const RE = __importStar(require("./re"));
|
|
44
45
|
const derivePath = (node, path) => {
|
|
45
46
|
if (typeof path !== 'string') {
|
|
@@ -72,6 +73,8 @@ const derivePath = (node, path) => {
|
|
|
72
73
|
* ```
|
|
73
74
|
*/
|
|
74
75
|
function parseKeyExpression({ keyExpression, isSegwit, isTaproot, ECPair, BIP32, network = bitcoinjs_lib_1.networks.bitcoin }) {
|
|
76
|
+
if (isTaproot && isSegwit !== true)
|
|
77
|
+
throw new Error(`Error: taproot key expressions require isSegwit`);
|
|
75
78
|
let pubkey; //won't be computed for ranged keyExpressions
|
|
76
79
|
let ecpair;
|
|
77
80
|
let bip32;
|
|
@@ -108,7 +111,7 @@ function parseKeyExpression({ keyExpression, isSegwit, isTaproot, ECPair, BIP32,
|
|
|
108
111
|
if (masterFingerprintHex.length > 0) {
|
|
109
112
|
if (masterFingerprintHex.length !== 8)
|
|
110
113
|
throw new Error(`Error: masterFingerprint ${masterFingerprintHex} invalid for keyExpression: ${keyExpression}`);
|
|
111
|
-
masterFingerprint =
|
|
114
|
+
masterFingerprint = (0, uint8array_tools_1.fromHex)(masterFingerprintHex);
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
//Remove the origin (if it exists) and store result in actualKey
|
|
@@ -116,10 +119,10 @@ function parseKeyExpression({ keyExpression, isSegwit, isTaproot, ECPair, BIP32,
|
|
|
116
119
|
let mPubKey, mWIF, mXpubKey, mXprvKey;
|
|
117
120
|
//match pubkey:
|
|
118
121
|
if ((mPubKey = actualKey.match(RE.anchorStartAndEnd(rePubKey))) !== null) {
|
|
119
|
-
pubkey =
|
|
122
|
+
pubkey = (0, uint8array_tools_1.fromHex)(mPubKey[0]);
|
|
120
123
|
if (isTaproot && pubkey.length === 32)
|
|
121
124
|
//convert the xonly point to a compressed point assuming even parity
|
|
122
|
-
pubkey =
|
|
125
|
+
pubkey = (0, uint8array_tools_1.concat)([Uint8Array.from([0x02]), pubkey]);
|
|
123
126
|
ecpair = ECPair.fromPublicKey(pubkey, { network });
|
|
124
127
|
//Validate the pubkey (compressed or uncompressed)
|
|
125
128
|
if (!ECPair.isPoint(pubkey) ||
|
|
@@ -127,6 +130,7 @@ function parseKeyExpression({ keyExpression, isSegwit, isTaproot, ECPair, BIP32,
|
|
|
127
130
|
throw new Error(`Error: invalid pubkey`);
|
|
128
131
|
}
|
|
129
132
|
//Do an extra check in case we know this pubkey refers to a segwit input
|
|
133
|
+
//Taproot x-only keys are converted to 33-byte compressed form above.
|
|
130
134
|
if (typeof isSegwit === 'boolean' &&
|
|
131
135
|
isSegwit &&
|
|
132
136
|
pubkey.length !== 33 //Inside wpkh and wsh, only compressed public keys are permitted.
|
|
@@ -207,21 +211,14 @@ function assertChangeIndexKeyPath({ change, index, keyPath }) {
|
|
|
207
211
|
if ((change !== undefined) === (keyPath !== undefined))
|
|
208
212
|
throw new Error(`Error: Pass either change and index or a keyPath`);
|
|
209
213
|
}
|
|
210
|
-
/** @
|
|
211
|
-
async function keyExpressionLedger({
|
|
212
|
-
if (ledgerManager && (ledgerClient || ledgerState))
|
|
213
|
-
throw new Error(`ledgerClient and ledgerState have been deprecated`);
|
|
214
|
-
if (ledgerManager)
|
|
215
|
-
({ ledgerClient, ledgerState } = ledgerManager);
|
|
216
|
-
if (!ledgerClient || !ledgerState)
|
|
217
|
-
throw new Error(`Could not retrieve ledgerClient or ledgerState`);
|
|
214
|
+
/** @hidden */
|
|
215
|
+
async function keyExpressionLedger({ ledgerManager, originPath, keyPath, change, index }) {
|
|
218
216
|
assertChangeIndexKeyPath({ change, index, keyPath });
|
|
219
217
|
const masterFingerprint = await (0, ledger_1.getLedgerMasterFingerPrint)({
|
|
220
|
-
|
|
221
|
-
ledgerState
|
|
218
|
+
ledgerManager
|
|
222
219
|
});
|
|
223
|
-
const origin = `[${
|
|
224
|
-
const xpub = await (0, ledger_1.getLedgerXpub)({ originPath,
|
|
220
|
+
const origin = `[${(0, uint8array_tools_1.toHex)(masterFingerprint)}${originPath}]`;
|
|
221
|
+
const xpub = await (0, ledger_1.getLedgerXpub)({ originPath, ledgerManager });
|
|
225
222
|
const keyRoot = `${origin}${xpub}`;
|
|
226
223
|
if (keyPath !== undefined)
|
|
227
224
|
return `${keyRoot}${keyPath}`;
|
|
@@ -232,14 +229,14 @@ async function keyExpressionLedger({ ledgerClient, ledgerState, ledgerManager, o
|
|
|
232
229
|
* Constructs a key expression string from its constituent components.
|
|
233
230
|
*
|
|
234
231
|
* This function essentially performs the reverse operation of
|
|
235
|
-
* {@link _Internal_.
|
|
232
|
+
* {@link _Internal_.KeyExpressionParser | KeyExpressionParser}. For detailed
|
|
236
233
|
* explanations and examples of the terms used here, refer to
|
|
237
|
-
* {@link _Internal_.
|
|
234
|
+
* {@link _Internal_.KeyExpressionParser | KeyExpressionParser}.
|
|
238
235
|
*/
|
|
239
236
|
function keyExpressionBIP32({ masterNode, originPath, keyPath, change, index, isPublic = true }) {
|
|
240
237
|
assertChangeIndexKeyPath({ change, index, keyPath });
|
|
241
238
|
const masterFingerprint = masterNode.fingerprint;
|
|
242
|
-
const origin = `[${
|
|
239
|
+
const origin = `[${(0, uint8array_tools_1.toHex)(masterFingerprint)}${originPath}]`;
|
|
243
240
|
const xpub = isPublic
|
|
244
241
|
? masterNode.derivePath(`m${originPath}`).neutered().toBase58().toString()
|
|
245
242
|
: masterNode.derivePath(`m${originPath}`).toBase58().toString();
|
package/dist/ledger.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OutputInstance } from './descriptors';
|
|
2
2
|
import { Network, Psbt } from 'bitcoinjs-lib';
|
|
3
3
|
import type { TinySecp256k1Interface } from './types';
|
|
4
4
|
/**
|
|
5
|
-
* Dynamically imports the 'ledger-bitcoin' module and, if provided, checks if `ledgerClient` is an instance of `AppClient`.
|
|
5
|
+
* Dynamically imports the '@ledgerhq/ledger-bitcoin' module and, if provided, checks if `ledgerClient` is an instance of `AppClient`.
|
|
6
6
|
*
|
|
7
7
|
* @async
|
|
8
8
|
* @param {unknown} ledgerClient - An optional parameter that, if provided, is checked to see if it's an instance of `AppClient`.
|
|
9
9
|
* @throws {Error} Throws an error if `ledgerClient` is provided but is not an instance of `AppClient`.
|
|
10
|
-
* @throws {Error} Throws an error if the 'ledger-bitcoin' module cannot be imported. This typically indicates that the 'ledger-bitcoin' peer dependency is not installed.
|
|
11
|
-
* @returns {Promise<unknown>} Returns a promise that resolves with the entire 'ledger-bitcoin' module if it can be successfully imported. We force it to return an unknown type so that the declaration of this function won't break projects that don't use ledger-bitcoin as dependency
|
|
10
|
+
* @throws {Error} Throws an error if the '@ledgerhq/ledger-bitcoin' module cannot be imported. This typically indicates that the '@ledgerhq/ledger-bitcoin' peer dependency is not installed.
|
|
11
|
+
* @returns {Promise<unknown>} Returns a promise that resolves with the entire '@ledgerhq/ledger-bitcoin' module if it can be successfully imported. We force it to return an unknown type so that the declaration of this function won't break projects that don't use @ledgerhq/ledger-bitcoin as dependency
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
*
|
|
@@ -48,8 +48,8 @@ export type LedgerPolicy = {
|
|
|
48
48
|
policyName?: string;
|
|
49
49
|
ledgerTemplate: string;
|
|
50
50
|
keyRoots: string[];
|
|
51
|
-
policyId?:
|
|
52
|
-
policyHmac?:
|
|
51
|
+
policyId?: Uint8Array;
|
|
52
|
+
policyHmac?: Uint8Array;
|
|
53
53
|
};
|
|
54
54
|
/**
|
|
55
55
|
* Ledger devices operate in a state-less manner. Therefore, policy information
|
|
@@ -57,7 +57,7 @@ export type LedgerPolicy = {
|
|
|
57
57
|
* `ledgerState` also stores cached xpubs and the masterFingerprint.
|
|
58
58
|
*/
|
|
59
59
|
export type LedgerState = {
|
|
60
|
-
masterFingerprint?:
|
|
60
|
+
masterFingerprint?: Uint8Array;
|
|
61
61
|
policies?: LedgerPolicy[];
|
|
62
62
|
xpubs?: {
|
|
63
63
|
[key: string]: string;
|
|
@@ -74,12 +74,7 @@ export type LedgerManager = {
|
|
|
74
74
|
*/
|
|
75
75
|
export declare function getLedgerMasterFingerPrint({ ledgerManager }: {
|
|
76
76
|
ledgerManager: LedgerManager;
|
|
77
|
-
}): Promise<
|
|
78
|
-
/** @hidden */
|
|
79
|
-
export declare function getLedgerMasterFingerPrint({ ledgerClient, ledgerState }: {
|
|
80
|
-
ledgerClient: unknown;
|
|
81
|
-
ledgerState: LedgerState;
|
|
82
|
-
}): Promise<Buffer>;
|
|
77
|
+
}): Promise<Uint8Array>;
|
|
83
78
|
/**
|
|
84
79
|
* Retrieves the xpub of a certain originPath of a Ledger device
|
|
85
80
|
*/
|
|
@@ -87,12 +82,6 @@ export declare function getLedgerXpub({ originPath, ledgerManager }: {
|
|
|
87
82
|
originPath: string;
|
|
88
83
|
ledgerManager: LedgerManager;
|
|
89
84
|
}): Promise<string>;
|
|
90
|
-
/** @deprecated @hidden */
|
|
91
|
-
export declare function getLedgerXpub({ originPath, ledgerClient, ledgerState }: {
|
|
92
|
-
originPath: string;
|
|
93
|
-
ledgerClient: unknown;
|
|
94
|
-
ledgerState: LedgerState;
|
|
95
|
-
}): Promise<string>;
|
|
96
85
|
/**
|
|
97
86
|
* Checks whether there is a policy in ledgerState that the ledger
|
|
98
87
|
* could use to sign this psbt input.
|
|
@@ -133,10 +122,9 @@ export declare function ledgerPolicyFromPsbtInput({ ledgerManager, psbt, index }
|
|
|
133
122
|
* This function takes into account all the considerations regarding Ledger
|
|
134
123
|
* policy implementation details expressed in the header of this file.
|
|
135
124
|
*/
|
|
136
|
-
export declare function ledgerPolicyFromOutput({ output,
|
|
125
|
+
export declare function ledgerPolicyFromOutput({ output, ledgerManager }: {
|
|
137
126
|
output: OutputInstance;
|
|
138
|
-
|
|
139
|
-
ledgerState: LedgerState;
|
|
127
|
+
ledgerManager: LedgerManager;
|
|
140
128
|
}): Promise<{
|
|
141
129
|
ledgerTemplate: string;
|
|
142
130
|
keyRoots: string[];
|
|
@@ -162,29 +150,18 @@ export declare function registerLedgerWallet({ descriptor, ledgerManager, policy
|
|
|
162
150
|
/** The Name we want to assign to this specific policy */
|
|
163
151
|
policyName: string;
|
|
164
152
|
}): Promise<void>;
|
|
165
|
-
/**
|
|
166
|
-
* @hidden
|
|
167
|
-
*/
|
|
168
|
-
export declare function registerLedgerWallet({ descriptor, ledgerClient, ledgerState, policyName }: {
|
|
169
|
-
descriptor: DescriptorInstance;
|
|
170
|
-
ledgerClient: unknown;
|
|
171
|
-
ledgerState: LedgerState;
|
|
172
|
-
policyName: string;
|
|
173
|
-
}): Promise<void>;
|
|
174
153
|
/**
|
|
175
154
|
* Retrieve a standard ledger policy or null if it does correspond.
|
|
176
155
|
**/
|
|
177
|
-
export declare function ledgerPolicyFromStandard({ output,
|
|
156
|
+
export declare function ledgerPolicyFromStandard({ output, ledgerManager }: {
|
|
178
157
|
output: OutputInstance;
|
|
179
|
-
|
|
180
|
-
ledgerState: LedgerState;
|
|
158
|
+
ledgerManager: LedgerManager;
|
|
181
159
|
}): Promise<LedgerPolicy | null>;
|
|
182
160
|
export declare function comparePolicies(policyA: LedgerPolicy, policyB: LedgerPolicy): boolean;
|
|
183
161
|
/**
|
|
184
162
|
* Retrieve a ledger policy from ledgerState or null if it does not exist yet.
|
|
185
163
|
**/
|
|
186
|
-
export declare function ledgerPolicyFromState({ output,
|
|
164
|
+
export declare function ledgerPolicyFromState({ output, ledgerManager }: {
|
|
187
165
|
output: OutputInstance;
|
|
188
|
-
|
|
189
|
-
ledgerState: LedgerState;
|
|
166
|
+
ledgerManager: LedgerManager;
|
|
190
167
|
}): Promise<LedgerPolicy | null>;
|