wallet-core: use crypto worker for eddsa signing
This commit is contained in:
parent
684c53e105
commit
dbfc599540
@ -38,7 +38,6 @@ import {
|
|||||||
* set up its own services.
|
* set up its own services.
|
||||||
*/
|
*/
|
||||||
export async function runBench1(configJson: any): Promise<void> {
|
export async function runBench1(configJson: any): Promise<void> {
|
||||||
|
|
||||||
const logger = new Logger("Bench1");
|
const logger = new Logger("Bench1");
|
||||||
|
|
||||||
// Validate the configuration file for this benchmark.
|
// Validate the configuration file for this benchmark.
|
||||||
@ -53,26 +52,29 @@ export async function runBench1(configJson: any): Promise<void> {
|
|||||||
|
|
||||||
const withdrawAmount = (numDeposits + 1) * 10;
|
const withdrawAmount = (numDeposits + 1) * 10;
|
||||||
|
|
||||||
logger.info(`Starting Benchmark iterations=${numIter} deposits=${numDeposits}`);
|
logger.info(
|
||||||
|
`Starting Benchmark iterations=${numIter} deposits=${numDeposits}`,
|
||||||
|
);
|
||||||
|
|
||||||
let wallet = {} as Wallet;
|
let wallet = {} as Wallet;
|
||||||
|
|
||||||
for (let i = 0; i < numIter; i++) {
|
for (let i = 0; i < numIter; i++) {
|
||||||
// Create a new wallet in each iteration
|
// Create a new wallet in each iteration
|
||||||
// otherwise the TPS go down
|
// otherwise the TPS go down
|
||||||
// my assumption is that the in-memory db file gets too large
|
// my assumption is that the in-memory db file gets too large
|
||||||
if (i % restartWallet == 0) {
|
if (i % restartWallet == 0) {
|
||||||
if (Object.keys(wallet).length !== 0) {
|
if (Object.keys(wallet).length !== 0) {
|
||||||
wallet.stop();
|
wallet.stop();
|
||||||
}
|
}
|
||||||
wallet = await getDefaultNodeWallet({
|
wallet = await getDefaultNodeWallet({
|
||||||
// No persistent DB storage.
|
// No persistent DB storage.
|
||||||
persistentStoragePath: undefined,
|
persistentStoragePath: undefined,
|
||||||
httpLib: myHttpLib,
|
httpLib: myHttpLib,
|
||||||
});
|
});
|
||||||
|
wallet.setInsecureTrustExchange();
|
||||||
await wallet.client.call(WalletApiOperation.InitWallet, {});
|
await wallet.client.call(WalletApiOperation.InitWallet, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.trace(`Starting withdrawal amount=${withdrawAmount}`);
|
logger.trace(`Starting withdrawal amount=${withdrawAmount}`);
|
||||||
let start = Date.now();
|
let start = Date.now();
|
||||||
|
|
||||||
@ -86,12 +88,13 @@ export async function runBench1(configJson: any): Promise<void> {
|
|||||||
stopWhenDone: true,
|
stopWhenDone: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info(`Finished withdrawal amount=${withdrawAmount} time=${Date.now() - start}`);
|
logger.info(
|
||||||
|
`Finished withdrawal amount=${withdrawAmount} time=${Date.now() - start}`,
|
||||||
|
);
|
||||||
|
|
||||||
for (let i = 0; i < numDeposits; i++) {
|
for (let i = 0; i < numDeposits; i++) {
|
||||||
|
|
||||||
logger.trace(`Starting deposit amount=10`);
|
logger.trace(`Starting deposit amount=10`);
|
||||||
start = Date.now()
|
start = Date.now();
|
||||||
|
|
||||||
await wallet.client.call(WalletApiOperation.CreateDepositGroup, {
|
await wallet.client.call(WalletApiOperation.CreateDepositGroup, {
|
||||||
amount: b1conf.currency + ":10",
|
amount: b1conf.currency + ":10",
|
||||||
|
@ -142,6 +142,21 @@ export interface PrimitiveWorker {
|
|||||||
sig: string;
|
sig: string;
|
||||||
pub: string;
|
pub: string;
|
||||||
}): Promise<{ valid: boolean }>;
|
}): Promise<{ valid: boolean }>;
|
||||||
|
|
||||||
|
eddsaSign(req: { msg: string; priv: string }): Promise<{ sig: string }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function myEddsaSign(
|
||||||
|
primitiveWorker: PrimitiveWorker | undefined,
|
||||||
|
req: { msg: string; priv: string },
|
||||||
|
): Promise<{ sig: string }> {
|
||||||
|
if (primitiveWorker) {
|
||||||
|
return primitiveWorker.eddsaSign(req);
|
||||||
|
}
|
||||||
|
const sig = eddsaSign(decodeCrock(req.msg), decodeCrock(req.priv));
|
||||||
|
return {
|
||||||
|
sig: encodeCrock(sig),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CryptoImplementation {
|
export class CryptoImplementation {
|
||||||
@ -153,13 +168,14 @@ export class CryptoImplementation {
|
|||||||
* Create a pre-coin of the given denomination to be withdrawn from then given
|
* Create a pre-coin of the given denomination to be withdrawn from then given
|
||||||
* reserve.
|
* reserve.
|
||||||
*/
|
*/
|
||||||
createPlanchet(req: PlanchetCreationRequest): PlanchetCreationResult {
|
async createPlanchet(
|
||||||
|
req: PlanchetCreationRequest,
|
||||||
|
): Promise<PlanchetCreationResult> {
|
||||||
if (
|
if (
|
||||||
req.denomPub.cipher === DenomKeyType.Rsa ||
|
req.denomPub.cipher === DenomKeyType.Rsa ||
|
||||||
req.denomPub.cipher === DenomKeyType.LegacyRsa
|
req.denomPub.cipher === DenomKeyType.LegacyRsa
|
||||||
) {
|
) {
|
||||||
const reservePub = decodeCrock(req.reservePub);
|
const reservePub = decodeCrock(req.reservePub);
|
||||||
const reservePriv = decodeCrock(req.reservePriv);
|
|
||||||
const denomPubRsa = decodeCrock(req.denomPub.rsa_public_key);
|
const denomPubRsa = decodeCrock(req.denomPub.rsa_public_key);
|
||||||
const derivedPlanchet = setupWithdrawPlanchet(
|
const derivedPlanchet = setupWithdrawPlanchet(
|
||||||
decodeCrock(req.secretSeed),
|
decodeCrock(req.secretSeed),
|
||||||
@ -180,7 +196,10 @@ export class CryptoImplementation {
|
|||||||
.put(evHash)
|
.put(evHash)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const sig = eddsaSign(withdrawRequest, reservePriv);
|
const sigResult = await myEddsaSign(this.primitiveWorker, {
|
||||||
|
msg: encodeCrock(withdrawRequest),
|
||||||
|
priv: req.reservePriv,
|
||||||
|
});
|
||||||
|
|
||||||
const planchet: PlanchetCreationResult = {
|
const planchet: PlanchetCreationResult = {
|
||||||
blindingKey: encodeCrock(derivedPlanchet.bks),
|
blindingKey: encodeCrock(derivedPlanchet.bks),
|
||||||
@ -194,7 +213,7 @@ export class CryptoImplementation {
|
|||||||
},
|
},
|
||||||
denomPubHash: encodeCrock(denomPubHash),
|
denomPubHash: encodeCrock(denomPubHash),
|
||||||
reservePub: encodeCrock(reservePub),
|
reservePub: encodeCrock(reservePub),
|
||||||
withdrawSig: encodeCrock(sig),
|
withdrawSig: sigResult.sig,
|
||||||
coinEvHash: encodeCrock(evHash),
|
coinEvHash: encodeCrock(evHash),
|
||||||
};
|
};
|
||||||
return planchet;
|
return planchet;
|
||||||
@ -427,7 +446,9 @@ export class CryptoImplementation {
|
|||||||
* Generate updated coins (to store in the database)
|
* Generate updated coins (to store in the database)
|
||||||
* and deposit permissions for each given coin.
|
* and deposit permissions for each given coin.
|
||||||
*/
|
*/
|
||||||
signDepositPermission(depositInfo: DepositInfo): CoinDepositPermission {
|
async signDepositPermission(
|
||||||
|
depositInfo: DepositInfo,
|
||||||
|
): Promise<CoinDepositPermission> {
|
||||||
// FIXME: put extensions here if used
|
// FIXME: put extensions here if used
|
||||||
const hExt = new Uint8Array(64);
|
const hExt = new Uint8Array(64);
|
||||||
let d: Uint8Array;
|
let d: Uint8Array;
|
||||||
@ -460,12 +481,15 @@ export class CryptoImplementation {
|
|||||||
} else {
|
} else {
|
||||||
throw Error("unsupported exchange protocol version");
|
throw Error("unsupported exchange protocol version");
|
||||||
}
|
}
|
||||||
const coinSig = eddsaSign(d, decodeCrock(depositInfo.coinPriv));
|
const coinSigRes = await myEddsaSign(this.primitiveWorker, {
|
||||||
|
msg: encodeCrock(d),
|
||||||
|
priv: depositInfo.coinPriv,
|
||||||
|
});
|
||||||
|
|
||||||
if (depositInfo.denomKeyType === DenomKeyType.Rsa) {
|
if (depositInfo.denomKeyType === DenomKeyType.Rsa) {
|
||||||
const s: CoinDepositPermission = {
|
const s: CoinDepositPermission = {
|
||||||
coin_pub: depositInfo.coinPub,
|
coin_pub: depositInfo.coinPub,
|
||||||
coin_sig: encodeCrock(coinSig),
|
coin_sig: coinSigRes.sig,
|
||||||
contribution: Amounts.stringify(depositInfo.spendAmount),
|
contribution: Amounts.stringify(depositInfo.spendAmount),
|
||||||
h_denom: depositInfo.denomPubHash,
|
h_denom: depositInfo.denomPubHash,
|
||||||
exchange_url: depositInfo.exchangeBaseUrl,
|
exchange_url: depositInfo.exchangeBaseUrl,
|
||||||
@ -478,7 +502,7 @@ export class CryptoImplementation {
|
|||||||
} else if (depositInfo.denomKeyType === DenomKeyType.LegacyRsa) {
|
} else if (depositInfo.denomKeyType === DenomKeyType.LegacyRsa) {
|
||||||
const s: CoinDepositPermission = {
|
const s: CoinDepositPermission = {
|
||||||
coin_pub: depositInfo.coinPub,
|
coin_pub: depositInfo.coinPub,
|
||||||
coin_sig: encodeCrock(coinSig),
|
coin_sig: coinSigRes.sig,
|
||||||
contribution: Amounts.stringify(depositInfo.spendAmount),
|
contribution: Amounts.stringify(depositInfo.spendAmount),
|
||||||
h_denom: depositInfo.denomPubHash,
|
h_denom: depositInfo.denomPubHash,
|
||||||
exchange_url: depositInfo.exchangeBaseUrl,
|
exchange_url: depositInfo.exchangeBaseUrl,
|
||||||
@ -611,10 +635,13 @@ export class CryptoImplementation {
|
|||||||
.put(decodeCrock(meltCoinPub))
|
.put(decodeCrock(meltCoinPub))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const confirmSig = eddsaSign(confirmData, decodeCrock(meltCoinPriv));
|
const confirmSigResp = await myEddsaSign(this.primitiveWorker, {
|
||||||
|
msg: encodeCrock(confirmData),
|
||||||
|
priv: meltCoinPriv,
|
||||||
|
});
|
||||||
|
|
||||||
const refreshSession: DerivedRefreshSession = {
|
const refreshSession: DerivedRefreshSession = {
|
||||||
confirmSig: encodeCrock(confirmSig),
|
confirmSig: confirmSigResp.sig,
|
||||||
hash: encodeCrock(sessionHash),
|
hash: encodeCrock(sessionHash),
|
||||||
meltCoinPub: meltCoinPub,
|
meltCoinPub: meltCoinPub,
|
||||||
planchetsForGammas: planchetsForGammas,
|
planchetsForGammas: planchetsForGammas,
|
||||||
@ -641,22 +668,24 @@ export class CryptoImplementation {
|
|||||||
return encodeCrock(hash(decodeCrock(encodedBytes)));
|
return encodeCrock(hash(decodeCrock(encodedBytes)));
|
||||||
}
|
}
|
||||||
|
|
||||||
signCoinLink(
|
async signCoinLink(
|
||||||
oldCoinPriv: string,
|
oldCoinPriv: string,
|
||||||
newDenomHash: string,
|
newDenomHash: string,
|
||||||
oldCoinPub: string,
|
oldCoinPub: string,
|
||||||
transferPub: string,
|
transferPub: string,
|
||||||
coinEv: string,
|
coinEv: string,
|
||||||
): string {
|
): Promise<string> {
|
||||||
const coinEvHash = hash(decodeCrock(coinEv));
|
const coinEvHash = hash(decodeCrock(coinEv));
|
||||||
const coinLink = buildSigPS(TalerSignaturePurpose.WALLET_COIN_LINK)
|
const coinLink = buildSigPS(TalerSignaturePurpose.WALLET_COIN_LINK)
|
||||||
.put(decodeCrock(newDenomHash))
|
.put(decodeCrock(newDenomHash))
|
||||||
.put(decodeCrock(transferPub))
|
.put(decodeCrock(transferPub))
|
||||||
.put(coinEvHash)
|
.put(coinEvHash)
|
||||||
.build();
|
.build();
|
||||||
const coinPriv = decodeCrock(oldCoinPriv);
|
const sig = await myEddsaSign(this.primitiveWorker, {
|
||||||
const sig = eddsaSign(coinLink, coinPriv);
|
msg: encodeCrock(coinLink),
|
||||||
return encodeCrock(sig);
|
priv: oldCoinPriv,
|
||||||
|
});
|
||||||
|
return sig.sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
benchmark(repetitions: number): BenchmarkResult {
|
benchmark(repetitions: number): BenchmarkResult {
|
||||||
|
@ -114,6 +114,16 @@ class MyPrimitiveWorker implements PrimitiveWorker {
|
|||||||
args: req,
|
args: req,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async eddsaSign(req: {
|
||||||
|
msg: string;
|
||||||
|
priv: string;
|
||||||
|
}): Promise<{ sig: string }> {
|
||||||
|
return this.queueRequest({
|
||||||
|
op: "eddsa_sign",
|
||||||
|
args: req,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -942,7 +942,7 @@ async function dispatchRequestInternal(
|
|||||||
}
|
}
|
||||||
const components = pt.targetPath.split("/");
|
const components = pt.targetPath.split("/");
|
||||||
const creditorAcct = components[components.length - 1];
|
const creditorAcct = components[components.length - 1];
|
||||||
logger.info(`making testbank transfer to '${creditorAcct}''`);
|
logger.info(`making testbank transfer to '${creditorAcct}'`);
|
||||||
const fbReq = await ws.http.postJson(
|
const fbReq = await ws.http.postJson(
|
||||||
new URL(`${creditorAcct}/admin/add-incoming`, req.bank).href,
|
new URL(`${creditorAcct}/admin/add-incoming`, req.bank).href,
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user