JoyIDSigner

JoyIDSigner is sub-class of Signer in ethers.js, it provides the same interface/API as Signer in ethers.js to interact with JoyID, but it also provides some JoyID specific methods.

For more information about Signer, please refer to ethers.js documentation.

Methods

signChallenge

Open a JoyID app popup window to sign message.

function signChallenge(
  challenge: string | Uint8Array,
  popupConfig?: PopupConfig
): Promise<SignMessageResponse>

challenge vs. message

signTransaction

Open a JoyID app popup window to sign transaction.

function signTransaction(
  tx: TransactionRequest,
  popupConfig?: PopupConfig
): Promise<string>

sendTransaction

Open a JoyID app popup window to sign transaction and send it.

function sendTransaction(
  tx: TransactionRequest,
  popupConfig?: PopupConfig
): Promise<providers.TransactionResponse>

sendUncheckedTransaction

Open a popup window in the JoyID app to sign and send the transaction, regardless of the transaction's status.

function sendUncheckedTransaction(
  tx: TransactionRequest,
  popupConfig?: PopupConfig
): Promise<TxHash extends string>

Types

interface PopupConfig {
  /**
   * Default is 300s
   */
  timeoutInSeconds?: number
  /**
   * popup instance
   */
  popup?: Window
}


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
}

interface TransactionRequest {
  to?: string
  from: string
  nonce?: string
  gasLimit?: string
  gasPrice?: string
  data?: string
  value?: string
  chainId?: number
  customData?: Record<string, any>
  ccipReadEnabled?: boolean
}

Details

Some methods in JoyIDSigner are different from Signer in ethers.js:

  • signMessage(): not supported in JoyIDSigner, use signChallenge instead.
  • _legacySignMessage(): not supported in JoyIDSigner, use signChallenge instead.
  • populateTransaction(): JoyIDSigner DO NOT populate transaction, the transaction will be populated by JoyID App instead.

Example

import { JoyIDProvider } from '@joyid/ethers'

const provider = new JoyIDProvider({
  name: 'MyApp',
  logo: 'https://myapp.com/logo.png',
  rpcURL: 'https://axon-rpc.internal.joyid.dev',
})

// connect to JoyID Wallet
const res = await provider.connect()
const connectedAddress = res.ethAddress

// get JoyID signer and sign a transaction
const signer = provider.getSigner(connectedAddress)
const tx = await signer.sendTransaction({ to: '0x...', value: '100', from: connectedAddress })