expo-standard-web-crypto 1.2.0 → 1.3.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/README.md CHANGED
@@ -8,7 +8,7 @@ This package provides a partial polyfill of the W3C Crypto API for Expo. Namely,
8
8
 
9
9
  # Installation in Expo projects
10
10
 
11
- First follow the instructions for installing [`expo-random`](https://github.com/expo/expo/blob/master/packages/expo-random/README.md), which is required by this package. Then install this package.
11
+ First follow the instructions for installing [`expo-random`](https://github.com/expo/expo/blob/main/packages/expo-random/README.md), which is required by this package. Then install this package.
12
12
 
13
13
  ### Add the package to your npm dependencies
14
14
 
@@ -9,3 +9,4 @@ declare type IntegerArray = Int8Array | Uint8Array | Int16Array | Uint16Array |
9
9
  export default function getRandomValues<TArray extends ArrayBufferView>(values: TArray): TArray;
10
10
  export declare function getRandomValuesInsecure<TArray extends IntegerArray>(values: TArray): TArray;
11
11
  export {};
12
+ //# sourceMappingURL=getRandomValues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRandomValues.d.ts","sourceRoot":"","sources":["../src/getRandomValues.ts"],"names":[],"mappings":"AAIA,aAAK,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"}
@@ -28,7 +28,7 @@ export default function getRandomValues(values) {
28
28
  // NOTE: Consider implementing `fillRandomBytes` to populate the given TypedArray directly
29
29
  randomBytes = getRandomBytes(values.byteLength);
30
30
  }
31
- catch (e) {
31
+ catch {
32
32
  // TODO: rethrow the error if it's not due to a lack of synchronous methods
33
33
  console.warn(`Random.getRandomBytes is not supported; falling back to insecure Math.random`);
34
34
  return 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,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,WAAuB,CAAC;IAC5B,IAAI;QACF,0FAA0F;QAC1F,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KACjD;IAAC,OAAO,CAAC,EAAE;QACV,2EAA2E;QAC3E,OAAO,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;QAC7F,OAAO,uBAAuB,CAAC,MAAM,CAAC,CAAC;KACxC;IAED,kGAAkG;IAClG,0EAA0E;IAC1E,MAAM,qBAAqB,GAAG,MAAM,CAAC,WAAsC,CAAC;IAC5E,MAAM,YAAY,GAAG,IAAI,qBAAqB,CAC5C,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,UAAU,EACtB,MAAM,CAAC,MAAM,CACd,CAAC;IAEF,wFAAwF;IACxF,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACzB,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 { 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 (e) {\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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M,EAClB,WAAW,CAAC,UAAU,EACtB,MAAM,CAAC,MAAM,CACd,CAAC;IAEF,wFAAwF;IACxF,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACzB,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 { 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"]}
package/build/index.d.ts CHANGED
@@ -4,3 +4,4 @@ declare class Crypto {
4
4
  declare const webCrypto: Crypto;
5
5
  export default webCrypto;
6
6
  export declare function polyfillWebCrypto(): void;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAM,MAAM;IACV,eAAe,CAAC,MAAM,SAAS,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;CAGxE;AAED,QAAA,MAAM,SAAS,QAAwD,CAAC;AAExE,eAAe,SAAS,CAAC;AAEzB,wBAAgB,iBAAiB,IAAI,IAAI,CAQxC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-standard-web-crypto",
3
- "version": "1.2.0",
3
+ "version": "1.3.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",
@@ -17,7 +17,7 @@
17
17
  "jest": {
18
18
  "preset": "expo-module-scripts"
19
19
  },
20
- "homepage": "https://github.com/expo/expo/blob/master/packages/expo-standard-web-crypto",
20
+ "homepage": "https://github.com/expo/expo/blob/main/packages/expo-standard-web-crypto",
21
21
  "repository": {
22
22
  "type": "git",
23
23
  "url": "https://github.com/expo/expo.git",
@@ -31,15 +31,15 @@
31
31
  "license": "MIT",
32
32
  "devDependencies": {
33
33
  "expo-module-scripts": "^2.0.0",
34
- "expo-random": "~12.1.0"
34
+ "expo-random": "~12.2.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "expo-random": "12.1.0"
37
+ "expo-random": "12.2.0"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "expo-random": {
41
41
  "optional": true
42
42
  }
43
43
  },
44
- "gitHead": "2e5c6983b86d5ecfca028ba64002897d8adc2cc4"
44
+ "gitHead": "22dce752354bb429c84851bc4389abe47a766b1f"
45
45
  }
@@ -56,7 +56,7 @@ export default function getRandomValues<TArray extends ArrayBufferView>(values:
56
56
  try {
57
57
  // NOTE: Consider implementing `fillRandomBytes` to populate the given TypedArray directly
58
58
  randomBytes = getRandomBytes(values.byteLength);
59
- } catch (e) {
59
+ } catch {
60
60
  // TODO: rethrow the error if it's not due to a lack of synchronous methods
61
61
  console.warn(`Random.getRandomBytes is not supported; falling back to insecure Math.random`);
62
62
  return getRandomValuesInsecure(values);