0.0.62 • Published 8 months ago

@dwn-protocol/dwn v0.0.62

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
8 months ago

@dwn-protocol/dwn

ID Node consists of the following components:

  • Decentralized Identifiers
  • Verifiable Credentials
  • Node personal datastores

The SDK sets out to gather the most oft used functionality from all three of these pillar technologies to provide a simple library that is as close to effortless as possible.

Docs

API Reference

new IDDwn([options])

const idDwn = new IDDwn();

const alice = await idDwn.did.create('key');

Assuming the alice instance is present from the example above, you would pass the following values to add it to the DID manager:

await idDwn.did.manager.set(alice.id, {
    connected: true,
    endpoint: 'app://dwn',
    keys: {
        '#dwn': {
          keyPair: myDid.keys.find(key => key.id === 'dwn').keyPair,
        }
    },
    services: alice.services,
});

Creates an isolated API object for doing IDDwn things, split into three main top-level objects: did, dwn, and vc.

  • options

When creating a IDDwn instance the following options can be provided:

  • dwn

This object contains options related to idDwn.dwn.

  • node - Dwn: A customizable Dwn instance to use instead of a default one created by idDwn.dwn. This can be used to customize the storage location/structure/etc. of the Dwn, how DIDs are resolved, etc..

idDwn.dwn.records.query(target, request)

Method for querying the Node of a provided target DID.

  • request

idDwn.dwn.records.create(target, request)

Method for writing a record to the DWeb Node of a provided target DID.

  • request

The write request must contain the following:

  • author - string: The decentralized identifier of the DID signing the query. This may be the same as the target parameter if the target and the signer of the query are the same entity, which is common for an app querying the DWeb Node of its own user.

  • message - object: The properties of the DWeb Node Message Descriptor that will be used to construct a valid DWeb Node message.

  • data - blob | stream | file: The data object of the bytes to be sent.

Example

const { record } = await idDwn.dwn.records.create('did:key:alice', {
  author: 'did:key:alice',
  data: 'Hello World!',
  message: {
    dataFormat: 'text/plain'
  }
});

console.log(record.data.text())

The query request must contain the following:

  • author - string: The decentralized identifier of the DID signing the query. This may be the same as the target parameter if the target and the signer of the query are the same entity, which is common for an app querying the Node of its own user

  • message - object: The properties of the Node Message Descriptor that will be used to construct a valid Node message

Example

const idDwn = new IDDwn();
const response = await idDwn.dwn.records.query('did:key:bob', {
  author: 'did:key:alice',
  message: {
    filter: {
      schema: 'https://schema.org/CarbonPermit',
      dataFormat: 'application/json'
    }
  }
});

idDwn.dwn.records.write(target, request)

Method for writing a record to the Node of a provided target DID.

  • request

The write request must contain the following:

  • author* - string*: The decentralized identifier of the DID signing the query. This may be the same as the target parameter if the target and the signer of the query are the same entity, which is common for an app querying the Node of its own user.

  • message - object: The properties of the Node Message Descriptor that will be used to construct a valid Node message.

  • data - blob | stream | file: The data object of the bytes to be sent.

Example

const imageFile = document.querySelector('#file_input').files[0];

const idDwn = new IDDwn();
const response = await idDwn.dwn.records.write('did:key:alice', {
  author: 'did:key:alice',
  data: imageFile,
  message: {
    dataFormat: 'image/png'
  }
});

idDwn.dwn.records.read(target, request)

Method for writing a record to the Node of a provided target DID.

  • request

The write request must contain the following:

  • author - string: The decentralized identifier of the DID signing the query. This may be the same as the target parameter if the target and the signer of the query are the same entity, which is common for an app querying the Node of its own user.

  • message - object: The properties of the Node Message Descriptor that will be used to construct a valid Node message.

  • recordId - string: the required record ID string that identifies the record data you are fetching.

Example

const idDwn = new IDDwn();
const response = await idDwn.dwn.records.read('did:key:alice', {
  author: 'did:key:alice',
  message: {
    filter: {
      recordId: 'bfw35evr6e54c4cqa4c589h4cq3v7w4nc534c9w7h5',
    }
  }
});

idDwn.dwn.records.delete(target, request)

Method for deleting a record in the Node of a provided target DID.

  • request

The delete request must contain the following:

  • author - string: The decentralized identifier of the DID signing the query. This may be the same as the target parameter if the target and the signer of the query are the same entity, which is common for an app querying the Node of its own user.

  • message - object: The properties of the Node Message Descriptor that will be used to construct a valid Node message.

  • recordId - string: the required record ID string that identifies the record being deleted.

Example

