npm package: @peaq-network/did-resolver
Description: Resolver for peaq DIDs
Author: peaq network
Latest version: 1.1.1

# 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`
- Install peaq's did-resolver: `npm install @peaq-network/did-resolver`

## Usage
```js
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 = 'https://quicknode1.peaq.xyz';
const name = "example_name";
const address = "0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C";


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.
<br/>
<br/>


### `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.
<br/>
<br/>

### `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.
<br/>
<br/>

### `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.
<br/>
<br/>

### `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.
<br/>
<br/>

### `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()`
```json
{
  "name": "example_name",
  "value": "0a336469643a706561713a30783945656162316143636231413730316145664142303046336238613237356133393634363634314312336469643a706561713a3078394565616231614363623141373031614566414230304633623861323735613339363436363431431acb010a3a6469643a706561713a307839456561623161436362314137303161456641423030463362386132373561333936343636343143236b6579732d3112204563647361536563703235366b315265636f766572794d6574686f64323032301a336469643a706561713a30783945656162316143636231413730316145664142303046336238613237356133393634363634314322366569703135353a333333383a30783945656162316143636231413730316145664142303046336238613237356133393634363634314322d5010a204563647361536563703235366b315265636f766572794d6574686f6432303230122a3078394565616231614363623141373031614566414230304633623861323735613339363436363431431a84013078326566316239333236303061353938396263643833653863323230326363666364353836663637646161303531306266306361383938653631643432353939333465316462336137613839656639626631313737316532313861666361373934376462343231613333623434313539326130323732613662633364373439326531622aa8010a0f23656d61696c5369676e6174757265120e656d61696c5369676e6174757265228401307835353138363935363966663936633031613065633838306562383366643035653131303837313565393465646331626362626438376336323834366238316636303531313137623962306463323663316537383366646663313461353465666661373263396135333261373037653036613838636330323336316634336164643162323a6469643a706561713a307839456561623161436362314137303161456641423030463362386132373561333936343636343143236b6579732d31",
  "validity": true,
  "created": "2025-11-13T17:37:18Z",
  "document": {
    "id": "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C",
    "controller": "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C",
    "signature": {
      "type": "EcdsaSecp256k1RecoveryMethod2020",
      "issuer": "0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C",
      "hash": "0x2ef1b932600a5989bcd83e8c2202ccfcd586f67daa0510bf0ca898e61d4259934e1db3a7a89ef9bf11771e218afca7947db421a33b441592a0272a6bc3d7492e1b"
    },
    "verificationMethod": [
      [ "{Object}" ]
    ],
    "service": [
      [ "{Object}" ]
    ],
    "authentication": [
      "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C#keys-1"
    ]
  }
}
```

### `resolve_document()`
```json
{
  "id": "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C",
  "controller": "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C",
  "signature": {
    "type": "EcdsaSecp256k1RecoveryMethod2020",
    "issuer": "0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C",
    "hash": "0x2ef1b932600a5989bcd83e8c2202ccfcd586f67daa0510bf0ca898e61d4259934e1db3a7a89ef9bf11771e218afca7947db421a33b441592a0272a6bc3d7492e1b"
  },
  "verificationMethod": [
    {
      "id": "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C#keys-1",
      "type": "EcdsaSecp256k1RecoveryMethod2020",
      "controller": "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C",
      "publicKeyMultibase": "eip155:3338:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C"
    }
  ],
  "service": [
    {
      "id": "#emailSignature",
      "type": "emailSignature"
    }
  ],
  "authentication": [
    "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C#keys-1"
  ]
}
```

### `resolve_services()`
```json
[
  {
    "id": "#emailSignature",
    "type": "emailSignature"
  }
]
```

### `resolve_verifications()`
```json
[
  {
    "id": "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C#keys-1",
    "type": "EcdsaSecp256k1RecoveryMethod2020",
    "controller": "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C",
    "publicKeyMultibase": "eip155:3338:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C"
  }
]
```

### `resolve_authentications()`
```json
[
  "did:peaq:0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C#keys-1"
]
```

### `resolve_signature()`
```json
{
  "type": "EcdsaSecp256k1RecoveryMethod2020",
  "issuer": "0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C",
  "hash": "0x2ef1b932600a5989bcd83e8c2202ccfcd586f67daa0510bf0ca898e61d4259934e1db3a7a89ef9bf11771e218afca7947db421a33b441592a0272a6bc3d7492e1b"
}
```


## Development
### Install:
```
npm install
```
### Build:
```
npm run build
```
### Test:
```
npm run test
```
### Pack:
```
npm pack
```