diff options
author | Florian Dold <florian@dold.me> | 2022-01-05 20:29:55 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-01-05 20:29:55 +0100 |
commit | a7b89247e41c272027d9c90a13c9a76901019daa (patch) | |
tree | 229a80e2498ff0b2c788ac72a524012a9c9ae67a /packages/taler-wallet-core/src/operations/refresh.ts | |
parent | 188ff0b453631c21f39ec6027e19aa3d1e99c30a (diff) | |
download | wallet-core-a7b89247e41c272027d9c90a13c9a76901019daa.tar.xz |
wallet-core: towards exchange protocol v12
Diffstat (limited to 'packages/taler-wallet-core/src/operations/refresh.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/refresh.ts | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index 51eac4a64..00eaa0eac 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -17,6 +17,7 @@ import { DenomKeyType, encodeCrock, + ExchangeProtocolVersion, getRandomBytes, HttpStatusCode, } from "@gnu-taler/taler-util"; @@ -91,8 +92,10 @@ export function getTotalRefreshCost( refreshedDenom: DenominationRecord, amountLeft: AmountJson, ): AmountJson { - const withdrawAmount = Amounts.sub(amountLeft, refreshedDenom.feeRefresh) - .amount; + const withdrawAmount = Amounts.sub( + amountLeft, + refreshedDenom.feeRefresh, + ).amount; const withdrawDenoms = selectWithdrawalDenominations(withdrawAmount, denoms); const resultingAmount = Amounts.add( Amounts.getZero(withdrawAmount.currency), @@ -198,9 +201,10 @@ async function refreshCreateSession( } // FIXME: use an index here, based on the withdrawal expiration time. - const availableDenoms: DenominationRecord[] = await tx.denominations.indexes.byExchangeBaseUrl - .iter(exchange.baseUrl) - .toArray(); + const availableDenoms: DenominationRecord[] = + await tx.denominations.indexes.byExchangeBaseUrl + .iter(exchange.baseUrl) + .toArray(); const availableAmount = Amounts.sub( refreshGroup.inputPerCoin[coinIndex], @@ -351,7 +355,22 @@ async function refreshMelt( const { newCoinDenoms, oldCoin, oldDenom, refreshGroup, refreshSession } = d; + let exchangeProtocolVersion: ExchangeProtocolVersion; + switch (d.oldDenom.denomPub.cipher) { + case DenomKeyType.LegacyRsa: { + exchangeProtocolVersion = ExchangeProtocolVersion.V9; + break; + } + case DenomKeyType.Rsa: { + exchangeProtocolVersion = ExchangeProtocolVersion.V12; + break; + } + default: + throw Error("unsupported key type"); + } + const derived = await ws.cryptoApi.deriveRefreshSession({ + exchangeProtocolVersion, kappa: 3, meltCoinDenomPubHash: oldCoin.denomPubHash, meltCoinPriv: oldCoin.coinPriv, @@ -531,7 +550,22 @@ async function refreshReveal( norevealIndex, } = d; + let exchangeProtocolVersion: ExchangeProtocolVersion; + switch (d.oldDenom.denomPub.cipher) { + case DenomKeyType.LegacyRsa: { + exchangeProtocolVersion = ExchangeProtocolVersion.V9; + break; + } + case DenomKeyType.Rsa: { + exchangeProtocolVersion = ExchangeProtocolVersion.V12; + break; + } + default: + throw Error("unsupported key type"); + } + const derived = await ws.cryptoApi.deriveRefreshSession({ + exchangeProtocolVersion, kappa: 3, meltCoinDenomPubHash: oldCoin.denomPubHash, meltCoinPriv: oldCoin.coinPriv, |