Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit c95abc6

Browse files
committed
change to curve P-256 and algorithm ES256 for generated keys
1 parent 38a60ab commit c95abc6

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/commands/key-generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class GenerateIdentityKeyCommand extends Command {
1212
* @override
1313
*/
1414
protected async action(): Promise<void> {
15-
const key = await JWK.generate('EC', 'secp256k1')
15+
const key = await JWK.generate('EC', 'P-256')
1616
const pem = key.toPEM(true)
1717
try {
1818
const filename = await writeFile('./identity-key.pem', pem)

src/commands/payid-sign.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
convertToVerifiedAddress,
33
signWithKeys,
4-
getDefaultAlgorithm,
54
IdentityKeySigningParams,
65
toKey,
76
} from '@payid-org/utils'
7+
import { JWKECKey, JWKOctKey, JWKOKPKey, JWKRSAKey } from 'jose'
88

99
import Command from './Command'
1010

@@ -69,3 +69,18 @@ export default class SignPayIdCommand extends Command {
6969
)
7070
}
7171
}
72+
73+
export function getDefaultAlgorithm(
74+
jwk: JWKRSAKey | JWKECKey | JWKOctKey | JWKOKPKey,
75+
): string {
76+
if (jwk.kty === 'EC') {
77+
return 'ES256'
78+
}
79+
if (jwk.kty === 'oct') {
80+
return 'HS512'
81+
}
82+
if (jwk.kty === 'OKP') {
83+
return 'EdDSA'
84+
}
85+
return 'RS512'
86+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'mocha'
2+
import { assert } from 'chai'
3+
import { JWK } from 'jose'
4+
5+
import { getDefaultAlgorithm } from '../../src/commands/payid-sign'
6+
7+
describe('when getDefaultAlgorithm()', function (): void {
8+
it('given an EC key then returns ES256', async function (): Promise<void> {
9+
const key = await JWK.generate('EC')
10+
const algorithm = getDefaultAlgorithm(key.toJWK())
11+
assert.equal(algorithm, 'ES256')
12+
})
13+
14+
it('given an RSA key then returns RS512', async function (): Promise<void> {
15+
const key = await JWK.generate('RSA')
16+
const algorithm = getDefaultAlgorithm(key.toJWK())
17+
assert.equal(algorithm, 'RS512')
18+
})
19+
})

0 commit comments

Comments
 (0)