signMessage
Open a JoyID app popup window to sign message.
Types
function signMessage (
// The challenge that was requested to be signed
challenge: string | Uint8Array,
// The address of the signer
signerAddress: string,
config?: SignConfig
): Promise<SignMessageResponse>
interface SignConfig extends PopupConfig {
/**
* The name of your app
*/
name?: string
/**
* The logo of your app
*/
logo?: string
/**
* The RPC URL of the AXON node that your app is using, defaults to https://axon-rpc.internal.joyid.dev
*/
rpcURL?: string
/**
* The network that your app is using, defaults to JoyID AXON devnet
*/
network?: Network
/**
* The URL of JoyID app url that your app is integrated with, defaults to https://app.joyid.dev
*/
joyidAppURL?: string
/**
* The URL of JoyID server url that your app is integrated with
*/
joyidServerURL?: string
}
interface PopupConfig {
/**
* Default is 300s
*/
timeoutInSeconds?: number
/**
* popup instance
*/
popup?: Window
}
interface Network {
name: string
chainId: number
}
interface SignMessageResponse {
// The public key of the authenticated user
pubkey: string
/**
* The challenge that was requested to be signed
*/
challenge: string
/**
* The message that was signed by the authenticator,
* Note that the message may not be the original raw message,
* but is combined with client data and authenticator data
* according to [WebAuthn Spec](https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion).
*/
message: string
/**
* The signature of the message that was signed by the authenticator
*/
signature: string
/**
* key type of the authenticated user
*/
keyType: 'main_key' | 'sub_key' | 'main_session_key' | 'sub_session_key'
/**
* The algorithm of the signature.
* corresponds to the `value` field of the [COSE](https://www.iana.org/assignments/cose/cose.xhtml#algorithms) structure
*/
alg: number
/**
* The attestation of the signature,
* only available when keyType is `main_session_key` or `sub_session_key`
*/
attestation?: string
}
Example
import { signMessage } from '@joyid/evm'
async function joyidSign() {
try {
const res = await signMessage(
'Sign this message',
'0x71372492b5bc6ae526fed2cda57919c2b0156afe',
{
logo: 'https://example.com/logo.png',
name: 'Example App'
}
)
console.log(res)
} catch (e) {
console.error(e)
}
}
Details
Note that challenge
and message
are two different concepts, in short:
challenge
is what you as a developer want JoyID to sign.
message
is what JoyID actually signs, which is a combination of challenge
and some other data (such as authenticator data, etc.), and challenge
will be always included in message
.
For more information, you can check out the WebAuthn Spec.
- See also: Guide - Verify Signature with a live demo