@bsv/sdk 1.0.22 → 1.0.24
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/dist/cjs/package.json +1 -1
- package/dist/cjs/src/script/Script.js +7 -1
- package/dist/cjs/src/script/Script.js.map +1 -1
- package/dist/cjs/src/transaction/MerklePath.js +3 -3
- package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
- package/dist/cjs/src/transaction/Transaction.js +36 -0
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/script/Script.js +7 -1
- package/dist/esm/src/script/Script.js.map +1 -1
- package/dist/esm/src/transaction/MerklePath.js +3 -3
- package/dist/esm/src/transaction/MerklePath.js.map +1 -1
- package/dist/esm/src/transaction/Transaction.js +36 -0
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/script/Script.d.ts.map +1 -1
- package/dist/types/src/transaction/MerklePath.d.ts.map +1 -1
- package/dist/types/src/transaction/Transaction.d.ts +27 -0
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/script/Script.ts +23 -20
- package/src/transaction/MerklePath.ts +12 -12
- package/src/transaction/Transaction.ts +43 -0
- package/src/transaction/__tests/Transaction.test.ts +20 -0
- package/dist/cjs/src/compat/BIP39.js +0 -272
- package/dist/cjs/src/compat/BIP39.js.map +0 -1
- package/dist/cjs/src/index.js +0 -5
- package/dist/cjs/src/index.js.map +0 -1
- package/dist/cjs/src/script/templates/P2PKHT.js +0 -99
- package/dist/cjs/src/script/templates/P2PKHT.js.map +0 -1
- package/dist/cjs/src/transaction/broadcasters/BRC22.js +0 -25
- package/dist/cjs/src/transaction/broadcasters/BRC22.js.map +0 -1
- package/dist/esm/src/compat/BIP39.js +0 -272
- package/dist/esm/src/compat/BIP39.js.map +0 -1
- package/dist/esm/src/script/templates/P2PKHT.js +0 -96
- package/dist/esm/src/script/templates/P2PKHT.js.map +0 -1
- package/dist/types/src/compat/BIP39.d.ts +0 -132
- package/dist/types/src/compat/BIP39.d.ts.map +0 -1
- package/dist/types/src/script/templates/P2PKHT.d.ts +0 -37
- package/dist/types/src/script/templates/P2PKHT.d.ts.map +0 -1
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { wordList } from './bip-39-wordlist-en.js';
|
|
2
|
-
import { encode, toArray, Reader, Writer } from '../primitives/utils.js';
|
|
3
|
-
import * as Hash from '../primitives/Hash.js';
|
|
4
|
-
import Random from '../primitives/Random.js';
|
|
5
|
-
/**
|
|
6
|
-
* @class BIP39
|
|
7
|
-
*
|
|
8
|
-
* @description
|
|
9
|
-
* Class representing BIP39 functionality.
|
|
10
|
-
* This class provides methods for generating, converting, and validating mnemonic phrases
|
|
11
|
-
* according to the BIP39 standard. It supports creating mnemonics from random entropy,
|
|
12
|
-
* converting mnemonics to seeds, and validating mnemonic phrases.
|
|
13
|
-
*/
|
|
14
|
-
export default class BIP39 {
|
|
15
|
-
mnemonic;
|
|
16
|
-
seed;
|
|
17
|
-
Wordlist;
|
|
18
|
-
/**
|
|
19
|
-
* Constructs a BIP39 object.
|
|
20
|
-
* @param {string} [mnemonic] - An optional mnemonic phrase.
|
|
21
|
-
* @param {number[]} [seed] - An optional seed derived from the mnemonic.
|
|
22
|
-
* @param {object} [wordlist=wordList] - An object containing a list of words and space character used in the mnemonic.
|
|
23
|
-
*/
|
|
24
|
-
constructor(mnemonic, seed, wordlist = wordList) {
|
|
25
|
-
this.mnemonic = mnemonic;
|
|
26
|
-
this.seed = seed;
|
|
27
|
-
this.Wordlist = wordlist;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Converts the mnemonic and seed into a binary representation.
|
|
31
|
-
* @returns {number[]} The binary representation of the mnemonic and seed.
|
|
32
|
-
*/
|
|
33
|
-
toBinary() {
|
|
34
|
-
const bw = new Writer();
|
|
35
|
-
if (this.mnemonic) {
|
|
36
|
-
const buf = toArray(this.mnemonic, 'utf8');
|
|
37
|
-
bw.writeVarIntNum(buf.length);
|
|
38
|
-
bw.write(buf);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
bw.writeVarIntNum(0);
|
|
42
|
-
}
|
|
43
|
-
if (this.seed) {
|
|
44
|
-
bw.writeVarIntNum(this.seed.length);
|
|
45
|
-
bw.write(this.seed);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
bw.writeVarIntNum(0);
|
|
49
|
-
}
|
|
50
|
-
return bw.toArray();
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Loads a mnemonic and seed from a binary representation.
|
|
54
|
-
* @param {number[]} bin - The binary representation of a mnemonic and seed.
|
|
55
|
-
* @returns {this} The BIP39 instance with loaded mnemonic and seed.
|
|
56
|
-
*/
|
|
57
|
-
fromBinary(bin) {
|
|
58
|
-
const br = new Reader(bin);
|
|
59
|
-
const mnemoniclen = br.readVarIntNum();
|
|
60
|
-
if (mnemoniclen > 0) {
|
|
61
|
-
this.mnemonic = encode(br.read(mnemoniclen), 'utf8');
|
|
62
|
-
}
|
|
63
|
-
const seedlen = br.readVarIntNum();
|
|
64
|
-
if (seedlen > 0) {
|
|
65
|
-
this.seed = br.read(seedlen);
|
|
66
|
-
}
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Generates a random mnemonic from a given bit length.
|
|
71
|
-
* @param {number} [bits=128] - The bit length for the random mnemonic (must be a multiple of 32 and at least 128).
|
|
72
|
-
* @returns {this} The BIP39 instance with the new random mnemonic.
|
|
73
|
-
* @throws {Error} If the bit length is not a multiple of 32 or is less than 128.
|
|
74
|
-
*/
|
|
75
|
-
fromRandom(bits) {
|
|
76
|
-
if (!bits) {
|
|
77
|
-
bits = 128;
|
|
78
|
-
}
|
|
79
|
-
if (bits % 32 !== 0) {
|
|
80
|
-
throw new Error('bits must be multiple of 32');
|
|
81
|
-
}
|
|
82
|
-
if (bits < 128) {
|
|
83
|
-
throw new Error('bits must be at least 128');
|
|
84
|
-
}
|
|
85
|
-
const buf = Random(bits / 8);
|
|
86
|
-
this.entropy2Mnemonic(buf);
|
|
87
|
-
this.mnemonic2Seed();
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Static method to generate a BIP39 instance with a random mnemonic.
|
|
92
|
-
* @param {number} [bits=128] - The bit length for the random mnemonic.
|
|
93
|
-
* @returns {BIP39} A new BIP39 instance.
|
|
94
|
-
*/
|
|
95
|
-
static fromRandom(bits) {
|
|
96
|
-
return new this().fromRandom(bits);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Converts given entropy into a mnemonic phrase.
|
|
100
|
-
* This method is used to generate a mnemonic from a specific entropy source.
|
|
101
|
-
* @param {number[]} buf - The entropy buffer, must be at least 128 bits.
|
|
102
|
-
* @returns {this} The BIP39 instance with the mnemonic set from the given entropy.
|
|
103
|
-
* @throws {Error} If the entropy is less than 128 bits.
|
|
104
|
-
*/
|
|
105
|
-
fromEntropy(buf) {
|
|
106
|
-
this.entropy2Mnemonic(buf);
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Static method to create a BIP39 instance from a given entropy.
|
|
111
|
-
* @param {number[]} buf - The entropy buffer.
|
|
112
|
-
* @returns {BIP39} A new BIP39 instance.
|
|
113
|
-
*/
|
|
114
|
-
static fromEntropy(buf) {
|
|
115
|
-
return new this().fromEntropy(buf);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Sets the mnemonic for the instance from a string.
|
|
119
|
-
* @param {string} mnemonic - The mnemonic phrase as a string.
|
|
120
|
-
* @returns {this} The BIP39 instance with the set mnemonic.
|
|
121
|
-
*/
|
|
122
|
-
fromString(mnemonic) {
|
|
123
|
-
this.mnemonic = mnemonic;
|
|
124
|
-
return this;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Static method to create a BIP39 instance from a mnemonic string.
|
|
128
|
-
* @param {string} str - The mnemonic phrase.
|
|
129
|
-
* @returns {BIP39} A new BIP39 instance.
|
|
130
|
-
*/
|
|
131
|
-
static fromString(str) {
|
|
132
|
-
return new this().fromString(str);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Converts the instance's mnemonic to a string representation.
|
|
136
|
-
* @returns {string} The mnemonic phrase as a string.
|
|
137
|
-
*/
|
|
138
|
-
toString() {
|
|
139
|
-
return this.mnemonic;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Converts the mnemonic to a seed.
|
|
143
|
-
* The mnemonic must pass the validity check before conversion.
|
|
144
|
-
* @param {string} [passphrase=''] - An optional passphrase for additional security.
|
|
145
|
-
* @returns {number[]} The generated seed.
|
|
146
|
-
* @throws {Error} If the mnemonic is invalid.
|
|
147
|
-
*/
|
|
148
|
-
toSeed(passphrase) {
|
|
149
|
-
this.mnemonic2Seed(passphrase);
|
|
150
|
-
return this.seed;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Converts entropy to a mnemonic phrase.
|
|
154
|
-
* This method takes a buffer of entropy and converts it into a corresponding
|
|
155
|
-
* mnemonic phrase based on the BIP39 wordlist. The entropy should be at least 128 bits.
|
|
156
|
-
* The method applies a checksum and maps the entropy to words in the wordlist.
|
|
157
|
-
* @param {number[]} buf - The entropy buffer to convert. Must be at least 128 bits.
|
|
158
|
-
* @returns {this} The BIP39 instance with the mnemonic set from the entropy.
|
|
159
|
-
* @throws {Error} If the entropy is less than 128 bits or if it's not an even multiple of 11 bits.
|
|
160
|
-
*/
|
|
161
|
-
entropy2Mnemonic(buf) {
|
|
162
|
-
if (buf.length < 128 / 8) {
|
|
163
|
-
throw new Error('Entropy is less than 128 bits. It must be 128 bits or more.');
|
|
164
|
-
}
|
|
165
|
-
const hash = Hash.sha256(buf);
|
|
166
|
-
let bin = '';
|
|
167
|
-
const bits = buf.length * 8;
|
|
168
|
-
for (let i = 0; i < buf.length; i++) {
|
|
169
|
-
bin = bin + ('00000000' + buf[i].toString(2)).slice(-8);
|
|
170
|
-
}
|
|
171
|
-
let hashbits = hash[0].toString(2);
|
|
172
|
-
hashbits = ('00000000' + hashbits).slice(-8).slice(0, bits / 32);
|
|
173
|
-
bin = bin + hashbits;
|
|
174
|
-
if (bin.length % 11 !== 0) {
|
|
175
|
-
throw new Error('internal error - entropy not an even multiple of 11 bits - ' + bin.length);
|
|
176
|
-
}
|
|
177
|
-
let mnemonic = '';
|
|
178
|
-
for (let i = 0; i < bin.length / 11; i++) {
|
|
179
|
-
if (mnemonic !== '') {
|
|
180
|
-
mnemonic = mnemonic + this.Wordlist.space;
|
|
181
|
-
}
|
|
182
|
-
const wi = parseInt(bin.slice(i * 11, (i + 1) * 11), 2);
|
|
183
|
-
mnemonic = mnemonic + this.Wordlist.value[wi];
|
|
184
|
-
}
|
|
185
|
-
this.mnemonic = mnemonic;
|
|
186
|
-
return this;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Validates the mnemonic phrase.
|
|
190
|
-
* Checks for correct length, absence of invalid words, and proper checksum.
|
|
191
|
-
* @returns {boolean} True if the mnemonic is valid, false otherwise.
|
|
192
|
-
* @throws {Error} If the mnemonic is not an even multiple of 11 bits.
|
|
193
|
-
*/
|
|
194
|
-
check() {
|
|
195
|
-
const mnemonic = this.mnemonic;
|
|
196
|
-
// confirm no invalid words
|
|
197
|
-
const words = mnemonic.split(this.Wordlist.space);
|
|
198
|
-
let bin = '';
|
|
199
|
-
for (let i = 0; i < words.length; i++) {
|
|
200
|
-
const ind = this.Wordlist.value.indexOf(words[i]);
|
|
201
|
-
if (ind < 0) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
bin = bin + ('00000000000' + ind.toString(2)).slice(-11);
|
|
205
|
-
}
|
|
206
|
-
if (bin.length % 11 !== 0) {
|
|
207
|
-
throw new Error('internal error - entropy not an even multiple of 11 bits - ' + bin.length);
|
|
208
|
-
}
|
|
209
|
-
// confirm checksum
|
|
210
|
-
const cs = bin.length / 33;
|
|
211
|
-
const hashBits = bin.slice(-cs);
|
|
212
|
-
const nonhashBits = bin.slice(0, bin.length - cs);
|
|
213
|
-
const buf = [];
|
|
214
|
-
for (let i = 0; i < nonhashBits.length / 8; i++) {
|
|
215
|
-
buf.push(parseInt(bin.slice(i * 8, (i + 1) * 8), 2));
|
|
216
|
-
}
|
|
217
|
-
const hash = Hash.sha256(buf.slice(0, nonhashBits.length / 8));
|
|
218
|
-
let expectedHashBits = hash[0].toString(2);
|
|
219
|
-
expectedHashBits = ('00000000' + expectedHashBits).slice(-8).slice(0, cs);
|
|
220
|
-
return expectedHashBits === hashBits;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Converts a mnemonic to a seed.
|
|
224
|
-
* This method takes the instance's mnemonic phrase, combines it with a passphrase (if provided),
|
|
225
|
-
* and uses PBKDF2 to generate a seed. It also validates the mnemonic before conversion.
|
|
226
|
-
* This seed can then be used for generating deterministic keys.
|
|
227
|
-
* @param {string} [passphrase=''] - An optional passphrase for added security.
|
|
228
|
-
* @returns {this} The BIP39 instance with the seed generated from the mnemonic.
|
|
229
|
-
* @throws {Error} If the mnemonic does not pass validation or if the passphrase is not a string.
|
|
230
|
-
*/
|
|
231
|
-
mnemonic2Seed(passphrase = '') {
|
|
232
|
-
let mnemonic = this.mnemonic;
|
|
233
|
-
if (!this.check()) {
|
|
234
|
-
throw new Error('Mnemonic does not pass the check - was the mnemonic typed incorrectly? Are there extra spaces?');
|
|
235
|
-
}
|
|
236
|
-
if (typeof passphrase !== 'string') {
|
|
237
|
-
throw new Error('passphrase must be a string or undefined');
|
|
238
|
-
}
|
|
239
|
-
mnemonic = mnemonic.normalize('NFKD');
|
|
240
|
-
passphrase = passphrase.normalize('NFKD');
|
|
241
|
-
const mbuf = toArray(mnemonic, 'utf8');
|
|
242
|
-
const pbuf = [...toArray('mnemonic', 'utf8'), ...toArray(passphrase, 'utf8')];
|
|
243
|
-
this.seed = Hash.pbkdf2(mbuf, pbuf, 2048, 64, 'sha512');
|
|
244
|
-
return this;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Determines the validity of a given passphrase with the mnemonic.
|
|
248
|
-
* This method is useful for checking if a passphrase matches with the mnemonic.
|
|
249
|
-
* @param {string} [passphrase=''] - The passphrase to validate.
|
|
250
|
-
* @returns {boolean} True if the mnemonic and passphrase combination is valid, false otherwise.
|
|
251
|
-
*/
|
|
252
|
-
isValid(passphrase = '') {
|
|
253
|
-
let isValid;
|
|
254
|
-
try {
|
|
255
|
-
isValid = !!this.mnemonic2Seed(passphrase);
|
|
256
|
-
}
|
|
257
|
-
catch (err) {
|
|
258
|
-
isValid = false;
|
|
259
|
-
}
|
|
260
|
-
return isValid;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Static method to check the validity of a given mnemonic and passphrase combination.
|
|
264
|
-
* @param {string} mnemonic - The mnemonic phrase.
|
|
265
|
-
* @param {string} [passphrase=''] - The passphrase to validate.
|
|
266
|
-
* @returns {boolean} True if the combination is valid, false otherwise.
|
|
267
|
-
*/
|
|
268
|
-
static isValid(mnemonic, passphrase = '') {
|
|
269
|
-
return new BIP39(mnemonic).isValid(passphrase);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
//# sourceMappingURL=BIP39.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BIP39.js","sourceRoot":"","sources":["../../../../src/compat/BIP39.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AACxE,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAA;AAC7C,OAAO,MAAM,MAAM,yBAA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E,CAAC;YACX,OAAO,GAAG,KAAK,CAAA;QACnB,CAAC;QACD,OAAO,OAAO,CAAA;IAClB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CAAC,QAAgB,EAAE,UAAU,GAAG,EAAE;QACnD,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAClD,CAAC;CACJ"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import OP from '../OP.js';
|
|
2
|
-
import LockingScript from '../LockingScript.js';
|
|
3
|
-
import UnlockingScript from '../UnlockingScript.js';
|
|
4
|
-
import TransactionSignature from '../../primitives/TransactionSignature.js';
|
|
5
|
-
import { sha256 } from '../../primitives/Hash.js';
|
|
6
|
-
import { toArray } from '../../primitives/utils.js';
|
|
7
|
-
/**
|
|
8
|
-
* P2PKH (Pay To Public Key Hash) class implementing ScriptTemplate.
|
|
9
|
-
*
|
|
10
|
-
* This class provides methods to create Pay To Public Key Hash locking and unlocking scripts, including the unlocking of P2PKH UTXOs with the private key.
|
|
11
|
-
*/
|
|
12
|
-
export default class P2PKHT {
|
|
13
|
-
/**
|
|
14
|
-
* Creates a P2PKH locking script for a given public key hash.
|
|
15
|
-
*
|
|
16
|
-
* @param {number[]} pubkeyhash - An array representing the public key hash.
|
|
17
|
-
* @returns {LockingScript} - A P2PKH locking script.
|
|
18
|
-
*/
|
|
19
|
-
lock(pubkeyhash) {
|
|
20
|
-
const time = toArray(Date.now().toString());
|
|
21
|
-
return new LockingScript([
|
|
22
|
-
{ op: time.length, data: time },
|
|
23
|
-
{ op: OP.OP_DROP },
|
|
24
|
-
{ op: OP.OP_DUP },
|
|
25
|
-
{ op: OP.OP_HASH160 },
|
|
26
|
-
{ op: pubkeyhash.length, data: pubkeyhash },
|
|
27
|
-
{ op: OP.OP_EQUALVERIFY },
|
|
28
|
-
{ op: OP.OP_CHECKSIG }
|
|
29
|
-
]);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Creates a function that generates a P2PKH unlocking script along with its signature and length estimation.
|
|
33
|
-
*
|
|
34
|
-
* The returned object contains:
|
|
35
|
-
* 1. `sign` - A function that, when invoked with a transaction and an input index,
|
|
36
|
-
* produces an unlocking script suitable for a P2PKH locked output.
|
|
37
|
-
* 2. `estimateLength` - A function that returns the estimated length of the unlocking script in bytes.
|
|
38
|
-
*
|
|
39
|
-
* @param {PrivateKey} privateKey - The private key used for signing the transaction.
|
|
40
|
-
* @param {'all'|'none'|'single'} signOutputs - The signature scope for outputs.
|
|
41
|
-
* @param {boolean} anyoneCanPay - Flag indicating if the signature allows for other inputs to be added later.
|
|
42
|
-
* @returns {Object} - An object containing the `sign` and `estimateLength` functions.
|
|
43
|
-
*/
|
|
44
|
-
unlock(privateKey, signOutputs = 'all', anyoneCanPay = false) {
|
|
45
|
-
return {
|
|
46
|
-
sign: async (tx, inputIndex) => {
|
|
47
|
-
let signatureScope = TransactionSignature.SIGHASH_FORKID;
|
|
48
|
-
if (signOutputs === 'all') {
|
|
49
|
-
signatureScope |= TransactionSignature.SIGHASH_ALL;
|
|
50
|
-
}
|
|
51
|
-
if (signOutputs === 'none') {
|
|
52
|
-
signatureScope |= TransactionSignature.SIGHASH_NONE;
|
|
53
|
-
}
|
|
54
|
-
if (signOutputs === 'single') {
|
|
55
|
-
signatureScope |= TransactionSignature.SIGHASH_SINGLE;
|
|
56
|
-
}
|
|
57
|
-
if (anyoneCanPay) {
|
|
58
|
-
signatureScope |= TransactionSignature.SIGHASH_ANYONECANPAY;
|
|
59
|
-
}
|
|
60
|
-
const otherInputs = [...tx.inputs];
|
|
61
|
-
const [input] = otherInputs.splice(inputIndex, 1);
|
|
62
|
-
if (typeof input.sourceTransaction !== 'object') {
|
|
63
|
-
// Question: Should the library support use-cases where the source transaction is not provided? This is to say, is it ever acceptable for someone to sign an input spending some output from a transaction they have not provided? Some elements (such as the satoshi value and output script) are always required. A merkle proof is also always required, and verifying it (while also verifying that the claimed output is contained within the claimed transaction) is also always required. This seems to require the entire input transaction.
|
|
64
|
-
throw new Error('The source transaction is needed for transaction signing.');
|
|
65
|
-
}
|
|
66
|
-
const preimage = TransactionSignature.format({
|
|
67
|
-
sourceTXID: input.sourceTransaction.id('hex'),
|
|
68
|
-
sourceOutputIndex: input.sourceOutputIndex,
|
|
69
|
-
sourceSatoshis: input.sourceTransaction.outputs[input.sourceOutputIndex].satoshis,
|
|
70
|
-
transactionVersion: tx.version,
|
|
71
|
-
otherInputs,
|
|
72
|
-
inputIndex,
|
|
73
|
-
outputs: tx.outputs,
|
|
74
|
-
inputSequence: input.sequence,
|
|
75
|
-
subscript: input.sourceTransaction.outputs[input.sourceOutputIndex].lockingScript,
|
|
76
|
-
lockTime: tx.lockTime,
|
|
77
|
-
scope: signatureScope
|
|
78
|
-
});
|
|
79
|
-
const rawSignature = privateKey.sign(sha256(preimage));
|
|
80
|
-
const sig = new TransactionSignature(rawSignature.r, rawSignature.s, signatureScope);
|
|
81
|
-
const sigForScript = sig.toChecksigFormat();
|
|
82
|
-
const pubkeyForScript = privateKey.toPublicKey().encode(true);
|
|
83
|
-
return new UnlockingScript([
|
|
84
|
-
{ op: sigForScript.length, data: sigForScript },
|
|
85
|
-
{ op: pubkeyForScript.length, data: pubkeyForScript }
|
|
86
|
-
]);
|
|
87
|
-
},
|
|
88
|
-
estimateLength: async () => {
|
|
89
|
-
// public key (1+33) + signature (1+71)
|
|
90
|
-
// Note: We add 1 to each element's length because of the associated OP_PUSH
|
|
91
|
-
return 106;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
//# sourceMappingURL=P2PKHT.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"P2PKHT.js","sourceRoot":"","sources":["../../../../../src/script/templates/P2PKHT.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAA;AAEzB,OAAO,aAAa,MAAM,qBAAqB,CAAA;AAC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C,EACd,YAAY,CAAC,CAAC,EACd,cAAc,CACf,CAAA;gBACD,MAAM,YAAY,GAAG,GAAG,CAAC,gBAAgB,EAAE,CAAA;gBAC3C,MAAM,eAAe,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAa,CAAA;gBACzE,OAAO,IAAI,eAAe,CAAC;oBACzB,EAAE,EAAE,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE;oBAC/C,EAAE,EAAE,EAAE,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE;iBACtD,CAAC,CAAA;YACJ,CAAC;YACD,cAAc,EAAE,KAAK,IAAI,EAAE;gBACzB,uCAAuC;gBACvC,4EAA4E;gBAC5E,OAAO,GAAG,CAAA;YACZ,CAAC;SACF,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @class BIP39
|
|
3
|
-
*
|
|
4
|
-
* @description
|
|
5
|
-
* Class representing BIP39 functionality.
|
|
6
|
-
* This class provides methods for generating, converting, and validating mnemonic phrases
|
|
7
|
-
* according to the BIP39 standard. It supports creating mnemonics from random entropy,
|
|
8
|
-
* converting mnemonics to seeds, and validating mnemonic phrases.
|
|
9
|
-
*/
|
|
10
|
-
export default class BIP39 {
|
|
11
|
-
mnemonic: string;
|
|
12
|
-
seed: number[];
|
|
13
|
-
Wordlist: {
|
|
14
|
-
value: string[];
|
|
15
|
-
space: string;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Constructs a BIP39 object.
|
|
19
|
-
* @param {string} [mnemonic] - An optional mnemonic phrase.
|
|
20
|
-
* @param {number[]} [seed] - An optional seed derived from the mnemonic.
|
|
21
|
-
* @param {object} [wordlist=wordList] - An object containing a list of words and space character used in the mnemonic.
|
|
22
|
-
*/
|
|
23
|
-
constructor(mnemonic?: string, seed?: number[], wordlist?: {
|
|
24
|
-
value: string[];
|
|
25
|
-
space: string;
|
|
26
|
-
});
|
|
27
|
-
/**
|
|
28
|
-
* Converts the mnemonic and seed into a binary representation.
|
|
29
|
-
* @returns {number[]} The binary representation of the mnemonic and seed.
|
|
30
|
-
*/
|
|
31
|
-
toBinary(): number[];
|
|
32
|
-
/**
|
|
33
|
-
* Loads a mnemonic and seed from a binary representation.
|
|
34
|
-
* @param {number[]} bin - The binary representation of a mnemonic and seed.
|
|
35
|
-
* @returns {this} The BIP39 instance with loaded mnemonic and seed.
|
|
36
|
-
*/
|
|
37
|
-
fromBinary(bin: number[]): this;
|
|
38
|
-
/**
|
|
39
|
-
* Generates a random mnemonic from a given bit length.
|
|
40
|
-
* @param {number} [bits=128] - The bit length for the random mnemonic (must be a multiple of 32 and at least 128).
|
|
41
|
-
* @returns {this} The BIP39 instance with the new random mnemonic.
|
|
42
|
-
* @throws {Error} If the bit length is not a multiple of 32 or is less than 128.
|
|
43
|
-
*/
|
|
44
|
-
fromRandom(bits?: number): this;
|
|
45
|
-
/**
|
|
46
|
-
* Static method to generate a BIP39 instance with a random mnemonic.
|
|
47
|
-
* @param {number} [bits=128] - The bit length for the random mnemonic.
|
|
48
|
-
* @returns {BIP39} A new BIP39 instance.
|
|
49
|
-
*/
|
|
50
|
-
static fromRandom(bits?: number): BIP39;
|
|
51
|
-
/**
|
|
52
|
-
* Converts given entropy into a mnemonic phrase.
|
|
53
|
-
* This method is used to generate a mnemonic from a specific entropy source.
|
|
54
|
-
* @param {number[]} buf - The entropy buffer, must be at least 128 bits.
|
|
55
|
-
* @returns {this} The BIP39 instance with the mnemonic set from the given entropy.
|
|
56
|
-
* @throws {Error} If the entropy is less than 128 bits.
|
|
57
|
-
*/
|
|
58
|
-
fromEntropy(buf: number[]): this;
|
|
59
|
-
/**
|
|
60
|
-
* Static method to create a BIP39 instance from a given entropy.
|
|
61
|
-
* @param {number[]} buf - The entropy buffer.
|
|
62
|
-
* @returns {BIP39} A new BIP39 instance.
|
|
63
|
-
*/
|
|
64
|
-
static fromEntropy(buf: number[]): BIP39;
|
|
65
|
-
/**
|
|
66
|
-
* Sets the mnemonic for the instance from a string.
|
|
67
|
-
* @param {string} mnemonic - The mnemonic phrase as a string.
|
|
68
|
-
* @returns {this} The BIP39 instance with the set mnemonic.
|
|
69
|
-
*/
|
|
70
|
-
fromString(mnemonic: string): this;
|
|
71
|
-
/**
|
|
72
|
-
* Static method to create a BIP39 instance from a mnemonic string.
|
|
73
|
-
* @param {string} str - The mnemonic phrase.
|
|
74
|
-
* @returns {BIP39} A new BIP39 instance.
|
|
75
|
-
*/
|
|
76
|
-
static fromString(str: string): BIP39;
|
|
77
|
-
/**
|
|
78
|
-
* Converts the instance's mnemonic to a string representation.
|
|
79
|
-
* @returns {string} The mnemonic phrase as a string.
|
|
80
|
-
*/
|
|
81
|
-
toString(): string;
|
|
82
|
-
/**
|
|
83
|
-
* Converts the mnemonic to a seed.
|
|
84
|
-
* The mnemonic must pass the validity check before conversion.
|
|
85
|
-
* @param {string} [passphrase=''] - An optional passphrase for additional security.
|
|
86
|
-
* @returns {number[]} The generated seed.
|
|
87
|
-
* @throws {Error} If the mnemonic is invalid.
|
|
88
|
-
*/
|
|
89
|
-
toSeed(passphrase?: string): number[];
|
|
90
|
-
/**
|
|
91
|
-
* Converts entropy to a mnemonic phrase.
|
|
92
|
-
* This method takes a buffer of entropy and converts it into a corresponding
|
|
93
|
-
* mnemonic phrase based on the BIP39 wordlist. The entropy should be at least 128 bits.
|
|
94
|
-
* The method applies a checksum and maps the entropy to words in the wordlist.
|
|
95
|
-
* @param {number[]} buf - The entropy buffer to convert. Must be at least 128 bits.
|
|
96
|
-
* @returns {this} The BIP39 instance with the mnemonic set from the entropy.
|
|
97
|
-
* @throws {Error} If the entropy is less than 128 bits or if it's not an even multiple of 11 bits.
|
|
98
|
-
*/
|
|
99
|
-
entropy2Mnemonic(buf: number[]): this;
|
|
100
|
-
/**
|
|
101
|
-
* Validates the mnemonic phrase.
|
|
102
|
-
* Checks for correct length, absence of invalid words, and proper checksum.
|
|
103
|
-
* @returns {boolean} True if the mnemonic is valid, false otherwise.
|
|
104
|
-
* @throws {Error} If the mnemonic is not an even multiple of 11 bits.
|
|
105
|
-
*/
|
|
106
|
-
check(): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Converts a mnemonic to a seed.
|
|
109
|
-
* This method takes the instance's mnemonic phrase, combines it with a passphrase (if provided),
|
|
110
|
-
* and uses PBKDF2 to generate a seed. It also validates the mnemonic before conversion.
|
|
111
|
-
* This seed can then be used for generating deterministic keys.
|
|
112
|
-
* @param {string} [passphrase=''] - An optional passphrase for added security.
|
|
113
|
-
* @returns {this} The BIP39 instance with the seed generated from the mnemonic.
|
|
114
|
-
* @throws {Error} If the mnemonic does not pass validation or if the passphrase is not a string.
|
|
115
|
-
*/
|
|
116
|
-
mnemonic2Seed(passphrase?: string): this;
|
|
117
|
-
/**
|
|
118
|
-
* Determines the validity of a given passphrase with the mnemonic.
|
|
119
|
-
* This method is useful for checking if a passphrase matches with the mnemonic.
|
|
120
|
-
* @param {string} [passphrase=''] - The passphrase to validate.
|
|
121
|
-
* @returns {boolean} True if the mnemonic and passphrase combination is valid, false otherwise.
|
|
122
|
-
*/
|
|
123
|
-
isValid(passphrase?: string): boolean;
|
|
124
|
-
/**
|
|
125
|
-
* Static method to check the validity of a given mnemonic and passphrase combination.
|
|
126
|
-
* @param {string} mnemonic - The mnemonic phrase.
|
|
127
|
-
* @param {string} [passphrase=''] - The passphrase to validate.
|
|
128
|
-
* @returns {boolean} True if the combination is valid, false otherwise.
|
|
129
|
-
*/
|
|
130
|
-
static isValid(mnemonic: string, passphrase?: string): boolean;
|
|
131
|
-
}
|
|
132
|
-
//# sourceMappingURL=BIP39.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BIP39.d.ts","sourceRoot":"","sources":["../../../../src/compat/BIP39.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IAC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G,OAAO;CAGpE"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import ScriptTemplate from '../ScriptTemplate.js';
|
|
2
|
-
import LockingScript from '../LockingScript.js';
|
|
3
|
-
import UnlockingScript from '../UnlockingScript.js';
|
|
4
|
-
import Transaction from '../../transaction/Transaction.js';
|
|
5
|
-
import PrivateKey from '../../primitives/PrivateKey.js';
|
|
6
|
-
/**
|
|
7
|
-
* P2PKH (Pay To Public Key Hash) class implementing ScriptTemplate.
|
|
8
|
-
*
|
|
9
|
-
* This class provides methods to create Pay To Public Key Hash locking and unlocking scripts, including the unlocking of P2PKH UTXOs with the private key.
|
|
10
|
-
*/
|
|
11
|
-
export default class P2PKHT implements ScriptTemplate {
|
|
12
|
-
/**
|
|
13
|
-
* Creates a P2PKH locking script for a given public key hash.
|
|
14
|
-
*
|
|
15
|
-
* @param {number[]} pubkeyhash - An array representing the public key hash.
|
|
16
|
-
* @returns {LockingScript} - A P2PKH locking script.
|
|
17
|
-
*/
|
|
18
|
-
lock(pubkeyhash: number[]): LockingScript;
|
|
19
|
-
/**
|
|
20
|
-
* Creates a function that generates a P2PKH unlocking script along with its signature and length estimation.
|
|
21
|
-
*
|
|
22
|
-
* The returned object contains:
|
|
23
|
-
* 1. `sign` - A function that, when invoked with a transaction and an input index,
|
|
24
|
-
* produces an unlocking script suitable for a P2PKH locked output.
|
|
25
|
-
* 2. `estimateLength` - A function that returns the estimated length of the unlocking script in bytes.
|
|
26
|
-
*
|
|
27
|
-
* @param {PrivateKey} privateKey - The private key used for signing the transaction.
|
|
28
|
-
* @param {'all'|'none'|'single'} signOutputs - The signature scope for outputs.
|
|
29
|
-
* @param {boolean} anyoneCanPay - Flag indicating if the signature allows for other inputs to be added later.
|
|
30
|
-
* @returns {Object} - An object containing the `sign` and `estimateLength` functions.
|
|
31
|
-
*/
|
|
32
|
-
unlock(privateKey: PrivateKey, signOutputs?: 'all' | 'none' | 'single', anyoneCanPay?: boolean): {
|
|
33
|
-
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
34
|
-
estimateLength: () => Promise<106>;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=P2PKHT.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"P2PKHT.d.ts","sourceRoot":"","sources":["../../../../../src/script/templates/P2PKHT.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,sBAAsB,CAAA;AACjD,OAAO,aAAa,MAAM,qBAAqB,CAAA;AAC/C,OAAO,eAAe,MAAM,uBAAuB,CAAA;AACnD,OAAO,WAAW,MAAM,kCAAkC,CAAA;AAC1D,OAAO,UAAU,MAAM,gCAAgC,CAAA;AAKvD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,MAAO,YAAW,cAAc;IACnD;;;;;OAKG;IACH,IAAI,CAAE,UAAU,EAAE,MAAM,EAAE,GAAG,aAAa;IAa1C;;;;;;;;;;;;OAYG;IACH,MAAM,CACJ,UAAU,EAAE,UAAU,EACtB,WAAW,GAAE,KAAK,GAAG,MAAM,GAAG,QAAgB,EAC9C,YAAY,GAAE,OAAe,GAC5B;QACC,IAAI,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,CAAA;QACvE,cAAc,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;KACnC;CAyDJ"}
|