summaryrefslogtreecommitdiff
path: root/src/wallet.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-02-13 09:53:34 +0100
committerFlorian Dold <florian.dold@gmail.com>2017-02-13 09:53:34 +0100
commit3a074443b764bf38b24e5ff4ef7e81d6ba351a55 (patch)
treeca446bd585b1938c8258cbee074d6a2bb66a5808 /src/wallet.ts
parente2738c58233038895611a67f127ee605112c5e11 (diff)
downloadwallet-core-3a074443b764bf38b24e5ff4ef7e81d6ba351a55.tar.gz
wallet-core-3a074443b764bf38b24e5ff4ef7e81d6ba351a55.tar.bz2
wallet-core-3a074443b764bf38b24e5ff4ef7e81d6ba351a55.zip
use EdDSA public key as nonce, store private key in DB
Diffstat (limited to 'src/wallet.ts')
-rw-r--r--src/wallet.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/wallet.ts b/src/wallet.ts
index 1c9de0170..67393edae 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -198,6 +198,11 @@ export interface Badge {
stopBusy(): void;
}
+export interface NonceRecord {
+ priv: string;
+ pub: string;
+}
+
function setTimeout(f: any, t: number) {
return chrome.extension.getBackgroundPage().setTimeout(f, t);
@@ -305,6 +310,12 @@ export namespace Stores {
pubKeyIndex = new Index<string,ExchangeRecord>(this, "pubKey", "masterPublicKey");
}
+ class NonceStore extends Store<NonceRecord> {
+ constructor() {
+ super("nonces", {keyPath: "pub"});
+ }
+ }
+
class CoinsStore extends Store<CoinRecord> {
constructor() {
super("coins", {keyPath: "coinPub"});
@@ -358,6 +369,7 @@ export namespace Stores {
}
export const exchanges: ExchangeStore = new ExchangeStore();
+ export const nonces: NonceStore = new NonceStore();
export const transactions: TransactionsStore = new TransactionsStore();
export const reserves: Store<ReserveRecord> = new Store<ReserveRecord>("reserves", {keyPath: "reserve_pub"});
export const coins: CoinsStore = new CoinsStore();
@@ -1708,6 +1720,19 @@ export class Wallet {
}
+ /**
+ * Generate a nonce in form of an EdDSA public key.
+ * Store the private key in our DB, so we can prove ownership.
+ */
+ async generateNonce(): Promise<string> {
+ let {priv, pub} = await this.cryptoApi.createEddsaKeypair();
+ await this.q()
+ .put(Stores.nonces, {priv, pub})
+ .finish();
+ return pub;
+ }
+
+
async paymentSucceeded(contractHash: string): Promise<any> {
const doPaymentSucceeded = async() => {
let t = await this.q().get<TransactionRecord>(Stores.transactions,