Browse Source

add check for valid "did:" DIDs

starred-projects
Trent Larson 10 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
const HIDDEN_DID = "did:none:HIDDEN";
export function isDid(did: string) {
return did.startsWith("did:");
}
export function isHiddenDid(did: string) {
return did === HIDDEN_DID;
}

17
src/views/ContactsView.vue

@ -44,14 +44,14 @@
<div class="w-full text-right">
Hours to Add:
<input
class="border border rounded border-slate-400 w-24 text-right"
class="border rounded border-slate-400 w-24 text-right"
type="text"
placeholder="1"
v-model="hourInput"
/>
<br />
<input
class="border border rounded border-slate-400 w-48"
class="border rounded border-slate-400 w-48"
type="text"
placeholder="Description"
v-model="hourDescriptionInput"
@ -303,6 +303,7 @@ import {
CONTACT_URL_PREFIX,
GiveServerRecord,
GiveVerifiableCredential,
isDid,
RegisterVerifiableCredential,
SERVICE_ID,
} from "@/libs/endorserServer";
@ -697,6 +698,18 @@ export default class ContactsView extends Vue {
);
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
return db.contacts
.add(newContact)

2
src/views/StartView.vue

@ -38,7 +38,7 @@
@click="onClickYes()"
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
@click="onClickNo()"

Loading…
Cancel
Save