@ayanworks/polygon-did-registry-contract 2.0.1-alpha.1 → 2.0.1-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/compile.ts CHANGED
@@ -34,9 +34,7 @@ function convertToHex(inputString: string) {
34
34
  return hex
35
35
  }
36
36
 
37
- const sourceHash = ethers.utils.sha256(
38
- '0x' + convertToHex(JSON.stringify(sources)),
39
- )
37
+ const sourceHash = ethers.sha256('0x' + convertToHex(JSON.stringify(sources)))
40
38
 
41
39
  console.log('\n'.repeat(process.stdout.rows))
42
40
 
@@ -19,33 +19,41 @@ contract PolygonDidRegistry {
19
19
  modifier onlyController(address _id) {
20
20
  require(
21
21
  polyDIDs[_id].controller == msg.sender,
22
- "message sender is not the controller of the DID Doc"
22
+ 'message sender is not the controller of the DID Doc'
23
23
  );
24
24
  _;
25
25
  }
26
26
  mapping(address => PolyDID) polyDIDs;
27
27
  mapping(uint256 => address) activeDIDs;
28
28
  mapping(address => uint256) activeAddress;
29
+
29
30
  event DIDCreated(address id, string doc);
30
31
  event DIDUpdated(address id, string doc);
31
- event DIDDeleted(address id);
32
32
  event TransferOwnership(address newOwner);
33
+ event ResourceAdded(
34
+ address _id,
35
+ string _resourceId,
36
+ string _resourcePayload
37
+ );
38
+
33
39
  bool private initialized;
34
40
 
35
41
  /**
36
42
  *@dev initializes the ownership of contract
37
43
  **/
38
44
 
45
+ mapping(address => string[]) private keysById;
46
+ mapping(address => mapping(string => string)) resourceData;
47
+
39
48
  function initialize() public {
40
- require(!initialized, "Contract instance has already been initialized");
49
+ require(!initialized, 'Contract instance has already been initialized');
41
50
  initialized = true;
42
51
  owner = msg.sender;
43
52
  totalDIDs = 0;
44
- deletedDID = 0;
45
53
  }
46
54
 
47
55
  modifier onlyOwner() {
48
- require(msg.sender == owner, "message sender is not the owner");
56
+ require(msg.sender == owner, 'message sender is not the owner');
49
57
  _;
50
58
  }
51
59
 
@@ -54,17 +62,15 @@ contract PolygonDidRegistry {
54
62
  *@param _newOwner - Address of the new owner to whom the ownership needs to be passed
55
63
  **/
56
64
 
57
- function transferOwnership(address _newOwner)
58
- public
59
- onlyOwner
60
- returns (string memory)
61
- {
65
+ function transferOwnership(
66
+ address _newOwner
67
+ ) public onlyOwner returns (string memory) {
62
68
  if (owner != _newOwner) {
63
69
  owner = _newOwner;
64
70
  emit TransferOwnership(owner);
65
- return ("Ownership transferred successfully");
71
+ return ('Ownership transferred successfully');
66
72
  } else {
67
- return ("Ownership cannot be transferred to the same account");
73
+ return ('Ownership cannot be transferred to the same account');
68
74
  }
69
75
  }
70
76
 
@@ -82,7 +88,10 @@ contract PolygonDidRegistry {
82
88
  *@param _doc - A string object that holds the DID Doc
83
89
  */
84
90
 
85
- function createDID(address _id, string memory _doc)
91
+ function createDID(
92
+ address _id,
93
+ string memory _doc
94
+ )
86
95
  public
87
96
  returns (
88
97
  address controller,
@@ -112,32 +121,23 @@ contract PolygonDidRegistry {
112
121
  *@param _id - Address that refers to the DID doc position
113
122
  */
114
123
 
115
- function getDIDDoc(address _id) public view returns (string memory) {
116
- return polyDIDs[_id].didDoc;
117
- }
118
-
119
- /**
120
- *@dev Reads total number of DIDs and total number of active DIDs from Chain
121
- */
124
+ function getDIDDoc(
125
+ address _id
126
+ ) public view returns (string memory, string[] memory) {
127
+ string[] memory result = new string[](keysById[_id].length);
122
128
 
123
- function getTotalNumberOfDIDs()
124
- public
125
- view
126
- returns (uint256 _totalDIDs, uint256 _activeDIDs)
127
- {
128
- return (totalDIDs, (totalDIDs - deletedDID));
129
+ for (uint256 i = 0; i < keysById[_id].length; i++) {
130
+ result[i] = resourceData[_id][keysById[_id][i]];
131
+ }
132
+ return (polyDIDs[_id].didDoc, result);
129
133
  }
130
134
 
131
135
  /**
132
- *@dev Reads total number of DIDs deleted from Chain
136
+ *@dev Reads total number of DIDs and total number of active DIDs from Chain
133
137
  */
134
138
 
135
- function getTotalNumberOfDeletedDIDs()
136
- public
137
- view
138
- returns (uint256 _deletedDID)
139
- {
140
- return deletedDID;
139
+ function getTotalNumberOfDIDs() public view returns (uint256 _totalDIDs) {
140
+ return (totalDIDs);
141
141
  }
142
142
 
143
143
  /**
@@ -146,11 +146,9 @@ contract PolygonDidRegistry {
146
146
  *@return _did - returns the DID Doc assciated with the index. Returns null if the DID Doc is deleted.
147
147
  */
148
148
 
149
- function getDIDDOcByIndex(uint256 _index)
150
- public
151
- view
152
- returns (string memory)
153
- {
149
+ function getDIDDocByIndex(
150
+ uint256 _index
151
+ ) public view returns (string memory) {
154
152
  return polyDIDs[activeDIDs[_index]].didDoc;
155
153
  }
156
154
 
@@ -160,7 +158,10 @@ contract PolygonDidRegistry {
160
158
  *@param _doc - A String that holds the DID doc
161
159
  */
162
160
 
163
- function updateDIDDoc(address _id, string memory _doc)
161
+ function updateDIDDoc(
162
+ address _id,
163
+ string memory _doc
164
+ )
164
165
  public
165
166
  onlyController(_id)
166
167
  returns (
@@ -182,14 +183,52 @@ contract PolygonDidRegistry {
182
183
  }
183
184
 
184
185
  /**
185
- *@dev To delete a DID from chain
186
- *@param _id - Address that refers to the DID doc that need to be deleted
186
+ *@dev To add linked resource in the DID doc
187
+ *@param _id - Address that refers to the DID doc
188
+ *@param _resourceId - Id that refers to the resource
189
+ */
190
+ function addResource(
191
+ address _id,
192
+ string memory _resourceId,
193
+ string memory _resourcePayload
194
+ )
195
+ public
196
+ onlyController(_id)
197
+ returns (address, string memory, string memory)
198
+ {
199
+ resourceData[_id][_resourceId] = _resourcePayload;
200
+ keysById[_id].push(_resourceId);
201
+ emit ResourceAdded(_id, _resourceId, _resourcePayload);
202
+ return (_id, _resourceId, _resourcePayload);
203
+ }
204
+
205
+ /**
206
+ *@dev Reads DID linked resource from Chain
207
+ *@param _id - Address that refers to the DID doc
208
+ *@param _resourceId - Id that refers to a specific resource
187
209
  */
188
210
 
189
- function deleteDIDDoc(address _id) public onlyController(_id) {
190
- delete polyDIDs[_id];
191
- delete activeDIDs[activeAddress[_id]];
192
- ++deletedDID;
193
- emit DIDDeleted(_id);
211
+ function getResource(
212
+ address _id,
213
+ string memory _resourceId
214
+ ) public view returns (string memory) {
215
+ return resourceData[_id][_resourceId];
216
+ }
217
+
218
+ /**
219
+ *@dev Reads all DID linked resource for a specific DID from Chain
220
+ *@param _id - Address that refers to the DID doc
221
+ */
222
+
223
+ function getAllResources(
224
+ address _id
225
+ ) public view returns (string[] memory) {
226
+ string[] memory result = new string[](keysById[_id].length);
227
+
228
+ for (uint256 i = 0; i < keysById[_id].length; i++) {
229
+ result[i] = resourceData[_id][keysById[_id][i]];
230
+ }
231
+
232
+ return result;
194
233
  }
195
- }
234
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @type import('hardhat/config').HardhatUserConfig
3
+ */
4
+
5
+ // import 'hardhat';
6
+ require('@nomicfoundation/hardhat-ethers')
7
+ require('@openzeppelin/hardhat-upgrades')
8
+
9
+ require('dotenv/config')
10
+
11
+ module.exports = {
12
+ solidity: {
13
+ version: '0.8.16',
14
+ settings: {
15
+ optimizer: {
16
+ enabled: true,
17
+ runs: 200,
18
+ },
19
+ },
20
+ },
21
+ networks: {
22
+ hardhat: {},
23
+ mumbai: {
24
+ url: process.env.RPCURL, // Update with Mumbai Matic RPC URL
25
+ accounts: [`0x${process.env.SIGNER}`],
26
+ },
27
+ },
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ayanworks/polygon-did-registry-contract",
3
- "version": "2.0.1-alpha.1",
3
+ "version": "2.0.1-alpha.3",
4
4
  "description": "Smart Contract to register DID on Polygon",
5
5
  "main": "build/index.js",
6
6
  "directories": {
@@ -11,9 +11,9 @@
11
11
  "test": "node compile.js && mocha --timeout 30000",
12
12
  "clean": "rm -rf build",
13
13
  "clean:deps": "pnpm clean && rm -rf node_modules",
14
- "build": "pnpm build:sol && tsc",
14
+ "build": "pnpm clean && pnpm build:sol && tsc",
15
15
  "build:sol": "node --require ts-node/register ./compile.ts",
16
- "prettier": "prettier --ignore-path .gitignore .",
16
+ "prettier": "prettier --ignore-path .prettierignore .",
17
17
  "check-format": "pnpm prettier --list-different",
18
18
  "check-types": "pnpm build --noEmit",
19
19
  "format": "pnpm prettier --write",
@@ -21,20 +21,19 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@openzeppelin/truffle-upgrades": "^1.15.0",
25
- "@truffle/hdwallet-provider": "^2.0.10",
24
+ "@nomicfoundation/hardhat-ethers": "^3.0.5",
25
+ "@openzeppelin/hardhat-upgrades": "^3.0.1",
26
26
  "@types/fs-extra": "^11.0.1",
27
27
  "@types/node": "^18.17.0",
28
28
  "dotenv": "^16.0.2",
29
29
  "eslint": "^8.23.1",
30
- "ethers": "^5.6.9",
30
+ "ethers": "^6.9.0",
31
31
  "fs-extra": "^11.1.1",
32
- "ganache-cli": "6.12.2",
32
+ "hardhat": "^2.19.4",
33
33
  "mocha": "^7.0.0",
34
34
  "prettier": "^3.0.2",
35
- "release-it": "^16.1.5",
35
+ "release-it": "^16.3.0",
36
36
  "solc": "^0.8.21",
37
- "truffle": "^5.5.20",
38
37
  "ts-node": "^10.9.1",
39
38
  "typescript": "^5.1.6"
40
39
  },
@@ -52,5 +51,6 @@
52
51
  "bugs": {
53
52
  "url": "https://github.com/ayanworks/polygon-did-registry-contract/issues"
54
53
  },
55
- "homepage": "https://github.com/ayanworks/polygon-did-registry-contract#readme"
54
+ "homepage": "https://github.com/ayanworks/polygon-did-registry-contract#readme",
55
+ "dependencies": {}
56
56
  }
@@ -0,0 +1,31 @@
1
+ const { ethers, upgrades } = require('hardhat')
2
+
3
+ async function main() {
4
+ try {
5
+ console.log('Deploying the smart contract...')
6
+ const PolygonDidRegistry =
7
+ await ethers.getContractFactory('PolygonDidRegistry')
8
+
9
+ // To deploy the initial upgradable smart contract
10
+
11
+ // const contract = await upgrades.deployProxy(PolygonDidRegistry, {
12
+ // initializer: 'initialize',
13
+ // })
14
+
15
+ const contract = await upgrades.upgradeProxy(
16
+ process.env.CONTRACT_ADDRESS,
17
+ PolygonDidRegistry,
18
+ {
19
+ initializer: 'initialize',
20
+ },
21
+ )
22
+
23
+ await contract.waitForDeployment()
24
+
25
+ console.log('Contract address::', contract.target)
26
+ } catch (error) {
27
+ console.error('Error deploying contract:', error.message)
28
+ }
29
+ }
30
+
31
+ main()
package/sst-config.json CHANGED
@@ -1 +1 @@
1
- {"sourceHash":"0xd34bb18b8a1a061e975b0850a1887bacdf0b8891d51e51399492bb038c05ff96"}
1
+ {"sourceHash":"0xb57d8b09722fddffbc5855f1dfba236305522e3e11aa91722f77789c16a9629b"}