11// react-native-quick-crypto is polyfilled in this example app, so jose will use it
22import { CompactEncrypt , exportJWK , importJWK } from 'jose' ;
3+ import type { KeyObject } from 'jose' ;
34import { describe , it } from '../../MochaRNAdapter' ;
45import crypto from 'react-native-quick-crypto' ;
56
67describe ( '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} ) ;
0 commit comments