Skip to content

Commit b17a223

Browse files
authored
Merge pull request #25 from Safeheron/dev
Added Query Wallet Account by Address and Retrieve a Single Web3 Wallet Account interfaces
2 parents e3bb793 + 6db61cb commit b17a223

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

safeheron_api_sdk_python/api/account_api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ def __init__(self):
3636
# Merchant unique business ID (100 characters max)
3737
self.customerRefId = None
3838

39-
39+
class OneAccountByAddressRequest:
40+
def __init__(self):
41+
# The wallet address. Note: Wallet addresses for the TRON, Solana, and TON networks are case-sensitive, while other networks are case-insensitive
42+
self.address = None
4043

4144
class CreateAccountRequest:
4245
def __init__(self):
@@ -206,6 +209,10 @@ def list_accounts(self, request: ListAccountRequest):
206209
def one_accounts(self, request: OneAccountRequest):
207210
return self.api_client.send_request(request, '/v1/account/one')
208211

212+
# Query Wallet Account by Address
213+
def get_account_by_address(self, request: OneAccountByAddressRequest):
214+
return self.api_client.send_request(request, '/v1/account/getByAddress')
215+
209216
# Create a new wallet account.
210217
def create_account(self, request: CreateAccountRequest):
211218
return self.api_client.send_request(request, '/v1/account/create')

safeheron_api_sdk_python/api/web3_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def __init__(self):
4141
# Merchant unique business ID (100 characters max)
4242
self.customerRefId = None
4343

44+
class OneWeb3AccountRequest:
45+
def __init__(self):
46+
# Account Key, the only account identifier。The Account Key, which is the unique identifier for the account. Cannot be empty at the same time as the customerRefId parameter. If both are provided, the accountKey parameter will take precedence.
47+
self.accountKey = None
48+
# Merchant unique business ID (100 characters max)
49+
self.customerRefId = None
4450

4551
class CreateWeb3EthSignRequest:
4652
def __init__(self):
@@ -239,6 +245,11 @@ def batchCreateWeb3Account(self, request: BatchCreateWeb3AccountRequest):
239245
def listWeb3Accounts(self, request: ListWeb3AccountRequest):
240246
return self.api_client.send_request(request, '/v1/web3/account/list')
241247

248+
# List Web3 Wallet Accounts
249+
# Filter Web3 wallet account lists by various conditions.
250+
def oneWeb3Account(self, request: OneWeb3AccountRequest):
251+
return self.api_client.send_request(request, '/v1/web3/account/one')
252+
242253
# Create ethSign
243254
# Merchants can initiate an ethSign signature through this interface. The merchant is required to serialize the transaction data, generating a corresponding hash (supporting both 0x and non-0x formatted data). The hash is then submitted through this interface to create a signature, which can be obtained by Retrieve a Single Web3 Signature interface or webhook. From there, merchants can complete the subsequent steps according to their own needs once they have obtained the signature.
244255
def createWeb3EthSign(self, request: CreateWeb3EthSignRequest):

safeheron_api_sdk_python/tools.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ def aes_encrypt(key: bytes, iv: bytes, message: bytes):
6262

6363
def aes_gcm_encrypt(key: bytes, iv: bytes, message: bytes):
6464
check_key_and_iv(key, iv)
65-
try:
66-
cipher = AES.new(key, AES.MODE_GCM, iv)
67-
cipher_text, tag = cipher.encrypt_and_digest(message)
68-
except Exception as e:
69-
raise Exception("aes encrypt error: %s" % e)
65+
cipher = AES.new(key, AES.MODE_GCM, iv)
66+
cipher_text, tag = cipher.encrypt_and_digest(message)
7067
return cipher_text + tag
7168

7269

@@ -82,12 +79,14 @@ def aes_decrypt(key: bytes, iv: bytes, encrypt_text: bytes):
8279

8380
def aes_gcm_decrypt(key: bytes, iv: bytes, encrypt_text: bytes):
8481
check_key_and_iv(key, iv)
82+
if len(encrypt_text) < 16:
83+
raise Exception("aes decrypt error: invalid ciphertext")
84+
ciphertext, tag = encrypt_text[:-16], encrypt_text[-16:]
85+
cipher = AES.new(key, AES.MODE_GCM, iv)
8586
try:
86-
cipher = AES.new(key, AES.MODE_GCM, iv)
87-
pad_text = cipher.decrypt(encrypt_text)
88-
except Exception as e:
89-
raise Exception("aes decrypt error: %s" % e)
90-
return pad_text[0:len(pad_text)-len(iv)]
87+
return cipher.decrypt_and_verify(ciphertext, tag)
88+
except ValueError as exc:
89+
raise Exception("aes decrypt error: tag verification failed") from exc
9190

9291

9392
def get_rsa_key(key_pem, passphrase=None):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
with open("README.rst", "r") as f:
44
long_description = f.read()
55
setup(name='safeheron_api_sdk_python',
6-
version='1.1.20',
6+
version='1.1.21',
77
description='Python for Safeheron API',
88
long_description=long_description,
99
author='safeheron',

0 commit comments

Comments
 (0)