Skip to content

Commit

Permalink
Show progress counter in sign-ext credential issuance signing dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
emlun committed Nov 26, 2024
1 parent 677c997 commit 4a61cb5
Showing 1 changed file with 65 additions and 58 deletions.
123 changes: 65 additions & 58 deletions src/services/LocalStorageKeystore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,64 +449,71 @@ export function useLocalStorageKeystore(): LocalStorageKeystore {
CommitCallback,
]> => (
await editPrivateData(async (originalContainer) => {
const moveUiStateMachine = webauthnInteractionCtx.setup(
t("Sign credential issuance"),
state => {
switch (state.id) {
case 'intro':
return {
bodyText: t('To proceed, please authenticate with your passkey.'),
buttons: {
continue: 'intro:ok',
},
};

case 'webauthn-begin':
return {
bodyText: t("Please interact with your authenticator..."),
};

case 'err':
return {
bodyText: t("An error occurred!"),
buttons: {
retry: true,
},
};

case 'err:ext:sign:signature-not-found':
return {
bodyText: t("An error occurred: Signature not found."),
buttons: {
retry: true,
},
};

case 'success':
return {
bodyText: t("Your credential has been issued successfully."),
buttons: {
continue: 'success:ok',
},
};

default:
throw new Error('Unknown WebAuthn interaction state:', { cause: state });
}
},
);

const { nonce, audience, issuer } = requests[0]; // the first row is enough since the nonce remains the same
const [{ proof_jwts }, newContainer] = await keystore.generateOpenid4vciProofs(
originalContainer,
config.DID_KEY_VERSION,
nonce,
audience,
issuer,
requests.length,
moveUiStateMachine,
);
return [{ proof_jwts }, newContainer];
let proof_jwts = [];
let container = originalContainer;

for (const { nonce, audience, issuer } of requests) {
const moveUiStateMachine = webauthnInteractionCtx.setup(
t("Sign credential issuance ({{currentNumber}} of {{totalNumber}})", { currentNumber: proof_jwts.length + 1, totalNumber: requests.length }),
state => {
switch (state.id) {
case 'intro':
return {
bodyText: t('To proceed, please authenticate with your passkey.'),
buttons: {
continue: 'intro:ok',
},
};

case 'webauthn-begin':
return {
bodyText: t("Please interact with your authenticator..."),
};

case 'err':
return {
bodyText: t("An error occurred!"),
buttons: {
retry: true,
},
};

case 'err:ext:sign:signature-not-found':
return {
bodyText: t("An error occurred: Signature not found."),
buttons: {
retry: true,
},
};

case 'success':
return {
bodyText: t("Your credential has been issued successfully."),
buttons: {
continue: 'success:ok',
},
};

default:
throw new Error('Unknown WebAuthn interaction state:', { cause: state });
}
},
);

const [{ proof_jwts: [proof_jwt] }, newContainer] = await keystore.generateOpenid4vciProofs(
originalContainer,
config.DID_KEY_VERSION,
nonce,
audience,
issuer,
1,
moveUiStateMachine,
);
proof_jwts.push(proof_jwt);
container = newContainer;
}

return [{ proof_jwts }, container];
})
),

Expand Down

0 comments on commit 4a61cb5

Please sign in to comment.