Browse Source

allow switching to did:peer ID, remove another unnecessary data point

pull/116/head
Trent Larson 5 months ago
parent
commit
122872f4bf
  1. 13
      src/libs/didPeer.ts
  2. 2
      src/views/IdentitySwitcherView.vue
  3. 7
      src/views/TestView.vue

13
src/libs/didPeer.ts

@ -30,10 +30,6 @@ export interface JWK {
x: string; x: string;
y: string; y: string;
} }
export interface PublicKeyCredential {
rawId: Uint8Array;
jwt: JWK;
}
function toBase64Url(anythingB64: string) { function toBase64Url(anythingB64: string) {
return anythingB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); 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 // https://chatgpt.com/share/3c13f061-6031-45bc-a2d7-3347c1e7a2d7
const credIdBase64Url = verification.registrationInfo?.credentialID as string; 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( const credIdHex = Buffer.from(
base64URLStringToArrayBuffer(credIdBase64Url), base64URLStringToArrayBuffer(credIdBase64Url),
).toString("hex"); ).toString("hex");
@ -86,7 +85,6 @@ export async function registerCredential(passkeyName?: string) {
return { return {
authData: verification.registrationInfo?.attestationObject, authData: verification.registrationInfo?.attestationObject,
credIdHex: credIdHex, credIdHex: credIdHex,
rawId: new Uint8Array(new Buffer(attResp.rawId, "base64")),
publicKeyJwk: publicKeyJwk, publicKeyJwk: publicKeyJwk,
publicKeyBytes: verification.registrationInfo publicKeyBytes: verification.registrationInfo
?.credentialPublicKey as Uint8Array, ?.credentialPublicKey as Uint8Array,
@ -286,7 +284,6 @@ export class PeerSetup {
// import { p256 } from "@noble/curves/p256"; // import { p256 } from "@noble/curves/p256";
export async function verifyJwtP256( export async function verifyJwtP256(
credIdHex: string, credIdHex: string,
rawId: Uint8Array,
did: string, did: string,
authenticatorData: ArrayBuffer, authenticatorData: ArrayBuffer,
challenge: Uint8Array, challenge: Uint8Array,
@ -315,7 +312,6 @@ export async function verifyJwtP256(
export async function verifyJwtSimplewebauthn( export async function verifyJwtSimplewebauthn(
credIdHex: string, credIdHex: string,
rawId: Uint8Array,
did: string, did: string,
authenticatorData: ArrayBuffer, authenticatorData: ArrayBuffer,
challenge: Uint8Array, challenge: Uint8Array,
@ -340,7 +336,7 @@ export async function verifyJwtSimplewebauthn(
authenticatorAttachment: "platform", authenticatorAttachment: "platform",
clientExtensionResults: {}, clientExtensionResults: {},
id: credId, id: credId,
rawId: arrayToBase64Url(rawId), rawId: credId,
response: { response: {
authenticatorData: authData, authenticatorData: authData,
clientDataJSON: clientDataJsonBase64Url, clientDataJSON: clientDataJsonBase64Url,
@ -355,7 +351,6 @@ export async function verifyJwtSimplewebauthn(
export async function verifyJwtWebCrypto( export async function verifyJwtWebCrypto(
credId: Base64URLString, credId: Base64URLString,
rawId: Uint8Array,
did: string, did: string,
authenticatorData: ArrayBuffer, authenticatorData: ArrayBuffer,
challenge: Uint8Array, challenge: Uint8Array,

2
src/views/IdentitySwitcherView.vue

@ -112,7 +112,7 @@ export default class IdentitySwitcherView extends Vue {
await accountsDB.open(); await accountsDB.open();
const accounts = await accountsDB.accounts.toArray(); const accounts = await accountsDB.accounts.toArray();
for (let n = 0; n < accounts.length; n++) { 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 }); this.otherIdentities.push({ did: did });
if (did && this.activeDid === did) { if (did && this.activeDid === did) {
this.activeDidInIdentities = true; this.activeDidInIdentities = true;

7
src/views/TestView.vue

@ -200,7 +200,7 @@
Navigator Navigator
</button> </button>
</div> </div>
<div> <div v-if="jwt">
Verify Verify
<button <button
@click="verifySimplewebauthn()" @click="verifySimplewebauthn()"
@ -256,7 +256,6 @@ export default class Help extends Vue {
activeDid?: string; activeDid?: string;
jwt?: string; jwt?: string;
peerSetup?: PeerSetup; peerSetup?: PeerSetup;
rawId?: Uint8Array;
userName?: string; userName?: string;
async mounted() { async mounted() {
@ -312,7 +311,6 @@ export default class Help extends Vue {
const publicKeyBytes = cred.publicKeyBytes; const publicKeyBytes = cred.publicKeyBytes;
this.activeDid = createPeerDid(publicKeyBytes as Uint8Array); this.activeDid = createPeerDid(publicKeyBytes as Uint8Array);
this.credIdHex = cred.credIdHex as string; this.credIdHex = cred.credIdHex as string;
this.rawId = cred.rawId as Uint8Array;
await accountsDB.open(); await accountsDB.open();
await accountsDB.accounts.add({ await accountsDB.accounts.add({
@ -372,7 +370,6 @@ export default class Help extends Vue {
public async verifyP256() { public async verifyP256() {
const decoded = await verifyJwtP256( const decoded = await verifyJwtP256(
this.credIdHex as Base64URLString, this.credIdHex as Base64URLString,
this.rawId as Uint8Array,
this.activeDid as string, this.activeDid as string,
this.peerSetup.authenticatorData as ArrayBuffer, this.peerSetup.authenticatorData as ArrayBuffer,
this.peerSetup.challenge as Uint8Array, this.peerSetup.challenge as Uint8Array,
@ -385,7 +382,6 @@ export default class Help extends Vue {
public async verifySimplewebauthn() { public async verifySimplewebauthn() {
const decoded = await verifyJwtSimplewebauthn( const decoded = await verifyJwtSimplewebauthn(
this.credIdHex as Base64URLString, this.credIdHex as Base64URLString,
this.rawId as Uint8Array,
this.activeDid as string, this.activeDid as string,
this.peerSetup.authenticatorData as ArrayBuffer, this.peerSetup.authenticatorData as ArrayBuffer,
this.peerSetup.challenge as Uint8Array, this.peerSetup.challenge as Uint8Array,
@ -398,7 +394,6 @@ export default class Help extends Vue {
public async verifyWebCrypto() { public async verifyWebCrypto() {
const decoded = await verifyJwtWebCrypto( const decoded = await verifyJwtWebCrypto(
this.credIdHex as Base64URLString, this.credIdHex as Base64URLString,
this.rawId as Uint8Array,
this.activeDid as string, this.activeDid as string,
this.peerSetup.authenticatorData as ArrayBuffer, this.peerSetup.authenticatorData as ArrayBuffer,
this.peerSetup.challenge as Uint8Array, this.peerSetup.challenge as Uint8Array,

Loading…
Cancel
Save