quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

commit 1f14415a426e2ba94575eb7e34db3da941b9f62c
parent 113f3607604d532f83e7a532030e107a10eb30fb
Author: Florian Dold <florian@dold.me>
Date:   Mon, 14 Nov 2022 20:23:02 +0100

wip

Diffstat:
MMakefile | 4++--
Mqjsc.c | 1+
Mquickjs-libc.c | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Areadme-wallet.md | 3+++
4 files changed, 73 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -174,8 +174,8 @@ QJS_LIB_OBJS+=$(OBJDIR)/libbf.o QJS_OBJS+=$(OBJDIR)/qjscalc.o endif -HOST_LIBS=-lm -ldl -lpthread -lcurl -LIBS=-lm -lcurl +HOST_LIBS=-lm -ldl -lpthread -lcurl -lsodium +LIBS=-lm -lcurl -lsodium ifndef CONFIG_WIN32 LIBS+=-ldl -lpthread endif diff --git a/qjsc.c b/qjsc.c @@ -454,6 +454,7 @@ static int output_executable(const char *out_filename, const char *cfilename, *arg++ = "-lpthread"; // FIXME: Make conditional *arg++ = "-lcurl"; + *arg++ = "-lsodium"; *arg = NULL; if (verbose) { diff --git a/quickjs-libc.c b/quickjs-libc.c @@ -76,6 +76,7 @@ typedef sig_t sighandler_t; */ #include <curl/curl.h> +#include <sodium.h> typedef struct { struct list_head link; @@ -3997,6 +3998,70 @@ static JSValue js_encode_utf8(JSContext *ctx, JSValueConst this_val, return buf; } +static JSValue js_random_bytes(JSContext *ctx, JSValueConst this_val, + int argc, JSValueConst *argv) +{ + uint32_t nbytes; + JSValue buf; + if (0 != JS_ToUint32(ctx, &nbytes, argv[0])) { + return JS_EXCEPTION; + } + { + uint8_t randbuf[nbytes]; + randombytes_buf (randbuf, nbytes); + buf = JS_NewArrayBufferCopy(ctx, randbuf, nbytes); + } + return buf; +} + +static JSValue js_talercrypto_encode_crock(JSContext *ctx, JSValue this_val, + int argc, JSValueConst *argv) +{ +} + +static JSValue js_talercrypto_decode_crock(JSContext *ctx, JSValue this_val, + int argc, JSValueConst *argv) +{ +} + +/** + * eddsaKeyCreate: () => ArrayBuffer + */ +static JSValue js_talercrypto_eddsa_key_create(JSContext *ctx, JSValue this_val, + int argc, JSValueConst *argv) +{ +} + +static JSValue js_talercrypto_eddsa_key_get_public(JSContext *ctx, JSValue this_val, + int argc, JSValueConst *argv) +{ +} + +static JSValue js_talercrypto_eddsa_sign(JSContext *ctx, JSValue this_val, + int argc, JSValueConst *argv) +{ +} + +static JSValue js_talercrypto_eddsa_verify(JSContext *ctx, JSValue this_val, + int argc, JSValueConst *argv) +{ +} + +static JSValue js_talercrypto_kx_ecdhe_eddsa(JSContext *ctx, JSValue this_val, + int argc, JSValueConst *argv) +{ +} + +static JSValue js_talercrypto_kx_eddsa_ecdhe(JSContext *ctx, JSValue this_val, + int argc, JSValueConst *argv) +{ +} + +static JSValue js_talercrypto_hash(JSContext *ctx, JSValue this_val, + int argc, JSValueConst *argv) +{ +} + static JSValue js_decode_utf8(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { @@ -4026,6 +4091,8 @@ void js_std_add_helpers(JSContext *ctx, int argc, char **argv) JS_NewCFunction(ctx, js_encode_utf8, "_encodeUtf8", 1)); JS_SetPropertyStr(ctx, global_obj, "_decodeUtf8", JS_NewCFunction(ctx, js_decode_utf8, "_decodeUtf8", 1)); + JS_SetPropertyStr(ctx, global_obj, "_randomBytes", + JS_NewCFunction(ctx, js_random_bytes, "_randomBytes", 1)); /* same methods as the mozilla JS shell */ if (argc >= 0) { diff --git a/readme-wallet.md b/readme-wallet.md @@ -0,0 +1,3 @@ +Run test: + +./qjs -I prelude.js -I ~/repos/taler/wallet-core/packages/taler-wallet-embedded/dist/taler-wallet-core-qjs.mjs -I wallet-setup.js