MCPcopy Create free account
hub / github.com/ccxt/ccxt / sign

Method sign

python/ccxt/async_support/aster.py:3900–3963  ·  view source on GitHub ↗
(self, path, api: Any = 'public', method='GET', params={}, headers: dict = None, body: Any = None)

Source from the content-addressed store, hash-verified

3898 return '0x' + r.rjust(64, '0') + s.rjust(64, '0') + v
3899
3900 def sign(self, path, api: Any = 'public', method='GET', params={}, headers: dict = None, body: Any = None):
3901 url = self.urls['api'][api] + '/' + path
3902 if api == 'fapiPublic' or api == 'sapiPublic':
3903 if params:
3904 url += '?' + self.rawencode(params)
3905 elif api == 'fapiPrivate' or api == 'sapiPrivate':
3906 self.check_required_credentials()
3907 nonce = self.milliseconds() * 1000
3908 # Sign using EIP-712 typed data per the AsterSignTransaction spec
3909 zeroAddress = self.safe_string(self.options, 'zeroAddress', '0x0000000000000000000000000000000000000000')
3910 v3ChainId = self.safe_integer(self.options, 'v3ChainId', 1666)
3911 walletAddress = self.eth_get_address_from_private_key(self.privateKey)
3912 signerAddress = self.safe_string(self.options, 'signerAddress', walletAddress) # default to user's wallet
3913 if signerAddress is None:
3914 raise ArgumentsRequired(self.id + ' requires signerAddress in options when use v3 api')
3915 domain = {
3916 'name': 'AsterSignTransaction',
3917 'version': '1',
3918 'chainId': v3ChainId,
3919 'verifyingContract': zeroAddress,
3920 }
3921 messageTypes = {
3922 'Message': [
3923 {'name': 'msg', 'type': 'string'},
3924 ],
3925 }
3926 # Build v3 params: original endpoint params + nonce(macroseconds) + user + signer
3927 # Note: timestamp and recvWindow are not used for v3; nonce replaces timestamp
3928 finalParams = self.extend({
3929 'nonce': str(nonce),
3930 'user': walletAddress,
3931 'signer': signerAddress,
3932 }, params)
3933 paramString = None
3934 paramsToEncode: dict
3935 isApproveBuilder = (path.find('/approveBuilder') >= 0)
3936 if isApproveBuilder:
3937 # domain['name'] = 'Aster'
3938 messageTypes = {
3939 'ApproveBuilder': [
3940 {'name': 'Builder', 'type': 'string'},
3941 {'name': 'MaxFeeRate', 'type': 'string'},
3942 {'name': 'BuilderName', 'type': 'string'},
3943 {'name': 'AsterChain', 'type': 'string'},
3944 {'name': 'User', 'type': 'string'},
3945 {'name': 'Nonce', 'type': 'uint256'},
3946 ],
3947 }
3948 del finalParams['signer'] # signer is not needed for approveBuilder endpoint
3949 paramString = self.encode_values_with_json(finalParams)
3950 paramsToEncode = self.capitalize_keys(finalParams)
3951 else:
3952 paramString = self.encode_values_with_json(finalParams)
3953 paramsToEncode = {'msg': paramString}
3954 encodedMessage = self.eth_encode_structured_data(domain, messageTypes, paramsToEncode)
3955 signature = self.sign_message(encodedMessage, self.privateKey)
3956 queryString = paramString + '&' + 'signature=' + signature
3957 if method == 'GET':

Callers

nothing calls this directly

Calls 13

capitalize_keysMethod · 0.95
sign_messageMethod · 0.95
ArgumentsRequiredClass · 0.90
safe_stringMethod · 0.80
safe_integerMethod · 0.80
findMethod · 0.80
rawencodeMethod · 0.45
millisecondsMethod · 0.45

Tested by

no test coverage detected