5.0.2 • Published 3 months ago

dids v5.0.2

Weekly downloads
519
License
(Apache-2.0 OR MI...
Repository
github
Last release
3 months ago

DID

A simple library to interact with DIDs that conform to the DID-provider interface.

Installation

npm install dids

Examples

Authentication with the provider

import { DID } from 'dids'
import IdentityWallet from 'identity-wallet'

// See https://github.com/3box/identity-wallet-js
const wallet = new IdentityWallet(...)
const alice = new DID({ provider: wallet.getDidProvider() })

// Authenticate with the provider
await alice.authenticate()

// Read the DID string - this will throw an error if the DID instance is not authenticated
const aliceDID = alice.DID

// Create a JWS - this will throw an error if the DID instance is not authenticated
const jws = await alice.createJWS({ hello: 'world' })

// Create a DagJWS - the payload will be encoded as ipld dag-cbor, the resulting JWS is dag-jose compatible
const { jws, linkedBlock } = await alice.createJWS({ hello: 'world' coolLink: new CID(...) })

Resolving DIDs

import { DID } from 'dids'

// See https://github.com/decentralized-identity/did-resolver
const registry = { test: myTestResolver }
const did = new DID({ resolver: { registry } })

// Resolve a DID document
await did.resolve('did:test:...')

Interfaces and types

DIDDocument

The DID document interface, as defined in the DID resolver library.

DIDProvider

The DID provider interface, an alias for RPCConnection.

AuthenticateOptions

interface AuthenticateOptions {
  provider?: DIDProvider
}

CreateJWSOptions

interface CreateJWSOptions {
  did?: string
  protected?: Record<string, any>
}

DagJWSResult

interface DagJWSResult {
  jws: string // base64-encoded
  linkedBlock: string // base64-encoded
}

ResolverRegistry

A record of DID methods to resolvers, as defined in the DID resolver library.

export type ResolverRegistry = Record<string, DIDResolver>

ResolverOptions

Options used to create a Resolver instance, as defined in the DID resolver library.

export interface ResolverOptions {
  registry?: ResolverRegistry
  cache?: DIDCache | boolean
}

DIDOptions

export interface DIDOptions {
  provider?: DIDProvider
  resolver?: Resolver | ResolverOptions
}

API

DID class

constructor

Arguments

  1. options?: DIDOptions

did.authenticated

Returns boolean

did.id

Accessing this property will throw an error if the instance is not authenticated

Returns string

did.setProvider()

Calling this method will throw an error if a different provider is already set

Arguments

  1. provider: DIDProvider

Returns void

did.setResolver()

Arguments

  1. resolver: Resolver | ResolverOptions

Returns void

did.authenticate()

Calling this method with a provider will throw an error if a different provider is already set

Arguments

  1. options?: AuthenticateOptions

Returns Promise<string>

did.createJWS()

The instance needs to be authenticated before calling this method

Arguments

  1. payload: Record<string, any>
  2. options?: CreateJWSOptions to specify the protected header

Returns Promise<string>

did.createDagJWS()

Creates a JWS that is compatible with dag-jose.

The instance needs to be authenticated before calling this method

Arguments

  1. payload: Record<string, any>
  2. options?: CreateJWSOptions to specify the protected header, and did with keyFragment

Returns Promise<DagJWSResult>

did.resolve()

Arguments

  1. didUrl: string

Returns Promise<DIDDocument>

License

MIT

@hypernetlabs/hypernet-core@infinitebrahmanuniverse/nolb-did@everything-registry/sub-chunk-1479xdv-universal-walletxdv-universal-wallet-core@dustil/cli@dustil/core@dustil/stream-tileweb3.storage-lit-sdk@epdomains/jetstream-sdk@epdomains/passport-database-client@epdomains/passport-schemasuse-ceramicvess-sdkvc-sdk@hashchat/js-hashchat@hoprdev/hoprd@index-as/lit-ceramic-sdk@indexas/key-did-provider-secp256k1-with-lit@discovery-dao/schemasorbis-sdkorbit-db-identity-providercmdatahub-demo-1@desci-labs/desci-codex-lib@dataverse/dataverse-kernel-testdid-sessiondids-threadsspk-auth-react@ceramicnetwork/cli@ceramicnetwork/core@ceramicnetwork/ceramic-core@ceramicnetwork/ceramic-doctype-three-id@ceramicnetwork/ceramic-doctype-tile@ceramicnetwork/ceramic-http-client@ceramic-solutions/key-did@ceramicnetwork/did-test-utils@ceramicnetwork/model-metrics@ceramicnetwork/stream-tile@ceramicstudio/idx-cli@didtools/key-secp256k1@oneverse/identify@orbitdb/identity-provider-did@orbisclub/orbis-sdk-react-native@orbisclub/sdk@geo-web/datamodels@gitcoinco/passport-sdk-writer@glazed/cli@glazed/jest-environment-glaze@glazed/types@js-ligo/agreements@js-ligo/client@js-ligo/interact@learncard/ceramic-plugin@sterahi/create-ceramic@satellite-im/iridium@self.id/webjest-environment-glazejest-environment-glazetempjest-environment-idx@spknetwork/graph-client@spknetwork/hive-keychain-ceramic@topocount/gasless-conviction-sdk@topocount/gasless-conviction-servicekontext-common@symfoni/key-did-provider-secp256k1key-did-provider-ed25519key-did-provider-p256key-did-provider-secp256k1key-did-provider-secp256k1-with-lit@tairu/did-signer-keyring@tairu/did-signer-web@tairu/testing@tairu/did-verifier@astraldao/astral-protocol-core@astralprotocol/core@builderdao/apis@blockchain-lab-um/ssi-snap@cambrianprotocol/stream-tile@cambrianprotocol/cli@cambrianprotocol/core@vsc.eco/client@collabland/did@collabland/idx@collabland/component-did@composedb/cli@composedb/types@dabit3/connectidx@dabit3/decentralized-identityceramic-address-book@dao-xyz/orbit-db-identity-provider@daoism-systems/dsafe-sdk@daemon-land/3id-connect@daemon-land/typesatmos-sdk-react-native@aomi/one-did-provider@aomi/one-did-resolvermaskodid@3id/connect@3id/did-manager@3id/did-provider
5.1.0-next.0

3 months ago

5.0.2

4 months ago

5.0.0

4 months ago

4.0.5-next.0

6 months ago

4.0.5-next.2

6 months ago

4.0.5-next.1

6 months ago

4.0.4

9 months ago

4.0.3

10 months ago

4.0.1

1 year ago

3.4.0-alpha.0

1 year ago

4.0.0

1 year ago

3.4.0

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

3.0.0-rc.0

2 years ago

3.0.0

2 years ago

3.0.0-alpha.10

2 years ago

3.0.0-alpha.12

2 years ago

3.0.0-alpha.11

2 years ago

3.0.0-alpha.9

2 years ago

3.0.0-alpha.7

2 years ago

3.0.0-alpha.6

2 years ago

3.0.0-alpha.8

2 years ago

3.0.0-alpha.3

2 years ago

3.0.0-alpha.2

2 years ago

3.0.0-alpha.5

2 years ago

3.0.0-alpha.4

2 years ago

2.4.1-alpha.0

2 years ago

3.0.0-alpha.1

2 years ago

2.4.1

2 years ago

3.0.0-alpha.0

2 years ago

2.4.3

2 years ago

2.4.2

2 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.8.0

3 years ago

0.7.0

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.5.0-alpha.0

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.1

4 years ago