@bsv/sdk 1.2.17 → 1.2.19
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/primitives/BigNumber.js +85 -89
- package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
- package/dist/cjs/src/primitives/PublicKey.js +5 -2
- package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
- package/dist/cjs/src/primitives/Random.js +3 -2
- package/dist/cjs/src/primitives/Random.js.map +1 -1
- package/dist/cjs/src/primitives/utils.js +71 -62
- package/dist/cjs/src/primitives/utils.js.map +1 -1
- package/dist/cjs/src/totp/totp.js +0 -1
- package/dist/cjs/src/totp/totp.js.map +1 -1
- package/dist/cjs/src/transaction/Beef.js +26 -40
- package/dist/cjs/src/transaction/Beef.js.map +1 -1
- package/dist/cjs/src/transaction/BeefParty.js +1 -1
- package/dist/cjs/src/transaction/BeefTx.js +75 -73
- package/dist/cjs/src/transaction/BeefTx.js.map +1 -1
- package/dist/cjs/src/transaction/MerklePath.js +12 -1
- package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
- package/dist/cjs/src/transaction/Transaction.js +70 -96
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js +20 -2
- package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/primitives/BigNumber.js +85 -89
- package/dist/esm/src/primitives/BigNumber.js.map +1 -1
- package/dist/esm/src/primitives/PublicKey.js +5 -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/utils.js +70 -61
- package/dist/esm/src/primitives/utils.js.map +1 -1
- package/dist/esm/src/totp/totp.js +0 -1
- package/dist/esm/src/totp/totp.js.map +1 -1
- package/dist/esm/src/transaction/Beef.js +25 -39
- package/dist/esm/src/transaction/Beef.js.map +1 -1
- package/dist/esm/src/transaction/BeefParty.js +1 -1
- package/dist/esm/src/transaction/BeefTx.js +76 -74
- package/dist/esm/src/transaction/BeefTx.js.map +1 -1
- package/dist/esm/src/transaction/MerklePath.js +12 -1
- package/dist/esm/src/transaction/MerklePath.js.map +1 -1
- package/dist/esm/src/transaction/Transaction.js +71 -97
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js +20 -2
- package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/primitives/BigNumber.d.ts +24 -22
- package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
- package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
- package/dist/types/src/primitives/utils.d.ts +17 -17
- package/dist/types/src/primitives/utils.d.ts.map +1 -1
- package/dist/types/src/transaction/Beef.d.ts +9 -12
- package/dist/types/src/transaction/Beef.d.ts.map +1 -1
- package/dist/types/src/transaction/BeefParty.d.ts +1 -1
- package/dist/types/src/transaction/BeefTx.d.ts +5 -2
- package/dist/types/src/transaction/BeefTx.d.ts.map +1 -1
- package/dist/types/src/transaction/ChainTracker.d.ts +6 -0
- package/dist/types/src/transaction/ChainTracker.d.ts.map +1 -1
- package/dist/types/src/transaction/MerklePath.d.ts +1 -0
- package/dist/types/src/transaction/MerklePath.d.ts.map +1 -1
- package/dist/types/src/transaction/Transaction.d.ts +6 -0
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
- package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts +2 -1
- package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/compat.md +13 -11
- package/docs/primitives.md +152 -188
- package/docs/transaction.md +78 -76
- package/package.json +1 -1
- package/src/primitives/BigNumber.ts +111 -111
- package/src/primitives/PublicKey.ts +5 -2
- package/src/primitives/Random.ts +2 -2
- package/src/primitives/utils.ts +92 -77
- package/src/totp/totp.ts +0 -1
- package/src/transaction/Beef.ts +20 -43
- package/src/transaction/BeefParty.ts +1 -1
- package/src/transaction/BeefTx.ts +89 -57
- package/src/transaction/ChainTracker.ts +6 -0
- package/src/transaction/MerklePath.ts +13 -1
- package/src/transaction/Transaction.ts +77 -100
- package/src/transaction/__tests/Beef.test.ts +9 -9
- package/src/transaction/__tests/MerklePath.test.ts +23 -2
- package/src/transaction/__tests/Transaction.benchmarks.test.ts +1 -1
- package/src/transaction/__tests/Transaction.test.ts +3 -3
- package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +2 -2
- package/src/transaction/chaintrackers/WhatsOnChain.ts +20 -2
- package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +32 -1
|
@@ -189,10 +189,12 @@ export default class BigNumber {
|
|
|
189
189
|
base = 10;
|
|
190
190
|
}
|
|
191
191
|
if (typeof number === 'number') {
|
|
192
|
-
|
|
192
|
+
this.initNumber(number, base, endian);
|
|
193
|
+
return;
|
|
193
194
|
}
|
|
194
195
|
if (typeof number === 'object') {
|
|
195
|
-
|
|
196
|
+
this.initArray(number, endian);
|
|
197
|
+
return;
|
|
196
198
|
}
|
|
197
199
|
if (base === 'hex') {
|
|
198
200
|
base = 16;
|
|
@@ -200,7 +202,7 @@ export default class BigNumber {
|
|
|
200
202
|
this.assert(base === (base | 0) && base >= 2 && base <= 36);
|
|
201
203
|
number = number.toString().replace(/\s+/g, '');
|
|
202
204
|
let start = 0;
|
|
203
|
-
if (number
|
|
205
|
+
if (number.startsWith('-')) {
|
|
204
206
|
start++;
|
|
205
207
|
this.negative = 1;
|
|
206
208
|
}
|
|
@@ -257,7 +259,7 @@ export default class BigNumber {
|
|
|
257
259
|
this.length = 2;
|
|
258
260
|
}
|
|
259
261
|
else {
|
|
260
|
-
this.assert(number
|
|
262
|
+
this.assert(number <= 0x1FFFFFFFFFFFFF, 'The number is larger than 2 ^ 53 (unsafe)');
|
|
261
263
|
this.words = [
|
|
262
264
|
number & 0x3ffffff,
|
|
263
265
|
(number / 0x4000000) & 0x3ffffff,
|
|
@@ -377,44 +379,33 @@ export default class BigNumber {
|
|
|
377
379
|
* @return The current BigNumber instance.
|
|
378
380
|
*/
|
|
379
381
|
parseHex(number, start, endian) {
|
|
380
|
-
//
|
|
382
|
+
// Initialize the words array
|
|
381
383
|
this.length = Math.ceil((number.length - start) / 6);
|
|
382
|
-
this.words = new Array(this.length);
|
|
383
|
-
let i = 0;
|
|
384
|
-
for (; i < this.length; i++) {
|
|
385
|
-
this.words[i] = 0;
|
|
386
|
-
}
|
|
384
|
+
this.words = new Array(this.length).fill(0);
|
|
387
385
|
// 24-bits chunks
|
|
388
386
|
let off = 0;
|
|
389
387
|
let j = 0;
|
|
390
|
-
|
|
388
|
+
const processHexByte = (i) => {
|
|
389
|
+
const w = this.parseHexByte(number, start, i) << off;
|
|
390
|
+
this.words[j] |= w & 0x3ffffff;
|
|
391
|
+
if (off >= 18) {
|
|
392
|
+
off -= 18;
|
|
393
|
+
j += 1;
|
|
394
|
+
this.words[j] |= w >>> 26;
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
off += 8;
|
|
398
|
+
}
|
|
399
|
+
};
|
|
391
400
|
if (endian === 'be') {
|
|
392
|
-
for (i = number.length - 1; i >= start; i -= 2) {
|
|
393
|
-
|
|
394
|
-
this.words[j] |= w & 0x3ffffff;
|
|
395
|
-
if (off >= 18) {
|
|
396
|
-
off -= 18;
|
|
397
|
-
j += 1;
|
|
398
|
-
this.words[j] |= w >>> 26;
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
off += 8;
|
|
402
|
-
}
|
|
401
|
+
for (let i = number.length - 1; i >= start; i -= 2) {
|
|
402
|
+
processHexByte(i);
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
else {
|
|
406
406
|
const parseLength = number.length - start;
|
|
407
|
-
for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
|
|
408
|
-
|
|
409
|
-
this.words[j] |= w & 0x3ffffff;
|
|
410
|
-
if (off >= 18) {
|
|
411
|
-
off -= 18;
|
|
412
|
-
j += 1;
|
|
413
|
-
this.words[j] |= w >>> 26;
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
off += 8;
|
|
417
|
-
}
|
|
407
|
+
for (let i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
|
|
408
|
+
processHexByte(i);
|
|
418
409
|
}
|
|
419
410
|
}
|
|
420
411
|
return this.strip();
|
|
@@ -567,7 +558,7 @@ export default class BigNumber {
|
|
|
567
558
|
* Increases the BigNumber length up to a certain size and initializes new elements with 0.
|
|
568
559
|
*
|
|
569
560
|
* @method expand
|
|
570
|
-
* @param size - The desired size to grow the BigNumber length.
|
|
561
|
+
* @param {number} size - The desired size to grow the BigNumber length.
|
|
571
562
|
* @returns The BigNumber instance after expansion.
|
|
572
563
|
*
|
|
573
564
|
* @example
|
|
@@ -641,69 +632,74 @@ export default class BigNumber {
|
|
|
641
632
|
* bn.toString(16); // Converts the BigNumber to a hexadecimal string.
|
|
642
633
|
*/
|
|
643
634
|
toString(base = 10, padding = 1) {
|
|
644
|
-
let out;
|
|
645
635
|
if (base === 16 || base === 'hex') {
|
|
646
|
-
|
|
647
|
-
let off = 0;
|
|
648
|
-
let carry = 0;
|
|
649
|
-
for (let i = 0; i < this.length; i++) {
|
|
650
|
-
const w = this.words[i];
|
|
651
|
-
const word = (((w << off) | carry) & 0xffffff).toString(16);
|
|
652
|
-
carry = (w >>> (24 - off)) & 0xffffff;
|
|
653
|
-
off += 2;
|
|
654
|
-
if (off >= 26) {
|
|
655
|
-
off -= 26;
|
|
656
|
-
i--;
|
|
657
|
-
}
|
|
658
|
-
if (carry !== 0 || i !== this.length - 1) {
|
|
659
|
-
out = BigNumber.zeros[6 - word.length] + word + out;
|
|
660
|
-
}
|
|
661
|
-
else {
|
|
662
|
-
out = word + out;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
if (carry !== 0) {
|
|
666
|
-
out = carry.toString(16) + out;
|
|
667
|
-
}
|
|
668
|
-
if (padding === 0 && out === '0') {
|
|
669
|
-
return '';
|
|
670
|
-
}
|
|
671
|
-
while (out.length % padding !== 0 && padding !== 0) {
|
|
672
|
-
out = '0' + out;
|
|
673
|
-
}
|
|
674
|
-
if (this.negative !== 0) {
|
|
675
|
-
out = '-' + out;
|
|
676
|
-
}
|
|
677
|
-
return out;
|
|
636
|
+
return this.toHexString(padding);
|
|
678
637
|
}
|
|
679
638
|
if (base === (base | 0) && base >= 2 && base <= 36) {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
639
|
+
return this.toBaseString(base, padding);
|
|
640
|
+
}
|
|
641
|
+
throw new Error('Base should be between 2 and 36');
|
|
642
|
+
}
|
|
643
|
+
toHexString(padding) {
|
|
644
|
+
let out = '';
|
|
645
|
+
let off = 0;
|
|
646
|
+
let carry = 0;
|
|
647
|
+
for (let i = 0; i < this.length; i++) {
|
|
648
|
+
const w = this.words[i];
|
|
649
|
+
const word = (((w << off) | carry) & 0xffffff).toString(16);
|
|
650
|
+
carry = (w >>> (24 - off)) & 0xffffff;
|
|
651
|
+
off += 2;
|
|
652
|
+
if (off >= 26) {
|
|
653
|
+
off -= 26;
|
|
654
|
+
i--;
|
|
694
655
|
}
|
|
695
|
-
if (this.
|
|
696
|
-
out =
|
|
656
|
+
if (carry !== 0 || i !== this.length - 1) {
|
|
657
|
+
out = BigNumber.zeros[6 - word.length] + word + out;
|
|
697
658
|
}
|
|
698
|
-
|
|
699
|
-
out =
|
|
659
|
+
else {
|
|
660
|
+
out = word + out;
|
|
700
661
|
}
|
|
701
|
-
|
|
702
|
-
|
|
662
|
+
}
|
|
663
|
+
if (carry !== 0) {
|
|
664
|
+
out = carry.toString(16) + out;
|
|
665
|
+
}
|
|
666
|
+
if (padding === 0 && out === '0') {
|
|
667
|
+
return '';
|
|
668
|
+
}
|
|
669
|
+
while (out.length % padding !== 0 && padding !== 0) {
|
|
670
|
+
out = '0' + out;
|
|
671
|
+
}
|
|
672
|
+
if (this.negative !== 0) {
|
|
673
|
+
out = '-' + out;
|
|
674
|
+
}
|
|
675
|
+
return out;
|
|
676
|
+
}
|
|
677
|
+
toBaseString(base, padding) {
|
|
678
|
+
const groupSize = BigNumber.groupSizes[base];
|
|
679
|
+
const groupBase = BigNumber.groupBases[base];
|
|
680
|
+
let out = '';
|
|
681
|
+
let c = this.clone();
|
|
682
|
+
c.negative = 0;
|
|
683
|
+
while (!c.isZero()) {
|
|
684
|
+
const r = c.modrn(groupBase).toString(base);
|
|
685
|
+
c = c.idivn(groupBase);
|
|
686
|
+
if (!c.isZero()) {
|
|
687
|
+
out = BigNumber.zeros[groupSize - r.length] + r + out;
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
out = r + out;
|
|
703
691
|
}
|
|
704
|
-
return out;
|
|
705
692
|
}
|
|
706
|
-
|
|
693
|
+
if (this.isZero()) {
|
|
694
|
+
out = '0' + out;
|
|
695
|
+
}
|
|
696
|
+
while (out.length % padding !== 0) {
|
|
697
|
+
out = '0' + out;
|
|
698
|
+
}
|
|
699
|
+
if (this.negative !== 0) {
|
|
700
|
+
out = '-' + out;
|
|
701
|
+
}
|
|
702
|
+
return out;
|
|
707
703
|
}
|
|
708
704
|
/**
|
|
709
705
|
* Converts the BigNumber instance to a JavaScript number.
|