signWithPopup

Open a JoyID app popup window to sign message.

Types

function signWithPopup (
  request: SignMessageRequest,
  config?: PopupConfigOptions
): Promise<SignMessageResponse>

interface SignMessageRequest {
  /**
   * The URL of your app that JoyID app should redirect to after authentication
   */
  redirectURL: string
  /**
   * name of your app
   */
  name?: string
  /**
   * logo of your app
   */
  logo?: string
  /**
   * The challenge that was requested to be signed
   */
  challenge: string

  /**
   * sign the challenge as a hex data
   */
  isData?: boolean
  /**
   * Custom state that will be returned to your app after signing
   */
  state?: any
}

interface SignMessageResponse {
  type: 'SignMessage'
  error?: string
  data?: SignMessageData
}

interface SignMessageData {
  // 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 PopupConfigOptions {
  /**
   * Default is 300s
   */
  timeoutInSeconds?: number
}

Example

import { SignWithPopup } from '@joyid/core'

async function joyidSign() {
  const request = {
    redirectURL: 'https://example.com',
    title: 'Example App',
    logo: 'https://example.com/logo.png',
    challenge: 'Sign this message',
  }
  const res = await signWithPopup(request)
  if (res.error != null) {
    console.error(res.error)
  } else {
    // the message has signed,
    // do something with res.data, it's type safe!
  }
}

Details

Table of Contents