expo-standard-web-crypto 1.0.1 → 1.2.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
@@ -13,7 +13,7 @@ First follow the instructions for installing [`expo-random`](https://github.com/
13
13
  ### Add the package to your npm dependencies
14
14
 
15
15
  ```
16
- npm install expo-standard-crypto
16
+ npm install expo-standard-web-crypto
17
17
  ```
18
18
 
19
19
  ### Using the polyfill
@@ -51,10 +51,7 @@ export function getRandomValuesInsecure(values) {
51
51
  return values;
52
52
  }
53
53
  class QuotaExceededError extends Error {
54
- constructor() {
55
- super(...arguments);
56
- this.name = 'QuotaExceededError';
57
- this.code = 22; // QUOTA_EXCEEDED_ERR
58
- }
54
+ name = 'QuotaExceededError';
55
+ code = 22; // QUOTA_EXCEEDED_ERR
59
56
  }
60
57
  //# sourceMappingURL=getRandomValues.js.map
@@ -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,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AC;QAC5B,SAAI,GAAG,EAAE,CAAC,CAAC,qBAAqB;IAClC,CAAC;CAAA","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":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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ytes } 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"]}
package/build/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  declare class Crypto {
2
2
  getRandomValues<TArray extends ArrayBufferView>(values: TArray): TArray;
3
3
  }
4
- declare const webCrypto: Crypto | globalThis.Crypto;
4
+ declare const webCrypto: Crypto;
5
5
  export default webCrypto;
6
6
  export declare function polyfillWebCrypto(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-standard-web-crypto",
3
- "version": "1.0.1",
3
+ "version": "1.2.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,15 @@
31
31
  "license": "MIT",
32
32
  "devDependencies": {
33
33
  "expo-module-scripts": "^2.0.0",
34
- "expo-random": "~11.1.0"
34
+ "expo-random": "~12.1.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "expo-random": "11.1.0"
37
+ "expo-random": "12.1.0"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "expo-random": {
41
41
  "optional": true
42
42
  }
43
43
  },
44
- "gitHead": "5b57d1fd0a20294c1dec7c43b5df34dd6425d1a5"
44
+ "gitHead": "2e5c6983b86d5ecfca028ba64002897d8adc2cc4"
45
45
  }