Skip to main content

signMessage

Function

Sign the message according to the account, ethConnectedSigner, arJWK, isSmartAccount parameters passed when the Everpay instance was created.

Parameter

everpay.signMessage(message: string, smartAccountDirectly?: boolean): Promise<SignMessageResult>
danger
  • smartAccountDirectly may not be passed, default is false.
  • The smartAccountDirectly parameter is only valid for mailbox account signatures.
  • When it is an email account, !!smartAccountDirectly is true.
    • The webauthn direct signature message is used.
    • message Must be >= 96 in length.
    • The message field in the returned result is the same as the original message.
  • When it is an email account, ! !smartAccountDirectly is false.
    • everpay-js internally hash the message with hashMessage before signing it with webauthn
    • message has no length limit.
    • The message field in the returned result is a hex string after hashMessage(message).

Return

export interface SignMessageResult {
message: string
sig: string
}

Example

EVM signMessage

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 signMessage

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())
})
})
})

Smart Account signMessage

danger

Due to browser window security popup restrictions, do not call the smartAccountAuth interface and the signMessage interface in the same function, they must be triggered by different event functions. The following is just an example

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