@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
package/README.md ADDED
@@ -0,0 +1,185 @@
1
+
2
+ # Ethernity Cloud SDK JS
3
+
4
+ This project provides a set of tools and scripts to work with the Ethernity Cloud SDK in a JavaScript environment.
5
+
6
+ ## Table of Contents
7
+
8
+ - [Installation](#installation)
9
+ - [Usage](#usage)
10
+ - [Scripts](#scripts)
11
+ - [Project Structure](#project-structure)
12
+ - [Contributing](#contributing)
13
+ - [License](#license)
14
+
15
+ ## Installation
16
+
17
+ To install the package and its dependencies, run:
18
+
19
+ ```sh
20
+ npm install ethernity-cloud-sdk-js
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ After installation, you can use the provided scripts to build, publish, and initialize your project.
26
+
27
+ ## Pre-requisites
28
+ The sdk requires the following to be installed on your system:
29
+ - Node.js v20.04 or higher
30
+ - npm
31
+ - docker (daemon running in the background for build and publish scripts)
32
+
33
+
34
+ ## Operating System compatibility
35
+ The sdk has been tested on the following operating systems:
36
+ - MacOS
37
+ - Ubuntu 20.04
38
+ - Windows 10
39
+
40
+ ## Blockchain compatibility
41
+ - Bloxberg:
42
+ - Testnet - tested and working
43
+ - Mainnet - to be provided during the following updates
44
+ - Polyhon:
45
+ - Amoy Testnet - to be provided during the following updates
46
+ - Mainnet - to be provided during the following updates
47
+
48
+ ### Scripts
49
+
50
+ - **Initialize**: To initialize the project, run:
51
+ ```sh
52
+ npm run ecld-init
53
+ ```
54
+ at this step, all the initial configurations will be set up and the project will be ready to be built, published and run.
55
+
56
+ - **Build**: To build the project, run:
57
+ ```sh
58
+ npm run ecld-build
59
+ ```
60
+ the project will be built and the docker repository output will be stored in the `registry/` directory. This is the stage where the backend functions are added to the secure images.
61
+
62
+ - **Publish**: To publish the project, run:
63
+ ```sh
64
+ npm run ecld-publish
65
+ ```
66
+ Required after build, to build and integrate the secure certificates that will be used during executions and to register the project to the Ethernity Cloud Image Register.
67
+
68
+ - **Run**: To run the project, run:
69
+ ```sh
70
+ npm run start
71
+ ```
72
+ command to start the demo application and test the integration.
73
+
74
+ ## Project Structure
75
+
76
+ ```
77
+ .gitignore
78
+ build.js
79
+ build.sh
80
+ demo/
81
+ init.js
82
+ nodenithy/
83
+ package.json
84
+ postinstall.js
85
+ publish.js
86
+ pynithy/
87
+ ```
88
+
89
+ ### Notable Directories and Files
90
+
91
+ - **[`build.js`](command:_github.copilot.openRelativePath?%5B%7B%22scheme%22%3A%22file%22%2C%22authority%22%3A%22%22%2C%22path%22%3A%22%2FUsers%2Fbullet%2Fethernity%2Fethernity-cloud-sdk-js%2Fbuild.js%22%2C%22query%22%3A%22%22%2C%22fragment%22%3A%22%22%7D%5D "/Users/bullet/ethernity/ethernity-cloud-sdk-js/build.js")**: Script to build the project.
92
+ - **[`init.js`](command:_github.copilot.openRelativePath?%5B%7B%22scheme%22%3A%22file%22%2C%22authority%22%3A%22%22%2C%22path%22%3A%22%2FUsers%2Fbullet%2Fethernity%2Fethernity-cloud-sdk-js%2Finit.js%22%2C%22query%22%3A%22%22%2C%22fragment%22%3A%22%22%7D%5D "/Users/bullet/ethernity/ethernity-cloud-sdk-js/init.js")**: Script to initialize the project.
93
+ - **[`publish.js`](command:_github.copilot.openRelativePath?%5B%7B%22scheme%22%3A%22file%22%2C%22authority%22%3A%22%22%2C%22path%22%3A%22%2FUsers%2Fbullet%2Fethernity%2Fethernity-cloud-sdk-js%2Fpublish.js%22%2C%22query%22%3A%22%22%2C%22fragment%22%3A%22%22%7D%5D "/Users/bullet/ethernity/ethernity-cloud-sdk-js/publish.js")**: Script to publish the project.
94
+ - **[`postinstall.js`](command:_github.copilot.openRelativePath?%5B%7B%22scheme%22%3A%22file%22%2C%22authority%22%3A%22%22%2C%22path%22%3A%22%2FUsers%2Fbullet%2Fethernity%2Fethernity-cloud-sdk-js%2Fpostinstall.js%22%2C%22query%22%3A%22%22%2C%22fragment%22%3A%22%22%7D%5D "/Users/bullet/ethernity/ethernity-cloud-sdk-js/postinstall.js")**: Script that runs after the package is installed.
95
+ - **[`nodenithy/`](command:_github.copilot.openRelativePath?%5B%7B%22scheme%22%3A%22file%22%2C%22authority%22%3A%22%22%2C%22path%22%3A%22%2FUsers%2Fbullet%2Fethernity%2Fethernity-cloud-sdk-js%2Fnodenithy%2F%22%2C%22query%22%3A%22%22%2C%22fragment%22%3A%22%22%7D%5D "/Users/bullet/ethernity/ethernity-cloud-sdk-js/nodenithy/")**: Contains various scripts and modules for the project.
96
+ - **[`pynithy/`](command:_github.copilot.openRelativePath?%5B%7B%22scheme%22%3A%22file%22%2C%22authority%22%3A%22%22%2C%22path%22%3A%22%2FUsers%2Fbullet%2Fethernity%2Fethernity-cloud-sdk-js%2Fpynithy%2F%22%2C%22query%22%3A%22%22%2C%22fragment%22%3A%22%22%7D%5D "/Users/bullet/ethernity/ethernity-cloud-sdk-js/pynithy/")**: Contains Python-related scripts and configurations.
97
+
98
+ ## Usage
99
+
100
+ To use the SDK:
101
+ - after installation, run `npm run ecld-init` to initialize the project
102
+ - in you workspace, you will find the `scr/serverless` directory, this contains a `backend.js` file. This file will be imported in the dApp images to provide the backend functions for calling from the frontend of your application, eg.:
103
+ ```js
104
+ function hello(msg='World') {
105
+ return "Hello "+msg;
106
+ }
107
+
108
+ module.exports = { hello };
109
+ ```
110
+ From your frontend application, using the ethernity cloud runner library, you will be calling the function as seen in the below example, where we pass `hello("World");` to be executed on the backend which will run in the Blockchain:
111
+ ```js
112
+ const AppCss = require('./App.css');
113
+ import EthernityCloudRunner from "@ethernity-cloud/runner";
114
+ import {ECEvent, ECRunner, ECStatus} from "@ethernity-cloud/runner/enums";
115
+ import Web3 from 'web3';
116
+
117
+ const PROJECT_NAME = "";
118
+ const IPFS_ENDPOINT = "";
119
+
120
+ const code = `hello("World");`;
121
+
122
+ function App() {
123
+ const executeTask = async () => {
124
+ const runner = new EthernityCloudRunner();
125
+ // this is a server provided by Ethernity CLOUD, please bear in mind that you can use your own Decentralized Storage server
126
+ const ipfsAddress = IPFS_ENDPOINT;
127
+ runner.initializeStorage(ipfsAddress);
128
+ console.log(PROJECT_NAME)
129
+ const onTaskProgress = (e) => {
130
+ if (e.detail.status === ECStatus.ERROR) {
131
+ console.error(e.detail.message);
132
+ } else {
133
+ console.log(e.detail.message);
134
+ }
135
+ };
136
+
137
+ const onTaskCompleted = (e) => {
138
+ console.log(`Task Result: ${e.detail.message.result}`);
139
+ // display the result in page below the buttons
140
+ const result = document.createElement("p");
141
+ result.innerHTML = `Task Result: ${e.detail.message.result}`;
142
+ document.body.appendChild(result);
143
+ }
144
+
145
+ runner.addEventListener(ECEvent.TASK_PROGRESS, onTaskProgress);
146
+ runner.addEventListener(ECEvent.TASK_COMPLETED, onTaskCompleted);
147
+
148
+ await runner.run(PROJECT_NAME,
149
+ code,
150
+ '',
151
+ { taskPrice: 10, cpu: 1, memory: 1, storage: 10, bandwidth: 1, duration: 1, validators: 1 });
152
+ };
153
+ const connectWallet = async () => {
154
+ if (window.ethereum) {
155
+ window.web3 = new Web3(window.ethereum);
156
+ try {
157
+ // Request account access
158
+ await window.ethereum.request({ method: 'eth_requestAccounts' });
159
+ console.log("Wallet connected");
160
+ } catch (error) {
161
+ console.error("User denied account access");
162
+ }
163
+ } else {
164
+ console.log('Please install MetaMask!');
165
+ }
166
+ };
167
+
168
+ return (
169
+ <div className="container">
170
+ <button className="centeredButton" onClick={executeTask}>Execute Task</button>
171
+ <button className="centeredButton" onClick={connectWallet}>Connect Wallet</button>
172
+ </div>
173
+ );
174
+ }
175
+ export default App;
176
+ ```
177
+ - you are able to define the functions needed to be used in the backend, while making sure that the function that is script is compilable and that it exports the function that will be called from the frontend, in the above example, the `hello` function.
178
+
179
+ ## Contributing
180
+
181
+ Contributions are welcome! Please open an issue or submit a pull request.
182
+
183
+ ## License
184
+
185
+ This project is licensed under the AGPL-3.0 License. See the LICENSE file for details.
package/build.js ADDED
@@ -0,0 +1,22 @@
1
+ const { execSync } = require('child_process');
2
+ const path = require('path');
3
+ require('dotenv').config();
4
+
5
+ const serviceType = process.env.SERVICE_TYPE;
6
+
7
+ if (serviceType === "Nodenithy") {
8
+ console.log("Adding prerequisites for Nodenithy...");
9
+ const scriptPath = path.resolve(__dirname, 'nodenithy/build.mjs');
10
+ console.log(`Running script: ${scriptPath}`);
11
+ execSync(`node ${scriptPath}`, { stdio: 'inherit' });
12
+ console.log(`Build script finished. You can now proceed to publish: npm run ecld-publish.`);
13
+ } else if (serviceType === "Pynithy") {
14
+ console.log("Adding prerequisites for Pynithy...");
15
+ const scriptPath = path.resolve(__dirname, 'pynithy/build.mjs');
16
+ console.log(`Running script: ${scriptPath}`);
17
+ execSync(`node ${scriptPath}`, { stdio: 'inherit' });
18
+ console.log(`Build script finished. You can now proceed to publish: npm run ecld-publish.`);
19
+ } else {
20
+ console.error("Something went wrong");
21
+ process.exit(1);
22
+ }
package/init.js ADDED
@@ -0,0 +1,301 @@
1
+ const fs = require("fs");
2
+ const readline = require("readline");
3
+ const { spawn, execSync } = require("child_process");
4
+ const path = require("path");
5
+
6
+ const rl = readline.createInterface({
7
+ input: process.stdin,
8
+ output: process.stdout,
9
+ });
10
+
11
+ const writeEnv = (key, value) => {
12
+ const envFile = ".env";
13
+ let content = "";
14
+
15
+ if (fs.existsSync(envFile)) {
16
+ content = fs.readFileSync(envFile, "utf8");
17
+ const regex = new RegExp(`^${key}=.*`, "m");
18
+ if (regex.test(content)) {
19
+ content = content.replace(regex, `${key}=${value}`);
20
+ } else {
21
+ content += `\n${key}=${value}`;
22
+ }
23
+ } else {
24
+ content = `${key}=${value}`;
25
+ }
26
+
27
+ fs.writeFileSync(envFile, content, "utf8");
28
+ };
29
+
30
+ const getProjectName = () => {
31
+ return new Promise((resolve) => {
32
+ const askProjectName = () => {
33
+ rl.question("Choose a name for your project: ", (projectName) => {
34
+ if (projectName.trim() === "") {
35
+ console.log(
36
+ "Project name cannot be blank. Please enter a valid name.",
37
+ );
38
+ askProjectName();
39
+ } else {
40
+ console.log(`You have chosen the project name: ${projectName}`);
41
+ resolve(projectName);
42
+ }
43
+ });
44
+ };
45
+ askProjectName();
46
+ });
47
+ };
48
+
49
+ const displayOptions = (options) => {
50
+ options.forEach((option, index) => {
51
+ console.log(`${index + 1}) ${option}`);
52
+ });
53
+ };
54
+
55
+ const promptOptions = (message, options, defaultOption) => {
56
+ return new Promise((resolve) => {
57
+ const askOption = () => {
58
+ displayOptions(options);
59
+ rl.question(message, (reply) => {
60
+ if (reply.trim() === "") {
61
+ console.log(`No option selected. Defaulting to ${defaultOption}.`);
62
+ resolve(defaultOption);
63
+ } else if (!isNaN(reply) && reply >= 1 && reply <= options.length) {
64
+ resolve(options[reply - 1]);
65
+ } else {
66
+ console.log(`Invalid option ${reply}. Please select a valid number.`);
67
+ askOption();
68
+ }
69
+ });
70
+ };
71
+ askOption();
72
+ });
73
+ };
74
+
75
+ const printIntro = () => {
76
+ const intro = `
77
+ ╔───────────────────────────────────────────────────────────────────────────────────────────────────────────────╗
78
+ │ │
79
+ │ .... -+++++++. .... │
80
+ │ -++++++++- .++++++++. _____ _ _ _ _ ____ _ _ │
81
+ │ .++- .. .++- .++- | ____| |_| |__ ___ _ __ _ __ (_) |_ _ _ / ___| | ___ _ _ __| | │
82
+ │ --++---- .++- ... | _| | __| '_ \\ / _ \\ '__| '_ \\| | __| | | | | | | |/ _ \\| | | |/ _\` | │
83
+ │ --++---- .++-. ... | |___| |_| | | | __/ | | | | | | |_| |_| | | |___| | (_) | |_| | (_| | │
84
+ │ .++- .+++. . .--. |_____|\\__|_| |_|\\___|_| |_| |_|_|\\__|\\__, | \\____|_|\\___/ \\__,_|\\__,_| │
85
+ │ -++++++++. .---------. |___/ │
86
+ │ .... .-------. .... │
87
+ │ │
88
+ ╚───────────────────────────────────────────────────────────────────────────────────────────────────────────────╝
89
+ Welcome to the Ethernity Cloud SDK
90
+
91
+ The Ethernity Cloud SDK is a comprehensive toolkit designed to facilitate the development and management of
92
+ decentralized applications (dApps) and serverless binaries on the Ethernity Cloud ecosystem. Geared towards
93
+ developers proficient in Python or Node.js, this toolkit aims to help you effectively harness the key features
94
+ of the ecosystem, such as data security, decentralized processing, and blockchain-driven transparency and
95
+ trustless model for real-time data processing.
96
+ `;
97
+ console.log(intro);
98
+ };
99
+
100
+ const main = async () => {
101
+ printIntro();
102
+ const projectName = await getProjectName();
103
+ console.log();
104
+ const serviceTypeOptions = ["Nodenithy", "Pynithy", "Custom"];
105
+ const serviceType = await promptOptions(
106
+ "Select the type of code to be ran during the compute layer (default is Nodenithy): ",
107
+ serviceTypeOptions,
108
+ "Nodenithy",
109
+ );
110
+
111
+ let dockerRepoUrl, dockerLogin, dockerPassword, baseImageTag;
112
+ if (serviceType === "Custom") {
113
+ dockerRepoUrl = await new Promise((resolve) =>
114
+ rl.question("Enter Docker repository URL: ", resolve),
115
+ );
116
+ dockerLogin = await new Promise((resolve) =>
117
+ rl.question("Enter Docker Login (username): ", resolve),
118
+ );
119
+ dockerPassword = await new Promise((resolve) =>
120
+ rl.question("Enter Password: ", resolve),
121
+ );
122
+ baseImageTag = await new Promise((resolve) =>
123
+ rl.question("Enter the image tag: ", resolve),
124
+ );
125
+ }
126
+ console.log();
127
+ const blockchainNetworkOptions = [
128
+ "Bloxberg Mainnet",
129
+ "Bloxberg Testnet",
130
+ "Polygon Mainnet",
131
+ "Polygon Amoy Testnet",
132
+ ];
133
+ const blockchainNetwork = await promptOptions(
134
+ "On which Blockchain network do you want to have the app set up, as a starting point? (default is Bloxberg Testnet): ",
135
+ blockchainNetworkOptions,
136
+ "Bloxberg Testnet",
137
+ );
138
+ console.log();
139
+
140
+ console.log(
141
+ `Checking if the project name (image name) is available on the ${blockchainNetwork.replace(/ /g, "_")} network and ownership...`,
142
+ );
143
+ // const { execSync } = require('child_process');
144
+ // execSync(`python $(pwd)/node_modules/@ethernity-cloud/sdk-js/nodenithy/run/image_registry.py "${blockchainNetwork.replace(/ /g, "_")}" "${projectName.replace(/ /g, "-")}" v3`);
145
+ const scriptPath = path.resolve(__dirname, "nodenithy/run/image_registry.js");
146
+ // Spawn a new process to run the image_registry.js script
147
+ const runChildProcess = () =>
148
+ new Promise((resolve, reject) => {
149
+ const child = spawn("node", [
150
+ scriptPath,
151
+ blockchainNetwork.replace(/ /g, "_"),
152
+ projectName.replace(/ /g, "-"),
153
+ "v3",
154
+ ]);
155
+ // Handle stdout data
156
+ child.stdout.on("data", (data) => {
157
+ console.log(
158
+ `${data}`.replace("duplicate definition - constructor", ""),
159
+ );
160
+ });
161
+ child.on("close", (code) => {
162
+ if (code === 0) {
163
+ resolve();
164
+ } else {
165
+ reject();
166
+ }
167
+ });
168
+ });
169
+ await runChildProcess();
170
+
171
+ // // Handle stderr data
172
+ // child.stderr.on('data', (data) => {
173
+ // console.error(`stderr: ${data}`);
174
+ // });
175
+
176
+ // Handle process exit
177
+ // child.on('close', (code) => {
178
+ // console.log(`child process exited with code ${code}`);
179
+ // });
180
+
181
+ console.log();
182
+ const ipfsServiceOptions = ["Ethernity (best effort)", "Custom IPFS"];
183
+ const ipfsService = await promptOptions(
184
+ "Select the IPFS pinning service you want to use (default is Ethernity): ",
185
+ ipfsServiceOptions,
186
+ "Ethernity (best effort)",
187
+ );
188
+
189
+ let customUrl, ipfsToken;
190
+ if (ipfsService === "Custom IPFS") {
191
+ customUrl = await new Promise((resolve) =>
192
+ rl.question(
193
+ "Enter the endpoint URL for the IPFS pinning service you want to use: ",
194
+ resolve,
195
+ ),
196
+ );
197
+ ipfsToken = await new Promise((resolve) =>
198
+ rl.question(
199
+ "Enter the access token to be used when calling the IPFS pinning service: ",
200
+ resolve,
201
+ ),
202
+ );
203
+ } else {
204
+ customUrl = "http://ipfs.ethernity.cloud:5001";
205
+ }
206
+
207
+ fs.mkdirSync("src/serverless", { recursive: true });
208
+
209
+ console.log();
210
+ const appTemplateOptions = ["yes", "no"];
211
+ const useAppTemplate = await promptOptions(
212
+ "Do you want a 'Hello World' app template as a starting point? (default is yes): ",
213
+ appTemplateOptions,
214
+ "yes",
215
+ );
216
+
217
+ if (useAppTemplate === "yes") {
218
+ console.log("Bringing Frontend/Backend templates...");
219
+ if (serviceType === "Nodenithy") {
220
+ console.log(" src/serverless/backend.js (Hello World function)");
221
+ console.log(
222
+ " src/ec_helloworld_example.js (Hello World function call - Frontend)",
223
+ );
224
+ // Simulate copying files
225
+ fs.cpSync("node_modules/@ethernity-cloud/sdk-js/nodenithy/src/", "src/", {
226
+ recursive: true,
227
+ });
228
+ fs.cpSync(
229
+ "node_modules/@ethernity-cloud/sdk-js/nodenithy/public/",
230
+ "public/",
231
+ { recursive: true },
232
+ );
233
+ } else if (serviceType === "Pynithy") {
234
+ console.log(" src/serverless/backend.py (Hello World function)");
235
+ console.log(
236
+ " src/ec_helloworld_example.js (Hello World function call - Frontend)",
237
+ );
238
+ // Simulate copying files
239
+ fs.cpSync("node_modules/@ethernity-cloud/sdk-js/pynithy/src/", "src/", {
240
+ recursive: true,
241
+ });
242
+ fs.cpSync(
243
+ "node_modules/@ethernity-cloud/sdk-js/pynithy/public/",
244
+ "public/",
245
+ { recursive: true },
246
+ );
247
+ }
248
+ console.log("Installing required packages...");
249
+ // Simulate npm install
250
+ execSync(
251
+ "npm install @ethernity-cloud/runner@0.0.26 @testing-library/jest-dom@5.17.0 @testing-library/react@13.4.0 @testing-library/user-event@13.5.0 react@18.3.1 react-dom@18.3.1 react-scripts@5.0.1 web-vitals@2.1.4 web3@4.9.0 dotenv@16.4.5",
252
+ { stdio: "inherit" },
253
+ );
254
+ } else {
255
+ console.log(
256
+ "Define backend functions in src/serverless to be available for Frontend interaction.",
257
+ );
258
+ }
259
+
260
+ writeEnv("PROJECT_NAME", projectName.replace(/ /g, "_"));
261
+ writeEnv("SERVICE_TYPE", serviceType);
262
+ if (serviceType === "Custom") {
263
+ writeEnv("BASE_IMAGE_TAG", baseImageTag || "");
264
+ writeEnv("DOCKER_REPO_URL", dockerRepoUrl);
265
+ writeEnv("DOCKER_LOGIN", dockerLogin);
266
+ writeEnv("DOCKER_PASSWORD", dockerPassword);
267
+ } else if (serviceType === "Nodenithy") {
268
+ writeEnv("BASE_IMAGE_TAG", "");
269
+ writeEnv("DOCKER_REPO_URL", "");
270
+ writeEnv("DOCKER_LOGIN", "");
271
+ writeEnv("DOCKER_PASSWORD", "");
272
+ } else if (serviceType === "Pynithy") {
273
+ writeEnv("BASE_IMAGE_TAG", "");
274
+ writeEnv("DOCKER_REPO_URL", "");
275
+ writeEnv("DOCKER_LOGIN", "");
276
+ writeEnv("DOCKER_PASSWORD", "");
277
+ }
278
+ // write TRUSTED_ZONE_IMAGE {token}_{name}{networktype} with the following rules:
279
+ // - token should be ecld if network is polygon, etny if network is bloxberg
280
+ // - name should be serviceType.toLowerCase()
281
+ // - networktype should be "" if network contains 'mainnet' else '_testnet'
282
+ writeEnv(
283
+ "TRUSTED_ZONE_IMAGE",
284
+ `${blockchainNetwork.includes("Polygon") ? "ecld" : "etny"
285
+ }-${serviceType.toLowerCase()}${blockchainNetwork.includes("Mainnet") ? "" : "-testnet"
286
+ }`,
287
+ );
288
+
289
+
290
+ writeEnv("BLOCKCHAIN_NETWORK", blockchainNetwork.replace(/ /g, "_"));
291
+ writeEnv("IPFS_ENDPOINT", customUrl);
292
+ writeEnv("IPFS_TOKEN", ipfsToken || "");
293
+ writeEnv("VERSION", "v1");
294
+ console.log();
295
+ console.log(
296
+ "You can proceed to run ecld-build, once you set up the serverless functions or directly if you want to test with the provided template.",
297
+ );
298
+ rl.close();
299
+ };
300
+
301
+ main();
@@ -0,0 +1,5 @@
1
+ FROM registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/sconecuratedimages/services:las as initial
2
+
3
+ FROM scratch
4
+
5
+ COPY --from=initial / /
@@ -0,0 +1,65 @@
1
+ FROM registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/ethernity/node:16.13.1-alpine3.15-scone5.8-production as release
2
+
3
+ RUN apk update
4
+
5
+ RUN cd /
6
+
7
+ RUN apk add bash
8
+
9
+ ENV SCONE_MODE=SIM
10
+ ENV SCONE_HEAP=256M
11
+ ENV SCONE_LOG=DEBUG
12
+ ENV ENCLAVE_NAME_SECURELOCK=__ENCLAVE_NAME_SECURELOCK__
13
+ ENV BUCKET_NAME=__BUCKET_NAME__
14
+ ENV SMART_CONTRACT_ADDRESS=__SMART_CONTRACT_ADDRESS__
15
+ ENV IMAGE_REGISTRY_ADDRESS=__IMAGE_REGISTRY_ADDRESS__
16
+ ENV RPC_URL=__RPC_URL__
17
+ ENV CHAIN_ID=__CHAIN_ID__
18
+ ENV TRUSTED_ZONE_IMAGE=__TRUSTED_ZONE_IMAGE__
19
+
20
+ RUN mkdir binary-fs-dir
21
+
22
+ COPY ./src /etny-securelock/
23
+ COPY scripts/* /etny-securelock/
24
+
25
+ WORKDIR /etny-securelock
26
+ RUN pwd
27
+ RUN npm install
28
+ RUN ls
29
+
30
+ WORKDIR /
31
+
32
+ RUN ["chmod", "+x", "etny-securelock/binary-fs-build.sh"]
33
+ RUN etny-securelock/binary-fs-build.sh
34
+
35
+ FROM registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/sconecuratedimages/crosscompilers as build
36
+
37
+ COPY --from=release /binary-fs-dir /.
38
+
39
+ RUN scone gcc ./binary_fs_blob.s ./libbinary_fs_template.a -shared -o /libbinary-fs.so
40
+
41
+ #
42
+ FROM registry.ethernity.cloud:443/debuggingdelight/ethernity-cloud-sdk-registry/ethernity/node:16.13.1-alpine3.15-scone5.8-production
43
+
44
+ COPY --from=build /libbinary-fs.so /lib/libbinary-fs.so
45
+ #
46
+
47
+ RUN apk update
48
+
49
+ RUN apk add openssl
50
+
51
+ RUN openssl genrsa -3 -out /enclave-key.pem 3072
52
+
53
+
54
+ ENV SCONE_LOG=info
55
+ ENV SCONE_HEAP=1024M
56
+ ENV SCONE_ALLOW_DLOPEN=1
57
+ ENV SCONE_EXTENSIONS_PATH=/lib/libbinary-fs.so
58
+
59
+ # Enable production mode for mainnet
60
+ # RUN scone-signer sign --key=/enclave-key.pem --env --production /usr/bin/node
61
+ RUN rm -rf /enclave-key.pem
62
+
63
+ #RUN scone cas attest scone-cas.cf 3061b9feb7fa67f3815336a085f629a13f04b0a1667c93b14ff35581dc8271e4 -GCS --only_for_testing-debug --only_for_testing-ignore-signer
64
+ RUN ls /usr/local/bin
65
+ ENTRYPOINT ["/usr/local/bin/node", "/etny-securelock/securelock.js"]
@@ -0,0 +1,28 @@
1
+ #!/bin/bash -v
2
+
3
+ cd /etny-securelock
4
+ ls
5
+ echo "####################"
6
+ cat .env
7
+ echo "####################"
8
+
9
+ cat securelock.js.tmpl | sed s/"__ENCLAVE_NAME_SECURELOCK__"/"${ENCLAVE_NAME_SECURELOCK}"/g > securelock.js.tmp
10
+ sed -i "s/__BUCKET_NAME__/${BUCKET_NAME}/g" securelock.js.tmp
11
+ sed -i "s/__SMART_CONTRACT_ADDRESS__/${SMART_CONTRACT_ADDRESS}/g" securelock.js.tmp
12
+ sed -i "s/__IMAGE_REGISTRY_ADDRESS__/${IMAGE_REGISTRY_ADDRESS}/g" securelock.js.tmp
13
+ sed -i "s/__RPC_URL__/${RPC_URL}/g" securelock.js.tmp
14
+ sed -i "s/__CHAIN_ID__/${CHAIN_ID}/g" securelock.js.tmp
15
+ sed -i "s/__TRUSTED_ZONE_IMAGE__/${TRUSTED_ZONE_IMAGE}/g" securelock.js.tmp
16
+ mv securelock.js.tmp securelock.js
17
+
18
+ echo "starting building binary-fs..."
19
+ EXEC=(scone binaryfs / /binary-fs-dir -v \
20
+ --include '/usr/local/bin/node' \
21
+ --include '/etny-securelock/*' \
22
+ --host-path=/etc/resolv.conf \
23
+ --host-path=/etc/hosts)
24
+ echo "finished building binary-fs..."
25
+
26
+ exec "${EXEC[@]}"
27
+
28
+ exit
@@ -0,0 +1,3 @@
1
+ VERSION="v3"
2
+ ETNY_MODE="PUBLIC_KEY"
3
+ ETNY_ORDER_ID=10500