npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@peaq-network/did-resolver

v1.0.3

Published

Resolver for peaq DIDs

Downloads

257

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 name
  • address: 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"
}