diff --git a/.github/ISSUE_TEMPLATE/Story.md b/.github/ISSUE_TEMPLATE/Story.md new file mode 100644 index 00000000..7a7c989e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Story.md @@ -0,0 +1,17 @@ +--- +name: Story +about: Create a story + +--- + +# Overview + + + +- + +# Completion condition + + + +- diff --git a/.github/ISSUE_TEMPLATE/Task.md b/.github/ISSUE_TEMPLATE/Task.md new file mode 100644 index 00000000..e53247f9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Task.md @@ -0,0 +1,23 @@ +--- +name: Task +about: Create a task + +--- + +# Overview + + + +- + +# Sub tasks + + + +- [ ] + +# Completion condition + + + +- \ No newline at end of file diff --git a/.github/workflows/check_pre-merge_develop.yml b/.github/workflows/check_pre-merge_develop.yml index f8b66fdf..3e6c074b 100644 --- a/.github/workflows/check_pre-merge_develop.yml +++ b/.github/workflows/check_pre-merge_develop.yml @@ -35,19 +35,13 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2.1.0 continue-on-error: true timeout-minutes: 1 with: node-version: ${{ matrix.node }} - name: setup-node retry - uses: actions/setup-node@v1 - continue-on-error: true - timeout-minutes: 1 - with: - node-version: ${{ matrix.node }} - - name: setup-node third-try - uses: actions/setup-node@v1 + uses: actions/setup-node@v2.1.0 timeout-minutes: 1 with: node-version: ${{ matrix.node }} diff --git a/.github/workflows/check_pre-merge_master.yml b/.github/workflows/check_pre-merge_master.yml index 133d67e1..8a62a1eb 100644 --- a/.github/workflows/check_pre-merge_master.yml +++ b/.github/workflows/check_pre-merge_master.yml @@ -33,19 +33,13 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2.1.0 continue-on-error: true timeout-minutes: 1 with: node-version: ${{ matrix.node }} - name: setup-node retry - uses: actions/setup-node@v1 - continue-on-error: true - timeout-minutes: 1 - with: - node-version: ${{ matrix.node }} - - name: setup-node third-try - uses: actions/setup-node@v1 + uses: actions/setup-node@v2.1.0 timeout-minutes: 1 with: node-version: ${{ matrix.node }} diff --git a/.github/workflows/check_pre-merge_sprint.yml b/.github/workflows/check_pre-merge_sprint.yml index 145734cb..2a230727 100644 --- a/.github/workflows/check_pre-merge_sprint.yml +++ b/.github/workflows/check_pre-merge_sprint.yml @@ -31,19 +31,13 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2.1.0 continue-on-error: true timeout-minutes: 1 with: node-version: ${{ matrix.node }} - name: setup-node retry - uses: actions/setup-node@v1 - continue-on-error: true - timeout-minutes: 1 - with: - node-version: ${{ matrix.node }} - - name: setup-node third-try - uses: actions/setup-node@v1 + uses: actions/setup-node@v2.1.0 timeout-minutes: 1 with: node-version: ${{ matrix.node }} diff --git a/.gitignore b/.gitignore index d8ccadf1..5dde228f 100644 --- a/.gitignore +++ b/.gitignore @@ -135,7 +135,6 @@ local.properties !.vscode/extensions.json -/wally.js output m4 diff --git a/CMakeLists.txt b/CMakeLists.txt index fee25fc5..aabec2b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,9 @@ else() add_subdirectory(src) endif() # CFDJS_API_INSTALLED +if(NOT ENABLE_EMSCRIPTEN) add_subdirectory(addon) +endif() if(NOT CFDJS_API_INSTALLED) diff --git a/README.md b/README.md index b905aae8..3aed0d6f 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,26 @@ npm run example npm run elements_example ``` +### Tool and library + +#### using library + +- cfd + +#### formatter + +- clang-format (using v10.0.0) + +#### linter + +- cpplint + +#### document tool + +- doxygen & graphviz + +--- + ## Note ### Git connection: diff --git a/addon/cfdjs_node_addon.cpp b/addon/cfdjs_node_addon.cpp index 30bd500f..2a1fce44 100644 --- a/addon/cfdjs_node_addon.cpp +++ b/addon/cfdjs_node_addon.cpp @@ -5,6 +5,7 @@ * @brief cfd node.js API implements file. */ #include // NOLINT + #include #include "cfd/cfd_common.h" @@ -220,6 +221,33 @@ Value CreateSignatureHash(const CallbackInfo &information) { return NodeAddonJsonApi(information, JsonMappingApi::CreateSignatureHash); } +/** + * @brief ConvertAes の JSON API関数(request, response). + * @param[in] information node addon apiのコールバック情報 + * @return 戻り値(JSON文字列) + */ +Value ConvertAes(const CallbackInfo &information) { + return NodeAddonJsonApi(information, JsonMappingApi::ConvertAes); +} + +/** + * @brief EncodeBase58 の JSON API関数(request, response). + * @param[in] information node addon apiのコールバック情報 + * @return 戻り値(JSON文字列) + */ +Value EncodeBase58(const CallbackInfo &information) { + return NodeAddonJsonApi(information, JsonMappingApi::EncodeBase58); +} + +/** + * @brief DecodeBase58 の JSON API関数(request, response). + * @param[in] information node addon apiのコールバック情報 + * @return 戻り値(JSON文字列) + */ +Value DecodeBase58(const CallbackInfo &information) { + return NodeAddonJsonApi(information, JsonMappingApi::DecodeBase58); +} + /** * @brief EncodeSignatureByDer の JSON API関数(request, response). * @param[in] information node addon apiのコールバック情報 @@ -440,6 +468,15 @@ Value SignWithPrivkey(const CallbackInfo &information) { return NodeAddonJsonApi(information, JsonMappingApi::SignWithPrivkey); } +/** + * @brief AddScriptHashSignのJSON API関数(request, response). + * @param[in] information node addon apiのコールバック情報 + * @return 戻り値(JSON文字列) + */ +Value AddScriptHashSign(const CallbackInfo &information) { + return NodeAddonJsonApi(information, JsonMappingApi::AddScriptHashSign); +} + /** * @brief UpdateWitnessStackのJSON API関数(request, response). * @param[in] information node addon apiのコールバック情報 @@ -736,6 +773,11 @@ void InitializeJsonApi(Env env, Object *exports) { exports->Set( String::New(env, "CreateSignatureHash"), Function::New(env, CreateSignatureHash)); + exports->Set(String::New(env, "ConvertAes"), Function::New(env, ConvertAes)); + exports->Set( + String::New(env, "EncodeBase58"), Function::New(env, EncodeBase58)); + exports->Set( + String::New(env, "DecodeBase58"), Function::New(env, DecodeBase58)); exports->Set( String::New(env, "EncodeSignatureByDer"), Function::New(env, EncodeSignatureByDer)); @@ -752,6 +794,9 @@ void InitializeJsonApi(Env env, Object *exports) { exports->Set( String::New(env, "SignWithPrivkey"), Function::New(env, SignWithPrivkey)); + exports->Set( + String::New(env, "AddScriptHashSign"), + Function::New(env, AddScriptHashSign)); exports->Set( String::New(env, "UpdateWitnessStack"), Function::New(env, UpdateWitnessStack)); diff --git a/cfdjs_util.js b/cfdjs_util.js index a28a4367..1e6873e4 100644 --- a/cfdjs_util.js +++ b/cfdjs_util.js @@ -1,4 +1,4 @@ -const cfdjs = require('./wrap_js/cfdjs_module.js'); +const cfdjs = require('./index'); /** * Parse bip32 path. diff --git a/cmake/CfdCommonOption.cmake b/cmake/CfdCommonOption.cmake index 4658402a..900cc0cc 100644 --- a/cmake/CfdCommonOption.cmake +++ b/cmake/CfdCommonOption.cmake @@ -5,6 +5,7 @@ option(ENABLE_SHARED "enable shared library (ON or OFF. default:OFF)" OFF) endif() option(ENABLE_ELEMENTS "enable elements code (ON or OFF. default:ON)" ON) option(ENABLE_TESTS "enable code tests (ON or OFF. default:ON)" ON) +option(ENABLE_EMSCRIPTEN "enable EMSCRIPTEN (ON or OFF. default:OFF)" OFF) # use "cmake -DCMAKE_BUILD_TYPE=Debug" or "cmake-js -D" # option(ENABLE_DEBUG "enable debugging (ON or OFF. default:OFF)" OFF) @@ -53,3 +54,12 @@ else() set(ELEMENTS_COMP_OPT BUILD_ELEMENTS) set(CFD_ELEMENTS_USE "") endif() + +if(NOT ENABLE_EMSCRIPTEN) +set(USE_EMSCRIPTEN FALSE) +set(EMSCRIPTEN_OPT "") +else() +set(USE_EMSCRIPTEN TRUE) +set(EMSCRIPTEN_OPT "") +#set(EMSCRIPTEN_OPT "-fwasm-exceptions") +endif() diff --git a/cmake/Cpp11Setting.cmake b/cmake/Cpp11Setting.cmake index 8de16805..c6beeab8 100644 --- a/cmake/Cpp11Setting.cmake +++ b/cmake/Cpp11Setting.cmake @@ -8,6 +8,11 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -ggdb") endif() endif() +if(${USE_EMSCRIPTEN}) +# feature: -fwasm-exceptions +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s DISABLE_EXCEPTION_CATCHING=0") +endif() + set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 2dd6309d..d01af681 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -71,7 +71,7 @@ if(CFD_TARGET_VERSION) set(CFD_TARGET_TAG ${CFD_TARGET_VERSION}) message(STATUS "[external project local] cfd target=${CFD_TARGET_VERSION}") else() -set(CFD_TARGET_TAG v0.1.2) +set(CFD_TARGET_TAG v0.1.3) endif() if(CFD_TARGET_URL) set(CFD_TARGET_REP ${CFD_TARGET_URL}) @@ -135,7 +135,7 @@ if(LIBWALLY_TARGET_VERSION) set(LIBWALLY_TARGET_TAG ${LIBWALLY_TARGET_VERSION}) message(STATUS "[external project cfd-js local] libwally-core target=${LIBWALLY_TARGET_VERSION}") else() -set(LIBWALLY_TARGET_TAG cmake_build) +set(LIBWALLY_TARGET_TAG refs/tags/cfd-0.0.2) endif() if(${USE_GIT_SSH}) diff --git a/include/cfdjs/cfdjs_api_elements_transaction.h b/include/cfdjs/cfdjs_api_elements_transaction.h index cb6fb7ab..4a72c101 100644 --- a/include/cfdjs/cfdjs_api_elements_transaction.h +++ b/include/cfdjs/cfdjs_api_elements_transaction.h @@ -93,6 +93,14 @@ class CFD_JS_API_EXPORT ElementsTransactionStructApi { static AddPubkeyHashSignResponseStruct AddPubkeyHashSign( const AddPubkeyHashSignRequestStruct& request); + /** + * @brief パラメータの情報を元に、Scriptの署名情報を追加する. + * @param[in] request Transactionと署名情報を格納した構造体 + * @return Transactionのhexデータを格納した構造体 + */ + static AddScriptHashSignResponseStruct AddScriptHashSign( + const AddScriptHashSignRequestStruct& request); + /** * @brief パラメータの情報を元に、WitnessStackの情報を更新する. * @param[in] request TransactionとWitnessStack追加情報を格納した構造体 diff --git a/include/cfdjs/cfdjs_api_json.h b/include/cfdjs/cfdjs_api_json.h index 1ad17495..910d2b65 100644 --- a/include/cfdjs/cfdjs_api_json.h +++ b/include/cfdjs/cfdjs_api_json.h @@ -2,30 +2,50 @@ /** * @file cfdjs_api_json.h * - * @brief cfd-apiで利用するJsonApiクラス定義 + * @brief Define JsonApi class used in cfd-api. * - * JSON形式のAPIを提供する. + * Provide JSON format API. */ #ifndef CFD_JS_INCLUDE_CFDJS_CFDJS_API_JSON_H_ #define CFD_JS_INCLUDE_CFDJS_CFDJS_API_JSON_H_ +#include +#include #include #include "cfdjs/cfdjs_api_common.h" /** - * @brief cfdapi名前空間 + * @brief cfdapi namespace */ namespace cfd { namespace js { namespace api { namespace json { +/// request and response function type. +using RequestFunction = std::function; +/// request and response function map. +using RequestFunctionMap = std::map; +/// response only function type. +using ResponseOnlyFunction = std::function; +/// response only function map. +using ResponseOnlyFunctionMap = std::map; + /** - * @brief 共通系の関数群クラス + * @brief Json mapped api class. */ class CFD_JS_API_EXPORT JsonMappingApi { public: + /** + * @brief load functions. + * @param[out] request_map request-response function map. + * @param[out] response_only_map response-only function map. + */ + static void LoadFunctions( + RequestFunctionMap *request_map, + ResponseOnlyFunctionMap *response_only_map); + /** * @brief GetSupportedFunctionのJSON API関数(request, response). * @return 戻り値(JSON文字列) @@ -126,6 +146,27 @@ class CFD_JS_API_EXPORT JsonMappingApi { */ static std::string CreateSignatureHash(const std::string &request_message); + /** + * @brief Convert data by AES. + * @param[in] request request json string. + * @return response struct including encoded string. + */ + static std::string ConvertAes(const std::string &request); + + /** + * @brief Encode the data by base58. + * @param[in] request request json string. + * @return response struct including encoded string. + */ + static std::string EncodeBase58(const std::string &request); + + /** + * @brief Decode the data by base58. + * @param[in] request request json string. + * @return response json string. + */ + static std::string DecodeBase58(const std::string &request); + /** * @brief EncodeSignatureByDer の JSON API関数(request, response). * @param[in] request_message リクエストされたjson文字列 @@ -299,6 +340,13 @@ class CFD_JS_API_EXPORT JsonMappingApi { */ static std::string SignWithPrivkey(const std::string &request_message); + /** + * @brief AddScriptHashSignのJSON API関数(request, response). + * @param[in] request_message リクエストされたjson文字列 + * @return 戻り値(JSON文字列) + */ + static std::string AddScriptHashSign(const std::string &request_message); + /** * @brief UpdateWitnessStackのJSON API関数(request, response). * @param[in] request_message リクエストされたjson文字列 diff --git a/include/cfdjs/cfdjs_api_transaction.h b/include/cfdjs/cfdjs_api_transaction.h index cdc90cc5..7f95ca65 100644 --- a/include/cfdjs/cfdjs_api_transaction.h +++ b/include/cfdjs/cfdjs_api_transaction.h @@ -101,6 +101,14 @@ class CFD_JS_API_EXPORT TransactionStructApi { static AddPubkeyHashSignResponseStruct AddPubkeyHashSign( const AddPubkeyHashSignRequestStruct& request); + /** + * @brief パラメータの情報を元に、Scriptの署名情報を追加する. + * @param[in] request Transactionと署名情報を格納した構造体 + * @return Transactionのhexデータを格納した構造体 + */ + static AddScriptHashSignResponseStruct AddScriptHashSign( + const AddScriptHashSignRequestStruct& request); + /** * @brief JSONパラメータの情報を元に、SigHashを作成する * @param[in] request sighashを生成するパラメータ diff --git a/include/cfdjs/cfdjs_api_utility.h b/include/cfdjs/cfdjs_api_utility.h index bc2c0d54..50ebb689 100644 --- a/include/cfdjs/cfdjs_api_utility.h +++ b/include/cfdjs/cfdjs_api_utility.h @@ -32,6 +32,29 @@ class CFD_JS_API_EXPORT UtilStructApi { */ static GetSupportedFunctionResponseStruct GetSupportedFunction(); + /** + * @brief Convert data by AES. + * @param[in] request request struct from json + * @return response struct including encoded or decoded data. + */ + static ConvertAesResponseStruct ConvertAes(ConvertAesRequestStruct request); + + /** + * @brief Encode the data by base58. + * @param[in] request request struct from json + * @return response struct including encoded string. + */ + static EncodeBase58ResponseStruct EncodeBase58( + EncodeBase58RequestStruct request); + + /** + * @brief Decode the data by base58. + * @param[in] request request struct from json + * @return response struct including decoded data. + */ + static DecodeBase58ResponseStruct DecodeBase58( + DecodeBase58RequestStruct request); + /** * @brief Encode the secp signature by der encodeing * @param[in] request request struct from json diff --git a/include/cfdjs/cfdjs_common.h b/include/cfdjs/cfdjs_common.h index c972f299..2c956d57 100644 --- a/include/cfdjs/cfdjs_common.h +++ b/include/cfdjs/cfdjs_common.h @@ -5,11 +5,11 @@ */ #ifndef CFD_JS_INCLUDE_CFDJS_CFDJS_COMMON_H_ #define CFD_JS_INCLUDE_CFDJS_CFDJS_COMMON_H_ +#include // NOLINT + #include #include -#include // NOLINT - /** * @brief APIのDLLエクスポート定義 */ diff --git a/include/cfdjs/cfdjs_struct.h b/include/cfdjs/cfdjs_struct.h index 1c85ad58..dd736868 100644 --- a/include/cfdjs/cfdjs_struct.h +++ b/include/cfdjs/cfdjs_struct.h @@ -195,6 +195,61 @@ struct AddRawTransactionResponseStruct { std::set ignore_items; //!< using on JSON mapping convert. }; +// ------------------------------------------------------------------------ +// ScriptHashSignDataStruct +// ------------------------------------------------------------------------ +/** + * @brief ScriptHashSignDataStruct struct + */ +struct ScriptHashSignDataStruct { + std::string hex = ""; //!< hex // NOLINT + std::string type = "auto"; //!< type // NOLINT + bool der_encode = false; //!< der_encode // NOLINT + std::string sighash_type = "all"; //!< sighash_type // NOLINT + bool sighash_anyone_can_pay = false; //!< sighash_anyone_can_pay // NOLINT + std::set ignore_items; //!< using on JSON mapping convert. +}; + +// ------------------------------------------------------------------------ +// AddScriptHashSignTxInRequestStruct +// ------------------------------------------------------------------------ +/** + * @brief AddScriptHashSignTxInRequestStruct struct + */ +struct AddScriptHashSignTxInRequestStruct { + std::string txid = ""; //!< txid // NOLINT + uint32_t vout = 0; //!< vout // NOLINT + std::vector sign_param; //!< sign_param // NOLINT + std::string redeem_script = ""; //!< redeem_script // NOLINT + std::string hash_type = ""; //!< hash_type // NOLINT + std::set ignore_items; //!< using on JSON mapping convert. +}; + +// ------------------------------------------------------------------------ +// AddScriptHashSignRequestStruct +// ------------------------------------------------------------------------ +/** + * @brief AddScriptHashSignRequestStruct struct + */ +struct AddScriptHashSignRequestStruct { + bool is_elements = false; //!< is_elements // NOLINT + std::string tx = ""; //!< tx // NOLINT + AddScriptHashSignTxInRequestStruct txin; //!< txin // NOLINT + std::set ignore_items; //!< using on JSON mapping convert. +}; + +// ------------------------------------------------------------------------ +// AddScriptHashSignResponseStruct +// ------------------------------------------------------------------------ +/** + * @brief AddScriptHashSignResponseStruct struct + */ +struct AddScriptHashSignResponseStruct { + std::string hex = ""; //!< hex // NOLINT + cfd::js::api::InnerErrorResponseStruct error; //!< error information + std::set ignore_items; //!< using on JSON mapping convert. +}; + // ------------------------------------------------------------------------ // SignDataStruct // ------------------------------------------------------------------------ @@ -386,6 +441,33 @@ struct CalculateEcSignatureResponseStruct { std::set ignore_items; //!< using on JSON mapping convert. }; +// ------------------------------------------------------------------------ +// ConvertAesRequestStruct +// ------------------------------------------------------------------------ +/** + * @brief ConvertAesRequestStruct struct + */ +struct ConvertAesRequestStruct { + bool is_encrypt = true; //!< is_encrypt // NOLINT + std::string mode = "cbc"; //!< mode // NOLINT + std::string key = ""; //!< key // NOLINT + std::string iv = ""; //!< iv // NOLINT + std::string data = ""; //!< data // NOLINT + std::set ignore_items; //!< using on JSON mapping convert. +}; + +// ------------------------------------------------------------------------ +// ConvertAesResponseStruct +// ------------------------------------------------------------------------ +/** + * @brief ConvertAesResponseStruct struct + */ +struct ConvertAesResponseStruct { + std::string hex = ""; //!< hex // NOLINT + cfd::js::api::InnerErrorResponseStruct error; //!< error information + std::set ignore_items; //!< using on JSON mapping convert. +}; + // ------------------------------------------------------------------------ // ConvertEntropyToMnemonicRequestStruct // ------------------------------------------------------------------------ @@ -768,6 +850,30 @@ struct CreateScriptResponseStruct { std::set ignore_items; //!< using on JSON mapping convert. }; +// ------------------------------------------------------------------------ +// DecodeBase58RequestStruct +// ------------------------------------------------------------------------ +/** + * @brief DecodeBase58RequestStruct struct + */ +struct DecodeBase58RequestStruct { + std::string data = ""; //!< data // NOLINT + bool has_checksum = true; //!< has_checksum // NOLINT + std::set ignore_items; //!< using on JSON mapping convert. +}; + +// ------------------------------------------------------------------------ +// DecodeBase58ResponseStruct +// ------------------------------------------------------------------------ +/** + * @brief DecodeBase58ResponseStruct struct + */ +struct DecodeBase58ResponseStruct { + std::string hex = ""; //!< hex // NOLINT + cfd::js::api::InnerErrorResponseStruct error; //!< error information + std::set ignore_items; //!< using on JSON mapping convert. +}; + // ------------------------------------------------------------------------ // DecodeDerSignatureToRawRequestStruct // ------------------------------------------------------------------------ @@ -1761,6 +1867,30 @@ struct UnblindRawTransactionResponseStruct { std::set ignore_items; //!< using on JSON mapping convert. }; +// ------------------------------------------------------------------------ +// EncodeBase58RequestStruct +// ------------------------------------------------------------------------ +/** + * @brief EncodeBase58RequestStruct struct + */ +struct EncodeBase58RequestStruct { + std::string hex = ""; //!< hex // NOLINT + bool has_checksum = true; //!< has_checksum // NOLINT + std::set ignore_items; //!< using on JSON mapping convert. +}; + +// ------------------------------------------------------------------------ +// EncodeBase58ResponseStruct +// ------------------------------------------------------------------------ +/** + * @brief EncodeBase58ResponseStruct struct + */ +struct EncodeBase58ResponseStruct { + std::string data = ""; //!< data // NOLINT + cfd::js::api::InnerErrorResponseStruct error; //!< error information + std::set ignore_items; //!< using on JSON mapping convert. +}; + // ------------------------------------------------------------------------ // EncodeSignatureByDerRequestStruct // ------------------------------------------------------------------------ @@ -2888,8 +3018,9 @@ struct VerifySignRequestStruct { * @brief FailSignTxInStruct struct */ struct FailSignTxInStruct { - std::string txid = ""; //!< txid // NOLINT - uint32_t vout = 0; //!< vout // NOLINT + std::string txid = ""; //!< txid // NOLINT + uint32_t vout = 0; //!< vout // NOLINT + std::string reason = ""; //!< reason // NOLINT std::set ignore_items; //!< using on JSON mapping convert. }; diff --git a/index.d.ts b/index.d.ts index 159438f8..da29a0b4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -75,6 +75,32 @@ export interface AddRawTransactionResponse { hex: string; } +export interface ScriptHashSignData { + hex: string; + type?: string; + derEncode?: boolean; + sighashType?: string; + sighashAnyoneCanPay?: boolean; +} + +export interface AddScriptHashSignTxInRequest { + txid: string; + vout: number; + signParam: ScriptHashSignData[]; + redeemScript: string; + hashType: string; +} + +export interface AddScriptHashSignRequest { + isElements?: boolean; + tx: string; + txin?: AddScriptHashSignTxInRequest; +} + +export interface AddScriptHashSignResponse { + hex: string; +} + export interface SignData { hex: string; type?: string; @@ -164,6 +190,18 @@ export interface CalculateEcSignatureResponse { signature: string; } +export interface ConvertAesRequest { + isEncrypt: boolean; + mode?: string; + key: string; + iv?: string; + data: string; +} + +export interface ConvertAesResponse { + hex: string; +} + export interface ConvertEntropyToMnemonicRequest { entropy: string; language?: string; @@ -330,6 +368,15 @@ export interface CreateScriptResponse { hex: string; } +export interface DecodeBase58Request { + data: string; + hasChecksum?: boolean; +} + +export interface DecodeBase58Response { + hex: string; +} + export interface DecodeDerSignatureToRawRequest { signature: string; } @@ -838,6 +885,15 @@ export interface UnblindRawTransactionResponse { issuanceOutputs?: UnblindIssuanceOutput[]; } +export interface EncodeBase58Request { + hex: string; + hasChecksum?: boolean; +} + +export interface EncodeBase58Response { + data: string; +} + export interface EncodeSignatureByDerRequest { signature: string; sighashType: string; @@ -1387,6 +1443,7 @@ export interface VerifySignRequest { export interface FailSignTxIn { txid: string; vout: number; + reason: string; } export interface VerifySignResponse { @@ -1423,6 +1480,8 @@ export function AddPubkeyHashSign(jsonObject: AddPubkeyHashSignRequest): AddPubk export function AddRawTransaction(jsonObject: AddRawTransactionRequest): AddRawTransactionResponse; +export function AddScriptHashSign(jsonObject: AddScriptHashSignRequest): AddScriptHashSignResponse; + export function AddSign(jsonObject: AddSignRequest): AddSignResponse; export function AppendDescriptorChecksum(jsonObject: AppendDescriptorChecksumRequest): AppendDescriptorChecksumResponse; @@ -1431,6 +1490,8 @@ export function BlindRawTransaction(jsonObject: BlindRawTransactionRequest): Bli export function CalculateEcSignature(jsonObject: CalculateEcSignatureRequest): CalculateEcSignatureResponse; +export function ConvertAes(jsonObject: ConvertAesRequest): ConvertAesResponse; + export function ConvertEntropyToMnemonic(jsonObject: ConvertEntropyToMnemonicRequest): ConvertEntropyToMnemonicResponse; export function ConvertMnemonicToSeed(jsonObject: ConvertMnemonicToSeedRequest): ConvertMnemonicToSeedResponse; @@ -1457,6 +1518,8 @@ export function CreateMultisigScriptSig(jsonObject: CreateMultisigScriptSigReque export function CreateScript(jsonObject: CreateScriptRequest): CreateScriptResponse; +export function DecodeBase58(jsonObject: DecodeBase58Request): DecodeBase58Response; + export function DecodeDerSignatureToRaw(jsonObject: DecodeDerSignatureToRawRequest): DecodeDerSignatureToRawResponse; export function DecodeRawTransaction(jsonObject: DecodeRawTransactionRequest): DecodeRawTransactionResponse; @@ -1485,6 +1548,8 @@ export function SetRawReissueAsset(jsonObject: SetRawReissueAssetRequest): SetRa export function UnblindRawTransaction(jsonObject: UnblindRawTransactionRequest): UnblindRawTransactionResponse; +export function EncodeBase58(jsonObject: EncodeBase58Request): EncodeBase58Response; + export function EncodeSignatureByDer(jsonObject: EncodeSignatureByDerRequest): EncodeSignatureByDerResponse; export function EstimateFee(jsonObject: EstimateFeeRequest): EstimateFeeResponse; diff --git a/index.js b/index.js index 96f4ef46..bc12ed24 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,41 @@ -const cfdjsModule = require('./wrap_js/cfdjs_module.js'); +const cfdjs = require('bindings')('cfd_js.node'); +if (typeof cfdjs !== 'object' || cfdjs === null) { + throw new ReferenceError('Not support typeof cfdjs.'); +} -module.exports = cfdjsModule; +const wrappedModule = {}; +Object.keys(cfdjs).forEach((key) => { + const hook = function(...args) { + if (args.length > 1) { + throw Error('ERROR: Invalid argument passed:' + + `func=[${funcName}], args=[${args}]`); + } + + let retObj; + try { + // stringify all arguments + const argStr = args.map((arg) => + JSON.stringify(arg, (key, value) => + typeof value === 'bigint' ? value.toString() : value), + ); + + retObj = JSON.parse(cfdjs[key].apply(wrappedModule, argStr)); + } catch (err) { + // JSON convert error + // console.log(err); + throw new Error('ERROR: Invalid function call:' + + ` func=[${key}], args=[${args}]`); + } + + if (retObj.hasOwnProperty('error')) { + throw new Error(JSON.stringify(retObj.error)); + } + return retObj; + }; + Object.defineProperty(wrappedModule, key, { + value: hook, + enumerable: true, + }); +}); + +module.exports = wrappedModule; diff --git a/package-lock.json b/package-lock.json index bc63008f..265465d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cfd-js", - "version": "0.1.2", + "version": "0.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 50fe1ca5..c9e92793 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cfd-js", - "version": "0.1.2", + "version": "0.1.3", "domain": "p2pderivatives", "repository": { "type": "git", @@ -51,6 +51,9 @@ "test_watch": "jest --no-cache --watch", "test_quiet": "jest --no-cache --silent", "test_logging": "jest --no-cache --silent=false --verbose false", + "format": "run-p format_cpp_all format_js_all", + "format_cpp_all": "run-s code_format lint_check", + "format_js_all": "run-s js_format eslint_check", "format_all": "run-p code_format js_format", "code_format": "clang-format -i --style=file src/*.cpp src/*.h include/cfdjs/*.h addon/*.cpp", "js_format": "eslint --ext .js,.ts *.ts index.js cfdjs_util.js tools/ wrap_js/ --fix", @@ -104,6 +107,11 @@ "cmake_static_debug_configure:win32": "cmake-js configure -O build --CDENABLE_SHARED=off --CDENABLE_CAPI=off --CDCFDCORE_DEBUG=on -D", "cmake_static_debug_configure:linux": "cmake-js configure -O build --CDENABLE_SHARED=off --CDENABLE_CAPI=off --CDCFDCORE_DEBUG=on --CDTARGET_RPATH=./build/Release -g -D", "cmake_static_debug_configure:darwin": "cmake-js configure -O build --CDENABLE_SHARED=off --CDENABLE_CAPI=off --CDCFDCORE_DEBUG=on --CDTARGET_RPATH=\"@executable_path;./build/Release\" -C -D", + "emcmake": "run-s cmake_clean emcmake_configure cmake_build_parallel", + "emcmake_configure": "run-script-os", + "emcmake_configure:win32": "emcmake cmake -S . -B build -G \"MinGW Makefiles\" -DENABLE_EMSCRIPTEN=on -DENABLE_SHARED=off -DENABLE_CAPI=off -DENABLE_TESTS=off -DENABLE_ELEMENTS=on -DGENERATE_WALLY=on -DENABLE_JS_WRAPPER=off -DTARGET_RPATH=./wallycore -DCMAKE_BUILD_TYPE=Release", + "emcmake_configure:linux": "emcmake cmake -S . -B build -G \"Unix Makefiles\" -DENABLE_EMSCRIPTEN=on -DENABLE_SHARED=off -DENABLE_CAPI=off -DENABLE_TESTS=off -DENABLE_ELEMENTS=on -DGENERATE_WALLY=on -DENABLE_JS_WRAPPER=off -DTARGET_RPATH=./wallycore -DCMAKE_BUILD_TYPE=Release", + "emcmake_configure:darwin": "emcmake cmake -S . -B build -G \"Unix Makefiles\" -DENABLE_EMSCRIPTEN=on -DENABLE_SHARED=off -DENABLE_CAPI=off -DENABLE_TESTS=off -DENABLE_ELEMENTS=on -DGENERATE_WALLY=on -DENABLE_JS_WRAPPER=off -DTARGET_RPATH=./wallycore -DCMAKE_BUILD_TYPE=Release", "cmake_build": "cmake-js build -O build", "cmake_debug_build": "cmake-js build -O build -D", "cmake_quiet_build": "cmake-js build -O build -i", @@ -137,6 +145,7 @@ "doxygen_check:win32": "cd doc && doxygen Doxyfile_quiet_all && rmdir /S /Q html_all_quiet", "doxygen_check:linux": "cd doc && doxygen Doxyfile_quiet_all && rm -rf html_all_quiet", "doxygen_check:darwin": "cd doc && doxygen Doxyfile_quiet_all && rm -rf html_all_quiet", + "doxygen_dev": "cd doc && doxygen Doxyfile_quiet_all", "lint_all": "run-s lint_check eslint_check", "lint_check": "run-script-os", "lint_check:win32": "cd tools && lint_all_quiet.bat", @@ -144,6 +153,7 @@ "lint_check:darwin": "cd tools && ./lint_quiet.sh", "eslint_check": "eslint --ext .js,.ts *.ts *.js wrap_js/", "git_subm_update": "git submodule -q foreach git fetch -q && git submodule -q update -i", + "check_local": "run-p doxygen_dev format_cpp_all format_js_all", "check": "run-s doxygen_check lint_all ctest_quiet test_quiet example elements_example ts_example", "check_all": "run-s cmake_clean git_subm_update cmake_quiet doxygen_check ctest_quiet test_quiet example elements_example ts_example lint_all", "convert_json": "ts-node ./tools/generate_json_map_class.ts", @@ -152,7 +162,7 @@ "dependencies": { "@types/node": "^13.11.0", "big-integer": "^1.6.48", - "bindings": "*", + "bindings": "^1.5.0", "cmake-js": "^5.3.2", "del-cli": "^3.0.0", "got": "^10.7.0", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6162c8a4..8a8ff343 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -83,7 +83,7 @@ target_compile_options(${PROJECT_NAME} $, /LD /source-charset:utf-8 /Wall ${OPTION_BIGOBJ} /wd4061 /wd4244 /wd4251 /wd4365 /wd4464 /wd4514 /wd4571 /wd4574 /wd4623 /wd4625 /wd4626 /wd4710 /wd4711 /wd4774 /wd4820 /wd4946 /wd5026 /wd5027 /wd5039 /wd5045 /wd5052, - -Wall + -Wall ${EMSCRIPTEN_OPT} > ) # -fstack-protector diff --git a/src/autogen/cfd_js_api_json_autogen.cpp b/src/autogen/cfd_js_api_json_autogen.cpp index 473d0a63..cda58f96 100644 --- a/src/autogen/cfd_js_api_json_autogen.cpp +++ b/src/autogen/cfd_js_api_json_autogen.cpp @@ -703,6 +703,236 @@ AddRawTransactionResponseStruct AddRawTransactionResponse::ConvertToStruct() con return result; } +// ------------------------------------------------------------------------ +// ScriptHashSignData +// ------------------------------------------------------------------------ +cfd::core::JsonTableMap + ScriptHashSignData::json_mapper; +std::vector ScriptHashSignData::item_list; + +void ScriptHashSignData::CollectFieldName() { + if (!json_mapper.empty()) { + return; + } + cfd::core::CLASS_FUNCTION_TABLE func_table; // NOLINT + + func_table = { + ScriptHashSignData::GetHexString, + ScriptHashSignData::SetHexString, + ScriptHashSignData::GetHexFieldType, + }; + json_mapper.emplace("hex", func_table); + item_list.push_back("hex"); + func_table = { + ScriptHashSignData::GetTypeString, + ScriptHashSignData::SetTypeString, + ScriptHashSignData::GetTypeFieldType, + }; + json_mapper.emplace("type", func_table); + item_list.push_back("type"); + func_table = { + ScriptHashSignData::GetDerEncodeString, + ScriptHashSignData::SetDerEncodeString, + ScriptHashSignData::GetDerEncodeFieldType, + }; + json_mapper.emplace("derEncode", func_table); + item_list.push_back("derEncode"); + func_table = { + ScriptHashSignData::GetSighashTypeString, + ScriptHashSignData::SetSighashTypeString, + ScriptHashSignData::GetSighashTypeFieldType, + }; + json_mapper.emplace("sighashType", func_table); + item_list.push_back("sighashType"); + func_table = { + ScriptHashSignData::GetSighashAnyoneCanPayString, + ScriptHashSignData::SetSighashAnyoneCanPayString, + ScriptHashSignData::GetSighashAnyoneCanPayFieldType, + }; + json_mapper.emplace("sighashAnyoneCanPay", func_table); + item_list.push_back("sighashAnyoneCanPay"); +} + +void ScriptHashSignData::ConvertFromStruct( + const ScriptHashSignDataStruct& data) { + hex_ = data.hex; + type_ = data.type; + der_encode_ = data.der_encode; + sighash_type_ = data.sighash_type; + sighash_anyone_can_pay_ = data.sighash_anyone_can_pay; + ignore_items = data.ignore_items; +} + +ScriptHashSignDataStruct ScriptHashSignData::ConvertToStruct() const { // NOLINT + ScriptHashSignDataStruct result; + result.hex = hex_; + result.type = type_; + result.der_encode = der_encode_; + result.sighash_type = sighash_type_; + result.sighash_anyone_can_pay = sighash_anyone_can_pay_; + result.ignore_items = ignore_items; + return result; +} + +// ------------------------------------------------------------------------ +// AddScriptHashSignTxInRequest +// ------------------------------------------------------------------------ +cfd::core::JsonTableMap + AddScriptHashSignTxInRequest::json_mapper; +std::vector AddScriptHashSignTxInRequest::item_list; + +void AddScriptHashSignTxInRequest::CollectFieldName() { + if (!json_mapper.empty()) { + return; + } + cfd::core::CLASS_FUNCTION_TABLE func_table; // NOLINT + + func_table = { + AddScriptHashSignTxInRequest::GetTxidString, + AddScriptHashSignTxInRequest::SetTxidString, + AddScriptHashSignTxInRequest::GetTxidFieldType, + }; + json_mapper.emplace("txid", func_table); + item_list.push_back("txid"); + func_table = { + AddScriptHashSignTxInRequest::GetVoutString, + AddScriptHashSignTxInRequest::SetVoutString, + AddScriptHashSignTxInRequest::GetVoutFieldType, + }; + json_mapper.emplace("vout", func_table); + item_list.push_back("vout"); + func_table = { + AddScriptHashSignTxInRequest::GetSignParamString, + AddScriptHashSignTxInRequest::SetSignParamString, + AddScriptHashSignTxInRequest::GetSignParamFieldType, + }; + json_mapper.emplace("signParam", func_table); + item_list.push_back("signParam"); + func_table = { + AddScriptHashSignTxInRequest::GetRedeemScriptString, + AddScriptHashSignTxInRequest::SetRedeemScriptString, + AddScriptHashSignTxInRequest::GetRedeemScriptFieldType, + }; + json_mapper.emplace("redeemScript", func_table); + item_list.push_back("redeemScript"); + func_table = { + AddScriptHashSignTxInRequest::GetHashTypeString, + AddScriptHashSignTxInRequest::SetHashTypeString, + AddScriptHashSignTxInRequest::GetHashTypeFieldType, + }; + json_mapper.emplace("hashType", func_table); + item_list.push_back("hashType"); +} + +void AddScriptHashSignTxInRequest::ConvertFromStruct( + const AddScriptHashSignTxInRequestStruct& data) { + txid_ = data.txid; + vout_ = data.vout; + sign_param_.ConvertFromStruct(data.sign_param); + redeem_script_ = data.redeem_script; + hash_type_ = data.hash_type; + ignore_items = data.ignore_items; +} + +AddScriptHashSignTxInRequestStruct AddScriptHashSignTxInRequest::ConvertToStruct() const { // NOLINT + AddScriptHashSignTxInRequestStruct result; + result.txid = txid_; + result.vout = vout_; + result.sign_param = sign_param_.ConvertToStruct(); + result.redeem_script = redeem_script_; + result.hash_type = hash_type_; + result.ignore_items = ignore_items; + return result; +} + +// ------------------------------------------------------------------------ +// AddScriptHashSignRequest +// ------------------------------------------------------------------------ +cfd::core::JsonTableMap + AddScriptHashSignRequest::json_mapper; +std::vector AddScriptHashSignRequest::item_list; + +void AddScriptHashSignRequest::CollectFieldName() { + if (!json_mapper.empty()) { + return; + } + cfd::core::CLASS_FUNCTION_TABLE func_table; // NOLINT + + func_table = { + AddScriptHashSignRequest::GetIsElementsString, + AddScriptHashSignRequest::SetIsElementsString, + AddScriptHashSignRequest::GetIsElementsFieldType, + }; + json_mapper.emplace("isElements", func_table); + item_list.push_back("isElements"); + func_table = { + AddScriptHashSignRequest::GetTxString, + AddScriptHashSignRequest::SetTxString, + AddScriptHashSignRequest::GetTxFieldType, + }; + json_mapper.emplace("tx", func_table); + item_list.push_back("tx"); + func_table = { + AddScriptHashSignRequest::GetTxinString, + AddScriptHashSignRequest::SetTxinString, + AddScriptHashSignRequest::GetTxinFieldType, + }; + json_mapper.emplace("txin", func_table); + item_list.push_back("txin"); +} + +void AddScriptHashSignRequest::ConvertFromStruct( + const AddScriptHashSignRequestStruct& data) { + is_elements_ = data.is_elements; + tx_ = data.tx; + txin_.ConvertFromStruct(data.txin); + ignore_items = data.ignore_items; +} + +AddScriptHashSignRequestStruct AddScriptHashSignRequest::ConvertToStruct() const { // NOLINT + AddScriptHashSignRequestStruct result; + result.is_elements = is_elements_; + result.tx = tx_; + result.txin = txin_.ConvertToStruct(); + result.ignore_items = ignore_items; + return result; +} + +// ------------------------------------------------------------------------ +// AddScriptHashSignResponse +// ------------------------------------------------------------------------ +cfd::core::JsonTableMap + AddScriptHashSignResponse::json_mapper; +std::vector AddScriptHashSignResponse::item_list; + +void AddScriptHashSignResponse::CollectFieldName() { + if (!json_mapper.empty()) { + return; + } + cfd::core::CLASS_FUNCTION_TABLE func_table; // NOLINT + + func_table = { + AddScriptHashSignResponse::GetHexString, + AddScriptHashSignResponse::SetHexString, + AddScriptHashSignResponse::GetHexFieldType, + }; + json_mapper.emplace("hex", func_table); + item_list.push_back("hex"); +} + +void AddScriptHashSignResponse::ConvertFromStruct( + const AddScriptHashSignResponseStruct& data) { + hex_ = data.hex; + ignore_items = data.ignore_items; +} + +AddScriptHashSignResponseStruct AddScriptHashSignResponse::ConvertToStruct() const { // NOLINT + AddScriptHashSignResponseStruct result; + result.hex = hex_; + result.ignore_items = ignore_items; + return result; +} + // ------------------------------------------------------------------------ // SignData // ------------------------------------------------------------------------ @@ -1491,6 +1721,112 @@ CalculateEcSignatureResponseStruct CalculateEcSignatureResponse::ConvertToStruct return result; } +// ------------------------------------------------------------------------ +// ConvertAesRequest +// ------------------------------------------------------------------------ +cfd::core::JsonTableMap + ConvertAesRequest::json_mapper; +std::vector ConvertAesRequest::item_list; + +void ConvertAesRequest::CollectFieldName() { + if (!json_mapper.empty()) { + return; + } + cfd::core::CLASS_FUNCTION_TABLE func_table; // NOLINT + + func_table = { + ConvertAesRequest::GetIsEncryptString, + ConvertAesRequest::SetIsEncryptString, + ConvertAesRequest::GetIsEncryptFieldType, + }; + json_mapper.emplace("isEncrypt", func_table); + item_list.push_back("isEncrypt"); + func_table = { + ConvertAesRequest::GetModeString, + ConvertAesRequest::SetModeString, + ConvertAesRequest::GetModeFieldType, + }; + json_mapper.emplace("mode", func_table); + item_list.push_back("mode"); + func_table = { + ConvertAesRequest::GetKeyString, + ConvertAesRequest::SetKeyString, + ConvertAesRequest::GetKeyFieldType, + }; + json_mapper.emplace("key", func_table); + item_list.push_back("key"); + func_table = { + ConvertAesRequest::GetIvString, + ConvertAesRequest::SetIvString, + ConvertAesRequest::GetIvFieldType, + }; + json_mapper.emplace("iv", func_table); + item_list.push_back("iv"); + func_table = { + ConvertAesRequest::GetDataString, + ConvertAesRequest::SetDataString, + ConvertAesRequest::GetDataFieldType, + }; + json_mapper.emplace("data", func_table); + item_list.push_back("data"); +} + +void ConvertAesRequest::ConvertFromStruct( + const ConvertAesRequestStruct& data) { + is_encrypt_ = data.is_encrypt; + mode_ = data.mode; + key_ = data.key; + iv_ = data.iv; + data_ = data.data; + ignore_items = data.ignore_items; +} + +ConvertAesRequestStruct ConvertAesRequest::ConvertToStruct() const { // NOLINT + ConvertAesRequestStruct result; + result.is_encrypt = is_encrypt_; + result.mode = mode_; + result.key = key_; + result.iv = iv_; + result.data = data_; + result.ignore_items = ignore_items; + return result; +} + +// ------------------------------------------------------------------------ +// ConvertAesResponse +// ------------------------------------------------------------------------ +cfd::core::JsonTableMap + ConvertAesResponse::json_mapper; +std::vector ConvertAesResponse::item_list; + +void ConvertAesResponse::CollectFieldName() { + if (!json_mapper.empty()) { + return; + } + cfd::core::CLASS_FUNCTION_TABLE func_table; // NOLINT + + func_table = { + ConvertAesResponse::GetHexString, + ConvertAesResponse::SetHexString, + ConvertAesResponse::GetHexFieldType, + }; + json_mapper.emplace("hex", func_table); + item_list.push_back("hex"); +} + +void ConvertAesResponse::ConvertFromStruct( + const ConvertAesResponseStruct& data) { + hex_ = data.hex; + ignore_items = data.ignore_items; +} + +ConvertAesResponseStruct ConvertAesResponse::ConvertToStruct() const { // NOLINT + ConvertAesResponseStruct result; + result.hex = hex_; + result.ignore_items = ignore_items; + return result; +} + // ------------------------------------------------------------------------ // ConvertEntropyToMnemonicRequest // ------------------------------------------------------------------------ @@ -2956,6 +3292,85 @@ CreateScriptResponseStruct CreateScriptResponse::ConvertToStruct() const { // N return result; } +// ------------------------------------------------------------------------ +// DecodeBase58Request +// ------------------------------------------------------------------------ +cfd::core::JsonTableMap + DecodeBase58Request::json_mapper; +std::vector DecodeBase58Request::item_list; + +void DecodeBase58Request::CollectFieldName() { + if (!json_mapper.empty()) { + return; + } + cfd::core::CLASS_FUNCTION_TABLE func_table; // NOLINT + + func_table = { + DecodeBase58Request::GetDataString, + DecodeBase58Request::SetDataString, + DecodeBase58Request::GetDataFieldType, + }; + json_mapper.emplace("data", func_table); + item_list.push_back("data"); + func_table = { + DecodeBase58Request::GetHasChecksumString, + DecodeBase58Request::SetHasChecksumString, + DecodeBase58Request::GetHasChecksumFieldType, + }; + json_mapper.emplace("hasChecksum", func_table); + item_list.push_back("hasChecksum"); +} + +void DecodeBase58Request::ConvertFromStruct( + const DecodeBase58RequestStruct& data) { + data_ = data.data; + has_checksum_ = data.has_checksum; + ignore_items = data.ignore_items; +} + +DecodeBase58RequestStruct DecodeBase58Request::ConvertToStruct() const { // NOLINT + DecodeBase58RequestStruct result; + result.data = data_; + result.has_checksum = has_checksum_; + result.ignore_items = ignore_items; + return result; +} + +// ------------------------------------------------------------------------ +// DecodeBase58Response +// ------------------------------------------------------------------------ +cfd::core::JsonTableMap + DecodeBase58Response::json_mapper; +std::vector DecodeBase58Response::item_list; + +void DecodeBase58Response::CollectFieldName() { + if (!json_mapper.empty()) { + return; + } + cfd::core::CLASS_FUNCTION_TABLE func_table; // NOLINT + + func_table = { + DecodeBase58Response::GetHexString, + DecodeBase58Response::SetHexString, + DecodeBase58Response::GetHexFieldType, + }; + json_mapper.emplace("hex", func_table); + item_list.push_back("hex"); +} + +void DecodeBase58Response::ConvertFromStruct( + const DecodeBase58ResponseStruct& data) { + hex_ = data.hex; + ignore_items = data.ignore_items; +} + +DecodeBase58ResponseStruct DecodeBase58Response::ConvertToStruct() const { // NOLINT + DecodeBase58ResponseStruct result; + result.hex = hex_; + result.ignore_items = ignore_items; + return result; +} + // ------------------------------------------------------------------------ // DecodeDerSignatureToRawRequest // ------------------------------------------------------------------------ @@ -7461,6 +7876,85 @@ UnblindRawTransactionResponseStruct UnblindRawTransactionResponse::ConvertToStru return result; } +// ------------------------------------------------------------------------ +// EncodeBase58Request +// ------------------------------------------------------------------------ +cfd::core::JsonTableMap + EncodeBase58Request::json_mapper; +std::vector EncodeBase58Request::item_list; + +void EncodeBase58Request::CollectFieldName() { + if (!json_mapper.empty()) { + return; + } + cfd::core::CLASS_FUNCTION_TABLE func_table; // NOLINT + + func_table = { + EncodeBase58Request::GetHexString, + EncodeBase58Request::SetHexString, + EncodeBase58Request::GetHexFieldType, + }; + json_mapper.emplace("hex", func_table); + item_list.push_back("hex"); + func_table = { + EncodeBase58Request::GetHasChecksumString, + EncodeBase58Request::SetHasChecksumString, + EncodeBase58Request::GetHasChecksumFieldType, + }; + json_mapper.emplace("hasChecksum", func_table); + item_list.push_back("hasChecksum"); +} + +void EncodeBase58Request::ConvertFromStruct( + const EncodeBase58RequestStruct& data) { + hex_ = data.hex; + has_checksum_ = data.has_checksum; + ignore_items = data.ignore_items; +} + +EncodeBase58RequestStruct EncodeBase58Request::ConvertToStruct() const { // NOLINT + EncodeBase58RequestStruct result; + result.hex = hex_; + result.has_checksum = has_checksum_; + result.ignore_items = ignore_items; + return result; +} + +// ------------------------------------------------------------------------ +// EncodeBase58Response +// ------------------------------------------------------------------------ +cfd::core::JsonTableMap + EncodeBase58Response::json_mapper; +std::vector EncodeBase58Response::item_list; + +void EncodeBase58Response::CollectFieldName() { + if (!json_mapper.empty()) { + return; + } + cfd::core::CLASS_FUNCTION_TABLE func_table; // NOLINT + + func_table = { + EncodeBase58Response::GetDataString, + EncodeBase58Response::SetDataString, + EncodeBase58Response::GetDataFieldType, + }; + json_mapper.emplace("data", func_table); + item_list.push_back("data"); +} + +void EncodeBase58Response::ConvertFromStruct( + const EncodeBase58ResponseStruct& data) { + data_ = data.data; + ignore_items = data.ignore_items; +} + +EncodeBase58ResponseStruct EncodeBase58Response::ConvertToStruct() const { // NOLINT + EncodeBase58ResponseStruct result; + result.data = data_; + result.ignore_items = ignore_items; + return result; +} + // ------------------------------------------------------------------------ // EncodeSignatureByDerRequest // ------------------------------------------------------------------------ @@ -12198,12 +12692,20 @@ void FailSignTxIn::CollectFieldName() { }; json_mapper.emplace("vout", func_table); item_list.push_back("vout"); + func_table = { + FailSignTxIn::GetReasonString, + FailSignTxIn::SetReasonString, + FailSignTxIn::GetReasonFieldType, + }; + json_mapper.emplace("reason", func_table); + item_list.push_back("reason"); } void FailSignTxIn::ConvertFromStruct( const FailSignTxInStruct& data) { txid_ = data.txid; vout_ = data.vout; + reason_ = data.reason; ignore_items = data.ignore_items; } @@ -12211,6 +12713,7 @@ FailSignTxInStruct FailSignTxIn::ConvertToStruct() const { // NOLINT FailSignTxInStruct result; result.txid = txid_; result.vout = vout_; + result.reason = reason_; result.ignore_items = ignore_items; return result; } diff --git a/src/autogen/cfd_js_api_json_autogen.h b/src/autogen/cfd_js_api_json_autogen.h index e96c7dd4..8c55d6f7 100644 --- a/src/autogen/cfd_js_api_json_autogen.h +++ b/src/autogen/cfd_js_api_json_autogen.h @@ -3053,18 +3053,18 @@ class AddRawTransactionResponse }; // ------------------------------------------------------------------------ -// SignData +// ScriptHashSignData // ------------------------------------------------------------------------ /** - * @brief JSON-API (SignData) class + * @brief JSON-API (ScriptHashSignData) class */ -class SignData - : public cfd::core::JsonClassBase { +class ScriptHashSignData + : public cfd::core::JsonClassBase { public: - SignData() { + ScriptHashSignData() { CollectFieldName(); } - virtual ~SignData() { + virtual ~ScriptHashSignData() { // do nothing } /** @@ -3100,7 +3100,7 @@ class SignData * @return JSON string */ static std::string GetHexString( // line separate - const SignData& obj) { // NOLINT + const ScriptHashSignData& obj) { // NOLINT return cfd::core::ConvertToString(obj.hex_); } /** @@ -3109,7 +3109,7 @@ class SignData * @param[in] json_value JSON object. */ static void SetHexString( // line separate - SignData& obj, // NOLINT + ScriptHashSignData& obj, // NOLINT const UniValue& json_value) { cfd::core::ConvertFromUniValue( // line separate obj.hex_, json_value); @@ -3143,7 +3143,7 @@ class SignData * @return JSON string */ static std::string GetTypeString( // line separate - const SignData& obj) { // NOLINT + const ScriptHashSignData& obj) { // NOLINT return cfd::core::ConvertToString(obj.type_); } /** @@ -3152,7 +3152,7 @@ class SignData * @param[in] json_value JSON object. */ static void SetTypeString( // line separate - SignData& obj, // NOLINT + ScriptHashSignData& obj, // NOLINT const UniValue& json_value) { cfd::core::ConvertFromUniValue( // line separate obj.type_, json_value); @@ -3186,7 +3186,7 @@ class SignData * @return JSON string */ static std::string GetDerEncodeString( // line separate - const SignData& obj) { // NOLINT + const ScriptHashSignData& obj) { // NOLINT return cfd::core::ConvertToString(obj.der_encode_); } /** @@ -3195,7 +3195,7 @@ class SignData * @param[in] json_value JSON object. */ static void SetDerEncodeString( // line separate - SignData& obj, // NOLINT + ScriptHashSignData& obj, // NOLINT const UniValue& json_value) { cfd::core::ConvertFromUniValue( // line separate obj.der_encode_, json_value); @@ -3229,7 +3229,7 @@ class SignData * @return JSON string */ static std::string GetSighashTypeString( // line separate - const SignData& obj) { // NOLINT + const ScriptHashSignData& obj) { // NOLINT return cfd::core::ConvertToString(obj.sighash_type_); } /** @@ -3238,7 +3238,7 @@ class SignData * @param[in] json_value JSON object. */ static void SetSighashTypeString( // line separate - SignData& obj, // NOLINT + ScriptHashSignData& obj, // NOLINT const UniValue& json_value) { cfd::core::ConvertFromUniValue( // line separate obj.sighash_type_, json_value); @@ -3272,7 +3272,7 @@ class SignData * @return JSON string */ static std::string GetSighashAnyoneCanPayString( // line separate - const SignData& obj) { // NOLINT + const ScriptHashSignData& obj) { // NOLINT return cfd::core::ConvertToString(obj.sighash_anyone_can_pay_); } /** @@ -3281,7 +3281,7 @@ class SignData * @param[in] json_value JSON object. */ static void SetSighashAnyoneCanPayString( // line separate - SignData& obj, // NOLINT + ScriptHashSignData& obj, // NOLINT const UniValue& json_value) { cfd::core::ConvertFromUniValue( // line separate obj.sighash_anyone_can_pay_, json_value); @@ -3300,27 +3300,27 @@ class SignData * @param[in] data struct data. */ void ConvertFromStruct( - const SignDataStruct& data); + const ScriptHashSignDataStruct& data); /** * @brief Convert class to struct. * @return struct data. */ - SignDataStruct ConvertToStruct() const; + ScriptHashSignDataStruct ConvertToStruct() const; protected: /** * @brief definition type of Map table. */ - using SignDataMapTable = - cfd::core::JsonTableMap; + using ScriptHashSignDataMapTable = + cfd::core::JsonTableMap; /** * @brief Get JSON mapping object. * @return JSON mapping object. * @see cfd::core::JsonClassBase::GetJsonMapper() */ - virtual const SignDataMapTable& GetJsonMapper() const { // NOLINT + virtual const ScriptHashSignDataMapTable& GetJsonMapper() const { // NOLINT return json_mapper; } /** @@ -3346,7 +3346,7 @@ class SignData /** * @brief JsonFunctionMap table */ - static SignDataMapTable json_mapper; + static ScriptHashSignDataMapTable json_mapper; /** * @brief field name list. */ @@ -3379,18 +3379,18 @@ class SignData }; // ------------------------------------------------------------------------ -// AddSignTxInRequest +// AddScriptHashSignTxInRequest // ------------------------------------------------------------------------ /** - * @brief JSON-API (AddSignTxInRequest) class + * @brief JSON-API (AddScriptHashSignTxInRequest) class */ -class AddSignTxInRequest - : public cfd::core::JsonClassBase { +class AddScriptHashSignTxInRequest + : public cfd::core::JsonClassBase { public: - AddSignTxInRequest() { + AddScriptHashSignTxInRequest() { CollectFieldName(); } - virtual ~AddSignTxInRequest() { + virtual ~AddScriptHashSignTxInRequest() { // do nothing } /** @@ -3426,7 +3426,7 @@ class AddSignTxInRequest * @return JSON string */ static std::string GetTxidString( // line separate - const AddSignTxInRequest& obj) { // NOLINT + const AddScriptHashSignTxInRequest& obj) { // NOLINT return cfd::core::ConvertToString(obj.txid_); } /** @@ -3435,7 +3435,7 @@ class AddSignTxInRequest * @param[in] json_value JSON object. */ static void SetTxidString( // line separate - AddSignTxInRequest& obj, // NOLINT + AddScriptHashSignTxInRequest& obj, // NOLINT const UniValue& json_value) { cfd::core::ConvertFromUniValue( // line separate obj.txid_, json_value); @@ -3469,7 +3469,7 @@ class AddSignTxInRequest * @return JSON string */ static std::string GetVoutString( // line separate - const AddSignTxInRequest& obj) { // NOLINT + const AddScriptHashSignTxInRequest& obj) { // NOLINT return cfd::core::ConvertToString(obj.vout_); } /** @@ -3478,60 +3478,17 @@ class AddSignTxInRequest * @param[in] json_value JSON object. */ static void SetVoutString( // line separate - AddSignTxInRequest& obj, // NOLINT + AddScriptHashSignTxInRequest& obj, // NOLINT const UniValue& json_value) { cfd::core::ConvertFromUniValue( // line separate obj.vout_, json_value); } - /** - * @brief Get of isWitness - * @return isWitness - */ - bool GetIsWitness() const { - return is_witness_; - } - /** - * @brief Set to isWitness - * @param[in] is_witness setting value. - */ - void SetIsWitness( // line separate - const bool& is_witness) { // NOLINT - this->is_witness_ = is_witness; - } - /** - * @brief Get data type of isWitness - * @return Data type of isWitness - */ - static std::string GetIsWitnessFieldType() { - return "bool"; - } - /** - * @brief Get json string of isWitness field. - * @param[in,out] obj class object. - * @return JSON string - */ - static std::string GetIsWitnessString( // line separate - const AddSignTxInRequest& obj) { // NOLINT - return cfd::core::ConvertToString(obj.is_witness_); - } - /** - * @brief Set json object to isWitness field. - * @param[in,out] obj class object. - * @param[in] json_value JSON object. - */ - static void SetIsWitnessString( // line separate - AddSignTxInRequest& obj, // NOLINT - const UniValue& json_value) { - cfd::core::ConvertFromUniValue( // line separate - obj.is_witness_, json_value); - } - /** * @brief Get of signParam. * @return signParam */ - JsonObjectVector& GetSignParam() { // NOLINT + JsonObjectVector& GetSignParam() { // NOLINT return sign_param_; } /** @@ -3539,7 +3496,7 @@ class AddSignTxInRequest * @param[in] sign_param setting value. */ void SetSignParam( // line separate - const JsonObjectVector& sign_param) { // NOLINT + const JsonObjectVector& sign_param) { // NOLINT this->sign_param_ = sign_param; } /** @@ -3547,7 +3504,7 @@ class AddSignTxInRequest * @return Data type of signParam. */ static std::string GetSignParamFieldType() { - return "JsonObjectVector"; // NOLINT + return "JsonObjectVector"; // NOLINT } /** * @brief Get json string of signParam field. @@ -3555,7 +3512,7 @@ class AddSignTxInRequest * @return JSON string. */ static std::string GetSignParamString( // line separate - const AddSignTxInRequest& obj) { // NOLINT + const AddScriptHashSignTxInRequest& obj) { // NOLINT // Do not set to const, because substitution of member variables // may occur in pre / post processing inside Serialize return obj.sign_param_.Serialize(); @@ -3566,52 +3523,95 @@ class AddSignTxInRequest * @param[in] json_value JSON object */ static void SetSignParamString( // line separate - AddSignTxInRequest& obj, // NOLINT + AddScriptHashSignTxInRequest& obj, // NOLINT const UniValue& json_value) { obj.sign_param_.DeserializeUniValue(json_value); } /** - * @brief Get of clearStack - * @return clearStack + * @brief Get of redeemScript + * @return redeemScript */ - bool GetClearStack() const { - return clear_stack_; + std::string GetRedeemScript() const { + return redeem_script_; } /** - * @brief Set to clearStack - * @param[in] clear_stack setting value. + * @brief Set to redeemScript + * @param[in] redeem_script setting value. */ - void SetClearStack( // line separate - const bool& clear_stack) { // NOLINT - this->clear_stack_ = clear_stack; + void SetRedeemScript( // line separate + const std::string& redeem_script) { // NOLINT + this->redeem_script_ = redeem_script; } /** - * @brief Get data type of clearStack - * @return Data type of clearStack + * @brief Get data type of redeemScript + * @return Data type of redeemScript */ - static std::string GetClearStackFieldType() { - return "bool"; + static std::string GetRedeemScriptFieldType() { + return "std::string"; } /** - * @brief Get json string of clearStack field. + * @brief Get json string of redeemScript field. * @param[in,out] obj class object. * @return JSON string */ - static std::string GetClearStackString( // line separate - const AddSignTxInRequest& obj) { // NOLINT - return cfd::core::ConvertToString(obj.clear_stack_); + static std::string GetRedeemScriptString( // line separate + const AddScriptHashSignTxInRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.redeem_script_); } /** - * @brief Set json object to clearStack field. + * @brief Set json object to redeemScript field. * @param[in,out] obj class object. * @param[in] json_value JSON object. */ - static void SetClearStackString( // line separate - AddSignTxInRequest& obj, // NOLINT + static void SetRedeemScriptString( // line separate + AddScriptHashSignTxInRequest& obj, // NOLINT const UniValue& json_value) { cfd::core::ConvertFromUniValue( // line separate - obj.clear_stack_, json_value); + obj.redeem_script_, json_value); + } + + /** + * @brief Get of hashType + * @return hashType + */ + std::string GetHashType() const { + return hash_type_; + } + /** + * @brief Set to hashType + * @param[in] hash_type setting value. + */ + void SetHashType( // line separate + const std::string& hash_type) { // NOLINT + this->hash_type_ = hash_type; + } + /** + * @brief Get data type of hashType + * @return Data type of hashType + */ + static std::string GetHashTypeFieldType() { + return "std::string"; + } + /** + * @brief Get json string of hashType field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetHashTypeString( // line separate + const AddScriptHashSignTxInRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.hash_type_); + } + /** + * @brief Set json object to hashType field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetHashTypeString( // line separate + AddScriptHashSignTxInRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.hash_type_, json_value); } /** @@ -3627,27 +3627,27 @@ class AddSignTxInRequest * @param[in] data struct data. */ void ConvertFromStruct( - const AddSignTxInRequestStruct& data); + const AddScriptHashSignTxInRequestStruct& data); /** * @brief Convert class to struct. * @return struct data. */ - AddSignTxInRequestStruct ConvertToStruct() const; + AddScriptHashSignTxInRequestStruct ConvertToStruct() const; protected: /** * @brief definition type of Map table. */ - using AddSignTxInRequestMapTable = - cfd::core::JsonTableMap; + using AddScriptHashSignTxInRequestMapTable = + cfd::core::JsonTableMap; /** * @brief Get JSON mapping object. * @return JSON mapping object. * @see cfd::core::JsonClassBase::GetJsonMapper() */ - virtual const AddSignTxInRequestMapTable& GetJsonMapper() const { // NOLINT + virtual const AddScriptHashSignTxInRequestMapTable& GetJsonMapper() const { // NOLINT return json_mapper; } /** @@ -3673,7 +3673,7 @@ class AddSignTxInRequest /** * @brief JsonFunctionMap table */ - static AddSignTxInRequestMapTable json_mapper; + static AddScriptHashSignTxInRequestMapTable json_mapper; /** * @brief field name list. */ @@ -3692,32 +3692,32 @@ class AddSignTxInRequest */ uint32_t vout_ = 0; /** - * @brief JsonAPI(isWitness) value + * @brief JsonAPI(signParam) value */ - bool is_witness_ = true; + JsonObjectVector sign_param_; // NOLINT /** - * @brief JsonAPI(signParam) value + * @brief JsonAPI(redeemScript) value */ - JsonObjectVector sign_param_; // NOLINT + std::string redeem_script_ = ""; /** - * @brief JsonAPI(clearStack) value + * @brief JsonAPI(hashType) value */ - bool clear_stack_ = true; + std::string hash_type_ = ""; }; // ------------------------------------------------------------------------ -// AddSignRequest +// AddScriptHashSignRequest // ------------------------------------------------------------------------ /** - * @brief JSON-API (AddSignRequest) class + * @brief JSON-API (AddScriptHashSignRequest) class */ -class AddSignRequest - : public cfd::core::JsonClassBase { +class AddScriptHashSignRequest + : public cfd::core::JsonClassBase { public: - AddSignRequest() { + AddScriptHashSignRequest() { CollectFieldName(); } - virtual ~AddSignRequest() { + virtual ~AddScriptHashSignRequest() { // do nothing } /** @@ -3726,96 +3726,96 @@ class AddSignRequest static void CollectFieldName(); /** - * @brief Get of tx - * @return tx + * @brief Get of isElements + * @return isElements */ - std::string GetTx() const { - return tx_; + bool GetIsElements() const { + return is_elements_; } /** - * @brief Set to tx - * @param[in] tx setting value. + * @brief Set to isElements + * @param[in] is_elements setting value. */ - void SetTx( // line separate - const std::string& tx) { // NOLINT - this->tx_ = tx; + void SetIsElements( // line separate + const bool& is_elements) { // NOLINT + this->is_elements_ = is_elements; } /** - * @brief Get data type of tx - * @return Data type of tx + * @brief Get data type of isElements + * @return Data type of isElements */ - static std::string GetTxFieldType() { - return "std::string"; + static std::string GetIsElementsFieldType() { + return "bool"; } /** - * @brief Get json string of tx field. + * @brief Get json string of isElements field. * @param[in,out] obj class object. * @return JSON string */ - static std::string GetTxString( // line separate - const AddSignRequest& obj) { // NOLINT - return cfd::core::ConvertToString(obj.tx_); + static std::string GetIsElementsString( // line separate + const AddScriptHashSignRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.is_elements_); } /** - * @brief Set json object to tx field. + * @brief Set json object to isElements field. * @param[in,out] obj class object. * @param[in] json_value JSON object. */ - static void SetTxString( // line separate - AddSignRequest& obj, // NOLINT + static void SetIsElementsString( // line separate + AddScriptHashSignRequest& obj, // NOLINT const UniValue& json_value) { cfd::core::ConvertFromUniValue( // line separate - obj.tx_, json_value); + obj.is_elements_, json_value); } /** - * @brief Get of isElements - * @return isElements + * @brief Get of tx + * @return tx */ - bool GetIsElements() const { - return is_elements_; + std::string GetTx() const { + return tx_; } /** - * @brief Set to isElements - * @param[in] is_elements setting value. + * @brief Set to tx + * @param[in] tx setting value. */ - void SetIsElements( // line separate - const bool& is_elements) { // NOLINT - this->is_elements_ = is_elements; + void SetTx( // line separate + const std::string& tx) { // NOLINT + this->tx_ = tx; } /** - * @brief Get data type of isElements - * @return Data type of isElements + * @brief Get data type of tx + * @return Data type of tx */ - static std::string GetIsElementsFieldType() { - return "bool"; + static std::string GetTxFieldType() { + return "std::string"; } /** - * @brief Get json string of isElements field. + * @brief Get json string of tx field. * @param[in,out] obj class object. * @return JSON string */ - static std::string GetIsElementsString( // line separate - const AddSignRequest& obj) { // NOLINT - return cfd::core::ConvertToString(obj.is_elements_); + static std::string GetTxString( // line separate + const AddScriptHashSignRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.tx_); } /** - * @brief Set json object to isElements field. + * @brief Set json object to tx field. * @param[in,out] obj class object. * @param[in] json_value JSON object. */ - static void SetIsElementsString( // line separate - AddSignRequest& obj, // NOLINT + static void SetTxString( // line separate + AddScriptHashSignRequest& obj, // NOLINT const UniValue& json_value) { cfd::core::ConvertFromUniValue( // line separate - obj.is_elements_, json_value); + obj.tx_, json_value); } /** * @brief Get of txin. * @return txin */ - AddSignTxInRequest& GetTxin() { // NOLINT + AddScriptHashSignTxInRequest& GetTxin() { // NOLINT return txin_; } /** @@ -3823,7 +3823,7 @@ class AddSignRequest * @param[in] txin setting value. */ void SetTxin( // line separate - const AddSignTxInRequest& txin) { // NOLINT + const AddScriptHashSignTxInRequest& txin) { // NOLINT this->txin_ = txin; } /** @@ -3831,7 +3831,7 @@ class AddSignRequest * @return Data type of txin. */ static std::string GetTxinFieldType() { - return "AddSignTxInRequest"; // NOLINT + return "AddScriptHashSignTxInRequest"; // NOLINT } /** * @brief Get json string of txin field. @@ -3839,7 +3839,7 @@ class AddSignRequest * @return JSON string. */ static std::string GetTxinString( // line separate - const AddSignRequest& obj) { // NOLINT + const AddScriptHashSignRequest& obj) { // NOLINT // Do not set to const, because substitution of member variables // may occur in pre / post processing inside Serialize return obj.txin_.Serialize(); @@ -3850,7 +3850,7 @@ class AddSignRequest * @param[in] json_value JSON object */ static void SetTxinString( // line separate - AddSignRequest& obj, // NOLINT + AddScriptHashSignRequest& obj, // NOLINT const UniValue& json_value) { obj.txin_.DeserializeUniValue(json_value); } @@ -3868,27 +3868,1051 @@ class AddSignRequest * @param[in] data struct data. */ void ConvertFromStruct( - const AddSignRequestStruct& data); + const AddScriptHashSignRequestStruct& data); /** * @brief Convert class to struct. * @return struct data. */ - AddSignRequestStruct ConvertToStruct() const; + AddScriptHashSignRequestStruct ConvertToStruct() const; protected: /** * @brief definition type of Map table. */ - using AddSignRequestMapTable = - cfd::core::JsonTableMap; + using AddScriptHashSignRequestMapTable = + cfd::core::JsonTableMap; /** * @brief Get JSON mapping object. * @return JSON mapping object. * @see cfd::core::JsonClassBase::GetJsonMapper() */ - virtual const AddSignRequestMapTable& GetJsonMapper() const { // NOLINT + virtual const AddScriptHashSignRequestMapTable& GetJsonMapper() const { // NOLINT + return json_mapper; + } + /** + * @brief Get item lists of JSON mapping. + * Fetch a list of target variable names in the order of definition. + * @return Item lists of JSON mapping. + * @see cfd::core::JsonClassBase::GetJsonItemList() + */ + virtual const std::vector& GetJsonItemList() const { + return item_list; + } + /** + * @brief Get ignore item lists of JSON mnapping. + * Ignore the target variable at Serialize. + * @return Item list of JSON mapping. + * @see cfd::core::JsonClassBase::GetIgnoreItem() + */ + virtual const std::set& GetIgnoreItem() const { + return ignore_items; + } + + private: + /** + * @brief JsonFunctionMap table + */ + static AddScriptHashSignRequestMapTable json_mapper; + /** + * @brief field name list. + */ + static std::vector item_list; + /** + * @brief ignore item list. + */ + std::set ignore_items; + + /** + * @brief JsonAPI(isElements) value + */ + bool is_elements_ = false; + /** + * @brief JsonAPI(tx) value + */ + std::string tx_ = ""; + /** + * @brief JsonAPI(txin) value + */ + AddScriptHashSignTxInRequest txin_; // NOLINT +}; + +// ------------------------------------------------------------------------ +// AddScriptHashSignResponse +// ------------------------------------------------------------------------ +/** + * @brief JSON-API (AddScriptHashSignResponse) class + */ +class AddScriptHashSignResponse + : public cfd::core::JsonClassBase { + public: + AddScriptHashSignResponse() { + CollectFieldName(); + } + virtual ~AddScriptHashSignResponse() { + // do nothing + } + /** + * @brief collect field name. + */ + static void CollectFieldName(); + + /** + * @brief Get of hex + * @return hex + */ + std::string GetHex() const { + return hex_; + } + /** + * @brief Set to hex + * @param[in] hex setting value. + */ + void SetHex( // line separate + const std::string& hex) { // NOLINT + this->hex_ = hex; + } + /** + * @brief Get data type of hex + * @return Data type of hex + */ + static std::string GetHexFieldType() { + return "std::string"; + } + /** + * @brief Get json string of hex field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetHexString( // line separate + const AddScriptHashSignResponse& obj) { // NOLINT + return cfd::core::ConvertToString(obj.hex_); + } + /** + * @brief Set json object to hex field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetHexString( // line separate + AddScriptHashSignResponse& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.hex_, json_value); + } + + /** + * @brief Set ignore item. + * @param[in] key ignore target key name. + */ + void SetIgnoreItem(const std::string& key) { + ignore_items.insert(key); + } + + /** + * @brief Convert struct to class. + * @param[in] data struct data. + */ + void ConvertFromStruct( + const AddScriptHashSignResponseStruct& data); + + /** + * @brief Convert class to struct. + * @return struct data. + */ + AddScriptHashSignResponseStruct ConvertToStruct() const; + + protected: + /** + * @brief definition type of Map table. + */ + using AddScriptHashSignResponseMapTable = + cfd::core::JsonTableMap; + + /** + * @brief Get JSON mapping object. + * @return JSON mapping object. + * @see cfd::core::JsonClassBase::GetJsonMapper() + */ + virtual const AddScriptHashSignResponseMapTable& GetJsonMapper() const { // NOLINT + return json_mapper; + } + /** + * @brief Get item lists of JSON mapping. + * Fetch a list of target variable names in the order of definition. + * @return Item lists of JSON mapping. + * @see cfd::core::JsonClassBase::GetJsonItemList() + */ + virtual const std::vector& GetJsonItemList() const { + return item_list; + } + /** + * @brief Get ignore item lists of JSON mnapping. + * Ignore the target variable at Serialize. + * @return Item list of JSON mapping. + * @see cfd::core::JsonClassBase::GetIgnoreItem() + */ + virtual const std::set& GetIgnoreItem() const { + return ignore_items; + } + + private: + /** + * @brief JsonFunctionMap table + */ + static AddScriptHashSignResponseMapTable json_mapper; + /** + * @brief field name list. + */ + static std::vector item_list; + /** + * @brief ignore item list. + */ + std::set ignore_items; + + /** + * @brief JsonAPI(hex) value + */ + std::string hex_ = ""; +}; + +// ------------------------------------------------------------------------ +// SignData +// ------------------------------------------------------------------------ +/** + * @brief JSON-API (SignData) class + */ +class SignData + : public cfd::core::JsonClassBase { + public: + SignData() { + CollectFieldName(); + } + virtual ~SignData() { + // do nothing + } + /** + * @brief collect field name. + */ + static void CollectFieldName(); + + /** + * @brief Get of hex + * @return hex + */ + std::string GetHex() const { + return hex_; + } + /** + * @brief Set to hex + * @param[in] hex setting value. + */ + void SetHex( // line separate + const std::string& hex) { // NOLINT + this->hex_ = hex; + } + /** + * @brief Get data type of hex + * @return Data type of hex + */ + static std::string GetHexFieldType() { + return "std::string"; + } + /** + * @brief Get json string of hex field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetHexString( // line separate + const SignData& obj) { // NOLINT + return cfd::core::ConvertToString(obj.hex_); + } + /** + * @brief Set json object to hex field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetHexString( // line separate + SignData& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.hex_, json_value); + } + + /** + * @brief Get of type + * @return type + */ + std::string GetType() const { + return type_; + } + /** + * @brief Set to type + * @param[in] type setting value. + */ + void SetType( // line separate + const std::string& type) { // NOLINT + this->type_ = type; + } + /** + * @brief Get data type of type + * @return Data type of type + */ + static std::string GetTypeFieldType() { + return "std::string"; + } + /** + * @brief Get json string of type field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetTypeString( // line separate + const SignData& obj) { // NOLINT + return cfd::core::ConvertToString(obj.type_); + } + /** + * @brief Set json object to type field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetTypeString( // line separate + SignData& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.type_, json_value); + } + + /** + * @brief Get of derEncode + * @return derEncode + */ + bool GetDerEncode() const { + return der_encode_; + } + /** + * @brief Set to derEncode + * @param[in] der_encode setting value. + */ + void SetDerEncode( // line separate + const bool& der_encode) { // NOLINT + this->der_encode_ = der_encode; + } + /** + * @brief Get data type of derEncode + * @return Data type of derEncode + */ + static std::string GetDerEncodeFieldType() { + return "bool"; + } + /** + * @brief Get json string of derEncode field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetDerEncodeString( // line separate + const SignData& obj) { // NOLINT + return cfd::core::ConvertToString(obj.der_encode_); + } + /** + * @brief Set json object to derEncode field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetDerEncodeString( // line separate + SignData& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.der_encode_, json_value); + } + + /** + * @brief Get of sighashType + * @return sighashType + */ + std::string GetSighashType() const { + return sighash_type_; + } + /** + * @brief Set to sighashType + * @param[in] sighash_type setting value. + */ + void SetSighashType( // line separate + const std::string& sighash_type) { // NOLINT + this->sighash_type_ = sighash_type; + } + /** + * @brief Get data type of sighashType + * @return Data type of sighashType + */ + static std::string GetSighashTypeFieldType() { + return "std::string"; + } + /** + * @brief Get json string of sighashType field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetSighashTypeString( // line separate + const SignData& obj) { // NOLINT + return cfd::core::ConvertToString(obj.sighash_type_); + } + /** + * @brief Set json object to sighashType field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetSighashTypeString( // line separate + SignData& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.sighash_type_, json_value); + } + + /** + * @brief Get of sighashAnyoneCanPay + * @return sighashAnyoneCanPay + */ + bool GetSighashAnyoneCanPay() const { + return sighash_anyone_can_pay_; + } + /** + * @brief Set to sighashAnyoneCanPay + * @param[in] sighash_anyone_can_pay setting value. + */ + void SetSighashAnyoneCanPay( // line separate + const bool& sighash_anyone_can_pay) { // NOLINT + this->sighash_anyone_can_pay_ = sighash_anyone_can_pay; + } + /** + * @brief Get data type of sighashAnyoneCanPay + * @return Data type of sighashAnyoneCanPay + */ + static std::string GetSighashAnyoneCanPayFieldType() { + return "bool"; + } + /** + * @brief Get json string of sighashAnyoneCanPay field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetSighashAnyoneCanPayString( // line separate + const SignData& obj) { // NOLINT + return cfd::core::ConvertToString(obj.sighash_anyone_can_pay_); + } + /** + * @brief Set json object to sighashAnyoneCanPay field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetSighashAnyoneCanPayString( // line separate + SignData& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.sighash_anyone_can_pay_, json_value); + } + + /** + * @brief Set ignore item. + * @param[in] key ignore target key name. + */ + void SetIgnoreItem(const std::string& key) { + ignore_items.insert(key); + } + + /** + * @brief Convert struct to class. + * @param[in] data struct data. + */ + void ConvertFromStruct( + const SignDataStruct& data); + + /** + * @brief Convert class to struct. + * @return struct data. + */ + SignDataStruct ConvertToStruct() const; + + protected: + /** + * @brief definition type of Map table. + */ + using SignDataMapTable = + cfd::core::JsonTableMap; + + /** + * @brief Get JSON mapping object. + * @return JSON mapping object. + * @see cfd::core::JsonClassBase::GetJsonMapper() + */ + virtual const SignDataMapTable& GetJsonMapper() const { // NOLINT + return json_mapper; + } + /** + * @brief Get item lists of JSON mapping. + * Fetch a list of target variable names in the order of definition. + * @return Item lists of JSON mapping. + * @see cfd::core::JsonClassBase::GetJsonItemList() + */ + virtual const std::vector& GetJsonItemList() const { + return item_list; + } + /** + * @brief Get ignore item lists of JSON mnapping. + * Ignore the target variable at Serialize. + * @return Item list of JSON mapping. + * @see cfd::core::JsonClassBase::GetIgnoreItem() + */ + virtual const std::set& GetIgnoreItem() const { + return ignore_items; + } + + private: + /** + * @brief JsonFunctionMap table + */ + static SignDataMapTable json_mapper; + /** + * @brief field name list. + */ + static std::vector item_list; + /** + * @brief ignore item list. + */ + std::set ignore_items; + + /** + * @brief JsonAPI(hex) value + */ + std::string hex_ = ""; + /** + * @brief JsonAPI(type) value + */ + std::string type_ = "auto"; + /** + * @brief JsonAPI(derEncode) value + */ + bool der_encode_ = false; + /** + * @brief JsonAPI(sighashType) value + */ + std::string sighash_type_ = "all"; + /** + * @brief JsonAPI(sighashAnyoneCanPay) value + */ + bool sighash_anyone_can_pay_ = false; +}; + +// ------------------------------------------------------------------------ +// AddSignTxInRequest +// ------------------------------------------------------------------------ +/** + * @brief JSON-API (AddSignTxInRequest) class + */ +class AddSignTxInRequest + : public cfd::core::JsonClassBase { + public: + AddSignTxInRequest() { + CollectFieldName(); + } + virtual ~AddSignTxInRequest() { + // do nothing + } + /** + * @brief collect field name. + */ + static void CollectFieldName(); + + /** + * @brief Get of txid + * @return txid + */ + std::string GetTxid() const { + return txid_; + } + /** + * @brief Set to txid + * @param[in] txid setting value. + */ + void SetTxid( // line separate + const std::string& txid) { // NOLINT + this->txid_ = txid; + } + /** + * @brief Get data type of txid + * @return Data type of txid + */ + static std::string GetTxidFieldType() { + return "std::string"; + } + /** + * @brief Get json string of txid field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetTxidString( // line separate + const AddSignTxInRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.txid_); + } + /** + * @brief Set json object to txid field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetTxidString( // line separate + AddSignTxInRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.txid_, json_value); + } + + /** + * @brief Get of vout + * @return vout + */ + uint32_t GetVout() const { + return vout_; + } + /** + * @brief Set to vout + * @param[in] vout setting value. + */ + void SetVout( // line separate + const uint32_t& vout) { // NOLINT + this->vout_ = vout; + } + /** + * @brief Get data type of vout + * @return Data type of vout + */ + static std::string GetVoutFieldType() { + return "uint32_t"; + } + /** + * @brief Get json string of vout field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetVoutString( // line separate + const AddSignTxInRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.vout_); + } + /** + * @brief Set json object to vout field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetVoutString( // line separate + AddSignTxInRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.vout_, json_value); + } + + /** + * @brief Get of isWitness + * @return isWitness + */ + bool GetIsWitness() const { + return is_witness_; + } + /** + * @brief Set to isWitness + * @param[in] is_witness setting value. + */ + void SetIsWitness( // line separate + const bool& is_witness) { // NOLINT + this->is_witness_ = is_witness; + } + /** + * @brief Get data type of isWitness + * @return Data type of isWitness + */ + static std::string GetIsWitnessFieldType() { + return "bool"; + } + /** + * @brief Get json string of isWitness field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetIsWitnessString( // line separate + const AddSignTxInRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.is_witness_); + } + /** + * @brief Set json object to isWitness field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetIsWitnessString( // line separate + AddSignTxInRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.is_witness_, json_value); + } + + /** + * @brief Get of signParam. + * @return signParam + */ + JsonObjectVector& GetSignParam() { // NOLINT + return sign_param_; + } + /** + * @brief Set to signParam. + * @param[in] sign_param setting value. + */ + void SetSignParam( // line separate + const JsonObjectVector& sign_param) { // NOLINT + this->sign_param_ = sign_param; + } + /** + * @brief Get data type of signParam. + * @return Data type of signParam. + */ + static std::string GetSignParamFieldType() { + return "JsonObjectVector"; // NOLINT + } + /** + * @brief Get json string of signParam field. + * @param[in,out] obj class object + * @return JSON string. + */ + static std::string GetSignParamString( // line separate + const AddSignTxInRequest& obj) { // NOLINT + // Do not set to const, because substitution of member variables + // may occur in pre / post processing inside Serialize + return obj.sign_param_.Serialize(); + } + /** + * @brief Set json object to signParam field. + * @param[in,out] obj class object + * @param[in] json_value JSON object + */ + static void SetSignParamString( // line separate + AddSignTxInRequest& obj, // NOLINT + const UniValue& json_value) { + obj.sign_param_.DeserializeUniValue(json_value); + } + + /** + * @brief Get of clearStack + * @return clearStack + */ + bool GetClearStack() const { + return clear_stack_; + } + /** + * @brief Set to clearStack + * @param[in] clear_stack setting value. + */ + void SetClearStack( // line separate + const bool& clear_stack) { // NOLINT + this->clear_stack_ = clear_stack; + } + /** + * @brief Get data type of clearStack + * @return Data type of clearStack + */ + static std::string GetClearStackFieldType() { + return "bool"; + } + /** + * @brief Get json string of clearStack field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetClearStackString( // line separate + const AddSignTxInRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.clear_stack_); + } + /** + * @brief Set json object to clearStack field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetClearStackString( // line separate + AddSignTxInRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.clear_stack_, json_value); + } + + /** + * @brief Set ignore item. + * @param[in] key ignore target key name. + */ + void SetIgnoreItem(const std::string& key) { + ignore_items.insert(key); + } + + /** + * @brief Convert struct to class. + * @param[in] data struct data. + */ + void ConvertFromStruct( + const AddSignTxInRequestStruct& data); + + /** + * @brief Convert class to struct. + * @return struct data. + */ + AddSignTxInRequestStruct ConvertToStruct() const; + + protected: + /** + * @brief definition type of Map table. + */ + using AddSignTxInRequestMapTable = + cfd::core::JsonTableMap; + + /** + * @brief Get JSON mapping object. + * @return JSON mapping object. + * @see cfd::core::JsonClassBase::GetJsonMapper() + */ + virtual const AddSignTxInRequestMapTable& GetJsonMapper() const { // NOLINT + return json_mapper; + } + /** + * @brief Get item lists of JSON mapping. + * Fetch a list of target variable names in the order of definition. + * @return Item lists of JSON mapping. + * @see cfd::core::JsonClassBase::GetJsonItemList() + */ + virtual const std::vector& GetJsonItemList() const { + return item_list; + } + /** + * @brief Get ignore item lists of JSON mnapping. + * Ignore the target variable at Serialize. + * @return Item list of JSON mapping. + * @see cfd::core::JsonClassBase::GetIgnoreItem() + */ + virtual const std::set& GetIgnoreItem() const { + return ignore_items; + } + + private: + /** + * @brief JsonFunctionMap table + */ + static AddSignTxInRequestMapTable json_mapper; + /** + * @brief field name list. + */ + static std::vector item_list; + /** + * @brief ignore item list. + */ + std::set ignore_items; + + /** + * @brief JsonAPI(txid) value + */ + std::string txid_ = ""; + /** + * @brief JsonAPI(vout) value + */ + uint32_t vout_ = 0; + /** + * @brief JsonAPI(isWitness) value + */ + bool is_witness_ = true; + /** + * @brief JsonAPI(signParam) value + */ + JsonObjectVector sign_param_; // NOLINT + /** + * @brief JsonAPI(clearStack) value + */ + bool clear_stack_ = true; +}; + +// ------------------------------------------------------------------------ +// AddSignRequest +// ------------------------------------------------------------------------ +/** + * @brief JSON-API (AddSignRequest) class + */ +class AddSignRequest + : public cfd::core::JsonClassBase { + public: + AddSignRequest() { + CollectFieldName(); + } + virtual ~AddSignRequest() { + // do nothing + } + /** + * @brief collect field name. + */ + static void CollectFieldName(); + + /** + * @brief Get of tx + * @return tx + */ + std::string GetTx() const { + return tx_; + } + /** + * @brief Set to tx + * @param[in] tx setting value. + */ + void SetTx( // line separate + const std::string& tx) { // NOLINT + this->tx_ = tx; + } + /** + * @brief Get data type of tx + * @return Data type of tx + */ + static std::string GetTxFieldType() { + return "std::string"; + } + /** + * @brief Get json string of tx field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetTxString( // line separate + const AddSignRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.tx_); + } + /** + * @brief Set json object to tx field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetTxString( // line separate + AddSignRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.tx_, json_value); + } + + /** + * @brief Get of isElements + * @return isElements + */ + bool GetIsElements() const { + return is_elements_; + } + /** + * @brief Set to isElements + * @param[in] is_elements setting value. + */ + void SetIsElements( // line separate + const bool& is_elements) { // NOLINT + this->is_elements_ = is_elements; + } + /** + * @brief Get data type of isElements + * @return Data type of isElements + */ + static std::string GetIsElementsFieldType() { + return "bool"; + } + /** + * @brief Get json string of isElements field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetIsElementsString( // line separate + const AddSignRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.is_elements_); + } + /** + * @brief Set json object to isElements field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetIsElementsString( // line separate + AddSignRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.is_elements_, json_value); + } + + /** + * @brief Get of txin. + * @return txin + */ + AddSignTxInRequest& GetTxin() { // NOLINT + return txin_; + } + /** + * @brief Set to txin. + * @param[in] txin setting value. + */ + void SetTxin( // line separate + const AddSignTxInRequest& txin) { // NOLINT + this->txin_ = txin; + } + /** + * @brief Get data type of txin. + * @return Data type of txin. + */ + static std::string GetTxinFieldType() { + return "AddSignTxInRequest"; // NOLINT + } + /** + * @brief Get json string of txin field. + * @param[in,out] obj class object + * @return JSON string. + */ + static std::string GetTxinString( // line separate + const AddSignRequest& obj) { // NOLINT + // Do not set to const, because substitution of member variables + // may occur in pre / post processing inside Serialize + return obj.txin_.Serialize(); + } + /** + * @brief Set json object to txin field. + * @param[in,out] obj class object + * @param[in] json_value JSON object + */ + static void SetTxinString( // line separate + AddSignRequest& obj, // NOLINT + const UniValue& json_value) { + obj.txin_.DeserializeUniValue(json_value); + } + + /** + * @brief Set ignore item. + * @param[in] key ignore target key name. + */ + void SetIgnoreItem(const std::string& key) { + ignore_items.insert(key); + } + + /** + * @brief Convert struct to class. + * @param[in] data struct data. + */ + void ConvertFromStruct( + const AddSignRequestStruct& data); + + /** + * @brief Convert class to struct. + * @return struct data. + */ + AddSignRequestStruct ConvertToStruct() const; + + protected: + /** + * @brief definition type of Map table. + */ + using AddSignRequestMapTable = + cfd::core::JsonTableMap; + + /** + * @brief Get JSON mapping object. + * @return JSON mapping object. + * @see cfd::core::JsonClassBase::GetJsonMapper() + */ + virtual const AddSignRequestMapTable& GetJsonMapper() const { // NOLINT return json_mapper; } /** @@ -6526,7 +7550,471 @@ class CalculateEcSignatureResponse /** * @brief JsonFunctionMap table */ - static CalculateEcSignatureResponseMapTable json_mapper; + static CalculateEcSignatureResponseMapTable json_mapper; + /** + * @brief field name list. + */ + static std::vector item_list; + /** + * @brief ignore item list. + */ + std::set ignore_items; + + /** + * @brief JsonAPI(signature) value + */ + std::string signature_ = ""; +}; + +// ------------------------------------------------------------------------ +// ConvertAesRequest +// ------------------------------------------------------------------------ +/** + * @brief JSON-API (ConvertAesRequest) class + */ +class ConvertAesRequest + : public cfd::core::JsonClassBase { + public: + ConvertAesRequest() { + CollectFieldName(); + } + virtual ~ConvertAesRequest() { + // do nothing + } + /** + * @brief collect field name. + */ + static void CollectFieldName(); + + /** + * @brief Get of isEncrypt + * @return isEncrypt + */ + bool GetIsEncrypt() const { + return is_encrypt_; + } + /** + * @brief Set to isEncrypt + * @param[in] is_encrypt setting value. + */ + void SetIsEncrypt( // line separate + const bool& is_encrypt) { // NOLINT + this->is_encrypt_ = is_encrypt; + } + /** + * @brief Get data type of isEncrypt + * @return Data type of isEncrypt + */ + static std::string GetIsEncryptFieldType() { + return "bool"; + } + /** + * @brief Get json string of isEncrypt field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetIsEncryptString( // line separate + const ConvertAesRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.is_encrypt_); + } + /** + * @brief Set json object to isEncrypt field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetIsEncryptString( // line separate + ConvertAesRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.is_encrypt_, json_value); + } + + /** + * @brief Get of mode + * @return mode + */ + std::string GetMode() const { + return mode_; + } + /** + * @brief Set to mode + * @param[in] mode setting value. + */ + void SetMode( // line separate + const std::string& mode) { // NOLINT + this->mode_ = mode; + } + /** + * @brief Get data type of mode + * @return Data type of mode + */ + static std::string GetModeFieldType() { + return "std::string"; + } + /** + * @brief Get json string of mode field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetModeString( // line separate + const ConvertAesRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.mode_); + } + /** + * @brief Set json object to mode field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetModeString( // line separate + ConvertAesRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.mode_, json_value); + } + + /** + * @brief Get of key + * @return key + */ + std::string GetKey() const { + return key_; + } + /** + * @brief Set to key + * @param[in] key setting value. + */ + void SetKey( // line separate + const std::string& key) { // NOLINT + this->key_ = key; + } + /** + * @brief Get data type of key + * @return Data type of key + */ + static std::string GetKeyFieldType() { + return "std::string"; + } + /** + * @brief Get json string of key field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetKeyString( // line separate + const ConvertAesRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.key_); + } + /** + * @brief Set json object to key field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetKeyString( // line separate + ConvertAesRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.key_, json_value); + } + + /** + * @brief Get of iv + * @return iv + */ + std::string GetIv() const { + return iv_; + } + /** + * @brief Set to iv + * @param[in] iv setting value. + */ + void SetIv( // line separate + const std::string& iv) { // NOLINT + this->iv_ = iv; + } + /** + * @brief Get data type of iv + * @return Data type of iv + */ + static std::string GetIvFieldType() { + return "std::string"; + } + /** + * @brief Get json string of iv field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetIvString( // line separate + const ConvertAesRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.iv_); + } + /** + * @brief Set json object to iv field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetIvString( // line separate + ConvertAesRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.iv_, json_value); + } + + /** + * @brief Get of data + * @return data + */ + std::string GetData() const { + return data_; + } + /** + * @brief Set to data + * @param[in] data setting value. + */ + void SetData( // line separate + const std::string& data) { // NOLINT + this->data_ = data; + } + /** + * @brief Get data type of data + * @return Data type of data + */ + static std::string GetDataFieldType() { + return "std::string"; + } + /** + * @brief Get json string of data field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetDataString( // line separate + const ConvertAesRequest& obj) { // NOLINT + return cfd::core::ConvertToString(obj.data_); + } + /** + * @brief Set json object to data field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetDataString( // line separate + ConvertAesRequest& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.data_, json_value); + } + + /** + * @brief Set ignore item. + * @param[in] key ignore target key name. + */ + void SetIgnoreItem(const std::string& key) { + ignore_items.insert(key); + } + + /** + * @brief Convert struct to class. + * @param[in] data struct data. + */ + void ConvertFromStruct( + const ConvertAesRequestStruct& data); + + /** + * @brief Convert class to struct. + * @return struct data. + */ + ConvertAesRequestStruct ConvertToStruct() const; + + protected: + /** + * @brief definition type of Map table. + */ + using ConvertAesRequestMapTable = + cfd::core::JsonTableMap; + + /** + * @brief Get JSON mapping object. + * @return JSON mapping object. + * @see cfd::core::JsonClassBase::GetJsonMapper() + */ + virtual const ConvertAesRequestMapTable& GetJsonMapper() const { // NOLINT + return json_mapper; + } + /** + * @brief Get item lists of JSON mapping. + * Fetch a list of target variable names in the order of definition. + * @return Item lists of JSON mapping. + * @see cfd::core::JsonClassBase::GetJsonItemList() + */ + virtual const std::vector& GetJsonItemList() const { + return item_list; + } + /** + * @brief Get ignore item lists of JSON mnapping. + * Ignore the target variable at Serialize. + * @return Item list of JSON mapping. + * @see cfd::core::JsonClassBase::GetIgnoreItem() + */ + virtual const std::set& GetIgnoreItem() const { + return ignore_items; + } + + private: + /** + * @brief JsonFunctionMap table + */ + static ConvertAesRequestMapTable json_mapper; + /** + * @brief field name list. + */ + static std::vector item_list; + /** + * @brief ignore item list. + */ + std::set ignore_items; + + /** + * @brief JsonAPI(isEncrypt) value + */ + bool is_encrypt_ = true; + /** + * @brief JsonAPI(mode) value + */ + std::string mode_ = "cbc"; + /** + * @brief JsonAPI(key) value + */ + std::string key_ = ""; + /** + * @brief JsonAPI(iv) value + */ + std::string iv_ = ""; + /** + * @brief JsonAPI(data) value + */ + std::string data_ = ""; +}; + +// ------------------------------------------------------------------------ +// ConvertAesResponse +// ------------------------------------------------------------------------ +/** + * @brief JSON-API (ConvertAesResponse) class + */ +class ConvertAesResponse + : public cfd::core::JsonClassBase { + public: + ConvertAesResponse() { + CollectFieldName(); + } + virtual ~ConvertAesResponse() { + // do nothing + } + /** + * @brief collect field name. + */ + static void CollectFieldName(); + + /** + * @brief Get of hex + * @return hex + */ + std::string GetHex() const { + return hex_; + } + /** + * @brief Set to hex + * @param[in] hex setting value. + */ + void SetHex( // line separate + const std::string& hex) { // NOLINT + this->hex_ = hex; + } + /** + * @brief Get data type of hex + * @return Data type of hex + */ + static std::string GetHexFieldType() { + return "std::string"; + } + /** + * @brief Get json string of hex field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetHexString( // line separate + const ConvertAesResponse& obj) { // NOLINT + return cfd::core::ConvertToString(obj.hex_); + } + /** + * @brief Set json object to hex field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetHexString( // line separate + ConvertAesResponse& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.hex_, json_value); + } + + /** + * @brief Set ignore item. + * @param[in] key ignore target key name. + */ + void SetIgnoreItem(const std::string& key) { + ignore_items.insert(key); + } + + /** + * @brief Convert struct to class. + * @param[in] data struct data. + */ + void ConvertFromStruct( + const ConvertAesResponseStruct& data); + + /** + * @brief Convert class to struct. + * @return struct data. + */ + ConvertAesResponseStruct ConvertToStruct() const; + + protected: + /** + * @brief definition type of Map table. + */ + using ConvertAesResponseMapTable = + cfd::core::JsonTableMap; + + /** + * @brief Get JSON mapping object. + * @return JSON mapping object. + * @see cfd::core::JsonClassBase::GetJsonMapper() + */ + virtual const ConvertAesResponseMapTable& GetJsonMapper() const { // NOLINT + return json_mapper; + } + /** + * @brief Get item lists of JSON mapping. + * Fetch a list of target variable names in the order of definition. + * @return Item lists of JSON mapping. + * @see cfd::core::JsonClassBase::GetJsonItemList() + */ + virtual const std::vector& GetJsonItemList() const { + return item_list; + } + /** + * @brief Get ignore item lists of JSON mnapping. + * Ignore the target variable at Serialize. + * @return Item list of JSON mapping. + * @see cfd::core::JsonClassBase::GetIgnoreItem() + */ + virtual const std::set& GetIgnoreItem() const { + return ignore_items; + } + + private: + /** + * @brief JsonFunctionMap table + */ + static ConvertAesResponseMapTable json_mapper; /** * @brief field name list. */ @@ -6537,9 +8025,9 @@ class CalculateEcSignatureResponse std::set ignore_items; /** - * @brief JsonAPI(signature) value + * @brief JsonAPI(hex) value */ - std::string signature_ = ""; + std::string hex_ = ""; }; // ------------------------------------------------------------------------ @@ -12901,6 +14389,329 @@ class CreateScriptResponse std::string hex_ = ""; }; +// ------------------------------------------------------------------------ +// DecodeBase58Request +// ------------------------------------------------------------------------ +/** + * @brief JSON-API (DecodeBase58Request) class + */ +class DecodeBase58Request + : public cfd::core::JsonClassBase { + public: + DecodeBase58Request() { + CollectFieldName(); + } + virtual ~DecodeBase58Request() { + // do nothing + } + /** + * @brief collect field name. + */ + static void CollectFieldName(); + + /** + * @brief Get of data + * @return data + */ + std::string GetData() const { + return data_; + } + /** + * @brief Set to data + * @param[in] data setting value. + */ + void SetData( // line separate + const std::string& data) { // NOLINT + this->data_ = data; + } + /** + * @brief Get data type of data + * @return Data type of data + */ + static std::string GetDataFieldType() { + return "std::string"; + } + /** + * @brief Get json string of data field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetDataString( // line separate + const DecodeBase58Request& obj) { // NOLINT + return cfd::core::ConvertToString(obj.data_); + } + /** + * @brief Set json object to data field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetDataString( // line separate + DecodeBase58Request& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.data_, json_value); + } + + /** + * @brief Get of hasChecksum + * @return hasChecksum + */ + bool GetHasChecksum() const { + return has_checksum_; + } + /** + * @brief Set to hasChecksum + * @param[in] has_checksum setting value. + */ + void SetHasChecksum( // line separate + const bool& has_checksum) { // NOLINT + this->has_checksum_ = has_checksum; + } + /** + * @brief Get data type of hasChecksum + * @return Data type of hasChecksum + */ + static std::string GetHasChecksumFieldType() { + return "bool"; + } + /** + * @brief Get json string of hasChecksum field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetHasChecksumString( // line separate + const DecodeBase58Request& obj) { // NOLINT + return cfd::core::ConvertToString(obj.has_checksum_); + } + /** + * @brief Set json object to hasChecksum field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetHasChecksumString( // line separate + DecodeBase58Request& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.has_checksum_, json_value); + } + + /** + * @brief Set ignore item. + * @param[in] key ignore target key name. + */ + void SetIgnoreItem(const std::string& key) { + ignore_items.insert(key); + } + + /** + * @brief Convert struct to class. + * @param[in] data struct data. + */ + void ConvertFromStruct( + const DecodeBase58RequestStruct& data); + + /** + * @brief Convert class to struct. + * @return struct data. + */ + DecodeBase58RequestStruct ConvertToStruct() const; + + protected: + /** + * @brief definition type of Map table. + */ + using DecodeBase58RequestMapTable = + cfd::core::JsonTableMap; + + /** + * @brief Get JSON mapping object. + * @return JSON mapping object. + * @see cfd::core::JsonClassBase::GetJsonMapper() + */ + virtual const DecodeBase58RequestMapTable& GetJsonMapper() const { // NOLINT + return json_mapper; + } + /** + * @brief Get item lists of JSON mapping. + * Fetch a list of target variable names in the order of definition. + * @return Item lists of JSON mapping. + * @see cfd::core::JsonClassBase::GetJsonItemList() + */ + virtual const std::vector& GetJsonItemList() const { + return item_list; + } + /** + * @brief Get ignore item lists of JSON mnapping. + * Ignore the target variable at Serialize. + * @return Item list of JSON mapping. + * @see cfd::core::JsonClassBase::GetIgnoreItem() + */ + virtual const std::set& GetIgnoreItem() const { + return ignore_items; + } + + private: + /** + * @brief JsonFunctionMap table + */ + static DecodeBase58RequestMapTable json_mapper; + /** + * @brief field name list. + */ + static std::vector item_list; + /** + * @brief ignore item list. + */ + std::set ignore_items; + + /** + * @brief JsonAPI(data) value + */ + std::string data_ = ""; + /** + * @brief JsonAPI(hasChecksum) value + */ + bool has_checksum_ = true; +}; + +// ------------------------------------------------------------------------ +// DecodeBase58Response +// ------------------------------------------------------------------------ +/** + * @brief JSON-API (DecodeBase58Response) class + */ +class DecodeBase58Response + : public cfd::core::JsonClassBase { + public: + DecodeBase58Response() { + CollectFieldName(); + } + virtual ~DecodeBase58Response() { + // do nothing + } + /** + * @brief collect field name. + */ + static void CollectFieldName(); + + /** + * @brief Get of hex + * @return hex + */ + std::string GetHex() const { + return hex_; + } + /** + * @brief Set to hex + * @param[in] hex setting value. + */ + void SetHex( // line separate + const std::string& hex) { // NOLINT + this->hex_ = hex; + } + /** + * @brief Get data type of hex + * @return Data type of hex + */ + static std::string GetHexFieldType() { + return "std::string"; + } + /** + * @brief Get json string of hex field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetHexString( // line separate + const DecodeBase58Response& obj) { // NOLINT + return cfd::core::ConvertToString(obj.hex_); + } + /** + * @brief Set json object to hex field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetHexString( // line separate + DecodeBase58Response& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.hex_, json_value); + } + + /** + * @brief Set ignore item. + * @param[in] key ignore target key name. + */ + void SetIgnoreItem(const std::string& key) { + ignore_items.insert(key); + } + + /** + * @brief Convert struct to class. + * @param[in] data struct data. + */ + void ConvertFromStruct( + const DecodeBase58ResponseStruct& data); + + /** + * @brief Convert class to struct. + * @return struct data. + */ + DecodeBase58ResponseStruct ConvertToStruct() const; + + protected: + /** + * @brief definition type of Map table. + */ + using DecodeBase58ResponseMapTable = + cfd::core::JsonTableMap; + + /** + * @brief Get JSON mapping object. + * @return JSON mapping object. + * @see cfd::core::JsonClassBase::GetJsonMapper() + */ + virtual const DecodeBase58ResponseMapTable& GetJsonMapper() const { // NOLINT + return json_mapper; + } + /** + * @brief Get item lists of JSON mapping. + * Fetch a list of target variable names in the order of definition. + * @return Item lists of JSON mapping. + * @see cfd::core::JsonClassBase::GetJsonItemList() + */ + virtual const std::vector& GetJsonItemList() const { + return item_list; + } + /** + * @brief Get ignore item lists of JSON mnapping. + * Ignore the target variable at Serialize. + * @return Item list of JSON mapping. + * @see cfd::core::JsonClassBase::GetIgnoreItem() + */ + virtual const std::set& GetIgnoreItem() const { + return ignore_items; + } + + private: + /** + * @brief JsonFunctionMap table + */ + static DecodeBase58ResponseMapTable json_mapper; + /** + * @brief field name list. + */ + static std::vector item_list; + /** + * @brief ignore item list. + */ + std::set ignore_items; + + /** + * @brief JsonAPI(hex) value + */ + std::string hex_ = ""; +}; + // ------------------------------------------------------------------------ // DecodeDerSignatureToRawRequest // ------------------------------------------------------------------------ @@ -33473,6 +35284,329 @@ class UnblindRawTransactionResponse JsonObjectVector issuance_outputs_; // NOLINT }; +// ------------------------------------------------------------------------ +// EncodeBase58Request +// ------------------------------------------------------------------------ +/** + * @brief JSON-API (EncodeBase58Request) class + */ +class EncodeBase58Request + : public cfd::core::JsonClassBase { + public: + EncodeBase58Request() { + CollectFieldName(); + } + virtual ~EncodeBase58Request() { + // do nothing + } + /** + * @brief collect field name. + */ + static void CollectFieldName(); + + /** + * @brief Get of hex + * @return hex + */ + std::string GetHex() const { + return hex_; + } + /** + * @brief Set to hex + * @param[in] hex setting value. + */ + void SetHex( // line separate + const std::string& hex) { // NOLINT + this->hex_ = hex; + } + /** + * @brief Get data type of hex + * @return Data type of hex + */ + static std::string GetHexFieldType() { + return "std::string"; + } + /** + * @brief Get json string of hex field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetHexString( // line separate + const EncodeBase58Request& obj) { // NOLINT + return cfd::core::ConvertToString(obj.hex_); + } + /** + * @brief Set json object to hex field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetHexString( // line separate + EncodeBase58Request& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.hex_, json_value); + } + + /** + * @brief Get of hasChecksum + * @return hasChecksum + */ + bool GetHasChecksum() const { + return has_checksum_; + } + /** + * @brief Set to hasChecksum + * @param[in] has_checksum setting value. + */ + void SetHasChecksum( // line separate + const bool& has_checksum) { // NOLINT + this->has_checksum_ = has_checksum; + } + /** + * @brief Get data type of hasChecksum + * @return Data type of hasChecksum + */ + static std::string GetHasChecksumFieldType() { + return "bool"; + } + /** + * @brief Get json string of hasChecksum field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetHasChecksumString( // line separate + const EncodeBase58Request& obj) { // NOLINT + return cfd::core::ConvertToString(obj.has_checksum_); + } + /** + * @brief Set json object to hasChecksum field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetHasChecksumString( // line separate + EncodeBase58Request& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.has_checksum_, json_value); + } + + /** + * @brief Set ignore item. + * @param[in] key ignore target key name. + */ + void SetIgnoreItem(const std::string& key) { + ignore_items.insert(key); + } + + /** + * @brief Convert struct to class. + * @param[in] data struct data. + */ + void ConvertFromStruct( + const EncodeBase58RequestStruct& data); + + /** + * @brief Convert class to struct. + * @return struct data. + */ + EncodeBase58RequestStruct ConvertToStruct() const; + + protected: + /** + * @brief definition type of Map table. + */ + using EncodeBase58RequestMapTable = + cfd::core::JsonTableMap; + + /** + * @brief Get JSON mapping object. + * @return JSON mapping object. + * @see cfd::core::JsonClassBase::GetJsonMapper() + */ + virtual const EncodeBase58RequestMapTable& GetJsonMapper() const { // NOLINT + return json_mapper; + } + /** + * @brief Get item lists of JSON mapping. + * Fetch a list of target variable names in the order of definition. + * @return Item lists of JSON mapping. + * @see cfd::core::JsonClassBase::GetJsonItemList() + */ + virtual const std::vector& GetJsonItemList() const { + return item_list; + } + /** + * @brief Get ignore item lists of JSON mnapping. + * Ignore the target variable at Serialize. + * @return Item list of JSON mapping. + * @see cfd::core::JsonClassBase::GetIgnoreItem() + */ + virtual const std::set& GetIgnoreItem() const { + return ignore_items; + } + + private: + /** + * @brief JsonFunctionMap table + */ + static EncodeBase58RequestMapTable json_mapper; + /** + * @brief field name list. + */ + static std::vector item_list; + /** + * @brief ignore item list. + */ + std::set ignore_items; + + /** + * @brief JsonAPI(hex) value + */ + std::string hex_ = ""; + /** + * @brief JsonAPI(hasChecksum) value + */ + bool has_checksum_ = true; +}; + +// ------------------------------------------------------------------------ +// EncodeBase58Response +// ------------------------------------------------------------------------ +/** + * @brief JSON-API (EncodeBase58Response) class + */ +class EncodeBase58Response + : public cfd::core::JsonClassBase { + public: + EncodeBase58Response() { + CollectFieldName(); + } + virtual ~EncodeBase58Response() { + // do nothing + } + /** + * @brief collect field name. + */ + static void CollectFieldName(); + + /** + * @brief Get of data + * @return data + */ + std::string GetData() const { + return data_; + } + /** + * @brief Set to data + * @param[in] data setting value. + */ + void SetData( // line separate + const std::string& data) { // NOLINT + this->data_ = data; + } + /** + * @brief Get data type of data + * @return Data type of data + */ + static std::string GetDataFieldType() { + return "std::string"; + } + /** + * @brief Get json string of data field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetDataString( // line separate + const EncodeBase58Response& obj) { // NOLINT + return cfd::core::ConvertToString(obj.data_); + } + /** + * @brief Set json object to data field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetDataString( // line separate + EncodeBase58Response& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.data_, json_value); + } + + /** + * @brief Set ignore item. + * @param[in] key ignore target key name. + */ + void SetIgnoreItem(const std::string& key) { + ignore_items.insert(key); + } + + /** + * @brief Convert struct to class. + * @param[in] data struct data. + */ + void ConvertFromStruct( + const EncodeBase58ResponseStruct& data); + + /** + * @brief Convert class to struct. + * @return struct data. + */ + EncodeBase58ResponseStruct ConvertToStruct() const; + + protected: + /** + * @brief definition type of Map table. + */ + using EncodeBase58ResponseMapTable = + cfd::core::JsonTableMap; + + /** + * @brief Get JSON mapping object. + * @return JSON mapping object. + * @see cfd::core::JsonClassBase::GetJsonMapper() + */ + virtual const EncodeBase58ResponseMapTable& GetJsonMapper() const { // NOLINT + return json_mapper; + } + /** + * @brief Get item lists of JSON mapping. + * Fetch a list of target variable names in the order of definition. + * @return Item lists of JSON mapping. + * @see cfd::core::JsonClassBase::GetJsonItemList() + */ + virtual const std::vector& GetJsonItemList() const { + return item_list; + } + /** + * @brief Get ignore item lists of JSON mnapping. + * Ignore the target variable at Serialize. + * @return Item list of JSON mapping. + * @see cfd::core::JsonClassBase::GetIgnoreItem() + */ + virtual const std::set& GetIgnoreItem() const { + return ignore_items; + } + + private: + /** + * @brief JsonFunctionMap table + */ + static EncodeBase58ResponseMapTable json_mapper; + /** + * @brief field name list. + */ + static std::vector item_list; + /** + * @brief ignore item list. + */ + std::set ignore_items; + + /** + * @brief JsonAPI(data) value + */ + std::string data_ = ""; +}; + // ------------------------------------------------------------------------ // EncodeSignatureByDerRequest // ------------------------------------------------------------------------ @@ -54548,6 +56682,49 @@ class FailSignTxIn obj.vout_, json_value); } + /** + * @brief Get of reason + * @return reason + */ + std::string GetReason() const { + return reason_; + } + /** + * @brief Set to reason + * @param[in] reason setting value. + */ + void SetReason( // line separate + const std::string& reason) { // NOLINT + this->reason_ = reason; + } + /** + * @brief Get data type of reason + * @return Data type of reason + */ + static std::string GetReasonFieldType() { + return "std::string"; + } + /** + * @brief Get json string of reason field. + * @param[in,out] obj class object. + * @return JSON string + */ + static std::string GetReasonString( // line separate + const FailSignTxIn& obj) { // NOLINT + return cfd::core::ConvertToString(obj.reason_); + } + /** + * @brief Set json object to reason field. + * @param[in,out] obj class object. + * @param[in] json_value JSON object. + */ + static void SetReasonString( // line separate + FailSignTxIn& obj, // NOLINT + const UniValue& json_value) { + cfd::core::ConvertFromUniValue( // line separate + obj.reason_, json_value); + } + /** * @brief Set ignore item. * @param[in] key ignore target key name. @@ -54625,6 +56802,10 @@ class FailSignTxIn * @brief JsonAPI(vout) value */ uint32_t vout_ = 0; + /** + * @brief JsonAPI(reason) value + */ + std::string reason_ = ""; }; // ------------------------------------------------------------------------ diff --git a/src/cfdapi_error_json.cpp b/src/cfdapi_error_json.cpp index 484438fa..b8c9ab4b 100644 --- a/src/cfdapi_error_json.cpp +++ b/src/cfdapi_error_json.cpp @@ -5,9 +5,10 @@ * @brief JSONマッピングファイル */ +#include "cfdapi_error_json.h" // NOLINT + #include -#include "cfdapi_error_json.h" // NOLINT #include "cfdcore/cfdcore_exception.h" namespace cfd { diff --git a/src/cfdapi_select_utxos_wrapper_json.cpp b/src/cfdapi_select_utxos_wrapper_json.cpp index 597c216c..3bcaf776 100644 --- a/src/cfdapi_select_utxos_wrapper_json.cpp +++ b/src/cfdapi_select_utxos_wrapper_json.cpp @@ -4,14 +4,14 @@ * * @brief json mapping override file. */ +#include "cfdapi_select_utxos_wrapper_json.h" // NOLINT + #include #include #include #include #include -#include "cfdapi_select_utxos_wrapper_json.h" // NOLINT - #include "cfdcore/cfdcore_elements_transaction.h" namespace cfd { diff --git a/src/cfdapi_select_utxos_wrapper_json.h b/src/cfdapi_select_utxos_wrapper_json.h index 8cf633b9..d750ea9e 100644 --- a/src/cfdapi_select_utxos_wrapper_json.h +++ b/src/cfdapi_select_utxos_wrapper_json.h @@ -9,6 +9,7 @@ #include #include + #include "cfd/cfd_utxo.h" #include "cfd_js_api_json_autogen.h" // NOLINT #include "cfdjs/cfdjs_struct.h" diff --git a/src/cfdjs_coin.cpp b/src/cfdjs_coin.cpp index 543f77a2..2bb56faa 100644 --- a/src/cfdjs_coin.cpp +++ b/src/cfdjs_coin.cpp @@ -4,13 +4,14 @@ * * @brief cfd-apiで利用するCoin操作の実装ファイル */ +#include "cfdjs_coin.h" // NOLINT + #include #include #include #include #include "cfd/cfd_utxo.h" -#include "cfdjs_coin.h" // NOLINT #include "cfdjs_internal.h" // NOLINT namespace cfd { diff --git a/src/cfdjs_elements_address.cpp b/src/cfdjs_elements_address.cpp index 808497cc..bfb591b8 100644 --- a/src/cfdjs_elements_address.cpp +++ b/src/cfdjs_elements_address.cpp @@ -9,7 +9,6 @@ #include #include "cfd/cfd_elements_address.h" - #include "cfd/cfdapi_elements_address.h" #include "cfdcore/cfdcore_descriptor.h" #include "cfdcore/cfdcore_elements_script.h" diff --git a/src/cfdjs_elements_transaction.cpp b/src/cfdjs_elements_transaction.cpp index 72d39173..32ea5953 100644 --- a/src/cfdjs_elements_transaction.cpp +++ b/src/cfdjs_elements_transaction.cpp @@ -917,6 +917,40 @@ ElementsTransactionStructApi::AddPubkeyHashSign( return result; } +AddScriptHashSignResponseStruct +ElementsTransactionStructApi::AddScriptHashSign( + const AddScriptHashSignRequestStruct& request) { + auto call_func = [](const AddScriptHashSignRequestStruct& request) + -> AddScriptHashSignResponseStruct { // NOLINT + AddScriptHashSignResponseStruct response; + + ConfidentialTransactionContext ctx(request.tx); + OutPoint outpoint(Txid(request.txin.txid), request.txin.vout); + Script redeem_script(request.txin.redeem_script); + AddressType addr_type = + AddressStructApi::ConvertAddressType(request.txin.hash_type); + std::vector signatures; + for (const auto& sign_data : request.txin.sign_param) { + SignParameter signature = + TransactionStructApiBase::ConvertSignDataStructToSignParameter( + sign_data); // NOLINT + signatures.emplace_back(signature); + } + + ctx.AddScriptHashSign( + outpoint, signatures, redeem_script, addr_type, + redeem_script.IsMultisigScript()); + response.hex = ctx.GetHex(); + return response; + }; + + AddScriptHashSignResponseStruct result; + result = ExecuteStructApi< + AddScriptHashSignRequestStruct, AddScriptHashSignResponseStruct>( + request, call_func, std::string(__FUNCTION__)); + return result; +} + UpdateWitnessStackResponseStruct ElementsTransactionStructApi::UpdateWitnessStack( const UpdateWitnessStackRequestStruct& request) { @@ -1130,14 +1164,14 @@ VerifySignResponseStruct ElementsTransactionStructApi::VerifySign( try { ctx.Verify(outpoint); } catch (const CfdException& except) { - warn( - CFD_LOG_SOURCE, "Failed to VerifySign. {}", - std::string(except.what())); + std::string error_msg = std::string(except.what()); + warn(CFD_LOG_SOURCE, "Failed to VerifySign. {}", error_msg); response.success = false; FailSignTxInStruct fail_data; fail_data.txid = outpoint.GetTxid().GetHex(); fail_data.vout = outpoint.GetVout(); - response.fail_txins.push_back(fail_data); + fail_data.reason = error_msg; + response.fail_txins.emplace_back(fail_data); } } diff --git a/src/cfdjs_hdwallet.cpp b/src/cfdjs_hdwallet.cpp index e0bd3eb8..7417cf58 100644 --- a/src/cfdjs_hdwallet.cpp +++ b/src/cfdjs_hdwallet.cpp @@ -177,18 +177,8 @@ HDWalletStructApi::CreateExtkeyFromParentPath( ExtKeyType key_type = ConvertExtKeyType(request.extkey_type); HDWalletApi api; if (request.path.empty()) { - std::vector path; - int64_t max = static_cast(std::numeric_limits::max()); - for (const int64_t& value : request.child_number_array) { - if ((value < 0) || (value > max)) { - throw CfdException( - CfdError::kCfdIllegalArgumentError, - "childNumber out of range. (0 - 0xffffffff)"); - } - path.push_back(static_cast(value)); - } response.extkey = api.CreateExtkeyFromParentPath( - request.extkey, net_type, key_type, path); + request.extkey, net_type, key_type, request.child_number_array); } else { response.extkey = api.CreateExtkeyFromPathString( request.extkey, net_type, key_type, request.path); diff --git a/src/cfdjs_json_mapping_api.cpp b/src/cfdjs_json_mapping_api.cpp index 8aa37ce5..dd458c55 100644 --- a/src/cfdjs_json_mapping_api.cpp +++ b/src/cfdjs_json_mapping_api.cpp @@ -4,9 +4,14 @@ * * @brief cfdのnode.js向けAPI実装ファイル */ +#include +#include #include #include "cfd/cfd_common.h" +#include "cfd_js_api_json_autogen.h" // NOLINT +#include "cfdapi_error_json.h" // NOLINT +#include "cfdapi_select_utxos_wrapper_json.h" // NOLINT #include "cfdjs/cfdjs_api_address.h" #include "cfdjs/cfdjs_api_common.h" #include "cfdjs/cfdjs_api_elements_address.h" @@ -17,13 +22,9 @@ #include "cfdjs/cfdjs_api_script.h" #include "cfdjs/cfdjs_api_transaction.h" #include "cfdjs/cfdjs_api_utility.h" - -#include "cfd_js_api_json_autogen.h" // NOLINT -#include "cfdapi_error_json.h" // NOLINT -#include "cfdapi_select_utxos_wrapper_json.h" // NOLINT -#include "cfdjs_coin.h" // NOLINT -#include "cfdjs_json_elements_transaction.h" // NOLINT -#include "cfdjs_json_transaction.h" // NOLINT +#include "cfdjs_coin.h" // NOLINT +#include "cfdjs_json_elements_transaction.h" // NOLINT +#include "cfdjs_json_transaction.h" // NOLINT // using using cfd::js::api::AddressStructApi; @@ -449,6 +450,27 @@ std::string JsonMappingApi::CreateSignatureHash( request_message, TransactionStructApi::CreateSignatureHash); } +std::string JsonMappingApi::ConvertAes(const std::string &request_message) { + return ExecuteJsonApi< + api::json::ConvertAesRequest, api::json::ConvertAesResponse, + api::ConvertAesRequestStruct, api::ConvertAesResponseStruct>( + request_message, UtilStructApi::ConvertAes); +} + +std::string JsonMappingApi::EncodeBase58(const std::string &request_message) { + return ExecuteJsonApi< + api::json::EncodeBase58Request, api::json::EncodeBase58Response, + api::EncodeBase58RequestStruct, api::EncodeBase58ResponseStruct>( + request_message, UtilStructApi::EncodeBase58); +} + +std::string JsonMappingApi::DecodeBase58(const std::string &request_message) { + return ExecuteJsonApi< + api::json::DecodeBase58Request, api::json::DecodeBase58Response, + api::DecodeBase58RequestStruct, api::DecodeBase58ResponseStruct>( + request_message, UtilStructApi::DecodeBase58); +} + std::string JsonMappingApi::EncodeSignatureByDer( const std::string &request_message) { return ExecuteJsonApi< @@ -679,6 +701,21 @@ std::string JsonMappingApi::SignWithPrivkey( #endif } +std::string JsonMappingApi::AddScriptHashSign( + const std::string &request_message) { + return ExecuteElementsCheckApi< + api::json::AddScriptHashSignRequest, + api::json::AddScriptHashSignResponse, + api::AddScriptHashSignRequestStruct, + api::AddScriptHashSignResponseStruct>( + request_message, TransactionStructApi::AddScriptHashSign, +#ifndef CFD_DISABLE_ELEMENTS + ElementsTransactionStructApi::AddScriptHashSign); +#else + TransactionStructApi::AddScriptHashSign); +#endif +} + std::string JsonMappingApi::UpdateWitnessStack( const std::string &request_message) { return ExecuteElementsCheckApi< @@ -971,6 +1008,136 @@ std::string JsonMappingApi::GetCommitment(const std::string &request_message) { #endif // CFD_DISABLE_ELEMENTS +void JsonMappingApi::LoadFunctions( + RequestFunctionMap *request_map, + ResponseOnlyFunctionMap *response_only_map) { + if (response_only_map != nullptr) { + response_only_map->emplace( + "GetSupportedFunction", JsonMappingApi::GetSupportedFunction); + } + + if (request_map != nullptr) { + request_map->emplace( + "CreateRawTransaction", JsonMappingApi::CreateRawTransaction); + request_map->emplace( + "AddRawTransaction", JsonMappingApi::AddRawTransaction); + request_map->emplace( + "DecodeRawTransaction", JsonMappingApi::DecodeRawTransaction); + request_map->emplace( + "ConvertEntropyToMnemonic", JsonMappingApi::ConvertEntropyToMnemonic); + request_map->emplace( + "ConvertMnemonicToSeed", JsonMappingApi::ConvertMnemonicToSeed); + request_map->emplace("CreateAddress", JsonMappingApi::CreateAddress); + request_map->emplace("CreateMultisig", JsonMappingApi::CreateMultisig); + request_map->emplace( + "GetAddressesFromMultisig", JsonMappingApi::GetAddressesFromMultisig); + request_map->emplace("GetAddressInfo", JsonMappingApi::GetAddressInfo); + request_map->emplace("ParseDescriptor", JsonMappingApi::ParseDescriptor); + request_map->emplace("CreateDescriptor", JsonMappingApi::CreateDescriptor); + request_map->emplace( + "AppendDescriptorChecksum", JsonMappingApi::AppendDescriptorChecksum); + request_map->emplace( + "CreateSignatureHash", JsonMappingApi::CreateSignatureHash); + request_map->emplace("ConvertAes", JsonMappingApi::ConvertAes); + request_map->emplace("EncodeBase58", JsonMappingApi::EncodeBase58); + request_map->emplace("DecodeBase58", JsonMappingApi::DecodeBase58); + request_map->emplace( + "EncodeSignatureByDer", JsonMappingApi::EncodeSignatureByDer); + request_map->emplace( + "DecodeDerSignatureToRaw", JsonMappingApi::DecodeDerSignatureToRaw); + request_map->emplace( + "GetWitnessStackNum", JsonMappingApi::GetWitnessStackNum); + request_map->emplace("AddSign", JsonMappingApi::AddSign); + request_map->emplace( + "AddPubkeyHashSign", JsonMappingApi::AddPubkeyHashSign); + request_map->emplace("SignWithPrivkey", JsonMappingApi::SignWithPrivkey); + request_map->emplace( + "AddScriptHashSign", JsonMappingApi::AddScriptHashSign); + request_map->emplace( + "UpdateWitnessStack", JsonMappingApi::UpdateWitnessStack); + request_map->emplace("AddMultisigSign", JsonMappingApi::AddMultisigSign); + request_map->emplace("VerifySignature", JsonMappingApi::VerifySignature); + request_map->emplace("VerifySign", JsonMappingApi::VerifySign); + request_map->emplace( + "GetMnemonicWordlist", JsonMappingApi::GetMnemonicWordlist); + request_map->emplace("GetExtkeyInfo", JsonMappingApi::GetExtkeyInfo); + request_map->emplace( + "GetPrivkeyFromExtkey", JsonMappingApi::GetPrivkeyFromExtkey); + request_map->emplace( + "GetPubkeyFromExtkey", JsonMappingApi::GetPubkeyFromExtkey); + request_map->emplace( + "GetPrivkeyFromWif", JsonMappingApi::GetPrivkeyFromWif); + request_map->emplace("GetPrivkeyWif", JsonMappingApi::GetPrivkeyWif); + request_map->emplace( + "GetPubkeyFromPrivkey", JsonMappingApi::GetPubkeyFromPrivkey); + request_map->emplace( + "GetCompressedPubkey", JsonMappingApi::GetCompressedPubkey); + request_map->emplace( + "CreateExtkeyFromSeed", JsonMappingApi::CreateExtkeyFromSeed); + request_map->emplace( + "CreateExtkeyFromParent", JsonMappingApi::CreateExtkeyFromParent); + request_map->emplace( + "CreateExtkeyFromParentPath", + JsonMappingApi::CreateExtkeyFromParentPath); + request_map->emplace( + "CreateExtkeyFromParentKey", + JsonMappingApi::CreateExtkeyFromParentKey); + request_map->emplace("CreateExtkey", JsonMappingApi::CreateExtkey); + request_map->emplace("CreateExtPubkey", JsonMappingApi::CreateExtPubkey); + request_map->emplace("CreateKeyPair", JsonMappingApi::CreateKeyPair); + request_map->emplace("ParseScript", JsonMappingApi::ParseScript); + request_map->emplace("CreateScript", JsonMappingApi::CreateScript); + request_map->emplace( + "CreateMultisigScriptSig", JsonMappingApi::CreateMultisigScriptSig); + request_map->emplace( + "CalculateEcSignature", JsonMappingApi::CalculateEcSignature); + request_map->emplace("EstimateFee", JsonMappingApi::EstimateFee); + request_map->emplace("SelectUtxos", JsonMappingApi::SelectUtxos); + request_map->emplace( + "FundRawTransaction", JsonMappingApi::FundRawTransaction); + request_map->emplace( + "UpdateTxOutAmount", JsonMappingApi::UpdateTxOutAmount); +#ifndef CFD_DISABLE_ELEMENTS + request_map->emplace( + "GetConfidentialAddress", JsonMappingApi::GetConfidentialAddress); + request_map->emplace( + "GetUnblindedAddress", JsonMappingApi::GetUnblindedAddress); + request_map->emplace( + "CreatePegInAddress", JsonMappingApi::CreatePegInAddress); + request_map->emplace( + "ElementsCreateRawTransaction", + JsonMappingApi::ElementsCreateRawTransaction); + request_map->emplace( + "ElementsAddRawTransaction", + JsonMappingApi::ElementsAddRawTransaction); + request_map->emplace( + "ElementsDecodeRawTransaction", + JsonMappingApi::ElementsDecodeRawTransaction); + request_map->emplace( + "BlindRawTransaction", JsonMappingApi::BlindRawTransaction); + request_map->emplace( + "UnblindRawTransaction", JsonMappingApi::UnblindRawTransaction); + request_map->emplace("SetRawIssueAsset", JsonMappingApi::SetRawIssueAsset); + request_map->emplace( + "SetRawReissueAsset", JsonMappingApi::SetRawReissueAsset); + request_map->emplace( + "CreateElementsSignatureHash", + JsonMappingApi::CreateElementsSignatureHash); + request_map->emplace("CreateRawPegin", JsonMappingApi::CreateRawPegin); + request_map->emplace("CreateRawPegout", JsonMappingApi::CreateRawPegout); + request_map->emplace( + "GetIssuanceBlindingKey", JsonMappingApi::GetIssuanceBlindingKey); + request_map->emplace( + "GetDefaultBlindingKey", JsonMappingApi::GetDefaultBlindingKey); + request_map->emplace( + "CreateDestroyAmount", JsonMappingApi::CreateDestroyAmount); + request_map->emplace( + "SerializeLedgerFormat", JsonMappingApi::SerializeLedgerFormat); + request_map->emplace("GetCommitment", JsonMappingApi::GetCommitment); +#endif // CFD_DISABLE_ELEMENTS + } +} + } // namespace json } // namespace api } // namespace js diff --git a/src/cfdjs_key.cpp b/src/cfdjs_key.cpp index 27e0b242..60a75418 100644 --- a/src/cfdjs_key.cpp +++ b/src/cfdjs_key.cpp @@ -6,10 +6,8 @@ */ #include -#include "cfdcore/cfdcore_transaction_common.h" - #include "cfd/cfdapi_key.h" - +#include "cfdcore/cfdcore_transaction_common.h" #include "cfdjs/cfdjs_api_address.h" #include "cfdjs/cfdjs_api_key.h" #include "cfdjs_internal.h" // NOLINT diff --git a/src/cfdjs_script.cpp b/src/cfdjs_script.cpp index 8a343b2b..6c9138d3 100644 --- a/src/cfdjs_script.cpp +++ b/src/cfdjs_script.cpp @@ -13,7 +13,6 @@ #include "cfdcore/cfdcore_exception.h" #include "cfdcore/cfdcore_logger.h" #include "cfdcore/cfdcore_script.h" - #include "cfdjs/cfdjs_api_script.h" #include "cfdjs_internal.h" // NOLINT #include "cfdjs_json_transaction.h" // NOLINT diff --git a/src/cfdjs_transaction.cpp b/src/cfdjs_transaction.cpp index bf837b7b..da72d8d2 100644 --- a/src/cfdjs_transaction.cpp +++ b/src/cfdjs_transaction.cpp @@ -523,6 +523,39 @@ AddPubkeyHashSignResponseStruct TransactionStructApi::AddPubkeyHashSign( return result; } +AddScriptHashSignResponseStruct TransactionStructApi::AddScriptHashSign( + const AddScriptHashSignRequestStruct& request) { + auto call_func = [](const AddScriptHashSignRequestStruct& request) + -> AddScriptHashSignResponseStruct { // NOLINT + AddScriptHashSignResponseStruct response; + + TransactionContext ctx(request.tx); + OutPoint outpoint(Txid(request.txin.txid), request.txin.vout); + Script redeem_script(request.txin.redeem_script); + AddressType addr_type = + AddressStructApi::ConvertAddressType(request.txin.hash_type); + std::vector signatures; + for (const auto& sign_data : request.txin.sign_param) { + SignParameter signature = + TransactionStructApiBase::ConvertSignDataStructToSignParameter( + sign_data); // NOLINT + signatures.emplace_back(signature); + } + + ctx.AddScriptHashSign( + outpoint, signatures, redeem_script, addr_type, + redeem_script.IsMultisigScript()); + response.hex = ctx.GetHex(); + return response; + }; + + AddScriptHashSignResponseStruct result; + result = ExecuteStructApi< + AddScriptHashSignRequestStruct, AddScriptHashSignResponseStruct>( + request, call_func, std::string(__FUNCTION__)); + return result; +} + CreateSignatureHashResponseStruct TransactionStructApi::CreateSignatureHash( const CreateSignatureHashRequestStruct& request) { auto call_func = [](const CreateSignatureHashRequestStruct& request) @@ -683,24 +716,23 @@ VerifySignResponseStruct TransactionStructApi::VerifySign( } ctx.CollectInputUtxo(utxos); - bool is_success = true; + response.success = !utxos.empty(); for (auto& utxo : utxos) { OutPoint outpoint(utxo.txid, utxo.vout); try { ctx.Verify(outpoint); } catch (const CfdException& except) { - warn( - CFD_LOG_SOURCE, "Failed to VerifySign. {}", - std::string(except.what())); - is_success = false; + std::string error_msg = std::string(except.what()); + warn(CFD_LOG_SOURCE, "Failed to VerifySign. {}", error_msg); + response.success = false; FailSignTxInStruct fail_data; fail_data.txid = outpoint.GetTxid().GetHex(); fail_data.vout = outpoint.GetVout(); - response.fail_txins.push_back(fail_data); + fail_data.reason = error_msg; + response.fail_txins.emplace_back(fail_data); } } - response.success = is_success; return response; }; diff --git a/src/cfdjs_transaction_base.cpp b/src/cfdjs_transaction_base.cpp index f0e5de6e..31a4732f 100644 --- a/src/cfdjs_transaction_base.cpp +++ b/src/cfdjs_transaction_base.cpp @@ -4,14 +4,14 @@ * * @brief cfd-apiで利用するTransaction作成の実装ファイル */ +#include "cfdjs_transaction_base.h" // NOLINT + #include #include #include #include "cfdcore/cfdcore_iterator.h" - -#include "cfdjs_internal.h" // NOLINT -#include "cfdjs_transaction_base.h" // NOLINT +#include "cfdjs_internal.h" // NOLINT namespace cfd { namespace js { @@ -301,6 +301,15 @@ template SignParameter TransactionStructApiBase::ConvertSignDataStructToSignParameter< MultisigScriptSigDataStruct>(const MultisigScriptSigDataStruct& sign_data); +/** + * @relates TransactionStructApiBase + * @param[in] sign_data ScriptHashSignDataStruct構造体 + * @returns SignParameter情報 + */ +template SignParameter +TransactionStructApiBase::ConvertSignDataStructToSignParameter< + ScriptHashSignDataStruct>(const ScriptHashSignDataStruct& sign_data); + } // namespace api } // namespace js } // namespace cfd diff --git a/src/cfdjs_utility.cpp b/src/cfdjs_utility.cpp index 3858e788..11476258 100644 --- a/src/cfdjs_utility.cpp +++ b/src/cfdjs_utility.cpp @@ -7,12 +7,11 @@ #include #include +#include "cfd/cfd_common.h" #include "cfdcore/cfdcore_bytedata.h" #include "cfdcore/cfdcore_exception.h" #include "cfdcore/cfdcore_logger.h" #include "cfdcore/cfdcore_util.h" - -#include "cfd/cfd_common.h" #include "cfdjs/cfdjs_api_utility.h" #include "cfdjs_internal.h" // NOLINT #include "cfdjs_transaction_base.h" // NOLINT @@ -51,6 +50,73 @@ GetSupportedFunctionResponseStruct UtilStructApi::GetSupportedFunction() { return result; } +ConvertAesResponseStruct UtilStructApi::ConvertAes( + ConvertAesRequestStruct request) { + auto call_func = + [](const ConvertAesRequestStruct& request) -> ConvertAesResponseStruct { + ConvertAesResponseStruct result; + ByteData data; + + if (request.is_encrypt) { + data = CryptoUtil::EncryptAes256Cbc( + ByteData(request.key), ByteData(request.iv), ByteData(request.data)); + } else { // decrypto + data = CryptoUtil::DecryptAes256Cbc( + ByteData(request.key), ByteData(request.iv), ByteData(request.data)); + } + + result.hex = data.GetHex(); + return result; + }; + + ConvertAesResponseStruct result; + result = ExecuteStructApi( + request, call_func, std::string(__FUNCTION__)); + return result; +} + +EncodeBase58ResponseStruct UtilStructApi::EncodeBase58( + EncodeBase58RequestStruct request) { + auto call_func = [](const EncodeBase58RequestStruct& request) + -> EncodeBase58ResponseStruct { + EncodeBase58ResponseStruct result; + if (request.has_checksum) { + result.data = CryptoUtil::EncodeBase58Check(ByteData(request.hex)); + } else { + result.data = CryptoUtil::EncodeBase58(ByteData(request.hex)); + } + return result; + }; + + EncodeBase58ResponseStruct result; + result = + ExecuteStructApi( + request, call_func, std::string(__FUNCTION__)); + return result; +} + +DecodeBase58ResponseStruct UtilStructApi::DecodeBase58( + DecodeBase58RequestStruct request) { + auto call_func = [](const DecodeBase58RequestStruct& request) + -> DecodeBase58ResponseStruct { + DecodeBase58ResponseStruct result; + ByteData data; + if (request.has_checksum) { + data = CryptoUtil::DecodeBase58Check(request.data); + } else { + data = CryptoUtil::DecodeBase58(request.data); + } + result.hex = data.GetHex(); + return result; + }; + + DecodeBase58ResponseStruct result; + result = + ExecuteStructApi( + request, call_func, std::string(__FUNCTION__)); + return result; +} + EncodeSignatureByDerResponseStruct UtilStructApi::EncodeSignatureByDer( EncodeSignatureByDerRequestStruct request) { auto call_func = [](const EncodeSignatureByDerRequestStruct& request) @@ -94,7 +160,7 @@ DecodeDerSignatureToRawResponseStruct UtilStructApi::DecodeDerSignatureToRaw( return result; } -// 実体定義用(多重定義防止のためCPP側に定義) +// Define the entity (Define on CPP side to prevent duplicate definition) InnerErrorResponseStruct ConvertCfdExceptionToStruct( const CfdException& cfde) { InnerErrorResponseStruct result; diff --git a/src/input_json_format/cfdapi_add_script_hash_sign.json b/src/input_json_format/cfdapi_add_script_hash_sign.json new file mode 100644 index 00000000..e2178b3d --- /dev/null +++ b/src/input_json_format/cfdapi_add_script_hash_sign.json @@ -0,0 +1,51 @@ +{ + "namespace": ["cfd","js","api","json"], + "request": { + ":class": "AddScriptHashSignRequest", + ":class:comment": "Add signatures to pubkey hash input", + "isElements": false, + "isElements:require": "optional", + "tx": "", + "tx:require": "require", + "tx:comment": "transaction hex", + "txin": { + ":class": "AddScriptHashSignTxInRequest", + "txid": "", + "txid:require": "require", + "vout": 0, + "vout:type": "uint32_t", + "vout:require": "require", + "signParam:require": "require", + "signParam": [ + { + ":class": "ScriptHashSignData", + "hex": "", + "hex:require": "require", + "hex:comment": "If the type is auto or op_code, character string input is enabled. Others are hex byte array only.", + "type": "auto", + "type:require": "optional", + "type:hint": "binary, sign", + "derEncode": false, + "derEncode:require": "optional", + "derEncode:comment": "Valid when type is auto or sign.", + "sighashType": "all", + "sighashType:require": "optional", + "sighashType:hint": "all, none, single", + "sighashAnyoneCanPay": false, + "sighashAnyoneCanPay:require": "optional" + } + ], + "redeemScript": "", + "redeemScript:require": "require", + "redeemScript:comment": "redeem script.", + "hashType": "", + "hashType:require": "require", + "hashType:hint": "p2sh, p2wsh or p2sh-p2wsh" + } + }, + "response": { + ":class": "AddScriptHashSignResponse", + "hex": "", + "hex:require": "require" + } +} \ No newline at end of file diff --git a/src/input_json_format/cfdapi_convert_aes.json b/src/input_json_format/cfdapi_convert_aes.json new file mode 100644 index 00000000..c90b8e19 --- /dev/null +++ b/src/input_json_format/cfdapi_convert_aes.json @@ -0,0 +1,28 @@ +{ + "namespace": ["cfd","js","api","json"], + "request": { + ":class": "ConvertAesRequest", + "isEncrypt": true, + "isEncrypt:require": "require", + "isEncrypt:hint": "false is decrypto", + "mode": "cbc", + "mode:require": "optional", + "mode:hint": "cbc only", + "key": "", + "key:require": "require", + "key:comment": "key data (32 byte)", + "iv": "", + "iv:require": "optional", + "iv:comment": "initial vector (16 byte)", + "iv:hint": "using by cbc mode only.", + "data": "", + "data:require": "require", + "data:comment": "crypto target data" + }, + "response": { + ":class": "ConvertAesResponse", + "hex": "", + "hex:require": "require", + "hex:comment": "encrypted or decrypted data" + } +} \ No newline at end of file diff --git a/src/input_json_format/cfdapi_decode_base58.json b/src/input_json_format/cfdapi_decode_base58.json new file mode 100644 index 00000000..d3cdaaf5 --- /dev/null +++ b/src/input_json_format/cfdapi_decode_base58.json @@ -0,0 +1,18 @@ +{ + "namespace": ["cfd","js","api","json"], + "request": { + ":class": "DecodeBase58Request", + "data": "", + "data:require": "require", + "data:comment": "base58 data", + "hasChecksum": true, + "hasChecksum:require": "optional", + "hasChecksum:comment": "use checksum mode." + }, + "response": { + ":class": "DecodeBase58Response", + "hex": "", + "hex:require": "require", + "hex:comment": "decoded data byte hex" + } +} \ No newline at end of file diff --git a/src/input_json_format/cfdapi_encode_base58.json b/src/input_json_format/cfdapi_encode_base58.json new file mode 100644 index 00000000..72c8699d --- /dev/null +++ b/src/input_json_format/cfdapi_encode_base58.json @@ -0,0 +1,18 @@ +{ + "namespace": ["cfd","js","api","json"], + "request": { + ":class": "EncodeBase58Request", + "hex": "", + "hex:require": "require", + "hex:comment": "base58 target byte hex", + "hasChecksum": true, + "useChecksum:require": "optional", + "useChecksum:comment": "use checksum mode." + }, + "response": { + ":class": "EncodeBase58Response", + "data": "", + "data:require": "require", + "data:comment": "encoded data" + } +} \ No newline at end of file diff --git a/src/input_json_format/cfdapi_verify_sign.json b/src/input_json_format/cfdapi_verify_sign.json index 4e3a025f..1e59ac8b 100644 --- a/src/input_json_format/cfdapi_verify_sign.json +++ b/src/input_json_format/cfdapi_verify_sign.json @@ -39,7 +39,10 @@ "txid:require": "require", "vout": 0, "vout:type": "uint32_t", - "vout:require": "require" + "vout:require": "require", + "reason": "", + "reason:require": "require", + "reason:hint": "error reason." }], "failTxins:require": "optional" } diff --git a/wally.js b/wally.js new file mode 100644 index 00000000..3d9b2c75 --- /dev/null +++ b/wally.js @@ -0,0 +1,1483 @@ + +try { + var window = global.window || {}; +} catch (e) { var window = {}; } + +module.exports = {}; + +if (window.cordova) { + var base64 = require('base64-js'); + + module.exports.wally_hex_from_bytes = function (uintArray) { + return uintArray.reduce(function (hex, i) { + return hex + (i < 16 ? '0' : '') + i.toString(16); + }, ''); + }; + + + module.exports.wally_sha256 = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_sha256', [base64.fromByteArray(_arguments[0])] + ); + }); + }; + + + + module.exports.wally_sha256d = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_sha256d', [base64.fromByteArray(_arguments[0])] + ); + }); + }; + + + + module.exports.wally_sha512 = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_sha512', [base64.fromByteArray(_arguments[0])] + ); + }); + }; + + + + module.exports.wally_hash160 = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_hash160', [base64.fromByteArray(_arguments[0])] + ); + }); + }; + + + + module.exports.wally_hmac_sha256 = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_hmac_sha256', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1])] + ); + }); + }; + + + + module.exports.wally_hmac_sha512 = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_hmac_sha512', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1])] + ); + }); + }; + + + + module.exports.wally_pbkdf2_hmac_sha256 = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_pbkdf2_hmac_sha256', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), _arguments[2], _arguments[3]] + ); + }); + }; + + + + module.exports.wally_pbkdf2_hmac_sha512 = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_pbkdf2_hmac_sha512', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), _arguments[2], _arguments[3]] + ); + }); + }; + + + + module.exports.wally_base58_from_bytes = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'wally_base58_from_bytes', [base64.fromByteArray(_arguments[0]), _arguments[1]] + ); + }); + }; + + + + module.exports.wally_base58_to_bytes = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_base58_to_bytes', [_arguments[0], _arguments[1], _arguments[0].length + ((_arguments[1] & 1) ? 4 : 0)] + ); + }); + }; + + + + module.exports.wally_addr_segwit_from_bytes = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'wally_addr_segwit_from_bytes', [base64.fromByteArray(_arguments[0]), _arguments[1], _arguments[2]] + ); + }); + }; + + + + module.exports.wally_addr_segwit_to_bytes = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_addr_segwit_to_bytes', [_arguments[0], _arguments[1], _arguments[2], 34] + ); + }); + }; + + + + module.exports.wally_wif_to_bytes = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_wif_to_bytes', [_arguments[1], _arguments[2], 32] + ); + }); + }; + + + + module.exports.wally_wif_is_uncompressed = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'wally_wif_is_uncompressed', [] + ); + }); + }; + + + + module.exports.wally_aes = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_aes', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), _arguments[2], _arguments[1].length] + ); + }); + }; + + + + module.exports.wally_aes_cbc = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_aes_cbc', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), base64.fromByteArray(_arguments[2]), _arguments[3], Math.ceil(_arguments[2].length / 16) * 16 + 16] + ); + }); + }; + + + + module.exports.wally_scriptpubkey_multisig_from_bytes = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_scriptpubkey_multisig_from_bytes', [base64.fromByteArray(_arguments[0]), _arguments[1], _arguments[2], Math.ceil(_arguments[0].length / 33) * 34 + 3] + ); + }); + }; + + + + module.exports.wally_scrypt = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_scrypt', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), _arguments[2], _arguments[3], _arguments[4], _arguments[5]] + ); + }); + }; + + + + module.exports.bip38_raw_from_private_key = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'bip38_raw_from_private_key', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), _arguments[2], 39] + ); + }); + }; + + + + module.exports.bip38_from_private_key = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'bip38_from_private_key', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), _arguments[2]] + ); + }); + }; + + + + module.exports.bip38_raw_to_private_key = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'bip38_raw_to_private_key', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), _arguments[2], 32] + ); + }); + }; + + + + module.exports.bip38_to_private_key = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'bip38_to_private_key', [_arguments[0], base64.fromByteArray(_arguments[1]), _arguments[2], 32] + ); + }); + }; + + + + module.exports.bip39_get_languages = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'bip39_get_languages', [] + ); + }); + }; + + + + module.exports.bip39_mnemonic_from_bytes = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'bip39_mnemonic_from_bytes', [base64.fromByteArray(_arguments[1])] + ); + }); + }; + + + + module.exports.bip39_mnemonic_to_seed = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'bip39_mnemonic_to_seed', [_arguments[0], _arguments[1], 64] + ); + }); + }; + + + + module.exports.wally_ec_sig_from_bytes = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_ec_sig_from_bytes', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), _arguments[2], 64 + ((_arguments[2] & 8) ? 1 : 0)] + ); + }); + }; + + + + module.exports.wally_ec_sig_to_der = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_ec_sig_to_der', [base64.fromByteArray(_arguments[0]), 72] + ); + }); + }; + + + + module.exports.wally_ec_sig_to_public_key = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_ec_sig_to_public_key', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), 33] + ); + }); + }; + + + + module.exports.bip32_key_from_seed = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'bip32_key_from_seed', [base64.fromByteArray(_arguments[0]), _arguments[1], _arguments[2]] + ); + }); + }; + + + + module.exports.bip32_privkey_from_parent = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'bip32_privkey_from_parent', [base64.fromByteArray(_arguments[0]), _arguments[1], _arguments[2]] + ); + }); + }; + + + + module.exports.bip32_pubkey_from_parent = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'bip32_pubkey_from_parent', [base64.fromByteArray(_arguments[0]), _arguments[1], _arguments[2]] + ); + }); + }; + + + + module.exports.bip32_key_get_priv_key = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'bip32_key_get_priv_key', [base64.fromByteArray(_arguments[0]), 32] + ); + }); + }; + + + + module.exports.bip32_key_get_pub_key = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'bip32_key_get_pub_key', [base64.fromByteArray(_arguments[0]), 33] + ); + }); + }; + + + + module.exports.wally_ec_public_key_from_private_key = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_ec_public_key_from_private_key', [base64.fromByteArray(_arguments[0]), 33] + ); + }); + }; + + + + module.exports.wally_ec_private_key_verify = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'wally_ec_private_key_verify', [base64.fromByteArray(_arguments[0])] + ); + }); + }; + + + + module.exports.wally_ec_public_key_verify = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'wally_ec_public_key_verify', [base64.fromByteArray(_arguments[0])] + ); + }); + }; + + + + module.exports.wally_tx_from_hex = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'wally_tx_from_hex', [_arguments[1]] + ); + }); + }; + + + + module.exports.wally_format_bitcoin_message = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_format_bitcoin_message', [base64.fromByteArray(_arguments[0]), _arguments[1], _arguments[1] & 1 ? 32 : 2 + "Bitcoin Signed Message:".length + _arguments[0].length + (_arguments[0].length < 253 ? 1 : 3)] + ); + }); + }; + + + + module.exports.wally_asset_generator_from_bytes = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_asset_generator_from_bytes', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), 33] + ); + }); + }; + + + + module.exports.wally_asset_final_vbf = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_asset_final_vbf', [_arguments[1], base64.fromByteArray(_arguments[2]), base64.fromByteArray(_arguments[3]), 32] + ); + }); + }; + + + + module.exports.wally_asset_unblind_with_nonce = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_asset_unblind_with_nonce', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), base64.fromByteArray(_arguments[2]), base64.fromByteArray(_arguments[3]), base64.fromByteArray(_arguments[4]), 32, 32, 32] + ); + }); + }; + + + + module.exports.wally_asset_unblind = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_asset_unblind', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), base64.fromByteArray(_arguments[2]), base64.fromByteArray(_arguments[3]), base64.fromByteArray(_arguments[4]), base64.fromByteArray(_arguments[5]), 32, 32, 32] + ); + }); + }; + + + + module.exports.wally_asset_value_commitment = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_asset_value_commitment', [base64.fromByteArray(_arguments[1]), base64.fromByteArray(_arguments[2]), 33] + ); + }); + }; + + + + module.exports.wally_asset_rangeproof_with_nonce = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_asset_rangeproof_with_nonce', [base64.fromByteArray(_arguments[1]), base64.fromByteArray(_arguments[2]), base64.fromByteArray(_arguments[3]), base64.fromByteArray(_arguments[4]), base64.fromByteArray(_arguments[5]), base64.fromByteArray(_arguments[6]), base64.fromByteArray(_arguments[7]), 5134] + ); + }); + }; + + + + module.exports.wally_asset_rangeproof = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_asset_rangeproof', [base64.fromByteArray(_arguments[1]), base64.fromByteArray(_arguments[2]), base64.fromByteArray(_arguments[3]), base64.fromByteArray(_arguments[4]), base64.fromByteArray(_arguments[5]), base64.fromByteArray(_arguments[6]), base64.fromByteArray(_arguments[7]), base64.fromByteArray(_arguments[8]), 5134] + ); + }); + }; + + + + module.exports.wally_asset_surjectionproof = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_asset_surjectionproof', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), base64.fromByteArray(_arguments[2]), base64.fromByteArray(_arguments[3]), base64.fromByteArray(_arguments[4]), base64.fromByteArray(_arguments[5]), base64.fromByteArray(_arguments[6]), (2 + Math.floor((_arguments[5].length/32 + 7)/8) + 32 * (1 + (_arguments[5].length/32 > 3 ? 3 : _arguments[5].length/32)))] + ); + }); + }; + + + + module.exports.wally_asset_blinding_key_from_seed = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_asset_blinding_key_from_seed', [base64.fromByteArray(_arguments[0]), 64] + ); + }); + }; + + + + module.exports.wally_asset_blinding_key_to_ec_private_key = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_asset_blinding_key_to_ec_private_key', [base64.fromByteArray(_arguments[0]), base64.fromByteArray(_arguments[1]), 32] + ); + }); + }; + + + + module.exports.wally_confidential_addr_from_addr = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'wally_confidential_addr_from_addr', [_arguments[0], _arguments[1], base64.fromByteArray(_arguments[2])] + ); + }); + }; + + + + module.exports.wally_confidential_addr_to_addr = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(res); }, + reject, 'Wally', 'wally_confidential_addr_to_addr', [_arguments[0], _arguments[1]] + ); + }); + }; + + + + module.exports.wally_confidential_addr_to_ec_public_key = function () { + var _arguments = arguments; + return new Promise(function (resolve, reject) { + window.cordova.exec( + function (res) { resolve(new Uint8Array(res)); }, + reject, 'Wally', 'wally_confidential_addr_to_ec_public_key', [_arguments[0], _arguments[1], 33] + ); + }); + }; + +} else { + var wallycore = require('./build/Release/wallycore'); + // nodejs + + module.exports.wally_sha256 = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(null); + var res = new Uint8Array(wallycore.wally_sha256.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_sha256d = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(null); + var res = new Uint8Array(wallycore.wally_sha256d.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_sha512 = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(null); + var res = new Uint8Array(wallycore.wally_sha512.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_hash160 = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(null); + var res = new Uint8Array(wallycore.wally_hash160.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_hmac_sha256 = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(null); + var res = new Uint8Array(wallycore.wally_hmac_sha256.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_hmac_sha512 = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(null); + var res = new Uint8Array(wallycore.wally_hmac_sha512.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_pbkdf2_hmac_sha256 = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(null); + var res = new Uint8Array(wallycore.wally_pbkdf2_hmac_sha256.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_pbkdf2_hmac_sha512 = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(null); + var res = new Uint8Array(wallycore.wally_pbkdf2_hmac_sha512.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_base58_from_bytes = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.wally_base58_from_bytes.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.wally_base58_to_bytes = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(_arguments[0].length + ((_arguments[1] & 1) ? 4 : 0)); + var res = new Uint8Array(wallycore.wally_base58_to_bytes.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_addr_segwit_from_bytes = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.wally_addr_segwit_from_bytes.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.wally_addr_segwit_to_bytes = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(34); + var res = new Uint8Array(wallycore.wally_addr_segwit_to_bytes.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_wif_to_bytes = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(32); + var res = new Uint8Array(wallycore.wally_wif_to_bytes.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_wif_is_uncompressed = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.wally_wif_is_uncompressed.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.wally_aes = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(_arguments[1].length); + var res = new Uint8Array(wallycore.wally_aes.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_aes_cbc = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(Math.ceil(_arguments[2].length / 16) * 16 + 16); + var res = new Uint8Array(wallycore.wally_aes_cbc.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_scriptpubkey_multisig_from_bytes = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(Math.ceil(_arguments[0].length / 33) * 34 + 3); + var res = new Uint8Array(wallycore.wally_scriptpubkey_multisig_from_bytes.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_scrypt = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(null); + var res = new Uint8Array(wallycore.wally_scrypt.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.bip38_raw_from_private_key = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(39); + var res = new Uint8Array(wallycore.bip38_raw_from_private_key.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.bip38_from_private_key = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.bip38_from_private_key.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.bip38_raw_to_private_key = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(32); + var res = new Uint8Array(wallycore.bip38_raw_to_private_key.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.bip38_to_private_key = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(32); + var res = new Uint8Array(wallycore.bip38_to_private_key.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.bip39_get_languages = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.bip39_get_languages.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.bip39_mnemonic_from_bytes = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.bip39_mnemonic_from_bytes.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.bip39_mnemonic_to_seed = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(64); + var res = new Uint8Array(wallycore.bip39_mnemonic_to_seed.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_ec_sig_from_bytes = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(64 + ((_arguments[2] & 8) ? 1 : 0)); + var res = new Uint8Array(wallycore.wally_ec_sig_from_bytes.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_ec_sig_to_der = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(72); + var res = new Uint8Array(wallycore.wally_ec_sig_to_der.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_ec_sig_to_public_key = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(33); + var res = new Uint8Array(wallycore.wally_ec_sig_to_public_key.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.bip32_key_from_seed = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.bip32_key_from_seed.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.bip32_privkey_from_parent = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.bip32_privkey_from_parent.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.bip32_pubkey_from_parent = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.bip32_pubkey_from_parent.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.bip32_key_get_priv_key = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(32); + var res = new Uint8Array(wallycore.bip32_key_get_priv_key.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.bip32_key_get_pub_key = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(33); + var res = new Uint8Array(wallycore.bip32_key_get_pub_key.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_ec_public_key_from_private_key = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(33); + var res = new Uint8Array(wallycore.wally_ec_public_key_from_private_key.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_ec_private_key_verify = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.wally_ec_private_key_verify.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.wally_ec_public_key_verify = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.wally_ec_public_key_verify.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.wally_tx_from_hex = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.wally_tx_from_hex.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.wally_format_bitcoin_message = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(_arguments[1] & 1 ? 32 : 2 + "Bitcoin Signed Message:".length + _arguments[0].length + (_arguments[0].length < 253 ? 1 : 3)); + var res = new Uint8Array(wallycore.wally_format_bitcoin_message.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_asset_generator_from_bytes = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(33); + var res = new Uint8Array(wallycore.wally_asset_generator_from_bytes.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_asset_final_vbf = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(32); + var res = new Uint8Array(wallycore.wally_asset_final_vbf.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_asset_unblind_with_nonce = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(32);_arguments.push(32);_arguments.push(32); + var res = wallycore.wally_asset_unblind_with_nonce.apply(wallycore, _arguments); + res[0] = new Uint8Array(res[0].buffer); +res[1] = new Uint8Array(res[1].buffer); +res[2] = new Uint8Array(res[2].buffer); +res[3] = new Uint8Array(res[3].buffer); + return Promise.resolve(res); + } + + + + module.exports.wally_asset_unblind = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(32);_arguments.push(32);_arguments.push(32); + var res = wallycore.wally_asset_unblind.apply(wallycore, _arguments); + res[0] = new Uint8Array(res[0].buffer); +res[1] = new Uint8Array(res[1].buffer); +res[2] = new Uint8Array(res[2].buffer); +res[3] = new Uint8Array(res[3].buffer); + return Promise.resolve(res); + } + + + + module.exports.wally_asset_value_commitment = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(33); + var res = new Uint8Array(wallycore.wally_asset_value_commitment.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_asset_rangeproof_with_nonce = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(5134); + var res = new Uint8Array(wallycore.wally_asset_rangeproof_with_nonce.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_asset_rangeproof = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(5134); + var res = new Uint8Array(wallycore.wally_asset_rangeproof.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_asset_surjectionproof = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push((2 + Math.floor((_arguments[5].length/32 + 7)/8) + 32 * (1 + (_arguments[5].length/32 > 3 ? 3 : _arguments[5].length/32)))); + var res = new Uint8Array(wallycore.wally_asset_surjectionproof.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_asset_blinding_key_from_seed = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(64); + var res = new Uint8Array(wallycore.wally_asset_blinding_key_from_seed.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_asset_blinding_key_to_ec_private_key = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(32); + var res = new Uint8Array(wallycore.wally_asset_blinding_key_to_ec_private_key.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + + + + module.exports.wally_confidential_addr_from_addr = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.wally_confidential_addr_from_addr.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.wally_confidential_addr_to_addr = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + + var res = wallycore.wally_confidential_addr_to_addr.apply(wallycore, _arguments); + + return Promise.resolve(res); + } + + + + module.exports.wally_confidential_addr_to_ec_public_key = function () { + var _arguments = []; + _arguments.push.apply(_arguments, arguments); + _arguments.push(33); + var res = new Uint8Array(wallycore.wally_confidential_addr_to_ec_public_key.apply(wallycore, _arguments).buffer); + + return Promise.resolve(res); + } + +} +var _export = function(name, value) { + Object.defineProperty(module.exports, name, {'value': value, 'writable': false}); +} +var _zero = new Uint8Array([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]); +var _one = new Uint8Array([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01]); +_export('ZERO_64', _zero); +_export('ONE_64', _one); + +_export("WALLY_WIF_FLAG_COMPRESSED", 0x0); +_export("WALLY_WIF_FLAG_UNCOMPRESSED", 0x1); +_export("WALLY_CA_PREFIX_LIQUID", 0x0c); +_export("WALLY_CA_PREFIX_LIQUID_REGTEST", 0x04); +_export("WALLY_NETWORK_BITCOIN_MAINNET", 0x01); +_export("WALLY_NETWORK_BITCOIN_TESTNET", 0x02); +_export("WALLY_NETWORK_LIQUID", 0x03); +_export("WALLY_NETWORK_LIQUID_REGTEST", 0x04); +_export("WALLY_ADDRESS_TYPE_P2PKH", 0x01); +_export("WALLY_ADDRESS_TYPE_P2SH_P2WPKH", 0x02); +_export("WALLY_ADDRESS_TYPE_P2WPKH", 0x04); +_export("WALLY_ADDRESS_VERSION_P2PKH_MAINNET", 0x00); +_export("WALLY_ADDRESS_VERSION_P2PKH_TESTNET", 0x6F); +_export("WALLY_ADDRESS_VERSION_P2PKH_LIQUID", 0x39); +_export("WALLY_ADDRESS_VERSION_P2PKH_LIQUID_REGTEST", 0xEB); +_export("WALLY_ADDRESS_VERSION_P2SH_MAINNET", 0x05); +_export("WALLY_ADDRESS_VERSION_P2SH_TESTNET", 0xC4); +_export("WALLY_ADDRESS_VERSION_P2SH_LIQUID", 0x27); +_export("WALLY_ADDRESS_VERSION_P2SH_LIQUID_REGTEST", 0x4B); +_export("WALLY_ADDRESS_VERSION_WIF_MAINNET", 0x80); +_export("WALLY_ADDRESS_VERSION_WIF_TESTNET", 0xEF); +_export("BIP32_ENTROPY_LEN_128", 16); +_export("BIP32_ENTROPY_LEN_256", 32); +_export("BIP32_ENTROPY_LEN_512", 64); +_export("BIP32_SERIALIZED_LEN", 78); +_export("BIP32_INITIAL_HARDENED_CHILD", 0x80000000); +_export("BIP32_FLAG_KEY_PRIVATE", 0x0); +_export("BIP32_FLAG_KEY_PUBLIC", 0x1); +_export("BIP32_FLAG_SKIP_HASH", 0x2); +_export("BIP32_FLAG_KEY_TWEAK_SUM", 0x4); +_export("BIP32_VER_MAIN_PUBLIC", 0x0488B21E); +_export("BIP32_VER_MAIN_PRIVATE", 0x0488ADE4); +_export("BIP32_VER_TEST_PUBLIC", 0x043587CF); +_export("BIP32_VER_TEST_PRIVATE", 0x04358394); +_export("BIP38_KEY_MAINNET", 0); +_export("BIP38_KEY_TESTNET", 111); +_export("BIP38_KEY_COMPRESSED", 256); +_export("BIP38_KEY_EC_MULT", 512); +_export("BIP38_KEY_QUICK_CHECK", 1024); +_export("BIP38_KEY_RAW_MODE", 2048); +_export("BIP38_KEY_SWAP_ORDER", 4096); +_export("BIP38_SERIALIZED_LEN", 39); +_export("BIP39_ENTROPY_LEN_128", 16); +_export("BIP39_ENTROPY_LEN_160", 20); +_export("BIP39_ENTROPY_LEN_192", 24); +_export("BIP39_ENTROPY_LEN_224", 28); +_export("BIP39_ENTROPY_LEN_256", 32); +_export("BIP39_ENTROPY_LEN_288", 36); +_export("BIP39_ENTROPY_LEN_320", 40); +_export("BIP39_SEED_LEN_512", 64); +_export("BIP39_WORDLIST_LEN", 2048); +_export("WALLY_OK", 0); +_export("WALLY_ERROR", -1); +_export("WALLY_EINVAL", -2); +_export("WALLY_ENOMEM", -3); +_export("FINGERPRINT_LEN", 4); +_export("WALLY_SECP_RANDOMIZE_LEN", 32); +_export("BASE58_FLAG_CHECKSUM", 0x1); +_export("BASE58_CHECKSUM_LEN", 4); +_export("AES_BLOCK_LEN", 16); +_export("AES_KEY_LEN_128", 16); +_export("AES_KEY_LEN_192", 24); +_export("AES_KEY_LEN_256", 32); +_export("AES_FLAG_ENCRYPT", 1); +_export("AES_FLAG_DECRYPT", 2); +_export("SHA256_LEN", 32); +_export("SHA512_LEN", 64); +_export("HASH160_LEN", 20); +_export("HMAC_SHA256_LEN", 32); +_export("HMAC_SHA512_LEN", 64); +_export("PBKDF2_HMAC_SHA256_LEN", 32); +_export("PBKDF2_HMAC_SHA512_LEN", 64); +_export("EC_PRIVATE_KEY_LEN", 32); +_export("EC_PUBLIC_KEY_LEN", 33); +_export("EC_PUBLIC_KEY_UNCOMPRESSED_LEN", 65); +_export("EC_MESSAGE_HASH_LEN", 32); +_export("EC_SIGNATURE_LEN", 64); +_export("EC_SIGNATURE_RECOVERABLE_LEN", 65); +_export("EC_SIGNATURE_DER_MAX_LEN", 72); +_export("EC_SIGNATURE_DER_MAX_LOW_R_LEN", 71); +_export("EC_FLAG_ECDSA", 0x1); +_export("EC_FLAG_SCHNORR", 0x2); +_export("EC_FLAG_GRIND_R", 0x4); +_export("EC_FLAG_RECOVERABLE", 0x8); +_export("BITCOIN_MESSAGE_MAX_LEN", (64 * 1024 - 64)); +_export("BITCOIN_MESSAGE_FLAG_HASH", 1); +_export("WALLY_NETWORK_BITCOIN_REGTEST", 0xff); +_export("ASSET_TAG_LEN", 32); +_export("BLINDING_FACTOR_LEN", 32); +_export("ASSET_GENERATOR_LEN", 33); +_export("ASSET_COMMITMENT_LEN", 33); +_export("ASSET_RANGEPROOF_MAX_LEN", 5134); +_export("WALLY_PSBT_SEPARATOR", 0x00); +_export("WALLY_PSBT_GLOBAL_UNSIGNED_TX", 0x00); +_export("WALLY_PSBT_IN_NON_WITNESS_UTXO", 0x00); +_export("WALLY_PSBT_IN_WITNESS_UTXO", 0x01); +_export("WALLY_PSBT_IN_PARTIAL_SIG", 0x02); +_export("WALLY_PSBT_IN_SIGHASH_TYPE", 0x03); +_export("WALLY_PSBT_IN_REDEEM_SCRIPT", 0x04); +_export("WALLY_PSBT_IN_WITNESS_SCRIPT", 0x05); +_export("WALLY_PSBT_IN_BIP32_DERIVATION", 0x06); +_export("WALLY_PSBT_IN_FINAL_SCRIPTSIG", 0x07); +_export("WALLY_PSBT_IN_FINAL_SCRIPTWITNESS", 0x08); +_export("WALLY_PSBT_OUT_REDEEM_SCRIPT", 0x00); +_export("WALLY_PSBT_OUT_WITNESS_SCRIPT", 0x01); +_export("WALLY_PSBT_OUT_BIP32_DERIVATION", 0x02); +_export("WALLY_SCRIPT_TYPE_UNKNOWN", 0x0); +_export("WALLY_SCRIPT_TYPE_OP_RETURN", 0x1); +_export("WALLY_SCRIPT_TYPE_P2PKH", 0x2); +_export("WALLY_SCRIPT_TYPE_P2SH", 0x4); +_export("WALLY_SCRIPT_TYPE_P2WPKH", 0x8); +_export("WALLY_SCRIPT_TYPE_P2WSH", 0x10); +_export("WALLY_SCRIPT_TYPE_MULTISIG", 0x20); +_export("WALLY_SCRIPTPUBKEY_P2PKH_LEN", 25); +_export("WALLY_SCRIPTPUBKEY_P2SH_LEN", 23); +_export("WALLY_SCRIPTPUBKEY_P2WPKH_LEN", 22); +_export("WALLY_SCRIPTPUBKEY_P2WSH_LEN", 34); +_export("WALLY_SCRIPTPUBKEY_OP_RETURN_MAX_LEN", 83); +_export("WALLY_MAX_OP_RETURN_LEN", 80); +_export("WALLY_SCRIPTSIG_P2PKH_MAX_LEN", 140); +_export("WALLY_WITNESSSCRIPT_MAX_LEN", 35); +_export("WALLY_SCRIPT_HASH160", 0x1); +_export("WALLY_SCRIPT_SHA256", 0x2); +_export("WALLY_SCRIPT_AS_PUSH", 0x4); +_export("WALLY_SCRIPT_MULTISIG_SORTED", 0x8); +_export("OP_0", 0x00); +_export("OP_FALSE", 0x00); +_export("OP_PUSHDATA1", 0x4c); +_export("OP_PUSHDATA2", 0x4d); +_export("OP_PUSHDATA4", 0x4e); +_export("OP_1NEGATE", 0x4f); +_export("OP_RESERVED", 0x50); +_export("OP_1", 0x51); +_export("OP_TRUE", 0x51); +_export("OP_2", 0x52); +_export("OP_3", 0x53); +_export("OP_4", 0x54); +_export("OP_5", 0x55); +_export("OP_6", 0x56); +_export("OP_7", 0x57); +_export("OP_8", 0x58); +_export("OP_9", 0x59); +_export("OP_10", 0x5a); +_export("OP_11", 0x5b); +_export("OP_12", 0x5c); +_export("OP_13", 0x5d); +_export("OP_14", 0x5e); +_export("OP_15", 0x5f); +_export("OP_16", 0x60); +_export("OP_NOP", 0x61); +_export("OP_VER", 0x62); +_export("OP_IF", 0x63); +_export("OP_NOTIF", 0x64); +_export("OP_VERIF", 0x65); +_export("OP_VERNOTIF", 0x66); +_export("OP_ELSE", 0x67); +_export("OP_ENDIF", 0x68); +_export("OP_VERIFY", 0x69); +_export("OP_RETURN", 0x6a); +_export("OP_TOALTSTACK", 0x6b); +_export("OP_FROMALTSTACK", 0x6c); +_export("OP_2DROP", 0x6d); +_export("OP_2DUP", 0x6e); +_export("OP_3DUP", 0x6f); +_export("OP_2OVER", 0x70); +_export("OP_2ROT", 0x71); +_export("OP_2SWAP", 0x72); +_export("OP_IFDUP", 0x73); +_export("OP_DEPTH", 0x74); +_export("OP_DROP", 0x75); +_export("OP_DUP", 0x76); +_export("OP_NIP", 0x77); +_export("OP_OVER", 0x78); +_export("OP_PICK", 0x79); +_export("OP_ROLL", 0x7a); +_export("OP_ROT", 0x7b); +_export("OP_SWAP", 0x7c); +_export("OP_TUCK", 0x7d); +_export("OP_CAT", 0x7e); +_export("OP_SUBSTR", 0x7f); +_export("OP_LEFT", 0x80); +_export("OP_RIGHT", 0x81); +_export("OP_SIZE", 0x82); +_export("OP_INVERT", 0x83); +_export("OP_AND", 0x84); +_export("OP_OR", 0x85); +_export("OP_XOR", 0x86); +_export("OP_EQUAL", 0x87); +_export("OP_EQUALVERIFY", 0x88); +_export("OP_RESERVED1", 0x89); +_export("OP_RESERVED2", 0x8a); +_export("OP_1ADD", 0x8b); +_export("OP_1SUB", 0x8c); +_export("OP_2MUL", 0x8d); +_export("OP_2DIV", 0x8e); +_export("OP_NEGATE", 0x8f); +_export("OP_ABS", 0x90); +_export("OP_NOT", 0x91); +_export("OP_0NOTEQUAL", 0x92); +_export("OP_ADD", 0x93); +_export("OP_SUB", 0x94); +_export("OP_MUL", 0x95); +_export("OP_DIV", 0x96); +_export("OP_MOD", 0x97); +_export("OP_LSHIFT", 0x98); +_export("OP_RSHIFT", 0x99); +_export("OP_BOOLAND", 0x9a); +_export("OP_BOOLOR", 0x9b); +_export("OP_NUMEQUAL", 0x9c); +_export("OP_NUMEQUALVERIFY", 0x9d); +_export("OP_NUMNOTEQUAL", 0x9e); +_export("OP_LESSTHAN", 0x9f); +_export("OP_GREATERTHAN", 0xa0); +_export("OP_LESSTHANOREQUAL", 0xa1); +_export("OP_GREATERTHANOREQUAL", 0xa2); +_export("OP_MIN", 0xa3); +_export("OP_MAX", 0xa4); +_export("OP_WITHIN", 0xa5); +_export("OP_RIPEMD160", 0xa6); +_export("OP_SHA1", 0xa7); +_export("OP_SHA256", 0xa8); +_export("OP_HASH160", 0xa9); +_export("OP_HASH256", 0xaa); +_export("OP_CODESEPARATOR", 0xab); +_export("OP_CHECKSIG", 0xac); +_export("OP_CHECKSIGVERIFY", 0xad); +_export("OP_CHECKMULTISIG", 0xae); +_export("OP_CHECKMULTISIGVERIFY", 0xaf); +_export("OP_NOP1", 0xb0); +_export("OP_CHECKLOCKTIMEVERIFY", 0xb1); +_export("OP_NOP2", 0xb1); +_export("OP_CHECKSEQUENCEVERIFY", 0xb2); +_export("OP_NOP3", 0xb2); +_export("OP_NOP4", 0xb3); +_export("OP_NOP5", 0xb4); +_export("OP_NOP6", 0xb5); +_export("OP_NOP7", 0xb6); +_export("OP_NOP8", 0xb7); +_export("OP_NOP9", 0xb8); +_export("OP_NOP10", 0xb9); +_export("OP_INVALIDOPCODE", 0xff); +_export("SYMMETRIC_KEY_LEN", 32); +_export("WALLY_TX_SEQUENCE_FINAL", 0xffffffff); +_export("WALLY_TX_VERSION_1", 1); +_export("WALLY_TX_VERSION_2", 2); +_export("WALLY_TX_IS_ELEMENTS", 1); +_export("WALLY_TX_IS_ISSUANCE", 2); +_export("WALLY_TX_IS_PEGIN", 4); +_export("WALLY_TX_IS_COINBASE", 8); +_export("WALLY_SATOSHI_PER_BTC", 100000000); +_export("WALLY_BTC_MAX", 21000000); +_export("WALLY_TXHASH_LEN", 32); +_export("WALLY_TX_FLAG_USE_WITNESS", 0x1); +_export("WALLY_TX_FLAG_USE_ELEMENTS", 0x2); +_export("WALLY_TX_FLAG_BLINDED_INITIAL_ISSUANCE", 0x1); +_export("WALLY_TX_DUMMY_NULL", 0x1); +_export("WALLY_TX_DUMMY_SIG", 0x2); +_export("WALLY_TX_DUMMY_SIG_LOW_R", 0x4); +_export("WALLY_SIGHASH_ALL", 0x01); +_export("WALLY_SIGHASH_NONE", 0x02); +_export("WALLY_SIGHASH_SINGLE", 0x03); +_export("WALLY_SIGHASH_FORKID", 0x40); +_export("WALLY_SIGHASH_ANYONECANPAY", 0x80); +_export("WALLY_TX_ASSET_CT_VALUE_PREFIX_A", 8); +_export("WALLY_TX_ASSET_CT_VALUE_PREFIX_B", 9); +_export("WALLY_TX_ASSET_CT_ASSET_PREFIX_A", 10); +_export("WALLY_TX_ASSET_CT_ASSET_PREFIX_B", 11); +_export("WALLY_TX_ASSET_CT_NONCE_PREFIX_A", 2); +_export("WALLY_TX_ASSET_CT_NONCE_PREFIX_B", 3); +_export("WALLY_TX_ASSET_TAG_LEN", 32); +_export("WALLY_TX_ASSET_CT_VALUE_LEN", 33); +_export("WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN", 9); +_export("WALLY_TX_ASSET_CT_ASSET_LEN", 33); +_export("WALLY_TX_ASSET_CT_NONCE_LEN", 33); +_export("WALLY_TX_ASSET_CT_LEN", 33); +_export("WALLY_TX_ISSUANCE_FLAG", (1 << 31)); +_export("WALLY_TX_PEGIN_FLAG", (1 << 30)); +_export("WALLY_TX_INDEX_MASK", 0x3fffffff); \ No newline at end of file diff --git a/wrap_js/__test__/AddScriptHashSign.spec.js b/wrap_js/__test__/AddScriptHashSign.spec.js new file mode 100644 index 00000000..5bcfe5e8 --- /dev/null +++ b/wrap_js/__test__/AddScriptHashSign.spec.js @@ -0,0 +1,108 @@ +const {AddScriptHashSign} = require('../cfdjs_raw_module'); +const TestHelper = require('./TestHelper'); + +const testCase = [ + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign witness stack type sign derEncode', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4c","vout":0,"signParam":[{"hex":"47ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb","type":"sign","derEncode":true,"sighashType":"all"}],"redeemScript":"2103a7fd499f727ca9343de6eebf651addffd06b28f62f4c23da2c2ee31c7b1d7a6eac","hashType":"p2sh"}}'], + '{"hex":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea000000006c473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb01232103a7fd499f727ca9343de6eebf651addffd06b28f62f4c23da2c2ee31c7b1d7a6eacffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000"}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign multisig p2wsh', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4c","vout":0,"signParam":[{"hex":"47ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb","type":"sign","derEncode":true,"sighashType":"all"},{"hex":"2c94045956c8df3e4154e9412f21b225d98c3f34a53744b204536c753590c43d77c89fa4a7b48758f47e871bce8f47795f0aab07c1ba3b1936bee93af90f08c2","type":"sign","derEncode":true,"sighashType":"all"}],"redeemScript":"52210205ffcdde75f262d66ada3dd877c7471f8f8ee9ee24d917c3e18d01cee458bafe2102be61f4350b4ae7544f99649a917f48ba16cf48c983ac1599774958d88ad17ec552ae","hashType":"p2wsh"}}'], + '{"hex":"020000000001014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c63296049032620400473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb0147304402202c94045956c8df3e4154e9412f21b225d98c3f34a53744b204536c753590c43d022077c89fa4a7b48758f47e871bce8f47795f0aab07c1ba3b1936bee93af90f08c2014752210205ffcdde75f262d66ada3dd877c7471f8f8ee9ee24d917c3e18d01cee458bafe2102be61f4350b4ae7544f99649a917f48ba16cf48c983ac1599774958d88ad17ec552ae00000000"}', + ), + TestHelper.createElementsTestCase( + 'AddScriptHashSign witness stack hex empty', + AddScriptHashSign, + ['{"tx":"020000000101319bff5f4311e6255ecf4dd472650a6ef85fde7d11cd10d3e6ba5974174aeb560100000000ffffffff020ae145e8632536e224757bd032e072746d30abf69b354988400edf39983f008793084922fb4232da7c9d12c88dcbf329175771bf4333bbbea23343e86023490253b4037400a34d389ced89874ab4fcd56b4a6b5d224c6fbe7e35598a27819b2c3c7a211976a9146a98a3f2935718df72518c00768ec67c589e0b2888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f0100000000004c4b40000000000000000000004301000173423ed95c29c059e93ee3becbd2a5e92cbf9e4ff5e54295c6602b7e997276141c367723a203679ef194e21280e652387926a586a3561ed9d3ec47b88eb18bb6fdcd0d602b0000000000000001373b0d3a0ae0e9b18d3b990f3050cd390391943ec0858a96a05f39900b2b46e60e7d9af5ebefecf46ada21a5cddb6d60b7df85d6896a4dfc2a3c0c452b7e1024805603253f2a1768c59d3dfce39234bec188a9b3f795f0dde4dafdc477942ee36698556e39eecf5c327cece7e05b912d254fc0cbd83dfb3f41fdc8b8ce43221cb06a82be5e05891517a78c3b9ca0c55266a9111603dc0ef78e19761448403cf4b104b2a4acd0bdecb45c3b35c8eaa024a5db7891c1a8d3282c3f7406e770ac9a6fe5b7e7a6abb1446badbf1feb0a1ab707d6ddee05eaf62ac45405ee45be142027cce0ca05d92368d30a0a9423da5d71edb75c221763c8a6703e47d1a958fe7447f9c8d8aadf1c29b45d3cc32d4ff40cca9c734347e0c5549f98d8b461141db694b6bda0f71d6891561ef4e000917ea0ab571d13ed81ede908b34dccb7e1c9f51e151d912bfeeaddc848066bf04c8eb1751ec15bbed66f8e787db2a152161f79f9a459870c713684c3f2c9537fbf7c0f932e47eb478fb78e9cb98a6a0d64a08b61070d63e244eacb01e12d2e6cc03a312589130294e4dad665051182367b4fb468f135ae89a77670365317d0e72a992dccbeca32519f755686ca218572e9a95ce129c09dd5209202cf4a234a947738efcfe4fa1009e02267ecfdc434a3bbda321664c63420607f2493d562df2ad42d3eb5dfcf5cd59820b27f1f87d4cb887ba833c73ecccf90d61d13f67484c0169cf27bca2ac6ce4898b07a035508382b932395eaaaff852be4faabee9023679a2652892d2e43e4f77bed08a25a5b3576a318c2e017c1a4f05597760b0ae7b484a0fd32777ebeeaa4ee94f8475cbde545469f254d21b36dbd590fc6daf68b58f694cfd42054e8c03fc4f72631a977ed5a6097516c56ebd6bde09b4db18a8577e3d948660b0ad2f3f86c75e97d6845ee98874dd88a934bf5f7b43fc029f0cf04a2e91caa881d87875fdd32c9f9097f29e9e72d08efad9c2399eb58d6df098cf004845360a8b25d3087c0cf7494aa42f872ee72dae4c8adc3060a141d65d029031955906acd9b7b60407bd696a20688d25109cb0055c43f3262b67c4c6d0da1cd6d60388dcfe5431df7c1a32a9b60bd930b70bf79138c25f38604022d5eaec14f175aab58a4e044d1fe4c6918459fd30e73dab508b94fba643d86dd0e6243767ac88ccd28d433496e71a709c6c52c0076ce7ed6450d2b3b322a691e000011d70daef0fe3b1cbc73f05fe631d1bcd1360b9234469849b08d68f9fac265be8ea2815dc60a53fd1eeb9d3bd55896fa3c5743f587af8c799a6788d083d1ba9d96223735cad17ac046b75d975765c7817a5027b4999bda9e4a26aa020b63595d6f3b50f0ade2b4d66235e3dd8a2840aa0b218aae98218b2fa9b6a7f9ab217f2c43279bf8f260f1dbc31f96e4fded5d666bb29fe66e81ff2642b9de74c5b001d61619e6b90d879059308b3c7e788537f4955e0eae16816063703a44a51de6d161820f71ca597213f4b48e5d3e2d79fafe6fc42914f232822f6ba5d0df88ef3b9e824ec1d0a2a59704a0780562513540a864c650fd9a293e870e556771ececc756ab9e33b166a31933446a066de03fa77f0b41b41fcb0708ce7bf03d5a6e3e6a3baf1df5b1a266ca7670a15666c8dcd62e712ea5f5d7245dd1e1987da48a08241348ab3dd84a6c386cf5b3f080bcf1dec3d843462cd24955794fe76a6865b1368a25398540d2c1ce1c2149fae9757da0addbe681fea4a314e3b52de9d73b228ca24a0c53aed9f715c95f3f6795bbfecf2ed88c3cda95585a89a85302862269bf99676a95da18d8c5cddcf27f4775f629581435a961bd929609db6c08a4b600b713bfe7f313f917cc9df9fd73c64119aafdba79163524d6d9ba217d8119cb3189ba47680a007e30522f6171141e330e91c8f6e0958bc0d0324853fd82232e784dd56d8a20cf36308975b1a510672478181e64f1900a4fc16927d35700e6d8b8c8b8e458d62992508b579cb2b36a870d92804798d9f5ca2113ab088fd06d7b04cf9a2f9dc0aa7d23f3586faca692fc733d0dbcdc66d0095b801feb3934010f5e8034e08af89812c64d79570f11d056018201386a97730895f31c58e21079c3ab720d0a60f1f9b12310687fa12a02463848b06aff07a6e9e2b4cd4774e298f3eaa7074e77395e0264eccf4addd435dd64212da06ebe02ac7c19237d2972c2f7bb3fc6a796b99a0eeabedfe35c6771e7a784d314b041a0ec1116da39fe604ae479175b609f16832ee69594ea738ea300e693e82db41d2c677d32d523b8233b2bdbc3236d1b74c17e1e20100460a452e03df52868e435688078600fe1e76be1c651425b097dc6b15b1fcf056e33a11ca33e03db9fec4a0f8c8b2762858f4ed4996120d239f57b67273d8d9e1422f81557fbf2b435e96c437a06e68ddec059b2a88646b8a81c12f42a08b311d15c0f8cda3857f48010abac55cee2df7f2195726c1d012c8602b164430cf040d5a78308d8d2752a87de8c46cff8cec0e54a5d40853f780273682e66fa507642f2e0888a110068444105bdfa7a450471a395dbaa9b30ca32c8d20faeeb1ebfd4b7cd0580deae21cbc986ad3165562035b1e0b6c2070751fc56431c046cc291e4d7870fce5535e049d39861bda942a54bdfe971ef23f2cba394136b3c0562881b6daf1ff4d3d28a75b3faa4e0dca313a0c57d8115310ce12c85a309a4b94f4e72a1dba9c3954ab5d7c2995b78eb349c39bba9e47411f9fd2eae450dafe176853daee6fd09578932d049fd600562d16d851944a6b49f6dfd001b90bee895604d9369c338cb0746c62ac7a1ccd9957a38f3c399d6a66a4116227dc0a0e82d43656317fc94f74eb8e5fe46b9dfc82157abf0dfe3186b0d36c920de8f50db89bdf73aba20241583062366bf4502266afafd649891651ebc2b7e838a9027db40320a307f35eb17e413e9af0cf5593ad465107096d7520834a8e66fc93d268bef0f1308899e98cc039b2766e2f40c671355239d5cbd1478fee223c81f0f4c8b2c30ea50319f58f52ba9fd715bc0856b2225906fa9c4fd0c5936c2df6be8e32dafcc3b1759e94cd1b75e7e1d8366661b599b38072b25900ed9dfeecbc893b0f049a731b7a8c35473cdf6a0962872c2c03a3074ac73502edbbbbbfc0ec8c012e3f994300c8e329a4ae6af970aa590c60541c50a96570ff749c022da5b47e5424afec3484185137dc3f44e4fed022c238ee2d6200171dd09555851fb2b07d3b5814a2c9a50383dc9ecb5f9a29bd18d1359a6c4b914fd0e13c16a6f45faf39c54cad0ff25f61c65ab6d02017bf81ca1e8969dcb52f91be435bea6f9d49e214d11ef16001072cbe3c6e32cce57c0ee0b050026939c349b2280eb16247265039325a623b8e05c93bb9ac1f71ba0725258eddae1fd99dd9cd941cfdd29a8601209547b6db8ba8834654046168a7787e2bf32e7971e5e2c710e9e426507ccf91cebbf24ff154568ef510419dd4fe88bd214c3d07b67fc624a458170bcc7f5f4d7cd1c83b970a1e0524a9510a601548555356a30eb5091e69df721ae3fa3a47f9e2f60132cb9457dfbe64102067978744fbcffb273b0c1c6fa8605de4991ba9dfe008d5fb9abb6414003e42772e88e83530e43c84431c7bc1994b05a75d6b13c046a4943457593f017fbe3054f4f618be6680d44af44c4036374251e6574779147d4b8f52372bb3f9cd1e72c1bc7f85577ffef629d7104f83269036244ce1ec10a0062c9222fddeadf891532b86c5c70598576cada11daff2d5ffab79bd70599011613a1a393d303e9383a2744224469ec6a1605cc137c96f047c90beaa676e61f9c773d3ce2b90e98d6eb53cfb5d2f49b2059a8a408a7e1dd1a5cdd1e9a48c931cd99fd2be75bdfce4ec7d1dac0f9a45a6894ea60bd6c81dc57533b5e67a34ba7be7d9f189b6c2b672bc8e474381536760f3d18819b5534d308bdb8baacf332540738a47bc80e82f23389c0d38c6a32107933912cb3c675c9807252ab2de793eaf225efc93453579879e60a6ff22c5ffde2ca7b01451e8e8c2c01711c5589b6612d15c2b28400b6f68cf8a20a97d85972d30b5bcd02daa032975646e2250997439b26b0928ed627983f704c1494cec4e60fdf45ce6908f22cee977c78df7ed89300fb4ff31872847b0001d610f8501c2f4c5d931130d6f692a486f0653da71dbb7e00a2de843fba42df811ac30b4768e8f645d9cd0e8d3674c72cf40b3748217f17ab1fcf77ca6aba58ee80fd17c60ceb91799fb03003ed39d1a8c8eecc8585342f2335f42103bbe39c9aa4f32afa65e801dd8ba7565b95d1068e53dc88de1a977642eacc6715aa713dba151cd3ac9e8c6647afb125a92278627700846811a29511a1454cefff17e46c1fabfd3dc41c830f22d1e034be21556e1ce87dc6ceed03c0c131767c49914cbfe87290169f3d1f523ee2f9d404b80a280883b99522f0d2239701f2a893c4eeaa4b6a360cd40276c8b32fcf26c9c0ecc462ffa02d0b360d543a93546a6801997707b7a3e271caaedc156a48a707d1e82389d34fa38dad220d83a0d599ac6e5350fc5e10172c226a0c994220add343b8d620ac9ed0c9e3d7fe423ca0a345e8111aa1a7af1a5b4055c85e0e9d85c823648bb6d85ee7f728d7ce8207ecdb9f11674bd164503c0de65107550386bb8dcbbc8cee18b262ee6ba6b5e746afffe81e91081ab6553c92636c86e4f2e2b5ab40f4620df839e7e0827046ead9f3f7360bd4b91bd6d207ad1d07db2e9c09e8fd8ab8a6e35d3e6d50abd013e523704a0abadf364204e381557708f8ce5bf01405268103106bcbfcd5de6361550d9b490b74e7e13a0428313f4b98effa287f33bc86afd524dae49c55652392f60146bc1bb1c3fd1439e2672bcf8102cdd96b5c9f0352b7a0a55e1c62aef8443cf076df77beb0f13e7933896c179f0ac2a7b4728ed9e40000","isElements":true,"txin":{"txid":"56eb4a177459bae6d310cd117dde5ff86e0a6572d44dcf5e25e611435fff9b31","vout":1,"signParam":[{"hex":"3044022054b6116e20efb6da997e4fabe8e0af10ecb7b9d5009050795c21475ca4c6f3c60220717787bc18eb2064b49a18cb8dec8b3bbaeb68ea71c58fa73bb1ec7e19d2cb2601","type":"binary","derEncode":false,"sighashType":"all"},{"hex":"2c94045956c8df3e4154e9412f21b225d98c3f34a53744b204536c753590c43d77c89fa4a7b48758f47e871bce8f47795f0aab07c1ba3b1936bee93af90f08c2","type":"sign","derEncode":true,"sighashType":"all"}],"redeemScript":"52210205ffcdde75f262d66ada3dd877c7471f8f8ee9ee24d917c3e18d01cee458bafe2102be61f4350b4ae7544f99649a917f48ba16cf48c983ac1599774958d88ad17ec552ae","hashType":"p2wsh"}}'], + '{"hex":"020000000101319bff5f4311e6255ecf4dd472650a6ef85fde7d11cd10d3e6ba5974174aeb560100000000ffffffff020ae145e8632536e224757bd032e072746d30abf69b354988400edf39983f008793084922fb4232da7c9d12c88dcbf329175771bf4333bbbea23343e86023490253b4037400a34d389ced89874ab4fcd56b4a6b5d224c6fbe7e35598a27819b2c3c7a211976a9146a98a3f2935718df72518c00768ec67c589e0b2888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f0100000000004c4b4000000000000000000400473044022054b6116e20efb6da997e4fabe8e0af10ecb7b9d5009050795c21475ca4c6f3c60220717787bc18eb2064b49a18cb8dec8b3bbaeb68ea71c58fa73bb1ec7e19d2cb260147304402202c94045956c8df3e4154e9412f21b225d98c3f34a53744b204536c753590c43d022077c89fa4a7b48758f47e871bce8f47795f0aab07c1ba3b1936bee93af90f08c2014752210205ffcdde75f262d66ada3dd877c7471f8f8ee9ee24d917c3e18d01cee458bafe2102be61f4350b4ae7544f99649a917f48ba16cf48c983ac1599774958d88ad17ec552ae004301000173423ed95c29c059e93ee3becbd2a5e92cbf9e4ff5e54295c6602b7e997276141c367723a203679ef194e21280e652387926a586a3561ed9d3ec47b88eb18bb6fdcd0d602b0000000000000001373b0d3a0ae0e9b18d3b990f3050cd390391943ec0858a96a05f39900b2b46e60e7d9af5ebefecf46ada21a5cddb6d60b7df85d6896a4dfc2a3c0c452b7e1024805603253f2a1768c59d3dfce39234bec188a9b3f795f0dde4dafdc477942ee36698556e39eecf5c327cece7e05b912d254fc0cbd83dfb3f41fdc8b8ce43221cb06a82be5e05891517a78c3b9ca0c55266a9111603dc0ef78e19761448403cf4b104b2a4acd0bdecb45c3b35c8eaa024a5db7891c1a8d3282c3f7406e770ac9a6fe5b7e7a6abb1446badbf1feb0a1ab707d6ddee05eaf62ac45405ee45be142027cce0ca05d92368d30a0a9423da5d71edb75c221763c8a6703e47d1a958fe7447f9c8d8aadf1c29b45d3cc32d4ff40cca9c734347e0c5549f98d8b461141db694b6bda0f71d6891561ef4e000917ea0ab571d13ed81ede908b34dccb7e1c9f51e151d912bfeeaddc848066bf04c8eb1751ec15bbed66f8e787db2a152161f79f9a459870c713684c3f2c9537fbf7c0f932e47eb478fb78e9cb98a6a0d64a08b61070d63e244eacb01e12d2e6cc03a312589130294e4dad665051182367b4fb468f135ae89a77670365317d0e72a992dccbeca32519f755686ca218572e9a95ce129c09dd5209202cf4a234a947738efcfe4fa1009e02267ecfdc434a3bbda321664c63420607f2493d562df2ad42d3eb5dfcf5cd59820b27f1f87d4cb887ba833c73ecccf90d61d13f67484c0169cf27bca2ac6ce4898b07a035508382b932395eaaaff852be4faabee9023679a2652892d2e43e4f77bed08a25a5b3576a318c2e017c1a4f05597760b0ae7b484a0fd32777ebeeaa4ee94f8475cbde545469f254d21b36dbd590fc6daf68b58f694cfd42054e8c03fc4f72631a977ed5a6097516c56ebd6bde09b4db18a8577e3d948660b0ad2f3f86c75e97d6845ee98874dd88a934bf5f7b43fc029f0cf04a2e91caa881d87875fdd32c9f9097f29e9e72d08efad9c2399eb58d6df098cf004845360a8b25d3087c0cf7494aa42f872ee72dae4c8adc3060a141d65d029031955906acd9b7b60407bd696a20688d25109cb0055c43f3262b67c4c6d0da1cd6d60388dcfe5431df7c1a32a9b60bd930b70bf79138c25f38604022d5eaec14f175aab58a4e044d1fe4c6918459fd30e73dab508b94fba643d86dd0e6243767ac88ccd28d433496e71a709c6c52c0076ce7ed6450d2b3b322a691e000011d70daef0fe3b1cbc73f05fe631d1bcd1360b9234469849b08d68f9fac265be8ea2815dc60a53fd1eeb9d3bd55896fa3c5743f587af8c799a6788d083d1ba9d96223735cad17ac046b75d975765c7817a5027b4999bda9e4a26aa020b63595d6f3b50f0ade2b4d66235e3dd8a2840aa0b218aae98218b2fa9b6a7f9ab217f2c43279bf8f260f1dbc31f96e4fded5d666bb29fe66e81ff2642b9de74c5b001d61619e6b90d879059308b3c7e788537f4955e0eae16816063703a44a51de6d161820f71ca597213f4b48e5d3e2d79fafe6fc42914f232822f6ba5d0df88ef3b9e824ec1d0a2a59704a0780562513540a864c650fd9a293e870e556771ececc756ab9e33b166a31933446a066de03fa77f0b41b41fcb0708ce7bf03d5a6e3e6a3baf1df5b1a266ca7670a15666c8dcd62e712ea5f5d7245dd1e1987da48a08241348ab3dd84a6c386cf5b3f080bcf1dec3d843462cd24955794fe76a6865b1368a25398540d2c1ce1c2149fae9757da0addbe681fea4a314e3b52de9d73b228ca24a0c53aed9f715c95f3f6795bbfecf2ed88c3cda95585a89a85302862269bf99676a95da18d8c5cddcf27f4775f629581435a961bd929609db6c08a4b600b713bfe7f313f917cc9df9fd73c64119aafdba79163524d6d9ba217d8119cb3189ba47680a007e30522f6171141e330e91c8f6e0958bc0d0324853fd82232e784dd56d8a20cf36308975b1a510672478181e64f1900a4fc16927d35700e6d8b8c8b8e458d62992508b579cb2b36a870d92804798d9f5ca2113ab088fd06d7b04cf9a2f9dc0aa7d23f3586faca692fc733d0dbcdc66d0095b801feb3934010f5e8034e08af89812c64d79570f11d056018201386a97730895f31c58e21079c3ab720d0a60f1f9b12310687fa12a02463848b06aff07a6e9e2b4cd4774e298f3eaa7074e77395e0264eccf4addd435dd64212da06ebe02ac7c19237d2972c2f7bb3fc6a796b99a0eeabedfe35c6771e7a784d314b041a0ec1116da39fe604ae479175b609f16832ee69594ea738ea300e693e82db41d2c677d32d523b8233b2bdbc3236d1b74c17e1e20100460a452e03df52868e435688078600fe1e76be1c651425b097dc6b15b1fcf056e33a11ca33e03db9fec4a0f8c8b2762858f4ed4996120d239f57b67273d8d9e1422f81557fbf2b435e96c437a06e68ddec059b2a88646b8a81c12f42a08b311d15c0f8cda3857f48010abac55cee2df7f2195726c1d012c8602b164430cf040d5a78308d8d2752a87de8c46cff8cec0e54a5d40853f780273682e66fa507642f2e0888a110068444105bdfa7a450471a395dbaa9b30ca32c8d20faeeb1ebfd4b7cd0580deae21cbc986ad3165562035b1e0b6c2070751fc56431c046cc291e4d7870fce5535e049d39861bda942a54bdfe971ef23f2cba394136b3c0562881b6daf1ff4d3d28a75b3faa4e0dca313a0c57d8115310ce12c85a309a4b94f4e72a1dba9c3954ab5d7c2995b78eb349c39bba9e47411f9fd2eae450dafe176853daee6fd09578932d049fd600562d16d851944a6b49f6dfd001b90bee895604d9369c338cb0746c62ac7a1ccd9957a38f3c399d6a66a4116227dc0a0e82d43656317fc94f74eb8e5fe46b9dfc82157abf0dfe3186b0d36c920de8f50db89bdf73aba20241583062366bf4502266afafd649891651ebc2b7e838a9027db40320a307f35eb17e413e9af0cf5593ad465107096d7520834a8e66fc93d268bef0f1308899e98cc039b2766e2f40c671355239d5cbd1478fee223c81f0f4c8b2c30ea50319f58f52ba9fd715bc0856b2225906fa9c4fd0c5936c2df6be8e32dafcc3b1759e94cd1b75e7e1d8366661b599b38072b25900ed9dfeecbc893b0f049a731b7a8c35473cdf6a0962872c2c03a3074ac73502edbbbbbfc0ec8c012e3f994300c8e329a4ae6af970aa590c60541c50a96570ff749c022da5b47e5424afec3484185137dc3f44e4fed022c238ee2d6200171dd09555851fb2b07d3b5814a2c9a50383dc9ecb5f9a29bd18d1359a6c4b914fd0e13c16a6f45faf39c54cad0ff25f61c65ab6d02017bf81ca1e8969dcb52f91be435bea6f9d49e214d11ef16001072cbe3c6e32cce57c0ee0b050026939c349b2280eb16247265039325a623b8e05c93bb9ac1f71ba0725258eddae1fd99dd9cd941cfdd29a8601209547b6db8ba8834654046168a7787e2bf32e7971e5e2c710e9e426507ccf91cebbf24ff154568ef510419dd4fe88bd214c3d07b67fc624a458170bcc7f5f4d7cd1c83b970a1e0524a9510a601548555356a30eb5091e69df721ae3fa3a47f9e2f60132cb9457dfbe64102067978744fbcffb273b0c1c6fa8605de4991ba9dfe008d5fb9abb6414003e42772e88e83530e43c84431c7bc1994b05a75d6b13c046a4943457593f017fbe3054f4f618be6680d44af44c4036374251e6574779147d4b8f52372bb3f9cd1e72c1bc7f85577ffef629d7104f83269036244ce1ec10a0062c9222fddeadf891532b86c5c70598576cada11daff2d5ffab79bd70599011613a1a393d303e9383a2744224469ec6a1605cc137c96f047c90beaa676e61f9c773d3ce2b90e98d6eb53cfb5d2f49b2059a8a408a7e1dd1a5cdd1e9a48c931cd99fd2be75bdfce4ec7d1dac0f9a45a6894ea60bd6c81dc57533b5e67a34ba7be7d9f189b6c2b672bc8e474381536760f3d18819b5534d308bdb8baacf332540738a47bc80e82f23389c0d38c6a32107933912cb3c675c9807252ab2de793eaf225efc93453579879e60a6ff22c5ffde2ca7b01451e8e8c2c01711c5589b6612d15c2b28400b6f68cf8a20a97d85972d30b5bcd02daa032975646e2250997439b26b0928ed627983f704c1494cec4e60fdf45ce6908f22cee977c78df7ed89300fb4ff31872847b0001d610f8501c2f4c5d931130d6f692a486f0653da71dbb7e00a2de843fba42df811ac30b4768e8f645d9cd0e8d3674c72cf40b3748217f17ab1fcf77ca6aba58ee80fd17c60ceb91799fb03003ed39d1a8c8eecc8585342f2335f42103bbe39c9aa4f32afa65e801dd8ba7565b95d1068e53dc88de1a977642eacc6715aa713dba151cd3ac9e8c6647afb125a92278627700846811a29511a1454cefff17e46c1fabfd3dc41c830f22d1e034be21556e1ce87dc6ceed03c0c131767c49914cbfe87290169f3d1f523ee2f9d404b80a280883b99522f0d2239701f2a893c4eeaa4b6a360cd40276c8b32fcf26c9c0ecc462ffa02d0b360d543a93546a6801997707b7a3e271caaedc156a48a707d1e82389d34fa38dad220d83a0d599ac6e5350fc5e10172c226a0c994220add343b8d620ac9ed0c9e3d7fe423ca0a345e8111aa1a7af1a5b4055c85e0e9d85c823648bb6d85ee7f728d7ce8207ecdb9f11674bd164503c0de65107550386bb8dcbbc8cee18b262ee6ba6b5e746afffe81e91081ab6553c92636c86e4f2e2b5ab40f4620df839e7e0827046ead9f3f7360bd4b91bd6d207ad1d07db2e9c09e8fd8ab8a6e35d3e6d50abd013e523704a0abadf364204e381557708f8ce5bf01405268103106bcbfcd5de6361550d9b490b74e7e13a0428313f4b98effa287f33bc86afd524dae49c55652392f60146bc1bb1c3fd1439e2672bcf8102cdd96b5c9f0352b7a0a55e1c62aef8443cf076df77beb0f13e7933896c179f0ac2a7b4728ed9e40000"}', + ), +]; + +const errorCase = [ + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign empty hex string', + AddScriptHashSign, + ['{"tx":"","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4c","vout":0,"signParam":[{"hex":"11111111","type":"binary","derEncode":false,"sighashType":"all"}]}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"transaction data invalid."}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign invalid hex string(3 chars)', + AddScriptHashSign, + ['{"tx":"000","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4c","vout":0,"signParam":[{"hex":"11111111","type":"binary","derEncode":false,"sighashType":"all"}],"redeemScript":"","hashType":"p2wsh"}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"hex to byte convert error."}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign empty txid string', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"","vout":0,"signParam":[{"hex":"11111111","type":"binary","derEncode":false,"sighashType":"all"}],"redeemScript":"","hashType":"p2wsh"}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"Txid size Invalid."}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign invalid txid string (20 chars)', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"ea9d5a9e974af1d16730","vout":0,"signParam":[{"hex":"11111111","type":"binary","derEncode":false,"sighashType":"all"}],"redeemScript":"","hashType":"p2wsh"}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"Txid size Invalid."}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign txid not found', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4d","vout":0,"signParam":[{"hex":"11111111","type":"binary","derEncode":false,"sighashType":"all"}],"redeemScript":"51","hashType":"p2wsh"}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"Txid is not found."}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign append signature to invalid txin(vout: -1)', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4c","vout":-1,"signParam":[{"hex":"11111111","type":"binary","derEncode":false,"sighashType":"all"}],"redeemScript":"51","hashType":"p2wsh"}}'], + '{"error":{"code":3,"type":"out_of_range","message":"Json value convert error. Value out of range."}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign append signature to invalid txin(vout: 1)', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4c","vout":1,"signParam":[{"hex":"11111111","type":"binary","derEncode":false,"sighashType":"all"}],"redeemScript":"51","hashType":"p2wsh"}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"Txid is not found."}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign invalid witness stack hex (3 chars)', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4c","vout":0,"signParam":[{"hex":"111","type":"binary","derEncode":false,"sighashType":"all"}],"redeemScript":"51","hashType":"p2wsh"}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"hex to byte convert error."}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign empty witness stack sighashType', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4c","vout":0,"signParam":[{"hex":"47ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb","type":"sign","derEncode":true,"sighashType":""}],"redeemScript":"51","hashType":"p2wsh"}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"Invalid sighashType. sighashType must be \\"all, none, single\\"."}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign invalid witness stack sighashType', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4c","vout":0,"signParam":[{"hex":"47ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb","type":"sign","derEncode":true,"sighashType":"abcde"}],"redeemScript":"51","hashType":"p2wsh"}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"Invalid sighashType. sighashType must be \\"all, none, single\\"."}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign OP_CODE not target', + AddScriptHashSign, + ['{"tx":"0100000001e007005f3b95e18a7b1faa75d13b98999f7381f345e3849a48ec1eb24c69e4a80000000000ffffffff0130ea052a010000001976a9140c989a8914b27e3a8402990000c05d081f3376c588ac00000000","txin":{"txid":"a8e4694cb21eec489a84e345f381739f99983bd175aa1f7b8ae1953b5f0007e0","vout":0,"isWitness":false,"signParam":[{"hex":"OP_TRUE","type":"auto"},{"hex":"OP_16","type":"auto"},{"hex":"OP_CHECKMULTISIG","type":"auto"}],"redeemScript":"51","hashType":"p2wsh", "clearStack":false}}'], + '{\"error\":{\"code\":1,\"type\":\"illegal_argument\",\"message\":\"Invalid signature type. signature type must be \\\"kSign\\\" or \\\"kBinary\\\".\"}}', + ), + TestHelper.createBitcoinTestCase( + 'AddScriptHashSign empty redeem script', + AddScriptHashSign, + ['{"tx":"02000000014cdeada737db97af334f0fa4e87432d6068759eea65a3067d1f14a979e5a9dea0000000000ffffffff0101000000000000002200201863143c14c5166804bd19203356da136c985678cd4d27a1b8c632960490326200000000","txin":{"txid":"ea9d5a9e974af1d167305aa6ee598706d63274e8a40f4f33af97db37a7adde4c","vout":0,"signParam":[{"hex":"47ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb","type":"sign","derEncode":true,"sighashType":"all"}],"redeemScript":"","hashType":"p2wsh"}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"Empty script."}}', + ), + TestHelper.createElementsTestCase( + 'AddScriptHashSign invalid witness stack sighashType', + AddScriptHashSign, + ['{"tx":"020000000001319bff5f4311e6255ecf4dd472650a6ef85fde7d11cd10d3e6ba5974174aeb560100000000ffffffff0201f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f0100000bd2cc1584c002deb65cc52301e1622f482a2f588b9800d2b8386ffabf74d6b2d73d17503a2f921976a9146a98a3f2935718df72518c00768ec67c589e0b2888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f0100000000004c4b40000000000000","isElements":true,"txin":{"txid":"56eb4a177459bae6d310cd117dde5ff86e0a6572d44dcf5e25e611435fff9b31","vout":1,"signParam":[{"hex":"47ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb","type":"sign","derEncode":true,"sighashType":"abcde"}],"redeemScript":"51","hashType":"p2wsh"}}'], + '{"error":{"code":1,"type":"illegal_argument","message":"Invalid sighashType. sighashType must be \\"all, none, single\\"."}}', + ), +]; + + +TestHelper.doTest('AddScriptHashSign', testCase); +TestHelper.doTest('AddScriptHashSign ErrorCase', errorCase); diff --git a/wrap_js/__test__/ConvertAes.spec.js b/wrap_js/__test__/ConvertAes.spec.js new file mode 100644 index 00000000..920f0642 --- /dev/null +++ b/wrap_js/__test__/ConvertAes.spec.js @@ -0,0 +1,59 @@ +const {ConvertAes} = require('../cfdjs_raw_module'); +const TestHelper = require('./TestHelper'); + +const testCase = [ + TestHelper.createTestCase( + 'ConvertAes encrypt', + ConvertAes, + ['{"isEncrypt": true,"mode": "cbc","key": "9876543210987654321098765432109876543210987654321098765432109876","iv": "01234567890123456789012345678901","data": "000011112222333300001111222233330000111122223333"}'], + '{"hex":"9a7012878146191eff9995851e78b322f9e5275ecd1fd50ca07136d194b0ad9b"}', + ), + TestHelper.createTestCase( + 'ConvertAes decrypt', + ConvertAes, + ['{"isEncrypt": false,"mode": "cbc","key": "9876543210987654321098765432109876543210987654321098765432109876","iv": "01234567890123456789012345678901","data": "9a7012878146191eff9995851e78b322f9e5275ecd1fd50ca07136d194b0ad9b"}'], + '{"hex":"000011112222333300001111222233330000111122223333"}', + ), +]; + +const errorCase = [ + TestHelper.createTestCase( + 'ConvertAes Error(empty key)', + ConvertAes, + ['{"isEncrypt": true,"mode": "cbc","key": "","iv": "01234567890123456789012345678901","data": "000011112222333300001111222233330000111122223333"}'], + '{\"error\":{\"code\":2,\"type\":\"illegal_state\",\"message\":\"EncryptAes256Cbc key size error.\"}}', + ), + TestHelper.createTestCase( + 'ConvertAes Error(empty iv)', + ConvertAes, + ['{"isEncrypt": true,"mode": "cbc","key": "9876543210987654321098765432109876543210987654321098765432109876","iv": "","data": "000011112222333300001111222233330000111122223333"}'], + '{\"error\":{\"code\":2,\"type\":\"illegal_state\",\"message\":\"EncryptAes256Cbc error.\"}}', + ), + TestHelper.createTestCase( + 'ConvertAes Error(empty decrypt data)', + ConvertAes, + ['{"isEncrypt": false,"mode": "cbc","key": "9876543210987654321098765432109876543210987654321098765432109876","iv": "01234567890123456789012345678901","data": ""}'], + '{\"error\":{\"code\":2,\"type\":\"illegal_state\",\"message\":\"DecryptAes256Cbc error.\"}}', + ), + TestHelper.createTestCase( + 'ConvertAes Error(invalid key)', + ConvertAes, + ['{"isEncrypt": true,"mode": "cbc","key": "00129876543210987654321098765432109876543210987654321098765432109876","iv": "01234567890123456789012345678901","data": "000011112222333300001111222233330000111122223333"}'], + '{\"error\":{\"code\":2,\"type\":\"illegal_state\",\"message\":\"EncryptAes256Cbc key size error.\"}}', + ), + TestHelper.createTestCase( + 'ConvertAes Error(invalid iv)', + ConvertAes, + ['{"isEncrypt": true,"mode": "cbc","key": "9876543210987654321098765432109876543210987654321098765432109876","iv": "001201234567890123456789012345678901","data": "000011112222333300001111222233330000111122223333"}'], + '{\"error\":{\"code\":2,\"type\":\"illegal_state\",\"message\":\"EncryptAes256Cbc error.\"}}', + ), + TestHelper.createTestCase( + 'ConvertAes Error(invalid decrypt data)', + ConvertAes, + ['{"isEncrypt": false,"mode": "cbc","key": "9876543210987654321098765432109876543210987654321098765432109876","iv": "01234567890123456789012345678901","data": "001202039a7012878146191eff9995851e78b322f9e5275ecd1fd50ca07136d194b0ad9b"}'], + '{\"error\":{\"code\":2,\"type\":\"illegal_state\",\"message\":\"DecryptAes256Cbc error.\"}}', + ), +]; + +TestHelper.doTest('ConvertAes', testCase); +TestHelper.doTest('ConvertAes ErrorCase', errorCase); diff --git a/wrap_js/__test__/DecodeBase58.spec.js b/wrap_js/__test__/DecodeBase58.spec.js new file mode 100644 index 00000000..3b2a2fc5 --- /dev/null +++ b/wrap_js/__test__/DecodeBase58.spec.js @@ -0,0 +1,35 @@ +const {DecodeBase58} = require('../cfdjs_raw_module'); +const TestHelper = require('./TestHelper'); + +const testCase = [ + TestHelper.createTestCase( + 'DecodeBase58 checkChecksum=true', + DecodeBase58, + ['{"data": "xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB", "hasChecksum": true}'], + '{"hex":"0488b21e00000000000000000060499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd968903cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7"}', + ), + TestHelper.createTestCase( + 'DecodeBase58 checkChecksum=false', + DecodeBase58, + ['{"data": "xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB", "hasChecksum": false}'], + '{"hex":"0488b21e00000000000000000060499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd968903cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7e233a252"}', + ), +]; + +const errorCase = [ + TestHelper.createTestCase( + 'DecodeBase58 Error(invalid format)', + DecodeBase58, + ['{"data": "9XpNiB4DberdMn4jZfZTsXNXKKpgdQ6Q8mFg63kyDnHd8FfRfTXPxGN27bYXRSe1TqTfe4s6MyyZVqiGTWgNiimiSSumMnnsk54MNP99U0", "hasChecksum": false}'], + '{"error":{"code":2,"type":"illegal_state","message":"Decode base58 error."}}', + ), + TestHelper.createTestCase( + 'DecodeBase58 Error(invalid checksum)', + DecodeBase58, + ['{"data": "xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGudso", "hasChecksum": true}'], + '{"error":{"code":2,"type":"illegal_state","message":"Decode base58 error."}}', + ), +]; + +TestHelper.doTest('DecodeBase58', testCase); +TestHelper.doTest('DecodeBase58 ErrorCase', errorCase); diff --git a/wrap_js/__test__/EncodeBase58.spec.js b/wrap_js/__test__/EncodeBase58.spec.js new file mode 100644 index 00000000..37b5b95c --- /dev/null +++ b/wrap_js/__test__/EncodeBase58.spec.js @@ -0,0 +1,29 @@ +const {EncodeBase58} = require('../cfdjs_raw_module'); +const TestHelper = require('./TestHelper'); + +const testCase = [ + TestHelper.createTestCase( + 'EncodeBase58 checkChecksum=true', + EncodeBase58, + ['{"hex": "0488b21e00000000000000000060499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd968903cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7", "hasChecksum": true}'], + '{"data":"xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB"}', + ), + TestHelper.createTestCase( + 'EncodeBase58 checkChecksum=false', + EncodeBase58, + ['{"hex": "0488b21e00000000000000000060499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd968903cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7e233a252", "hasChecksum": false}'], + '{"data":"xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB"}', + ), +]; + +const errorCase = [ + TestHelper.createTestCase( + 'EncodeBase58 Error(invalid hex format)', + EncodeBase58, + ['{"hex": "048", "hasChecksum": false}'], + '{\"error\":{\"code\":1,\"type\":\"illegal_argument\",\"message\":\"hex to byte convert error.\"}}', + ), +]; + +TestHelper.doTest('EncodeBase58', testCase); +TestHelper.doTest('EncodeBase58 ErrorCase', errorCase); diff --git a/wrap_js/__test__/EstimateFee.spec.js b/wrap_js/__test__/EstimateFee.spec.js index 81eef1ee..ba2dff0f 100644 --- a/wrap_js/__test__/EstimateFee.spec.js +++ b/wrap_js/__test__/EstimateFee.spec.js @@ -252,7 +252,7 @@ const elementsTestCase = [ feeAsset: FEE_ASSET, minimumBits: 36, })], - '{\"feeAmount\":1036,\"txFeeAmount\":945,\"utxoFeeAmount\":91}', + '{\"feeAmount\":1012,\"txFeeAmount\":921,\"utxoFeeAmount\":91}', ); })(), (() => { @@ -268,7 +268,7 @@ const elementsTestCase = [ feeAsset: FEE_ASSET, minimumBits: 36, })], - '{\"feeAmount\":2015,\"txFeeAmount\":1833,\"utxoFeeAmount\":182}', + '{\"feeAmount\":1984,\"txFeeAmount\":1802,\"utxoFeeAmount\":182}', ); })(), (() => { @@ -284,7 +284,7 @@ const elementsTestCase = [ feeAsset: FEE_ASSET, minimumBits: 36, })], - '{\"feeAmount\":20720,\"txFeeAmount\":18900,\"utxoFeeAmount\":1820}', + '{\"feeAmount\":20240,\"txFeeAmount\":18420,\"utxoFeeAmount\":1820}', ); })(), (() => { @@ -300,7 +300,7 @@ const elementsTestCase = [ feeAsset: FEE_ASSET, minimumBits: 36, })], - '{\"feeAmount\":40300,\"txFeeAmount\":36660,\"utxoFeeAmount\":3640}', + '{\"feeAmount\":39680,\"txFeeAmount\":36040,\"utxoFeeAmount\":3640}', ); })(), (() => { @@ -316,7 +316,7 @@ const elementsTestCase = [ feeAsset: FEE_ASSET, minimumBits: 36, })], - '{\"feeAmount\":1014,\"txFeeAmount\":945,\"utxoFeeAmount\":69}', + '{\"feeAmount\":990,\"txFeeAmount\":921,\"utxoFeeAmount\":69}', ); })(), (() => { @@ -332,7 +332,7 @@ const elementsTestCase = [ feeAsset: FEE_ASSET, minimumBits: 36, })], - '{\"feeAmount\":1971,\"txFeeAmount\":1833,\"utxoFeeAmount\":138}', + '{\"feeAmount\":1940,\"txFeeAmount\":1802,\"utxoFeeAmount\":138}', ); })(), (() => { @@ -347,7 +347,7 @@ const elementsTestCase = [ isElements: true, feeAsset: FEE_ASSET, })], - '{\"feeAmount\":1344,\"txFeeAmount\":1265,\"utxoFeeAmount\":79}', + '{\"feeAmount\":1320,\"txFeeAmount\":1241,\"utxoFeeAmount\":79}', ); })(), (() => { @@ -362,7 +362,7 @@ const elementsTestCase = [ isElements: true, feeAsset: FEE_ASSET, })], - '{\"feeAmount\":2632,\"txFeeAmount\":2474,\"utxoFeeAmount\":158}', + '{\"feeAmount\":2600,\"txFeeAmount\":2442,\"utxoFeeAmount\":158}', ); })(), (() => { @@ -394,7 +394,7 @@ const elementsTestCase = [ feeAsset: FEE_ASSET, isBlind: false, })], - '{\"feeAmount\":1516,\"txFeeAmount\":1334,\"utxoFeeAmount\":182}', + '{\"feeAmount\":1501,\"txFeeAmount\":1319,\"utxoFeeAmount\":182}', ); })(), (() => { @@ -418,7 +418,7 @@ const elementsTestCase = [ feeAsset: '017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c18', minimumBits: 36, })], - '{\"feeAmount\":4387,\"txFeeAmount\":2720,\"utxoFeeAmount\":1667}', + '{\"feeAmount\":4364,\"txFeeAmount\":2697,\"utxoFeeAmount\":1667}', ); })(), (() => { @@ -443,7 +443,7 @@ const elementsTestCase = [ feeAsset: FEE_ASSET, isBlind: false, })], - '{\"feeAmount\":1536,\"txFeeAmount\":1334,\"utxoFeeAmount\":202}', + '{\"feeAmount\":1513,\"txFeeAmount\":1311,\"utxoFeeAmount\":202}', ); })(), ]; diff --git a/wrap_js/__test__/FundRawTransaction.spec.js b/wrap_js/__test__/FundRawTransaction.spec.js index 5971185f..36b17fd4 100644 --- a/wrap_js/__test__/FundRawTransaction.spec.js +++ b/wrap_js/__test__/FundRawTransaction.spec.js @@ -1025,7 +1025,7 @@ const elementsTestCase = [ minimumBits: 36, }, })], - '{"hex":"0200000000030000000100000000000000000000000000000000000000000000000000efcdab0000000000ffffffff00000003000000000000000000000000000000000000000000000000000000000000000000ffffffff00000060000000000000000000000000000000000000000000000000000000000000000000ffffffff0501efcdab8967452301efcdab8967452301efcdab8967452301efcdab8967452301010000000000e4e1c000160014d5fe71ae19437243be1fd703b88623ca1525b96201efcdabefcdabcdabefcdabefcdabefcdabefcdabefcdabefcdabefcdabefcdab01000000000001340c000001efcdab8967452301efcdab8967452301efcdab8967452301efcdab8967452301010000000002aea54000160014d5fe71ae19437243be1fd703b88623ca1525b9620134129078563412907856341290785634129078563412907856341290785634120100000000000f42400017a91436130aa418b118d85ae6d4355e7f0a897ae8b94a8701efcdabefcdabcdabefcdabefcdabefcdabefcdabefcdabefcdabefcdabefcdab0100000000002c92b403c7ab265c9460f192f02eacb6af7664dfecd17daebee23a3ace915d41639f84ff17a9141b3407a0be5d01401fae0ddfc3af014758f3aed48700000000","usedAddresses":["ert1q6hl8rtsegdey80sl6upm3p3reg2jtwtz58zkmv","XGHA9XyorJoHdaC97SJ79oBamMfg1Wrk7v","AzpwJygcRVMbrYsDsc9Xmaz3uEgFyQH3pRTtoBkmvyw86W4snH3wCdNe9cygXXH714vS7nc4qEXgvKDL"],"feeAmount":78860}', + '{"hex":"0200000000030000000100000000000000000000000000000000000000000000000000efcdab0000000000ffffffff00000003000000000000000000000000000000000000000000000000000000000000000000ffffffff00000060000000000000000000000000000000000000000000000000000000000000000000ffffffff0501efcdab8967452301efcdab8967452301efcdab8967452301efcdab8967452301010000000000e4e1c000160014d5fe71ae19437243be1fd703b88623ca1525b96201efcdabefcdabcdabefcdabefcdabefcdabefcdabefcdabefcdabefcdabefcdab0100000000000131a0000001efcdab8967452301efcdab8967452301efcdab8967452301efcdab8967452301010000000002aea54000160014d5fe71ae19437243be1fd703b88623ca1525b9620134129078563412907856341290785634129078563412907856341290785634120100000000000f42400017a91436130aa418b118d85ae6d4355e7f0a897ae8b94a8701efcdabefcdabcdabefcdabefcdabefcdabefcdabefcdabefcdabefcdabefcdab0100000000002c952003c7ab265c9460f192f02eacb6af7664dfecd17daebee23a3ace915d41639f84ff17a9141b3407a0be5d01401fae0ddfc3af014758f3aed48700000000","usedAddresses":["ert1q6hl8rtsegdey80sl6upm3p3reg2jtwtz58zkmv","XGHA9XyorJoHdaC97SJ79oBamMfg1Wrk7v","AzpwJygcRVMbrYsDsc9Xmaz3uEgFyQH3pRTtoBkmvyw86W4snH3wCdNe9cygXXH714vS7nc4qEXgvKDL"],"feeAmount":78240}', ); })(), ]; diff --git a/wrap_js/__test__/ParseDescriptor.spec.js b/wrap_js/__test__/ParseDescriptor.spec.js index 777e66f5..ae3e3a6c 100644 --- a/wrap_js/__test__/ParseDescriptor.spec.js +++ b/wrap_js/__test__/ParseDescriptor.spec.js @@ -115,6 +115,24 @@ const testCase = [ ['{"isElements":false,"descriptor":"raw(6a4c4f54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e)#zf2avljj","network":"mainnet"}'], '{\"type\":\"raw\",\"lockingScript\":\"6a4c4f54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e\",\"includeMultisig\":false}', ), + TestHelper.createBitcoinTestCase( + 'ParseDescriptor p2sh miniscript', + ParseDescriptor, + ['{"isElements":false,"descriptor":"sh(or_d(sha256(38df1c1f64a24a77b23393bca50dff872e31edc4f3b5aa3b90ad0b82f4f089b6),and_n(un:after(499999999),older(4194305))))","network":"mainnet"}'], + '{\"type\":\"sh\",\"address\":\"38WFPv9fne2UeFxVkGMhLkamMadH8j6s1c\",\"lockingScript\":\"a9144abf8cfc94ae837bf59965e0c74d02a611ec132987\",\"hashType\":\"p2sh\",\"redeemScript\":\"82012088a82038df1c1f64a24a77b23393bca50dff872e31edc4f3b5aa3b90ad0b82f4f089b68773646304ff64cd1db19267006864006703010040b26868\",\"includeMultisig\":false,\"scripts\":[{\"depth\":0,\"lockingScript\":\"a9144abf8cfc94ae837bf59965e0c74d02a611ec132987\",\"address\":\"38WFPv9fne2UeFxVkGMhLkamMadH8j6s1c\",\"redeemScript\":\"82012088a82038df1c1f64a24a77b23393bca50dff872e31edc4f3b5aa3b90ad0b82f4f089b68773646304ff64cd1db19267006864006703010040b26868\"}]}', + ), + TestHelper.createBitcoinTestCase( + 'ParseDescriptor p2wsh miniscript', + ParseDescriptor, + ['{"isElements":false,"descriptor":"wsh(thresh(2,multi(2,03a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7,036d2b085e9e382ed10b69fc311a03f8641ccfff21574de0927513a49d9a688a00),a:multi(1,036d2b085e9e382ed10b69fc311a03f8641ccfff21574de0927513a49d9a688a00),ac:pk_k(022f01e5e15cca351daff3843fb70f3c2f0a1bdd05e5af888a67784ef3e10a2a01)))","network":"mainnet"}'], + '{\"type\":\"wsh\",\"address\":\"bc1qdfky9a3dh8atpy0l47fsuz5ywergnrfztcddjnl5xgnwyqvqh8gschn2ch\",\"lockingScript\":\"00206a6c42f62db9fab091ffaf930e0a847646898d225e1ad94ff43226e20180b9d1\",\"hashType\":\"p2wsh\",\"redeemScript\":\"522103a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c721036d2b085e9e382ed10b69fc311a03f8641ccfff21574de0927513a49d9a688a0052ae6b5121036d2b085e9e382ed10b69fc311a03f8641ccfff21574de0927513a49d9a688a0051ae6c936b21022f01e5e15cca351daff3843fb70f3c2f0a1bdd05e5af888a67784ef3e10a2a01ac6c935287\",\"includeMultisig\":false,\"scripts\":[{\"depth\":0,\"lockingScript\":\"00206a6c42f62db9fab091ffaf930e0a847646898d225e1ad94ff43226e20180b9d1\",\"address\":\"bc1qdfky9a3dh8atpy0l47fsuz5ywergnrfztcddjnl5xgnwyqvqh8gschn2ch\",\"hashType\":\"p2wsh\",\"redeemScript\":\"522103a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c721036d2b085e9e382ed10b69fc311a03f8641ccfff21574de0927513a49d9a688a0052ae6b5121036d2b085e9e382ed10b69fc311a03f8641ccfff21574de0927513a49d9a688a0051ae6c936b21022f01e5e15cca351daff3843fb70f3c2f0a1bdd05e5af888a67784ef3e10a2a01ac6c935287\"}]}', + ), + TestHelper.createBitcoinTestCase( + 'ParseDescriptor p2sh-p2wsh miniscript', + ParseDescriptor, + ['{"isElements":false,"descriptor":"sh(wsh(c:or_i(andor(c:pk_h(xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/1/0/*),pk_h(xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/0/0/*),pk_h(02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5)),pk_k(02d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e))))","bip32DerivationPath":"44","network":"mainnet"}'], + '{\"type\":\"sh\",\"address\":\"3GyYN9WnJBoMn8M5tuqVcFJq1BvbAcdPAt\",\"lockingScript\":\"a914a7a9f411001e3e3db96d7f02fc9ab1d0dc6aa69187\",\"hashType\":\"p2sh-p2wsh\",\"redeemScript\":\"0020e29b7f3e543d581c99c92b59d45218b008b82c2d406bba3c7384d52e568124aa\",\"includeMultisig\":false,\"scripts\":[{\"depth\":0,\"lockingScript\":\"a914a7a9f411001e3e3db96d7f02fc9ab1d0dc6aa69187\",\"address\":\"3GyYN9WnJBoMn8M5tuqVcFJq1BvbAcdPAt\",\"hashType\":\"p2sh-p2wsh\",\"redeemScript\":\"0020e29b7f3e543d581c99c92b59d45218b008b82c2d406bba3c7384d52e568124aa\"},{\"depth\":1,\"lockingScript\":\"0020e29b7f3e543d581c99c92b59d45218b008b82c2d406bba3c7384d52e568124aa\",\"address\":\"bc1qu2dh70j584vpexwf9dvag5sckqytstpdgp4m50rnsn2ju45pyj4qudazmh\",\"hashType\":\"p2wsh\",\"redeemScript\":\"6376a914520e6e72bcd5b616bc744092139bd759c31d6bbe88ac6476a91406afd46bcdfd22ef94ac122aa11f241244a37ecc886776a9145ab62f0be26fe9d6205a155403f33e2ad2d31efe8868672102d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e68ac\"}]}', + ), // --- Elements ---- TestHelper.createElementsTestCase( 'ParseDescriptor Elements pkh liquidv1', diff --git a/wrap_js/__test__/VerifySign.spec.js b/wrap_js/__test__/VerifySign.spec.js new file mode 100644 index 00000000..49afef75 --- /dev/null +++ b/wrap_js/__test__/VerifySign.spec.js @@ -0,0 +1,48 @@ +const {VerifySign} = require('../cfdjs_raw_module'); +const TestHelper = require('./TestHelper'); + +// テストベクター参考(https://techmedia-think.hatenablog.com/entry/2016/07/08/153449) +const testCase = [ + TestHelper.createBitcoinTestCase( + 'VerifySign HashType(P2WPKH)', + VerifySign, + ['{"tx":"020000000001019c53cb2a6118530aaa345b799aeb7e4e5055de41ac5b2dd2ce47419624c57b580000000000ffffffff0130ea052a010000001976a9143cadb10040e9e7002bbd9d0620f5f79c05603ffd88ac0247304402200aecb70a0dfff96a088c6cd60dc5905e8117f5e68e9009de0e45a87fe5f6bdc402204188555d295daaf309716ca2372bb9d9cc778105fe87de50f5a9ccc352acf314012103f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d600000000","isElements":false,"txins":[{"txid":"587bc524964147ced22d5bac41de55504e7eeb9a795b34aa0a5318612acb539c", "vout":0, "address":"", "amount":1000000, "descriptor":"wpkh(03f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d6)"}]}'], + '{"success":true,\"failTxins\":[]}', + ), + TestHelper.createBitcoinTestCase( + 'VerifySign missing signature', + VerifySign, + ['{"tx":"020000000001019c53cb2a6118530aaa345b799aeb7e4e5055de41ac5b2dd2ce47419624c57b580000000000ffffffff0130ea052a010000001976a9143cadb10040e9e7002bbd9d0620f5f79c05603ffd88ac0247304402200aecb70a0dfff96a088c6cd60dc5905e8117f5e68e9009de0e45a87fe5f6bdc402204188555d295daaf309716ca2372bb9d9cc778105fe87de50f5a9ccc352acf314012103f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d600000000","isElements":false,"txins":[{"txid":"587bc524964147ced22d5bac41de55504e7eeb9a795b34aa0a5318612acb539c", "vout":0, "address":"", "amount":2000000, "descriptor":"wpkh(03f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d6)"}]}'], + '{"success":false,\"failTxins\":[{\"txid\":\"587bc524964147ced22d5bac41de55504e7eeb9a795b34aa0a5318612acb539c\",\"vout\":0,\"reason\":\"Verify signature fail.\"}]}', + ), + TestHelper.createBitcoinTestCase( + 'VerifySign missing pubkey', + VerifySign, + ['{"tx":"020000000001019c53cb2a6118530aaa345b799aeb7e4e5055de41ac5b2dd2ce47419624c57b580000000000ffffffff0130ea052a010000001976a9143cadb10040e9e7002bbd9d0620f5f79c05603ffd88ac0247304402200aecb70a0dfff96a088c6cd60dc5905e8117f5e68e9009de0e45a87fe5f6bdc402204188555d295daaf309716ca2372bb9d9cc778105fe87de50f5a9ccc352acf314012103f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d600000000","isElements":false,"txins":[{"txid":"587bc524964147ced22d5bac41de55504e7eeb9a795b34aa0a5318612acb539c", "vout":0, "address":"", "amount":1000000, "descriptor":"wpkh(02fd54c734e48c544c3c3ad1aab0607f896eb95e23e7058b174a580826a7940ad8)"}]}'], + '{"success":false,\"failTxins\":[{\"txid\":\"587bc524964147ced22d5bac41de55504e7eeb9a795b34aa0a5318612acb539c\",\"vout\":0,\"reason\":\"Unmatch locking script.\"}]}', + ), + TestHelper.createElementsTestCase( + 'VerifySign HashType(P2WPKH) Elements', + VerifySign, + ['{"tx":"020000000101319bff5f4311e6255ecf4dd472650a6ef85fde7d11cd10d3e6ba5974174aeb560100000000ffffffff0201f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f0100000bd2cc1584c002deb65cc52301e1622f482a2f588b9800d2b8386ffabf74d6b2d73d17503a2f921976a9146a98a3f2935718df72518c00768ec67c589e0b2888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f0100000000004c4b40000000000000000002473044022045792f51da8d092f237d6f06aacfdf22c7398a2a0db68c7a3cd1ee05aa728b240220486477ec0560de88000855d7e9ea90fcae3808e37f32b6389663e2c8cf3db604012103f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d60000000000", "isElements": true, "txins":[{"txid":"56eb4a177459bae6d310cd117dde5ff86e0a6572d44dcf5e25e611435fff9b31", "vout":1, "address":"", "amount":0, "descriptor":"wpkh(03f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d6)"}]}'], + '{"success":true,\"failTxins\":[]}', + ), + TestHelper.createElementsTestCase( + 'VerifySign missing pubkey Elements', + VerifySign, + ['{"tx":"020000000103564f093ef3f31cd268a8489ca927f96813d4f1a860fe88644e984912697daa8a0100000000ffffffffcfccb9da664ce180c41e904a6200a92e5a8457e134910ffa9ddd99c8c37c302d0000000000ffffffffe4cc814af5b1e86966ecdc99e9ccebf9c6ed1976ac6ecdc2c6a52ee9ead6484a0100000000ffffffff040bc2d608b1e3e822e966e20407cbd0991a296b7305013a3d41b399368a1f1149af09175a8b328c9e80f7458cac99227b176492a7e76c98e6f62e4137eed36718e7c103e84c58d6108c6e78dd7990dcc24d60fcf287cf3282dd8a30934d73118f4cc418220020991049dc37a98a0e03da9167a36e4aaedfde020d5331cf7b394f7060ca01c81c0ba5d62d41c3263d1363ce96e4ba78242e5f1cea777743dcd60e9f8a6f2603cab70991fbad5c63042f8200007262f6282b8a6ea2ba570e745911f3b5ee5dac6482f403c87352825b581e610986c12590bb13846f4c54d436e642cfe005af5387f3cd4e22002080dafc20603d1e188a89eac7be8818ac5831dced2a558f2a4e73790b83ba8e550a44521d106bec818660a9ca8e604a4a755318c58025c157174d7c5b2d9f000d0b0887291bd3b1d46d67878051a03bbf1a05aba0f5bdecdff16c7a27eaf5ad4c55f903e9b55e29f355b1e230d7b674032a8f135f0690e0c5fe04a50754e17315c263d3220020a206a457180384fd5bee2a7ef2d0642b27948390f902b7094a4110575be9c0940125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a01000000000000138800000000000000000400473044022003aa101ad83919edc5e1178c9a30df6a9146b2229663b387860b72b2fda4d42202204ba4e44e7c9b66015cd4b8d3f27de7195aab7be98fc3cf949f557e5a0b00a8ed01473044022076050536ec34f5f93b2ba0302bd0e96879ea29d37af7a203eb8af978d7098cb802203ab1644f04575e2c5e9f957b36a51c6baace5e4f16e34c30e83de1efc419dab70169522102f1a5e75580f6c53aa8f223801296195792ad6ff5dbf1dfc0ba96d5522875620c21033d62b96bca95840a3a89a861ac0a6850c2389f4a78a300018b157e45a89480332103c05c228038c244a82b7584043ccfc59807e4e8e4d84d726e098ce71a0fceb57b53ae0000000400483045022100be67f6fff0de9484b8eaa21bb5ae96c8fc2a1e90d8326917cc09937c5815d5d302201d1e6751c24395e2b9d0e05883909f587bbee2313e76913472d1ca89c4f36cea0147304402201f8845d04becd73359357374aa175ff4575452eb2b86eef724ccb3b557d985ab02207d47f344a43a51f5c9258eb19db8c79aad491ba0fc201ec553a38396f5a44dc80169522103159f6ea0c32bd50173460b0ff3a26b34c5beaba0f982235a5645a28caea2d13321033d62b96bca95840a3a89a861ac0a6850c2389f4a78a300018b157e45a89480332103c05c228038c244a82b7584043ccfc59807e4e8e4d84d726e098ce71a0fceb57b53ae000000030046304302203ea3b5a4f8f8a6c94164433c92ab256cbe11d94e2d8d9fe029f4b4f54bb46bcd021f2268604869ceef5caea7593fe13dc3dd2f81878e4dea43c8756dad901f3191012551210324ab7a32fbe6d27c0de57c82c4e970f4edb57262e06b0f5ba9feaf2470c68e1751ae0083030007b364febd5a38754da1a454487fe0cbc92698a68ad887a15ea276492e1358077c12d758ac811cddd0ea82197ae96fe50f864739c38475e7338f6f550e9c91f27be186d75689a4a11a6abab605336f07ee272fa4fda8c321aa19066ae513d65269f2619fd9c4fdc98459737efe488e2823a13d4a6091be8eedc2e380b7a4d86df2fd4d0b60230000000000000001ecc801e2db7ff305fb57a72a2f001d32312ae15231e1ccb86d39204f504760c2bbe6535d5c1379df946acd6102521a14fb2f9cac2542ab28e02e4dc1d4a5b98ee371b4da82081bbe7d43ebc255fb59c3126566c3408b57af68ea59f0ad5147a2a2eade30d24d3e617e4cbd7022a9085d8fb4de5210f25bcfa8f925cc01274f74a5a2c908ac3e91d4b9c449671590712d6a79e0608fd24d07d534ff2abe21fd045bbe6311239b3e2fdf2cd3f761b043d5a72bf7b4621ac8862877be0300670384c52752bd1d2af192779740097b5a9955a70b604e8e8d6e9f90deb8065e836012ef00028df81b2978489cd48aa13abeba93a58e053c6fa350d17891f0375b463e18ea1280cafbd1ac7e3df7cb998ce525d0b24762c844a6b801cf520d3e95c96105c21c17f5ca96e4aa92cc6b3425f4636aec277440c21834cd18ee1893e8371218202f4a35e3e1dee8bb16a241dbc9755407fbeee33b75d28b4bb95d20ffe73b805bbe6cf6358ca86f69cfec0263d8aca03a04257f26fa536614f9680f072a19c0ba522b421f53e23d154e4c02cc2d683a59474be2d563f7d9a99b21db8227c71f9c0193a6f5ff02c589c2377908706528ec19fe8a683a8b514cc03217a8c5875f5a14613818bc8a9c81bddf86eab29c312a147de9a6a21be3e1bbfd585d23496acd91df9e13ee9e31e82e8e0f3472fbb313b6501430afe98accf9726612256ba52dc415b0c01f3e16ad2e9969ea4ff56a874b6d1a212b71d73ed8eb0290a39f1b776bd1fb1c18a1d7b03363932a10590406630fdff9983ad79acf3cfe9c33d6f9fb087174ccbeb9e2b333c65aff7072ff39bcb8a18da02696894a03ea009b951e1266faf7fecb0f61c6bc4caf6941e1d21300faf407b996ee959b7d958379bebcb3e2b5ed6c30d9e28e16266b23db1ffd0bf13276acfbc553232323b9fa599a04108c5455a469809e1859851ad9942ad584929866d9f506c8b222c286034889456f805e9daa261774cbb652a4e198821b1a8102fd7ece03bf2f8f27a22619359605eea4cce157861577e18df8ea134760417608bfad1f05f531d92316681e291dd7b3facd231e4f9687cff4abd15bddae82498e172e721587856431ef99af47861de7c246ad1d1da08f86c98ac5059f3c9977ab58fb07dcdf21630316fa45ca66e017fb4a1a9928ac494096c0fa0bdb0a267ad215bc1e3cb8f5c2afedd77d104b3e996a200abf59a6ebbbefe56a816f138d19b1d1503d8166278bddfe5062087a6305803cecc538d99d5d6f206201c3721a1b8129c4bd4efa6757d2d38556e1e2e6ac40f4565376332b068e29caec4a2e3e3f5fdf20d7c8a6742eeb0e2d2346eb4207433428fe7705cc785edce7409d1d7956e0725d47da491bc3578f439dd213efe1cdd616b015a3b2c41660742fb435fce00baea54e79918e4ee9624b124ed0298c11c40f3aca652ae962da291a7a93ac1db3c94a664f558d9980477034f85e7d0aef9dccece53e0a4271a0d1d4242ef4782cf8ce20d1276299eaed6051fa0bd8b2a82a060fc6b245c6c661dc1e685c4390adb580f1c05b467c11b751fabfb837709287238a248d32ffd743be9fa323202fc0d16b8ca99f06937da895d0fec80fcec6b4158b0e4d5087da285c22a57ab902a3db9cc94a58f1671aa32756bfcd05a646a61db3fe240f6243caf5e78abc0f2d830d6a3201c2dc8bc56707681bb4ffaf4139fef390f7fdff3641cd9a3f345d6611f10ccc0e5685b309c84cc3d1cc59f5e57672b188f93ffc263fed0cd7ca837abaa76d565a2fffd5a772bc8a506d4452dcba2204c9ab9e0f7725b121a7e641a9760e38ff6bbcc8243ddc6bf18cb372b6721a44c1d19415a67a2b438a5732b9de0d1050d83959e5b7db687de9e39f677426138f8ff9e788b60a7315291c85ace3109b03e323cae8d3784cc79220621c35780fe3685336504c7595826a24fc12de045e0f7aa7e0f0df2c3ba9c518da40cd85dc0ee86f23f927643af25c9c4de7f6994a702c754b439aee614c15f42ce80588fc746fce11e1ad8ea7ec7eeee953045038e33b2281d05be8b91dbe302e92d57ffdc088702e80ee9277699a161769cb085f4299d136ef2f4692ab0c036d0787bf57e9ec615373c8c194f4b3a4f1dbe813bee7b85866d91c58870785e14c668fcc30001014a04507db104c23f66ec6395c3de1059528deafa7224454d107e6a2d4ae1006dc16af74b8ee1acc75de36cfb2f4ad0486b5e63549325cdc2e35813cc2d144af4d021eaf47912550c6bfc95bbd247dc7eb584e5d8ede64d7c38ff2d19dfa706a4977631e1b34cecb8734e8713f361c0f3bf5c7bd565f3ac6ec3c08952bd07ff3eb0797356f1995c6e839801918f92f4a4dfd023a60e3d2172b0218fb5dae59a775b83de3bfd4b2735a2a1097cae026f62af3a353b862e7db8e32eb74662ef228a3172158aec908a36893ecda285c6fbb843bf7dd4f97fd6cf32ff5e0431ffcc94dbc6f119c9c5699e2dafc2c03263b152fabfe9a6483c9f1281ea293dfcb0769c8400dd8918996b53c6af4e1a8bb206190796cbce988dc5ada4687cd7dff221a8be4582946959340266da1e6781c976f8e3d235509dcbb4da519acde4e8bbc59cbbfcce57ed6b8b4dc96adbf0d502e276574ec42ab1d0d9dff8afe1bcedb0a929383027984a8b7e0de2545f53b9000ce0dbb09d21421cb85023a98a480d80b9e25fdce5b2d89d6461aad96d5d71449c78924f932a93650191082b804971c65adf6e0d0876f5bb7d794902522d28ecfb963c1d13c81a892f6ef332b3e5098e9dd90ae163ebcfce5fb81c1bec4d00033cb4adcf591c797097d02d08f00617dc628dee55127be366851c79da587c0710d849a08fa3cb5d56579c969a0be9818e6a15a0607f68a21732eb7bfba46676acce7a125288313a64c24802a7018228499f4ed3014b1b9b8641fb6cc8cc40d0b96f1af4aadd031584bbc88e840e72bc103307a01c4d2a4dcea5ebd3e72c24ee815a6bc7c92674f4ae225633726cdf06ad2bf03e8ee196a85e8c27aa2a0e16fb93d25203531371dfb82367878aef1553e9c9de0e92ceac641abd215eb57f7729fa4d75fa4d79314e66975deb1d8c963b28607c3b25902d6fa77d7390d39f849420ed33a72868da13dd88fc4071cbcd1685c8528fc0f2b70a788985b3a513f51e7f110a4653f93839ab82fbf1f9ca3b58387edd1d520c0b5dd9ba31fcc44e92b40be17c200438b189064e8db968047d408cf094644e75a67357c7d9a56ade90fb2d2f1d5597b9f8c4f0dd75a7585de36a727bd485f11f14166314bf3e20c1d2b3fcb44959b6d88cad3f0318938a627d042dbc3147511d015333a30894e1e8b2f78c4b2a054db3d6898c2cec1c16aaeaab4bea2fd113b8ccf42b36e770b4e80602d273bb6787a0d34c3cf1dfda623a9d6168c713ba051795a0b23ea040561d87dd964f547965d23eb8c9aab2671457b1c3a156792a345a7b71b58a7948a853532f1df6dcf1f94469ebbcfdfb8f5f8e8236927a6dec83c549ac4377c265493a3396be1b487d435ca8dc71805a482a39d9beb85149892c6f9a2670d7e7e1ea842ee59120695529f4c7be63aea197fe35421e740dab7f8e79d6e97f3893ee0457e7123752f9eb89f1dcfc4d0918cb03db5999ae43dfc55b75655f3481924db5d5743b2294f4156538b13223b72e57a25ab9c67a34507e2fdcb002517d91d30e9afc45f57eee057453899aa93d924773ecf5c14a7c7807955b77d8dd6416ae40750b7ddf5ec80aa525634f80735e003d75c197aaa7c3676b90f131d9f6f2e89abb638be5b1fd6cc29b76ea7a94ff5a9baf8c7ac6b8294a2c6d5e5b0302f55edbce57cc59774ea1a675937d155089246f34cc3180ad20d0ce5b59124615246d110b201aff0cd52cd88077b6b91fcaceaef25a00e691360aab4baa373f49d051df94d53651557b7d021e7142c30bbb21f065b1c0ff0783f4a3171837336d2be8d0f99fad769c7b9f5a8ec4d2ec37f56bde0b1c34f73f4f81b0d2348d61933d9e13a7ad14af8f36a1223907e47652ebf263890830300070fb268f9887f31d95696419eff0a6add4096115299afed2ea786698c568e55bee1c766d0ec794c518ffebf36859c5ba65100de27ab3edf5ff2b2ad1f94f6cca43fccc1a5e969395567644fded51e5efc353c2d7cab7654b3185e7e80314d3bdddf448785dfd871cbefd50d3ed1ccae4f98e13821f5519cb50e12b8a830f73c4afd4d0b60230000000000000001e5ca018ac6d02ca5d4a0ae462086eebd6227713461814ba36907d53acd75f1fa94e1ab89cd49bb8eaf94a7ef6164082b8fe754b0bfb8ab7031ca8722f78d4affeef1ba0857e888a4f76593e185640c8aee39ff109181e258d051171ec8f87c45b075db74169ec85fada3e521c9256bb1fc29412e1509f25b66c093e8bba5d851f8611c8a72c13b460618506c62e27d6bec521504d623e23210533e58831f76f92d3271759688fd7fe51a40a2dad94c8fea6deec5d08d918a9b89f2a7029924de76b30739755570c3c7adc4ad205c35734fa520c5ecd1beac2c71a8bc871fe6301352b8e00dd285a5f997e0a2975df8d91d24cc22072422b918cb95db0dc48df5b2ac7f39c5ecd95d24c43c9fbdb32984d9ea4177876dfb632441fed0222c2858745fbcbf9be47d02db02c79c5d9089a0c9f660d295581ed250a4899655f537e90b36cdee8466de12c5e05d5503555cfa899bd3c56a7e53018ed055c86adb361b9e5bb5f579db55654b8347071e649abdcae6a2e9b87742ae1d5b4ca159a6f097eea10844f46816087ce0976226d0d469b7380a70e64f140127afc6ea5b152b4e08edb396b1ccbbd283336d860188a3cd7115afe6dd71ffe61aad20e8d0929ce635754871f19cf1c8f3e3c3b4d100c5faee2c0d15823d67bc69e21205cc2d6c4c7317cd6504739bc580fb8b72d339b4dc904ee763f7cbfed6c8f5532f25d0bc0a260a97093907327b4d732da2e02dfd0f38b42c59a6d097b6df4b6a35668fd314e0d16d33aa0c60a73656c8ce050c6aa0f2ad91d206d7c62ce0712e3280349e243e08369d77052f9005175b5eab5da2a088b8ff9a99231788d6ae5aa5881cdb07f85993b8b5ad4c6f2b947cd917944d7b2b0a306ceb634e465ca75b68bda91974d3170bbde89a9993eda1de365326e4eb73d5ae147c2a92d1a9375263b6fc9246ea5ac2b6981fe19cbd3e9f07a5e738d9db729f9250953218d14080f21ffd9c8637f79e2fd2382c8a9375162f41b5a4015da76698a9752473d7b3ea266bb44899c6eb106e601edebbd5de53d2dab5eb2f376cf4132c3bdef1aa71858143f564af8f07c7dc3152d5a35f5dd59bd02fc97315f8af1e2432987cddf8a21edd631164e77f4356eb128ffd3e518865762ee83be6e787ebd1583098a647006eac33b7ad6491560e94b340a5673fbb41c2947ae88f981c6bd2e7a79461634f4e451d2c492d358cd3fff0da8c377c4bae859eb3936d49ee30886666d8b8496ec008dba87ca205201907b5a131b140355b8444daa2c72437155ab30b1266f3221839687bef2137c73cc1caeebdc8c1cecb215af1da72734a36201fb37fa1a8e2756286f2f1bd993cf975362745f9034f6c8a47a2bc85588fa9d04448981be092714fe39bc36cd0ff27710816373ec00ae1840ff27de93e3d7756c440fe6dbebbe6bc5da603b9886a3b236229d6e97a09a536a80088250e3d687ca42ca1fab767539bf176a0896789104878a13a44a462d2b3b5d1e9f0343857a68db9a99f2d58cde5398efff2fc169db15482ec400df8ce138ab00d45471dc112c5e6f8313de6b8fd180f040be7100e414b54744e6c061b993725afafebe7ee2f6f067db5d8ebc595573c88b2be6066d5bad3837da2598b7eae7d2c9e22ff62202df7ee23c30d83d44ee23f67f73cac7ea89bc248b5dd62bb8680bd9e6be214566cd99a5ddb4d82d173c750d1f1fa00eb45e42ba44b61e5b8c2576c0fdb2f59f6a23a10196a5434068bcd5de651f31a3aea8f3a1394c9050d15a917ea8031291931e3ae92ad2f4bf2d49c36a874dc5733363bab1eb4ec40cc2c84840d2d0c4ba4f2bf3fa0199687befc79158075f4887d656943833789d68e58ba33813972e6a13f2dc02f20326704804e3e2d16cd66dffd4dbd968327e37a37f8235f389412c3e49aacae886a4a0a664c0c8aa26d975f8929130e928d63b34ce53d115d035a3a56918eadba60039cd35de91c4a0806ec19e22d8242326d6bb4abfdd7b06e424a73d3ca5da08f8a3096454c20ece255400f7453130364354f1db77387b7bcbe76fb6ad8db785cae6b22bd0f625d43fb0353b1e86e35eb9dd9bb2d5c8dec374210420e3040c5f7ce37ba04ce4293bc745d8b2b93fc71d5c47448abe79e4985aabe7d7c1090fb9239d15b5093355f8b2905aaa87ed706f277547516cf140f487becc4e353a7c5fd4cedf6942f52ccf5321a022181ab5ef2de3745277bce989482fe5007bc00640ef4b13db53e6b9d6d0b279f5918bc275750e9b8a2ab084a9d9daa001e8b769381627732ffb7223ae4ebb4dbd5c009a467c657d3d13b6e5f308318fb0c06a1c9659a720934f2cd80d88a53a49a6c5c7665db7467de875e80c72f6ba055b9720e1b6a0024c16a755eadf8b3a96918ff2cd13a13b976af3bea6de7a29e852edf4c8e44a5165b16fa1ec676cce6000a47f68de2202ac4c16f14f693ff53489a437f52e255b0813993bde86d65989f4570f6def21bc28a804547b38bcddcc7e9747b8b3660462af05eb4b2d30d8e063270ede0df13abdc6a554a446dc063422aafa7ebb3b17e92fc9948a3b5d69a86c078386569d9ed9b73c07cbaaaf03381e87ed668753dc5497a94bedc5543a5b50d3263138a7aa2c795e2db398e7b38664ba9974ea27df33a05f3568e270dda912590503396cc22bd9a5f70b1340a01d36e11d1b1d57abc83ad2dac4ce28e8b4374049311f86ffd28974f19dbe50ff48bf5064dfba0307adf452e67317af1e3071156d633027efc5ab4941a38b688f8c9a9970896b9d636d2f35b288d23c012724ee2514356bada435e279d8608f743345efe0fb802e5c4ac3fbca2b5a10eb86fe11a285c5efcabf36e1929951faf0ee1e31f79b8508ef7eeb1141cfe0011abda55e447fae0dc7c5b6e6ddccbb232d2ae5091bc78f196a59763e69a23e9ee34e0e113462b6b92907242558ce4779e5904b4b571e0f95c22ccda4711d22a90e837f5b612536dd4cc0e1c728fe879bf2d12b1272257b2c4c062ab2ce9762d1bd2a5f9c3d53237acc2c48af60f58ea983db5a0884eb70827723e75404ed02d1c397da40536e558139897ec69c0ad491ce5d3ec81f99391c4a55ae01bebef57e70f107805d5b9a9a3e8e48eaed7974140f81be96d1958ddda66c133133523812d96b8d72f4121542f7d3017e8235599ead52fc318e8145abb16aef5bc1217414d008b02e48b06d7a1b9380a25edad4c332f266bbb4962ebefe8974e5372cecb7bbc16ddd2fd11d7e70e56b2ba0bd0cc7c9555874561c6d86f47a404fd93b2a092cb9a4f98b3455322c19043121e9c731c099b397af065b188fe83388bf76b4dab9e08beb0b81ae99e2dffe7af7e694dd33ed53e8e2b4843d6e64076ea891b7756da6d218af40a7394503f2434d387986d5cdbc4ce6da8a448934758785398610e2ac1107bc7d127053d32450f265be980917d88bd5a40c37f8d799d4b14b698d2ff7cb6838593da2b3adf0d36ec254a809142fb85441a8018e6be1c7f159e040f4706d29c72c82141d94153ee53ddcf92cfb553592b678806111d6bbfddf7b91ba2d207cc8955db63ef8ddea96b139dde226f63691009ce9c30d05099c0290871120eeb8255ffa9a2892642796cefd2592593c3ffe03d6c76b570fd04b5efdbc1d0d5df60a0a8cc23883d792f00040d2489772674cccb9bd5fb2dea7a94ee2029daae0fcf1c679fd441f1d8bca71f3e5da17c1ef40aa5fdcc944255e81a209d605263a2c78d4d55af31c97c0fc9962667a27c1d6fff4735d9a5d4bf30b3d6aa920dd8bcc469fabd60020f4afd5023afc014582e5c1af4e0d001c16b24a46b4b9bf276637eb5ab0d8986c487c4acd6a35440ffaa8ea8a2cdbcb475730d8442868b14f47403cd1f5efe6faac55836b9764ec5244a164d1246e4eaf0ca6c0e53ec5ea147f7547037e9d781ce39de9cb10b7b50b566a7f2dcf2c482c00b8d752f220d75085da1a511e8229276d198c715eb8e44659f7171bb3b5448f942ea285bc26259ef2243295a9eb78851422ecc987d1b53c729af2a2ee40e57c6d2360c698303000749d0ca04d6fc08dde97ad23cdf22dd410240d64c94914714459f6deca33e2cbfc122476deaeedf9551f8bbc16f4d34cf69017b8382a902a2cc55d41dbab36271233ddfbd8e77ca42c1a247695bd77f7ad48db6d8a8d1ff43a59ca1877af0364064109093f54d6a45f86fff5f7c2c222d08304fb735906a1a42842e57e012800dfd4d0b60230000000000000001aa1400fd5d054449384995562badfef9e76ce2141f06b125876b8fbce4ecebeb12628d4feff1b547aae298c72c95b64c4ad5621919f2e6ad43ee8df95fdd9c6252809bed4f4d88870ba26a844b905be34e0bea957ca558bdedc1e002690a945037214b64acc049d36a458ea7fd8c3013ccebf8950f31972df6b0d592471aab617502a8cd7bae25d243a8782dae3462840736d7e11a2acadaed60e636e36a485f1d8eed54b6efcef548d99919eaa65e3923bb2f7099897be85e46551aa6b45a61a5b7ac59917f6a4642f19055194f65b98725bf451fb8d5712f569db48b0458966c979777e59baa5603de6416244c0b92b3c0968e2f78bc1e1f39545ce8c50071fe4efc2f8046956b0c911b12e1a961b04a248d401a0d06f8748284a2aff858e1b3713dea72ce43c3c0c18d1fed0b23365cd35014cdb068e9a6a42e1baefbb3c8ca8ae39d7df4ec00cec96be68f3df67be06bb5bb979259c6c60aea4635624c4399f3070eae3b601b22c182a4deba2c26e7651c889daa4bdf3bd5c937e8a1387c296aafe5b239b9128dc11d2834f8b7662c5bfc9d2c4d50bc8f9013425200a3547a6ba25fb6cc504f6566eb48ec488f48828a3dc291249987c3e163335f912cbd7c97cf0d09d6a18b335094e35c1274de251875aeb09029fd289af6b09126a070ce0d08eaf3b9d1a030176c631384a9e6e446e59ada4f3f326227263b208bc098892acf82df9c3271f600877e4754cc0efb520393bb63c78c88c0605f51e250b1cf26bc81590dbb4a181563ecb28fb73138c83bb771d686e0e3d53c7a2b31b9a9568b9c95444a829f110eb16a68cef132e1dbee8a0ae2f59699162e87178af7fc16084f0abdca3ba03585b3c1245b5caa4e531769b835a64606f91844e5e488421e6f6854901dbfddd7915aacd9f7b1231293ca6d50dacfb71a3407f46dca85bd844b6afdd6926933051631a633214deae160bbe34a2c36c1c141180e43bc79240144cd318d438a8169d4b9592d96abe42c1ecd46d48fe5d03d6ffb6dd8a7b516eb182cc19e731b59ec25bf6fd99dda42837d2416bbda67671b68835ed4143c8aafb7a733b4bac5a2b8482888f75853c16037841ef7056b5e5f57e07ea96695120b5daa3bc9fa32b604170565f4ad8cf429da2d244ff13ec2cb6fa0a671edeb4a9570a1193636f77786ea0e08ae0f17622a06ff5ba8d2141734f0e2b0ee87457b9fb566c46eba778cb5eb6744d310d5edda2dbd1a4cbca13ee74f48f23fabf11d1cae0c782e9c4c1f6a1f3fb7feb3869bae18fab39515a334ee1722d188eafa55caf371c6b4d510d6ea0d3cd0946c445849a8c8d2ba7f5a0d0d42cbe3aa87ad768537d2a5672bf5bef1e295fbc19427edd8d8b44f394eb7aed9f71f3713e2afb5276d06a4862ed9c5f852f22f6e113ffddf0b00de0bb3c511bad61783a04a6f89e388fe6f7a58d7fbf4173a5d1409dc5eb32152d5428013b6d359e4318dc0cddf2e0c1281f81d06fda77db9df13664a1d83c14b514b661e898bb78d163df352ca68258aa752efe0678d1d34f47919b22033b1c99825462fa469149baa825d4006cb253e95873a7898fa83117aaa0efca0d29a5cf23abc9c69515c806c2d0980d39670d705fa6324fd4ab3889b93b7708aae372b7d597bb3d4ae70da3504081c65da35b2ac1a6868c1ca1e312b097b898656dc2f8772a917cccdf475890eec51410d2a5c9a804bd272f9f59fba2a25f827c6e1a07275a34781199c3f5985de8d4c232234dbdb314c7d49e2f90c11db975ea98170a6bfb272c5126e4657e50a9036f122a12272b294f4551761056122977eadc686c75e01af84c8226d5c6904e9959875f4fb96a33e3b491ab829f4758da52af4fc03cb322847b913fd57a6456b6d5b4e94b71e63f8c2fcca78dd444a5f919108a7a6ff228d4a00e3d8e642ce35a85d1046ccbc9d66bbf8e17c0ef0531158fd722c5c000af86244f6242ed061d6fb046c6a20c22464484353e926c9438aef1480afbdc4c02bcee4c1f73331c81204932ccd8442d1c44e7b1852ac41f65778694c1bde462ddb87c847e81df08c637804bafe414db96f6b3d66ede9b1cb1dc6b050b8604435c37c7caefa677697a2e9a47ee783183052c9d94117d6c204f4c618bd5faf42745359e49dc997692d23abfcb7d8ebb79b71c28103566e77bbc6db443c2a674c65c8db0b5f8e4349e9d02301a4f51747e2dd5929fe4f4eb0789c365be1051568828c2d0bedcccefe50c0347fea26a27cc86fd4bab37f54008fe5265e906e9d4d5645193e3862f5b1509ecd0bf146a121cbdf0f7cf1471693fe21deaff40b26d15de9be1d387aec2e936cd039cff701dd2e7d4a9ae104a3c7bd93bed543c4f0af9921f2d6edee1a05bb1272e3e8fb662a86f75c5a6530f01d0c602aed1dc8d1165b2d723cb80be5b2ee4f4e4bb4130d0db4e7781c0bd99e9cefad525a77c23fc9929d5d8c752b6e59c3a2b03c2b88917f69c8a04aac7aac949514881b0e8e025fbcae33d78140e408a6ba8eb5a4b2fea40ec38f8f32dec4ba7d2e19c878e87199d5b8db8d7af7f013ca40fc97685dc86ebe63a51613c6eb1621df99a6968bbabefdf15351846b6c1d79d5fa1933f45e9e4768a8c5463bc9e25472520120c6a500f6ef0e7ab151f30d0d2bd4a95925ea2b780d16f224f76d96d1ccf8965701d0bc8fe9c0f756d5fdb4ef07dabc69dccf527d1c9aa694e66a774372580d99d6625fcade07781e45e456a255c47ffdf37924e246627db977844086c6857b15e43e2a640ee3a34b2a15e537114f5331ed9bf96a291064b5ede514d40b1ac19bc4266986141408e1a67bf36b462bf320eb645c52dd19235478aecc89fb89fa61024dd2abaab0c1331c75e793ad701861ec137d47d5c7d50a41e3331ba19a1fbb68a52430fb63ab1390b5c84fb32e277b36253743ef8fcf7726a73781ac06d818156064e758e304e34a12a17edd3c28fe4fb7170948827f15af322bcf9d699b2981879380cfc632d0a8d7bf4838950d4c475681c5679c6f5fc07ff25e45e367fa08c68d9f23ba4a39dd7e40fb8ccde6cff83c00cb14f3087e4b8d7f11a117b4c3648aa0c7016198c8ef00985eb3a17aac5c80f3a032f711b8c4c2c9e9bb8128feb9c2702f1a37b9711bc3b9866e1291943f6a7adcce314338929a80bb1fce7cfc3ba69004ef3c9eca700923b81d74e96de2817f2c76595a3deb603ee7b7f0e6d2cf0dc68ff7a33584a9a13a8fa3d580731da3553417a36187c3a20caf7cecf7fd5f5b65e39207bd70b13b1139835b02d108ffc57ab50d26d4af580a71b3cfd8b0105d3d97a1bbd893803c576c266149badbc1b5f88fc7c106c72272d26e58ed8d08de2f969f3932969e8078bcd12a3f0af30041da278571073d80d7606a1a09e8f6dbe454114e84442379b09b30ec0246c63f1f66697ae76f1730f6e556b853bfc57810c539e14c6d2591df5d292bdcf291c53d9084e027a739957d57416157f507ae5d6493c0f9c5bf02b2358bfc0c50eb8d82561c2e8c4bc435bfbdcff44e960b3ec4aaa2796852ceae0c7b56cea0fed943b02e1810392af5917972bfbdbb3defe3aa3004ebc425536c705a4b6edbadf7df40374345d01a3aefc942cd8329f0d20e22863ab8cc977b93dfb2c1db137fead1cf5cca626bf22dbcb262acafe968e65b3cc80e9ffb1e679645723dc45fdbcd69851b66aaa28d6427de89e978ea20af57bec53833f161284dfd26c583018e7c42b3a9753f77d1735b456978b692944986f627892e71a5b08e13dd5764272d72ea0c5f6ebc4c815c75af7acb9167559678efa3463e07c3ca06c0d1fa59b016a5af59ac6e02d32aeb6a676feb3fd7feb9533fa67da24e50dc8c7cde3558f9585ad137497f380c908abe3bf9330e7fcc2fe8616463a2fe439d3730ba1e96b1857a0160ccda1db4e35f52b379448dbeeebb3ade791950ee32ebafa170a94ddde0787d8e4212f4f1fc50246bf45002bb3c5842fcba0dd19d7570a5cff7bdc480cd81bdb4d5d37fb483bed93c2d0856d0a18012e0c353d888308ed3ed06907b15a0c00000", "isElements": true, "txins":[{"txid":"4a48d6eae92ea5c6c2cd6eac7619edc6f9ebcce999dcec6669e8b1f54a81cce4", "vout":1, "address":"ert1qppexyx85s385srndchfa2tja76ju77ted4zey2vyvq698609saks5jpjma", "descriptor":"", "confidentialValueCommitment":"08014db26ca6fede7f381a16b0a1b52d56b703c8f96f1bd9ebd0de002034f63c28"}]}'], + '{"success":false,\"failTxins\":[{\"txid\":\"4a48d6eae92ea5c6c2cd6eac7619edc6f9ebcce999dcec6669e8b1f54a81cce4\",\"vout\":1,\"reason\":\"Unmatch locking script.\"}]}', + ), +]; + +const errorCase = [ + TestHelper.createBitcoinTestCase( + 'VerifySign HashType(P2WPKH)', + VerifySign, + ['{"tx":"020000000001019c53cb2a6118530aaa345b799aeb7e4e5055de41ac5b2dd2ce47419624c57b580000000000ffffffff0130ea052a010000001976a9143cadb10040e9e7002bbd9d0620f5f79c05603ffd88ac0247304402200aecb70a0dfff96a088c6cd60dc5905e8117f5e68e9009de0e45a87fe5f6bdc402204188555d295daaf309716ca2372bb9d9cc778105fe87de50f5a9ccc352acf314012103f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d600000000","isElements":false,"txins":[{"txid":"", "vout":0, "address":"", "amount":1000000, "descriptor":"wpkh(03f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d6)"}]}'], + '{\"error\":{\"code\":1,\"type\":\"illegal_argument\",\"message\":\"Txid size Invalid.\"}}', + ), +]; + +TestHelper.doTest('VerifySign', testCase); +TestHelper.doTest('VerifySign ErrorCase', errorCase); diff --git a/wrap_js/cfdjs_module.js b/wrap_js/cfdjs_module.js index e8f080bc..04c035f9 100644 --- a/wrap_js/cfdjs_module.js +++ b/wrap_js/cfdjs_module.js @@ -1,38 +1,3 @@ 'use strict'; -const cfdjs = require(`./cfdjs_raw_module.js`); -const wrappedModule = {}; -Object.keys(cfdjs).forEach((key) => { - const hook = function(...args) { - if (args.length > 1) { - throw Error('ERROR: Invalid argument passed:' + - `func=[${funcName}], args=[${args}]`); - } - - let retObj; - try { - // stringify all arguments - const argStr = args.map((arg) => - JSON.stringify(arg, (key, value) => - typeof value === 'bigint' ? value.toString() : value), - ); - - retObj = JSON.parse(cfdjs[key].apply(wrappedModule, argStr)); - } catch (err) { - // JSON convert error - // console.log(err); - throw new Error('ERROR: Invalid function call:' + - ` func=[${key}], args=[${args}]`); - } - - if (retObj.hasOwnProperty('error')) { - throw new Error(JSON.stringify(retObj.error)); - } - return retObj; - }; - Object.defineProperty(wrappedModule, key, { - value: hook, - enumerable: true, - }); -}); - -module.exports = wrappedModule; +const cfdjs = require(`../index`); +module.exports = cfdjs; diff --git a/wrap_js/cfdjs_raw_module.js b/wrap_js/cfdjs_raw_module.js index b11066e7..5caf5846 100644 --- a/wrap_js/cfdjs_raw_module.js +++ b/wrap_js/cfdjs_raw_module.js @@ -1,49 +1,5 @@ 'use strict'; -const path = require('path'); -const fs = require('fs'); - -// check exists -let buildTarget = 'Release'; -const buildDirPath = '../build'; -let isFindThisFile = false; -try { - fs.statSync(path.resolve(__dirname, './cfdjs_module.js')); - isFindThisFile = true; -} catch (err) { - // compiled file. -} -try { - fs.statSync(path.resolve(__dirname, '../build/Release')); -} catch (err) { - try { - fs.statSync(path.resolve(__dirname, '../build/Debug')); - buildTarget = 'Debug'; - } catch (err) { - if (isFindThisFile) { - throw new ReferenceError(`missing cfdjs module. ${err}`); - } - } -} - -// search cfd-js path -let requirePath = `${buildDirPath}/${buildTarget}/cfd_js`; -if (!isFindThisFile) { - let parentPath = ''; - for (let i = 0; i < 10; ++i) { - parentPath += '../'; - try { - fs.statSync(path.resolve(__dirname, parentPath, - `node_modules/cfd-js/build/${buildTarget}`)); - requirePath = path.resolve(__dirname, parentPath, - `node_modules/cfd-js/build/${buildTarget}/cfd_js.node`); - } catch (err) { - // not found - } - } -} - -// load cfd-js module -const cfdjs = require(requirePath); +const cfdjs = require('bindings')('cfd_js.node'); if (typeof cfdjs !== 'object' || cfdjs === null) { throw new ReferenceError('Not support typeof cfdjs.'); } diff --git a/wrap_js/elements_example.js b/wrap_js/elements_example.js index 9f618e72..e3f61b77 100644 --- a/wrap_js/elements_example.js +++ b/wrap_js/elements_example.js @@ -608,7 +608,7 @@ if (!supportFunctions.elements) { }, }; /* eslint-enable max-len */ - console.log('*** Request ***\n', reqJson); + console.log('*** Request ***\n', JSON.stringify(reqJson, null, ' ')); addSign1 = AddSign(reqJson); console.log('\n*** Response ***\n', addSign1, '\n'); } @@ -634,7 +634,7 @@ if (!supportFunctions.elements) { }, }; /* eslint-enable max-len */ - console.log('*** Request ***\n', reqJson); + console.log('*** Request ***\n', JSON.stringify(reqJson, null, ' ')); addSign2 = AddSign(reqJson); console.log('\n*** Response ***\n', addSign2, '\n'); } diff --git a/wrap_js/example.js b/wrap_js/example.js index 93cd4b9b..05935b5e 100644 --- a/wrap_js/example.js +++ b/wrap_js/example.js @@ -50,6 +50,9 @@ const { AddPubkeyHashSign, SignWithPrivkey, UpdateTxOutAmount, + ConvertAes, + EncodeBase58, + DecodeBase58, } = cfdjsModule; const DUMMY_TXID_1 = '86dc9d4a8764c8658f24ab0286f215abe443f98221c272e1999c56e902c9a6ac'; // eslint-disable-line max-len @@ -840,7 +843,7 @@ let addP2WPKHTxSign2; }, }; /* eslint-enable max-len */ - console.log('*** Request ***\n', reqJson); + console.log('*** Request ***\n', JSON.stringify(reqJson, null, ' ')); addP2WPKHTxSign2 = AddSign(reqJson); console.log('\n*** Response ***\n', addP2WPKHTxSign2, '\n'); } @@ -1380,6 +1383,52 @@ let getCompressedPubkeyResult; console.log('*** GetCompressedPubkey:Response ***\n', getCompressedPubkeyResult); } +let convertAesResult; +{ + console.log('\n===== ConvertAes (encode/decode) ====='); + const encReqJson = { + isEncrypt: true, + mode: 'cbc', + key: '9876543210987654321098765432109876543210987654321098765432109876', + iv: '01234567890123456789012345678901', + data: '000011112222333300001111222233330000111122223333', + }; + console.log('*** ConvertAes(encode):Request ***\n', encReqJson); + convertAesResult = ConvertAes(encReqJson); + console.log('*** ConvertAes(encode):Response ***\n', convertAesResult); + + const decReqJson = { + isEncrypt: false, + mode: 'cbc', + key: '9876543210987654321098765432109876543210987654321098765432109876', + iv: '01234567890123456789012345678901', + data: convertAesResult.hex, + }; + console.log('*** ConvertAes(decode):Request ***\n', decReqJson); + const result = ConvertAes(decReqJson); + console.log('*** ConvertAes(decode):Response ***\n', result); +} + +let convertBase58Result; +{ + console.log('\n===== EncodeBase58 / DecodeBase58 ====='); + const decReqJson = { + data: 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB', + hasChecksum: true, + }; + console.log('*** DecodeBase58:Request ***\n', decReqJson); + const result = DecodeBase58(decReqJson); + console.log('*** DecodeBase58:Response ***\n', result); + + const encReqJson = { + hex: result.hex, + hasChecksum: true, + }; + console.log('*** EncodeBase58:Request ***\n', encReqJson); + convertBase58Result = EncodeBase58(encReqJson); + console.log('*** EncodeBase58:Response ***\n', convertBase58Result); +} + { console.log('\n===== HasChildExtkey(success) ====='); // [44h]xpub6LeyMkufeeMnKV1hcfXycCFietNdxSp4BGNsGiwJGZxvP9Ys7gQG7b6Lbk9xUwySGX1dFrkLyoynRwrKAMXRE6A6ciXx94FQ1xiFNJnm8Pw/0/4