summaryrefslogtreecommitdiff
path: root/packages/taler-util/src/talerCrypto.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-util/src/talerCrypto.ts')
-rw-r--r--packages/taler-util/src/talerCrypto.ts27
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 {