cafe-utility 26.10.0 → 26.12.0
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 -5
- package/index.js +36 -26
- package/module.mjs +2 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -515,6 +515,7 @@ declare function getBit(bytes: Uint8Array, index: number): 0 | 1;
|
|
|
515
515
|
declare function binaryIndexOf(bytes: Uint8Array, value: Uint8Array, start?: number): number;
|
|
516
516
|
declare function binaryPad(bytes: Uint8Array, size: number): Uint8Array;
|
|
517
517
|
declare function binaryPadToMultiple(bytes: Uint8Array, multiple: number): Uint8Array;
|
|
518
|
+
declare function xorCypher(bytes: Uint8Array, key: Uint8Array): Uint8Array;
|
|
518
519
|
declare function binaryEquals(a: Uint8Array, b: Uint8Array): boolean;
|
|
519
520
|
declare function privateKeyToPublicKey(privateKey: bigint): [bigint, bigint];
|
|
520
521
|
declare function publicKeyToAddress(publicKey: [bigint, bigint]): Uint8Array;
|
|
@@ -522,17 +523,14 @@ declare function signMessage(message: Uint8Array, privateKey: bigint, nonce?: bi
|
|
|
522
523
|
declare function signHash(hash: bigint, privateKey: bigint, nonce?: bigint): [bigint, bigint, 27n | 28n];
|
|
523
524
|
declare function recoverPublicKey(message: Uint8Array, r: bigint, s: bigint, v: 27n | 28n): [bigint, bigint];
|
|
524
525
|
declare function verifySignature(message: Uint8Array, publicKey: [bigint, bigint], r: bigint, s: bigint): boolean;
|
|
525
|
-
|
|
526
|
-
max: () => number;
|
|
527
|
-
}
|
|
528
|
-
declare class Uint8ArrayReader implements Uint8ArrayIO {
|
|
526
|
+
export declare class Uint8ArrayReader {
|
|
529
527
|
cursor: number;
|
|
530
528
|
buffer: Uint8Array;
|
|
531
529
|
constructor(buffer: Uint8Array);
|
|
532
530
|
read(size: number): Uint8Array;
|
|
533
531
|
max(): number;
|
|
534
532
|
}
|
|
535
|
-
declare class Uint8ArrayWriter
|
|
533
|
+
export declare class Uint8ArrayWriter {
|
|
536
534
|
cursor: number;
|
|
537
535
|
buffer: Uint8Array;
|
|
538
536
|
constructor(buffer: Uint8Array);
|
|
@@ -638,6 +636,7 @@ export declare const Binary: {
|
|
|
638
636
|
equals: typeof binaryEquals;
|
|
639
637
|
pad: typeof binaryPad;
|
|
640
638
|
padToMultiple: typeof binaryPadToMultiple;
|
|
639
|
+
xorCypher: typeof xorCypher;
|
|
641
640
|
};
|
|
642
641
|
export declare const Elliptic: {
|
|
643
642
|
privateKeyToPublicKey: typeof privateKeyToPublicKey;
|
package/index.js
CHANGED
|
@@ -17,6 +17,8 @@ Object.defineProperty(exports, '__esModule', { value: !0 }),
|
|
|
17
17
|
exports.AsyncQueue =
|
|
18
18
|
exports.PubSubChannel =
|
|
19
19
|
exports.Chunk =
|
|
20
|
+
exports.Uint8ArrayWriter =
|
|
21
|
+
exports.Uint8ArrayReader =
|
|
20
22
|
exports.AsyncLazy =
|
|
21
23
|
exports.Lazy =
|
|
22
24
|
exports.Optional =
|
|
@@ -2202,9 +2204,9 @@ function keccakPermutate(n) {
|
|
|
2202
2204
|
x = u ^ On,
|
|
2203
2205
|
b = f ^ Tn,
|
|
2204
2206
|
kn = (t << 1) | (r >>> 31),
|
|
2205
|
-
|
|
2207
|
+
Rn = (r << 1) | (t >>> 31),
|
|
2206
2208
|
$ = c ^ kn,
|
|
2207
|
-
A = s ^
|
|
2209
|
+
A = s ^ Rn
|
|
2208
2210
|
;(n[0] ^= p),
|
|
2209
2211
|
(n[1] ^= d),
|
|
2210
2212
|
(n[2] ^= m),
|
|
@@ -2260,23 +2262,23 @@ function keccakPermutate(n) {
|
|
|
2260
2262
|
O = (n[2] << 1) | (n[3] >>> 31),
|
|
2261
2263
|
T = (n[3] << 1) | (n[2] >>> 31),
|
|
2262
2264
|
k = (n[5] << 30) | (n[4] >>> 2),
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
+
R = (n[4] << 30) | (n[5] >>> 2),
|
|
2266
|
+
S = (n[6] << 28) | (n[7] >>> 4),
|
|
2265
2267
|
D = (n[7] << 28) | (n[6] >>> 4),
|
|
2266
2268
|
I = (n[8] << 27) | (n[9] >>> 5),
|
|
2267
2269
|
C = (n[9] << 27) | (n[8] >>> 5),
|
|
2268
2270
|
P = (n[11] << 4) | (n[10] >>> 28),
|
|
2269
2271
|
B = (n[10] << 4) | (n[11] >>> 28),
|
|
2270
2272
|
L = (n[13] << 12) | (n[12] >>> 20),
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
+
U = (n[12] << 12) | (n[13] >>> 20),
|
|
2274
|
+
N = (n[14] << 6) | (n[15] >>> 26),
|
|
2273
2275
|
j = (n[15] << 6) | (n[14] >>> 26),
|
|
2274
2276
|
F = (n[17] << 23) | (n[16] >>> 9),
|
|
2275
2277
|
z = (n[16] << 23) | (n[17] >>> 9),
|
|
2276
2278
|
q = (n[18] << 20) | (n[19] >>> 12),
|
|
2277
2279
|
v = (n[19] << 20) | (n[18] >>> 12),
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
+
W = (n[20] << 3) | (n[21] >>> 29),
|
|
2281
|
+
H = (n[21] << 3) | (n[20] >>> 29),
|
|
2280
2282
|
V = (n[22] << 10) | (n[23] >>> 22),
|
|
2281
2283
|
_ = (n[23] << 10) | (n[22] >>> 22),
|
|
2282
2284
|
J = (n[25] << 11) | (n[24] >>> 21),
|
|
@@ -2306,34 +2308,34 @@ function keccakPermutate(n) {
|
|
|
2306
2308
|
yn = (n[48] << 14) | (n[49] >>> 18),
|
|
2307
2309
|
xn = (n[49] << 14) | (n[48] >>> 18)
|
|
2308
2310
|
;(n[0] = E ^ (~L & J)),
|
|
2309
|
-
(n[1] = M ^ (~
|
|
2311
|
+
(n[1] = M ^ (~U & K)),
|
|
2310
2312
|
(n[2] = L ^ (~J & un)),
|
|
2311
|
-
(n[3] =
|
|
2313
|
+
(n[3] = U ^ (~K & cn)),
|
|
2312
2314
|
(n[4] = J ^ (~un & yn)),
|
|
2313
2315
|
(n[5] = K ^ (~cn & xn)),
|
|
2314
2316
|
(n[6] = un ^ (~yn & E)),
|
|
2315
2317
|
(n[7] = cn ^ (~xn & M)),
|
|
2316
2318
|
(n[8] = yn ^ (~E & L)),
|
|
2317
|
-
(n[9] = xn ^ (~M &
|
|
2318
|
-
(n[10] =
|
|
2319
|
-
(n[11] = D ^ (~v &
|
|
2320
|
-
(n[12] = q ^ (~
|
|
2321
|
-
(n[13] = v ^ (~
|
|
2322
|
-
(n[14] =
|
|
2323
|
-
(n[15] =
|
|
2324
|
-
(n[16] = en ^ (~dn &
|
|
2319
|
+
(n[9] = xn ^ (~M & U)),
|
|
2320
|
+
(n[10] = S ^ (~q & W)),
|
|
2321
|
+
(n[11] = D ^ (~v & H)),
|
|
2322
|
+
(n[12] = q ^ (~W & en)),
|
|
2323
|
+
(n[13] = v ^ (~H & tn)),
|
|
2324
|
+
(n[14] = W ^ (~en & dn)),
|
|
2325
|
+
(n[15] = H ^ (~tn & mn)),
|
|
2326
|
+
(n[16] = en ^ (~dn & S)),
|
|
2325
2327
|
(n[17] = tn ^ (~mn & D)),
|
|
2326
|
-
(n[18] = dn ^ (~
|
|
2328
|
+
(n[18] = dn ^ (~S & q)),
|
|
2327
2329
|
(n[19] = mn ^ (~D & v)),
|
|
2328
|
-
(n[20] = O ^ (~
|
|
2330
|
+
(n[20] = O ^ (~N & Z)),
|
|
2329
2331
|
(n[21] = T ^ (~j & Q)),
|
|
2330
|
-
(n[22] =
|
|
2332
|
+
(n[22] = N ^ (~Z & fn)),
|
|
2331
2333
|
(n[23] = j ^ (~Q & sn)),
|
|
2332
2334
|
(n[24] = Z ^ (~fn & ln)),
|
|
2333
2335
|
(n[25] = Q ^ (~sn & an)),
|
|
2334
2336
|
(n[26] = fn ^ (~ln & O)),
|
|
2335
2337
|
(n[27] = sn ^ (~an & T)),
|
|
2336
|
-
(n[28] = ln ^ (~O &
|
|
2338
|
+
(n[28] = ln ^ (~O & N)),
|
|
2337
2339
|
(n[29] = an ^ (~T & j)),
|
|
2338
2340
|
(n[30] = I ^ (~P & V)),
|
|
2339
2341
|
(n[31] = C ^ (~B & _)),
|
|
@@ -2346,15 +2348,15 @@ function keccakPermutate(n) {
|
|
|
2346
2348
|
(n[38] = gn ^ (~I & P)),
|
|
2347
2349
|
(n[39] = wn ^ (~C & B)),
|
|
2348
2350
|
(n[40] = k ^ (~F & G)),
|
|
2349
|
-
(n[41] =
|
|
2351
|
+
(n[41] = R ^ (~z & Y)),
|
|
2350
2352
|
(n[42] = F ^ (~G & X)),
|
|
2351
2353
|
(n[43] = z ^ (~Y & nn)),
|
|
2352
2354
|
(n[44] = G ^ (~X & hn)),
|
|
2353
2355
|
(n[45] = Y ^ (~nn & pn)),
|
|
2354
2356
|
(n[46] = X ^ (~hn & k)),
|
|
2355
|
-
(n[47] = nn ^ (~pn &
|
|
2357
|
+
(n[47] = nn ^ (~pn & R)),
|
|
2356
2358
|
(n[48] = hn ^ (~k & F)),
|
|
2357
|
-
(n[49] = pn ^ (~
|
|
2359
|
+
(n[49] = pn ^ (~R & z)),
|
|
2358
2360
|
(n[0] ^= IOTA_CONSTANTS[e * 2]),
|
|
2359
2361
|
(n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
|
|
2360
2362
|
}
|
|
@@ -2467,6 +2469,11 @@ function binaryPadToMultiple(n, e) {
|
|
|
2467
2469
|
const t = n.length % e
|
|
2468
2470
|
return t === 0 ? n : binaryPad(n, n.length + e - t)
|
|
2469
2471
|
}
|
|
2472
|
+
function xorCypher(n, e) {
|
|
2473
|
+
const t = new Uint8Array(n.length)
|
|
2474
|
+
for (let r = 0; r < n.length; r++) t[r] = n[r] ^ e[r % e.length]
|
|
2475
|
+
return t
|
|
2476
|
+
}
|
|
2470
2477
|
function binaryEquals(n, e) {
|
|
2471
2478
|
if (n.length !== e.length) return !1
|
|
2472
2479
|
for (let t = 0; t < n.length; t++) if (n[t] !== e[t]) return !1
|
|
@@ -2592,6 +2599,7 @@ class Uint8ArrayReader {
|
|
|
2592
2599
|
return this.buffer.length - this.cursor
|
|
2593
2600
|
}
|
|
2594
2601
|
}
|
|
2602
|
+
exports.Uint8ArrayReader = Uint8ArrayReader
|
|
2595
2603
|
class Uint8ArrayWriter {
|
|
2596
2604
|
constructor(e) {
|
|
2597
2605
|
;(this.buffer = e), (this.cursor = 0)
|
|
@@ -2604,6 +2612,7 @@ class Uint8ArrayWriter {
|
|
|
2604
2612
|
return this.buffer.length - this.cursor
|
|
2605
2613
|
}
|
|
2606
2614
|
}
|
|
2615
|
+
exports.Uint8ArrayWriter = Uint8ArrayWriter
|
|
2607
2616
|
class Chunk {
|
|
2608
2617
|
constructor(e, t = 0n) {
|
|
2609
2618
|
;(this.span = t), (this.writer = new Uint8ArrayWriter(new Uint8Array(e)))
|
|
@@ -2942,7 +2951,8 @@ class AsyncQueue {
|
|
|
2942
2951
|
indexOf: binaryIndexOf,
|
|
2943
2952
|
equals: binaryEquals,
|
|
2944
2953
|
pad: binaryPad,
|
|
2945
|
-
padToMultiple: binaryPadToMultiple
|
|
2954
|
+
padToMultiple: binaryPadToMultiple,
|
|
2955
|
+
xorCypher
|
|
2946
2956
|
}),
|
|
2947
2957
|
(exports.Elliptic = {
|
|
2948
2958
|
privateKeyToPublicKey,
|
package/module.mjs
CHANGED
|
@@ -21,3 +21,5 @@ export const Chunk = utility.Chunk
|
|
|
21
21
|
export const Lazy = utility.Lazy
|
|
22
22
|
export const AsyncLazy = utility.AsyncLazy
|
|
23
23
|
export const AsyncQueue = utility.AsyncQueue
|
|
24
|
+
export const Uint8ArrayReader = utility.Uint8ArrayReader
|
|
25
|
+
export const Uint8ArrayWriter = utility.Uint8ArrayWriter
|