Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mattschoch committed Apr 3, 2024
1 parent 1335280 commit 7f2c98f
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions apps/vault/src/shared/guard/authorization.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class AuthorizationGuard implements CanActivate {
}).catch((err) => {
throw new ApplicationException({
message: err.message,
origin: err,
suggestedHttpStatusCode: HttpStatus.FORBIDDEN
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/signature/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './lib/decode'
export * from './lib/encrypt'
export * from './lib/hash-request'
export * from './lib/hash'
export * from './lib/sign'
export * from './lib/types'
export * from './lib/utils'
Expand Down
9 changes: 6 additions & 3 deletions packages/signature/src/lib/__test__/unit/decode.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { decodeJwt } from '../../decode'
import { JwtError } from '../../error'
import { signJwt } from '../../sign'
import { privateKeyToJwk } from '../../utils'

Expand All @@ -25,10 +26,12 @@ describe('decodeJwt', () => {
signature: rawJwt.split('.')[2]
})
})

it('throws an error if token is malformed', async () => {
expect(() => decodeJwt('invalid')).toThrow()
expect(() => decodeJwt('invalid')).toThrow(JwtError)
})
it('throws an error if token is formed well with unmeaningful data', async () => {
expect(() => decodeJwt('invalid.invalid.invalid')).toThrow()

it('throws an error if token is in correct format but not valid base64url encoded data', async () => {
expect(() => decodeJwt('invalid.invalid.invalid')).toThrow(JwtError)
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hash } from '../../hash-request'
import { hash } from '../../hash'

describe('hashRequest', () => {
it('hashes the given object', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/signature/src/lib/__test__/unit/mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hash } from '../../hash-request'
import { hash } from '../../hash'
import { Alg } from '../../types'

export const ALGORITHM = Alg.ES256
Expand Down
4 changes: 2 additions & 2 deletions packages/signature/src/lib/__test__/unit/verify.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { signatureToHex, toBytes } from 'viem'
import { JwtError } from '../../error'
import { hash } from '../../hash-request'
import { hash } from '../../hash'
import { secp256k1PublicKeySchema } from '../../schemas'
import { signJwt, signSecp256k1 } from '../../sign'
import { Alg, Header, JwtVerifyOptions, Payload, Secp256k1PublicKey, SigningAlg } from '../../types'
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('verifySecp256k1', () => {
})

describe('verifyJwtHeader', () => {
it('should return true when all recognized crit parameters are present in the header', () => {
it('returns true when all recognized crit parameters are present in the header', () => {
const header = {
kid: 'kid1',
alg: 'ES256K',
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/signature/src/lib/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sha256 as sha256Hash } from '@noble/hashes/sha256'
import { keccak_256 as keccak256 } from '@noble/hashes/sha3'
import { SignJWT, importJWK } from 'jose'
import { isHex, signatureToHex, toBytes, toHex } from 'viem'
import { hash } from './hash-request'
import { hash } from './hash'
import { canonicalize } from './json.util'
import { jwkBaseSchema, privateKeySchema } from './schemas'
import { EcdsaSignature, Header, Hex, Jwk, JwsdHeader, PartialJwk, Payload, PrivateKey, SigningAlg } from './types'
Expand Down
2 changes: 1 addition & 1 deletion packages/signature/src/lib/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { promisify } from 'node:util'
import { hexToBytes, isAddressEqual, recoverAddress } from 'viem'
import { decodeJwsd, decodeJwt } from './decode'
import { JwtError } from './error'
import { hash } from './hash-request'
import { hash } from './hash'
import { JwsdHeader, publicKeySchema } from './schemas'
import { eip191Hash } from './sign'
import { isSecp256k1PublicKeyJwk } from './typeguards'
Expand Down

0 comments on commit 7f2c98f

Please sign in to comment.