0.0.23 • Published 1 year ago

@peerpiper/did-ar v0.0.23

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

DID:AR

I just wrote this, so there will be some changes, improvements and bugs. But feel free to play around with it.

Enables users to create a smartweave contract on Arweave to store their Decentralized Identity Document (DID Doc).

✔️📇 Your Own Permanent Identity on Web3

✔️🗃️ Resolve DID from .ar name, so douganderson444.ar -> did:ar:....

✔️💰 No Tokens / cryptocurrency (under 100kb), thanks to Bundlr!

✔️♾️ Lasts forever, thanks to Arweave!

✔️💻 Saves to your OWN device, thanks to PeerPiper!

✔️🗃️ Conveniently Control Your Data

Install

Package deployed to npm @peerpiper/did-ar

npm i @peerpiper/did-ar

Initialize

import { init } from 'did-ar';

const didar: DIDAr = await init({
	// local: true, // default is false, uses local Arweave instance
	// wallet: JWKInterface, // default is 'use_wallet' if no wallet is set
});

// which gives you a DIDAr instance:
interface DIDAr {
	warp: WarpFactory;
	wallet: JWKInterface | 'use_wallet';
	create: Function;
	read: Function;
	update: Function;
}

Create DID

Pass an RSA Public Key JWK and Ed25519PublicKey bytes (Uint8Array) to create, which will create a did and did document saved as the Arweave Smartweave contract state.

The Demo uses the keys from a PeerPiper/web3-wallet-connector to create the DID.

const did = await didar.create({ RSAPublicKey: JWK, Ed25519PublicKey: Uint8Array });
console.log(did); // did:ar:abc123zyx-ELEMENOPee
// or when running in `vite dev` mode:
console.log(did); // did:arlocal:abc123zyx-ELEMENOPee

Read DID (Resolve)

If you have a didar instance, you can simply read from it:

const didDoc = await didar.read(did);

If you are using DID from an external source, read using the resolver, as this library exports a standalone DID Resolver compliant with the DIF.

import { didArResolver } from '@peerpiper/did-ar';
import { Resolver } from 'did-resolver'; // Decentralized Identity Foundation

const did = `did:ar:abc123zyx-ELEMENOPeeeeeeeeeeeeeeee`;
// or when running in `vite dev` mode:
// did:arlocal

const arResolver = didArResolver.getResolver();
resolver = new Resolver(arResolver);
const didDoc = (await resolver.resolve(did)).didDocument;

console.log(didDoc.verificationMethod[0].publicKeyJwk); // one of the did's public keys

Read from .ar name (Resolve DID from Arweave Name Service / Name Token)

import { arnsResolver } from '@peerpiper/did-ar';

const arnsName = 'douganderson444'; // From: douganderson444.ar or 'douganderson444.arweave.dev' || 'douganderson444.ar.page';
const did = await arnsResolver(arnsName);

console.log(did); // did:ar:UGnqpxdraMbkmG-4F6jU7xkFhErNgaXLQf39tW7yYck

Update DID Document

To update, just pass the new DID Doc properties you wish to update. Then, did-ar verifies that the caller is the wallet owner (and by extention the did:ar owner). If anyone other than the owner of the contract tries to update the did document, the contract will only return the current DID Doc state.

The contract then replaces the old DID Document properties with the new properties.

const id = did;
let didDoc; // exsiting DID Doc

const replaceProperties = {
	service: [
		...didDoc.service, // keep existing service listings
		{
			id: `${did}#linked-domain`,
			type: 'LinkedDomains',
			serviceEndpoint: 'https://douganderson444.arweave.dev'
		}
	]
};

await didar.update({ id, ...replaceProperties }); // will change service property of DID Doc

Transfer

You can add or transfer controller of this DID by adding/changing the array of controllers.

⚠️ Be careful! Only the controller can update the DID Doc. Make sure you know what you are doing here. ⚠️

Controllers

Transfer is just an update where the controller is updated. Send an update command with the added/changed controller property:

const id = did;
let didDoc; // exsiting DID Doc

const replaceProperties = {
	...didDoc,
	controller: ['did:ar:newControllerDID']
};

await didar.update({ id, ...replaceProperties }); // will change the controller (ie owner) of DID Doc

Delete

TODO: Implement ANS-106 Do Not Store Request

What can you do with a DeID?

You can grab the keys out of the document. From the RSA key, you can get an Arweave address and look up their Arweave data. You can grab their DAG from ArDAG and interact with that data and apps too.

Forking The Smart Contract

With Arweave, using Warp Contract's deployFromSourceTx you can use an existing deployed contract and add your own initial state to make a new DID Doc.

TODO: List published version so others can deploy from source.

References

DID Core W3C Reccomendation

JOSE JWK RFC

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.6

2 years ago