show badge

This commit is contained in:
Florian Dold 2015-12-16 05:53:55 +01:00
parent ccce0f9749
commit 3315470598
6 changed files with 138738 additions and 66419 deletions

View File

@ -56,6 +56,7 @@ var emscAlloc = {
rsa_public_key_decode: getEmsc('GNUNET_CRYPTO_rsa_public_key_decode', 'number', ['number', 'number']),
rsa_signature_decode: getEmsc('GNUNET_CRYPTO_rsa_signature_decode', 'number', ['number', 'number']),
rsa_public_key_encode: getEmsc('GNUNET_CRYPTO_rsa_public_key_encode', 'number', ['number', 'number']),
rsa_unblind: getEmsc('GNUNET_CRYPTO_rsa_unblind', 'number', ['number', 'number', 'number']),
malloc: (size) => Module._malloc(size),
};
var SignaturePurpose;
@ -71,8 +72,12 @@ var RandomQuality;
class ArenaObject {
constructor(arena) {
this.nativePtr = null;
if (!arena)
arena = defaultArena;
if (!arena) {
if (arenaStack.length == 0) {
throw Error("No arena available");
}
arena = arenaStack[arenaStack.length - 1];
}
arena.put(this);
this.arena = arena;
}
@ -110,7 +115,7 @@ class ArenaObject {
return this.getNative();
}
}
class Arena {
class DefaultArena {
constructor() {
this.heap = [];
}
@ -118,11 +123,32 @@ class Arena {
this.heap.push(obj);
}
destroy() {
// XXX: todo
for (let obj of this.heap) {
obj.destroy();
}
this.heap = [];
}
}
// Arena to track allocations that do not use an explicit arena.
var defaultArena = new Arena();
/**
* Arena that destroys all its objects once control has returned to the message
* loop and a small interval has passed.
*/
class SyncArena extends DefaultArena {
constructor() {
super();
let me = this;
this.timer = new Worker('background/timerThread.js');
this.timer.onmessage = (e) => {
this.destroy();
};
//this.timer.postMessage({interval: 50});
}
destroy() {
super.destroy();
}
}
let arenaStack = [];
arenaStack.push(new SyncArena());
class Amount extends ArenaObject {
constructor(args, arena) {
super(arena);
@ -450,6 +476,8 @@ function eddsaSign(purpose, priv, a) {
}
return sig;
}
function rsaUnblind(sig, bk, pk) {
throw Error("Not implemented");
function rsaUnblind(sig, bk, pk, a) {
let x = new RsaSignature(a);
x.nativePtr = emscAlloc.rsa_unblind(sig.nativePtr, bk.nativePtr, pk.nativePtr);
return x;
}

View File

@ -132,6 +132,9 @@ var emscAlloc = {
rsa_public_key_encode: getEmsc('GNUNET_CRYPTO_rsa_public_key_encode',
'number',
['number', 'number']),
rsa_unblind: getEmsc('GNUNET_CRYPTO_rsa_unblind',
'number',
['number', 'number', 'number']),
malloc: (size: number) => Module._malloc(size),
};
@ -154,8 +157,12 @@ abstract class ArenaObject {
constructor(arena?: Arena) {
this.nativePtr = null;
if (!arena)
arena = defaultArena;
if (!arena) {
if (arenaStack.length == 0) {
throw Error("No arena available")
}
arena = arenaStack[arenaStack.length - 1];
}
arena.put(this);
this.arena = arena;
}
@ -201,9 +208,14 @@ abstract class ArenaObject {
}
class Arena {
interface Arena {
put(obj: ArenaObject): void;
destroy(): void;
}
class DefaultArena implements Arena {
heap: Array<ArenaObject>;
constructor () {
constructor() {
this.heap = [];
}
@ -212,13 +224,38 @@ class Arena {
}
destroy() {
// XXX: todo
for (let obj of this.heap) {
obj.destroy();
}
this.heap = []
}
}
// Arena to track allocations that do not use an explicit arena.
var defaultArena = new Arena();
/**
* Arena that destroys all its objects once control has returned to the message
* loop and a small interval has passed.
*/
class SyncArena extends DefaultArena {
timer: Worker;
constructor() {
super();
let me = this;
this.timer = new Worker('background/timerThread.js');
this.timer.onmessage = (e) => {
this.destroy();
};
//this.timer.postMessage({interval: 50});
}
destroy() {
super.destroy();
}
}
let arenaStack: Arena[] = [];
arenaStack.push(new SyncArena());
class Amount extends ArenaObject {
@ -624,8 +661,11 @@ function eddsaSign(purpose: EccSignaturePurpose,
function rsaUnblind(sig: RsaSignature,
bk: RsaBlindingKey,
pk: RsaPublicKey): RsaSignature {
throw Error("Not implemented");
pk: RsaPublicKey,
a?: Arena): RsaSignature {
let x = new RsaSignature(a);
x.nativePtr = emscAlloc.rsa_unblind(sig.nativePtr, bk.nativePtr, pk.nativePtr);
return x;
}

File diff suppressed because one or more lines are too long

View File

@ -24,7 +24,7 @@ function openTalerDb() {
db.createObjectStore("mints", { keyPath: "baseUrl" });
db.createObjectStore("reserves", { keyPath: "reserve_pub" });
db.createObjectStore("denoms", { keyPath: "denom_pub" });
db.createObjectStore("coins", { keyPath: "coin_pub" });
db.createObjectStore("coins", { keyPath: "coinPub" });
db.createObjectStore("withdrawals", { keyPath: "id", autoIncrement: true });
db.createObjectStore("transactions", { keyPath: "id", autoIncrement: true });
db.createObjectStore("precoins", { keyPath: "coinPub", autoIncrement: true });
@ -215,7 +215,33 @@ function withdrawExecute(db, pc) {
});
}));
}
function updateBadge(db) {
let tx = db.transaction(['coins'], 'readwrite');
let req = tx.objectStore('coins').openCursor();
let n = 0;
req.onsuccess = (e) => {
let cursor = req.result;
if (cursor) {
n++;
cursor.continue();
}
else {
console.log("badge");
chrome.browserAction.setBadgeText({ text: "" + n });
chrome.browserAction.setBadgeBackgroundColor({ color: "#0F0" });
}
};
}
function storeCoin(db, coin) {
let tx = db.transaction(['coins', 'precoins'], 'readwrite');
tx.objectStore('precoins').delete(coin.coinPub);
tx.objectStore('coins').add(coin);
return new Promise((resolve, reject) => {
tx.oncomplete = (e) => {
resolve();
updateBadge(db);
};
});
}
function withdraw(db, denom, reserve) {
return withdrawPrepare(db, denom, reserve)
@ -358,6 +384,7 @@ function dumpDb(db, detail, sendResponse) {
}
return true;
}
chrome.browserAction.setBadgeText({ text: "" });
openTalerDb().then((db) => {
console.log("db loaded");
chrome.runtime.onMessage.addListener(function (req, sender, onresponse) {

View File

@ -27,7 +27,7 @@ function openTalerDb(): Promise<IDBDatabase> {
db.createObjectStore("mints", { keyPath: "baseUrl" });
db.createObjectStore("reserves", { keyPath: "reserve_pub"});
db.createObjectStore("denoms", { keyPath: "denom_pub" });
db.createObjectStore("coins", { keyPath: "coin_pub" });
db.createObjectStore("coins", { keyPath: "coinPub" });
db.createObjectStore("withdrawals", { keyPath: "id", autoIncrement: true });
db.createObjectStore("transactions", { keyPath: "id", autoIncrement: true });
db.createObjectStore("precoins", { keyPath: "coinPub", autoIncrement: true });
@ -268,7 +268,34 @@ function withdrawExecute(db, pc: PreCoin): Promise<Coin> {
}
function storeCoin(db, coin) {
function updateBadge(db) {
let tx = db.transaction(['coins'], 'readwrite');
let req = tx.objectStore('coins').openCursor();
let n = 0;
req.onsuccess = (e) => {
let cursor = req.result;
if (cursor) {
n++;
cursor.continue();
} else {
console.log("badge");
chrome.browserAction.setBadgeText({text: ""+n});
chrome.browserAction.setBadgeBackgroundColor({color: "#0F0"});
}
}
}
function storeCoin(db, coin: Coin) {
let tx = db.transaction(['coins', 'precoins'], 'readwrite');
tx.objectStore('precoins').delete(coin.coinPub);
tx.objectStore('coins').add(coin);
return new Promise<void>((resolve, reject) => {
tx.oncomplete = (e) => {
resolve();
updateBadge(db);
}
});
}
@ -424,6 +451,8 @@ function dumpDb(db, detail, sendResponse) {
}
chrome.browserAction.setBadgeText({text: ""});
openTalerDb().then((db) => {
console.log("db loaded");
chrome.runtime.onMessage.addListener(

View File

@ -79,12 +79,12 @@ function update_currency (currency, amount)
}
document.addEventListener('DOMContentLoaded', (e) => {
chrome.runtime.sendMessage({type: "WALLET_GET"}, function(wallet) {
for (let currency in wallet) {
let amount = amount_format(wallet[currency]);
add_currency(currency, amount);
}
});
//chrome.runtime.sendMessage({type: "WALLET_GET"}, function(wallet) {
// for (let currency in wallet) {
// let amount = amount_format(wallet[currency]);
// add_currency(currency, amount);
// }
//});
// FIXME: remove
add_currency('EUR', 42);