-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a new screen for allowing verifiable credentials. A couple of notes: * This only includes the screen, not the actual flow. * The screen currently does not process markdown; this will be done separately.
- Loading branch information
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/frontend/src/flows/verifiableCredentials/allowCredentials.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"en": { | ||
"title": "Credential Access Request", | ||
"allow_start": "Allow verifying credential", | ||
"allow_sep_with": "with", | ||
"cancel": "Cancel", | ||
"allow": "Allow" | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
src/frontend/src/flows/verifiableCredentials/allowCredentials.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { mkAnchorInput } from "$src/components/anchorInput"; | ||
import { mainWindow } from "$src/components/mainWindow"; | ||
import { I18n } from "$src/i18n"; | ||
import { mount, renderPage } from "$src/utils/lit-html"; | ||
import { TemplateResult, html } from "lit-html"; | ||
|
||
import copyJson from "./allowCredentials.json"; | ||
|
||
/* A screen prompting the user to allow (or cancel) issuing verified | ||
* credentials */ | ||
|
||
const allowCredentialsTemplate = ({ | ||
i18n, | ||
relyingOrigin, | ||
providerOrigin, | ||
consentMessage, | ||
userNumber, | ||
onAllow, | ||
onCancel, | ||
scrollToTop = false, | ||
}: { | ||
i18n: I18n; | ||
relyingOrigin: string; | ||
providerOrigin: string; | ||
consentMessage: string; | ||
userNumber?: bigint; | ||
onAllow: (userNumber: bigint) => void; | ||
onCancel: () => void; | ||
/* put the page into view */ | ||
scrollToTop?: boolean; | ||
}): TemplateResult => { | ||
const copy = i18n.i18n(copyJson); | ||
const anchorInput = mkAnchorInput({ | ||
userNumber, | ||
onSubmit: (userNumber) => onAllow(userNumber), | ||
}); | ||
|
||
const slot = html` | ||
<hgroup | ||
data-page="vc-allow" | ||
${scrollToTop ? mount(() => window.scrollTo(0, 0)) : undefined} | ||
> | ||
<h1 class="t-title t-title--main">${copy.title}</h1> | ||
</hgroup> | ||
${anchorInput.template} | ||
<p class="t-paragraph"> | ||
${copy.allow_start} | ||
<strong class="t-strong">${providerOrigin}</strong> ${copy.allow_sep_with} | ||
<strong class="t-strong">${relyingOrigin}</strong>? | ||
</p> | ||
<div class="l-stack c-input c-input--readonly"> | ||
<pre class="c-consent-message">${consentMessage}</pre> | ||
</div> | ||
<div class="c-button-group"> | ||
<button | ||
data-action="cancel" | ||
class="c-button c-button--secondary" | ||
@click="${() => onCancel()}" | ||
> | ||
${copy.cancel} | ||
</button> | ||
<button | ||
data-action="allow" | ||
class="c-button" | ||
@click="${() => anchorInput.submit()}" | ||
> | ||
${copy.allow} | ||
</button> | ||
</div> | ||
`; | ||
|
||
return mainWindow({ | ||
showFooter: false, | ||
showLogo: false, | ||
slot, | ||
}); | ||
}; | ||
|
||
export const allowCredentialsPage = renderPage(allowCredentialsTemplate); | ||
|
||
// Prompt to allow verifying credentials | ||
export const allowCredentials = ({ | ||
relyingOrigin, | ||
providerOrigin, | ||
consentMessage, | ||
userNumber, | ||
}: { | ||
relyingOrigin: string; | ||
providerOrigin: string; | ||
consentMessage: string; | ||
userNumber?: bigint; | ||
}): Promise<{ tag: "allowed"; userNumber: bigint } | { tag: "canceled" }> => { | ||
return new Promise((resolve) => | ||
allowCredentialsPage({ | ||
i18n: new I18n(), | ||
relyingOrigin, | ||
providerOrigin, | ||
consentMessage, | ||
userNumber, | ||
onAllow: (userNumber) => resolve({ tag: "allowed", userNumber }), | ||
onCancel: () => resolve({ tag: "canceled" }), | ||
scrollToTop: true, | ||
}) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters