react-native-quick-crypto 1.0.10 → 1.0.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 (158) hide show
  1. package/android/CMakeLists.txt +9 -0
  2. package/cpp/argon2/HybridArgon2.cpp +103 -0
  3. package/cpp/argon2/HybridArgon2.hpp +32 -0
  4. package/cpp/certificate/HybridCertificate.cpp +42 -0
  5. package/cpp/certificate/HybridCertificate.hpp +16 -0
  6. package/cpp/cipher/HybridCipher.cpp +58 -0
  7. package/cpp/cipher/HybridCipher.hpp +4 -0
  8. package/cpp/dh/HybridDhKeyPair.cpp +179 -0
  9. package/cpp/dh/HybridDhKeyPair.hpp +37 -0
  10. package/cpp/dsa/HybridDsaKeyPair.cpp +128 -0
  11. package/cpp/dsa/HybridDsaKeyPair.hpp +32 -0
  12. package/cpp/ecdh/HybridECDH.cpp +35 -0
  13. package/cpp/ecdh/HybridECDH.hpp +1 -0
  14. package/cpp/keys/HybridKeyObjectHandle.cpp +19 -0
  15. package/cpp/prime/HybridPrime.cpp +81 -0
  16. package/cpp/prime/HybridPrime.hpp +20 -0
  17. package/lib/commonjs/argon2.js +39 -0
  18. package/lib/commonjs/argon2.js.map +1 -0
  19. package/lib/commonjs/certificate.js +35 -0
  20. package/lib/commonjs/certificate.js.map +1 -0
  21. package/lib/commonjs/cipher.js +8 -0
  22. package/lib/commonjs/cipher.js.map +1 -1
  23. package/lib/commonjs/dhKeyPair.js +109 -0
  24. package/lib/commonjs/dhKeyPair.js.map +1 -0
  25. package/lib/commonjs/dsa.js +92 -0
  26. package/lib/commonjs/dsa.js.map +1 -0
  27. package/lib/commonjs/ecdh.js +37 -0
  28. package/lib/commonjs/ecdh.js.map +1 -1
  29. package/lib/commonjs/index.js +35 -0
  30. package/lib/commonjs/index.js.map +1 -1
  31. package/lib/commonjs/keys/classes.js +9 -7
  32. package/lib/commonjs/keys/classes.js.map +1 -1
  33. package/lib/commonjs/keys/generateKeyPair.js +11 -0
  34. package/lib/commonjs/keys/generateKeyPair.js.map +1 -1
  35. package/lib/commonjs/prime.js +84 -0
  36. package/lib/commonjs/prime.js.map +1 -0
  37. package/lib/commonjs/specs/argon2.nitro.js +6 -0
  38. package/lib/commonjs/specs/argon2.nitro.js.map +1 -0
  39. package/lib/commonjs/specs/certificate.nitro.js +6 -0
  40. package/lib/commonjs/specs/certificate.nitro.js.map +1 -0
  41. package/lib/commonjs/specs/dhKeyPair.nitro.js +6 -0
  42. package/lib/commonjs/specs/dhKeyPair.nitro.js.map +1 -0
  43. package/lib/commonjs/specs/dsaKeyPair.nitro.js +6 -0
  44. package/lib/commonjs/specs/dsaKeyPair.nitro.js.map +1 -0
  45. package/lib/commonjs/specs/prime.nitro.js +6 -0
  46. package/lib/commonjs/specs/prime.nitro.js.map +1 -0
  47. package/lib/commonjs/subtle.js +101 -10
  48. package/lib/commonjs/subtle.js.map +1 -1
  49. package/lib/commonjs/utils/types.js.map +1 -1
  50. package/lib/module/argon2.js +34 -0
  51. package/lib/module/argon2.js.map +1 -0
  52. package/lib/module/certificate.js +30 -0
  53. package/lib/module/certificate.js.map +1 -0
  54. package/lib/module/cipher.js +7 -0
  55. package/lib/module/cipher.js.map +1 -1
  56. package/lib/module/dhKeyPair.js +102 -0
  57. package/lib/module/dhKeyPair.js.map +1 -0
  58. package/lib/module/dsa.js +85 -0
  59. package/lib/module/dsa.js.map +1 -0
  60. package/lib/module/ecdh.js +37 -0
  61. package/lib/module/ecdh.js.map +1 -1
  62. package/lib/module/index.js +9 -0
  63. package/lib/module/index.js.map +1 -1
  64. package/lib/module/keys/classes.js +9 -7
  65. package/lib/module/keys/classes.js.map +1 -1
  66. package/lib/module/keys/generateKeyPair.js +11 -0
  67. package/lib/module/keys/generateKeyPair.js.map +1 -1
  68. package/lib/module/prime.js +77 -0
  69. package/lib/module/prime.js.map +1 -0
  70. package/lib/module/specs/argon2.nitro.js +4 -0
  71. package/lib/module/specs/argon2.nitro.js.map +1 -0
  72. package/lib/module/specs/certificate.nitro.js +4 -0
  73. package/lib/module/specs/certificate.nitro.js.map +1 -0
  74. package/lib/module/specs/dhKeyPair.nitro.js +4 -0
  75. package/lib/module/specs/dhKeyPair.nitro.js.map +1 -0
  76. package/lib/module/specs/dsaKeyPair.nitro.js +4 -0
  77. package/lib/module/specs/dsaKeyPair.nitro.js.map +1 -0
  78. package/lib/module/specs/prime.nitro.js +4 -0
  79. package/lib/module/specs/prime.nitro.js.map +1 -0
  80. package/lib/module/subtle.js +102 -12
  81. package/lib/module/subtle.js.map +1 -1
  82. package/lib/module/utils/types.js.map +1 -1
  83. package/lib/tsconfig.tsbuildinfo +1 -1
  84. package/lib/typescript/argon2.d.ts +16 -0
  85. package/lib/typescript/argon2.d.ts.map +1 -0
  86. package/lib/typescript/certificate.d.ts +8 -0
  87. package/lib/typescript/certificate.d.ts.map +1 -0
  88. package/lib/typescript/cipher.d.ts +12 -0
  89. package/lib/typescript/cipher.d.ts.map +1 -1
  90. package/lib/typescript/dhKeyPair.d.ts +19 -0
  91. package/lib/typescript/dhKeyPair.d.ts.map +1 -0
  92. package/lib/typescript/dsa.d.ts +19 -0
  93. package/lib/typescript/dsa.d.ts.map +1 -0
  94. package/lib/typescript/ecdh.d.ts +3 -0
  95. package/lib/typescript/ecdh.d.ts.map +1 -1
  96. package/lib/typescript/index.d.ts +17 -0
  97. package/lib/typescript/index.d.ts.map +1 -1
  98. package/lib/typescript/keys/classes.d.ts +2 -0
  99. package/lib/typescript/keys/classes.d.ts.map +1 -1
  100. package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -1
  101. package/lib/typescript/prime.d.ts +19 -0
  102. package/lib/typescript/prime.d.ts.map +1 -0
  103. package/lib/typescript/specs/argon2.nitro.d.ts +9 -0
  104. package/lib/typescript/specs/argon2.nitro.d.ts.map +1 -0
  105. package/lib/typescript/specs/certificate.nitro.d.ts +10 -0
  106. package/lib/typescript/specs/certificate.nitro.d.ts.map +1 -0
  107. package/lib/typescript/specs/cipher.nitro.d.ts +9 -0
  108. package/lib/typescript/specs/cipher.nitro.d.ts.map +1 -1
  109. package/lib/typescript/specs/dhKeyPair.nitro.d.ts +14 -0
  110. package/lib/typescript/specs/dhKeyPair.nitro.d.ts.map +1 -0
  111. package/lib/typescript/specs/dsaKeyPair.nitro.d.ts +13 -0
  112. package/lib/typescript/specs/dsaKeyPair.nitro.d.ts.map +1 -0
  113. package/lib/typescript/specs/ecdh.nitro.d.ts +1 -0
  114. package/lib/typescript/specs/ecdh.nitro.d.ts.map +1 -1
  115. package/lib/typescript/specs/prime.nitro.d.ts +11 -0
  116. package/lib/typescript/specs/prime.nitro.d.ts.map +1 -0
  117. package/lib/typescript/subtle.d.ts +2 -0
  118. package/lib/typescript/subtle.d.ts.map +1 -1
  119. package/lib/typescript/utils/types.d.ts +13 -3
  120. package/lib/typescript/utils/types.d.ts.map +1 -1
  121. package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +5 -0
  122. package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +50 -0
  123. package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +50 -0
  124. package/nitrogen/generated/shared/c++/CipherInfo.hpp +104 -0
  125. package/nitrogen/generated/shared/c++/HybridArgon2Spec.cpp +22 -0
  126. package/nitrogen/generated/shared/c++/HybridArgon2Spec.hpp +66 -0
  127. package/nitrogen/generated/shared/c++/HybridCertificateSpec.cpp +23 -0
  128. package/nitrogen/generated/shared/c++/HybridCertificateSpec.hpp +64 -0
  129. package/nitrogen/generated/shared/c++/HybridCipherSpec.cpp +1 -0
  130. package/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +4 -0
  131. package/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.cpp +27 -0
  132. package/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.hpp +69 -0
  133. package/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.cpp +26 -0
  134. package/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.hpp +68 -0
  135. package/nitrogen/generated/shared/c++/HybridECDHSpec.cpp +1 -0
  136. package/nitrogen/generated/shared/c++/HybridECDHSpec.hpp +1 -0
  137. package/nitrogen/generated/shared/c++/HybridPrimeSpec.cpp +24 -0
  138. package/nitrogen/generated/shared/c++/HybridPrimeSpec.hpp +67 -0
  139. package/package.json +1 -1
  140. package/src/argon2.ts +83 -0
  141. package/src/certificate.ts +41 -0
  142. package/src/cipher.ts +24 -0
  143. package/src/dhKeyPair.ts +156 -0
  144. package/src/dsa.ts +129 -0
  145. package/src/ecdh.ts +59 -0
  146. package/src/index.ts +9 -0
  147. package/src/keys/classes.ts +16 -5
  148. package/src/keys/generateKeyPair.ts +14 -0
  149. package/src/prime.ts +134 -0
  150. package/src/specs/argon2.nitro.ts +29 -0
  151. package/src/specs/certificate.nitro.ts +8 -0
  152. package/src/specs/cipher.nitro.ts +14 -0
  153. package/src/specs/dhKeyPair.nitro.ts +14 -0
  154. package/src/specs/dsaKeyPair.nitro.ts +13 -0
  155. package/src/specs/ecdh.nitro.ts +1 -0
  156. package/src/specs/prime.nitro.ts +18 -0
  157. package/src/subtle.ts +271 -12
  158. package/src/utils/types.ts +22 -3
package/src/ecdh.ts CHANGED
@@ -2,7 +2,20 @@ import { NitroModules } from 'react-native-nitro-modules';
2
2
  import type { ECDH as ECDHInterface } from './specs/ecdh.nitro';
3
3
  import { Buffer } from '@craftzdog/react-native-buffer';
4
4
 
5
+ const POINT_CONVERSION_COMPRESSED = 2;
6
+ const POINT_CONVERSION_UNCOMPRESSED = 4;
7
+ const POINT_CONVERSION_HYBRID = 6;
8
+
5
9
  export class ECDH {
10
+ private static _convertKeyHybrid: ECDHInterface | undefined;
11
+ private static get convertKeyHybrid(): ECDHInterface {
12
+ if (!this._convertKeyHybrid) {
13
+ this._convertKeyHybrid =
14
+ NitroModules.createHybridObject<ECDHInterface>('ECDH');
15
+ }
16
+ return this._convertKeyHybrid;
17
+ }
18
+
6
19
  private _hybrid: ECDHInterface;
7
20
 
8
21
  constructor(curveName: string) {
@@ -69,6 +82,52 @@ export class ECDH {
69
82
  }
70
83
  this._hybrid.setPublicKey(keyBuf.buffer as ArrayBuffer);
71
84
  }
85
+
86
+ static convertKey(
87
+ key: Buffer | string,
88
+ curve: string,
89
+ inputEncoding?: BufferEncoding,
90
+ outputEncoding?: BufferEncoding,
91
+ format?: 'uncompressed' | 'compressed' | 'hybrid',
92
+ ): Buffer | string {
93
+ let keyBuf: Buffer;
94
+ if (Buffer.isBuffer(key)) {
95
+ keyBuf = key;
96
+ } else {
97
+ keyBuf = Buffer.from(key, inputEncoding);
98
+ }
99
+
100
+ let formatNum: number;
101
+ switch (format) {
102
+ case 'compressed':
103
+ formatNum = POINT_CONVERSION_COMPRESSED;
104
+ break;
105
+ case 'hybrid':
106
+ formatNum = POINT_CONVERSION_HYBRID;
107
+ break;
108
+ case 'uncompressed':
109
+ case undefined:
110
+ formatNum = POINT_CONVERSION_UNCOMPRESSED;
111
+ break;
112
+ default:
113
+ throw new TypeError(
114
+ `Invalid point conversion format: ${format as string}`,
115
+ );
116
+ }
117
+
118
+ const result = Buffer.from(
119
+ ECDH.convertKeyHybrid.convertKey(
120
+ keyBuf.buffer as ArrayBuffer,
121
+ curve,
122
+ formatNum,
123
+ ),
124
+ );
125
+
126
+ if (outputEncoding) {
127
+ return result.toString(outputEncoding);
128
+ }
129
+ return result;
130
+ }
72
131
  }
