aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-11-21 23:09:43 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-11-21 23:09:43 +0100
commitc6233094306cd264f8faa2041388dff01ff8cf01 (patch)
treef3ee839a4254c528058887c6517a76bec8919b15 /src/crypto
parente8f362ccfea683fe16ce68b956f068ffa0b001b1 (diff)
downloadwallet-core-c6233094306cd264f8faa2041388dff01ff8cf01.tar.xz
WIP: simplification and error handling
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/cryptoApi-test.ts23
-rw-r--r--src/crypto/cryptoImplementation.ts16
2 files changed, 22 insertions, 17 deletions
diff --git a/src/crypto/cryptoApi-test.ts b/src/crypto/cryptoApi-test.ts
index 39f46c5c3..d9d42081c 100644
--- a/src/crypto/cryptoApi-test.ts
+++ b/src/crypto/cryptoApi-test.ts
@@ -22,6 +22,7 @@ import {
DenominationRecord,
DenominationStatus,
ReserveRecord,
+ ReserveRecordStatus,
} from "../dbTypes";
import { CryptoApi } from "./cryptoApi";
@@ -86,18 +87,18 @@ test("precoin creation", async t => {
const crypto = new CryptoApi(new NodeCryptoWorkerFactory());
const { priv, pub } = await crypto.createEddsaKeypair();
const r: ReserveRecord = {
- created: 0,
- current_amount: null,
- exchange_base_url: "https://example.com/exchange",
+ created: { t_ms: 0 },
+ currentAmount: null,
+ exchangeBaseUrl: "https://example.com/exchange",
hasPayback: false,
- precoin_amount: { currency: "PUDOS", value: 0, fraction: 0 },
- requested_amount: { currency: "PUDOS", value: 0, fraction: 0 },
- reserve_priv: priv,
- reserve_pub: pub,
- timestamp_confirmed: 0,
- timestamp_depleted: 0,
- timestamp_reserve_info_posted: 0,
- exchangeWire: "payto://foo"
+ precoinAmount: { currency: "PUDOS", value: 0, fraction: 0 },
+ requestedAmount: { currency: "PUDOS", value: 0, fraction: 0 },
+ reservePriv: priv,
+ reservePub: pub,
+ timestampConfirmed: undefined,
+ timestampReserveInfoPosted: undefined,
+ exchangeWire: "payto://foo",
+ reserveStatus: ReserveRecordStatus.UNCONFIRMED,
};
const precoin = await crypto.createPreCoin(denomValid1, r);
diff --git a/src/crypto/cryptoImplementation.ts b/src/crypto/cryptoImplementation.ts
index d50d40027..7dd019c18 100644
--- a/src/crypto/cryptoImplementation.ts
+++ b/src/crypto/cryptoImplementation.ts
@@ -45,6 +45,7 @@ import * as native from "./emscInterface";
import { AmountJson } from "../amounts";
import * as Amounts from "../amounts";
import * as timer from "../timer";
+import { getRandomBytes, encodeCrock } from "./nativeCrypto";
export class CryptoImplementation {
static enableTracing: boolean = false;
@@ -60,9 +61,9 @@ export class CryptoImplementation {
reserve: ReserveRecord,
): PreCoinRecord {
const reservePriv = new native.EddsaPrivateKey(this.emsc);
- reservePriv.loadCrock(reserve.reserve_priv);
+ reservePriv.loadCrock(reserve.reservePriv);
const reservePub = new native.EddsaPublicKey(this.emsc);
- reservePub.loadCrock(reserve.reserve_pub);
+ reservePub.loadCrock(reserve.reservePub);
const denomPub = native.RsaPublicKey.fromCrock(this.emsc, denom.denomPub);
const coinPriv = native.EddsaPrivateKey.create(this.emsc);
const coinPub = coinPriv.getPublicKey();
@@ -103,7 +104,7 @@ export class CryptoImplementation {
coinValue: denom.value,
denomPub: denomPub.toCrock(),
denomPubHash: denomPubHash.toCrock(),
- exchangeBaseUrl: reserve.exchange_base_url,
+ exchangeBaseUrl: reserve.exchangeBaseUrl,
isFromTip: false,
reservePub: reservePub.toCrock(),
withdrawSig: sig.toCrock(),
@@ -199,14 +200,14 @@ export class CryptoImplementation {
isValidWireFee(type: string, wf: WireFee, masterPub: string): boolean {
const p = new native.MasterWireFeePS(this.emsc, {
closing_fee: new native.Amount(this.emsc, wf.closingFee).toNbo(),
- end_date: native.AbsoluteTimeNbo.fromStampSeconds(this.emsc, wf.endStamp),
+ end_date: native.AbsoluteTimeNbo.fromStampSeconds(this.emsc, (wf.endStamp.t_ms / 1000)),
h_wire_method: native.ByteArray.fromStringWithNull(
this.emsc,
type,
).hash(),
start_date: native.AbsoluteTimeNbo.fromStampSeconds(
this.emsc,
- wf.startStamp,
+ Math.floor(wf.startStamp.t_ms / 1000),
),
wire_fee: new native.Amount(this.emsc, wf.wireFee).toNbo(),
});
@@ -354,7 +355,7 @@ export class CryptoImplementation {
const newAmount = new native.Amount(this.emsc, cd.coin.currentAmount);
newAmount.sub(coinSpend);
cd.coin.currentAmount = newAmount.toJson();
- cd.coin.status = CoinStatus.PurchasePending;
+ cd.coin.status = CoinStatus.Dirty;
const d = new native.DepositRequestPS(this.emsc, {
amount_with_fee: coinSpend.toNbo(),
@@ -505,7 +506,10 @@ export class CryptoImplementation {
valueOutput = Amounts.add(valueOutput, denom.value).amount;
}
+ const refreshSessionId = encodeCrock(getRandomBytes(32));
+
const refreshSession: RefreshSessionRecord = {
+ refreshSessionId,
confirmSig,
exchangeBaseUrl,
finished: false,