Skip to content

Commit

Permalink
feat: export error prefixes as object instead of enum (#244)
Browse files Browse the repository at this point in the history
closes #243
  • Loading branch information
mirceanis committed Aug 19, 2022
1 parent e19331d commit e5b070d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@
*
* @beta
*/
export const enum JWT_ERROR {
export const JWT_ERROR = {
/**
* Thrown when a JWT payload schema is unexpected or when validity period does not match
*/
INVALID_JWT = 'invalid_jwt',
INVALID_JWT: 'invalid_jwt',
/**
* Thrown when the verifier audience does not match the one set in the JWT payload
*/
INVALID_AUDIENCE = 'invalid_config',
INVALID_AUDIENCE: 'invalid_config',
/**
* Thrown when none of the public keys of the issuer match the signature of the JWT.
*
* This is equivalent to `NO_SUITABLE_KEYS` when the `proofPurpose` is NOT specified.
*/
INVALID_SIGNATURE = 'invalid_signature',
INVALID_SIGNATURE: 'invalid_signature',
/**
* Thrown when the DID document of the issuer does not have any keys that match the signature for the given
* `proofPurpose`.
*
* This is equivalent to `invalid_signature`, when a `proofPurpose` is specified.
*/
NO_SUITABLE_KEYS = 'no_suitable_keys',
NO_SUITABLE_KEYS: 'no_suitable_keys',
/**
* Thrown when the `alg` of the JWT or the encoding of the key is not supported
*/
NOT_SUPPORTED = 'not_supported',
NOT_SUPPORTED: 'not_supported',
/**
* Thrown when the DID resolver is unable to resolve the issuer DID.
*/
RESOLVER_ERROR = 'resolver_error',
RESOLVER_ERROR: 'resolver_error',
}
4 changes: 2 additions & 2 deletions src/__tests__/ES256Signer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Secp256r1 Signer', () => {
const signer = ES256Signer(base58ToBytes(privateKey))
const plaintext = 'thequickbrownfoxjumpedoverthelazyprogrammer'
await expect(signer(plaintext)).resolves.toEqual(
'vOTe64WujVUjEiQrAlwaPJtNADx4usSlCfe8OXHS6Np1BqJdqdJX912pVwVlAjmbqR_TMVE5i5TWB_GJVgrHgg'
'vOTe64WujVUjEiQrAlwaPJtNADx4usSlCfe8OXHS6Np1BqJdqdJX912pVwVlAjmbqR_TMVE5i5TWB_GJVgrHgg'
)
})

Expand All @@ -51,7 +51,7 @@ describe('Secp256r1 Signer', () => {
'vOTe64WujVUjEiQrAlwaPJtNADx4usSlCfe8OXHS6Np1BqJdqdJX912pVwVlAjmbqR_TMVE5i5TWB_GJVgrHgg'
)
})

it('refuses wrong key size (too short)', async () => {
expect.assertions(1)
const privateKey = '040f1dbf0a2ca86875447a7c010b0fc6d39d76859c458fbe8f2bf775a40ad7'
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/JWT.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ describe('verifyJWT()', () => {
const jwt = await createJWT({ aud }, { issuer: did, signer })
const { payload, issuer } = await verifyJWT(jwt, {
resolver,
policies: { aud: false }
policies: { aud: false },
})
expect(payload).toBeDefined()
expect(issuer).toEqual(did)
Expand Down

0 comments on commit e5b070d

Please sign in to comment.