godprotocol 1.0.81 → 1.0.82

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 (51) hide show
  1. package/.babelrc +3 -0
  2. package/Index.js +8 -19
  3. package/Loader_sequence/main.js +368 -234
  4. package/Objects/Account.js +187 -178
  5. package/Objects/Block.js +60 -61
  6. package/Objects/Blockweb.js +27 -34
  7. package/Objects/Chain.js +115 -118
  8. package/Objects/Explorer.js +30 -37
  9. package/Objects/Filesystem.js +95 -80
  10. package/Objects/Frame.js +43 -48
  11. package/Objects/Manager.js +60 -69
  12. package/Objects/Opcodes.js +39 -101
  13. package/Objects/Oracle.js +50 -66
  14. package/Objects/Virtual_machine.js +132 -132
  15. package/build/Account.js +187 -0
  16. package/build/Block.js +68 -0
  17. package/build/Blockweb.js +36 -0
  18. package/build/Chain.js +119 -0
  19. package/build/Explorer.js +47 -0
  20. package/build/Filesystem.js +127 -0
  21. package/build/Frame.js +52 -0
  22. package/build/Index.js +20 -0
  23. package/build/Manager.js +86 -0
  24. package/build/Opcodes.js +109 -0
  25. package/build/Oracle.js +81 -0
  26. package/build/Virtual_machine.js +136 -0
  27. package/build/add.js +26 -0
  28. package/build/create_server.js +132 -0
  29. package/build/framer.js +59 -0
  30. package/build/functions.js +82 -0
  31. package/build/hash.js +14 -0
  32. package/build/indices.js +31 -0
  33. package/build/jmp.js +19 -0
  34. package/build/main.js +327 -0
  35. package/build/opcodes.js +60 -0
  36. package/build/privacy.js +27 -0
  37. package/build/services.js +50 -0
  38. package/build/std.js +15 -0
  39. package/framer.js +36 -34
  40. package/opcodes/add.js +9 -25
  41. package/opcodes/indices.js +13 -16
  42. package/opcodes/jmp.js +7 -12
  43. package/opcodes/std.js +7 -13
  44. package/opcodes.js +32 -42
  45. package/package.json +1 -1
  46. package/readme.md +4 -4
  47. package/utils/create_server.js +72 -105
  48. package/utils/functions.js +31 -43
  49. package/utils/hash.js +10 -11
  50. package/utils/privacy.js +10 -15
  51. package/utils/services.js +32 -33
