Python 为 Blur.io 签署 EIP-712 消息

标签 python nft eip

目标是在 python 中对blur.io 进行收藏出价。 要访问 Blur API,我使用 https://rapidapi.com/openseatools/api/blur/ .

总结一下这个问题:我无法成功签署消息(或者使用相同的数据在 python 中获得与 Metamask 中相同的签名)。

尝试:

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) 

消息是来自 POST/v1/collection-bids/format 的响应。

您可以通过访问blur.io并发布集合出价(并观察格式并提交请求)来测试该流程。


来自rapidapi.com的开发者提供了以下代码来用JS对消息进行签名。这段代码工作正常,所以问题可能是:如何在 python 中实现这个函数?

const signature = await wallet.signer._signTypedData(
      message.signData.domain,
      message.signData.types,
      message.signData.value,
    );

最佳答案

错误在这里:

values["extraParams"] = bytes.fromhex(values["extraParams"][2:])

关于Python 为 Blur.io 签署 EIP-712 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76221518/

相关文章:

python - 通过sqlite在sql alchemy中远程创建数据库

python - 使用 salt 进行 MariaDB 复制 - 未找到状态

blockchain - 如何检查 NFT 是否在特定钱包中

java - 带有关联表达式的 Camel 聚合器

java - 阻塞路由直到消费者收到消息

python - 如何在 numpy.polyfit 中包含测量误差

python - python/pandas 中的条件聚合

node.js - 类型错误 : Cannot read properties of undefined (reading 'path' )

web3js - 错误: 410 Gone: "The RPC call or parameters have been disabled."

java - Apache Camel(这里使用哪个 EIP?)聚合/丰富具有重复 header 数据的所有行