@ethernity-cloud/sdk-js 1.1.0

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.
Files changed (184) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +185 -0
  3. package/build.js +22 -0
  4. package/init.js +301 -0
  5. package/nodenithy/build/las/Dockerfile +5 -0
  6. package/nodenithy/build/securelock/Dockerfile.tmpl +65 -0
  7. package/nodenithy/build/securelock/scripts/binary-fs-build.sh +28 -0
  8. package/nodenithy/build/securelock/src/.env +3 -0
  9. package/nodenithy/build/securelock/src/etny_crypto.js +201 -0
  10. package/nodenithy/build/securelock/src/etny_exec.js +65 -0
  11. package/nodenithy/build/securelock/src/image_registry_abi.js +808 -0
  12. package/nodenithy/build/securelock/src/models.js +261 -0
  13. package/nodenithy/build/securelock/src/package.json +40 -0
  14. package/nodenithy/build/securelock/src/pox_abi.js +1491 -0
  15. package/nodenithy/build/securelock/src/securelock.js.tmpl +421 -0
  16. package/nodenithy/build/securelock/src/swift_stream_service.js +147 -0
  17. package/nodenithy/build/securelock/src/task_status.js +15 -0
  18. package/nodenithy/build/securelock/src/wallet.js +29 -0
  19. package/nodenithy/build/squash/Dockerfile +7 -0
  20. package/nodenithy/build/trustedzone/Dockerfile.tmpl +57 -0
  21. package/nodenithy/build/trustedzone/scripts/binary-fs-build.sh +22 -0
  22. package/nodenithy/build/trustedzone/src/.env +3 -0
  23. package/nodenithy/build/trustedzone/src/etny_crypto.js +202 -0
  24. package/nodenithy/build/trustedzone/src/etny_exec.js +54 -0
  25. package/nodenithy/build/trustedzone/src/image_registry_abi.js +808 -0
  26. package/nodenithy/build/trustedzone/src/models.js +261 -0
  27. package/nodenithy/build/trustedzone/src/package.json +40 -0
  28. package/nodenithy/build/trustedzone/src/pox_abi.js +1491 -0
  29. package/nodenithy/build/trustedzone/src/swift_stream_service.js +147 -0
  30. package/nodenithy/build/trustedzone/src/task_status.js +15 -0
  31. package/nodenithy/build/trustedzone/src/test.js +44 -0
  32. package/nodenithy/build/trustedzone/src/trustedzone.js.tmpl +508 -0
  33. package/nodenithy/build/trustedzone/src/wallet.js +28 -0
  34. package/nodenithy/build/validator/Dockerfile +58 -0
  35. package/nodenithy/build/validator/package-lock.json +6 -0
  36. package/nodenithy/build/validator/scripts/binary-fs-build.sh +19 -0
  37. package/nodenithy/build/validator/src/.env +3 -0
  38. package/nodenithy/build/validator/src/cert.pem +5 -0
  39. package/nodenithy/build/validator/src/etny_crypto.js +204 -0
  40. package/nodenithy/build/validator/src/etny_exec.js +52 -0
  41. package/nodenithy/build/validator/src/image_registry_abi.js +808 -0
  42. package/nodenithy/build/validator/src/key.pem +6 -0
  43. package/nodenithy/build/validator/src/models.js +261 -0
  44. package/nodenithy/build/validator/src/package-lock.json +2498 -0
  45. package/nodenithy/build/validator/src/package.json +40 -0
  46. package/nodenithy/build/validator/src/pox_abi.js +1491 -0
  47. package/nodenithy/build/validator/src/swift_stream_service.js +147 -0
  48. package/nodenithy/build/validator/src/task_status.js +15 -0
  49. package/nodenithy/build/validator/src/test.js +44 -0
  50. package/nodenithy/build/validator/src/trustedzone.js +613 -0
  51. package/nodenithy/build/validator/src/validator_abi.js +834 -0
  52. package/nodenithy/build/validator/src/wallet.js +28 -0
  53. package/nodenithy/build.js +184 -0
  54. package/nodenithy/build.mjs +179 -0
  55. package/nodenithy/build.sh +161 -0
  56. package/nodenithy/ipfs.js +135 -0
  57. package/nodenithy/ipfs.mjs +551 -0
  58. package/nodenithy/public/favicon.ico +0 -0
  59. package/nodenithy/public/index.html +43 -0
  60. package/nodenithy/public/logo192.png +0 -0
  61. package/nodenithy/public/logo512.png +0 -0
  62. package/nodenithy/public/manifest.json +25 -0
  63. package/nodenithy/public/robots.txt +3 -0
  64. package/nodenithy/run/__pycache__/swift_stream_service.cpython-312.pyc +0 -0
  65. package/nodenithy/run/app/input.txt +4 -0
  66. package/nodenithy/run/app/payload.js +4 -0
  67. package/nodenithy/run/docker-compose-final.yml.tmpl +65 -0
  68. package/nodenithy/run/docker-compose-swift-stream.yml +17 -0
  69. package/nodenithy/run/docker-compose.yml.tmpl +76 -0
  70. package/nodenithy/run/etny-securelock-test.yaml.tpl +46 -0
  71. package/nodenithy/run/etny-trustedzone-test.yaml.tpl +45 -0
  72. package/nodenithy/run/git.sh +22 -0
  73. package/nodenithy/run/image_registry.abi +1 -0
  74. package/nodenithy/run/image_registry.js +372 -0
  75. package/nodenithy/run/image_registry.py +327 -0
  76. package/nodenithy/run/image_registry_runner.py +71 -0
  77. package/nodenithy/run/ipfs.sh +58 -0
  78. package/nodenithy/run/ipfs_pre.sh +75 -0
  79. package/nodenithy/run/public_key_service.js +90 -0
  80. package/nodenithy/run/public_key_service.py +107 -0
  81. package/nodenithy/run/swift_stream_service.py +212 -0
  82. package/nodenithy/run/swiftstream.py +37 -0
  83. package/nodenithy/run/swiftstream1.py +27 -0
  84. package/nodenithy/run.js +538 -0
  85. package/nodenithy/run.sh +277 -0
  86. package/nodenithy/scripts/build-ipfs-upload.sh +23 -0
  87. package/nodenithy/scripts/build.sh +40 -0
  88. package/nodenithy/scripts/ipfs-daemon.sh +7 -0
  89. package/nodenithy/scripts/run.sh +50 -0
  90. package/nodenithy/src/App.css +57 -0
  91. package/nodenithy/src/ec_helloworld_example.js +64 -0
  92. package/nodenithy/src/index.css +13 -0
  93. package/nodenithy/src/index.js +17 -0
  94. package/nodenithy/src/preStart.js +45 -0
  95. package/nodenithy/src/preStart.mjs +57 -0
  96. package/nodenithy/src/reportWebVitals.js +13 -0
  97. package/nodenithy/src/serverless/backend.js +5 -0
  98. package/package.json +48 -0
  99. package/postinstall.js +34 -0
  100. package/publish.js +126 -0
  101. package/pynithy/build/docker-compose.yml +68 -0
  102. package/pynithy/build/las/Dockerfile +11 -0
  103. package/pynithy/build/las/src/etny_entrypoint.sh +6 -0
  104. package/pynithy/build/las/src/las_entrypoint.sh +26 -0
  105. package/pynithy/build/scripts/binary-fs-build.sh +28 -0
  106. package/pynithy/build/securelock/Dockerfile.tmpl +78 -0
  107. package/pynithy/build/securelock/scripts/binary-fs-build.sh +41 -0
  108. package/pynithy/build/securelock/src/app/.env +5 -0
  109. package/pynithy/build/securelock/src/app/cert1-ca1-clean.crt +10 -0
  110. package/pynithy/build/securelock/src/app/cert1-ca1-clean.key +6 -0
  111. package/pynithy/build/securelock/src/app/enclave_pub_cert.pem +10 -0
  112. package/pynithy/build/securelock/src/app/input.txt +1 -0
  113. package/pynithy/build/securelock/src/app/payload.py +25 -0
  114. package/pynithy/build/securelock/src/app/public-cert-clean.pem +10 -0
  115. package/pynithy/build/securelock/src/app/result.txt +1 -0
  116. package/pynithy/build/securelock/src/app/transaction.txt +1 -0
  117. package/pynithy/build/securelock/src/etny_crypto.py +167 -0
  118. package/pynithy/build/securelock/src/etny_exec.py +79 -0
  119. package/pynithy/build/securelock/src/image_registry.abi +1 -0
  120. package/pynithy/build/securelock/src/key_generation.py +17 -0
  121. package/pynithy/build/securelock/src/models.py +176 -0
  122. package/pynithy/build/securelock/src/pox.abi +1489 -0
  123. package/pynithy/build/securelock/src/securelock.py.tmpl +411 -0
  124. package/pynithy/build/securelock/src/swift_stream_service.py +186 -0
  125. package/pynithy/build/trustedzone/Dockerfile.tmpl +56 -0
  126. package/pynithy/build/trustedzone/scripts/binary-fs-build.sh +32 -0
  127. package/pynithy/build/trustedzone/src/app/.env +5 -0
  128. package/pynithy/build/trustedzone/src/app/cert1-ca1-clean.crt +10 -0
  129. package/pynithy/build/trustedzone/src/app/cert1-ca1-clean.key +6 -0
  130. package/pynithy/build/trustedzone/src/app/enclave_pub_cert.pem +10 -0
  131. package/pynithy/build/trustedzone/src/app/input.txt +1 -0
  132. package/pynithy/build/trustedzone/src/app/payload.py +25 -0
  133. package/pynithy/build/trustedzone/src/app/public-cert-clean.pem +10 -0
  134. package/pynithy/build/trustedzone/src/app/result.txt +1 -0
  135. package/pynithy/build/trustedzone/src/app/securelock.crt +10 -0
  136. package/pynithy/build/trustedzone/src/app/transaction.txt +1 -0
  137. package/pynithy/build/trustedzone/src/app/trustedzone.crt +10 -0
  138. package/pynithy/build/trustedzone/src/etny_crypto.py +188 -0
  139. package/pynithy/build/trustedzone/src/etny_exec.py +56 -0
  140. package/pynithy/build/trustedzone/src/formatter.py +42 -0
  141. package/pynithy/build/trustedzone/src/image_registry.abi +1 -0
  142. package/pynithy/build/trustedzone/src/key_generation.py +17 -0
  143. package/pynithy/build/trustedzone/src/models.py +176 -0
  144. package/pynithy/build/trustedzone/src/pox.abi +1489 -0
  145. package/pynithy/build/trustedzone/src/swift_stream_service.py +186 -0
  146. package/pynithy/build/trustedzone/src/trustedzone.py.tmpl +460 -0
  147. package/pynithy/build.mjs +179 -0
  148. package/pynithy/docker-compose.yml +0 -0
  149. package/pynithy/ipfs.mjs +244 -0
  150. package/pynithy/public/favicon.ico +0 -0
  151. package/pynithy/public/index.html +43 -0
  152. package/pynithy/public/logo192.png +0 -0
  153. package/pynithy/public/logo512.png +0 -0
  154. package/pynithy/public/manifest.json +25 -0
  155. package/pynithy/public/robots.txt +3 -0
  156. package/pynithy/run/certs/cert.pem +31 -0
  157. package/pynithy/run/certs/challenge.crt +10 -0
  158. package/pynithy/run/certs/key.pem +52 -0
  159. package/pynithy/run/docker-compose-final.yml +59 -0
  160. package/pynithy/run/docker-compose-final.yml.tmpl +59 -0
  161. package/pynithy/run/docker-compose-swift-stream.yml +27 -0
  162. package/pynithy/run/docker-compose-swift-stream.yml.tmpl +27 -0
  163. package/pynithy/run/docker-compose.yml +55 -0
  164. package/pynithy/run/docker-compose.yml.tmpl +55 -0
  165. package/pynithy/run/etny-pynity-test.yaml.tpl +46 -0
  166. package/pynithy/run/etny-securelock-test.yaml.tpl +46 -0
  167. package/pynithy/run/etny-trustedzone-test.yaml.tpl +46 -0
  168. package/pynithy/run/git.sh +22 -0
  169. package/pynithy/run/image_registry.abi +1 -0
  170. package/pynithy/run/image_registry.js +372 -0
  171. package/pynithy/run/image_registry.py +139 -0
  172. package/pynithy/run/image_registry_runner.py +45 -0
  173. package/pynithy/run/ipfs.sh +89 -0
  174. package/pynithy/run/public_key_service.js +90 -0
  175. package/pynithy/run/swiftstream.py +28 -0
  176. package/pynithy/run.js +538 -0
  177. package/pynithy/src/App.css +57 -0
  178. package/pynithy/src/ec_helloworld_example.js +64 -0
  179. package/pynithy/src/index.css +13 -0
  180. package/pynithy/src/index.js +17 -0
  181. package/pynithy/src/preStart.mjs +57 -0
  182. package/pynithy/src/reportWebVitals.js +13 -0
  183. package/pynithy/src/serverless/__init__.py +0 -0
  184. package/pynithy/src/serverless/backend.py +2 -0
@@ -0,0 +1,372 @@
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 = "0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31"; // bloxberg testnet
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
+ IMAGE_REGISTRY_ADDRESS = "0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31";
21
+ } else if (BLOCKCHAIN_NETWORK.includes("Polygon")) {
22
+ if (BLOCKCHAIN_NETWORK.includes("Mainnet")) {
23
+ NETWORK_RPC = "https://polygon-rpc.com";
24
+ IMAGE_REGISTRY_ADDRESS = "0x689f3806874d3c8A973f419a4eB24e6fBA7E830F";
25
+ CHAIN_ID = 137;
26
+ GAS = 20000000;
27
+ GAS_PRICE = 40500500010;
28
+ } else {
29
+ NETWORK_RPC = "https://rpc-amoy.polygon.technology";
30
+ IMAGE_REGISTRY_ADDRESS = "0xF7F4eEb3d9a64387F4AcEb6d521b948E6E2fB049";
31
+ CHAIN_ID = 80002;
32
+ GAS = 20000000;
33
+ GAS_PRICE = 1300000010;
34
+ }
35
+ }
36
+ }
37
+
38
+ setVars();
39
+
40
+ function isStringPrivateKey(privateKey) {
41
+ try {
42
+ let key = privateKey;
43
+ if (!key.startsWith("0x")) {
44
+ key = `0x${privateKey}`;
45
+ }
46
+
47
+ Web3.eth.accounts.privateKeyToAccount(key);
48
+ return "OK";
49
+ } catch (e) {
50
+ return e.toString();
51
+ }
52
+ }
53
+
54
+ async function checkAccountBalance() {
55
+ try {
56
+ const web3 = new ethers.providers.JsonRpcProvider(NETWORK_RPC);
57
+ const account = new ethers.Wallet(PRIVATE_KEY, this.provider);
58
+ const balance = await web3.getBalance(account.address);
59
+ return Web3.utils.fromWei(balance, 'ether');
60
+ } catch (e) {
61
+ console.error(e);
62
+ return 0;
63
+ }
64
+ }
65
+
66
+ class ImageRegistry {
67
+ constructor() {
68
+ try {
69
+ this.imageRegistryAbi = this.readContractAbi('image_registry.abi');
70
+ this.imageRegistryAddress = IMAGE_REGISTRY_ADDRESS;
71
+ console.log("imageRegistryAddress: ", this.imageRegistryAddress);
72
+ this.provider = new ethers.providers.JsonRpcProvider(NETWORK_RPC);
73
+
74
+ if (PRIVATE_KEY) {
75
+ this.acct = new ethers.Wallet(PRIVATE_KEY, this.provider);
76
+ } else {
77
+ const _privateKey = new ethers.Wallet.createRandom().privateKey;
78
+ this.acct = new ethers.Wallet(_privateKey, this.provider);
79
+ }
80
+ this.imageRegistryContract = new ethers.Contract(
81
+ this.imageRegistryAddress,
82
+ this.imageRegistryAbi,
83
+ this.acct
84
+ );
85
+ } catch (e) {
86
+ console.error(e);
87
+ }
88
+ }
89
+
90
+ readContractAbi(contractName) {
91
+ const filePath = path.join(__dirname, contractName);
92
+ return JSON.parse(fs.readFileSync(filePath, 'utf8'));
93
+ }
94
+
95
+ async addTrustedZoneCert(certContent, ipfsHash, imageName, dockerComposeHash, enclaveNameTrustedZone, fee) {
96
+ console.log("Adding trusted zone cert to image registry");
97
+ const nonce = await this.provider.getTransactionCount(this.acct.address);
98
+
99
+ const unicornTxn = this.imageRegistryContract.addTrustedZoneImage(
100
+ ipfsHash, certContent, "v3", imageName, dockerComposeHash, enclaveNameTrustedZone, fee
101
+ ).send({
102
+ gas: GAS,
103
+ chainId: CHAIN_ID,
104
+ nonce: nonce,
105
+ gasPrice: GAS_PRICE === 1 ? ethers.utils.parseUnits('1', 'mwei') : GAS_PRICE
106
+ });
107
+
108
+ console.log("transaction status: ", receipt.status);
109
+ console.log("transaction receipt: ", receipt);
110
+ if (receipt.status === 1) {
111
+ console.log("Adding trusted zone cert transaction was successful!");
112
+ } else {
113
+ console.log("Adding trusted zone cert transaction was UNSUCCESSFUL!");
114
+ }
115
+ const signedTxn = await this.acct.signTransaction(unicornTxn);
116
+ const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
117
+ }
118
+
119
+ async addSecureLockImageCert(certContent, ipfsHash, imageName, version, dockerComposeHash, enclaveNameSecureLock, fee) {
120
+ try {
121
+ console.log("Adding secure lock image cert to image registry");
122
+ // Fetch current nonce
123
+ if (BLOCKCHAIN_NETWORK.includes("Polygon")) {
124
+ console.log("Polygon Mainnet");
125
+ let nonce = await this.provider.getTransactionCount(this.acct.address, 'pending');
126
+ // Fetch current gas price and increase it
127
+ let gasPrice = await this.provider.getGasPrice();
128
+ gasPrice = gasPrice.mul(ethers.BigNumber.from(110)).div(ethers.BigNumber.from(100));
129
+ const unicornTxn = await this.imageRegistryContract.addImage(
130
+ ipfsHash, certContent, version, imageName, dockerComposeHash, enclaveNameSecureLock, fee,
131
+ {
132
+ nonce: nonce,
133
+ gasPrice: gasPrice,
134
+ });
135
+ // console.log("Transaction: ", unicornTxn);
136
+ const receipt = await this.imageRegistryContract.provider.waitForTransaction(unicornTxn.hash);
137
+
138
+ // console.log("transaction status: ", receipt.status);
139
+ console.log("transaction receipt: ", unicornTxn.hash);
140
+ if (receipt.status === 1) {
141
+ console.log("Adding secure lock image cert transaction was successful!");
142
+ } else {
143
+ // console.log("receipt.status", receipt.status)
144
+ console.log("Image certificates already exist for this image!");
145
+ }
146
+ } else {
147
+ const unicornTxn = await this.imageRegistryContract.addImage(
148
+ ipfsHash, certContent, version, imageName, dockerComposeHash, enclaveNameSecureLock, fee);
149
+ // console.log("Transaction: ", unicornTxn);
150
+ const receipt = await this.imageRegistryContract.provider.waitForTransaction(unicornTxn.hash);
151
+
152
+ // console.log("transaction status: ", receipt.status);
153
+ console.log("transaction receipt: ", unicornTxn.hash);
154
+ if (receipt.status === 1) {
155
+ console.log("Adding secure lock image cert transaction was successful!");
156
+ } else {
157
+ // console.log("receipt.status", receipt.status)
158
+ console.log("Image certificates already exist for this image!");
159
+ }
160
+ }
161
+
162
+ // console.log("this.acct.address: ", this.acct.address);
163
+ // console.log("private key", PRIVATE_KEY);
164
+ // console.log('Getting nonce');
165
+ // const nonce = await this.imageRegistryContract.provider.getTransactionCount(this.acct.address);
166
+
167
+
168
+ // const signedTxn = await this.acct.signTransaction(unicornTxn);
169
+ // const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
170
+ } catch (e) {
171
+ // console.error(e);
172
+ console.log("Image certificates already exist for this image!");
173
+ }
174
+ }
175
+
176
+ async getImagePublicKeyCert(ipfsHash) {
177
+ try {
178
+ console.log("Getting image cert from image registry");
179
+ // console.log("this.acct.address: ", this.acct.address);
180
+ // console.log("private key", PRIVATE_KEY);
181
+ // console.log('Getting nonce');
182
+ // const nonce = await this.imageRegistryContract.provider.getTransactionCount(this.acct.address);
183
+ const unicornTxn = await this.imageRegistryContract.getImageCertPublicKey(ipfsHash);
184
+ console.log("unicornTxn: ", unicornTxn);
185
+ // const receipt = await this.imageRegistryContract.provider.waitForTransaction(unicornTxn.hash);
186
+
187
+ // console.log("transaction status: ", receipt.status);
188
+ // // console.log("transaction receipt: ", unicornTxn);
189
+ // if (receipt.status === 1) {
190
+ // console.log("");
191
+ // } else {
192
+ // console.log("Adding secure lock image cert transaction was UNSUCCESSFUL!");
193
+ // }
194
+ // const signedTxn = await this.acct.signTransaction(unicornTxn);
195
+ // const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
196
+ } catch (e) {
197
+ console.error(e);
198
+ console.log("Getting image cert transaction was UNSUCCESSFUL!");
199
+ }
200
+ }
201
+
202
+ async validateSecureLockImageCert(certContent, ipfsHash, imageName, dockerComposeHash, enclaveNameSecureLock, fee) {
203
+ console.log("Validating secure lock image cert in image registry");
204
+ const nonce = await this.provider.getTransactionCount(this.acct.address);
205
+ const unicornTxn = this.imageRegistryContract.validateSecureLockImage(
206
+ ipfsHash, certContent, "v3", imageName, dockerComposeHash, enclaveNameSecureLock, fee
207
+ ).send({
208
+ gas: GAS,
209
+ chainId: CHAIN_ID,
210
+ nonce: nonce,
211
+ gasPrice: GAS_PRICE === 1 ? ethers.utils.parseUnits('1', 'mwei') : GAS_PRICE
212
+ });
213
+
214
+ console.log("transaction status: ", receipt.status);
215
+ console.log("transaction receipt: ", receipt);
216
+ if (receipt.status === 1) {
217
+ console.log("Validating secure lock image cert transaction was successful!");
218
+ } else {
219
+ console.log("Validating secure lock image cert transaction was UNSUCCESSFUL!");
220
+ }
221
+ const signedTxn = await this.acct.signTransaction(unicornTxn);
222
+ const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
223
+ }
224
+
225
+ async addSecureLockAndValidateImageCert(certContent, ipfsHash, imageName, dockerComposeHash, enclaveNameSecureLock, fee) {
226
+ console.log("Adding and validating secure lock image cert in image registry");
227
+ const nonce = await this.provider.getTransactionCount(this.acct.address);
228
+ const unicornTxn = this.imageRegistryContract.addSecureLockAndValidateImage(
229
+ ipfsHash, certContent, "v3", imageName, dockerComposeHash, enclaveNameSecureLock, fee
230
+ ).send({
231
+ gas: GAS,
232
+ chainId: CHAIN_ID,
233
+ nonce: nonce,
234
+ gasPrice: GAS_PRICE === 1 ? ethers.utils.parseUnits('1', 'mwei') : GAS_PRICE
235
+ });
236
+
237
+ console.log("transaction status: ", receipt.status);
238
+ console.log("transaction receipt: ", receipt);
239
+ if (receipt.status === 1) {
240
+ console.log("Adding and validating secure lock image cert transaction was successful!");
241
+ } else {
242
+ console.log("Adding and validating secure lock image cert transaction was UNSUCCESSFUL!");
243
+ }
244
+ const signedTxn = await this.acct.signTransaction(unicornTxn);
245
+ const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
246
+ }
247
+
248
+ async getTrustedZoneCert(ipfsHash) {
249
+ const cert = await this.imageRegistryContract.getTrustedZoneCert(ipfsHash);
250
+ return cert;
251
+ }
252
+
253
+ async getSecureLockCert(ipfsHash) {
254
+ const cert = await this.imageRegistryContract.getSecureLockCert(ipfsHash);
255
+ return cert;
256
+ }
257
+
258
+ async getImageDetails(ipfsHash) {
259
+ try {
260
+ const details = await this.imageRegistryContract.imageDetails(ipfsHash);
261
+ return details;
262
+ } catch (e) {
263
+ return ['', '', ''];
264
+ }
265
+ }
266
+
267
+ async _getLatestImageVersionPublicKey(projectName, version) {
268
+ try {
269
+ // console.log("Getting latest image version public key");
270
+ const publicKey = await this.imageRegistryContract.getLatestImageVersionPublicKey(projectName, version);
271
+ // console.log("public key: ", publicKey);
272
+ return publicKey;
273
+ } catch (e) {
274
+ // console.error(e);
275
+ return ['', '', ''];
276
+ }
277
+ }
278
+ }
279
+
280
+ (async () => {
281
+ try {
282
+ const [networkName, projectName, version, privateKey, action] = process.argv.slice(2);
283
+ if (action === "validateAddress") {
284
+ if (privateKey) {
285
+ console.log(isStringPrivateKey(privateKey));
286
+ }
287
+ process.exit(0);
288
+ }
289
+ if (networkName && projectName) {
290
+ BLOCKCHAIN_NETWORK = networkName;
291
+ }
292
+ setVars(networkName);
293
+ if (action === "checkBalance") {
294
+ const balance = await checkAccountBalance();
295
+ console.log(`${balance} gas`);
296
+ process.exit(0);
297
+ }
298
+ if (action === 'getTrustedZoneCert') {
299
+ const imageRegistry = new ImageRegistry();
300
+ const public = (await imageRegistry._getLatestImageVersionPublicKey(projectName, version))[1]
301
+ console.log(public);
302
+ return public;
303
+ }
304
+
305
+ const imageRegistry = new ImageRegistry();
306
+ if (action === 'registerSecureLockImage') {
307
+ const secureLock = fs.readFileSync("./registry/certificate.securelock.crt", 'utf8');
308
+ // console.log("SECURELOCK:", secureLock);
309
+ const ipfsHash = process.env.IPFS_HASH || "";
310
+ console.log(`ipfsHash: ${ipfsHash}`);
311
+ const ipfsDockerComposeHash = process.env.IPFS_DOCKER_COMPOSE_HASH || "";
312
+ console.log(`ipfsDockerComposeHash: ${ipfsDockerComposeHash}`);
313
+ const imageName = process.env.PROJECT_NAME || "";
314
+ console.log(`imageName: ${imageName}`);
315
+ const enclaveVersion = process.env.VERSION || "";
316
+ const enclaveNameSecureLock = process.env.ENCLAVE_NAME_SECURELOCK || "";
317
+ console.log(`enclaveNameSecureLock: ${enclaveNameSecureLock}`);
318
+ const fee = process.env.DEVELOPER_FEE || "0";
319
+ console.log(`fee: ${fee}`);
320
+
321
+ // Register the SAME build under two registry version keys:
322
+ // "v3" -> the moving "latest" pointer the runner resolves by
323
+ // default (getLatestImageVersionPublicKey(name,"v3")).
324
+ // This MUST be "v3" (the protocol version), NOT the
325
+ // enclave/template VERSION -- registering under the
326
+ // VERSION (e.g. "21") wrote the pointer where the
327
+ // runner never looks, so it kept using a stale image.
328
+ // <VERSION> -> an immutable per-version entry (e.g. "22") so this
329
+ // exact build can be pinned/rolled back to later.
330
+ // The contract stores each (name,version) channel append-only.
331
+ const versionKeys = ["v3"];
332
+ if (enclaveVersion && enclaveVersion !== "v3") versionKeys.push(enclaveVersion);
333
+ for (const versionKey of versionKeys) {
334
+ console.log(`Registering securelock under version '${versionKey}'`);
335
+ await imageRegistry.addSecureLockImageCert(secureLock, ipfsHash, imageName, versionKey, ipfsDockerComposeHash, enclaveNameSecureLock, fee);
336
+ }
337
+ process.exit(0);
338
+ }
339
+ if (action === 'getImagePublicKey') {
340
+ const ipfsHash = process.env.IPFS_HASH || "";
341
+ await imageRegistry.getImagePublicKeyCert(ipfsHash);
342
+ process.exit(0);
343
+ }
344
+ console.log(`Checking image: '${projectName}' on the ${networkName} blockchain...`);
345
+ const imageHash = (await imageRegistry._getLatestImageVersionPublicKey(projectName, version))[0];
346
+ console.log(`Image hash: ${imageHash}`);
347
+ if (!imageHash) {
348
+ console.log(`Image: '${projectName}' is available on the ${networkName} blockchain.`);
349
+ process.exit(0);
350
+ }
351
+ const imageOwner = (await imageRegistry.getImageDetails(imageHash))[0];
352
+
353
+ if (privateKey) {
354
+ if (isStringPrivateKey(privateKey) === "OK") {
355
+ const account = Account.fromPrivate(privateKey);
356
+ if (imageOwner !== account.address) {
357
+ 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`);
358
+ process.exit(1);
359
+ }
360
+ }
361
+ }
362
+
363
+ if (imageOwner) {
364
+ 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`);
365
+ process.exit(0);
366
+ }
367
+
368
+ console.log(`Image: '${projectName}' is available on the ${networkName} blockchain.`);
369
+ } catch (e) {
370
+ process.exit(0);
371
+ }
372
+ })();
@@ -0,0 +1,139 @@
1
+ import os
2
+
3
+ from web3 import Web3
4
+ from web3.middleware import geth_poa_middleware
5
+ from eth_account import Account
6
+
7
+ privatekey = "abf7fc132da9391d9926918d772d50c0e5d6c81817f1e26d54789037ce23b625"
8
+
9
+
10
+ class ImageRegistry:
11
+ def __init__(self):
12
+ self.acct = Account.privateKeyToAccount(privatekey)
13
+ image_registry_abi = self.__read_contract_abi('image_registry.abi')
14
+ self.image_registry_address = "0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31"
15
+
16
+ self.web3_provider = "https://bloxberg.ethernity.cloud"
17
+ self.w3 = Web3(Web3.HTTPProvider(self.web3_provider))
18
+ self.w3.middleware_onion.inject(geth_poa_middleware, layer=0)
19
+
20
+ self.image_registry = self.w3.eth.contract(address=self.w3.toChecksumAddress(self.image_registry_address),
21
+ abi=image_registry_abi)
22
+
23
+ def __read_contract_abi(self, contract_name):
24
+ f = open(os.path.dirname(os.path.realpath(__file__)) + f'/{contract_name}')
25
+ contract_abi = f.read()
26
+ f.close()
27
+ return contract_abi
28
+
29
+ # (string memory ipfsHash, string memory publicKey, string memory version, string memory imageName, string memory dockerComposeHash)
30
+ def add_trusted_zone_cert(self, cert_content, ipfs_hash, image_name, docker_compose_hash, enclave_name_trustedzone, fee):
31
+ print('Adding trusted zone cert to image registry')
32
+ nonce = self.w3.eth.getTransactionCount(self.acct.address)
33
+ unicorn_txn = self.image_registry.functions.addTrustedZoneImage(
34
+ ipfs_hash, cert_content, 'v3', image_name, docker_compose_hash, enclave_name_trustedzone, fee
35
+ ).buildTransaction({
36
+ 'gas': 9000000,
37
+ 'chainId': 8995,
38
+ 'nonce': nonce,
39
+ 'gasPrice': self.w3.toWei("1", "mwei"),
40
+ })
41
+
42
+ signed_txn = self.w3.eth.account.sign_transaction(unicorn_txn, private_key=self.acct.key)
43
+ self.w3.eth.sendRawTransaction(signed_txn.rawTransaction)
44
+ # self.transaction = unicorn_tx signed
45
+ hash = self.w3.toHex(self.w3.sha3(signed_txn.rawTransaction))
46
+
47
+ try:
48
+ receipt = self.w3.eth.waitForTransactionReceipt(hash)
49
+ except Exception as e:
50
+ print(f'An error occurred while sending transaction', e)
51
+ raise
52
+
53
+ print('transaction status: ', receipt.status)
54
+ print('transaction receipt: ', receipt)
55
+ if receipt.status == 1:
56
+ print("Adding trusted zone cert transaction was successful!")
57
+ else:
58
+ print("Adding trusted zone cert transaction was UNSUCCESSFUL!")
59
+
60
+ def add_secure_lock_image_cert(self, cert_content, ipfs_hash, image_name, docker_compose_hash, enclave_name_securelock, fee):
61
+ print('Adding secure lock cert to image registry')
62
+ nonce = self.w3.eth.getTransactionCount(self.acct.address)
63
+ unicorn_txn = self.image_registry.functions.addImage(
64
+ ipfs_hash, cert_content, 'v3', image_name, docker_compose_hash, enclave_name_securelock, fee
65
+ ).buildTransaction({
66
+ 'gas': 9000000,
67
+ 'chainId': 8995,
68
+ 'nonce': nonce,
69
+ 'gasPrice': self.w3.toWei("1", "mwei"),
70
+ })
71
+ signed_txn = self.w3.eth.account.sign_transaction(unicorn_txn, private_key=self.acct.key)
72
+ self.w3.eth.sendRawTransaction(signed_txn.rawTransaction)
73
+ # self.transaction = unicorn_tx signed
74
+ hash = self.w3.toHex(self.w3.sha3(signed_txn.rawTransaction))
75
+
76
+ try:
77
+ receipt = self.w3.eth.waitForTransactionReceipt(hash)
78
+ except Exception as e:
79
+ print(f'An error occurred while sending transaction', e)
80
+ raise
81
+
82
+ print('transaction status: ', receipt.status)
83
+ print('transaction receipt: ', receipt)
84
+ if receipt.status == 1:
85
+ print("Adding secure lock transaction was successful!")
86
+ else:
87
+ print("Adding secure lock transaction was UNSUCCESSFUL!")
88
+
89
+ def validate_secure_lock_image_cert(self, ipfs_hash):
90
+ print('Validating secure lock cert to image registry')
91
+ nonce = self.w3.eth.getTransactionCount(self.acct.address)
92
+ unicorn_txn = self.image_registry.functions.validateImage(
93
+ ipfs_hash
94
+ ).buildTransaction({
95
+ 'gas': 9000000,
96
+ 'chainId': 8995,
97
+ 'nonce': nonce,
98
+ 'gasPrice': self.w3.toWei("1", "mwei"),
99
+ })
100
+ signed_txn = self.w3.eth.account.sign_transaction(unicorn_txn, private_key=self.acct.key)
101
+ self.w3.eth.sendRawTransaction(signed_txn.rawTransaction)
102
+ # self.transaction = unicorn_tx signed
103
+ hash = self.w3.toHex(self.w3.sha3(signed_txn.rawTransaction))
104
+
105
+ try:
106
+ receipt = self.w3.eth.waitForTransactionReceipt(hash)
107
+ except Exception as e:
108
+ print(f'An error occurred while sending transaction', e)
109
+ raise
110
+
111
+ print('transaction status: ', receipt.status)
112
+ print('transaction receipt: ', receipt)
113
+ if receipt.status == 1:
114
+ print("Validating secure lock cert transaction was successful!")
115
+ else:
116
+ print("Validating secure lock cert transaction was UNSUCCESSFUL!")
117
+
118
+ def add_secure_lock_and_validate_image_cert(self, cert_content, ipfs_hash, image_name, docker_compose_hash, enclave_name_securelock, fee):
119
+ self.add_secure_lock_image_cert(cert_content, ipfs_hash, image_name, docker_compose_hash, enclave_name_securelock, fee)
120
+ self.validate_secure_lock_image_cert(ipfs_hash)
121
+
122
+ def get_trusted_zone_cert(self, image_ipfs_hash):
123
+ cert = self.image_registry.caller().getTrustedZoneImageCertPublicKey(image_ipfs_hash)
124
+ print(cert)
125
+
126
+ def get_secure_lock_cert(self, image_ipfs_hash):
127
+ cert = self.image_registry.caller().getImageCertPublicKey(image_ipfs_hash)
128
+ print(cert)
129
+
130
+
131
+ if __name__ == '__main__':
132
+ image_registry = ImageRegistry()
133
+
134
+ # image_registry.add_trusted_zone_cert('cert-content', 'ipfs-hash')
135
+
136
+ # image_registry.add_secure_lock_and_validate_image_cert('cert-content', 'ipfs-hash')
137
+
138
+ image_registry.get_trusted_zone_cert('QmVPSWaDkSwMYjHd9G8SMrCwRH2KuXHzEWSnXQ7N7YsgvJ')
139
+ image_registry.get_secure_lock_cert('QmVPSWaDkSwMYjHd9G8SMrCwRH2KuXHzEWSnXQ7N7YsgvJ')
@@ -0,0 +1,45 @@
1
+ #!/usr/local/bin/python
2
+
3
+ import os
4
+
5
+ from image_registry import ImageRegistry
6
+ import re
7
+
8
+ try:
9
+ print("*********************")
10
+
11
+ def extract_certificate(certificate_string):
12
+ pattern = r"(?<=-----BEGIN CERTIFICATE-----\n)(.*?)(?=\n-----END CERTIFICATE-----)"
13
+ matches = re.findall(pattern, certificate_string, re.DOTALL)
14
+ if matches:
15
+ return matches[0].strip()
16
+ else:
17
+ return None
18
+
19
+
20
+ def read_file_content(file_path):
21
+ with open(file_path, 'r') as file:
22
+ content = file.read()
23
+ return content
24
+
25
+
26
+ secure_lock = read_file_content('certificate.securelock.crt')
27
+ # secure_lock = extract_certificate(secure_lock)
28
+ print("SECURELOCK:")
29
+ print(secure_lock)
30
+
31
+ trusted_zone = read_file_content('certificate.trustedzone.crt')
32
+ # trusted_zone = extract_certificate(trusted_zone)
33
+ print("TRUSTEDZONE:")
34
+ print(trusted_zone)
35
+ ipfs_hash = read_file_content('IPFS_HASH.ipfs')
36
+ ipfs_hash = ipfs_hash.strip()
37
+ ipfs_docker_compose_hash = read_file_content('IPFS_DOCKER_COMPOSE_HASH.ipfs')
38
+ ipfs_docker_compose_hash = ipfs_docker_compose_hash.strip()
39
+ print("IPFS_HASH: " + ipfs_hash)
40
+ imageRegistry = ImageRegistry()
41
+ imageRegistry.add_trusted_zone_cert(trusted_zone, ipfs_hash, 'etny-pynithy-testnet', ipfs_docker_compose_hash, os.getenv("ENCLAVE_NAME_TRUSTEDZONE"), 10)
42
+ imageRegistry.add_secure_lock_and_validate_image_cert(secure_lock, ipfs_hash, 'etny-pynithy-testnet', ipfs_docker_compose_hash, os.getenv("ENCLAVE_NAME_SECURELOCK"), 0)
43
+ print("************************")
44
+ except Exception as e:
45
+ print("An exception occurred: " + str(e))
@@ -0,0 +1,89 @@
1
+ #!/bin/sh
2
+
3
+ apk add wget tar git screen
4
+
5
+ export IPFS_HOME=${PWD}/ipfs
6
+ export IPFS_PATH=${IPFS_HOME}/.ipfs
7
+
8
+ export KUBO_URL="https://github.com/ipfs/kubo/releases/download/v0.17.0/kubo_v0.17.0_linux-386.tar.gz"
9
+ echo KUBO_URL=${KUBO_URL}
10
+
11
+ echo "git clone https://ci:${CI_ACCESS_TOKEN}@gitlab.ethernity.cloud/etny-node/etny-hash-packages.git ${CI_PROJECT_DIR}/etny-hash-packages"
12
+ git clone https://ci:${CI_ACCESS_TOKEN}@gitlab.ethernity.cloud/etny-node/etny-hash-packages.git ${CI_PROJECT_DIR}/etny-hash-packages
13
+
14
+ git -C ${CI_PROJECT_DIR}/etny-hash-packages config --local user.email "ci@ethernity.cloud"
15
+ git -C ${CI_PROJECT_DIR}/etny-hash-packages config --local user.name "CI/CD"
16
+
17
+ mkdir -p ${IPFS_HOME}
18
+
19
+ wget -qO- ${KUBO_URL} | tar xvz
20
+
21
+ # wget -qO- ${KUBO_URL} | tar xvz
22
+
23
+ echo "*** KUBO Downloaded ***"
24
+
25
+ if [ -d "${IPFS_PATH}" ]; then
26
+ killall ipfs
27
+ rm -fr ${IPFS_PATH}
28
+ fi
29
+
30
+ export IPFS_CMD=${PWD}/kubo/ipfs
31
+
32
+ ${IPFS_CMD} init
33
+
34
+ sleep 20
35
+
36
+ ${IPFS_CMD} daemon &
37
+
38
+ sleep 20
39
+
40
+ ${IPFS_CMD} swarm connect /ip4/31.7.188.59/tcp/4001/ipfs/QmRBc1eBt4hpJQUqHqn6eA8ixQPD3LFcUDsn6coKBQtia5
41
+ ${IPFS_CMD} bootstrap add /ip4/31.7.188.59/tcp/4001/ipfs/QmRBc1eBt4hpJQUqHqn6eA8ixQPD3LFcUDsn6coKBQtia5
42
+
43
+ #ADDING DOCKER COMPOSE hash
44
+ export IPFS_DOCKER_COMPOSE_HASH=`${IPFS_CMD} add docker-compose-final.yml | grep added | tail -1 | awk '{print $2}'`
45
+ echo "IPFS_DOCKER_COMPOSE_HASH=${IPFS_DOCKER_COMPOSE_HASH}"
46
+
47
+ cp certificate.securelock.crt "${REGISTRY_PATH}/certificate.securelock.crt"
48
+ cp certificate.trustedzone.crt "${REGISTRY_PATH}/certificate.trustedzone.crt"
49
+ echo "${REGISTRY_PATH}"
50
+ cd ${REGISTRY_PATH}
51
+
52
+ echo ipfs pin add --progress ${IPFS_DOCKER_COMPOSE_HASH}
53
+ ${IPFS_CMD} pin add --progress ${IPFS_DOCKER_COMPOSE_HASH}
54
+
55
+ #ADDING DOCKER IMAGE hash
56
+ export IPFS_HASH=`${IPFS_CMD} add . -r | grep added | tail -1 | awk '{print $2}'`
57
+ echo "IPFS_HASH=${IPFS_HASH}"
58
+
59
+ echo ipfs pin add --progress ${IPFS_HASH}
60
+ ${IPFS_CMD} pin add --progress ${IPFS_HASH}
61
+
62
+ #DOWNLOADING DOCKER COMPOSE FROM IFPS HASH
63
+ echo ipfs get ${IPFS_DOCKER_COMPOSE_HASH}
64
+ ${IPFS_CMD} get ${IPFS_DOCKER_COMPOSE_HASH}
65
+
66
+ #DOWNLOADING DOCKER IMAGE FROM IFPS HASH
67
+ echo ipfs get ${IPFS_HASH}
68
+ ${IPFS_CMD} get ${IPFS_HASH}
69
+
70
+
71
+ #ADD DOCKER IMAGE to GIT
72
+ echo touch ${CI_PROJECT_DIR}/etny-hash-packages/etny-pynithy/v3/${IPFS_HASH}
73
+ touch ${CI_PROJECT_DIR}/etny-hash-packages/etny-pynithy/v3/${IPFS_HASH}
74
+
75
+ #Add DOCKER COMPOSE to GIT
76
+ echo touch ${CI_PROJECT_DIR}/etny-hash-packages/etny-pynithy/v3/docker/${IPFS_DOCKER_COMPOSE_HASH}
77
+ touch ${CI_PROJECT_DIR}/etny-hash-packages/etny-pynithy/v3/docker/${IPFS_DOCKER_COMPOSE_HASH}
78
+
79
+ #ADDING CERTIFICATE TO GIT
80
+ mv certificate.securelock.crt "${CI_PROJECT_DIR}/etny-hash-packages/etny-pynithy/v3/cert/securelock/${IPFS_HASH}.crt"
81
+ cat "${CI_PROJECT_DIR}/etny-hash-packages/etny-pynithy/v3/cert/securelock/${IPFS_HASH}.crt"
82
+
83
+ mv certificate.trustedzone.crt "${CI_PROJECT_DIR}/etny-hash-packages/etny-pynithy/v3/cert/trustedzone/${IPFS_HASH}.crt"
84
+ cat "${CI_PROJECT_DIR}/etny-hash-packages/etny-pynithy/v3/cert/trustedzone/${IPFS_HASH}.crt"
85
+
86
+ cd -
87
+
88
+ echo "${IPFS_HASH}" > "IPFS_HASH.ipfs"
89
+ echo "${IPFS_DOCKER_COMPOSE_HASH}" > "IPFS_DOCKER_COMPOSE_HASH.ipfs"