diff options
author | Florian Dold <florian@dold.me> | 2021-11-23 23:51:12 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-11-23 23:51:12 +0100 |
commit | ae8af3f27c0ed1746c49a7608fe05af24ae8a18b (patch) | |
tree | c28f588071bdd1d4cda2279e62563a3664d79be9 /packages/taler-util/src | |
parent | 829a59e1a24d6a99ce7554d28acfd05f21baeaf8 (diff) | |
download | wallet-core-ae8af3f27c0ed1746c49a7608fe05af24ae8a18b.tar.xz |
wallet: tipping protocol change / merchant version info
Diffstat (limited to 'packages/taler-util/src')
-rw-r--r-- | packages/taler-util/src/backupTypes.ts | 2 | ||||
-rw-r--r-- | packages/taler-util/src/libtool-version.test.ts | 2 | ||||
-rw-r--r-- | packages/taler-util/src/libtool-version.ts | 74 | ||||
-rw-r--r-- | packages/taler-util/src/talerCrypto.ts | 4 | ||||
-rw-r--r-- | packages/taler-util/src/talerTypes.ts | 63 |
5 files changed, 94 insertions, 51 deletions
diff --git a/packages/taler-util/src/backupTypes.ts b/packages/taler-util/src/backupTypes.ts index ecdd6fdf8..8663850c9 100644 --- a/packages/taler-util/src/backupTypes.ts +++ b/packages/taler-util/src/backupTypes.ts @@ -1102,6 +1102,8 @@ export interface BackupExchange { currency: string; + protocol_version_range: string; + /** * Time when the pointer to the exchange details * was last updated. diff --git a/packages/taler-util/src/libtool-version.test.ts b/packages/taler-util/src/libtool-version.test.ts index d35642518..c1683f0df 100644 --- a/packages/taler-util/src/libtool-version.test.ts +++ b/packages/taler-util/src/libtool-version.test.ts @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import * as LibtoolVersion from "./libtool-version.js"; +import { LibtoolVersion } from "./libtool-version.js"; import test from "ava"; diff --git a/packages/taler-util/src/libtool-version.ts b/packages/taler-util/src/libtool-version.ts index 5e9d0b74e..17d2bbbdc 100644 --- a/packages/taler-util/src/libtool-version.ts +++ b/packages/taler-util/src/libtool-version.ts @@ -40,49 +40,51 @@ interface Version { age: number; } -/** - * Compare two libtool-style version strings. - */ -export function compare( - me: string, - other: string, -): VersionMatchResult | undefined { - const meVer = parseVersion(me); - const otherVer = parseVersion(other); - - if (!(meVer && otherVer)) { - return undefined; - } +export namespace LibtoolVersion { + /** + * Compare two libtool-style version strings. + */ + export function compare( + me: string, + other: string, + ): VersionMatchResult | undefined { + const meVer = parseVersion(me); + const otherVer = parseVersion(other); - const compatible = - meVer.current - meVer.age <= otherVer.current && - meVer.current >= otherVer.current - otherVer.age; + if (!(meVer && otherVer)) { + return undefined; + } - const currentCmp = Math.sign(meVer.current - otherVer.current); + const compatible = + meVer.current - meVer.age <= otherVer.current && + meVer.current >= otherVer.current - otherVer.age; - return { compatible, currentCmp }; -} + const currentCmp = Math.sign(meVer.current - otherVer.current); -function parseVersion(v: string): Version | undefined { - const [currentStr, revisionStr, ageStr, ...rest] = v.split(":"); - if (rest.length !== 0) { - return undefined; + return { compatible, currentCmp }; } - const current = Number.parseInt(currentStr); - const revision = Number.parseInt(revisionStr); - const age = Number.parseInt(ageStr); - if (Number.isNaN(current)) { - return undefined; - } + function parseVersion(v: string): Version | undefined { + const [currentStr, revisionStr, ageStr, ...rest] = v.split(":"); + if (rest.length !== 0) { + return undefined; + } + const current = Number.parseInt(currentStr); + const revision = Number.parseInt(revisionStr); + const age = Number.parseInt(ageStr); - if (Number.isNaN(revision)) { - return undefined; - } + if (Number.isNaN(current)) { + return undefined; + } - if (Number.isNaN(age)) { - return undefined; - } + if (Number.isNaN(revision)) { + return undefined; + } - return { current, revision, age }; + if (Number.isNaN(age)) { + return undefined; + } + + return { current, revision, age }; + } } diff --git a/packages/taler-util/src/talerCrypto.ts b/packages/taler-util/src/talerCrypto.ts index b107786cd..c20ce72a6 100644 --- a/packages/taler-util/src/talerCrypto.ts +++ b/packages/taler-util/src/talerCrypto.ts @@ -24,7 +24,7 @@ import * as nacl from "./nacl-fast.js"; import { kdf } from "./kdf.js"; import bigint from "big-integer"; -import { DenominationPubKey } from "./talerTypes.js"; +import { DenominationPubKey, DenomKeyType } from "./talerTypes.js"; export function getRandomBytes(n: number): Uint8Array { return nacl.randomBytes(n); @@ -350,7 +350,7 @@ export function hash(d: Uint8Array): Uint8Array { } export function hashDenomPub(pub: DenominationPubKey): Uint8Array { - if (pub.cipher !== 1) { + if (pub.cipher !== DenomKeyType.Rsa) { throw Error("unsupported cipher"); } const pubBuf = decodeCrock(pub.rsa_public_key); diff --git a/packages/taler-util/src/talerTypes.ts b/packages/taler-util/src/talerTypes.ts index 04d700483..bd9c67d7e 100644 --- a/packages/taler-util/src/talerTypes.ts +++ b/packages/taler-util/src/talerTypes.ts @@ -598,9 +598,9 @@ export interface TipPickupRequest { /** * Reserve signature, defined as separate class to facilitate - * schema validation with "@Checkable". + * schema validation. */ -export interface BlindSigWrapper { +export interface MerchantBlindSigWrapperV1 { /** * Reserve signature. */ @@ -611,11 +611,26 @@ export interface BlindSigWrapper { * Response of the merchant * to the TipPickupRequest. */ -export interface TipResponse { +export interface MerchantTipResponseV1 { /** * The order of the signatures matches the planchets list. */ - blind_sigs: BlindSigWrapper[]; + blind_sigs: MerchantBlindSigWrapperV1[]; +} + +export interface MerchantBlindSigWrapperV2 { + blind_sig: BlindedDenominationSignature; +} + +/** + * Response of the merchant + * to the TipPickupRequest. + */ +export interface MerchantTipResponseV2 { + /** + * The order of the signatures matches the planchets list. + */ + blind_sigs: MerchantBlindSigWrapperV2[]; } /** @@ -1032,13 +1047,14 @@ export interface BankWithdrawalOperationPostResponse { export type DenominationPubKey = RsaDenominationPubKey | CsDenominationPubKey; export interface RsaDenominationPubKey { - cipher: 1; + cipher: DenomKeyType.Rsa; rsa_public_key: string; age_mask?: number; } export interface CsDenominationPubKey { - cipher: 2; + cipher: DenomKeyType.ClauseSchnorr; + // FIXME: finish definition } export const codecForDenominationPubKey = () => @@ -1201,15 +1217,25 @@ export const codecForMerchantRefundResponse = (): Codec<MerchantRefundResponse> .property("refunds", codecForList(codecForMerchantRefundPermission())) .build("MerchantRefundResponse"); -export const codecForBlindSigWrapper = (): Codec<BlindSigWrapper> => - buildCodecForObject<BlindSigWrapper>() +export const codecForMerchantBlindSigWrapperV1 = (): Codec<MerchantBlindSigWrapperV1> => + buildCodecForObject<MerchantBlindSigWrapperV1>() .property("blind_sig", codecForString()) .build("BlindSigWrapper"); -export const codecForTipResponse = (): Codec<TipResponse> => - buildCodecForObject<TipResponse>() - .property("blind_sigs", codecForList(codecForBlindSigWrapper())) - .build("TipResponse"); +export const codecForMerchantTipResponseV1 = (): Codec<MerchantTipResponseV1> => + buildCodecForObject<MerchantTipResponseV1>() + .property("blind_sigs", codecForList(codecForMerchantBlindSigWrapperV1())) + .build("MerchantTipResponseV1"); + +export const codecForBlindSigWrapperV2 = (): Codec<MerchantBlindSigWrapperV2> => + buildCodecForObject<MerchantBlindSigWrapperV2>() + .property("blind_sig", codecForBlindedDenominationSignature()) + .build("MerchantBlindSigWrapperV2"); + +export const codecForMerchantTipResponseV2 = (): Codec<MerchantTipResponseV2> => + buildCodecForObject<MerchantTipResponseV2>() + .property("blind_sigs", codecForList(codecForBlindSigWrapperV2())) + .build("MerchantTipResponseV2"); export const codecForRecoup = (): Codec<Recoup> => buildCodecForObject<Recoup>() @@ -1510,3 +1536,16 @@ export const codecForKeysManagementResponse = (): Codec<FutureKeysResponse> => .property("denom_secmod_public_key", codecForAny()) .property("signkey_secmod_public_key", codecForAny()) .build("FutureKeysResponse"); + +export interface MerchantConfigResponse { + currency: string; + name: string; + version: string; +} + +export const codecForMerchantConfigResponse = (): Codec<MerchantConfigResponse> => + buildCodecForObject<MerchantConfigResponse>() + .property("currency", codecForString()) + .property("name", codecForString()) + .property("version", codecForString()) + .build("MerchantConfigResponse"); |