const idDwn = new IDDwn();
const response = await idDwn.dwn.records.delete('did:key:alice', {
  author: 'did:key:alice',
  message: {
    recordId: 'bfw35evr6e54c4cqa4c589h4cq3v7w4nc534c9w7h5'
  }
});

idDwn.dwn.protocols.query(target, request)

Method for querying the protocols that a target DID has added configurations for in their Node.

  • request

The query request must contain the following:

  • author - string: The decentralized identifier of the DID signing the query. This may be the same as the target parameter if the target and the signer of the query are the same entity, which is common for an app querying the Node of its own user.

  • message - object: The properties of the Node Message Descriptor that will be used to construct a valid Node message.

  • filter - object: an object that defines a set of properties to filter results.

  • protocol - URI string: a URI that represents the protocol being queried for.

Example

const idDwn = new IDDwn();
const response = await idDwn.dwn.protocols.query('did:key:alice', {
  author: 'did:key:alice',
  message: {
    filter: {
      protocol: "https://decentralized-storage.org/protocol",
    }
  }
});

idDwn.dwn.protocols.configure(target, request)

Method for deleting a record in the Node of a provided target DID.

  • request

The confiuration request must contain the following:

  • author - string: The decentralized identifier of the DID signing the query. This may be the same as the target parameter if the target and the signer of the query are the same entity, which is common for an app querying the Node of its own user.

  • message - object: The properties of the Node Message Descriptor that will be used to construct a valid Node message.

    • protocol - URI string: a URI that represents the protocol being configured via the definition object.

    • definition - object: an object that defines the ruleset that will be applied to the records and activities under the protocol.

    • labels - object: an object that defines the composition of records that will be used in the records tree below.

    • records - object: a recursive object that defines the structure of an app, including data relationships and constraints on which entities can perform various activities.

Example

const response = await idDwn.dwn.protocols.configure('did:key:alice', {
          author: 'did:key:alice',
          message: { protocol, definition },
});

idDwn.connect([options])

Enables an app to request connection to a user's local identity app, or generate an in-app DID to represent the user (e.g. if the user does not have an identity app).

NOTE: This method MUST be invoked within the scope of a 'trusted user action', which is something the browser/OS decides. For browsers this is generally some direct user intent, like clicking a link or button.

  • options

The connect method optionally accepts an object with the following properties:

  • storage

Used by connect to store connection data/keys/etc. for reuse when calling connect again (e.g. during another session).

If provided, storage must be an object that has the same methods as Storage.

If not provided, an instance of LocalStorage is used instead.

  • connectionLocation

Controls where in storage the connection data is stored.

Defaults to 'iddwn-connection'.

  • keysLocation

Controls where in storage the connection keys are stored.

Defaults to 'iddwn-keys'.

  • silent

Controls whether to prompt the user to start a new connection if a connection has not already been established.

Defaults to false.

Project Resources

ResourceDescription
CODEOWNERSOutlines the project lead(s)
CODE_OF_CONDUCT.mdExpected behavior for project contributors, promoting a welcoming environment
CONTRIBUTING.mdDeveloper guide to build, test, run, access CI, chat, discuss, file issues
GOVERNANCE.mdProject governance
LICENSEApache License, Version 2.0
0.0.40

10 months ago

0.0.41

10 months ago

0.0.42

10 months ago

0.0.43

10 months ago

0.0.44

10 months ago

0.0.45

10 months ago

0.0.46

10 months ago

0.0.47

10 months ago

0.0.37

10 months ago

0.0.38

10 months ago

0.0.39

10 months ago

0.0.30

10 months ago

0.0.31

10 months ago

0.0.32

10 months ago

0.0.33

10 months ago

0.0.34

10 months ago

0.0.35

10 months ago

0.0.36

10 months ago

0.0.28

10 months ago

0.0.29

10 months ago

0.0.62

8 months ago

0.0.60

8 months ago

0.0.61

8 months ago

0.0.59

8 months ago

0.0.51

9 months ago

0.0.52

9 months ago

0.0.53

9 months ago

0.0.54

9 months ago

0.0.55

9 months ago

0.0.56

9 months ago

0.0.57

9 months ago

0.0.58

9 months ago

0.0.50

9 months ago

0.0.48

10 months ago

0.0.49

10 months ago

0.0.27

11 months ago

0.0.26

11 months ago

0.0.25

11 months ago

0.0.24

11 months ago

0.0.23

11 months ago

0.0.22

11 months ago

0.0.21

11 months ago

0.0.20

11 months ago

0.0.19

11 months ago

0.0.18

11 months ago

0.0.17

11 months ago

0.0.16

11 months ago

0.0.15

11 months ago

0.0.14

11 months ago

0.0.13

11 months ago

0.0.12

11 months ago

0.0.11

11 months ago

0.0.10

11 months ago

0.0.9

12 months ago

0.0.8

12 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago