@ethernity-cloud/sdk-js 1.7.9 → 1.7.11

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.
@@ -3,7 +3,10 @@
3
3
  // .env, the way ecld-run reads the same values. PROJECT_NAME and
4
4
  // TRUSTED_ZONE_IMAGE take their -unsafe form on an -unsafe network; the
5
5
  // network's token address, chain id and -unsafe (network, type) come from the
6
- // runner's own enums through the SDK's network table.
6
+ // runner's own enums through the SDK's network table; IPFS_ENDPOINT is the
7
+ // IPFS API of the dApp's own, or '' (no setting, or the public API, which
8
+ // takes no writes without a token), on which the dApp delivers its task
9
+ // artefacts through the bootnode's payload intake.
7
10
  import fs from 'fs';
8
11
  import { createRequire } from 'module';
9
12
  import dotenv from 'dotenv';
@@ -13,6 +16,7 @@ dotenv.config();
13
16
  const require = createRequire(import.meta.url);
14
17
  const casConfig = require('@ethernity-cloud/sdk-js/cas/config.js');
15
18
  const { networkFor } = require('@ethernity-cloud/sdk-js/network.js');
19
+ const { dappEndpoint } = require('@ethernity-cloud/sdk-js/localKubo.js');
16
20
 
17
21
  const { PROJECT_NAME, TRUSTED_ZONE_IMAGE, BLOCKCHAIN_NETWORK, IPFS_ENDPOINT } = process.env;
