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

Method sign

python/ccxt/aster.py:3899–3962  ·  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

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