Skip to content

Commit

Permalink
refactor: removes explicit secrets and config vars from the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Elghareeb committed Jan 16, 2024
1 parent fda31ea commit a23458d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ISSUER_URL=
ISSUER_API_KEY=
VERIFIER_URL=
VERIFIER_API_KEY=
4 changes: 2 additions & 2 deletions components/Issuer/IndyWalletConnectionSetUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const invitationLink = ref('')
let WalletConnectionID: string|null = null
const generateQRCodeForConnection = () => {
createConnection(connectionUserName).then(({invitationURL, connectionID}) => {
createConnection(true).then(({invitationURL, connectionID}) => {
console.log(`invitation.....${invitationURL}`)
invitationLink.value = invitationURL
WalletConnectionID = connectionID
Expand All @@ -27,7 +27,7 @@ async function checkForAcceptedInvitation(): Promise<boolean|undefined> {
console.log("Invitation not accepted yet!")
return
}
return checkInvitationIsAccepted(WalletConnectionID).then((isAccepted) => {
return checkInvitationIsAccepted(WalletConnectionID, true).then((isAccepted) => {
if (isAccepted) {
console.log("Invitation accepted!")
emit('walletConnectionEstablished', WalletConnectionID)
Expand Down
75 changes: 45 additions & 30 deletions composables/IndyAPI.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
import axios from "axios";
import {type DiplomaSchema } from "~/composables/VerifiableCredential";
export async function createConnection (connectionUserName: string): Promise<{ invitationURL: string; connectionID: string}> {
console.log(`Creating connection...${connectionUserName}`);

export async function createConnection (isIssuer: boolean): Promise<{ invitationURL: string; connectionID: string}> {
let connectorName, connectionDomain, connectionAPIKey: string
if (isIssuer) {
connectorName = 'EPFL';
connectionDomain = process.env.ISSUER_URL;
connectionAPIKey = process.env.ISSUER_API_KEY;
} else {
connectorName = 'Leo Inc.';

This comment has been minimized.

Copy link
@ineiti

ineiti Jan 16, 2024

Member

:)

connectionDomain = process.env.VERIFIER_URL;
connectionDomain = process.env.VERIFIER_API_KEY;
}
const {data} = await axios.post(
'http://eid.c4dt.org:8000/connections/create-invitation?auto_accept=true',
`${connectionDomain}/connections/create-invitation?auto_accept=true`,
{
"my_label": "EPFL C4DT"
"my_label": connectorName
},
{
headers: {
'Content-Type': 'application/json',
'X-API-KEY': 'NVRGbAQdIPGBritg3TzDYhpAu'
'X-API-KEY': connectionAPIKey
}
})
console.log(data);
return {invitationURL: data.invitation_url, connectionID: data.connection_id};
}

export async function checkInvitationIsAccepted (connectionID: string, isIssuer: boolean): Promise<boolean> {
let connectionDomain, connectionAPIKey: string
if (isIssuer) {
connectionDomain = process.env.ISSUER_URL;
connectionAPIKey = process.env.ISSUER_API_KEY;
} else {
connectionDomain = process.env.VERIFIER_URL;
connectionDomain = process.env.VERIFIER_API_KEY;
}
console.log('Checking invitation is accepted...');
const {data} = await axios.get(
`${connectionDomain}/connections/${connectionID}`,
{
headers: {
'Content-Type': 'application/json',
'X-API-KEY': connectionAPIKey
}
})
return data.state === 'active';
}

export const GenerateVC = async (connectionID: string, credentialData: DiplomaSchema) => {
console.log('Generating Verifiable Credential...');
const {data} = await axios.post('http://eid.c4dt.org:8000/issue-credential/send', {
console.log('Generating Verifiable Credential');
const {data} = await axios.post(`${process.env.ISSUER_URL}/issue-credential/send`, {
"connection_id": connectionID,
"credential_proposal": {
"attributes": [
Expand Down Expand Up @@ -62,30 +92,17 @@ export const GenerateVC = async (connectionID: string, credentialData: DiplomaSc
{
headers: {
'Content-Type': 'application/json',
'X-API-KEY': 'NVRGbAQdIPGBritg3TzDYhpAu' // TODO: Move to .env

This comment has been minimized.

Copy link
@ineiti

ineiti Jan 16, 2024

Member

So this is not active anymore?

This comment has been minimized.

Copy link
@lanterno

lanterno Jan 16, 2024

Member

Yes, already killed this one.

'X-API-KEY': process.env.ISSUER_API_KEY
}
})
console.log(data);
return
}

export async function checkInvitationIsAccepted (connectionID: string): Promise<boolean> {
console.log('Checking invitation is accepted...');
const {data} = await axios.get(
`http://eid.c4dt.org:8000/connections/${connectionID}`,
{
headers: {
'Content-Type': 'application/json',
'X-API-KEY': 'NVRGbAQdIPGBritg3TzDYhpAu'
}
})
return data.state === 'active';
}

export async function sendProofRequest (connectionID: string, proofRequest: any): Promise<void> {
console.log('Sending proof request...');
export async function sendProofRequest (connectionID: string): Promise<void> {
console.log('Sending proof request');
const {data} = await axios.post(
'http://eid.c4dt.org:8000/present-proof/send-request',
`${process.env.VERIFIER_URL}/present-proof/send-request`,
{
"connection_id": connectionID,
"auto_remove": false,
Expand Down Expand Up @@ -117,7 +134,7 @@ export async function sendProofRequest (connectionID: string, proofRequest: any)
{
headers: {
'Content-Type': 'application/json',
'X-API-KEY': 'NVRGbAQdIPGBritg3TzDYhpAu'
'X-API-KEY': process.env.VERIFIER_API_KEY
}
})
return data
Expand All @@ -126,15 +143,13 @@ export async function sendProofRequest (connectionID: string, proofRequest: any)
export async function checkProofRequestIsAccepted (proofRequestID: string): Promise<boolean> {
console.log('Checking proof request is accepted...');
let {data} = await axios.get(
`http://eid.c4dt.org:8000/present-proof/records/${proofRequestID}`,
`${process.env.VERIFIER_URL}/present-proof/records/${proofRequestID}`,
{
headers: {
'Content-Type': 'application/json',
'X-API-KEY': 'NVRGbAQdIPGBritg3TzDYhpAu'
'X-API-KEY': process.env.VERIFIER_API_KEY
}
})
console.log("Printing data......");
console.log(data);
let accepted = data.state === 'verified';
if (accepted) {
data = {
Expand Down
4 changes: 3 additions & 1 deletion pages/issue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
const step = ref(Step.VC_FORM);
const CredentialData = ref({} as DiplomaSchema);
const connectionID = ref("");
function createCredentialData(createdCredential: DiplomaSchema) {
console.log(`createCredentialData..... ${createdCredential}`)
CredentialData.value = createdCredential;
step.value = Step.CONNECTION_SETUP;
}
function SendCredentialToWallet(walletConnectionID: string) {
console.log(`SendCredentialToWallet..... ${walletConnectionID}`)
connectionID.value = walletConnectionID
Expand All @@ -42,7 +44,7 @@
console.log(`GenerateVC..... ${res}`)
setTimeout(() => {
step.value = Step.DONE;
}, 4000)
}, 2000)
})
}
</script>
5 changes: 2 additions & 3 deletions pages/verify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import {ref} from "vue";
import QrcodeVue from "qrcode.vue";
import {checkInvitationIsAccepted, createConnection} from "~/composables/IndyAPI";
import type {DiplomaSchema} from "~/composables/VerifiableCredential";
enum Step {CONNECTION_SETUP, REQUESTING_CREDENTIALS, DONE}
const step = ref(Step.CONNECTION_SETUP);
Expand All @@ -31,7 +30,7 @@
const proofRequestDocumentNumber = ref("");
const generateQRCodeForConnection = () => {
createConnection("Verifier!").then(({invitationURL, connectionID}) => {
createConnection(false).then(({invitationURL, connectionID}) => {
console.log(`invitation.....${invitationURL}`)
invitationLink.value = invitationURL
WalletConnectionID.value = connectionID
Expand All @@ -47,7 +46,7 @@
console.log("Invitation not accepted yet!")
return
}
return checkInvitationIsAccepted(WalletConnectionID.value).then((isAccepted) => {
return checkInvitationIsAccepted(WalletConnectionID.value, false).then((isAccepted) => {
if (isAccepted) {
console.log("Invitation accepted!")
step.value = Step.REQUESTING_CREDENTIALS
Expand Down

0 comments on commit a23458d

Please sign in to comment.