diff --git a/dap_chain_wallet.c b/dap_chain_wallet.c new file mode 100644 index 0000000000000000000000000000000000000000..0bacc351965932dc0322dd9436f13cb49dee7f2f --- /dev/null +++ b/dap_chain_wallet.c @@ -0,0 +1,86 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "dap_common.h" +#include "dap_chain_wallet.h" +#include "dap_chain_wallet_internal.h" + +#define LOG_TAG "dap_chain_wallet" + +/** + * @brief dap_chain_wallet_open + * @param a_file_name + * @param a_sig_type + * @details Creates new one if not found + * @return Wallet, new wallet or NULL if errors + */ +dap_chain_wallet_t * dap_chain_wallet_open(const char * a_file_name, dap_chain_sig_type_t a_sig_type) +{ + dap_chain_wallet_t * l_wallet = DAP_NEW_Z(dap_chain_wallet_t); + DAP_CHAIN_WALLET_INTERNAL_LOCAL_NEW(l_wallet); + return l_wallet; +} + +/** + * @brief dap_chain_wallet_close + * @param a_wallet + */ +void dap_chain_wallet_close( dap_chain_wallet_t * a_wallet) +{ + DAP_CHAIN_WALLET_INTERNAL_LOCAL(a_wallet); + DAP_DELETE(l_wallet_internal); + DAP_DELETE(a_wallet); +} + +/** + * @brief dap_chain_wallet_get_pkey + * @param a_wallet + * @param a_pkey_idx + * @param a_pkey + * @param a_pkey_size_max + * @return 0 if everything is ok, negative value if error + */ +int dap_chain_wallet_get_pkey( dap_chain_wallet_t * a_wallet,uint32_t a_pkey_idx, void * a_pkey, size_t a_pkey_size_max) +{ + DAP_CHAIN_WALLET_INTERNAL_LOCAL(a_wallet); + return 0; +} + +/** + * @brief dap_chain_wallet_sign + * @param a_wallet + * @param a_pkey_idx + * @param a_data + * @param a_data_size + * @param a_sign + * @param a_sign_size_max + * @return 0 if everything is ok, negative value if error + */ +int dap_chain_wallet_sign( dap_chain_wallet_t * a_wallet,uint32_t a_pkey_idx, const void * a_data, size_t a_data_size, + void * a_sign, size_t a_sign_size_max) +{ + DAP_CHAIN_WALLET_INTERNAL_LOCAL(a_wallet); + + return 0; +} diff --git a/dap_chain_wallet.h b/dap_chain_wallet.h new file mode 100644 index 0000000000000000000000000000000000000000..e27f402465ca1add7a433f9d5bce4940793fabe9 --- /dev/null +++ b/dap_chain_wallet.h @@ -0,0 +1,38 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once +#include "dap_chain_common.h" +typedef struct dap_chain_wallet{ + void * _internal; + void * _inheritor; +} dap_chain_wallet_t; + +dap_chain_wallet_t * dap_chain_wallet_open(const char * a_file_name, dap_chain_sig_type_t a_sig_type); // Creates new one if not found +void dap_chain_wallet_close( dap_chain_wallet_t * a_wallet); + +int dap_chain_wallet_get_pkey( dap_chain_wallet_t * a_wallet,uint32_t a_pkey_idx, void * a_pkey, size_t a_pkey_size_max); + +int dap_chain_wallet_sign( dap_chain_wallet_t * a_wallet,uint32_t a_pkey_idx, const void * a_data, size_t a_data_size, void * a_sign, size_t a_sign_size_max); + diff --git a/dap_chain_wallet_internal.h b/dap_chain_wallet_internal.h new file mode 100644 index 0000000000000000000000000000000000000000..fd5146060394afd9795ea059729f0c023d744b0f --- /dev/null +++ b/dap_chain_wallet_internal.h @@ -0,0 +1,66 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include "dap_enc_key.h" +#include "dap_chain_common.h" + +#include "dap_chain_wallet.h" + +#define DAP_CHAIN_WALLET_FILE_SIGNATURE 0x1a167bef15feea18 + +typedef struct dap_chain_wallet_key{ + struct { + dap_chain_sig_type_t sig_type; /// Signature type + uint32_t key_size; /// Private key size + } header; + uint8_t key_raw[]; /// Raw data of the private key +} DAP_ALIGN_PACKED dap_chain_wallet_key_t; + + +typedef struct dap_chain_wallet_file +{ + struct { + uint64_t signature; + uint32_t version; + uint8_t type; /// Wallet storage type 0x00 - uncompressed and unencrypted + uint64_t keys_size; + } DAP_ALIGN_PACKED header; + uint8_t keys[]; +} DAP_ALIGN_PACKED dap_chain_wallet_file_t; + +typedef struct dap_chain_wallet_internal +{ + dap_chain_addr_t addr; + char * file_name; + size_t keys_count; + dap_enc_key_t ** keys; +} dap_chain_wallet_internal_t; + +#define DAP_CHAIN_WALLET_INTERNAL(a) ((dap_chain_wallet_internal_t *) a->_internal ) + +#define DAP_CHAIN_WALLET_INTERNAL_LOCAL(a) dap_chain_wallet_internal_t * l_wallet_internal = DAP_CHAIN_WALLET_INTERNAL(a) + +#define DAP_CHAIN_WALLET_INTERNAL_LOCAL_NEW(a) dap_chain_wallet_internal_t * l_wallet_internal = DAP_NEW_Z(dap_chain_wallet_internal_t); a->_internal = l_wallet_internal