react-native-quick-crypto 1.0.0-beta.1 → 1.0.0-beta.10
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/QuickCrypto.podspec +17 -4
- package/README.md +172 -0
- package/android/CMakeLists.txt +28 -17
- package/android/build.gradle +36 -3
- package/android/src/main/cpp/cpp-adapter.cpp +3 -10
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +15 -10
- package/cpp/ed25519/HybridEdKeyPair.cpp +268 -0
- package/cpp/ed25519/HybridEdKeyPair.hpp +85 -0
- package/cpp/pbkdf2/HybridPbkdf2.cpp +72 -0
- package/cpp/pbkdf2/HybridPbkdf2.hpp +35 -0
- package/cpp/random/HybridRandom.cpp +59 -0
- package/cpp/random/HybridRandom.hpp +33 -0
- package/cpp/utils/Utils.hpp +20 -0
- package/deps/fastpbkdf2/fastpbkdf2.c +352 -0
- package/deps/fastpbkdf2/fastpbkdf2.h +68 -0
- package/lib/commonjs/ed.js +42 -0
- package/lib/commonjs/ed.js.map +1 -0
- package/lib/commonjs/index.js +61 -10
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +191 -0
- package/lib/commonjs/keys/classes.js.map +1 -0
- package/lib/commonjs/keys/generateKeyPair.js +148 -0
- package/lib/commonjs/keys/generateKeyPair.js.map +1 -0
- package/lib/commonjs/keys/index.js +62 -0
- package/lib/commonjs/keys/index.js.map +1 -0
- package/lib/commonjs/keys/signVerify.js +41 -0
- package/lib/commonjs/keys/signVerify.js.map +1 -0
- package/lib/commonjs/keys/utils.js +118 -0
- package/lib/commonjs/keys/utils.js.map +1 -0
- package/lib/commonjs/pbkdf2.js +89 -0
- package/lib/commonjs/pbkdf2.js.map +1 -0
- package/lib/commonjs/random.js +3 -3
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/specs/edKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/edKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/keyObjectHandle.nitro.js +6 -0
- package/lib/commonjs/specs/keyObjectHandle.nitro.js.map +1 -0
- package/lib/commonjs/specs/pbkdf2.nitro.js +6 -0
- package/lib/commonjs/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/commonjs/utils/conversion.js +101 -6
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/commonjs/utils/errors.js +14 -0
- package/lib/commonjs/utils/errors.js.map +1 -0
- package/lib/commonjs/utils/hashnames.js +90 -0
- package/lib/commonjs/utils/hashnames.js.map +1 -0
- package/lib/commonjs/utils/index.js +54 -5
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/types.js +38 -0
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/commonjs/utils/validation.js +25 -0
- package/lib/commonjs/utils/validation.js.map +1 -0
- package/lib/module/ed.js +37 -0
- package/lib/module/ed.js.map +1 -0
- package/lib/module/index.js +16 -9
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +182 -0
- package/lib/module/keys/classes.js.map +1 -0
- package/lib/module/keys/generateKeyPair.js +148 -0
- package/lib/module/keys/generateKeyPair.js.map +1 -0
- package/lib/module/keys/index.js +29 -0
- package/lib/module/keys/index.js.map +1 -0
- package/lib/module/keys/signVerify.js +41 -0
- package/lib/module/keys/signVerify.js.map +1 -0
- package/lib/module/keys/utils.js +110 -0
- package/lib/module/keys/utils.js.map +1 -0
- package/lib/module/pbkdf2.js +83 -0
- package/lib/module/pbkdf2.js.map +1 -0
- package/lib/module/random.js +1 -1
- package/lib/module/random.js.map +1 -1
- package/lib/module/specs/edKeyPair.nitro.js +4 -0
- package/lib/module/specs/edKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/keyObjectHandle.nitro.js +4 -0
- package/lib/module/specs/keyObjectHandle.nitro.js.map +1 -0
- package/lib/module/specs/pbkdf2.nitro.js +4 -0
- package/lib/module/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/module/utils/conversion.js +99 -8
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/module/utils/errors.js +10 -0
- package/lib/module/utils/errors.js.map +1 -0
- package/lib/module/utils/hashnames.js +88 -0
- package/lib/module/utils/hashnames.js.map +1 -0
- package/lib/module/utils/index.js +5 -5
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/types.js +40 -0
- package/lib/module/utils/types.js.map +1 -1
- package/lib/module/utils/validation.js +19 -0
- package/lib/module/utils/validation.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/ed.d.ts +17 -0
- package/lib/typescript/ed.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +50 -9
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +38 -0
- package/lib/typescript/keys/classes.d.ts.map +1 -0
- package/lib/typescript/keys/generateKeyPair.d.ts +1 -0
- package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -0
- package/lib/typescript/keys/index.d.ts +4 -0
- package/lib/typescript/keys/index.d.ts.map +1 -0
- package/lib/typescript/keys/signVerify.d.ts +1 -0
- package/lib/typescript/keys/signVerify.d.ts.map +1 -0
- package/lib/typescript/keys/utils.d.ts +32 -0
- package/lib/typescript/keys/utils.d.ts.map +1 -0
- package/lib/typescript/pbkdf2.d.ts +12 -0
- package/lib/typescript/pbkdf2.d.ts.map +1 -0
- package/lib/typescript/random.d.ts +5 -5
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/specs/edKeyPair.nitro.d.ts +16 -0
- package/lib/typescript/specs/edKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +15 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/pbkdf2.nitro.d.ts +9 -0
- package/lib/typescript/specs/pbkdf2.nitro.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +23 -2
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/lib/typescript/utils/errors.d.ts +7 -0
- package/lib/typescript/utils/errors.d.ts.map +1 -0
- package/lib/typescript/utils/hashnames.d.ts +11 -0
- package/lib/typescript/utils/hashnames.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +5 -5
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/utils/types.d.ts +158 -1
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/lib/typescript/utils/validation.d.ts +8 -0
- package/lib/typescript/utils/validation.d.ts.map +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +65 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +27 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +64 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +58 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +27 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +38 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +55 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +12 -0
- package/nitrogen/generated/shared/c++/CFRGKeyPairType.hpp +86 -0
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +74 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +93 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/JWK.hpp +162 -0
- package/nitrogen/generated/shared/c++/JWKkty.hpp +86 -0
- package/nitrogen/generated/shared/c++/JWKuse.hpp +78 -0
- package/nitrogen/generated/shared/c++/KFormatType.hpp +65 -0
- package/nitrogen/generated/shared/c++/KeyDetail.hpp +93 -0
- package/nitrogen/generated/shared/c++/KeyEncoding.hpp +66 -0
- package/nitrogen/generated/shared/c++/KeyType.hpp +65 -0
- package/nitrogen/generated/shared/c++/KeyUsage.hpp +102 -0
- package/nitrogen/generated/shared/c++/NamedCurve.hpp +82 -0
- package/package.json +55 -34
- package/src/ed.ts +79 -0
- package/src/index.ts +15 -9
- package/src/keys/classes.ts +211 -0
- package/src/keys/generateKeyPair.ts +146 -0
- package/src/keys/index.ts +42 -0
- package/src/keys/signVerify.ts +39 -0
- package/src/keys/utils.ts +184 -0
- package/src/pbkdf2.ts +154 -0
- package/src/random.ts +19 -23
- package/src/specs/edKeyPair.nitro.ts +41 -0
- package/src/specs/keyObjectHandle.nitro.ts +32 -0
- package/src/specs/pbkdf2.nitro.ts +18 -0
- package/src/specs/random.nitro.ts +2 -2
- package/src/utils/conversion.ts +116 -9
- package/src/utils/errors.ts +15 -0
- package/src/utils/hashnames.ts +96 -0
- package/src/utils/index.ts +5 -6
- package/src/utils/types.ts +263 -3
- package/src/utils/validation.ts +35 -0
- package/ios/QuickCryptoOnLoad.mm +0 -19
package/src/utils/types.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Buffer as CraftzdogBuffer } from '@craftzdog/react-native-buffer';
|
|
2
|
+
import type { Buffer as SafeBuffer } from 'safe-buffer';
|
|
3
|
+
import type { CipherKey } from 'crypto'; // @types/node
|
|
4
|
+
import type { KeyObjectHandle } from '../specs/keyObjectHandle.nitro';
|
|
5
|
+
|
|
6
|
+
export type ABV = TypedArray | DataView | ArrayBufferLike | CraftzdogBuffer;
|
|
2
7
|
|
|
3
8
|
export type TypedArray =
|
|
4
9
|
| Uint8Array
|
|
@@ -11,5 +16,260 @@ export type TypedArray =
|
|
|
11
16
|
| Float32Array
|
|
12
17
|
| Float64Array;
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
export type RandomCallback<T> = (err: Error | null, value: T) => void;
|
|
20
|
+
|
|
21
|
+
export type BufferLike =
|
|
22
|
+
| ArrayBuffer
|
|
23
|
+
| CraftzdogBuffer
|
|
24
|
+
| SafeBuffer
|
|
25
|
+
| ArrayBufferView;
|
|
26
|
+
|
|
27
|
+
export type BinaryLike =
|
|
28
|
+
| string
|
|
29
|
+
| ArrayBuffer
|
|
30
|
+
| CraftzdogBuffer
|
|
31
|
+
| SafeBuffer
|
|
32
|
+
| TypedArray
|
|
33
|
+
| DataView;
|
|
34
|
+
|
|
35
|
+
export type BinaryLikeNode = CipherKey | BinaryLike;
|
|
36
|
+
|
|
37
|
+
export type DigestAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
38
|
+
|
|
39
|
+
export type HashAlgorithm = DigestAlgorithm | 'SHA-224' | 'RIPEMD-160';
|
|
40
|
+
|
|
41
|
+
export type RSAKeyPairAlgorithm = 'RSASSA-PKCS1-v1_5' | 'RSA-PSS' | 'RSA-OAEP';
|
|
42
|
+
|
|
43
|
+
export type ECKeyPairAlgorithm = 'ECDSA' | 'ECDH';
|
|
44
|
+
|
|
45
|
+
export type CFRGKeyPairAlgorithm = 'Ed25519' | 'Ed448' | 'X25519' | 'X448';
|
|
46
|
+
export type CFRGKeyPairType = 'ed25519' | 'ed448' | 'x25519' | 'x448';
|
|
47
|
+
|
|
48
|
+
export type KeyPairAlgorithm =
|
|
49
|
+
| RSAKeyPairAlgorithm
|
|
50
|
+
| ECKeyPairAlgorithm
|
|
51
|
+
| CFRGKeyPairAlgorithm;
|
|
52
|
+
|
|
53
|
+
export type AESAlgorithm = 'AES-CTR' | 'AES-CBC' | 'AES-GCM' | 'AES-KW';
|
|
54
|
+
|
|
55
|
+
export type SecretKeyAlgorithm = 'HMAC' | AESAlgorithm;
|
|
56
|
+
|
|
57
|
+
export type SignVerifyAlgorithm =
|
|
58
|
+
| 'RSASSA-PKCS1-v1_5'
|
|
59
|
+
| 'RSA-PSS'
|
|
60
|
+
| 'ECDSA'
|
|
61
|
+
| 'HMAC'
|
|
62
|
+
| 'Ed25519'
|
|
63
|
+
| 'Ed448';
|
|
64
|
+
|
|
65
|
+
export type DeriveBitsAlgorithm =
|
|
66
|
+
| 'PBKDF2'
|
|
67
|
+
| 'HKDF'
|
|
68
|
+
| 'ECDH'
|
|
69
|
+
| 'X25519'
|
|
70
|
+
| 'X448';
|
|
71
|
+
|
|
72
|
+
export type EncryptDecryptAlgorithm =
|
|
73
|
+
| 'RSA-OAEP'
|
|
74
|
+
| 'AES-CTR'
|
|
75
|
+
| 'AES-CBC'
|
|
76
|
+
| 'AES-GCM';
|
|
77
|
+
|
|
78
|
+
export type AnyAlgorithm =
|
|
79
|
+
| DigestAlgorithm
|
|
80
|
+
| HashAlgorithm
|
|
81
|
+
| KeyPairAlgorithm
|
|
82
|
+
| SecretKeyAlgorithm
|
|
83
|
+
| SignVerifyAlgorithm
|
|
84
|
+
| DeriveBitsAlgorithm
|
|
85
|
+
| EncryptDecryptAlgorithm
|
|
86
|
+
| AESAlgorithm
|
|
87
|
+
| 'PBKDF2'
|
|
88
|
+
| 'HKDF'
|
|
89
|
+
| 'unknown';
|
|
90
|
+
|
|
91
|
+
export type NamedCurve = 'P-256' | 'P-384' | 'P-521';
|
|
92
|
+
|
|
93
|
+
export type SubtleAlgorithm = {
|
|
94
|
+
name: AnyAlgorithm;
|
|
95
|
+
salt?: string;
|
|
96
|
+
iterations?: number;
|
|
97
|
+
hash?: HashAlgorithm;
|
|
98
|
+
namedCurve?: NamedCurve;
|
|
99
|
+
length?: number;
|
|
100
|
+
modulusLength?: number;
|
|
101
|
+
publicExponent?: number | Uint8Array;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type KeyPairType = CFRGKeyPairType;
|
|
105
|
+
|
|
106
|
+
export type KeyUsage =
|
|
107
|
+
| 'encrypt'
|
|
108
|
+
| 'decrypt'
|
|
109
|
+
| 'sign'
|
|
110
|
+
| 'verify'
|
|
111
|
+
| 'deriveKey'
|
|
112
|
+
| 'deriveBits'
|
|
113
|
+
| 'wrapKey'
|
|
114
|
+
| 'unwrapKey';
|
|
115
|
+
|
|
116
|
+
// On node this value is defined on the native side, for now I'm just creating it here in JS
|
|
117
|
+
// TODO(osp) move this into native side to make sure they always match
|
|
118
|
+
export enum KFormatType {
|
|
119
|
+
kKeyFormatDER,
|
|
120
|
+
kKeyFormatPEM,
|
|
121
|
+
kKeyFormatJWK,
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Same as KFormatType, this enum needs to be defined on the native side
|
|
125
|
+
export enum KeyType {
|
|
126
|
+
Secret,
|
|
127
|
+
Public,
|
|
128
|
+
Private,
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export enum KeyEncoding {
|
|
132
|
+
kKeyEncodingPKCS1,
|
|
133
|
+
kKeyEncodingPKCS8,
|
|
134
|
+
kKeyEncodingSPKI,
|
|
135
|
+
kKeyEncodingSEC1,
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export type KeyPairGenConfig = {
|
|
139
|
+
publicFormat?: KFormatType;
|
|
140
|
+
publicType?: KeyEncoding;
|
|
141
|
+
privateFormat?: KFormatType;
|
|
142
|
+
privateType?: KeyEncoding;
|
|
143
|
+
cipher?: string;
|
|
144
|
+
passphrase?: ArrayBuffer;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export type AsymmetricKeyType =
|
|
148
|
+
// 'rsa' |
|
|
149
|
+
// 'rsa-pss' |
|
|
150
|
+
// 'dsa' |
|
|
151
|
+
// 'ec' |
|
|
152
|
+
// 'dh' |
|
|
153
|
+
CFRGKeyPairType;
|
|
154
|
+
|
|
155
|
+
type JWKkty = 'AES' | 'RSA' | 'EC' | 'oct';
|
|
156
|
+
type JWKuse = 'sig' | 'enc';
|
|
157
|
+
|
|
158
|
+
export interface JWK {
|
|
159
|
+
kty?: JWKkty;
|
|
160
|
+
use?: JWKuse;
|
|
161
|
+
key_ops?: KeyUsage[];
|
|
162
|
+
alg?: string; // TODO: enumerate these (RFC-7517)
|
|
163
|
+
crv?: string;
|
|
164
|
+
kid?: string;
|
|
165
|
+
x5u?: string;
|
|
166
|
+
x5c?: string[];
|
|
167
|
+
x5t?: string;
|
|
168
|
+
'x5t#256'?: string;
|
|
169
|
+
n?: string;
|
|
170
|
+
e?: string;
|
|
171
|
+
d?: string;
|
|
172
|
+
p?: string;
|
|
173
|
+
q?: string;
|
|
174
|
+
x?: string;
|
|
175
|
+
y?: string;
|
|
176
|
+
k?: string;
|
|
177
|
+
dp?: string;
|
|
178
|
+
dq?: string;
|
|
179
|
+
qi?: string;
|
|
180
|
+
ext?: boolean;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export type KTypePrivate = 'pkcs1' | 'pkcs8' | 'sec1';
|
|
184
|
+
export type KTypePublic = 'pkcs1' | 'spki';
|
|
185
|
+
export type KType = KTypePrivate | KTypePublic;
|
|
186
|
+
|
|
187
|
+
export type KFormat = 'der' | 'pem' | 'jwk';
|
|
188
|
+
|
|
189
|
+
export type DSAEncoding = 'der' | 'ieee-p1363';
|
|
190
|
+
|
|
191
|
+
export type EncodingOptions = {
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
193
|
+
key?: any;
|
|
194
|
+
type?: KType;
|
|
195
|
+
encoding?: string;
|
|
196
|
+
dsaEncoding?: DSAEncoding;
|
|
197
|
+
format?: KFormat;
|
|
198
|
+
padding?: number;
|
|
199
|
+
cipher?: string;
|
|
200
|
+
passphrase?: BinaryLike;
|
|
201
|
+
saltLength?: number;
|
|
202
|
+
oaepHash?: string;
|
|
203
|
+
oaepLabel?: BinaryLike;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export interface KeyDetail {
|
|
207
|
+
length?: number;
|
|
208
|
+
publicExponent?: number;
|
|
209
|
+
modulusLength?: number;
|
|
210
|
+
hashAlgorithm?: string;
|
|
211
|
+
mgf1HashAlgorithm?: string;
|
|
212
|
+
saltLength?: number;
|
|
213
|
+
namedCurve?: string;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export type GenerateKeyPairOptions = {
|
|
217
|
+
modulusLength?: number; // Key size in bits (RSA, DSA).
|
|
218
|
+
publicExponent?: number; // Public exponent (RSA). Default: 0x10001.
|
|
219
|
+
hashAlgorithm?: string; // Name of the message digest (RSA-PSS).
|
|
220
|
+
mgf1HashAlgorithm?: string; // string Name of the message digest used by MGF1 (RSA-PSS).
|
|
221
|
+
saltLength?: number; // Minimal salt length in bytes (RSA-PSS).
|
|
222
|
+
divisorLength?: number; // Size of q in bits (DSA).
|
|
223
|
+
namedCurve?: string; // Name of the curve to use (EC).
|
|
224
|
+
prime?: CraftzdogBuffer; // The prime parameter (DH).
|
|
225
|
+
primeLength?: number; // Prime length in bits (DH).
|
|
226
|
+
generator?: number; // Custom generator (DH). Default: 2.
|
|
227
|
+
groupName?: string; // Diffie-Hellman group name (DH). See crypto.getDiffieHellman().
|
|
228
|
+
publicKeyEncoding?: EncodingOptions; // See keyObject.export().
|
|
229
|
+
privateKeyEncoding?: EncodingOptions; // See keyObject.export().
|
|
230
|
+
paramEncoding?: string;
|
|
231
|
+
hash?: string;
|
|
232
|
+
mgf1Hash?: string;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// Note: removed CryptoKey class from this type (from 0.x) because Nitro doesn't
|
|
236
|
+
// handle custom JS objects. We might need to make it a JS object.
|
|
237
|
+
export type KeyPairKey = ArrayBuffer | KeyObjectHandle | undefined;
|
|
238
|
+
|
|
239
|
+
export type GenerateKeyPairReturn = [
|
|
240
|
+
error?: Error,
|
|
241
|
+
privateKey?: KeyPairKey,
|
|
242
|
+
publicKey?: KeyPairKey,
|
|
243
|
+
];
|
|
244
|
+
|
|
245
|
+
export type GenerateKeyPairCallback = (
|
|
246
|
+
error?: Error,
|
|
247
|
+
publicKey?: KeyPairKey,
|
|
248
|
+
privateKey?: KeyPairKey,
|
|
249
|
+
) => GenerateKeyPairReturn | void;
|
|
250
|
+
|
|
251
|
+
export type KeyPair = {
|
|
252
|
+
publicKey?: KeyPairKey;
|
|
253
|
+
privateKey?: KeyPairKey;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export type GenerateKeyPairPromiseReturn = [error?: Error, keypair?: KeyPair];
|
|
257
|
+
|
|
258
|
+
export type CryptoKeyPair = {
|
|
259
|
+
publicKey: KeyPairKey;
|
|
260
|
+
privateKey: KeyPairKey;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
export enum KeyVariant {
|
|
264
|
+
RSA_SSA_PKCS1_v1_5,
|
|
265
|
+
RSA_PSS,
|
|
266
|
+
RSA_OAEP,
|
|
267
|
+
DSA,
|
|
268
|
+
EC,
|
|
269
|
+
NID,
|
|
270
|
+
DH,
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export type SignCallback = (err: Error | null, signature?: ArrayBuffer) => void;
|
|
274
|
+
|
|
275
|
+
export type VerifyCallback = (err: Error | null, valid?: boolean) => void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function validateFunction(f: unknown): boolean {
|
|
2
|
+
return f !== null && typeof f === 'function';
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function isStringOrBuffer(val: unknown): val is string | ArrayBuffer {
|
|
6
|
+
return (
|
|
7
|
+
typeof val === 'string' ||
|
|
8
|
+
ArrayBuffer.isView(val) ||
|
|
9
|
+
val instanceof ArrayBuffer
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function validateObject<T>(
|
|
14
|
+
value: unknown,
|
|
15
|
+
name: string,
|
|
16
|
+
options?: {
|
|
17
|
+
allowArray: boolean;
|
|
18
|
+
allowFunction: boolean;
|
|
19
|
+
nullable: boolean;
|
|
20
|
+
} | null,
|
|
21
|
+
): value is T {
|
|
22
|
+
const useDefaultOptions = options == null;
|
|
23
|
+
const allowArray = useDefaultOptions ? false : options.allowArray;
|
|
24
|
+
const allowFunction = useDefaultOptions ? false : options.allowFunction;
|
|
25
|
+
const nullable = useDefaultOptions ? false : options.nullable;
|
|
26
|
+
if (
|
|
27
|
+
(!nullable && value === null) ||
|
|
28
|
+
(!allowArray && Array.isArray(value)) ||
|
|
29
|
+
(typeof value !== 'object' &&
|
|
30
|
+
(!allowFunction || typeof value !== 'function'))
|
|
31
|
+
) {
|
|
32
|
+
throw new Error(`${name} is not a valid object $${value}`);
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
package/ios/QuickCryptoOnLoad.mm
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
#include "HybridRandom.hpp"
|
|
3
|
-
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
4
|
-
|
|
5
|
-
@interface QuickCryptoOnLoad : NSObject
|
|
6
|
-
@end
|
|
7
|
-
|
|
8
|
-
@implementation QuickCryptoOnLoad
|
|
9
|
-
|
|
10
|
-
using namespace margelo::nitro;
|
|
11
|
-
using namespace margelo::crypto;
|
|
12
|
-
|
|
13
|
-
+ (void)load {
|
|
14
|
-
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
15
|
-
"Random", []() -> std::shared_ptr<HybridObject> { return std::make_shared<HybridRandom>();
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@end
|