Authenticating with SDK

Authenticate

Once you've created an account and keypair has been created for it, to now interact with the protocol, to sign messages and transactions you will first have to authenticate. For authentication the flow is more or less the same.

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

const signer = new WebauthnSigner({
      rpId: window.location.hostname,
      rpName: "rpName",
});
s
const passport = new Passport({
    scope_id: "insert_your_scope_id",
    signer: signer
});

const userInput {
   username: "insert_username_here"
   userDisplayName: "insert_user_display_name_here"
}

await passport.setupEncryption();
const [authenticatedHeader, address] = await passport.authenticate(userInput);

The setup is the same we just call the authenticate function with the userInput.

The authenticate function returns two items, a header which we use to authenticate subsequent requests, and the address associated with the account

The authenticatedHeader

{
    // When we call setupEncryption, it generates a random aes key for you. It is the encrypted version of AES key using our public RSA key
    "X-Encrypted-Key": "nAr0IMFWsvN8nGqF43s+kmQ+dkCJhCQwr58SQ+vK+QaAqhuKur+974CeLApUPg+MeM8lOQOfFlm8Bkqowg0w2oszUcUyFH2WE2iDQk2ZrdQVDusSzjgP2lCZjxFDUHK2kpoD1qjoPMgjOI1sOnc0Bd9jLbv0OKWcVm6u/+8pJrV7LXZ5df2BOdUg3xXCg2OS2UfnuXgYR6o10aC4m+FdTDwbDl6bnUox8zESDuCHM6WfioaQTGRMrPxyajENSrEpGwwB6369hlW0lxeR7Lz+YIGLNPpGsoBx6P2zZfaJ8/DcOd5LUXXXMZT4bGeQxuNHJmw2I8wgmznmJy1T54UTsA==",
    // JWT token encrypted with encryption key (aes key provided by you)
    "X-Encrypted-Session": "C2FjnsrFaGlm3OOGwCoBNqaX8tO1FqVwPK3qKKD8gu9U3ZDVzYG6go9pV2kgg4suU3GwdwAOAF7fd9ULwVuIVcASuxDiL5uZ8A+yXw233TXuRk1vr0q2ZeJTnRkOSV4dV9EAfeuYzUtCCfrHaa7LlE7IXfVGHQ3lxm5F7AUt+bm+Ttphq+4c3iTp9XHzFH5vIUfATvpj1w2bSwe/4R8viMpcDHcj/OGGpdj5X0yWnEshP2Y1hpXYFXs71QWUjGueGavyaeAJK81eKOvOf0wT8zi0ZJWKPNGV45FqB+9VvDXooyQVfzoPojnybMPE/oRjSvSazU9MMUMEInRE9BIoeztBrQeoVG65W6erq1viITYb0OsV75+PzKOESmnLhRuoyqOi3If5wXu+gGQzI2xmnsgoXZNlfiUmgPhQU05989sUHRHRDpbX/LDD03Jq6X4l8GEa5+WVsTFkP55iyIePVfoXYFwVihYCwtPFeQgJp76KeRKs7T5YSneBDpoR5M+Y7a6aDpepjgmLReBGR1uRKaEZooW/bUdtgpwXjr4C1HFderWC/aBt4Mr2ySehHPOspNgmXNr0vN0tFkjfFgAC2mykE5d9Bn4h3M4laT/gM2dpIZAgWAwesJjmVIXAJ3za6EbREyJesicEg/SlbzbbLIw1W+vKYwfQgCCxdGwv8qV1BIuVm4OihNf4akZz9A9K6SBOybnbSQACOAXmzN57VZ6d4CMJl8Vx1XU1YaPAktiMb83J2ahbfxPsEOy2amYjyg==",
    //The scope if you passed during initialization
    "X-Scope-Id": "your_scope_id",
    //The user input you passed in authenticate function encrypted with encryption key (aes key provided by you)
    "X-Encrypted-User": "JZVjZw33OGoQDEMcbOdckx4TzspQEKP5j+iAGqf6b6gPleziY/Noyd4uW6KMSujq0HKP2Rb69p9Wi8ic5O8LZl9oTmmWk4op0CUKejqcV5DsNDp83PYzUg=="
}

The address:

0xb3be8fcdc1f2b2fab67e9ecdf93b513a7a2500c1

Now with these setup, we can start to sign messages and transactions.

Last updated