cafe-utility 26.9.0 → 26.11.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 +4 -0
  2. package/index.js +34 -21
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -415,6 +415,7 @@ declare function removeEmptyValues(object: CafeObject): CafeObject;
415
415
  declare function filterObjectKeys<T>(object: CafeObject<T>, predicate: (key: string) => boolean): CafeObject<T>;
416
416
  declare function filterObjectValues<T>(object: CafeObject<T>, predicate: (value: T) => boolean): CafeObject<T>;
417
417
  declare function mapObject<T, K>(object: CafeObject<T>, mapper: (value: T) => K): CafeObject<K>;
418
+ declare function mapIterable<T, K>(iterable: Iterable<T>, mapper: (value: T, index: number) => K): K[];
418
419
  declare function rethrow<T>(asyncFn: () => Promise<T>, throwable: Error): Promise<T>;
419
420
  declare function setSomeOnObject(object: CafeObject, key: string, value: unknown): void;
420
421
  declare function setSomeDeep(target: CafeObject, targetPath: string, source: CafeObject, sourcePath: string): void;
@@ -514,6 +515,7 @@ declare function getBit(bytes: Uint8Array, index: number): 0 | 1;
514
515
  declare function binaryIndexOf(bytes: Uint8Array, value: Uint8Array, start?: number): number;
515
516
  declare function binaryPad(bytes: Uint8Array, size: number): Uint8Array;
516
517
  declare function binaryPadToMultiple(bytes: Uint8Array, multiple: number): Uint8Array;
518
+ declare function xorCypher(bytes: Uint8Array, key: Uint8Array): Uint8Array;
517
519
  declare function binaryEquals(a: Uint8Array, b: Uint8Array): boolean;
518
520
  declare function privateKeyToPublicKey(privateKey: bigint): [bigint, bigint];
519
521
  declare function publicKeyToAddress(publicKey: [bigint, bigint]): Uint8Array;
@@ -637,6 +639,7 @@ export declare const Binary: {
637
639
  equals: typeof binaryEquals;
638
640
  pad: typeof binaryPad;
639
641
  padToMultiple: typeof binaryPadToMultiple;
642
+ xorCypher: typeof xorCypher;
640
643
  };
