From c12a366d4937a5ede3dfe8cef3111e12fc39f23a Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Thu, 3 Aug 2023 21:44:53 +0200 Subject: adjustment of age-commitment and -proof generation age-withdraw requires that the public keys in the age groups that are too large for the commitment are derived from a published public key. --- packages/taler-util/src/taler-crypto.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'packages/taler-util/src') diff --git a/packages/taler-util/src/taler-crypto.ts b/packages/taler-util/src/taler-crypto.ts index 408b7e7c2..d52edc1e5 100644 --- a/packages/taler-util/src/taler-crypto.ts +++ b/packages/taler-util/src/taler-crypto.ts @@ -1280,6 +1280,9 @@ export namespace AgeRestriction { }; } + const PublishedAgeRestrictionBaseKey: Edx25519PublicKey = decodeCrock( + "CH0VKFDZ2GWRWHQBBGEK9MWV5YDQVJ0RXEE0KYT3NMB69F0R96TG"); + export async function restrictionCommitSeeded( ageMask: number, age: number, @@ -1292,19 +1295,32 @@ export namespace AgeRestriction { const pubs: Edx25519PublicKey[] = []; const privs: Edx25519PrivateKey[] = []; - for (let i = 0; i < numPubs; i++) { + for (let i = 0; i < numPrivs; i++) { const privSeed = await kdfKw({ outputLength: 32, ikm: seed, - info: stringToBytes("age-restriction-commit"), + info: stringToBytes("age-commitment"), salt: bufferForUint32(i), }); + const priv = await Edx25519.keyCreateFromSeed(privSeed); const pub = await Edx25519.getPublic(priv); pubs.push(pub); - if (i < numPrivs) { - privs.push(priv); - } + privs.push(priv); + } + + for (let i = numPrivs; i < numPubs; i++) { + const deriveSeed = await kdfKw({ + outputLength: 32, + ikm: seed, + info: stringToBytes("age-factor"), + salt: bufferForUint32(i), + }); + const pub = await Edx25519.publicKeyDerive( + PublishedAgeRestrictionBaseKey, + deriveSeed, + ); + pubs.push(pub); } return { @@ -1604,7 +1620,9 @@ export function amountToBuffer(amount: AmountLike): Uint8Array { return u8buf; } -export function timestampRoundedToBuffer(ts: TalerProtocolTimestamp): Uint8Array { +export function timestampRoundedToBuffer( + ts: TalerProtocolTimestamp, +): Uint8Array { const b = new ArrayBuffer(8); const v = new DataView(b); // The buffer we sign over represents the timestamp in microseconds. -- cgit v1.2.3 From 308a4282cbdde7376d88ca76e3eca967a1f02c46 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 5 Aug 2023 23:19:55 +0200 Subject: wallet-core: mock implementation of GetCurrencyInfo --- .../src/integrationtests/test-age-restrictions-peer.ts | 4 ++-- packages/taler-util/src/wallet-types.ts | 14 ++++++++++++++ packages/taler-wallet-core/src/db.ts | 5 ++++- packages/taler-wallet-core/src/wallet-api-types.ts | 10 ++++++++++ packages/taler-wallet-core/src/wallet.ts | 9 +++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) (limited to 'packages/taler-util/src') diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts index d15858322..45a4391cb 100644 --- a/packages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts +++ b/packages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts @@ -26,7 +26,7 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; -import { GlobalTestState, WalletCli } from "../harness/harness.js"; +import { GlobalTestState } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, createWalletDaemonWithClient, @@ -106,7 +106,7 @@ export async function runAgeRestrictionsPeerTest(t: GlobalTestState) { ); await wallet2.call(WalletApiOperation.ConfirmPeerPushCredit, { - peerPushPaymentIncomingId: checkResp.peerPushPaymentIncomingId, + transactionId: checkResp.transactionId, }); const peerPullCreditDoneCond = wallet2.waitForNotificationCond( diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 38e5787ba..922b20862 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -379,6 +379,20 @@ export interface Balance { requiresUserInput: boolean; } +export interface GetCurrencyInfoRequest { + currency: string; + scope: ScopeInfo; +} + +export interface GetCurrencyInfoResponse { + decimalSeparator: string; + numFractionalDigits: number; + /** + * Is the currency name leading or trailing? + */ + isCurrencyNameLeading: boolean; +} + export interface InitRequest { skipDefaults?: boolean; } diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 3d2878d93..c7d0b0bda 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -711,7 +711,10 @@ export interface RewardCoinSource { coinIndex: number; } -export type CoinSource = WithdrawCoinSource | RefreshCoinSource | RewardCoinSource; +export type CoinSource = + | WithdrawCoinSource + | RefreshCoinSource + | RewardCoinSource; /** * CoinRecord as stored in the "coins" data store diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index eaa99a6c3..0c9755a3a 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -114,6 +114,8 @@ import { WithdrawUriInfoResponse, SharePaymentRequest, SharePaymentResult, + GetCurrencyInfoRequest, + GetCurrencyInfoResponse, } from "@gnu-taler/taler-util"; import { AuditorTrustRecord, WalletContractData } from "./db.js"; import { @@ -210,6 +212,7 @@ export enum WalletApiOperation { ApplyDevExperiment = "applyDevExperiment", ValidateIban = "validateIban", TestingWaitTransactionsFinal = "testingWaitTransactionsFinal", + GetCurrencyInfo = "getCurrencyInfo", } // group: Initialization @@ -601,6 +604,12 @@ export type ListCurrenciesOp = { response: WalletCurrencyInfo; }; +export type GetCurrencyInfoOp = { + op: WalletApiOperation.GetCurrencyInfo; + request: GetCurrencyInfoRequest; + response: GetCurrencyInfoResponse; +}; + // group: Deposits /** @@ -1072,6 +1081,7 @@ export type WalletOperations = { [WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp; [WalletApiOperation.ValidateIban]: ValidateIbanOp; [WalletApiOperation.TestingWaitTransactionsFinal]: TestingWaitTransactionsFinal; + [WalletApiOperation.GetCurrencyInfo]: GetCurrencyInfoOp; }; export type WalletCoreRequestType< diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index aab414e94..81ea26260 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -118,6 +118,7 @@ import { sampleWalletCoreTransactions, validateIban, codecForSharePaymentRequest, + GetCurrencyInfoResponse, } from "@gnu-taler/taler-util"; import { HttpRequestLibrary, @@ -1395,6 +1396,14 @@ async function dispatchRequestInternal( const resp = await getBackupRecovery(ws); return resp; } + case WalletApiOperation.GetCurrencyInfo: { + const resp: GetCurrencyInfoResponse = { + decimalSeparator: ",", + isCurrencyNameLeading: false, + numFractionalDigits: 2, + }; + return resp; + } case WalletApiOperation.ImportBackupRecovery: { const req = codecForAny().decode(payload); await loadBackupRecovery(ws, req); -- cgit v1.2.3 From 6286699f26f486a9406827ef7359f62896a2dada Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 5 Aug 2023 23:34:25 +0200 Subject: -validation --- packages/taler-util/src/wallet-types.ts | 52 +++++++++++++++++++--- packages/taler-wallet-core/src/wallet-api-types.ts | 8 ++-- packages/taler-wallet-core/src/wallet.ts | 6 ++- 3 files changed, 56 insertions(+), 10 deletions(-) (limited to 'packages/taler-util/src') diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 922b20862..42d54752a 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -379,11 +379,44 @@ export interface Balance { requiresUserInput: boolean; } +export const codecForScopeInfoGlobal = (): Codec => + buildCodecForObject() + .property("currency", codecForString()) + .property("type", codecForConstString(ScopeType.Global)) + .build("ScopeInfoGlobal"); + +export const codecForScopeInfoExchange = (): Codec => + buildCodecForObject() + .property("currency", codecForString()) + .property("type", codecForConstString(ScopeType.Exchange)) + .property("url", codecForString()) + .build("ScopeInfoExchange"); + +export const codecForScopeInfoAuditor = (): Codec => + buildCodecForObject() + .property("currency", codecForString()) + .property("type", codecForConstString(ScopeType.Auditor)) + .property("url", codecForString()) + .build("ScopeInfoAuditor"); + +export const codecForScopeInfo = (): Codec => + buildCodecForUnion() + .discriminateOn("type") + .alternative(ScopeType.Global, codecForScopeInfoGlobal()) + .alternative(ScopeType.Exchange, codecForScopeInfoExchange()) + .alternative(ScopeType.Auditor, codecForScopeInfoAuditor()) + .build("ScopeInfo"); + export interface GetCurrencyInfoRequest { - currency: string; scope: ScopeInfo; } +export const codecForGetCurrencyInfoRequest = + (): Codec => + buildCodecForObject() + .property("scope", codecForScopeInfo()) + .build("GetCurrencyInfoRequest"); + export interface GetCurrencyInfoResponse { decimalSeparator: string; numFractionalDigits: number; @@ -407,10 +440,19 @@ export enum ScopeType { Auditor = "auditor", } -export type ScopeInfo = - | { type: ScopeType.Global; currency: string } - | { type: ScopeType.Exchange; currency: string; url: string } - | { type: ScopeType.Auditor; currency: string; url: string }; +export type ScopeInfoGlobal = { type: ScopeType.Global; currency: string }; +export type ScopeInfoExchange = { + type: ScopeType.Exchange; + currency: string; + url: string; +}; +export type ScopeInfoAuditor = { + type: ScopeType.Auditor; + currency: string; + url: string; +}; + +export type ScopeInfo = ScopeInfoGlobal | ScopeInfoExchange | ScopeInfoAuditor; export interface BalancesResponse { balances: Balance[]; diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index 0c9755a3a..36c4809af 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -212,7 +212,7 @@ export enum WalletApiOperation { ApplyDevExperiment = "applyDevExperiment", ValidateIban = "validateIban", TestingWaitTransactionsFinal = "testingWaitTransactionsFinal", - GetCurrencyInfo = "getCurrencyInfo", + GetScopedCurrencyInfo = "getScopedCurrencyInfo", } // group: Initialization @@ -604,8 +604,8 @@ export type ListCurrenciesOp = { response: WalletCurrencyInfo; }; -export type GetCurrencyInfoOp = { - op: WalletApiOperation.GetCurrencyInfo; +export type GetScopedCurrencyInfoOp = { + op: WalletApiOperation.GetScopedCurrencyInfo; request: GetCurrencyInfoRequest; response: GetCurrencyInfoResponse; }; @@ -1081,7 +1081,7 @@ export type WalletOperations = { [WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp; [WalletApiOperation.ValidateIban]: ValidateIbanOp; [WalletApiOperation.TestingWaitTransactionsFinal]: TestingWaitTransactionsFinal; - [WalletApiOperation.GetCurrencyInfo]: GetCurrencyInfoOp; + [WalletApiOperation.GetScopedCurrencyInfo]: GetScopedCurrencyInfoOp; }; export type WalletCoreRequestType< diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 81ea26260..dfa41d60e 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -119,6 +119,7 @@ import { validateIban, codecForSharePaymentRequest, GetCurrencyInfoResponse, + codecForGetCurrencyInfoRequest, } from "@gnu-taler/taler-util"; import { HttpRequestLibrary, @@ -1396,7 +1397,10 @@ async function dispatchRequestInternal( const resp = await getBackupRecovery(ws); return resp; } - case WalletApiOperation.GetCurrencyInfo: { + case WalletApiOperation.GetScopedCurrencyInfo: { + logger.info(`payload: ${j2s(payload)}`); + // Ignore result, just validate in this mock implementation + codecForGetCurrencyInfoRequest().decode(payload); const resp: GetCurrencyInfoResponse = { decimalSeparator: ",", isCurrencyNameLeading: false, -- cgit v1.2.3 From 44aeaba7b4d21e518928ca545b114e2a8e8c2a24 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 5 Aug 2023 23:56:07 +0200 Subject: wallet-core: introduce tiny digits --- packages/taler-util/src/wallet-types.ts | 1 + packages/taler-wallet-core/src/wallet.ts | 1 + 2 files changed, 2 insertions(+) (limited to 'packages/taler-util/src') diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 42d54752a..3179cd6f3 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -420,6 +420,7 @@ export const codecForGetCurrencyInfoRequest = export interface GetCurrencyInfoResponse { decimalSeparator: string; numFractionalDigits: number; + numTinyDigits: number; /** * Is the currency name leading or trailing? */ diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 78fb8789e..796a96f14 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -1404,6 +1404,7 @@ async function dispatchRequestInternal( decimalSeparator: ",", isCurrencyNameLeading: false, numFractionalDigits: 2, + numTinyDigits: 1, }; return resp; } -- cgit v1.2.3 From 8eb0183c784865225569da1fa1f91a8038693405 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 7 Aug 2023 06:47:51 -0300 Subject: fix: support for empty strings --- packages/taler-util/src/taleruri.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/taler-util/src') diff --git a/packages/taler-util/src/taleruri.ts b/packages/taler-util/src/taleruri.ts index 777cb5245..fff1ca833 100644 --- a/packages/taler-util/src/taleruri.ts +++ b/packages/taler-util/src/taleruri.ts @@ -767,7 +767,7 @@ function getUrlInfo( const qp = new URLSearchParams(); let withParams = false; Object.entries(params).forEach(([name, value]) => { - if (value) { + if (value !== undefined) { withParams = true; qp.append(name, value); } -- cgit v1.2.3