react-native-quick-crypto 0.7.10 → 0.7.11

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.
Files changed (55) hide show
  1. package/android/CMakeLists.txt +59 -62
  2. package/android/build.gradle +7 -7
  3. package/lib/commonjs/Algorithms.js +224 -0
  4. package/lib/commonjs/Algorithms.js.map +1 -0
  5. package/lib/commonjs/Hash.js +1 -1
  6. package/lib/commonjs/Hash.js.map +1 -1
  7. package/lib/commonjs/Hashnames.js +1 -1
  8. package/lib/commonjs/Hashnames.js.map +1 -1
  9. package/lib/commonjs/Utils.js +27 -235
  10. package/lib/commonjs/Utils.js.map +1 -1
  11. package/lib/commonjs/keys.js.map +1 -1
  12. package/lib/commonjs/pbkdf2.js +1 -1
  13. package/lib/commonjs/pbkdf2.js.map +1 -1
  14. package/lib/commonjs/random.js.map +1 -1
  15. package/lib/commonjs/subtle.js +7 -6
  16. package/lib/commonjs/subtle.js.map +1 -1
  17. package/lib/module/Algorithms.js +219 -0
  18. package/lib/module/Algorithms.js.map +1 -0
  19. package/lib/module/Hash.js +1 -1
  20. package/lib/module/Hash.js.map +1 -1
  21. package/lib/module/Hashnames.js +1 -1
  22. package/lib/module/Hashnames.js.map +1 -1
  23. package/lib/module/Utils.js +25 -230
  24. package/lib/module/Utils.js.map +1 -1
  25. package/lib/module/keys.js.map +1 -1
  26. package/lib/module/pbkdf2.js +1 -1
  27. package/lib/module/pbkdf2.js.map +1 -1
  28. package/lib/module/random.js.map +1 -1
  29. package/lib/module/subtle.js +2 -1
  30. package/lib/module/subtle.js.map +1 -1
  31. package/lib/typescript/src/Algorithms.d.ts +4 -0
  32. package/lib/typescript/src/Algorithms.d.ts.map +1 -0
  33. package/lib/typescript/src/Hashnames.d.ts +2 -2
  34. package/lib/typescript/src/Hashnames.d.ts.map +1 -1
  35. package/lib/typescript/src/Utils.d.ts +20 -8
  36. package/lib/typescript/src/Utils.d.ts.map +1 -1
  37. package/lib/typescript/src/index.d.ts +4 -4
  38. package/lib/typescript/src/index.d.ts.map +1 -1
  39. package/lib/typescript/src/keys.d.ts +5 -2
  40. package/lib/typescript/src/keys.d.ts.map +1 -1
  41. package/lib/typescript/src/random.d.ts +5 -6
  42. package/lib/typescript/src/random.d.ts.map +1 -1
  43. package/lib/typescript/src/sig.d.ts +1 -1
  44. package/lib/typescript/src/subtle.d.ts.map +1 -1
  45. package/package.json +40 -52
  46. package/react-native-quick-crypto.podspec +1 -1
  47. package/src/Algorithms.ts +247 -0
  48. package/src/Hash.ts +1 -1
  49. package/src/Hashnames.ts +4 -4
  50. package/src/Utils.ts +34 -279
  51. package/src/keys.ts +5 -1
  52. package/src/pbkdf2.ts +1 -1
  53. package/src/random.ts +16 -24
  54. package/src/subtle.ts +1 -2
  55. package/LICENSE +0 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-quick-crypto",
3
- "version": "0.7.10",
3
+ "version": "0.7.11",
4
4
  "description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
5
5
  "packageManager": "bun@1.1.26",
6
6
  "main": "lib/commonjs/index",
@@ -26,17 +26,16 @@
26
26
  "!**/__mocks__"
27
27
  ],
28
28
  "scripts": {
29
+ "clean": "del-cli android/build lib",
30
+ "deepclean": "del-cli node_modules",
29
31
  "tsc": "tsc --noEmit",
30
32
  "typescript": "tsc --noEmit",
31
33
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
32
34
  "lint:fix": "eslint \"**/*.{js,ts,tsx}\" --fix",
33
35
  "format": "prettier --check \"**/*.{js,ts,tsx}\"",
34
36
  "format:fix": "prettier --write \"**/*.{js,ts,tsx}\"",
35
- "prepare": "bob build",
37
+ "prepare": "bun clean && bun tsc && bob build",
36
38
  "release": "release-it",
37
- "example": "cd example && bun start",
38
- "pods": "cd example && bun install && bun pods",
39
- "bootstrap": "bun install && bun pods && bun example",
40
39
  "test": "jest"
41
40
  },
