Browse Source

add check for valid "did:" DIDs

starred-projects
Trent Larson 9 months ago
parent
commit
331c4f64d6
  1. 4
      src/libs/endorserServer.ts
  2. 17
      src/views/ContactsView.vue
  3. 2
      src/views/StartView.vue

4
src/libs/endorserServer.ts

@ -241,6 +241,10 @@ export type CreateAndSubmitClaimResult = SuccessResult | ErrorResult;
// See https://github.com/trentlarson/endorser-ch/blob/0cb626f803028e7d9c67f095858a9fc8542e3dbd/server/api/services/util.js#L6 // See https://github.com/trentlarson/endorser-ch/blob/0cb626f803028e7d9c67f095858a9fc8542e3dbd/server/api/services/util.js#L6
const HIDDEN_DID = "did:none:HIDDEN"; const HIDDEN_DID = "did:none:HIDDEN";
export function isDid(did: string) {
return did.startsWith("did:");
}
export function isHiddenDid(did: string) { export function isHiddenDid(did: string) {
return did === HIDDEN_DID; return did === HIDDEN_DID;
} }

17
src/views/ContactsView.vue

@ -44,14 +44,14 @@
<div class="w-full text-right"> <div class="w-full text-right">
Hours to Add: Hours to Add:
<input <input
class="border border rounded border-slate-400 w-24 text-right" class="border rounded border-slate-400 w-24 text-right"
type="text" type="text"
placeholder="1" placeholder="1"
v-model="hourInput" v-model="hourInput"
/> />
<br /> <br />
<input <input
class="border border rounded border-slate-400 w-48" class="border rounded border-slate-400 w-48"
type="text" type="text"
placeholder="Description" placeholder="Description"
v-model="hourDescriptionInput" v-model="hourDescriptionInput"
@ -303,6 +303,7 @@ import {
CONTACT_URL_PREFIX, CONTACT_URL_PREFIX,
GiveServerRecord, GiveServerRecord,
GiveVerifiableCredential, GiveVerifiableCredential,
isDid,
RegisterVerifiableCredential, RegisterVerifiableCredential,
SERVICE_ID, SERVICE_ID,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
@ -697,6 +698,18 @@ export default class ContactsView extends Vue {
); );
return; return;
} }
if (!isDid(newContact.did)) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Invalid DID",
text: "The DID is not valid. It must begin with 'did:'",
},
-1,
);
return;
}
newContact.seesMe = true; // since we will immediately set that on the server newContact.seesMe = true; // since we will immediately set that on the server
return db.contacts return db.contacts
.add(newContact) .add(newContact)

2
src/views/StartView.vue

@ -38,7 +38,7 @@
@click="onClickYes()" @click="onClickYes()"
class="block w-full text-center text-lg uppercase bg-blue-600 text-white px-2 py-3 rounded-md" class="block w-full text-center text-lg uppercase bg-blue-600 text-white px-2 py-3 rounded-md"
> >
Yes Yes, generate one
</a> </a>
<a <a
@click="onClickNo()" @click="onClickNo()"

Loading…
Cancel
Save