英文:
Python signing EIP-712 messages for blur.io
问题
values = message["signatures"][0]["signData"]["value"]
# 'message' types that differ from 'types' schema
values["tokenId"] = int(values["tokenId"])
values["amount"] = int(values["amount"])
values["price"] = int(values["price"])
values["expirationTime"] = int(values["expirationTime"], 16)
values["salt"] = int(values["salt"], 16)
values["extraParams"] = bytes.fromhex(values["extraParams"])
values["nonce"] = int(values["nonce"])
data = {
"domain": message["signatures"][0]["signData"]["domain"],
"message": values,
"types": {
"EIP712Domain": [
{"name": "name", "type": "string"},
{"name": "version", "type": "string"},
{"name": "chainId", "type": "uint256"},
{"name": "verifyingContract", "type": "address"},
],
**message["signatures"][0]["signData"]["types"],
},
"primaryType": 'Order',
}
signature = Web3().eth.account.sign_message(
encode_structured_data(data),
private_key=self.wallet_credentials.private_key)
英文:
The goal is to place a collection bid on blur.io in python.
To access the Blur API I use https://rapidapi.com/openseatools/api/blur/.
To summarise the issue: I cannot manage to successfully sign a message (or get the same signature in python as in Metamask, using the same data).
The attempt:
values = message["signatures"][0]["signData"]["value"]
# 'message' types that differs from 'types' schema
values["tokenId"] = int(values["tokenId"])
values["amount"] = int(values["amount"])
values["price"] = int(values["price"])
values["expirationTime"] = int(values["expirationTime"], 16)
values["salt"] = int(values["salt"], 16)
values["extraParams"] = bytes(int(values["extraParams"], 16))
values["nonce"] = int(values["nonce"])
data = {
"domain": message["signatures"][0]["signData"]["domain"],
"message": values,
"types": {
"EIP712Domain": [
{"name": "name", "type": "string"},
{"name": "version", "type": "string"},
{"name": "chainId", "type": "uint256"},
{"name": "verifyingContract", "type": "address"},
],
**message["signatures"][0]["signData"]["types"]
},
"primaryType": 'Order',
}
signature = Web3().eth.account.sign_message(
encode_structured_data(data),
private_key=self.wallet_credentials.private_key)
With message
being the response from a POST /v1/collection-bids/format.
You can test the process by visiting blur.io and posting a collection bid (and watching the format and submit requests).
The developer from rapidapi.com provided the following code to sign the message in JS. This code works fine, so the question could be: how to implement this function in python?
const signature = await wallet.signer._signTypedData(
message.signData.domain,
message.signData.types,
message.signData.value,
);
答案1
得分: 1
错误发生在这里:
values["extraParams"] = bytes.fromhex(values["extraParams"][2:])
英文:
The error was here:
values["extraParams"] = bytes.fromhex(values["extraParams"][2:])
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论