42
41
  "keywords": [
@@ -53,7 +52,11 @@
53
52
  "type": "git",
54
53
  "url": "git+https://github.com/margelo/react-native-quick-crypto.git"
55
54
  },
56
- "authors": "Szymon Kapała (szymon20000@gmail.com) & Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
55
+ "authors": [
56
+ "Szymon Kapała <szymon20000@gmail.com>",
57
+ "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
58
+ "Brad Anderson <brad@sankatygroup.com> (https://github.com/boorad)"
59
+ ],
57
60
  "license": "MIT",
58
61
  "bugs": {
59
62
  "url": "https://github.com/margelo/react-native-quick-crypto/issues"
@@ -71,69 +74,50 @@
71
74
  },
72
75
  "devDependencies": {
73
76
  "@eslint/compat": "^1.1.1",
74
- "@eslint/js": "10.0.0",
75
- "@react-native/babel-preset": "^0.75.0-main",
76
- "@react-native/eslint-config": "^0.75.0-main",
77
- "@react-native/eslint-plugin": "^0.75.0-main",
77
+ "@eslint/js": "9.17.0",
78
+ "@react-native/babel-preset": "0.76.5",
79
+ "@react-native/eslint-config": "0.76.5",
80
+ "@react-native/eslint-plugin": "0.76.5",
78
81
  "@release-it/conventional-changelog": "^9.0.3",
79
82
  "@types/jest": "^29.5.11",
80
83
  "@types/node": "^22.0.0",
81
84
  "@types/react": "^18.0.33",
82
85
  "@types/readable-stream": "^4.0.11",
86
+ "del-cli": "^6.0.0",
83
87
  "eslint": "9.15.0",
84
88
  "eslint-plugin-react-native": "^4.1.0",
85
89
  "jest": "^29.7.0",
86
90
  "prettier": "3.3.3",
87
- "react": "^18.2.0",
88
- "react-native": "^0.72.7",
89
- "react-native-builder-bob": "0.32.1",
90
- "release-it": "^17.2.0",
91
+ "react": "18.2.0",
92
+ "react-native": "0.72.7",
93
+ "react-native-builder-bob": "0.35.2",
94
+ "release-it": "17.11.0",
91
95
  "sscrypto": "^1.1.1",
92
- "typescript": "5.6.3",
93
- "typescript-eslint": "8.15.0"
94
- },
95
- "peerDependencies": {
96
- "react": "*",
97
- "react-native": "*"
96
+ "typescript": "5.7.2",
97
+ "typescript-eslint": "8.19.0"
98
98
  },
99
99
  "release-it": {
100
- "git": {
101
- "commitMessage": "chore: release ${version}",
102
- "tagName": "v${version}"
103
- },
104
100
  "npm": {
105
101
  "publish": true
106
102
  },
103
+ "git": false,
107
104
  "github": {
108
- "release": true
105
+ "release": false
106
+ },
107
+ "hooks": {
108
+ "after:bump": "bun tsc && bun lint && bun format && bun prepare"
109
109
  },
110
110
  "plugins": {
111
- "@release-it/conventional-changelog": {
112
- "preset": {
113
- "name": "conventionalcommits",
114
- "types": [
115
- {
116
- "type": "feat",
117
- "section": "✨ Features"
118
- },
119
- {
120
- "type": "fix",
121
- "section": "🐛 Bug Fixes"
122
- },
123
- {
124
- "type": "perf",
125
- "section": "💨 Performance Improvements"
126
- },
127
- {
128
- "type": "chore(deps)",
129
- "section": "🛠️ Dependency Upgrades"
130
- },
131
- {
132
- "type": "docs",
133
- "section": "📚 Documentation"
134
- }
135
- ]
136
- }
111
+ "@release-it/bumper": {
112
+ "out": [
113
+ {
114
+ "file": "../../packages/example/package.json",
115
+ "path": [
116
+ "version",
117
+ "dependencies.react-native-quick-crypto"
118
+ ]
119
+ }
120
+ ]
137
121
  }
138
122
  }
139
123
  },
@@ -150,5 +134,9 @@
150
134
  }
151
135
  ]
152
136
  ]
153
- }
137
+ },
138
+ "workspaces": [
139
+ ".",
140
+ "example"
141
+ ]
154
142
  }
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.authors = package["authors"]
12
12
 
13
13
  s.platforms = { :ios => "12.4", :tvos => "12.0", :osx => "10.14" }
14
- s.source = { :git => "https://github.com/mrousavy/react-native-quick-crypto.git", :tag => "#{s.version}" }
14
+ s.source = { :git => "https://github.com/margelo/react-native-quick-crypto.git", :tag => "#{s.version}" }
15
15
 
16
16
  s.source_files = [
17
17
  "ios/**/*.{h,m,mm}",
@@ -0,0 +1,247 @@
1
+ import type {
2
+ AnyAlgorithm,
3
+ DeriveBitsAlgorithm,
4
+ DigestAlgorithm,
5
+ EncryptDecryptAlgorithm,
6
+ EncryptDecryptParams,
7
+ KeyPairAlgorithm,
8
+ SecretKeyAlgorithm,
9
+ SignVerifyAlgorithm,
10
+ SubtleAlgorithm,
11
+ } from './keys';
12
+
13
+ type SupportedAlgorithm<Type extends string> = {
14
+ [key in Type]: string | null;
15
+ };
16
+
17
+ type SupportedAlgorithms = {
18
+ digest: SupportedAlgorithm<DigestAlgorithm>;
19
+ generateKey: SupportedAlgorithm<KeyPairAlgorithm | SecretKeyAlgorithm>;
20
+ sign: SupportedAlgorithm<SignVerifyAlgorithm>;
21
+ verify: SupportedAlgorithm<SignVerifyAlgorithm>;
22
+ importKey: SupportedAlgorithm<
23
+ KeyPairAlgorithm | 'PBKDF2' | SecretKeyAlgorithm | 'HKDF'
24
+ >;
25
+ deriveBits: SupportedAlgorithm<DeriveBitsAlgorithm>;
26
+ encrypt: SupportedAlgorithm<EncryptDecryptAlgorithm>;
27
+ decrypt: SupportedAlgorithm<EncryptDecryptAlgorithm>;
28
+ 'get key length': SupportedAlgorithm<SecretKeyAlgorithm | 'PBKDF2' | 'HKDF'>;
29
+ wrapKey: SupportedAlgorithm<'AES-KW'>;
30
+ unwrapKey: SupportedAlgorithm<'AES-KW'>;
31
+ };
32
+
33
+ export type Operation =
34
+ | 'digest'
35
+ | 'generateKey'
36
+ | 'sign'
37
+ | 'verify'
38
+ | 'importKey'
39
+ | 'deriveBits'
40
+ | 'encrypt'
41
+ | 'decrypt'
42
+ | 'get key length'
43
+ | 'wrapKey'
44
+ | 'unwrapKey';
45
+
46
+ const kSupportedAlgorithms: SupportedAlgorithms = {
47
+ digest: {
48
+ 'SHA-1': null,
49
+ 'SHA-256': null,
50
+ 'SHA-384': null,
51
+ 'SHA-512': null,
52
+ },
53
+ generateKey: {
54
+ 'RSASSA-PKCS1-v1_5': 'RsaHashedKeyGenParams',
55
+ 'RSA-PSS': 'RsaHashedKeyGenParams',
56
+ 'RSA-OAEP': 'RsaHashedKeyGenParams',
57
+ ECDSA: 'EcKeyGenParams',
58
+ ECDH: 'EcKeyGenParams',
59
+ 'AES-CTR': 'AesKeyGenParams',
60
+ 'AES-CBC': 'AesKeyGenParams',
61
+ 'AES-GCM': 'AesKeyGenParams',
62
+ 'AES-KW': 'AesKeyGenParams',
63
+ HMAC: 'HmacKeyGenParams',
64
+ X25519: null,
65
+ Ed25519: null,
66
+ X448: null,
67
+ Ed448: null,
68
+ },
69
+ sign: {
70
+ 'RSASSA-PKCS1-v1_5': null,
71
+ 'RSA-PSS': 'RsaPssParams',
72
+ ECDSA: 'EcdsaParams',
73
+ HMAC: null,
74
+ Ed25519: null,
75
+ Ed448: 'Ed448Params',
76
+ },
77
+ verify: {
78
+ 'RSASSA-PKCS1-v1_5': null,
79
+ 'RSA-PSS': 'RsaPssParams',
80
+ ECDSA: 'EcdsaParams',
81
+ HMAC: null,
82
+ Ed25519: null,
83
+ Ed448: 'Ed448Params',
84
+ },
85
+ importKey: {
86
+ 'RSASSA-PKCS1-v1_5': 'RsaHashedImportParams',
87
+ 'RSA-PSS': 'RsaHashedImportParams',
88
+ 'RSA-OAEP': 'RsaHashedImportParams',
89
+ ECDSA: 'EcKeyImportParams',
90
+ ECDH: 'EcKeyImportParams',
91
+ HMAC: 'HmacImportParams',
92
+ HKDF: null,
93
+ PBKDF2: null,
94
+ 'AES-CTR': null,
95
+ 'AES-CBC': null,
96
+ 'AES-GCM': null,
97
+ 'AES-KW': null,
98
+ Ed25519: null,
99
+ X25519: null,
100
+ Ed448: null,
101
+ X448: null,
102
+ },
103
+ deriveBits: {
104
+ HKDF: 'HkdfParams',
105
+ PBKDF2: 'Pbkdf2Params',
106
+ ECDH: 'EcdhKeyDeriveParams',
107
+ X25519: 'EcdhKeyDeriveParams',
108
+ X448: 'EcdhKeyDeriveParams',
109
+ },
110
+ encrypt: {
111
+ 'RSA-OAEP': 'RsaOaepParams',
112
+ 'AES-CBC': 'AesCbcParams',
113
+ 'AES-GCM': 'AesGcmParams',
114
+ 'AES-CTR': 'AesCtrParams',
115
+ },
116
+ decrypt: {
117
+ 'RSA-OAEP': 'RsaOaepParams',
118
+ 'AES-CBC': 'AesCbcParams',
119
+ 'AES-GCM': 'AesGcmParams',
120
+ 'AES-CTR': 'AesCtrParams',
121
+ },
122
+ 'get key length': {
123
+ 'AES-CBC': 'AesDerivedKeyParams',
124
+ 'AES-CTR': 'AesDerivedKeyParams',
125
+ 'AES-GCM': 'AesDerivedKeyParams',
126
+ 'AES-KW': 'AesDerivedKeyParams',
127
+ HMAC: 'HmacImportParams',
128
+ HKDF: null,
129
+ PBKDF2: null,
130
+ },
131
+ wrapKey: {
132
+ 'AES-KW': null,
133
+ },
134
+ unwrapKey: {
135
+ 'AES-KW': null,
136
+ },
137
+ };
138
+
139
+ type AlgorithmDictionaries = {
140
+ [key in string]: object;
141
+ };
142
+
143
+ const simpleAlgorithmDictionaries: AlgorithmDictionaries = {
144
+ AesGcmParams: { iv: 'BufferSource', additionalData: 'BufferSource' },
145
+ RsaHashedKeyGenParams: { hash: 'HashAlgorithmIdentifier' },
146
+ EcKeyGenParams: {},
147
+ HmacKeyGenParams: { hash: 'HashAlgorithmIdentifier' },
148
+ RsaPssParams: {},
149
+ EcdsaParams: { hash: 'HashAlgorithmIdentifier' },
150
+ HmacImportParams: { hash: 'HashAlgorithmIdentifier' },
151
+ HkdfParams: {
152
+ hash: 'HashAlgorithmIdentifier',
153
+ salt: 'BufferSource',
154
+ info: 'BufferSource',
155
+ },
156
+ Ed448Params: { context: 'BufferSource' },
157
+ Pbkdf2Params: { hash: 'HashAlgorithmIdentifier', salt: 'BufferSource' },
158
+ RsaOaepParams: { label: 'BufferSource' },
159
+ RsaHashedImportParams: { hash: 'HashAlgorithmIdentifier' },
160
+ EcKeyImportParams: {},
161
+ };
162
+
163
+ // https://w3c.github.io/webcrypto/#algorithm-normalization-normalize-an-algorithm
164
+ // adapted for Node.js from Deno's implementation
165
+ // https://github.com/denoland/deno/blob/v1.29.1/ext/crypto/00_crypto.js#L195
166
+ export const normalizeAlgorithm = (
167
+ algorithm: SubtleAlgorithm | EncryptDecryptParams | AnyAlgorithm,
168
+ op: Operation,
169
+ ): SubtleAlgorithm | EncryptDecryptParams => {
170
+ if (typeof algorithm === 'string') {
171
+ return normalizeAlgorithm({ name: algorithm }, op);
172
+ }
173
+
174
+ // 1.
175
+ const registeredAlgorithms = kSupportedAlgorithms[op];
176
+ // 2. 3.
177
+ // commented, because typescript takes care of this for us 🤞👀
178
+ // const initialAlg = webidl.converters.Algorithm(algorithm, {
179
+ // prefix: 'Failed to normalize algorithm',
180
+ // context: 'passed algorithm',
181
+ // });
182
+
183
+ // 4.
184
+ let algName = algorithm.name;
185
+ if (algName === undefined) return { name: 'unknown' };
186
+
187
+ // 5.
188
+ let desiredType: string | null | undefined;
189
+ for (const key in registeredAlgorithms) {
190
+ if (!Object.prototype.hasOwnProperty.call(registeredAlgorithms, key)) {
191
+ continue;
192
+ }
193
+ if (key.toUpperCase() === algName.toUpperCase()) {
194
+ algName = key as AnyAlgorithm;
195
+ desiredType = (
196
+ registeredAlgorithms as Record<string, typeof desiredType>
197
+ )[algName];
198
+ }
199
+ }
200
+ if (desiredType === undefined)
201
+ throw new Error(`Unrecognized algorithm name: ${algName}`);
202
+
203
+ // Fast path everything below if the registered dictionary is null
204
+ if (desiredType === null) return { name: algName };
205
+
206
+ // 6.
207
+ const normalizedAlgorithm = algorithm;
208
+ // TODO: implement this? Maybe via typescript?
209
+ // webidl.converters[desiredType](algorithm, {
210
+ // prefix: 'Failed to normalize algorithm',
211
+ // context: 'passed algorithm',
212
+ // });
213
+ // 7.
214
+ normalizedAlgorithm.name = algName;
215
+
216
+ // 9.
217
+ const dict = simpleAlgorithmDictionaries[desiredType];
218
+ // 10.
219
+ const dictKeys = dict ? Object.keys(dict) : [];
220
+ for (let i = 0; i < dictKeys.length; i++) {
221
+ const member = dictKeys[i] || '';
222
+ if (!Object.prototype.hasOwnProperty.call(dict, member)) continue;
223
+ // TODO: implement this? Maybe via typescript?
224
+ // const idlType = dict[member];
225
+ // const idlValue = normalizedAlgorithm[member];
226
+ // 3.
227
+ // if (idlType === 'BufferSource' && idlValue) {
228
+ // const isView = ArrayBufferIsView(idlValue);
229
+ // normalizedAlgorithm[member] = TypedArrayPrototypeSlice(
230
+ // new Uint8Array(
231
+ // isView ? getDataViewOrTypedArrayBuffer(idlValue) : idlValue,
232
+ // isView ? getDataViewOrTypedArrayByteOffset(idlValue) : 0,
233
+ // isView
234
+ // ? getDataViewOrTypedArrayByteLength(idlValue)
235
+ // : ArrayBufferPrototypeGetByteLength(idlValue)
236
+ // )
237
+ // );
238
+ // } else if (idlType === 'HashAlgorithmIdentifier') {
239
+ // normalizedAlgorithm[member] = normalizeAlgorithm(idlValue, 'digest');
240
+ // } else if (idlType === 'AlgorithmIdentifier') {
241
+ // // This extension point is not used by any supported algorithm (yet?)
242
+ // throw lazyDOMException('Not implemented.', 'NotSupportedError');
243
+ // }
244
+ }
245
+
246
+ return normalizedAlgorithm;
247
+ };
package/src/Hash.ts CHANGED
@@ -135,5 +135,5 @@ const internalDigest = (
135
135
  const normalizedHashName = normalizeHashName(algorithm.name);
136
136
  const hash = new Hash(normalizedHashName);
137
137
  hash.update(bufferLikeToArrayBuffer(data));
138
- return hash.digest();
138
+ return toArrayBuffer(hash.digest());
139
139
  };
package/src/Hashnames.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { HashAlgorithm, SubtleAlgorithm } from './keys';
1
+ import type { HashAlgorithmIdentifier, HashAlgorithm } from './keys';
2
2
 
3
3
  export enum HashContext {
4
4
  Node,
@@ -79,7 +79,7 @@ const kHashNames: HashNames = {
79
79
  }
80
80
 
81
81
  export function normalizeHashName(
82
- algo: string | HashAlgorithm | SubtleAlgorithm | undefined,
82
+ algo: string | HashAlgorithm | HashAlgorithmIdentifier | undefined,
83
83
  context: HashContext = HashContext.Node,
84
84
  ): HashAlgorithm {
85
85
  if (typeof algo !== 'undefined') {
@@ -91,8 +91,8 @@ export function normalizeHashName(
91
91
  const alias = kHashNames[normAlgo]![context] as HashAlgorithm;
92
92
  if (alias) return alias;
93
93
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
94
- } catch (_e) {
95
- // ignore
94
+ } catch (_e: unknown) {
95
+ /* empty */
96
96
  }
97
97
  }
98
98
  throw new Error(`Invalid Hash Algorithm: ${algo}`);