|
| 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. |
0 commit comments