@onekeyfe/react-native-aes-crypto 6.7.0-6 → 6.7.0-60
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 +126 -55
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,82 +1,153 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
authenticated GCM operations, PBKDF2, HMAC, hashing and random values.
|
|
3
|
+
# @onekeyfe/react-native-aes-crypto
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
**Native AES, PBKDF2, HMAC, hashing and random-value primitives for OneKey apps on iOS and Android.**
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-aes-crypto)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
functions return promises and depend on the native TurboModule.
|
|
13
|
+
</div>
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
Exposes the crypto primitives OneKey needs without a JavaScript crypto
|
|
16
|
+
implementation: AES-CBC/CTR encryption, AES-GCM authenticated encryption,
|
|
17
|
+
PBKDF2, HMAC-SHA256/512, SHA-1/256/512 and random values. Every call crosses a
|
|
18
|
+
React Native TurboModule and returns a promise; the module has no Web
|
|
19
|
+
implementation. Applications still own key storage, nonce uniqueness and the
|
|
20
|
+
decision of when a failure is fatal.
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
const randomBytes = await randomKey(32);
|
|
20
|
-
```
|
|
22
|
+
## Features
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
- **Audited-style AEAD surface** — AES-GCM with a stricter-than-RFC contract:
|
|
25
|
+
12-byte nonce, non-empty AAD, and ciphertext with a trailing 16-byte tag.
|
|
26
|
+
- **Cross-platform byte compatibility** — iOS CryptoKit/CommonCrypto and Android
|
|
27
|
+
JCE/BouncyCastle are pinned to the same formats, so ciphertexts match.
|
|
28
|
+
- **Symmetric helpers** — AES-128/192/256 in CBC (PKCS#7) and CTR modes with hex
|
|
29
|
+
input and hex output.
|
|
30
|
+
- **Key derivation and MACs** — PBKDF2 with SHA-1/256/512 PRFs, HMAC-SHA256 and
|
|
31
|
+
HMAC-SHA512.
|
|
32
|
+
- **Random values** — `randomUuid()` and a cryptographically secure
|
|
33
|
+
`randomKey(length)`.
|
|
34
|
+
- **Fail-loud validation** — empty, malformed or non-integer arguments reject
|
|
35
|
+
with a stable error code instead of producing zero-length input.
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
`pbkdf2`, `hmac256`, `hmac512`, `sha1`, `sha256`, `sha512`, `randomUuid` and
|
|
26
|
-
`randomKey`. The default export is the native module.
|
|
37
|
+
## Installation
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
inputs or authentication tag are invalid. Those formats are specific to the
|
|
32
|
-
GCM helpers; do not assume that every other method uses the same encoding.
|
|
39
|
+
```sh
|
|
40
|
+
yarn add @onekeyfe/react-native-aes-crypto
|
|
41
|
+
```
|
|
33
42
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
Install the application's iOS pods and rebuild the native binary; this package is
|
|
44
|
+
a TurboModule, so a JavaScript-only install does not register it. The iOS pod
|
|
45
|
+
links `Security` and `CryptoKit`; Android resolves its dependencies through
|
|
46
|
+
autolinking. No permissions or `Info.plist` keys are required.
|
|
37
47
|
|
|
38
|
-
##
|
|
48
|
+
## Usage
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
```ts
|
|
51
|
+
import {
|
|
52
|
+
sha256,
|
|
53
|
+
randomKey,
|
|
54
|
+
aesGcmEncrypt,
|
|
55
|
+
aesGcmDecrypt,
|
|
56
|
+
} from '@onekeyfe/react-native-aes-crypto';
|
|
57
|
+
|
|
58
|
+
// Every string argument is hex-encoded bytes; every result is hex.
|
|
59
|
+
const digest = await sha256('68656c6c6f');
|
|
60
|
+
|
|
61
|
+
const key = await randomKey(32); // 32 random bytes, 64 hex characters
|
|
62
|
+
const nonce = await randomKey(12); // GCM requires exactly 12 nonce bytes
|
|
63
|
+
const sealed = await aesGcmEncrypt('deadbeef', key, nonce, '0102');
|
|
64
|
+
const opened = await aesGcmDecrypt(sealed, key, nonce, '0102');
|
|
65
|
+
|
|
66
|
+
console.log(digest, opened); // opened === 'deadbeef'
|
|
67
|
+
```
|
|
45
68
|
|
|
46
|
-
The
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
69
|
+
The application owns key storage, nonce uniqueness and long-term encoding of the
|
|
70
|
+
hex strings; the module does not persist anything.
|
|
71
|
+
|
|
72
|
+
## API
|
|
73
|
+
|
|
74
|
+
| Export | Signature | Platforms | Description |
|
|
75
|
+
| --- | --- | :-: | --- |
|
|
76
|
+
| `encrypt` | `(data, key, iv, algorithm) => Promise<string>` | iOS, Android | AES encrypt; `algorithm` is `aes-128-cbc`, `aes-192-cbc`, `aes-256-cbc`, or the matching `-ctr` name. |
|
|
77
|
+
| `decrypt` | `(ciphertext, key, iv, algorithm) => Promise<string>` | iOS, Android | Inverse of `encrypt`; returns hex. |
|
|
78
|
+
| `aesGcmEncrypt` | `(data, key, nonce, aad) => Promise<string>` | iOS, Android | Returns hex `ciphertext || 16-byte tag`; empty plaintext is allowed. |
|
|
79
|
+
| `aesGcmDecrypt` | `(ciphertextWithTag, key, nonce, aad) => Promise<string>` | iOS, Android | Verifies the tag; parameters must match the encryption call byte for byte. |
|
|
80
|
+
| `pbkdf2` | `(password, salt, cost, length, algorithm) => Promise<string>` | iOS, Android | PBKDF2; `length` is in bits, `algorithm` is `sha1`, `sha256` or `sha512`. |
|
|
81
|
+
| `hmac256` | `(data, key) => Promise<string>` | iOS, Android | HMAC-SHA256 over hex-decoded bytes. |
|
|
82
|
+
| `hmac512` | `(data, key) => Promise<string>` | iOS, Android | HMAC-SHA512 over hex-decoded bytes. |
|
|
83
|
+
| `sha1` | `(text) => Promise<string>` | iOS, Android | SHA-1 digest of hex-decoded bytes. |
|
|
84
|
+
| `sha256` | `(text) => Promise<string>` | iOS, Android | SHA-256 digest of hex-decoded bytes. |
|
|
85
|
+
| `sha512` | `(text) => Promise<string>` | iOS, Android | SHA-512 digest of hex-decoded bytes. |
|
|
86
|
+
| `randomUuid` | `() => Promise<string>` | iOS, Android | Random UUID string. |
|
|
87
|
+
| `randomKey` | `(length) => Promise<string>` | iOS, Android | `length` secure random bytes, returned as hex. |
|
|
88
|
+
|
|
89
|
+
All failures reject with code `"-1"`. The default export is the raw TurboModule;
|
|
90
|
+
named exports wrap the same methods. See
|
|
91
|
+
[`src/NativeAesCrypto.ts`](src/NativeAesCrypto.ts) for the bridge contract and
|
|
92
|
+
[`src/index.tsx`](src/index.tsx) for the documented GCM rules.
|
|
93
|
+
|
|
94
|
+
## Platform support
|
|
95
|
+
|
|
96
|
+
| Capability | iOS | Android | Web |
|
|
97
|
+
| --- | :-: | :-: | :-: |
|
|
98
|
+
| AES-CBC / AES-CTR encrypt and decrypt | ✅ | ✅ | — |
|
|
99
|
+
| AES-GCM authenticated encryption | ✅ | ✅ | — |
|
|
100
|
+
| PBKDF2 | ✅ | ✅ | — |
|
|
101
|
+
| HMAC-SHA256 / HMAC-SHA512 | ✅ | ✅ | — |
|
|
102
|
+
| SHA-1 / SHA-256 / SHA-512 | ✅ | ✅ | — |
|
|
103
|
+
| Random UUID and random bytes | ✅ | ✅ | — |
|
|
104
|
+
|
|
105
|
+
## Caveats
|
|
106
|
+
|
|
107
|
+
> [!IMPORTANT]
|
|
108
|
+
> String arguments are not UTF-8 text: they are hex-encoded byte arrays. Pass
|
|
109
|
+
> `'68656c6c6f'`, not `'hello'`, to `sha256`, HMAC and AES functions; malformed
|
|
110
|
+
> hex rejects instead of hashing the literal string.
|
|
111
|
+
|
|
112
|
+
> [!WARNING]
|
|
113
|
+
> GCM is deliberately stricter than RFC 5116: the nonce is exactly 12 bytes, AAD
|
|
114
|
+
> must be non-empty, the key must decode to 16, 24 or 32 bytes, and the
|
|
115
|
+
> ciphertext passed to decryption must include the 16-byte tag. Any mismatch
|
|
116
|
+
> rejects as a tag-verification failure.
|
|
117
|
+
|
|
118
|
+
> [!NOTE]
|
|
119
|
+
> PBKDF2 `length` is in bits and `cost`/`length` must be positive integers. Never
|
|
120
|
+
> reuse a GCM nonce with the same key.
|
|
121
|
+
|
|
122
|
+
## References
|
|
123
|
+
|
|
124
|
+
- [Changelog](../../CHANGELOG.md)
|
|
51
125
|
|
|
52
126
|
## Upstream attribution
|
|
53
127
|
|
|
54
|
-
|
|
55
|
-
|
|
128
|
+
<details>
|
|
129
|
+
<summary>Forked from <code>tectiv3/react-native-aes</code></summary>
|
|
56
130
|
|
|
57
|
-
|
|
58
|
-
[tectiv3/react-native-aes](https://github.com/tectiv3/react-native-aes).
|
|
131
|
+
First, a sincere thank-you to tectiv3 and the `react-native-aes-crypto` maintainers for their excellent work 🙏
|
|
59
132
|
|
|
60
|
-
|
|
61
|
-
`react-native-aes-crypto`.
|
|
133
|
+
This package is built on, and inspired by, [tectiv3/react-native-aes](https://github.com/tectiv3/react-native-aes).
|
|
62
134
|
|
|
63
|
-
As our product requirements evolved, the scope of those changes outgrew what we
|
|
64
|
-
could reasonably maintain as an upstream patch set. We regret that we were
|
|
65
|
-
unable to keep this work in patch form.
|
|
135
|
+
Our original plan was to keep our customizations as patches on top of upstream `react-native-aes-crypto`. As our product requirements evolved, the scope of those changes outgrew what we could reasonably maintain as an upstream patch set. We regret that we were unable to keep this work in patch form. As the gap grew, we ultimately forked `react-native-aes-crypto` to keep development and delivery stable.
|
|
66
136
|
|
|
67
|
-
|
|
68
|
-
development and delivery stable.
|
|
69
|
-
|
|
70
|
-
## Upstream Project
|
|
137
|
+
### Upstream Project
|
|
71
138
|
|
|
72
139
|
- Repository: [tectiv3/react-native-aes](https://github.com/tectiv3/react-native-aes)
|
|
73
140
|
- License: MIT
|
|
74
141
|
|
|
75
|
-
|
|
142
|
+
### Notes
|
|
76
143
|
|
|
77
144
|
- This fork includes OneKey-specific adaptations for our product requirements.
|
|
78
|
-
- If you are looking for original behavior and full documentation, please refer
|
|
79
|
-
|
|
145
|
+
- If you are looking for original behavior and full documentation, please refer to the upstream repository.
|
|
146
|
+
|
|
147
|
+
Thank you again to tectiv3 and everyone who contributes to `react-native-aes-crypto` 💙
|
|
148
|
+
|
|
149
|
+
</details>
|
|
150
|
+
|
|
151
|
+
## License
|
|
80
152
|
|
|
81
|
-
|
|
82
|
-
`react-native-aes-crypto` 💙
|
|
153
|
+
MIT. See [LICENSE](LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-aes-crypto",
|
|
3
|
-
"version": "6.7.0-
|
|
3
|
+
"version": "6.7.0-60",
|
|
4
4
|
"description": "react-native-aes-crypto",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"@eslint/compat": "^1.3.2",
|
|
58
58
|
"@eslint/eslintrc": "^3.3.1",
|
|
59
59
|
"@eslint/js": "^9.35.0",
|
|
60
|
-
"@react-native/babel-preset": "0.
|
|
61
|
-
"@react-native/eslint-config": "0.
|
|
60
|
+
"@react-native/babel-preset": "0.88.0",
|
|
61
|
+
"@react-native/eslint-config": "0.88.0",
|
|
62
62
|
"@release-it/conventional-changelog": "^10.0.1",
|
|
63
63
|
"@types/jest": "^29.5.14",
|
|
64
|
-
"@types/react": "^19.
|
|
64
|
+
"@types/react": "^19.3.0",
|
|
65
65
|
"commitlint": "^19.8.1",
|
|
66
66
|
"del-cli": "^6.0.0",
|
|
67
67
|
"eslint": "^9.35.0",
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"jest": "^29.7.0",
|
|
71
71
|
"lefthook": "^2.0.3",
|
|
72
72
|
"prettier": "^2.8.8",
|
|
73
|
-
"react": "19.
|
|
74
|
-
"react-native": "patch:react-native@npm%3A0.
|
|
73
|
+
"react": "19.3.0",
|
|
74
|
+
"react-native": "patch:react-native@npm%3A0.88.0#~/.yarn/patches/react-native-npm-0.88.0-60c6201dd2.patch",
|
|
75
75
|
"react-native-builder-bob": "^0.40.17",
|
|
76
76
|
"release-it": "^19.0.4",
|
|
77
77
|
"turbo": "^2.5.6",
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
"useTabs": false
|
|
121
121
|
},
|
|
122
122
|
"jest": {
|
|
123
|
-
"preset": "react-native",
|
|
123
|
+
"preset": "@react-native/jest-preset",
|
|
124
124
|
"modulePathIgnorePatterns": [
|
|
125
125
|
"<rootDir>/lib/"
|
|
126
126
|
]
|