Skip to main content

Create a User with a Passkey Credential

1. Initialize the Passkey Client

import { Turnkey } from "@turnkey/sdk-browser";

const turnkey = new Turnkey({
apiBaseUrl: "https://api.turnkey.com",
defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID,
});
const passkeyClient = turnkey.passkeyClient();

2. Create a Local Passkey Credential

This will prompt a user natively in their browser to create a passkey.

const credential = await passkeyClient.createUserPasskey({
publicKey: {
user: {
name: <userName>,
displayName: <userDisplayName>
}
}
})

3. Configure the SubOrganization for the User

import { DEFAULT_ETHEREUM_ACCOUNTS } from "@turnkey/sdk-browser";

const subOrganizationConfig = {
subOrganizationName: <subOrganizationName>,
rootUsers: [{
userName: <userName>,
userEmail: <userEmail>,
apiKeys: [],
authenticators: [
{
authenticatorName: <authenticatorName>,
challenge: credential.challenge,
attestation: credential.attestation
}
],
oauthProviders: []
}],
rootQuorumThreshold: 1,
wallet: {
walletName: <initialWalletName>,
accounts: DEFAULT_ETHEREUM_ACCOUNTS
}
}

4. Call createSubOrganization from your backend

await turnkey.serverSign("createSubOrganization", [subOrganizationConfig]);