Skip to content

Commit

Permalink
feat(ref-imp): #781 - fix test net did parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacJChen committed Sep 22, 2020
1 parent 2f73838 commit 9920999
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/core/versions/latest/Did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ export default class Did {
private constructor (did: string, didMethodName: string) {
this.didMethodName = didMethodName;
const didPrefix = `did:${didMethodName}:`;
// TODO https://github.com/decentralized-identity/sidetree/issues/470 add network prefix to the didPrefix string

if (!did.startsWith(didPrefix)) {
throw new SidetreeError(ErrorCode.DidIncorrectPrefix);
}

// split by : and ?, if there are 3 elements, then it's short form. Long form has 4 elements
const didWithoutPrefix = did.split(didPrefix)[1];

// split by : and ?, if there are 1 elements, then it's short form. Long form has 2 elements
// when the ? format is deprecated, `:` will be the only seperator.
const didSplitLength = did.split(/:|\?/).length;
if (didSplitLength === 3) {
const didSplitLength = didWithoutPrefix.split(/:|\?/).length;
if (didSplitLength === 1) {
this.isShortForm = true;
} else {
this.isShortForm = false;
Expand Down

0 comments on commit 9920999

Please sign in to comment.