if checkmasterpub is specified, throw if master pub is not equal to the expected value
This commit is contained in:
parent
1e173e279f
commit
87fc6ebf48
@ -75,7 +75,13 @@ import {
|
|||||||
GetReadWriteAccess,
|
GetReadWriteAccess,
|
||||||
} from "../util/query.js";
|
} from "../util/query.js";
|
||||||
import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "../versions.js";
|
import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "../versions.js";
|
||||||
import { OperationAttemptResult, OperationAttemptResultType, runTaskWithErrorReporting, TaskIdentifiers, unwrapOperationHandlerResultOrThrow } from "./common.js";
|
import {
|
||||||
|
OperationAttemptResult,
|
||||||
|
OperationAttemptResultType,
|
||||||
|
runTaskWithErrorReporting,
|
||||||
|
TaskIdentifiers,
|
||||||
|
unwrapOperationHandlerResultOrThrow,
|
||||||
|
} from "./common.js";
|
||||||
|
|
||||||
const logger = new Logger("exchanges.ts");
|
const logger = new Logger("exchanges.ts");
|
||||||
|
|
||||||
@ -544,6 +550,7 @@ export async function updateExchangeFromUrl(
|
|||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
options: {
|
options: {
|
||||||
|
checkMasterPub?: string;
|
||||||
forceNow?: boolean;
|
forceNow?: boolean;
|
||||||
cancellationToken?: CancellationToken;
|
cancellationToken?: CancellationToken;
|
||||||
} = {},
|
} = {},
|
||||||
@ -570,6 +577,7 @@ export async function updateExchangeFromUrlHandler(
|
|||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
exchangeBaseUrl: string,
|
exchangeBaseUrl: string,
|
||||||
options: {
|
options: {
|
||||||
|
checkMasterPub?: string;
|
||||||
forceNow?: boolean;
|
forceNow?: boolean;
|
||||||
cancellationToken?: CancellationToken;
|
cancellationToken?: CancellationToken;
|
||||||
} = {},
|
} = {},
|
||||||
@ -605,6 +613,13 @@ export async function updateExchangeFromUrlHandler(
|
|||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
logger.info("using existing exchange info");
|
logger.info("using existing exchange info");
|
||||||
|
|
||||||
|
if (options.checkMasterPub) {
|
||||||
|
if (exchangeDetails.masterPublicKey !== options.checkMasterPub) {
|
||||||
|
throw Error(`master public key mismatch`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: OperationAttemptResultType.Finished,
|
type: OperationAttemptResultType.Finished,
|
||||||
result: { exchange, exchangeDetails },
|
result: { exchange, exchangeDetails },
|
||||||
@ -621,6 +636,12 @@ export async function updateExchangeFromUrlHandler(
|
|||||||
timeout,
|
timeout,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (options.checkMasterPub) {
|
||||||
|
if (keysInfo.masterPublicKey !== options.checkMasterPub) {
|
||||||
|
throw Error(`master public key mismatch`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("updating exchange /wire info");
|
logger.info("updating exchange /wire info");
|
||||||
const wireInfoDownload = await downloadExchangeWireInfo(
|
const wireInfoDownload = await downloadExchangeWireInfo(
|
||||||
exchangeBaseUrl,
|
exchangeBaseUrl,
|
||||||
|
@ -243,7 +243,12 @@ import {
|
|||||||
testPay,
|
testPay,
|
||||||
withdrawTestBalance,
|
withdrawTestBalance,
|
||||||
} from "./operations/testing.js";
|
} from "./operations/testing.js";
|
||||||
import { acceptTip, computeTipTransactionStatus, prepareTip, processTip } from "./operations/tip.js";
|
import {
|
||||||
|
acceptTip,
|
||||||
|
computeTipTransactionStatus,
|
||||||
|
prepareTip,
|
||||||
|
processTip,
|
||||||
|
} from "./operations/tip.js";
|
||||||
import {
|
import {
|
||||||
abortTransaction,
|
abortTransaction,
|
||||||
deleteTransaction,
|
deleteTransaction,
|
||||||
@ -281,7 +286,10 @@ import {
|
|||||||
GetReadOnlyAccess,
|
GetReadOnlyAccess,
|
||||||
GetReadWriteAccess,
|
GetReadWriteAccess,
|
||||||
} from "./util/query.js";
|
} from "./util/query.js";
|
||||||
import { OperationAttemptResult, TaskIdentifiers } from "./operations/common.js";
|
import {
|
||||||
|
OperationAttemptResult,
|
||||||
|
TaskIdentifiers,
|
||||||
|
} from "./operations/common.js";
|
||||||
import { TimerAPI, TimerGroup } from "./util/timer.js";
|
import { TimerAPI, TimerGroup } from "./util/timer.js";
|
||||||
import {
|
import {
|
||||||
WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
|
WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
|
||||||
@ -1068,6 +1076,7 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
|
|||||||
case WalletApiOperation.AddExchange: {
|
case WalletApiOperation.AddExchange: {
|
||||||
const req = codecForAddExchangeRequest().decode(payload);
|
const req = codecForAddExchangeRequest().decode(payload);
|
||||||
await updateExchangeFromUrl(ws, req.exchangeBaseUrl, {
|
await updateExchangeFromUrl(ws, req.exchangeBaseUrl, {
|
||||||
|
checkMasterPub: req.masterPub,
|
||||||
forceNow: req.forceUpdate,
|
forceNow: req.forceUpdate,
|
||||||
});
|
});
|
||||||
return {};
|
return {};
|
||||||
@ -1783,36 +1792,42 @@ class InternalWalletStateImpl implements InternalWalletState {
|
|||||||
return computePayMerchantTransactionState(rec);
|
return computePayMerchantTransactionState(rec);
|
||||||
}
|
}
|
||||||
case TransactionType.Refund: {
|
case TransactionType.Refund: {
|
||||||
const rec = await tx.refundGroups.get(
|
const rec = await tx.refundGroups.get(parsedTxId.refundGroupId);
|
||||||
parsedTxId.refundGroupId,
|
|
||||||
);
|
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return computeRefundTransactionState(rec);
|
return computeRefundTransactionState(rec);
|
||||||
}
|
}
|
||||||
case TransactionType.PeerPullCredit:
|
case TransactionType.PeerPullCredit:
|
||||||
const rec = await tx.peerPullPaymentInitiations.get(parsedTxId.pursePub);
|
const rec = await tx.peerPullPaymentInitiations.get(
|
||||||
|
parsedTxId.pursePub,
|
||||||
|
);
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return computePeerPullCreditTransactionState(rec);
|
return computePeerPullCreditTransactionState(rec);
|
||||||
case TransactionType.PeerPullDebit: {
|
case TransactionType.PeerPullDebit: {
|
||||||
const rec = await tx.peerPullPaymentIncoming.get(parsedTxId.peerPullPaymentIncomingId);
|
const rec = await tx.peerPullPaymentIncoming.get(
|
||||||
|
parsedTxId.peerPullPaymentIncomingId,
|
||||||
|
);
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return computePeerPullDebitTransactionState(rec);
|
return computePeerPullDebitTransactionState(rec);
|
||||||
}
|
}
|
||||||
case TransactionType.PeerPushCredit: {
|
case TransactionType.PeerPushCredit: {
|
||||||
const rec = await tx.peerPushPaymentIncoming.get(parsedTxId.peerPushPaymentIncomingId);
|
const rec = await tx.peerPushPaymentIncoming.get(
|
||||||
|
parsedTxId.peerPushPaymentIncomingId,
|
||||||
|
);
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return computePeerPushCreditTransactionState(rec);
|
return computePeerPushCreditTransactionState(rec);
|
||||||
}
|
}
|
||||||
case TransactionType.PeerPushDebit: {
|
case TransactionType.PeerPushDebit: {
|
||||||
const rec = await tx.peerPushPaymentInitiations.get(parsedTxId.pursePub);
|
const rec = await tx.peerPushPaymentInitiations.get(
|
||||||
|
parsedTxId.pursePub,
|
||||||
|
);
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -1823,7 +1838,7 @@ class InternalWalletStateImpl implements InternalWalletState {
|
|||||||
if (!rec) {
|
if (!rec) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return computeRefreshTransactionState(rec)
|
return computeRefreshTransactionState(rec);
|
||||||
}
|
}
|
||||||
case TransactionType.Tip: {
|
case TransactionType.Tip: {
|
||||||
const rec = await tx.tips.get(parsedTxId.walletTipId);
|
const rec = await tx.tips.get(parsedTxId.walletTipId);
|
||||||
|
Loading…
Reference in New Issue
Block a user