diff --git a/src/ocean/DID.ts b/src/ocean/DID.ts index ef3d13f..ed5e99c 100644 --- a/src/ocean/DID.ts +++ b/src/ocean/DID.ts @@ -14,11 +14,10 @@ export default class DID { */ public static parse(didString: string): DID { let did: DID - if (didString.startsWith(prefix)) { - const id = didString.split(prefix)[1] - if (!id.startsWith("0x")) { - did = new DID(id) - } + const didMatch = didString.match(/^did:op:([a-f0-9]{64})$/i) + + if (didMatch) { + did = new DID(didMatch[1]) } if (!did) { diff --git a/test/ocean/DID.test.ts b/test/ocean/DID.test.ts index 9fb7bfa..75d98b1 100644 --- a/test/ocean/DID.test.ts +++ b/test/ocean/DID.test.ts @@ -13,7 +13,7 @@ describe("DID", () => { describe("#parse()", () => { it("should parse a valid did", () => { - const id = "1234" + const id = "a".repeat(64) const did: DID = DID.parse(`did:op:${id}`) assert(did) @@ -33,7 +33,7 @@ describe("DID", () => { it("should throw if id does not match", (done) => { - const id = "0x1234" + const id = "xyz" try { const did: DID = DID.parse(`did:op:${id}`) assert(!did) @@ -56,7 +56,7 @@ describe("DID", () => { describe("#getDid()", () => { it("should return only the id part of the did", () => { - const id = "1234" + const id = "a".repeat(64) const did: DID = DID.parse(`did:op:${id}`) assert(did)