diff options
author | Florian Dold <florian@dold.me> | 2021-11-27 20:56:58 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-11-27 20:57:07 +0100 |
commit | 5c4c25516df9d65d29dc7f3f38b5a2a1a8e9e374 (patch) | |
tree | 4665e79a6033ab949de211fd9de8de8ca681c2e0 /packages/taler-util/src/talerCrypto.ts | |
parent | 403de8170ef538ef74505859b1c04e3542cad9fb (diff) | |
download | wallet-core-5c4c25516df9d65d29dc7f3f38b5a2a1a8e9e374.tar.xz |
wallet: support both protocol versions
Diffstat (limited to 'packages/taler-util/src/talerCrypto.ts')
-rw-r--r-- | packages/taler-util/src/talerCrypto.ts | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/packages/taler-util/src/talerCrypto.ts b/packages/taler-util/src/talerCrypto.ts index c20ce72a6..d96c23236 100644 --- a/packages/taler-util/src/talerCrypto.ts +++ b/packages/taler-util/src/talerCrypto.ts @@ -349,18 +349,25 @@ export function hash(d: Uint8Array): Uint8Array { return nacl.hash(d); } +/** + * Hash a denomination public key according to the + * algorithm of exchange protocol v10. + */ export function hashDenomPub(pub: DenominationPubKey): Uint8Array { - if (pub.cipher !== DenomKeyType.Rsa) { - throw Error("unsupported cipher"); + if (pub.cipher === DenomKeyType.Rsa) { + const pubBuf = decodeCrock(pub.rsa_public_key); + const hashInputBuf = new ArrayBuffer(pubBuf.length + 4 + 4); + const uint8ArrayBuf = new Uint8Array(hashInputBuf); + const dv = new DataView(hashInputBuf); + dv.setUint32(0, pub.age_mask ?? 0); + dv.setUint32(4, pub.cipher); + uint8ArrayBuf.set(pubBuf, 8); + return nacl.hash(uint8ArrayBuf); + } else if (pub.cipher === DenomKeyType.LegacyRsa) { + return hash(decodeCrock(pub.rsa_public_key)); + } else { + throw Error(`unsupported cipher (${pub.cipher}), unable to hash`); } - const pubBuf = decodeCrock(pub.rsa_public_key); - const hashInputBuf = new ArrayBuffer(pubBuf.length + 4 + 4); - const uint8ArrayBuf = new Uint8Array(hashInputBuf); - const dv = new DataView(hashInputBuf); - dv.setUint32(0, pub.age_mask ?? 0); - dv.setUint32(4, pub.cipher); - uint8ArrayBuf.set(pubBuf, 8); - return nacl.hash(uint8ArrayBuf); } export function eddsaSign(msg: Uint8Array, eddsaPriv: Uint8Array): Uint8Array { |