Class Name | Did |
---|---|
Extends | Logger |
Source | did.ts |
Tests | did.spec.ts |
The Did module allows to interact with DIDs on evan.network. As development of identity and DID handling on evan.network is an ongoing process, this document describes the current interoperability of DIDs on evan.network and can be seen as a work-in-progress state of the current implementation.
new Did(options);
Creates a new Did instance.
options
-DidOptions
: options for Did constructor.accountStore
-AccountStore
:AccountStore
instancecontractLoader
-ContractLoader
:ContractLoader
instancedfs
-DfsInterface
:DfsInterface
instanceexecutor
-Executor
:Executor
instancenameResolver
-NameResolver
:NameResolver
instancesignerIdentity
-SignerIdentity
:SignerIdentity
instanceweb3
-Web3
:Web3
instancelog
-Function
(optional): function to use for logging:(message, level) => {...}
logLevel
-LogLevel
(optional): messages with this level will be logged withlog
logLog
-LogLogInterface
(optional): container for collecting log messageslogLogLevel
-LogLevel
(optional): messages with this level will be pushed tologLog
config
-DidConfig
(optional): description, defaults to123
registryAddress
-string
(optional): contract address or ENS name for DidRegistry
Did
instance
const did = new Did({
contractLoader,
dfs,
executor,
nameResolver,
signerIdentity,
web3,
});
did.deactivateDidDocument(didToDeactivate);
Unlinks the current DID document from the given DID
did
-string
: DID to unlink the DID document from
Promise
returns void
: Resolves when done
const twinIdentity = '0x1234512345123451234512345123451234512345';
const twinDid = await runtime.did.convertIdentityToDid(twinIdentity);
await runtime.did.deactivateDidDocument(twinDid);
did.didIsDeactivated(didToCheck);
Gets the deactivation status of a DID.
did
-string
: DID to check
Promise
returns boolean
: True if the DID has been deactivated
const twinIdentity = '0x1234512345123451234512345123451234512345';
const twinDid = await runtime.did.convertIdentityToDid(twinIdentity);
await runtime.did.deactivateDidDocument(twinDid);
console.log(await runtime.did.didIsDeactivated(twinDid));
// Output: true
did.getDidDocument(myDid);
Get DID document for given DID. If the DID has a proof property, getDidDocument will attempt to validate the proof and throw an error if the proof is invalid.
did
-string
: DID to fetch DID document for.
Promise
returns DidDocument
: A DID document. For deactivated DIDs it returns a default DID document containing no authentication material.
const identity = await runtime.verifications.getIdentityForAccount(accountsId, true);
const did = await runtime.did.convertIdentityToDid(identity);
const document = await runtime.did.getDidDocumentTemplate();
await runtime.did.setDidDocument(did, document);
const retrieved = await runtime.did.getDidDocument(did);
did.getService(myDid);
Get the services from a DID document.
did
-string
: DID to fetch DID service for.
Promise
returns DidServiceEntry[]
: Array of services.
const document = await runtime.did.getDidDocumentTemplate();
const identity = await runtime.verifications.getIdentityForAccount(account, true);
const did = await runtime.did.convertIdentityToDid(identity);
await runtime.did.setDidDocument(did, document);
const service = {
id: `${did}#randomService`,
type: `randomService-${random}`,
serviceEndpoint: `https://openid.example.com/${random}`,
};
await runtime.did.setService(did, service);
const retrieved = await runtime.did.getService(did);
did.setDidDocument(myDid, document);
Store given DID document for given DID. If the document misses the property created, it will automatically be appended. The updated property will be updated accordingly. A proof over the DID document will be generated automatically and appended to the document.
did
-string
: DID to store DID document fordocument
-DidDocument
: DID document to store,getDidDocumentTemplate
can be used as a starting point for DID documents
Promise
returns void
: resolved when done
const identity = await runtime.verifications.getIdentityForAccount(accountsId, true);
const did = await runtime.did.convertIdentityToDid(identity);
const document = await runtime.did.getDidDocumentTemplate();
await runtime.did.setDidDocument(did, document);
did.setService(myDid, service);
Sets service in DID document. Overrides old services, so make sure to include current service if you only want to add a service.
did
-string
: DID name to set service forservice
-DidServiceEntry[] | DidServiceEntry
: service or array of services to set
Promise
returns void
: resolved when done
const document = await runtime.did.getDidDocumentTemplate();
const identity = await runtime.verifications.getIdentityForAccount(account, true);
const did = await runtime.did.convertIdentityToDid(identity);
await runtime.did.setDidDocument(did, document);
const service = {
id: `${did}#randomService`,
type: `randomService-${random}`,
serviceEndpoint: `https://openid.example.com/${random}`,
};
await runtime.did.setService(did, service);
did.convertDidToIdentity(didToConvert);
Converts given DID to a evan.network identity.
did
-string
: a DID like "did:evan:testcore:0x000000000000000000000000000000000000001234"
Promise
returns string
: evan.network identity like "0x000000000000000000000000000000000000001234"
const did = 'did:evan:testcore:0x000000000000000000000000000000000000001234';
const identity = await did.convertDidToIdentity(did);
console.log(identity);
// Output:
// 0x000000000000000000000000000000000000001234
did.convertIdentityToDid(identityToConvert);
Converts given evan.network identity hash to DID.
identity
-string
: evan.network identity like "0x000000000000000000000000000000000000001234"
Promise
returns string
: a DID like "did:evan:testcore:0x000000000000000000000000000000000000001234"
const identity = '0x000000000000000000000000000000000000001234';
const did = await did.convertIdentityToDid(identity);
console.log(did);
// Output:
// did:evan:testcore:0x000000000000000000000000000000000000001234
did.getDidDocumentTemplate();
Gets a DID document for currently configured identity. Notice, that this document may a complete DID document for currently configured active identity, a part of it or not matching it at all. You can use the result of this function to build a new DID document but should extend it or an existing DID document, if your details derive from default format.
All three arguments are optional. When they are used, all of them have to be given and the result then describes a contracts DID document. If all of them are omitted the result describes an accounts DID document.
did
-string
(optional): contract DIDcontrollerDid
-string
(optional): controller of contracts identity (DID)authenticationKey
-string
(optional): authentication key used for contract
Promise
returns DidDocumentTemplate
: template for DID document
const document = await runtime.did.getDidDocumentTemplate();
console.log(JSON.stringify(document, null, 2));
// Output:
// {
// "@context": "https://w3id.org/did/v1",
// "id": "did:evan:testcore:0x126E901F6F408f5E260d95c62E7c73D9B60fd734",
// "publicKey": [
// {
// "id": "did:evan:testcore:0x126E901F6F408f5E260d95c62E7c73D9B60fd734#key-1",
// "type": "Secp256k1VerificationKey2018",
// "controller": "did:evan:testcore:0x126E901F6F408f5E260d95c62E7c73D9B60fd734",
// "ethereumAddress": "0x126E901F6F408f5E260d95c62E7c73D9B60fd734"
// }
// ],
// "authentication": [
// "did:evan:testcore:0x126E901F6F408f5E260d95c62E7c73D9B60fd734#key-1"
// ]
// }