From 9da386ed63a3fcc8b9b3b9d189e4f7168c46a579 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Dec 2015 05:36:06 +0100 Subject: [PATCH] Skeletons for wrappers. --- extension/background/emscriptif.js | 23 ++++++++++++++------- extension/background/emscriptif.ts | 33 +++++++++++++++++++----------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/extension/background/emscriptif.js b/extension/background/emscriptif.js index 7188012f3..b72d22bf8 100644 --- a/extension/background/emscriptif.js +++ b/extension/background/emscriptif.js @@ -32,6 +32,7 @@ var emscAlloc = { get_amount: getEmsc('TALER_WRALL_get_amount', 'number', ['number', 'number', 'number', 'string']), eddsa_key_create: getEmsc('GNUNET_CRYPTO_eddsa_key_create', 'number'), eddsa_public_key_from_private: getEmsc('TALER_WRALL_eddsa_public_key_from_private', 'number', ['number']), + data_to_string_alloc: getEmsc('GNUNET_STRINGS_data_to_string_alloc', 'number', ['number', 'number']), malloc: (size) => Module._malloc(size), }; class ArenaObject { @@ -119,12 +120,23 @@ class Amount extends ArenaObject { emsc.amount_normalize(this.nativePtr); } } -class EddsaPrivateKey extends ArenaObject { +class SizedArenaObject extends ArenaObject { + encode() { + var d = emscAlloc.data_to_string_alloc(this.nativePtr, this.size); + var s = Module.Pointer_stringify(d); + emsc.free(d); + return s; + } +} +class EddsaPrivateKey extends SizedArenaObject { static create(a) { let k = new EddsaPrivateKey(a); k.nativePtr = emscAlloc.eddsa_key_create(); return k; } + get size() { + return 32; + } destroy() { // TODO } @@ -133,16 +145,13 @@ class EddsaPrivateKey extends ArenaObject { pk.nativePtr = emscAlloc.eddsa_public_key_from_private(this.nativePtr); return pk; } - encode() { - throw "not implemented"; - } } -class EddsaPublicKey extends ArenaObject { +class EddsaPublicKey extends SizedArenaObject { destroy() { // TODO } - encode() { - throw "not implemented"; + get size() { + return 32; } } class RsaBlindingKey extends ArenaObject { diff --git a/extension/background/emscriptif.ts b/extension/background/emscriptif.ts index 1b339c0c0..b99b471f1 100644 --- a/extension/background/emscriptif.ts +++ b/extension/background/emscriptif.ts @@ -58,6 +58,9 @@ var emscAlloc = { eddsa_public_key_from_private: getEmsc('TALER_WRALL_eddsa_public_key_from_private', 'number', ['number']), + data_to_string_alloc: getEmsc('GNUNET_STRINGS_data_to_string_alloc', + 'number', + ['number', 'number']), malloc: (size : number) => Module._malloc(size), }; @@ -168,36 +171,42 @@ class Amount extends ArenaObject { } -class EddsaPrivateKey extends ArenaObject { +abstract class PackedArenaObject extends ArenaObject { + size: number; + + encode(): string { + var d = emscAlloc.data_to_string_alloc(this.nativePtr, this.size); + var s = Module.Pointer_stringify(d); + emsc.free(d); + return s; + } +} + + +class EddsaPrivateKey extends PackedArenaObject { static create(a?: Arena): EddsaPrivateKey { let k = new EddsaPrivateKey(a); k.nativePtr = emscAlloc.eddsa_key_create(); return k; } - destroy() { - // TODO - } + get size() { return 32; } getPublicKey(): EddsaPublicKey { let pk = new EddsaPublicKey(this.arena); pk.nativePtr = emscAlloc.eddsa_public_key_from_private(this.nativePtr); return pk; } - - encode(): string { - throw "not implemented"; - } } -class EddsaPublicKey extends ArenaObject { +class EddsaPublicKey extends PackedArenaObject { destroy() { // TODO } - encode(): string { - throw "not implemented"; + get size() { + return 32; } } @@ -216,7 +225,7 @@ class HashCode extends ArenaObject { } -class ByteArray extends ArenaObject { +class ByteArray extends PackedArenaObject { destroy() { // TODO }