From b9f3d4f44eb3a09e6c3240fcca1b16dfe1ccda53 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Sat, 28 Sep 2024 17:34:59 +0200 Subject: [PATCH 1/2] Fix types --- src/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index 7a893a1..c1d41d3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -107,7 +107,7 @@ export type Subaccount = { bip44_discovered: false hidden: false name: "" - pointer: 0 + pointer: number receiving_id: "" required_ca: 0 type: SubaccountType @@ -119,7 +119,7 @@ export type ReceiveAddressType = { blinding_key: string is_confidential: boolean is_internal: boolean - pointer: boolean + pointer: number scriptpubkey: string subaccount: number unconfidential_address: string From 841fe029119765f542586c794ae858271be5ebb1 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Sat, 28 Sep 2024 18:17:02 +0200 Subject: [PATCH 2/2] Add registerNetwork --- cpp/GdkHostObject.cpp | 309 ++++++++++++++++++++------------------ src/GdkNativeInterface.ts | 1 + src/createGdk.ts | 4 +- src/types.ts | 34 +++++ 4 files changed, 205 insertions(+), 143 deletions(-) diff --git a/cpp/GdkHostObject.cpp b/cpp/GdkHostObject.cpp index 20a2b85..fd8597a 100644 --- a/cpp/GdkHostObject.cpp +++ b/cpp/GdkHostObject.cpp @@ -13,7 +13,7 @@ using json = nlohmann::json; GdkHostObject::GdkHostObject(std::string dirUrl, jsi::Runtime &runtime, std::shared_ptr jsCallInvoker): invoker(jsCallInvoker), rt(runtime) { sessionDirectoryUrl = dirUrl; pool = std::make_shared(); - + } GdkHostObject::~GdkHostObject() { @@ -50,6 +50,7 @@ std::vector GdkHostObject::getPropertyNames(jsi::Runtime& rt) { result.push_back(jsi::PropNameID::forUtf8(rt, std::string("broadcastTransaction"))); result.push_back(jsi::PropNameID::forUtf8(rt, std::string("getNetworks"))); result.push_back(jsi::PropNameID::forUtf8(rt, std::string("signPsbt"))); + result.push_back(jsi::PropNameID::forUtf8(rt, std::string("registerNetwork"))); return result; } @@ -119,7 +120,7 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop return jsi::Value::undefined(); }); } - + if (propName == "getNetworks") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -130,7 +131,7 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop size_t count) -> jsi::Value { utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_json *networks; @@ -139,7 +140,7 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { jsi::Value res = utils::GAJsonToObject(rt, networks); - + GA_destroy_json(networks); p->resolve(res); }); @@ -147,13 +148,13 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } - + }; - + pool->queueWork(task); - + }; - + return utils::makePromise(runtime, func); }); } @@ -203,19 +204,19 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details_json; utils::jsiValueJsonToGAJson(runtime, arguments[1].getObject(runtime), &details_json); - + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_register_user(session, hw_device_json, details_json, &call)); - + json res = utils::resolve(call); - + GA_destroy_json(hw_device_json); GA_destroy_json(details_json); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -230,14 +231,14 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } - + }; - + pool->queueWork(task); - + }; - - + + return utils::makePromise(runtime, func); }); } @@ -257,19 +258,19 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details_json; utils::jsiValueJsonToGAJson(runtime, arguments[1].getObject(runtime), &details_json); - + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_login_user(session, hw_device_json, details_json, &call)); json res = utils::resolve(call); - + GA_destroy_json(hw_device_json); GA_destroy_json(details_json); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -284,14 +285,14 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } - + }; - + pool->queueWork(task); - + }; - + return utils::makePromise(runtime, func); }); } @@ -308,18 +309,18 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_get_subaccounts(session, details, &call)); json res = utils::resolve(call); - + GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -333,13 +334,13 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } - + }; - + pool->queueWork(task); - + }; - + return utils::makePromise(runtime, func); }); } @@ -355,15 +356,15 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(rt, arguments[0].getObject(rt), &details); utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_create_subaccount(session, details, &call)); json res = utils::resolve(call); - + GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -377,11 +378,11 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } - + }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); @@ -401,15 +402,15 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_get_receive_address(session, details, &call)); json res = utils::resolve(call); - + GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -423,11 +424,11 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } - + }; - + pool->queueWork(task); - + }; @@ -509,17 +510,17 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_get_transactions(session, details, &call)); json res = utils::resolve(call); - + GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -533,11 +534,11 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } - + }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); @@ -556,16 +557,16 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_get_unspent_outputs(session, details, &call)); json res = utils::resolve(call); GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -574,22 +575,22 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop p->reject(res["error"].dump()); } }); - + } catch (utils::Exception e) { GA_destroy_json(details); std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); }); } - + if (propName == "getBalance") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -602,16 +603,16 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_get_balance(session, details, &call)); json res = utils::resolve(call); GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -620,16 +621,16 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop p->reject(res["error"].dump()); } }); - + } catch (utils::Exception e) { GA_destroy_json(details); std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); @@ -672,7 +673,7 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop size_t count) -> jsi::Value { utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_json *estimates; @@ -681,7 +682,7 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { jsi::Value res = utils::GAJsonToObject(rt, estimates); - + GA_destroy_json(estimates); p->resolve(res); }); @@ -689,13 +690,13 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } - + }; - + pool->queueWork(task); - + }; - + return utils::makePromise(runtime, func); }); } @@ -711,16 +712,16 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_get_previous_addresses(session, details, &call)); json res = utils::resolve(call); GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -729,19 +730,19 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop p->reject(res["error"].dump()); } }); - + } catch (utils::Exception e) { GA_destroy_json(details); std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; - + return utils::makePromise(runtime, func); }); } @@ -757,17 +758,17 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - - + + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_get_credentials(session, details, &call)); json res = utils::resolve(call); GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -776,22 +777,22 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop p->reject(res["error"].dump()); } }); - + } catch (utils::Exception e) { GA_destroy_json(details); std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); }); } - + if (propName == "setPin") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -803,17 +804,17 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - - + + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_encrypt_with_pin(session, details, &call)); json res = utils::resolve(call); GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -822,22 +823,22 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop p->reject(res["error"].dump()); } }); - + } catch (utils::Exception e) { GA_destroy_json(details); std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); }); } - + if (propName == "getTransactionDetails") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -876,7 +877,7 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop return utils::makePromise(runtime, func); }); } - + if (propName == "createTransaction") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -888,18 +889,18 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - - + + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_create_transaction(session, details, &call)); json res = utils::resolve(call); - + GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -914,22 +915,22 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop p->reject(res["error"].dump()); } }); - + } catch (utils::Exception e) { GA_destroy_json(details); std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); }); } - + if (propName == "blindTransaction") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -941,17 +942,17 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - - + + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_blind_transaction(session, details, &call)); json res = utils::resolve(call); GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -960,22 +961,22 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop p->reject(res["error"].dump()); } }); - + } catch (utils::Exception e) { GA_destroy_json(details); std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); }); } - + if (propName == "signTransaction") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -987,17 +988,17 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - - + + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_sign_transaction(session, details, &call)); json res = utils::resolve(call); GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -1006,22 +1007,22 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop p->reject(res["error"].dump()); } }); - + } catch (utils::Exception e) { GA_destroy_json(details); std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); }); } - + if (propName == "sendTransaction") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -1033,17 +1034,17 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - - + + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_send_transaction(session, details, &call)); json res = utils::resolve(call); GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -1052,22 +1053,22 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop p->reject(res["error"].dump()); } }); - + } catch (utils::Exception e) { GA_destroy_json(details); std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); }); } - + if (propName == "signPsbt") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -1079,17 +1080,17 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop GA_json *details; utils::jsiValueJsonToGAJson(runtime, arguments[0].getObject(runtime), &details); - - + + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { GA_auth_handler *call; utils::wrapCall(GA_psbt_sign(session, details, &call)); json res = utils::resolve(call); GA_destroy_json(details); - + std::shared_ptr c = invoker.lock(); c->invokeAsync([=, &rt] { if (res.contains("result")) { @@ -1098,22 +1099,22 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop p->reject(res["error"].dump()); } }); - + } catch (utils::Exception e) { GA_destroy_json(details); std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); }); } - + if (propName == "broadcastTransaction") { return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forAscii(runtime, funcName), @@ -1124,9 +1125,9 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop size_t count) -> jsi::Value { std::string txhex = arguments[0].getString(runtime).utf8(runtime); - + utils::Promised func = [=](jsi::Runtime& rt, std::shared_ptr p){ - + auto task = [=, &rt](){ try { char* txHash; @@ -1138,20 +1139,44 @@ jsi::Value GdkHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& prop jsi::Value res = jsi::String::createFromUtf8(rt, hash); p->resolve(res); }); - + } catch (utils::Exception e) { std::shared_ptr c = invoker.lock(); c->invokeAsync([=] { p->reject(e.what()); }); } }; - + pool->queueWork(task); - + }; return utils::makePromise(runtime, func); }); } + if (propName == "registerNetwork") { + return jsi::Function::createFromHostFunction(runtime, + jsi::PropNameID::forAscii(runtime, funcName), + 1, + [this](jsi::Runtime& runtime, + const jsi::Value& thisValue, + const jsi::Value* arguments, + size_t count) -> jsi::Value { + + GA_json *network_details; + utils::jsiValueJsonToGAJson(runtime, arguments[1].getObject(runtime), &network_details); + std::string name = arguments[0].getString(runtime).utf8(runtime); + + + + + utils::wrapCall(GA_register_network(name.c_str(), network_details)); + +// GA_destroy_json(network_details); + + return jsi::Value::undefined(); + }); + } + return jsi::Value::undefined(); } diff --git a/src/GdkNativeInterface.ts b/src/GdkNativeInterface.ts index 8fd87f2..b8bb789 100644 --- a/src/GdkNativeInterface.ts +++ b/src/GdkNativeInterface.ts @@ -36,4 +36,5 @@ export interface GdkNativeInterface { broadcastTransaction: (txHex: string) => Promise signPsbt: (details: GDK.PsbtSignDetails) => Promise<{ psbt: string }> getBalance: (details: GDK.GetSubaccountReq) => Promise<{ [assetId: string]: number }> + registerNetwork: (name: string, network: GDK.NetworkDetails) => void } diff --git a/src/createGdk.ts b/src/createGdk.ts index be8dab8..59d1e3a 100644 --- a/src/createGdk.ts +++ b/src/createGdk.ts @@ -141,6 +141,7 @@ export interface GdkInterface { broadcastTransaction: (txHex: string) => Promise signPsbt: (details: GDK.PsbtSignDetails) => Promise<{ psbt: string }> getBalance: (details: GDK.GetSubaccountReq) => Promise<{ [assetId: string]: number }> + registerNetwork: (name: string, network: GDK.NetworkDetails) => void } declare global { @@ -217,6 +218,7 @@ export const createGdk = (): GdkInterface => { broadcastTransaction: gdk.broadcastTransaction, getNetworks: gdk.getNetworks, signPsbt: gdk.signPsbt, - getBalance: gdk.getBalance + getBalance: gdk.getBalance, + registerNetwork: gdk.registerNetwork } } diff --git a/src/types.ts b/src/types.ts index c1d41d3..afccdc6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -382,3 +382,37 @@ export type PsbtSignDetails = { // eslint-disable-next-line @typescript-eslint/ban-types blinding_nonces?: unknown[] } + +export type NetworkDetails = { + address_explorer_url: string + bech32_prefix?: string + default_peers?: string[] + development: boolean + liquid: boolean + mainnet: boolean + name: string + network: string + p2pkh_version?: number + p2sh_version?: number + service_chain_code?: string + service_pubkey?: string + tx_explorer_url: string + wamp_cert_pins?: string[] + wamp_onion_url?: string + wamp_url?: string + electrum_url: string + spv_enabled: boolean + tls: boolean + asset_registry_url: string + asset_registry_onion_url: string + policy_asset: string + ct_exponent: number + ct_bits: number + bip21_prefix: string + server_type: string + pin_server_url: string + pin_server_public_key: string + spv_cross_validation: boolean + pin_server_onion_url: string + spv_cross_validation_servers: [] +}