@absolutejs/sync-expo 0.0.2 → 0.0.3
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/bridge.js +7 -2
- package/dist/bridge.js.map +5 -4
- package/dist/client.js +7 -2
- package/dist/client.js.map +5 -4
- package/dist/crypto.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -537
- package/dist/index.js.map +6 -8
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// src/crypto.ts
|
|
2
|
+
import * as Crypto from "expo-crypto";
|
|
3
|
+
var expoSyncRandomBytes = (length) => Crypto.getRandomBytes(length);
|
|
4
|
+
var expoSyncRandomId = () => Crypto.randomUUID();
|
|
5
|
+
|
|
1
6
|
// src/bridge.ts
|
|
2
7
|
var requireRecord = (value, label) => {
|
|
3
8
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
@@ -26,7 +31,7 @@ var createExpoSyncBridgeHost = ({
|
|
|
26
31
|
store,
|
|
27
32
|
namespace,
|
|
28
33
|
transactionTimeoutMs = 8000,
|
|
29
|
-
createId =
|
|
34
|
+
createId = expoSyncRandomId
|
|
30
35
|
}) => {
|
|
31
36
|
if (!namespace || namespace.length > 512)
|
|
32
37
|
throw new TypeError("Expo Sync bridge namespace is invalid.");
|
|
@@ -344,540 +349,8 @@ var createExpoSyncSocketBridgeHost = ({
|
|
|
344
349
|
};
|
|
345
350
|
};
|
|
346
351
|
|
|
347
|
-
// node_modules/@noble/ciphers/utils.js
|
|
348
|
-
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
|
|
349
|
-
function isBytes(a) {
|
|
350
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
351
|
-
}
|
|
352
|
-
var atitle = (title) => title ? `"${title}" ` : "";
|
|
353
|
-
function abool(value, title = "") {
|
|
354
|
-
if (typeof value !== "boolean")
|
|
355
|
-
throw new TypeError(atitle(title) + "expected boolean, got type=" + typeof value);
|
|
356
|
-
return value;
|
|
357
|
-
}
|
|
358
|
-
function anumber(n, title = "") {
|
|
359
|
-
if (typeof n !== "number")
|
|
360
|
-
throw new TypeError(atitle(title) + "expected number, got " + typeof n);
|
|
361
|
-
if (!Number.isSafeInteger(n) || n < 0)
|
|
362
|
-
throw new RangeError(atitle(title) + "expected integer >= 0, got " + n);
|
|
363
|
-
return n;
|
|
364
|
-
}
|
|
365
|
-
function abytes(value, length, title = "") {
|
|
366
|
-
if (isBytes(value) && (length === undefined || value.length === length))
|
|
367
|
-
return value;
|
|
368
|
-
if (length !== undefined)
|
|
369
|
-
anumber(length, "length");
|
|
370
|
-
const bytes = isBytes(value);
|
|
371
|
-
const ofLen = length !== undefined ? ` of length ${length}` : "";
|
|
372
|
-
const got = bytes ? `length=${value.length}` : `type=${typeof value}`;
|
|
373
|
-
const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
374
|
-
if (!bytes)
|
|
375
|
-
throw new TypeError(message);
|
|
376
|
-
throw new RangeError(message);
|
|
377
|
-
}
|
|
378
|
-
function aexists(instance, checkFinished = true) {
|
|
379
|
-
if (instance.destroyed)
|
|
380
|
-
throw new Error("hash was destroyed");
|
|
381
|
-
if (checkFinished && instance.finished)
|
|
382
|
-
throw new Error("digest() was already called");
|
|
383
|
-
}
|
|
384
|
-
function aoutput(out, instance) {
|
|
385
|
-
abytes(out, undefined, "output");
|
|
386
|
-
const min = instance.outputLen;
|
|
387
|
-
if (!(out.length >= min)) {
|
|
388
|
-
throw new RangeError('"output" expected length >= ' + min);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
function aoutput32(out, instance) {
|
|
392
|
-
aoutput(out, instance);
|
|
393
|
-
if (!isAligned32(out))
|
|
394
|
-
throw new Error("invalid output, must be aligned");
|
|
395
|
-
}
|
|
396
|
-
function u8(arr) {
|
|
397
|
-
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
398
|
-
}
|
|
399
|
-
function u32(arr) {
|
|
400
|
-
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
401
|
-
}
|
|
402
|
-
function clean(...arrays) {
|
|
403
|
-
for (let i = 0;i < arrays.length; i++) {
|
|
404
|
-
arrays[i].fill(0);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
function createView(arr) {
|
|
408
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
409
|
-
}
|
|
410
|
-
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
411
|
-
function byteSwap(word) {
|
|
412
|
-
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
413
|
-
}
|
|
414
|
-
var swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n) >>> 0;
|
|
415
|
-
function byteSwap32(arr) {
|
|
416
|
-
for (let i = 0;i < arr.length; i++) {
|
|
417
|
-
arr[i] = byteSwap(arr[i]);
|
|
418
|
-
}
|
|
419
|
-
return arr;
|
|
420
|
-
}
|
|
421
|
-
var swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
422
|
-
function equalBytes(a, b) {
|
|
423
|
-
a = abytes(a);
|
|
424
|
-
b = abytes(b);
|
|
425
|
-
if (a.length !== b.length)
|
|
426
|
-
return false;
|
|
427
|
-
let diff = 0;
|
|
428
|
-
for (let i = 0;i < a.length; i++)
|
|
429
|
-
diff |= a[i] ^ b[i];
|
|
430
|
-
return diff === 0;
|
|
431
|
-
}
|
|
432
|
-
function wrapMacConstructor(keyLen, macCons, fromMsg) {
|
|
433
|
-
const mac = macCons;
|
|
434
|
-
const getArgs = fromMsg || (() => []);
|
|
435
|
-
const macC = (msg, key) => mac(key, ...getArgs(msg)).update(msg).digest();
|
|
436
|
-
const tmp = mac(new Uint8Array(keyLen), ...getArgs(new Uint8Array(0)));
|
|
437
|
-
macC.outputLen = tmp.outputLen;
|
|
438
|
-
macC.blockLen = tmp.blockLen;
|
|
439
|
-
macC.create = (key, ...args) => mac(key, ...args);
|
|
440
|
-
return macC;
|
|
441
|
-
}
|
|
442
|
-
var wrapCipher = (params, constructor) => {
|
|
443
|
-
function wrappedCipher(key, ...args) {
|
|
444
|
-
abytes(key, undefined, "key");
|
|
445
|
-
if (params.nonceLength !== undefined) {
|
|
446
|
-
const nonce = args[0];
|
|
447
|
-
abytes(nonce, params.varSizeNonce ? undefined : params.nonceLength, "nonce");
|
|
448
|
-
}
|
|
449
|
-
const tagl = params.tagLength;
|
|
450
|
-
const aadStart = params.nonceLength !== undefined ? 1 : 0;
|
|
451
|
-
if (!params.withAAD) {
|
|
452
|
-
for (let i = aadStart;i < args.length; i++)
|
|
453
|
-
if (isBytes(args[i]))
|
|
454
|
-
throw new Error("AAD not supported");
|
|
455
|
-
}
|
|
456
|
-
if (params.withAAD && args[aadStart] !== undefined)
|
|
457
|
-
abytes(args[aadStart], undefined, "AAD");
|
|
458
|
-
const cipher = constructor(key, ...args);
|
|
459
|
-
const checkOutput = (fnLength, output) => {
|
|
460
|
-
if (output !== undefined) {
|
|
461
|
-
if (fnLength !== 2)
|
|
462
|
-
throw new Error("cipher output not supported");
|
|
463
|
-
abytes(output, undefined, "output");
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
let called = false;
|
|
467
|
-
const wrCipher = {
|
|
468
|
-
encrypt(data, output) {
|
|
469
|
-
if (called)
|
|
470
|
-
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
471
|
-
called = true;
|
|
472
|
-
abytes(data, undefined, "data");
|
|
473
|
-
checkOutput(cipher.encrypt.length, output);
|
|
474
|
-
return cipher.encrypt(data, output);
|
|
475
|
-
},
|
|
476
|
-
decrypt(data, output) {
|
|
477
|
-
abytes(data, undefined, "data");
|
|
478
|
-
if (tagl && data.length < tagl)
|
|
479
|
-
throw new Error('"ciphertext" expected length >= tagLength=' + tagl);
|
|
480
|
-
checkOutput(cipher.decrypt.length, output);
|
|
481
|
-
return cipher.decrypt(data, output);
|
|
482
|
-
}
|
|
483
|
-
};
|
|
484
|
-
return wrCipher;
|
|
485
|
-
}
|
|
486
|
-
Object.assign(wrappedCipher, params);
|
|
487
|
-
return wrappedCipher;
|
|
488
|
-
};
|
|
489
|
-
function getOutput(expectedLength, out, onlyAligned = true) {
|
|
490
|
-
if (out === undefined)
|
|
491
|
-
return new Uint8Array(expectedLength);
|
|
492
|
-
abytes(out, expectedLength, "output");
|
|
493
|
-
if (onlyAligned && !isAligned32(out))
|
|
494
|
-
throw new Error("invalid output, must be aligned");
|
|
495
|
-
return out;
|
|
496
|
-
}
|
|
497
|
-
function u64Lengths(dataLength, aadLength, isLE2) {
|
|
498
|
-
anumber(dataLength);
|
|
499
|
-
anumber(aadLength);
|
|
500
|
-
abool(isLE2);
|
|
501
|
-
const num = new Uint8Array(16);
|
|
502
|
-
const view = createView(num);
|
|
503
|
-
view.setBigUint64(0, BigInt(aadLength), isLE2);
|
|
504
|
-
view.setBigUint64(8, BigInt(dataLength), isLE2);
|
|
505
|
-
return num;
|
|
506
|
-
}
|
|
507
|
-
function isAligned32(bytes) {
|
|
508
|
-
return bytes.byteOffset % 4 === 0;
|
|
509
|
-
}
|
|
510
|
-
function copyBytes(bytes) {
|
|
511
|
-
return Uint8Array.from(abytes(bytes));
|
|
512
|
-
}
|
|
513
|
-
function randomBytes(bytesLength = 32) {
|
|
514
|
-
anumber(bytesLength, "bytesLength");
|
|
515
|
-
const cr = typeof globalThis === "object" ? globalThis.crypto : null;
|
|
516
|
-
if (typeof cr?.getRandomValues !== "function")
|
|
517
|
-
throw new Error("crypto.getRandomValues must be defined");
|
|
518
|
-
if (bytesLength > 65536)
|
|
519
|
-
throw new RangeError(`"bytesLength" expected <= 65536, got ${bytesLength}`);
|
|
520
|
-
return cr.getRandomValues(new Uint8Array(bytesLength));
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// node_modules/@noble/ciphers/_polyval.js
|
|
524
|
-
var BLOCK_SIZE = 16;
|
|
525
|
-
var ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
|
|
526
|
-
var ZEROS32 = /* @__PURE__ */ u32(ZEROS16);
|
|
527
|
-
var POLY = 225;
|
|
528
|
-
var mul2 = (s0, s1, s2, s3) => {
|
|
529
|
-
const hiBit = s3 & 1;
|
|
530
|
-
return {
|
|
531
|
-
s3: s2 << 31 | s3 >>> 1,
|
|
532
|
-
s2: s1 << 31 | s2 >>> 1,
|
|
533
|
-
s1: s0 << 31 | s1 >>> 1,
|
|
534
|
-
s0: s0 >>> 1 ^ POLY << 24 & -(hiBit & 1)
|
|
535
|
-
};
|
|
536
|
-
};
|
|
537
|
-
var swapLE = (n) => (n >>> 0 & 255) << 24 | (n >>> 8 & 255) << 16 | (n >>> 16 & 255) << 8 | n >>> 24 & 255 | 0;
|
|
538
|
-
var estimateWindow = (bytes) => {
|
|
539
|
-
if (bytes > 64 * 1024)
|
|
540
|
-
return 8;
|
|
541
|
-
if (bytes > 1024)
|
|
542
|
-
return 4;
|
|
543
|
-
return 2;
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
class GHASH {
|
|
547
|
-
blockLen = BLOCK_SIZE;
|
|
548
|
-
outputLen = BLOCK_SIZE;
|
|
549
|
-
s0 = 0;
|
|
550
|
-
s1 = 0;
|
|
551
|
-
s2 = 0;
|
|
552
|
-
s3 = 0;
|
|
553
|
-
finished = false;
|
|
554
|
-
destroyed = false;
|
|
555
|
-
t;
|
|
556
|
-
W;
|
|
557
|
-
windowSize;
|
|
558
|
-
constructor(key, expectedLength) {
|
|
559
|
-
abytes(key, 16, "key");
|
|
560
|
-
key = copyBytes(key);
|
|
561
|
-
const kView = createView(key);
|
|
562
|
-
let k0 = kView.getUint32(0, false);
|
|
563
|
-
let k1 = kView.getUint32(4, false);
|
|
564
|
-
let k2 = kView.getUint32(8, false);
|
|
565
|
-
let k3 = kView.getUint32(12, false);
|
|
566
|
-
const doubles = [];
|
|
567
|
-
for (let i = 0;i < 128; i++) {
|
|
568
|
-
doubles.push({ s0: swapLE(k0), s1: swapLE(k1), s2: swapLE(k2), s3: swapLE(k3) });
|
|
569
|
-
({ s0: k0, s1: k1, s2: k2, s3: k3 } = mul2(k0, k1, k2, k3));
|
|
570
|
-
}
|
|
571
|
-
const W = estimateWindow(expectedLength || 1024);
|
|
572
|
-
if (![1, 2, 4, 8].includes(W))
|
|
573
|
-
throw new Error("ghash: invalid window size, expected 2, 4 or 8");
|
|
574
|
-
this.W = W;
|
|
575
|
-
const bits = 128;
|
|
576
|
-
const windows = bits / W;
|
|
577
|
-
const windowSize = this.windowSize = 2 ** W;
|
|
578
|
-
const items = [];
|
|
579
|
-
for (let w = 0;w < windows; w++) {
|
|
580
|
-
for (let byte = 0;byte < windowSize; byte++) {
|
|
581
|
-
let s0 = 0, s1 = 0, s2 = 0, s3 = 0;
|
|
582
|
-
for (let j = 0;j < W; j++) {
|
|
583
|
-
const bit = byte >>> W - j - 1 & 1;
|
|
584
|
-
if (!bit)
|
|
585
|
-
continue;
|
|
586
|
-
const { s0: d0, s1: d1, s2: d2, s3: d3 } = doubles[W * w + j];
|
|
587
|
-
s0 ^= d0, s1 ^= d1, s2 ^= d2, s3 ^= d3;
|
|
588
|
-
}
|
|
589
|
-
items.push({ s0, s1, s2, s3 });
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
this.t = items;
|
|
593
|
-
}
|
|
594
|
-
_updateBlock(s0, s1, s2, s3) {
|
|
595
|
-
s0 ^= this.s0, s1 ^= this.s1, s2 ^= this.s2, s3 ^= this.s3;
|
|
596
|
-
const { W, t, windowSize } = this;
|
|
597
|
-
let o0 = 0, o1 = 0, o2 = 0, o3 = 0;
|
|
598
|
-
const mask = (1 << W) - 1;
|
|
599
|
-
let w = 0;
|
|
600
|
-
for (const num of [s0, s1, s2, s3]) {
|
|
601
|
-
for (let bytePos = 0;bytePos < 4; bytePos++) {
|
|
602
|
-
const byte = num >>> 8 * bytePos & 255;
|
|
603
|
-
for (let bitPos = 8 / W - 1;bitPos >= 0; bitPos--) {
|
|
604
|
-
const bit = byte >>> W * bitPos & mask;
|
|
605
|
-
const { s0: e0, s1: e1, s2: e2, s3: e3 } = t[w * windowSize + bit];
|
|
606
|
-
o0 ^= e0, o1 ^= e1, o2 ^= e2, o3 ^= e3;
|
|
607
|
-
w += 1;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
this.s0 = o0;
|
|
612
|
-
this.s1 = o1;
|
|
613
|
-
this.s2 = o2;
|
|
614
|
-
this.s3 = o3;
|
|
615
|
-
}
|
|
616
|
-
update(data) {
|
|
617
|
-
aexists(this);
|
|
618
|
-
abytes(data);
|
|
619
|
-
data = copyBytes(data);
|
|
620
|
-
const b32 = u32(data);
|
|
621
|
-
const blocks = Math.floor(data.length / BLOCK_SIZE);
|
|
622
|
-
const left = data.length % BLOCK_SIZE;
|
|
623
|
-
for (let i = 0;i < blocks; i++) {
|
|
624
|
-
this._updateBlock(swap8IfBE(b32[i * 4 + 0]), swap8IfBE(b32[i * 4 + 1]), swap8IfBE(b32[i * 4 + 2]), swap8IfBE(b32[i * 4 + 3]));
|
|
625
|
-
}
|
|
626
|
-
if (left) {
|
|
627
|
-
ZEROS16.set(data.subarray(blocks * BLOCK_SIZE));
|
|
628
|
-
this._updateBlock(swap8IfBE(ZEROS32[0]), swap8IfBE(ZEROS32[1]), swap8IfBE(ZEROS32[2]), swap8IfBE(ZEROS32[3]));
|
|
629
|
-
clean(ZEROS32);
|
|
630
|
-
}
|
|
631
|
-
return this;
|
|
632
|
-
}
|
|
633
|
-
destroy() {
|
|
634
|
-
this.destroyed = true;
|
|
635
|
-
const { t } = this;
|
|
636
|
-
for (const elm of t) {
|
|
637
|
-
elm.s0 = 0, elm.s1 = 0, elm.s2 = 0, elm.s3 = 0;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
digestInto(out) {
|
|
641
|
-
aexists(this);
|
|
642
|
-
aoutput32(out, this);
|
|
643
|
-
this.finished = true;
|
|
644
|
-
const { s0, s1, s2, s3 } = this;
|
|
645
|
-
const o32 = u32(out);
|
|
646
|
-
o32[0] = s0;
|
|
647
|
-
o32[1] = s1;
|
|
648
|
-
o32[2] = s2;
|
|
649
|
-
o32[3] = s3;
|
|
650
|
-
if (!isLE)
|
|
651
|
-
swap32IfBE(o32.subarray(0, BLOCK_SIZE / 4));
|
|
652
|
-
}
|
|
653
|
-
digest() {
|
|
654
|
-
const res = new Uint8Array(BLOCK_SIZE);
|
|
655
|
-
this.digestInto(res);
|
|
656
|
-
this.destroy();
|
|
657
|
-
return res;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
var ghash = /* @__PURE__ */ wrapMacConstructor(16, (key, expectedLength) => new GHASH(key, expectedLength), (msg) => [msg.length]);
|
|
661
|
-
|
|
662
|
-
// node_modules/@noble/ciphers/aes.js
|
|
663
|
-
var BLOCK_SIZE2 = 16;
|
|
664
|
-
var BLOCK_SIZE32 = 4;
|
|
665
|
-
var EMPTY_BLOCK = /* @__PURE__ */ new Uint8Array(BLOCK_SIZE2);
|
|
666
|
-
var POLY2 = 283;
|
|
667
|
-
function validateKeyLength(key) {
|
|
668
|
-
if (![16, 24, 32].includes(key.length))
|
|
669
|
-
throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length=' + key.length);
|
|
670
|
-
}
|
|
671
|
-
function mul22(n) {
|
|
672
|
-
return n << 1 ^ POLY2 & -(n >> 7);
|
|
673
|
-
}
|
|
674
|
-
function mul(a, b) {
|
|
675
|
-
let res = 0;
|
|
676
|
-
for (;b > 0; b >>= 1) {
|
|
677
|
-
res ^= a & -(b & 1);
|
|
678
|
-
a = mul22(a);
|
|
679
|
-
}
|
|
680
|
-
return res;
|
|
681
|
-
}
|
|
682
|
-
var sbox = /* @__PURE__ */ (() => {
|
|
683
|
-
const t = new Uint8Array(256);
|
|
684
|
-
for (let i = 0, x = 1;i < 256; i++, x ^= mul22(x))
|
|
685
|
-
t[i] = x;
|
|
686
|
-
const box = new Uint8Array(256);
|
|
687
|
-
box[0] = 99;
|
|
688
|
-
for (let i = 0;i < 255; i++) {
|
|
689
|
-
let x = t[255 - i];
|
|
690
|
-
x |= x << 8;
|
|
691
|
-
box[t[i]] = (x ^ x >> 4 ^ x >> 5 ^ x >> 6 ^ x >> 7 ^ 99) & 255;
|
|
692
|
-
}
|
|
693
|
-
clean(t);
|
|
694
|
-
return box;
|
|
695
|
-
})();
|
|
696
|
-
var rotr32_8 = (n) => n << 24 | n >>> 8;
|
|
697
|
-
var rotl32_8 = (n) => n << 8 | n >>> 24;
|
|
698
|
-
function genTtable(sbox2, fn) {
|
|
699
|
-
if (sbox2.length !== 256)
|
|
700
|
-
throw new Error("wrong sbox length");
|
|
701
|
-
const T0 = new Uint32Array(256).map((_, j) => fn(sbox2[j]));
|
|
702
|
-
const T1 = T0.map(rotl32_8);
|
|
703
|
-
const T2 = T1.map(rotl32_8);
|
|
704
|
-
const T3 = T2.map(rotl32_8);
|
|
705
|
-
const T01 = new Uint32Array(256 * 256);
|
|
706
|
-
const T23 = new Uint32Array(256 * 256);
|
|
707
|
-
const sbox22 = new Uint16Array(256 * 256);
|
|
708
|
-
for (let i = 0;i < 256; i++) {
|
|
709
|
-
for (let j = 0;j < 256; j++) {
|
|
710
|
-
const idx = i * 256 + j;
|
|
711
|
-
T01[idx] = T0[i] ^ T1[j];
|
|
712
|
-
T23[idx] = T2[i] ^ T3[j];
|
|
713
|
-
sbox22[idx] = sbox2[i] << 8 | sbox2[j];
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
return { sbox: sbox2, sbox2: sbox22, T0, T1, T2, T3, T01, T23 };
|
|
717
|
-
}
|
|
718
|
-
var tableEncoding = /* @__PURE__ */ genTtable(sbox, (s) => mul(s, 3) << 24 | s << 16 | s << 8 | mul(s, 2));
|
|
719
|
-
var xPowers = /* @__PURE__ */ (() => {
|
|
720
|
-
const p = new Uint8Array(16);
|
|
721
|
-
for (let i = 0, x = 1;i < 16; i++, x = mul22(x))
|
|
722
|
-
p[i] = x;
|
|
723
|
-
return p;
|
|
724
|
-
})();
|
|
725
|
-
function expandKeyLE(key) {
|
|
726
|
-
abytes(key);
|
|
727
|
-
const len = key.length;
|
|
728
|
-
validateKeyLength(key);
|
|
729
|
-
const { sbox2 } = tableEncoding;
|
|
730
|
-
const toClean = [];
|
|
731
|
-
if (!isLE || !isAligned32(key))
|
|
732
|
-
toClean.push(key = copyBytes(key));
|
|
733
|
-
const k32 = swap32IfBE(u32(key));
|
|
734
|
-
const Nk = k32.length;
|
|
735
|
-
const subByte = (n) => applySbox(sbox2, n, n, n, n);
|
|
736
|
-
const xk = new Uint32Array(len + 28);
|
|
737
|
-
xk.set(k32);
|
|
738
|
-
for (let i = Nk;i < xk.length; i++) {
|
|
739
|
-
let t = xk[i - 1];
|
|
740
|
-
if (i % Nk === 0)
|
|
741
|
-
t = subByte(rotr32_8(t)) ^ xPowers[i / Nk - 1];
|
|
742
|
-
else if (Nk > 6 && i % Nk === 4)
|
|
743
|
-
t = subByte(t);
|
|
744
|
-
xk[i] = xk[i - Nk] ^ t;
|
|
745
|
-
}
|
|
746
|
-
clean(...toClean);
|
|
747
|
-
return xk;
|
|
748
|
-
}
|
|
749
|
-
function apply0123(T01, T23, s0, s1, s2, s3) {
|
|
750
|
-
return T01[s0 << 8 & 65280 | s1 >>> 8 & 255] ^ T23[s2 >>> 8 & 65280 | s3 >>> 24 & 255];
|
|
751
|
-
}
|
|
752
|
-
function applySbox(sbox2, s0, s1, s2, s3) {
|
|
753
|
-
return sbox2[s0 & 255 | s1 & 65280] | sbox2[s2 >>> 16 & 255 | s3 >>> 16 & 65280] << 16;
|
|
754
|
-
}
|
|
755
|
-
function encrypt(xk, s0, s1, s2, s3) {
|
|
756
|
-
const { sbox2, T01, T23 } = tableEncoding;
|
|
757
|
-
let k = 0;
|
|
758
|
-
s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
|
|
759
|
-
const rounds = xk.length / 4 - 2;
|
|
760
|
-
for (let i = 0;i < rounds; i++) {
|
|
761
|
-
const t02 = xk[k++] ^ apply0123(T01, T23, s0, s1, s2, s3);
|
|
762
|
-
const t12 = xk[k++] ^ apply0123(T01, T23, s1, s2, s3, s0);
|
|
763
|
-
const t22 = xk[k++] ^ apply0123(T01, T23, s2, s3, s0, s1);
|
|
764
|
-
const t32 = xk[k++] ^ apply0123(T01, T23, s3, s0, s1, s2);
|
|
765
|
-
s0 = t02, s1 = t12, s2 = t22, s3 = t32;
|
|
766
|
-
}
|
|
767
|
-
const t0 = xk[k++] ^ applySbox(sbox2, s0, s1, s2, s3);
|
|
768
|
-
const t1 = xk[k++] ^ applySbox(sbox2, s1, s2, s3, s0);
|
|
769
|
-
const t2 = xk[k++] ^ applySbox(sbox2, s2, s3, s0, s1);
|
|
770
|
-
const t3 = xk[k++] ^ applySbox(sbox2, s3, s0, s1, s2);
|
|
771
|
-
return { s0: t0, s1: t1, s2: t2, s3: t3 };
|
|
772
|
-
}
|
|
773
|
-
function ctr32(xk, isLE2, nonce, src, dst) {
|
|
774
|
-
abytes(nonce, BLOCK_SIZE2, "nonce");
|
|
775
|
-
abytes(src);
|
|
776
|
-
dst = getOutput(src.length, dst);
|
|
777
|
-
const ctr = nonce;
|
|
778
|
-
const c32 = u32(ctr);
|
|
779
|
-
const view = createView(ctr);
|
|
780
|
-
const src32 = u32(src);
|
|
781
|
-
const dst32 = u32(dst);
|
|
782
|
-
const ctrPos = isLE2 ? 0 : 12;
|
|
783
|
-
const srcLen = src.length;
|
|
784
|
-
let ctrNum = view.getUint32(ctrPos, isLE2);
|
|
785
|
-
for (let i = 0;i + 4 <= src32.length; i += 4) {
|
|
786
|
-
const { s0, s1, s2, s3 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
787
|
-
dst32[i + 0] = src32[i + 0] ^ swap8IfBE(s0);
|
|
788
|
-
dst32[i + 1] = src32[i + 1] ^ swap8IfBE(s1);
|
|
789
|
-
dst32[i + 2] = src32[i + 2] ^ swap8IfBE(s2);
|
|
790
|
-
dst32[i + 3] = src32[i + 3] ^ swap8IfBE(s3);
|
|
791
|
-
ctrNum = ctrNum + 1 >>> 0;
|
|
792
|
-
view.setUint32(ctrPos, ctrNum, isLE2);
|
|
793
|
-
}
|
|
794
|
-
const start = BLOCK_SIZE2 * Math.floor(src32.length / BLOCK_SIZE32);
|
|
795
|
-
if (start < srcLen) {
|
|
796
|
-
const { s0, s1, s2, s3 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
797
|
-
const b32 = new Uint32Array([s0, s1, s2, s3]);
|
|
798
|
-
swap32IfBE(b32);
|
|
799
|
-
const buf = u8(b32);
|
|
800
|
-
for (let i = start, pos = 0;i < srcLen; i++, pos++)
|
|
801
|
-
dst[i] = src[i] ^ buf[pos];
|
|
802
|
-
clean(b32);
|
|
803
|
-
}
|
|
804
|
-
return dst;
|
|
805
|
-
}
|
|
806
|
-
function computeTag(fn, isLE2, key, data, AAD) {
|
|
807
|
-
const aadLength = AAD ? AAD.length : 0;
|
|
808
|
-
const h = fn.create(key, data.length + aadLength);
|
|
809
|
-
if (AAD)
|
|
810
|
-
h.update(AAD);
|
|
811
|
-
const num = u64Lengths(8 * data.length, 8 * aadLength, isLE2);
|
|
812
|
-
h.update(data);
|
|
813
|
-
h.update(num);
|
|
814
|
-
const res = h.digest();
|
|
815
|
-
clean(num);
|
|
816
|
-
return res;
|
|
817
|
-
}
|
|
818
|
-
var gcm = /* @__PURE__ */ wrapCipher({ blockSize: 16, nonceLength: 12, tagLength: 16, withAAD: true, varSizeNonce: true }, function aesgcm(key, nonce, AAD) {
|
|
819
|
-
if (nonce.length < 8)
|
|
820
|
-
throw new Error("aes/gcm: invalid nonce length");
|
|
821
|
-
const tagLength = 16;
|
|
822
|
-
function _computeTag(authKey, tagMask, data) {
|
|
823
|
-
const tag = computeTag(ghash, false, authKey, data, AAD);
|
|
824
|
-
for (let i = 0;i < tagMask.length; i++)
|
|
825
|
-
tag[i] ^= tagMask[i];
|
|
826
|
-
return tag;
|
|
827
|
-
}
|
|
828
|
-
function deriveKeys() {
|
|
829
|
-
const xk = expandKeyLE(key);
|
|
830
|
-
const authKey = EMPTY_BLOCK.slice();
|
|
831
|
-
const counter = EMPTY_BLOCK.slice();
|
|
832
|
-
ctr32(xk, false, counter, counter, authKey);
|
|
833
|
-
if (nonce.length === 12) {
|
|
834
|
-
counter.set(nonce);
|
|
835
|
-
} else {
|
|
836
|
-
const nonceLen = EMPTY_BLOCK.slice();
|
|
837
|
-
const view = createView(nonceLen);
|
|
838
|
-
view.setBigUint64(8, BigInt(nonce.length * 8), false);
|
|
839
|
-
const g = ghash.create(authKey).update(nonce).update(nonceLen);
|
|
840
|
-
g.digestInto(counter);
|
|
841
|
-
g.destroy();
|
|
842
|
-
}
|
|
843
|
-
const tagMask = ctr32(xk, false, counter, EMPTY_BLOCK);
|
|
844
|
-
return { xk, authKey, counter, tagMask };
|
|
845
|
-
}
|
|
846
|
-
return {
|
|
847
|
-
encrypt(plaintext) {
|
|
848
|
-
const { xk, authKey, counter, tagMask } = deriveKeys();
|
|
849
|
-
const out = new Uint8Array(plaintext.length + tagLength);
|
|
850
|
-
const toClean = [xk, authKey, counter, tagMask];
|
|
851
|
-
if (!isAligned32(plaintext))
|
|
852
|
-
toClean.push(plaintext = copyBytes(plaintext));
|
|
853
|
-
ctr32(xk, false, counter, plaintext, out.subarray(0, plaintext.length));
|
|
854
|
-
const tag = _computeTag(authKey, tagMask, out.subarray(0, out.length - tagLength));
|
|
855
|
-
toClean.push(tag);
|
|
856
|
-
out.set(tag, plaintext.length);
|
|
857
|
-
clean(...toClean);
|
|
858
|
-
return out;
|
|
859
|
-
},
|
|
860
|
-
decrypt(ciphertext) {
|
|
861
|
-
const { xk, authKey, counter, tagMask } = deriveKeys();
|
|
862
|
-
const toClean = [xk, authKey, tagMask, counter];
|
|
863
|
-
if (!isAligned32(ciphertext))
|
|
864
|
-
toClean.push(ciphertext = copyBytes(ciphertext));
|
|
865
|
-
const data = ciphertext.subarray(0, -tagLength);
|
|
866
|
-
const passedTag = ciphertext.subarray(-tagLength);
|
|
867
|
-
const tag = _computeTag(authKey, tagMask, data);
|
|
868
|
-
toClean.push(tag);
|
|
869
|
-
if (!equalBytes(tag, passedTag)) {
|
|
870
|
-
clean(...toClean);
|
|
871
|
-
throw new Error("aes-gcm: invalid tag");
|
|
872
|
-
}
|
|
873
|
-
const out = ctr32(xk, false, counter, data);
|
|
874
|
-
clean(...toClean);
|
|
875
|
-
return out;
|
|
876
|
-
}
|
|
877
|
-
};
|
|
878
|
-
});
|
|
879
|
-
|
|
880
352
|
// src/index.ts
|
|
353
|
+
import { gcm } from "@noble/ciphers/aes.js";
|
|
881
354
|
import * as BackgroundTask from "expo-background-task";
|
|
882
355
|
import * as Network from "expo-network";
|
|
883
356
|
import * as SecureStore from "expo-secure-store";
|
|
@@ -1262,7 +735,7 @@ var createExpoSyncProtection = (options = {}) => {
|
|
|
1262
735
|
const existing = await storage.getItemAsync(keyName, secureStoreOptions);
|
|
1263
736
|
if (existing)
|
|
1264
737
|
return unbase64(existing);
|
|
1265
|
-
const created =
|
|
738
|
+
const created = expoSyncRandomBytes(32);
|
|
1266
739
|
await storage.setItemAsync(keyName, base64(created), secureStoreOptions);
|
|
1267
740
|
const persisted = await storage.getItemAsync(keyName, secureStoreOptions);
|
|
1268
741
|
if (!persisted)
|
|
@@ -1282,7 +755,7 @@ var createExpoSyncProtection = (options = {}) => {
|
|
|
1282
755
|
return textDecoder.decode(gcm(key, nonce, additionalData(context)).decrypt(bytes.slice(12)));
|
|
1283
756
|
},
|
|
1284
757
|
seal: (value, context) => {
|
|
1285
|
-
const nonce =
|
|
758
|
+
const nonce = expoSyncRandomBytes(12);
|
|
1286
759
|
const encrypted = gcm(key, nonce, additionalData(context)).encrypt(textEncoder.encode(value));
|
|
1287
760
|
const output = new Uint8Array(nonce.length + encrypted.length);
|
|
1288
761
|
output.set(nonce);
|
|
@@ -1384,10 +857,11 @@ export {
|
|
|
1384
857
|
createExpoSyncProtection,
|
|
1385
858
|
createExpoSyncSocketBridgeHost,
|
|
1386
859
|
defineExpoSyncBackgroundTask,
|
|
860
|
+
expoSyncRandomId,
|
|
1387
861
|
installExpoSyncLifecycle,
|
|
1388
862
|
registerExpoSyncBackgroundTask,
|
|
1389
863
|
unregisterExpoSyncBackgroundTask
|
|
1390
864
|
};
|
|
1391
865
|
|
|
1392
|
-
//# debugId=
|
|
866
|
+
//# debugId=4F7885AE99B6C6D464756E2164756E21
|
|
1393
867
|
//# sourceMappingURL=index.js.map
|