@ethernity-cloud/sdk-js 1.7.0 → 1.7.7
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.
- package/README.md +74 -50
- package/cas/config.js +6 -6
- package/cas/resolver.js +49 -18
- package/cas/session_registry.js +72 -24
- package/info.js +1 -1
- package/init.js +17 -2
- package/localKubo.js +160 -0
- package/network.js +51 -0
- package/nodenithy/build/securelock/src/etny_crypto.js +20 -2
- package/nodenithy/build/securelock/src/models.js +3 -5
- package/nodenithy/build/securelock/src/securelock.js.tmpl +136 -70
- package/nodenithy/build.mjs +8 -7
- package/nodenithy/ipfs.mjs +37 -13
- package/nodenithy/run/image_registry.abi +1 -1
- package/nodenithy/run/image_registry.js +258 -68
- package/nodenithy/run/public_key_service.js +10 -3
- package/nodenithy/run/public_key_service.py +12 -6
- package/nodenithy/run.js +160 -88
- package/nodenithy/src/ec_helloworld_example.js +46 -42
- package/nodenithy/src/preStart.mjs +41 -51
- package/package.json +5 -2
- package/publish.js +20 -8
- package/pynithy/build/securelock/src/securelock.py.tmpl +21 -9
- package/pynithy/build.mjs +8 -7
- package/pynithy/ipfs.mjs +37 -13
- package/pynithy/run/image_registry.abi +1 -1
- package/pynithy/run/image_registry.js +258 -68
- package/pynithy/run/public_key_service.js +10 -3
- package/pynithy/run.js +160 -88
- package/pynithy/src/ec_helloworld_example.js +46 -42
- package/pynithy/src/preStart.mjs +41 -51
- package/revert.js +76 -0
- package/run.js +1 -39
- package/nodenithy/src/preStart.js +0 -45
package/run.js
CHANGED
|
@@ -40,48 +40,10 @@
|
|
|
40
40
|
const fs = require('fs');
|
|
41
41
|
try { require('dotenv').config(); } catch (e) { /* dotenv optional */ }
|
|
42
42
|
const casConfig = require('./cas/config.js');
|
|
43
|
+
const { networkFor, unsafeVariant } = require('./network.js');
|
|
43
44
|
|
|
44
45
|
const DEFAULT_IPFS = 'https://ipfs.ethernity.cloud/api/v0';
|
|
45
46
|
|
|
46
|
-
/* Map a BLOCKCHAIN_NETWORK token (as ecld-init writes it, spaces -> underscores)
|
|
47
|
-
* to the runner's network: its token ADDRESS, the chain id of a testnet whose
|
|
48
|
-
* token address other testnets share, and for an -unsafe network the
|
|
49
|
-
* (network, type) the runner is set to, which runs only -unsafe trustedzones.
|
|
50
|
-
* Built from the runner's own enums so it can't drift. Accepts a few spellings
|
|
51
|
-
* per network. */
|
|
52
|
-
function networkFor({ ECAddress, ECNetworkByChainId }, raw) {
|
|
53
|
-
const key = String(raw || '').trim().toUpperCase().replace(/\s+/g, '_');
|
|
54
|
-
const bloxbergTestnet = { address: ECAddress.BLOXBERG.TESTNET_ADDRESS };
|
|
55
|
-
const amoy = { address: ECAddress.POLYGON.TESTNET_ADDRESS };
|
|
56
|
-
const sepolia = { address: ECAddress.SEPOLIA.TESTNET_ADDRESS, chainId: ECNetworkByChainId.SEPOLIA.TESTNET };
|
|
57
|
-
const litvm = { address: ECAddress.LITVM.TESTNET_ADDRESS, chainId: ECNetworkByChainId.LITVM.TESTNET };
|
|
58
|
-
const table = {
|
|
59
|
-
BLOXBERG_TESTNET: bloxbergTestnet,
|
|
60
|
-
BLOXBERG_TESTNET_UNSAFE: { ...bloxbergTestnet, unsafe: ['BLOXBERG', 'TESTNET_UNSAFE'] },
|
|
61
|
-
BLOXBERG_MAINNET: { address: ECAddress.BLOXBERG.MAINNET_ADDRESS },
|
|
62
|
-
POLYGON_MAINNET: { address: ECAddress.POLYGON.MAINNET_ADDRESS },
|
|
63
|
-
POLYGON_AMOY: amoy,
|
|
64
|
-
POLYGON_AMOY_TESTNET: amoy,
|
|
65
|
-
IOTEX_TESTNET: { address: ECAddress.IOTEX.TESTNET_ADDRESS, chainId: ECNetworkByChainId.IOTEX.TESTNET },
|
|
66
|
-
ETHEREUM_SEPOLIA: sepolia,
|
|
67
|
-
SEPOLIA: sepolia,
|
|
68
|
-
LITVM_LITEFORGE: litvm,
|
|
69
|
-
LITVM: litvm,
|
|
70
|
-
LITVM_LITEFORGE_UNSAFE: { ...litvm, unsafe: ['LITVM', 'TESTNET_UNSAFE'] },
|
|
71
|
-
};
|
|
72
|
-
return { key, network: table[key] || null, known: Object.keys(table) };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/* The -unsafe network a network token names, or whose sibling it names; null
|
|
76
|
-
* when the network has no -unsafe variant. */
|
|
77
|
-
function unsafeVariant(raw) {
|
|
78
|
-
const key = String(raw || '').trim().replace(/\s+/g, '_');
|
|
79
|
-
if (casConfig.isUnsafeNetwork(key)) return key;
|
|
80
|
-
const variant = Object.keys(casConfig.UNSAFE_NETWORKS)
|
|
81
|
-
.find((name) => casConfig.UNSAFE_NETWORKS[name].toUpperCase() === key.toUpperCase());
|
|
82
|
-
return variant || null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
47
|
function parseArgs(argv) {
|
|
86
48
|
const opts = { ipfs: DEFAULT_IPFS, timeout: 600, taskPrice: 3, cpu: 1, memory: 1, storage: 10, bandwidth: 1, duration: 1, validators: 1, node: '' };
|
|
87
49
|
const positional = [];
|
|
@@ -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');
|