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

Merge branch 'feature/did-tools' into feature/did-resolver

This commit is contained in:
Bill Barman 2018-11-22 16:40:46 +08:00
commit f15f318a7a
2 changed files with 6 additions and 6 deletions

View File

@ -121,7 +121,7 @@ export function idToDID(id: string, method?: string): string {
* :return a hex string, without the leading '0x'
* :return null if the DID is invalid
*/
export function DIDToId(did: string): string {
export function didToId(did: string): string {
const result = didParse(did)
if (result && result.idHex ) {
return result.idHex
@ -129,7 +129,7 @@ export function DIDToId(did: string): string {
return null
}
export function DIDToIdBytes(did: string): Uint8Array {
export function didToIdBytes(did: string): Uint8Array {
const result = didParse(did)
if (result && result.idHex) {
return Web3.utils.hexToBytes("0x" + result.idHex)

View File

@ -1,9 +1,9 @@
import * as assert from "assert"
import * as didTools from "../src/DID"
import * as didTools from "../../src/utils/DIDTools"
import * as Web3 from "web3"
describe("DID Tests", () => {
describe("DIDTools Tests", () => {
describe("did generate", () => {
@ -68,7 +68,7 @@ describe("DID Tests", () => {
const testId = Web3.utils.randomHex(32).substring(2)
const testMethod = "op"
const validDID = "did:" + testMethod + ":" + testId
assert(didTools.DIDToId(validDID) === testId)
assert(didTools.didToId(validDID) === testId)
})
it("should convert an Ocean DID to an array of bytes", async () => {
@ -76,7 +76,7 @@ describe("DID Tests", () => {
const byteId = Web3.utils.hexToBytes("0x" + testId)
const testMethod = "op"
const validDID = "did:" + testMethod + ":" + testId
const bufferTest = Buffer.from(didTools.DIDToIdBytes(validDID))
const bufferTest = Buffer.from(didTools.didToIdBytes(validDID))
const bufferValid = Buffer.from(byteId)
assert(Buffer.compare(bufferTest, bufferValid) === 0 )
})