@ethernity-cloud/sdk-js 1.6.2 → 1.7.1

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 (57) hide show
  1. package/README.md +86 -48
  2. package/cas/config.js +61 -3
  3. package/info.js +14 -5
  4. package/init.js +24 -6
  5. package/network.js +51 -0
  6. package/nodenithy/build/securelock/Dockerfile.tmpl +34 -32
  7. package/nodenithy/build/securelock/scripts/binary-fs-build.sh +7 -6
  8. package/nodenithy/build.mjs +80 -68
  9. package/nodenithy/run/docker-compose-final.yml.tmpl +36 -31
  10. package/nodenithy/run/docker-compose.yml.tmpl +34 -45
  11. package/nodenithy/run/image_registry.js +17 -4
  12. package/nodenithy/run.js +42 -28
  13. package/nodenithy/src/ec_helloworld_example.js +46 -42
  14. package/nodenithy/src/preStart.mjs +41 -51
  15. package/package.json +6 -3
  16. package/publish.js +4 -2
  17. package/pynithy/build/securelock/Dockerfile.base.tpl +13 -0
  18. package/pynithy/build/securelock/Dockerfile.tpl +131 -0
  19. package/pynithy/build/securelock/scripts/binary-fs-build.sh +25 -34
  20. package/pynithy/build/securelock/scripts/pyfreeze.sh +32 -0
  21. package/pynithy/build/securelock/src/{pox.abi → abi/etnyImplementationV2.abi} +1489 -1489
  22. package/pynithy/build/securelock/src/abi/image_registry.abi +1 -0
  23. package/pynithy/build/securelock/src/ecld_state.py +906 -0
  24. package/pynithy/build/securelock/src/esr.abi +1 -0
  25. package/pynithy/build/securelock/src/esr_local.py +267 -0
  26. package/pynithy/build/securelock/src/esr_wallet.py +150 -0
  27. package/pynithy/build/securelock/src/etny_crypto.py +208 -167
  28. package/pynithy/build/securelock/src/etny_exec.py +385 -79
  29. package/pynithy/build/securelock/src/etny_exec_flask.py +535 -0
  30. package/pynithy/build/securelock/src/etny_exec_serv.py +353 -0
  31. package/pynithy/build/securelock/src/etny_session_exec.py +245 -0
  32. package/pynithy/build/securelock/src/get_sgx_report.so +0 -0
  33. package/pynithy/build/securelock/src/image_registry.abi +1 -1
  34. package/pynithy/build/securelock/src/key_generation.py +17 -17
  35. package/pynithy/build/securelock/src/local_api.py +189 -0
  36. package/pynithy/build/securelock/src/models.py +200 -176
  37. package/pynithy/build/securelock/src/securelock.py.tmpl +1037 -731
  38. package/pynithy/build/securelock/src/swift_stream_service.py +206 -186
  39. package/pynithy/build.mjs +139 -89
  40. package/pynithy/run/docker-compose-final.yml.tmpl +58 -51
  41. package/pynithy/run/docker-compose.yml.tmpl +62 -48
  42. package/pynithy/run/etny-securelock-test.yaml.tpl +4 -1
  43. package/pynithy/run/image_registry.js +17 -4
  44. package/pynithy/run.js +44 -28
  45. package/pynithy/src/ec_helloworld_example.js +46 -42
  46. package/pynithy/src/preStart.mjs +41 -51
  47. package/pynithy/src/serverless/Dockerfile.serverless +8 -0
  48. package/pynithy/src/serverless/requirements.txt +6 -0
  49. package/run.js +37 -34
  50. package/nodenithy/build/las/Dockerfile +0 -5
  51. package/nodenithy/src/preStart.js +0 -45
  52. package/pynithy/build/docker-compose.yml +0 -70
  53. package/pynithy/build/las/Dockerfile +0 -11
  54. package/pynithy/build/las/src/etny_entrypoint.sh +0 -6
  55. package/pynithy/build/las/src/las_entrypoint.sh +0 -26
  56. package/pynithy/build/scripts/binary-fs-build.sh +0 -28
  57. package/pynithy/build/securelock/Dockerfile.tmpl +0 -95
