diff --git a/package.json b/package.json index e138b0e8..68c17407 100644 --- a/package.json +++ b/package.json @@ -176,14 +176,14 @@ "iso-random-stream": "^2.0.0", "multiformats": "^9.4.5", "node-forge": "^1.1.0", - "protons-runtime": "^1.0.2", + "protons-runtime": "^1.0.4", "uint8arrays": "^3.0.0" }, "devDependencies": { "@types/mocha": "^9.0.0", "aegir": "^37.0.12", "benchmark": "^2.1.4", - "protons": "^3.0.2", + "protons": "^3.0.4", "sinon": "^13.0.1", "util": "^0.12.3", "wherearewe": "^1.0.0" diff --git a/src/keys/index.ts b/src/keys/index.ts index 38e582bc..d72278cf 100644 --- a/src/keys/index.ts +++ b/src/keys/index.ts @@ -17,6 +17,8 @@ export { keyStretcher } export { generateEphemeralKeyPair } export { keysPBM } +export type KeyTypes = 'RSA' | 'Ed25519' | 'secp256k1' + export const supportedKeys = { rsa: RSA, ed25519: Ed25519, @@ -39,13 +41,13 @@ function typeToKey (type: string) { } // Generates a keypair of the given type and bitsize -export async function generateKeyPair (type: 'RSA' | 'Ed25519' | 'secp256k1', bits?: number): Promise { // eslint-disable-line require-await +export async function generateKeyPair (type: KeyTypes, bits?: number): Promise { // eslint-disable-line require-await return await typeToKey(type).generateKeyPair(bits ?? 2048) } // Generates a keypair of the given type and bitsize // seed is a 32 byte uint8array -export async function generateKeyPairFromSeed (type: 'RSA' | 'Ed25519' | 'secp256k1', seed: Uint8Array, bits?: number): Promise { // eslint-disable-line require-await +export async function generateKeyPairFromSeed (type: KeyTypes, seed: Uint8Array, bits?: number): Promise { // eslint-disable-line require-await if (type.toLowerCase() !== 'ed25519') { throw errcode(new Error('Seed key derivation is unimplemented for RSA or secp256k1'), 'ERR_UNSUPPORTED_KEY_DERIVATION_TYPE') } diff --git a/src/keys/keys.ts b/src/keys/keys.ts index b974434b..10efbd48 100644 --- a/src/keys/keys.ts +++ b/src/keys/keys.ts @@ -2,6 +2,7 @@ /* eslint-disable @typescript-eslint/no-namespace */ import { enumeration, encodeMessage, decodeMessage, message, bytes } from 'protons-runtime' +import type { Codec } from 'protons-runtime' export enum KeyType { RSA = 'RSA', @@ -9,19 +10,24 @@ export enum KeyType { Secp256k1 = 'Secp256k1' } +enum __KeyTypeValues { + RSA = 0, + Ed25519 = 1, + Secp256k1 = 2 +} + export namespace KeyType { export const codec = () => { - return enumeration(KeyType) + return enumeration(__KeyTypeValues) } } - export interface PublicKey { Type: KeyType Data: Uint8Array } export namespace PublicKey { - export const codec = () => { + export const codec = (): Codec => { return message({ 1: { name: 'Type', codec: KeyType.codec() }, 2: { name: 'Data', codec: bytes } @@ -43,7 +49,7 @@ export interface PrivateKey { } export namespace PrivateKey { - export const codec = () => { + export const codec = (): Codec => { return message({ 1: { name: 'Type', codec: KeyType.codec() }, 2: { name: 'Data', codec: bytes }