Browser Passkeys

Initialize the Halliday SDK via Browser Passkeys

To get started with our SDK using our browser passkey log-in flow, first install halliday-sdk:

npm install halliday-sdk

or

yarn add halliday-sdk

The following example shows how to leverage browser passkeys with our SDK to access your Halliday Smart Account:

import {HallidayViaPasskey, BlockchainType} from "halliday-sdk";

// Initialize the Halliday client.
const hallidayClient = new HallidayViaPasskey({
  hallidayPublicApiKey: "API_KEY",          // Provided to you by the Halliday team
  gameName: "Demo Game Name",               // Your application's name, mainly for display purposes when passkey prompt comes to user
  domain: "localhost",                      // Your domain, to register the passkey with (localhost for local testing)
  blockchainType: BlockchainType.MUMBAI,    // Optional argument - defaults to Mumbai
  sandbox: true                             // Optional argument - defaults to false. If true, the SDK will interact with our test environment.
});

In your registration flow, prompt a new user for a passkey and use the passkey to connect your user to Halliday. The passkeyName (along with gameName in the constructor) is for display purposes when prompting the user for a passkey. The passkeyName can be the user's username or any identifier for display purposes.

const passkeyName = "Demo Username";

async function onClickRegisterButton(passkeyName) {
  await hallidayClient.registerUser(passkeyName);
}

In your login flow, prompt a returning user to choose a previously stored passkey to connect your user to Halliday. Passkeys will be labeled based on the gameName entered in the constructor and the passkeyName entered with the registerUser() function.

async function onClickLoginButton() {
  await hallidayClient.login();
}

Once the user has registered or logged in with browser passkeys, they can access their Halliday Smart Account as demonstrated below:

// To get or create the Halliday Smart Account, call getOrCreateHallidayAAWallet. 
// This will get the user's smart account for the blockchain you specified in the constructor.
const userInGameId = "user_in_game_id";           // The user's id in your application. Must be unique for each user.
const hallidayAccount = await hallidayClient.getOrCreateHallidayAAWallet(
  userInGameId,					
  "[email protected]"
);
const hallidayAccountAddress = hallidayAccount.account_address;