diff --git a/monero_utils/MyMoneroCoreBridge.js b/monero_utils/MyMoneroCoreBridge.js index 9b3a25d..c4a2e13 100644 --- a/monero_utils/MyMoneroCoreBridge.js +++ b/monero_utils/MyMoneroCoreBridge.js @@ -459,6 +459,53 @@ class MyMoneroCoreBridge mask: ret.mask, }; } + decodeRctSimple(rv, sk, i) + { + const ecdhInfo = []; // should obvs be plural but just keeping exact names in-tact + for (var j = 0 ; j < rv.outPk.length ; j++) { + var this_ecdhInfo = rv.ecdhInfo[j]; + ecdhInfo.push({ + mask: this_ecdhInfo.mask, + amount: this_ecdhInfo.amount + }) + } + const outPk = []; + for (var j = 0 ; j < rv.outPk.length ; j++) { + var this_outPk_mask = null; + var this_outPk = rv.outPk[j]; + if (typeof this_outPk === 'string') { + this_outPk_mask = this_outPk; + } else if (typeof this_outPk === "object") { + this_outPk_mask = this_outPk.mask; + } + if (this_outPk_mask == null) { + return { err_msg: "Couldn't locate outPk mask value" } + } + outPk.push({ + mask: this_outPk_mask + }) + } + const args = + { + i: "" + i, // must be passed as string + sk: sk, + rv: { + type: "" + rv.type/*must be string*/, // e.g. 1, 3 ... corresponding to rct::RCTType* in rctSigs.cpp + ecdhInfo: ecdhInfo, + outPk: outPk + } + }; + const args_str = JSON.stringify(args); + const ret_string = this.Module.decodeRctSimple(args_str); + const ret = JSON.parse(ret_string); + if (typeof ret.err_msg !== 'undefined' && ret.err_msg) { + return { err_msg: ret.err_msg } + } + return { // calling these out so as to provide a stable ret val interface + amount: ret.amount, // string + mask: ret.mask, + }; + } estimated_tx_network_fee(fee_per_kb__string, priority, optl__fee_per_b_string) // this is until we switch the server over to fee per b { // TODO update this API to take object rather than arg list const args = diff --git a/src/index.cpp b/src/index.cpp index 58187ff..0211ca6 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -63,6 +63,7 @@ EMSCRIPTEN_BINDINGS(my_module) emscripten::function("derive_public_key", &serial_bridge::derive_public_key); emscripten::function("derive_subaddress_public_key", &serial_bridge::derive_subaddress_public_key); emscripten::function("decodeRct", &serial_bridge::decodeRct); + emscripten::function("decodeRctSimple", &serial_bridge::decodeRctSimple); // } extern "C" diff --git a/tests/MyMoneroCoreCpp.node.js b/tests/MyMoneroCoreCpp.node.js index ee84fe9..b4b5277 100644 --- a/tests/MyMoneroCoreCpp.node.js +++ b/tests/MyMoneroCoreCpp.node.js @@ -168,6 +168,13 @@ function tests(Module) console.timeEnd("decodeRct") console.log("decodeRct ret", ret_string) } + { + console.time("decodeRctSimple") + const args_str = '{"i":"0","sk":"a2259749f7aad692e000af4b7f383f4441ba4085bf70e518081365750db73b06","rv":{"type":"3","ecdhInfo":[{"mask":"dc9a2e8a66a336f67bb1a150f6de4522f09c451a10f450d7ee096baa75660a05","amount":"0c8f7514fd1d7c4f49795f33254739ce8e96275b17f50a03c877ed4b56896601"},{"mask":"f0d94c21aa892ad4e0d492f5fce4b8e99ff5e1ed687134b9419a2290e8701004","amount":"dbaeca613d37b53ff0a22a1fb6e09150baa6f4f5f6e145ef78a78cc19624a702"}],"outPk":[{"mask":"4dd9e7e2a2d8f31f065562923079399ec6c90d4b155d289208001994815bd01f"},{"mask":"c23cdb07e56bcb6a9ad087122b7079f2c34e217bcbddd16ca6031ab8828f7a84"}]}}' + const ret_string = Module.decodeRctSimple(args_str) + console.timeEnd("decodeRctSimple") + console.log("decodeRctSimple ret", ret_string) + } { console.time("send_funds") const task_id = "something unique";