641
644
  export declare const Elliptic: {
642
645
  privateKeyToPublicKey: typeof privateKeyToPublicKey;
@@ -805,6 +808,7 @@ export declare const Objects: {
805
808
  match: typeof match;
806
809
  sort: typeof sortObjectValues;
807
810
  map: typeof mapObject;
811
+ mapIterable: typeof mapIterable;
808
812
  filterKeys: typeof filterObjectKeys;
809
813
  filterValues: typeof filterObjectValues;
810
814
  rethrow: typeof rethrow;
package/index.js CHANGED
@@ -1789,6 +1789,12 @@ function mapObject(n, e) {
1789
1789
  for (const r of Object.entries(n)) t[r[0]] = e(r[1])
1790
1790
  return t
1791
1791
  }
1792
+ function mapIterable(n, e) {
1793
+ const t = []
1794
+ let r = 0
1795
+ for (const o of n) t.push(e(o, r++))
1796
+ return t
1797
+ }
1792
1798
  async function rethrow(n, e) {
1793
1799
  try {
1794
1800
  return await n()
@@ -2181,8 +2187,8 @@ function keccakPermutate(n) {
2181
2187
  a = n[9] ^ n[19] ^ n[29] ^ n[39] ^ n[49],
2182
2188
  h = (o << 1) | (i >>> 31),
2183
2189
  bn = (i << 1) | (o >>> 31),
2184
- d = l ^ h,
2185
- p = a ^ bn,
2190
+ p = l ^ h,
2191
+ d = a ^ bn,
2186
2192
  $n = (u << 1) | (f >>> 31),
2187
2193
  An = (f << 1) | (u >>> 31),
2188
2194
  m = t ^ $n,
@@ -2199,8 +2205,8 @@ function keccakPermutate(n) {
2199
2205
  Sn = (r << 1) | (t >>> 31),
2200
2206
  $ = c ^ kn,
2201
2207
  A = s ^ Sn
2202
- ;(n[0] ^= d),
2203
- (n[1] ^= p),
2208
+ ;(n[0] ^= p),
2209
+ (n[1] ^= d),
2204
2210
  (n[2] ^= m),
2205
2211
  (n[3] ^= g),
2206
2212
  (n[4] ^= w),
@@ -2209,8 +2215,8 @@ function keccakPermutate(n) {
2209
2215
  (n[7] ^= b),
2210
2216
  (n[8] ^= $),
2211
2217
  (n[9] ^= A),
2212
- (n[10] ^= d),
2213
- (n[11] ^= p),
2218
+ (n[10] ^= p),
2219
+ (n[11] ^= d),
2214
2220
  (n[12] ^= m),
2215
2221
  (n[13] ^= g),
2216
2222
  (n[14] ^= w),
@@ -2219,8 +2225,8 @@ function keccakPermutate(n) {
2219
2225
  (n[17] ^= b),
2220
2226
  (n[18] ^= $),
2221
2227
  (n[19] ^= A),
2222
- (n[20] ^= d),
2223
- (n[21] ^= p),
2228
+ (n[20] ^= p),
2229
+ (n[21] ^= d),
2224
2230
  (n[22] ^= m),
2225
2231
  (n[23] ^= g),
2226
2232
  (n[24] ^= w),
@@ -2229,8 +2235,8 @@ function keccakPermutate(n) {
2229
2235
  (n[27] ^= b),
2230
2236
  (n[28] ^= $),
2231
2237
  (n[29] ^= A),
2232
- (n[30] ^= d),
2233
- (n[31] ^= p),
2238
+ (n[30] ^= p),
2239
+ (n[31] ^= d),
2234
2240
  (n[32] ^= m),
2235
2241
  (n[33] ^= g),
2236
2242
  (n[34] ^= w),
@@ -2239,8 +2245,8 @@ function keccakPermutate(n) {
2239
2245
  (n[37] ^= b),
2240
2246
  (n[38] ^= $),
2241
2247
  (n[39] ^= A),
2242
- (n[40] ^= d),
2243
- (n[41] ^= p),
2248
+ (n[40] ^= p),
2249
+ (n[41] ^= d),
2244
2250
  (n[42] ^= m),
2245
2251
  (n[43] ^= g),
2246
2252
  (n[44] ^= w),
@@ -2292,8 +2298,8 @@ function keccakPermutate(n) {
2292
2298
  ln = (n[40] << 18) | (n[41] >>> 14),
2293
2299
  an = (n[41] << 18) | (n[40] >>> 14),
2294
2300
  hn = (n[42] << 2) | (n[43] >>> 30),
2295
- dn = (n[43] << 2) | (n[42] >>> 30),
2296
- pn = (n[45] << 29) | (n[44] >>> 3),
2301
+ pn = (n[43] << 2) | (n[42] >>> 30),
2302
+ dn = (n[45] << 29) | (n[44] >>> 3),
2297
2303
  mn = (n[44] << 29) | (n[45] >>> 3),
2298
2304
  gn = (n[47] << 24) | (n[46] >>> 8),
2299
2305
  wn = (n[46] << 24) | (n[47] >>> 8),
@@ -2313,11 +2319,11 @@ function keccakPermutate(n) {
2313
2319
  (n[11] = D ^ (~v & W)),
2314
2320
  (n[12] = q ^ (~H & en)),
2315
2321
  (n[13] = v ^ (~W & tn)),
2316
- (n[14] = H ^ (~en & pn)),
2322
+ (n[14] = H ^ (~en & dn)),
2317
2323
  (n[15] = W ^ (~tn & mn)),
2318
- (n[16] = en ^ (~pn & R)),
2324
+ (n[16] = en ^ (~dn & R)),
2319
2325
  (n[17] = tn ^ (~mn & D)),
2320
- (n[18] = pn ^ (~R & q)),
2326
+ (n[18] = dn ^ (~R & q)),
2321
2327
  (n[19] = mn ^ (~D & v)),
2322
2328
  (n[20] = O ^ (~U & Z)),
2323
2329
  (n[21] = T ^ (~j & Q)),
@@ -2344,11 +2350,11 @@ function keccakPermutate(n) {
2344
2350
  (n[42] = F ^ (~G & X)),
2345
2351
  (n[43] = z ^ (~Y & nn)),
2346
2352
  (n[44] = G ^ (~X & hn)),
2347
- (n[45] = Y ^ (~nn & dn)),
2353
+ (n[45] = Y ^ (~nn & pn)),
2348
2354
  (n[46] = X ^ (~hn & k)),
2349
- (n[47] = nn ^ (~dn & S)),
2355
+ (n[47] = nn ^ (~pn & S)),
2350
2356
  (n[48] = hn ^ (~k & F)),
2351
- (n[49] = dn ^ (~S & z)),
2357
+ (n[49] = pn ^ (~S & z)),
2352
2358
  (n[0] ^= IOTA_CONSTANTS[e * 2]),
2353
2359
  (n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
2354
2360
  }
@@ -2461,6 +2467,11 @@ function binaryPadToMultiple(n, e) {
2461
2467
  const t = n.length % e
2462
2468
  return t === 0 ? n : binaryPad(n, n.length + e - t)
2463
2469
  }
2470
+ function xorCypher(n, e) {
2471
+ const t = new Uint8Array(n.length)
2472
+ for (let r = 0; r < n.length; r++) t[r] = n[r] ^ e[r % e.length]
2473
+ return t
2474
+ }
2464
2475
  function binaryEquals(n, e) {
2465
2476
  if (n.length !== e.length) return !1
2466
2477
  for (let t = 0; t < n.length; t++) if (n[t] !== e[t]) return !1
@@ -2936,7 +2947,8 @@ class AsyncQueue {
2936
2947
  indexOf: binaryIndexOf,
2937
2948
  equals: binaryEquals,
2938
2949
  pad: binaryPad,
2939
- padToMultiple: binaryPadToMultiple
2950
+ padToMultiple: binaryPadToMultiple,
2951
+ xorCypher
2940
2952
  }),
2941
2953
  (exports.Elliptic = {
2942
2954
  privateKeyToPublicKey,
@@ -3094,6 +3106,7 @@ class AsyncQueue {
3094
3106
  match,
3095
3107
  sort: sortObjectValues,
3096
3108
  map: mapObject,
3109
+ mapIterable,
3097
3110
  filterKeys: filterObjectKeys,
3098
3111
  filterValues: filterObjectValues,
3099
3112
  rethrow,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "26.9.0",
3
+ "version": "26.11.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {