Skip to content

Commit

Permalink
fix: use EdDSA as the 'alg' header for Ed25519 signatures (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjg authored Oct 1, 2020
1 parent 57ad660 commit 2736ee7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/SignerAlgorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ interface SignerAlgorithms {
const algorithms: SignerAlgorithms = {
ES256K: ES256KSigner(),
'ES256K-R': ES256KSigner(true),
Ed25519: Ed25519Signer()
// This is actually incorrect but retained for backwards compatibility
// see https://github.com/decentralized-identity/did-jwt/issues/130
Ed25519: Ed25519Signer(),
EdDSA: Ed25519Signer()
}

function SignerAlgorithm(alg: string): SignerAlgorithm {
Expand Down
5 changes: 4 additions & 1 deletion src/VerifierAlgorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ interface Algorithms {
const algorithms: Algorithms = {
ES256K: verifyES256K,
'ES256K-R': verifyRecoverableES256K,
Ed25519: verifyEd25519
// This is actually incorrect but retained for backwards compatibility
// see https://github.com/decentralized-identity/did-jwt/issues/130
Ed25519: verifyEd25519,
EdDSA: verifyEd25519
}

function VerifierAlgorithm(alg: string): Verifier {
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/SignerAlgorithm-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ describe('SignerAlgorithm', () => {
expect(typeof SignerAlgorithm('Ed25519')).toEqual('function')
})

it('supports EdDSA', () => {
expect(typeof SignerAlgorithm('EdDSA')).toEqual('function')
})

it('fails on unsupported algorithm', () => {
expect(() => SignerAlgorithm('BADALGO')).toThrowError('Unsupported algorithm BADALGO')
})
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/VerifierAlgorithm-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ describe('VerifierAlgorithm', () => {
it('fails on unsupported algorithm', () => {
expect(() => VerifierAlgorithm('BADALGO')).toThrowError('Unsupported algorithm BADALGO')
})

it('supports EdDSA', () => {
expect(typeof VerifierAlgorithm('EdDSA')).toEqual('function')
})
})

const mnid = '2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX'
Expand Down

0 comments on commit 2736ee7

Please sign in to comment.