Passport
  • 👩‍💻Welcome
  • How Passport Works
    • Overview
    • Background
      • Threshold Cryptography
      • Secure Multi-Party Computation
      • Distributed Architecture
      • Secure Enclaves
    • In Depth
      • Under the Hood
      • User Flows and Account Controls
      • The Halides Model
      • End-to-End Encryption
      • Security
      • Node Operation
  • guides and examples
    • Getting Started
    • Quickstarts and Examples
      • Passkey Account
      • Clerk Auth
      • Lambda Quickstart
  • Authentication
    • Overview
    • Configuring your scope
    • Passkeys
      • Registration
        • Register using SDK
        • Register using API
          • Initiate Registration
          • Complete Registration
      • Authentication
        • Authenticating with SDK
        • Authenticating with API
          • Initiate Authentication
          • Complete Authentication
    • Developer Owned Auth
      • Registration
        • Register using SDK
        • Register using API
          • Delegate Registration
  • Wallet Operations
    • Overview
    • Passkeys Signer
      • Sign Message
        • Sign Message SDK
        • Sign Message API
      • Sign Transaction
        • Sign Transaction SDK
        • Sign Transaction API
    • DOA Signer
      • Sign Message
        • Sign Message SDK
        • Sign Message API
      • Sign Transaction
        • Sign Transaction SDK
        • Sign Transaction API
    • Viem Support
  • Programmability
    • Overview
    • Passport Lambda
    • Lambda Functions
      • Create Lambda
        • Create Lambda SDK
        • Create Lambda API
      • Execute Lambda
        • Execute Lambda SDK
        • Execute Lambda API
      • List Lambda
        • List Lambda SDK
        • List Lambda API
  • Appendix
    • Moving to Mainnet
    • State Of The Network
    • Generating DOA Keys
    • API Request Setup
      • Unauthenticated Requests
      • Authenticated Requests
Powered by GitBook
On this page
  • Session-Based Authentication
  • signMessage Parameters
  • Direct Passkey Authentication
  • signMessage Parameters
  1. Wallet Operations
  2. Passkeys Signer
  3. Sign Message

Sign Message SDK

signMessage allows you to generate a signature on a message.

To sign a message a user / an account would need to have to have been register and authenticated by going through Register using SDK flow.

Once you have registered the user, you can choose one of the below 2 flows

Session-Based Authentication

In order to use this flow, you must Authenticating with SDK first to obtain a JWT. Here is a sample of how to use it

import { Passport } from "@0xpass/passport";
import { WebauthnSigner } from "@0xpass/webauthn-signer";
import { stringToHex } from "viem";
import { Passport } from "@0xpass/passport";
import { WebauthnSigner } from "@0xpass/webauthn-signer";

const signer = new WebauthnSigner({
      rpId: window.location.hostname,
      rpName: "rpName",
});

const passport = new Passport({
    scopeId: "insert_your_scope_id",
    signer: signer
});

const userInput {
   username: "insert_registered_username_here"
   userDisplayName: "insert_registered_user_display_name_here"
}

await passport.setupEncryption();
await passport.authenticate(userInput);

// Generate a signature
const signature = await passport.signMessage(stringToHex("hello world!"));
console.log(signature);

signMessage Parameters

Parameter
Description
Example Values

message

The message you'd like to sign

68656c6c6f20776f726c64 (hex represenation of "hello world")

signMessage Response

A successful response will return the following, a signature of the signed message by the authenticated account.

{
    "jsonrpc": "2.0",
    "result": "signature_here",
    "id": 1
}

Direct Passkey Authentication

Since you will be directly authenticating with Passkeys here, you don't need to go through authentication step. Here is a code sample:

import { Passport } from "@0xpass/passport";
import { WebauthnSigner } from "@0xpass/webauthn-signer";
import { stringToHex } from "viem";
import { Passport } from "@0xpass/passport";
import { WebauthnSigner } from "@0xpass/webauthn-signer";

const signer = new WebauthnSigner({
      rpId: window.location.hostname,
      rpName: "rpName",
});

const passport = new Passport({
    scope_id: "insert_your_scope_id",
    signer: signer
    allow_sessions: false
});

const userInput {
   username: "insert_registered_username_here"
   userDisplayName: "insert_registered_user_display_name_here"
}

await passport.setupEncryption();
//This step is different for direct authentication
passport.setUserData(userInput)

// Generate a signature
const signature = await passport.signMessage(stringToHex("hello world!"));
console.log(signature);

signMessage Parameters

Parameter
Description
Example Values

message

The message you'd like to sign

68656c6c6f20776f726c64 (hex represenation of "hello world")

signMessage Response

A successful response will return the following, a signature of the signed message by the authenticated account.

{
    "jsonrpc": "2.0",
    "result": "signature_here",
    "id": 1
}
PreviousSign MessageNextSign Message API

Last updated 9 months ago