Skip to content

Commit 37c96cc

Browse files
committed
fix: export types, helper fns
1 parent 3a0dba7 commit 37c96cc

16 files changed

Lines changed: 67 additions & 57 deletions

File tree

packages/example/src/testing/fixtures/aes_gcm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TagLength } from '../../../../react-native-quick-crypto/src/keys';
1+
import type { TagLength } from 'react-native-quick-crypto';
22
import { decodeHex } from '../tests/util';
33
import type {
44
AesEncryptDecryptTestVector,

packages/example/src/testing/tests/CipherTests/GenerateKeyPairTests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert, expect } from 'chai';
22
import type { Buffer } from '@craftzdog/react-native-buffer';
33
import { describe, it } from '../../MochaRNAdapter';
44
import crypto from 'react-native-quick-crypto';
5-
import type { KeyPairKey } from '../../../../../react-native-quick-crypto/src/Cipher';
5+
import type { KeyObject } from 'react-native-quick-crypto';
66

77
// Constructs a regular expression for a PEM-encoded key with the given label.
88
function getRegExpForPEM(label: string, cipher?: string | null) {
@@ -16,7 +16,7 @@ function getRegExpForPEM(label: string, cipher?: string | null) {
1616
return new RegExp(`^${head}${rfc1421Header}\n${body}\n${end}\n$`);
1717
}
1818

19-
function assertApproximateSize(kpk: KeyPairKey, expectedSize: number) {
19+
function assertApproximateSize(kpk: string | Buffer | KeyObject, expectedSize: number) {
2020
const key = kpk as unknown as Buffer;
2121
const u = typeof key === 'string' ? 'chars' : 'bytes';
2222
const min = Math.floor(0.9 * expectedSize);

packages/example/src/testing/tests/CipherTests/PublicCipherTests.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { assert, expect } from 'chai';
22
import { Buffer } from '@craftzdog/react-native-buffer';
33
import { describe, it } from '../../MochaRNAdapter';
44
import crypto from 'react-native-quick-crypto';
5-
import type { KeyPairKey } from '../../../../../react-native-quick-crypto/src/Cipher';
6-
import type { EncodingOptions } from '../../../../../react-native-quick-crypto/src/keys';
5+
import type { EncodingOptions, KeyPairKey } from 'react-native-quick-crypto';
76
// import { PrivateKey } from 'sscrypto/node';
87

98
// Tests that a key pair can be used for encryption / decryption.

packages/example/src/testing/tests/CipherTests/generateKey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { expect } from 'chai';
44
import crypto from 'react-native-quick-crypto';
55
import { describe, it } from '../../MochaRNAdapter';
6-
import type { AESLength } from '../../../../../react-native-quick-crypto/src/keys';
6+
import type { AESLength } from 'react-native-quick-crypto';
77

88
const { generateKey, generateKeySync } = crypto;
99

packages/example/src/testing/tests/RandomTests/randomTests.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ import { describe, it } from '../../MochaRNAdapter';
2626
import { Buffer } from '@craftzdog/react-native-buffer';
2727
import { assert } from 'chai';
2828
import type { Done } from 'mocha';
29-
import {
30-
ab2str,
31-
abvToArrayBuffer,
32-
} from '../../../../../react-native-quick-crypto/src/Utils';
29+
const { ab2str, abvToArrayBuffer } = crypto;
3330

3431
describe('random', () => {
3532
// TODO (Szymon)
@@ -612,7 +609,10 @@ describe('random', () => {
612609
[true, NaN, null, {}, [], 10].forEach((val) => {
613610
it(`expect type error: ${val}`, () => {
614611
assert.throws(
615-
() => crypto.randomInt(0, 1, val),
612+
() => {
613+
// @ts-expect-error Intentionally passing invalid type for callback test
614+
crypto.randomInt(0, 1, val);
615+
},
616616
/callback must be a function or undefined/,
617617
);
618618
});

packages/example/src/testing/tests/issues/specific_issues.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { BinaryLikeNode } from '../../../../../react-native-quick-crypto/src/Utils';
1+
import type { BinaryLikeNode } from 'react-native-quick-crypto';
22
import { Buffer as CraftzdogBuffer } from '@craftzdog/react-native-buffer';
33
import { Buffer as FerossBuffer } from 'buffer';
44
import crypto from 'react-native-quick-crypto';

packages/example/src/testing/tests/pbkdf2Tests/pbkdf2Tests.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { Buffer as SBuffer } from 'safe-buffer';
66

77
import type { Done } from 'mocha';
88
import { fixtures, type Fixture } from './fixtures';
9-
import type { HashAlgorithm } from '../../../../../react-native-quick-crypto/src/keys';
10-
import type { BinaryLike } from '../../../../../react-native-quick-crypto/src/Utils';
9+
import type { BinaryLike, HashAlgorithm } from 'react-native-quick-crypto';
1110

1211
type TestFixture = [string, string, number, number, string];
1312

packages/example/src/testing/tests/webcryptoTests/deriveBits.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { expect } from 'chai';
22
import crypto from 'react-native-quick-crypto';
33
import { describe, it } from '../../MochaRNAdapter';
4-
import { ab2str } from '../../../../../react-native-quick-crypto/src/Utils';
5-
import type { HashAlgorithm } from '../../../../../react-native-quick-crypto/src/keys';
4+
import type { HashAlgorithm } from 'react-native-quick-crypto';
65

7-
const { subtle } = crypto;
6+
const { subtle, ab2str } = crypto;
87

98
type TestFixture = [string, string, number, HashAlgorithm, number, string];
109

packages/example/src/testing/tests/webcryptoTests/digest.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import { expect } from 'chai';
22
import { Buffer } from '@craftzdog/react-native-buffer';
3-
import crypto from 'react-native-quick-crypto';
43
import { describe, it } from '../../MochaRNAdapter';
5-
import type { HashAlgorithm } from '../../../../../react-native-quick-crypto/src/keys';
6-
import {
7-
ab2str,
8-
toArrayBuffer,
9-
} from '../../../../../react-native-quick-crypto/src/Utils';
10-
import { createHash } from '../../../../../react-native-quick-crypto/src/Hash';
11-
12-
const { subtle } = crypto;
4+
import crypto from 'react-native-quick-crypto';
5+
import type { HashAlgorithm } from 'react-native-quick-crypto';
6+
7+
const { subtle, ab2str, createHash, toArrayBuffer } = crypto;
138

149
type Test = [HashAlgorithm, string, number];
1510

packages/example/src/testing/tests/webcryptoTests/encrypt_decrypt.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ import type {
1313
EncryptDecryptParams,
1414
KeyUsage,
1515
RsaOaepParams,
16-
} from '../../../../../react-native-quick-crypto/src/keys';
16+
} from 'react-native-quick-crypto';
1717
import rsa_oaep_fixtures from '../../fixtures/rsa';
1818
import aes_cbc_fixtures from '../../fixtures/aes_cbc';
1919
import aes_ctr_fixtures from '../../fixtures/aes_ctr';
2020
import aes_gcm_fixtures from '../../fixtures/aes_gcm';
2121
import { assertThrowsAsync } from '../util';
22-
import { ab2str } from '../../../../../react-native-quick-crypto/src/Utils';
2322

2423
export type RsaEncryptDecryptTestVector = {
2524
name: string;
@@ -51,7 +50,7 @@ export type BadPadding = {
5150
};
5251
export type BadPaddingVectorValue = Record<string, BadPadding>;
5352

54-
const { subtle } = crypto;
53+
const { subtle, ab2str } = crypto;
5554

5655
// This is only a partial test. The WebCrypto Web Platform Tests
5756
// will provide much greater coverage.

0 commit comments

Comments
 (0)