diff --git a/src/DIDResolver.ts b/src/DIDResolver.ts new file mode 100644 index 0000000..4011b4d --- /dev/null +++ b/src/DIDResolver.ts @@ -0,0 +1,49 @@ +/* + +DIDResolver module to resolve Ocean DID's off the block chain + +*/ + +import DIDRegistry from "./keeper/contracts/DIDRegistry" +// import Web3Provider from "./keeper/Web3Provider" +// import * as Web3 from "web3" + + +class DIDResolved { + public items: string[] + public value: string + + public constructor() { + this.items = [] + } + + public addData(data: string, value: string) { + this.items.push(data) + } +} + +/* + * + * Resolve a DID to an URL/DDO or later an internal/extrenal DID + * :param did: 32 byte value or DID string to resolver, this is part of the ocean DID did:op:<32 byte value> + * :param max_hop_count: max number of hops allowed to find the destination URL/DDO + * :return DIDResolved object: URL or DDO of the resolved DID + * :return null: if the DID cannot be resolved + * :raises TypeError: on non 32byte value as the DID + * :raises TypeError: on any of the resolved values are not string/DID bytes. + * :raises OceanDIDCircularReference: on the chain being pointed back to itself. + * :raises OceanDIDNotFound: if no DID can be found to resolve. + * + */ +export default class DIDResolver { + + public didRegistry + public constructor(didRegistry: DIDRegistry) { + this.didRegistry = didRegistry + } + + public resolve(did: string, maxHopCount?: number): DIDResolved { + + return new DIDResolved() + } +} diff --git a/test/keeper/DIDResolver.test.ts b/test/keeper/DIDResolver.test.ts new file mode 100644 index 0000000..6dd0a90 --- /dev/null +++ b/test/keeper/DIDResolver.test.ts @@ -0,0 +1,53 @@ + +import {assert} from "chai" +import ConfigProvider from "../../src/ConfigProvider" +import DIDRegistry from "../../src/keeper/contracts/DIDRegistry" +import Web3Provider from "../../src/keeper/Web3Provider" +import ValueType from "../../src/models/ValueType" +import Account from "../../src/ocean/Account" +import IdGenerator from "../../src/ocean/IdGenerator" +import Ocean from "../../src/ocean/Ocean" +//import Logger from "../src/utils/Logger" +import config from "../config" +import TestContractHandler from "./TestContractHandler" +import DIDResolver from "../../src/DIDResolver" +import * as DIDTools from "../../src/DID" + +let ocean: Ocean +let didRegistry: DIDRegistry + + +describe("DIDResolver", () => { + + before(async () => { + ConfigProvider.setConfig(config) + await TestContractHandler.prepareContracts() + ocean = await Ocean.getInstance(config) + didRegistry = await DIDRegistry.getInstance() + }) + + describe("register and resolve", () => { + + it("should register an attribute as a new DID and resolve", async () => { + const testId = IdGenerator.generateId() + + const did = DIDTools.idToDID(testId) + const didId = DIDTools.DIDToId(did) + const ownerAccount: Account = (await ocean.getAccounts())[0] + const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider") + const data = "my nice provider, is nice" + const receipt = await didRegistry.registerAttribute(didId, ValueType.DID, providerKey, + data, ownerAccount.getId()) + assert(receipt.status) + assert(receipt.events.DIDAttributeRegistered) + + const didResolver = new DIDResolver(didRegistry) + didResolver.resolve(did) + + }) + + }) + + +}) +