-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from luputeodor2/recovery-code
PharmaLedger-IMI/epi-workspace#906 my-identities: you can copy your r…
- Loading branch information
Showing
8 changed files
with
233 additions
and
18 deletions.
There are no files selected for viewing
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
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
36 changes: 25 additions & 11 deletions
36
code/components/dw-dialog-waiting-approval/dw-dialog-waiting-approval.html
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 |
---|---|---|
@@ -1,15 +1,29 @@ | ||
<link rel="stylesheet" href="components/dw-dialog-waiting-approval/dw-dialog-waiting-approval.css"> | ||
<sl-dialog class="dw-dialog dw-dialog-waiting-approval" no-header> | ||
<header> | ||
<h3> | ||
<sl-icon name="person-bounding-box"></sl-icon> | ||
Waiting for administrator to grant access | ||
</h3> | ||
<sl-icon-button name="x-lg" close></sl-icon-button> | ||
</header> | ||
|
||
<sl-dialog class="dw-dialog dw-dialog-waiting-approval" no-header> | ||
<main> | ||
<h4>Copy this DID and give it to the right administrator.</h4> | ||
<dw-clipboard-input value="@did" readonly></dw-clipboard-input> | ||
<div id="did-div"> | ||
<h3> | ||
<sl-icon name="person-bounding-box"></sl-icon> | ||
Waiting for administrator to grant access | ||
</h3> | ||
<br> | ||
<h4>Copy this DID and give it to the right administrator.</h4> | ||
<dw-clipboard-input value="@did" readonly></dw-clipboard-input> | ||
</div> | ||
<webc-container controller="DwDialogWaitingApprovalController" id="recovery-code-div"> | ||
<h3> | ||
<sl-icon name="clipboard-check"></sl-icon> | ||
Or go ahead and | ||
</h3> | ||
<br> | ||
<h4>Paste your recovery code here to gain access.</h4> | ||
<sl-input name="recovery-code" placeholder="recovery code" id="add-member-input" type="password" required clearable> | ||
<sl-button slot="suffix" type="text" data-tag="paste-from-clipboard" class="dw-paste"> | ||
Paste | ||
</sl-button> | ||
<sl-icon slot="suffix" name="arrow-right-short" data-tag="continue"></sl-icon> | ||
</sl-input> | ||
</webc-container> | ||
</main> | ||
</sl-dialog> | ||
</sl-dialog> |
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
81 changes: 81 additions & 0 deletions
81
code/scripts/controllers/DwDialogWaitingApprovalController.js
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,81 @@ | ||
import {DwUI} from "./DwController.js"; | ||
|
||
const {DwController} = WebCardinal.controllers; | ||
|
||
export default class DwDialogWaitingApprovalController extends DwController { | ||
constructor(...props) { | ||
super(...props); | ||
|
||
this.showToast = new DwUI().showToast; | ||
this.tagClickListeners(); | ||
} | ||
|
||
tagClickListeners() { | ||
this.onTagClick("paste-from-clipboard", () => { | ||
navigator.clipboard.readText() | ||
.then((clipText) => (document.getElementById("add-member-input").value = clipText)) | ||
.catch(err => console.log(err)); | ||
}); | ||
this.onTagClick("continue", async () => { | ||
if (document.getElementById("add-member-input").value === "") { | ||
await this.showToast(`Please insert a recovery code.`); | ||
return; | ||
} | ||
this.setSharedEnclaveKeySSI().then( | ||
() => { | ||
this.getSharedEnclaveKeySSI().then( | ||
() => { | ||
this.ui.enableMenu(); | ||
this.navigateToPageTag("quick-actions"); | ||
} | ||
).catch(async err => { | ||
this.model.notAuthorized = true; | ||
console.log("sharedEnclave doesn't have a defined KeySSI. " + err); | ||
await this.showToast(`Recovery code is not valid.`); | ||
}) | ||
} | ||
).catch(async err => { | ||
await this.showToast(`Recovery code is not valid.`); | ||
}); | ||
}); | ||
} | ||
|
||
async setSharedEnclaveKeySSI() { | ||
return new Promise((resolve, reject) => { | ||
const openDSU = require("opendsu"); | ||
const scAPI = openDSU.loadAPI("sc"); | ||
const keySSI = openDSU.loadAPI("keyssi"); | ||
const enclaveAPI = openDSU.loadAPI("enclave"); | ||
const recoveryCode = document.getElementById("add-member-input").value; | ||
|
||
try { | ||
keySSI.parse(recoveryCode); // parse and check if the recoveryCode has the right format for a sharedEnclaveKeySSI | ||
} catch (err) { | ||
return reject(err); | ||
} | ||
|
||
const sharedEnclave = enclaveAPI.initialiseWalletDBEnclave(recoveryCode); | ||
sharedEnclave.on("initialised", async () => { | ||
try { | ||
await $$.promisify(scAPI.setSharedEnclave)(sharedEnclave); | ||
resolve(); | ||
} catch (e) { | ||
reject("Failed to set shared enclave."); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
async getSharedEnclaveKeySSI() { | ||
const openDSU = require("opendsu"); | ||
const scAPI = openDSU.loadAPI("sc"); | ||
|
||
let sharedEnclave; | ||
try { | ||
sharedEnclave = await $$.promisify(scAPI.getSharedEnclave)(); | ||
} catch (e) { | ||
console.log("Failed to get shared enclave " + e); | ||
} | ||
return sharedEnclave.getKeySSIAsync(); | ||
} | ||
} |
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