package/pynithy/run.js CHANGED
@@ -60,13 +60,19 @@ const writeEnv = (key, value) => {
60
60
 
61
61
  let templateName = process.env.TRUSTED_ZONE_IMAGE || 'etny-pynithy-testnet';
62
62
 
63
- const isMainnet = !templateName.includes('testnet');
64
- // A testnet template with a SessionRegistry is CAS-attested by the
65
- // ethernity-cas validator set: the session is registered on-chain, the
66
- // enclave is provisioned from a validator, and the certificate comes out of
67
- // the CAS session. Other testnets self-sign and register nothing.
68
- const casTestnet = !isMainnet && casConfig.casProvisioned(templateName, isMainnet);
63
+ const isMainnet = casConfig.isMainnetNetwork(process.env.BLOCKCHAIN_NETWORK);
64
+ // Mainnet enclaves are provisioned by the Scontain CAS. A testnet template
65
+ // with a SessionRegistry is CAS-attested by the ethernity-cas validator set:
66
+ // the session is registered on-chain, the enclave is provisioned from a
67
+ // validator, and the certificate comes out of the CAS session. Every other
68
+ // testnet's enclaves self-sign from MR_ENCLAVE and register no session.
69
+ const cas = casConfig.casProvisioned(templateName, isMainnet);
70
+ const casTestnet = !isMainnet && cas;
69
71
  const casChain = casConfig.CHAIN[templateName] || {};
72
+ // An -unsafe network is a self-signing testnet whose compose carries no LAS;
73
+ // its securelock is registered as <project>-unsafe.
74
+ const unsafe = casConfig.isUnsafeNetwork(process.env.BLOCKCHAIN_NETWORK);
75
+ const securelock = casConfig.nameOnNetwork(process.env.PROJECT_NAME, process.env.BLOCKCHAIN_NETWORK);
70
76
 
71
77
  const currentDir = process.cwd();
72
78
  console.log(`currentDir: ${currentDir}`);
@@ -107,14 +113,21 @@ const extractSignedMrenclave = (service) => {
107
113
 
108
114
  const main = async () => {
109
115
  process.env.NODE_NO_WARNINGS = 1
110
- const backupFiles = ['docker-compose.yml.tmpl', 'docker-compose-final.yml.tmpl'];
111
- backupFiles.forEach(file => {
112
- if (!fs.existsSync(file)) {
113
- console.error(`Error: ${file} not found!`);
116
+ // The securelock heap ecld-build signed it with (part of MRENCLAVE).
117
+ const memory = (process.env.MEMORY_TO_ALLOCATE || '').trim();
118
+ if (!memory) {
119
+ console.error("Error: MEMORY_TO_ALLOCATE is not set in .env; run ecld-build first.");
120
+ process.exit(1);
121
+ }
122
+ ['docker-compose.yml', 'docker-compose-final.yml'].forEach(file => {
123
+ const template = `${file}.tmpl`;
124
+ if (!fs.existsSync(template)) {
125
+ console.error(`Error: ${template} not found!`);
114
126
  return;
115
127
  }
116
- const backupContent = fs.readFileSync(file, 'utf8');
117
- fs.writeFileSync(file.replace('.tmpl', ''), backupContent, 'utf8');
128
+ const content = casConfig.renderCompose(fs.readFileSync(template, 'utf8'), cas, unsafe)
129
+ .replace(/__MEMORY_TO_ALLOCATE__/g, memory);
130
+ fs.writeFileSync(file, content, 'utf8');
118
131
  });
119
132
 
120
133
 
@@ -130,7 +143,7 @@ const main = async () => {
130
143
  // MRENCLAVE signed --production at build time (/signed_mrenclave.txt). A
131
144
  // mismatch means SCONE recomputed the measurement at load (params drift) and
132
145
  // re-signed as DEBUG, which CAS rejects on mainnet. Refuse to publish.
133
- if (isMainnet || casTestnet) {
146
+ if (cas) {
134
147
  const signedMrenclave = extractSignedMrenclave('etny-securelock');
135
148
  if (!signedMrenclave || signedMrenclave !== process.env.MRENCLAVE_SECURELOCK) {
136
149
  console.error(`Error: securelock runtime MRENCLAVE (${process.env.MRENCLAVE_SECURELOCK}) != signed MRENCLAVE (${signedMrenclave}).`);
@@ -218,15 +231,20 @@ const main = async () => {
218
231
  MRENCLAVE: process.env.MRENCLAVE_SECURELOCK,
219
232
  ENCLAVE_NAME: ENCLAVE_NAME_SECURELOCK
220
233
  };
221
- processYamlTemplate('etny-securelock-test.yaml.tpl', 'etny-securelock-test.yaml', replacementsSecurelock);
234
+ if (cas) {
235
+ processYamlTemplate('etny-securelock-test.yaml.tpl', 'etny-securelock-test.yaml', replacementsSecurelock);
236
+ }
222
237
 
223
238
  // Where the session goes depends on who provisions the securelock. On a
224
239
  // CAS-attested testnet it is registered ON-CHAIN in the ethernity-cas
225
240
  // SessionRegistry, which the validator set reads and which accepts no
226
241
  // POST; the publish then waits until the validators serve it, because the
227
- // public-key harvest below provisions the enclave from them. Every other
228
- // network keeps the Scontain CAS registration that follows.
229
- if (casTestnet) {
242
+ // public-key harvest below provisions the enclave from them. On mainnet it
243
+ // is registered with the Scontain CAS. A self-signing testnet has none: a
244
+ // CAS-issued certificate would not match the key the enclave derives.
245
+ if (!cas) {
246
+ console.log(`\t✔ ${process.env.BLOCKCHAIN_NETWORK}: no CAS session; the securelock self-signs from MR_ENCLAVE`);
247
+ } else if (casTestnet) {
230
248
  const registered = await sessionRegistry.register(
231
249
  casChain.rpcUrl, casChain.chainId, casConfig.SESSION_REGISTRY[templateName],
232
250
  process.env.PRIVATE_KEY, fs.readFileSync('etny-securelock-test.yaml'),
@@ -429,13 +447,9 @@ const main = async () => {
429
447
  console.log(`No __ENCLAVE_NAME_TRUSTEDZONE__ found in ${file}`);
430
448
  }
431
449
 
432
- let ENCLAVE_NAME_TRUSTEDZONE = 'etny-pynithy-trustedzone-v3-testnet-0.1.12'
433
- if (isMainnet) {
434
- ENCLAVE_NAME_TRUSTEDZONE = 'ecld-pynithy-trustedzone-v3-3.0.0'
435
- }
436
- if (casTestnet) {
437
- ENCLAVE_NAME_TRUSTEDZONE = trustedZoneSession;
438
- }
450
+ // Named only in a CAS-provisioned compose; a self-signing one has no
451
+ // __CAS_ONLY__ lines left.
452
+ const ENCLAVE_NAME_TRUSTEDZONE = casTestnet ? trustedZoneSession : 'ecld-pynithy-trustedzone-v3-3.0.0';
439
453
  let updatedContent = fileContentBefore
440
454
  .replace(/__ENCLAVE_NAME_SECURELOCK__/g, ENCLAVE_NAME_SECURELOCK)
441
455
  .replace(/__ENCLAVE_NAME_TRUSTEDZONE__/g, ENCLAVE_NAME_TRUSTEDZONE);
@@ -544,7 +558,7 @@ const main = async () => {
544
558
  console.log()
545
559
 
546
560
  console.log(`ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}`);
547
- execSync(`node ./public_key_service.js --enclave_name "${process.env.PROJECT_NAME}" --protocol_version "v3" --network "${process.env.BLOCKCHAIN_NETWORK}" --template_version "${process.env.VERSION}"`, { stdio: 'inherit' });
561
+ execSync(`node ./public_key_service.js --enclave_name "${securelock}" --protocol_version "v3" --network "${process.env.BLOCKCHAIN_NETWORK}" --template_version "${process.env.VERSION}"`, { stdio: 'inherit' });
548
562
  PUBLIC_KEY_SECURELOCK_RES = fs.readFileSync('PUBLIC_KEY.txt', 'utf8').trim();
549
563
  console.log(`PUBLIC_KEY_SECURELOCK_RES: ${PUBLIC_KEY_SECURELOCK_RES}`);
550
564
  if (!PUBLIC_KEY_SECURELOCK_RES || PUBLIC_KEY_SECURELOCK_RES === '-1') {
@@ -611,10 +625,12 @@ const main = async () => {
611
625
  console.log("IPFS_HASH: ", process.env.IPFS_HASH);
612
626
  writeEnv('IPFS_HASH', process.env.IPFS_HASH);
613
627
  process.chdir(currentDir);
614
- console.log("Adding certificates for SECURELOCK into IMAGE REGISTRY smart contract...");
628
+ console.log(`Adding certificates for SECURELOCK ${securelock} into IMAGE REGISTRY smart contract...`);
629
+ // image_registry.js registers the image under PROJECT_NAME.
630
+ const registryEnv = { ...process.env, PROJECT_NAME: securelock };
615
631
  let existing = false;
616
632
  try {
617
- const existingImages = execSync(`node ${runDir}/image_registry.js "${process.env.BLOCKCHAIN_NETWORK}" "${process.env.PROJECT_NAME}" "${process.env.VERSION}" "${process.env.PRIVATE_KEY}" "registerSecureLockImage"`, { stdio: "inherit" });
633
+ const existingImages = execSync(`node ${runDir}/image_registry.js "${process.env.BLOCKCHAIN_NETWORK}" "${securelock}" "${process.env.VERSION}" "${process.env.PRIVATE_KEY}" "registerSecureLockImage"`, { stdio: "inherit", env: registryEnv });
618
634
  if (existingImages.toString().trim().replace('Image hash: ', '') === process.env.IPFS_HASH) {
619
635
  console.log("Certificates for SECURELOCK already added to IMAGE REGISTRY smart contract");
620
636
  }
@@ -626,7 +642,7 @@ const main = async () => {
626
642
  }
627
643
 
628
644
  if (!existing) {
629
- const res = execSync(`node ${runDir}/image_registry.js "${process.env.BLOCKCHAIN_NETWORK}" "" "" "" "registerSecureLockImage"`, { stdio: "inherit" });
645
+ const res = execSync(`node ${runDir}/image_registry.js "${process.env.BLOCKCHAIN_NETWORK}" "" "" "" "registerSecureLockImage"`, { stdio: "inherit", env: registryEnv });
630
646
  }
631
647
  // The on-chain session points at the image it admits, so a validator can
632
648
  // pin the image beside the body it serves.
@@ -1,58 +1,62 @@
1
- const AppCss = require('./App.css');
1
+ import './App.css';
2
2
  import EthernityCloudRunner from "@ethernity-cloud/runner";
3
- import {ECEvent, ECRunner, ECStatus} from "@ethernity-cloud/runner/enums";
4
- import Web3 from 'web3';
3
+ import { ECStatus } from "@ethernity-cloud/runner/enums";
5
4
 
5
+ // Filled in from the project's .env by src/preStart.mjs on `npm start`: the
6
+ // securelock this dApp is published as, the trustedzone it was built against,
7
+ // the network's token address and chain id, the -unsafe network when the dApp
8
+ // runs without a CAS (null otherwise), and the IPFS endpoint.
6
9
  const PROJECT_NAME = "";
10
+ const TRUSTED_ZONE_IMAGE = "";
11
+ const NETWORK_ADDRESS = "";
12
+ const CHAIN_ID = null;
13
+ const UNSAFE_NETWORK = null;
7
14
  const IPFS_ENDPOINT = "";
8
15
 
16
+ // A call into src/serverless/backend.py; its return value is the task result.
9
17
  const code = `hello("World")`;
10
18
 
11
19
  function App() {
12
20
  const executeTask = async () => {
13
- const runner = new EthernityCloudRunner();
14
- // this is a server provided by Ethernity CLOUD, please bear in mind that you can use your own Decentralized Storage server
15
- const ipfsAddress = IPFS_ENDPOINT;
16
- runner.initializeStorage(ipfsAddress);
17
- console.log(PROJECT_NAME)
18
- const onTaskProgress = (e) => {
19
- if (e.detail.status === ECStatus.ERROR) {
20
- console.error(e.detail.message);
21
- } else {
22
- console.log(e.detail.message);
23
- }
24
- };
25
-
26
- const onTaskCompleted = (e) => {
27
- console.log(`Task Result: ${e.detail.message.result}`);
28
- // display the result in page below the buttons
29
- const result = document.createElement("p");
30
- result.innerHTML = `Task Result: ${e.detail.message.result}`;
31
- document.body.appendChild(result);
21
+ // The browser wallet (MetaMask) signs and pays for the order.
22
+ const runner = new EthernityCloudRunner(NETWORK_ADDRESS, {}, CHAIN_ID || undefined);
23
+ if (UNSAFE_NETWORK) {
24
+ await runner.setNetwork(...UNSAFE_NETWORK);
32
25
  }
26
+ runner.initializeStorage(IPFS_ENDPOINT);
33
27
 
34
- runner.addEventListener(ECEvent.TASK_PROGRESS, onTaskProgress);
35
- runner.addEventListener(ECEvent.TASK_COMPLETED, onTaskCompleted);
28
+ // Events are named by task status; detail is { message, status, progress }.
29
+ runner.addEventListener(ECStatus.DEFAULT, (e) => {
30
+ console.log(`[${e.detail.progress}] ${e.detail.message}`);
31
+ });
32
+ runner.addEventListener(ECStatus.ERROR, (e) => {
33
+ console.error(e.detail.message);
34
+ });
35
+ runner.addEventListener(ECStatus.SUCCESS, async () => {
36
+ const result = await runner.getResult();
37
+ console.log(`Task Result: ${result}`);
38
+ // display the result in page below the buttons
39
+ const line = document.createElement("p");
40
+ line.textContent = `Task Result: ${result}`;
41
+ document.body.appendChild(line);
42
+ });
36
43
 
37
- await runner.run(PROJECT_NAME,
38
- code,
39
- '0xd58f5C1834279ABD601df85b3E4b2323aDD4E75e',
40
- { taskPrice: 6, cpu: 1, memory: 1, storage: 10, bandwidth: 1, duration: 1, validators: 1 });
44
+ const resources = { taskPrice: 10, cpu: 1, memory: 1, storage: 10, bandwidth: 1, duration: 1, validators: 1 };
45
+ await runner.run(resources, PROJECT_NAME, code, '', TRUSTED_ZONE_IMAGE);
41
46
  };
47
+
42
48
  const connectWallet = async () => {
43
- if (window.ethereum) {
44
- window.web3 = new Web3(window.ethereum);
45
- try {
46
- // Request account access
47
- await window.ethereum.request({ method: 'eth_requestAccounts' });
48
- console.log("Wallet connected");
49
- } catch (error) {
50
- console.error("User denied account access");
51
- }
52
- } else {
53
- console.log('Please install MetaMask!');
54
- }
55
- };
49
+ if (!window.ethereum) {
50
+ console.log('Please install MetaMask!');
51
+ return;
52
+ }
53
+ try {
54
+ await window.ethereum.request({ method: 'eth_requestAccounts' });
55
+ console.log("Wallet connected");
56
+ } catch (error) {
57
+ console.error("User denied account access");
58
+ }
59
+ };
56
60
 
57
61
  return (
58
62
  <div className="container">
@@ -61,4 +65,4 @@ function App() {
61
65
  </div>
62
66
  );
63
67
  }
64
- export default App;
68
+ export default App;
@@ -1,57 +1,47 @@
1
+ // Runs before `react-scripts start` (the project's `npm start`): fills the
2
+ // constants at the top of src/ec_helloworld_example.js from the project's
3
+ // .env, the way ecld-run reads the same values. PROJECT_NAME and
4
+ // TRUSTED_ZONE_IMAGE take their -unsafe form on an -unsafe network; the
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.
1
7
  import fs from 'fs';
8
+ import { createRequire } from 'module';
2
9
  import dotenv from 'dotenv';
3
- dotenv.config();
10
+ import * as enums from '@ethernity-cloud/runner/enums.js';
4
11
 
5
- export const ECRunner = {
6
- 'etny-pynithy-testnet': ['0x02882F03097fE8cD31afbdFbB5D72a498B41112c'],
7
- 'etny-nodenithy-testnet': ['0x02882F03097fE8cD31afbdFbB5D72a498B41112c'],
8
- 'etny-pynithy': ['0x549A6E06BB2084100148D50F51CF77a3436C3Ae7'],
9
- 'etny-nodenithy': ['0x549A6E06BB2084100148D50F51CF77a3436C3Ae7'],
10
- 'ecld-nodenithy-testnet': ['0xfb450e40f590F1B5A119a4B82E6F3579D6742a00'],
11
- 'ecld-pynithy': ['0xc6920888988cAcEeA7ACCA0c96f2D65b05eE22Ba'],
12
- 'ecld-nodenithy': ['0xc6920888988cAcEeA7ACCA0c96f2D65b05eE22Ba']
12
+ dotenv.config();
13
+ const require = createRequire(import.meta.url);
14
+ const casConfig = require('@ethernity-cloud/sdk-js/cas/config.js');
15
+ const { networkFor } = require('@ethernity-cloud/sdk-js/network.js');
16
+
17
+ const { PROJECT_NAME, TRUSTED_ZONE_IMAGE, BLOCKCHAIN_NETWORK, IPFS_ENDPOINT } = process.env;
18
+ if (!PROJECT_NAME || !BLOCKCHAIN_NETWORK) {
19
+ console.error('preStart: PROJECT_NAME and BLOCKCHAIN_NETWORK are not set in .env; run `npm run ecld-init` first.');
20
+ process.exit(1);
21
+ }
22
+ const { network, known } = networkFor(enums, BLOCKCHAIN_NETWORK);
23
+ if (!network) {
24
+ console.error(`preStart: unknown BLOCKCHAIN_NETWORK '${BLOCKCHAIN_NETWORK}' in .env. Known: ${known.join(', ')}`);
25
+ process.exit(1);
26
+ }
27
+
28
+ const constants = {
29
+ PROJECT_NAME: casConfig.nameOnNetwork(PROJECT_NAME, BLOCKCHAIN_NETWORK),
30
+ TRUSTED_ZONE_IMAGE: casConfig.nameOnNetwork(TRUSTED_ZONE_IMAGE, BLOCKCHAIN_NETWORK) || '',
31
+ NETWORK_ADDRESS: network.address,
32
+ CHAIN_ID: network.chainId || null,
33
+ UNSAFE_NETWORK: network.unsafe || null,
34
+ IPFS_ENDPOINT: IPFS_ENDPOINT || 'https://ipfs.ethernity.cloud',
13
35
  };
14
36
 
15
37
  const filePath = 'src/ec_helloworld_example.js';
16
- const fileContent = fs.readFileSync(filePath, 'utf8');
17
-
18
- const updatedContent = fileContent
19
- .replace(/const PROJECT_NAME = ".*?";/, `const PROJECT_NAME = "${process.env.PROJECT_NAME}";`)
20
- .replace(/const IPFS_ENDPOINT = ".*?";/, `const IPFS_ENDPOINT = "${process.env.IPFS_ENDPOINT}";`)
21
- .replace(/new EthernityCloudRunner\(.*?\);/, `new EthernityCloudRunner('${ECRunner[process.env.ENCLAVE_NAME_TRUSTEDZONE]}');`);
22
-
23
- fs.writeFileSync(filePath, updatedContent, 'utf8');
24
-
25
- // const code = updatedContent.match(/const code = `hello\("(.*?)"\);/)[1];
26
-
27
- const imageRegistryPath = 'node_modules/@ethernity-cloud/runner/contract/operation/imageRegistryContract.js';
28
- const imageRegistryContent = fs.readFileSync(imageRegistryPath, 'utf8');
29
-
30
- // Log the original content for debugging
31
- // console.log('Original imageRegistryContent:', imageRegistryContent);
32
-
33
- // Replace the content in imageRegistryContract.js
34
- // const updatedImageRegistryContent = imageRegistryContent.replace(/getLatestTrustedZoneImageCertPublicKey\([^)]*\);/, "getLatestTrustedZoneImageCertPublicKey('" + process.env.ENCLAVE_NAME_TRUSTEDZONE + "', 'v3')").replace(/getLatestImageVersionPublicKey\([^)]*\)/, "getLatestImageVersionPublicKey(imageName, '" + process.env.VERSION + "')");
35
- const updatedImageRegistryContent = imageRegistryContent.replace(
36
- /async getEnclaveDetailsV3\(.*?\{[\s\S]*?\}\s*\}/,
37
- `async getEnclaveDetailsV3(imageName, version) {
38
- try {
39
- const trustedZonePublicKey = (await this.contract.getLatestTrustedZoneImageCertPublicKey('${process.env.ENCLAVE_NAME_TRUSTEDZONE}', 'v3'));
40
- const imageDetails = await this.contract.getLatestImageVersionPublicKey(imageName, '${process.env.VERSION}');
41
- return [imageDetails[0], trustedZonePublicKey[1], imageDetails[2]];
42
- } catch (e) {
43
- console.log(e);
44
- return null;
45
- }
46
- }`
47
- );
48
-
49
-
50
- fs.writeFileSync(imageRegistryPath, updatedImageRegistryContent, 'utf8');
51
-
52
- const runnerPath = 'node_modules/@ethernity-cloud/runner/runner.js';
53
- const runnerContent = fs.readFileSync(runnerPath, 'utf8');
54
-
55
- const updatedRunnerContent = runnerContent.replace(/this.#enclaveImageIPFSHash}:.*?:/, "this.#enclaveImageIPFSHash}:"+process.env.ENCLAVE_NAME_TRUSTEDZONE+":").replace(/new ImageRegistryContract\([^)]*\);/, "new ImageRegistryContract(this.#networkAddress, '"+process.env.ENCLAVE_NAME_TRUSTEDZONE+"');");
56
-
57
- fs.writeFileSync(runnerPath, updatedRunnerContent, 'utf8');
38
+ let content = fs.readFileSync(filePath, 'utf8');
39
+ for (const [name, value] of Object.entries(constants)) {
40
+ const line = new RegExp(`^const ${name} = .*;$`, 'm');
41
+ if (!line.test(content)) {
42
+ console.error(`preStart: ${filePath} has no 'const ${name} = ...;' line to fill.`);
43
+ process.exit(1);
44
+ }
45
+ content = content.replace(line, `const ${name} = ${JSON.stringify(value)};`);
46
+ }
47
+ fs.writeFileSync(filePath, content, 'utf8');
@@ -0,0 +1,8 @@
1
+ FROM etny-securelock-base
2
+
3
+ # System packages your backend needs, added to the securelock base image by
4
+ # ecld-build.
5
+ #
6
+ # Example:
7
+ # RUN apk update
8
+ # RUN apk add gcc g++ git openblas-dev
@@ -0,0 +1,6 @@
1
+ # Python packages your backend imports, one per line; ecld-build installs them
2
+ # into the securelock enclave.
3
+ # Example:
4
+ #
5
+ # scipy
6
+ # numpy
package/run.js CHANGED
@@ -15,8 +15,10 @@
15
15
  * ecld-publish), matching how ethernity_task drives a run:
16
16
  *
17
17
  * BLOCKCHAIN_NETWORK e.g. "Bloxberg_Testnet" -> the network token address
18
- * PROJECT_NAME the securelock enclave to run
19
- * TRUSTED_ZONE_IMAGE the trustedzone enclave
18
+ * PROJECT_NAME the securelock enclave to run (<PROJECT_NAME>-unsafe
19
+ * on an -unsafe network)
20
+ * TRUSTED_ZONE_IMAGE the trustedzone enclave (its -unsafe variant on an
21
+ * -unsafe network)
20
22
  * PRIVATE_KEY a funded 0x key — it pays for the order
21
23
  *
22
24
  * Usage, from the project root:
@@ -25,6 +27,7 @@
25
27
  * npx ecld-run --file payload.js
26
28
  * npx ecld-run --input data.json 'processData(___etny_data_set___)'
27
29
  * npx ecld-run --network BLOXBERG_TESTNET --task-price 3 'esrIncrement()'
30
+ * npx ecld-run --unsafe 'hello("World")' # the network's -unsafe variant
28
31
  * npx ecld-run --json 'hello("World")' # machine-readable result
29
32
  *
30
33
  * The runner is ESM; this CJS entry loads it with dynamic import().
@@ -36,29 +39,11 @@
36
39
 
37
40
  const fs = require('fs');
38
41
  try { require('dotenv').config(); } catch (e) { /* dotenv optional */ }
42
+ const casConfig = require('./cas/config.js');
43
+ const { networkFor, unsafeVariant } = require('./network.js');
39
44
 
40
45
  const DEFAULT_IPFS = 'https://ipfs.ethernity.cloud/api/v0';
41
46
 
42
- /* Map a BLOCKCHAIN_NETWORK token (as ecld-init writes it, spaces -> underscores)
43
- * to the runner's network token ADDRESS. Built from the runner's own ECAddress
44
- * so it can't drift. Accepts a few spellings per network. */
45
- function networkAddress(ECAddress, raw) {
46
- const key = String(raw || '').trim().toUpperCase().replace(/\s+/g, '_');
47
- const table = {
48
- BLOXBERG_TESTNET: ECAddress.BLOXBERG.TESTNET_ADDRESS,
49
- BLOXBERG_MAINNET: ECAddress.BLOXBERG.MAINNET_ADDRESS,
50
- POLYGON_MAINNET: ECAddress.POLYGON.MAINNET_ADDRESS,
51
- POLYGON_AMOY: ECAddress.POLYGON.TESTNET_ADDRESS,
52
- POLYGON_AMOY_TESTNET: ECAddress.POLYGON.TESTNET_ADDRESS,
53
- IOTEX_TESTNET: ECAddress.IOTEX && ECAddress.IOTEX.TESTNET_ADDRESS,
54
- ETHEREUM_SEPOLIA: ECAddress.SEPOLIA && ECAddress.SEPOLIA.TESTNET_ADDRESS,
55
- SEPOLIA: ECAddress.SEPOLIA && ECAddress.SEPOLIA.TESTNET_ADDRESS,
56
- LITVM_LITEFORGE: ECAddress.LITVM && ECAddress.LITVM.TESTNET_ADDRESS,
57
- LITVM: ECAddress.LITVM && ECAddress.LITVM.TESTNET_ADDRESS,
58
- };
59
- return { key, address: table[key] || null, known: Object.keys(table) };
60
- }
61
-
62
47
  function parseArgs(argv) {
63
48
  const opts = { ipfs: DEFAULT_IPFS, timeout: 600, taskPrice: 3, cpu: 1, memory: 1, storage: 10, bandwidth: 1, duration: 1, validators: 1, node: '' };
64
49
  const positional = [];
@@ -68,6 +53,7 @@ function parseArgs(argv) {
68
53
  else if (a === '--input' || a === '-i') opts.inputFile = argv[++i];
69
54
  else if (a === '--input-text') opts.inputText = argv[++i];
70
55
  else if (a === '--network') opts.network = argv[++i];
56
+ else if (a === '--unsafe') opts.unsafe = true;
71
57
  else if (a === '--securelock') opts.securelock = argv[++i];
72
58
  else if (a === '--trustedzone') opts.trustedzone = argv[++i];
73
59
  else if (a === '--node') opts.node = argv[++i];
@@ -94,7 +80,10 @@ usage: ecld-run 'hello("World")' | ecld-run --file payload.js | ecld-run --input
94
80
 
95
81
  payload: a code string, or --file <path>; input via --input <file> / --input-text <str>
96
82
  network: --network BLOXBERG_TESTNET (default: BLOCKCHAIN_NETWORK from .env)
97
- enclaves: --securelock <name> (default PROJECT_NAME), --trustedzone <name> (default TRUSTED_ZONE_IMAGE)
83
+ --unsafe: the network's -unsafe variant, which runs without a CAS
84
+ (BLOXBERG_TESTNET_UNSAFE, LITVM_LITEFORGE_UNSAFE)
85
+ enclaves: --securelock <name> (default PROJECT_NAME), --trustedzone <name> (default TRUSTED_ZONE_IMAGE);
86
+ on an -unsafe network the default is each one's -unsafe variant
98
87
  key: PRIVATE_KEY (a funded 0x key) from .env / env, or ECLD_PRIVATE_KEY
99
88
  resources: --task-price 3 --cpu 1 --memory 1 --storage 10 --bandwidth 1 --duration 1 --validators 1
100
89
  other: --node <addr> --ipfs <url> --timeout <sec> --json`;
@@ -121,27 +110,37 @@ async function main() {
121
110
  // ecld-run mirrors ecld-test: input is delivered via the payload call itself.
122
111
 
123
112
  // ---- runner (ESM) ----
124
- let EthernityCloudRunner, ECStatus, ECEvent, ECAddress, ECOrderTaskStatus;
113
+ let EthernityCloudRunner, ECStatus, ECEvent, ECOrderTaskStatus, enums;
125
114
  try {
126
115
  const runnerMod = await import('@ethernity-cloud/runner');
127
116
  EthernityCloudRunner = runnerMod.default || runnerMod.EthernityCloudRunner;
128
- const enums = await import('@ethernity-cloud/runner/enums.js');
129
- ({ ECStatus, ECEvent, ECAddress, ECOrderTaskStatus } = enums);
117
+ enums = await import('@ethernity-cloud/runner/enums.js');
118
+ ({ ECStatus, ECEvent, ECOrderTaskStatus } = enums);
130
119
  } catch (e) {
131
120
  console.error('ecld-run: the runner package is not installed or is too old '
132
- + '(need @ethernity-cloud/runner >= 0.4.4): ' + e.message);
121
+ + '(need @ethernity-cloud/runner >= 0.6.0): ' + e.message);
133
122
  process.exit(1);
134
123
  }
135
124
 
136
125
  // ---- network / enclaves / key ----
137
- const rawNetwork = opts.network || process.env.BLOCKCHAIN_NETWORK || 'BLOXBERG_TESTNET';
138
- const { key: netKey, address, known } = networkAddress(ECAddress, rawNetwork);
139
- if (!address) {
126
+ let rawNetwork = opts.network || process.env.BLOCKCHAIN_NETWORK || 'BLOXBERG_TESTNET';
127
+ if (opts.unsafe) {
128
+ const variant = unsafeVariant(rawNetwork);
129
+ if (!variant) {
130
+ console.error(`ecld-run: ${rawNetwork} has no -unsafe variant. -unsafe networks: `
131
+ + Object.keys(casConfig.UNSAFE_NETWORKS).join(', '));
132
+ process.exit(1);
133
+ }
134
+ rawNetwork = variant;
135
+ }
136
+ const { key: netKey, network, known } = networkFor(enums, rawNetwork);
137
+ if (!network) {
140
138
  console.error(`ecld-run: unknown network '${rawNetwork}'. Known: ${known.join(', ')}`);
141
139
  process.exit(1);
142
140
  }
143
- const securelock = opts.securelock || process.env.PROJECT_NAME;
144
- const trustedzone = opts.trustedzone || process.env.TRUSTED_ZONE_IMAGE; // may be undefined -> run() default
141
+ const securelock = opts.securelock || casConfig.nameOnNetwork(process.env.PROJECT_NAME, rawNetwork);
142
+ // May be undefined -> run() default.
143
+ const trustedzone = opts.trustedzone || casConfig.nameOnNetwork(process.env.TRUSTED_ZONE_IMAGE, rawNetwork);
145
144
  if (!securelock) {
146
145
  console.error('ecld-run: no securelock enclave: set PROJECT_NAME in .env '
147
146
  + '(run ecld-init/ecld-publish) or pass --securelock.');
@@ -156,7 +155,10 @@ async function main() {
156
155
  }
157
156
  if (!privateKey.startsWith('0x')) privateKey = '0x' + privateKey;
158
157
 
159
- console.log(`network : ${netKey} (${address})`);
158
+ console.log(`network : ${netKey} (${network.address})`);
159
+ if (network.unsafe) {
160
+ console.log(' UNSAFE: no CAS; the enclaves are debug-signed and sign their own certificates');
161
+ }
160
162
  console.log(`securelock : ${securelock}`);
161
163
  console.log(`trustedzone: ${trustedzone || '(runner default)'}`);
162
164
  console.log(`payload : ${JSON.stringify(code)}`);
@@ -165,7 +167,8 @@ async function main() {
165
167
  // ---- drive the runner ----
166
168
  let runner;
167
169
  try {
168
- runner = new EthernityCloudRunner(address, { privateKey });
170
+ runner = new EthernityCloudRunner(network.address, { privateKey }, network.chainId);
171
+ if (network.unsafe) await runner.setNetwork(...network.unsafe);
169
172
  } catch (e) {
170
173
  console.error('ecld-run: could not initialise the runner: ' + e.message);
171
174
  process.exit(1);
@@ -1,5 +0,0 @@
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 / /
@@ -1,45 +0,0 @@
1
- const fs = require('fs');
2
- require('dotenv').config();
3
-
4
- const filePath = 'src/ec_helloworld_example.js';
5
- const fileContent = fs.readFileSync(filePath, 'utf8');
6
-
7
- const updatedContent = fileContent
8
- .replace(/const PROJECT_NAME = ".*?";/, `const PROJECT_NAME = "${process.env.PROJECT_NAME}";`)
9
- .replace(/const IPFS_ENDPOINT = ".*?";/, `const IPFS_ENDPOINT = "${process.env.IPFS_ENDPOINT}";`)
10
-
11
- fs.writeFileSync(filePath, updatedContent, 'utf8');
12
-
13
- // const code = updatedContent.match(/const code = `hello\("(.*?)"\);/)[1];
14
-
15
- const imageRegistryPath = 'node_modules/@ethernity-cloud/runner/contract/operation/imageRegistryContract.js';
16
- const imageRegistryContent = fs.readFileSync(imageRegistryPath, 'utf8');
17
-
18
- // Log the original content for debugging
19
- // console.log('Original imageRegistryContent:', imageRegistryContent);
20
-
21
- // Replace the content in imageRegistryContract.js
22
- // const updatedImageRegistryContent = imageRegistryContent.replace(/getLatestTrustedZoneImageCertPublicKey\([^)]*\);/, "getLatestTrustedZoneImageCertPublicKey('" + process.env.ENCLAVE_NAME_TRUSTEDZONE + "', 'v3')").replace(/getLatestImageVersionPublicKey\([^)]*\)/, "getLatestImageVersionPublicKey(imageName, '" + process.env.VERSION + "')");
23
- const updatedImageRegistryContent = imageRegistryContent.replace(
24
- /async getEnclaveDetailsV3\(.*?\{[\s\S]*?\}\s*\}/,
25
- `async getEnclaveDetailsV3(imageName, version) {
26
- try {
27
- const trustedZonePublicKey = (await this.contract.getLatestTrustedZoneImageCertPublicKey('${process.env.ENCLAVE_NAME_TRUSTEDZONE}', 'v3'));
28
- const imageDetails = await this.contract.getLatestImageVersionPublicKey(imageName, '${process.env.VERSION}');
29
- return [imageDetails[0], trustedZonePublicKey[1], imageDetails[2]];
30
- } catch (e) {
31
- console.log(e);
32
- return null;
33
- }
34
- }`
35
- );
36
-
37
-
38
- fs.writeFileSync(imageRegistryPath, updatedImageRegistryContent, 'utf8');
39
-
40
- const runnerPath = 'node_modules/@ethernity-cloud/runner/runner.js';
41
- const runnerContent = fs.readFileSync(runnerPath, 'utf8');
42
-
43
- const updatedRunnerContent = runnerContent.replace(/this.#enclaveImageIPFSHash}:.*?:/, "this.#enclaveImageIPFSHash}:"+process.env.ENCLAVE_NAME_TRUSTEDZONE+":").replace(/new ImageRegistryContract\([^)]*\);/, "new ImageRegistryContract(this.#networkAddress, '"+process.env.ENCLAVE_NAME_TRUSTEDZONE+"');");
44
-
45
- fs.writeFileSync(runnerPath, updatedRunnerContent, 'utf8');
@@ -1,70 +0,0 @@
1
- version: '3.2'
2
- services:
3
- las:
4
- container_name: las
5
- privileged: true
6
- image: etny-las
7
- entrypoint: "/las_entrypoint.sh"
8
- # -a 0.0.0.0: without it the LAS binds dual-stack (:::18766) and cannot
9
- # allocate the socket on a host booted with ipv6.disable=1.
10
- command: "/usr/local/bin/las -a 0.0.0.0"
11
- devices:
12
- - "/dev/sgx_enclave:/dev/sgx_enclave"
13
- restart: on-failure
14
- networks:
15
- - ethernity
16
- ports:
17
- - target: 18766
18
- published: 18766
19
- protocol: tcp
20
- mode: host
21
-
22
- etny-securelock:
23
- container_name: etny-securelock
24
- privileged: true
25
- image: etny-securelock
26
- entrypoint: ""
27
- command: [ "/usr/local/bin/python", "/etny-securelock/securelock.py" ]
28
- environment:
29
- - SCONE_CAS_ADDR=scone-cas.cf
30
- - SCONE_LAS_ADDR=las
31
- - SCONE_CONFIG_ID=etny-pynity-test-0.0.18/application
32
- - SCONE_HEAP=128M
33
- - SCONE_LOG=DEBUG
34
- - SCONE_MODE=SIM
35
- - SCONE_ALLOW_DLOPEN=2
36
- - SCONE_EXTENSIONS_PATH=/lib/libbinary-fs.so
37
- restart: on-failure
38
- networks:
39
- - ethernity
40
- devices:
41
- - "/dev/sgx_enclave:/dev/sgx_enclave"
42
- depends_on:
43
- - las
44
-
45
- etny-trustedzone:
46
- container_name: etny-trustedzone
47
- privileged: true
48
- image: etny-trustedzone
49
- entrypoint: ""
50
- command: [ "/usr/local/bin/python", "/etny-trustedzone/trustedzone.py" ]
51
- environment:
52
- - SCONE_CAS_ADDR=scone-cas.cf
53
- - SCONE_LAS_ADDR=las
54
- - SCONE_CONFIG_ID=etny-pynity-trustedzone-0.0.18/application
55
- - SCONE_HEAP=128M
56
- - SCONE_LOG=DEBUG
57
- - SCONE_MODE=SIM
58
- - SCONE_ALLOW_DLOPEN=2
59
- - SCONE_EXTENSIONS_PATH=/lib/libbinary-fs.so
60
- restart: on-failure
61
- networks:
62
- - ethernity
63
- devices:
64
- - "/dev/sgx_enclave:/dev/sgx_enclave"
65
- depends_on:
66
- - las
67
-
68
- networks:
69
- ethernity:
70
- external: true
@@ -1,11 +0,0 @@
1
- FROM registry.scontain.com:5050/sconecuratedimages/services:las as initial
2
-
3
- FROM scratch
4
-
5
- COPY --from=initial / /
6
-
7
- RUN apt-get update
8
- RUN apt-get install psmisc
9
-
10
- COPY src/* /
11
-