Trezor钱包JS开发文档

verifyMessagee - 验证消息

请求设备使用签名地址和签名验证消息。

调用方法

ES6:

const result = await TrezorConnect.verifyMessage(params);

CommonJS:

TrezorConnect.verifyMessage(params).then(function(result) {

});

参数:

可选的公共参数。

flowtype:

  • address:签名地址,必须
  • message:已签名消息,必须
  • signature:签名,base64格式,必须
  • coin:数字货币标识

示例代码

TrezorConnect.verifyMessage({
    address: "3BD8TL6iShVzizQzvo789SuynEKGpLTms9",
    message: "example message",
    signature: "JO7vL3tOB1qQyfSeIVLvdEw9G1tCvL+lNj78XDAVM4t6UptADs3kXDTO2+2ZeEOLFL4/+wm+BBdSpo3kb3Cnsas=",
    coin: "btc"
});

返回结果

flowtype:

{
    success: true,
    payload: {
        message: "Message verified"
    }
}

错误信息:

{
    success: false,
    payload: {
        error: string // error message
    }
}

从早期版本迁移

V4及更早版本:

var address = "3BD8TL6iShVzizQzvo789SuynEKGpLTms9";
var signature = "JO7vL3tOB1qQyfSeIVLvdEw9G1tCvL+lNj78XDAVM4t6UptADs3kXDTO2+2ZeEOLFL4/+wm+BBdSpo3kb3Cnsas=";
TrezorConnect.verifyMessage(
    address,
    signature,
    "example message",
    function(result) {
    ...
}, "bitcoin");

V5:

// params are key-value pairs inside Object
TrezorConnect.verifyMessage({ 
    address: "3BD8TL6iShVzizQzvo789SuynEKGpLTms9",
    signature: "JO7vL3tOB1qQyfSeIVLvdEw9G1tCvL+lNj78XDAVM4t6UptADs3kXDTO2+2ZeEOLFL4/+wm+BBdSpo3kb3Cnsas=",
    message: "example message",
    coin: "btc"
}).then(function(result) {
    ...
})