@dwn-protocol/dwn v0.0.62
@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
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 customizableDwn
instance to use instead of a default one created byidDwn.dwn
. This can be used to customize the storage location/structure/etc. of theDwn
, 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 thetarget
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 thetarget
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 usermessage
-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 thetarget
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 thetarget
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 thetarget
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 thetarget
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 thetarget
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 thedefinition
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 therecords
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
Resource | Description |
---|---|
CODEOWNERS | Outlines the project lead(s) |
CODE_OF_CONDUCT.md | Expected behavior for project contributors, promoting a welcoming environment |
CONTRIBUTING.md | Developer guide to build, test, run, access CI, chat, discuss, file issues |
GOVERNANCE.md | Project governance |
LICENSE | Apache License, Version 2.0 |
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago