UNPKG

ipns-did

Version:

Library for resolving, creating, and publishing DID documents over IPNS

46 lines (45 loc) 1.98 kB
import { DIDResolutionResult } from "did-resolver"; import { IPFS } from "ipfs-core-types"; import { BlockCodec } from "multiformats/codecs/interface"; import { Hasher } from "multiformats/hashes/hasher"; export { DIDResolutionResult } from "did-resolver"; import { DIDDocument } from "did-doc"; import { PeerId } from "@libp2p/interface-peer-id"; import { CID } from "multiformats"; declare type MultidecoderParam = { codecs?: [BlockCodec<any, any>]; hashers?: [Hasher<any, any>]; }; export default function (opts: { ipfs: IPFS; multicodecs?: MultidecoderParam; }): { /** * Resolve an IPNS method DID into a document. * @throws Will throw if DID method isn't `ipns` * @throws Will throw if IPNS cannot resolve into an IPFS CID * @throws Will throw if the document can't be found, or if the given path can't be followed */ resolve(did: string): Promise<DIDResolutionResult>; _publishValue(value: any, codec?: number, hasher?: number): Promise<CID>; /** * Publish a DID document to IPNS using a given peer ID. * @param {DIDDocument} doc The DID document to publish * @param {Object} opts Document serialization options * @param {number} opts.codec Code of the codec used to serialize * @param {number} opts.hasher Code of the hasher used to serialize * @param {PeerId} peerId The peer ID (keypair) used to create the IPNS block * @param {number} lifetime The lifetime (TTL) of the published document, in milliseconds * @throws {TypeError} Will throw if the passed document isn't valid * @returns Returns the CIDs of the document and IPNS blocks */ publishDid(doc: DIDDocument, opts: { codec?: number; hasher?: number; }, peerId: PeerId, lifetime: number): Promise<{ ipnsCid: CID; docCid: CID; }>; peerIdToDid(peerId: PeerId): string; domainToDid(domain: string): string; };