18
22
  if (!PROJECT_NAME || !BLOCKCHAIN_NETWORK) {
@@ -31,7 +35,7 @@ const constants = {
31
35
  NETWORK_ADDRESS: network.address,
32
36
  CHAIN_ID: network.chainId || null,
33
37
  UNSAFE_NETWORK: network.unsafe || null,
34
- IPFS_ENDPOINT: IPFS_ENDPOINT || 'https://ipfs.ethernity.cloud',
38
+ IPFS_ENDPOINT: dappEndpoint(IPFS_ENDPOINT),
35
39
  };
36
40
 
37
41
  const filePath = 'src/ec_helloworld_example.js';
package/run.js CHANGED
@@ -4,8 +4,10 @@
4
4
  * The network-side sibling of `ecld-test`: same payload flags (a code string,
5
5
  * --file, --input/--input-text), but instead of executing locally it drives the
6
6
  * real runner (@ethernity-cloud/runner's EthernityCloudRunner) end to end —
7
- * encrypt the payload, push to IPFS, place the on-chain DO request, wait for a
8
- * node to process it, download and decrypt the result.
7
+ * encrypt the payload, place the on-chain DO request, deliver the payload to
8
+ * the bootnode's payload intake once the request is on chain (or to the IPFS
9
+ * API named with --ipfs <url>), wait for a node to process it, download and
10
+ * decrypt the result.
9
11
  *
10
12
  * Where ecld-test answers "does my CALL work?", ecld-run answers "does it work
11
13
  * on the network, on the enclave I published?" — it costs gas and needs a
@@ -41,12 +43,14 @@ const fs = require('fs');
41
43
  try { require('dotenv').config(); } catch (e) { /* dotenv optional */ }
42
44
  const casConfig = require('./cas/config.js');
43
45
  const { networkFor, unsafeVariant } = require('./network.js');
46
+ const { PUBLIC_IPFS_HOST } = require('./localKubo.js');
44
47
 
45
48
  // `--ipfs intake` (the default): the artefacts' CIDs are computed locally and
46
49
  // the bytes delivered to the bootnode's payload intake once the DO request is
47
50
  // on chain (runner initializePublicIntake); `--ipfs <url>` uploads and reads
48
- // through that Kubo RPC API instead. The public API's add is closed to callers
49
- // without a token.
51
+ // through that IPFS RPC API instead, with ECLD_IPFS_TOKEN or IPFS_TOKEN as its
52
+ // Authorization header. The public API takes writes only with a writer token,
53
+ // so a URL naming it is refused without one.
50
54
  const DEFAULT_IPFS = 'intake';
51
55
 
52
56
  function parseArgs(argv) {
@@ -86,12 +90,13 @@ usage: ecld-run 'hello("World")' | ecld-run --file payload.js | ecld-run --input
86
90
  payload: a code string, or --file <path>; input via --input <file> / --input-text <str>
87
91
  network: --network BLOXBERG_TESTNET (default: BLOCKCHAIN_NETWORK from .env)
88
92
  --unsafe: the network's -unsafe variant, which runs without a CAS
89
- (BLOXBERG_TESTNET_UNSAFE, LITVM_LITEFORGE_UNSAFE)
93
+ (BLOXBERG_TESTNET_UNSAFE, LITVM_LITEFORGE_UNSAFE, ETHEREUM_SEPOLIA_UNSAFE)
90
94
  enclaves: --securelock <name> (default PROJECT_NAME), --trustedzone <name> (default TRUSTED_ZONE_IMAGE);
91
95
  on an -unsafe network the default is each one's -unsafe variant
92
96
  key: PRIVATE_KEY (a funded 0x key) from .env / env, or ECLD_PRIVATE_KEY
93
97
  resources: --task-price 3 --cpu 1 --memory 1 --storage 10 --bandwidth 1 --duration 1 --validators 1
94
- other: --node <addr> --ipfs intake|<kubo api url> (default intake: the bootnode's payload intake)
98
+ other: --node <addr> --ipfs intake|<ipfs api url> (default intake: the bootnode's payload intake;
99
+ a URL takes ECLD_IPFS_TOKEN or IPFS_TOKEN as its Authorization header)
95
100
  --timeout <sec> --json`;
96
101
 
97
102
  async function main() {
@@ -179,8 +184,19 @@ async function main() {
179
184
  console.error('ecld-run: could not initialise the runner: ' + e.message);
180
185
  process.exit(1);
181
186
  }
182
- if (opts.ipfs === 'intake') runner.initializePublicIntake();
183
- else runner.initializeStorage(opts.ipfs);
187
+ if (opts.ipfs === 'intake') {
188
+ runner.initializePublicIntake();
189
+ } else {
190
+ const token = (process.env.ECLD_IPFS_TOKEN || process.env.IPFS_TOKEN || '').trim();
191
+ let host = '';
192
+ try { host = new URL(opts.ipfs).hostname; } catch (e) { /* not a URL: the runner reports it */ }
193
+ if (host === PUBLIC_IPFS_HOST && !token) {
194
+ console.error(`ecld-run: the public API ${PUBLIC_IPFS_HOST} takes writes only with a writer token `
195
+ + '(ECLD_IPFS_TOKEN or IPFS_TOKEN); use the intake (--ipfs intake) or your own Kubo.');
196
+ process.exit(2);
197
+ }
198
+ runner.initializeStorage(opts.ipfs, undefined, undefined, token || undefined);
199
+ }
184
200
 
185
201
  let lastPhase = null;
186
202
  const onProgress = (e) => {
package/nodenithy/ipfs.js DELETED
@@ -1,135 +0,0 @@
1
- import { create } from 'ipfs-http-client';
2
- import { delay, getRetryDelay } from './utils';
3
- import { ECError } from './enums';
4
-
5
- let ipfs = null;
6
- const writeFile = promisify(fs.writeFile);
7
-
8
- export const initialize = (host, protocol, port, token) => {
9
- if (host.search('http') !== -1) {
10
- ipfs = create(host);
11
- } else if (token === '') {
12
- ipfs = create({
13
- host,
14
- protocol,
15
- port
16
- });
17
- } else {
18
- // example of authorization headers
19
- // headers: {
20
- // authorization: 'Bearer ' + TOKEN
21
- // }
22
- // const auth =
23
- // 'Basic ' + Buffer.from(INFURA_ID + ':' + INFURA_SECRET_KEY).toString('base64');
24
- ipfs = create({
25
- host,
26
- protocol,
27
- port,
28
- headers: { authorization: token }
29
- });
30
- }
31
- };
32
-
33
- export const uploadToIPFS = async (code) => {
34
- try {
35
- const response = await ipfs.add(code);
36
- return response.path;
37
- } catch (e) {
38
- console.log(e);
39
- return null;
40
- }
41
- };
42
-
43
- export const uploadFileToIPFS = async (path) => {
44
- try {
45
- const response = await ipfs.add(path);
46
- return response.path;
47
- } catch (e) {
48
- console.log(e);
49
- return null;
50
- }
51
- };
52
-
53
- export const uploadFolderToIPFS = async (path) => {
54
- try {
55
- const response = await ipfs.add(path, { recursive: true });
56
- return response.path;
57
- } catch (e) {
58
- console.log(e);
59
- return null;
60
- }
61
- };
62
-
63
- // export const getFromIPFS = async (hash) => {
64
- // let res = '';
65
- // try {
66
- // // eslint-disable-next-line no-restricted-syntax
67
- // for await (const file of ipfs.cat(hash)) {
68
- // res += new TextDecoder().decode(file.buffer);
69
- // }
70
- //
71
- // return res;
72
- // } catch (error) {
73
- // console.error(error.message);
74
- // await delay(2000);
75
- // return getFromIPFS(hash);
76
- // }
77
- // };
78
-
79
- export const getFromIPFS = async (hash, filePath, maxRetries = process.env.REACT_APP_IPFS_RETRIES || 5) => {
80
- let res = '';
81
- let retryCount = 0;
82
-
83
- while (retryCount < maxRetries) {
84
- try {
85
- // eslint-disable-next-line no-restricted-syntax,no-await-in-loop
86
- for await (const file of ipfs.cat(hash)) {
87
- res += new TextDecoder().decode(file.buffer);
88
- }
89
-
90
- // Save the content to a file
91
- await writeFile(filePath, res);
92
- return res;
93
- } catch (error) {
94
- console.error(error.message);
95
- retryCount += 1;
96
-
97
- if (retryCount < maxRetries) {
98
- // eslint-disable-next-line no-await-in-loop
99
- await delay(getRetryDelay(retryCount));
100
- // eslint-disable-next-line no-continue
101
- continue;
102
- } else {
103
- throw new Error(ECError.IPFS_DOWNLOAD_ERROR);
104
- }
105
- }
106
- }
107
- };
108
-
109
- export const getContentFromIPFS = async (hash, maxRetries = process.env.REACT_APP_IPFS_RETRIES || 5) => {
110
- let res = '';
111
- let retryCount = 0;
112
-
113
- while (retryCount < maxRetries) {
114
- try {
115
- // eslint-disable-next-line no-restricted-syntax,no-await-in-loop
116
- for await (const file of ipfs.cat(hash)) {
117
- res += new TextDecoder().decode(file.buffer);
118
- }
119
-
120
- return res;
121
- } catch (error) {
122
- console.error(error.message);
123
- retryCount += 1;
124
-
125
- if (retryCount < maxRetries) {
126
- // eslint-disable-next-line no-await-in-loop
127
- await delay(getRetryDelay(retryCount));
128
- // eslint-disable-next-line no-continue
129
- continue;
130
- } else {
131
- throw new Error(ECError.IPFS_DOWNLOAD_ERROR);
132
- }
133
- }
134
- }
135
- };
@@ -1,22 +0,0 @@
1
- #!/bin/sh
2
-
3
- # apk add git
4
-
5
- # ls -la
6
-
7
- # echo "${REGISTRY_PATH}"
8
- # cd ${REGISTRY_PATH}
9
-
10
- # ls -la
11
-
12
- # #commit add all to git
13
- # ls -la ${CI_PROJECT_DIR}/etny-hash-packages/etny-nodenithy/v3/
14
- # echo "Adding changed files to GIT: IPFS_HASH, IPFS_DOCKER_COMPOSE_HASH, CERTIFICATE..."
15
- # git -C ${CI_PROJECT_DIR}/etny-hash-packages add etny-nodenithy/v3/.
16
- # echo "Committed all files"
17
- # git -C ${CI_PROJECT_DIR}/etny-hash-packages commit -m 'Adding changed files to GIT: IPFS_HASH, IPFS_DOCKER_COMPOSE_HASH, CERTIFICATE'
18
- # echo "Pushed all files"
19
- # git -C ${CI_PROJECT_DIR}/etny-hash-packages push
20
- # echo "Added and committed all files"
21
- # cd -
22
-
@@ -1,58 +0,0 @@
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"
@@ -1,75 +0,0 @@
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"
package/nodenithy/run.sh DELETED
@@ -1,277 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
-
5
- # Source environment variables
6
- if [ -f .env ]; then
7
- source .env
8
- else
9
- echo "Error: .env file not found"
10
- exit 1
11
- fi
12
-
13
- write_env() {
14
- local key=$1
15
- local value=$2
16
- local env_file="$current_dir/.env"
17
-
18
- # Check if the .env file exists
19
- if [[ -f $env_file ]]; then
20
- # Check if the key exists in the .env file
21
- if grep -q "^${key}=" "$env_file"; then
22
- # Update the existing key with the new value
23
- sed -i '' "s/^${key}=.*/${key}=${value}/" "$env_file"
24
- else
25
- # Add the new key-value pair to the .env file
26
- echo "${key}=${value}" >> "$env_file"
27
- fi
28
- else
29
- # Create the .env file and add the key-value pair
30
- echo "${key}=${value}" > "$env_file"
31
- fi
32
- }
33
-
34
- current_dir=$(pwd)
35
- echo "current_dir: $current_dir"
36
-
37
- # Set up local registry path
38
- export REGISTRY_PATH=${PWD}/registry
39
-
40
-
41
- # check for sgx compatible machine
42
- # check if image name is available in smart contract
43
-
44
-
45
- RUNNER_TYPE="nodenithy"
46
- echo "VERSION = ${VERSION}"
47
-
48
- cd ${PWD}/node_modules/ethernity-cloud-sdk-js/nodenithy/run
49
-
50
- echo "ETNY MODE: ${ETNY_MODE}"
51
-
52
- # Determine MRENCLAVE values
53
- export MRENCLAVE_SECURELOCK=$(docker-compose run -e SCONE_LOG=INFO -e SCONE_HASH=1 etny-securelock | grep -v Creating | grep -v Pulling | grep -v latest | grep -v Digest | tr -d '\r')
54
- export MRENCLAVE_TRUSTEDZONE=$(docker-compose run -e SCONE_LOG=INFO -e SCONE_HASH=1 etny-trustedzone | grep -v Creating | grep -v Pulling | grep -v latest | grep -v Digest | tr -d '\r')
55
- export MRENCLAVE_VALIDATOR=$(docker-compose run -e SCONE_LOG=INFO -e SCONE_HASH=1 etny-validator | grep -v Creating | grep -v Pulling | grep -v latest | grep -v Digest | tr -d '\r')
56
-
57
- echo "MRENCLAVE_SECURELOCK: ${MRENCLAVE_SECURELOCK}"
58
- echo "MRENCLAVE_TRUSTEDZONE: ${MRENCLAVE_TRUSTEDZONE}"
59
- echo "MRENCLAVE_VALIDATOR: ${MRENCLAVE_VALIDATOR}"
60
-
61
- write_env "MRENCLAVE_SECURELOCK" "${MRENCLAVE_SECURELOCK}"
62
- write_env "MRENCLAVE_TRUSTEDZONE" "${MRENCLAVE_TRUSTEDZONE}"
63
- write_env "MRENCLAVE_VALIDATOR" "${MRENCLAVE_VALIDATOR}"
64
-
65
- export CI_COMMIT_BRANCH = ${PROJECT_NAME}
66
- # Generate enclave names
67
- ENCLAVE_NAME_SECURELOCK=$(echo ${ENCLAVE_NAME_SECURELOCK} | awk '{print toupper($0)}' | sed 's#/#_#g' | sed 's#-#_#g')
68
- PREDECESSOR_NAME_SECURELOCK=$(echo PREDECESSOR_SECURELOCK_${VERSION}_${CI_COMMIT_BRANCH} | awk '{print toupper($0)}' | sed 's#/#_#g' | sed 's#-#_#g')
69
-
70
- echo
71
- echo "ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}"
72
- echo "PREDECESSOR_NAME_SECURELOCK: ${PREDECESSOR_NAME_SECURELOCK}"
73
- write_env "PREDECESSOR_NAME_SECURELOCK" "${PREDECESSOR_NAME_SECURELOCK}"
74
- echo
75
-
76
- export ENCLAVE_NAME_SECURELOCK
77
- # write_env "ENCLAVE_NAME_SECURELOCK" "${ENCLAVE_NAME_SECURELOCK}"
78
-
79
- PREDECESSOR_HASH_SECURELOCK=$(eval "echo \${$PREDECESSOR_NAME_SECURELOCK}")
80
-
81
- # Set default values only if environment variables are not set
82
- PREDECESSOR_HASH_SECURELOCK=${PREDECESSOR_HASH_SECURELOCK:-"EMPTY"}
83
-
84
- # Debug: Print environment variables
85
- echo "PREDECESSOR_HASH_SECURELOCK: ${PREDECESSOR_HASH_SECURELOCK}"
86
- echo "MRENCLAVE_SECURELOCK: ${MRENCLAVE_SECURELOCK}"
87
- echo "ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}"
88
-
89
- # Process etny-securelock-test.yaml
90
- if [ ! -f etny-securelock-test.yaml.tpl ]; then
91
- echo "Error: Template file etny-securelock-test.yaml.tpl not found!"
92
- exit 1
93
- fi
94
-
95
- if [ "${PREDECESSOR_HASH_SECURELOCK}" = "EMPTY" ]; then
96
- sed -e "s|__PREDECESSOR__ |#predecessor: ${PREDECESSOR_HASH_SECURELOCK}|g" \
97
- -e "s|__MRENCLAVE__|${MRENCLAVE_SECURELOCK}|g" \
98
- -e "s|__ENCLAVE_NAME__|${ENCLAVE_NAME_SECURELOCK}|g" \
99
- etny-securelock-test.yaml.tpl > etny-securelock-test.yaml
100
- else
101
- sed -e "s|__PREDECESSOR__|predecessor: ${PREDECESSOR_HASH_SECURELOCK}|g" \
102
- -e "s|__MRENCLAVE__|${MRENCLAVE_SECURELOCK}|g" \
103
- -e "s|__ENCLAVE_NAME__|${ENCLAVE_NAME_SECURELOCK}|g" \
104
- etny-securelock-test.yaml.tpl > etny-securelock-test.yaml
105
- fi
106
-
107
- echo "Contents of etny-securelock-test.yaml:"
108
- cat etny-securelock-test.yaml
109
-
110
- echo "Checking for remaining placeholders:"
111
- grep -n "__.*__" etny-securelock-test.yaml || echo "No placeholders found."
112
-
113
- echo "##############################################################################################################"
114
-
115
- ENCLAVE_NAME_TRUSTEDZONE=$(echo ${ENCLAVE_NAME_TRUSTEDZONE} | awk '{print toupper($0)}' | sed 's#/#_#g' | sed 's#-#_#g')
116
- PREDECESSOR_NAME_TRUSTEDZONE=$(echo PREDECESSOR_TRUSTEDZONE_${VERSION}_${CI_COMMIT_BRANCH} | awk '{print toupper($0)}' | sed 's#/#_#g' | sed 's#-#_#g')
117
-
118
- echo
119
- echo "ENCLAVE_NAME_TRUSTEDZONE: ${ENCLAVE_NAME_TRUSTEDZONE}"
120
- echo "PREDECESSOR_NAME_TRUSTEDZONE: ${PREDECESSOR_NAME_TRUSTEDZONE}"
121
- echo
122
-
123
- export ENCLAVE_NAME_TRUSTEDZONE
124
- # write_env "ENCLAVE_NAME_TRUSTEDZONE" "${ENCLAVE_NAME_TRUSTEDZONE}"
125
-
126
- PREDECESSOR_HASH_TRUSTEDZONE=$(eval "echo \${$PREDECESSOR_NAME_TRUSTEDZONE}")
127
- PREDECESSOR_HASH_TRUSTEDZONE=${PREDECESSOR_HASH_TRUSTEDZONE:-"EMPTY"}
128
-
129
- # Debug: Print environment variables
130
- echo "PREDECESSOR_HASH_TRUSTEDZONE: ${PREDECESSOR_HASH_TRUSTEDZONE}"
131
- echo "MRENCLAVE_TRUSTEDZONE: ${MRENCLAVE_TRUSTEDZONE}"
132
- echo "MRENCLAVE_VALIDATOR: ${MRENCLAVE_VALIDATOR}"
133
- echo "ENCLAVE_NAME_TRUSTEDZONE: ${ENCLAVE_NAME_TRUSTEDZONE}"
134
-
135
- # Process etny-trustedzone-test.yaml
136
- if [ ! -f etny-trustedzone-test.yaml.tpl ]; then
137
- echo "Error: Template file etny-trustedzone-test.yaml.tpl not found!"
138
- exit 1
139
- fi
140
-
141
- if [ "${PREDECESSOR_HASH_TRUSTEDZONE}" = "EMPTY" ]; then
142
- sed -e "s|__PREDECESSOR__|# predecessor: ${PREDECESSOR_HASH_TRUSTEDZONE}|g" \
143
- -e "s|__MRENCLAVE__|${MRENCLAVE_TRUSTEDZONE}|g" \
144
- -e "s|__MRENCLAVE_VALIDATOR__|${MRENCLAVE_VALIDATOR}|g" \
145
- -e "s|__ENCLAVE_NAME__|${ENCLAVE_NAME_TRUSTEDZONE}|g" \
146
- etny-trustedzone-test.yaml.tpl > etny-trustedzone-test.yaml
147
- else
148
- sed -e "s|__PREDECESSOR__|predecessor: ${PREDECESSOR_HASH_TRUSTEDZONE}|g" \
149
- -e "s|__MRENCLAVE__|${MRENCLAVE_TRUSTEDZONE}|g" \
150
- -e "s|__MRENCLAVE_VALIDATOR__|${MRENCLAVE_VALIDATOR}|g" \
151
- -e "s|__ENCLAVE_NAME__|${ENCLAVE_NAME_TRUSTEDZONE}|g" \
152
- etny-trustedzone-test.yaml.tpl > etny-trustedzone-test.yaml
153
- fi
154
-
155
- echo "Contents of etny-trustedzone-test.yaml:"
156
- cat etny-trustedzone-test.yaml
157
-
158
- echo "Checking for remaining placeholders:"
159
- grep -n "__.*__" etny-trustedzone-test.yaml || echo "No placeholders found."
160
-
161
- echo "# Update docker-compose files"
162
-
163
- # Update docker-compose files
164
- for file in docker-compose.yml docker-compose-final.yml; do
165
- if [ ! -f "$file" ]; then
166
- echo "Error: $file not found!"
167
- continue
168
- fi
169
-
170
- echo "Processing $file"
171
- echo "ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}"
172
- echo "ENCLAVE_NAME_TRUSTEDZONE: ${ENCLAVE_NAME_TRUSTEDZONE}"
173
-
174
- echo "Checking for placeholders before replacement:"
175
- grep "__ENCLAVE_NAME_SECURELOCK__" "$file" || echo "No __ENCLAVE_NAME_SECURELOCK__ found in $file"
176
- grep "__ENCLAVE_NAME_TRUSTEDZONE__" "$file" || echo "No __ENCLAVE_NAME_TRUSTEDZONE__ found in $file"
177
-
178
- sed -i '' -e "s|__ENCLAVE_NAME_SECURELOCK__|${ENCLAVE_NAME_SECURELOCK}|g" \
179
- -e "s|__ENCLAVE_NAME_TRUSTEDZONE__|${ENCLAVE_NAME_TRUSTEDZONE}|g" \
180
- "$file"
181
-
182
- echo "Checking for placeholders after replacement:"
183
- grep "__ENCLAVE_NAME_SECURELOCK__" "$file" || echo "No __ENCLAVE_NAME_SECURELOCK__ found in $file"
184
- grep "__ENCLAVE_NAME_TRUSTEDZONE__" "$file" || echo "No __ENCLAVE_NAME_TRUSTEDZONE__ found in $file"
185
-
186
- echo "Contents of $file:"
187
- cat "$file"
188
- echo
189
- done
190
-
191
- # export binaries hashes from scontain base image (node/python)
192
- # use them allong with the ipfs hash of the uploaded registry artefact
193
-
194
- # Get PUBLIC_KEY for SECURELOCK
195
- export PUBLIC_KEY_SECURELOCK_RES=$(docker-compose run etny-securelock | grep -v Creating | grep -v Pulling | grep -v latest | grep -v Digest | sed 's/.*PUBLIC_KEY:\s*//' | tr -d '\r')
196
-
197
- echo "PUBLIC_KEY_SECURELOCK_RES: ${PUBLIC_KEY_SECURELOCK_RES}"
198
-
199
-
200
- # Check if PUBLIC_KEY_SECURELOCK_RES is empty
201
- if [ -z "${PUBLIC_KEY_SECURELOCK_RES}" ]; then
202
- echo
203
- echo
204
- echo "It seams that your machine is not SGX compatible."
205
- echo
206
- echo "Do you want to continue by generating the necesary certificates using the Ethernity Cloud signing service? (yes/no)"
207
- read -p "Select an option (default is no): " REPLY
208
- if [[ -z "$REPLY" ]]; then
209
- echo "No option selected. Exiting."
210
- exit 1
211
- elif [[ "$REPLY" == "yes" ]]; then
212
- echo
213
- echo "Generating certificates using the Ethernity Cloud signing service..."
214
- echo
215
- echo "**** Started ipfs initial pining ****"
216
- if [ -f ipfs.sh ]; then
217
- chmod +x ipfs_pre.sh
218
- ./ipfs_pre.sh
219
- else
220
- echo "Warning: ipfs_pre.sh not found. Skipping IPFS setup."
221
- fi
222
- echo "**** Finished ipfs initial pining ****"
223
- echo "ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}"
224
- echo "VERSION: ${VERSION}"
225
- echo "BLOCKCHAIN_NETWORK: ${BLOCKCHAIN_NETWORK}"
226
- python3 ./public_key_service.py --enclave_name "${PROJECT_NAME}" --protocol_version "${VERSION}" --network "${BLOCKCHAIN_NETWORK}" --template_version "0.1.12"
227
- # read PUBLIC_KEY_SECURELOCK_RES from PUBLIC_KEY.txt
228
- PUBLIC_KEY_SECURELOCK_RES=$(cat PUBLIC_KEY.txt)
229
- else
230
- echo "Exiting."
231
- exit 1
232
- fi
233
- fi
234
-
235
- export CERTIFICATE_CONTENT_SECURELOCK=$(echo "${PUBLIC_KEY_SECURELOCK_RES}" | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' | sed -e '/-----BEGIN CERTIFICATE-----/d' -e '/-----END CERTIFICATE-----/d')
236
- if [ -z "${CERTIFICATE_CONTENT_SECURELOCK}" ]; then
237
- echo "ERROR! PUBLIC_KEY_SECURELOCK not found"
238
- exit 1
239
- else
240
- echo "FOUND PUBLIC_KEY_SECURELOCK"
241
- fi
242
-
243
-
244
-
245
- echo -e "${PUBLIC_KEY_SECURELOCK}" > certificate.securelock.crt
246
- echo "Listing certificate PUBLIC_KEY_SECURELOCK:"
247
- cat certificate.securelock.crt
248
-
249
-
250
- CERTIFICATE_CONTENT_TRUSTEDZONE="MIIBczCB+6ADAgECAgkAkZLVvEgT6QgwCgYIKoZIzj0EAwMwEjEQMA4GA1UEAwwHQ0FfQ0VSVDAgFw0yNDA2MDUwODEyMjhaGA80MDk2MDEwMTAwMDAwMFowFjEUMBIGA1UEAwwLU0VSVkVSX0NFUlQwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAARuZILgRDczZfYdvx+GP3MMNKWX0SsUYkG3ySN/lJL0iEm/rgjoLDRT2gV8p+xfzeGPqzAjL/6/5N7JLjKdmzMCSi0umbFKIzV1UOBQMoTye8Kq9pmrZSKW/gcDeg2tDb+jFzAVMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAoGCCqGSM49BAMDA2cAMGQCMDjiF3lBtlj+AiPu7k4AiaPcluAk8V7AFrKpNwfLCsmR8iSkjKuhMSWN0+Y1htUg+wIwVSY9CI8vbUJYWvOCd7n5IjLq2G0SF8Kw9k5BmX6XucnZxHc9dFgLm+6pcpuQg3YG"
251
- export PUBLIC_KEY_TRUSTEDZONE="-----BEGIN CERTIFICATE-----\n${CERTIFICATE_CONTENT_TRUSTEDZONE}\n-----END CERTIFICATE-----"
252
- echo -e "${PUBLIC_KEY_TRUSTEDZONE}" > certificate.trustedzone.crt
253
- echo "Listing certificate PUBLIC_KEY_TRUSTEDZONE:"
254
- cat certificate.trustedzone.crt
255
-
256
- echo "**** Started ipfs final ****"
257
- if [ -f ipfs.sh ]; then
258
- chmod +x ipfs.sh
259
- ./ipfs.sh
260
- else
261
- echo "Warning: ipfs.sh not found. Skipping IPFS setup."
262
- fi
263
- echo "**** Finished ipfs final ****"
264
-
265
- echo "Adding certificates for SECURELOCK into IMAGE REGISTRY smart contract..."
266
- if [ -f image_registry_runner.py ]; then
267
- brew install python3
268
- python3 -m venv venv
269
- source venv/bin/activate
270
- pip3 install --no-cache --upgrade pip minio web3==5.17.0 eth_account python-dotenv requests
271
- python3 image_registry_runner.py
272
- deactivate
273
- else
274
- echo "Warning: image_registry_runner.py not found. Skipping certificate addition to IMAGE REGISTRY smart contract."
275
- fi
276
-
277
- echo "Script completed successfully."
@@ -1,23 +0,0 @@
1
- #!/bin/sh
2
-
3
- apk add screen
4
-
5
- cd /
6
- wget https://github.com/ipfs/kubo/releases/download/v0.17.0/kubo_v0.17.0_linux-386.tar.gz
7
- tar zxvf kubo_v0.17.0_linux-386.tar.gz
8
- mv kubo go-ipfs
9
- cd go-ipfs
10
- ./ipfs init
11
-
12
- screen -dm -t ipfs-swarm watch /go-ipfs/ipfs swarm connect /ip4/31.7.188.59/tcp/4001/p2p/QmRBc1eBt4hpJQUqHqn6eA8ixQPD3LFcUDsn6coKBQtia5
13
-
14
- screen -dm -t ipfs-daemon /ipfs-daemon.sh
15
-
16
- sleep 10
17
-
18
- cd /var/lib/registry
19
- HASH=`/go-ipfs/ipfs add . -r | grep added | tail -1 | awk '{print $2}'`
20
- /go-ipfs/ipfs pin add ${HASH}
21
-
22
-
23
- echo "HASH is ${HASH}"