@symbiote-native/standard-web-crypto 3.0.0 → 3.0.1
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 +23 -5
- package/build/core/web-crypto.js +13 -0
- package/build-ngc/core/web-crypto.js +13 -0
- package/build-ngc/core/web-crypto.js.map +1 -1
- package/package.json +15 -15
- package/src/core/web-crypto.ts +17 -0
package/README.md
CHANGED
|
@@ -15,13 +15,29 @@ plain re-exports of the same `core`.
|
|
|
15
15
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
18
|
+
**New app:**
|
|
19
|
+
|
|
18
20
|
```bash
|
|
19
|
-
|
|
21
|
+
npx @symbiote-native/cli new my-app --standard-web-crypto
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Existing SymbioteNative app:**
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx @symbiote-native/cli add --standard-web-crypto
|
|
20
28
|
```
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
Either way: installs `@symbiote-native/standard-web-crypto` + `@symbiote-native/crypto` and wires
|
|
31
|
+
the latter's native autolinking automatically — see [`@symbiote-native/cli`](../cli). This package
|
|
32
|
+
has no native module of its own; `@symbiote-native/crypto` does the actual native random-byte
|
|
33
|
+
generation.
|
|
34
|
+
|
|
35
|
+
<details>
|
|
36
|
+
<summary>Manual install (no CLI — installing and wiring native autolinking by hand)</summary>
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install @symbiote-native/standard-web-crypto @symbiote-native/crypto
|
|
40
|
+
```
|
|
25
41
|
|
|
26
42
|
`@symbiote-native/crypto` comes along as a regular dependency and does the actual native random-byte
|
|
27
43
|
generation — see [its README](../crypto/README.md) for `expo-crypto`'s own native autolinking
|
|
@@ -30,6 +46,8 @@ requirements (already satisfied in any app that already wires up `@symbiote-nati
|
|
|
30
46
|
|
|
31
47
|
No further native wiring is needed for this package itself — it has no native module of its own.
|
|
32
48
|
|
|
49
|
+
</details>
|
|
50
|
+
|
|
33
51
|
## Shape
|
|
34
52
|
|
|
35
53
|
```
|
|
@@ -41,7 +59,7 @@ src/angular/ @symbiote-native/standard-web-crypto/angular — export * from '..
|
|
|
41
59
|
|
|
42
60
|
`./react`, `./vue`, `./svelte`, and `./solid` are `exports`-map aliases straight onto `src/core/` —
|
|
43
61
|
no physical per-framework file, since there's nothing to subscribe to or clean up. (The `webCrypto`
|
|
44
|
-
named re-export used to
|
|
62
|
+
named re-export used to be duplicated across those per-framework barrels; it now lives once in
|
|
45
63
|
`src/core/index.ts` instead.) `./angular` stays a physical file/subpath since Angular ships
|
|
46
64
|
through a separate `ngc`/AOT build (`build-ngc/`).
|
|
47
65
|
|
package/build/core/web-crypto.js
CHANGED
|
@@ -18,11 +18,24 @@ function isSupportedTypedArray(value) {
|
|
|
18
18
|
value instanceof Int32Array ||
|
|
19
19
|
value instanceof Uint32Array);
|
|
20
20
|
}
|
|
21
|
+
// Upstream's own getRandomValues.ts enforces this per the W3C spec
|
|
22
|
+
// (https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues) regardless of what the
|
|
23
|
+
// underlying native call can actually handle — @symbiote-native/crypto's getRandomValues has no
|
|
24
|
+
// length limit of its own, so without this check an oversized view would sail straight through to
|
|
25
|
+
// the native module instead of failing the same way a real Web Crypto implementation does.
|
|
26
|
+
const MAX_RANDOM_BYTES = 65_536;
|
|
27
|
+
class QuotaExceededError extends Error {
|
|
28
|
+
name = 'QuotaExceededError';
|
|
29
|
+
code = 22; // QUOTA_EXCEEDED_ERR
|
|
30
|
+
}
|
|
21
31
|
class Crypto {
|
|
22
32
|
getRandomValues(values) {
|
|
23
33
|
if (!isSupportedTypedArray(values)) {
|
|
24
34
|
throw new TypeError('The provided ArrayBuffer view is not a supported integer-typed array');
|
|
25
35
|
}
|
|
36
|
+
if (values.byteLength > MAX_RANDOM_BYTES) {
|
|
37
|
+
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})`);
|
|
38
|
+
}
|
|
26
39
|
return getNativeRandomValues(values);
|
|
27
40
|
}
|
|
28
41
|
}
|
|
@@ -18,11 +18,24 @@ function isSupportedTypedArray(value) {
|
|
|
18
18
|
value instanceof Int32Array ||
|
|
19
19
|
value instanceof Uint32Array);
|
|
20
20
|
}
|
|
21
|
+
// Upstream's own getRandomValues.ts enforces this per the W3C spec
|
|
22
|
+
// (https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues) regardless of what the
|
|
23
|
+
// underlying native call can actually handle — @symbiote-native/crypto's getRandomValues has no
|
|
24
|
+
// length limit of its own, so without this check an oversized view would sail straight through to
|
|
25
|
+
// the native module instead of failing the same way a real Web Crypto implementation does.
|
|
26
|
+
const MAX_RANDOM_BYTES = 65_536;
|
|
27
|
+
class QuotaExceededError extends Error {
|
|
28
|
+
name = 'QuotaExceededError';
|
|
29
|
+
code = 22; // QUOTA_EXCEEDED_ERR
|
|
30
|
+
}
|
|
21
31
|
class Crypto {
|
|
22
32
|
getRandomValues(values) {
|
|
23
33
|
if (!isSupportedTypedArray(values)) {
|
|
24
34
|
throw new TypeError('The provided ArrayBuffer view is not a supported integer-typed array');
|
|
25
35
|
}
|
|
36
|
+
if (values.byteLength > MAX_RANDOM_BYTES) {
|
|
37
|
+
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})`);
|
|
38
|
+
}
|
|
26
39
|
return getNativeRandomValues(values);
|
|
27
40
|
}
|
|
28
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-crypto.js","sourceRoot":"","sources":["../../src/core/web-crypto.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,+FAA+F;AAC/F,mGAAmG;AACnG,+FAA+F;AAC/F,kGAAkG;AAClG,4FAA4F;AAC5F,iBAAiB;A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,UAAU,oEAAoE,gBAAgB,GAAG,CAChJ,CAAC;QACJ,CAAC;QACD,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;CACF;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CACL,iBAAiB,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,eAAe,KAAK,UAAU,CAC1E,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,iGAAiG;AACjG,gGAAgG;AAChG,4EAA4E;AAC5E,SAAS,gBAAgB;IACvB,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACzD,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAChD,CAAC;AAED,MAAM,SAAS,GAAe,gBAAgB,EAAE,IAAI,IAAI,MAAM,EAAE,CAAC;AAEjE,eAAe,SAAS,CAAC;AAEzB,MAAM,UAAU,iBAAiB;IAC/B,IAAI,gBAAgB,EAAE,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE;YAC1C,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,IAAI;YAChB,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS;SACrB,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbiote-native/standard-web-crypto",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "expo-standard-web-crypto ported for SymbioteNative — a Web Crypto API getRandomValues polyfill built on @symbiote-native/crypto's native random source.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@symbiote-native/crypto": "3.0.
|
|
71
|
+
"@symbiote-native/crypto": "3.0.1"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@angular/core": ">=20",
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
"solid-js": ">=1.9.0",
|
|
79
79
|
"svelte": ">=5.56.0",
|
|
80
80
|
"vue": ">=3.5.0",
|
|
81
|
-
"@symbiote-native/angular": "^3.
|
|
82
|
-
"@symbiote-native/engine": "^1.
|
|
83
|
-
"@symbiote-native/react": "^3.0.
|
|
84
|
-
"@symbiote-native/solid": "^3.0.
|
|
85
|
-
"@symbiote-native/svelte": "^3.0.
|
|
86
|
-
"@symbiote-native/vue": "^3.0.
|
|
81
|
+
"@symbiote-native/angular": "^3.1.1",
|
|
82
|
+
"@symbiote-native/engine": "^1.3.0",
|
|
83
|
+
"@symbiote-native/react": "^3.0.3",
|
|
84
|
+
"@symbiote-native/solid": "^3.0.3",
|
|
85
|
+
"@symbiote-native/svelte": "^3.0.3",
|
|
86
|
+
"@symbiote-native/vue": "^3.0.3"
|
|
87
87
|
},
|
|
88
88
|
"peerDependenciesMeta": {
|
|
89
89
|
"@symbiote-native/angular": {
|
|
@@ -131,13 +131,13 @@
|
|
|
131
131
|
"solid-js": "^1.9.14",
|
|
132
132
|
"svelte": "^5.56.0",
|
|
133
133
|
"typescript": "~6.0.0",
|
|
134
|
-
"@symbiote-native/angular": "3.
|
|
135
|
-
"@symbiote-native/engine": "1.
|
|
136
|
-
"@symbiote-native/react": "3.0.
|
|
137
|
-
"@symbiote-native/solid": "3.0.
|
|
138
|
-
"@symbiote-native/svelte": "3.0.
|
|
139
|
-
"@symbiote-native/test-utils": "0.3
|
|
140
|
-
"@symbiote-native/vue": "3.0.
|
|
134
|
+
"@symbiote-native/angular": "3.1.1",
|
|
135
|
+
"@symbiote-native/engine": "1.3.0",
|
|
136
|
+
"@symbiote-native/react": "3.0.3",
|
|
137
|
+
"@symbiote-native/solid": "3.0.3",
|
|
138
|
+
"@symbiote-native/svelte": "3.0.3",
|
|
139
|
+
"@symbiote-native/test-utils": "0.4.3",
|
|
140
|
+
"@symbiote-native/vue": "3.0.3"
|
|
141
141
|
},
|
|
142
142
|
"scripts": {
|
|
143
143
|
"typecheck": "tsc --build",
|
package/src/core/web-crypto.ts
CHANGED
|
@@ -27,6 +27,18 @@ function isSupportedTypedArray(value: ArrayBufferView): value is ITypedArray {
|
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
// Upstream's own getRandomValues.ts enforces this per the W3C spec
|
|
31
|
+
// (https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues) regardless of what the
|
|
32
|
+
// underlying native call can actually handle — @symbiote-native/crypto's getRandomValues has no
|
|
33
|
+
// length limit of its own, so without this check an oversized view would sail straight through to
|
|
34
|
+
// the native module instead of failing the same way a real Web Crypto implementation does.
|
|
35
|
+
const MAX_RANDOM_BYTES = 65_536;
|
|
36
|
+
|
|
37
|
+
class QuotaExceededError extends Error {
|
|
38
|
+
override name = 'QuotaExceededError';
|
|
39
|
+
code = 22; // QUOTA_EXCEEDED_ERR
|
|
40
|
+
}
|
|
41
|
+
|
|
30
42
|
class Crypto implements IWebCrypto {
|
|
31
43
|
getRandomValues<TArray extends ArrayBufferView>(values: TArray): TArray {
|
|
32
44
|
if (!isSupportedTypedArray(values)) {
|
|
@@ -34,6 +46,11 @@ class Crypto implements IWebCrypto {
|
|
|
34
46
|
'The provided ArrayBuffer view is not a supported integer-typed array',
|
|
35
47
|
);
|
|
36
48
|
}
|
|
49
|
+
if (values.byteLength > MAX_RANDOM_BYTES) {
|
|
50
|
+
throw new QuotaExceededError(
|
|
51
|
+
`The ArrayBuffer view's byte length (${values.byteLength}) exceeds the number of bytes of entropy available via this API (${MAX_RANDOM_BYTES})`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
37
54
|
return getNativeRandomValues(values);
|
|
38
55
|
}
|
|
39
56
|
}
|