cafe-utility 28.2.0 → 29.1.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.
Files changed (3) hide show
  1. package/index.d.ts +3 -1
  2. package/index.js +59 -35
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -533,7 +533,7 @@ declare function sliceBytes(bytes: Uint8Array, lengths: number[]): Uint8Array[];
533
533
  declare function partition(bytes: Uint8Array, size: number): Uint8Array[];
534
534
  declare function keccak256(bytes: Uint8Array): Uint8Array;
535
535
  declare function sha3_256(bytes: Uint8Array): Uint8Array;
536
- declare function proximity(one: Uint8Array, other: Uint8Array, max: number): number;
536
+ declare function proximity(one: Uint8Array, other: Uint8Array): number;
537
537
  declare function commonPrefix(one: Uint8Array, other: Uint8Array): Uint8Array;
538
538
  declare function setBit(bytes: Uint8Array, index: number, value: 0 | 1, endian: 'LE' | 'BE'): void;
539
539
  declare function getBit(bytes: Uint8Array, index: number, endian: 'LE' | 'BE'): 0 | 1;
@@ -543,6 +543,7 @@ declare function binaryPadStartToMultiple(bytes: Uint8Array, multiple: number, p
543
543
  declare function binaryPadEnd(bytes: Uint8Array, size: number, paddingByte?: number): Uint8Array;
544
544
  declare function binaryPadEndToMultiple(bytes: Uint8Array, multiple: number, paddingByte?: number): Uint8Array;
545
545
  declare function xorCypher(bytes: Uint8Array, key: Uint8Array): Uint8Array;
546
+ declare function isUtf8(bytes: Uint8Array): boolean;
546
547
  declare function binaryEquals(a: Uint8Array, b: Uint8Array): boolean;
547
548
  declare function privateKeyToPublicKey(privateKey: bigint): [bigint, bigint];
548
549
  declare function compressPublicKey(publicKey: [bigint, bigint]): Uint8Array;
@@ -702,6 +703,7 @@ export declare const Binary: {
702
703
  padEnd: typeof binaryPadEnd;
703
704
  padEndToMultiple: typeof binaryPadEndToMultiple;
704
705
  xorCypher: typeof xorCypher;
706
+ isUtf8: typeof isUtf8;
705
707
  };
706
708
  export declare const Elliptic: {
707
709
  privateKeyToPublicKey: typeof privateKeyToPublicKey;
package/index.js CHANGED
@@ -2299,12 +2299,12 @@ function keccakPermutate(n) {
2299
2299
  m = t ^ $n,
2300
2300
  g = r ^ An,
2301
2301
  En = (c << 1) | (f >>> 31),
2302
- On = (f << 1) | (c >>> 31),
2302
+ Mn = (f << 1) | (c >>> 31),
2303
2303
  w = o ^ En,
2304
- y = i ^ On,
2305
- Mn = (l << 1) | (a >>> 31),
2304
+ x = i ^ Mn,
2305
+ On = (l << 1) | (a >>> 31),
2306
2306
  kn = (a << 1) | (l >>> 31),
2307
- x = u ^ Mn,
2307
+ y = u ^ On,
2308
2308
  b = s ^ kn,
2309
2309
  Tn = (t << 1) | (r >>> 31),
2310
2310
  Sn = (r << 1) | (t >>> 31),
@@ -2315,8 +2315,8 @@ function keccakPermutate(n) {
2315
2315
  (n[2] ^= m),
2316
2316
  (n[3] ^= g),
2317
2317
  (n[4] ^= w),
2318
- (n[5] ^= y),
2319
- (n[6] ^= x),
2318
+ (n[5] ^= x),
2319
+ (n[6] ^= y),
2320
2320
  (n[7] ^= b),
2321
2321
  (n[8] ^= $),
2322
2322
  (n[9] ^= A),
@@ -2325,8 +2325,8 @@ function keccakPermutate(n) {
2325
2325
  (n[12] ^= m),
2326
2326
  (n[13] ^= g),
2327
2327
  (n[14] ^= w),
2328
- (n[15] ^= y),
2329
- (n[16] ^= x),
2328
+ (n[15] ^= x),
2329
+ (n[16] ^= y),
2330
2330
  (n[17] ^= b),
2331
2331
  (n[18] ^= $),
2332
2332
  (n[19] ^= A),
@@ -2335,8 +2335,8 @@ function keccakPermutate(n) {
2335
2335
  (n[22] ^= m),
2336
2336
  (n[23] ^= g),
2337
2337
  (n[24] ^= w),
2338
- (n[25] ^= y),
2339
- (n[26] ^= x),
2338
+ (n[25] ^= x),
2339
+ (n[26] ^= y),
2340
2340
  (n[27] ^= b),
2341
2341
  (n[28] ^= $),
2342
2342
  (n[29] ^= A),
@@ -2345,8 +2345,8 @@ function keccakPermutate(n) {
2345
2345
  (n[32] ^= m),
2346
2346
  (n[33] ^= g),
2347
2347
  (n[34] ^= w),
2348
- (n[35] ^= y),
2349
- (n[36] ^= x),
2348
+ (n[35] ^= x),
2349
+ (n[36] ^= y),
2350
2350
  (n[37] ^= b),
2351
2351
  (n[38] ^= $),
2352
2352
  (n[39] ^= A),
@@ -2355,14 +2355,14 @@ function keccakPermutate(n) {
2355
2355
  (n[42] ^= m),
2356
2356
  (n[43] ^= g),
2357
2357
  (n[44] ^= w),
2358
- (n[45] ^= y),
2359
- (n[46] ^= x),
2358
+ (n[45] ^= x),
2359
+ (n[46] ^= y),
2360
2360
  (n[47] ^= b),
2361
2361
  (n[48] ^= $),
2362
2362
  (n[49] ^= A)
2363
2363
  const E = n[0],
2364
- O = n[1],
2365
- M = (n[2] << 1) | (n[3] >>> 31),
2364
+ M = n[1],
2365
+ O = (n[2] << 1) | (n[3] >>> 31),
2366
2366
  k = (n[3] << 1) | (n[2] >>> 31),
2367
2367
  T = (n[5] << 30) | (n[4] >>> 2),
2368
2368
  S = (n[4] << 30) | (n[5] >>> 2),
@@ -2408,18 +2408,18 @@ function keccakPermutate(n) {
2408
2408
  mn = (n[44] << 29) | (n[45] >>> 3),
2409
2409
  gn = (n[47] << 24) | (n[46] >>> 8),
2410
2410
  wn = (n[46] << 24) | (n[47] >>> 8),
2411
- yn = (n[48] << 14) | (n[49] >>> 18),
2412
- xn = (n[49] << 14) | (n[48] >>> 18)
2411
+ xn = (n[48] << 14) | (n[49] >>> 18),
2412
+ yn = (n[49] << 14) | (n[48] >>> 18)
2413
2413
  ;(n[0] = E ^ (~v & K)),
2414
- (n[1] = O ^ (~U & Z)),
2414
+ (n[1] = M ^ (~U & Z)),
2415
2415
  (n[2] = v ^ (~K & un)),
2416
2416
  (n[3] = U ^ (~Z & cn)),
2417
- (n[4] = K ^ (~un & yn)),
2418
- (n[5] = Z ^ (~cn & xn)),
2419
- (n[6] = un ^ (~yn & E)),
2420
- (n[7] = cn ^ (~xn & O)),
2421
- (n[8] = yn ^ (~E & v)),
2422
- (n[9] = xn ^ (~O & U)),
2417
+ (n[4] = K ^ (~un & xn)),
2418
+ (n[5] = Z ^ (~cn & yn)),
2419
+ (n[6] = un ^ (~xn & E)),
2420
+ (n[7] = cn ^ (~yn & M)),
2421
+ (n[8] = xn ^ (~E & v)),
2422
+ (n[9] = yn ^ (~M & U)),
2423
2423
  (n[10] = R ^ (~z & q)),
2424
2424
  (n[11] = I ^ (~W & H)),
2425
2425
  (n[12] = z ^ (~q & en)),
@@ -2430,15 +2430,15 @@ function keccakPermutate(n) {
2430
2430
  (n[17] = tn ^ (~mn & I)),
2431
2431
  (n[18] = pn ^ (~R & z)),
2432
2432
  (n[19] = mn ^ (~I & W)),
2433
- (n[20] = M ^ (~L & Q)),
2433
+ (n[20] = O ^ (~L & Q)),
2434
2434
  (n[21] = k ^ (~N & G)),
2435
2435
  (n[22] = L ^ (~Q & sn)),
2436
2436
  (n[23] = N ^ (~G & fn)),
2437
2437
  (n[24] = Q ^ (~sn & ln)),
2438
2438
  (n[25] = G ^ (~fn & an)),
2439
- (n[26] = sn ^ (~ln & M)),
2439
+ (n[26] = sn ^ (~ln & O)),
2440
2440
  (n[27] = fn ^ (~an & k)),
2441
- (n[28] = ln ^ (~M & L)),
2441
+ (n[28] = ln ^ (~O & L)),
2442
2442
  (n[29] = an ^ (~k & N)),
2443
2443
  (n[30] = D ^ (~B & V)),
2444
2444
  (n[31] = C ^ (~P & J)),
@@ -2535,13 +2535,13 @@ function keccak256(n) {
2535
2535
  function sha3_256(n) {
2536
2536
  return squeeze(absorb(new Array(50).fill(0), divideToBlocks(n, 6)))
2537
2537
  }
2538
- function proximity(n, e, t) {
2539
- const r = Math.min(n.length, e.length, t / 8 + 1)
2540
- for (let o = 0; o < r; o++) {
2541
- const i = n[o] ^ e[o]
2542
- for (let u = 0; u < 8; u++) if ((i >> (7 - u)) & 1) return o * 8 + u
2538
+ function proximity(n, e) {
2539
+ const t = Math.min(n.length, e.length)
2540
+ for (let r = 0; r < t; r++) {
2541
+ const o = n[r] ^ e[r]
2542
+ for (let i = 0; i < 8; i++) if ((o >> (7 - i)) & 1) return r * 8 + i
2543
2543
  }
2544
- return t
2544
+ return Math.min(n.length, e.length) * 8
2545
2545
  }
2546
2546
  function commonPrefix(n, e) {
2547
2547
  const t = Math.min(n.length, e.length)
@@ -2586,6 +2586,29 @@ function xorCypher(n, e) {
2586
2586
  for (let r = 0; r < n.length; r++) t[r] = n[r] ^ e[r % e.length]
2587
2587
  return t
2588
2588
  }
2589
+ function isUtf8(n) {
2590
+ for (let e = 0; e < n.length; e++) {
2591
+ const t = n[e]
2592
+ if (!(t < 128))
2593
+ if ((t & 224) === 192) {
2594
+ if (e + 1 >= n.length || (n[e + 1] & 192) !== 128) return !1
2595
+ e += 1
2596
+ } else if ((t & 240) === 224) {
2597
+ if (e + 2 >= n.length || (n[e + 1] & 192) !== 128 || (n[e + 2] & 192) !== 128) return !1
2598
+ e += 2
2599
+ } else if ((t & 248) === 240) {
2600
+ if (
2601
+ e + 3 >= n.length ||
2602
+ (n[e + 1] & 192) !== 128 ||
2603
+ (n[e + 2] & 192) !== 128 ||
2604
+ (n[e + 3] & 192) !== 128
2605
+ )
2606
+ return !1
2607
+ e += 3
2608
+ } else return !1
2609
+ }
2610
+ return !0
2611
+ }
2589
2612
  function binaryEquals(n, e) {
2590
2613
  if (n.length !== e.length) return !1
2591
2614
  for (let t = 0; t < n.length; t++) if (n[t] !== e[t]) return !1
@@ -3179,7 +3202,8 @@ class TrieRouter {
3179
3202
  padStartToMultiple: binaryPadStartToMultiple,
3180
3203
  padEnd: binaryPadEnd,
3181
3204
  padEndToMultiple: binaryPadEndToMultiple,
3182
- xorCypher
3205
+ xorCypher,
3206
+ isUtf8
3183
3207
  }),
3184
3208
  (exports.Elliptic = {
3185
3209
  privateKeyToPublicKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "28.2.0",
3
+ "version": "29.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {