react-native-quick-crypto 1.0.16 → 1.0.18
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/cpp/ec/HybridEcKeyPair.cpp +34 -4
- package/cpp/utils/HybridUtils.cpp +216 -0
- package/cpp/utils/HybridUtils.hpp +2 -0
- package/lib/commonjs/ed.js +72 -39
- package/lib/commonjs/ed.js.map +1 -1
- package/lib/commonjs/hash.js.map +1 -1
- package/lib/commonjs/utils/conversion.js +24 -0
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/module/ed.js +72 -39
- package/lib/module/ed.js.map +1 -1
- package/lib/module/hash.js.map +1 -1
- package/lib/module/utils/conversion.js +20 -0
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/ed.d.ts.map +1 -1
- package/lib/typescript/hash.d.ts +3 -2
- package/lib/typescript/hash.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/utils.nitro.d.ts +2 -0
- package/lib/typescript/specs/utils.nitro.d.ts.map +1 -1
- package/lib/typescript/utils/conversion.d.ts +4 -0
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/nitrogen/generated/shared/c++/HybridUtilsSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridUtilsSpec.hpp +3 -0
- package/package.json +1 -1
- package/src/ed.ts +84 -67
- package/src/hash.ts +7 -1
- package/src/specs/utils.nitro.ts +2 -0
- package/src/utils/conversion.ts +38 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ed.d.ts","sourceRoot":"","sources":["../../src/ed.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAExD,OAAO,EACL,SAAS,EAIV,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBA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MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,WAAW,CAmCb"}
|
package/lib/typescript/hash.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ declare class Hash extends Stream.Transform {
|
|
|
42
42
|
* @param encoding The `encoding` of the return value.
|
|
43
43
|
*/
|
|
44
44
|
digest(): Buffer;
|
|
45
|
-
digest(encoding: Encoding):
|
|
45
|
+
digest(encoding: Encoding): string;
|
|
46
46
|
/**
|
|
47
47
|
* Creates a new `Hash` object that contains a deep copy of the internal state
|
|
48
48
|
* of the current `Hash` object.
|
|
@@ -114,7 +114,8 @@ export declare function createHash(algorithm: string, options?: HashOptions): Ha
|
|
|
114
114
|
* @returns Promise resolving to the hash digest as ArrayBuffer
|
|
115
115
|
*/
|
|
116
116
|
export declare const asyncDigest: (algorithm: SubtleAlgorithm, data: BufferLike) => Promise<ArrayBuffer>;
|
|
117
|
-
export declare function hash(algorithm: string, data: BinaryLike, outputEncoding
|
|
117
|
+
export declare function hash(algorithm: string, data: BinaryLike, outputEncoding: Encoding): string;
|
|
118
|
+
export declare function hash(algorithm: string, data: BinaryLike): Buffer;
|
|
118
119
|
export declare const hashExports: {
|
|
119
120
|
createHash: typeof createHash;
|
|
120
121
|
getHashes: typeof getHashes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAExD,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EAChB,MAAM,SAAS,CAAC;AAiBjB,wBAAgB,SAAS,aAExB;AAED,UAAU,WAAY,SAAQ,gBAAgB;IAC5C;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS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,CAAC,WAAW,CAqCrB,CAAC;AAoBF,wBAAgB,IAAI,CAClB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,UAAU,EAChB,cAAc,EAAE,QAAQ,GACvB,MAAM,CAAC;AACV,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;AAWlE,eAAO,MAAM,WAAW;;;;6BA3EX,eAAe,QACpB,UAAU,KACf,OAAO,CAAC,WAAW,CAAC;CA8EtB,CAAC"}
|
|
@@ -50,6 +50,8 @@ declare const QuickCrypto: {
|
|
|
50
50
|
bufferLikeToArrayBuffer(buf: utils.BufferLike): ArrayBuffer;
|
|
51
51
|
binaryLikeToArrayBuffer(input: utils.BinaryLikeNode, encoding?: string): ArrayBuffer;
|
|
52
52
|
ab2str(buf: ArrayBuffer, encoding?: string): string;
|
|
53
|
+
bufferToString(buf: ArrayBuffer, encoding?: string): string;
|
|
54
|
+
stringToBuffer(str: string, encoding?: string): ArrayBuffer;
|
|
53
55
|
abvToArrayBuffer: (buf: utils.ABV) => ArrayBuffer;
|
|
54
56
|
kEmptyObject: any;
|
|
55
57
|
ensureBytes(title: string, hex: utils.Hex, expectedLength?: number): Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAGxD,OAAO,KAAK,YAAY,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAG3B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAE/B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,M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B,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -4,5 +4,7 @@ export interface Utils extends HybridObject<{
|
|
|
4
4
|
android: 'c++';
|
|
5
5
|
}> {
|
|
6
6
|
timingSafeEqual(a: ArrayBuffer, b: ArrayBuffer): boolean;
|
|
7
|
+
bufferToString(buffer: ArrayBuffer, encoding: string): string;
|
|
8
|
+
stringToBuffer(str: string, encoding: string): ArrayBuffer;
|
|
7
9
|
}
|
|
8
10
|
//# sourceMappingURL=utils.nitro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.nitro.d.ts","sourceRoot":"","sources":["../../../src/specs/utils.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,KAAM,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;IACzE,eAAe,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.nitro.d.ts","sourceRoot":"","sources":["../../../src/specs/utils.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,KAAM,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;IACzE,eAAe,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;IACzD,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9D,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC;CAC5D"}
|
|
@@ -21,6 +21,10 @@ export declare function bufferLikeToArrayBuffer(buf: BufferLike): ArrayBuffer;
|
|
|
21
21
|
export declare function binaryLikeToArrayBuffer(input: BinaryLikeNode, // CipherKey adds compat with node types
|
|
22
22
|
encoding?: string): ArrayBuffer;
|
|
23
23
|
export declare function ab2str(buf: ArrayBuffer, encoding?: string): string;
|
|
24
|
+
/** Native C++ buffer-to-string — exposed for benchmarking */
|
|
25
|
+
export declare function bufferToString(buf: ArrayBuffer, encoding?: string): string;
|
|
26
|
+
/** Native C++ string-to-buffer — exposed for benchmarking */
|
|
27
|
+
export declare function stringToBuffer(str: string, encoding?: string): ArrayBuffer;
|
|
24
28
|
export declare const kEmptyObject: any;
|
|
25
29
|
export * from './noble';
|
|
26
30
|
//# sourceMappingURL=conversion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.d.ts","sourceRoot":"","sources":["../../../src/utils/conversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"conversion.d.ts","sourceRoot":"","sources":["../../../src/utils/conversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAI/D;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,GAAG,gBAQxC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,eAAe,GAAG,UAAU,GAAG,eAAe,GAClD,WAAW,CAiBb;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,UAAU,GAAG,WAAW,CAgCpE;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,cAAc,EAAE,wCAAwC;AAC/D,QAAQ,GAAE,MAAgB,GACzB,WAAW,CAiEb;AAaD,wBAAgB,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,QAAQ,GAAE,MAAc,GAAG,MAAM,CAKzE;AAED,6DAA6D;AAC7D,wBAAgB,cAAc,CAC5B,GAAG,EAAE,WAAW,EAChB,QAAQ,GAAE,MAAc,GACvB,MAAM,CAER;AAED,6DAA6D;AAC7D,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,MAAgB,GACzB,WAAW,CAEb;AAED,eAAO,MAAM,YAAY,KAAqC,CAAC;AAE/D,cAAc,SAAS,CAAC"}
|
|
@@ -15,6 +15,8 @@ namespace margelo::nitro::crypto {
|
|
|
15
15
|
// load custom methods/properties
|
|
16
16
|
registerHybrids(this, [](Prototype& prototype) {
|
|
17
17
|
prototype.registerHybridMethod("timingSafeEqual", &HybridUtilsSpec::timingSafeEqual);
|
|
18
|
+
prototype.registerHybridMethod("bufferToString", &HybridUtilsSpec::bufferToString);
|
|
19
|
+
prototype.registerHybridMethod("stringToBuffer", &HybridUtilsSpec::stringToBuffer);
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
#include <NitroModules/ArrayBuffer.hpp>
|
|
19
|
+
#include <string>
|
|
19
20
|
|
|
20
21
|
namespace margelo::nitro::crypto {
|
|
21
22
|
|
|
@@ -49,6 +50,8 @@ namespace margelo::nitro::crypto {
|
|
|
49
50
|
public:
|
|
50
51
|
// Methods
|
|
51
52
|
virtual bool timingSafeEqual(const std::shared_ptr<ArrayBuffer>& a, const std::shared_ptr<ArrayBuffer>& b) = 0;
|
|
53
|
+
virtual std::string bufferToString(const std::shared_ptr<ArrayBuffer>& buffer, const std::string& encoding) = 0;
|
|
54
|
+
virtual std::shared_ptr<ArrayBuffer> stringToBuffer(const std::string& str, const std::string& encoding) = 0;
|
|
52
55
|
|
|
53
56
|
protected:
|
|
54
57
|
// Hybrid Setup
|
package/package.json
CHANGED
package/src/ed.ts
CHANGED
|
@@ -58,9 +58,11 @@ export class Ed {
|
|
|
58
58
|
options: DiffieHellmanOptions,
|
|
59
59
|
callback?: DiffieHellmanCallback,
|
|
60
60
|
): Buffer | void {
|
|
61
|
-
// extract
|
|
62
|
-
const
|
|
63
|
-
const
|
|
61
|
+
// extract raw key bytes from KeyObject instances
|
|
62
|
+
const privKeyObj = options.privateKey as AsymmetricKeyObject;
|
|
63
|
+
const pubKeyObj = options.publicKey as AsymmetricKeyObject;
|
|
64
|
+
const privateKey = privKeyObj.handle.exportKey();
|
|
65
|
+
const publicKey = pubKeyObj.handle.exportKey();
|
|
64
66
|
|
|
65
67
|
try {
|
|
66
68
|
const ret = this.native.diffieHellman(privateKey, publicKey);
|
|
@@ -178,51 +180,97 @@ export function diffieHellman(
|
|
|
178
180
|
return ed.diffieHellman(options, callback);
|
|
179
181
|
}
|
|
180
182
|
|
|
183
|
+
function ed_createKeyObjects(ed: Ed): {
|
|
184
|
+
pub: PublicKeyObject;
|
|
185
|
+
priv: PrivateKeyObjectClass;
|
|
186
|
+
} {
|
|
187
|
+
const publicKeyData = ed.getPublicKey();
|
|
188
|
+
const privateKeyData = ed.getPrivateKey();
|
|
189
|
+
const pub = KeyObject.createKeyObject(
|
|
190
|
+
'public',
|
|
191
|
+
publicKeyData,
|
|
192
|
+
KFormatType.DER,
|
|
193
|
+
KeyEncoding.SPKI,
|
|
194
|
+
) as PublicKeyObject;
|
|
195
|
+
const priv = KeyObject.createKeyObject(
|
|
196
|
+
'private',
|
|
197
|
+
privateKeyData,
|
|
198
|
+
KFormatType.DER,
|
|
199
|
+
KeyEncoding.PKCS8,
|
|
200
|
+
) as PrivateKeyObjectClass;
|
|
201
|
+
return { pub, priv };
|
|
202
|
+
}
|
|
203
|
+
|
|
181
204
|
// Node API
|
|
205
|
+
function ed_formatKeyPairOutput(
|
|
206
|
+
ed: Ed,
|
|
207
|
+
encoding: KeyPairGenConfig,
|
|
208
|
+
): {
|
|
209
|
+
publicKey: PublicKeyObject | string | ArrayBuffer;
|
|
210
|
+
privateKey: PrivateKeyObjectClass | string | ArrayBuffer;
|
|
211
|
+
} {
|
|
212
|
+
const { publicFormat, privateFormat, cipher, passphrase } = encoding;
|
|
213
|
+
const { pub, priv } = ed_createKeyObjects(ed);
|
|
214
|
+
|
|
215
|
+
let publicKey: PublicKeyObject | string | ArrayBuffer;
|
|
216
|
+
let privateKey: PrivateKeyObjectClass | string | ArrayBuffer;
|
|
217
|
+
|
|
218
|
+
if (publicFormat == null || publicFormat === -1) {
|
|
219
|
+
publicKey = pub;
|
|
220
|
+
} else {
|
|
221
|
+
const format =
|
|
222
|
+
publicFormat === KFormatType.PEM ? KFormatType.PEM : KFormatType.DER;
|
|
223
|
+
const exported = pub.handle.exportKey(format, KeyEncoding.SPKI);
|
|
224
|
+
if (format === KFormatType.PEM) {
|
|
225
|
+
publicKey = Buffer.from(new Uint8Array(exported)).toString('utf-8');
|
|
226
|
+
} else {
|
|
227
|
+
publicKey = exported;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (privateFormat == null || privateFormat === -1) {
|
|
232
|
+
privateKey = priv;
|
|
233
|
+
} else {
|
|
234
|
+
const format =
|
|
235
|
+
privateFormat === KFormatType.PEM ? KFormatType.PEM : KFormatType.DER;
|
|
236
|
+
const exported = priv.handle.exportKey(
|
|
237
|
+
format,
|
|
238
|
+
KeyEncoding.PKCS8,
|
|
239
|
+
cipher,
|
|
240
|
+
passphrase,
|
|
241
|
+
);
|
|
242
|
+
if (format === KFormatType.PEM) {
|
|
243
|
+
privateKey = Buffer.from(new Uint8Array(exported)).toString('utf-8');
|
|
244
|
+
} else {
|
|
245
|
+
privateKey = exported;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return { publicKey, privateKey };
|
|
250
|
+
}
|
|
251
|
+
|
|
182
252
|
export function ed_generateKeyPair(
|
|
183
253
|
isAsync: boolean,
|
|
184
254
|
type: CFRGKeyPairType,
|
|
185
255
|
encoding: KeyPairGenConfig,
|
|
186
256
|
callback: GenerateKeyPairCallback | undefined,
|
|
187
257
|
): GenerateKeyPairReturn | void {
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
} => {
|
|
195
|
-
const publicKeyRaw = ed.getPublicKey();
|
|
196
|
-
const privateKeyRaw = ed.getPrivateKey();
|
|
197
|
-
|
|
198
|
-
// Check if PEM format was requested (KFormatType.PEM = 1)
|
|
199
|
-
const isPemPublic = encoding.publicFormat === KFormatType.PEM;
|
|
200
|
-
const isPemPrivate = encoding.privateFormat === KFormatType.PEM;
|
|
201
|
-
|
|
202
|
-
// Convert ArrayBuffer to string for PEM format
|
|
203
|
-
const arrayBufferToString = (ab: ArrayBuffer): string => {
|
|
204
|
-
return Buffer.from(new Uint8Array(ab)).toString('utf-8');
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const publicKey = isPemPublic
|
|
208
|
-
? arrayBufferToString(publicKeyRaw)
|
|
209
|
-
: publicKeyRaw;
|
|
210
|
-
const privateKey = isPemPrivate
|
|
211
|
-
? arrayBufferToString(privateKeyRaw)
|
|
212
|
-
: privateKeyRaw;
|
|
213
|
-
|
|
214
|
-
return { publicKey, privateKey };
|
|
258
|
+
const derConfig: KeyPairGenConfig = {
|
|
259
|
+
...encoding,
|
|
260
|
+
publicFormat: KFormatType.DER,
|
|
261
|
+
publicType: KeyEncoding.SPKI,
|
|
262
|
+
privateFormat: KFormatType.DER,
|
|
263
|
+
privateType: KeyEncoding.PKCS8,
|
|
215
264
|
};
|
|
265
|
+
const ed = new Ed(type, derConfig);
|
|
216
266
|
|
|
217
|
-
// Async path
|
|
218
267
|
if (isAsync) {
|
|
219
268
|
if (!callback) {
|
|
220
|
-
// This should not happen if called from public API
|
|
221
269
|
throw new Error('A callback is required for async key generation.');
|
|
222
270
|
}
|
|
223
271
|
ed.generateKeyPair()
|
|
224
272
|
.then(() => {
|
|
225
|
-
const { publicKey, privateKey } =
|
|
273
|
+
const { publicKey, privateKey } = ed_formatKeyPairOutput(ed, encoding);
|
|
226
274
|
callback(undefined, publicKey, privateKey);
|
|
227
275
|
})
|
|
228
276
|
.catch(err => {
|
|
@@ -231,7 +279,6 @@ export function ed_generateKeyPair(
|
|
|
231
279
|
return;
|
|
232
280
|
}
|
|
233
281
|
|
|
234
|
-
// Sync path
|
|
235
282
|
let err: Error | undefined;
|
|
236
283
|
try {
|
|
237
284
|
ed.generateKeyPairSync();
|
|
@@ -241,7 +288,7 @@ export function ed_generateKeyPair(
|
|
|
241
288
|
|
|
242
289
|
const { publicKey, privateKey } = err
|
|
243
290
|
? { publicKey: undefined, privateKey: undefined }
|
|
244
|
-
:
|
|
291
|
+
: ed_formatKeyPairOutput(ed, encoding);
|
|
245
292
|
|
|
246
293
|
if (callback) {
|
|
247
294
|
callback(err, publicKey, privateKey);
|
|
@@ -374,29 +421,14 @@ export async function ed_generateKeyPairWebCrypto(
|
|
|
374
421
|
await ed.generateKeyPair();
|
|
375
422
|
|
|
376
423
|
const algorithmName = type === 'ed25519' ? 'Ed25519' : 'Ed448';
|
|
424
|
+
const { pub, priv } = ed_createKeyObjects(ed);
|
|
377
425
|
|
|
378
|
-
const publicKeyData = ed.getPublicKey();
|
|
379
|
-
const privateKeyData = ed.getPrivateKey();
|
|
380
|
-
|
|
381
|
-
const pub = KeyObject.createKeyObject(
|
|
382
|
-
'public',
|
|
383
|
-
publicKeyData,
|
|
384
|
-
KFormatType.DER,
|
|
385
|
-
KeyEncoding.SPKI,
|
|
386
|
-
) as PublicKeyObject;
|
|
387
426
|
const publicKey = new CryptoKey(
|
|
388
427
|
pub,
|
|
389
428
|
{ name: algorithmName } as SubtleAlgorithm,
|
|
390
429
|
publicUsages,
|
|
391
430
|
true,
|
|
392
431
|
);
|
|
393
|
-
|
|
394
|
-
const priv = KeyObject.createKeyObject(
|
|
395
|
-
'private',
|
|
396
|
-
privateKeyData,
|
|
397
|
-
KFormatType.DER,
|
|
398
|
-
KeyEncoding.PKCS8,
|
|
399
|
-
) as PrivateKeyObjectClass;
|
|
400
432
|
const privateKey = new CryptoKey(
|
|
401
433
|
priv,
|
|
402
434
|
{ name: algorithmName } as SubtleAlgorithm,
|
|
@@ -434,29 +466,14 @@ export async function x_generateKeyPairWebCrypto(
|
|
|
434
466
|
await ed.generateKeyPair();
|
|
435
467
|
|
|
436
468
|
const algorithmName = type === 'x25519' ? 'X25519' : 'X448';
|
|
469
|
+
const { pub, priv } = ed_createKeyObjects(ed);
|
|
437
470
|
|
|
438
|
-
const publicKeyData = ed.getPublicKey();
|
|
439
|
-
const privateKeyData = ed.getPrivateKey();
|
|
440
|
-
|
|
441
|
-
const pub = KeyObject.createKeyObject(
|
|
442
|
-
'public',
|
|
443
|
-
publicKeyData,
|
|
444
|
-
KFormatType.DER,
|
|
445
|
-
KeyEncoding.SPKI,
|
|
446
|
-
) as PublicKeyObject;
|
|
447
471
|
const publicKey = new CryptoKey(
|
|
448
472
|
pub,
|
|
449
473
|
{ name: algorithmName } as SubtleAlgorithm,
|
|
450
474
|
publicUsages,
|
|
451
475
|
true,
|
|
452
476
|
);
|
|
453
|
-
|
|
454
|
-
const priv = KeyObject.createKeyObject(
|
|
455
|
-
'private',
|
|
456
|
-
privateKeyData,
|
|
457
|
-
KFormatType.DER,
|
|
458
|
-
KeyEncoding.PKCS8,
|
|
459
|
-
) as PrivateKeyObjectClass;
|
|
460
477
|
const privateKey = new CryptoKey(
|
|
461
478
|
priv,
|
|
462
479
|
{ name: algorithmName } as SubtleAlgorithm,
|
package/src/hash.ts
CHANGED
|
@@ -120,7 +120,7 @@ class Hash extends Stream.Transform {
|
|
|
120
120
|
* @param encoding The `encoding` of the return value.
|
|
121
121
|
*/
|
|
122
122
|
digest(): Buffer;
|
|
123
|
-
digest(encoding: Encoding):
|
|
123
|
+
digest(encoding: Encoding): string;
|
|
124
124
|
digest(encoding?: Encoding): Buffer | string {
|
|
125
125
|
const nativeDigest = this.native.digest(encoding);
|
|
126
126
|
|
|
@@ -296,6 +296,12 @@ const internalDigest = (
|
|
|
296
296
|
return arrayBuffer;
|
|
297
297
|
};
|
|
298
298
|
|
|
299
|
+
export function hash(
|
|
300
|
+
algorithm: string,
|
|
301
|
+
data: BinaryLike,
|
|
302
|
+
outputEncoding: Encoding,
|
|
303
|
+
): string;
|
|
304
|
+
export function hash(algorithm: string, data: BinaryLike): Buffer;
|
|
299
305
|
export function hash(
|
|
300
306
|
algorithm: string,
|
|
301
307
|
data: BinaryLike,
|
package/src/specs/utils.nitro.ts
CHANGED
|
@@ -2,4 +2,6 @@ import { type HybridObject } from 'react-native-nitro-modules';
|
|
|
2
2
|
|
|
3
3
|
export interface Utils extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
|
|
4
4
|
timingSafeEqual(a: ArrayBuffer, b: ArrayBuffer): boolean;
|
|
5
|
+
bufferToString(buffer: ArrayBuffer, encoding: string): string;
|
|
6
|
+
stringToBuffer(str: string, encoding: string): ArrayBuffer;
|
|
5
7
|
}
|
package/src/utils/conversion.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Buffer as CraftzdogBuffer } from '@craftzdog/react-native-buffer';
|
|
2
2
|
import { Buffer as SafeBuffer } from 'safe-buffer';
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
import type { Utils } from '../specs/utils.nitro';
|
|
3
5
|
import type { ABV, BinaryLikeNode, BufferLike } from './types';
|
|
4
6
|
|
|
7
|
+
const utils = NitroModules.createHybridObject<Utils>('Utils');
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
10
|
* Converts supplied argument to an ArrayBuffer. Note this does not copy the
|
|
7
11
|
* data so it is faster than toArrayBuffer. Not copying is important for
|
|
@@ -93,8 +97,10 @@ export function binaryLikeToArrayBuffer(
|
|
|
93
97
|
);
|
|
94
98
|
}
|
|
95
99
|
|
|
100
|
+
if (nativeEncodings.has(encoding)) {
|
|
101
|
+
return utils.stringToBuffer(input, encoding);
|
|
102
|
+
}
|
|
96
103
|
const buffer = CraftzdogBuffer.from(input, encoding);
|
|
97
|
-
|
|
98
104
|
return buffer.buffer.slice(
|
|
99
105
|
buffer.byteOffset,
|
|
100
106
|
buffer.byteOffset + buffer.byteLength,
|
|
@@ -149,10 +155,40 @@ export function binaryLikeToArrayBuffer(
|
|
|
149
155
|
);
|
|
150
156
|
}
|
|
151
157
|
|
|
152
|
-
|
|
158
|
+
const nativeEncodings = new Set([
|
|
159
|
+
'hex',
|
|
160
|
+
'base64',
|
|
161
|
+
'base64url',
|
|
162
|
+
'utf8',
|
|
163
|
+
'utf-8',
|
|
164
|
+
'latin1',
|
|
165
|
+
'binary',
|
|
166
|
+
'ascii',
|
|
167
|
+
]);
|
|
168
|
+
|
|
169
|
+
export function ab2str(buf: ArrayBuffer, encoding: string = 'hex'): string {
|
|
170
|
+
if (nativeEncodings.has(encoding)) {
|
|
171
|
+
return utils.bufferToString(buf, encoding);
|
|
172
|
+
}
|
|
153
173
|
return CraftzdogBuffer.from(buf).toString(encoding);
|
|
154
174
|
}
|
|
155
175
|
|
|
176
|
+
/** Native C++ buffer-to-string — exposed for benchmarking */
|
|
177
|
+
export function bufferToString(
|
|
178
|
+
buf: ArrayBuffer,
|
|
179
|
+
encoding: string = 'hex',
|
|
180
|
+
): string {
|
|
181
|
+
return utils.bufferToString(buf, encoding);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Native C++ string-to-buffer — exposed for benchmarking */
|
|
185
|
+
export function stringToBuffer(
|
|
186
|
+
str: string,
|
|
187
|
+
encoding: string = 'utf-8',
|
|
188
|
+
): ArrayBuffer {
|
|
189
|
+
return utils.stringToBuffer(str, encoding);
|
|
190
|
+
}
|
|
191
|
+
|
|
156
192
|
export const kEmptyObject = Object.freeze(Object.create(null));
|
|
157
193
|
|
|
158
194
|
export * from './noble';
|