when as number instead of string, fix codec used before declaration, pretty

This commit is contained in:
Sebastian 2023-01-10 17:11:34 -03:00
parent 52be8c9158
commit 335d22b12b
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
10 changed files with 90 additions and 559 deletions

View File

@ -123,17 +123,17 @@ export function notEmpty<T>(value: T | null | undefined): value is T {
}
/**
* Safe function to stringify errors.
* Safe function to stringify errors.
*/
export function stringifyError(x: any): string {
if (typeof x === "undefined") {
return "<thrown undefined>";
}
if (x === null) {
return `<thrown null>`;
return `<thrown null>`;
}
if (typeof x === "object") {
return x.toString();
}
return `<thrown ${typeof x}>`;
}
}

View File

@ -71,11 +71,20 @@ interface NativeTartLib {
ecdheGetPublic(buf: Uint8Array): Uint8Array;
eddsaSign(msg: Uint8Array, priv: Uint8Array): Uint8Array;
eddsaVerify(msg: Uint8Array, sig: Uint8Array, pub: Uint8Array): boolean;
kdf(outLen: number, ikm: Uint8Array, salt?: Uint8Array, info?: Uint8Array): Uint8Array;
kdf(
outLen: number,
ikm: Uint8Array,
salt?: Uint8Array,
info?: Uint8Array,
): Uint8Array;
keyExchangeEcdhEddsa(ecdhPriv: Uint8Array, eddsaPub: Uint8Array): Uint8Array;
keyExchangeEddsaEcdh(eddsaPriv: Uint8Array, ecdhPub: Uint8Array): Uint8Array;
rsaBlind(hmsg: Uint8Array, bks: Uint8Array, rsaPub: Uint8Array): Uint8Array;
rsaUnblind(blindSig: Uint8Array, rsaPub: Uint8Array, bks: Uint8Array): Uint8Array;
rsaUnblind(
blindSig: Uint8Array,
rsaPub: Uint8Array,
bks: Uint8Array,
): Uint8Array;
rsaVerify(hmsg: Uint8Array, rsaSig: Uint8Array, rsaPub: Uint8Array): boolean;
hashStateInit(): any;
hashStateUpdate(st: any, data: Uint8Array): any;
@ -168,7 +177,7 @@ export function kdf(
info?: Uint8Array,
): Uint8Array {
if (tart) {
return tart.kdf(outputLength, ikm, salt, info)
return tart.kdf(outputLength, ikm, salt, info);
}
salt = salt ?? new Uint8Array(64);
// extract
@ -199,7 +208,6 @@ export function kdf(
return output.slice(0, outputLength);
}
/**
* HMAC-SHA512-SHA256 (see RFC 5869).
*/
@ -460,7 +468,7 @@ export function rsaUnblind(
bks: Uint8Array,
): Uint8Array {
if (tart) {
return tart.rsaUnblind(sig, rsaPubEnc, bks)
return tart.rsaUnblind(sig, rsaPubEnc, bks);
}
const rsaPub = rsaPubDecode(rsaPubEnc);
const blinded_s = loadBigInt(sig);
@ -839,7 +847,7 @@ export function createHashContext(): TalerHashState {
return {
finish: () => t.hashStateFinish(st),
update: (d) => t.hashStateUpdate(st, d),
}
};
}
return new nacl.HashState();
}

File diff suppressed because it is too large Load Diff

View File

@ -249,7 +249,7 @@ export interface ConfirmPayResultPending {
export const codecForTalerErrorDetail = (): Codec<TalerErrorDetail> =>
buildCodecForObject<TalerErrorDetail>()
.property("code", codecForNumber())
.property("when", codecForString())
.property("when", codecForAbsoluteTime)
.property("hint", codecOptional(codecForString()))
.build("TalerErrorDetail");
@ -408,6 +408,64 @@ export const codecForPreparePayResultPaymentPossible =
)
.build("PreparePayResultPaymentPossible");
/**
* Detailed reason for why the wallet's balance is insufficient.
*/
export interface PayMerchantInsufficientBalanceDetails {
/**
* Amount requested by the merchant.
*/
amountRequested: AmountString;
/**
* Balance of type "available" (see balance.ts for definition).
*/
balanceAvailable: AmountString;
/**
* Balance of type "material" (see balance.ts for definition).
*/
balanceMaterial: AmountString;
/**
* Balance of type "age-acceptable" (see balance.ts for definition).
*/
balanceAgeAcceptable: AmountString;
/**
* Balance of type "merchant-acceptable" (see balance.ts for definition).
*/
balanceMerchantAcceptable: AmountString;
/**
* Balance of type "merchant-depositable" (see balance.ts for definition).
*/
balanceMerchantDepositable: AmountString;
/**
* If the payment would succeed without fees
* (i.e. balanceMechantWireable >= amountRequested),
* this field contains an estimate of the amount that would additionally
* be required to cover the fees.
*
* It is not possible to give an exact value here, since it depends
* on the coin selection for the amount that would be additionally withdrawn.
*/
feeGapEstimate: AmountString;
}
export const codecForPayMerchantInsufficientBalanceDetails =
(): Codec<PayMerchantInsufficientBalanceDetails> =>
buildCodecForObject<PayMerchantInsufficientBalanceDetails>()
.property("amountRequested", codecForAmountString())
.property("balanceAgeAcceptable", codecForAmountString())
.property("balanceAvailable", codecForAmountString())
.property("balanceMaterial", codecForAmountString())
.property("balanceMerchantAcceptable", codecForAmountString())
.property("balanceMerchantDepositable", codecForAmountString())
.property("feeGapEstimate", codecForAmountString())
.build("PayMerchantInsufficientBalanceDetails");
export const codecForPreparePayResultInsufficientBalance =
(): Codec<PreparePayResultInsufficientBalance> =>
buildCodecForObject<PreparePayResultInsufficientBalance>()
@ -538,7 +596,7 @@ export interface WalletDiagnostics {
export interface TalerErrorDetail {
code: TalerErrorCode;
when?: string;
when: AbsoluteTime;
hint?: string;
[x: string]: unknown;
}
@ -2099,64 +2157,6 @@ export interface InitiatePeerPullPaymentResponse {
transactionId: string;
}
/**
* Detailed reason for why the wallet's balance is insufficient.
*/
export interface PayMerchantInsufficientBalanceDetails {
/**
* Amount requested by the merchant.
*/
amountRequested: AmountString;
/**
* Balance of type "available" (see balance.ts for definition).
*/
balanceAvailable: AmountString;
/**
* Balance of type "material" (see balance.ts for definition).
*/
balanceMaterial: AmountString;
/**
* Balance of type "age-acceptable" (see balance.ts for definition).
*/
balanceAgeAcceptable: AmountString;
/**
* Balance of type "merchant-acceptable" (see balance.ts for definition).
*/
balanceMerchantAcceptable: AmountString;
/**
* Balance of type "merchant-depositable" (see balance.ts for definition).
*/
balanceMerchantDepositable: AmountString;
/**
* If the payment would succeed without fees
* (i.e. balanceMechantWireable >= amountRequested),
* this field contains an estimate of the amount that would additionally
* be required to cover the fees.
*
* It is not possible to give an exact value here, since it depends
* on the coin selection for the amount that would be additionally withdrawn.
*/
feeGapEstimate: AmountString;
}
export const codecForPayMerchantInsufficientBalanceDetails =
(): Codec<PayMerchantInsufficientBalanceDetails> =>
buildCodecForObject<PayMerchantInsufficientBalanceDetails>()
.property("amountRequested", codecForAmountString())
.property("balanceAgeAcceptable", codecForAmountString())
.property("balanceAvailable", codecForAmountString())
.property("balanceMaterial", codecForAmountString())
.property("balanceMerchantAcceptable", codecForAmountString())
.property("balanceMerchantDepositable", codecForAmountString())
.property("feeGapEstimate", codecForAmountString())
.build("PayMerchantInsufficientBalanceDetails");
/**
* Detailed reason for why the wallet's balance is insufficient.
*/

View File

@ -14,6 +14,7 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
import { AbsoluteTime } from "@gnu-taler/taler-util";
import test from "ava";
import { CryptoDispatcher, CryptoWorkerFactory } from "./crypto-dispatcher.js";
import {
@ -74,7 +75,7 @@ export class MyCryptoWorker implements CryptoWorker {
type: "error",
error: {
code: 42,
when: "now",
when: AbsoluteTime.now(),
hint: "bla",
},
};

View File

@ -24,6 +24,7 @@
* Imports.
*/
import {
AbsoluteTime,
PayMerchantInsufficientBalanceDetails,
PayPeerInsufficientBalanceDetails,
TalerErrorCode,
@ -103,7 +104,7 @@ export function makeErrorDetail<C extends TalerErrorCode>(
if (!hint && !(detail as any).hint) {
hint = getDefaultHint(code);
}
const when = new Date().toISOString();
const when = AbsoluteTime.now();
return { code, when, hint, ...detail };
}
@ -161,7 +162,7 @@ export class TalerError<T = any> extends Error {
if (!hint) {
hint = getDefaultHint(code);
}
const when = new Date().toISOString();
const when = AbsoluteTime.now();
return new TalerError<unknown>({ code, when, hint, ...detail });
}

View File

@ -1822,7 +1822,7 @@ export async function processPurchase(
errorDetail: {
// FIXME: allocate more specific error code
code: TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
when: new Date().toISOString(),
when: AbsoluteTime.now(),
hint: `trying to pay for purchase that is not in the database`,
proposalId: proposalId,
},
@ -1873,7 +1873,7 @@ export async function processPurchasePay(
errorDetail: {
// FIXME: allocate more specific error code
code: TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
when: new Date().toISOString(),
when: AbsoluteTime.now(),
hint: `trying to pay for purchase that is not in the database`,
proposalId: proposalId,
},
@ -1952,7 +1952,7 @@ export async function processPurchasePay(
await scheduleRetry(ws, RetryTags.forPay(purchase), {
code: TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
when: new Date().toISOString(),
when: AbsoluteTime.now(),
message: "unexpected exception",
hint: "unexpected exception",
details: {

View File

@ -19,7 +19,7 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
import { TalerProtocolTimestamp } from "@gnu-taler/taler-util";
import { AbsoluteTime, TalerProtocolTimestamp } from "@gnu-taler/taler-util";
import { ProviderPaymentType } from "@gnu-taler/taler-wallet-core";
import { tests } from "@gnu-taler/web-util/lib/index.browser";
import { ProviderView as TestedComponent } from "./ProviderDetailPage.js";
@ -79,7 +79,7 @@ export const ActiveErrorSync = tests.createExample(TestedComponent, {
lastError: {
code: 2002,
details: "details",
when: new Date().toISOString(),
when: AbsoluteTime.now(),
hint: "error hint from the server",
message: "message",
},

View File

@ -216,7 +216,7 @@ const transactionError = {
hint: "The payment is too late, the offer has expired.",
},
},
when: new Date().toISOString(),
when: AbsoluteTime.now(),
hint: "Error: WALLET_UNEXPECTED_REQUEST_ERROR",
message: "Unexpected error code in response",
};

View File

@ -22,6 +22,7 @@
* Imports.
*/
import {
AbsoluteTime,
CoreApiResponse,
Logger,
NotificationType,
@ -125,7 +126,7 @@ class BackgroundApiClientImpl implements BackgroundApiClient {
if (error instanceof Error) {
throw new BackgroundError(operation, {
code: TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR,
when: new Date().toISOString(),
when: AbsoluteTime.now(),
});
}
throw error;