Skip to content

Commit

Permalink
SKALE-2468 Add sign_hash method to sgx wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrotkk committed Apr 23, 2020
1 parent 0813e6c commit bdf4a00
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"web3==5.5.1",
"asyncio==3.4.3",
"pyyaml==5.3.1",
"sgx.py==0.4.dev6",
"sgx.py==0.5dev0",
],

python_requires='>=3.6,<4',
Expand Down
3 changes: 3 additions & 0 deletions skale/wallets/ledger_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def sign_and_send(self, tx) -> str:
signed_tx = self.sign(tx)
return self._web3.eth.sendRawTransaction(signed_tx.rawTransaction).hex()

def sign_hash(self, unsigned_hash: str):
raise NotImplementedError('sign_hash is not implemented for hardware wallet')

@classmethod
def parse_derive_result(cls, exchange_result):
pk_len = exchange_result[0]
Expand Down
3 changes: 3 additions & 0 deletions skale/wallets/sgx_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def sign_and_send(self, tx_dict) -> str:
signed_tx = self.sign(tx_dict)
return self._web3.eth.sendRawTransaction(signed_tx.rawTransaction).hex()

def sign_hash(self, unsigned_hash: str):
return self.sgx_client.sign_hash(unsigned_hash, self._key_name, self._web3.eth.chainId)

@property
def address(self):
return self._address
Expand Down
19 changes: 19 additions & 0 deletions tests/wallets/sgx_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ def sign(self, transaction_dict, key_name):
'v': 37,
})

def sign_hash(self, message, key_name, chain_id):
return AttributeDict({
'messageHash': HexBytes('0x0'),
'r': 123,
's': 123,
'v': 27,
'signature': HexBytes('0x0')
})


def test_sgx_sign():
with mock.patch('skale.wallets.sgx_wallet.SgxClient',
Expand Down Expand Up @@ -113,6 +122,16 @@ def test_sgx_sign_with_key():
wallet.sign(tx_dict)


def test_sgx_sign_hash():
with mock.patch('skale.wallets.sgx_wallet.SgxClient',
new=SgxClient):
web3 = init_web3(ENDPOINT)
wallet = SgxWallet('TEST_ENDPOINT', web3, key_name='TEST_KEY')
unsigned_hash = '0x0'
signed_message = wallet.sign_hash(unsigned_hash)
assert signed_message.signature == HexBytes('0x0')


def test_sgx_key_init():
with mock.patch('skale.wallets.sgx_wallet.SgxClient',
new=SgxClient):
Expand Down

0 comments on commit bdf4a00

Please sign in to comment.