From af2ad00d84ba386883769b1886e4b2382b1500db Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 11 Jun 2021 13:26:18 +0200 Subject: store exchange public key with signature on denomination --- packages/taler-wallet-core/src/db.ts | 6 +++ .../src/operations/backup/import.ts | 1 + .../taler-wallet-core/src/operations/exchanges.ts | 44 +++++++++++++--------- .../src/operations/withdraw.test.ts | 6 +++ 4 files changed, 39 insertions(+), 18 deletions(-) (limited to 'packages/taler-wallet-core/src') diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 727e9de0b..5e2a3fefa 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -513,6 +513,12 @@ export interface DenominationRecord { * Base URL of the exchange. */ exchangeBaseUrl: string; + + /** + * Master public key of the exchange that made the signature + * on the denomination. + */ + exchangeMasterPub: string; } export interface ExchangeBankAccount { diff --git a/packages/taler-wallet-core/src/operations/backup/import.ts b/packages/taler-wallet-core/src/operations/backup/import.ts index 9363ecfba..146fd5109 100644 --- a/packages/taler-wallet-core/src/operations/backup/import.ts +++ b/packages/taler-wallet-core/src/operations/backup/import.ts @@ -337,6 +337,7 @@ export async function importBackup( denomPub: backupDenomination.denom_pub, denomPubHash: denomPubHash, exchangeBaseUrl: backupExchangeDetails.base_url, + exchangeMasterPub: backupExchangeDetails.master_public_key, feeDeposit: Amounts.parseOrThrow(backupDenomination.fee_deposit), feeRefresh: Amounts.parseOrThrow(backupDenomination.fee_refresh), feeRefund: Amounts.parseOrThrow(backupDenomination.fee_refund), diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index bea4b668d..ff85372ec 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -77,6 +77,7 @@ const logger = new Logger("exchanges.ts"); function denominationRecordFromKeys( exchangeBaseUrl: string, + exchangeMasterPub: string, denomIn: Denomination, ): DenominationRecord { const denomPubHash = encodeCrock(hash(decodeCrock(denomIn.denom_pub))); @@ -84,6 +85,7 @@ function denominationRecordFromKeys( denomPub: denomIn.denom_pub, denomPubHash, exchangeBaseUrl, + exchangeMasterPub, feeDeposit: Amounts.parseOrThrow(denomIn.fee_deposit), feeRefresh: Amounts.parseOrThrow(denomIn.fee_refresh), feeRefund: Amounts.parseOrThrow(denomIn.fee_refund), @@ -378,7 +380,11 @@ async function downloadKeysInfo( currency, auditors: exchangeKeysJson.auditors, currentDenominations: exchangeKeysJson.denoms.map((d) => - denominationRecordFromKeys(baseUrl, d), + denominationRecordFromKeys( + baseUrl, + exchangeKeysJson.master_public_key, + d, + ), ), protocolVersion: exchangeKeysJson.version, signingKeys: exchangeKeysJson.signkeys, @@ -410,20 +416,22 @@ async function updateExchangeFromUrlImpl( const r = await provideExchangeRecord(ws, baseUrl, now); if (!forceNow && r && !isTimestampExpired(r.nextUpdate)) { - const res = await ws.db.mktx((x) => ({ - exchanges: x.exchanges, - exchangeDetails: x.exchangeDetails, - })).runReadOnly(async (tx) => { - const exchange = await tx.exchanges.get(baseUrl); - if (!exchange) { - return; - } - const exchangeDetails = await getExchangeDetails(tx, baseUrl); - if (!exchangeDetails) { - return; - } - return { exchange, exchangeDetails }; - }); + const res = await ws.db + .mktx((x) => ({ + exchanges: x.exchanges, + exchangeDetails: x.exchangeDetails, + })) + .runReadOnly(async (tx) => { + const exchange = await tx.exchanges.get(baseUrl); + if (!exchange) { + return; + } + const exchangeDetails = await getExchangeDetails(tx, baseUrl); + if (!exchangeDetails) { + return; + } + return { exchange, exchangeDetails }; + }); if (res) { logger.info("using existing exchange info"); return res; @@ -493,9 +501,9 @@ async function updateExchangeFromUrlImpl( r.lastError = undefined; r.retryInfo = initRetryInfo(false); r.lastUpdate = getTimestampNow(); - r.nextUpdate = keysInfo.expiry, - // New denominations might be available. - r.nextRefreshCheck = getTimestampNow(); + (r.nextUpdate = keysInfo.expiry), + // New denominations might be available. + (r.nextRefreshCheck = getTimestampNow()); r.detailsPointer = { currency: details.currency, masterPublicKey: details.masterPublicKey, diff --git a/packages/taler-wallet-core/src/operations/withdraw.test.ts b/packages/taler-wallet-core/src/operations/withdraw.test.ts index ad52a5f0c..a059eef95 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.test.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.test.ts @@ -33,6 +33,7 @@ test("withdrawal selection bug repro", (t) => { denomPubHash: "Q21FQSSG4FXNT96Z14CHXM8N1RZAG9GPHAV8PRWS0PZAAVWH7PBW6R97M2CH19KKP65NNSWXY7B6S53PT3CBM342E357ZXDDJ8RDVW8", exchangeBaseUrl: "https://exchange.demo.taler.net/", + exchangeMasterPub: "", feeDeposit: { currency: "KUDOS", fraction: 1000000, @@ -82,6 +83,7 @@ test("withdrawal selection bug repro", (t) => { denomPubHash: "447WA23SCBATMABHA0793F92MYTBYVPYMMQHCPKMKVY5P7RZRFMQ6VRW0Y8HRA7177GTBT0TBT08R21DZD129AJ995H9G09XBFE55G8", exchangeBaseUrl: "https://exchange.demo.taler.net/", + exchangeMasterPub: "", feeDeposit: { currency: "KUDOS", fraction: 1000000, @@ -131,6 +133,7 @@ test("withdrawal selection bug repro", (t) => { denomPubHash: "JS61DTKAFM0BX8Q4XV3ZSKB921SM8QK745Z2AFXTKFMBHHFNBD8TQ5ETJHFNDGBGX22FFN2A2ERNYG1SGSDQWNQHQQ2B14DBVJYJG8R", exchangeBaseUrl: "https://exchange.demo.taler.net/", + exchangeMasterPub: "", feeDeposit: { currency: "KUDOS", fraction: 1000000, @@ -180,6 +183,7 @@ test("withdrawal selection bug repro", (t) => { denomPubHash: "8T51NEY81VMPQ180EQ5WR0YH7GMNNT90W55Q0514KZM18AZT71FHJGJHQXGK0WTA7ACN1X2SD0S53XPBQ1A9KH960R48VCVVM6E3TH8", exchangeBaseUrl: "https://exchange.demo.taler.net/", + exchangeMasterPub: "", feeDeposit: { currency: "KUDOS", fraction: 1000000, @@ -229,6 +233,7 @@ test("withdrawal selection bug repro", (t) => { denomPubHash: "A41HW0Q2H9PCNMEWW0C0N45QAYVXZ8SBVRRAHE4W6X24SV1TH38ANTWDT80JXEBW9Z8PVPGT9GFV2EYZWJ5JW5W1N34NFNKHQSZ1PFR", exchangeBaseUrl: "https://exchange.demo.taler.net/", + exchangeMasterPub: "", feeDeposit: { currency: "KUDOS", fraction: 1000000, @@ -278,6 +283,7 @@ test("withdrawal selection bug repro", (t) => { denomPubHash: "F5NGBX33DTV4595XZZVK0S2MA1VMXFEJQERE5EBP5DS4QQ9EFRANN7YHWC1TKSHT2K6CQWDBRES8D3DWR0KZF5RET40B4AZXZ0RW1ZG", exchangeBaseUrl: "https://exchange.demo.taler.net/", + exchangeMasterPub: "", feeDeposit: { currency: "KUDOS", fraction: 1000000, -- cgit v1.2.3