@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,28 @@
1
+ const ethers = require('ethers');
2
+ const {sha256} = require('./etny_crypto');
3
+
4
+ function getWalletAddress(clientChallenge, enclaveChallenge) {
5
+ const encoded = clientChallenge + enclaveChallenge;
6
+ //console.log(encoded);
7
+ const walletPrivate = sha256(sha256(encoded));
8
+ //console.log(`0x${walletPrivate}`);
9
+
10
+ const wallet = new ethers.Wallet(walletPrivate);
11
+ //console.log(wallet);
12
+ return [wallet.address, walletPrivate];
13
+ }
14
+
15
+ function generateWalletFromPrivate(hash) {
16
+ return new ethers.Wallet(hash);
17
+ }
18
+
19
+ // const firstString = 'test';
20
+ // const secondString = 'test';
21
+ // const [addr, private] = getWalletAddress(firstString, secondString);
22
+ // console.log('account address =', addr); // 0xf63106856F7007A30025f0fFD5A534EA880878C3
23
+ // console.log('private =', private);
24
+
25
+ module.exports = {
26
+ getWalletAddress,
27
+ generateWalletFromPrivate
28
+ }
@@ -0,0 +1,184 @@
1
+ const AdmZip = require('adm-zip');
2
+ const shell = require('shelljs');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ require('dotenv').config();
6
+
7
+ const VERSION = process.env.VERSION;
8
+ console.log(`Building ${VERSION}`);
9
+
10
+ const writeEnv = (key, value) => {
11
+ const envFile = `${currentDir}/.env`;
12
+ let envContent = '';
13
+
14
+ if (fs.existsSync(envFile)) {
15
+ envContent = fs.readFileSync(envFile, 'utf8');
16
+ const regex = new RegExp(`^${key}=.*`, 'm');
17
+ if (regex.test(envContent)) {
18
+ envContent = envContent.replace(regex, `${key}=${value}`);
19
+ } else {
20
+ envContent += `\n${key}=${value}`;
21
+ }
22
+ } else {
23
+ envContent = `${key}=${value}`;
24
+ }
25
+
26
+ fs.writeFileSync(envFile, envContent, 'utf8');
27
+ };
28
+
29
+
30
+ const runCommand = (command, canPass = false) => {
31
+ if (shell.exec(command).code !== 0 && !canPass) {
32
+ console.error(`Error executing command: ${command}`);
33
+ process.exit(1);
34
+ }
35
+ };
36
+
37
+ // Downloading dependencies
38
+ shell.rm('-rf', './registry');
39
+ const currentDir = process.cwd();
40
+ // console.log(`current_dir: ${currentDir}`);
41
+ const buildDir = path.join(currentDir, 'node_modules/@ethernity-cloud/sdk-js/nodenithy/build');
42
+ // console.log(`build_dir: ${buildDir}`);
43
+
44
+ const dockerPS = shell.exec('docker ps --filter name=registry -q', { silent: true }).stdout.trim();
45
+ if (dockerPS) {
46
+ runCommand(`docker stop ${dockerPS.split('\n').join(' ')}`);
47
+ }
48
+ const dockeri = shell.exec('docker ps --filter name=las -q', { silent: true }).stdout.trim();
49
+ if (dockeri) {
50
+ runCommand(`docker stop ${dockeri.split('\n').join(' ')}`);
51
+ }
52
+ const dockerRm = shell.exec('docker ps --filter name=registry -q', { silent: true }).stdout.trim();
53
+ if (dockerRm) {
54
+ runCommand(`docker rm ${dockerRm.split('\n').join(' ')} -f`);
55
+ }
56
+ const dockerImg = shell.exec('docker images --filter reference="*etny*" -q', { silent: true }).stdout.trim();
57
+ if (dockerImg) {
58
+ runCommand(`docker rmi ${dockerImg.split('\n').join(' ')} -f`);
59
+ }
60
+ const dockerImgReg = shell.exec('docker images --filter reference="*registry*" -q', { silent: true }).stdout.trim();
61
+ if (dockerImgReg) {
62
+ runCommand(`docker rmi ${dockerImgReg.split('\n').join(' ')} -f`);
63
+ }
64
+ runCommand(`docker rm registry -f`);
65
+
66
+
67
+
68
+ const srcDir = './src/serverless';
69
+ const destDir = path.join(buildDir, 'securelock/src/serverless');
70
+ console.log(`Creating destination directory: ${destDir}`);
71
+ fs.mkdirSync(destDir, { recursive: true });
72
+
73
+ console.log(`Copying files from ${srcDir} to ${destDir}`);
74
+ fs.readdirSync(srcDir).forEach(file => {
75
+ fs.copyFileSync(path.join(srcDir, file), path.join(destDir, file));
76
+ });
77
+
78
+ process.chdir(buildDir);
79
+
80
+ // templateName is TRUSTED_ZONE_IMAGE (the registry image-name segment); trustedZoneNet
81
+ // is the network tag the nodenithy CI pushes the prebuilt trustedzone under
82
+ // (registry.ethernity.cloud:443/.../<templateName>/trustedzone:<trustedZoneNet>). Both must
83
+ // match v3/networks.yaml image_name + network key in the etny-nodenithy repo, or the pull
84
+ // below 404s and the SDK falls back to the vendored tarball.
85
+ let templateName = "";
86
+ let trustedZoneNet = "";
87
+ if (process.env.BLOCKCHAIN_NETWORK === 'Bloxberg_Testnet') {
88
+ templateName = 'etny-nodenithy-testnet'; trustedZoneNet = 'bloxberg_testnet';
89
+ } else if (process.env.BLOCKCHAIN_NETWORK === 'Bloxberg_Mainnet') {
90
+ templateName = 'etny-nodenithy'; trustedZoneNet = 'bloxberg';
91
+ } else if (process.env.BLOCKCHAIN_NETWORK === 'Polygon_Mainnet') {
92
+ templateName = 'ecld-nodenithy'; trustedZoneNet = 'polygon';
93
+ } else if (process.env.BLOCKCHAIN_NETWORK === 'Polygon_Amoy_Testnet') {
94
+ // image_name in etny-nodenithy v3/networks.yaml (amoy) is ecld-nodenithy-amoy,
95
+ // NOT ecld-nodenithy-testnet -- must match or the registry pull 404s.
96
+ templateName = 'ecld-nodenithy-amoy'; trustedZoneNet = 'amoy';
97
+ } else {
98
+ templateName = 'etny-nodenithy-testnet'; trustedZoneNet = 'bloxberg_testnet';
99
+ }
100
+
101
+ const ENCLAVE_NAME_TRUSTEDZONE = templateName;
102
+
103
+ runCommand('docker pull registry:2');
104
+ runCommand('docker run -d --restart=always -p 5000:5000 --name registry registry:2');
105
+ runCommand(`docker login ${process.env.DOCKER_REPO_URL} -u ${process.env.DOCKER_LOGIN} -p ${process.env.DOCKER_PASSWORD}`);
106
+
107
+ // const CI_COMMIT_BRANCH = process.env.PROJECT_NAME;
108
+ // aleXPRoj-securelock-v3-testnet-0.1.0...
109
+ const ENCLAVE_NAME_SECURELOCK = `${process.env.PROJECT_NAME}-SECURELOCK-V3-${process.env.BLOCKCHAIN_NETWORK.split('_')[1].toLowerCase()}-${VERSION}`.replace(/\//g, '_').replace(/-/g, '_');
110
+ console.log(`ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}`);
111
+ writeEnv('ENCLAVE_NAME_SECURELOCK', ENCLAVE_NAME_SECURELOCK);
112
+
113
+ console.log('Building etny-securelock');
114
+ process.chdir('securelock');
115
+ // runCommand(`cat Dockerfile.tmpl | sed s/"__ENCLAVE_NAME_SECURELOCK__"/"${ENCLAVE_NAME_SECURELOCK}"/g > Dockerfile`);
116
+ const dockerfileSecureTemplate = fs.readFileSync('Dockerfile.tmpl', 'utf8');
117
+ const dockerfileSecureContent = dockerfileSecureTemplate.replace(/__ENCLAVE_NAME_SECURELOCK__/g, ENCLAVE_NAME_SECURELOCK).replace(/__BUCKET_NAME__/g, templateName+"-v3");
118
+ fs.writeFileSync('Dockerfile', dockerfileSecureContent);
119
+
120
+
121
+ runCommand(`docker build --build-arg ENCLAVE_NAME_SECURELOCK=${ENCLAVE_NAME_SECURELOCK} -t etny-securelock:latest .`);
122
+ runCommand('docker tag etny-securelock localhost:5000/etny-securelock');
123
+ runCommand('docker push localhost:5000/etny-securelock');
124
+ // runCommand('docker save etny-securelock:latest -o etny-securelock.tar');
125
+ process.chdir('..');
126
+ // const ENCLAVE_NAME_TRUSTEDZONE = `ENCLAVE_NAME_TRUSTEDZONE_${VERSION}_${CI_COMMIT_BRANCH}`.toUpperCase().replace(/\//g, '_').replace(/-/g, '_');
127
+
128
+
129
+ console.log(`ENCLAVE_NAME_TRUSTEDZONE: ${ENCLAVE_NAME_TRUSTEDZONE}`);
130
+ writeEnv('ENCLAVE_NAME_TRUSTEDZONE', ENCLAVE_NAME_TRUSTEDZONE);
131
+
132
+ console.log('Building etny-trustedzone');
133
+ process.chdir('trustedzone');
134
+
135
+ // // runCommand(`cat Dockerfile.tmpl | sed s/"__ENCLAVE_NAME_TRUSTEDZONE__"/"${ENCLAVE_NAME_TRUSTEDZONE}"/g > Dockerfile`);
136
+ // const dockerfileTrustedTemplate = fs.readFileSync('Dockerfile.tmpl', 'utf8');
137
+ // const dockerfileTrustedContent = dockerfileTrustedTemplate.replace(/__ENCLAVE_NAME_SECURELOCK__/g, ENCLAVE_NAME_SECURELOCK);
138
+ // fs.writeFileSync('Dockerfile', dockerfileTrustedContent);
139
+
140
+ // Prefer the CI-built trustedzone published to the ethernity registry by the
141
+ // etny-nodenithy pipeline (registry.ethernity.cloud:443/.../<templateName>/trustedzone:<net>).
142
+ // This mirrors the Python SDK (ec-sdk-py build.py) and keeps the bundled trustedzone
143
+ // in sync with what is registered on-chain -- the vendored etny-trustedzone.tar.zip
144
+ // only refreshes when someone manually re-vendors it, so it drifts. Fall back to the
145
+ // vendored tarball if the pull fails (e.g. tag not yet published for this network).
146
+ const trustedZoneImage = `registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/${templateName}/trustedzone:${trustedZoneNet}`;
147
+ let pulledTrustedZone = false;
148
+ console.log(`Pulling prebuilt trustedzone: ${trustedZoneImage}`);
149
+ // canPass=true: a failed pull must NOT exit the build -- fall back to the vendored
150
+ // tarball instead (runCommand process.exit(1)s on failure otherwise).
151
+ if (shell.exec(`docker pull ${trustedZoneImage}`).code === 0) {
152
+ runCommand(`docker tag ${trustedZoneImage} etny-trustedzone:latest`);
153
+ pulledTrustedZone = true;
154
+ } else {
155
+ console.log(`WARN: could not pull ${trustedZoneImage}; falling back to vendored etny-trustedzone.tar.zip`);
156
+ }
157
+ if (!pulledTrustedZone) {
158
+ const zip = new AdmZip('etny-trustedzone.tar.zip');
159
+ zip.extractAllTo('.', true);
160
+ runCommand('docker load -i etny-trustedzone.tar');
161
+ }
162
+ runCommand('docker tag etny-trustedzone:latest localhost:5000/etny-trustedzone');
163
+ runCommand('docker push localhost:5000/etny-trustedzone');
164
+
165
+ console.log('Building validator');
166
+ process.chdir('../validator');
167
+ runCommand('docker build -t etny-validator:latest .');
168
+ runCommand('docker tag etny-validator localhost:5000/etny-validator');
169
+ runCommand('docker push localhost:5000/etny-validator');
170
+ // runCommand('docker save etny-validator:latest -o etny-validator.tar');
171
+
172
+ console.log('Building etny-las');
173
+ process.chdir('../las');
174
+ runCommand('docker build -t etny-las .');
175
+ runCommand('docker tag etny-las localhost:5000/etny-las');
176
+ runCommand('docker push localhost:5000/etny-las');
177
+ // runCommand('docker save etny-las:latest -o etny-las.tar');
178
+
179
+
180
+ process.chdir(currentDir);
181
+ runCommand('docker cp registry:/var/lib/registry registry');
182
+
183
+ console.log('Cleaning up');
184
+ fs.rmSync(destDir, { recursive: true, force: true });
@@ -0,0 +1,179 @@
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import dotenv from 'dotenv';
5
+ dotenv.config();
6
+
7
+ const VERSION = process.env.VERSION;
8
+ console.log(`Building ${VERSION}`);
9
+
10
+ const writeEnv = (key, value) => {
11
+ const envFile = `${currentDir}/.env`;
12
+ let envContent = '';
13
+
14
+ if (fs.existsSync(envFile)) {
15
+ envContent = fs.readFileSync(envFile, 'utf8');
16
+ const regex = new RegExp(`^${key}=.*`, 'm');
17
+ if (regex.test(envContent)) {
18
+ envContent = envContent.replace(regex, `${key}=${value}`);
19
+ } else {
20
+ envContent += `\n${key}=${value}`;
21
+ }
22
+ } else {
23
+ envContent = `${key}=${value}`;
24
+ }
25
+
26
+ fs.writeFileSync(envFile, envContent, 'utf8');
27
+ };
28
+ // runner name: [smart contract address, image registry address, rpc url, chainid]
29
+ export const ECRunner = {
30
+ 'etny-pynithy-testnet': ['0x02882F03097fE8cD31afbdFbB5D72a498B41112c', '0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31', 'https://core.bloxberg.org', 8995],
31
+ 'etny-nodenithy-testnet': ['0x02882F03097fE8cD31afbdFbB5D72a498B41112c', '0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31', 'https://core.bloxberg.org', 8995],
32
+ 'etny-pynithy': ['0x549A6E06BB2084100148D50F51CF77a3436C3Ae7', '0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31', 'https://core.bloxberg.org', 8995],
33
+ 'etny-nodenithy': ['0x549A6E06BB2084100148D50F51CF77a3436C3Ae7', '0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31', 'https://core.bloxberg.org', 8995],
34
+ 'ecld-nodenithy-testnet': ['0x4274b1188ABCfa0d864aFdeD86bF9545B020dCDf', '0xF7F4eEb3d9a64387F4AcEb6d521b948E6E2fB049', 'https://rpc-mumbai.matic.today', 80001],
35
+ 'ecld-pynithy': ['0x439945BE73fD86fcC172179021991E96Beff3Cc4', '0x689f3806874d3c8A973f419a4eB24e6fBA7E830F', 'https://polygon-rpc.com', 137],
36
+ 'ecld-nodenithy': ['0x439945BE73fD86fcC172179021991E96Beff3Cc4', '0x689f3806874d3c8A973f419a4eB24e6fBA7E830F', 'https://polygon-rpc.com', 137]
37
+ };
38
+
39
+ const runCommand = (command, canPass = false) => {
40
+ if (shell.exec(command).code !== 0 && !canPass) {
41
+ console.error(`Error executing command: ${command}`);
42
+ process.exit(1);
43
+ }
44
+ };
45
+
46
+ // Downloading dependencies
47
+ shell.rm('-rf', './registry');
48
+ const currentDir = process.cwd();
49
+ // console.log(`current_dir: ${currentDir}`);
50
+ const buildDir = path.join(currentDir, 'node_modules/@ethernity-cloud/sdk-js/nodenithy/build');
51
+ // console.log(`build_dir: ${buildDir}`);
52
+
53
+ const dockerPS = shell.exec('docker ps --filter name=registry -q', { silent: true }).stdout.trim();
54
+ if (dockerPS) {
55
+ runCommand(`docker stop ${dockerPS.split('\n').join(' ')}`);
56
+ }
57
+ const dockeri = shell.exec('docker ps --filter name=las -q', { silent: true }).stdout.trim();
58
+ if (dockeri) {
59
+ runCommand(`docker stop ${dockeri.split('\n').join(' ')}`);
60
+ }
61
+ const dockerRm = shell.exec('docker ps --filter name=registry -q', { silent: true }).stdout.trim();
62
+ if (dockerRm) {
63
+ runCommand(`docker rm ${dockerRm.split('\n').join(' ')} -f`);
64
+ }
65
+ const dockerImg = shell.exec('docker images --filter reference="*etny*" -q', { silent: true }).stdout.trim();
66
+ if (dockerImg) {
67
+ runCommand(`docker rmi ${dockerImg.split('\n').join(' ')} -f`);
68
+ }
69
+ const dockerImgReg = shell.exec('docker images --filter reference="*registry*" -q', { silent: true }).stdout.trim();
70
+ if (dockerImgReg) {
71
+ runCommand(`docker rmi ${dockerImgReg.split('\n').join(' ')} -f`);
72
+ }
73
+ runCommand(`docker rm registry -f`);
74
+
75
+
76
+
77
+ const srcDir = './src/serverless';
78
+ const destDir = path.join(buildDir, 'securelock/src/serverless');
79
+ console.log(`Creating destination directory: ${destDir}`);
80
+ fs.mkdirSync(destDir, { recursive: true });
81
+
82
+ console.log(`Copying files from ${srcDir} to ${destDir}`);
83
+ fs.readdirSync(srcDir).forEach(file => {
84
+ fs.copyFileSync(path.join(srcDir, file), path.join(destDir, file));
85
+ });
86
+
87
+ process.chdir(buildDir);
88
+
89
+ let templateName = process.env.TRUSTED_ZONE_IMAGE || 'etny-nodenithy-testnet';
90
+
91
+ const isMainnet = !templateName.includes('testnet');
92
+
93
+ const ENCLAVE_NAME_TRUSTEDZONE = templateName;
94
+
95
+ runCommand('docker pull registry:2');
96
+ runCommand('docker run -d --restart=always -p 5000:5000 --name registry registry:2');
97
+ // runCommand(`docker login ${process.env.DOCKER_REPO_URL} -u ${process.env.DOCKER_LOGIN} -p ${process.env.DOCKER_PASSWORD}`);
98
+
99
+ // const CI_COMMIT_BRANCH = process.env.PROJECT_NAME;
100
+ // aleXPRoj-securelock-v3-testnet-0.1.0...
101
+ const ENCLAVE_NAME_SECURELOCK = `${process.env.PROJECT_NAME}-SECURELOCK-V3-${process.env.BLOCKCHAIN_NETWORK.split('_')[1].toLowerCase()}-${VERSION}`.replace(/\//g, '_').replace(/-/g, '_');
102
+ console.log(`ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}`);
103
+ writeEnv('ENCLAVE_NAME_SECURELOCK', ENCLAVE_NAME_SECURELOCK);
104
+
105
+ console.log('Building etny-securelock');
106
+ process.chdir('securelock');
107
+ // runCommand(`cat Dockerfile.tmpl | sed s/"__ENCLAVE_NAME_SECURELOCK__"/"${ENCLAVE_NAME_SECURELOCK}"/g > Dockerfile`);
108
+ const dockerfileSecureTemplate = fs.readFileSync('Dockerfile.tmpl', 'utf8');
109
+ const dockerfileSecureContent = dockerfileSecureTemplate.replace(/__ENCLAVE_NAME_SECURELOCK__/g, ENCLAVE_NAME_SECURELOCK).replace(/__BUCKET_NAME__/g, templateName + "-v3").replace(/__SMART_CONTRACT_ADDRESS__/g, ECRunner[templateName][0]).replace(/__IMAGE_REGISTRY_ADDRESS__/g, ECRunner[templateName][1]).replace(/__RPC_URL__/g, ECRunner[templateName][2]).replace(/__CHAIN_ID__/g, ECRunner[templateName][3]).replace(/__TRUSTED_ZONE_IMAGE__/g, templateName);
110
+
111
+ fs.writeFileSync('Dockerfile', dockerfileSecureContent);
112
+
113
+ let imagesTag = process.env.BLOCKCHAIN_NETWORK.toLowerCase();
114
+
115
+ if (isMainnet) {
116
+ fs.writeFileSync('Dockerfile', dockerfileSecureContent.replace('# RUN scone-signer sign', 'RUN scone-signer sign'));
117
+ imagesTag = process.env.BLOCKCHAIN_NETWORK.split("_")[0].toLowerCase()
118
+ }
119
+
120
+
121
+
122
+
123
+ runCommand(`docker build --build-arg ENCLAVE_NAME_SECURELOCK=${ENCLAVE_NAME_SECURELOCK} -t etny-securelock:latest .`);
124
+ runCommand('docker tag etny-securelock localhost:5000/etny-securelock');
125
+ runCommand('docker push localhost:5000/etny-securelock');
126
+ // runCommand('docker save etny-securelock:latest -o etny-securelock.tar');
127
+ process.chdir('..');
128
+ // const ENCLAVE_NAME_TRUSTEDZONE = `ENCLAVE_NAME_TRUSTEDZONE_${VERSION}_${CI_COMMIT_BRANCH}`.toUpperCase().replace(/\//g, '_').replace(/-/g, '_');
129
+
130
+
131
+ console.log(`ENCLAVE_NAME_TRUSTEDZONE: ${ENCLAVE_NAME_TRUSTEDZONE}`);
132
+ writeEnv('ENCLAVE_NAME_TRUSTEDZONE', ENCLAVE_NAME_TRUSTEDZONE);
133
+
134
+ console.log('Building etny-trustedzone');
135
+ process.chdir('trustedzone');
136
+
137
+ // // runCommand(`cat Dockerfile.tmpl | sed s/"__ENCLAVE_NAME_TRUSTEDZONE__"/"${ENCLAVE_NAME_TRUSTEDZONE}"/g > Dockerfile`);
138
+ // const dockerfileTrustedTemplate = fs.readFileSync('Dockerfile.tmpl', 'utf8');
139
+ // const dockerfileTrustedContent = dockerfileTrustedTemplate.replace(/__ENCLAVE_NAME_SECURELOCK__/g, ENCLAVE_NAME_SECURELOCK);
140
+ // fs.writeFileSync('Dockerfile', dockerfileTrustedContent);
141
+
142
+ // runCommand(`docker build --build-arg ENCLAVE_NAME_TRUSTEDZONE=${ENCLAVE_NAME_TRUSTEDZONE} -t etny-trustedzone:latest .`);
143
+ // runCommand('docker tag etny-trustedzone localhost:5000/etny-trustedzone');
144
+ // runCommand('docker push localhost:5000/etny-trustedzone');
145
+ // runCommand('docker save etny-trustedzone:latest -o etny-trustedzone.tar');
146
+ // const zip = new AdmZip('etny-trustedzone.tar.zip');
147
+ // zip.extractAllTo('.', true);
148
+
149
+ runCommand(`docker pull registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/ethernity/etny-trustedzone:${imagesTag}`);
150
+ runCommand(`docker tag registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/ethernity/etny-trustedzone:${imagesTag} localhost:5000/etny-trustedzone`);
151
+ runCommand('docker push localhost:5000/etny-trustedzone');
152
+
153
+ if (isMainnet) {
154
+ console.log('Building validator');
155
+ process.chdir('../validator');
156
+ // runCommand('docker build -t etny-validator:latest .');
157
+ // runCommand('docker tag etny-validator localhost:5000/etny-validator');
158
+ // runCommand('docker push localhost:5000/etny-validator');
159
+ runCommand(`docker pull registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/ethernity/etny-validator:${imagesTag}`);
160
+ runCommand(`docker tag registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/ethernity/etny-validator:${imagesTag} localhost:5000/etny-validator`);
161
+ runCommand('docker push localhost:5000/etny-validator');
162
+ }
163
+
164
+
165
+ console.log('Building etny-las');
166
+ process.chdir('../las');
167
+ // runCommand('docker build -t etny-las .');
168
+ // runCommand('docker tag etny-las localhost:5000/etny-las');
169
+ // runCommand('docker push localhost:5000/etny-las');
170
+ runCommand(`docker pull registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/ethernity/etny-las:${imagesTag}`);
171
+ runCommand(`docker tag registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/ethernity/etny-las:${imagesTag} localhost:5000/etny-las`);
172
+ runCommand('docker push localhost:5000/etny-las');
173
+
174
+
175
+ process.chdir(currentDir);
176
+ runCommand('docker cp registry:/var/lib/registry registry');
177
+
178
+ console.log('Cleaning up');
179
+ fs.rmSync(destDir, { recursive: true, force: true });
@@ -0,0 +1,161 @@
1
+ #!/bin/sh
2
+ source .env
3
+ echo "Building ${VERSION}"
4
+
5
+ write_env() {
6
+ local key=$1
7
+ local value=$2
8
+ local env_file="$current_dir/.env"
9
+
10
+ # Check if the .env file exists
11
+ if [[ -f $env_file ]]; then
12
+ # Check if the key exists in the .env file
13
+ if grep -q "^${key}=" "$env_file"; then
14
+ # Update the existing key with the new value
15
+ sed -i '' "s/^${key}=.*/${key}=${value}/" "$env_file"
16
+ else
17
+ # Add the new key-value pair to the .env file
18
+ echo "${key}=${value}" >> "$env_file"
19
+ fi
20
+ else
21
+ # Create the .env file and add the key-value pair
22
+ echo "${key}=${value}" > "$env_file"
23
+ fi
24
+ }
25
+
26
+ # Downloading dependencies
27
+
28
+ rm -rf "./registry"
29
+
30
+ brew install jq
31
+ brew install wget
32
+ brew install python3
33
+ python3 -m venv venv
34
+ source venv/bin/activate
35
+ pip3 install --no-cache --upgrade pip minio web3==5.17.0 eth_account python-dotenv requests
36
+
37
+ docker stop $(docker ps -q)
38
+ docker rm $(docker ps -q) -f
39
+ docker rmi $(docker images -q) -f
40
+ docker system prune -f
41
+
42
+
43
+ # Changing to build directory
44
+ # cd build
45
+ # save current directory so that we can cd back to it at the end
46
+ current_dir=$(pwd)
47
+ echo "current_dir: $current_dir"
48
+ build_dir=$(pwd)/node_modules/ethernity-cloud-sdk-js/nodenithy/build
49
+ echo "build_dir: $build_dir"
50
+
51
+ src_dir="./src/serverless"
52
+ dest_dir="$build_dir/securelock/src/serverless"
53
+ # Create destination directory if it doesn't exist
54
+ echo "Creating destination directory: $dest_dir"
55
+ mkdir -p "$dest_dir"
56
+ if [ $? -eq 0 ]; then
57
+ echo "Directory created successfully: $dest_dir"
58
+ else
59
+ echo "Failed to create directory: $dest_dir"
60
+ fi
61
+
62
+ # Copy all files from source to destination
63
+ echo "Copying files from $src_dir to $dest_dir"
64
+ cp -r "$src_dir/"* "$dest_dir/"
65
+ if [ $? -eq 0 ]; then
66
+ echo "Files copied successfully"
67
+ else
68
+ echo "Failed to copy files"
69
+ fi
70
+
71
+ cd $build_dir
72
+
73
+ # Pulls default docker registry image and starts on local port 5001
74
+ docker pull registry:2
75
+ docker run -d --restart=always -p 5001:5000 --name registry registry:2
76
+
77
+ # Login to scontain registry using enviornment variables (The are set in Gitlab now)
78
+ docker login ${DOCKER_REPO_URL} -u ${DOCKER_LOGIN} -p ${DOCKER_PASSWORD}
79
+
80
+ CI_COMMIT_BRANCH=PROJECT_NAME
81
+
82
+ # Defining ENV variables for build
83
+ ENCLAVE_NAME_SECURELOCK=$(echo ENCLAVE_NAME_SECURELOCK_${VERSION}_${CI_COMMIT_BRANCH} | awk '{print toupper($0)}' | sed 's#/#_#' | sed 's#-#_#')
84
+
85
+ # Create new variable PREDECESSOR_NAME if it doesn't exits
86
+ # curl -s --request POST --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" "https://gitlab.ethernity.cloud/api/v4/projects/${CI_PROJECT_ID}/variables" --form "key=${ENCLAVE_NAME_SECURELOCK}" --form "value=etny-${RUNNER_TYPE}-securelock-${VERSION}-testnet-0.0.0"
87
+ # echo "ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}"
88
+
89
+ # ENCLAVE_NAME_SECURELOCK=${ENCLAVE_NAME_SECURELOCK}"
90
+
91
+ echo
92
+ echo "ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}"
93
+ write_env "ENCLAVE_NAME_SECURELOCK" "${ENCLAVE_NAME_SECURELOCK}"
94
+ echo
95
+
96
+
97
+ echo "Building etny-securelock"
98
+ cd securelock/
99
+ cat Dockerfile.tmpl | sed s/"__ENCLAVE_NAME_SECURELOCK__"/"${ENCLAVE_NAME_SECURELOCK}"/g > Dockerfile
100
+ docker build --build-arg ENCLAVE_NAME_SECURELOCK=${ENCLAVE_NAME_SECURELOCK} -t etny-securelock:latest .
101
+ docker tag etny-securelock localhost:5001/etny-securelock
102
+ # Pushes the resulting image to local registry
103
+ docker push localhost:5001/etny-securelock
104
+
105
+ docker save etny-securelock:latest -o etny-securelock.tar
106
+
107
+
108
+ # Defining ENV variables for build
109
+ ENCLAVE_NAME_TRUSTEDZONE=$(echo ENCLAVE_NAME_TRUSTEDZONE_${VERSION}_${CI_COMMIT_BRANCH} | awk '{print toupper($0)}' | sed 's#/#_#' | sed 's#-#_#')
110
+
111
+ # Create new variable PREDECESSOR_NAME if it doesn't exits
112
+ #curl -s --request POST --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" "https://gitlab.ethernity.cloud/api/v4/projects/${CI_PROJECT_ID}/variables" --form "key=${ENCLAVE_NAME_TRUSTEDZONE}" --form "value=etny-${RUNNER_TYPE}-trustedzone-${VERSION}-testnet-0.0.0"
113
+
114
+ # ENCLAVE_NAME_TRUSTEDZONE=$(eval "echo \${$ENCLAVE_NAME_TRUSTEDZONE}")
115
+
116
+ echo
117
+ echo "ENCLAVE_NAME_TRUSTEDZONE: ${ENCLAVE_NAME_TRUSTEDZONE}"
118
+ write_env "ENCLAVE_NAME_TRUSTEDZONE" "${ENCLAVE_NAME_TRUSTEDZONE}"
119
+
120
+ echo
121
+
122
+ cd ../trustedzone/
123
+ echo "Building etny-trustedzone"
124
+ cat Dockerfile.tmpl | sed s/"__ENCLAVE_NAME_TRUSTEDZONE__"/"${ENCLAVE_NAME_TRUSTEDZONE}"/g > Dockerfile
125
+ docker build --build-arg ENCLAVE_NAME_TRUSTEDZONE=${ENCLAVE_NAME_TRUSTEDZONE} -t etny-trustedzone:latest .
126
+ docker tag etny-trustedzone localhost:5001/etny-trustedzone
127
+ # Pushes the resulting image to local registry
128
+ docker push localhost:5001/etny-trustedzone
129
+ docker save etny-trustedzone:latest -o etny-trustedzone.tar
130
+
131
+
132
+ cd ../validator/
133
+ echo "Building validator"
134
+ docker build -t etny-validator:latest .
135
+ docker tag etny-validator localhost:5001/etny-validator
136
+ # Pushes the resulting image to local registry
137
+ docker push localhost:5001/etny-validator
138
+
139
+ docker save etny-validator:latest -o etny-validator.tar
140
+
141
+ cd ../
142
+
143
+ # Downloads las, squashes and pushes it to local registry
144
+ cd las
145
+ docker build -t etny-las .
146
+ docker tag etny-las localhost:5001/etny-las
147
+ docker push localhost:5001/etny-las
148
+ docker save etny-las:latest -o etny-las.tar
149
+
150
+
151
+ # Copying from the registry container the whole storage of the registry and saves it under 'registry'. This is where the artifacts are picked up from.
152
+ # cd ../../
153
+
154
+ # delete the ecld-backend.js files we copied to the build directory
155
+ rm -rf "$dest_dir"
156
+
157
+ # exit the python virtual environment
158
+ deactivate
159
+
160
+ cd $current_dir
161
+ docker cp registry:/var/lib/registry registry