To sign a transaction a user / an account would need to have to have been register and authenticated by going through Register using SDK flow.
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";constsigner=newWebauthnSigner({ rpId:window.location.hostname, rpName:"rpName",});constpassport=newPassport({ scopeId:"insert_your_scope_id", signer: signer});constuserInput { username:"insert_registered_username_here" userDisplayName:"insert_registered_user_display_name_here"}awaitpassport.setupEncryption();awaitpassport.authenticate(userInput);// Transaction Can be of type legacy (0x0),// EIP2930 (0x01) or EIP1559 (0x02)consttransaction= { nonce:"0", maxPriorityFeePerGas:"0x9184E72A", maxFeePerGas:"0x9184E72A", to:"0xb89FF4E9AD6B33F69153fa710F9849f51712eEc4", gas:"0x7530", value:"0x2386F26FC10000", chainId:"0x7A69", type:"0x02"}// Generate a threshold signatureconstsignature=awaitpassport.signTransaction(transaction);console.log(signature); // This is an rlp encoded transaction signature
signTransaction Parameters
Parameter
Description
Example Values
transaction
The transaction object to be signed, can be a Legacy, EIP2930, or EIP1559 transaction type
signTransaction Response
A successful response will return the following, an RLP encoded transaction signature from the authenticated account that can be executed as a raw transaction.
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";constsigner=newWebauthnSigner({ rpId:window.location.hostname, rpName:"rpName",});constpassport=newPassport({ scope_id:"insert_your_scope_id", signer: signer});constuserInput { username:"insert_registered_username_here" userDisplayName:"insert_registered_user_display_name_here"}awaitpassport.setupEncryption();//This step is different for direct authenticationpassport.setUserData(userInput)// Transaction Can be of type legacy (0x0),// EIP2930 (0x01) or EIP1559 (0x02)consttransaction= { nonce:"0", maxPriorityFeePerGas:"0x9184E72A", maxFeePerGas:"0x9184E72A", to:"0xb89FF4E9AD6B33F69153fa710F9849f51712eEc4", gas:"0x7530", value:"0x2386F26FC10000", chainId:"0x7A69", type:"0x02"}// Generate a threshold signatureconstsignature=awaitpassport.signTransaction(transaction);console.log(signature); // This is an rlp encoded transaction signature
signTransaction Parameters
Parameter
Description
Example Values
transaction
The transaction object to be signed, can be a Legacy, EIP2930, or EIP1559 transaction type
signTransaction Response
A successful response will return the following, an RLP encoded transaction signature from the authenticated account that can be executed as a raw transaction.