Installing the ID DWN SDK
The entire ID DWN library is available on npmjs.com To install the library, simply run either:
npm i
@dwn-protocol/dwn
or
yarn add
@dwn-protocol/dwn
Instantiate the DWN from the SDK
import { IDDwn } from './browser.mjs'; // browser version only
// OR
import { IDDwn } from '@dwn-protocol/dwn'; // node version
let idDwn = new IDDwn;
Create a decentralized identity (DID)
const did = await idDwn.did.create('ion');
Store the DID
await idDwn.did.manager.set(did.id, {
connected: true,
endpoint: 'app://dwn',
keys: {
['#dwn']:
{
keyPair: did.keys.find(key => key.id === 'dwn').keyPair,
},
},
});
Create some data
const {record} = await idDwn.dwn.records.create(did.id, {
author: did.id,
data: "Hello ID++",
message: {
dataFormat: 'text/plain',
},
});
Read the data
const readResult = await record.data.text();
Update the data
const updateResult = await record.update({data: "Hello, I'm updated!"});
Delete the data
const deleteResult = await record.delete();
Last updated