package/opcodes/jmp.js CHANGED
@@ -1,19 +1,14 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.jmp = void 0;
7
- var jmp = function jmp(args, vm, meta) {
1
+ const jmp = (args, vm, meta) => {
8
2
  meta = meta || {};
9
- var _meta = meta,
10
- flag = _meta.flag,
11
- inverse = _meta.inverse;
12
- var condition;
3
+ let { flag, inverse } = meta;
4
+
5
+ let condition;
13
6
  if (flag) condition = vm.flags[flag];
14
7
  if (inverse) condition = !!!condition;
8
+
15
9
  if ((condition || !flag) && typeof args.op0 === "number") {
16
10
  vm.track.pointer = args.op0;
17
11
  }
18
12
  };
19
- exports.jmp = jmp;
13
+
14
+ export { jmp };
package/opcodes/std.js CHANGED
@@ -1,15 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.stdout = void 0;
7
- var stdout = function stdout(args, vm) {
1
+ const stdout = (args, vm) => {
8
2
  if (!args) return;
9
- vm.account.stdout.push({
10
- data: args,
11
- pid: vm.track.pid
12
- });
13
- for (var v in args) console.log(args[v]);
3
+
4
+ vm.account.stdout.push({ data: args, pid: vm.track.pid });
5
+
6
+ for (let v in args) console.log(args[v]);
14
7
  };
15
- exports.stdout = stdout;
8
+
9
+ export { stdout };
package/opcodes.js CHANGED
@@ -1,60 +1,50 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _add = require("./opcodes/add");
8
- var _indices = require("./opcodes/indices");
9
- var _jmp = require("./opcodes/jmp");
10
- var _std = require("./opcodes/std");
11
- var _services = require("./utils/services");
12
1
  // import { socket_send } from "./Socket";
2
+ import { ops } from "./opcodes/add";
3
+ import { getter, setter } from "./opcodes/indices";
4
+ import { jmp } from "./opcodes/jmp";
5
+ import { stdout } from "./opcodes/std";
6
+ import { post_request } from "./utils/services";
13
7
 
14
- var opcodes = function opcodes(account) {
15
- var set = account.vm.set;
16
- _add.ops.map(function (op) {
17
- set(op.name, function (args) {
8
+ const opcodes = (account) => {
9
+ let set = account.vm.set;
10
+
11
+ ops.map((op) => {
12
+ set(op.name, (args) => {
18
13
  if (!args) return;
14
+
19
15
  try {
20
- var result = eval("".concat(args.op0, " ").concat(op.sign, " ").concat(args.op1));
16
+ let result = eval(`${args.op0} ${op.sign} ${args.op1}`);
21
17
  if (op.sign === "==") {
22
18
  account.vm.flags.equal = !!result;
23
19
  return;
24
20
  }
21
+
25
22
  return result;
26
23
  } catch (e) {
27
24
  console.log(e.message);
28
25
  }
29
26
  });
30
27
  });
31
- Object.keys(account.vm.flags).map(function (flag) {
32
- set("jmp_".concat(flag), function (args, vm) {
33
- return (0, _jmp.jmp)(args, vm, {
34
- flag: flag
35
- });
36
- });
37
- set("jmp_not_".concat(flag), function (args, vm) {
38
- return (0, _jmp.jmp)(args, vm, {
39
- flag: flag,
40
- inverse: true
41
- });
42
- });
43
- });
44
- set("jmp", _jmp.jmp);
45
- set("setter", _indices.setter);
46
- set("getter", _indices.getter);
47
- set("send", function (data) {
48
- return (0, _services.post_request)(data, account.vm.stdin);
28
+
29
+ Object.keys(account.vm.flags).map((flag) => {
30
+ set(`jmp_${flag}`, (args, vm) => jmp(args, vm, { flag }));
31
+ set(`jmp_not_${flag}`, (args, vm) =>
32
+ jmp(args, vm, { flag, inverse: true })
33
+ );
49
34
  });
35
+ set("jmp", jmp);
36
+
37
+ set("setter", setter);
38
+ set("getter", getter);
39
+
40
+ set("send", (data) => post_request(data, account.vm.stdin));
50
41
  // set("socket_send", socket_send);
51
42
 
52
- set("stdout", _std.stdout);
53
- ["run", "load", "parse", "create_account"].map(function (op) {
54
- return set(op, function (arg) {
55
- return arg && arg.op0 && account[op](arg && arg.op0);
56
- });
57
- });
43
+ set("stdout", stdout);
44
+
45
+ ["run", "load", "parse", "create_account"].map((op) =>
46
+ set(op, (arg) => arg && arg.op0 && account[op](arg && arg.op0))
47
+ );
58
48
  };
59
- var _default = opcodes;
60
- exports["default"] = _default;
49
+
50
+ export default opcodes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "1.0.81",
3
+ "version": "1.0.82",
4
4
  "description": "A data mediator.",
5
5
  "main": "Index.js",
6
6
  "types": "types/index.d.ts",
package/readme.md CHANGED
@@ -20,10 +20,10 @@ You can get overall comprehension in just 4 method calls.
20
20
  Accounts comes with their own VM, thereby providing concurrency on processes being executed.
21
21
 
22
22
  ```js
23
- import manager from "godprotocol";
23
+ import start from "godprotocol";
24
24
 
25
25
  // Create an initial account
26
- let initiator = manager.add_account(`name`, { private: true || false });
26
+ let initiator = start(`name`, { private: true || false });
27
27
  // if private is set to `true`, communication to the account instance must be validated by sigining with the private key.
28
28
  // N.B your keypairs are generated offline.
29
29
  ```
@@ -70,7 +70,7 @@ The run is technically the second in the pipeline.
70
70
  initiator.run(
71
71
  {
72
72
  physical_address: "Account/initiator/Datatypes/Number", // This points to a chain
73
- query: "blocks:0", // Basically saying, index 0 block in physical_address chain, run again its instructions.
73
+ query: { blocks: 0 }, // Basically saying, index 0 block in physical_address chain, run again its instructions.
74
74
  account: `public_key`,
75
75
  },
76
76
  cb
@@ -99,7 +99,7 @@ It is used to retrieve blocks and chains, and also extract their properties.
99
99
  initiator.parse(
100
100
  {
101
101
  physical_address: "Account/initiator/Datatypes/Number", // This points to a chain
102
- query: "blocks:0", // Basically saying, index 0 block in physical_address chain, retrieve it.
102
+ query: { blocks: 0 }, // Basically saying, index 0 block in physical_address chain, retrieve it.
103
103
  account: `public_key`,
104
104
  },
105
105
  cb
@@ -1,132 +1,99 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.extension = exports["default"] = exports.PORT = void 0;
7
- var _http = _interopRequireDefault(require("http"));
8
- var _functions = require("./functions");
9
- var _Index = require("../Index");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
13
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
14
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
15
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
18
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
- var PORT = Number(process.env.PORT) || 1408;
21
- exports.PORT = PORT;
22
- var cb = function cb(res, data) {
1
+ import http from "http";
2
+ import { is_port_available } from "./functions";
3
+ import { initiator } from "../Index";
4
+
5
+ let PORT = Number(process.env.PORT) || 1408;
6
+
7
+ const cb = (res, data) => {
23
8
  if (typeof data !== "string") data = JSON.stringify(data);
9
+
24
10
  res(data);
25
11
  };
26
- var extensions = new Object();
27
- var extension = function extension(route, handler) {
28
- var handlers = extensions[route];
12
+
13
+ let extensions = new Object();
14
+
15
+ const extension = (route, handler) => {
16
+ let handlers = extensions[route];
29
17
  if (!handlers) {
30
18
  handlers = new Array();
31
19
  extensions[route] = handlers;
32
20
  }
21
+
33
22
  handlers.push(handler);
34
23
  };
35
- exports.extension = extension;
36
- var handle_routes = function handle_routes(req, res, app) {
37
- var data = "";
38
- var is_in_default_routes = ["run", "load", "parse", "create_account"].includes(req.url.slice(1));
39
- if (is_in_default_routes || !is_in_default_routes && !app) {
40
- req.on("data", function (chunk) {
24
+
25
+ const handle_routes = (req, res, app) => {
26
+ let data = "";
27
+
28
+ let is_in_default_routes = [
29
+ "run",
30
+ "load",
31
+ "parse",
32
+ "create_account",
33
+ ].includes(req.url.slice(1));
34
+
35
+ if (is_in_default_routes || (!is_in_default_routes && !app)) {
36
+ req.on("data", (chunk) => {
41
37
  data += chunk;
42
38
  });
43
- req.on("end", function () {
39
+
40
+ req.on("end", () => {
44
41
  try {
45
42
  data = JSON.parse(data);
46
43
  } catch (e) {
47
- return cb(res.end, {
48
- error_message: "Invalid data",
49
- error: true
50
- });
44
+ return cb(res.end, { error_message: "Invalid data", error: true });
51
45
  }
46
+
52
47
  if (req.url === "/create_account") {
53
- var account = _Index.initiator.create_account(data);
48
+ let account = initiator.create_account(data);
54
49
  res.end(account.stringify(true));
55
50
  } else if (["run", "load", "parse"].includes(req.url.slice(1))) {
56
- var payload = _objectSpread(_objectSpread({}, data), {}, {
57
- callback: function callback(datagram) {
58
- return cb(res.end, datagram);
59
- }
60
- });
61
- _Index.initiator.endpoint(req.url.slice(1), payload);
51
+ let payload = {
52
+ ...data,
53
+ callback: (datagram) => cb(res.end, datagram),
54
+ };
55
+ initiator.endpoint(req.url.slice(1), payload);
62
56
  } else {
63
- var _extension = extensions[req.url.slice(1)];
64
- _extension && _extension.map(function (ex) {
65
- typeof ex === "function" && ex(data, {
66
- req: req,
67
- res: res
57
+ let extension = extensions[req.url.slice(1)];
58
+
59
+ extension &&
60
+ extension.map((ex) => {
61
+ typeof ex === "function" && ex(data, { req, res });
68
62
  });
69
- });
70
63
  }
71
64
  });
72
- req.on("error", function (e) {
73
- res.writeHead(500, {
74
- "Content-Type": "application/json"
75
- });
76
- res.end(JSON.stringify({
77
- status: "error",
78
- message: e.message
79
- }));
65
+
66
+ req.on("error", (e) => {
67
+ res.writeHead(500, { "Content-Type": "application/json" });
68
+ res.end(JSON.stringify({ status: "error", message: e.message }));
80
69
  });
81
70
  } else {
82
71
  app && app(req, res);
83
72
  }
84
73
  };
85
- var create_server = /*#__PURE__*/function () {
86
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(app, settings) {
87
- var port, port_search, av, server;
88
- return _regeneratorRuntime().wrap(function _callee$(_context) {
89
- while (1) switch (_context.prev = _context.next) {
90
- case 0:
91
- settings = settings || {};
92
- port = settings.port || PORT, port_search = settings.port_search;
93
- if (!port_search) {
94
- _context.next = 13;
95
- break;
96
- }
97
- _context.next = 5;
98
- return (0, _functions.is_port_available)(port);
99
- case 5:
100
- av = _context.sent;
101
- case 6:
102
- if (av) {
103
- _context.next = 13;
104
- break;
105
- }
106
- port++;
107
- _context.next = 10;
108
- return (0, _functions.is_port_available)(port);
109
- case 10:
110
- av = _context.sent;
111
- _context.next = 6;
112
- break;
113
- case 13:
114
- exports.PORT = PORT = port;
115
- server = _http["default"].createServer(function (req, res) {
116
- return handle_routes(req, res, app);
117
- });
118
- server.listen(port, function () {
119
- console.log("\n...GOD PROTOCOL RUNNING :".concat(port));
120
- });
121
- case 16:
122
- case "end":
123
- return _context.stop();
124
- }
125
- }, _callee);
126
- }));
127
- return function create_server(_x, _x2) {
128
- return _ref.apply(this, arguments);
129
- };
130
- }();
131
- var _default = create_server;
132
- exports["default"] = _default;
74
+
75
+ const create_server = async (app, settings) => {
76
+ settings = settings || {};
77
+
78
+ let port = settings.port || PORT,
79
+ port_search = settings.port_search;
80
+
81
+ if (port_search) {
82
+ let av = await is_port_available(port);
83
+
84
+ while (!av) {
85
+ port++;
86
+ av = await is_port_available(port);
87
+ }
88
+ }
89
+ PORT = port;
90
+
91
+ let server = http.createServer((req, res) => handle_routes(req, res, app));
92
+
93
+ server.listen(port, () => {
94
+ console.log(`\n...GOD PROTOCOL RUNNING :${port}`);
95
+ });
96
+ };
97
+
98
+ export default create_server;
99
+ export { PORT, extension };
@@ -1,62 +1,45 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.array_to_nested_objects = void 0;
7
- exports.is_port_available = is_port_available;
8
- exports.transpile_object = void 0;
9
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
11
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- function _toArray(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest(); }
14
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
16
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
17
- function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
18
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
19
- var array_to_nested_objects = function array_to_nested_objects(arr) {
1
+ const array_to_nested_objects = (arr) => {
20
2
  if (arr.length === 0) return null;
21
- var _arr = _toArray(arr),
22
- first = _arr[0],
23
- rest = _arr.slice(1);
24
- return _defineProperty({}, first, array_to_nested_objects(rest));
3
+
4
+ let [first, ...rest] = arr;
5
+ return { [first]: array_to_nested_objects(rest) };
25
6
  };
26
- exports.array_to_nested_objects = array_to_nested_objects;
27
- var transpile_object = function transpile_object(object) {
28
- var code_string = "",
29
- type = _typeof(object);
7
+
8
+ const transpile_object = (object) => {
9
+ let code_string = "",
10
+ type = typeof object;
30
11
  if (type === "object") {
31
12
  if (Array.isArray(object)) {
32
13
  code_string += "arr(";
33
- object.map(function (o) {
34
- code_string += "".concat(transpile_object(o), ",");
14
+ object.map((o) => {
15
+ code_string += `${transpile_object(o)},`;
35
16
  });
36
17
  code_string = code_string.slice(0, -1);
37
18
  code_string += ")";
38
19
  } else {
39
- if (!object) code_string = "Void";else {
20
+ if (!object) code_string = "Void";
21
+ else {
40
22
  code_string = "twain(";
41
- for (var prop in object) {
42
- var val = object[prop];
43
- code_string += "".concat(transpile_object(prop), ":").concat(transpile_object(val), ",");
23
+ for (let prop in object) {
24
+ let val = object[prop];
25
+ code_string += `${transpile_object(prop)}:${transpile_object(val)},`;
44
26
  }
45
27
  code_string = code_string.slice(0, -1);
46
28
  code_string += ")";
47
29
  }
48
30
  }
49
31
  } else if (type === "string") {
50
- code_string = "\"".concat(object, "\"");
32
+ code_string = `"${object}"`;
51
33
  } else if (type === "number") {
52
- code_string = "".concat(object);
34
+ code_string = `${object}`;
53
35
  } else if (type === "boolean") {
54
- code_string = "".concat(object);
36
+ code_string = `${object}`;
55
37
  }
38
+
56
39
  return code_string;
57
40
  };
58
- exports.transpile_object = transpile_object;
59
- var net = require("net");
41
+
42
+ const net = require("net");
60
43
 
61
44
  /**
62
45
  * Check if a port is available
@@ -64,19 +47,24 @@ var net = require("net");
64
47
  * @returns {Promise<boolean>} - Resolves to true if the port is available, false otherwise
65
48
  */
66
49
  function is_port_available(port) {
67
- return new Promise(function (resolve, reject) {
68
- var server = net.createServer();
69
- server.once("error", function (err) {
50
+ return new Promise((resolve, reject) => {
51
+ const server = net.createServer();
52
+
53
+ server.once("error", (err) => {
70
54
  if (err.code === "EADDRINUSE") {
71
55
  resolve(false); // Port is in use
72
56
  } else {
73
57
  reject(err); // Some other error
74
58
  }
75
59
  });
76
- server.once("listening", function () {
60
+
61
+ server.once("listening", () => {
77
62
  server.close();
78
63
  resolve(true); // Port is available
79
64
  });
65
+
80
66
  server.listen(port);
81
67
  });
82
- }
68
+ }
69
+
70
+ export { array_to_nested_objects, transpile_object, is_port_available };
package/utils/hash.js CHANGED
@@ -1,14 +1,13 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.hash = void 0;
7
- var crypto = require("crypto");
8
- var hash = function hash(data) {
9
- var hash = crypto.createHash("sha256");
1
+ const crypto = require("crypto");
2
+
3
+ const hash = (data) => {
4
+ let hash = crypto.createHash("sha256");
5
+
10
6
  hash.update(data);
11
- var result = hash.digest("hex");
7
+
8
+ let result = hash.digest("hex");
9
+
12
10
  return result;
13
11
  };
14
- exports.hash = hash;
12
+
13
+ export { hash };
package/utils/privacy.js CHANGED
@@ -1,11 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var EC = require("elliptic").ec;
8
- var ec = new EC("secp256k1"); // You can use other curves like 'ed25519' based on your requirements
1
+ const EC = require("elliptic").ec;
2
+ const ec = new EC("secp256k1"); // You can use other curves like 'ed25519' based on your requirements
9
3
 
10
4
  /**
11
5
  * Function to validate a signature using elliptic
@@ -14,14 +8,15 @@ var ec = new EC("secp256k1"); // You can use other curves like 'ed25519' based o
14
8
  * @param {string} signature - The signature to be validated
15
9
  * @returns {boolean} - True if the signature is valid, false otherwise
16
10
  */
17
- var validate_signature = function validate_signature(public_key, message, signature) {
18
- var key = ec.keyFromPublic(public_key, "hex");
19
- var hash = ec.hash().update(message).digest("hex");
20
- var sig = {
11
+ const validate_signature = (public_key, message, signature) => {
12
+ let key = ec.keyFromPublic(public_key, "hex");
13
+ let hash = ec.hash().update(message).digest("hex");
14
+ let sig = {
21
15
  r: signature.slice(0, 64),
22
- s: signature.slice(64, 128)
16
+ s: signature.slice(64, 128),
23
17
  };
18
+
24
19
  return key.verify(hash, sig);
25
20
  };
26
- var _default = validate_signature;
27
- exports["default"] = _default;
21
+
22
+ export default validate_signature;