@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
|
@@ -11,7 +11,7 @@ export default class BigNumber {
|
|
|
11
11
|
/**
|
|
12
12
|
* @privateinitializer
|
|
13
13
|
*/
|
|
14
|
-
static zeros: string[] = [
|
|
14
|
+
public static readonly zeros: string[] = [
|
|
15
15
|
'',
|
|
16
16
|
'0',
|
|
17
17
|
'00',
|
|
@@ -43,7 +43,7 @@ export default class BigNumber {
|
|
|
43
43
|
/**
|
|
44
44
|
* @privateinitializer
|
|
45
45
|
*/
|
|
46
|
-
static groupSizes: number[] = [
|
|
46
|
+
static readonly groupSizes: number[] = [
|
|
47
47
|
0, 0,
|
|
48
48
|
25, 16, 12, 11, 10, 9, 8,
|
|
49
49
|
8, 7, 7, 7, 7, 6, 6,
|
|
@@ -55,7 +55,7 @@ export default class BigNumber {
|
|
|
55
55
|
/**
|
|
56
56
|
* @privateinitializer
|
|
57
57
|
*/
|
|
58
|
-
static groupBases: number[] = [
|
|
58
|
+
static readonly groupBases: number[] = [
|
|
59
59
|
0, 0,
|
|
60
60
|
33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
|
|
61
61
|
43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
|
|
@@ -72,7 +72,7 @@ export default class BigNumber {
|
|
|
72
72
|
* @example
|
|
73
73
|
* console.log(BigNumber.wordSize); // output: 26
|
|
74
74
|
*/
|
|
75
|
-
static wordSize: number = 26
|
|
75
|
+
static readonly wordSize: number = 26
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Negative flag. Indicates whether the big number is a negative number.
|
|
@@ -208,11 +208,13 @@ export default class BigNumber {
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
if (typeof number === 'number') {
|
|
211
|
-
|
|
211
|
+
this.initNumber(number, base, endian)
|
|
212
|
+
return
|
|
212
213
|
}
|
|
213
214
|
|
|
214
215
|
if (typeof number === 'object') {
|
|
215
|
-
|
|
216
|
+
this.initArray(number, endian)
|
|
217
|
+
return
|
|
216
218
|
}
|
|
217
219
|
|
|
218
220
|
if (base === 'hex') {
|
|
@@ -222,7 +224,7 @@ export default class BigNumber {
|
|
|
222
224
|
|
|
223
225
|
number = number.toString().replace(/\s+/g, '')
|
|
224
226
|
let start = 0
|
|
225
|
-
if (number
|
|
227
|
+
if (number.startsWith('-')) {
|
|
226
228
|
start++
|
|
227
229
|
this.negative = 1
|
|
228
230
|
}
|
|
@@ -263,7 +265,7 @@ export default class BigNumber {
|
|
|
263
265
|
* @param endian - The endianness ('be' for big-endian, 'le' for little-endian).
|
|
264
266
|
* @returns The current BigNumber instance.
|
|
265
267
|
*/
|
|
266
|
-
private initNumber (number, base, endian):
|
|
268
|
+
private initNumber (number, base, endian): this {
|
|
267
269
|
if (number < 0) {
|
|
268
270
|
this.negative = 1
|
|
269
271
|
number = -number
|
|
@@ -279,7 +281,7 @@ export default class BigNumber {
|
|
|
279
281
|
this.length = 2
|
|
280
282
|
} else {
|
|
281
283
|
this.assert(
|
|
282
|
-
number
|
|
284
|
+
number <= 0x1FFFFFFFFFFFFF,
|
|
283
285
|
'The number is larger than 2 ^ 53 (unsafe)'
|
|
284
286
|
)
|
|
285
287
|
this.words = [
|
|
@@ -408,44 +410,35 @@ export default class BigNumber {
|
|
|
408
410
|
* @param endian - The endianness ('be', 'le').
|
|
409
411
|
* @return The current BigNumber instance.
|
|
410
412
|
*/
|
|
411
|
-
private parseHex (number: string, start: number, endian): BigNumber {
|
|
412
|
-
//
|
|
413
|
+
private parseHex (number: string, start: number, endian: 'be' | 'le'): BigNumber {
|
|
414
|
+
// Initialize the words array
|
|
413
415
|
this.length = Math.ceil((number.length - start) / 6)
|
|
414
|
-
this.words = new Array(this.length)
|
|
415
|
-
let i = 0
|
|
416
|
-
for (; i < this.length; i++) {
|
|
417
|
-
this.words[i] = 0
|
|
418
|
-
}
|
|
416
|
+
this.words = new Array(this.length).fill(0)
|
|
419
417
|
|
|
420
418
|
// 24-bits chunks
|
|
421
419
|
let off = 0
|
|
422
420
|
let j = 0
|
|
423
421
|
|
|
424
|
-
|
|
422
|
+
const processHexByte = (i: number): void => {
|
|
423
|
+
const w = this.parseHexByte(number, start, i) << off
|
|
424
|
+
this.words[j] |= w & 0x3ffffff
|
|
425
|
+
if (off >= 18) {
|
|
426
|
+
off -= 18
|
|
427
|
+
j += 1
|
|
428
|
+
this.words[j] |= w >>> 26
|
|
429
|
+
} else {
|
|
430
|
+
off += 8
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
425
434
|
if (endian === 'be') {
|
|
426
|
-
for (i = number.length - 1; i >= start; i -= 2) {
|
|
427
|
-
|
|
428
|
-
this.words[j] |= w & 0x3ffffff
|
|
429
|
-
if (off >= 18) {
|
|
430
|
-
off -= 18
|
|
431
|
-
j += 1
|
|
432
|
-
this.words[j] |= w >>> 26
|
|
433
|
-
} else {
|
|
434
|
-
off += 8
|
|
435
|
-
}
|
|
435
|
+
for (let i = number.length - 1; i >= start; i -= 2) {
|
|
436
|
+
processHexByte(i)
|
|
436
437
|
}
|
|
437
438
|
} else {
|
|
438
439
|
const parseLength = number.length - start
|
|
439
|
-
for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
|
|
440
|
-
|
|
441
|
-
this.words[j] |= w & 0x3ffffff
|
|
442
|
-
if (off >= 18) {
|
|
443
|
-
off -= 18
|
|
444
|
-
j += 1
|
|
445
|
-
this.words[j] |= w >>> 26
|
|
446
|
-
} else {
|
|
447
|
-
off += 8
|
|
448
|
-
}
|
|
440
|
+
for (let i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
|
|
441
|
+
processHexByte(i)
|
|
449
442
|
}
|
|
450
443
|
}
|
|
451
444
|
|
|
@@ -613,14 +606,14 @@ export default class BigNumber {
|
|
|
613
606
|
* Increases the BigNumber length up to a certain size and initializes new elements with 0.
|
|
614
607
|
*
|
|
615
608
|
* @method expand
|
|
616
|
-
* @param size - The desired size to grow the BigNumber length.
|
|
609
|
+
* @param {number} size - The desired size to grow the BigNumber length.
|
|
617
610
|
* @returns The BigNumber instance after expansion.
|
|
618
611
|
*
|
|
619
612
|
* @example
|
|
620
613
|
* const bn = new BigNumber('123456', 10, 'be');
|
|
621
614
|
* bn.expand(10);
|
|
622
615
|
*/
|
|
623
|
-
expand (size):
|
|
616
|
+
expand (size: number): this {
|
|
624
617
|
while (this.length < size) {
|
|
625
618
|
this.words[this.length++] = 0
|
|
626
619
|
}
|
|
@@ -638,7 +631,7 @@ export default class BigNumber {
|
|
|
638
631
|
* bn.strip();
|
|
639
632
|
* // bn now represents 0
|
|
640
633
|
*/
|
|
641
|
-
strip ():
|
|
634
|
+
strip (): this {
|
|
642
635
|
while (this.length > 1 && this.words[this.length - 1] === 0) {
|
|
643
636
|
this.length--
|
|
644
637
|
}
|
|
@@ -655,7 +648,7 @@ export default class BigNumber {
|
|
|
655
648
|
* const bn = new BigNumber('-0', 10, 'be');
|
|
656
649
|
* bn.normSign();
|
|
657
650
|
*/
|
|
658
|
-
normSign ():
|
|
651
|
+
normSign (): this {
|
|
659
652
|
// -0 = 0
|
|
660
653
|
if (this.length === 1 && this.words[0] === 0) {
|
|
661
654
|
this.negative = 0
|
|
@@ -691,70 +684,77 @@ export default class BigNumber {
|
|
|
691
684
|
* bn.toString(16); // Converts the BigNumber to a hexadecimal string.
|
|
692
685
|
*/
|
|
693
686
|
toString (base: number | 'hex' = 10, padding: number = 1): string {
|
|
694
|
-
let out: string
|
|
695
687
|
if (base === 16 || base === 'hex') {
|
|
696
|
-
|
|
697
|
-
let off = 0
|
|
698
|
-
let carry = 0
|
|
699
|
-
for (let i = 0; i < this.length; i++) {
|
|
700
|
-
const w = this.words[i]
|
|
701
|
-
const word = (((w << off) | carry) & 0xffffff).toString(16)
|
|
702
|
-
carry = (w >>> (24 - off)) & 0xffffff
|
|
703
|
-
off += 2
|
|
704
|
-
if (off >= 26) {
|
|
705
|
-
off -= 26
|
|
706
|
-
i--
|
|
707
|
-
}
|
|
708
|
-
if (carry !== 0 || i !== this.length - 1) {
|
|
709
|
-
out = BigNumber.zeros[6 - word.length] + word + out
|
|
710
|
-
} else {
|
|
711
|
-
out = word + out
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
if (carry !== 0) {
|
|
715
|
-
out = carry.toString(16) + out
|
|
716
|
-
}
|
|
717
|
-
if (padding === 0 && out === '0') {
|
|
718
|
-
return ''
|
|
719
|
-
}
|
|
720
|
-
while (out.length % padding !== 0 && padding !== 0) {
|
|
721
|
-
out = '0' + out
|
|
722
|
-
}
|
|
723
|
-
if (this.negative !== 0) {
|
|
724
|
-
out = '-' + out
|
|
725
|
-
}
|
|
726
|
-
return out
|
|
688
|
+
return this.toHexString(padding)
|
|
727
689
|
}
|
|
728
690
|
|
|
729
691
|
if (base === (base | 0) && base >= 2 && base <= 36) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
if (
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
while (out.length % padding !== 0) {
|
|
749
|
-
out = '0' + out
|
|
692
|
+
return this.toBaseString(base, padding)
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
throw new Error('Base should be between 2 and 36')
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
private toHexString (padding: number): string {
|
|
699
|
+
let out = ''
|
|
700
|
+
let off = 0
|
|
701
|
+
let carry = 0
|
|
702
|
+
for (let i = 0; i < this.length; i++) {
|
|
703
|
+
const w = this.words[i]
|
|
704
|
+
const word = (((w << off) | carry) & 0xffffff).toString(16)
|
|
705
|
+
carry = (w >>> (24 - off)) & 0xffffff
|
|
706
|
+
off += 2
|
|
707
|
+
if (off >= 26) {
|
|
708
|
+
off -= 26
|
|
709
|
+
i--
|
|
750
710
|
}
|
|
751
|
-
if (this.
|
|
752
|
-
out =
|
|
711
|
+
if (carry !== 0 || i !== this.length - 1) {
|
|
712
|
+
out = BigNumber.zeros[6 - word.length] + word + out
|
|
713
|
+
} else {
|
|
714
|
+
out = word + out
|
|
753
715
|
}
|
|
754
|
-
return out
|
|
755
716
|
}
|
|
717
|
+
if (carry !== 0) {
|
|
718
|
+
out = carry.toString(16) + out
|
|
719
|
+
}
|
|
720
|
+
if (padding === 0 && out === '0') {
|
|
721
|
+
return ''
|
|
722
|
+
}
|
|
723
|
+
while (out.length % padding !== 0 && padding !== 0) {
|
|
724
|
+
out = '0' + out
|
|
725
|
+
}
|
|
726
|
+
if (this.negative !== 0) {
|
|
727
|
+
out = '-' + out
|
|
728
|
+
}
|
|
729
|
+
return out
|
|
730
|
+
}
|
|
756
731
|
|
|
757
|
-
|
|
732
|
+
private toBaseString (base: number, padding: number): string {
|
|
733
|
+
const groupSize = BigNumber.groupSizes[base]
|
|
734
|
+
const groupBase = BigNumber.groupBases[base]
|
|
735
|
+
let out = ''
|
|
736
|
+
let c = this.clone()
|
|
737
|
+
c.negative = 0
|
|
738
|
+
while (!c.isZero()) {
|
|
739
|
+
const r = c.modrn(groupBase).toString(base)
|
|
740
|
+
c = c.idivn(groupBase)
|
|
741
|
+
|
|
742
|
+
if (!c.isZero()) {
|
|
743
|
+
out = BigNumber.zeros[groupSize - r.length] + r + out
|
|
744
|
+
} else {
|
|
745
|
+
out = r + out
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
if (this.isZero()) {
|
|
749
|
+
out = '0' + out
|
|
750
|
+
}
|
|
751
|
+
while (out.length % padding !== 0) {
|
|
752
|
+
out = '0' + out
|
|
753
|
+
}
|
|
754
|
+
if (this.negative !== 0) {
|
|
755
|
+
out = '-' + out
|
|
756
|
+
}
|
|
757
|
+
return out
|
|
758
758
|
}
|
|
759
759
|
|
|
760
760
|
/**
|
|
@@ -1336,7 +1336,7 @@ export default class BigNumber {
|
|
|
1336
1336
|
* const num2 = new BigNumber('20');
|
|
1337
1337
|
* console.log(num1.iuxor(num2).toString());
|
|
1338
1338
|
*/
|
|
1339
|
-
iuxor (num: BigNumber):
|
|
1339
|
+
iuxor (num: BigNumber): this {
|
|
1340
1340
|
if (this.length > num.length) {
|
|
1341
1341
|
for (let i = 0; i < num.length; i++) {
|
|
1342
1342
|
this.words[i] = this.words[i] ^ num.words[i]
|
|
@@ -1368,7 +1368,7 @@ export default class BigNumber {
|
|
|
1368
1368
|
* const num2 = new BigNumber('20');
|
|
1369
1369
|
* console.log(num1.ixor(num2).toString());
|
|
1370
1370
|
*/
|
|
1371
|
-
ixor (num: BigNumber):
|
|
1371
|
+
ixor (num: BigNumber): this {
|
|
1372
1372
|
this.assert(
|
|
1373
1373
|
(this.negative | num.negative) === 0,
|
|
1374
1374
|
'Neither number can be negative'
|
|
@@ -1484,7 +1484,7 @@ export default class BigNumber {
|
|
|
1484
1484
|
* num.setn(2, 1);
|
|
1485
1485
|
* console.log(num.toString());
|
|
1486
1486
|
*/
|
|
1487
|
-
setn (bit: number, val: 0 | 1 | true | false):
|
|
1487
|
+
setn (bit: number, val: 0 | 1 | true | false): this {
|
|
1488
1488
|
this.assert(typeof bit === 'number' && bit >= 0)
|
|
1489
1489
|
|
|
1490
1490
|
const off = (bit / 26) | 0
|
|
@@ -1513,7 +1513,7 @@ export default class BigNumber {
|
|
|
1513
1513
|
* num1.iadd(new BigNumber('20'));
|
|
1514
1514
|
* console.log(num1.toString());
|
|
1515
1515
|
*/
|
|
1516
|
-
iadd (num: BigNumber):
|
|
1516
|
+
iadd (num: BigNumber): this {
|
|
1517
1517
|
let r
|
|
1518
1518
|
|
|
1519
1519
|
// negative + positive
|
|
@@ -2551,7 +2551,7 @@ export default class BigNumber {
|
|
|
2551
2551
|
* let myNumber = new BigNumber(4);
|
|
2552
2552
|
* myNumber.iushln(2); // Returns BigNumber of value 16
|
|
2553
2553
|
*/
|
|
2554
|
-
iushln (bits: number):
|
|
2554
|
+
iushln (bits: number): this {
|
|
2555
2555
|
this.assert(typeof bits === 'number' && bits >= 0)
|
|
2556
2556
|
const r = bits % 26
|
|
2557
2557
|
const s = (bits - r) / 26
|
|
@@ -2600,7 +2600,7 @@ export default class BigNumber {
|
|
|
2600
2600
|
* let myNumber = new BigNumber(4);
|
|
2601
2601
|
* myNumber.ishln(2); // Returns BigNumber of value 16
|
|
2602
2602
|
*/
|
|
2603
|
-
ishln (bits: number):
|
|
2603
|
+
ishln (bits: number): this {
|
|
2604
2604
|
this.assert(this.negative === 0)
|
|
2605
2605
|
return this.iushln(bits)
|
|
2606
2606
|
}
|
|
@@ -2618,7 +2618,7 @@ export default class BigNumber {
|
|
|
2618
2618
|
* let myNumber = new BigNumber(16);
|
|
2619
2619
|
* myNumber.iushrn(2); // Returns BigNumber of value 4
|
|
2620
2620
|
*/
|
|
2621
|
-
iushrn (bits: number, hint?: number, extended?: BigNumber):
|
|
2621
|
+
iushrn (bits: number, hint?: number, extended?: BigNumber): this {
|
|
2622
2622
|
this.assert(typeof bits === 'number' && bits >= 0)
|
|
2623
2623
|
let h
|
|
2624
2624
|
if (typeof hint === 'number' && hint !== 0) {
|
|
@@ -2689,7 +2689,7 @@ export default class BigNumber {
|
|
|
2689
2689
|
* let myNumber = new BigNumber(16);
|
|
2690
2690
|
* myNumber.ishrn(2); // Returns BigNumber of value 4
|
|
2691
2691
|
*/
|
|
2692
|
-
ishrn (bits, hint?, extended?):
|
|
2692
|
+
ishrn (bits, hint?, extended?): this {
|
|
2693
2693
|
this.assert(this.negative === 0)
|
|
2694
2694
|
return this.iushrn(bits, hint, extended)
|
|
2695
2695
|
}
|
|
@@ -2795,7 +2795,7 @@ export default class BigNumber {
|
|
|
2795
2795
|
* const myNumber = new BigNumber(52);
|
|
2796
2796
|
* myNumber.imaskn(2); // myNumber becomes 0 because lower 2 bits of 52 (110100) are 00.
|
|
2797
2797
|
*/
|
|
2798
|
-
imaskn (bits):
|
|
2798
|
+
imaskn (bits): this {
|
|
2799
2799
|
this.assert(typeof bits === 'number' && bits >= 0)
|
|
2800
2800
|
const r = bits % 26
|
|
2801
2801
|
let s = (bits - r) / 26
|
|
@@ -2872,7 +2872,7 @@ export default class BigNumber {
|
|
|
2872
2872
|
* @param num - The plain number to add.
|
|
2873
2873
|
* @returns Returns the BigNumber after the addition.
|
|
2874
2874
|
*/
|
|
2875
|
-
_iaddn (num: number):
|
|
2875
|
+
_iaddn (num: number): this {
|
|
2876
2876
|
this.words[0] += num
|
|
2877
2877
|
|
|
2878
2878
|
// Carry
|
|
@@ -2962,7 +2962,7 @@ export default class BigNumber {
|
|
|
2962
2962
|
* const myNumber = new BigNumber(-50);
|
|
2963
2963
|
* myNumber.iabs(); // myNumber becomes 50.
|
|
2964
2964
|
*/
|
|
2965
|
-
iabs ():
|
|
2965
|
+
iabs (): this {
|
|
2966
2966
|
this.negative = 0
|
|
2967
2967
|
return this
|
|
2968
2968
|
}
|
|
@@ -2998,7 +2998,7 @@ export default class BigNumber {
|
|
|
2998
2998
|
* number._ishlnsubmul(new BigNumber(2), 3, 1);
|
|
2999
2999
|
* console.log(number.toString()); // Outputs result after performing operations
|
|
3000
3000
|
*/
|
|
3001
|
-
_ishlnsubmul (num: BigNumber, mul, shift: number):
|
|
3001
|
+
_ishlnsubmul (num: BigNumber, mul, shift: number): this {
|
|
3002
3002
|
const len = num.length + shift
|
|
3003
3003
|
let i: number
|
|
3004
3004
|
|
|
@@ -3692,7 +3692,7 @@ export default class BigNumber {
|
|
|
3692
3692
|
* let a = new BigNumber(5);
|
|
3693
3693
|
* a.bincn(2); // a = 7
|
|
3694
3694
|
*/
|
|
3695
|
-
bincn (bit: number):
|
|
3695
|
+
bincn (bit: number): this {
|
|
3696
3696
|
this.assert(typeof bit === 'number')
|
|
3697
3697
|
const r = bit % 26
|
|
3698
3698
|
const s = (bit - r) / 26
|
|
@@ -4037,7 +4037,7 @@ export default class BigNumber {
|
|
|
4037
4037
|
* let redCtx = new ReductionContext();
|
|
4038
4038
|
* bigNum.forceRed(redCtx);
|
|
4039
4039
|
*/
|
|
4040
|
-
forceRed (ctx: ReductionContext):
|
|
4040
|
+
forceRed (ctx: ReductionContext): this {
|
|
4041
4041
|
// this.assert(this.red == null, 'Already a number in reduction context')
|
|
4042
4042
|
this.red = ctx
|
|
4043
4043
|
return this
|
|
@@ -235,9 +235,12 @@ export default class PublicKey extends Point {
|
|
|
235
235
|
throw new Error('Invalid Compact Byte')
|
|
236
236
|
}
|
|
237
237
|
let r = data[0] - 27
|
|
238
|
-
|
|
238
|
+
// NOTE: We don't use uncompressed pubkeys in this library,
|
|
239
|
+
// but whether the key is compressed is captured in the recovery param.
|
|
240
|
+
// Code below is commented out for reference of how you could capture this.
|
|
241
|
+
// let compressed = false
|
|
239
242
|
if (r > 3) {
|
|
240
|
-
compressed = true
|
|
243
|
+
// compressed = true
|
|
241
244
|
r -= 4
|
|
242
245
|
}
|
|
243
246
|
const s = new Signature(
|
package/src/primitives/Random.ts
CHANGED
|
@@ -6,7 +6,7 @@ class Rand {
|
|
|
6
6
|
}
|
|
7
7
|
if (typeof self === 'object') {
|
|
8
8
|
/* eslint-disable-next-line */
|
|
9
|
-
if (self.crypto
|
|
9
|
+
if (self.crypto?.getRandomValues) {
|
|
10
10
|
this._rand = n => {
|
|
11
11
|
const arr = new Uint8Array(n)
|
|
12
12
|
/* eslint-disable-next-line */
|
|
@@ -21,7 +21,7 @@ class Rand {
|
|
|
21
21
|
/* eslint-disable-next-line */
|
|
22
22
|
const crypto = require('crypto')
|
|
23
23
|
if (typeof crypto.randomBytes === 'function') {
|
|
24
|
-
this._rand = n => [...crypto.randomBytes(n)]
|
|
24
|
+
this._rand = (n: number) => [...crypto.randomBytes(n)]
|
|
25
25
|
}
|
|
26
26
|
} catch (e) {
|
|
27
27
|
this._rand = noRand
|