Skip to content

Commit 7c57be6

Browse files
committed
Lazy-init signing utils
1 parent 8fc6964 commit 7c57be6

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

packages/utils/src/SigningUtil.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ export abstract class SigningUtil {
3131
abstract assertValidKeyPair(publicKey: UserIDRaw, privateKey: Uint8Array): void
3232

3333
static getInstance(type: KeyType): SigningUtil {
34-
const util = keyTypeToInstance[type]
35-
if (!util) {
36-
throw new Error(`Unknown key pair type: ${type}`)
34+
switch (type) {
35+
case 'ECDSA_SECP256K1_EVM':
36+
return new EcdsaSecp256k1Evm()
37+
case 'ECDSA_SECP256R1':
38+
return new EcdsaSecp256r1()
39+
case 'ML_DSA_87':
40+
return new MlDsa87()
41+
default:
42+
throw new Error(`Unknown key pair type: ${type}`)
3743
}
38-
return util
3944
}
4045
}
4146

@@ -315,13 +320,4 @@ export class MlDsa87 extends SigningUtil {
315320
throw new Error(`The given ML-DSA public key and private key don't match!`)
316321
}
317322
}
318-
319-
}
320-
321-
// Declared at the bottom of the file because the classes need to be
322-
// declared first. TS makes sure all KeyPairTypes are present.
323-
const keyTypeToInstance: Record<KeyType, SigningUtil> = {
324-
ECDSA_SECP256K1_EVM: new EcdsaSecp256k1Evm(),
325-
ECDSA_SECP256R1: new EcdsaSecp256r1(),
326-
ML_DSA_87: new MlDsa87()
327323
}

0 commit comments

Comments
 (0)