Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @ceramicnetwork/3id-did-resolver

3ID DID Resolver

3ID is a DID method that uses the Ceramic network to resolve DID documents.

Getting started

Installation

$ npm install @ceramicnetwork/3id-did-resolver

Usage

import ThreeIdResolver from '@ceramicnetwork/3id-did-resolver'
import { Resolver } from 'did-resolver'

// You need an instance of Ceramic to call getResolver.
// This can be either @ceramicnetwork/core or @ceramicnetwork/http-client.
// You can also set an address for your own ethr-did-registry contract
const ceramic = // ...

// getResolver will return an object with a key/value pair of { '3': resolver }
// where resolver is a function used by the generic did resolver.
const threeIdResolver = ThreeIdResolver.getResolver(ceramic)
const didResolver = Resolver(threeIdResolver)

const doc = await didResolver.resolve('did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74')
console.log(doc)

Development

Run tests:

$ npm test

Run linter:

npm run lint

Contributing

We are happy to accept small and large contributions. Make sure to check out the Ceramic specifications for details of how the protocol works.

License

Index

Variables

Const DID_JSON

DID_JSON: "application/did+json" = "application/did+json"

Const DID_LD_JSON

DID_LD_JSON: "application/did+ld+json" = "application/did+ld+json"

Const LIMIT

LIMIT: 100 = 100

Const THREEBOX_API_URL

THREEBOX_API_URL: "https://ipfs.3box.io" = "https://ipfs.3box.io"

Const fetchCache

fetchCache: LRUMap<string, any> = new LRUMap<string, any>(LIMIT)

Functions

Const LegacyResolver

  • LegacyResolver(didId: string, ipfs?: IPFS): Promise<any>

Const compressKey

  • compressKey(key: string): string

Const didDocReq

  • didDocReq(cid: string): string

Const encodeKey

  • encodeKey(key: Uint8Array, encryption?: boolean): string

extractMetadata

  • extractMetadata(requestedVersionState: StreamState, latestVersionState: StreamState): DIDDocumentMetadata
  • Extracts the DIDDocumentMetadata for the 3ID that we have resolved. Requires the latest version of the 3ID ceramic document state as well as the state of the version we are resolving

    Parameters

    • requestedVersionState: StreamState

      the StreamState of the version of the 3ID we are resolving

    • latestVersionState: StreamState

      the StreamState of the latest version of the 3ID we are resolving

    Returns DIDDocumentMetadata

Const fetchJson

  • fetchJson(url: string): Promise<any>

Const formatTime

  • formatTime(timestamp: number): string

getVersionInfo

Const isLegacyDid

  • isLegacyDid(didId: string): boolean

Const legacyResolve

  • legacyResolve(ceramic: CeramicApi, didId: string, verNfo: VersionInfo): Promise<DIDResolutionResult>

Const resolve

  • resolve(ceramic: CeramicApi, didId: string, verNfo: VersionInfo, v03ID?: string): Promise<DIDResolutionResult>

wrapDocument

  • wrapDocument(content: any, did: string): DIDDocument | null
  • Wraps the content from the Ceramic 3ID document tile and formats it as a proper DIDDocument.

    Parameters

    • content: any

      the content from the 3ID Ceramic tile

    • did: string

      the did to use when wrapping the document

    Returns DIDDocument | null

Object literals

Const ipfsMock

ipfsMock: object

dag

dag: object

get

  • get(cid: string): Promise<any>