Skip to content

Commit

Permalink
Merge pull request #8 from hypersign-protocol/v3.0
Browse files Browse the repository at this point in the history
V3.0
  • Loading branch information
Vishwas1 authored Jul 30, 2021
2 parents 6aea227 + 5186cd5 commit 563c3bf
Show file tree
Hide file tree
Showing 15 changed files with 611 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/node_modules
/web-server/node_modules
/web-server/public
/*.log
/dist
/dist-zip
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"build:Testnet": "cross-env NETWORK=Testnet npm run build",
"watch:dev:Testnet": "cross-env NETWORK=Testnet npm run watch:dev",
"watch:dev:tests": "cross-env NETWORK=Testnet RUNNING_IN_TESTS=true npm run watch:dev",
"build:tests": "cross-env NETWORK=Testnet RUNNING_IN_TESTS=true npm run build:dev"
"build:tests": "cross-env NETWORK=Testnet RUNNING_IN_TESTS=true npm run build:dev",
"webserver": "cp -R dist/web/root/* web-server/public/ && node web-server/index.js"
},
"dependencies": {
"@aeternity/aepp-components": "git+https://github.com/aeternity/aepp-components.git#develop",
Expand Down
30 changes: 26 additions & 4 deletions src/mixins/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default {
this.ifEdit = false;
this.ifCreate = true;
},
async setupProfile() {
async setupProfile(isThridPartyAuth = false) {
// try {
// this.loading = true;
//// HS_TODO::
Expand All @@ -52,22 +52,44 @@ export default {
const HS_STUDIO_REGISTER_URL = `${SUPERHERO_HS_AUTH_BASE_URL}${SUPERHERO_HS_AUTH_CREDENTIAL_ISSUE_API}`

const body = {
name: this.profile.name,
email: this.profile.email
user: {
name: this.profile.name,
email: this.profile.email
},
isThridPartyAuth: false
}

if(isThridPartyAuth){
body["user"]["did"] = this.profile.did;
body["isThridPartyAuth"] = true;
}

// console.log("Calling authserver register")

let res = await axios.post(HS_STUDIO_REGISTER_URL, body);

if (!res) throw new Error("Could not register the user");
// console.log("After getting response")
res = res.data;
// console.log(res)
// console.log(res.message)
if (res && res.status != 200) throw new Error(res.error);


// console.log(typeof(res.message))
// console.log(res.message)
if(isThridPartyAuth && res && res.message){
// console.log("Before setting 3rdPartyAuthVC");
// only in case of 3rd party auth, verifiable credenital will come
localStorage.setItem("3rdPartyAuthVC", JSON.stringify(res.message));
}

this.$store.commit('addHSProfile', this.profile);
this.ifEdit = true;
this.ifCreate = false;
this.ifAllDisabled = true;

return true;
return true;
},
},
};
41 changes: 31 additions & 10 deletions src/popup/router/pages/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ export default {
},
async created() {
try {
const vcStr = localStorage.getItem("3rdPartyAuthVC");
if(vcStr){
// console.log("vcStr is present");
const vc = JSON.parse(vcStr);
// console.log("Able to parse vcStr")
if(vc){
// console.log("Vc is not null");
// console.log("Calling credentialsQRData()");
this.credentialsQRData(vc);
}
}
// put it somewhere eles other whise it wont work... like somewhere when the app loads
if (!this.hypersign.hsAuthDID) {
const res = await axios.get(HS_AUTH_DID_URL);
Expand All @@ -94,18 +107,23 @@ export default {
} else {
this.hsAuthDid = this.hypersign.hsAuthDID;
}
localStorage.setItem("isMobileWallet", false)
//Only for deeplinking
if (this.$route.query.url && this.$route.query.url != '') {
const JSONData = decodeURI(this.$route.query.url);
this.receiveOrGiveCredential(JSONData);
}
} catch (e) {
if (e.message) this.$store.dispatch('modals/open', { name: 'default', msg: e.message });
}
},
methods: {
async scan() {
localStorage.setItem("isMobileWallet", true)
const QRData = await this.$store.dispatch('modals/open', {
name: 'read-qr-code',
title: this.$t('pages.credential.scan'),
Expand All @@ -122,7 +140,9 @@ export default {
// console.log(data);
switch(data.QRType){
case 'ISSUE_CRED': {
this.credentialsQRData(data.url);
this.credentialUrl = data.url;
let cred = await this.fetchCredential();
this.credentialsQRData(cred);
break;
}
case 'REQUEST_CRED': {
Expand All @@ -141,6 +161,9 @@ export default {
},
async fetchCredential() {
if(!this.credentialUrl){
throw new Error("Credential Url is null or empty");
}
this.credentialUrl = this.credentialUrl + '&did=' + this.hypersign.did;
this.loading = true;
let response = await axios.get(this.credentialUrl);
Expand All @@ -154,19 +177,18 @@ export default {
return response.message;
},
async credentialsQRData(data) {
async credentialsQRData(cred) {
try {
this.credentialUrl = data;
let cred = await this.fetchCredential();
if(!cred){
throw new Error('Credential can not be null or empty');
}
// TODO: Check if this credential already exsits in wallet: otherwise reject
const credInWallet = this.hypersign.credentials.find((x) => x.id == cred.id);
if (credInWallet) {
throw new Error('The credential already exist in your wallet');
}
// console.log(1)
// console.log({
// hs_app_did: this.hypersign.did,
// credentialSubjectDid: cred.credentialSubject.id
Expand All @@ -175,12 +197,11 @@ export default {
// TODO: Check if you are the owner of this credenital: otherwise reject
if (this.hypersign.did != cred.credentialSubject.id) {
throw new Error('The credential is not issued to you');
}
// console.log(2)
}
this.$store.commit('addHSVerifiableCredentialTemp', cred);
this.$router.push(`/credential/temp/${cred.id}`);
localStorage.removeItem("3rdPartyAuthVC");
} catch (e) {
console.log(e);
this.loading = false;
Expand Down
36 changes: 36 additions & 0 deletions src/popup/router/pages/Auth.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>

<div class="auth">
sdfnkjsdfn
</div>
</template>

<script>
export default {
name: 'Auth',
components: {},
mounted(){
const routeHash = this.$route.hash;
const accessToken = routeHash.split("&")[0].split("=")[1];
const authToken = routeHash.split("&")[5].split("=")[1];
localStorage.setItem("accessToken", accessToken)
localStorage.setItem("authToken", authToken)
this.$router.push({path: "/", params: {
authToken: authToken, accessToken: accessToken
}})
}
};
</script>

<style>
</style>
16 changes: 13 additions & 3 deletions src/popup/router/pages/CredentialsDetailsAuthorize.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,22 @@ export default {
if(response.status == 401 || response.status == 403) {
throw new Error('Could not authorize the user')
}else if(response.status == 200){
if (response.message)
await this.$store.dispatch('modals/open', {
const isMobileWallet = JSON.parse(localStorage.getItem("isMobileWallet"));
if (response.message){
if(!isMobileWallet){
return window.close()
}
await this.$store.dispatch('modals/open', {
name: 'default',
msg: 'Credential successfully verified',
});
this.reject()
this.reject()
}
}else {
throw new Error(response.error)
}
Expand Down
Loading

0 comments on commit 563c3bf

Please sign in to comment.