@bsv/sdk 1.0.13 → 1.0.15
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 +1 -1
- package/dist/cjs/package.json +2 -2
- package/dist/cjs/src/compat/BSM.js.map +1 -1
- package/dist/cjs/src/compat/ECIES.js +105 -76
- package/dist/cjs/src/compat/ECIES.js.map +1 -1
- package/dist/cjs/src/compat/HD.js +65 -65
- package/dist/cjs/src/compat/HD.js.map +1 -1
- package/dist/cjs/src/compat/Mnemonic.js +79 -79
- package/dist/cjs/src/compat/Mnemonic.js.map +1 -1
- package/dist/cjs/src/compat/bip-39-wordlist-en.js +2 -2
- package/dist/cjs/src/compat/bip-39-wordlist-en.js.map +1 -1
- package/dist/cjs/src/primitives/AESGCM.js.map +1 -1
- package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
- package/dist/cjs/src/primitives/DRBG.js.map +1 -1
- package/dist/cjs/src/primitives/ECDSA.js.map +1 -1
- package/dist/cjs/src/primitives/Hash.js +26 -13
- package/dist/cjs/src/primitives/Hash.js.map +1 -1
- package/dist/cjs/src/primitives/PrivateKey.js +3 -2
- package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
- package/dist/cjs/src/primitives/PublicKey.js +1 -2
- package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
- package/dist/cjs/src/primitives/Random.js +2 -2
- package/dist/cjs/src/primitives/Random.js.map +1 -1
- package/dist/cjs/src/primitives/Signature.js +141 -4
- package/dist/cjs/src/primitives/Signature.js.map +1 -1
- package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -1
- package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -1
- package/dist/cjs/src/primitives/utils.js +14 -9
- package/dist/cjs/src/primitives/utils.js.map +1 -1
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/src/script/templates/P2PKH.js +1 -1
- package/dist/cjs/src/script/templates/P2PKH.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 +2 -2
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/compat/BSM.js.map +1 -1
- package/dist/esm/src/compat/ECIES.js +105 -76
- package/dist/esm/src/compat/ECIES.js.map +1 -1
- package/dist/esm/src/compat/HD.js +65 -65
- package/dist/esm/src/compat/HD.js.map +1 -1
- package/dist/esm/src/compat/Mnemonic.js +79 -79
- package/dist/esm/src/compat/Mnemonic.js.map +1 -1
- package/dist/esm/src/compat/bip-39-wordlist-en.js +2 -2
- package/dist/esm/src/compat/bip-39-wordlist-en.js.map +1 -1
- package/dist/esm/src/primitives/AESGCM.js.map +1 -1
- package/dist/esm/src/primitives/BigNumber.js.map +1 -1
- package/dist/esm/src/primitives/DRBG.js.map +1 -1
- package/dist/esm/src/primitives/ECDSA.js.map +1 -1
- package/dist/esm/src/primitives/Hash.js +26 -13
- package/dist/esm/src/primitives/Hash.js.map +1 -1
- package/dist/esm/src/primitives/PrivateKey.js +3 -2
- package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
- package/dist/esm/src/primitives/PublicKey.js +1 -2
- package/dist/esm/src/primitives/PublicKey.js.map +1 -1
- package/dist/esm/src/primitives/Random.js +2 -2
- package/dist/esm/src/primitives/Random.js.map +1 -1
- package/dist/esm/src/primitives/Signature.js +141 -4
- package/dist/esm/src/primitives/Signature.js.map +1 -1
- package/dist/esm/src/primitives/SymmetricKey.js.map +1 -1
- package/dist/esm/src/primitives/TransactionSignature.js.map +1 -1
- package/dist/esm/src/primitives/utils.js +14 -9
- package/dist/esm/src/primitives/utils.js.map +1 -1
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/src/script/templates/P2PKH.js +1 -1
- package/dist/esm/src/script/templates/P2PKH.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 +2 -2
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/compat/ECIES.d.ts +36 -36
- package/dist/types/src/compat/ECIES.d.ts.map +1 -1
- package/dist/types/src/compat/HD.d.ts +65 -65
- package/dist/types/src/compat/HD.d.ts.map +1 -1
- package/dist/types/src/compat/Mnemonic.d.ts +79 -79
- package/dist/types/src/compat/Mnemonic.d.ts.map +1 -1
- package/dist/types/src/primitives/AESGCM.d.ts.map +1 -1
- package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
- package/dist/types/src/primitives/Hash.d.ts.map +1 -1
- package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
- package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
- package/dist/types/src/primitives/Signature.d.ts +62 -0
- package/dist/types/src/primitives/Signature.d.ts.map +1 -1
- package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -1
- package/dist/types/src/primitives/TransactionSignature.d.ts.map +1 -1
- package/dist/types/src/primitives/utils.d.ts.map +1 -1
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/docs/compat.md +4 -4
- package/docs/primitives.md +288 -79
- package/mod.ts +8 -0
- package/package.json +5 -3
- package/src/compat/BSM.ts +12 -12
- package/src/compat/ECIES.ts +417 -418
- package/src/compat/HD.ts +228 -228
- package/src/compat/Mnemonic.ts +173 -173
- package/src/compat/__tests/BSM.test.ts +13 -2
- package/src/compat/bip-39-wordlist-en.ts +2052 -2052
- package/src/primitives/AESGCM.ts +30 -30
- package/src/primitives/BigNumber.ts +0 -1
- package/src/primitives/DRBG.ts +5 -5
- package/src/primitives/ECDSA.ts +1 -1
- package/src/primitives/Hash.ts +278 -293
- package/src/primitives/PrivateKey.ts +18 -19
- package/src/primitives/PublicKey.ts +9 -10
- package/src/primitives/Random.ts +4 -4
- package/src/primitives/Signature.ts +158 -14
- package/src/primitives/SymmetricKey.ts +3 -3
- package/src/primitives/TransactionSignature.ts +9 -9
- package/src/primitives/index.ts +1 -1
- package/src/primitives/utils.ts +60 -64
- package/src/script/Spend.ts +12 -12
- package/src/script/index.ts +1 -1
- package/src/script/templates/P2PKH.ts +1 -1
- package/src/transaction/MerklePath.ts +3 -3
- package/src/transaction/Transaction.ts +23 -23
|
@@ -60,7 +60,7 @@ export default class Transaction {
|
|
|
60
60
|
* @param beef A binary representation of a transaction in BEEF format.
|
|
61
61
|
* @returns An anchored transaction, linked to its associated inputs populated with merkle paths.
|
|
62
62
|
*/
|
|
63
|
-
static fromBEEF(beef: number[]): Transaction {
|
|
63
|
+
static fromBEEF (beef: number[]): Transaction {
|
|
64
64
|
const reader = new Reader(beef)
|
|
65
65
|
// Read the version
|
|
66
66
|
const version = reader.readUInt32LE()
|
|
@@ -120,7 +120,7 @@ export default class Transaction {
|
|
|
120
120
|
return transactions[lastTXID].tx
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
private static fromReader(br: Reader): Transaction {
|
|
123
|
+
private static fromReader (br: Reader): Transaction {
|
|
124
124
|
const version = br.readUInt32LE()
|
|
125
125
|
const inputsLength = br.readVarIntNum()
|
|
126
126
|
const inputs: TransactionInput[] = []
|
|
@@ -161,7 +161,7 @@ export default class Transaction {
|
|
|
161
161
|
* @param {number[]} bin - The binary array representation of the transaction.
|
|
162
162
|
* @returns {Transaction} - A new Transaction instance.
|
|
163
163
|
*/
|
|
164
|
-
static fromBinary(bin: number[]): Transaction {
|
|
164
|
+
static fromBinary (bin: number[]): Transaction {
|
|
165
165
|
const br = new Reader(bin)
|
|
166
166
|
return Transaction.fromReader(br)
|
|
167
167
|
}
|
|
@@ -173,7 +173,7 @@ export default class Transaction {
|
|
|
173
173
|
* @param {string} hex - The hexadecimal string representation of the transaction.
|
|
174
174
|
* @returns {Transaction} - A new Transaction instance.
|
|
175
175
|
*/
|
|
176
|
-
static fromHex(hex: string): Transaction {
|
|
176
|
+
static fromHex (hex: string): Transaction {
|
|
177
177
|
return Transaction.fromBinary(toArray(hex, 'hex'))
|
|
178
178
|
}
|
|
179
179
|
|
|
@@ -184,11 +184,11 @@ export default class Transaction {
|
|
|
184
184
|
* @param {string} hex - The hexadecimal string representation of the transaction BEEF.
|
|
185
185
|
* @returns {Transaction} - A new Transaction instance.
|
|
186
186
|
*/
|
|
187
|
-
static fromHexBEEF(hex: string): Transaction {
|
|
187
|
+
static fromHexBEEF (hex: string): Transaction {
|
|
188
188
|
return Transaction.fromBEEF(toArray(hex, 'hex'))
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
constructor(
|
|
191
|
+
constructor (
|
|
192
192
|
version: number = 1,
|
|
193
193
|
inputs: TransactionInput[] = [],
|
|
194
194
|
outputs: TransactionOutput[] = [],
|
|
@@ -210,7 +210,7 @@ export default class Transaction {
|
|
|
210
210
|
* @param {TransactionInput} input - The TransactionInput object to add to the transaction.
|
|
211
211
|
* @throws {Error} - If the input does not have a sourceTXID or sourceTransaction defined.
|
|
212
212
|
*/
|
|
213
|
-
addInput(input: TransactionInput): void {
|
|
213
|
+
addInput (input: TransactionInput): void {
|
|
214
214
|
if (
|
|
215
215
|
typeof input.sourceTXID === 'undefined' &&
|
|
216
216
|
typeof input.sourceTransaction === 'undefined'
|
|
@@ -230,7 +230,7 @@ export default class Transaction {
|
|
|
230
230
|
*
|
|
231
231
|
* @param {TransactionOutput} output - The TransactionOutput object to add to the transaction.
|
|
232
232
|
*/
|
|
233
|
-
addOutput(output: TransactionOutput): void {
|
|
233
|
+
addOutput (output: TransactionOutput): void {
|
|
234
234
|
this.cachedHash = undefined
|
|
235
235
|
this.outputs.push(output)
|
|
236
236
|
}
|
|
@@ -240,7 +240,7 @@ export default class Transaction {
|
|
|
240
240
|
*
|
|
241
241
|
* @param {Record<string, any>} metadata - The metadata object to merge into the existing metadata.
|
|
242
242
|
*/
|
|
243
|
-
updateMetadata(metadata: Record<string, any>): void {
|
|
243
|
+
updateMetadata (metadata: Record<string, any>): void {
|
|
244
244
|
this.metadata = {
|
|
245
245
|
...this.metadata,
|
|
246
246
|
...metadata
|
|
@@ -257,7 +257,7 @@ export default class Transaction {
|
|
|
257
257
|
*
|
|
258
258
|
* TODO: Benford's law change distribution.
|
|
259
259
|
*/
|
|
260
|
-
async fee(model?: FeeModel, changeDistribution: 'equal' | 'random' = 'equal'): Promise<void> {
|
|
260
|
+
async fee (model?: FeeModel, changeDistribution: 'equal' | 'random' = 'equal'): Promise<void> {
|
|
261
261
|
this.cachedHash = undefined
|
|
262
262
|
if (typeof model === 'undefined') {
|
|
263
263
|
model = new SatoshisPerKilobyte(10)
|
|
@@ -310,7 +310,7 @@ export default class Transaction {
|
|
|
310
310
|
/**
|
|
311
311
|
* Signs a transaction, hydrating all its unlocking scripts based on the provided script templates where they are available.
|
|
312
312
|
*/
|
|
313
|
-
async sign(): Promise<void> {
|
|
313
|
+
async sign (): Promise<void> {
|
|
314
314
|
this.cachedHash = undefined
|
|
315
315
|
for (const out of this.outputs) {
|
|
316
316
|
if (typeof out.satoshis === 'undefined') {
|
|
@@ -323,9 +323,9 @@ export default class Transaction {
|
|
|
323
323
|
}
|
|
324
324
|
const unlockingScripts = await Promise.all(this.inputs.map(async (x, i): Promise<UnlockingScript | undefined> => {
|
|
325
325
|
if (typeof this.inputs[i].unlockingScriptTemplate === 'object') {
|
|
326
|
-
return this.inputs[i].unlockingScriptTemplate.sign(this, i)
|
|
326
|
+
return await this.inputs[i].unlockingScriptTemplate.sign(this, i)
|
|
327
327
|
} else {
|
|
328
|
-
return Promise.resolve(undefined)
|
|
328
|
+
return await Promise.resolve(undefined)
|
|
329
329
|
}
|
|
330
330
|
}))
|
|
331
331
|
for (let i = 0, l = this.inputs.length; i < l; i++) {
|
|
@@ -341,7 +341,7 @@ export default class Transaction {
|
|
|
341
341
|
* @param broadcaster The Broadcaster instance wwhere the transaction will be sent
|
|
342
342
|
* @returns A BroadcastResponse or BroadcastFailure from the Broadcaster
|
|
343
343
|
*/
|
|
344
|
-
async broadcast(broadcaster: Broadcaster): Promise<BroadcastResponse | BroadcastFailure> {
|
|
344
|
+
async broadcast (broadcaster: Broadcaster): Promise<BroadcastResponse | BroadcastFailure> {
|
|
345
345
|
return await broadcaster.broadcast(this)
|
|
346
346
|
}
|
|
347
347
|
|
|
@@ -350,7 +350,7 @@ export default class Transaction {
|
|
|
350
350
|
*
|
|
351
351
|
* @returns {number[]} - The binary array representation of the transaction.
|
|
352
352
|
*/
|
|
353
|
-
toBinary(): number[] {
|
|
353
|
+
toBinary (): number[] {
|
|
354
354
|
const writer = new Writer()
|
|
355
355
|
writer.writeUInt32LE(this.version)
|
|
356
356
|
writer.writeVarIntNum(this.inputs.length)
|
|
@@ -382,7 +382,7 @@ export default class Transaction {
|
|
|
382
382
|
*
|
|
383
383
|
* @returns {number[]} - The BRC-30 EF representation of the transaction.
|
|
384
384
|
*/
|
|
385
|
-
toEF(): number[] {
|
|
385
|
+
toEF (): number[] {
|
|
386
386
|
const writer = new Writer()
|
|
387
387
|
writer.writeUInt32LE(this.version)
|
|
388
388
|
writer.write([0, 0, 0, 0, 0, 0xef])
|
|
@@ -418,7 +418,7 @@ export default class Transaction {
|
|
|
418
418
|
*
|
|
419
419
|
* @returns {string} - The hexadecimal string representation of the transaction EF.
|
|
420
420
|
*/
|
|
421
|
-
toHexEF(): string {
|
|
421
|
+
toHexEF (): string {
|
|
422
422
|
return toHex(this.toEF())
|
|
423
423
|
}
|
|
424
424
|
|
|
@@ -427,7 +427,7 @@ export default class Transaction {
|
|
|
427
427
|
*
|
|
428
428
|
* @returns {string} - The hexadecimal string representation of the transaction.
|
|
429
429
|
*/
|
|
430
|
-
toHex(): string {
|
|
430
|
+
toHex (): string {
|
|
431
431
|
return toHex(this.toBinary())
|
|
432
432
|
}
|
|
433
433
|
|
|
@@ -436,7 +436,7 @@ export default class Transaction {
|
|
|
436
436
|
*
|
|
437
437
|
* @returns {string} - The hexadecimal string representation of the transaction BEEF.
|
|
438
438
|
*/
|
|
439
|
-
toHexBEEF(): string {
|
|
439
|
+
toHexBEEF (): string {
|
|
440
440
|
return toHex(this.toBEEF())
|
|
441
441
|
}
|
|
442
442
|
|
|
@@ -446,7 +446,7 @@ export default class Transaction {
|
|
|
446
446
|
* @param {'hex' | undefined} enc - The encoding to use for the hash. If 'hex', returns a hexadecimal string; otherwise returns a binary array.
|
|
447
447
|
* @returns {string | number[]} - The hash of the transaction in the specified format.
|
|
448
448
|
*/
|
|
449
|
-
hash(enc?: 'hex'): number[] | string {
|
|
449
|
+
hash (enc?: 'hex'): number[] | string {
|
|
450
450
|
let hash
|
|
451
451
|
if (this.cachedHash) {
|
|
452
452
|
hash = this.cachedHash
|
|
@@ -467,7 +467,7 @@ export default class Transaction {
|
|
|
467
467
|
* @param {'hex' | undefined} enc - The encoding to use for the ID. If 'hex', returns a hexadecimal string; otherwise returns a binary array.
|
|
468
468
|
* @returns {string | number[]} - The ID of the transaction in the specified format.
|
|
469
469
|
*/
|
|
470
|
-
id(enc?: 'hex'): number[] | string {
|
|
470
|
+
id (enc?: 'hex'): number[] | string {
|
|
471
471
|
const id = [...this.hash() as number[]]
|
|
472
472
|
id.reverse()
|
|
473
473
|
if (enc === 'hex') {
|
|
@@ -483,7 +483,7 @@ export default class Transaction {
|
|
|
483
483
|
*
|
|
484
484
|
* @returns Whether the transaction is valid according to the rules of SPV.
|
|
485
485
|
*/
|
|
486
|
-
async verify(chainTracker: ChainTracker | 'scripts only'): Promise<boolean> {
|
|
486
|
+
async verify (chainTracker: ChainTracker | 'scripts only'): Promise<boolean> {
|
|
487
487
|
// If the transaction has a valid merkle path, verification is complete.
|
|
488
488
|
if (typeof this.merklePath === 'object' && chainTracker !== 'scripts only') {
|
|
489
489
|
const proofValid = await this.merklePath.verify(
|
|
@@ -551,7 +551,7 @@ export default class Transaction {
|
|
|
551
551
|
*
|
|
552
552
|
* @returns The serialized BEEF structure
|
|
553
553
|
*/
|
|
554
|
-
toBEEF(): number[] {
|
|
554
|
+
toBEEF (): number[] {
|
|
555
555
|
const writer = new Writer()
|
|
556
556
|
writer.writeUInt32LE(4022206465)
|
|
557
557
|
const BUMPs: MerklePath[] = []
|