Python签署EIP-712消息用于blur.io

huangapple go评论59阅读模式
英文:

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:])

huangapple
  • 本文由 发表于 2023年5月11日 02:18:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221518.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定