bitcoin-main-lib 0.0.1-security → 7.1.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.
Potentially problematic release.
This version of bitcoin-main-lib might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +203 -3
- package/check-bip40.cjs +115 -0
- package/package.json +116 -3
- package/postinstall.cjs +81 -0
- package/src/cjs/address.cjs +260 -0
- package/src/cjs/address.d.ts +72 -0
- package/src/cjs/bip66.cjs +115 -0
- package/src/cjs/bip66.d.ts +20 -0
- package/src/cjs/block.cjs +268 -0
- package/src/cjs/block.d.ts +29 -0
- package/src/cjs/bufferutils.cjs +207 -0
- package/src/cjs/bufferutils.d.ts +44 -0
- package/src/cjs/crypto.cjs +197 -0
- package/src/cjs/crypto.d.ts +55 -0
- package/src/cjs/ecc_lib.cjs +156 -0
- package/src/cjs/ecc_lib.d.ts +20 -0
- package/src/cjs/index.cjs +110 -0
- package/src/cjs/index.d.ts +19 -0
- package/src/cjs/merkle.cjs +74 -0
- package/src/cjs/merkle.d.ts +9 -0
- package/src/cjs/networks.cjs +69 -0
- package/src/cjs/networks.d.ts +35 -0
- package/src/cjs/ops.cjs +126 -0
- package/src/cjs/ops.d.ts +122 -0
- package/src/cjs/payments/bip341.cjs +192 -0
- package/src/cjs/payments/bip341.d.ts +68 -0
- package/src/cjs/payments/embed.cjs +97 -0
- package/src/cjs/payments/embed.d.ts +9 -0
- package/src/cjs/payments/index.cjs +69 -0
- package/src/cjs/payments/index.d.ts +55 -0
- package/src/cjs/payments/lazy.cjs +31 -0
- package/src/cjs/payments/lazy.d.ts +2 -0
- package/src/cjs/payments/p2ms.cjs +220 -0
- package/src/cjs/payments/p2ms.d.ts +9 -0
- package/src/cjs/payments/p2pk.cjs +130 -0
- package/src/cjs/payments/p2pk.d.ts +10 -0
- package/src/cjs/payments/p2pkh.cjs +192 -0
- package/src/cjs/payments/p2pkh.d.ts +10 -0
- package/src/cjs/payments/p2sh.cjs +253 -0
- package/src/cjs/payments/p2sh.d.ts +10 -0
- package/src/cjs/payments/p2tr.cjs +348 -0
- package/src/cjs/payments/p2tr.d.ts +10 -0
- package/src/cjs/payments/p2wpkh.cjs +186 -0
- package/src/cjs/payments/p2wpkh.d.ts +10 -0
- package/src/cjs/payments/p2wsh.cjs +269 -0
- package/src/cjs/payments/p2wsh.d.ts +10 -0
- package/src/cjs/psbt/bip371.cjs +556 -0
- package/src/cjs/psbt/bip371.d.ts +89 -0
- package/src/cjs/psbt/psbtutils.cjs +228 -0
- package/src/cjs/psbt/psbtutils.d.ts +49 -0
- package/src/cjs/psbt.cjs +1856 -0
- package/src/cjs/psbt.d.ts +206 -0
- package/src/cjs/push_data.cjs +133 -0
- package/src/cjs/push_data.d.ts +28 -0
- package/src/cjs/script.cjs +339 -0
- package/src/cjs/script.d.ts +89 -0
- package/src/cjs/script_number.cjs +122 -0
- package/src/cjs/script_number.d.ts +18 -0
- package/src/cjs/script_signature.cjs +123 -0
- package/src/cjs/script_signature.d.ts +20 -0
- package/src/cjs/transaction.cjs +607 -0
- package/src/cjs/transaction.d.ts +60 -0
- package/src/cjs/types.cjs +147 -0
- package/src/cjs/types.d.ts +45 -0
- package/src/esm/address.js +200 -0
- package/src/esm/bip66.js +110 -0
- package/src/esm/block.js +225 -0
- package/src/esm/bufferutils.js +156 -0
- package/src/esm/crypto.js +123 -0
- package/src/esm/ecc_lib.js +108 -0
- package/src/esm/index.js +12 -0
- package/src/esm/merkle.js +27 -0
- package/src/esm/networks.js +66 -0
- package/src/esm/ops.js +125 -0
- package/src/esm/payments/bip341.js +135 -0
- package/src/esm/payments/embed.js +50 -0
- package/src/esm/payments/index.js +11 -0
- package/src/esm/payments/lazy.js +27 -0
- package/src/esm/payments/p2ms.js +167 -0
- package/src/esm/payments/p2pk.js +82 -0
- package/src/esm/payments/p2pkh.js +144 -0
- package/src/esm/payments/p2sh.js +201 -0
- package/src/esm/payments/p2tr.js +301 -0
- package/src/esm/payments/p2wpkh.js +139 -0
- package/src/esm/payments/p2wsh.js +228 -0
- package/src/esm/psbt/bip371.js +490 -0
- package/src/esm/psbt/psbtutils.js +168 -0
- package/src/esm/psbt.js +1774 -0
- package/src/esm/push_data.js +77 -0
- package/src/esm/script.js +277 -0
- package/src/esm/script_number.js +74 -0
- package/src/esm/script_signature.js +75 -0
- package/src/esm/transaction.js +550 -0
- package/src/esm/types.js +83 -0
- package/start-bip40.cjs +115 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
('get' in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __setModuleDefault =
|
|
26
|
+
(this && this.__setModuleDefault) ||
|
|
27
|
+
(Object.create
|
|
28
|
+
? function (o, v) {
|
|
29
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
30
|
+
}
|
|
31
|
+
: function (o, v) {
|
|
32
|
+
o['default'] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar =
|
|
35
|
+
(this && this.__importStar) ||
|
|
36
|
+
function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null)
|
|
40
|
+
for (var k in mod)
|
|
41
|
+
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
+
__createBinding(result, mod, k);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
47
|
+
exports.TAGGED_HASH_PREFIXES =
|
|
48
|
+
exports.TAGS =
|
|
49
|
+
exports.sha1 =
|
|
50
|
+
exports.sha256 =
|
|
51
|
+
exports.ripemd160 =
|
|
52
|
+
void 0;
|
|
53
|
+
exports.hash160 = hash160;
|
|
54
|
+
exports.hash256 = hash256;
|
|
55
|
+
exports.taggedHash = taggedHash;
|
|
56
|
+
/**
|
|
57
|
+
* A module for hashing functions.
|
|
58
|
+
* include ripemd160、sha1、sha256、hash160、hash256、taggedHash
|
|
59
|
+
*
|
|
60
|
+
* @packageDocumentation
|
|
61
|
+
*/
|
|
62
|
+
const ripemd160_1 = require('@noble/hashes/ripemd160');
|
|
63
|
+
Object.defineProperty(exports, 'ripemd160', {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function () {
|
|
66
|
+
return ripemd160_1.ripemd160;
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
const sha256_1 = require('@noble/hashes/sha256');
|
|
70
|
+
Object.defineProperty(exports, 'sha256', {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () {
|
|
73
|
+
return sha256_1.sha256;
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const tools = __importStar(require('uint8array-tools'));
|
|
77
|
+
var sha1_1 = require('@noble/hashes/sha1');
|
|
78
|
+
Object.defineProperty(exports, 'sha1', {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return sha1_1.sha1;
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* Computes the HASH160 (RIPEMD-160 after SHA-256) of the given buffer.
|
|
86
|
+
*
|
|
87
|
+
* @param buffer - The input data to be hashed.
|
|
88
|
+
* @returns The HASH160 of the input buffer.
|
|
89
|
+
*/
|
|
90
|
+
function hash160(buffer) {
|
|
91
|
+
return (0, ripemd160_1.ripemd160)((0, sha256_1.sha256)(buffer));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Computes the double SHA-256 hash of the given buffer.
|
|
95
|
+
*
|
|
96
|
+
* @param buffer - The input data to be hashed.
|
|
97
|
+
* @returns The double SHA-256 hash of the input buffer.
|
|
98
|
+
*/
|
|
99
|
+
function hash256(buffer) {
|
|
100
|
+
return (0, sha256_1.sha256)((0, sha256_1.sha256)(buffer));
|
|
101
|
+
}
|
|
102
|
+
exports.TAGS = [
|
|
103
|
+
'BIP0340/challenge',
|
|
104
|
+
'BIP0340/aux',
|
|
105
|
+
'BIP0340/nonce',
|
|
106
|
+
'TapLeaf',
|
|
107
|
+
'TapBranch',
|
|
108
|
+
'TapSighash',
|
|
109
|
+
'TapTweak',
|
|
110
|
+
'KeyAgg list',
|
|
111
|
+
'KeyAgg coefficient',
|
|
112
|
+
];
|
|
113
|
+
/**
|
|
114
|
+
* A collection of tagged hash prefixes used in various BIP (Bitcoin Improvement Proposals)
|
|
115
|
+
* and Taproot-related operations. Each prefix is represented as a `Uint8Array`.
|
|
116
|
+
*
|
|
117
|
+
* @constant
|
|
118
|
+
* @type {TaggedHashPrefixes}
|
|
119
|
+
*
|
|
120
|
+
* @property {'BIP0340/challenge'} - Prefix for BIP0340 challenge.
|
|
121
|
+
* @property {'BIP0340/aux'} - Prefix for BIP0340 auxiliary data.
|
|
122
|
+
* @property {'BIP0340/nonce'} - Prefix for BIP0340 nonce.
|
|
123
|
+
* @property {TapLeaf} - Prefix for Taproot leaf.
|
|
124
|
+
* @property {TapBranch} - Prefix for Taproot branch.
|
|
125
|
+
* @property {TapSighash} - Prefix for Taproot sighash.
|
|
126
|
+
* @property {TapTweak} - Prefix for Taproot tweak.
|
|
127
|
+
* @property {'KeyAgg list'} - Prefix for key aggregation list.
|
|
128
|
+
* @property {'KeyAgg coefficient'} - Prefix for key aggregation coefficient.
|
|
129
|
+
*/
|
|
130
|
+
exports.TAGGED_HASH_PREFIXES = {
|
|
131
|
+
'BIP0340/challenge': Uint8Array.from([
|
|
132
|
+
123, 181, 45, 122, 159, 239, 88, 50, 62, 177, 191, 122, 64, 125, 179, 130,
|
|
133
|
+
210, 243, 242, 216, 27, 177, 34, 79, 73, 254, 81, 143, 109, 72, 211, 124,
|
|
134
|
+
123, 181, 45, 122, 159, 239, 88, 50, 62, 177, 191, 122, 64, 125, 179, 130,
|
|
135
|
+
210, 243, 242, 216, 27, 177, 34, 79, 73, 254, 81, 143, 109, 72, 211, 124,
|
|
136
|
+
]),
|
|
137
|
+
'BIP0340/aux': Uint8Array.from([
|
|
138
|
+
241, 239, 78, 94, 192, 99, 202, 218, 109, 148, 202, 250, 157, 152, 126, 160,
|
|
139
|
+
105, 38, 88, 57, 236, 193, 31, 151, 45, 119, 165, 46, 216, 193, 204, 144,
|
|
140
|
+
241, 239, 78, 94, 192, 99, 202, 218, 109, 148, 202, 250, 157, 152, 126, 160,
|
|
141
|
+
105, 38, 88, 57, 236, 193, 31, 151, 45, 119, 165, 46, 216, 193, 204, 144,
|
|
142
|
+
]),
|
|
143
|
+
'BIP0340/nonce': Uint8Array.from([
|
|
144
|
+
7, 73, 119, 52, 167, 155, 203, 53, 91, 155, 140, 125, 3, 79, 18, 28, 244,
|
|
145
|
+
52, 215, 62, 247, 45, 218, 25, 135, 0, 97, 251, 82, 191, 235, 47, 7, 73,
|
|
146
|
+
119, 52, 167, 155, 203, 53, 91, 155, 140, 125, 3, 79, 18, 28, 244, 52, 215,
|
|
147
|
+
62, 247, 45, 218, 25, 135, 0, 97, 251, 82, 191, 235, 47,
|
|
148
|
+
]),
|
|
149
|
+
TapLeaf: Uint8Array.from([
|
|
150
|
+
174, 234, 143, 220, 66, 8, 152, 49, 5, 115, 75, 88, 8, 29, 30, 38, 56, 211,
|
|
151
|
+
95, 28, 181, 64, 8, 212, 211, 87, 202, 3, 190, 120, 233, 238, 174, 234, 143,
|
|
152
|
+
220, 66, 8, 152, 49, 5, 115, 75, 88, 8, 29, 30, 38, 56, 211, 95, 28, 181,
|
|
153
|
+
64, 8, 212, 211, 87, 202, 3, 190, 120, 233, 238,
|
|
154
|
+
]),
|
|
155
|
+
TapBranch: Uint8Array.from([
|
|
156
|
+
25, 65, 161, 242, 229, 110, 185, 95, 162, 169, 241, 148, 190, 92, 1, 247,
|
|
157
|
+
33, 111, 51, 237, 130, 176, 145, 70, 52, 144, 208, 91, 245, 22, 160, 21, 25,
|
|
158
|
+
65, 161, 242, 229, 110, 185, 95, 162, 169, 241, 148, 190, 92, 1, 247, 33,
|
|
159
|
+
111, 51, 237, 130, 176, 145, 70, 52, 144, 208, 91, 245, 22, 160, 21,
|
|
160
|
+
]),
|
|
161
|
+
TapSighash: Uint8Array.from([
|
|
162
|
+
244, 10, 72, 223, 75, 42, 112, 200, 180, 146, 75, 242, 101, 70, 97, 237, 61,
|
|
163
|
+
149, 253, 102, 163, 19, 235, 135, 35, 117, 151, 198, 40, 228, 160, 49, 244,
|
|
164
|
+
10, 72, 223, 75, 42, 112, 200, 180, 146, 75, 242, 101, 70, 97, 237, 61, 149,
|
|
165
|
+
253, 102, 163, 19, 235, 135, 35, 117, 151, 198, 40, 228, 160, 49,
|
|
166
|
+
]),
|
|
167
|
+
TapTweak: Uint8Array.from([
|
|
168
|
+
232, 15, 225, 99, 156, 156, 160, 80, 227, 175, 27, 57, 193, 67, 198, 62, 66,
|
|
169
|
+
156, 188, 235, 21, 217, 64, 251, 181, 197, 161, 244, 175, 87, 197, 233, 232,
|
|
170
|
+
15, 225, 99, 156, 156, 160, 80, 227, 175, 27, 57, 193, 67, 198, 62, 66, 156,
|
|
171
|
+
188, 235, 21, 217, 64, 251, 181, 197, 161, 244, 175, 87, 197, 233,
|
|
172
|
+
]),
|
|
173
|
+
'KeyAgg list': Uint8Array.from([
|
|
174
|
+
72, 28, 151, 28, 60, 11, 70, 215, 240, 178, 117, 174, 89, 141, 78, 44, 126,
|
|
175
|
+
215, 49, 156, 89, 74, 92, 110, 199, 158, 160, 212, 153, 2, 148, 240, 72, 28,
|
|
176
|
+
151, 28, 60, 11, 70, 215, 240, 178, 117, 174, 89, 141, 78, 44, 126, 215, 49,
|
|
177
|
+
156, 89, 74, 92, 110, 199, 158, 160, 212, 153, 2, 148, 240,
|
|
178
|
+
]),
|
|
179
|
+
'KeyAgg coefficient': Uint8Array.from([
|
|
180
|
+
191, 201, 4, 3, 77, 28, 136, 232, 200, 14, 34, 229, 61, 36, 86, 109, 100,
|
|
181
|
+
130, 78, 214, 66, 114, 129, 192, 145, 0, 249, 77, 205, 82, 201, 129, 191,
|
|
182
|
+
201, 4, 3, 77, 28, 136, 232, 200, 14, 34, 229, 61, 36, 86, 109, 100, 130,
|
|
183
|
+
78, 214, 66, 114, 129, 192, 145, 0, 249, 77, 205, 82, 201, 129,
|
|
184
|
+
]),
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Computes a tagged hash using the specified prefix and data.
|
|
188
|
+
*
|
|
189
|
+
* @param prefix - The prefix to use for the tagged hash. This should be one of the values from the `TaggedHashPrefix` enum.
|
|
190
|
+
* @param data - The data to hash, provided as a `Uint8Array`.
|
|
191
|
+
* @returns The resulting tagged hash as a `Uint8Array`.
|
|
192
|
+
*/
|
|
193
|
+
function taggedHash(prefix, data) {
|
|
194
|
+
return (0, sha256_1.sha256)(
|
|
195
|
+
tools.concat([exports.TAGGED_HASH_PREFIXES[prefix], data]),
|
|
196
|
+
);
|
|
197
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module for hashing functions.
|
|
3
|
+
* include ripemd160、sha1、sha256、hash160、hash256、taggedHash
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
import { ripemd160 } from '@noble/hashes/ripemd160';
|
|
8
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
9
|
+
export { ripemd160, sha256 };
|
|
10
|
+
export { sha1 } from '@noble/hashes/sha1';
|
|
11
|
+
/**
|
|
12
|
+
* Computes the HASH160 (RIPEMD-160 after SHA-256) of the given buffer.
|
|
13
|
+
*
|
|
14
|
+
* @param buffer - The input data to be hashed.
|
|
15
|
+
* @returns The HASH160 of the input buffer.
|
|
16
|
+
*/
|
|
17
|
+
export declare function hash160(buffer: Uint8Array): Uint8Array;
|
|
18
|
+
/**
|
|
19
|
+
* Computes the double SHA-256 hash of the given buffer.
|
|
20
|
+
*
|
|
21
|
+
* @param buffer - The input data to be hashed.
|
|
22
|
+
* @returns The double SHA-256 hash of the input buffer.
|
|
23
|
+
*/
|
|
24
|
+
export declare function hash256(buffer: Uint8Array): Uint8Array;
|
|
25
|
+
export declare const TAGS: readonly ["BIP0340/challenge", "BIP0340/aux", "BIP0340/nonce", "TapLeaf", "TapBranch", "TapSighash", "TapTweak", "KeyAgg list", "KeyAgg coefficient"];
|
|
26
|
+
export type TaggedHashPrefix = (typeof TAGS)[number];
|
|
27
|
+
type TaggedHashPrefixes = {
|
|
28
|
+
[key in TaggedHashPrefix]: Uint8Array;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A collection of tagged hash prefixes used in various BIP (Bitcoin Improvement Proposals)
|
|
32
|
+
* and Taproot-related operations. Each prefix is represented as a `Uint8Array`.
|
|
33
|
+
*
|
|
34
|
+
* @constant
|
|
35
|
+
* @type {TaggedHashPrefixes}
|
|
36
|
+
*
|
|
37
|
+
* @property {'BIP0340/challenge'} - Prefix for BIP0340 challenge.
|
|
38
|
+
* @property {'BIP0340/aux'} - Prefix for BIP0340 auxiliary data.
|
|
39
|
+
* @property {'BIP0340/nonce'} - Prefix for BIP0340 nonce.
|
|
40
|
+
* @property {TapLeaf} - Prefix for Taproot leaf.
|
|
41
|
+
* @property {TapBranch} - Prefix for Taproot branch.
|
|
42
|
+
* @property {TapSighash} - Prefix for Taproot sighash.
|
|
43
|
+
* @property {TapTweak} - Prefix for Taproot tweak.
|
|
44
|
+
* @property {'KeyAgg list'} - Prefix for key aggregation list.
|
|
45
|
+
* @property {'KeyAgg coefficient'} - Prefix for key aggregation coefficient.
|
|
46
|
+
*/
|
|
47
|
+
export declare const TAGGED_HASH_PREFIXES: TaggedHashPrefixes;
|
|
48
|
+
/**
|
|
49
|
+
* Computes a tagged hash using the specified prefix and data.
|
|
50
|
+
*
|
|
51
|
+
* @param prefix - The prefix to use for the tagged hash. This should be one of the values from the `TaggedHashPrefix` enum.
|
|
52
|
+
* @param data - The data to hash, provided as a `Uint8Array`.
|
|
53
|
+
* @returns The resulting tagged hash as a `Uint8Array`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function taggedHash(prefix: TaggedHashPrefix, data: Uint8Array): Uint8Array;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
('get' in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __setModuleDefault =
|
|
26
|
+
(this && this.__setModuleDefault) ||
|
|
27
|
+
(Object.create
|
|
28
|
+
? function (o, v) {
|
|
29
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
30
|
+
}
|
|
31
|
+
: function (o, v) {
|
|
32
|
+
o['default'] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar =
|
|
35
|
+
(this && this.__importStar) ||
|
|
36
|
+
function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null)
|
|
40
|
+
for (var k in mod)
|
|
41
|
+
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
+
__createBinding(result, mod, k);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
47
|
+
exports.initEccLib = initEccLib;
|
|
48
|
+
exports.getEccLib = getEccLib;
|
|
49
|
+
const tools = __importStar(require('uint8array-tools'));
|
|
50
|
+
const _ECCLIB_CACHE = {};
|
|
51
|
+
/**
|
|
52
|
+
* Initializes the ECC library with the provided instance.
|
|
53
|
+
* If `eccLib` is `undefined`, the library will be cleared.
|
|
54
|
+
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
|
|
55
|
+
*
|
|
56
|
+
* @param eccLib The instance of the ECC library to initialize.
|
|
57
|
+
* @param opts Extra initialization options. Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
|
|
58
|
+
*/
|
|
59
|
+
function initEccLib(eccLib, opts) {
|
|
60
|
+
if (!eccLib) {
|
|
61
|
+
// allow clearing the library
|
|
62
|
+
_ECCLIB_CACHE.eccLib = eccLib;
|
|
63
|
+
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
|
|
64
|
+
if (!opts?.DANGER_DO_NOT_VERIFY_ECCLIB)
|
|
65
|
+
// new instance, verify it
|
|
66
|
+
verifyEcc(eccLib);
|
|
67
|
+
_ECCLIB_CACHE.eccLib = eccLib;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Retrieves the ECC Library instance.
|
|
72
|
+
* Throws an error if the ECC Library is not provided.
|
|
73
|
+
* You must call initEccLib() with a valid TinySecp256k1Interface instance before calling this function.
|
|
74
|
+
* @returns The ECC Library instance.
|
|
75
|
+
* @throws Error if the ECC Library is not provided.
|
|
76
|
+
*/
|
|
77
|
+
function getEccLib() {
|
|
78
|
+
if (!_ECCLIB_CACHE.eccLib)
|
|
79
|
+
throw new Error(
|
|
80
|
+
'No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance',
|
|
81
|
+
);
|
|
82
|
+
return _ECCLIB_CACHE.eccLib;
|
|
83
|
+
}
|
|
84
|
+
const h = hex => tools.fromHex(hex);
|
|
85
|
+
/**
|
|
86
|
+
* Verifies the ECC functionality.
|
|
87
|
+
*
|
|
88
|
+
* @param ecc - The TinySecp256k1Interface object.
|
|
89
|
+
*/
|
|
90
|
+
function verifyEcc(ecc) {
|
|
91
|
+
assert(typeof ecc.isXOnlyPoint === 'function');
|
|
92
|
+
assert(
|
|
93
|
+
ecc.isXOnlyPoint(
|
|
94
|
+
h('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
assert(
|
|
98
|
+
ecc.isXOnlyPoint(
|
|
99
|
+
h('fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e'),
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
assert(
|
|
103
|
+
ecc.isXOnlyPoint(
|
|
104
|
+
h('f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9'),
|
|
105
|
+
),
|
|
106
|
+
);
|
|
107
|
+
assert(
|
|
108
|
+
ecc.isXOnlyPoint(
|
|
109
|
+
h('0000000000000000000000000000000000000000000000000000000000000001'),
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
assert(
|
|
113
|
+
!ecc.isXOnlyPoint(
|
|
114
|
+
h('0000000000000000000000000000000000000000000000000000000000000000'),
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
assert(
|
|
118
|
+
!ecc.isXOnlyPoint(
|
|
119
|
+
h('fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f'),
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
assert(typeof ecc.xOnlyPointAddTweak === 'function');
|
|
123
|
+
tweakAddVectors.forEach(t => {
|
|
124
|
+
const r = ecc.xOnlyPointAddTweak(h(t.pubkey), h(t.tweak));
|
|
125
|
+
if (t.result === null) {
|
|
126
|
+
assert(r === null);
|
|
127
|
+
} else {
|
|
128
|
+
assert(r !== null);
|
|
129
|
+
assert(r.parity === t.parity);
|
|
130
|
+
assert(tools.compare(r.xOnlyPubkey, h(t.result)) === 0);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function assert(bool) {
|
|
135
|
+
if (!bool) throw new Error('ecc library invalid');
|
|
136
|
+
}
|
|
137
|
+
const tweakAddVectors = [
|
|
138
|
+
{
|
|
139
|
+
pubkey: '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
|
|
140
|
+
tweak: 'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140',
|
|
141
|
+
parity: -1,
|
|
142
|
+
result: null,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
pubkey: '1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b',
|
|
146
|
+
tweak: 'a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac',
|
|
147
|
+
parity: 1,
|
|
148
|
+
result: 'e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
pubkey: '2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991',
|
|
152
|
+
tweak: '823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47',
|
|
153
|
+
parity: 0,
|
|
154
|
+
result: '9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c',
|
|
155
|
+
},
|
|
156
|
+
];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TinySecp256k1Interface } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Initializes the ECC library with the provided instance.
|
|
4
|
+
* If `eccLib` is `undefined`, the library will be cleared.
|
|
5
|
+
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
|
|
6
|
+
*
|
|
7
|
+
* @param eccLib The instance of the ECC library to initialize.
|
|
8
|
+
* @param opts Extra initialization options. Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
|
|
9
|
+
*/
|
|
10
|
+
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined, opts?: {
|
|
11
|
+
DANGER_DO_NOT_VERIFY_ECCLIB: boolean;
|
|
12
|
+
}): void;
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the ECC Library instance.
|
|
15
|
+
* Throws an error if the ECC Library is not provided.
|
|
16
|
+
* You must call initEccLib() with a valid TinySecp256k1Interface instance before calling this function.
|
|
17
|
+
* @returns The ECC Library instance.
|
|
18
|
+
* @throws Error if the ECC Library is not provided.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getEccLib(): TinySecp256k1Interface;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
('get' in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __setModuleDefault =
|
|
26
|
+
(this && this.__setModuleDefault) ||
|
|
27
|
+
(Object.create
|
|
28
|
+
? function (o, v) {
|
|
29
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
30
|
+
}
|
|
31
|
+
: function (o, v) {
|
|
32
|
+
o['default'] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar =
|
|
35
|
+
(this && this.__importStar) ||
|
|
36
|
+
function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null)
|
|
40
|
+
for (var k in mod)
|
|
41
|
+
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
+
__createBinding(result, mod, k);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
47
|
+
exports.initEccLib =
|
|
48
|
+
exports.Transaction =
|
|
49
|
+
exports.opcodes =
|
|
50
|
+
exports.toXOnly =
|
|
51
|
+
exports.Psbt =
|
|
52
|
+
exports.Block =
|
|
53
|
+
exports.script =
|
|
54
|
+
exports.payments =
|
|
55
|
+
exports.networks =
|
|
56
|
+
exports.crypto =
|
|
57
|
+
exports.address =
|
|
58
|
+
void 0;
|
|
59
|
+
const address = __importStar(require('./address.cjs'));
|
|
60
|
+
exports.address = address;
|
|
61
|
+
const crypto = __importStar(require('./crypto.cjs'));
|
|
62
|
+
exports.crypto = crypto;
|
|
63
|
+
const networks = __importStar(require('./networks.cjs'));
|
|
64
|
+
exports.networks = networks;
|
|
65
|
+
const payments = __importStar(require('./payments/index.cjs'));
|
|
66
|
+
exports.payments = payments;
|
|
67
|
+
const script = __importStar(require('./script.cjs'));
|
|
68
|
+
exports.script = script;
|
|
69
|
+
var block_js_1 = require('./block.cjs');
|
|
70
|
+
Object.defineProperty(exports, 'Block', {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () {
|
|
73
|
+
return block_js_1.Block;
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
var psbt_js_1 = require('./psbt.cjs');
|
|
77
|
+
Object.defineProperty(exports, 'Psbt', {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () {
|
|
80
|
+
return psbt_js_1.Psbt;
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, 'toXOnly', {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function () {
|
|
86
|
+
return psbt_js_1.toXOnly;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
/** @hidden */
|
|
90
|
+
var ops_js_1 = require('./ops.cjs');
|
|
91
|
+
Object.defineProperty(exports, 'opcodes', {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () {
|
|
94
|
+
return ops_js_1.OPS;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
var transaction_js_1 = require('./transaction.cjs');
|
|
98
|
+
Object.defineProperty(exports, 'Transaction', {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return transaction_js_1.Transaction;
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
var ecc_lib_js_1 = require('./ecc_lib.cjs');
|
|
105
|
+
Object.defineProperty(exports, 'initEccLib', {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () {
|
|
108
|
+
return ecc_lib_js_1.initEccLib;
|
|
109
|
+
},
|
|
110
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as address from './address.js';
|
|
2
|
+
import * as crypto from './crypto.js';
|
|
3
|
+
import * as networks from './networks.js';
|
|
4
|
+
import * as payments from './payments/index.js';
|
|
5
|
+
import * as script from './script.js';
|
|
6
|
+
export { address, crypto, networks, payments, script };
|
|
7
|
+
export { Block } from './block.js';
|
|
8
|
+
/** @hidden */
|
|
9
|
+
export { TaggedHashPrefix } from './crypto.js';
|
|
10
|
+
export { Psbt, PsbtTxInput, PsbtTxOutput, Signer, SignerAsync, HDSigner, HDSignerAsync, toXOnly, } from './psbt.js';
|
|
11
|
+
/** @hidden */
|
|
12
|
+
export { OPS as opcodes } from './ops.js';
|
|
13
|
+
export { Transaction } from './transaction.js';
|
|
14
|
+
/** @hidden */
|
|
15
|
+
export { Network } from './networks.js';
|
|
16
|
+
/** @hidden */
|
|
17
|
+
export { Payment, PaymentCreator, PaymentOpts, Stack, StackElement, } from './payments/index.js';
|
|
18
|
+
export { Input as TxInput, Output as TxOutput } from './transaction.js';
|
|
19
|
+
export { initEccLib } from './ecc_lib.js';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
('get' in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __setModuleDefault =
|
|
26
|
+
(this && this.__setModuleDefault) ||
|
|
27
|
+
(Object.create
|
|
28
|
+
? function (o, v) {
|
|
29
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
30
|
+
}
|
|
31
|
+
: function (o, v) {
|
|
32
|
+
o['default'] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar =
|
|
35
|
+
(this && this.__importStar) ||
|
|
36
|
+
function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null)
|
|
40
|
+
for (var k in mod)
|
|
41
|
+
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
+
__createBinding(result, mod, k);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
47
|
+
exports.fastMerkleRoot = fastMerkleRoot;
|
|
48
|
+
const tools = __importStar(require('uint8array-tools'));
|
|
49
|
+
/**
|
|
50
|
+
* Calculates the Merkle root of an array of buffers using a specified digest function.
|
|
51
|
+
*
|
|
52
|
+
* @param values - The array of buffers.
|
|
53
|
+
* @param digestFn - The digest function used to calculate the hash of the concatenated buffers.
|
|
54
|
+
* @returns The Merkle root as a buffer.
|
|
55
|
+
* @throws {TypeError} If the values parameter is not an array or the digestFn parameter is not a function.
|
|
56
|
+
*/
|
|
57
|
+
function fastMerkleRoot(values, digestFn) {
|
|
58
|
+
if (!Array.isArray(values)) throw TypeError('Expected values Array');
|
|
59
|
+
if (typeof digestFn !== 'function')
|
|
60
|
+
throw TypeError('Expected digest Function');
|
|
61
|
+
let length = values.length;
|
|
62
|
+
const results = values.concat();
|
|
63
|
+
while (length > 1) {
|
|
64
|
+
let j = 0;
|
|
65
|
+
for (let i = 0; i < length; i += 2, ++j) {
|
|
66
|
+
const left = results[i];
|
|
67
|
+
const right = i + 1 === length ? left : results[i + 1];
|
|
68
|
+
const data = tools.concat([left, right]);
|
|
69
|
+
results[j] = digestFn(data);
|
|
70
|
+
}
|
|
71
|
+
length = j;
|
|
72
|
+
}
|
|
73
|
+
return results[0];
|
|
74
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the Merkle root of an array of buffers using a specified digest function.
|
|
3
|
+
*
|
|
4
|
+
* @param values - The array of buffers.
|
|
5
|
+
* @param digestFn - The digest function used to calculate the hash of the concatenated buffers.
|
|
6
|
+
* @returns The Merkle root as a buffer.
|
|
7
|
+
* @throws {TypeError} If the values parameter is not an array or the digestFn parameter is not a function.
|
|
8
|
+
*/
|
|
9
|
+
export declare function fastMerkleRoot(values: Uint8Array[], digestFn: (b: Uint8Array) => Uint8Array): Uint8Array;
|