gpt4 book ai didi

javascript - 尝试验证签名时来自以太的无效签名错误

转载 作者:行者123 更新时间:2023-12-05 00:27:33 25 4
gpt4 key购买 nike

我正在开发一个需要验证用户签名的 dapp。使用 Metamask 进行测试时,一切正常。
尝试验证来自 Ambire 钱包的签名时,我从 ethers.utils.verifyMessage 收到“错误:无效签名字符串”
例如,这是我从 Ambire 那里得到的签名:0xf1b5f561c1914d513f4020edd397f729836e26eeae8f1b9e4070d134492aa38b0a84b9d7cefe06f180ade91595fd74c4e845c2b8c2d053fa57785fdf5ec5dca31c01当我尝试验证它时,会发生这种情况

require('ethers').utils.verifyMessage('test', '0xf1b5f561c1914d513f4020edd397f729836e26eeae8f1b9e4070d134492aa38b0a84b9d7cefe06f180ade91595fd74c4e845c2b8c2d053fa57785fdf5ec5dca31c01')
Uncaught:
Error: invalid signature string (argument="signature", value="0xf1b5f561c1914d513f4020edd397f729836e26eeae8f1b9e4070d134492aa38b0a84b9d7cefe06f180ade91595fd74c4e845c2b8c2d053fa57785fdf5ec5dca31c01", code=INVALID_ARGUMENT, version=bytes/5.6.1)
知道这是否可以解决吗?

最佳答案

为了支持 Ambire、Gnosis Safe、Argent 等智能钱包,您需要 implement EIP 1271 .
Ambire 通用签名验证,支持:

  • 标准消息验证 (eth_sign)
  • 712 类型数据验证 (eth_signTypedData_v*)
  • 1271 智能合约链上验证(isValidSignature)
    可选的智能合约签名链下验证(例如,如果智能钱包是反事实的且尚未部署)

  • 使用 @ambire/signature-validator 进行简单的 eth_sign 验证
    const ethers = require('ethers')
    const { verifyMessage } = require('@ambire/signature-validator')

    const provider = new ethers.providers.JsonRpcProvider('https://polygon-rpc.com')

    async function run() {
    // Replace `ethers.verifyMessage(message, signature) === signer` with this:
    const isValidSig = await verifyMessage({
    signer: '0xaC39b311DCEb2A4b2f5d8461c1cdaF756F4F7Ae9',
    message: 'My funds are SAFU with Ambire Wallet',
    signature: '0x9863d84f3119ac01d9e3bf9294e6c0c3572a07780fc7c49e8dc913806f4b1dbd4cc075462dc84422a9b981b2556f9c9197d76da7ba3603e53e9300869c574d821c',
    // this is needed so that smart contract signatures can be verified
    provider,
    })
    console.log('is the sig valid: ', isValidSig)
    }
    run().catch(e => console.error(e))

    关于javascript - 尝试验证签名时来自以太的无效签名错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72228594/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com