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 registered through Register using SDK flow.

Direct Authentication

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

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

const signer = new KeySigner(process.env.PRIVATE_KEY!, true);

const passport = new Passport({
    scopeId: "insert_your_scope_id",
    signer: signer,
    allowSessions: 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

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
}

Last updated