@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,71 @@
1
+ #!/usr/local/bin/python
2
+
3
+ import os
4
+
5
+ from dotenv import load_dotenv
6
+
7
+ from image_registry import ImageRegistry
8
+ import re
9
+
10
+ load_dotenv()
11
+
12
+ try:
13
+ print("*********************")
14
+
15
+ def extract_certificate(certificate_string: str) -> str:
16
+ pattern = (
17
+ r"(?<=-----BEGIN CERTIFICATE-----\n)(.*?)(?=\n-----END CERTIFICATE-----)"
18
+ )
19
+ matches = re.findall(pattern, certificate_string, re.DOTALL)
20
+ if matches:
21
+ return matches[0].strip()
22
+ else:
23
+ return None # type: ignore
24
+
25
+ def read_file_content(file_path: str) -> str:
26
+ with open(file_path, "r") as file:
27
+ content = file.read()
28
+ return content
29
+
30
+ secure_lock = read_file_content("certificate.securelock.crt")
31
+ # secure_lock = extract_certificate(secure_lock)
32
+ print("SECURELOCK:")
33
+ print(secure_lock)
34
+
35
+ trusted_zone = read_file_content("certificate.trustedzone.crt")
36
+ # trusted_zone = extract_certificate(trusted_zone)
37
+ print("TRUSTEDZONE:")
38
+ print(trusted_zone)
39
+ ipfs_hash = read_file_content("IPFS_HASH.ipfs")
40
+ ipfs_hash = ipfs_hash.strip()
41
+ ipfs_docker_compose_hash = read_file_content("IPFS_DOCKER_COMPOSE_HASH.ipfs")
42
+ ipfs_docker_compose_hash = ipfs_docker_compose_hash.strip()
43
+ print("IPFS_HASH: " + ipfs_hash)
44
+ imageRegistry = ImageRegistry()
45
+ print("PROJECT_NAME: " + os.getenv("PROJECT_NAME", ""))
46
+ # print("ENCLAVE_NAME_TRUSTEDZONE: " + os.getenv("ENCLAVE_NAME_TRUSTEDZONE", ""))
47
+ print("ENCLAVE_NAME_SECURELOCK: " + os.getenv("ENCLAVE_NAME_SECURELOCK", ""))
48
+ print("DEVELOPER_FEE: " + os.getenv("DEVELOPER_FEE", "10"))
49
+ # imageRegistry.add_trusted_zone_cert(
50
+ # trusted_zone,
51
+ # ipfs_hash,
52
+ # os.getenv("PROJECT_NAME", ""),
53
+ # ipfs_docker_compose_hash,
54
+ # os.getenv("ENCLAVE_NAME_TRUSTEDZONE", ""),
55
+ # os.getenv(key="DEVELOPER_FEE", default="10"),
56
+ # )
57
+ imageRegistry.add_secure_lock_and_validate_image_cert(
58
+ secure_lock,
59
+ ipfs_hash,
60
+ os.getenv("PROJECT_NAME", ""),
61
+ ipfs_docker_compose_hash,
62
+ os.getenv("ENCLAVE_NAME_SECURELOCK", ""),
63
+ os.getenv(key="DEVELOPER_FEE", default="0"),
64
+ )
65
+
66
+ # secure lock - addImage
67
+ # publishImage(hash)
68
+
69
+ print("************************")
70
+ except Exception as e:
71
+ print("An exception occurred: " + str(e))
@@ -0,0 +1,58 @@
1
+ #!/bin/bash
2
+
3
+ export IPFS_HOME=${PWD}/ipfs
4
+ export IPFS_PATH=${IPFS_HOME}/.ipfs
5
+
6
+ export KUBO_URL="https://github.com/ipfs/kubo/releases/download/v0.17.0/kubo_v0.17.0_darwin-amd64.tar.gz"
7
+ echo KUBO_URL=${KUBO_URL}
8
+
9
+ mkdir -p ${IPFS_HOME}
10
+
11
+ curl -L ${KUBO_URL} | tar xvz
12
+
13
+ echo "*** KUBO Downloaded ***"
14
+
15
+ if [ -d "${IPFS_PATH}" ]; then
16
+ killall ipfs
17
+ rm -fr ${IPFS_PATH}
18
+ fi
19
+
20
+ export IPFS_CMD=${PWD}/kubo/ipfs
21
+ export REGISTRY_PATH=../../../../registry
22
+
23
+ ${IPFS_CMD} init
24
+
25
+ sleep 20
26
+
27
+ ${IPFS_CMD} daemon &
28
+
29
+ sleep 20
30
+
31
+ ${IPFS_CMD} swarm connect /ip4/31.7.188.59/tcp/4001/ipfs/QmRBc1eBt4hpJQUqHqn6eA8ixQPD3LFcUDsn6coKBQtia5
32
+ ${IPFS_CMD} bootstrap add /ip4/31.7.188.59/tcp/4001/ipfs/QmRBc1eBt4hpJQUqHqn6eA8ixQPD3LFcUDsn6coKBQtia5
33
+
34
+
35
+ cp certificate.securelock.crt "${REGISTRY_PATH}/certificate.securelock.crt"
36
+ cp certificate.trustedzone.crt "${REGISTRY_PATH}/certificate.trustedzone.crt"
37
+ echo "${REGISTRY_PATH}"
38
+ cd ${REGISTRY_PATH}
39
+
40
+ #ADDING DOCKER IMAGE hash
41
+ export IPFS_HASH=$(${IPFS_CMD} add . -r | grep added | tail -1 | awk '{print $2}')
42
+ echo "IPFS_HASH=${IPFS_HASH}"
43
+
44
+ echo ipfs pin add --progress ${IPFS_HASH}
45
+ ${IPFS_CMD} pin add --progress ${IPFS_HASH}
46
+
47
+ #DOWNLOADING DOCKER IMAGE FROM IFPS HASH
48
+ echo ipfs get ${IPFS_HASH}
49
+ ${IPFS_CMD} get ${IPFS_HASH}
50
+
51
+ if [ -d "${IPFS_PATH}" ]; then
52
+ killall ipfs
53
+ rm -fr ${IPFS_PATH}
54
+ fi
55
+
56
+ cd -
57
+
58
+ echo "${IPFS_HASH}" > "IPFS_HASH.ipfs"
@@ -0,0 +1,75 @@
1
+ #!/bin/bash
2
+
3
+ export IPFS_HOME=${PWD}/ipfs
4
+ export IPFS_PATH=${IPFS_HOME}/.ipfs
5
+
6
+ export KUBO_URL="https://github.com/ipfs/kubo/releases/download/v0.17.0/kubo_v0.17.0_darwin-amd64.tar.gz"
7
+ echo KUBO_URL=${KUBO_URL}
8
+
9
+ mkdir -p ${IPFS_HOME}
10
+
11
+ curl -L ${KUBO_URL} | tar xvz
12
+
13
+ echo "*** KUBO Downloaded ***"
14
+
15
+ if [ -d "${IPFS_PATH}" ]; then
16
+ killall ipfs
17
+ rm -fr ${IPFS_PATH}
18
+ fi
19
+
20
+ export IPFS_CMD=${PWD}/kubo/ipfs
21
+ export REGISTRY_PATH=../../../../registry
22
+
23
+ ${IPFS_CMD} init
24
+
25
+ sleep 20
26
+
27
+ # Configure Kubo to use the custom IPFS API endpoint
28
+ ${IPFS_CMD} config Addresses.API /ip4/127.0.0.1/tcp/5001
29
+ ${IPFS_CMD} config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
30
+ ${IPFS_CMD} config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST", "GET"]'
31
+
32
+ ${IPFS_CMD} daemon &
33
+
34
+ sleep 20
35
+
36
+ # Connect to the custom IPFS node
37
+ ${IPFS_CMD} swarm connect /dns4/ipfs.ethernity.cloud/tcp/5001
38
+
39
+ # Adding Docker Compose hash
40
+ export IPFS_DOCKER_COMPOSE_HASH=$(${IPFS_CMD} add docker-compose-final.yml | grep added | tail -1 | awk '{print $2}')
41
+ echo "IPFS_DOCKER_COMPOSE_HASH=${IPFS_DOCKER_COMPOSE_HASH}"
42
+
43
+ echo ipfs pin add --progress ${IPFS_DOCKER_COMPOSE_HASH}
44
+ ${IPFS_CMD} pin add --progress ${IPFS_DOCKER_COMPOSE_HASH}
45
+
46
+ # Downloading Docker Compose from IPFS hash
47
+ echo ipfs get ${IPFS_DOCKER_COMPOSE_HASH}
48
+ ${IPFS_CMD} get ${IPFS_DOCKER_COMPOSE_HASH}
49
+
50
+ # Remove downloaded
51
+ rm -fr ${IPFS_DOCKER_COMPOSE_HASH}
52
+
53
+ echo "${REGISTRY_PATH}"
54
+ cd ${REGISTRY_PATH}
55
+
56
+ # Adding Docker image hash
57
+ export IPFS_HASH=$(${IPFS_CMD} add . -r | grep added | tail -1 | awk '{print $2}')
58
+ echo "IPFS_HASH=${IPFS_HASH}"
59
+
60
+ echo ipfs pin add --progress ${IPFS_HASH}
61
+ ${IPFS_CMD} pin add --progress ${IPFS_HASH}
62
+
63
+ # Downloading Docker image from IPFS hash
64
+ echo ipfs get ${IPFS_HASH}
65
+ ${IPFS_CMD} get ${IPFS_HASH}
66
+
67
+ if [ -d "${IPFS_PATH}" ]; then
68
+ killall ipfs
69
+ rm -fr ${IPFS_PATH}
70
+ fi
71
+
72
+ cd -
73
+
74
+ echo "${IPFS_DOCKER_COMPOSE_HASH}" > "IPFS_DOCKER_COMPOSE_HASH.ipfs"
75
+ echo "${IPFS_HASH}" > "IPFS_HASH.ipfs"
@@ -0,0 +1,90 @@
1
+ const axios = require('axios');
2
+ const fs = require('fs');
3
+ const { Command } = require('commander');
4
+ const program = new Command();
5
+
6
+ const BASE_URL = "https://publickey.ethernity.cloud";
7
+
8
+ async function submitIpfsHash(hash, enclaveName, protocolVersion, network, templateVersion, dockerComposerHash) {
9
+ const url = `${BASE_URL}/api/addHash`;
10
+ const payload = {
11
+ hash: hash,
12
+ enclave_name: enclaveName,
13
+ protocol_version: protocolVersion,
14
+ network: network,
15
+ template_version: templateVersion,
16
+ docker_composer_hash: dockerComposerHash,
17
+ };
18
+ try {
19
+ const response = await axios.post(url, payload);
20
+ // console.log(`response: ${response}`);
21
+ return response.data;
22
+ } catch (error) {
23
+ console.error("Error:", error.response ? error.response.data : error.message);
24
+ process.exit(1);
25
+ }
26
+ }
27
+
28
+ async function checkIpfsHashStatus(hash) {
29
+ const url = `${BASE_URL}/api/checkHash/${hash}`;
30
+ try {
31
+ const response = await axios.get(url);
32
+ return response.data;
33
+ } catch (error) {
34
+ console.error("Error:", error.response ? error.response.data : error.message);
35
+ process.exit(1);
36
+ }
37
+ }
38
+
39
+ program
40
+ .requiredOption('--enclave_name <enclaveName>', 'Enclave name')
41
+ .requiredOption('--protocol_version <protocolVersion>', 'Protocol version')
42
+ .requiredOption('--network <network>', 'Network')
43
+ .requiredOption('--template_version <templateVersion>', 'Template version');
44
+
45
+ program.parse(process.argv);
46
+
47
+ const options = program.opts();
48
+ const enclaveName = options.enclave_name;
49
+ const protocolVersion = options.protocol_version;
50
+ const network = options.network.toLowerCase().split("_")[1];
51
+ const templateVersion = options.template_version;
52
+
53
+ const hhash = fs.readFileSync('IPFS_HASH.ipfs', 'utf8').trim();
54
+ const dockerComposerHash = fs.readFileSync('IPFS_DOCKER_COMPOSE_HASH.ipfs', 'utf8').trim();
55
+
56
+ console.log("IPFS Hash:", hhash);
57
+ console.log("Enclave Name:", enclaveName);
58
+ console.log("Protocol Version:", protocolVersion);
59
+ console.log("Network:", network);
60
+ console.log("Template Version:", templateVersion);
61
+ console.log("Docker Composer Hash:", dockerComposerHash);
62
+
63
+ (async () => {
64
+ // Submit IPFS Hash
65
+ const submitResponse = await submitIpfsHash(hhash, enclaveName, protocolVersion, network, templateVersion, dockerComposerHash);
66
+ console.log("Submit IPFS Hash Response:", submitResponse);
67
+
68
+ // Check IPFS Hash Status
69
+ while (true) {
70
+ const checkResponse = await checkIpfsHashStatus(hhash);
71
+ if ("publicKey" in checkResponse) {
72
+ if (checkResponse.publicKey === 0) {
73
+ console.log(`Public key not available yet. Queue position: ${checkResponse.queuePosition || 'Unknown'}`);
74
+ } else if (checkResponse.publicKey === -1) {
75
+ console.log("Hash is not derived from Eternity Cloud SDK.");
76
+ process.exit(1);
77
+ } else {
78
+ console.log("Public Key:", checkResponse.publicKey);
79
+ // Save public key to file
80
+ fs.writeFileSync('PUBLIC_KEY.txt', checkResponse.publicKey);
81
+ break;
82
+ }
83
+ } else {
84
+ console.log("Unexpected response:", checkResponse);
85
+ process.exit(1);
86
+ }
87
+
88
+ await new Promise(resolve => setTimeout(resolve, 10000)); // Wait for 10 seconds before checking again
89
+ }
90
+ })();
@@ -0,0 +1,107 @@
1
+ import requests
2
+ import time
3
+ import argparse
4
+
5
+ BASE_URL = "https://publickey.ethernity.cloud"
6
+
7
+
8
+ def submit_ipfs_hash(
9
+ hhash,
10
+ enclave_name,
11
+ protocol_version,
12
+ network,
13
+ template_version,
14
+ docker_composer_hash,
15
+ ):
16
+ url = f"{BASE_URL}/api/addHash"
17
+ payload = {
18
+ "hash": hhash,
19
+ "enclave_name": enclave_name,
20
+ "protocol_version": protocol_version,
21
+ "network": network,
22
+ "template_version": template_version,
23
+ "docker_composer_hash": docker_composer_hash,
24
+ }
25
+ response = requests.post(url, json=payload)
26
+ print(f"response:{response}")
27
+ if response.status_code == 200:
28
+ return response.json()
29
+ else:
30
+ print("Error:", response.con)
31
+ exit(1)
32
+
33
+
34
+ def check_ipfs_hash_status(hash):
35
+ url = f"{BASE_URL}/api/checkHash/{hash}"
36
+ response = requests.get(url)
37
+ if response.status_code == 200:
38
+ return response.json()
39
+ else:
40
+ print("Error:", response.json())
41
+ exit(1)
42
+
43
+
44
+ if __name__ == "__main__":
45
+ # Example usage
46
+ # python3 ./public_key_service.py --enclave_name ${ENCLAVE_NAME_SECURELOCK} --protocol_version ${VERSION} --network ${BLOCKCHAIN_NETWORK} --template_version ${VERSION}
47
+
48
+ # read enclave_name, protocol_version, network, template_version from command line arguments
49
+ parser = argparse.ArgumentParser()
50
+ parser.add_argument("--enclave_name", help="Enclave name", required=True)
51
+ parser.add_argument("--protocol_version", help="Protocol version", required=True)
52
+ parser.add_argument("--network", help="Network", required=True)
53
+ parser.add_argument("--template_version", help="Template version", required=True)
54
+
55
+ args = parser.parse_args()
56
+ enclave_name = args.enclave_name
57
+ protocol_version = args.protocol_version
58
+ network = args.network.lower().split("_")[1]
59
+ template_version = args.template_version
60
+
61
+ hhash = ""
62
+ with open("IPFS_HASH.ipfs", "r") as f:
63
+ hhash = f.read().strip()
64
+ docker_composer_hash = ""
65
+ with open("IPFS_DOCKER_COMPOSE_HASH.ipfs", "r") as f:
66
+ docker_composer_hash = f.read().strip()
67
+
68
+ print("IPFS Hash:", hhash)
69
+ print("Enclave Name:", enclave_name)
70
+ print("Protocol Version:", protocol_version)
71
+ print("Network:", network)
72
+ print("Template Version:", template_version)
73
+ print("Docker Composer Hash:", docker_composer_hash)
74
+
75
+ # Submit IPFS Hash
76
+ submit_response = submit_ipfs_hash(
77
+ hhash,
78
+ enclave_name,
79
+ protocol_version,
80
+ network,
81
+ template_version,
82
+ docker_composer_hash,
83
+ )
84
+ print("Submit IPFS Hash Response:", submit_response)
85
+
86
+ # Check IPFS Hash Status
87
+ while True:
88
+ check_response = check_ipfs_hash_status(hhash)
89
+ if "publicKey" in check_response:
90
+ if check_response["publicKey"] == 0:
91
+ print(
92
+ f"Public key not available yet. Queue position: {check_response.get('queuePosition', 'Unknown')}"
93
+ )
94
+ elif check_response["publicKey"] == -1:
95
+ print("Hash is not derived from Eternity Cloud SDK.")
96
+ exit(1)
97
+ else:
98
+ print("Public Key:", check_response["publicKey"])
99
+ # save public key to file
100
+ with open("PUBLIC_KEY.txt", "w") as f:
101
+ f.write(check_response["publicKey"])
102
+ break
103
+ else:
104
+ print("Unexpected response:", check_response)
105
+ exit(1)
106
+
107
+ time.sleep(10) # Wait for 10 seconds before checking again
@@ -0,0 +1,212 @@
1
+ import os
2
+
3
+ from minio import Minio
4
+ from minio.error import S3Error
5
+
6
+
7
+ class SwiftStreamService:
8
+
9
+ def __init__(self, endpoint: str, access_key: str, secret_key: str):
10
+ self.client = Minio(
11
+ endpoint=endpoint,
12
+ access_key=access_key,
13
+ secret_key=secret_key,
14
+ secure=False,
15
+ )
16
+
17
+ def create_bucket(self, bucket_name: str) -> (bool, str):
18
+ try:
19
+ if not self.client.bucket_exists(bucket_name):
20
+ self.client.make_bucket(bucket_name)
21
+ else:
22
+ return False, f"Bucket, {bucket_name} already exists!"
23
+ except S3Error as err:
24
+ return False, err
25
+
26
+ return True, f"Bucket, {bucket_name} successfully created!"
27
+
28
+ def delete_bucket(self, bucket_name: str) -> (bool, str):
29
+ try:
30
+ if self.client.bucket_exists(bucket_name):
31
+ file_objects = self.client.list_objects(bucket_name)
32
+ if file_objects.size() == 0:
33
+ self.client.remove_bucket(bucket_name)
34
+ else:
35
+ for file_object in file_objects:
36
+ self.delete_file(bucket_name, file_object)
37
+ self.client.remove_bucket(bucket_name)
38
+ else:
39
+ return False, f"Bucket, {bucket_name} does not exists!"
40
+ except S3Error as err:
41
+ return False, err
42
+
43
+ return True, f"Bucket, {bucket_name} successfully deleted!"
44
+
45
+ def delete_file(self, bucket_name: str, file_name: str) -> (bool, str):
46
+ try:
47
+ self.client.remove_object(bucket_name, file_name)
48
+ except S3Error as err:
49
+ return False, err
50
+
51
+ return True, f"File, {file_name} successfully deleted!"
52
+
53
+ def delete_files(self, bucket_name: str, list_of_files: list[str]) -> (bool, str):
54
+ try:
55
+ errors = self.client.remove_objects(bucket_name, list_of_files)
56
+ for error in errors:
57
+ print(f"[Error] Error occurred when deleting file: {error}!")
58
+ except S3Error as err:
59
+ return False, err
60
+
61
+ return True, f"Files, {list_of_files} successfully deleted!"
62
+
63
+ def upload_file(
64
+ self, bucket_name: str, file_name: str, file_path: str
65
+ ) -> (bool, str):
66
+ try:
67
+ if self.client.bucket_exists(bucket_name):
68
+ self.client.fput_object(bucket_name, file_name, file_path)
69
+ else:
70
+ self.create_bucket(bucket_name)
71
+ self.client.fput_object(bucket_name, file_name, file_path)
72
+ except S3Error as err:
73
+ return False, err
74
+
75
+ return True, f"{file_path} is successfully uploaded to bucket {bucket_name}."
76
+
77
+ def upload_files(
78
+ self, bucket_name: str, list_of_files: list[str], upload_file_paths: list[str]
79
+ ) -> (bool, str):
80
+ try:
81
+ if self.client.bucket_exists(bucket_name):
82
+ for file_idx in range(len(upload_file_paths)):
83
+ self.client.fput_object(
84
+ bucket_name,
85
+ list_of_files[file_idx],
86
+ upload_file_paths[file_idx],
87
+ )
88
+ else:
89
+ self.create_bucket(bucket_name)
90
+ for file_idx in range(len(upload_file_paths)):
91
+ self.client.fput_object(
92
+ bucket_name,
93
+ list_of_files[file_idx],
94
+ upload_file_paths[file_idx],
95
+ )
96
+ except S3Error as err:
97
+ return False, err
98
+
99
+ return (
100
+ True,
101
+ f"{upload_file_paths} are successfully uploaded to bucket {bucket_name}.",
102
+ )
103
+
104
+ def download_file(
105
+ self, bucket_name: str, file_name: str, file_path: str
106
+ ) -> (bool, str):
107
+ try:
108
+ if self.client.bucket_exists(bucket_name):
109
+ self.client.fget_object(bucket_name, file_name, file_path)
110
+ else:
111
+ return False, f"Bucket, {bucket_name} does not exists!"
112
+ except S3Error as err:
113
+ return False, err
114
+
115
+ return (
116
+ True,
117
+ f"File, {file_name} from bucket {bucket_name} was downloaded in {file_path}.",
118
+ )
119
+
120
+ def download_files(
121
+ self, bucket_name: str, list_of_files: list[str], download_file_paths: list[str]
122
+ ) -> (bool, str):
123
+ try:
124
+ if self.client.bucket_exists(bucket_name):
125
+ for file_idx in range(len(list_of_files)):
126
+ self.client.fget_object(
127
+ bucket_name,
128
+ list_of_files[file_idx],
129
+ download_file_paths[file_idx],
130
+ )
131
+ else:
132
+ return False, f"Bucket, {bucket_name} does not exists!"
133
+ except S3Error as err:
134
+ return False, err
135
+
136
+ return (
137
+ True,
138
+ f"{download_file_paths} are successfully uploaded to bucket {bucket_name}.",
139
+ )
140
+
141
+ def get_file_content_bytes(self, bucket_name: str, file_name: str) -> (bool, bytes):
142
+ response = None
143
+ try:
144
+ response = self.client.get_object(bucket_name, file_name)
145
+ _d = b""
146
+ for data in response.stream(amt=1024 * 1024):
147
+ _d = _d + data
148
+
149
+ except S3Error as err:
150
+ return False, err
151
+ finally:
152
+ if not response:
153
+ response.close()
154
+ response.release_conn()
155
+ return True, _d
156
+
157
+ def get_file_content(self, bucket_name: str, file_name: str) -> (bool, str):
158
+ status, content = self.get_file_content_bytes(bucket_name, file_name)
159
+ if status:
160
+ return True, content.decode("utf-8")
161
+ return status, content
162
+
163
+ def put_file_content(
164
+ self,
165
+ bucket_name: str,
166
+ object_name: str,
167
+ object_path: str,
168
+ object_data: object = None,
169
+ ) -> (bool, str):
170
+ try:
171
+ if object_data is not None:
172
+ self.client.put_object(
173
+ bucket_name, object_name, object_data, len(object_data.getbuffer())
174
+ )
175
+ else:
176
+ object_stat = os.stat(object_path)
177
+ with open(object_path, "rb") as file_data:
178
+ self.client.put_object(
179
+ bucket_name, object_name, file_data, object_stat.st_size
180
+ )
181
+ file_data.close()
182
+ except S3Error as err:
183
+ return False, err
184
+
185
+ return True, f"{object_name} is successfully uploaded to bucket {bucket_name}."
186
+
187
+ def is_object_in_bucket(self, bucket_name: str, object_name: str) -> (bool, str):
188
+ found = False
189
+ try:
190
+ result = self.client.stat_object(bucket_name, object_name)
191
+ if result:
192
+ found = True
193
+ except S3Error as err:
194
+ return False, err
195
+
196
+ if found:
197
+ return found, f"{object_name} exists inside {bucket_name}."
198
+ else:
199
+ return found, f"{object_name} doesn't exists inside {bucket_name}."
200
+
201
+ def _list_buckets(self) -> None:
202
+ buckets = self.client.list_buckets()
203
+ for bucket in buckets:
204
+ print(bucket.name, bucket.creation_date)
205
+
206
+ def _list_objects(self, bucket_name: str) -> None:
207
+ objects = self.client.list_objects(bucket_name)
208
+ for obj in objects:
209
+ print("-> ", obj.object_name, obj.owner_name)
210
+
211
+ def _is_bucket(self, bucket_name: str) -> bool:
212
+ return self.client.bucket_exists(bucket_name)
@@ -0,0 +1,37 @@
1
+ #!/usr/local/bin/python
2
+
3
+ from minio import Minio
4
+ from minio.error import S3Error
5
+ from swift_stream_service import SwiftStreamService
6
+
7
+ try:
8
+ print("*********************")
9
+ print("Initializing SwiftStream Service from python...")
10
+ swiftStreamClient = SwiftStreamService(
11
+ "docker:9000", "swiftstreamadmin", "swiftstreamadmin"
12
+ )
13
+ print("Initialized SwiftStream Service successfully")
14
+ print("*********************")
15
+ swiftStreamClient.create_bucket("etny-nodenithy-v3")
16
+
17
+ swiftStreamClient.upload_file("etny-nodenithy-v3", ".env", "./.env")
18
+
19
+ print(swiftStreamClient.is_object_in_bucket("etny-nodenithy-v3", ".env"))
20
+
21
+ status, content = swiftStreamClient.get_file_content("etny-nodenithy-v3", ".env")
22
+
23
+ print("************************")
24
+ print("Status %s" % status)
25
+ print("Content %s" % content)
26
+ print("************************")
27
+
28
+ status, content = swiftStreamClient.get_file_content_bytes(
29
+ "etny-nodenithy-v3", ".env"
30
+ )
31
+
32
+ print("************************")
33
+ print("Status %s" % status)
34
+ print("Content %s" % content)
35
+ print("************************")
36
+ except:
37
+ print("An exception occurred")
@@ -0,0 +1,27 @@
1
+ #!/usr/local/bin/python
2
+
3
+ from minio import Minio
4
+ from minio.error import S3Error
5
+ from swift_stream_service import SwiftStreamService
6
+
7
+ try:
8
+ print("*********************")
9
+ print("Initializing SwiftStream Service from python...")
10
+ swiftStreamClient = SwiftStreamService(
11
+ "localhost:9000", "swiftstreamadmin", "swiftstreamadmin"
12
+ )
13
+ print("Initialized SwiftStream Service successfully")
14
+ print("*********************")
15
+
16
+ status, content = swiftStreamClient.get_file_content(
17
+ "etny-nodenithy-v2", "result11.txt"
18
+ )
19
+
20
+ # status, content = swiftStreamClient.get_file_content_bytes("etny-nodenithy-v2", "result11.txt")
21
+
22
+ print("************************")
23
+ print("Status %s" % status)
24
+ print("Content %s" % content)
25
+ print("************************")
26
+ except Exception as e:
27
+ print("An exception occurred" + str(e))