Skip to content

Commit

Permalink
tests: add new test for kyobject support
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiofrittoli committed Dec 14, 2024
1 parent a105a37 commit 9f2389c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions __tests__/signature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import crypto from 'crypto'
import Signature from '@/index'


describe( 'Signature.sign()', () => {
it( 'supports crypto KeyObject', () => {
const key = crypto.createSecretKey( Buffer.from( 'myscretkey' ) )
const signature = Signature.sign( 'My message', key, 'HS1' )

expect( signature.toString( 'base64url' ) )
.toBe( 'MI446pz8PBXelRlxq7Ihw2AraVU' )
} )
} )


describe( 'Signature.sign() - HMAC', () => {

it( 'creates a signature with HS1', () => {
Expand Down
11 changes: 11 additions & 0 deletions __tests__/verify.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import crypto from 'crypto'
import Signature from '@/index'

describe( 'Signature.isValid()', () => {
it( 'supports crypto KeyObject', () => {
const key = crypto.createSecretKey( Buffer.from( 'myscretkey' ) )
const signature = Signature.sign( 'My message', key, 'HS1' )

expect(
Signature.isValid( signature, 'My message', key, 'HS1' )
).toBe( true )
} )
} )


describe( 'Signature.isValid() - HMAC', () => {

Expand Down

0 comments on commit 9f2389c

Please sign in to comment.