remove excessive namespacing, format
This commit is contained in:
parent
0050bf005a
commit
f180d05804
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"trailingComma": "all",
|
|
||||||
"tabWidth": 2,
|
|
||||||
"semi": true,
|
|
||||||
"singleQuote": false
|
|
||||||
}
|
|
@ -12,13 +12,14 @@
|
|||||||
"test": "tsc && ava",
|
"test": "tsc && ava",
|
||||||
"compile": "tsc && rollup -c && api-extractor run",
|
"compile": "tsc && rollup -c && api-extractor run",
|
||||||
"clean": "rimraf dist lib tsconfig.tsbuildinfo",
|
"clean": "rimraf dist lib tsconfig.tsbuildinfo",
|
||||||
"pretty": "prettier --config ../../.prettierrc --write src"
|
"pretty": "prettier --write src"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@microsoft/api-extractor": "^7.9.3",
|
"@microsoft/api-extractor": "^7.9.3",
|
||||||
"@rollup/plugin-typescript": "^5.0.2",
|
"@rollup/plugin-typescript": "^5.0.2",
|
||||||
"ava": "^3.10.1",
|
"ava": "^3.10.1",
|
||||||
"esm": "^3.2.25",
|
"esm": "^3.2.25",
|
||||||
|
"prettier": "^2.0.5",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rollup": "^2.23.0",
|
"rollup": "^2.23.0",
|
||||||
"typescript": "^3.7.0"
|
"typescript": "^3.7.0"
|
||||||
|
@ -10,11 +10,7 @@ import {
|
|||||||
import fakeDOMStringList from "./util/fakeDOMStringList";
|
import fakeDOMStringList from "./util/fakeDOMStringList";
|
||||||
import FakeEvent from "./util/FakeEvent";
|
import FakeEvent from "./util/FakeEvent";
|
||||||
import FakeEventTarget from "./util/FakeEventTarget";
|
import FakeEventTarget from "./util/FakeEventTarget";
|
||||||
import {
|
import { FakeDOMStringList, RequestObj, TransactionMode } from "./util/types";
|
||||||
FakeDOMStringList,
|
|
||||||
RequestObj,
|
|
||||||
TransactionMode,
|
|
||||||
} from "./util/types";
|
|
||||||
import queueTask from "./util/queueTask";
|
import queueTask from "./util/queueTask";
|
||||||
import openPromise from "./util/openPromise";
|
import openPromise from "./util/openPromise";
|
||||||
import { DatabaseTransaction, Backend } from "./backend-interface";
|
import { DatabaseTransaction, Backend } from "./backend-interface";
|
||||||
|
@ -36,7 +36,14 @@ import {
|
|||||||
IndexProperties,
|
IndexProperties,
|
||||||
} from "./backend-interface";
|
} from "./backend-interface";
|
||||||
import FakeEventTarget, { Listener } from "./util/FakeEventTarget";
|
import FakeEventTarget, { Listener } from "./util/FakeEventTarget";
|
||||||
import { DatabaseDump, ObjectStoreDump, IndexDump, IndexRecord, ObjectStoreRecord, MemoryBackendDump } from "./MemoryBackend";
|
import {
|
||||||
|
DatabaseDump,
|
||||||
|
ObjectStoreDump,
|
||||||
|
IndexDump,
|
||||||
|
IndexRecord,
|
||||||
|
ObjectStoreRecord,
|
||||||
|
MemoryBackendDump,
|
||||||
|
} from "./MemoryBackend";
|
||||||
import { Event } from "./idbtypes";
|
import { Event } from "./idbtypes";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -67,7 +67,11 @@ export class FakeEvent implements Event {
|
|||||||
composedPath(): EventTarget[] {
|
composedPath(): EventTarget[] {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
initEvent(type: string, bubbles?: boolean | undefined, cancelable?: boolean | undefined): void {
|
initEvent(
|
||||||
|
type: string,
|
||||||
|
bubbles?: boolean | undefined,
|
||||||
|
cancelable?: boolean | undefined,
|
||||||
|
): void {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,12 @@
|
|||||||
import { InvalidStateError } from "./errors";
|
import { InvalidStateError } from "./errors";
|
||||||
import FakeEvent from "./FakeEvent";
|
import FakeEvent from "./FakeEvent";
|
||||||
import { EventType } from "./types";
|
import { EventType } from "./types";
|
||||||
import { EventTarget, Event, EventListenerOrEventListenerObject, EventListener } from "../idbtypes";
|
import {
|
||||||
|
EventTarget,
|
||||||
|
Event,
|
||||||
|
EventListenerOrEventListenerObject,
|
||||||
|
EventListener,
|
||||||
|
} from "../idbtypes";
|
||||||
|
|
||||||
type EventTypeProp =
|
type EventTypeProp =
|
||||||
| "onabort"
|
| "onabort"
|
||||||
|
@ -4,12 +4,14 @@
|
|||||||
"description": "Integration tests and fault injection for GNU Taler components",
|
"description": "Integration tests and fault injection for GNU Taler components",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "tsc -b"
|
"compile": "tsc -b",
|
||||||
|
"pretty": "prettier --write src"
|
||||||
},
|
},
|
||||||
"author": "Florian Dold <dold@taler.net>",
|
"author": "Florian Dold <dold@taler.net>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"esm": "^3.2.25",
|
"esm": "^3.2.25",
|
||||||
|
"prettier": "^2.0.5",
|
||||||
"source-map-support": "^0.5.19",
|
"source-map-support": "^0.5.19",
|
||||||
"ts-node": "^8.10.2",
|
"ts-node": "^8.10.2",
|
||||||
"typescript": "^3.9.7"
|
"typescript": "^3.9.7"
|
||||||
|
@ -32,21 +32,29 @@ import * as http from "http";
|
|||||||
import { ChildProcess, spawn } from "child_process";
|
import { ChildProcess, spawn } from "child_process";
|
||||||
import {
|
import {
|
||||||
Configuration,
|
Configuration,
|
||||||
walletCoreApi,
|
|
||||||
codec,
|
|
||||||
AmountJson,
|
AmountJson,
|
||||||
Amounts,
|
Amounts,
|
||||||
|
Codec,
|
||||||
|
makeCodecForObject,
|
||||||
|
codecForString,
|
||||||
|
Duration,
|
||||||
|
CoreApiResponse,
|
||||||
} from "taler-wallet-core";
|
} from "taler-wallet-core";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { talerCrypto, time } from "taler-wallet-core";
|
|
||||||
import {
|
import {
|
||||||
codecForMerchantOrderPrivateStatusResponse,
|
codecForMerchantOrderPrivateStatusResponse,
|
||||||
codecForPostOrderResponse,
|
codecForPostOrderResponse,
|
||||||
PostOrderRequest,
|
PostOrderRequest,
|
||||||
PostOrderResponse,
|
PostOrderResponse,
|
||||||
} from "./merchantApiTypes";
|
} from "./merchantApiTypes";
|
||||||
import { EddsaKeyPair } from "taler-wallet-core/lib/crypto/talerCrypto";
|
import {
|
||||||
|
EddsaKeyPair,
|
||||||
|
getRandomBytes,
|
||||||
|
encodeCrock,
|
||||||
|
eddsaGetPublic,
|
||||||
|
createEddsaKeyPair,
|
||||||
|
} from "taler-wallet-core/lib/crypto/talerCrypto";
|
||||||
|
|
||||||
const exec = util.promisify(require("child_process").exec);
|
const exec = util.promisify(require("child_process").exec);
|
||||||
|
|
||||||
@ -540,11 +548,10 @@ export class BankService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createRandomBankUser(): Promise<BankUser> {
|
async createRandomBankUser(): Promise<BankUser> {
|
||||||
const username =
|
const username = "user-" + encodeCrock(getRandomBytes(10));
|
||||||
"user-" + talerCrypto.encodeCrock(talerCrypto.getRandomBytes(10));
|
|
||||||
const bankUser: BankUser = {
|
const bankUser: BankUser = {
|
||||||
username,
|
username,
|
||||||
password: "pw-" + talerCrypto.encodeCrock(talerCrypto.getRandomBytes(10)),
|
password: "pw-" + encodeCrock(getRandomBytes(10)),
|
||||||
accountPaytoUri: `payto://x-taler-bank/localhost/${username}`,
|
accountPaytoUri: `payto://x-taler-bank/localhost/${username}`,
|
||||||
};
|
};
|
||||||
await this.createAccount(bankUser.username, bankUser.password);
|
await this.createAccount(bankUser.username, bankUser.password);
|
||||||
@ -617,13 +624,10 @@ export interface WithdrawalOperationInfo {
|
|||||||
taler_withdraw_uri: string;
|
taler_withdraw_uri: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const codecForWithdrawalOperationInfo = (): codec.Codec<
|
const codecForWithdrawalOperationInfo = (): Codec<WithdrawalOperationInfo> =>
|
||||||
WithdrawalOperationInfo
|
makeCodecForObject<WithdrawalOperationInfo>()
|
||||||
> =>
|
.property("withdrawal_id", codecForString)
|
||||||
codec
|
.property("taler_withdraw_uri", codecForString)
|
||||||
.makeCodecForObject<WithdrawalOperationInfo>()
|
|
||||||
.property("withdrawal_id", codec.codecForString)
|
|
||||||
.property("taler_withdraw_uri", codec.codecForString)
|
|
||||||
.build("WithdrawalOperationInfo");
|
.build("WithdrawalOperationInfo");
|
||||||
|
|
||||||
export const defaultCoinConfig = [
|
export const defaultCoinConfig = [
|
||||||
@ -666,7 +670,7 @@ export class ExchangeService implements ExchangeServiceInterface {
|
|||||||
const eddsaPriv = fs.readFileSync(privFile);
|
const eddsaPriv = fs.readFileSync(privFile);
|
||||||
const keyPair: EddsaKeyPair = {
|
const keyPair: EddsaKeyPair = {
|
||||||
eddsaPriv,
|
eddsaPriv,
|
||||||
eddsaPub: talerCrypto.eddsaGetPublic(eddsaPriv),
|
eddsaPub: eddsaGetPublic(eddsaPriv),
|
||||||
};
|
};
|
||||||
return new ExchangeService(gc, ec, cfgFilename, keyPair);
|
return new ExchangeService(gc, ec, cfgFilename, keyPair);
|
||||||
}
|
}
|
||||||
@ -728,12 +732,12 @@ export class ExchangeService implements ExchangeServiceInterface {
|
|||||||
|
|
||||||
config.setString("exchangedb-postgres", "config", e.database);
|
config.setString("exchangedb-postgres", "config", e.database);
|
||||||
|
|
||||||
const exchangeMasterKey = talerCrypto.createEddsaKeyPair();
|
const exchangeMasterKey = createEddsaKeyPair();
|
||||||
|
|
||||||
config.setString(
|
config.setString(
|
||||||
"exchange",
|
"exchange",
|
||||||
"master_public_key",
|
"master_public_key",
|
||||||
talerCrypto.encodeCrock(exchangeMasterKey.eddsaPub),
|
encodeCrock(exchangeMasterKey.eddsaPub),
|
||||||
);
|
);
|
||||||
|
|
||||||
const masterPrivFile = config
|
const masterPrivFile = config
|
||||||
@ -758,7 +762,7 @@ export class ExchangeService implements ExchangeServiceInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get masterPub() {
|
get masterPub() {
|
||||||
return talerCrypto.encodeCrock(this.keyPair.eddsaPub);
|
return encodeCrock(this.keyPair.eddsaPub);
|
||||||
}
|
}
|
||||||
|
|
||||||
get port() {
|
get port() {
|
||||||
@ -812,7 +816,7 @@ export class ExchangeService implements ExchangeServiceInterface {
|
|||||||
private globalState: GlobalTestState,
|
private globalState: GlobalTestState,
|
||||||
private exchangeConfig: ExchangeConfig,
|
private exchangeConfig: ExchangeConfig,
|
||||||
private configFilename: string,
|
private configFilename: string,
|
||||||
private keyPair: talerCrypto.EddsaKeyPair,
|
private keyPair: EddsaKeyPair,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
@ -983,7 +987,7 @@ export class MerchantService {
|
|||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
talerRefundUri: resp.data.taler_refund_uri,
|
talerRefundUri: resp.data.taler_refund_uri,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async createOrder(
|
async createOrder(
|
||||||
@ -1015,8 +1019,8 @@ export interface MerchantInstanceConfig {
|
|||||||
defaultMaxWireFee?: string;
|
defaultMaxWireFee?: string;
|
||||||
defaultMaxDepositFee?: string;
|
defaultMaxDepositFee?: string;
|
||||||
defaultWireFeeAmortization?: number;
|
defaultWireFeeAmortization?: number;
|
||||||
defaultWireTransferDelay?: time.Duration;
|
defaultWireTransferDelay?: Duration;
|
||||||
defaultPayDelay?: time.Duration;
|
defaultPayDelay?: Duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1106,7 +1110,7 @@ export class WalletCli {
|
|||||||
async apiRequest(
|
async apiRequest(
|
||||||
request: string,
|
request: string,
|
||||||
payload: Record<string, unknown>,
|
payload: Record<string, unknown>,
|
||||||
): Promise<walletCoreApi.CoreApiResponse> {
|
): Promise<CoreApiResponse> {
|
||||||
const wdb = this.globalTestState.testDir + "/walletdb.json";
|
const wdb = this.globalTestState.testDir + "/walletdb.json";
|
||||||
const resp = await sh(
|
const resp = await sh(
|
||||||
this.globalTestState,
|
this.globalTestState,
|
||||||
@ -1116,7 +1120,7 @@ export class WalletCli {
|
|||||||
)}`,
|
)}`,
|
||||||
);
|
);
|
||||||
console.log(resp);
|
console.log(resp);
|
||||||
return JSON.parse(resp) as walletCoreApi.CoreApiResponse;
|
return JSON.parse(resp) as CoreApiResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
async runUntilDone(): Promise<void> {
|
async runUntilDone(): Promise<void> {
|
||||||
|
@ -75,7 +75,10 @@ export async function createSimpleTestkudosEnvironment(
|
|||||||
database: db.connStr,
|
database: db.connStr,
|
||||||
});
|
});
|
||||||
|
|
||||||
const exchangeBankAccount = await bank.createExchangeAccount("MyExchange", "x");
|
const exchangeBankAccount = await bank.createExchangeAccount(
|
||||||
|
"MyExchange",
|
||||||
|
"x",
|
||||||
|
);
|
||||||
exchange.addBankAccount("1", exchangeBankAccount);
|
exchange.addBankAccount("1", exchangeBankAccount);
|
||||||
|
|
||||||
bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri);
|
bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri);
|
||||||
@ -123,13 +126,15 @@ export async function createSimpleTestkudosEnvironment(
|
|||||||
/**
|
/**
|
||||||
* Withdraw balance.
|
* Withdraw balance.
|
||||||
*/
|
*/
|
||||||
export async function withdrawViaBank(t: GlobalTestState, p: {
|
export async function withdrawViaBank(
|
||||||
|
t: GlobalTestState,
|
||||||
|
p: {
|
||||||
wallet: WalletCli;
|
wallet: WalletCli;
|
||||||
bank: BankService;
|
bank: BankService;
|
||||||
exchange: ExchangeService;
|
exchange: ExchangeService;
|
||||||
amount: AmountString;
|
amount: AmountString;
|
||||||
}): Promise<void> {
|
},
|
||||||
|
): Promise<void> {
|
||||||
const { wallet, bank, exchange, amount } = p;
|
const { wallet, bank, exchange, amount } = p;
|
||||||
|
|
||||||
const user = await bank.createRandomBankUser();
|
const user = await bank.createRandomBankUser();
|
||||||
|
@ -22,23 +22,34 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imports
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
codec,
|
ContractTerms,
|
||||||
talerTypes,
|
Duration,
|
||||||
time,
|
Codec,
|
||||||
|
makeCodecForObject,
|
||||||
|
codecForString,
|
||||||
|
makeCodecOptional,
|
||||||
|
makeCodecForConstString,
|
||||||
|
codecForBoolean,
|
||||||
|
codecForNumber,
|
||||||
|
codecForContractTerms,
|
||||||
|
codecForAny,
|
||||||
|
makeCodecForUnion,
|
||||||
|
AmountString,
|
||||||
|
Timestamp,
|
||||||
|
CoinPublicKeyString,
|
||||||
} from "taler-wallet-core";
|
} from "taler-wallet-core";
|
||||||
|
|
||||||
|
|
||||||
export interface PostOrderRequest {
|
export interface PostOrderRequest {
|
||||||
// The order must at least contain the minimal
|
// The order must at least contain the minimal
|
||||||
// order detail, but can override all
|
// order detail, but can override all
|
||||||
order: Partial<talerTypes.ContractTerms>;
|
order: Partial<ContractTerms>;
|
||||||
|
|
||||||
// if set, the backend will then set the refund deadline to the current
|
// if set, the backend will then set the refund deadline to the current
|
||||||
// time plus the specified delay.
|
// time plus the specified delay.
|
||||||
refund_delay?: time.Duration;
|
refund_delay?: Duration;
|
||||||
|
|
||||||
// specifies the payment target preferred by the client. Can be used
|
// specifies the payment target preferred by the client. Can be used
|
||||||
// to select among the various (active) wire methods supported by the instance.
|
// to select among the various (active) wire methods supported by the instance.
|
||||||
@ -60,51 +71,44 @@ export interface PostOrderResponse {
|
|||||||
token?: ClaimToken;
|
token?: ClaimToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const codecForPostOrderResponse = (): codec.Codec<PostOrderResponse> =>
|
export const codecForPostOrderResponse = (): Codec<PostOrderResponse> =>
|
||||||
codec
|
makeCodecForObject<PostOrderResponse>()
|
||||||
.makeCodecForObject<PostOrderResponse>()
|
.property("order_id", codecForString)
|
||||||
.property("order_id", codec.codecForString)
|
.property("token", makeCodecOptional(codecForString))
|
||||||
.property("token", codec.makeCodecOptional(codec.codecForString))
|
|
||||||
.build("PostOrderResponse");
|
.build("PostOrderResponse");
|
||||||
|
|
||||||
export const codecForCheckPaymentPaidResponse = (): codec.Codec<
|
export const codecForCheckPaymentPaidResponse = (): Codec<
|
||||||
CheckPaymentPaidResponse
|
CheckPaymentPaidResponse
|
||||||
> =>
|
> =>
|
||||||
codec
|
makeCodecForObject<CheckPaymentPaidResponse>()
|
||||||
.makeCodecForObject<CheckPaymentPaidResponse>()
|
.property("order_status", makeCodecForConstString("paid"))
|
||||||
.property("order_status", codec.makeCodecForConstString("paid"))
|
.property("refunded", codecForBoolean)
|
||||||
.property("refunded", codec.codecForBoolean)
|
.property("wired", codecForBoolean)
|
||||||
.property("wired", codec.codecForBoolean)
|
.property("deposit_total", codecForString)
|
||||||
.property("deposit_total", codec.codecForString)
|
.property("exchange_ec", codecForNumber)
|
||||||
.property("exchange_ec", codec.codecForNumber)
|
.property("exchange_hc", codecForNumber)
|
||||||
.property("exchange_hc", codec.codecForNumber)
|
.property("refund_amount", codecForString)
|
||||||
.property("refund_amount", codec.codecForString)
|
.property("contract_terms", codecForContractTerms())
|
||||||
.property("contract_terms", talerTypes.codecForContractTerms())
|
|
||||||
// FIXME: specify
|
// FIXME: specify
|
||||||
.property("wire_details", codec.codecForAny)
|
.property("wire_details", codecForAny)
|
||||||
.property("wire_reports", codec.codecForAny)
|
.property("wire_reports", codecForAny)
|
||||||
.property("refund_details", codec.codecForAny)
|
.property("refund_details", codecForAny)
|
||||||
.build("CheckPaymentPaidResponse");
|
.build("CheckPaymentPaidResponse");
|
||||||
|
|
||||||
export const codecForCheckPaymentUnpaidResponse = (): codec.Codec<
|
export const codecForCheckPaymentUnpaidResponse = (): Codec<
|
||||||
CheckPaymentUnpaidResponse
|
CheckPaymentUnpaidResponse
|
||||||
> =>
|
> =>
|
||||||
codec
|
makeCodecForObject<CheckPaymentUnpaidResponse>()
|
||||||
.makeCodecForObject<CheckPaymentUnpaidResponse>()
|
.property("order_status", makeCodecForConstString("unpaid"))
|
||||||
.property("order_status", codec.makeCodecForConstString("unpaid"))
|
.property("taler_pay_uri", codecForString)
|
||||||
.property("taler_pay_uri", codec.codecForString)
|
.property("order_status_url", codecForString)
|
||||||
.property("order_status_url", codec.codecForString)
|
.property("already_paid_order_id", makeCodecOptional(codecForString))
|
||||||
.property(
|
|
||||||
"already_paid_order_id",
|
|
||||||
codec.makeCodecOptional(codec.codecForString),
|
|
||||||
)
|
|
||||||
.build("CheckPaymentPaidResponse");
|
.build("CheckPaymentPaidResponse");
|
||||||
|
|
||||||
export const codecForMerchantOrderPrivateStatusResponse = (): codec.Codec<
|
export const codecForMerchantOrderPrivateStatusResponse = (): Codec<
|
||||||
MerchantOrderPrivateStatusResponse
|
MerchantOrderPrivateStatusResponse
|
||||||
> =>
|
> =>
|
||||||
codec
|
makeCodecForUnion<MerchantOrderPrivateStatusResponse>()
|
||||||
.makeCodecForUnion<MerchantOrderPrivateStatusResponse>()
|
|
||||||
.discriminateOn("order_status")
|
.discriminateOn("order_status")
|
||||||
.alternative("paid", codecForCheckPaymentPaidResponse())
|
.alternative("paid", codecForCheckPaymentPaidResponse())
|
||||||
.alternative("unpaid", codecForCheckPaymentUnpaidResponse())
|
.alternative("unpaid", codecForCheckPaymentUnpaidResponse())
|
||||||
@ -126,7 +130,7 @@ export interface CheckPaymentPaidResponse {
|
|||||||
|
|
||||||
// Total amount the exchange deposited into our bank account
|
// Total amount the exchange deposited into our bank account
|
||||||
// for this contract, excluding fees.
|
// for this contract, excluding fees.
|
||||||
deposit_total: talerTypes.AmountString;
|
deposit_total: AmountString;
|
||||||
|
|
||||||
// Numeric error code indicating errors the exchange
|
// Numeric error code indicating errors the exchange
|
||||||
// encountered tracking the wire transfer for this purchase (before
|
// encountered tracking the wire transfer for this purchase (before
|
||||||
@ -140,10 +144,10 @@ export interface CheckPaymentPaidResponse {
|
|||||||
exchange_hc: number;
|
exchange_hc: number;
|
||||||
|
|
||||||
// Total amount that was refunded, 0 if refunded is false.
|
// Total amount that was refunded, 0 if refunded is false.
|
||||||
refund_amount: talerTypes.AmountString;
|
refund_amount: AmountString;
|
||||||
|
|
||||||
// Contract terms
|
// Contract terms
|
||||||
contract_terms: talerTypes.ContractTerms;
|
contract_terms: ContractTerms;
|
||||||
|
|
||||||
// Ihe wire transfer status from the exchange for this order if available, otherwise empty array
|
// Ihe wire transfer status from the exchange for this order if available, otherwise empty array
|
||||||
wire_details: TransactionWireTransfer[];
|
wire_details: TransactionWireTransfer[];
|
||||||
@ -177,10 +181,10 @@ export interface RefundDetails {
|
|||||||
reason: string;
|
reason: string;
|
||||||
|
|
||||||
// when was the refund approved
|
// when was the refund approved
|
||||||
timestamp: time.Timestamp;
|
timestamp: Timestamp;
|
||||||
|
|
||||||
// Total amount that was refunded (minus a refund fee).
|
// Total amount that was refunded (minus a refund fee).
|
||||||
amount: talerTypes.AmountString;
|
amount: AmountString;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TransactionWireTransfer {
|
export interface TransactionWireTransfer {
|
||||||
@ -191,11 +195,11 @@ export interface TransactionWireTransfer {
|
|||||||
wtid: string;
|
wtid: string;
|
||||||
|
|
||||||
// execution time of the wire transfer
|
// execution time of the wire transfer
|
||||||
execution_time: time.Timestamp;
|
execution_time: Timestamp;
|
||||||
|
|
||||||
// Total amount that has been wire transfered
|
// Total amount that has been wire transfered
|
||||||
// to the merchant
|
// to the merchant
|
||||||
amount: talerTypes.AmountString;
|
amount: AmountString;
|
||||||
|
|
||||||
// Was this transfer confirmed by the merchant via the
|
// Was this transfer confirmed by the merchant via the
|
||||||
// POST /transfers API, or is it merely claimed by the exchange?
|
// POST /transfers API, or is it merely claimed by the exchange?
|
||||||
@ -216,5 +220,5 @@ export interface TransactionWireReport {
|
|||||||
exchange_hc: number;
|
exchange_hc: number;
|
||||||
|
|
||||||
// Public key of the coin for which we got the exchange error.
|
// Public key of the coin for which we got the exchange error.
|
||||||
coin_pub: talerTypes.CoinPublicKeyString;
|
coin_pub: CoinPublicKeyString;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ runTest(async (t: GlobalTestState) => {
|
|||||||
orderResp.order_id,
|
orderResp.order_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
t.assertTrue(orderStatus.order_status === "unpaid")
|
t.assertTrue(orderStatus.order_status === "unpaid");
|
||||||
|
|
||||||
console.log(orderStatus);
|
console.log(orderStatus);
|
||||||
|
|
||||||
|
@ -31,7 +31,11 @@ import {
|
|||||||
WalletCli,
|
WalletCli,
|
||||||
defaultCoinConfig,
|
defaultCoinConfig,
|
||||||
} from "./harness";
|
} from "./harness";
|
||||||
import { FaultInjectedExchangeService, FaultInjectionRequestContext, FaultInjectionResponseContext } from "./faultInjection";
|
import {
|
||||||
|
FaultInjectedExchangeService,
|
||||||
|
FaultInjectionRequestContext,
|
||||||
|
FaultInjectionResponseContext,
|
||||||
|
} from "./faultInjection";
|
||||||
import { CoreApiResponse } from "taler-wallet-core/lib/walletCoreApiHandler";
|
import { CoreApiResponse } from "taler-wallet-core/lib/walletCoreApiHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +60,10 @@ runTest(async (t: GlobalTestState) => {
|
|||||||
database: db.connStr,
|
database: db.connStr,
|
||||||
});
|
});
|
||||||
|
|
||||||
const exchangeBankAccount = await bank.createExchangeAccount("MyExchange", "x");
|
const exchangeBankAccount = await bank.createExchangeAccount(
|
||||||
|
"MyExchange",
|
||||||
|
"x",
|
||||||
|
);
|
||||||
|
|
||||||
bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri);
|
bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri);
|
||||||
|
|
||||||
@ -79,7 +86,7 @@ runTest(async (t: GlobalTestState) => {
|
|||||||
},
|
},
|
||||||
modifyResponse(ctx: FaultInjectionResponseContext) {
|
modifyResponse(ctx: FaultInjectionResponseContext) {
|
||||||
console.log("got response", ctx);
|
console.log("got response", ctx);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const merchant = await MerchantService.create(t, {
|
const merchant = await MerchantService.create(t, {
|
||||||
@ -174,7 +181,7 @@ runTest(async (t: GlobalTestState) => {
|
|||||||
faultCount++;
|
faultCount++;
|
||||||
ctx.dropResponse = true;
|
ctx.dropResponse = true;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// confirmPay won't work, as the exchange is unreachable
|
// confirmPay won't work, as the exchange is unreachable
|
||||||
|
@ -30,10 +30,12 @@ import {
|
|||||||
} from "./harness";
|
} from "./harness";
|
||||||
import { withdrawViaBank } from "./helpers";
|
import { withdrawViaBank } from "./helpers";
|
||||||
|
|
||||||
async function setupTest(t: GlobalTestState): Promise<{
|
async function setupTest(
|
||||||
merchant: MerchantService,
|
t: GlobalTestState,
|
||||||
exchange: ExchangeService,
|
): Promise<{
|
||||||
bank: BankService,
|
merchant: MerchantService;
|
||||||
|
exchange: ExchangeService;
|
||||||
|
bank: BankService;
|
||||||
}> {
|
}> {
|
||||||
const db = await setupDb(t);
|
const db = await setupDb(t);
|
||||||
|
|
||||||
@ -51,7 +53,10 @@ async function setupTest(t: GlobalTestState): Promise<{
|
|||||||
database: db.connStr,
|
database: db.connStr,
|
||||||
});
|
});
|
||||||
|
|
||||||
const exchangeBankAccount = await bank.createExchangeAccount("MyExchange", "x");
|
const exchangeBankAccount = await bank.createExchangeAccount(
|
||||||
|
"MyExchange",
|
||||||
|
"x",
|
||||||
|
);
|
||||||
|
|
||||||
exchange.addOfferedCoins([coin_ct10, coin_u1]);
|
exchange.addOfferedCoins([coin_ct10, coin_u1]);
|
||||||
|
|
||||||
@ -96,7 +101,7 @@ async function setupTest(t: GlobalTestState): Promise<{
|
|||||||
merchant,
|
merchant,
|
||||||
bank,
|
bank,
|
||||||
exchange,
|
exchange,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,7 +52,7 @@ runTest(async (t: GlobalTestState) => {
|
|||||||
orderResp.order_id,
|
orderResp.order_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
t.assertTrue(orderStatus.order_status === "unpaid")
|
t.assertTrue(orderStatus.order_status === "unpaid");
|
||||||
|
|
||||||
// Make wallet pay for the order
|
// Make wallet pay for the order
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ runTest(async (t: GlobalTestState) => {
|
|||||||
orderResp.order_id,
|
orderResp.order_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
t.assertTrue(orderStatus.order_status === "unpaid")
|
t.assertTrue(orderStatus.order_status === "unpaid");
|
||||||
|
|
||||||
// Make wallet pay for the order
|
// Make wallet pay for the order
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ runTest(async (t: GlobalTestState) => {
|
|||||||
orderResp.order_id,
|
orderResp.order_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
t.assertTrue(orderStatus.order_status === "unpaid")
|
t.assertTrue(orderStatus.order_status === "unpaid");
|
||||||
|
|
||||||
// Make wallet pay for the order
|
// Make wallet pay for the order
|
||||||
|
|
||||||
|
@ -19,13 +19,12 @@
|
|||||||
*/
|
*/
|
||||||
import { runTest, GlobalTestState } from "./harness";
|
import { runTest, GlobalTestState } from "./harness";
|
||||||
import { createSimpleTestkudosEnvironment } from "./helpers";
|
import { createSimpleTestkudosEnvironment } from "./helpers";
|
||||||
import { walletTypes } from "taler-wallet-core";
|
import { codecForBalancesResponse } from "taler-wallet-core";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run test for basic, bank-integrated withdrawal.
|
* Run test for basic, bank-integrated withdrawal.
|
||||||
*/
|
*/
|
||||||
runTest(async (t: GlobalTestState) => {
|
runTest(async (t: GlobalTestState) => {
|
||||||
|
|
||||||
// Set up test environment
|
// Set up test environment
|
||||||
|
|
||||||
const { wallet, bank, exchange } = await createSimpleTestkudosEnvironment(t);
|
const { wallet, bank, exchange } = await createSimpleTestkudosEnvironment(t);
|
||||||
@ -61,8 +60,8 @@ runTest(async (t: GlobalTestState) => {
|
|||||||
|
|
||||||
const balApiResp = await wallet.apiRequest("getBalances", {});
|
const balApiResp = await wallet.apiRequest("getBalances", {});
|
||||||
t.assertTrue(balApiResp.type === "response");
|
t.assertTrue(balApiResp.type === "response");
|
||||||
const balResp = walletTypes.codecForBalancesResponse().decode(balApiResp.result);
|
const balResp = codecForBalancesResponse().decode(balApiResp.result);
|
||||||
t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available)
|
t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available);
|
||||||
|
|
||||||
await t.shutdown();
|
await t.shutdown();
|
||||||
});
|
});
|
||||||
|
@ -19,17 +19,21 @@
|
|||||||
*/
|
*/
|
||||||
import { runTest, GlobalTestState } from "./harness";
|
import { runTest, GlobalTestState } from "./harness";
|
||||||
import { createSimpleTestkudosEnvironment } from "./helpers";
|
import { createSimpleTestkudosEnvironment } from "./helpers";
|
||||||
import { walletTypes } from "taler-wallet-core";
|
|
||||||
import { CoreApiResponse } from "taler-wallet-core/lib/walletCoreApiHandler";
|
import { CoreApiResponse } from "taler-wallet-core/lib/walletCoreApiHandler";
|
||||||
|
import { codecForBalancesResponse } from "taler-wallet-core";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run test for basic, bank-integrated withdrawal.
|
* Run test for basic, bank-integrated withdrawal.
|
||||||
*/
|
*/
|
||||||
runTest(async (t: GlobalTestState) => {
|
runTest(async (t: GlobalTestState) => {
|
||||||
|
|
||||||
// Set up test environment
|
// Set up test environment
|
||||||
|
|
||||||
const { wallet, bank, exchange, exchangeBankAccount } = await createSimpleTestkudosEnvironment(t);
|
const {
|
||||||
|
wallet,
|
||||||
|
bank,
|
||||||
|
exchange,
|
||||||
|
exchangeBankAccount,
|
||||||
|
} = await createSimpleTestkudosEnvironment(t);
|
||||||
|
|
||||||
// Create a withdrawal operation
|
// Create a withdrawal operation
|
||||||
|
|
||||||
@ -67,8 +71,8 @@ runTest(async (t: GlobalTestState) => {
|
|||||||
|
|
||||||
const balApiResp = await wallet.apiRequest("getBalances", {});
|
const balApiResp = await wallet.apiRequest("getBalances", {});
|
||||||
t.assertTrue(balApiResp.type === "response");
|
t.assertTrue(balApiResp.type === "response");
|
||||||
const balResp = walletTypes.codecForBalancesResponse().decode(balApiResp.result);
|
const balResp = codecForBalancesResponse().decode(balApiResp.result);
|
||||||
t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available)
|
t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available);
|
||||||
|
|
||||||
await t.shutdown();
|
await t.shutdown();
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "tsc && rollup -c",
|
"compile": "tsc && rollup -c",
|
||||||
"pretty": "prettier --config ../../.prettierrc --write src",
|
"pretty": "prettier --write src",
|
||||||
"test": "tsc && ava",
|
"test": "tsc && ava",
|
||||||
"coverage": "tsc && nyc ava",
|
"coverage": "tsc && nyc ava",
|
||||||
"clean": "rimraf lib dist"
|
"clean": "rimraf lib dist"
|
||||||
@ -33,6 +33,7 @@
|
|||||||
"@rollup/plugin-node-resolve": "^8.4.0",
|
"@rollup/plugin-node-resolve": "^8.4.0",
|
||||||
"@rollup/plugin-replace": "^2.3.3",
|
"@rollup/plugin-replace": "^2.3.3",
|
||||||
"@types/node": "^14.0.27",
|
"@types/node": "^14.0.27",
|
||||||
|
"prettier": "^2.0.5",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rollup": "^2.23.0",
|
"rollup": "^2.23.0",
|
||||||
"rollup-plugin-sourcemaps": "^0.6.2",
|
"rollup-plugin-sourcemaps": "^0.6.2",
|
||||||
|
@ -21,42 +21,47 @@ import {
|
|||||||
Wallet,
|
Wallet,
|
||||||
getDefaultNodeWallet,
|
getDefaultNodeWallet,
|
||||||
DefaultNodeWalletArgs,
|
DefaultNodeWalletArgs,
|
||||||
versions,
|
|
||||||
httpLib,
|
|
||||||
nodeThreadWorker,
|
|
||||||
promiseUtil,
|
|
||||||
NodeHttpLib,
|
NodeHttpLib,
|
||||||
walletCoreApi,
|
|
||||||
walletNotifications,
|
|
||||||
TalerErrorCode,
|
TalerErrorCode,
|
||||||
makeErrorDetails,
|
makeErrorDetails,
|
||||||
|
handleWorkerError,
|
||||||
|
handleWorkerMessage,
|
||||||
|
HttpRequestLibrary,
|
||||||
|
OpenedPromise,
|
||||||
|
HttpResponse,
|
||||||
|
HttpRequestOptions,
|
||||||
|
openPromise,
|
||||||
|
Headers,
|
||||||
|
CoreApiEnvelope,
|
||||||
|
CoreApiResponse,
|
||||||
|
CoreApiResponseSuccess,
|
||||||
|
WalletNotification,
|
||||||
|
WALLET_EXCHANGE_PROTOCOL_VERSION,
|
||||||
|
WALLET_MERCHANT_PROTOCOL_VERSION,
|
||||||
|
handleCoreApiRequest,
|
||||||
} from "taler-wallet-core";
|
} from "taler-wallet-core";
|
||||||
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
export const handleWorkerError = nodeThreadWorker.handleWorkerError;
|
export { handleWorkerError, handleWorkerMessage };
|
||||||
export const handleWorkerMessage = nodeThreadWorker.handleWorkerMessage;
|
|
||||||
|
|
||||||
export class AndroidHttpLib implements httpLib.HttpRequestLibrary {
|
export class AndroidHttpLib implements HttpRequestLibrary {
|
||||||
useNfcTunnel = false;
|
useNfcTunnel = false;
|
||||||
|
|
||||||
private nodeHttpLib: httpLib.HttpRequestLibrary = new NodeHttpLib();
|
private nodeHttpLib: HttpRequestLibrary = new NodeHttpLib();
|
||||||
|
|
||||||
private requestId = 1;
|
private requestId = 1;
|
||||||
|
|
||||||
private requestMap: {
|
private requestMap: {
|
||||||
[id: number]: promiseUtil.OpenedPromise<httpLib.HttpResponse>;
|
[id: number]: OpenedPromise<HttpResponse>;
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
constructor(private sendMessage: (m: string) => void) {}
|
constructor(private sendMessage: (m: string) => void) {}
|
||||||
|
|
||||||
get(
|
get(url: string, opt?: HttpRequestOptions): Promise<HttpResponse> {
|
||||||
url: string,
|
|
||||||
opt?: httpLib.HttpRequestOptions,
|
|
||||||
): Promise<httpLib.HttpResponse> {
|
|
||||||
if (this.useNfcTunnel) {
|
if (this.useNfcTunnel) {
|
||||||
const myId = this.requestId++;
|
const myId = this.requestId++;
|
||||||
const p = promiseUtil.openPromise<httpLib.HttpResponse>();
|
const p = openPromise<HttpResponse>();
|
||||||
this.requestMap[myId] = p;
|
this.requestMap[myId] = p;
|
||||||
const request = {
|
const request = {
|
||||||
method: "get",
|
method: "get",
|
||||||
@ -78,11 +83,11 @@ export class AndroidHttpLib implements httpLib.HttpRequestLibrary {
|
|||||||
postJson(
|
postJson(
|
||||||
url: string,
|
url: string,
|
||||||
body: any,
|
body: any,
|
||||||
opt?: httpLib.HttpRequestOptions,
|
opt?: HttpRequestOptions,
|
||||||
): Promise<httpLib.HttpResponse> {
|
): Promise<HttpResponse> {
|
||||||
if (this.useNfcTunnel) {
|
if (this.useNfcTunnel) {
|
||||||
const myId = this.requestId++;
|
const myId = this.requestId++;
|
||||||
const p = promiseUtil.openPromise<httpLib.HttpResponse>();
|
const p = openPromise<HttpResponse>();
|
||||||
this.requestMap[myId] = p;
|
this.requestMap[myId] = p;
|
||||||
const request = {
|
const request = {
|
||||||
method: "postJson",
|
method: "postJson",
|
||||||
@ -106,9 +111,9 @@ export class AndroidHttpLib implements httpLib.HttpRequestLibrary {
|
|||||||
`no matching request for tunneled HTTP response, id=${myId}`,
|
`no matching request for tunneled HTTP response, id=${myId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const headers = new httpLib.Headers();
|
const headers = new Headers();
|
||||||
if (msg.status != 0) {
|
if (msg.status != 0) {
|
||||||
const resp: httpLib.HttpResponse = {
|
const resp: HttpResponse = {
|
||||||
// FIXME: pass through this URL
|
// FIXME: pass through this URL
|
||||||
requestUrl: "",
|
requestUrl: "",
|
||||||
headers,
|
headers,
|
||||||
@ -125,7 +130,7 @@ export class AndroidHttpLib implements httpLib.HttpRequestLibrary {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendAkonoMessage(ev: walletCoreApi.CoreApiEnvelope): void {
|
function sendAkonoMessage(ev: CoreApiEnvelope): void {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const sendMessage = globalThis.__akono_sendMessage;
|
const sendMessage = globalThis.__akono_sendMessage;
|
||||||
if (typeof sendMessage !== "function") {
|
if (typeof sendMessage !== "function") {
|
||||||
@ -142,7 +147,7 @@ function sendAkonoMessage(ev: walletCoreApi.CoreApiEnvelope): void {
|
|||||||
class AndroidWalletMessageHandler {
|
class AndroidWalletMessageHandler {
|
||||||
walletArgs: DefaultNodeWalletArgs | undefined;
|
walletArgs: DefaultNodeWalletArgs | undefined;
|
||||||
maybeWallet: Wallet | undefined;
|
maybeWallet: Wallet | undefined;
|
||||||
wp = promiseUtil.openPromise<Wallet>();
|
wp = openPromise<Wallet>();
|
||||||
httpLib = new NodeHttpLib();
|
httpLib = new NodeHttpLib();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,10 +157,8 @@ class AndroidWalletMessageHandler {
|
|||||||
operation: string,
|
operation: string,
|
||||||
id: string,
|
id: string,
|
||||||
args: any,
|
args: any,
|
||||||
): Promise<walletCoreApi.CoreApiResponse> {
|
): Promise<CoreApiResponse> {
|
||||||
const wrapResponse = (
|
const wrapResponse = (result: unknown): CoreApiResponseSuccess => {
|
||||||
result: unknown,
|
|
||||||
): walletCoreApi.CoreApiResponseSuccess => {
|
|
||||||
return {
|
return {
|
||||||
type: "response",
|
type: "response",
|
||||||
id,
|
id,
|
||||||
@ -166,9 +169,7 @@ class AndroidWalletMessageHandler {
|
|||||||
switch (operation) {
|
switch (operation) {
|
||||||
case "init": {
|
case "init": {
|
||||||
this.walletArgs = {
|
this.walletArgs = {
|
||||||
notifyHandler: async (
|
notifyHandler: async (notification: WalletNotification) => {
|
||||||
notification: walletNotifications.WalletNotification,
|
|
||||||
) => {
|
|
||||||
sendAkonoMessage({ type: "notification", payload: notification });
|
sendAkonoMessage({ type: "notification", payload: notification });
|
||||||
},
|
},
|
||||||
persistentStoragePath: args.persistentStoragePath,
|
persistentStoragePath: args.persistentStoragePath,
|
||||||
@ -182,8 +183,8 @@ class AndroidWalletMessageHandler {
|
|||||||
this.wp.resolve(w);
|
this.wp.resolve(w);
|
||||||
return wrapResponse({
|
return wrapResponse({
|
||||||
supported_protocol_versions: {
|
supported_protocol_versions: {
|
||||||
exchange: versions.WALLET_EXCHANGE_PROTOCOL_VERSION,
|
exchange: WALLET_EXCHANGE_PROTOCOL_VERSION,
|
||||||
merchant: versions.WALLET_MERCHANT_PROTOCOL_VERSION,
|
merchant: WALLET_MERCHANT_PROTOCOL_VERSION,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -216,7 +217,7 @@ class AndroidWalletMessageHandler {
|
|||||||
}
|
}
|
||||||
const wallet = await this.wp.promise;
|
const wallet = await this.wp.promise;
|
||||||
wallet.stop();
|
wallet.stop();
|
||||||
this.wp = promiseUtil.openPromise<Wallet>();
|
this.wp = openPromise<Wallet>();
|
||||||
this.maybeWallet = undefined;
|
this.maybeWallet = undefined;
|
||||||
const w = await getDefaultNodeWallet(this.walletArgs);
|
const w = await getDefaultNodeWallet(this.walletArgs);
|
||||||
this.maybeWallet = w;
|
this.maybeWallet = w;
|
||||||
@ -228,12 +229,7 @@ class AndroidWalletMessageHandler {
|
|||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
const wallet = await this.wp.promise;
|
const wallet = await this.wp.promise;
|
||||||
return await walletCoreApi.handleCoreApiRequest(
|
return await handleCoreApiRequest(wallet, operation, id, args);
|
||||||
wallet,
|
|
||||||
operation,
|
|
||||||
id,
|
|
||||||
args,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,7 +260,7 @@ export function installAndroidWalletListener(): void {
|
|||||||
);
|
);
|
||||||
sendAkonoMessage(respMsg);
|
sendAkonoMessage(respMsg);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const respMsg: walletCoreApi.CoreApiResponse = {
|
const respMsg: CoreApiResponse = {
|
||||||
type: "error",
|
type: "error",
|
||||||
id,
|
id,
|
||||||
operation,
|
operation,
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "tsc && rollup -c",
|
"compile": "tsc && rollup -c",
|
||||||
"clean": "rimraf lib dist",
|
"clean": "rimraf lib dist",
|
||||||
"pretty": "prettier --config ../../.prettierrc --write src"
|
"pretty": "prettier --write src"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"AUTHORS",
|
"AUTHORS",
|
||||||
@ -34,6 +34,7 @@
|
|||||||
"@rollup/plugin-node-resolve": "^8.4.0",
|
"@rollup/plugin-node-resolve": "^8.4.0",
|
||||||
"@rollup/plugin-replace": "^2.3.3",
|
"@rollup/plugin-replace": "^2.3.3",
|
||||||
"@types/node": "^14.0.27",
|
"@types/node": "^14.0.27",
|
||||||
|
"prettier": "^2.0.5",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rollup": "^2.23.0",
|
"rollup": "^2.23.0",
|
||||||
"rollup-plugin-sourcemaps": "^0.6.2",
|
"rollup-plugin-sourcemaps": "^0.6.2",
|
||||||
|
@ -23,15 +23,17 @@ import {
|
|||||||
Wallet,
|
Wallet,
|
||||||
OperationFailedAndReportedError,
|
OperationFailedAndReportedError,
|
||||||
OperationFailedError,
|
OperationFailedError,
|
||||||
time,
|
|
||||||
taleruri,
|
|
||||||
walletTypes,
|
|
||||||
talerCrypto,
|
|
||||||
payto,
|
|
||||||
codec,
|
|
||||||
testvectors,
|
|
||||||
walletCoreApi,
|
|
||||||
NodeHttpLib,
|
NodeHttpLib,
|
||||||
|
PreparePayResultType,
|
||||||
|
setDangerousTimetravel,
|
||||||
|
handleCoreApiRequest,
|
||||||
|
classifyTalerUri,
|
||||||
|
TalerUriType,
|
||||||
|
decodeCrock,
|
||||||
|
addPaytoQueryParams,
|
||||||
|
makeCodecForList,
|
||||||
|
codecForString,
|
||||||
|
printTestVectors,
|
||||||
} from "taler-wallet-core";
|
} from "taler-wallet-core";
|
||||||
import * as clk from "./clk";
|
import * as clk from "./clk";
|
||||||
import { NodeThreadCryptoWorkerFactory } from "taler-wallet-core/lib/crypto/workers/nodeThreadWorker";
|
import { NodeThreadCryptoWorkerFactory } from "taler-wallet-core/lib/crypto/workers/nodeThreadWorker";
|
||||||
@ -55,13 +57,13 @@ async function doPay(
|
|||||||
options: { alwaysYes: boolean } = { alwaysYes: true },
|
options: { alwaysYes: boolean } = { alwaysYes: true },
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const result = await wallet.preparePayForUri(payUrl);
|
const result = await wallet.preparePayForUri(payUrl);
|
||||||
if (result.status === walletTypes.PreparePayResultType.InsufficientBalance) {
|
if (result.status === PreparePayResultType.InsufficientBalance) {
|
||||||
console.log("contract", result.contractTerms);
|
console.log("contract", result.contractTerms);
|
||||||
console.error("insufficient balance");
|
console.error("insufficient balance");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result.status === walletTypes.PreparePayResultType.AlreadyConfirmed) {
|
if (result.status === PreparePayResultType.AlreadyConfirmed) {
|
||||||
if (result.paid) {
|
if (result.paid) {
|
||||||
console.log("already paid!");
|
console.log("already paid!");
|
||||||
} else {
|
} else {
|
||||||
@ -127,7 +129,7 @@ export const walletCli = clk
|
|||||||
onPresentHandler: (x) => {
|
onPresentHandler: (x) => {
|
||||||
// Convert microseconds to milliseconds and do timetravel
|
// Convert microseconds to milliseconds and do timetravel
|
||||||
logger.info(`timetravelling ${x} microseconds`);
|
logger.info(`timetravelling ${x} microseconds`);
|
||||||
time.setDangerousTimetravel(x / 1000);
|
setDangerousTimetravel(x / 1000);
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.maybeOption("inhibit", ["--inhibit"], clk.STRING, {
|
.maybeOption("inhibit", ["--inhibit"], clk.STRING, {
|
||||||
@ -208,7 +210,7 @@ walletCli
|
|||||||
console.error("Invalid JSON");
|
console.error("Invalid JSON");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const resp = await walletCoreApi.handleCoreApiRequest(
|
const resp = await handleCoreApiRequest(
|
||||||
wallet,
|
wallet,
|
||||||
args.api.operation,
|
args.api.operation,
|
||||||
"reqid-1",
|
"reqid-1",
|
||||||
@ -277,22 +279,22 @@ walletCli
|
|||||||
.action(async (args) => {
|
.action(async (args) => {
|
||||||
await withWallet(args, async (wallet) => {
|
await withWallet(args, async (wallet) => {
|
||||||
const uri: string = args.handleUri.uri;
|
const uri: string = args.handleUri.uri;
|
||||||
const uriType = taleruri.classifyTalerUri(uri);
|
const uriType = classifyTalerUri(uri);
|
||||||
switch (uriType) {
|
switch (uriType) {
|
||||||
case taleruri.TalerUriType.TalerPay:
|
case TalerUriType.TalerPay:
|
||||||
await doPay(wallet, uri, { alwaysYes: args.handleUri.autoYes });
|
await doPay(wallet, uri, { alwaysYes: args.handleUri.autoYes });
|
||||||
break;
|
break;
|
||||||
case taleruri.TalerUriType.TalerTip:
|
case TalerUriType.TalerTip:
|
||||||
{
|
{
|
||||||
const res = await wallet.getTipStatus(uri);
|
const res = await wallet.getTipStatus(uri);
|
||||||
console.log("tip status", res);
|
console.log("tip status", res);
|
||||||
await wallet.acceptTip(res.tipId);
|
await wallet.acceptTip(res.tipId);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case taleruri.TalerUriType.TalerRefund:
|
case TalerUriType.TalerRefund:
|
||||||
await wallet.applyRefund(uri);
|
await wallet.applyRefund(uri);
|
||||||
break;
|
break;
|
||||||
case taleruri.TalerUriType.TalerWithdraw:
|
case TalerUriType.TalerWithdraw:
|
||||||
{
|
{
|
||||||
const withdrawInfo = await wallet.getWithdrawalDetailsForUri(uri);
|
const withdrawInfo = await wallet.getWithdrawalDetailsForUri(uri);
|
||||||
const selectedExchange = withdrawInfo.defaultExchangeBaseUrl;
|
const selectedExchange = withdrawInfo.defaultExchangeBaseUrl;
|
||||||
@ -419,7 +421,7 @@ advancedCli
|
|||||||
})
|
})
|
||||||
.action((args) => {
|
.action((args) => {
|
||||||
const enc = fs.readFileSync(0, "utf8");
|
const enc = fs.readFileSync(0, "utf8");
|
||||||
fs.writeFileSync(1, talerCrypto.decodeCrock(enc.trim()));
|
fs.writeFileSync(1, decodeCrock(enc.trim()));
|
||||||
});
|
});
|
||||||
|
|
||||||
advancedCli
|
advancedCli
|
||||||
@ -446,7 +448,7 @@ advancedCli
|
|||||||
exchange.baseUrl,
|
exchange.baseUrl,
|
||||||
Amounts.parseOrThrow(args.withdrawManually.amount),
|
Amounts.parseOrThrow(args.withdrawManually.amount),
|
||||||
);
|
);
|
||||||
const completePaytoUri = payto.addPaytoQueryParams(acct.payto_uri, {
|
const completePaytoUri = addPaytoQueryParams(acct.payto_uri, {
|
||||||
amount: args.withdrawManually.amount,
|
amount: args.withdrawManually.amount,
|
||||||
message: `Taler top-up ${reserve.reservePub}`,
|
message: `Taler top-up ${reserve.reservePub}`,
|
||||||
});
|
});
|
||||||
@ -490,17 +492,17 @@ advancedCli
|
|||||||
await withWallet(args, async (wallet) => {
|
await withWallet(args, async (wallet) => {
|
||||||
const res = await wallet.preparePayForUri(args.payPrepare.url);
|
const res = await wallet.preparePayForUri(args.payPrepare.url);
|
||||||
switch (res.status) {
|
switch (res.status) {
|
||||||
case walletTypes.PreparePayResultType.InsufficientBalance:
|
case PreparePayResultType.InsufficientBalance:
|
||||||
console.log("insufficient balance");
|
console.log("insufficient balance");
|
||||||
break;
|
break;
|
||||||
case walletTypes.PreparePayResultType.AlreadyConfirmed:
|
case PreparePayResultType.AlreadyConfirmed:
|
||||||
if (res.paid) {
|
if (res.paid) {
|
||||||
console.log("already paid!");
|
console.log("already paid!");
|
||||||
} else {
|
} else {
|
||||||
console.log("payment in progress");
|
console.log("payment in progress");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case walletTypes.PreparePayResultType.PaymentPossible:
|
case PreparePayResultType.PaymentPossible:
|
||||||
console.log("payment possible");
|
console.log("payment possible");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -546,7 +548,7 @@ advancedCli
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const coinPubListCodec = codec.makeCodecForList(codec.codecForString);
|
const coinPubListCodec = makeCodecForList(codecForString);
|
||||||
|
|
||||||
advancedCli
|
advancedCli
|
||||||
.subcommand("suspendCoins", "suspend-coins", {
|
.subcommand("suspendCoins", "suspend-coins", {
|
||||||
@ -640,7 +642,7 @@ const testCli = walletCli.subcommand("testingArgs", "testing", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testCli.subcommand("vectors", "vectors").action(async (args) => {
|
testCli.subcommand("vectors", "vectors").action(async (args) => {
|
||||||
testvectors.printTestVectors();
|
printTestVectors();
|
||||||
});
|
});
|
||||||
|
|
||||||
testCli.subcommand("cryptoworker", "cryptoworker").action(async (args) => {
|
testCli.subcommand("cryptoworker", "cryptoworker").action(async (args) => {
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "tsc && rollup -c",
|
"compile": "tsc && rollup -c",
|
||||||
"pretty": "prettier --config ../../.prettierrc --write src",
|
"pretty": "prettier --write src",
|
||||||
"test": "tsc && ava",
|
"test": "tsc && ava",
|
||||||
"coverage": "tsc && nyc ava",
|
"coverage": "tsc && nyc ava",
|
||||||
"clean": "rimraf dist lib"
|
"clean": "rimraf dist lib"
|
||||||
|
@ -46,7 +46,6 @@ import {
|
|||||||
|
|
||||||
import * as timer from "../../util/timer";
|
import * as timer from "../../util/timer";
|
||||||
import { Logger } from "../../util/logging";
|
import { Logger } from "../../util/logging";
|
||||||
import { walletCoreApi } from "../..";
|
|
||||||
|
|
||||||
const logger = new Logger("cryptoApi.ts");
|
const logger = new Logger("cryptoApi.ts");
|
||||||
|
|
||||||
|
@ -26,57 +26,52 @@ export {
|
|||||||
export { Amounts, AmountJson } from "./util/amounts";
|
export { Amounts, AmountJson } from "./util/amounts";
|
||||||
export { Logger } from "./util/logging";
|
export { Logger } from "./util/logging";
|
||||||
|
|
||||||
export * as talerCrypto from "./crypto/talerCrypto";
|
export * from "./crypto/talerCrypto";
|
||||||
export {
|
export {
|
||||||
OperationFailedAndReportedError,
|
OperationFailedAndReportedError,
|
||||||
OperationFailedError,
|
OperationFailedError,
|
||||||
makeErrorDetails,
|
makeErrorDetails,
|
||||||
} from "./operations/errors";
|
} from "./operations/errors";
|
||||||
|
|
||||||
export * as walletTypes from "./types/walletTypes";
|
export * from "./types/walletTypes";
|
||||||
|
|
||||||
export * as talerTypes from "./types/talerTypes";
|
export * from "./types/talerTypes";
|
||||||
|
|
||||||
export * as walletCoreApi from "./walletCoreApiHandler";
|
export * from "./walletCoreApiHandler";
|
||||||
|
|
||||||
export * as taleruri from "./util/taleruri";
|
export * from "./util/taleruri";
|
||||||
|
|
||||||
export * as time from "./util/time";
|
export * from "./util/time";
|
||||||
|
|
||||||
export * as codec from "./util/codec";
|
export * from "./util/codec";
|
||||||
|
|
||||||
export { NodeHttpLib } from "./headless/NodeHttpLib";
|
export { NodeHttpLib } from "./headless/NodeHttpLib";
|
||||||
|
|
||||||
export * as payto from "./util/payto";
|
export * from "./util/payto";
|
||||||
|
|
||||||
export * as testvectors from "./util/testvectors";
|
export * from "./util/testvectors";
|
||||||
|
|
||||||
export * as versions from "./operations/versions";
|
export * from "./operations/versions";
|
||||||
|
|
||||||
export type { CryptoWorker } from "./crypto/workers/cryptoWorker";
|
export type { CryptoWorker } from "./crypto/workers/cryptoWorker";
|
||||||
export type { CryptoWorkerFactory } from "./crypto/workers/cryptoApi";
|
export type { CryptoWorkerFactory } from "./crypto/workers/cryptoApi";
|
||||||
|
|
||||||
export * as httpLib from "./util/http";
|
export * from "./util/http";
|
||||||
|
|
||||||
export { TalerErrorCode } from "./TalerErrorCode";
|
export { TalerErrorCode } from "./TalerErrorCode";
|
||||||
|
|
||||||
export * as queryLib from "./util/query";
|
export * from "./util/query";
|
||||||
|
|
||||||
export { CryptoImplementation } from "./crypto/workers/cryptoImplementation";
|
export { CryptoImplementation } from "./crypto/workers/cryptoImplementation";
|
||||||
|
|
||||||
export * as db from "./db";
|
export * from "./db";
|
||||||
|
|
||||||
export * as promiseUtil from "./util/promiseUtils";
|
export * from "./util/promiseUtils";
|
||||||
|
|
||||||
export * as i18n from "./i18n";
|
export * from "./i18n";
|
||||||
|
|
||||||
export * as nodeThreadWorker from "./crypto/workers/nodeThreadWorker";
|
export * from "./crypto/workers/nodeThreadWorker";
|
||||||
|
|
||||||
export * as walletNotifications from "./types/notifications";
|
export * from "./types/notifications";
|
||||||
|
|
||||||
export { Configuration } from "./util/talerconfig";
|
export { Configuration } from "./util/talerconfig";
|
||||||
|
|
||||||
export {
|
|
||||||
handleWorkerMessage,
|
|
||||||
handleWorkerError,
|
|
||||||
} from "./crypto/workers/nodeThreadWorker";
|
|
||||||
|
@ -413,7 +413,8 @@ export async function applyRefund(
|
|||||||
).amount,
|
).amount,
|
||||||
).amount;
|
).amount;
|
||||||
} else {
|
} else {
|
||||||
amountRefundGone = Amounts.add(amountRefundGone, refund.refundAmount).amount;
|
amountRefundGone = Amounts.add(amountRefundGone, refund.refundAmount)
|
||||||
|
.amount;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ import {
|
|||||||
codecForBoolean,
|
codecForBoolean,
|
||||||
} from "../util/codec";
|
} from "../util/codec";
|
||||||
import { AmountString } from "./talerTypes";
|
import { AmountString } from "./talerTypes";
|
||||||
import { codec } from "..";
|
|
||||||
import { TransactionError } from "./transactions";
|
import { TransactionError } from "./transactions";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -202,20 +201,18 @@ export const enum ConfirmPayResultType {
|
|||||||
* Result for confirmPay
|
* Result for confirmPay
|
||||||
*/
|
*/
|
||||||
export interface ConfirmPayResultDone {
|
export interface ConfirmPayResultDone {
|
||||||
type: ConfirmPayResultType.Done,
|
type: ConfirmPayResultType.Done;
|
||||||
|
|
||||||
nextUrl: string;
|
nextUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConfirmPayResultPending {
|
export interface ConfirmPayResultPending {
|
||||||
type: ConfirmPayResultType.Pending,
|
type: ConfirmPayResultType.Pending;
|
||||||
|
|
||||||
lastError: TransactionError;
|
lastError: TransactionError;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ConfirmPayResult =
|
export type ConfirmPayResult = ConfirmPayResultDone | ConfirmPayResultPending;
|
||||||
| ConfirmPayResultDone
|
|
||||||
| ConfirmPayResultPending
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about all sender wire details known to the wallet,
|
* Information about all sender wire details known to the wallet,
|
||||||
|
@ -29,7 +29,7 @@ test("pathsub", (t) => {
|
|||||||
w: "world",
|
w: "world",
|
||||||
f: "foo",
|
f: "foo",
|
||||||
"1foo": "x",
|
"1foo": "x",
|
||||||
"foo_bar": "quux",
|
foo_bar: "quux",
|
||||||
};
|
};
|
||||||
|
|
||||||
t.is(
|
t.is(
|
||||||
|
@ -240,7 +240,9 @@ export class Configuration {
|
|||||||
} else if (x === "no") {
|
} else if (x === "no") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
throw Error(`invalid config value for [${secNorm}]/${optNorm}, expected yes/no`);
|
throw Error(
|
||||||
|
`invalid config value for [${secNorm}]/${optNorm}, expected yes/no`,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
return new ConfigValue(secNorm, optNorm, val, convert);
|
return new ConfigValue(secNorm, optNorm, val, convert);
|
||||||
}
|
}
|
||||||
@ -253,7 +255,9 @@ export class Configuration {
|
|||||||
try {
|
try {
|
||||||
return Number.parseInt(x, 10);
|
return Number.parseInt(x, 10);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Error(`invalid config value for [${secNorm}]/${optNorm}, expected number`);
|
throw Error(
|
||||||
|
`invalid config value for [${secNorm}]/${optNorm}, expected number`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return new ConfigValue(secNorm, optNorm, val, convert);
|
return new ConfigValue(secNorm, optNorm, val, convert);
|
||||||
|
@ -121,7 +121,7 @@ const nullTimerHandle = {
|
|||||||
unref() {
|
unref() {
|
||||||
// do nothing
|
// do nothing
|
||||||
return;
|
return;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,7 +173,7 @@ export class TimerGroup {
|
|||||||
},
|
},
|
||||||
unref() {
|
unref() {
|
||||||
h.unref();
|
h.unref();
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ export class TimerGroup {
|
|||||||
},
|
},
|
||||||
unref() {
|
unref() {
|
||||||
h.unref();
|
h.unref();
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,30 @@
|
|||||||
|
/*
|
||||||
|
This file is part of GNU Taler
|
||||||
|
(C) 2020 Taler Systems S.A.
|
||||||
|
|
||||||
import { httpLib, OperationFailedError, Logger } from "taler-wallet-core";
|
GNU Taler is free software; you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 3, or (at your option) any later version.
|
||||||
|
|
||||||
|
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports.
|
||||||
|
*/
|
||||||
|
import {
|
||||||
|
OperationFailedError,
|
||||||
|
Logger,
|
||||||
|
HttpRequestLibrary,
|
||||||
|
HttpRequestOptions,
|
||||||
|
HttpResponse,
|
||||||
|
Headers,
|
||||||
|
} from "taler-wallet-core";
|
||||||
import { TalerErrorCode } from "taler-wallet-core/lib/TalerErrorCode";
|
import { TalerErrorCode } from "taler-wallet-core/lib/TalerErrorCode";
|
||||||
|
|
||||||
const logger = new Logger("browserHttpLib");
|
const logger = new Logger("browserHttpLib");
|
||||||
@ -8,14 +33,14 @@ const logger = new Logger("browserHttpLib");
|
|||||||
* An implementation of the [[HttpRequestLibrary]] using the
|
* An implementation of the [[HttpRequestLibrary]] using the
|
||||||
* browser's XMLHttpRequest.
|
* browser's XMLHttpRequest.
|
||||||
*/
|
*/
|
||||||
export class BrowserHttpLib implements httpLib.HttpRequestLibrary {
|
export class BrowserHttpLib implements HttpRequestLibrary {
|
||||||
private req(
|
private req(
|
||||||
method: string,
|
method: string,
|
||||||
url: string,
|
url: string,
|
||||||
requestBody?: any,
|
requestBody?: any,
|
||||||
options?: httpLib.HttpRequestOptions,
|
options?: HttpRequestOptions,
|
||||||
): Promise<httpLib.HttpResponse> {
|
): Promise<HttpResponse> {
|
||||||
return new Promise<httpLib.HttpResponse>((resolve, reject) => {
|
return new Promise<HttpResponse>((resolve, reject) => {
|
||||||
const myRequest = new XMLHttpRequest();
|
const myRequest = new XMLHttpRequest();
|
||||||
myRequest.open(method, url);
|
myRequest.open(method, url);
|
||||||
if (options?.headers) {
|
if (options?.headers) {
|
||||||
@ -87,7 +112,7 @@ export class BrowserHttpLib implements httpLib.HttpRequestLibrary {
|
|||||||
const arr = headers.trim().split(/[\r\n]+/);
|
const arr = headers.trim().split(/[\r\n]+/);
|
||||||
|
|
||||||
// Create a map of header names to values
|
// Create a map of header names to values
|
||||||
const headerMap: httpLib.Headers = new httpLib.Headers();
|
const headerMap: Headers = new Headers();
|
||||||
arr.forEach(function (line) {
|
arr.forEach(function (line) {
|
||||||
const parts = line.split(": ");
|
const parts = line.split(": ");
|
||||||
const headerName = parts.shift();
|
const headerName = parts.shift();
|
||||||
@ -98,7 +123,7 @@ export class BrowserHttpLib implements httpLib.HttpRequestLibrary {
|
|||||||
const value = parts.join(": ");
|
const value = parts.join(": ");
|
||||||
headerMap.set(headerName, value);
|
headerMap.set(headerName, value);
|
||||||
});
|
});
|
||||||
const resp: httpLib.HttpResponse = {
|
const resp: HttpResponse = {
|
||||||
requestUrl: url,
|
requestUrl: url,
|
||||||
status: myRequest.status,
|
status: myRequest.status,
|
||||||
headers: headerMap,
|
headers: headerMap,
|
||||||
@ -112,15 +137,15 @@ export class BrowserHttpLib implements httpLib.HttpRequestLibrary {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get(url: string, opt?: httpLib.HttpRequestOptions): Promise<httpLib.HttpResponse> {
|
get(url: string, opt?: HttpRequestOptions): Promise<HttpResponse> {
|
||||||
return this.req("GET", url, undefined, opt);
|
return this.req("GET", url, undefined, opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
postJson(
|
postJson(
|
||||||
url: string,
|
url: string,
|
||||||
body: unknown,
|
body: unknown,
|
||||||
opt?: httpLib.HttpRequestOptions,
|
opt?: HttpRequestOptions,
|
||||||
): Promise<httpLib.HttpResponse> {
|
): Promise<HttpResponse> {
|
||||||
return this.req("POST", url, JSON.stringify(body), opt);
|
return this.req("POST", url, JSON.stringify(body), opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { i18n as i18nCore } from "taler-wallet-core";
|
import * as i18nCore from "taler-wallet-core";
|
||||||
/**
|
/**
|
||||||
* Convert template strings to a msgid
|
* Convert template strings to a msgid
|
||||||
*/
|
*/
|
||||||
|
@ -30,10 +30,10 @@ import * as wxApi from "../wxApi";
|
|||||||
|
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
|
|
||||||
import { Amounts, AmountJson, walletTypes, talerTypes } from "taler-wallet-core";
|
import { Amounts, AmountJson, PreparePayResult, PreparePayResultType, ContractTerms, codecForContractTerms, ConfirmPayResultType } from "taler-wallet-core";
|
||||||
|
|
||||||
function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element {
|
function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element {
|
||||||
const [payStatus, setPayStatus] = useState<walletTypes.PreparePayResult | undefined>();
|
const [payStatus, setPayStatus] = useState<PreparePayResult | undefined>();
|
||||||
const [payErrMsg, setPayErrMsg] = useState<string | undefined>("");
|
const [payErrMsg, setPayErrMsg] = useState<string | undefined>("");
|
||||||
const [numTries, setNumTries] = useState(0);
|
const [numTries, setNumTries] = useState(0);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@ -60,7 +60,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element {
|
|||||||
amountEffective = Amounts.parseOrThrow(payStatus.amountEffective);
|
amountEffective = Amounts.parseOrThrow(payStatus.amountEffective);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payStatus.status === walletTypes.PreparePayResultType.AlreadyConfirmed && numTries === 0) {
|
if (payStatus.status === PreparePayResultType.AlreadyConfirmed && numTries === 0) {
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
You have already paid for this article. Click{" "}
|
You have already paid for this article. Click{" "}
|
||||||
@ -69,10 +69,10 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let contractTerms: talerTypes.ContractTerms;
|
let contractTerms: ContractTerms;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
contractTerms = talerTypes.codecForContractTerms().decode(payStatus.contractTerms);
|
contractTerms = codecForContractTerms().decode(payStatus.contractTerms);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// This should never happen, as the wallet is supposed to check the contract terms
|
// This should never happen, as the wallet is supposed to check the contract terms
|
||||||
// before storing them.
|
// before storing them.
|
||||||
@ -109,7 +109,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element {
|
|||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const res = await wxApi.confirmPay(proposalId, undefined);
|
const res = await wxApi.confirmPay(proposalId, undefined);
|
||||||
if (res.type !== walletTypes.ConfirmPayResultType.Done) {
|
if (res.type !== ConfirmPayResultType.Done) {
|
||||||
throw Error("payment pending");
|
throw Error("payment pending");
|
||||||
}
|
}
|
||||||
document.location.href = res.nextUrl;
|
document.location.href = res.nextUrl;
|
||||||
|
@ -29,9 +29,10 @@ import * as i18n from "../i18n";
|
|||||||
import {
|
import {
|
||||||
AmountJson,
|
AmountJson,
|
||||||
Amounts,
|
Amounts,
|
||||||
time,
|
BalancesResponse,
|
||||||
taleruri,
|
Balance,
|
||||||
walletTypes,
|
classifyTalerUri,
|
||||||
|
TalerUriType,
|
||||||
} from "taler-wallet-core";
|
} from "taler-wallet-core";
|
||||||
|
|
||||||
|
|
||||||
@ -174,7 +175,7 @@ function EmptyBalanceView(): JSX.Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class WalletBalanceView extends React.Component<any, any> {
|
class WalletBalanceView extends React.Component<any, any> {
|
||||||
private balance?: walletTypes.BalancesResponse;
|
private balance?: BalancesResponse;
|
||||||
private gotError = false;
|
private gotError = false;
|
||||||
private canceler: (() => void) | undefined = undefined;
|
private canceler: (() => void) | undefined = undefined;
|
||||||
private unmount = false;
|
private unmount = false;
|
||||||
@ -198,7 +199,7 @@ class WalletBalanceView extends React.Component<any, any> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.updateBalanceRunning = true;
|
this.updateBalanceRunning = true;
|
||||||
let balance: walletTypes.BalancesResponse;
|
let balance: BalancesResponse;
|
||||||
try {
|
try {
|
||||||
balance = await wxApi.getBalance();
|
balance = await wxApi.getBalance();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -221,7 +222,7 @@ class WalletBalanceView extends React.Component<any, any> {
|
|||||||
this.setState({});
|
this.setState({});
|
||||||
}
|
}
|
||||||
|
|
||||||
formatPending(entry: walletTypes.Balance): JSX.Element {
|
formatPending(entry: Balance): JSX.Element {
|
||||||
let incoming: JSX.Element | undefined;
|
let incoming: JSX.Element | undefined;
|
||||||
let payment: JSX.Element | undefined;
|
let payment: JSX.Element | undefined;
|
||||||
|
|
||||||
@ -393,25 +394,25 @@ function makeExtensionUrlWithParams(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function actionForTalerUri(talerUri: string): string | undefined {
|
function actionForTalerUri(talerUri: string): string | undefined {
|
||||||
const uriType = taleruri.classifyTalerUri(talerUri);
|
const uriType = classifyTalerUri(talerUri);
|
||||||
switch (uriType) {
|
switch (uriType) {
|
||||||
case taleruri.TalerUriType.TalerWithdraw:
|
case TalerUriType.TalerWithdraw:
|
||||||
return makeExtensionUrlWithParams("withdraw.html", {
|
return makeExtensionUrlWithParams("withdraw.html", {
|
||||||
talerWithdrawUri: talerUri,
|
talerWithdrawUri: talerUri,
|
||||||
});
|
});
|
||||||
case taleruri.TalerUriType.TalerPay:
|
case TalerUriType.TalerPay:
|
||||||
return makeExtensionUrlWithParams("pay.html", {
|
return makeExtensionUrlWithParams("pay.html", {
|
||||||
talerPayUri: talerUri,
|
talerPayUri: talerUri,
|
||||||
});
|
});
|
||||||
case taleruri.TalerUriType.TalerTip:
|
case TalerUriType.TalerTip:
|
||||||
return makeExtensionUrlWithParams("tip.html", {
|
return makeExtensionUrlWithParams("tip.html", {
|
||||||
talerTipUri: talerUri,
|
talerTipUri: talerUri,
|
||||||
});
|
});
|
||||||
case taleruri.TalerUriType.TalerRefund:
|
case TalerUriType.TalerRefund:
|
||||||
return makeExtensionUrlWithParams("refund.html", {
|
return makeExtensionUrlWithParams("refund.html", {
|
||||||
talerRefundUri: talerUri,
|
talerRefundUri: talerUri,
|
||||||
});
|
});
|
||||||
case taleruri.TalerUriType.TalerNotifyReserve:
|
case TalerUriType.TalerNotifyReserve:
|
||||||
// FIXME: implement
|
// FIXME: implement
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -21,15 +21,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
import * as wxApi from "../wxApi";
|
import * as wxApi from "../wxApi";
|
||||||
import { AmountView } from "../renderHtml";
|
import { AmountView } from "../renderHtml";
|
||||||
import { walletTypes } from "taler-wallet-core";
|
import { PurchaseDetails } from "taler-wallet-core";
|
||||||
|
|
||||||
function RefundStatusView(props: { talerRefundUri: string }): JSX.Element {
|
function RefundStatusView(props: { talerRefundUri: string }): JSX.Element {
|
||||||
const [applied, setApplied] = useState(false);
|
const [applied, setApplied] = useState(false);
|
||||||
const [purchaseDetails, setPurchaseDetails] = useState<
|
const [purchaseDetails, setPurchaseDetails] = useState<
|
||||||
walletTypes.PurchaseDetails | undefined
|
PurchaseDetails | undefined
|
||||||
>(undefined);
|
>(undefined);
|
||||||
const [errMsg, setErrMsg] = useState<string | undefined>(undefined);
|
const [errMsg, setErrMsg] = useState<string | undefined>(undefined);
|
||||||
|
|
||||||
|
@ -22,16 +22,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
|
||||||
import { acceptTip, getTipStatus } from "../wxApi";
|
import { acceptTip, getTipStatus } from "../wxApi";
|
||||||
|
|
||||||
import { renderAmount, ProgressButton } from "../renderHtml";
|
import { renderAmount, ProgressButton } from "../renderHtml";
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { walletTypes } from "taler-wallet-core";
|
import { TipStatus } from "taler-wallet-core";
|
||||||
|
|
||||||
function TipDisplay(props: { talerTipUri: string }): JSX.Element {
|
function TipDisplay(props: { talerTipUri: string }): JSX.Element {
|
||||||
const [tipStatus, setTipStatus] = useState<walletTypes.TipStatus | undefined>(undefined);
|
const [tipStatus, setTipStatus] = useState<TipStatus | undefined>(undefined);
|
||||||
const [discarded, setDiscarded] = useState(false);
|
const [discarded, setDiscarded] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [finished, setFinished] = useState(false);
|
const [finished, setFinished] = useState(false);
|
||||||
|
@ -26,11 +26,11 @@ import { PageLink } from "../renderHtml";
|
|||||||
import * as wxApi from "../wxApi";
|
import * as wxApi from "../wxApi";
|
||||||
import { getPermissionsApi } from "../compat";
|
import { getPermissionsApi } from "../compat";
|
||||||
import { extendedPermissions } from "../permissions";
|
import { extendedPermissions } from "../permissions";
|
||||||
import { walletTypes } from "taler-wallet-core";
|
import { WalletDiagnostics } from "taler-wallet-core";
|
||||||
|
|
||||||
function Diagnostics(): JSX.Element | null {
|
function Diagnostics(): JSX.Element | null {
|
||||||
const [timedOut, setTimedOut] = useState(false);
|
const [timedOut, setTimedOut] = useState(false);
|
||||||
const [diagnostics, setDiagnostics] = useState<walletTypes.WalletDiagnostics | undefined>(
|
const [diagnostics, setDiagnostics] = useState<WalletDiagnostics | undefined>(
|
||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
/**
|
/**
|
||||||
* Imports.
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import { AmountJson, Amounts, time, walletTypes } from "taler-wallet-core";
|
import { AmountJson, Amounts, stringifyTimestamp, ExchangeWithdrawDetails } from "taler-wallet-core";
|
||||||
import * as i18n from "./i18n";
|
import * as i18n from "./i18n";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ export class Collapsible extends React.Component<
|
|||||||
|
|
||||||
function WireFee(props: {
|
function WireFee(props: {
|
||||||
s: string;
|
s: string;
|
||||||
rci: walletTypes.ExchangeWithdrawDetails;
|
rci: ExchangeWithdrawDetails;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -144,7 +144,7 @@ function WireFee(props: {
|
|||||||
<tbody>
|
<tbody>
|
||||||
{props.rci.wireFees.feesForType[props.s].map((f) => (
|
{props.rci.wireFees.feesForType[props.s].map((f) => (
|
||||||
<tr key={f.sig}>
|
<tr key={f.sig}>
|
||||||
<td>{time.stringifyTimestamp(f.endStamp)}</td>
|
<td>{stringifyTimestamp(f.endStamp)}</td>
|
||||||
<td>{renderAmount(f.wireFee)}</td>
|
<td>{renderAmount(f.wireFee)}</td>
|
||||||
<td>{renderAmount(f.closingFee)}</td>
|
<td>{renderAmount(f.closingFee)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -155,7 +155,7 @@ function WireFee(props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function AuditorDetailsView(props: {
|
function AuditorDetailsView(props: {
|
||||||
rci: walletTypes.ExchangeWithdrawDetails | null;
|
rci: ExchangeWithdrawDetails | null;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const rci = props.rci;
|
const rci = props.rci;
|
||||||
console.log("rci", rci);
|
console.log("rci", rci);
|
||||||
@ -192,7 +192,7 @@ function AuditorDetailsView(props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function FeeDetailsView(props: {
|
function FeeDetailsView(props: {
|
||||||
rci: walletTypes.ExchangeWithdrawDetails | null;
|
rci: ExchangeWithdrawDetails | null;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const rci = props.rci;
|
const rci = props.rci;
|
||||||
if (!rci) {
|
if (!rci) {
|
||||||
@ -222,7 +222,7 @@ function FeeDetailsView(props: {
|
|||||||
<p>
|
<p>
|
||||||
{i18n.str`Rounding loss:`} {overhead}
|
{i18n.str`Rounding loss:`} {overhead}
|
||||||
</p>
|
</p>
|
||||||
<p>{i18n.str`Earliest expiration (for deposit): ${time.stringifyTimestamp(
|
<p>{i18n.str`Earliest expiration (for deposit): ${stringifyTimestamp(
|
||||||
rci.earliestDepositExpiration,
|
rci.earliestDepositExpiration,
|
||||||
)}`}</p>
|
)}`}</p>
|
||||||
<h3>Coin Fees</h3>
|
<h3>Coin Fees</h3>
|
||||||
@ -268,7 +268,7 @@ function FeeDetailsView(props: {
|
|||||||
* Shows details about a withdraw request.
|
* Shows details about a withdraw request.
|
||||||
*/
|
*/
|
||||||
export function WithdrawDetailView(props: {
|
export function WithdrawDetailView(props: {
|
||||||
rci: walletTypes.ExchangeWithdrawDetails | null;
|
rci: ExchangeWithdrawDetails | null;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const rci = props.rci;
|
const rci = props.rci;
|
||||||
return (
|
return (
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
/**
|
/**
|
||||||
* Imports.
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import { AmountJson, walletTypes } from "taler-wallet-core";
|
import { AmountJson, ConfirmPayResult, BalancesResponse, PurchaseDetails, TipStatus, BenchmarkResult, PreparePayResult, AcceptWithdrawalResponse, WalletDiagnostics } from "taler-wallet-core";
|
||||||
|
|
||||||
|
|
||||||
export interface ExtendedPermissionsResponse {
|
export interface ExtendedPermissionsResponse {
|
||||||
@ -101,7 +101,7 @@ export function refresh(coinPub: string): Promise<void> {
|
|||||||
export function confirmPay(
|
export function confirmPay(
|
||||||
proposalId: string,
|
proposalId: string,
|
||||||
sessionId: string | undefined,
|
sessionId: string | undefined,
|
||||||
): Promise<walletTypes.ConfirmPayResult> {
|
): Promise<ConfirmPayResult> {
|
||||||
return callBackend("confirm-pay", { proposalId, sessionId });
|
return callBackend("confirm-pay", { proposalId, sessionId });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ export function resetDb(): Promise<void> {
|
|||||||
/**
|
/**
|
||||||
* Get balances for all currencies/exchanges.
|
* Get balances for all currencies/exchanges.
|
||||||
*/
|
*/
|
||||||
export function getBalance(): Promise<walletTypes.BalancesResponse> {
|
export function getBalance(): Promise<BalancesResponse> {
|
||||||
return callBackend("balances", {});
|
return callBackend("balances", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,14 +143,14 @@ export function returnCoins(args: {
|
|||||||
*/
|
*/
|
||||||
export function getPurchaseDetails(
|
export function getPurchaseDetails(
|
||||||
proposalId: string,
|
proposalId: string,
|
||||||
): Promise<walletTypes.PurchaseDetails> {
|
): Promise<PurchaseDetails> {
|
||||||
return callBackend("get-purchase-details", { proposalId });
|
return callBackend("get-purchase-details", { proposalId });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the status of processing a tip.
|
* Get the status of processing a tip.
|
||||||
*/
|
*/
|
||||||
export function getTipStatus(talerTipUri: string): Promise<walletTypes.TipStatus> {
|
export function getTipStatus(talerTipUri: string): Promise<TipStatus> {
|
||||||
return callBackend("get-tip-status", { talerTipUri });
|
return callBackend("get-tip-status", { talerTipUri });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,14 +180,14 @@ export function abortFailedPayment(contractTermsHash: string): Promise<void> {
|
|||||||
/**
|
/**
|
||||||
* Abort a failed payment and try to get a refund.
|
* Abort a failed payment and try to get a refund.
|
||||||
*/
|
*/
|
||||||
export function benchmarkCrypto(repetitions: number): Promise<walletTypes.BenchmarkResult> {
|
export function benchmarkCrypto(repetitions: number): Promise<BenchmarkResult> {
|
||||||
return callBackend("benchmark-crypto", { repetitions });
|
return callBackend("benchmark-crypto", { repetitions });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get details about a pay operation.
|
* Get details about a pay operation.
|
||||||
*/
|
*/
|
||||||
export function preparePay(talerPayUri: string): Promise<walletTypes.PreparePayResult> {
|
export function preparePay(talerPayUri: string): Promise<PreparePayResult> {
|
||||||
return callBackend("prepare-pay", { talerPayUri });
|
return callBackend("prepare-pay", { talerPayUri });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ export function preparePay(talerPayUri: string): Promise<walletTypes.PreparePayR
|
|||||||
export function acceptWithdrawal(
|
export function acceptWithdrawal(
|
||||||
talerWithdrawUri: string,
|
talerWithdrawUri: string,
|
||||||
selectedExchange: string,
|
selectedExchange: string,
|
||||||
): Promise<walletTypes.AcceptWithdrawalResponse> {
|
): Promise<AcceptWithdrawalResponse> {
|
||||||
return callBackend("accept-withdrawal", {
|
return callBackend("accept-withdrawal", {
|
||||||
talerWithdrawUri,
|
talerWithdrawUri,
|
||||||
selectedExchange,
|
selectedExchange,
|
||||||
@ -207,7 +207,7 @@ export function acceptWithdrawal(
|
|||||||
/**
|
/**
|
||||||
* Get diagnostics information
|
* Get diagnostics information
|
||||||
*/
|
*/
|
||||||
export function getDiagnostics(): Promise<walletTypes.WalletDiagnostics> {
|
export function getDiagnostics(): Promise<WalletDiagnostics> {
|
||||||
return callBackend("get-diagnostics", {});
|
return callBackend("get-diagnostics", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import * as wxApi from "./wxApi";
|
|||||||
import MessageSender = chrome.runtime.MessageSender;
|
import MessageSender = chrome.runtime.MessageSender;
|
||||||
import { extendedPermissions } from "./permissions";
|
import { extendedPermissions } from "./permissions";
|
||||||
|
|
||||||
import { Wallet, promiseUtil, db, walletTypes, taleruri, queryLib } from "taler-wallet-core";
|
import { Wallet, OpenedPromise, openPromise, deleteTalerDatabase, WALLET_DB_MINOR_VERSION, WalletDiagnostics, openTalerDatabase, Database, classifyTalerUri, TalerUriType } from "taler-wallet-core";
|
||||||
import { BrowserHttpLib } from "./browserHttpLib";
|
import { BrowserHttpLib } from "./browserHttpLib";
|
||||||
import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory";
|
import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory";
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ let currentDatabase: IDBDatabase | undefined;
|
|||||||
*/
|
*/
|
||||||
let outdatedDbVersion: number | undefined;
|
let outdatedDbVersion: number | undefined;
|
||||||
|
|
||||||
const walletInit: promiseUtil.OpenedPromise<void> = promiseUtil.openPromise<void>();
|
const walletInit: OpenedPromise<void> = openPromise<void>();
|
||||||
|
|
||||||
const notificationPorts: chrome.runtime.Port[] = [];
|
const notificationPorts: chrome.runtime.Port[] = [];
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ async function handleMessage(
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
case "reset-db": {
|
case "reset-db": {
|
||||||
db.deleteTalerDatabase(indexedDB);
|
deleteTalerDatabase(indexedDB);
|
||||||
setBadgeText({ text: "" });
|
setBadgeText({ text: "" });
|
||||||
console.log("reset done");
|
console.log("reset done");
|
||||||
if (!currentWallet) {
|
if (!currentWallet) {
|
||||||
@ -148,7 +148,7 @@ async function handleMessage(
|
|||||||
dbResetRequired = true;
|
dbResetRequired = true;
|
||||||
}
|
}
|
||||||
const resp: wxApi.UpgradeResponse = {
|
const resp: wxApi.UpgradeResponse = {
|
||||||
currentDbVersion: db.WALLET_DB_MINOR_VERSION.toString(),
|
currentDbVersion: WALLET_DB_MINOR_VERSION.toString(),
|
||||||
dbResetRequired,
|
dbResetRequired,
|
||||||
oldDbVersion: (outdatedDbVersion || "unknown").toString(),
|
oldDbVersion: (outdatedDbVersion || "unknown").toString(),
|
||||||
};
|
};
|
||||||
@ -217,7 +217,7 @@ async function handleMessage(
|
|||||||
errors.push(`Outdated DB version: ${outdatedDbVersion}`);
|
errors.push(`Outdated DB version: ${outdatedDbVersion}`);
|
||||||
dbOutdated = true;
|
dbOutdated = true;
|
||||||
}
|
}
|
||||||
const diagnostics: walletTypes.WalletDiagnostics = {
|
const diagnostics: WalletDiagnostics = {
|
||||||
walletManifestDisplayVersion:
|
walletManifestDisplayVersion:
|
||||||
manifestData.version_name || "(undefined)",
|
manifestData.version_name || "(undefined)",
|
||||||
walletManifestVersion: manifestData.version,
|
walletManifestVersion: manifestData.version,
|
||||||
@ -368,7 +368,7 @@ async function reinitWallet(): Promise<void> {
|
|||||||
currentDatabase = undefined;
|
currentDatabase = undefined;
|
||||||
setBadgeText({ text: "" });
|
setBadgeText({ text: "" });
|
||||||
try {
|
try {
|
||||||
currentDatabase = await db.openTalerDatabase(indexedDB, reinitWallet);
|
currentDatabase = await openTalerDatabase(indexedDB, reinitWallet);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("could not open database", e);
|
console.error("could not open database", e);
|
||||||
walletInit.reject(e);
|
walletInit.reject(e);
|
||||||
@ -377,7 +377,7 @@ async function reinitWallet(): Promise<void> {
|
|||||||
const http = new BrowserHttpLib();
|
const http = new BrowserHttpLib();
|
||||||
console.log("setting wallet");
|
console.log("setting wallet");
|
||||||
const wallet = new Wallet(
|
const wallet = new Wallet(
|
||||||
new queryLib.Database(currentDatabase),
|
new Database(currentDatabase),
|
||||||
http,
|
http,
|
||||||
new BrowserCryptoWorkerFactory(),
|
new BrowserCryptoWorkerFactory(),
|
||||||
);
|
);
|
||||||
@ -432,9 +432,9 @@ function headerListener(
|
|||||||
for (const header of details.responseHeaders || []) {
|
for (const header of details.responseHeaders || []) {
|
||||||
if (header.name.toLowerCase() === "taler") {
|
if (header.name.toLowerCase() === "taler") {
|
||||||
const talerUri = header.value || "";
|
const talerUri = header.value || "";
|
||||||
const uriType = taleruri.classifyTalerUri(talerUri);
|
const uriType = classifyTalerUri(talerUri);
|
||||||
switch (uriType) {
|
switch (uriType) {
|
||||||
case taleruri.TalerUriType.TalerWithdraw:
|
case TalerUriType.TalerWithdraw:
|
||||||
return makeSyncWalletRedirect(
|
return makeSyncWalletRedirect(
|
||||||
"withdraw.html",
|
"withdraw.html",
|
||||||
details.tabId,
|
details.tabId,
|
||||||
@ -443,7 +443,7 @@ function headerListener(
|
|||||||
talerWithdrawUri: talerUri,
|
talerWithdrawUri: talerUri,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
case taleruri.TalerUriType.TalerPay:
|
case TalerUriType.TalerPay:
|
||||||
return makeSyncWalletRedirect(
|
return makeSyncWalletRedirect(
|
||||||
"pay.html",
|
"pay.html",
|
||||||
details.tabId,
|
details.tabId,
|
||||||
@ -452,7 +452,7 @@ function headerListener(
|
|||||||
talerPayUri: talerUri,
|
talerPayUri: talerUri,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
case taleruri.TalerUriType.TalerTip:
|
case TalerUriType.TalerTip:
|
||||||
return makeSyncWalletRedirect(
|
return makeSyncWalletRedirect(
|
||||||
"tip.html",
|
"tip.html",
|
||||||
details.tabId,
|
details.tabId,
|
||||||
@ -461,7 +461,7 @@ function headerListener(
|
|||||||
talerTipUri: talerUri,
|
talerTipUri: talerUri,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
case taleruri.TalerUriType.TalerRefund:
|
case TalerUriType.TalerRefund:
|
||||||
return makeSyncWalletRedirect(
|
return makeSyncWalletRedirect(
|
||||||
"refund.html",
|
"refund.html",
|
||||||
details.tabId,
|
details.tabId,
|
||||||
@ -470,7 +470,7 @@ function headerListener(
|
|||||||
talerRefundUri: talerUri,
|
talerRefundUri: talerUri,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
case taleruri.TalerUriType.TalerNotifyReserve:
|
case TalerUriType.TalerNotifyReserve:
|
||||||
Promise.resolve().then(() => {
|
Promise.resolve().then(() => {
|
||||||
const w = currentWallet;
|
const w = currentWallet;
|
||||||
if (!w) {
|
if (!w) {
|
||||||
|
@ -10,6 +10,7 @@ importers:
|
|||||||
'@rollup/plugin-typescript': 5.0.2_d508d998c8e6588bf77175f7541372d0
|
'@rollup/plugin-typescript': 5.0.2_d508d998c8e6588bf77175f7541372d0
|
||||||
ava: 3.11.0
|
ava: 3.11.0
|
||||||
esm: 3.2.25
|
esm: 3.2.25
|
||||||
|
prettier: 2.0.5
|
||||||
rimraf: 3.0.2
|
rimraf: 3.0.2
|
||||||
rollup: 2.23.0
|
rollup: 2.23.0
|
||||||
typescript: 3.9.7
|
typescript: 3.9.7
|
||||||
@ -19,6 +20,7 @@ importers:
|
|||||||
'@types/node': ^14.0.27
|
'@types/node': ^14.0.27
|
||||||
ava: ^3.10.1
|
ava: ^3.10.1
|
||||||
esm: ^3.2.25
|
esm: ^3.2.25
|
||||||
|
prettier: ^2.0.5
|
||||||
rimraf: ^3.0.2
|
rimraf: ^3.0.2
|
||||||
rollup: ^2.23.0
|
rollup: ^2.23.0
|
||||||
tslib: ^2.0.0
|
tslib: ^2.0.0
|
||||||
@ -38,12 +40,14 @@ importers:
|
|||||||
tslib: 2.0.0
|
tslib: 2.0.0
|
||||||
devDependencies:
|
devDependencies:
|
||||||
esm: 3.2.25
|
esm: 3.2.25
|
||||||
|
prettier: 2.0.5
|
||||||
source-map-support: 0.5.19
|
source-map-support: 0.5.19
|
||||||
ts-node: 8.10.2_typescript@3.9.7
|
ts-node: 8.10.2_typescript@3.9.7
|
||||||
typescript: 3.9.7
|
typescript: 3.9.7
|
||||||
specifiers:
|
specifiers:
|
||||||
axios: ^0.19.2
|
axios: ^0.19.2
|
||||||
esm: ^3.2.25
|
esm: ^3.2.25
|
||||||
|
prettier: ^2.0.5
|
||||||
source-map-support: ^0.5.19
|
source-map-support: ^0.5.19
|
||||||
taler-wallet-core: 'workspace:*'
|
taler-wallet-core: 'workspace:*'
|
||||||
ts-node: ^8.10.2
|
ts-node: ^8.10.2
|
||||||
@ -59,6 +63,7 @@ importers:
|
|||||||
'@rollup/plugin-node-resolve': 8.4.0_rollup@2.23.0
|
'@rollup/plugin-node-resolve': 8.4.0_rollup@2.23.0
|
||||||
'@rollup/plugin-replace': 2.3.3_rollup@2.23.0
|
'@rollup/plugin-replace': 2.3.3_rollup@2.23.0
|
||||||
'@types/node': 14.0.27
|
'@types/node': 14.0.27
|
||||||
|
prettier: 2.0.5
|
||||||
rimraf: 3.0.2
|
rimraf: 3.0.2
|
||||||
rollup: 2.23.0
|
rollup: 2.23.0
|
||||||
rollup-plugin-sourcemaps: 0.6.2_1bb4f16ce5b550396581a296af208cfa
|
rollup-plugin-sourcemaps: 0.6.2_1bb4f16ce5b550396581a296af208cfa
|
||||||
@ -70,6 +75,7 @@ importers:
|
|||||||
'@rollup/plugin-node-resolve': ^8.4.0
|
'@rollup/plugin-node-resolve': ^8.4.0
|
||||||
'@rollup/plugin-replace': ^2.3.3
|
'@rollup/plugin-replace': ^2.3.3
|
||||||
'@types/node': ^14.0.27
|
'@types/node': ^14.0.27
|
||||||
|
prettier: ^2.0.5
|
||||||
rimraf: ^3.0.2
|
rimraf: ^3.0.2
|
||||||
rollup: ^2.23.0
|
rollup: ^2.23.0
|
||||||
rollup-plugin-sourcemaps: ^0.6.2
|
rollup-plugin-sourcemaps: ^0.6.2
|
||||||
@ -88,6 +94,7 @@ importers:
|
|||||||
'@rollup/plugin-node-resolve': 8.4.0_rollup@2.23.0
|
'@rollup/plugin-node-resolve': 8.4.0_rollup@2.23.0
|
||||||
'@rollup/plugin-replace': 2.3.3_rollup@2.23.0
|
'@rollup/plugin-replace': 2.3.3_rollup@2.23.0
|
||||||
'@types/node': 14.0.27
|
'@types/node': 14.0.27
|
||||||
|
prettier: 2.0.5
|
||||||
rimraf: 3.0.2
|
rimraf: 3.0.2
|
||||||
rollup: 2.23.0
|
rollup: 2.23.0
|
||||||
rollup-plugin-sourcemaps: 0.6.2_1bb4f16ce5b550396581a296af208cfa
|
rollup-plugin-sourcemaps: 0.6.2_1bb4f16ce5b550396581a296af208cfa
|
||||||
@ -100,6 +107,7 @@ importers:
|
|||||||
'@rollup/plugin-node-resolve': ^8.4.0
|
'@rollup/plugin-node-resolve': ^8.4.0
|
||||||
'@rollup/plugin-replace': ^2.3.3
|
'@rollup/plugin-replace': ^2.3.3
|
||||||
'@types/node': ^14.0.27
|
'@types/node': ^14.0.27
|
||||||
|
prettier: ^2.0.5
|
||||||
rimraf: ^3.0.2
|
rimraf: ^3.0.2
|
||||||
rollup: ^2.23.0
|
rollup: ^2.23.0
|
||||||
rollup-plugin-sourcemaps: ^0.6.2
|
rollup-plugin-sourcemaps: ^0.6.2
|
||||||
|
Loading…
Reference in New Issue
Block a user