1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Merge pull request #116 from oceanprotocol/feature/improve-did

Better DID validation.
This commit is contained in:
Pedro Gutiérrez 2019-01-23 12:53:33 +01:00 committed by GitHub
commit 063c294b64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 16 deletions

View File

@ -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) {

View File

@ -1,4 +1,4 @@
import deprecated from 'deprecated-decorator';
import deprecated from "deprecated-decorator"
import AquariusProvider from "../aquarius/AquariusProvider"
import SearchQuery from "../aquarius/query/SearchQuery"
@ -82,9 +82,9 @@ export default class Ocean {
* @param {string} did Decentralized ID.
* @return {Promise<DDO>}
*/
@deprecated('resolveAssetDID')
@deprecated("resolveAssetDID")
public async resolveDID(did: string): Promise<DDO> {
return await this.resolveAssetDID(did);
return await this.resolveAssetDID(did)
}
/**
@ -203,13 +203,13 @@ export default class Ocean {
* @return {Promise<any>}
*
*/
@deprecated('purchaseAssetService')
@deprecated("purchaseAssetService")
public async signServiceAgreement(
did: string,
serviceDefinitionId: string,
consumer: Account,
): Promise<any> {
return await this.purchaseAssetService(did, serviceDefinitionId, consumer);
return await this.purchaseAssetService(did, serviceDefinitionId, consumer)
}
/**
@ -369,7 +369,6 @@ export default class Ocean {
return AquariusProvider.getAquarius().queryMetadata(query)
}
/**
* Search over the assets using a keyword.
* @param {SearchQuery} text Text to filter the assets.

View File

@ -1,4 +1,4 @@
import fetch, { Response, RequestInit, BodyInit } from "node-fetch"
import fetch, { BodyInit, RequestInit, Response } from "node-fetch"
/**
* Provides a common interface to web services.

View File

@ -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)