aboutsummaryrefslogtreecommitdiff
path: root/extension/background
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2015-12-16 10:45:16 +0100
committerFlorian Dold <florian.dold@gmail.com>2015-12-16 10:45:16 +0100
commit276f9108ab1dac3b7fc6670b1061f8cf7809785a (patch)
treef8d7fe273c6fc710da7317833d9961912a17fe55 /extension/background
parent1b295d0f1aa18ece305fdc96cc356bfc2e794934 (diff)
missing files
Diffstat (limited to 'extension/background')
-rw-r--r--extension/background/emscriptif.js8
-rw-r--r--extension/background/emscriptif.ts22
-rw-r--r--extension/background/wallet.js15
-rw-r--r--extension/background/wallet.ts14
4 files changed, 45 insertions, 14 deletions
diff --git a/extension/background/emscriptif.js b/extension/background/emscriptif.js
index 3c5dabe7c..26c0c631d 100644
--- a/extension/background/emscriptif.js
+++ b/extension/background/emscriptif.js
@@ -360,8 +360,11 @@ class EccSignaturePurpose extends PackedArenaObject {
size() { return this.payloadSize + 8; }
}
class SignatureStruct {
- constructor() {
+ constructor(x) {
this.members = {};
+ for (let k in x) {
+ this.set(k[0], k[1]);
+ }
}
toPurpose(a) {
let totalSize = 0;
@@ -401,6 +404,9 @@ class SignatureStruct {
}
}
class WithdrawRequestPS extends SignatureStruct {
+ constructor(w) {
+ super(w);
+ }
purpose() { return SignaturePurpose.RESERVE_WITHDRAW; }
fieldTypes() {
return [
diff --git a/extension/background/emscriptif.ts b/extension/background/emscriptif.ts
index 82f78e34f..618f92a41 100644
--- a/extension/background/emscriptif.ts
+++ b/extension/background/emscriptif.ts
@@ -516,6 +516,13 @@ abstract class SignatureStruct {
abstract fieldTypes(): Array<any>;
abstract purpose(): SignaturePurpose;
private members: any = {};
+
+ constructor(x: any) {
+ for (let k in x) {
+ this.set(k[0], k[1]);
+ }
+ }
+
toPurpose(a?: Arena): EccSignaturePurpose {
let totalSize = 0;
for (let f of this.fieldTypes()) {
@@ -541,7 +548,7 @@ abstract class SignatureStruct {
return x;
}
- set(name: string, value: PackedArenaObject) {
+ protected set(name: string, value: PackedArenaObject) {
let typemap: any = {}
for (let f of this.fieldTypes()) {
typemap[f[0]] = f[1];
@@ -557,7 +564,20 @@ abstract class SignatureStruct {
}
+// It's redundant, but more type safe.
+interface WithdrawRequestPS_Args {
+ reserve_pub: EddsaPublicKey;
+ amount_with_fee: AmountNbo;
+ withdraw_fee: AmountNbo;
+ h_denomination_pub: HashCode;
+ h_coin_envelope: HashCode;
+}
+
+
class WithdrawRequestPS extends SignatureStruct {
+ constructor(w: WithdrawRequestPS_Args) {
+ super(w);
+ }
purpose() { return SignaturePurpose.RESERVE_WITHDRAW; }
fieldTypes() {
return [
diff --git a/extension/background/wallet.js b/extension/background/wallet.js
index e5740e3b8..36d3e8a85 100644
--- a/extension/background/wallet.js
+++ b/extension/background/wallet.js
@@ -136,12 +136,13 @@ function withdrawPrepare(db, denom, reserve) {
amountWithFee.add(new Amount(denom.fee_withdraw));
let withdrawFee = new Amount(denom.fee_withdraw);
// Signature
- let withdrawRequest = new WithdrawRequestPS();
- withdrawRequest.set("reserve_pub", reservePub);
- withdrawRequest.set("amount_with_fee", amountWithFee.toNbo());
- withdrawRequest.set("withdraw_fee", withdrawFee.toNbo());
- withdrawRequest.set("h_denomination_pub", denomPub.encode().hash());
- withdrawRequest.set("h_coin_envelope", ev.hash());
+ let withdrawRequest = new WithdrawRequestPS({
+ reserve_pub: reservePub,
+ amount_with_fee: amountWithFee.toNbo(),
+ withdraw_fee: withdrawFee.toNbo(),
+ h_denomination_pub: denomPub.encode().hash(),
+ h_coin_envelope: ev.hash()
+ });
console.log("about to sign");
var sig = eddsaSign(withdrawRequest.toPurpose(), reservePriv);
console.log("signed");
@@ -392,12 +393,14 @@ function dumpDb(db, detail, sendResponse) {
}
return true;
}
+// Just for debugging.
function reset(db, detail, sendResponse) {
let tx = db.transaction(db.objectStoreNames, 'readwrite');
for (let i = 0; i < db.objectStoreNames.length; i++) {
tx.objectStore(db.objectStoreNames[i]).clear();
}
indexedDB.deleteDatabase(DB_NAME);
+ chrome.browserAction.setBadgeText({ text: "" });
console.log("reset done");
return false;
}
diff --git a/extension/background/wallet.ts b/extension/background/wallet.ts
index 96a2ab220..dd2ceca7d 100644
--- a/extension/background/wallet.ts
+++ b/extension/background/wallet.ts
@@ -185,12 +185,14 @@ function withdrawPrepare(db: IDBDatabase, denom, reserve): Promise<PreCoin> {
let withdrawFee = new Amount(denom.fee_withdraw);
// Signature
- let withdrawRequest = new WithdrawRequestPS();
- withdrawRequest.set("reserve_pub", reservePub);
- withdrawRequest.set("amount_with_fee", amountWithFee.toNbo());
- withdrawRequest.set("withdraw_fee", withdrawFee.toNbo());
- withdrawRequest.set("h_denomination_pub", denomPub.encode().hash());
- withdrawRequest.set("h_coin_envelope", ev.hash());
+ let withdrawRequest = new WithdrawRequestPS({
+ reserve_pub: reservePub,
+ amount_with_fee: amountWithFee.toNbo(),
+ withdraw_fee: withdrawFee.toNbo(),
+ h_denomination_pub: denomPub.encode().hash(),
+ h_coin_envelope: ev.hash()
+ });
+
console.log("about to sign");
var sig = eddsaSign(withdrawRequest.toPurpose(), reservePriv);
console.log("signed");