@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.
- package/LICENSE +661 -0
- package/README.md +185 -0
- package/build.js +22 -0
- package/init.js +301 -0
- package/nodenithy/build/las/Dockerfile +5 -0
- package/nodenithy/build/securelock/Dockerfile.tmpl +65 -0
- package/nodenithy/build/securelock/scripts/binary-fs-build.sh +28 -0
- package/nodenithy/build/securelock/src/.env +3 -0
- package/nodenithy/build/securelock/src/etny_crypto.js +201 -0
- package/nodenithy/build/securelock/src/etny_exec.js +65 -0
- package/nodenithy/build/securelock/src/image_registry_abi.js +808 -0
- package/nodenithy/build/securelock/src/models.js +261 -0
- package/nodenithy/build/securelock/src/package.json +40 -0
- package/nodenithy/build/securelock/src/pox_abi.js +1491 -0
- package/nodenithy/build/securelock/src/securelock.js.tmpl +421 -0
- package/nodenithy/build/securelock/src/swift_stream_service.js +147 -0
- package/nodenithy/build/securelock/src/task_status.js +15 -0
- package/nodenithy/build/securelock/src/wallet.js +29 -0
- package/nodenithy/build/squash/Dockerfile +7 -0
- package/nodenithy/build/trustedzone/Dockerfile.tmpl +57 -0
- package/nodenithy/build/trustedzone/scripts/binary-fs-build.sh +22 -0
- package/nodenithy/build/trustedzone/src/.env +3 -0
- package/nodenithy/build/trustedzone/src/etny_crypto.js +202 -0
- package/nodenithy/build/trustedzone/src/etny_exec.js +54 -0
- package/nodenithy/build/trustedzone/src/image_registry_abi.js +808 -0
- package/nodenithy/build/trustedzone/src/models.js +261 -0
- package/nodenithy/build/trustedzone/src/package.json +40 -0
- package/nodenithy/build/trustedzone/src/pox_abi.js +1491 -0
- package/nodenithy/build/trustedzone/src/swift_stream_service.js +147 -0
- package/nodenithy/build/trustedzone/src/task_status.js +15 -0
- package/nodenithy/build/trustedzone/src/test.js +44 -0
- package/nodenithy/build/trustedzone/src/trustedzone.js.tmpl +508 -0
- package/nodenithy/build/trustedzone/src/wallet.js +28 -0
- package/nodenithy/build/validator/Dockerfile +58 -0
- package/nodenithy/build/validator/package-lock.json +6 -0
- package/nodenithy/build/validator/scripts/binary-fs-build.sh +19 -0
- package/nodenithy/build/validator/src/.env +3 -0
- package/nodenithy/build/validator/src/cert.pem +5 -0
- package/nodenithy/build/validator/src/etny_crypto.js +204 -0
- package/nodenithy/build/validator/src/etny_exec.js +52 -0
- package/nodenithy/build/validator/src/image_registry_abi.js +808 -0
- package/nodenithy/build/validator/src/key.pem +6 -0
- package/nodenithy/build/validator/src/models.js +261 -0
- package/nodenithy/build/validator/src/package-lock.json +2498 -0
- package/nodenithy/build/validator/src/package.json +40 -0
- package/nodenithy/build/validator/src/pox_abi.js +1491 -0
- package/nodenithy/build/validator/src/swift_stream_service.js +147 -0
- package/nodenithy/build/validator/src/task_status.js +15 -0
- package/nodenithy/build/validator/src/test.js +44 -0
- package/nodenithy/build/validator/src/trustedzone.js +613 -0
- package/nodenithy/build/validator/src/validator_abi.js +834 -0
- package/nodenithy/build/validator/src/wallet.js +28 -0
- package/nodenithy/build.js +184 -0
- package/nodenithy/build.mjs +179 -0
- package/nodenithy/build.sh +161 -0
- package/nodenithy/ipfs.js +135 -0
- package/nodenithy/ipfs.mjs +551 -0
- package/nodenithy/public/favicon.ico +0 -0
- package/nodenithy/public/index.html +43 -0
- package/nodenithy/public/logo192.png +0 -0
- package/nodenithy/public/logo512.png +0 -0
- package/nodenithy/public/manifest.json +25 -0
- package/nodenithy/public/robots.txt +3 -0
- package/nodenithy/run/__pycache__/swift_stream_service.cpython-312.pyc +0 -0
- package/nodenithy/run/app/input.txt +4 -0
- package/nodenithy/run/app/payload.js +4 -0
- package/nodenithy/run/docker-compose-final.yml.tmpl +65 -0
- package/nodenithy/run/docker-compose-swift-stream.yml +17 -0
- package/nodenithy/run/docker-compose.yml.tmpl +76 -0
- package/nodenithy/run/etny-securelock-test.yaml.tpl +46 -0
- package/nodenithy/run/etny-trustedzone-test.yaml.tpl +45 -0
- package/nodenithy/run/git.sh +22 -0
- package/nodenithy/run/image_registry.abi +1 -0
- package/nodenithy/run/image_registry.js +372 -0
- package/nodenithy/run/image_registry.py +327 -0
- package/nodenithy/run/image_registry_runner.py +71 -0
- package/nodenithy/run/ipfs.sh +58 -0
- package/nodenithy/run/ipfs_pre.sh +75 -0
- package/nodenithy/run/public_key_service.js +90 -0
- package/nodenithy/run/public_key_service.py +107 -0
- package/nodenithy/run/swift_stream_service.py +212 -0
- package/nodenithy/run/swiftstream.py +37 -0
- package/nodenithy/run/swiftstream1.py +27 -0
- package/nodenithy/run.js +538 -0
- package/nodenithy/run.sh +277 -0
- package/nodenithy/scripts/build-ipfs-upload.sh +23 -0
- package/nodenithy/scripts/build.sh +40 -0
- package/nodenithy/scripts/ipfs-daemon.sh +7 -0
- package/nodenithy/scripts/run.sh +50 -0
- package/nodenithy/src/App.css +57 -0
- package/nodenithy/src/ec_helloworld_example.js +64 -0
- package/nodenithy/src/index.css +13 -0
- package/nodenithy/src/index.js +17 -0
- package/nodenithy/src/preStart.js +45 -0
- package/nodenithy/src/preStart.mjs +57 -0
- package/nodenithy/src/reportWebVitals.js +13 -0
- package/nodenithy/src/serverless/backend.js +5 -0
- package/package.json +48 -0
- package/postinstall.js +34 -0
- package/publish.js +126 -0
- package/pynithy/build/docker-compose.yml +68 -0
- package/pynithy/build/las/Dockerfile +11 -0
- package/pynithy/build/las/src/etny_entrypoint.sh +6 -0
- package/pynithy/build/las/src/las_entrypoint.sh +26 -0
- package/pynithy/build/scripts/binary-fs-build.sh +28 -0
- package/pynithy/build/securelock/Dockerfile.tmpl +78 -0
- package/pynithy/build/securelock/scripts/binary-fs-build.sh +41 -0
- package/pynithy/build/securelock/src/app/.env +5 -0
- package/pynithy/build/securelock/src/app/cert1-ca1-clean.crt +10 -0
- package/pynithy/build/securelock/src/app/cert1-ca1-clean.key +6 -0
- package/pynithy/build/securelock/src/app/enclave_pub_cert.pem +10 -0
- package/pynithy/build/securelock/src/app/input.txt +1 -0
- package/pynithy/build/securelock/src/app/payload.py +25 -0
- package/pynithy/build/securelock/src/app/public-cert-clean.pem +10 -0
- package/pynithy/build/securelock/src/app/result.txt +1 -0
- package/pynithy/build/securelock/src/app/transaction.txt +1 -0
- package/pynithy/build/securelock/src/etny_crypto.py +167 -0
- package/pynithy/build/securelock/src/etny_exec.py +79 -0
- package/pynithy/build/securelock/src/image_registry.abi +1 -0
- package/pynithy/build/securelock/src/key_generation.py +17 -0
- package/pynithy/build/securelock/src/models.py +176 -0
- package/pynithy/build/securelock/src/pox.abi +1489 -0
- package/pynithy/build/securelock/src/securelock.py.tmpl +411 -0
- package/pynithy/build/securelock/src/swift_stream_service.py +186 -0
- package/pynithy/build/trustedzone/Dockerfile.tmpl +56 -0
- package/pynithy/build/trustedzone/scripts/binary-fs-build.sh +32 -0
- package/pynithy/build/trustedzone/src/app/.env +5 -0
- package/pynithy/build/trustedzone/src/app/cert1-ca1-clean.crt +10 -0
- package/pynithy/build/trustedzone/src/app/cert1-ca1-clean.key +6 -0
- package/pynithy/build/trustedzone/src/app/enclave_pub_cert.pem +10 -0
- package/pynithy/build/trustedzone/src/app/input.txt +1 -0
- package/pynithy/build/trustedzone/src/app/payload.py +25 -0
- package/pynithy/build/trustedzone/src/app/public-cert-clean.pem +10 -0
- package/pynithy/build/trustedzone/src/app/result.txt +1 -0
- package/pynithy/build/trustedzone/src/app/securelock.crt +10 -0
- package/pynithy/build/trustedzone/src/app/transaction.txt +1 -0
- package/pynithy/build/trustedzone/src/app/trustedzone.crt +10 -0
- package/pynithy/build/trustedzone/src/etny_crypto.py +188 -0
- package/pynithy/build/trustedzone/src/etny_exec.py +56 -0
- package/pynithy/build/trustedzone/src/formatter.py +42 -0
- package/pynithy/build/trustedzone/src/image_registry.abi +1 -0
- package/pynithy/build/trustedzone/src/key_generation.py +17 -0
- package/pynithy/build/trustedzone/src/models.py +176 -0
- package/pynithy/build/trustedzone/src/pox.abi +1489 -0
- package/pynithy/build/trustedzone/src/swift_stream_service.py +186 -0
- package/pynithy/build/trustedzone/src/trustedzone.py.tmpl +460 -0
- package/pynithy/build.mjs +179 -0
- package/pynithy/docker-compose.yml +0 -0
- package/pynithy/ipfs.mjs +244 -0
- package/pynithy/public/favicon.ico +0 -0
- package/pynithy/public/index.html +43 -0
- package/pynithy/public/logo192.png +0 -0
- package/pynithy/public/logo512.png +0 -0
- package/pynithy/public/manifest.json +25 -0
- package/pynithy/public/robots.txt +3 -0
- package/pynithy/run/certs/cert.pem +31 -0
- package/pynithy/run/certs/challenge.crt +10 -0
- package/pynithy/run/certs/key.pem +52 -0
- package/pynithy/run/docker-compose-final.yml +59 -0
- package/pynithy/run/docker-compose-final.yml.tmpl +59 -0
- package/pynithy/run/docker-compose-swift-stream.yml +27 -0
- package/pynithy/run/docker-compose-swift-stream.yml.tmpl +27 -0
- package/pynithy/run/docker-compose.yml +55 -0
- package/pynithy/run/docker-compose.yml.tmpl +55 -0
- package/pynithy/run/etny-pynity-test.yaml.tpl +46 -0
- package/pynithy/run/etny-securelock-test.yaml.tpl +46 -0
- package/pynithy/run/etny-trustedzone-test.yaml.tpl +46 -0
- package/pynithy/run/git.sh +22 -0
- package/pynithy/run/image_registry.abi +1 -0
- package/pynithy/run/image_registry.js +372 -0
- package/pynithy/run/image_registry.py +139 -0
- package/pynithy/run/image_registry_runner.py +45 -0
- package/pynithy/run/ipfs.sh +89 -0
- package/pynithy/run/public_key_service.js +90 -0
- package/pynithy/run/swiftstream.py +28 -0
- package/pynithy/run.js +538 -0
- package/pynithy/src/App.css +57 -0
- package/pynithy/src/ec_helloworld_example.js +64 -0
- package/pynithy/src/index.css +13 -0
- package/pynithy/src/index.js +17 -0
- package/pynithy/src/preStart.mjs +57 -0
- package/pynithy/src/reportWebVitals.js +13 -0
- package/pynithy/src/serverless/__init__.py +0 -0
- package/pynithy/src/serverless/backend.py +2 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/bin/bash -v
|
|
2
|
+
|
|
3
|
+
cd /etny-trustedzone
|
|
4
|
+
ls
|
|
5
|
+
echo "####################"
|
|
6
|
+
cat .env
|
|
7
|
+
echo "####################"
|
|
8
|
+
|
|
9
|
+
cat trustedzone.js.tmpl | sed s/"__ENCLAVE_NAME_TRUSTEDZONE__"/"${ENCLAVE_NAME_TRUSTEDZONE}"/g > trustedzone.js
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
echo "starting building binary-fs..."
|
|
13
|
+
EXEC=(scone binaryfs / /binary-fs-dir -v \
|
|
14
|
+
--include '/usr/local/bin/node' \
|
|
15
|
+
--include '/etny-trustedzone/*' \
|
|
16
|
+
--host-path=/etc/resolv.conf \
|
|
17
|
+
--host-path=/etc/hosts)
|
|
18
|
+
echo "finished building binary-fs..."
|
|
19
|
+
|
|
20
|
+
exec "${EXEC[@]}"
|
|
21
|
+
|
|
22
|
+
exit
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const elliptic = require('elliptic');
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const rs = require('jsrsasign');
|
|
5
|
+
const ECKey = require('ec-key');
|
|
6
|
+
const curve = new elliptic.ec('p384');
|
|
7
|
+
const ascii85 = require('ascii85');
|
|
8
|
+
const ethSigUtil = require('@metamask/eth-sig-util');
|
|
9
|
+
const {createHash} = require('crypto');
|
|
10
|
+
|
|
11
|
+
function sha256(content) {
|
|
12
|
+
return createHash('sha256').update(content).digest('hex');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function fileChecksum(file) {
|
|
16
|
+
const fileContent = fs.readFileSync(file, 'utf8');
|
|
17
|
+
return sha256(fileContent);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function fileChecksumFromSwiftStream(swiftStreamClient, bucketName, fileName) {
|
|
21
|
+
const fileContent = await swiftStreamClient.getFileContent(bucketName, fileName);
|
|
22
|
+
//console.log(fileContent);
|
|
23
|
+
return sha256(fileContent);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const getPEMFromPublicFile = (publicKeyPath) => {
|
|
27
|
+
const publicKey = fs.readFileSync(publicKeyPath, 'utf8');
|
|
28
|
+
return crypto.createPublicKey(publicKey).export({type: 'spki', format: 'pem'});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const getPEMFromPublic = (publicKey) => {
|
|
32
|
+
return crypto.createPublicKey(publicKey).export({type: 'spki', format: 'pem'});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const loadCertificate = (certificate) => {
|
|
36
|
+
//console.log(certificate)
|
|
37
|
+
const publicKeyPEM = getPEMFromPublic(certificate);
|
|
38
|
+
const key = new ECKey(publicKeyPEM, 'pem');
|
|
39
|
+
//console.log(key);
|
|
40
|
+
return key;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getPrivatePointFromPrivateKey(privateKeyFile) {
|
|
44
|
+
let privateKey = fs.readFileSync(privateKeyFile, 'utf8');
|
|
45
|
+
//console.log(privateKey);
|
|
46
|
+
let privateKeyHex = rs.KEYUTIL.getKey(privateKey).prvKeyHex;
|
|
47
|
+
const privateKeyObject = curve.keyFromPrivate(privateKeyHex, 'hex');
|
|
48
|
+
return privateKeyObject.getPrivate();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const generatePublicKey = (x, y) => {
|
|
52
|
+
const pub = {x: x, y};
|
|
53
|
+
return curve.keyFromPublic(pub, 'hex');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getPublicPointFromCoords(x, y) {
|
|
57
|
+
const publicKey = generatePublicKey(x, y);
|
|
58
|
+
return publicKey.getPublic();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function ecc_point_to_256_bit_key(point) {
|
|
62
|
+
const value = point.getX().toString() + point.getY().toString();
|
|
63
|
+
const hash = crypto.createHash('sha256');
|
|
64
|
+
hash.update(value);
|
|
65
|
+
return hash.digest();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function encryptedDataToBase64Json(encryptedMsg) {
|
|
69
|
+
const key = curve.keyFromPublic(encryptedMsg.cipherTextPublicKey, 'hex');
|
|
70
|
+
const jsonObj = {
|
|
71
|
+
ciphertext: encryptedMsg.ciphertext.toString('hex'),
|
|
72
|
+
nonce: encryptedMsg.nonce.toString('hex'),
|
|
73
|
+
authTag: encryptedMsg.authTag.toString('hex'),
|
|
74
|
+
x: key.getPublic().getX(),
|
|
75
|
+
y: key.getPublic().getY()
|
|
76
|
+
};
|
|
77
|
+
const jsonString = JSON.stringify(jsonObj);
|
|
78
|
+
const binaryData = Buffer.from(jsonString, 'utf8');
|
|
79
|
+
return binaryData.toString('base64');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function encryptedDataFromBase64Json(base64Data) {
|
|
83
|
+
// decode the base64-encoded string back to a JSON string
|
|
84
|
+
const decodedJsonData = Buffer.from(base64Data, 'base64').toString('utf8');
|
|
85
|
+
return JSON.parse(decodedJsonData);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
function encrypt(certificate, message) {
|
|
91
|
+
const key = loadCertificate(certificate);
|
|
92
|
+
return encrypt_ecc(message, generatePublicKey(key.x, key.y));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function encrypt_ecc(msg, publicKey) {
|
|
96
|
+
const cipherTextPrivateKey = crypto.randomBytes(32);
|
|
97
|
+
const sharedEccKey = publicKey.getPublic().mul(cipherTextPrivateKey);
|
|
98
|
+
const secretKey = ecc_point_to_256_bit_key(sharedEccKey);
|
|
99
|
+
const iv = crypto.randomBytes(16);
|
|
100
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', secretKey, iv);
|
|
101
|
+
let encrypted = cipher.update(msg, 'utf8', 'hex');
|
|
102
|
+
encrypted += cipher.final('hex');
|
|
103
|
+
const cipherTextPublicKey = curve.g.mul(cipherTextPrivateKey);
|
|
104
|
+
return {
|
|
105
|
+
ciphertext: encrypted,
|
|
106
|
+
secretKey: secretKey,
|
|
107
|
+
nonce: iv,
|
|
108
|
+
authTag: cipher.getAuthTag().toString("hex"),
|
|
109
|
+
cipherTextPublicKey: cipherTextPublicKey.encode('hex')
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function decrypt(privateKeyFile, encryptedMsg) {
|
|
114
|
+
//console.log(privateKeyFile);
|
|
115
|
+
const privatePoint = getPrivatePointFromPrivateKey(privateKeyFile);
|
|
116
|
+
return decrypt_ecc(encryptedMsg, privatePoint);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function decrypt_ecc(encryptedMsg, privatePoint) {
|
|
120
|
+
try {
|
|
121
|
+
const {ciphertext, nonce, authTag, x, y} = encryptedMsg;
|
|
122
|
+
const publicPoint = getPublicPointFromCoords(`${x}`, `${y}`);
|
|
123
|
+
const sharedEccKey = publicPoint.mul(privatePoint);
|
|
124
|
+
const secretKey = ecc_point_to_256_bit_key(sharedEccKey);
|
|
125
|
+
|
|
126
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', secretKey, Buffer.from(nonce, 'hex'));
|
|
127
|
+
decipher.setAuthTag(Buffer.from(authTag, 'hex'));
|
|
128
|
+
let decrypted = decipher.update(ciphertext, 'hex', 'utf8');
|
|
129
|
+
decrypted += decipher.final('utf8');
|
|
130
|
+
return decrypted;
|
|
131
|
+
} catch (e) {
|
|
132
|
+
console.log(`Error while decrypting ECC:`, e.message);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function hexToBytes(hexStr) {
|
|
138
|
+
if (hexStr.startsWith("0x")) {
|
|
139
|
+
hexStr = hexStr.slice(2);
|
|
140
|
+
}
|
|
141
|
+
return Buffer.from(hexStr, "hex");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function encryptWithPublicKey(publicKey, data) {
|
|
145
|
+
// Returned object contains 4 properties: version, ephemPublicKey, nonce, ciphertext
|
|
146
|
+
// Each contains data encoded using base64, version is always the same string
|
|
147
|
+
const enc = ethSigUtil.encrypt({
|
|
148
|
+
publicKey: hexToBytes(publicKey).toString('base64'),
|
|
149
|
+
data: ascii85.encode(Buffer.from(data)).toString(),
|
|
150
|
+
version: 'x25519-xsalsa20-poly1305',
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// We want to store the data in smart contract, therefore we concatenate them
|
|
154
|
+
// into single Buffer
|
|
155
|
+
const buf = Buffer.concat([
|
|
156
|
+
Buffer.from(enc.ephemPublicKey, 'base64'),
|
|
157
|
+
Buffer.from(enc.nonce, 'base64'),
|
|
158
|
+
Buffer.from(enc.ciphertext, 'base64'),
|
|
159
|
+
]);
|
|
160
|
+
|
|
161
|
+
// In smart contract we are using `bytes[112]` variable (fixed size byte array)
|
|
162
|
+
// you might need to use `bytes` type for dynamic sized array
|
|
163
|
+
// We are also using ethers.js which requires type `number[]` when passing data
|
|
164
|
+
// for argument of type `bytes` to the smart contract function
|
|
165
|
+
// Next line just converts the buffer to `number[]` required by contract function
|
|
166
|
+
// THIS LINE IS USED IN OUR ORIGINAL CODE:
|
|
167
|
+
// return buf.toJSON().data;
|
|
168
|
+
|
|
169
|
+
// Return just the Buffer to make the function directly compatible with decryptData function
|
|
170
|
+
return buf;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// (async () => {
|
|
174
|
+
// try {
|
|
175
|
+
// const message = 'testabc1';
|
|
176
|
+
// console.log('initial message:', message);
|
|
177
|
+
// const publicKeyPEM = getPEMFromPublic('./app/cert1-ca1-clean.crt');
|
|
178
|
+
// const ECKey = require('ec-key');
|
|
179
|
+
// const key = new ECKey(publicKeyPEM, 'pem');
|
|
180
|
+
// const encrypted_message = encrypt(key.x, key.y, message);
|
|
181
|
+
// console.log(encrypted_message);
|
|
182
|
+
// console.log(encryptedDataToBase64Json(encrypted_message));
|
|
183
|
+
// //
|
|
184
|
+
// // const encrypted_message = 'eyJjaXBoZXJ0ZXh0IjoiZTYzZTcyNDY0MWY4YWRmN2QyNjNmMTI0ZGYxZTdlYzZmNGM5NGU1NCIsIm5vbmNlIjoiYmE0YWU5YjMyOWFhZWRiM2ViZTM5MGU4YTY3YWFiNmMiLCJhdXRoVGFnIjoiOGU2NmI4NTVmNTE3N2E0NzZlMjkwNTE3Y2Q2ZDE3ZmUiLCJ4IjoiN2E1MjhhNGI5YzAzODM4Mjc0ZmFiYzVlM2RiOWQ2ZWFiNzBiZTFiMDA3YWJiOTcyYzI0YmFhNGE1ZmI4OGJjNTVmNDVlNGNkMjZjY2NhNTFhOTk3OGZkNDRhZmE1YjQ0IiwieSI6IjE5M2NjMWYwMzVmOGMxZjEzNGU4MTEzOGIyOTRiODBiZWQyYjkyMzdkZmIyOTMyOGRjOTg1MzlmMjhkNjIzMTJiYTQ2OTU2NDFkYjIyNjk0ZWUyNGFjZjQ4MjBiZDlhMSJ9';
|
|
185
|
+
// // const messageDecrypted = decrypt('./app/cert1-ca1-clean.key', encryptedDataToBase64Json(encrypted_message));
|
|
186
|
+
// // console.log('decrypted message:', messageDecrypted);
|
|
187
|
+
// } catch (e) {
|
|
188
|
+
// console.log(e);
|
|
189
|
+
// }
|
|
190
|
+
//
|
|
191
|
+
// })();
|
|
192
|
+
|
|
193
|
+
module.exports = {
|
|
194
|
+
encryptedDataFromBase64Json,
|
|
195
|
+
encryptedDataToBase64Json,
|
|
196
|
+
encryptWithPublicKey,
|
|
197
|
+
decrypt,
|
|
198
|
+
encrypt,
|
|
199
|
+
sha256,
|
|
200
|
+
fileChecksum,
|
|
201
|
+
fileChecksumFromSwiftStream
|
|
202
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const { TaskStatus } = require('./task_status');
|
|
5
|
+
|
|
6
|
+
function ___etny_result___(data) {
|
|
7
|
+
return [0, data];
|
|
8
|
+
}
|
|
9
|
+
function executeTask(payload, input) {
|
|
10
|
+
return exec(payload, input, { '___etny_result___': ___etny_result___ });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function exec(payload, input, globals = null) {
|
|
14
|
+
try {
|
|
15
|
+
if (payload && payload !== "") {
|
|
16
|
+
if (input && input !== "") {
|
|
17
|
+
if (globals) {
|
|
18
|
+
globals['___etny_data_set___'] = input;
|
|
19
|
+
}
|
|
20
|
+
return eval(payload);
|
|
21
|
+
} else {
|
|
22
|
+
return eval(payload);
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
return [TaskStatus.PAYLOAD_NOT_DEFINED, 'Could not find the source file to execute'];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// return [TaskStatus.SUCCESS, 'TASK EXECUTED SUCCESSFULLY'];
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error instanceof ReferenceError) {
|
|
31
|
+
return [TaskStatus.SYSTEM_ERROR, error.message];
|
|
32
|
+
} else if (error instanceof EvalError) {
|
|
33
|
+
return [TaskStatus.KEY_ERROR, error.message];
|
|
34
|
+
} else if (error instanceof SyntaxError) {
|
|
35
|
+
return [TaskStatus.SYNTAX_WARNING, error.message];
|
|
36
|
+
} else if (error instanceof Error) {
|
|
37
|
+
try {
|
|
38
|
+
if (error.args[0][0] === 0) {
|
|
39
|
+
return [TaskStatus.SUCCESS, error.args[0][1]];
|
|
40
|
+
} else {
|
|
41
|
+
return [TaskStatus.BASE_EXCEPTION, error.args[0]];
|
|
42
|
+
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
return [TaskStatus.BASE_EXCEPTION, error.message];
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
return [TaskStatus.BASE_EXCEPTION, error.message];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
executeTask
|
|
54
|
+
};
|