-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db2a85e
commit 1b16d31
Showing
29 changed files
with
2,115 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright (c) 2016-2023 Knuth Project developers. | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef KTH_JS_NATIVE_WALLET_CONVERTIONS_HPP_ | ||
#define KTH_JS_NATIVE_WALLET_CONVERTIONS_HPP_ | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
#include <node.h> | ||
#include <nan.h> | ||
|
||
#include <kth/capi/wallet/hd_lineage.h> | ||
|
||
namespace kth::js_native { | ||
|
||
inline | ||
v8::Local<v8::Uint8Array> ec_secret_to_js(v8::Isolate* isolate, kth_ec_secret_t const& x) { | ||
return byte_array_to_js(isolate, x.hash, KTH_BITCOIN_EC_SECRET_SIZE); | ||
} | ||
|
||
inline | ||
v8::Local<v8::Uint8Array> hd_key_to_js(v8::Isolate* isolate, kth_hd_key_t const& x) { | ||
return byte_array_to_js(isolate, x.data, KTH_HD_KEY_SIZE); | ||
} | ||
|
||
inline | ||
v8::Local<v8::Uint8Array> ec_compressed_to_js(v8::Isolate* isolate, kth_ec_compressed_t const& x) { | ||
return byte_array_to_js(isolate, x.data, KTH_EC_COMPRESSED_SIZE); | ||
} | ||
|
||
inline | ||
v8::Local<v8::Uint8Array> ec_uncompressed_to_js(v8::Isolate* isolate, kth_ec_uncompressed_t const& x) { | ||
return byte_array_to_js(isolate, x.data, KTH_BITCOIN_EC_UNCOMPRESSED_SIZE); | ||
} | ||
|
||
inline | ||
v8::Local<v8::Uint8Array> hd_chain_code_to_js(v8::Isolate* isolate, kth_hd_chain_code_t const& x) { | ||
return byte_array_to_js(isolate, x.data, KTH_HD_CHAIN_CODE_SIZE); | ||
} | ||
|
||
inline | ||
v8::Local<v8::Object> hd_lineage_to_js(v8::Isolate* isolate, kth_hd_lineage const& x) { | ||
auto ctx = isolate->GetCurrentContext(); | ||
v8::Local<v8::Object> res = v8::Object::New(isolate); | ||
res->Set(ctx, string_to_js(isolate, "prefixes"), v8::Number::New(isolate, x.prefixes)); | ||
res->Set(ctx, string_to_js(isolate, "depth"), v8::Number::New(isolate, x.depth)); | ||
res->Set(ctx, string_to_js(isolate, "parent_fingerprint"), v8::Number::New(isolate, x.parent_fingerprint)); | ||
res->Set(ctx, string_to_js(isolate, "child_number"), v8::Number::New(isolate, x.child_number)); | ||
return res; | ||
} | ||
|
||
inline | ||
kth_hd_key_t to_native_hd_key(v8::Local<v8::Uint8Array> const& arr) { | ||
//precondition: arr->Length() == KTH_HD_KEY_SIZE | ||
kth_hd_key_t res; | ||
|
||
#if (V8_MAJOR_VERSION >= 8) | ||
uint8_t* native_arr = (uint8_t*)arr->Buffer()->GetBackingStore()->Data(); | ||
#else | ||
uint8_t* native_arr = (uint8_t*)arr->Buffer()->GetContents().Data(); | ||
#endif | ||
|
||
for (uint32_t i = 0; i < arr->Length(); ++i) { | ||
res.data[i] = native_arr[i]; | ||
} | ||
return res; | ||
} | ||
|
||
inline | ||
kth_ec_secret_t to_native_ec_secret(v8::Local<v8::Uint8Array> const& arr) { | ||
//precondition: arr->Length() == 32 | ||
kth_ec_secret_t res; | ||
|
||
#if (V8_MAJOR_VERSION >= 8) | ||
uint8_t* native_arr = (uint8_t*)arr->Buffer()->GetBackingStore()->Data(); | ||
#else | ||
uint8_t* native_arr = (uint8_t*)arr->Buffer()->GetContents().Data(); | ||
#endif | ||
|
||
for (uint32_t i = 0; i < arr->Length(); ++i) { | ||
res.hash[i] = native_arr[i]; | ||
} | ||
return res; | ||
} | ||
|
||
inline | ||
kth_wif_compressed_t to_native_wif_compressed(v8::Local<v8::Uint8Array> arr) { | ||
//precondition: arr->Length() == 38 | ||
kth_wif_compressed_t res; | ||
|
||
#if (V8_MAJOR_VERSION >= 8) | ||
uint8_t* native_arr = (uint8_t*)arr->Buffer()->GetBackingStore()->Data(); | ||
#else | ||
uint8_t* native_arr = (uint8_t*)arr->Buffer()->GetContents().Data(); | ||
#endif | ||
|
||
for (uint32_t i = 0; i < arr->Length(); ++i) { | ||
res.data[i] = native_arr[i]; | ||
} | ||
return res; | ||
} | ||
|
||
inline | ||
kth_wif_uncompressed_t to_native_wif_uncompressed(v8::Local<v8::Uint8Array> arr) { | ||
//precondition: arr->Length() == 37 | ||
kth_wif_uncompressed_t res; | ||
|
||
#if (V8_MAJOR_VERSION >= 8) | ||
uint8_t* native_arr = (uint8_t*)arr->Buffer()->GetBackingStore()->Data(); | ||
#else | ||
uint8_t* native_arr = (uint8_t*)arr->Buffer()->GetContents().Data(); | ||
#endif | ||
|
||
for (uint32_t i = 0; i < arr->Length(); ++i) { | ||
res.data[i] = native_arr[i]; | ||
} | ||
return res; | ||
} | ||
|
||
} // namespace kth::js_native | ||
|
||
#endif // KTH_JS_NATIVE_WALLET_CONVERTIONS_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2016-2023 Knuth Project developers. | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef KTH_JS_WALLET_EC_PRIVATE_HPP_ | ||
#define KTH_JS_WALLET_EC_PRIVATE_HPP_ | ||
|
||
#include <node.h> | ||
|
||
namespace kth::js_native { | ||
|
||
void wallet_ec_private_construct_default(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_construct_string(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_construct_compressed(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_construct_uncompressed(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_construct_secret(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_destruct(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_is_valid(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_encoded(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_secret(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_version(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_payment_version(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_wif_version(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_compressed(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_to_public(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_private_to_payment_address(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
|
||
} // namespace kth::js_native | ||
|
||
#endif //KTH_JS_WALLET_EC_PRIVATE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2016-2023 Knuth Project developers. | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef KTH_JS_WALLET_EC_PUBLIC_HPP_ | ||
#define KTH_JS_WALLET_EC_PUBLIC_HPP_ | ||
|
||
#include <node.h> | ||
|
||
namespace kth::js_native { | ||
|
||
void wallet_ec_public_construct_default(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_construct(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_construct_from_decoded(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_construct_from_base16(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_construct_from_point(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_destruct(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_is_valid(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_encoded(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_point(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_compressed(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_to_data(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_to_uncompressed(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_public_to_payment_address(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
|
||
} // namespace kth::js_native | ||
|
||
#endif //KTH_JS_WALLET_EC_PUBLIC_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2016-2023 Knuth Project developers. | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef KTH_JS_WALLET_ELLIPTIC_CURVE_HPP | ||
#define KTH_JS_WALLET_ELLIPTIC_CURVE_HPP | ||
|
||
#include <node.h> | ||
|
||
namespace kth::js_native { | ||
|
||
void wallet_secret_to_public(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
|
||
} // namespace kth::js_native | ||
|
||
#endif //KTH_JS_WALLET_ELLIPTIC_CURVE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2016-2023 Knuth Project developers. | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef KTH_JS_WALLET_HD_PRIVATE_HPP_ | ||
#define KTH_JS_WALLET_HD_PRIVATE_HPP_ | ||
|
||
#include <node.h> | ||
|
||
namespace kth::js_native { | ||
|
||
void wallet_hd_private_construct_default(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_construct(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_construct_with_prefix(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_construct_with_prefixes(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_construct_with_seed(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_construct_string(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_construct_string_with_prefix(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_construct_string_with_prefixes(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_destruct(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_encoded(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_secret(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_to_hd_key(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_to_public(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_derive_private(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_derive_public(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
|
||
|
||
} // namespace kth::js_native | ||
|
||
#endif //KTH_JS_WALLET_HD_PRIVATE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2016-2023 Knuth Project developers. | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef KTH_JS_WALLET_HD_PUBLIC_HPP_ | ||
#define KTH_JS_WALLET_HD_PUBLIC_HPP_ | ||
|
||
#include <node.h> | ||
|
||
namespace kth::js_native { | ||
|
||
void wallet_hd_public_construct_default(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_construct(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_construct_with_prefix(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_construct_string(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_construct_string_with_prefix(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_destruct(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_is_valid(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_encoded(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_chain_code(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_lineage(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_point(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_to_hd_key(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_public_derive_public(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
|
||
|
||
} // namespace kth::js_native | ||
|
||
#endif //KTH_JS_WALLET_HD_PUBLIC_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2016-2023 Knuth Project developers. | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef KTH_JS_WALLET_WALLET_HPP_ | ||
#define KTH_JS_WALLET_WALLET_HPP_ | ||
|
||
#include <node.h> | ||
|
||
namespace kth::js_native { | ||
|
||
void wallet_mnemonics_to_seed(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_new(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_hd_private_to_ec(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_to_public(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
void wallet_ec_to_address(v8::FunctionCallbackInfo<v8::Value> const& args); | ||
|
||
} // namespace kth::js_native | ||
|
||
#endif //KTH_JS_WALLET_WALLET_HPP_ |
Oops, something went wrong.