Skip to content

Commit

Permalink
Add python bindings for iroha crypto.
Browse files Browse the repository at this point in the history
Signed-off-by: luckychess <[email protected]>
  • Loading branch information
luckychess authored and lebdron committed Dec 19, 2017
1 parent 42ba1be commit 044ae40
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 9 deletions.
2 changes: 1 addition & 1 deletion shared_model/cryptography/blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace shared_model {
* migration to shared model in whole project
*/
template <typename BlobType>
[[deprecated]] BlobType makeOldModel() const {
BlobType makeOldModel() const {
return BlobType::from_string(blob());
}

Expand Down
1 change: 1 addition & 0 deletions shared_model/cryptography/ed25519_sha3_impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

add_subdirectory(internal)
add_subdirectory(bindings)

add_library(shared_ed25519_sha3
signer.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2017 Soramitsu Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

find_package(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

FIND_PACKAGE(PythonLibs REQUIRED)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
SET(CMAKE_SWIG_FLAGS "")
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

SET_SOURCE_FILES_PROPERTIES(crypto.i PROPERTIES CPLUSPLUS ON)
SWIG_ADD_LIBRARY(crypto LANGUAGE python SOURCES crypto.i)

SWIG_LINK_LIBRARIES(crypto ${PYTHON_LIBRARIES} shared_ed25519_sha3 hash cryptography ed25519_sha3)
51 changes: 51 additions & 0 deletions shared_model/cryptography/ed25519_sha3_impl/bindings/crypto.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
* http://soramitsu.co.jp
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

%module crypto
%include "std_string.i"

%{
#include "cryptography/ed25519_sha3_impl/crypto_provider.hpp"
%}

%include "interfaces/model_primitive.hpp"
%include "interfaces/primitive.hpp"
%include "cryptography/blob.hpp"
%include "cryptography/seed.hpp"
%include "cryptography/signed.hpp"
%include "cryptography/public_key.hpp"
%include "cryptography/private_key.hpp"
%include "cryptography/keypair.hpp"
%include "cryptography/ed25519_sha3_impl/crypto_provider.hpp"

namespace shared_model {
namespace interface {
%template(imodelprim) shared_model::interface::ModelPrimitive<shared_model::crypto::Blob>;
%template(ikeypair) ModelPrimitive<crypto::Keypair>;
%template(iprim) shared_model::interface::Primitive<crypto::Keypair, iroha::keypair_t>;
}

namespace crypto {
class Blob;
class Keypair;
class Seed;
class Signed;
class PublicKey;
class PrivateKey;
class CryptoProvider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ namespace shared_model {
}

Keypair CryptoProvider::generateKeypair() const {
auto keypair = iroha::create_keypair();
return Keypair(PublicKey(keypair.pubkey.to_string()),
PrivateKey(keypair.privkey.to_string()));
return generateKeypair(generateSeed());
}

Keypair CryptoProvider::generateKeypair(const Seed &seed) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ namespace shared_model {
bool verify(const Signed &signedData,
const Blob &orig,
const PublicKey &publicKey) const;

/**
* Generates nes seed
* Generates new seed
* @return Seed generated
*/
Seed generateSeed() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ add_library(hash
)

target_link_libraries(hash
ed25519_sha3
common
pb_model_converters
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ add_library(ed25519_sha3
sign.c
verify.c
)
#target_include_directories(ed25519_sha3 INTERFACE ed25519)
3 changes: 2 additions & 1 deletion shared_model/cryptography/keypair.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace shared_model {
.finalize();
}

OldModelType *makeOldModel() const override {
interface::Primitive<Keypair, iroha::keypair_t>::OldModelType *
makeOldModel() const override {
return new iroha::keypair_t{
.pubkey = publicKey().makeOldModel<PublicKey::OldPublicKeyType>(),
.privkey =
Expand Down
2 changes: 1 addition & 1 deletion shared_model/interfaces/primitive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace shared_model {
* model
* @return pointer for old-style object
*/
[[deprecated]] virtual OldModelType *makeOldModel() const = 0;
virtual OldModelType *makeOldModel() const = 0;
};

} // namespace interface
Expand Down

0 comments on commit 044ae40

Please sign in to comment.