Skip to content

Commit ad0cb6c

Browse files
committed
fix: some Jose fixes, WIP
1 parent 37c96cc commit ad0cb6c

2 files changed

Lines changed: 10 additions & 34 deletions

File tree

  • packages
    • example/src/testing/tests/webcryptoTests
    • react-native-quick-crypto/src
Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
// react-native-quick-crypto is polyfilled in this example app, so jose will use it
22
import { CompactEncrypt, exportJWK, importJWK } from 'jose';
3+
import type { KeyObject } from 'jose';
34
import { describe, it } from '../../MochaRNAdapter';
45
import crypto from 'react-native-quick-crypto';
56

67
describe('jose compatibility', () => {
78
it('importJwk', async () => {
89
const key = {
910
kty: 'RSA',
11+
use: 'enc',
1012
alg: 'RSA-OAEP-256',
1113
n: 'qPfgaTEWEP3S9w0tgsicURfo-nLW09_0KfOPinhYZ4ouzU-3xC4pSlEp8Ut9FgL0AgqNslNaK34Kq-NZjO9DAQ==',
1214
e: 'AQAB',
1315
};
1416
const value = 'hello world';
1517

16-
try {
17-
const publicKey = await importJWK(key);
18-
const plaintext = Buffer.from(value, 'utf-8');
19-
const encryptedValue = await new CompactEncrypt(plaintext)
20-
.setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM' })
21-
.encrypt(publicKey);
18+
const publicKey = await importJWK(key);
19+
const plaintext = Buffer.from(value, 'utf-8');
20+
const encryptedValue = await new CompactEncrypt(plaintext)
21+
.setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM' })
22+
.encrypt(publicKey);
2223

23-
console.log(encryptedValue);
24-
} catch (e) {
25-
console.error(e);
26-
console.log(e.stack);
27-
}
24+
console.log(encryptedValue);
2825
});
2926

3027
it('exportJWK', async () => {
@@ -33,13 +30,8 @@ describe('jose compatibility', () => {
3330
console.error('internal error', err);
3431
return;
3532
}
36-
try {
37-
const publicKeyJwk = exportJWK(publicKey as CryptoKey);
38-
console.log(publicKeyJwk);
39-
} catch (e) {
40-
console.error(e);
41-
console.log(e.stack);
42-
}
33+
const publicKeyJwk = exportJWK(publicKey as KeyObject);
34+
console.log(publicKeyJwk);
4335
});
4436
});
4537
});

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -714,10 +714,6 @@ export class SecretKeyObject extends KeyObject {
714714
super('secret', handle);
715715
}
716716

717-
get [Symbol.toStringTag]() {
718-
return 'SecretKeyObject';
719-
}
720-
721717
// get symmetricKeySize() {
722718
// return this[kHandle].getSymmetricKeySize();
723719
// }
@@ -753,10 +749,6 @@ class AsymmetricKeyObject extends KeyObject {
753749
super(type, handle);
754750
}
755751

756-
get [Symbol.toStringTag]() {
757-
return 'AsymmetricKeyObject';
758-
}
759-
760752
private _asymmetricKeyType?: AsymmetricKeyType;
761753

762754
get asymmetricKeyType(): AsymmetricKeyType {
@@ -789,10 +781,6 @@ export class PublicKeyObject extends AsymmetricKeyObject {
789781
super('public', handle);
790782
}
791783

792-
get [Symbol.toStringTag]() {
793-
return 'PublicKeyObject';
794-
}
795-
796784
export(options: EncodingOptions) {
797785
if (options?.format === 'jwk') {
798786
throw new Error('PublicKey export for jwk is not implemented');
@@ -811,10 +799,6 @@ export class PrivateKeyObject extends AsymmetricKeyObject {
811799
super('private', handle);
812800
}
813801

814-
get [Symbol.toStringTag]() {
815-
return 'PrivateKeyObject';
816-
}
817-
818802
export(options: EncodingOptions) {
819803
if (options?.format === 'jwk') {
820804
if (options.passphrase !== undefined) {

0 commit comments

Comments
 (0)