expo-standard-web-crypto 1.4.2 → 1.5.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.
@@ -1 +1 @@
1
- {"version":3,"file":"getRandomValues.d.ts","sourceRoot":"","sources":["../src/getRandomValues.ts"],"names":[],"mappings":"AAIA,KAAK,YAAY,GACb,SAAS,GACT,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,GACX,iBAAiB,CAAC;AAWtB;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,MAAM,SAAS,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA+C9F;AAED,wBAAgB,uBAAuB,CAAC,MAAM,SAAS,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQ3F"}
1
+ {"version":3,"file":"getRandomValues.d.ts","sourceRoot":"","sources":["../src/getRandomValues.ts"],"names":[],"mappings":"AAIA,KAAK,YAAY,GACb,SAAS,GACT,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,GACX,iBAAiB,CAAC;AAEtB;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,MAAM,SAAS,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAmC9F;AAED,wBAAgB,uBAAuB,CAAC,MAAM,SAAS,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQ3F"}
@@ -1,4 +1,4 @@
1
- import { getRandomBytes } from 'expo-random';
1
+ import { getRandomValues as expoCryptoGetRandomValues } from 'expo-crypto';
2
2
  const MAX_RANDOM_BYTES = 65536;
3
3
  /**
4
4
  * An implementation of Crypto.getRandomValues that uses expo-random's secure random generator if
@@ -23,22 +23,15 @@ export default function getRandomValues(values) {
23
23
  if (values.byteLength > MAX_RANDOM_BYTES) {
24
24
  throw new QuotaExceededError(`The ArrayBuffer view's byte length (${values.byteLength}) exceeds the number of bytes of entropy available via this API (${MAX_RANDOM_BYTES})`);
25
25
  }
26
- let randomBytes;
27
26
  try {
28
27
  // NOTE: Consider implementing `fillRandomBytes` to populate the given TypedArray directly
29
- randomBytes = getRandomBytes(values.byteLength);
28
+ expoCryptoGetRandomValues(values);
30
29
  }
31
30
  catch {
32
31
  // TODO: rethrow the error if it's not due to a lack of synchronous methods
33
32
  console.warn(`Random.getRandomBytes is not supported; falling back to insecure Math.random`);
34
33
  return getRandomValuesInsecure(values);
35
34
  }
36
- // Create a new TypedArray that is of the same type as the given TypedArray but is backed with the
37
- // array buffer containing random bytes. This is cheap and copies no data.
38
- const TypedArrayConstructor = values.constructor;
39
- const randomValues = new TypedArrayConstructor(randomBytes.buffer, randomBytes.byteOffset, values.length);
40
- // Copy the data into the given TypedArray, letting the VM optimize the copy if possible
41
- values.set(randomValues);
42
35
  return values;
43
36
  }
44
37
  export function getRandomValuesInsecure(values) {
@@ -1 +1 @@
1
- {"version":3,"file":"getRandomValues.js","sourceRoot":"","sources":["../src/getRandomValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAoB/B;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAiC,MAAc;IACpF,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;QACxB,MAAM,IAAI,SAAS,CACjB,gFAAgF,CACjF,CAAC;KACH;IAED,IACE,CAAC,CAAC,MAAM,YAAY,SAAS,CAAC;QAC9B,CAAC,CAAC,MAAM,YAAY,UAAU,CAAC;QAC/B,CAAC,CAAC,MAAM,YAAY,UAAU,CAAC;QAC/B,CAAC,CAAC,MAAM,YAAY,WAAW,CAAC;QAChC,CAAC,CAAC,MAAM,YAAY,UAAU,CAAC;QAC/B,CAAC,CAAC,MAAM,YAAY,WAAW,CAAC;QAChC,CAAC,CAAC,MAAM,YAAY,iBAAiB,CAAC,EACtC;QACA,MA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,GAAG,EAAE,CAAC,CAAC,qBAAqB;CACjC","sourcesContent":["import { getRandomBytes } from 'expo-random';\n\nconst MAX_RANDOM_BYTES = 65536;\n\ntype IntegerArray =\n | Int8Array\n | Uint8Array\n | Int16Array\n | Uint16Array\n | Int32Array\n | Uint32Array\n | Uint8ClampedArray;\n\ntype IntegerArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Uint8ClampedArrayConstructor;\n\n/**\n * An implementation of Crypto.getRandomValues that uses expo-random's secure random generator if\n * available and falls back to Math.random (cryptographically insecure) when synchronous bridged\n * methods are unavailable.\n *\n * See https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues\n */\nexport default function getRandomValues<TArray extends ArrayBufferView>(values: TArray): TArray {\n if (arguments.length < 1) {\n throw new TypeError(\n `An ArrayBuffer view must be specified as the destination for the random values`\n );\n }\n\n if (\n !(values instanceof Int8Array) &&\n !(values instanceof Uint8Array) &&\n !(values instanceof Int16Array) &&\n !(values instanceof Uint16Array) &&\n !(values instanceof Int32Array) &&\n !(values instanceof Uint32Array) &&\n !(values instanceof Uint8ClampedArray)\n ) {\n throw new TypeError(`The provided ArrayBuffer view is not an integer-typed array`);\n }\n\n if (values.byteLength > MAX_RANDOM_BYTES) {\n throw new QuotaExceededError(\n `The ArrayBuffer view's byte length (${values.byteLength}) exceeds the number of bytes of entropy available via this API (${MAX_RANDOM_BYTES})`\n );\n }\n\n let randomBytes: Uint8Array;\n try {\n // NOTE: Consider implementing `fillRandomBytes` to populate the given TypedArray directly\n randomBytes = getRandomBytes(values.byteLength);\n } catch {\n // TODO: rethrow the error if it's not due to a lack of synchronous methods\n console.warn(`Random.getRandomBytes is not supported; falling back to insecure Math.random`);\n return getRandomValuesInsecure(values);\n }\n\n // Create a new TypedArray that is of the same type as the given TypedArray but is backed with the\n // array buffer containing random bytes. This is cheap and copies no data.\n const TypedArrayConstructor = values.constructor as IntegerArrayConstructor;\n const randomValues = new TypedArrayConstructor(\n randomBytes.buffer,\n randomBytes.byteOffset,\n values.length\n );\n\n // Copy the data into the given TypedArray, letting the VM optimize the copy if possible\n values.set(randomValues);\n return values;\n}\n\nexport function getRandomValuesInsecure<TArray extends IntegerArray>(values: TArray): TArray {\n // Write random bytes to the given TypedArray's underlying ArrayBuffer\n const byteView = new Uint8Array(values.buffer, values.byteOffset, values.byteLength);\n for (let i = 0; i < byteView.length; i++) {\n // The range of Math.random() is [0, 1) and the ToUint8 abstract operation rounds down\n byteView[i] = Math.random() * 256;\n }\n return values;\n}\n\nclass QuotaExceededError extends Error {\n name = 'QuotaExceededError';\n code = 22; // QUOTA_EXCEEDED_ERR\n}\n"]}
1
+ {"version":3,"file":"getRandomValues.js","sourceRoot":"","sources":["../src/getRandomValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAE3E,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAW/B;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAiC,MAAc;IACpF,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;QACxB,MAAM,IAAI,SAAS,CACjB,gFAAgF,CACjF,CAAC;KACH;IAED,IACE,CAAC,CAAC,MAAM,YAAY,SAAS,CAAC;QAC9B,CAAC,CAAC,MAAM,YAAY,UAAU,CAAC;QAC/B,CAAC,CAAC,MAAM,YAAY,UAAU,CAAC;QAC/B,CAAC,CAAC,MAAM,YAAY,WAAW,CAAC;QAChC,CAAC,CAAC,MAAM,YAAY,UAAU,CAAC;QAC/B,CAAC,CAAC,MAAM,YAAY,WAAW,CAAC;QAChC,CAAC,CAAC,MAAM,YAAY,iBAAiB,CAAC,EACtC;QACA,MAAM,IAAI,SAAS,CAAC,6DAA6D,CAAC,CAAC;KACpF;IAED,IAAI,MAAM,CAAC,UAAU,GAAG,gBAAgB,EAAE;QACxC,MAAM,IAAI,kBAAkB,CAC1B,uCAAuC,MAAM,CAAC,UAAU,oEAAoE,gBAAgB,GAAG,CAChJ,CAAC;KACH;IAED,IAAI;QACF,0FAA0F;QAC1F,yBAAyB,CAAC,MAAM,CAAC,CAAC;KACnC;IAAC,MAAM;QACN,2EAA2E;QAC3E,OAAO,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;QAC7F,OAAO,uBAAuB,CAAC,MAAM,CAAC,CAAC;KACxC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,uBAAuB,CAA8B,MAAc;IACjF,sEAAsE;IACtE,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IACrF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACxC,sFAAsF;QACtF,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;KACnC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,kBAAmB,SAAQ,KAAK;IACpC,IAAI,GAAG,oBAAoB,CAAC;IAC5B,IAAI,GAAG,EAAE,CAAC,CAAC,qBAAqB;CACjC","sourcesContent":["import { getRandomValues as expoCryptoGetRandomValues } from 'expo-crypto';\n\nconst MAX_RANDOM_BYTES = 65536;\n\ntype IntegerArray =\n | Int8Array\n | Uint8Array\n | Int16Array\n | Uint16Array\n | Int32Array\n | Uint32Array\n | Uint8ClampedArray;\n\n/**\n * An implementation of Crypto.getRandomValues that uses expo-random's secure random generator if\n * available and falls back to Math.random (cryptographically insecure) when synchronous bridged\n * methods are unavailable.\n *\n * See https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues\n */\nexport default function getRandomValues<TArray extends ArrayBufferView>(values: TArray): TArray {\n if (arguments.length < 1) {\n throw new TypeError(\n `An ArrayBuffer view must be specified as the destination for the random values`\n );\n }\n\n if (\n !(values instanceof Int8Array) &&\n !(values instanceof Uint8Array) &&\n !(values instanceof Int16Array) &&\n !(values instanceof Uint16Array) &&\n !(values instanceof Int32Array) &&\n !(values instanceof Uint32Array) &&\n !(values instanceof Uint8ClampedArray)\n ) {\n throw new TypeError(`The provided ArrayBuffer view is not an integer-typed array`);\n }\n\n if (values.byteLength > MAX_RANDOM_BYTES) {\n throw new QuotaExceededError(\n `The ArrayBuffer view's byte length (${values.byteLength}) exceeds the number of bytes of entropy available via this API (${MAX_RANDOM_BYTES})`\n );\n }\n\n try {\n // NOTE: Consider implementing `fillRandomBytes` to populate the given TypedArray directly\n expoCryptoGetRandomValues(values);\n } catch {\n // TODO: rethrow the error if it's not due to a lack of synchronous methods\n console.warn(`Random.getRandomBytes is not supported; falling back to insecure Math.random`);\n return getRandomValuesInsecure(values);\n }\n\n return values;\n}\n\nexport function getRandomValuesInsecure<TArray extends IntegerArray>(values: TArray): TArray {\n // Write random bytes to the given TypedArray's underlying ArrayBuffer\n const byteView = new Uint8Array(values.buffer, values.byteOffset, values.byteLength);\n for (let i = 0; i < byteView.length; i++) {\n // The range of Math.random() is [0, 1) and the ToUint8 abstract operation rounds down\n byteView[i] = Math.random() * 256;\n }\n return values;\n}\n\nclass QuotaExceededError extends Error {\n name = 'QuotaExceededError';\n code = 22; // QUOTA_EXCEEDED_ERR\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-standard-web-crypto",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "description": "A partial implementation of the W3C Crypto API for Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -31,15 +31,16 @@
31
31
  "license": "MIT",
32
32
  "devDependencies": {
33
33
  "expo-module-scripts": "^3.0.0",
34
- "expo-random": "~13.1.0"
34
+ "expo-crypto": "^12.2.1"
35
35
  },
36
36
  "peerDependencies": {
37
- "expo-random": "13.1.0"
37
+ "expo-crypto": "^12.2.1"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "expo-random": {
41
41
  "optional": true
42
42
  }
43
43
  },
44
- "gitHead": "1815e2eaad8c753588c7b1eb74420174a28e01f4"
44
+ "dependencies": {},
45
+ "gitHead": "d65d889ad266be731a54eabe7fab7db51801f14d"
45
46
  }
@@ -1,4 +1,4 @@
1
- import { getRandomBytes } from 'expo-random';
1
+ import { getRandomValues as expoCryptoGetRandomValues } from 'expo-crypto';
2
2
 
3
3
  const MAX_RANDOM_BYTES = 65536;
4
4
 
@@ -11,15 +11,6 @@ type IntegerArray =
11
11
  | Uint32Array
12
12
  | Uint8ClampedArray;
13
13
 
14
- type IntegerArrayConstructor =
15
- | Int8ArrayConstructor
16
- | Uint8ArrayConstructor
17
- | Int16ArrayConstructor
18
- | Uint16ArrayConstructor
19
- | Int32ArrayConstructor
20
- | Uint32ArrayConstructor
21
- | Uint8ClampedArrayConstructor;
22
-
23
14
  /**
24
15
  * An implementation of Crypto.getRandomValues that uses expo-random's secure random generator if
25
16
  * available and falls back to Math.random (cryptographically insecure) when synchronous bridged
@@ -52,27 +43,15 @@ export default function getRandomValues<TArray extends ArrayBufferView>(values:
52
43
  );
53
44
  }
54
45
 
55
- let randomBytes: Uint8Array;
56
46
  try {
57
47
  // NOTE: Consider implementing `fillRandomBytes` to populate the given TypedArray directly
58
- randomBytes = getRandomBytes(values.byteLength);
48
+ expoCryptoGetRandomValues(values);
59
49
  } catch {
60
50
  // TODO: rethrow the error if it's not due to a lack of synchronous methods
61
51
  console.warn(`Random.getRandomBytes is not supported; falling back to insecure Math.random`);
62
52
  return getRandomValuesInsecure(values);
63
53
  }
64
54
 
65
- // Create a new TypedArray that is of the same type as the given TypedArray but is backed with the
66
- // array buffer containing random bytes. This is cheap and copies no data.
67
- const TypedArrayConstructor = values.constructor as IntegerArrayConstructor;
68
- const randomValues = new TypedArrayConstructor(
69
- randomBytes.buffer,
70
- randomBytes.byteOffset,
71
- values.length
72
- );
73
-
74
- // Copy the data into the given TypedArray, letting the VM optimize the copy if possible
75
- values.set(randomValues);
76
55
  return values;
77
56
  }
78
57