73
132
 
74
133
  export function createECDH(curveName: string): ECDH {
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  import { Buffer } from '@craftzdog/react-native-buffer';
3
3
 
4
4
  // API imports
5
+ import * as argon2Module from './argon2';
5
6
  import * as keys from './keys';
6
7
  import * as blake3 from './blake3';
7
8
  import * as cipher from './cipher';
@@ -10,10 +11,12 @@ import { hashExports as hash } from './hash';
10
11
  import { hmacExports as hmac } from './hmac';
11
12
  import * as hkdf from './hkdf';
12
13
  import * as pbkdf2 from './pbkdf2';
14
+ import * as prime from './prime';
13
15
  import * as scrypt from './scrypt';
14
16
  import * as random from './random';
15
17
  import * as ecdh from './ecdh';
16
18
  import * as dh from './diffie-hellman';
19
+ import { Certificate } from './certificate';
17
20
  import { getCurves } from './ec';
18
21
  import { constants } from './constants';
19
22
 
@@ -26,6 +29,7 @@ import * as subtle from './subtle';
26
29
  * See `docs/implementation-coverage.md` for status.
27
30
  */
28
31
  const QuickCrypto = {
32
+ ...argon2Module,
29
33
  ...keys,
30
34
  ...blake3,
31
35
  ...cipher,
@@ -34,12 +38,14 @@ const QuickCrypto = {
34
38
  ...hmac,
35
39
  ...hkdf,
36
40
  ...pbkdf2,
41
+ ...prime,
37
42
  ...scrypt,
38
43
  ...random,
39
44
  ...ecdh,
40
45
  ...dh,
41
46
  ...utils,
42
47
  ...subtle,
48
+ Certificate,
43
49
  getCurves,
44
50
  constants,
45
51
  Buffer,
@@ -72,7 +78,9 @@ if (global.process.nextTick == null) {
72
78
 
73
79
  // exports
74
80
  export default QuickCrypto;
81
+ export * from './argon2';
75
82
  export * from './blake3';
83
+ export { Certificate } from './certificate';
76
84
  export * from './cipher';
77
85
  export * from './ed';
78
86
  export * from './keys';
@@ -80,6 +88,7 @@ export * from './hash';
80
88
  export * from './hmac';
81
89
  export * from './hkdf';
82
90
  export * from './pbkdf2';
91
+ export * from './prime';
83
92
  export * from './scrypt';
84
93
  export * from './random';
85
94
  export * from './ecdh';
@@ -126,11 +126,22 @@ export class KeyObject {
126
126
  this.type = type as 'public' | 'secret' | 'private';
127
127
  }
128
128
 
129
- // static from(key) {
130
- // if (!isCryptoKey(key))
131
- // throw new ERR_INVALID_ARG_TYPE('key', 'CryptoKey', key);
132
- // return key[kKeyObject];
133
- // }
129
+ static from(key: CryptoKey): KeyObject {
130
+ if (!(key instanceof CryptoKey)) {
131
+ throw new TypeError(
132
+ `The "key" argument must be an instance of CryptoKey. Received ${typeof key}`,
133
+ );
134
+ }
135
+ return key.keyObject;
136
+ }
137
+
138
+ toCryptoKey(
139
+ algorithm: SubtleAlgorithm,
140
+ extractable: boolean,
141
+ keyUsages: KeyUsage[],
142
+ ): CryptoKey {
143
+ return new CryptoKey(this, algorithm, keyUsages, extractable);
144
+ }
134
145
 
135
146
  static createKeyObject(
136
147
  type: string,
@@ -1,6 +1,11 @@
1
1
  import { ed_generateKeyPair } from '../ed';
2
2
  import { rsa_generateKeyPairNode, rsa_generateKeyPairNodeSync } from '../rsa';
3
3
  import { ec_generateKeyPairNode, ec_generateKeyPairNodeSync } from '../ec';
4
+ import { dsa_generateKeyPairNode, dsa_generateKeyPairNodeSync } from '../dsa';
5
+ import {
6
+ dh_generateKeyPairNode,
7
+ dh_generateKeyPairNodeSync,
8
+ } from '../dhKeyPair';
4
9
  import {
5
10
  kEmptyObject,
6
11
  validateFunction,
@@ -139,6 +144,7 @@ function internalGenerateKeyPair(
139
144
  case 'rsa-pss':
140
145
  case 'dsa':
141
146
  case 'ec':
147
+ case 'dh':
142
148
  break;
143
149
  default: {
144
150
  const err = new Error(`
@@ -158,6 +164,10 @@ function internalGenerateKeyPair(
158
164
  result = await rsa_generateKeyPairNode(type, options, encoding);
159
165
  } else if (type === 'ec') {
160
166
  result = await ec_generateKeyPairNode(options, encoding);
167
+ } else if (type === 'dsa') {
168
+ result = await dsa_generateKeyPairNode(options, encoding);
169
+ } else if (type === 'dh') {
170
+ result = await dh_generateKeyPairNode(options, encoding);
161
171
  } else {
162
172
  throw new Error(`Unsupported key type: ${type}`);
163
173
  }
@@ -184,6 +194,10 @@ function internalGenerateKeyPair(
184
194
  result = rsa_generateKeyPairNodeSync(type, options, encoding);
185
195
  } else if (type === 'ec') {
186
196
  result = ec_generateKeyPairNodeSync(options, encoding);
197
+ } else if (type === 'dsa') {
198
+ result = dsa_generateKeyPairNodeSync(options, encoding);
199
+ } else if (type === 'dh') {
200
+ result = dh_generateKeyPairNodeSync(options, encoding);
187
201
  } else {
188
202
  throw new Error(`Unsupported key type: ${type}`);
189
203
  }
package/src/prime.ts ADDED
@@ -0,0 +1,134 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import { Buffer } from '@craftzdog/react-native-buffer';
3
+ import type { Prime as NativePrime } from './specs/prime.nitro';
4
+ import type { BinaryLike } from './utils';
5
+ import { binaryLikeToArrayBuffer } from './utils';
6
+
7
+ let native: NativePrime;
8
+ function getNative(): NativePrime {
9
+ if (native == null) {
10
+ native = NitroModules.createHybridObject<NativePrime>('Prime');
11
+ }
12
+ return native;
13
+ }
14
+
15
+ export interface GeneratePrimeOptions {
16
+ safe?: boolean;
17
+ bigint?: boolean;
18
+ add?: ArrayBuffer | Buffer | Uint8Array;
19
+ rem?: ArrayBuffer | Buffer | Uint8Array;
20
+ }
21
+
22
+ export interface CheckPrimeOptions {
23
+ checks?: number;
24
+ }
25
+
26
+ function toOptionalArrayBuffer(
27
+ value?: ArrayBuffer | Buffer | Uint8Array,
28
+ ): ArrayBuffer | undefined {
29
+ if (value == null) return undefined;
30
+ if (value instanceof ArrayBuffer) return value;
31
+ return binaryLikeToArrayBuffer(value);
32
+ }
33
+
34
+ function bufferToBigInt(buf: Buffer): bigint {
35
+ let result = 0n;
36
+ for (let i = 0; i < buf.length; i++) {
37
+ result = (result << 8n) | BigInt(buf[i]!);
38
+ }
39
+ return result;
40
+ }
41
+
42
+ function bigIntToBuffer(value: bigint): ArrayBuffer {
43
+ if (value === 0n) return new Uint8Array([0]).buffer;
44
+ const hex = value.toString(16);
45
+ const paddedHex = hex.length % 2 ? '0' + hex : hex;
46
+ const bytes = new Uint8Array(paddedHex.length / 2);
47
+ for (let i = 0; i < bytes.length; i++) {
48
+ bytes[i] = parseInt(paddedHex.substring(i * 2, i * 2 + 2), 16);
49
+ }
50
+ return bytes.buffer;
51
+ }
52
+
53
+ export function generatePrimeSync(
54
+ size: number,
55
+ options?: GeneratePrimeOptions,
56
+ ): Buffer | bigint {
57
+ const safe = options?.safe ?? false;
58
+ const add = toOptionalArrayBuffer(options?.add);
59
+ const rem = toOptionalArrayBuffer(options?.rem);
60
+ const result = Buffer.from(
61
+ getNative().generatePrimeSync(size, safe, add, rem),
62
+ );
63
+ if (options?.bigint) {
64
+ return bufferToBigInt(result);
65
+ }
66
+ return result;
67
+ }
68
+
69
+ type GeneratePrimeCallback = (
70
+ err: Error | null,
71
+ prime: Buffer | bigint,
72
+ ) => void;
73
+
74
+ export function generatePrime(
75
+ size: number,
76
+ options: GeneratePrimeOptions | GeneratePrimeCallback,
77
+ callback?: GeneratePrimeCallback,
78
+ ): void {
79
+ if (typeof options === 'function') {
80
+ callback = options;
81
+ options = {};
82
+ }
83
+ const safe = options?.safe ?? false;
84
+ const add = toOptionalArrayBuffer(options?.add);
85
+ const rem = toOptionalArrayBuffer(options?.rem);
86
+ const wantBigint = options?.bigint ?? false;
87
+
88
+ getNative()
89
+ .generatePrime(size, safe, add, rem)
90
+ .then(ab => {
91
+ const result = Buffer.from(ab);
92
+ if (wantBigint) {
93
+ callback?.(null, bufferToBigInt(result));
94
+ } else {
95
+ callback?.(null, result);
96
+ }
97
+ })
98
+ .catch((err: Error) => callback?.(err, Buffer.alloc(0)));
99
+ }
100
+
101
+ export function checkPrimeSync(
102
+ candidate: BinaryLike | bigint,
103
+ options?: CheckPrimeOptions,
104
+ ): boolean {
105
+ const checks = options?.checks ?? 0;
106
+ const buf =
107
+ typeof candidate === 'bigint'
108
+ ? bigIntToBuffer(candidate)
109
+ : binaryLikeToArrayBuffer(candidate);
110
+ return getNative().checkPrimeSync(buf, checks);
111
+ }
112
+
113
+ type CheckPrimeCallback = (err: Error | null, result: boolean) => void;
114
+
115
+ export function checkPrime(
116
+ candidate: BinaryLike | bigint,
117
+ options: CheckPrimeOptions | CheckPrimeCallback,
118
+ callback?: CheckPrimeCallback,
119
+ ): void {
120
+ if (typeof options === 'function') {
121
+ callback = options;
122
+ options = {};
123
+ }
124
+ const checks = options.checks ?? 0;
125
+ const buf =
126
+ typeof candidate === 'bigint'
127
+ ? bigIntToBuffer(candidate)
128
+ : binaryLikeToArrayBuffer(candidate);
129
+
130
+ getNative()
131
+ .checkPrime(buf, checks)
132
+ .then(result => callback?.(null, result))
133
+ .catch((err: Error) => callback?.(err, false));
134
+ }
@@ -0,0 +1,29 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface Argon2 extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
4
+ hash(
5
+ algorithm: string,
6
+ message: ArrayBuffer,
7
+ nonce: ArrayBuffer,
8
+ parallelism: number,
9
+ tagLength: number,
10
+ memory: number,
11
+ passes: number,
12
+ version: number,
13
+ secret?: ArrayBuffer,
14
+ associatedData?: ArrayBuffer,
15
+ ): Promise<ArrayBuffer>;
16
+
17
+ hashSync(
18
+ algorithm: string,
19
+ message: ArrayBuffer,
20
+ nonce: ArrayBuffer,
21
+ parallelism: number,
22
+ tagLength: number,
23
+ memory: number,
24
+ passes: number,
25
+ version: number,
26
+ secret?: ArrayBuffer,
27
+ associatedData?: ArrayBuffer,
28
+ ): ArrayBuffer;
29
+ }
@@ -0,0 +1,8 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface Certificate
4
+ extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
5
+ verifySpkac(spkac: ArrayBuffer): boolean;
6
+ exportPublicKey(spkac: ArrayBuffer): ArrayBuffer;
7
+ exportChallenge(spkac: ArrayBuffer): ArrayBuffer;
8
+ }
@@ -8,6 +8,15 @@ type CipherArgs = {
8
8
  authTagLen?: number;
9
9
  };
10
10
 
11
+ interface CipherInfo {
12
+ name: string;
13
+ nid: number;
14
+ mode: string;
15
+ keyLength: number;
16
+ blockSize?: number;
17
+ ivLength?: number;
18
+ }
19
+
11
20
  export interface Cipher extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
12
21
  update(data: ArrayBuffer): ArrayBuffer;
13
22
  final(): ArrayBuffer;
@@ -17,6 +26,11 @@ export interface Cipher extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
17
26
  setAuthTag(tag: ArrayBuffer): boolean;
18
27
  getAuthTag(): ArrayBuffer;
19
28
  getSupportedCiphers(): string[];
29
+ getCipherInfo(
30
+ name: string,
31
+ keyLength?: number,
32
+ ivLength?: number,
33
+ ): CipherInfo | undefined;
20
34
  }
21
35
 
22
36
  export interface CipherFactory
@@ -0,0 +1,14 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface DhKeyPair
4
+ extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
5
+ generateKeyPair(): Promise<void>;
6
+ generateKeyPairSync(): void;
7
+
8
+ setPrimeLength(primeLength: number): void;
9
+ setPrime(prime: ArrayBuffer): void;
10
+ setGenerator(generator: number): void;
11
+
12
+ getPublicKey(): ArrayBuffer;
13
+ getPrivateKey(): ArrayBuffer;
14
+ }
@@ -0,0 +1,13 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface DsaKeyPair
4
+ extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
5
+ generateKeyPair(): Promise<void>;
6
+ generateKeyPairSync(): void;
7
+
8
+ setModulusLength(modulusLength: number): void;
9
+ setDivisorLength(divisorLength: number): void;
10
+
11
+ getPublicKey(): ArrayBuffer;
12
+ getPrivateKey(): ArrayBuffer;
13
+ }
@@ -8,4 +8,5 @@ export interface ECDH extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
8
8
  setPrivateKey(privateKey: ArrayBuffer): void;
9
9
  getPublicKey(): ArrayBuffer;
10
10
  setPublicKey(publicKey: ArrayBuffer): void;
11
+ convertKey(key: ArrayBuffer, curve: string, format: number): ArrayBuffer;
11
12
  }
@@ -0,0 +1,18 @@
1
+ import { type HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface Prime extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
4
+ generatePrime(
5
+ size: number,
6
+ safe: boolean,
7
+ add?: ArrayBuffer,
8
+ rem?: ArrayBuffer,
9
+ ): Promise<ArrayBuffer>;
10
+ generatePrimeSync(
11
+ size: number,
12
+ safe: boolean,
13
+ add?: ArrayBuffer,
14
+ rem?: ArrayBuffer,
15
+ ): ArrayBuffer;
16
+ checkPrime(candidate: ArrayBuffer, checks: number): Promise<boolean>;
17
+ checkPrimeSync(candidate: ArrayBuffer, checks: number): boolean;
18
+ }