Skip to content

Commit 4218237

Browse files
authored
Update README.md file (#24)
* Update README.md file Signed-off-by: DeepakNemad <deepak.nemade@ayanworks.com> * Update README.md file Signed-off-by: DeepakNemad <deepak.nemade@ayanworks.com> * Update README.md file Signed-off-by: DeepakNemad <deepak.nemade@ayanworks.com> --------- Signed-off-by: DeepakNemad <deepak.nemade@ayanworks.com>
1 parent fed57c0 commit 4218237

6 files changed

Lines changed: 404 additions & 0 deletions

File tree

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Polygon DID Modules
2+
3+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4+
[![Node.js](https://img.shields.io/badge/Node.js-22%2B-green.svg)](https://nodejs.org/)
5+
[![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
6+
7+
A comprehensive suite of modules for implementing Polygon-based Decentralized Identifiers (DIDs) with W3C compliance, enabling secure identity management on the Polygon blockchain network.
8+
9+
10+
## Packages
11+
12+
This monorepo contains the following packages:
13+
14+
| Package | Description | Version |
15+
|---------|-------------|---------|
16+
| `credo-module` | Credo framework integration module | ![npm](https://img.shields.io/npm/v/@ayanworks/credo-polygon-w3c-module) |
17+
| `did-resolver` | Polygon DID resolver implementation | ![npm](https://img.shields.io/npm/v/@ayanworks/polygon-did-resolver) |
18+
| `did-registrar` | DID registration and management | ![npm](https://img.shields.io/npm/v/@ayanworks/polygon-did-registrar) |
19+
| `schema-manager` | W3C schema management utilities | ![npm](https://img.shields.io/npm/v/@ayanworks/polygon-schema-manager) |
20+
| `did-registry-contract` | Smart contract for DID registry | ![npm](https://img.shields.io/npm/v/@ayanworks/polygon-did-registry-contract) |
21+
22+
23+
### Setup
24+
25+
```bash
26+
# Clone the repository
27+
git clone https://github.com/ayanworks/polygon-did-modules.git
28+
29+
# Install dependencies
30+
pnpm install
31+
32+
# Build all packages
33+
pnpm build
34+
35+
# Run tests
36+
pnpm test
37+
38+
# Type checking
39+
pnpm types:check
40+
41+
# Code formatting
42+
pnpm style:fix
43+
```
44+
45+

packages/credo-module/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Credo did:polygon W3C Module
2+
3+
- W3C did:polygon method registry for [credo-ts](https://github.com/openwallet-foundation/credo-ts).
4+
5+
## Usage
6+
7+
```ts
8+
import { PolygonDidResolver, PolygonDidRegistrar, PolygonModule } from 'afj-polygon-w3c-module'
9+
10+
const agent = new Agent({
11+
config: {
12+
/* agent config */
13+
},
14+
dependencies,
15+
modules: {
16+
/* ... */
17+
dids: new DidsModule({
18+
resolvers: [ /* ... */, new PolygonDidResolver()],
19+
registrars: [ /* ... */, new PolygonDidRegistrar()],
20+
}),
21+
/* ... */
22+
polygon: new PolygonModule({
23+
rpcUrl: 'rpcUrl' // polygon rpc url,
24+
didContractAddress: 'didContractAddress' // polygon did contract address,
25+
fileServerToken: 'fileServerToken' // polygon file server token to store schema json,

packages/did-registrar/README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Polygon DID Method
2+
3+
The polygon DID method library uses Ethereum based addresses as fully functional DID’s or Decentralized identifiers, on the Polygon network. The following allows one to create a key Pair based and facilitates its storage on the registry smart contract, deployed on Polygon chain.
4+
Third party users can use this to create polygon DID identities. It allows the controller to perform actions like resolve, update and delete by encapsulating polygonDID registry and PolygonDID resolver.
5+
The DID identifier allows the controller to resolve DID document for usage in different scenarios.
6+
7+
### Example of polygon DID document resolved using PolygonDIDResolver:
8+
9+
```json
10+
{
11+
"@context": "https://w3id.org/did/v1",
12+
"id": "did:polygon:0x794b781493AeD65b9ceBD680716fec257e118993",
13+
"verificationMethod": [
14+
{
15+
"id": "did:polygon:0x794b781493AeD65b9ceBD680716fec257e118993",
16+
"type": "EcdsaSecp256k1VerificationKey2019",
17+
"controller": ["did:polygon:0x794b781493AeD65b9ceBD680716fec257e118993"],
18+
"publicKeyBase58": "7Lnm1ZnseKDkH1baAb1opREfAU4MPY7zCdUDSrWSm9NxNTQmy4neU9brFUYnEcyy7CwFKjD11ikyP9J8cf6zEaAKrEzzp"
19+
}
20+
]
21+
}
22+
```
23+
24+
# DID Method or DID schema
25+
26+
The DID method is a specific implementation of a DID scheme that will be identified by method name. For this case the method name is “polygon”, and the identifier is an Ethereum address.
27+
28+
## The DID for Polygon looks like:
29+
30+
### On Polygon mainnet
31+
32+
```
33+
did:polygon:0xdce5306fb5f9ba6797546dcd2e11eb5c5201bfeb
34+
```
35+
36+
### On Polygon testnet
37+
38+
```
39+
did:polygon:testnet:0xdce5306fb5f9ba6797546dcd2e11eb5c5201bfeb
40+
```
41+
42+
## DID On-Chain
43+
44+
Every DID on chain has the same structure, defined as:
45+
46+
Where,
47+
48+
- controller : the address of the person who creates and manages the DID
49+
- created : holds the timestamp of the block when DID was created
50+
- updated : initially holds the timestamp of when the DID was created, but is updated if the controller updates the DID on chain, and
51+
- doc : holds the entire DID document in form of string.
52+
53+
# DID Operations
54+
55+
## Create
56+
57+
Creating a createKeyPair refers to generation of a DID uri, based on a newly generated wallet.
58+
59+
```js
60+
import { createKeyPair } from 'polygon-did-registrar'
61+
const keys = await createKeyPair(network)
62+
```
63+
64+
The function returns address, privateKey, publicKeyBase58, did
65+
66+
## Register
67+
68+
Register of DID is done by logging the transaction on the polygon-register smart contract, by invoking
69+
70+
```js
71+
import { create } from 'polygon-did-registrar'
72+
const txHash = await create(did, didDoc)
73+
```
74+
75+
The function returns a txnHash and DID and didDoc on successful execution.
76+
77+
## Update
78+
79+
The DID controller requests for the update functionality, if the controller wishes to edit the did doc store on the ledger using :
80+
81+
```js
82+
import { update } from 'polygon-did-registrar'
83+
const txHash = await update(did, didDoc)
84+
```
85+
86+
## Add Resource
87+
88+
Add DID-linked resource for the DID-Doc.
89+
90+
```js
91+
import { addResource } from 'polygon-did-registrar'
92+
const txHash = await addResource(did, resourcePayload)
93+
```
94+
95+
The function returns a txhash, DID, and resourceId on successful execution.
96+
97+
## Update Resource
98+
99+
Update DID-linked resource for the DID-Doc.
100+
101+
```js
102+
import { updateResource } from 'polygon-did-registrar'
103+
const txHash = await updateResource(did, resourceId, resourcePayload)
104+
```
105+
106+
The function returns a txhash, DID, and resourceId on successful execution.
107+
108+
## Fetch Resource
109+
110+
Get a DID-linked resource for a specific DID.
111+
112+
```js
113+
import { getResourceByDidAndResourceId } from 'polygon-did-registrar'
114+
const txHash = await getResourceByDidAndResourceId(did, resourceId)
115+
```
116+
117+
The function returns DID-linked resource and DID uri on successful execution.
118+
119+
## Fetch all Resources
120+
121+
Get all DID-linked resources for a specific DID.
122+
123+
```js
124+
import { getResourcesByDid } from 'polygon-did-registrar'
125+
const txHash = await getResourcesByDid(did)
126+
```
127+
128+
The function returns the list of DID-linked resources and DID on successful execution.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Polygon DID Registry Contract
2+
3+
This library is an implementation of a registry contract that supports the Polygon DID Method.
4+
5+
## Overview
6+
7+
The Polygon registry contract acts as a public ledger, where the Polygon-Identity specified Decentralised Identifiers will be logged. The specifications related to polygon DID method are mentioned in the document. A DID generated using the Polygon DID generator, can be stored and managed on the ledger using this contract library.
8+
9+
## Contract Deployment
10+
11+
| Network | ChainId | Registry Address |
12+
| :--------------------: | :-----: | :----------------------------------------: |
13+
| Polygon Mainnet | 137 | 0x0C16958c4246271622201101C83B9F0Fc7180d15 |
14+
| Polygon Testnet (amoy) | 80002 | 0xcB80F37eDD2bE3570c6C9D5B0888614E04E1e49E |
15+
16+
## Methods
17+
18+
- `createDID(address, string)` : The method createDID is used to create and log a new DID on the polygon chain. The parameter of address type, will act as the reference key, to refer the did document stored on the chain. The string type variable will contain the did document, that will be stored on the matic chain.
19+
20+
- `updateDIDDoc(address, string)` : The method updateDID is included in contract, which will facilitate the controller, and only the controller of the did, to update the document if need arises. Though the Polygon DID method, defines how the DID doc is defined as per standards, and that can be resolved.
21+
22+
- `getDIDDoc(address)` : The method getDID helps to resolve the DID document.
23+
24+
- `transferOwnership(address)` : The method transferOwnership, helps in transferring the ownership of contract to a new owner. Only the current owner can access this function.
25+
26+
- `getOwner()` : the method getOwner helps one to fetch the current owner of the contract.
27+
28+
- `addResource(address, string, string)` : The addResource method allows the controller of a DID to add a linked resource to the DID document. This method ensures that only authorized controllers can add resources by requiring the caller to be the controller of the DID.
29+
30+
- `getResource(address, string)` : The getResource method fetches a specific linked resource from the blockchain that is associated with a given DID document.
31+
32+
- `getAllResources(address)` : The getAllResources method retrieves all resources linked to a specific DID document. This provides a comprehensive list of all resources associated with a given DID.
33+
34+
## Example ethers code
35+
36+
Using ethers, the following illustrates how one can interact with PolygonRegistry contract, from client side application.
37+
38+
## Loading the Contract
39+
40+
```
41+
const ethers = require('ethers');
42+
const url = https://rpc-amoy.polygon.technology; // For amoy testnet
43+
const DID_ADDRESS = `<Contract Address>`;
44+
const provider = new ethers.providers.JsonRpcProvider(url);
45+
46+
let wallet = new ethers.Wallet(`<Signer Key/Private Key>`, provider);
47+
let registry = new ethers.Contract(DID_ADDRESS, <Contract ABI>, wallet);
48+
```
49+
50+
# Deploying the Contract on Matic network
51+
52+
Pre-requisites
53+
54+
- NodeJS - https://nodejs.org/en/download/
55+
- Hardhat - https://hardhat.org
56+
- A wallet connected to polygon network, with Matic token in it. One can receive the Matic Test Tokens from their faucet.
57+
58+
## Deployment
59+
60+
Clone the repository
61+
62+
```
63+
git clone https://github.com/ayanworks/polygon-did-registry-contract.git
64+
```
65+
66+
Install Dependencies
67+
68+
```
69+
pnpm i
70+
```
71+
72+
Update your and RPC URL in .env file.
73+
74+
```
75+
MAINNET_RPCURL="<Place your Mainnet RPC URL here>"
76+
AMOY_RPCURL="<Place your Amoy RPC URL here>"
77+
SIGNER_TESTNET="<Place your Testnet Signer Key here>"
78+
SIGNER_MAINNET="<Place your Mainnet Signer Key here>"
79+
```
80+
81+
On a new console window run
82+
83+
```
84+
npx hardhat run deploy --network <network name>
85+
```
86+
87+
## Testing
88+
89+
For Testing use the command
90+
91+
```
92+
pnpm test
93+
```

packages/did-resolver/REAMDE.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Polygon DID Resolver
2+
3+
The polygon resolver library is used for resolving DID’s in Polygon Method Space. The module is supposed to be used as an integration to polygon library.
4+
5+
## Install
6+
7+
```
8+
pnpm install
9+
```
10+
11+
## Usage
12+
13+
In combination with the DID-Resolver:
14+
15+
```js
16+
import { resolveDID } from 'polygon-did-resolver'
17+
const didDocument = await resolveDID(did)
18+
```
19+
20+
The function returns a DID Document.
21+
22+
## Testing
23+
24+
For testing use the command
25+
26+
```
27+
pnpm run test
28+
```

0 commit comments

Comments
 (0)