Skip to content

Commit f6678a4

Browse files
committed
feat: scaffold hash hybrid object
1 parent 81ccd11 commit f6678a4

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

docs/implementation-coverage.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ This document attempts to describe the implementation status of Crypto APIs/Inte
4343
*`ecdh.getPublicKey([encoding][, format])`
4444
*`ecdh.setPrivateKey(privateKey[, encoding])`
4545
*`ecdh.setPublicKey(publicKey[, encoding])`
46-
* Class: `Hash`
47-
* `hash.copy([options])`
48-
* `hash.digest([encoding])`
49-
* `hash.update(data[, inputEncoding])`
46+
* Class: `Hash`
47+
* `hash.copy([options])`
48+
* `hash.digest([encoding])`
49+
* `hash.update(data[, inputEncoding])`
5050
* ❌ Class: `Hmac`
5151
*`hmac.digest([encoding])`
5252
*`hmac.update(data[, inputEncoding])`
@@ -101,7 +101,7 @@ This document attempts to describe the implementation status of Crypto APIs/Inte
101101
*`crypto.createDiffieHellman(primeLength[, generator])`
102102
*`crypto.createDiffieHellmanGroup(name)`
103103
*`crypto.createECDH(curveName)`
104-
* `crypto.createHash(algorithm[, options])`
104+
* `crypto.createHash(algorithm[, options])`
105105
*`crypto.createHmac(algorithm, key[, options])`
106106
*`crypto.createPrivateKey(key)`
107107
*`crypto.createPublicKey(key)`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@release-it/conventional-changelog": "^9.0.3",
2222
"release-it": "^17.10.0"
2323
},
24-
"packageManager": "bun@1.1.26",
24+
"packageManager": "bun@1.2.0",
2525
"release-it": {
2626
"npm": {
2727
"publish": false
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Stream } from 'readable-stream';
2+
import { NitroModules } from 'react-native-nitro-modules';
3+
import type { TransformOptions } from 'readable-stream';
4+
import type { Hash as NativeHash } from './specs/hash.nitro';
5+
import type { HashAlgorithm } from './utils';
6+
7+
interface HashArgs {
8+
algorithm: HashAlgorithm;
9+
options: Record<string, TransformOptions>;
10+
}
11+
12+
class Hash extends Stream.Transform {
13+
private native: NativeHash;
14+
15+
constructor({ options }: HashArgs) {
16+
super(options);
17+
this.native = NitroModules.createHybridObject<NativeHash>('Hash');
18+
console.log(`${this.native.name} created`);
19+
}
20+
}
21+
22+
export function createHash(
23+
algorithm: HashAlgorithm,
24+
options?: TransformOptions,
25+
): Hash {
26+
return new Hash({
27+
algorithm,
28+
options: options as Record<string, TransformOptions>,
29+
});
30+
}
31+
32+
export const hashExports = {
33+
createHash,
34+
};

packages/react-native-quick-crypto/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { Buffer } from '@craftzdog/react-native-buffer';
33

44
// API imports
5+
import { hashExports as hash } from './hash';
56
import * as keys from './keys';
67
import { cipherExports as cipher } from './cipher';
78
import * as ed from './ed';
@@ -18,6 +19,7 @@ import * as utils from './utils';
1819
const QuickCrypto = {
1920
...keys,
2021
...cipher,
22+
...hash,
2123
...ed,
2224
...pbkdf2,
2325
...random,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { HybridObject } from 'react-native-nitro-modules';
2+
import type { TransformOptions } from 'readable-stream';
3+
4+
export interface Hash extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
5+
copy(options: TransformOptions[]): ArrayBuffer;
6+
}

0 commit comments

Comments
 (0)