Skip to content

Commit b1b0148

Browse files
authored
feat: add more tests for ed25519 (#542)
1 parent ae88f65 commit b1b0148

File tree

8 files changed

+39
-13
lines changed

8 files changed

+39
-13
lines changed

.github/workflows/validate-js.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868

6969
- name: Bootstrap JS
7070
run: |
71-
bun install --frozen-lockfile
71+
bun install
7272
7373
- name: Run ESLint (rnqc)
7474
run: |
@@ -83,4 +83,4 @@ jobs:
8383
bun format:fix
8484
8585
- name: Verify no files have changed after auto-fix
86-
run: git diff --exit-code HEAD
86+
run: git diff --exit-code HEAD -- . ':(exclude)bun.lockb'

bun.lockb

-296 Bytes
Binary file not shown.

example/ios/Podfile.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PODS:
3131
- ReactCommon/turbomodule/core
3232
- Yoga
3333
- OpenSSL-Universal (3.3.2000)
34-
- QuickCrypto (1.0.0-beta.5):
34+
- QuickCrypto (1.0.0-beta.6):
3535
- DoubleConversion
3636
- glog
3737
- hermes-engine
@@ -1719,8 +1719,8 @@ DEPENDENCIES:
17191719
- fmt (from `../../node_modules/react-native/third-party-podspecs/fmt.podspec`)
17201720
- glog (from `../../node_modules/react-native/third-party-podspecs/glog.podspec`)
17211721
- hermes-engine (from `../../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
1722-
- NitroModules (from `../node_modules/react-native-nitro-modules`)
1723-
- QuickCrypto (from `../node_modules/react-native-quick-crypto`)
1722+
- NitroModules (from `../../node_modules/react-native-nitro-modules`)
1723+
- QuickCrypto (from `../../node_modules/react-native-quick-crypto`)
17241724
- RCT-Folly (from `../../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
17251725
- RCT-Folly/Fabric (from `../../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
17261726
- RCTDeprecation (from `../../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation`)
@@ -1805,9 +1805,9 @@ EXTERNAL SOURCES:
18051805
:podspec: "../../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
18061806
:tag: hermes-2024-09-09-RNv0.76.0-db6d12e202e15f7a446d8848d6ca8f7abb3cfb32
18071807
NitroModules:
1808-
:path: "../node_modules/react-native-nitro-modules"
1808+
:path: "../../node_modules/react-native-nitro-modules"
18091809
QuickCrypto:
1810-
:path: "../node_modules/react-native-quick-crypto"
1810+
:path: "../../node_modules/react-native-quick-crypto"
18111811
RCT-Folly:
18121812
:podspec: "../../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec"
18131813
RCTDeprecation:
@@ -1940,7 +1940,7 @@ SPEC CHECKSUMS:
19401940
hermes-engine: 46f1ffbf0297f4298862068dd4c274d4ac17a1fd
19411941
NitroModules: 55f64932b4581a7d02103bc35b84c7bd3204106b
19421942
OpenSSL-Universal: b60a3702c9fea8b3145549d421fdb018e53ab7b4
1943-
QuickCrypto: 8d76ae3a0bf60509f671193eb4ed666a80da34cb
1943+
QuickCrypto: e68316432823f70bdae0bf1486dc5e9afdfdff4d
19441944
RCT-Folly: 84578c8756030547307e4572ab1947de1685c599
19451945
RCTDeprecation: fde92935b3caa6cb65cbff9fbb7d3a9867ffb259
19461946
RCTRequired: 75c6cee42d21c1530a6f204ba32ff57335d19007

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"react-native-bouncy-checkbox": "4.0.1",
3737
"react-native-nitro-modules": "0.18.1",
3838
"react-native-quick-base64": "2.1.2",
39-
"react-native-quick-crypto": "1.0.0-beta.5",
39+
"react-native-quick-crypto": "workspace:*",
4040
"react-native-safe-area-context": "4.14.0",
4141
"react-native-screens": "3.35.0",
4242
"react-native-vector-icons": "^10.1.0",

example/src/navigators/Root.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Tab = createBottomTabNavigator();
1212
export const Root: React.FC = () => {
1313
return (
1414
<NavigationContainer>
15-
<Tab.Navigator initialRouteName="Benchmarks">
15+
<Tab.Navigator initialRouteName="Tests">
1616
<Tab.Screen
1717
name="Tests"
1818
component={TestStack}

example/src/tests/ed25519/ed25519_tests.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-unused-expressions */
2-
import { Ed } from 'react-native-quick-crypto';
2+
import { Ed, randomBytes, ab2str } from 'react-native-quick-crypto';
33
// import type {
44
// // KeyObject,
55
// // CFRGKeyPairType,
@@ -46,11 +46,32 @@ types.map((type) => {
4646
});
4747
*/
4848

49-
test(SUITE, 'sign/verify', async () => {
49+
test(SUITE, 'sign/verify - round trip happy', async () => {
5050
const data = Buffer.from('hello world');
5151
const ed = new Ed('ed25519', {});
5252
await ed.generateKeyPair();
5353
const signature = await ed.sign(data.buffer);
5454
const verified = await ed.verify(signature, data.buffer);
5555
expect(verified).to.be.true;
5656
});
57+
58+
test(SUITE, 'sign/verify - round trip sad', async () => {
59+
const data1 = Buffer.from('hello world');
60+
const data2 = Buffer.from('goodbye cruel world');
61+
const ed = new Ed('ed25519', {});
62+
await ed.generateKeyPair();
63+
const signature = await ed.sign(data1.buffer);
64+
const verified = await ed.verify(signature, data2.buffer);
65+
expect(verified).to.be.false;
66+
});
67+
68+
test(SUITE, 'sign/verify - bad signature does not verify', async () => {
69+
const data = Buffer.from('hello world');
70+
const ed = new Ed('ed25519', {});
71+
await ed.generateKeyPair();
72+
const signature = await ed.sign(data.buffer);
73+
const signature2 = randomBytes(64).buffer;
74+
expect(ab2str(signature2)).not.to.equal(ab2str(signature));
75+
const verified = await ed.verify(signature2, data.buffer);
76+
expect(verified).to.be.false;
77+
});

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
},
4747
{
4848
"file": "example/package.json",
49-
"path": "version"
49+
"path": [
50+
"version",
51+
"dependencies.react-native-quick-crypto"
52+
]
5053
}
5154
]
5255
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ global.process.nextTick = setImmediate;
6060
// exports
6161
export default QuickCrypto;
6262
export * from './ed';
63+
export * from './pbkdf2';
64+
export * from './random';
6365
export * from './utils';
6466

6567
// Additional exports for CommonJS compatibility

0 commit comments

Comments
 (0)