跳到主要内容

signMessage

功能

message 根据 Everpay 实例创建时,传递的 account, ethConnectedSigner, arJWK, isSmartAccount 参数进行签名

参数

everpay.signMessage(message: string, smartAccountDirectly?: boolean): Promise<SignMessageResult>
危险
  • smartAccountDirectly 可不传递,默认为 false
  • smartAccountDirectly 参数仅对邮箱账户的签名有效
  • 当为邮箱账户时,!!smartAccountDirectlytrue
    • 会使用 webauthn 直接签名 message
    • message 长度必须 >= 96
    • 返回结果中的 message 字段与原 message 一致
  • 当为邮箱账户时,!!smartAccountDirectlyfalse
    • everpay-js 内部会先通过 hashMessagemessage 进行一层 hash 处理后,再使用 webauthn 签名
    • message 没有长度限制
    • 返回结果中的 message 字段为 hashMessage(message) 后的 hex string

返回

export interface SignMessageResult {
message: string
sig: string
}

示例

EVM 签名示例

describe('signMessage for EVM', () => {
test('signMessage EVM should be OK', async () => {
const message = 'verify'
const signResult = await everpayEVM.signMessage(message)
expect(signResult.message).toBe(message)
return await everpayEVM.verifyMessage({
type: 'sign',
message,
account: ethWalletHasUSDT.address,
sig: signResult.sig
}).then(result => {
expect(result.public).toBeTruthy()
expect(result.publicId.toLowerCase()).toBe(ethWalletHasUSDT.address.toLowerCase())
})
})
})

Arweave 签名示例

describe('signMessage for Arweave', () => {
test('signMessage for Arweave should be OK', async () => {
const account = arWallet1.address
const message = 'verify'
const signResult = await everpayAR.signMessage(message)
expect(signResult.message).toBe(message)
return await everpayAR.verifyMessage({
type: 'sign',
message,
account,
sig: signResult.sig
}).then(result => {
expect(result.public).toBeTruthy()
expect(result.publicId.toLowerCase()).toBe(account.toLowerCase())
})
})
})

邮箱账户签名示例

危险

因浏览器窗口安全弹出限制,请勿将 smartAccountAuth 接口与 signMessage 接口在同一个函数中调用,必须要由不同的事件函数触发。以下仅为示例

const authResult = await new Everpay().smartAccountAuth()
const everpaySmartAccount = new Everpay({
account: authResult.account,
isSmartAccount: true
})
const signResult = await everpaySmartAccount.signMessage('Hello World')
/*
{
message: "0xa1de988600a42c4b4ab089b619297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