cafe-utility 27.11.0 → 27.12.1
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/index.d.ts +4 -3
- package/index.js +39 -31
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -583,16 +583,17 @@ export declare class FixedPointNumber {
|
|
|
583
583
|
value: bigint;
|
|
584
584
|
scale: number;
|
|
585
585
|
constructor(value: bigint | string | number, scale: number);
|
|
586
|
-
static fromDecimalString(
|
|
586
|
+
static fromDecimalString(decimalString: string, scale: number): FixedPointNumber;
|
|
587
587
|
add(other: FixedPointNumber): FixedPointNumber;
|
|
588
588
|
subtract(other: FixedPointNumber): FixedPointNumber;
|
|
589
589
|
multiply(factor: bigint): FixedPointNumber;
|
|
590
|
-
|
|
590
|
+
divmod(divisor: bigint): [FixedPointNumber, FixedPointNumber];
|
|
591
|
+
exchange(direction: '*' | '/', rate: FixedPointNumber, targetScale: number): FixedPointNumber;
|
|
591
592
|
compare(other: FixedPointNumber): 1 | 0 | -1;
|
|
592
593
|
toDecimalString(): string;
|
|
593
594
|
toString(): string;
|
|
594
595
|
toJSON(): string;
|
|
595
|
-
|
|
596
|
+
assertSameScale(other: FixedPointNumber): void;
|
|
596
597
|
}
|
|
597
598
|
type Playbook<T> = {
|
|
598
599
|
ttl: number;
|
package/index.js
CHANGED
|
@@ -2315,16 +2315,16 @@ function keccakPermutate(n) {
|
|
|
2315
2315
|
T = (n[5] << 30) | (n[4] >>> 2),
|
|
2316
2316
|
S = (n[4] << 30) | (n[5] >>> 2),
|
|
2317
2317
|
R = (n[6] << 28) | (n[7] >>> 4),
|
|
2318
|
-
|
|
2319
|
-
|
|
2318
|
+
D = (n[7] << 28) | (n[6] >>> 4),
|
|
2319
|
+
C = (n[8] << 27) | (n[9] >>> 5),
|
|
2320
2320
|
I = (n[9] << 27) | (n[8] >>> 5),
|
|
2321
|
-
|
|
2322
|
-
|
|
2321
|
+
v = (n[11] << 4) | (n[10] >>> 28),
|
|
2322
|
+
B = (n[10] << 4) | (n[11] >>> 28),
|
|
2323
2323
|
P = (n[13] << 12) | (n[12] >>> 20),
|
|
2324
2324
|
U = (n[12] << 12) | (n[13] >>> 20),
|
|
2325
2325
|
L = (n[14] << 6) | (n[15] >>> 26),
|
|
2326
|
-
|
|
2327
|
-
|
|
2326
|
+
j = (n[15] << 6) | (n[14] >>> 26),
|
|
2327
|
+
N = (n[17] << 23) | (n[16] >>> 9),
|
|
2328
2328
|
z = (n[16] << 23) | (n[17] >>> 9),
|
|
2329
2329
|
F = (n[18] << 20) | (n[19] >>> 12),
|
|
2330
2330
|
q = (n[19] << 20) | (n[18] >>> 12),
|
|
@@ -2369,44 +2369,44 @@ function keccakPermutate(n) {
|
|
|
2369
2369
|
(n[8] = yn ^ (~E & P)),
|
|
2370
2370
|
(n[9] = xn ^ (~M & U)),
|
|
2371
2371
|
(n[10] = R ^ (~F & H)),
|
|
2372
|
-
(n[11] =
|
|
2372
|
+
(n[11] = D ^ (~q & W)),
|
|
2373
2373
|
(n[12] = F ^ (~H & en)),
|
|
2374
2374
|
(n[13] = q ^ (~W & tn)),
|
|
2375
2375
|
(n[14] = H ^ (~en & pn)),
|
|
2376
2376
|
(n[15] = W ^ (~tn & mn)),
|
|
2377
2377
|
(n[16] = en ^ (~pn & R)),
|
|
2378
|
-
(n[17] = tn ^ (~mn &
|
|
2378
|
+
(n[17] = tn ^ (~mn & D)),
|
|
2379
2379
|
(n[18] = pn ^ (~R & F)),
|
|
2380
|
-
(n[19] = mn ^ (~
|
|
2380
|
+
(n[19] = mn ^ (~D & q)),
|
|
2381
2381
|
(n[20] = O ^ (~L & Q)),
|
|
2382
|
-
(n[21] = k ^ (~
|
|
2382
|
+
(n[21] = k ^ (~j & _)),
|
|
2383
2383
|
(n[22] = L ^ (~Q & sn)),
|
|
2384
|
-
(n[23] =
|
|
2384
|
+
(n[23] = j ^ (~_ & fn)),
|
|
2385
2385
|
(n[24] = Q ^ (~sn & ln)),
|
|
2386
2386
|
(n[25] = _ ^ (~fn & an)),
|
|
2387
2387
|
(n[26] = sn ^ (~ln & O)),
|
|
2388
2388
|
(n[27] = fn ^ (~an & k)),
|
|
2389
2389
|
(n[28] = ln ^ (~O & L)),
|
|
2390
|
-
(n[29] = an ^ (~k &
|
|
2391
|
-
(n[30] =
|
|
2392
|
-
(n[31] = I ^ (~
|
|
2393
|
-
(n[32] =
|
|
2394
|
-
(n[33] =
|
|
2390
|
+
(n[29] = an ^ (~k & j)),
|
|
2391
|
+
(n[30] = C ^ (~v & V)),
|
|
2392
|
+
(n[31] = I ^ (~B & J)),
|
|
2393
|
+
(n[32] = v ^ (~V & rn)),
|
|
2394
|
+
(n[33] = B ^ (~J & on)),
|
|
2395
2395
|
(n[34] = V ^ (~rn & gn)),
|
|
2396
2396
|
(n[35] = J ^ (~on & wn)),
|
|
2397
|
-
(n[36] = rn ^ (~gn &
|
|
2397
|
+
(n[36] = rn ^ (~gn & C)),
|
|
2398
2398
|
(n[37] = on ^ (~wn & I)),
|
|
2399
|
-
(n[38] = gn ^ (~
|
|
2400
|
-
(n[39] = wn ^ (~I &
|
|
2401
|
-
(n[40] = T ^ (~
|
|
2399
|
+
(n[38] = gn ^ (~C & v)),
|
|
2400
|
+
(n[39] = wn ^ (~I & B)),
|
|
2401
|
+
(n[40] = T ^ (~N & G)),
|
|
2402
2402
|
(n[41] = S ^ (~z & Y)),
|
|
2403
|
-
(n[42] =
|
|
2403
|
+
(n[42] = N ^ (~G & X)),
|
|
2404
2404
|
(n[43] = z ^ (~Y & nn)),
|
|
2405
2405
|
(n[44] = G ^ (~X & hn)),
|
|
2406
2406
|
(n[45] = Y ^ (~nn & dn)),
|
|
2407
2407
|
(n[46] = X ^ (~hn & T)),
|
|
2408
2408
|
(n[47] = nn ^ (~dn & S)),
|
|
2409
|
-
(n[48] = hn ^ (~T &
|
|
2409
|
+
(n[48] = hn ^ (~T & N)),
|
|
2410
2410
|
(n[49] = dn ^ (~S & z)),
|
|
2411
2411
|
(n[0] ^= IOTA_CONSTANTS[e * 2]),
|
|
2412
2412
|
(n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
|
|
@@ -2748,23 +2748,31 @@ class FixedPointNumber {
|
|
|
2748
2748
|
return (o = (o || '').padEnd(t, '0').slice(0, t)), new FixedPointNumber(BigInt(r + o), t)
|
|
2749
2749
|
}
|
|
2750
2750
|
add(e) {
|
|
2751
|
-
return this.
|
|
2751
|
+
return this.assertSameScale(e), new FixedPointNumber(this.value + e.value, this.scale)
|
|
2752
2752
|
}
|
|
2753
2753
|
subtract(e) {
|
|
2754
|
-
return this.
|
|
2754
|
+
return this.assertSameScale(e), new FixedPointNumber(this.value - e.value, this.scale)
|
|
2755
2755
|
}
|
|
2756
2756
|
multiply(e) {
|
|
2757
2757
|
return new FixedPointNumber(this.value * e, this.scale)
|
|
2758
2758
|
}
|
|
2759
|
-
|
|
2759
|
+
divmod(e) {
|
|
2760
2760
|
if (e === 0n) throw new Error('Division by zero is not allowed')
|
|
2761
|
-
const t =
|
|
2762
|
-
r =
|
|
2763
|
-
|
|
2764
|
-
|
|
2761
|
+
const t = this.value / e,
|
|
2762
|
+
r = this.value % e
|
|
2763
|
+
return [new FixedPointNumber(t, this.scale), new FixedPointNumber(r, this.scale)]
|
|
2764
|
+
}
|
|
2765
|
+
exchange(e, t, r) {
|
|
2766
|
+
if (e === '*') {
|
|
2767
|
+
const i = (this.value * t.value) / 10n ** BigInt(this.scale)
|
|
2768
|
+
return new FixedPointNumber(i, r)
|
|
2769
|
+
}
|
|
2770
|
+
this.assertSameScale(t)
|
|
2771
|
+
const o = (this.value * 10n ** BigInt(r)) / t.value
|
|
2772
|
+
return new FixedPointNumber(o, r)
|
|
2765
2773
|
}
|
|
2766
2774
|
compare(e) {
|
|
2767
|
-
return this.
|
|
2775
|
+
return this.assertSameScale(e), this.value > e.value ? 1 : this.value < e.value ? -1 : 0
|
|
2768
2776
|
}
|
|
2769
2777
|
toDecimalString() {
|
|
2770
2778
|
if (this.scale === 0) return this.value.toString()
|
|
@@ -2779,7 +2787,7 @@ class FixedPointNumber {
|
|
|
2779
2787
|
toJSON() {
|
|
2780
2788
|
return this.toString()
|
|
2781
2789
|
}
|
|
2782
|
-
|
|
2790
|
+
assertSameScale(e) {
|
|
2783
2791
|
if (this.scale !== e.scale) throw new Error(`Scale mismatch: expected ${this.scale}, but got ${e.scale}`)
|
|
2784
2792
|
}
|
|
2785
2793
|
}
|