@ethernity-cloud/sdk-js 1.1.0

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