@bitcoinerlab/descriptors-core 3.1.0
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 +710 -0
- package/dist/adapters/applyPR2137.d.ts +2 -0
- package/dist/adapters/applyPR2137.js +150 -0
- package/dist/adapters/bitcoinjs.d.ts +8 -0
- package/dist/adapters/bitcoinjs.js +36 -0
- package/dist/adapters/scure/address.d.ts +2 -0
- package/dist/adapters/scure/address.js +50 -0
- package/dist/adapters/scure/bip32.d.ts +2 -0
- package/dist/adapters/scure/bip32.js +16 -0
- package/dist/adapters/scure/common.d.ts +14 -0
- package/dist/adapters/scure/common.js +36 -0
- package/dist/adapters/scure/ecpair.d.ts +2 -0
- package/dist/adapters/scure/ecpair.js +58 -0
- package/dist/adapters/scure/payments.d.ts +2 -0
- package/dist/adapters/scure/payments.js +216 -0
- package/dist/adapters/scure/psbt.d.ts +43 -0
- package/dist/adapters/scure/psbt.js +382 -0
- package/dist/adapters/scure/script.d.ts +20 -0
- package/dist/adapters/scure/script.js +163 -0
- package/dist/adapters/scure/transaction.d.ts +2 -0
- package/dist/adapters/scure/transaction.js +32 -0
- package/dist/adapters/scure.d.ts +6 -0
- package/dist/adapters/scure.js +37 -0
- package/dist/adapters/scureKeys.d.ts +4 -0
- package/dist/adapters/scureKeys.js +135 -0
- package/dist/bip174.d.ts +87 -0
- package/dist/bip174.js +12 -0
- package/dist/bitcoinLib.d.ts +385 -0
- package/dist/bitcoinLib.js +19 -0
- package/dist/bitcoinjs-lib-internals.d.ts +6 -0
- package/dist/bitcoinjs-lib-internals.js +60 -0
- package/dist/bitcoinjs.d.ts +12 -0
- package/dist/bitcoinjs.js +18 -0
- package/dist/checksum.d.ts +6 -0
- package/dist/checksum.js +58 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +79 -0
- package/dist/descriptors.d.ts +481 -0
- package/dist/descriptors.js +1888 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +87 -0
- package/dist/keyExpressions.d.ts +124 -0
- package/dist/keyExpressions.js +310 -0
- package/dist/keyInterfaces.d.ts +5 -0
- package/dist/keyInterfaces.js +50 -0
- package/dist/ledger.d.ts +183 -0
- package/dist/ledger.js +618 -0
- package/dist/miniscript.d.ts +125 -0
- package/dist/miniscript.js +310 -0
- 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/networks.d.ts +16 -0
- package/dist/networks.js +31 -0
- package/dist/parseUtils.d.ts +7 -0
- package/dist/parseUtils.js +46 -0
- package/dist/psbt.d.ts +40 -0
- package/dist/psbt.js +228 -0
- package/dist/re.d.ts +31 -0
- package/dist/re.js +79 -0
- package/dist/resourceLimits.d.ts +28 -0
- package/dist/resourceLimits.js +84 -0
- package/dist/scriptExpressions.d.ts +95 -0
- package/dist/scriptExpressions.js +98 -0
- package/dist/scure.d.ts +4 -0
- package/dist/scure.js +10 -0
- package/dist/signers.d.ts +161 -0
- package/dist/signers.js +324 -0
- package/dist/tapMiniscript.d.ts +231 -0
- package/dist/tapMiniscript.js +524 -0
- package/dist/tapTree.d.ts +91 -0
- package/dist/tapTree.js +166 -0
- package/dist/types.d.ts +296 -0
- package/dist/types.js +4 -0
- package/package.json +148 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Reimplements a small subset of bitcoinjs-lib internal helpers.
|
|
4
|
+
* Keep this module free of deep imports (for example `bitcoinjs-lib/src/*`)
|
|
5
|
+
* so it works consistently across Node.js, browser bundlers (including
|
|
6
|
+
* CodeSandbox), and React Native/Metro.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.tapleafHash = tapleafHash;
|
|
10
|
+
exports.tapTweakHash = tapTweakHash;
|
|
11
|
+
exports.witnessStackToScriptWitness = witnessStackToScriptWitness;
|
|
12
|
+
exports.isTaprootInput = isTaprootInput;
|
|
13
|
+
const varuint_bitcoin_1 = require("varuint-bitcoin");
|
|
14
|
+
const uint8array_tools_1 = require("uint8array-tools");
|
|
15
|
+
const crypto_1 = require("./crypto");
|
|
16
|
+
const TAPROOT_LEAF_VERSION_TAPSCRIPT = 0xc0;
|
|
17
|
+
const OP_1 = 0x51;
|
|
18
|
+
const PUSH_DATA_32 = 0x20;
|
|
19
|
+
function serializeScript(script) {
|
|
20
|
+
const { buffer: encodedLength } = (0, varuint_bitcoin_1.encode)(script.length);
|
|
21
|
+
return (0, uint8array_tools_1.concat)([encodedLength, script]);
|
|
22
|
+
}
|
|
23
|
+
function isP2TRScript(script) {
|
|
24
|
+
return (script instanceof Uint8Array &&
|
|
25
|
+
script.length === 34 &&
|
|
26
|
+
script[0] === OP_1 &&
|
|
27
|
+
script[1] === PUSH_DATA_32);
|
|
28
|
+
}
|
|
29
|
+
function tapleafHash(leaf) {
|
|
30
|
+
const version = leaf.version || TAPROOT_LEAF_VERSION_TAPSCRIPT;
|
|
31
|
+
return (0, crypto_1.taggedHash)('TapLeaf', (0, uint8array_tools_1.concat)([Uint8Array.from([version]), serializeScript(leaf.output)]));
|
|
32
|
+
}
|
|
33
|
+
function tapTweakHash(pubKey, h) {
|
|
34
|
+
return (0, crypto_1.taggedHash)('TapTweak', (0, uint8array_tools_1.concat)(h ? [pubKey, h] : [pubKey]));
|
|
35
|
+
}
|
|
36
|
+
function witnessStackToScriptWitness(witness) {
|
|
37
|
+
let buffer = new Uint8Array(0);
|
|
38
|
+
const writeSlice = (slice) => {
|
|
39
|
+
buffer = (0, uint8array_tools_1.concat)([buffer, slice]);
|
|
40
|
+
};
|
|
41
|
+
const writeVarInt = (value) => {
|
|
42
|
+
const { buffer: encoded } = (0, varuint_bitcoin_1.encode)(value);
|
|
43
|
+
writeSlice(encoded);
|
|
44
|
+
};
|
|
45
|
+
const writeVarSlice = (slice) => {
|
|
46
|
+
writeVarInt(slice.length);
|
|
47
|
+
writeSlice(slice);
|
|
48
|
+
};
|
|
49
|
+
writeVarInt(witness.length);
|
|
50
|
+
witness.forEach(writeVarSlice);
|
|
51
|
+
return buffer;
|
|
52
|
+
}
|
|
53
|
+
function isTaprootInput(input) {
|
|
54
|
+
return (!!input &&
|
|
55
|
+
!!(input.tapInternalKey ||
|
|
56
|
+
input.tapMerkleRoot ||
|
|
57
|
+
(input.tapLeafScript && input.tapLeafScript.length > 0) ||
|
|
58
|
+
(input.tapBip32Derivation && input.tapBip32Derivation.length > 0) ||
|
|
59
|
+
isP2TRScript(input.witnessUtxo?.script)));
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Separate entry point for the bitcoinjs-lib adapter.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { createBitcoinjsLib } from '@bitcoinerlab/descriptors/bitcoinjs';
|
|
6
|
+
* import { DescriptorsFactory } from '@bitcoinerlab/descriptors';
|
|
7
|
+
* import * as ecc from '@bitcoinerlab/secp256k1';
|
|
8
|
+
*
|
|
9
|
+
* const lib = createBitcoinjsLib(ecc);
|
|
10
|
+
* const { Output } = DescriptorsFactory(lib);
|
|
11
|
+
*/
|
|
12
|
+
export { createBitcoinjsLib } from './adapters/bitcoinjs';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2026 Jose-Luis Landabaso - https://bitcoinerlab.com
|
|
3
|
+
// Distributed under the MIT software license
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.createBitcoinjsLib = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* Separate entry point for the bitcoinjs-lib adapter.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* import { createBitcoinjsLib } from '@bitcoinerlab/descriptors/bitcoinjs';
|
|
11
|
+
* import { DescriptorsFactory } from '@bitcoinerlab/descriptors';
|
|
12
|
+
* import * as ecc from '@bitcoinerlab/secp256k1';
|
|
13
|
+
*
|
|
14
|
+
* const lib = createBitcoinjsLib(ecc);
|
|
15
|
+
* const { Output } = DescriptorsFactory(lib);
|
|
16
|
+
*/
|
|
17
|
+
var bitcoinjs_1 = require("./adapters/bitcoinjs");
|
|
18
|
+
Object.defineProperty(exports, "createBitcoinjsLib", { enumerable: true, get: function () { return bitcoinjs_1.createBitcoinjsLib; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const CHECKSUM_CHARSET: string;
|
|
2
|
+
/**
|
|
3
|
+
* Implements the Bitcoin descriptor's checksum algorithm described in
|
|
4
|
+
* {@link https://github.com/bitcoin/bitcoin/blob/master/src/script/descriptor.cpp}
|
|
5
|
+
*/
|
|
6
|
+
export declare const DescriptorChecksum: (span: string) => string;
|
package/dist/checksum.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DescriptorChecksum = exports.CHECKSUM_CHARSET = void 0;
|
|
4
|
+
// Converted to Javascript by Jose-Luis Landabaso, 2023 - https://bitcoinerlab.com
|
|
5
|
+
// Source: https://github.com/bitcoin/bitcoin/blob/master/src/script/descriptor.cpp
|
|
6
|
+
// Distributed under the MIT software license
|
|
7
|
+
const PolyMod = (c, val) => {
|
|
8
|
+
const c0 = c >> 35n;
|
|
9
|
+
c = ((c & 0x7ffffffffn) << 5n) ^ val;
|
|
10
|
+
if (c0 & 1n)
|
|
11
|
+
c ^= 0xf5dee51989n;
|
|
12
|
+
if (c0 & 2n)
|
|
13
|
+
c ^= 0xa9fdca3312n;
|
|
14
|
+
if (c0 & 4n)
|
|
15
|
+
c ^= 0x1bab10e32dn;
|
|
16
|
+
if (c0 & 8n)
|
|
17
|
+
c ^= 0x3706b1677an;
|
|
18
|
+
if (c0 & 16n)
|
|
19
|
+
c ^= 0x644d626ffdn;
|
|
20
|
+
return c;
|
|
21
|
+
};
|
|
22
|
+
exports.CHECKSUM_CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
|
|
23
|
+
/**
|
|
24
|
+
* Implements the Bitcoin descriptor's checksum algorithm described in
|
|
25
|
+
* {@link https://github.com/bitcoin/bitcoin/blob/master/src/script/descriptor.cpp}
|
|
26
|
+
*/
|
|
27
|
+
const DescriptorChecksum = (span) => {
|
|
28
|
+
const INPUT_CHARSET = '0123456789()[],\'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#"\\ ';
|
|
29
|
+
let c = 1n;
|
|
30
|
+
let cls = 0n;
|
|
31
|
+
let clscount = 0n;
|
|
32
|
+
for (const ch of span) {
|
|
33
|
+
const pos = BigInt(INPUT_CHARSET.indexOf(ch));
|
|
34
|
+
if (pos === -1n)
|
|
35
|
+
return '';
|
|
36
|
+
c = PolyMod(c, pos & 31n);
|
|
37
|
+
cls = cls * 3n + (pos >> 5n);
|
|
38
|
+
if (++clscount === 3n) {
|
|
39
|
+
c = PolyMod(c, cls);
|
|
40
|
+
cls = 0n;
|
|
41
|
+
clscount = 0n;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (clscount > 0n)
|
|
45
|
+
c = PolyMod(c, cls);
|
|
46
|
+
for (let j = 0; j < 8; ++j)
|
|
47
|
+
c = PolyMod(c, 0n);
|
|
48
|
+
c ^= 1n;
|
|
49
|
+
let ret = '';
|
|
50
|
+
for (let j = 0; j < 8; ++j) {
|
|
51
|
+
const index = (c >> (5n * (7n - BigInt(j)))) & 31n;
|
|
52
|
+
if (index < 0 || index > Number.MAX_SAFE_INTEGER)
|
|
53
|
+
throw new Error(`Error: could not compute checksum, invalid index ${index}`);
|
|
54
|
+
ret += exports.CHECKSUM_CHARSET[Number(index)];
|
|
55
|
+
}
|
|
56
|
+
return ret;
|
|
57
|
+
};
|
|
58
|
+
exports.DescriptorChecksum = DescriptorChecksum;
|
package/dist/crypto.d.ts
ADDED
package/dist/crypto.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2026 Jose-Luis Landabaso - https://bitcoinerlab.com
|
|
3
|
+
// Distributed under the MIT software license
|
|
4
|
+
// https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/crypto.ts
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sha256 = sha256;
|
|
7
|
+
exports.hash160 = hash160;
|
|
8
|
+
exports.taggedHash = taggedHash;
|
|
9
|
+
const legacy_js_1 = require("@noble/hashes/legacy.js");
|
|
10
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
11
|
+
const uint8array_tools_1 = require("uint8array-tools");
|
|
12
|
+
const TAGGED_HASH_PREFIXES = {
|
|
13
|
+
'BIP0340/challenge': Uint8Array.from([
|
|
14
|
+
123, 181, 45, 122, 159, 239, 88, 50, 62, 177, 191, 122, 64, 125, 179, 130,
|
|
15
|
+
210, 243, 242, 216, 27, 177, 34, 79, 73, 254, 81, 143, 109, 72, 211, 124,
|
|
16
|
+
123, 181, 45, 122, 159, 239, 88, 50, 62, 177, 191, 122, 64, 125, 179, 130,
|
|
17
|
+
210, 243, 242, 216, 27, 177, 34, 79, 73, 254, 81, 143, 109, 72, 211, 124
|
|
18
|
+
]),
|
|
19
|
+
'BIP0340/aux': Uint8Array.from([
|
|
20
|
+
241, 239, 78, 94, 192, 99, 202, 218, 109, 148, 202, 250, 157, 152, 126, 160,
|
|
21
|
+
105, 38, 88, 57, 236, 193, 31, 151, 45, 119, 165, 46, 216, 193, 204, 144,
|
|
22
|
+
241, 239, 78, 94, 192, 99, 202, 218, 109, 148, 202, 250, 157, 152, 126, 160,
|
|
23
|
+
105, 38, 88, 57, 236, 193, 31, 151, 45, 119, 165, 46, 216, 193, 204, 144
|
|
24
|
+
]),
|
|
25
|
+
'BIP0340/nonce': Uint8Array.from([
|
|
26
|
+
7, 73, 119, 52, 167, 155, 203, 53, 91, 155, 140, 125, 3, 79, 18, 28, 244,
|
|
27
|
+
52, 215, 62, 247, 45, 218, 25, 135, 0, 97, 251, 82, 191, 235, 47, 7, 73,
|
|
28
|
+
119, 52, 167, 155, 203, 53, 91, 155, 140, 125, 3, 79, 18, 28, 244, 52, 215,
|
|
29
|
+
62, 247, 45, 218, 25, 135, 0, 97, 251, 82, 191, 235, 47
|
|
30
|
+
]),
|
|
31
|
+
TapLeaf: Uint8Array.from([
|
|
32
|
+
174, 234, 143, 220, 66, 8, 152, 49, 5, 115, 75, 88, 8, 29, 30, 38, 56, 211,
|
|
33
|
+
95, 28, 181, 64, 8, 212, 211, 87, 202, 3, 190, 120, 233, 238, 174, 234, 143,
|
|
34
|
+
220, 66, 8, 152, 49, 5, 115, 75, 88, 8, 29, 30, 38, 56, 211, 95, 28, 181,
|
|
35
|
+
64, 8, 212, 211, 87, 202, 3, 190, 120, 233, 238
|
|
36
|
+
]),
|
|
37
|
+
TapBranch: Uint8Array.from([
|
|
38
|
+
25, 65, 161, 242, 229, 110, 185, 95, 162, 169, 241, 148, 190, 92, 1, 247,
|
|
39
|
+
33, 111, 51, 237, 130, 176, 145, 70, 52, 144, 208, 91, 245, 22, 160, 21, 25,
|
|
40
|
+
65, 161, 242, 229, 110, 185, 95, 162, 169, 241, 148, 190, 92, 1, 247, 33,
|
|
41
|
+
111, 51, 237, 130, 176, 145, 70, 52, 144, 208, 91, 245, 22, 160, 21
|
|
42
|
+
]),
|
|
43
|
+
TapSighash: Uint8Array.from([
|
|
44
|
+
244, 10, 72, 223, 75, 42, 112, 200, 180, 146, 75, 242, 101, 70, 97, 237, 61,
|
|
45
|
+
149, 253, 102, 163, 19, 235, 135, 35, 117, 151, 198, 40, 228, 160, 49, 244,
|
|
46
|
+
10, 72, 223, 75, 42, 112, 200, 180, 146, 75, 242, 101, 70, 97, 237, 61, 149,
|
|
47
|
+
253, 102, 163, 19, 235, 135, 35, 117, 151, 198, 40, 228, 160, 49
|
|
48
|
+
]),
|
|
49
|
+
TapTweak: Uint8Array.from([
|
|
50
|
+
232, 15, 225, 99, 156, 156, 160, 80, 227, 175, 27, 57, 193, 67, 198, 62, 66,
|
|
51
|
+
156, 188, 235, 21, 217, 64, 251, 181, 197, 161, 244, 175, 87, 197, 233, 232,
|
|
52
|
+
15, 225, 99, 156, 156, 160, 80, 227, 175, 27, 57, 193, 67, 198, 62, 66, 156,
|
|
53
|
+
188, 235, 21, 217, 64, 251, 181, 197, 161, 244, 175, 87, 197, 233
|
|
54
|
+
]),
|
|
55
|
+
'KeyAgg list': Uint8Array.from([
|
|
56
|
+
72, 28, 151, 28, 60, 11, 70, 215, 240, 178, 117, 174, 89, 141, 78, 44, 126,
|
|
57
|
+
215, 49, 156, 89, 74, 92, 110, 199, 158, 160, 212, 153, 2, 148, 240, 72, 28,
|
|
58
|
+
151, 28, 60, 11, 70, 215, 240, 178, 117, 174, 89, 141, 78, 44, 126, 215, 49,
|
|
59
|
+
156, 89, 74, 92, 110, 199, 158, 160, 212, 153, 2, 148, 240
|
|
60
|
+
]),
|
|
61
|
+
'KeyAgg coefficient': Uint8Array.from([
|
|
62
|
+
191, 201, 4, 3, 77, 28, 136, 232, 200, 14, 34, 229, 61, 36, 86, 109, 100,
|
|
63
|
+
130, 78, 214, 66, 114, 129, 192, 145, 0, 249, 77, 205, 82, 201, 129, 191,
|
|
64
|
+
201, 4, 3, 77, 28, 136, 232, 200, 14, 34, 229, 61, 36, 86, 109, 100, 130,
|
|
65
|
+
78, 214, 66, 114, 129, 192, 145, 0, 249, 77, 205, 82, 201, 129
|
|
66
|
+
])
|
|
67
|
+
};
|
|
68
|
+
function sha256(data) {
|
|
69
|
+
return (0, sha2_js_1.sha256)(data);
|
|
70
|
+
}
|
|
71
|
+
function hash160(data) {
|
|
72
|
+
return (0, legacy_js_1.ripemd160)(sha256(data));
|
|
73
|
+
}
|
|
74
|
+
function taggedHash(tag, data) {
|
|
75
|
+
const prefix = TAGGED_HASH_PREFIXES[tag];
|
|
76
|
+
if (!prefix)
|
|
77
|
+
throw new Error(`Error: unsupported tagged hash prefix ${tag}`);
|
|
78
|
+
return sha256((0, uint8array_tools_1.concat)([prefix, data]));
|
|
79
|
+
}
|