diff options
author | Florian Dold <florian@dold.me> | 2022-02-02 23:44:36 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-02-03 01:35:21 +0100 |
commit | f5ff4afae6a0a1a6cc006a97b529429c539e7a17 (patch) | |
tree | 3af81cc5fa1da96621d97714a6fd0a48289f532b /packages/taler-util/src | |
parent | 003ba5e91bb016caa1d068805723edc3e15f4d30 (diff) | |
download | wallet-core-f5ff4afae6a0a1a6cc006a97b529429c539e7a17.tar.xz |
clause schnorr
Diffstat (limited to 'packages/taler-util/src')
-rw-r--r-- | packages/taler-util/src/talerCrypto.ts | 15 | ||||
-rw-r--r-- | packages/taler-util/src/talerTypes.ts | 20 |
2 files changed, 33 insertions, 2 deletions
diff --git a/packages/taler-util/src/talerCrypto.ts b/packages/taler-util/src/talerCrypto.ts index 934a04e84..90d52ca72 100644 --- a/packages/taler-util/src/talerCrypto.ts +++ b/packages/taler-util/src/talerCrypto.ts @@ -616,8 +616,21 @@ export function hashDenomPub(pub: DenominationPubKey): Uint8Array { return nacl.hash(uint8ArrayBuf); } else if (pub.cipher === DenomKeyType.LegacyRsa) { return hash(decodeCrock(pub.rsa_public_key)); + } else if (pub.cipher === DenomKeyType.ClauseSchnorr) { + const pubBuf = decodeCrock(pub.cs_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 { - throw Error(`unsupported cipher (${pub.cipher}), unable to hash`); + throw Error( + `unsupported cipher (${ + (pub as DenominationPubKey).cipher + }), unable to hash`, + ); } } diff --git a/packages/taler-util/src/talerTypes.ts b/packages/taler-util/src/talerTypes.ts index 37350c661..7305122bd 100644 --- a/packages/taler-util/src/talerTypes.ts +++ b/packages/taler-util/src/talerTypes.ts @@ -1123,7 +1123,8 @@ export interface RsaDenominationPubKey { export interface CsDenominationPubKey { cipher: DenomKeyType.ClauseSchnorr; - // FIXME: finish definition + age_mask: number; + cs_public_key: string; } export namespace DenominationPubKey { @@ -1151,6 +1152,16 @@ export namespace DenominationPubKey { return 1; } return strcmp(p1.rsa_public_key, p2.rsa_public_key); + } else if ( + p1.cipher === DenomKeyType.ClauseSchnorr && + p2.cipher === DenomKeyType.ClauseSchnorr + ) { + if ((p1.age_mask ?? 0) < (p2.age_mask ?? 0)) { + return -1; + } else if ((p1.age_mask ?? 0) > (p2.age_mask ?? 0)) { + return 1; + } + return strcmp(p1.cs_public_key, p2.cs_public_key); } else { throw Error("unsupported cipher"); } @@ -1171,6 +1182,7 @@ export const codecForDenominationPubKey = () => buildCodecForUnion<DenominationPubKey>() .discriminateOn("cipher") .alternative(1, codecForRsaDenominationPubKey()) + .alternative(2, codecForCsDenominationPubKey()) .alternative(3, codecForLegacyRsaDenominationPubKey()) .build("DenominationPubKey"); @@ -1186,6 +1198,12 @@ export const codecForLegacyRsaDenominationPubKey = () => .property("rsa_public_key", codecForString()) .build("LegacyRsaDenominationPubKey"); +export const codecForCsDenominationPubKey = () => + buildCodecForObject<CsDenominationPubKey>() + .property("cipher", codecForConstNumber(2)) + .property("cs_public_key", codecForString()) + .build("CsDenominationPubKey"); + export const codecForBankWithdrawalOperationPostResponse = (): Codec<BankWithdrawalOperationPostResponse> => buildCodecForObject<BankWithdrawalOperationPostResponse>() |