package forms import "github.com/onsonr/sonr/pkg/blocks/cards" type RegisterPasskeyData struct { Address string Handle string Name string Challenge string CreationBlock string } templ RegisterPasskey(action, method string, data RegisterPasskeyData) {
@cards.SonrProfile(data.Address, data.Name, data.Handle, data.CreationBlock)
@passkeyDropzone(data.Address, data.Handle, data.Challenge)
Register Vault
} templ passkeyDropzone(addr string, userHandle string, challenge string) {
Link a passkey to your vault
} script createPasskey(userId string, userHandle string, challenge string) { const publicKey = { challenge: Uint8Array.from(challenge, (c) => c.charCodeAt(0)), rp: { name: "Sonr.ID", }, user: { // Assuming that userId is ASCII-only id: Uint8Array.from(userId, (c) => c.charCodeAt(0)), name: userId, displayName: userHandle, }, pubKeyCredParams: [ { type: "public-key", alg: -7, // "ES256" }, { type: "public-key", alg: -257, // "RS256" }, ], authenticatorSelection: { userVerification: "required", residentKey: "required", authenticatorAttachment: "platform", }, timeout: 60000, // 1 minute extensions: { payment: { isPayment: true, }, }, }; navigator.credentials .create({ publicKey }) .then((newCredentialInfo) => { console.log(newCredentialInfo); // Send new credential info to server for verification and registration. }) .catch((err) => { console.error(err); // No acceptable authenticator or user refused consent. Handle appropriately. }); }