@ethernity-cloud/sdk-js 1.6.1 → 1.6.2
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/README.md +3 -3
- package/cas/config.js +2 -2
- package/info.js +324 -324
- package/nodenithy/build/securelock/src/securelock.js.tmpl +5 -2
- package/nodenithy/build.mjs +3 -3
- package/nodenithy/run/image_registry.js +383 -380
- package/package.json +2 -2
- package/pynithy/build/securelock/src/securelock.py.tmpl +6 -2
- package/pynithy/build.mjs +3 -3
- package/pynithy/run/image_registry.js +383 -380
|
@@ -1,381 +1,384 @@
|
|
|
1
|
-
const Web3 = require('web3');
|
|
2
|
-
const { ethers } = require('ethers');
|
|
3
|
-
const { Account } = require('eth-lib/lib/account');
|
|
4
|
-
const { config } = require('dotenv');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
|
|
8
|
-
config();
|
|
9
|
-
|
|
10
|
-
const PRIVATE_KEY = process.env.PRIVATE_KEY || "";
|
|
11
|
-
let BLOCKCHAIN_NETWORK = process.env.BLOCKCHAIN_NETWORK || "Bloxberg_Testnet";
|
|
12
|
-
let NETWORK_RPC = "https://bloxberg.ethernity.cloud";
|
|
13
|
-
let IMAGE_REGISTRY_ADDRESS = "
|
|
14
|
-
let CHAIN_ID = 8995;
|
|
15
|
-
let GAS = 9000000;
|
|
16
|
-
let GAS_PRICE = 1;
|
|
17
|
-
|
|
18
|
-
function setVars(network = "") {
|
|
19
|
-
if (BLOCKCHAIN_NETWORK.includes("Bloxberg")) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.acct = new ethers.Wallet(
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
this.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// console.log("
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
console.log("
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
// console.log("
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
console.log("
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
// const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
//
|
|
183
|
-
|
|
184
|
-
console.log(
|
|
185
|
-
// const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
// console.
|
|
275
|
-
return
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const
|
|
326
|
-
console.log(`
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
//
|
|
334
|
-
//
|
|
335
|
-
//
|
|
336
|
-
//
|
|
337
|
-
//
|
|
338
|
-
//
|
|
339
|
-
//
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
1
|
+
const Web3 = require('web3');
|
|
2
|
+
const { ethers } = require('ethers');
|
|
3
|
+
const { Account } = require('eth-lib/lib/account');
|
|
4
|
+
const { config } = require('dotenv');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
config();
|
|
9
|
+
|
|
10
|
+
const PRIVATE_KEY = process.env.PRIVATE_KEY || "";
|
|
11
|
+
let BLOCKCHAIN_NETWORK = process.env.BLOCKCHAIN_NETWORK || "Bloxberg_Testnet";
|
|
12
|
+
let NETWORK_RPC = "https://bloxberg.ethernity.cloud";
|
|
13
|
+
let IMAGE_REGISTRY_ADDRESS = "0x99A84C624C028bdf0a855A1E9E3f2fcf7275B3D8"; // bloxberg testnet (ECImageRegistryV2)
|
|
14
|
+
let CHAIN_ID = 8995;
|
|
15
|
+
let GAS = 9000000;
|
|
16
|
+
let GAS_PRICE = 1;
|
|
17
|
+
|
|
18
|
+
function setVars(network = "") {
|
|
19
|
+
if (BLOCKCHAIN_NETWORK.includes("Bloxberg")) {
|
|
20
|
+
// The bloxberg testnet reads ECImageRegistryV2; mainnet the original registry.
|
|
21
|
+
IMAGE_REGISTRY_ADDRESS = BLOCKCHAIN_NETWORK.includes("Testnet")
|
|
22
|
+
? "0x99A84C624C028bdf0a855A1E9E3f2fcf7275B3D8"
|
|
23
|
+
: "0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31";
|
|
24
|
+
} else if (BLOCKCHAIN_NETWORK.includes("Polygon")) {
|
|
25
|
+
if (BLOCKCHAIN_NETWORK.includes("Mainnet")) {
|
|
26
|
+
NETWORK_RPC = "https://polygon-rpc.com";
|
|
27
|
+
IMAGE_REGISTRY_ADDRESS = "0x689f3806874d3c8A973f419a4eB24e6fBA7E830F";
|
|
28
|
+
CHAIN_ID = 137;
|
|
29
|
+
GAS = 20000000;
|
|
30
|
+
GAS_PRICE = 40500500010;
|
|
31
|
+
} else {
|
|
32
|
+
NETWORK_RPC = "https://polygon-amoy-bor-rpc.publicnode.com";
|
|
33
|
+
IMAGE_REGISTRY_ADDRESS = "0xF7F4eEb3d9a64387F4AcEb6d521b948E6E2fB049";
|
|
34
|
+
CHAIN_ID = 80002;
|
|
35
|
+
GAS = 20000000;
|
|
36
|
+
GAS_PRICE = 1300000010;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setVars();
|
|
42
|
+
|
|
43
|
+
function isStringPrivateKey(privateKey) {
|
|
44
|
+
try {
|
|
45
|
+
let key = privateKey;
|
|
46
|
+
if (!key.startsWith("0x")) {
|
|
47
|
+
key = `0x${privateKey}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Web3.eth.accounts.privateKeyToAccount(key);
|
|
51
|
+
return "OK";
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return e.toString();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function checkAccountBalance() {
|
|
58
|
+
try {
|
|
59
|
+
const web3 = new ethers.providers.JsonRpcProvider(NETWORK_RPC);
|
|
60
|
+
const account = new ethers.Wallet(PRIVATE_KEY, this.provider);
|
|
61
|
+
const balance = await web3.getBalance(account.address);
|
|
62
|
+
return Web3.utils.fromWei(balance, 'ether');
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.error(e);
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
class ImageRegistry {
|
|
70
|
+
constructor() {
|
|
71
|
+
try {
|
|
72
|
+
this.imageRegistryAbi = this.readContractAbi('image_registry.abi');
|
|
73
|
+
this.imageRegistryAddress = IMAGE_REGISTRY_ADDRESS;
|
|
74
|
+
console.log("imageRegistryAddress: ", this.imageRegistryAddress);
|
|
75
|
+
this.provider = new ethers.providers.JsonRpcProvider(NETWORK_RPC);
|
|
76
|
+
|
|
77
|
+
if (PRIVATE_KEY) {
|
|
78
|
+
this.acct = new ethers.Wallet(PRIVATE_KEY, this.provider);
|
|
79
|
+
} else {
|
|
80
|
+
const _privateKey = new ethers.Wallet.createRandom().privateKey;
|
|
81
|
+
this.acct = new ethers.Wallet(_privateKey, this.provider);
|
|
82
|
+
}
|
|
83
|
+
this.imageRegistryContract = new ethers.Contract(
|
|
84
|
+
this.imageRegistryAddress,
|
|
85
|
+
this.imageRegistryAbi,
|
|
86
|
+
this.acct
|
|
87
|
+
);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
console.error(e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
readContractAbi(contractName) {
|
|
94
|
+
const filePath = path.join(__dirname, contractName);
|
|
95
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async addTrustedZoneCert(certContent, ipfsHash, imageName, dockerComposeHash, enclaveNameTrustedZone, fee) {
|
|
99
|
+
console.log("Adding trusted zone cert to image registry");
|
|
100
|
+
const nonce = await this.provider.getTransactionCount(this.acct.address);
|
|
101
|
+
|
|
102
|
+
const unicornTxn = this.imageRegistryContract.addTrustedZoneImage(
|
|
103
|
+
ipfsHash, certContent, "v3", imageName, dockerComposeHash, enclaveNameTrustedZone, fee
|
|
104
|
+
).send({
|
|
105
|
+
gas: GAS,
|
|
106
|
+
chainId: CHAIN_ID,
|
|
107
|
+
nonce: nonce,
|
|
108
|
+
gasPrice: GAS_PRICE === 1 ? ethers.utils.parseUnits('1', 'mwei') : GAS_PRICE
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
console.log("transaction status: ", receipt.status);
|
|
112
|
+
console.log("transaction receipt: ", receipt);
|
|
113
|
+
if (receipt.status === 1) {
|
|
114
|
+
console.log("Adding trusted zone cert transaction was successful!");
|
|
115
|
+
} else {
|
|
116
|
+
console.log("Adding trusted zone cert transaction was UNSUCCESSFUL!");
|
|
117
|
+
}
|
|
118
|
+
const signedTxn = await this.acct.signTransaction(unicornTxn);
|
|
119
|
+
const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async addSecureLockImageCert(certContent, ipfsHash, imageName, version, dockerComposeHash, enclaveNameSecureLock, fee) {
|
|
123
|
+
try {
|
|
124
|
+
console.log("Adding secure lock image cert to image registry");
|
|
125
|
+
// Fetch current nonce
|
|
126
|
+
if (BLOCKCHAIN_NETWORK.includes("Polygon")) {
|
|
127
|
+
console.log("Polygon Mainnet");
|
|
128
|
+
let nonce = await this.provider.getTransactionCount(this.acct.address, 'pending');
|
|
129
|
+
// Fetch current gas price and increase it
|
|
130
|
+
let gasPrice = await this.provider.getGasPrice();
|
|
131
|
+
gasPrice = gasPrice.mul(ethers.BigNumber.from(110)).div(ethers.BigNumber.from(100));
|
|
132
|
+
const unicornTxn = await this.imageRegistryContract.addImage(
|
|
133
|
+
ipfsHash, certContent, version, imageName, dockerComposeHash, enclaveNameSecureLock, fee,
|
|
134
|
+
{
|
|
135
|
+
nonce: nonce,
|
|
136
|
+
gasPrice: gasPrice,
|
|
137
|
+
});
|
|
138
|
+
// console.log("Transaction: ", unicornTxn);
|
|
139
|
+
const receipt = await this.imageRegistryContract.provider.waitForTransaction(unicornTxn.hash);
|
|
140
|
+
|
|
141
|
+
// console.log("transaction status: ", receipt.status);
|
|
142
|
+
console.log("transaction receipt: ", unicornTxn.hash);
|
|
143
|
+
if (receipt.status === 1) {
|
|
144
|
+
console.log("Adding secure lock image cert transaction was successful!");
|
|
145
|
+
} else {
|
|
146
|
+
// console.log("receipt.status", receipt.status)
|
|
147
|
+
console.log("Image certificates already exist for this image!");
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
const unicornTxn = await this.imageRegistryContract.addImage(
|
|
151
|
+
ipfsHash, certContent, version, imageName, dockerComposeHash, enclaveNameSecureLock, fee);
|
|
152
|
+
// console.log("Transaction: ", unicornTxn);
|
|
153
|
+
const receipt = await this.imageRegistryContract.provider.waitForTransaction(unicornTxn.hash);
|
|
154
|
+
|
|
155
|
+
// console.log("transaction status: ", receipt.status);
|
|
156
|
+
console.log("transaction receipt: ", unicornTxn.hash);
|
|
157
|
+
if (receipt.status === 1) {
|
|
158
|
+
console.log("Adding secure lock image cert transaction was successful!");
|
|
159
|
+
} else {
|
|
160
|
+
// console.log("receipt.status", receipt.status)
|
|
161
|
+
console.log("Image certificates already exist for this image!");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// console.log("this.acct.address: ", this.acct.address);
|
|
166
|
+
// console.log("private key", PRIVATE_KEY);
|
|
167
|
+
// console.log('Getting nonce');
|
|
168
|
+
// const nonce = await this.imageRegistryContract.provider.getTransactionCount(this.acct.address);
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
// const signedTxn = await this.acct.signTransaction(unicornTxn);
|
|
172
|
+
// const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
|
|
173
|
+
} catch (e) {
|
|
174
|
+
// console.error(e);
|
|
175
|
+
console.log("Image certificates already exist for this image!");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async getImagePublicKeyCert(ipfsHash) {
|
|
180
|
+
try {
|
|
181
|
+
console.log("Getting image cert from image registry");
|
|
182
|
+
// console.log("this.acct.address: ", this.acct.address);
|
|
183
|
+
// console.log("private key", PRIVATE_KEY);
|
|
184
|
+
// console.log('Getting nonce');
|
|
185
|
+
// const nonce = await this.imageRegistryContract.provider.getTransactionCount(this.acct.address);
|
|
186
|
+
const unicornTxn = await this.imageRegistryContract.getImageCertPublicKey(ipfsHash);
|
|
187
|
+
console.log("unicornTxn: ", unicornTxn);
|
|
188
|
+
// const receipt = await this.imageRegistryContract.provider.waitForTransaction(unicornTxn.hash);
|
|
189
|
+
|
|
190
|
+
// console.log("transaction status: ", receipt.status);
|
|
191
|
+
// // console.log("transaction receipt: ", unicornTxn);
|
|
192
|
+
// if (receipt.status === 1) {
|
|
193
|
+
// console.log("");
|
|
194
|
+
// } else {
|
|
195
|
+
// console.log("Adding secure lock image cert transaction was UNSUCCESSFUL!");
|
|
196
|
+
// }
|
|
197
|
+
// const signedTxn = await this.acct.signTransaction(unicornTxn);
|
|
198
|
+
// const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
console.error(e);
|
|
201
|
+
console.log("Getting image cert transaction was UNSUCCESSFUL!");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async validateSecureLockImageCert(certContent, ipfsHash, imageName, dockerComposeHash, enclaveNameSecureLock, fee) {
|
|
206
|
+
console.log("Validating secure lock image cert in image registry");
|
|
207
|
+
const nonce = await this.provider.getTransactionCount(this.acct.address);
|
|
208
|
+
const unicornTxn = this.imageRegistryContract.validateSecureLockImage(
|
|
209
|
+
ipfsHash, certContent, "v3", imageName, dockerComposeHash, enclaveNameSecureLock, fee
|
|
210
|
+
).send({
|
|
211
|
+
gas: GAS,
|
|
212
|
+
chainId: CHAIN_ID,
|
|
213
|
+
nonce: nonce,
|
|
214
|
+
gasPrice: GAS_PRICE === 1 ? ethers.utils.parseUnits('1', 'mwei') : GAS_PRICE
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
console.log("transaction status: ", receipt.status);
|
|
218
|
+
console.log("transaction receipt: ", receipt);
|
|
219
|
+
if (receipt.status === 1) {
|
|
220
|
+
console.log("Validating secure lock image cert transaction was successful!");
|
|
221
|
+
} else {
|
|
222
|
+
console.log("Validating secure lock image cert transaction was UNSUCCESSFUL!");
|
|
223
|
+
}
|
|
224
|
+
const signedTxn = await this.acct.signTransaction(unicornTxn);
|
|
225
|
+
const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async addSecureLockAndValidateImageCert(certContent, ipfsHash, imageName, dockerComposeHash, enclaveNameSecureLock, fee) {
|
|
229
|
+
console.log("Adding and validating secure lock image cert in image registry");
|
|
230
|
+
const nonce = await this.provider.getTransactionCount(this.acct.address);
|
|
231
|
+
const unicornTxn = this.imageRegistryContract.addSecureLockAndValidateImage(
|
|
232
|
+
ipfsHash, certContent, "v3", imageName, dockerComposeHash, enclaveNameSecureLock, fee
|
|
233
|
+
).send({
|
|
234
|
+
gas: GAS,
|
|
235
|
+
chainId: CHAIN_ID,
|
|
236
|
+
nonce: nonce,
|
|
237
|
+
gasPrice: GAS_PRICE === 1 ? ethers.utils.parseUnits('1', 'mwei') : GAS_PRICE
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
console.log("transaction status: ", receipt.status);
|
|
241
|
+
console.log("transaction receipt: ", receipt);
|
|
242
|
+
if (receipt.status === 1) {
|
|
243
|
+
console.log("Adding and validating secure lock image cert transaction was successful!");
|
|
244
|
+
} else {
|
|
245
|
+
console.log("Adding and validating secure lock image cert transaction was UNSUCCESSFUL!");
|
|
246
|
+
}
|
|
247
|
+
const signedTxn = await this.acct.signTransaction(unicornTxn);
|
|
248
|
+
const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async getTrustedZoneCert(ipfsHash) {
|
|
252
|
+
const cert = await this.imageRegistryContract.getTrustedZoneCert(ipfsHash);
|
|
253
|
+
return cert;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async getSecureLockCert(ipfsHash) {
|
|
257
|
+
const cert = await this.imageRegistryContract.getSecureLockCert(ipfsHash);
|
|
258
|
+
return cert;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async getImageDetails(ipfsHash) {
|
|
262
|
+
try {
|
|
263
|
+
const details = await this.imageRegistryContract.imageDetails(ipfsHash);
|
|
264
|
+
return details;
|
|
265
|
+
} catch (e) {
|
|
266
|
+
return ['', '', ''];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async _getLatestImageVersionPublicKey(projectName, version) {
|
|
271
|
+
try {
|
|
272
|
+
// console.log("Getting latest image version public key");
|
|
273
|
+
const publicKey = await this.imageRegistryContract.getLatestImageVersionPublicKey(projectName, version);
|
|
274
|
+
// console.log("public key: ", publicKey);
|
|
275
|
+
return publicKey;
|
|
276
|
+
} catch (e) {
|
|
277
|
+
// console.error(e);
|
|
278
|
+
return ['', '', ''];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
(async () => {
|
|
284
|
+
try {
|
|
285
|
+
const [networkName, projectName, version, privateKey, action] = process.argv.slice(2);
|
|
286
|
+
if (action === "validateAddress") {
|
|
287
|
+
if (privateKey) {
|
|
288
|
+
console.log(isStringPrivateKey(privateKey));
|
|
289
|
+
}
|
|
290
|
+
process.exit(0);
|
|
291
|
+
}
|
|
292
|
+
if (networkName && projectName) {
|
|
293
|
+
BLOCKCHAIN_NETWORK = networkName;
|
|
294
|
+
}
|
|
295
|
+
setVars(networkName);
|
|
296
|
+
if (action === "checkBalance") {
|
|
297
|
+
const balance = await checkAccountBalance();
|
|
298
|
+
console.log(`${balance} gas`);
|
|
299
|
+
process.exit(0);
|
|
300
|
+
}
|
|
301
|
+
if (action === 'getTrustedZoneCert') {
|
|
302
|
+
const imageRegistry = new ImageRegistry();
|
|
303
|
+
const public = (await imageRegistry._getLatestImageVersionPublicKey(projectName, version))[1]
|
|
304
|
+
console.log(public);
|
|
305
|
+
return public;
|
|
306
|
+
}
|
|
307
|
+
// The CAS session name recorded for the trustedzone template's latest
|
|
308
|
+
// image: what the compose's SCONE_CONFIG_ID for the trustedzone must name.
|
|
309
|
+
if (action === 'getTrustedZoneSession') {
|
|
310
|
+
const imageRegistry = new ImageRegistry();
|
|
311
|
+
const latest = await imageRegistry.imageRegistryContract.getLatestTrustedZoneImageCertPublicKey(projectName, version);
|
|
312
|
+
const session = await imageRegistry.imageRegistryContract.getTrustedZoneImageSession(latest[0]);
|
|
313
|
+
console.log(session);
|
|
314
|
+
return session;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const imageRegistry = new ImageRegistry();
|
|
318
|
+
if (action === 'registerSecureLockImage') {
|
|
319
|
+
const secureLock = fs.readFileSync("./registry/certificate.securelock.crt", 'utf8');
|
|
320
|
+
// console.log("SECURELOCK:", secureLock);
|
|
321
|
+
const ipfsHash = process.env.IPFS_HASH || "";
|
|
322
|
+
console.log(`ipfsHash: ${ipfsHash}`);
|
|
323
|
+
const ipfsDockerComposeHash = process.env.IPFS_DOCKER_COMPOSE_HASH || "";
|
|
324
|
+
console.log(`ipfsDockerComposeHash: ${ipfsDockerComposeHash}`);
|
|
325
|
+
const imageName = process.env.PROJECT_NAME || "";
|
|
326
|
+
console.log(`imageName: ${imageName}`);
|
|
327
|
+
const enclaveVersion = process.env.VERSION || "";
|
|
328
|
+
const enclaveNameSecureLock = process.env.ENCLAVE_NAME_SECURELOCK || "";
|
|
329
|
+
console.log(`enclaveNameSecureLock: ${enclaveNameSecureLock}`);
|
|
330
|
+
const fee = process.env.DEVELOPER_FEE || "0";
|
|
331
|
+
console.log(`fee: ${fee}`);
|
|
332
|
+
|
|
333
|
+
// Register the SAME build under two registry version keys:
|
|
334
|
+
// "v3" -> the moving "latest" pointer the runner resolves by
|
|
335
|
+
// default (getLatestImageVersionPublicKey(name,"v3")).
|
|
336
|
+
// This MUST be "v3" (the protocol version), NOT the
|
|
337
|
+
// enclave/template VERSION -- registering under the
|
|
338
|
+
// VERSION (e.g. "21") wrote the pointer where the
|
|
339
|
+
// runner never looks, so it kept using a stale image.
|
|
340
|
+
// <VERSION> -> an immutable per-version entry (e.g. "22") so this
|
|
341
|
+
// exact build can be pinned/rolled back to later.
|
|
342
|
+
// The contract stores each (name,version) channel append-only.
|
|
343
|
+
const versionKeys = ["v3"];
|
|
344
|
+
if (enclaveVersion && enclaveVersion !== "v3") versionKeys.push(enclaveVersion);
|
|
345
|
+
for (const versionKey of versionKeys) {
|
|
346
|
+
console.log(`Registering securelock under version '${versionKey}'`);
|
|
347
|
+
await imageRegistry.addSecureLockImageCert(secureLock, ipfsHash, imageName, versionKey, ipfsDockerComposeHash, enclaveNameSecureLock, fee);
|
|
348
|
+
}
|
|
349
|
+
process.exit(0);
|
|
350
|
+
}
|
|
351
|
+
if (action === 'getImagePublicKey') {
|
|
352
|
+
const ipfsHash = process.env.IPFS_HASH || "";
|
|
353
|
+
await imageRegistry.getImagePublicKeyCert(ipfsHash);
|
|
354
|
+
process.exit(0);
|
|
355
|
+
}
|
|
356
|
+
console.log(`Checking image: '${projectName}' on the ${networkName} blockchain...`);
|
|
357
|
+
const imageHash = (await imageRegistry._getLatestImageVersionPublicKey(projectName, version))[0];
|
|
358
|
+
console.log(`Image hash: ${imageHash}`);
|
|
359
|
+
if (!imageHash) {
|
|
360
|
+
console.log(`Image: '${projectName}' is available on the ${networkName} blockchain.`);
|
|
361
|
+
process.exit(0);
|
|
362
|
+
}
|
|
363
|
+
const imageOwner = (await imageRegistry.getImageDetails(imageHash))[0];
|
|
364
|
+
|
|
365
|
+
if (privateKey) {
|
|
366
|
+
if (isStringPrivateKey(privateKey) === "OK") {
|
|
367
|
+
const account = Account.fromPrivate(privateKey);
|
|
368
|
+
if (imageOwner !== account.address) {
|
|
369
|
+
console.log(`!!! Image: '${projectName}' is owned by '${imageOwner}'.\nYou are not the account holder of the image.\nPlease change the project name and try again.\n`);
|
|
370
|
+
process.exit(1);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (imageOwner) {
|
|
376
|
+
console.log(`Image: '${projectName}' is owned by '${imageOwner}'.\nIf you are not the account holder, you will not be able to publish your project with the current name. Please change the project name and try again.\n`);
|
|
377
|
+
process.exit(0);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
console.log(`Image: '${projectName}' is available on the ${networkName} blockchain.`);
|
|
381
|
+
} catch (e) {
|
|
382
|
+
process.exit(0);
|
|
383
|
+
}
|
|
381
384
|
})();
|