@peaq-network/did-resolver
v1.0.3
Published
Resolver for peaq DIDs
Downloads
84
Readme
did-resolver
peaq's DID Resolver package provides methods to resolve a Decentralized Identifier (DID) from the peaq blockchain based on a specified node URL, DID name, and address. The package can retrieve various fields of a DID document, such as verifications, services, authentications, and signatures, that are stored on the blockchain.
Installation
- Initialize npm package:
npm init -y
- Add
"type": "module",
to package.json - Install peaq's did-resolver:
npm install @peaq-network/did-resolver
Usage
import { peaqDidResolver } from '@peaq-network/did-resolver';
// Ensure that the DID associated with the specified 'name' has been previously created
// at the Base URL endpoint by the entity (wallet) that owns the 'address'.
// The 'address' should correspond to the wallet that created and controls the DID at the given Base URL.
const BASE_URL = 'wss://wsspc1-qa.agung.peaq.network';
const name = "myDID_123";
const address = "5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg";
const main = async () => {
const resolver = new peaqDidResolver();
// Resolve the entire DID
const result1 = await resolver.resolve({
baseUrl: BASE_URL,
name: name,
address: address
});
console.log(result1);
// Resolve the DID document
const result2 = await resolver.resolve_document({
baseUrl: BASE_URL,
name: name,
address: address
});
console.log(result2);
// Resolve the services field of the DID
const result3 = await resolver.resolve_services({
baseUrl: BASE_URL,
name: name,
address: address
});
console.log(result3);
// Resolve the verifications field of the DID
const result4 = await resolver.resolve_verifications({
baseUrl: BASE_URL,
name: name,
address: address
});
console.log(result4);
// Resolve the authentications field of the DID
const result5 = await resolver.resolve_authentications({
baseUrl: BASE_URL,
name: name,
address: address
});
console.log(result5);
// Resolve the signature field of the DID
const result6 = await resolver.resolve_signature({
baseUrl: BASE_URL,
name: name,
address: address
});
console.log(result6);
};
main();
API Reference
resolve({baseUrl, name, address})
Resolves the entire DID. Including fields such as the DID name, hash value of the DID, DID document, etc.
Parameters:
baseUrl:
The peaq blockchain node URL (WebSocket URL).name:
The DID nameaddress:
The wallet address (DID controller).
Returns:
Full DID as stored on chain.
resolve_document({baseUrl, name, address})
Resolves and returns the entire DID document with the verifications, services, authentications, etc.
Parameters:
- Same as resolve().
Returns:
The DID document.
resolve_services({baseUrl, name, address})
Reads the services field of the DID document.
Parameters:
- Same as resolve().
Returns:
The services field of the DID document.
resolve_verifications({baseUrl, name, address})
Reads the verifications field of the DID document.
Parameters:
- Same as resolve().
Returns:
The verifications field of the DID document.
resolve_authentications({baseUrl, name, address})
Reads the authentications field of the DID document.
Parameters:
- Same as resolve().
Returns:
The authentications field of the DID document.
resolve_signature({baseUrl, name, address})
Reads the signature field of the DID document.
Parameters:
- Same as resolve().
Returns:
The signature field of the DID document.
Example Responses
resolve()
{
"name": "myDID_123",
"value": "0x0a426469643a637573746f6d5f...",
"validity": "4,294,967,295",
"created": "2024-10-01T07:35:06Z",
"document": {
"id": "did:custom_prefix:5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg",
"controller": "did:custom_prefix:5FEw7aWmqcnWDaMcwjKyGtJMjQfqYGxXmDWKVfcpnEPmUM7q",
"signature": {
"type": "Ed25519VerificationKey2020",
"issuer": "5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg",
"hash": "0x12345"
},
"verificationMethod": [ [Object] ],
"service": [ [Object], [Object] ],
"authentication": [
"did:custom_prefix:5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg#keys-1"
]
}
}
resolve_document()
{
"id": "did:custom_prefix:5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg",
"controller": "did:custom_prefix:5FEw7aWmqcnWDaMcwjKyGtJMjQfqYGxXmDWKVfcpnEPmUM7q",
"signature": {
"type": "Ed25519VerificationKey2020",
"issuer": "5Df42mkztLtkksgQuLy4YV6hmhzdjYvDnnoxHv1QBkaY1333",
"hash": "0x12345"
},
"verificationMethod": [
{
"id": "did:custom_prefix:5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg#keys-1",
"type": "Ed25519VerificationKey2020",
"controller": "did:custom_prefix:5FEw7aWmqcnWDaMcwjKyGtJMjQfqYGxXmDWKVfcpnEPmUM7q",
"publicKeyMultibase": "466e7d57daf5d7176c3afce9ddf8e26b3670c932476f270cec0f625274788e23"
}
],
"service": [
{
"id": "#mongoDBConnection",
"type": "yourDataBaseName",
"serviceEndpoint": "mongodb://localhost:27017",
"data": "yourCollectionName"
},
{
"id": "#mongoDBIdentifier",
"type": "mongoID",
"serviceEndpoint": "mongodb://localhost:27017",
"data": "123"
}
],
"authentications": [
"did:custom_prefix:5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg#keys-1"
]
}
resolve_services()
[
{
"id": "#mongoDBConnection",
"type": "yourDataBaseName",
"serviceEndpoint": "mongodb://localhost:27017",
"data": "yourCollectionName"
},
{
"id": "#mongoDBIdentifier",
"type": "mongoID",
"serviceEndpoint": "mongodb://localhost:27017",
"data": "123"
}
]
resolve_verifications()
[
{
"id": "did:custom_prefix:5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg#keys-1",
"type": "Ed25519VerificationKey2020",
"controller": "did:custom_prefix:5FEw7aWmqcnWDaMcwjKyGtJMjQfqYGxXmDWKVfcpnEPmUM7q",
"publicKeyMultibase": "466e7d57daf5d7176c3afce9ddf8e26b3670c932476f270cec0f625274788e23"
}
]
resolve_authentications()
[
"did:custom_prefix:5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg#keys-1"
]
resolve_signature()
{
"type": "Ed25519VerificationKey2020",
"issuer": "5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg",
"hash": "0x12345"
}