@@ -21,11 +21,12 @@ import {
21
21
fromArrayBufferToHex ,
22
22
} from '../src/crypto/crypto' ;
23
23
import { NodeCrypto } from '../src/crypto/node/crypto' ;
24
- import { createPublicKey } from 'crypto' ;
24
+ import { createPrivateKey , createPublicKey } from 'crypto' ;
25
25
26
26
const publicKey = fs . readFileSync ( './test/fixtures/public.pem' , 'utf-8' ) ;
27
27
const privateKey = fs . readFileSync ( './test/fixtures/private.pem' , 'utf-8' ) ;
28
28
const jwtPublicKeyJWT = createPublicKey ( publicKey ) . export ( { format : 'jwk' } ) ;
29
+ const jwtPrivateKeyJWT = createPrivateKey ( privateKey ) . export ( { format : 'jwk' } ) ;
29
30
30
31
/**
31
32
* Converts a Node.js Buffer to an ArrayBuffer.
@@ -100,7 +101,24 @@ describe('crypto', () => {
100
101
assert ( verified ) ;
101
102
} ) ;
102
103
103
- it ( 'should sign a message' , async ( ) => {
104
+ it ( 'should sign a message (JWT)' , async ( ) => {
105
+ const message = 'This message is signed' ;
106
+ const expectedSignatureBase64 = [
107
+ 'ufyKBV+Ar7Yq8CSmSIN9m38ch4xnWBz8CP4qHh6V+' ,
108
+ 'm4cCbeXdR1MEmWVhNJjZQFv3KL3tDAnl0Q4bTcSR/' ,
109
+ 'mmhXaRjdxyJ6xAUp0KcbVq6xsDIbnnYHSgYr3zVoS' ,
110
+ 'dRRefWSWTknN1S69fNmKEfUeBIJA93xitr3pbqtLC' ,
111
+ 'bP28XNU=' ,
112
+ ] . join ( '' ) ;
113
+
114
+ const signatureBase64 = await crypto . sign (
115
+ jwtPrivateKeyJWT as unknown as JwkCertificate ,
116
+ message
117
+ ) ;
118
+ assert . strictEqual ( signatureBase64 , expectedSignatureBase64 ) ;
119
+ } ) ;
120
+
121
+ it ( 'should sign a message (PEM)' , async ( ) => {
104
122
const message = 'This message is signed' ;
105
123
const expectedSignatureBase64 = [
106
124
'ufyKBV+Ar7Yq8CSmSIN9m38ch4xnWBz8CP4qHh6V+' ,
0 commit comments