@velocitycareerlabs/metadata-registry-contract 1.25.0-dev-build.12642c864
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/.openzeppelin/unknown-1480.json +1336 -0
- package/.openzeppelin/unknown-1481.json +1199 -0
- package/.openzeppelin/unknown-1482.json +1198 -0
- package/.openzeppelin/unknown-1483.json +702 -0
- package/LICENSE +248 -0
- package/build/contracts/Migrations.json +1104 -0
- package/contracts/MetadataRegistry.sol +351 -0
- package/contracts/Migrations.sol +19 -0
- package/migration-status.js +42 -0
- package/migrations/10_vl-5092-use-check-operator-credential-type.js +19 -0
- package/migrations/11_vl-8185-allow-unknown-types.js +19 -0
- package/migrations/1_initial_migration.js +5 -0
- package/migrations/2_deploy_metadata.js +29 -0
- package/migrations/3_upgrade_metadata.js +44 -0
- package/migrations/4_upgrade_metadata.js +21 -0
- package/migrations/5_upgrade_metadata_send_msg_sender_burn.js +21 -0
- package/migrations/6_upgrade_metadata_add_permissions.js +18 -0
- package/migrations/7_vl-5477-signatures.js +19 -0
- package/migrations/8_vl-5480-signatures.js +19 -0
- package/migrations/9_vl-5092-new-permissions.js +19 -0
- package/package.json +43 -0
- package/test/.gitkeep +0 -0
- package/test/metadata-registry.test.js +1512 -0
- package/truffle-config.js +31 -0
@@ -0,0 +1,351 @@
|
|
1
|
+
pragma solidity 0.8.4;
|
2
|
+
pragma abicoder v2;
|
3
|
+
|
4
|
+
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
5
|
+
import "@velocitycareerlabs/verification-coupon-contract/contracts/VerificationCoupon.sol";
|
6
|
+
import "@velocitycareerlabs/permissions-contract/contracts/Permissions.sol";
|
7
|
+
import "@velocitycareerlabs/signature-verification-library/libraries/SignatureVerification.sol";
|
8
|
+
|
9
|
+
contract MetadataRegistry is Initializable {
|
10
|
+
VerificationCoupon internal Coupon;
|
11
|
+
|
12
|
+
struct CredentialEntry {
|
13
|
+
bytes2 credentialType;
|
14
|
+
bytes encryptedPublicKey;
|
15
|
+
bool used;
|
16
|
+
}
|
17
|
+
|
18
|
+
struct ListMetadata {
|
19
|
+
bytes2 version;
|
20
|
+
bytes2 algType;
|
21
|
+
bytes issuerVc;
|
22
|
+
bool used;
|
23
|
+
}
|
24
|
+
|
25
|
+
struct CredentialIdentifier {
|
26
|
+
address accountId;
|
27
|
+
uint256 listId;
|
28
|
+
uint32 index;
|
29
|
+
}
|
30
|
+
|
31
|
+
struct CredentialMetadata {
|
32
|
+
bytes2 version;
|
33
|
+
bytes2 credentialType;
|
34
|
+
bytes2 algType;
|
35
|
+
bytes encryptedPublicKey;
|
36
|
+
bytes issuerVc;
|
37
|
+
}
|
38
|
+
|
39
|
+
mapping(bytes2 => bool) public freeCredentialTypes;
|
40
|
+
mapping(address => mapping(uint256 => ListMetadata)) public lists;
|
41
|
+
mapping(address => mapping(uint256 => mapping(uint32 => CredentialEntry))) internal indexUsed;
|
42
|
+
|
43
|
+
Permissions internal permissions;
|
44
|
+
|
45
|
+
event CreatedMetadataList(address sender, bytes issuerVc, uint256 listId, string traceId, string caoDid);
|
46
|
+
event AddedCredentialMetadata(address sender, bytes issuerVc, uint256 listId, bytes2 credentialType, uint32 index, string traceId, string caoDid);
|
47
|
+
event GotCredentialMetadata(CredentialMetadata[] credentialMetadataList);
|
48
|
+
|
49
|
+
modifier onlyVnf() {
|
50
|
+
require(msg.sender == permissions.getVNF(), "Permissions: caller is not VNF");
|
51
|
+
_;
|
52
|
+
}
|
53
|
+
|
54
|
+
function initialize(address _coupon, bytes2[] memory freeCredentialTypesList) public initializer {
|
55
|
+
Coupon = VerificationCoupon(_coupon);
|
56
|
+
for (uint256 i = 0; i < freeCredentialTypesList.length; i++) {
|
57
|
+
freeCredentialTypes[freeCredentialTypesList[i]] = true;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
function setPermissionsAddress(address _permissions) public {
|
62
|
+
require(address(permissions) == address(0) || msg.sender == permissions.getVNF(), 'Permissions: caller is not VNF');
|
63
|
+
permissions = Permissions(_permissions);
|
64
|
+
}
|
65
|
+
|
66
|
+
function getPermissionsAddress() public view returns (address) {
|
67
|
+
return address(permissions);
|
68
|
+
}
|
69
|
+
|
70
|
+
function setCouponAddress(address _coupon) public {
|
71
|
+
require(msg.sender == Coupon.getVNF(), "The caller is not VNF");
|
72
|
+
Coupon = VerificationCoupon(_coupon);
|
73
|
+
}
|
74
|
+
|
75
|
+
function isExistMetadataList(address accountId, uint256 listId) public view returns (bool){
|
76
|
+
return lists[accountId][listId].used;
|
77
|
+
}
|
78
|
+
|
79
|
+
function newMetadataList(uint256 listId, bytes2 algType, bytes2 version, bytes memory issuerVc, string memory traceId, string memory caoDid) public {
|
80
|
+
newMetadataListInternal(listId, algType, version, issuerVc, traceId, caoDid, msg.sender);
|
81
|
+
}
|
82
|
+
|
83
|
+
function newMetadataListSigned(uint256 listId, bytes2 algType, bytes2 version, bytes memory issuerVc, string memory traceId, string memory caoDid, bytes memory signature) public {
|
84
|
+
address operator = SignatureVerification.recoverSigner(abi.encode(msg.sender), signature);
|
85
|
+
newMetadataListInternal(listId, algType, version, issuerVc, traceId, caoDid, operator);
|
86
|
+
}
|
87
|
+
|
88
|
+
function newMetadataListInternal(uint256 listId, bytes2 algType, bytes2 version, bytes memory issuerVc, string memory traceId, string memory caoDid, address operator) private {
|
89
|
+
address primary = permissions.checkOperator(operator);
|
90
|
+
require(!lists[primary][listId].used, "List id already used");
|
91
|
+
ListMetadata storage entries = lists[primary][listId];
|
92
|
+
entries.version = version;
|
93
|
+
entries.algType = algType;
|
94
|
+
entries.issuerVc = issuerVc;
|
95
|
+
entries.used = true;
|
96
|
+
emit CreatedMetadataList(primary, issuerVc, listId, traceId, caoDid);
|
97
|
+
}
|
98
|
+
|
99
|
+
function setEntry(
|
100
|
+
bytes2 credentialType,
|
101
|
+
bytes memory encryptedPublicKey,
|
102
|
+
uint256 listId,
|
103
|
+
uint32 index,
|
104
|
+
string memory traceId,
|
105
|
+
string memory caoDid
|
106
|
+
) public {
|
107
|
+
setEntryInternal(credentialType, encryptedPublicKey, listId, index, traceId, caoDid, msg.sender);
|
108
|
+
}
|
109
|
+
|
110
|
+
function setEntrySigned(
|
111
|
+
bytes2 credentialType,
|
112
|
+
bytes memory encryptedPublicKey,
|
113
|
+
uint256 listId,
|
114
|
+
uint32 index,
|
115
|
+
string memory traceId,
|
116
|
+
string memory caoDid,
|
117
|
+
bytes memory signature
|
118
|
+
) public {
|
119
|
+
address operator = SignatureVerification.recoverSigner(abi.encode(msg.sender), signature);
|
120
|
+
setEntryInternal(credentialType, encryptedPublicKey, listId, index, traceId, caoDid, operator);
|
121
|
+
}
|
122
|
+
|
123
|
+
function setEntryInternal(
|
124
|
+
bytes2 credentialType,
|
125
|
+
bytes memory encryptedPublicKey,
|
126
|
+
uint256 listId,
|
127
|
+
uint32 index,
|
128
|
+
string memory traceId,
|
129
|
+
string memory caoDid,
|
130
|
+
address operator
|
131
|
+
) private {
|
132
|
+
address primary = checkOperatorWithCredentialType(operator, credentialType);
|
133
|
+
require(index < 10000, "Invalid index");
|
134
|
+
require(!indexUsed[primary][listId][index].used, "Index already used");
|
135
|
+
require(lists[primary][listId].used, "List Id not aveliable");
|
136
|
+
CredentialEntry storage entryDataLocal = indexUsed[primary][listId][index];
|
137
|
+
entryDataLocal.credentialType = credentialType;
|
138
|
+
entryDataLocal.encryptedPublicKey = encryptedPublicKey;
|
139
|
+
entryDataLocal.used = true;
|
140
|
+
emit AddedCredentialMetadata(primary, lists[primary][listId].issuerVc, listId, credentialType, index, traceId, caoDid);
|
141
|
+
}
|
142
|
+
|
143
|
+
function addFreeTypes(bytes2[] memory freeCredentialTypesList) public {
|
144
|
+
require(msg.sender == Coupon.getVNF(), "The caller is not VNF");
|
145
|
+
for (uint256 i = 0; i < freeCredentialTypesList.length; i++) {
|
146
|
+
freeCredentialTypes[freeCredentialTypesList[i]] = true;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
function removeFreeTypes(bytes2[] memory freeCredentialTypesList) public {
|
151
|
+
require(msg.sender == Coupon.getVNF(), "The caller is not VNF");
|
152
|
+
for (uint256 i = 0; i < freeCredentialTypesList.length; i++) {
|
153
|
+
delete freeCredentialTypes[freeCredentialTypesList[i]];
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
function isFreeCredentialType(bytes2 credentialType) public view returns (bool){
|
158
|
+
return freeCredentialTypes[credentialType];
|
159
|
+
}
|
160
|
+
|
161
|
+
function isFreeGetEntries(CredentialMetadata[] memory entries) private view returns (bool){
|
162
|
+
for (uint256 i = 0; i < entries.length; i++) {
|
163
|
+
if (!isFreeCredentialType(entries[i].credentialType)) {
|
164
|
+
return false;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
return true;
|
168
|
+
}
|
169
|
+
|
170
|
+
function _getEntries(
|
171
|
+
CredentialIdentifier[] memory _entryIndexes
|
172
|
+
) private view returns (CredentialMetadata[] memory) {
|
173
|
+
CredentialMetadata[] memory entries = new CredentialMetadata[](
|
174
|
+
_entryIndexes.length
|
175
|
+
);
|
176
|
+
for (uint256 i = 0; i < _entryIndexes.length; i++) {
|
177
|
+
require(lists[_entryIndexes[i].accountId][_entryIndexes[i].listId].used, "List id not used");
|
178
|
+
require(indexUsed[_entryIndexes[i].accountId][_entryIndexes[i].listId][_entryIndexes[i].index].used, "Index not used");
|
179
|
+
entries[i].version = lists[_entryIndexes[i].accountId][_entryIndexes[i].listId].version;
|
180
|
+
entries[i].credentialType = indexUsed[_entryIndexes[i].accountId][_entryIndexes[i].listId][_entryIndexes[i].index].credentialType;
|
181
|
+
entries[i].algType = lists[_entryIndexes[i].accountId][_entryIndexes[i].listId].algType;
|
182
|
+
entries[i].encryptedPublicKey = indexUsed[_entryIndexes[i].accountId][_entryIndexes[i].listId][_entryIndexes[i].index].encryptedPublicKey;
|
183
|
+
entries[i].issuerVc = lists[_entryIndexes[i].accountId][_entryIndexes[i].listId].issuerVc;
|
184
|
+
}
|
185
|
+
return entries;
|
186
|
+
}
|
187
|
+
|
188
|
+
function getFreeEntries(
|
189
|
+
CredentialIdentifier[] memory _entryIndexes
|
190
|
+
) public view returns (CredentialMetadata[] memory) {
|
191
|
+
CredentialMetadata[] memory entries = _getEntries(_entryIndexes);
|
192
|
+
require(isFreeGetEntries(entries), 'Only free creadential types is allowed without coupon');
|
193
|
+
return entries;
|
194
|
+
}
|
195
|
+
|
196
|
+
function getPaidEntries(
|
197
|
+
CredentialIdentifier[] memory _entryIndexes,
|
198
|
+
string memory traceId,
|
199
|
+
string memory caoDid,
|
200
|
+
string memory burnerDid
|
201
|
+
) public {
|
202
|
+
getPaidEntriesInternal(_entryIndexes, traceId, caoDid, burnerDid, msg.sender);
|
203
|
+
}
|
204
|
+
|
205
|
+
function getPaidEntriesSigned(
|
206
|
+
CredentialIdentifier[] memory _entryIndexes,
|
207
|
+
string memory traceId,
|
208
|
+
string memory caoDid,
|
209
|
+
string memory burnerDid,
|
210
|
+
bytes memory signature
|
211
|
+
) public {
|
212
|
+
address operator = SignatureVerification.recoverSigner(abi.encode(msg.sender), signature);
|
213
|
+
getPaidEntriesInternal(_entryIndexes, traceId, caoDid, burnerDid, operator);
|
214
|
+
}
|
215
|
+
|
216
|
+
function getPaidEntriesInternal(
|
217
|
+
CredentialIdentifier[] memory _entryIndexes,
|
218
|
+
string memory traceId,
|
219
|
+
string memory caoDid,
|
220
|
+
string memory burnerDid,
|
221
|
+
address operator
|
222
|
+
) private {
|
223
|
+
CredentialMetadata[] memory entries = _getEntries(_entryIndexes);
|
224
|
+
require(!isFreeGetEntries(entries), 'No paid creadential types');
|
225
|
+
uint256 _coupon = Coupon.getTokenId(operator);
|
226
|
+
Coupon.burn(_coupon, traceId, caoDid, burnerDid, operator);
|
227
|
+
emit GotCredentialMetadata(entries);
|
228
|
+
}
|
229
|
+
|
230
|
+
function checkOperatorWithCredentialType(address operator, bytes2 credentialType) public view returns (address) {
|
231
|
+
string memory permission = getPermissionOfCredentialTypeHash(credentialType);
|
232
|
+
try permissions.checkOperatorPermission(operator, permission) returns (address primary) {
|
233
|
+
return primary;
|
234
|
+
} catch Error(string memory reason) {
|
235
|
+
require(isEqual(reason, "Permissions: primary of operator lacks requested permission"), reason);
|
236
|
+
require(false, buildCheckOperatorPermissionError(permission));
|
237
|
+
}
|
238
|
+
return address(0);
|
239
|
+
}
|
240
|
+
|
241
|
+
function getPermissionOfCredentialTypeHash(bytes2 credentialType) private pure returns (string memory) {
|
242
|
+
string memory permissionCredentialIssue = "credential:issue";
|
243
|
+
string memory permissionCredentialIdentityIssue = "credential:identityissue";
|
244
|
+
string memory permissionCredentialContactIssue = "credential:contactissue";
|
245
|
+
string memory fallbackPermission = permissionCredentialIssue;
|
246
|
+
if (credentialType == 0x7808) {return permissionCredentialIssue;}
|
247
|
+
// Assessment
|
248
|
+
else if (credentialType == 0x41ec) {return permissionCredentialIssue;}
|
249
|
+
// AssessmentV1.0
|
250
|
+
else if (credentialType == 0xaf29) {return permissionCredentialIssue;}
|
251
|
+
// AssessmentV1.1
|
252
|
+
else if (credentialType == 0x0024) {return permissionCredentialIssue;}
|
253
|
+
// Badge
|
254
|
+
else if (credentialType == 0xc184) {return permissionCredentialIssue;}
|
255
|
+
// BadgeV1.1
|
256
|
+
else if (credentialType == 0x8684) {return permissionCredentialIssue;}
|
257
|
+
// Certification
|
258
|
+
else if (credentialType == 0x5df0) {return permissionCredentialIssue;}
|
259
|
+
// CertificationV1.0
|
260
|
+
else if (credentialType == 0xade9) {return permissionCredentialIssue;}
|
261
|
+
// CertificationV1.1
|
262
|
+
else if (credentialType == 0x2096) {return permissionCredentialIssue;}
|
263
|
+
// Course
|
264
|
+
else if (credentialType == 0xb037) {return permissionCredentialIssue;}
|
265
|
+
// CourseAttendanceV1.0
|
266
|
+
else if (credentialType == 0xc385) {return permissionCredentialIssue;}
|
267
|
+
// CourseAttendanceV1.1
|
268
|
+
else if (credentialType == 0x5f0e) {return permissionCredentialIssue;}
|
269
|
+
// CourseCompletionV1.0
|
270
|
+
else if (credentialType == 0x4b80) {return permissionCredentialIssue;}
|
271
|
+
// CourseCompletionV1.1
|
272
|
+
else if (credentialType == 0xf2dc) {return permissionCredentialIssue;}
|
273
|
+
// CourseRegistrationV1.0
|
274
|
+
else if (credentialType == 0x955b) {return permissionCredentialIssue;}
|
275
|
+
// CourseRegistrationV1.1
|
276
|
+
else if (credentialType == 0x7516) {return permissionCredentialIssue;}
|
277
|
+
// CurrentEmploymentPosition
|
278
|
+
else if (credentialType == 0xeea2) {return permissionCredentialIdentityIssue;}
|
279
|
+
// DriversLicenseV1.0
|
280
|
+
else if (credentialType == 0xb89f) {return permissionCredentialIssue;}
|
281
|
+
// EducationDegree
|
282
|
+
else if (credentialType == 0x294a) {return permissionCredentialIssue;}
|
283
|
+
// EducationDegreeGraduationV1.0
|
284
|
+
else if (credentialType == 0x8642) {return permissionCredentialIssue;}
|
285
|
+
// EducationDegreeGraduationV1.1
|
286
|
+
else if (credentialType == 0x9b9f) {return permissionCredentialIssue;}
|
287
|
+
// EducationDegreeRegistrationV1.0
|
288
|
+
else if (credentialType == 0x5ab6) {return permissionCredentialIssue;}
|
289
|
+
// EducationDegreeRegistrationV1.1
|
290
|
+
else if (credentialType == 0xb139) {return permissionCredentialIssue;}
|
291
|
+
// EducationDegreeStudyV1.0
|
292
|
+
else if (credentialType == 0xa214) {return permissionCredentialIssue;}
|
293
|
+
// EducationDegreeStudyV1.1
|
294
|
+
else if (credentialType == 0x969c) {return permissionCredentialContactIssue;}
|
295
|
+
// Email
|
296
|
+
else if (credentialType == 0x8f07) {return permissionCredentialContactIssue;}
|
297
|
+
// EmailV1.0
|
298
|
+
else if (credentialType == 0x764c) {return permissionCredentialIssue;}
|
299
|
+
// EmploymentCurrentV1.0
|
300
|
+
else if (credentialType == 0xdb4c) {return permissionCredentialIssue;}
|
301
|
+
// EmploymentCurrentV1.1
|
302
|
+
else if (credentialType == 0x7e15) {return permissionCredentialIssue;}
|
303
|
+
// EmploymentPastV1.0
|
304
|
+
else if (credentialType == 0xf4aa) {return permissionCredentialIssue;}
|
305
|
+
// EmploymentPastV1.1
|
306
|
+
else if (credentialType == 0x851f) {return permissionCredentialIdentityIssue;}
|
307
|
+
// IdDocument
|
308
|
+
else if (credentialType == 0xfeab) {return permissionCredentialIdentityIssue;}
|
309
|
+
// IdDocumentV1.0
|
310
|
+
else if (credentialType == 0xefca) {return permissionCredentialIssue;}
|
311
|
+
// LicenseV1.0
|
312
|
+
else if (credentialType == 0xd8ae) {return permissionCredentialIssue;}
|
313
|
+
// LicenseV1.1
|
314
|
+
else if (credentialType == 0xdeef) {return permissionCredentialIdentityIssue;}
|
315
|
+
// NationalIdCardV1.0
|
316
|
+
else if (credentialType == 0x2936) {return permissionCredentialIssue;}
|
317
|
+
// OpenBadgeCredential
|
318
|
+
else if (credentialType == 0x86bf) {return permissionCredentialIssue;}
|
319
|
+
// OpenBadgeV1.0
|
320
|
+
else if (credentialType == 0x5b0e) {return permissionCredentialIssue;}
|
321
|
+
// OpenBadgeV2.0
|
322
|
+
else if (credentialType == 0x7b17) {return permissionCredentialIdentityIssue;}
|
323
|
+
// PassportV1.0
|
324
|
+
else if (credentialType == 0x29d2) {return permissionCredentialIssue;}
|
325
|
+
// PastEmploymentPosition
|
326
|
+
else if (credentialType == 0x63dc) {return permissionCredentialContactIssue;}
|
327
|
+
// Phone
|
328
|
+
else if (credentialType == 0x4ffb) {return permissionCredentialContactIssue;}
|
329
|
+
// PhoneV1.0
|
330
|
+
else if (credentialType == 0xf052) {return permissionCredentialIssue;}
|
331
|
+
// ProofOfAgeV1.0
|
332
|
+
else if (credentialType == 0xa004) {return permissionCredentialIdentityIssue;}
|
333
|
+
// ResidentPermitV1.0
|
334
|
+
return fallbackPermission;
|
335
|
+
}
|
336
|
+
|
337
|
+
function buildCheckOperatorPermissionError(string memory permission) private pure returns (string memory) {
|
338
|
+
if (isEqual(permission, "credential:issue")) {
|
339
|
+
return "Permissions: primary of operator lacks credential:issue permission";
|
340
|
+
} else if (isEqual(permission, "credential:identityissue")) {
|
341
|
+
return "Permissions: primary of operator lacks credential:identityissue permission";
|
342
|
+
} else if (isEqual(permission, "credential:contactissue")) {
|
343
|
+
return "Permissions: primary of operator lacks credential:contactissue permission";
|
344
|
+
}
|
345
|
+
return "Permissions: primary of operator lacks permission for credentialType";
|
346
|
+
}
|
347
|
+
|
348
|
+
function isEqual(string memory a, string memory b) public pure returns (bool) {
|
349
|
+
return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))));
|
350
|
+
}
|
351
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity 0.8.4;
|
3
|
+
|
4
|
+
contract Migrations {
|
5
|
+
address public owner = msg.sender;
|
6
|
+
uint public last_completed_migration;
|
7
|
+
|
8
|
+
modifier restricted() {
|
9
|
+
require(
|
10
|
+
msg.sender == owner,
|
11
|
+
"This function is restricted to the contract's owner"
|
12
|
+
);
|
13
|
+
_;
|
14
|
+
}
|
15
|
+
|
16
|
+
function setCompleted(uint completed) public restricted {
|
17
|
+
last_completed_migration = completed;
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
const Web3 = require('web3');
|
2
|
+
const Migrations = require('./build/contracts/Migrations.json');
|
3
|
+
const truffleConfig = require('./truffle-config');
|
4
|
+
|
5
|
+
const cmd = process.argv[2] || 'get';
|
6
|
+
const env = process.argv[3] || 'localdocker';
|
7
|
+
const value = process.argv[4] || '1';
|
8
|
+
const networkId = truffleConfig.networks[env].network_id;
|
9
|
+
|
10
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
11
|
+
|
12
|
+
const config = {
|
13
|
+
contractAddress: Migrations.networks[networkId].address,
|
14
|
+
provider: truffleConfig.networks[env].provider,
|
15
|
+
gas: truffleConfig.networks[env].gas,
|
16
|
+
gasPrice: truffleConfig.networks[env].gasPrice,
|
17
|
+
};
|
18
|
+
|
19
|
+
const main = async () => {
|
20
|
+
const web3 = new Web3(config.provider);
|
21
|
+
|
22
|
+
const instance = new web3.eth.Contract(
|
23
|
+
Migrations.abi,
|
24
|
+
config.contractAddress
|
25
|
+
);
|
26
|
+
|
27
|
+
if (cmd === 'set') {
|
28
|
+
await instance.methods.setCompleted(value).send({
|
29
|
+
from: config.provider.addresses[0],
|
30
|
+
gas: config.gas,
|
31
|
+
gasPrice: config.gasPrice,
|
32
|
+
});
|
33
|
+
}
|
34
|
+
|
35
|
+
const lastCompletedMigration = await instance.methods
|
36
|
+
.last_completed_migration()
|
37
|
+
.call();
|
38
|
+
// eslint-disable-next-line no-console
|
39
|
+
console.log('last_completed_migration:', lastCompletedMigration);
|
40
|
+
};
|
41
|
+
|
42
|
+
main();
|
@@ -0,0 +1,19 @@
|
|
1
|
+
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
|
2
|
+
const truffleConfig = require('../truffle-config');
|
3
|
+
|
4
|
+
const MetadataRegistry = artifacts.require('MetadataRegistry');
|
5
|
+
|
6
|
+
const env = process.argv[4] || 'localdocker';
|
7
|
+
const networkId = truffleConfig.networks[env].network_id;
|
8
|
+
|
9
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
10
|
+
|
11
|
+
const contractAddress = require(`../.openzeppelin/unknown-${networkId}.json`)
|
12
|
+
.proxies[0].address;
|
13
|
+
|
14
|
+
module.exports = async (deployer) => {
|
15
|
+
const instance = await upgradeProxy(contractAddress, MetadataRegistry, {
|
16
|
+
deployer,
|
17
|
+
});
|
18
|
+
console.log('Upgraded:', instance.address);
|
19
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
|
2
|
+
const truffleConfig = require('../truffle-config');
|
3
|
+
|
4
|
+
const MetadataRegistry = artifacts.require('MetadataRegistry');
|
5
|
+
|
6
|
+
const env = process.argv[4] || 'localdocker';
|
7
|
+
const networkId = truffleConfig.networks[env].network_id;
|
8
|
+
|
9
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
10
|
+
|
11
|
+
const contractAddress = require(`../.openzeppelin/unknown-${networkId}.json`)
|
12
|
+
.proxies[0].address;
|
13
|
+
|
14
|
+
module.exports = async (deployer) => {
|
15
|
+
const instance = await upgradeProxy(contractAddress, MetadataRegistry, {
|
16
|
+
deployer,
|
17
|
+
});
|
18
|
+
console.log('Upgraded:', instance.address);
|
19
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
const { map } = require('lodash/fp');
|
3
|
+
const {
|
4
|
+
createHash,
|
5
|
+
} = require('crypto');
|
6
|
+
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
|
7
|
+
const MetadataRegistry = artifacts.require('MetadataRegistry');
|
8
|
+
const truffleConfig = require('../truffle-config.js');
|
9
|
+
|
10
|
+
const freeCredentialTypesList = ['Email', 'EmailV1.0', 'Phone', 'PhoneV1.0', 'IdDocument', 'IdDocumentV1.0', 'PassportV1.0', 'DriversLicenseV1.0', 'NationalIdCardV1.0', 'ProofOfAgeV1.0', 'ResidentPermitV1.0', 'VerificationIdentifier']
|
11
|
+
|
12
|
+
const get2BytesHash = (value) => {
|
13
|
+
return `0x${createHash('sha256').update(value).digest('hex').slice(0, 4)}`;
|
14
|
+
};
|
15
|
+
const env = process.argv[4] || 'localdocker';
|
16
|
+
const networkId = truffleConfig.networks[env].network_id;
|
17
|
+
|
18
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
19
|
+
|
20
|
+
|
21
|
+
const couponContractAddressV1 = require(`../../verification-coupon/.openzeppelin/unknown-${networkId}.json`).proxies[0].address;
|
22
|
+
|
23
|
+
module.exports = async function (deployer) {
|
24
|
+
const instance = await deployProxy(MetadataRegistry, [
|
25
|
+
couponContractAddressV1,
|
26
|
+
map(get2BytesHash, freeCredentialTypesList)
|
27
|
+
], { deployer });
|
28
|
+
console.log('Deployed', instance.address);
|
29
|
+
};
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
const { map } = require('lodash/fp');
|
3
|
+
const {
|
4
|
+
createHash,
|
5
|
+
} = require('crypto');
|
6
|
+
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
|
7
|
+
const truffleConfig = require('../truffle-config.js');
|
8
|
+
const MetadataRegistry = artifacts.require('MetadataRegistry');
|
9
|
+
|
10
|
+
const get2BytesHash = (value) => {
|
11
|
+
return `0x${createHash('sha256').update(value).digest('hex').slice(0, 4)}`;
|
12
|
+
};
|
13
|
+
|
14
|
+
const env = process.argv[4] || 'localdocker';
|
15
|
+
const networkId = truffleConfig.networks[env].network_id;
|
16
|
+
|
17
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
18
|
+
const contractAddress = require(`../.openzeppelin/unknown-${networkId}.json`).proxies[0].address
|
19
|
+
console.log('contractAddress', contractAddress)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
module.exports = async function (deployer) {
|
24
|
+
const instance = await upgradeProxy(contractAddress, MetadataRegistry, { deployer });
|
25
|
+
console.log("Upgraded", instance.address);
|
26
|
+
|
27
|
+
const newFreeCredentialTypes = map(get2BytesHash, ['DriversLicenseV1.0']);
|
28
|
+
const currentFreeCredentialTypes = map(get2BytesHash, ['DrivingLicenseV1.0']);
|
29
|
+
|
30
|
+
const statusBefore = await Promise.all([
|
31
|
+
instance.isFreeCredentialType(newFreeCredentialTypes[0]),
|
32
|
+
instance.isFreeCredentialType(currentFreeCredentialTypes[0])
|
33
|
+
]);
|
34
|
+
console.log("isFreeCredentialType() of the new / current credentials: ", statusBefore);
|
35
|
+
|
36
|
+
await instance.addFreeTypes(newFreeCredentialTypes);
|
37
|
+
await instance.removeFreeTypes(currentFreeCredentialTypes);
|
38
|
+
|
39
|
+
const statusAfter = await Promise.all([
|
40
|
+
instance.isFreeCredentialType(newFreeCredentialTypes[0]),
|
41
|
+
instance.isFreeCredentialType(currentFreeCredentialTypes[0])
|
42
|
+
]);
|
43
|
+
console.log("isFreeCredentialType() of the new / current credentials: ", statusAfter);
|
44
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
|
3
|
+
const truffleConfig = require('../truffle-config.js');
|
4
|
+
const MetadataRegistry = artifacts.require('MetadataRegistry');
|
5
|
+
|
6
|
+
const env = process.argv[4] || 'localdocker';
|
7
|
+
const networkId = truffleConfig.networks[env].network_id;
|
8
|
+
|
9
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
10
|
+
|
11
|
+
|
12
|
+
const couponContractAddressV2 = require(`../../verification-coupon/.openzeppelin/unknown-${networkId}.json`).proxies[1].address;
|
13
|
+
const contractAddress = require(`../.openzeppelin/unknown-${networkId}.json`).proxies[0].address
|
14
|
+
console.log('contractAddress', contractAddress, 'couponContractAddressV2', couponContractAddressV2)
|
15
|
+
|
16
|
+
module.exports = async function (deployer) {
|
17
|
+
const instance = await upgradeProxy(contractAddress, MetadataRegistry, { deployer });
|
18
|
+
await instance.setCouponAddress(couponContractAddressV2);
|
19
|
+
console.log("Upgraded:", instance.address);
|
20
|
+
console.log("Set couponContractAddressV2:", couponContractAddressV2);
|
21
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
const {upgradeProxy} = require('@openzeppelin/truffle-upgrades');
|
2
|
+
const truffleConfig = require('../truffle-config.js');
|
3
|
+
const MetadataRegistry = artifacts.require('MetadataRegistry');
|
4
|
+
const Permissions = artifacts.require('../../permissions/contracts/Permissions')
|
5
|
+
|
6
|
+
const env = process.argv[4] || 'localdocker';
|
7
|
+
const networkId = truffleConfig.networks[env].network_id;
|
8
|
+
|
9
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
10
|
+
|
11
|
+
const contractAddress = require(`../.openzeppelin/unknown-${networkId}.json`).proxies[0].address
|
12
|
+
const permissionsContractAddress = require(`../../permissions/.openzeppelin/unknown-${networkId}.json`).proxies[0].address
|
13
|
+
|
14
|
+
module.exports = async function (deployer) {
|
15
|
+
const instance = await upgradeProxy(contractAddress, MetadataRegistry, {deployer});
|
16
|
+
console.log("Upgraded:", instance.address);
|
17
|
+
const permissionsInstance = await Permissions.at(permissionsContractAddress)
|
18
|
+
await permissionsInstance.addAddressScope(instance.address, "coupon:burn")
|
19
|
+
const hasScope = await permissionsInstance.checkAddressScope(instance.address, "coupon:burn")
|
20
|
+
console.log(`Metadata Registry Contract at ${instance.address} add "coupon:burn" result: ${hasScope}`)
|
21
|
+
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
const {upgradeProxy} = require('@openzeppelin/truffle-upgrades');
|
2
|
+
const truffleConfig = require('../truffle-config.js');
|
3
|
+
const MetadataRegistry = artifacts.require('MetadataRegistry');
|
4
|
+
|
5
|
+
const env = process.argv[4] || 'localdocker';
|
6
|
+
const networkId = truffleConfig.networks[env].network_id;
|
7
|
+
|
8
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
9
|
+
|
10
|
+
const contractAddress = require(`../.openzeppelin/unknown-${networkId}.json`).proxies[0].address
|
11
|
+
const permissionsContractAddress = require(`../../permissions/.openzeppelin/unknown-${networkId}.json`).proxies[0].address
|
12
|
+
|
13
|
+
module.exports = async function (deployer) {
|
14
|
+
const instance = await upgradeProxy(contractAddress, MetadataRegistry, {deployer});
|
15
|
+
console.log("Upgraded:", instance.address);
|
16
|
+
await instance.setPermissionsAddress(permissionsContractAddress)
|
17
|
+
console.log(`Metadata Registry Contract at ${instance.address} Permission Contract instance set to: ${permissionsContractAddress}`)
|
18
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
|
2
|
+
const truffleConfig = require('../truffle-config');
|
3
|
+
|
4
|
+
const MetadataRegistry = artifacts.require('MetadataRegistry');
|
5
|
+
|
6
|
+
const env = process.argv[4] || 'localdocker';
|
7
|
+
const networkId = truffleConfig.networks[env].network_id;
|
8
|
+
|
9
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
10
|
+
|
11
|
+
const contractAddress = require(`../.openzeppelin/unknown-${networkId}.json`)
|
12
|
+
.proxies[0].address;
|
13
|
+
|
14
|
+
module.exports = async (deployer) => {
|
15
|
+
const instance = await upgradeProxy(contractAddress, MetadataRegistry, {
|
16
|
+
deployer,
|
17
|
+
});
|
18
|
+
console.log('Upgraded:', instance.address);
|
19
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
|
2
|
+
const truffleConfig = require('../truffle-config');
|
3
|
+
|
4
|
+
const MetadataRegistry = artifacts.require('MetadataRegistry');
|
5
|
+
|
6
|
+
const env = process.argv[4] || 'localdocker';
|
7
|
+
const networkId = truffleConfig.networks[env].network_id;
|
8
|
+
|
9
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
10
|
+
|
11
|
+
const contractAddress = require(`../.openzeppelin/unknown-${networkId}.json`)
|
12
|
+
.proxies[0].address;
|
13
|
+
|
14
|
+
module.exports = async (deployer) => {
|
15
|
+
const instance = await upgradeProxy(contractAddress, MetadataRegistry, {
|
16
|
+
deployer,
|
17
|
+
});
|
18
|
+
console.log('Upgraded:', instance.address);
|
19
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
|
2
|
+
const truffleConfig = require('../truffle-config');
|
3
|
+
|
4
|
+
const MetadataRegistry = artifacts.require('MetadataRegistry');
|
5
|
+
|
6
|
+
const env = process.argv[4] || 'localdocker';
|
7
|
+
const networkId = truffleConfig.networks[env].network_id;
|
8
|
+
|
9
|
+
console.log(`ENV: ${env} Network Id: ${networkId}`);
|
10
|
+
|
11
|
+
const contractAddress = require(`../.openzeppelin/unknown-${networkId}.json`)
|
12
|
+
.proxies[0].address;
|
13
|
+
|
14
|
+
module.exports = async (deployer) => {
|
15
|
+
const instance = await upgradeProxy(contractAddress, MetadataRegistry, {
|
16
|
+
deployer,
|
17
|
+
});
|
18
|
+
console.log('Upgraded:', instance.address);
|
19
|
+
};
|