passkey test #116
@@ -30,10 +30,6 @@ export interface JWK {
|
||||
x: string;
|
||||
y: string;
|
||||
}
|
||||
export interface PublicKeyCredential {
|
||||
rawId: Uint8Array;
|
||||
jwt: JWK;
|
||||
}
|
||||
|
||||
function toBase64Url(anythingB64: string) {
|
||||
return anythingB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
||||
@@ -76,6 +72,9 @@ export async function registerCredential(passkeyName?: string) {
|
||||
// https://chatgpt.com/share/3c13f061-6031-45bc-a2d7-3347c1e7a2d7
|
||||
|
||||
const credIdBase64Url = verification.registrationInfo?.credentialID as string;
|
||||
if (attResp.rawId !== credIdBase64Url) {
|
||||
console.log("Warning! The raw ID does not match the credential ID.")
|
||||
}
|
||||
const credIdHex = Buffer.from(
|
||||
base64URLStringToArrayBuffer(credIdBase64Url),
|
||||
).toString("hex");
|
||||
@@ -86,7 +85,6 @@ export async function registerCredential(passkeyName?: string) {
|
||||
return {
|
||||
authData: verification.registrationInfo?.attestationObject,
|
||||
credIdHex: credIdHex,
|
||||
rawId: new Uint8Array(new Buffer(attResp.rawId, "base64")),
|
||||
publicKeyJwk: publicKeyJwk,
|
||||
publicKeyBytes: verification.registrationInfo
|
||||
?.credentialPublicKey as Uint8Array,
|
||||
@@ -286,7 +284,6 @@ export class PeerSetup {
|
||||
// import { p256 } from "@noble/curves/p256";
|
||||
export async function verifyJwtP256(
|
||||
credIdHex: string,
|
||||
rawId: Uint8Array,
|
||||
did: string,
|
||||
authenticatorData: ArrayBuffer,
|
||||
challenge: Uint8Array,
|
||||
@@ -315,7 +312,6 @@ export async function verifyJwtP256(
|
||||
|
||||
export async function verifyJwtSimplewebauthn(
|
||||
credIdHex: string,
|
||||
rawId: Uint8Array,
|
||||
did: string,
|
||||
authenticatorData: ArrayBuffer,
|
||||
challenge: Uint8Array,
|
||||
@@ -340,7 +336,7 @@ export async function verifyJwtSimplewebauthn(
|
||||
authenticatorAttachment: "platform",
|
||||
clientExtensionResults: {},
|
||||
id: credId,
|
||||
rawId: arrayToBase64Url(rawId),
|
||||
rawId: credId,
|
||||
response: {
|
||||
authenticatorData: authData,
|
||||
clientDataJSON: clientDataJsonBase64Url,
|
||||
@@ -355,7 +351,6 @@ export async function verifyJwtSimplewebauthn(
|
||||
|
||||
export async function verifyJwtWebCrypto(
|
||||
credId: Base64URLString,
|
||||
rawId: Uint8Array,
|
||||
did: string,
|
||||
authenticatorData: ArrayBuffer,
|
||||
challenge: Uint8Array,
|
||||
|
||||
@@ -112,7 +112,7 @@ export default class IdentitySwitcherView extends Vue {
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
for (let n = 0; n < accounts.length; n++) {
|
||||
const did = JSON.parse(accounts[n].identity)["did"];
|
||||
const did = accounts[n]["did"];
|
||||
this.otherIdentities.push({ did: did });
|
||||
if (did && this.activeDid === did) {
|
||||
this.activeDidInIdentities = true;
|
||||
|
||||
@@ -200,7 +200,7 @@
|
||||
Navigator
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<div v-if="jwt">
|
||||
Verify
|
||||
<button
|
||||
@click="verifySimplewebauthn()"
|
||||
@@ -256,7 +256,6 @@ export default class Help extends Vue {
|
||||
activeDid?: string;
|
||||
jwt?: string;
|
||||
peerSetup?: PeerSetup;
|
||||
rawId?: Uint8Array;
|
||||
userName?: string;
|
||||
|
||||
async mounted() {
|
||||
@@ -312,7 +311,6 @@ export default class Help extends Vue {
|
||||
const publicKeyBytes = cred.publicKeyBytes;
|
||||
this.activeDid = createPeerDid(publicKeyBytes as Uint8Array);
|
||||
this.credIdHex = cred.credIdHex as string;
|
||||
this.rawId = cred.rawId as Uint8Array;
|
||||
|
||||
await accountsDB.open();
|
||||
await accountsDB.accounts.add({
|
||||
@@ -372,7 +370,6 @@ export default class Help extends Vue {
|
||||
public async verifyP256() {
|
||||
const decoded = await verifyJwtP256(
|
||||
this.credIdHex as Base64URLString,
|
||||
this.rawId as Uint8Array,
|
||||
this.activeDid as string,
|
||||
this.peerSetup.authenticatorData as ArrayBuffer,
|
||||
this.peerSetup.challenge as Uint8Array,
|
||||
@@ -385,7 +382,6 @@ export default class Help extends Vue {
|
||||
public async verifySimplewebauthn() {
|
||||
const decoded = await verifyJwtSimplewebauthn(
|
||||
this.credIdHex as Base64URLString,
|
||||
this.rawId as Uint8Array,
|
||||
this.activeDid as string,
|
||||
this.peerSetup.authenticatorData as ArrayBuffer,
|
||||
this.peerSetup.challenge as Uint8Array,
|
||||
@@ -398,7 +394,6 @@ export default class Help extends Vue {
|
||||
public async verifyWebCrypto() {
|
||||
const decoded = await verifyJwtWebCrypto(
|
||||
this.credIdHex as Base64URLString,
|
||||
this.rawId as Uint8Array,
|
||||
this.activeDid as string,
|
||||
this.peerSetup.authenticatorData as ArrayBuffer,
|
||||
this.peerSetup.challenge as Uint8Array,
|
||||
|
||||
Reference in New Issue
Block a user