godprotocol 1.0.79 → 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.
- package/Index.js +8 -14
- package/Loader_sequence/main.js +384 -206
- package/Objects/Account.js +191 -157
- package/Objects/Block.js +60 -58
- package/Objects/Blockweb.js +27 -34
- package/Objects/Chain.js +115 -118
- package/Objects/Explorer.js +30 -37
- package/Objects/Filesystem.js +95 -80
- package/Objects/Frame.js +43 -48
- package/Objects/Manager.js +67 -89
- package/Objects/Opcodes.js +43 -36
- package/Objects/Oracle.js +63 -40
- package/Objects/Virtual_machine.js +135 -127
- package/build/Account.js +187 -0
- package/build/Block.js +68 -0
- package/build/Blockweb.js +36 -0
- package/build/Chain.js +119 -0
- package/build/Explorer.js +47 -0
- package/build/Filesystem.js +127 -0
- package/build/Frame.js +52 -0
- package/build/Index.js +20 -0
- package/build/Manager.js +86 -0
- package/build/Opcodes.js +109 -0
- package/build/Oracle.js +81 -0
- package/build/Virtual_machine.js +136 -0
- package/build/add.js +26 -0
- package/build/create_server.js +132 -0
- package/build/framer.js +59 -0
- package/build/functions.js +82 -0
- package/build/hash.js +14 -0
- package/build/indices.js +31 -0
- package/build/jmp.js +19 -0
- package/build/main.js +327 -0
- package/build/opcodes.js +60 -0
- package/build/privacy.js +27 -0
- package/build/services.js +50 -0
- package/build/std.js +15 -0
- package/framer.js +58 -54
- package/opcodes/add.js +9 -40
- package/opcodes/indices.js +28 -0
- package/opcodes/jmp.js +12 -17
- package/opcodes/std.js +7 -9
- package/opcodes.js +36 -28
- package/package.json +4 -3
- package/tsconfig.json +8 -0
- package/types/Account.d.ts +73 -0
- package/types/Block.d.ts +22 -0
- package/types/Blockweb.d.ts +14 -0
- package/types/Chain.d.ts +35 -0
- package/types/Explorer.d.ts +9 -0
- package/types/Filesystem.d.ts +23 -0
- package/types/Frame.d.ts +14 -0
- package/types/Manager.d.ts +21 -0
- package/types/Opcodes.d.ts +11 -0
- package/types/Oracle.d.ts +17 -0
- package/types/Virtual_machine.d.ts +20 -0
- package/types/index.d.ts +4 -0
- package/utils/create_server.js +88 -108
- package/utils/functions.js +31 -43
- package/utils/hash.js +10 -11
- package/utils/privacy.js +10 -15
- package/utils/services.js +32 -33
package/build/framer.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.obj = exports["default"] = void 0;
|
|
7
|
+
var _Frame = _interopRequireDefault(require("./Objects/Frame"));
|
|
8
|
+
var _Opcodes;
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
13
|
+
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); }
|
|
14
|
+
var obj = {
|
|
15
|
+
Opcodes: (_Opcodes = {
|
|
16
|
+
add: null,
|
|
17
|
+
equal: null,
|
|
18
|
+
multiply: null,
|
|
19
|
+
subtract: null,
|
|
20
|
+
divide: null,
|
|
21
|
+
exp: null
|
|
22
|
+
}, _defineProperty(_Opcodes, "equal", null), _defineProperty(_Opcodes, "send", null), _defineProperty(_Opcodes, "readonly", null), _defineProperty(_Opcodes, "socket_send", null), _defineProperty(_Opcodes, "jmp", null), _defineProperty(_Opcodes, "stdout", null), _defineProperty(_Opcodes, "stdin", null), _defineProperty(_Opcodes, "run", null), _defineProperty(_Opcodes, "load", null), _defineProperty(_Opcodes, "parse", null), _defineProperty(_Opcodes, "create_account", null), _Opcodes),
|
|
23
|
+
Datatypes: {
|
|
24
|
+
Number: null,
|
|
25
|
+
String: null,
|
|
26
|
+
Twain: null,
|
|
27
|
+
Array: null
|
|
28
|
+
},
|
|
29
|
+
Objects: {
|
|
30
|
+
Blockchain: {
|
|
31
|
+
Chain: null,
|
|
32
|
+
Block: null
|
|
33
|
+
},
|
|
34
|
+
Folder: {
|
|
35
|
+
active_file: null,
|
|
36
|
+
folder: null,
|
|
37
|
+
file: null
|
|
38
|
+
},
|
|
39
|
+
File: {
|
|
40
|
+
row: null,
|
|
41
|
+
parse: null,
|
|
42
|
+
column: null,
|
|
43
|
+
write: null
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.obj = obj;
|
|
48
|
+
var framer = function framer(initiator) {
|
|
49
|
+
var frame = new _Frame["default"](obj);
|
|
50
|
+
frame.to_instruction();
|
|
51
|
+
var instructions = frame.flatten_instructions();
|
|
52
|
+
initiator.load({
|
|
53
|
+
program: {
|
|
54
|
+
instructions: instructions
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
var _default = framer;
|
|
59
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,82 @@
|
|
|
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) {
|
|
20
|
+
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));
|
|
25
|
+
};
|
|
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);
|
|
30
|
+
if (type === "object") {
|
|
31
|
+
if (Array.isArray(object)) {
|
|
32
|
+
code_string += "arr(";
|
|
33
|
+
object.map(function (o) {
|
|
34
|
+
code_string += "".concat(transpile_object(o), ",");
|
|
35
|
+
});
|
|
36
|
+
code_string = code_string.slice(0, -1);
|
|
37
|
+
code_string += ")";
|
|
38
|
+
} else {
|
|
39
|
+
if (!object) code_string = "Void";else {
|
|
40
|
+
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), ",");
|
|
44
|
+
}
|
|
45
|
+
code_string = code_string.slice(0, -1);
|
|
46
|
+
code_string += ")";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} else if (type === "string") {
|
|
50
|
+
code_string = "\"".concat(object, "\"");
|
|
51
|
+
} else if (type === "number") {
|
|
52
|
+
code_string = "".concat(object);
|
|
53
|
+
} else if (type === "boolean") {
|
|
54
|
+
code_string = "".concat(object);
|
|
55
|
+
}
|
|
56
|
+
return code_string;
|
|
57
|
+
};
|
|
58
|
+
exports.transpile_object = transpile_object;
|
|
59
|
+
var net = require("net");
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Check if a port is available
|
|
63
|
+
* @param {number} port - The port to check
|
|
64
|
+
* @returns {Promise<boolean>} - Resolves to true if the port is available, false otherwise
|
|
65
|
+
*/
|
|
66
|
+
function is_port_available(port) {
|
|
67
|
+
return new Promise(function (resolve, reject) {
|
|
68
|
+
var server = net.createServer();
|
|
69
|
+
server.once("error", function (err) {
|
|
70
|
+
if (err.code === "EADDRINUSE") {
|
|
71
|
+
resolve(false); // Port is in use
|
|
72
|
+
} else {
|
|
73
|
+
reject(err); // Some other error
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
server.once("listening", function () {
|
|
77
|
+
server.close();
|
|
78
|
+
resolve(true); // Port is available
|
|
79
|
+
});
|
|
80
|
+
server.listen(port);
|
|
81
|
+
});
|
|
82
|
+
}
|
package/build/hash.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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");
|
|
10
|
+
hash.update(data);
|
|
11
|
+
var result = hash.digest("hex");
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
exports.hash = hash;
|
package/build/indices.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.setter = exports.getter = void 0;
|
|
7
|
+
var getter = function getter(args) {
|
|
8
|
+
var base = args.op0;
|
|
9
|
+
if (typeof base === "number") return base;
|
|
10
|
+
if (typeof base === "string") return base[args.op1];
|
|
11
|
+
if (Array.isArray(base)) return base.slice(args.op1)[0];
|
|
12
|
+
return base[args.op1];
|
|
13
|
+
};
|
|
14
|
+
exports.getter = getter;
|
|
15
|
+
var setter = function setter(args) {
|
|
16
|
+
var base = args.op0;
|
|
17
|
+
if (typeof base === "number") return base;
|
|
18
|
+
if (typeof base === "string") {
|
|
19
|
+
base = ""
|
|
20
|
+
.concat(base.slice(0, args.op2))
|
|
21
|
+
.concat(args.op1)
|
|
22
|
+
.concat(base.slice(args.op2 + 1));
|
|
23
|
+
} else {
|
|
24
|
+
if (Array.isArray(base)) {
|
|
25
|
+
if (args.op2 == null || args.op2 >= base.length) base.push(args.op1);
|
|
26
|
+
else base[args.op2] = args.op1;
|
|
27
|
+
} else base[args.op2] = args.op1;
|
|
28
|
+
}
|
|
29
|
+
return base;
|
|
30
|
+
};
|
|
31
|
+
exports.setter = setter;
|
package/build/jmp.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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) {
|
|
8
|
+
meta = meta || {};
|
|
9
|
+
var _meta = meta,
|
|
10
|
+
flag = _meta.flag,
|
|
11
|
+
inverse = _meta.inverse;
|
|
12
|
+
var condition;
|
|
13
|
+
if (flag) condition = vm.flags[flag];
|
|
14
|
+
if (inverse) condition = !!!condition;
|
|
15
|
+
if ((condition || !flag) && typeof args.op0 === "number") {
|
|
16
|
+
vm.track.pointer = args.op0;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.jmp = jmp;
|
package/build/main.js
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
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); }
|
|
8
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
9
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
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; } }
|
|
11
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
12
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
13
|
+
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; }
|
|
14
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
15
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
16
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
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 num_pattern = /^[+-]?\d+(\.\d+)?$/;
|
|
21
|
+
// let str_pattern = /^["'][^"']*["']$/;
|
|
22
|
+
var var_pattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
23
|
+
var Loader = /*#__PURE__*/_createClass(function Loader(account) {
|
|
24
|
+
var _this = this;
|
|
25
|
+
_classCallCheck(this, Loader);
|
|
26
|
+
_defineProperty(this, "instruction_index", function () {
|
|
27
|
+
var index = _this.instruction_indexes.slice(-1);
|
|
28
|
+
index++;
|
|
29
|
+
_this.instruction_indexes.splice(-1, 1, index);
|
|
30
|
+
return index;
|
|
31
|
+
});
|
|
32
|
+
_defineProperty(this, "stack_instruction", function (instruction) {
|
|
33
|
+
if (Array.isArray(instruction)) return instruction.map(function (i) {
|
|
34
|
+
return _this.stack_instruction(i);
|
|
35
|
+
});
|
|
36
|
+
_this.instruction_stacks.slice(-1)[0].push(instruction);
|
|
37
|
+
});
|
|
38
|
+
_defineProperty(this, "new_stack", function (addr) {
|
|
39
|
+
_this.stacks.push(addr);
|
|
40
|
+
});
|
|
41
|
+
_defineProperty(this, "push_instruction", function (instruction) {
|
|
42
|
+
if (Array.isArray(instruction)) return instruction.map(function (i) {
|
|
43
|
+
return _this.push_instruction(i);
|
|
44
|
+
});
|
|
45
|
+
if (_this.pure) {
|
|
46
|
+
_this.instructions.push(instruction);
|
|
47
|
+
} else {
|
|
48
|
+
_this.stack_instruction("cursor ".concat(_this.instruction_index()));
|
|
49
|
+
_this.stack_instruction("write ".concat(instruction));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
_defineProperty(this, "parse_tokens", function (line, stop_char) {
|
|
53
|
+
var tokens = new Array();
|
|
54
|
+
var pos = 0,
|
|
55
|
+
line_number = 0;
|
|
56
|
+
var push_token = function push_token(value, type) {
|
|
57
|
+
return tokens.push({
|
|
58
|
+
value: value,
|
|
59
|
+
type: type,
|
|
60
|
+
line: line_number,
|
|
61
|
+
pos: pos
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
line = line.trim();
|
|
65
|
+
while (pos < line.length) {
|
|
66
|
+
var _char = line[pos].trim();
|
|
67
|
+
if (_char === stop_char) return {
|
|
68
|
+
tokens: tokens,
|
|
69
|
+
pos: pos
|
|
70
|
+
};
|
|
71
|
+
if (!_char) {
|
|
72
|
+
pos++;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (_char === "\n") {
|
|
76
|
+
line_number++;
|
|
77
|
+
pos++;
|
|
78
|
+
} else if (_char === "@") {
|
|
79
|
+
var acc = "";
|
|
80
|
+
while (line[pos] && line[pos].trim()) {
|
|
81
|
+
acc += line[pos];
|
|
82
|
+
pos++;
|
|
83
|
+
}
|
|
84
|
+
push_token(acc, "address");
|
|
85
|
+
} else if (_char === ",") {
|
|
86
|
+
pos++;
|
|
87
|
+
} else if (_char === ":") {
|
|
88
|
+
push_token(_char, "separator");
|
|
89
|
+
pos++;
|
|
90
|
+
} else if (_char === "[") {
|
|
91
|
+
pos++;
|
|
92
|
+
var toks = _this.parse_tokens(line.slice(pos), "]");
|
|
93
|
+
push_token(toks.tokens, "array");
|
|
94
|
+
pos += toks.pos + 1;
|
|
95
|
+
} else if (_char === "{") {
|
|
96
|
+
pos++;
|
|
97
|
+
var _toks = _this.parse_tokens(line.slice(pos), "}");
|
|
98
|
+
push_token(_toks.tokens, "twain");
|
|
99
|
+
pos += _toks.pos + 1;
|
|
100
|
+
} else if (_char === ">") {
|
|
101
|
+
pos++;
|
|
102
|
+
} else if (_char === "'" || _char === '"') {
|
|
103
|
+
var _acc = "";
|
|
104
|
+
pos++;
|
|
105
|
+
while (line[pos] !== _char) {
|
|
106
|
+
if (!line[pos]) break;
|
|
107
|
+
_acc += line[pos];
|
|
108
|
+
pos++;
|
|
109
|
+
}
|
|
110
|
+
pos++;
|
|
111
|
+
push_token(_acc, "string");
|
|
112
|
+
} else if (num_pattern.test(_char)) {
|
|
113
|
+
var _acc2 = _char;
|
|
114
|
+
pos++;
|
|
115
|
+
while (num_pattern.test(line[pos]) || line[pos] === "." && !_acc2.includes(line[pos])) {
|
|
116
|
+
if (!line[pos]) break;
|
|
117
|
+
_acc2 += line[pos];
|
|
118
|
+
pos++;
|
|
119
|
+
}
|
|
120
|
+
push_token(_acc2, "number");
|
|
121
|
+
} else if (var_pattern.test(_char)) {
|
|
122
|
+
var _acc3 = _char;
|
|
123
|
+
pos++;
|
|
124
|
+
while (line[pos] && var_pattern.test("".concat(line[pos].trim()))) {
|
|
125
|
+
_acc3 += line[pos];
|
|
126
|
+
pos++;
|
|
127
|
+
}
|
|
128
|
+
push_token(_acc3, _this.opcodes.includes(_acc3) ? "opcode" : "variable");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return tokens;
|
|
132
|
+
});
|
|
133
|
+
_defineProperty(this, "parse", function (token) {
|
|
134
|
+
if (token.type === "string" || token.type === "number") {
|
|
135
|
+
_this.push_instruction(["link ".concat(_this.account.physical_address, "/Datatypes/", "".concat(token.type[0].toUpperCase()).concat(token.type.slice(1))), "write ".concat(token.value), "pop ".concat(token.type)]);
|
|
136
|
+
} else if (token.type === "array") {
|
|
137
|
+
_this.push_instruction("link Accounts/".concat(_this.account.name, "/Datatypes/Array"));
|
|
138
|
+
token.value.map(function (item, i) {
|
|
139
|
+
_this.parse(item);
|
|
140
|
+
_this.push_instruction(["cursor ".concat(i), "write ".concat(_this.is_not_literal(item.type) ? "{metadata.output:-1}" : "{datapath:-1}")]);
|
|
141
|
+
});
|
|
142
|
+
_this.push_instruction("pop Array");
|
|
143
|
+
} else if (token.type === "twain") {
|
|
144
|
+
_this.push_instruction("link Accounts/".concat(_this.account.name, "/Datatypes/Twain"));
|
|
145
|
+
var curs = true;
|
|
146
|
+
if (token.value) token.value.map(function (entry) {
|
|
147
|
+
if (entry.type === "separator") {
|
|
148
|
+
curs = false;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
_this.parse(entry);
|
|
152
|
+
if (curs) {
|
|
153
|
+
{
|
|
154
|
+
_this.push_instruction("cursor {*".concat(_this.is_not_literal(entry.type) ? "metadata.output:-1" : "datapath:-1", "}"));
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
_this.push_instruction("write ".concat(_this.is_not_literal(entry.type) ? "{metadata.output:-1}" : "{datapath:-1}"));
|
|
158
|
+
curs = true;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
_this.push_instruction("pop Twain");
|
|
162
|
+
} else if (token.type === "variable") {
|
|
163
|
+
_this.push_instruction(["link ".concat("".concat(_this.stacks.slice(-1)[0], "/").concat(token.value)), "pop ".concat(token.value)]);
|
|
164
|
+
} else if (token.type === "address") _this.parse_assignment(token);
|
|
165
|
+
});
|
|
166
|
+
_defineProperty(this, "is_not_literal", function (type) {
|
|
167
|
+
return !type || ["variable", "opcode", "address"].includes(type);
|
|
168
|
+
});
|
|
169
|
+
_defineProperty(this, "parse_assignment", function (line, linked) {
|
|
170
|
+
var tokens = linked || line.type ? line : _this.parse_tokens(line);
|
|
171
|
+
var identifier = tokens[0];
|
|
172
|
+
if (linked || line.type) {
|
|
173
|
+
var line_split = (line.value || line).slice(line.value ? null : 1).trim().split(" ");
|
|
174
|
+
var path = line_split[0].split("/");
|
|
175
|
+
_this.push_instruction("link ".concat(_this.resolve_addr(path.join("/"))));
|
|
176
|
+
tokens = !line.type && _this.parse_tokens(line_split.slice(1).join(" "));
|
|
177
|
+
tokens.unshift && tokens.unshift(null);
|
|
178
|
+
if (line.type === "address") return _this.push_instruction("pop ".concat(path[path.length - 1]));
|
|
179
|
+
} else {
|
|
180
|
+
_this.push_instruction("chain ".concat(identifier.value));
|
|
181
|
+
_this.stack_instruction(["link ".concat(_this.stacks.slice(-1)[0]), "chain ".concat(identifier.value), "pop ".concat(identifier.value), "pop"]);
|
|
182
|
+
}
|
|
183
|
+
var prev_token;
|
|
184
|
+
if (tokens[1] && tokens[1].type === "opcode") {
|
|
185
|
+
_this.parse_opcode(tokens.slice(1));
|
|
186
|
+
prev_token = tokens[1];
|
|
187
|
+
} else {
|
|
188
|
+
tokens.slice(1).map(function (tok) {
|
|
189
|
+
_this.parse(tok);
|
|
190
|
+
});
|
|
191
|
+
prev_token = tokens.slice(-1)[0];
|
|
192
|
+
}
|
|
193
|
+
if (tokens.length > 1) {
|
|
194
|
+
_this.push_instruction(["cursor {output}", "write ".concat(_this.is_not_literal(prev_token && prev_token.type) ? "{metadata.output:-1}" : "{datapath:-1}"), "pop ".concat(identifier.value)]);
|
|
195
|
+
} else _this.push_instruction("pop ".concat(identifier.value));
|
|
196
|
+
});
|
|
197
|
+
_defineProperty(this, "marker_pattern", /@[a-zA-Z_][a-zA-Z0-9_]*/);
|
|
198
|
+
_defineProperty(this, "parse_opcode", function (line) {
|
|
199
|
+
var tokens = Array.isArray(line) ? line : _this.parse_tokens(line);
|
|
200
|
+
var op = tokens[0];
|
|
201
|
+
if (op.type !== "opcode") return _this.parse(op);
|
|
202
|
+
_this.push_instruction(["link Accounts/".concat(_this.account.name, "/Opcodes/").concat(op.value), "link Accounts/".concat(_this.account.name, "/Datatypes/Twain")]);
|
|
203
|
+
tokens.slice(1).map(function (tok, i) {
|
|
204
|
+
if (tok.type === "address" && tok.value.match(_this.marker_pattern)) {
|
|
205
|
+
_this.push_instruction(["link ".concat(_this.account.physical_address, "/Datatypes/Number"), "write ".concat(tok.value), "pop Number"]);
|
|
206
|
+
} else _this.parse(tok);
|
|
207
|
+
_this.push_instruction(["cursor op".concat(i), "write ".concat(_this.is_not_literal(tok.type) && !(tok.type === "address" && tok.value.match(_this.marker_pattern)) ? "{metadata.output:-1}" : "{datapath:-1}")]);
|
|
208
|
+
});
|
|
209
|
+
_this.push_instruction(["pop Twain", "cursor inputs", "write {datapath:-1}", op.value, "cursor {output}", "write {datapath:-1}", "pop ".concat(op.value)]);
|
|
210
|
+
});
|
|
211
|
+
_defineProperty(this, "resolve_addr", function (addr) {
|
|
212
|
+
addr = addr.split("/");
|
|
213
|
+
var real_addr = "";
|
|
214
|
+
if (addr[0] === "@") {
|
|
215
|
+
addr[0] = _this.account.physical_address;
|
|
216
|
+
real_addr = addr.join("/");
|
|
217
|
+
} else if (addr[0] === ".." || addr[0] === ".") {
|
|
218
|
+
var curr_addr = _this.stacks.slice(-1)[0].split("/");
|
|
219
|
+
while (addr[0] === ".." || addr[0] === ".") {
|
|
220
|
+
if (addr[0] === "..") curr_addr.splice(-1);
|
|
221
|
+
delete addr[0];
|
|
222
|
+
}
|
|
223
|
+
real_addr = curr_addr.join("/") + "".concat(addr.join("/"));
|
|
224
|
+
}
|
|
225
|
+
return real_addr;
|
|
226
|
+
});
|
|
227
|
+
_defineProperty(this, "new_stack_instructions", function (new_stack) {
|
|
228
|
+
var curr_stack = _this.stacks.slice(-1)[0].split("/");
|
|
229
|
+
new_stack = new_stack.split("/");
|
|
230
|
+
if (curr_stack[1] !== new_stack[1]) {} else {
|
|
231
|
+
var i = 0;
|
|
232
|
+
while (curr_stack[i] === new_stack[i]) i++;
|
|
233
|
+
for (var j = 2; j < new_stack.length; j++) _this.stack_instruction("chain ".concat(new_stack[j]));
|
|
234
|
+
_this.stack_instruction("link ".concat(_this.account.physical_address, "/Datatypes/Array"));
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
_defineProperty(this, "parse_routine", function (line) {
|
|
238
|
+
var addr = _this.resolve_addr(line);
|
|
239
|
+
_this.instruction_stacks.push([]);
|
|
240
|
+
_this.new_stack_instructions(addr);
|
|
241
|
+
_this.new_stack(addr);
|
|
242
|
+
_this.instruction_indexes.push(-1);
|
|
243
|
+
});
|
|
244
|
+
_defineProperty(this, "pop", function () {
|
|
245
|
+
var _this$instructions;
|
|
246
|
+
var addr = _this.stacks.splice(-1)[0].split("/");
|
|
247
|
+
_this.stack_instruction(["pop Array", "cursor {program}", "write {datapath:-1}"]);
|
|
248
|
+
for (var j = 2; j < addr.length; j++) _this.stack_instruction("pop ".concat(addr[j]));
|
|
249
|
+
(_this$instructions = _this.instructions).push.apply(_this$instructions, _toConsumableArray(_this.instruction_stacks.splice(-1)[0]));
|
|
250
|
+
_this.instruction_indexes.pop();
|
|
251
|
+
});
|
|
252
|
+
_defineProperty(this, "revamp_marks", function () {
|
|
253
|
+
var instruction_stack = _this.instruction_stacks.slice(-1)[0];
|
|
254
|
+
instruction_stack = instruction_stack.map(function (ins) {
|
|
255
|
+
return _this.resolve_offset(ins, true);
|
|
256
|
+
});
|
|
257
|
+
_this.instruction_stacks[_this.instruction_stacks.length - 1] = instruction_stack;
|
|
258
|
+
});
|
|
259
|
+
_defineProperty(this, "handle_marker", function (line) {
|
|
260
|
+
var splits = line.slice(1).split(" ");
|
|
261
|
+
var name = splits[0];
|
|
262
|
+
var curr_stack = _this.stacks.slice(-1)[0];
|
|
263
|
+
var markers = _this.markers[curr_stack];
|
|
264
|
+
if (!markers) {
|
|
265
|
+
markers = new Object();
|
|
266
|
+
_this.markers[curr_stack] = markers;
|
|
267
|
+
}
|
|
268
|
+
markers[name] = _this.instruction_index();
|
|
269
|
+
_this.revamp_marks();
|
|
270
|
+
return splits.slice(1).join(" ");
|
|
271
|
+
});
|
|
272
|
+
_defineProperty(this, "resolve_offset", function (line, revamping) {
|
|
273
|
+
var matches = line.match(_this.marker_pattern),
|
|
274
|
+
value;
|
|
275
|
+
if (matches) {
|
|
276
|
+
var match = matches[0].slice(1);
|
|
277
|
+
var curr_stack = _this.stacks.slice(-1)[0];
|
|
278
|
+
var markers = _this.markers[curr_stack];
|
|
279
|
+
if (!markers) {
|
|
280
|
+
markers = new Object();
|
|
281
|
+
_this.markers[curr_stack] = markers;
|
|
282
|
+
}
|
|
283
|
+
value = markers[match];
|
|
284
|
+
}
|
|
285
|
+
if (typeof value === "number") line = line.replace(_this.marker_pattern, (revamping && value > 0 ? value - 1 : value).toString());
|
|
286
|
+
return line;
|
|
287
|
+
});
|
|
288
|
+
_defineProperty(this, "compile", function (codes) {
|
|
289
|
+
var code_array = codes.split("\n");
|
|
290
|
+
for (var c = 0; c < code_array.length; c++) {
|
|
291
|
+
var line = code_array[c].trim();
|
|
292
|
+
if (!line) continue;
|
|
293
|
+
if (line.startsWith(":")) {
|
|
294
|
+
line = _this.handle_marker(line);
|
|
295
|
+
if (!line) continue;
|
|
296
|
+
}
|
|
297
|
+
line = _this.resolve_offset(line);
|
|
298
|
+
if (line === ";") _this.pop();else if (line.startsWith(".") || line.startsWith("@")) _this.parse_routine(line);else if (line.startsWith("//")) continue;else if (line.startsWith(">@")) _this.parse_assignment(line, true);else if (line.startsWith(">")) _this.parse_assignment(line);else _this.parse_opcode(line);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
_defineProperty(this, "run", function (codes, meta) {
|
|
302
|
+
if (!meta) meta = {};
|
|
303
|
+
_this.pure = meta && meta.pure;
|
|
304
|
+
var cb = meta && meta.cb;
|
|
305
|
+
_this.compile(codes);
|
|
306
|
+
|
|
307
|
+
// console.log(JSON.stringify(this.instructions, null, 2), "hiya");
|
|
308
|
+
|
|
309
|
+
_this.account.load({
|
|
310
|
+
program: {
|
|
311
|
+
instructions: _toConsumableArray(_this.instructions)
|
|
312
|
+
},
|
|
313
|
+
callback: cb
|
|
314
|
+
});
|
|
315
|
+
_this.instructions = [];
|
|
316
|
+
_this.pure = false;
|
|
317
|
+
});
|
|
318
|
+
this.account = account;
|
|
319
|
+
this.opcodes = new Array();
|
|
320
|
+
this.instructions = new Array();
|
|
321
|
+
this.instruction_indexes = new Array();
|
|
322
|
+
this.instruction_stacks = [[]];
|
|
323
|
+
this.stacks = new Array(account.physical_address);
|
|
324
|
+
this.markers = new Array();
|
|
325
|
+
});
|
|
326
|
+
var _default = Loader;
|
|
327
|
+
exports["default"] = _default;
|
package/build/opcodes.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
// import { socket_send } from "./Socket";
|
|
13
|
+
|
|
14
|
+
var opcodes = function opcodes(account) {
|
|
15
|
+
var set = account.vm.set;
|
|
16
|
+
_add.ops.map(function (op) {
|
|
17
|
+
set(op.name, function (args) {
|
|
18
|
+
if (!args) return;
|
|
19
|
+
try {
|
|
20
|
+
var result = eval("".concat(args.op0, " ").concat(op.sign, " ").concat(args.op1));
|
|
21
|
+
if (op.sign === "==") {
|
|
22
|
+
account.vm.flags.equal = !!result;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.log(e.message);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
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);
|
|
49
|
+
});
|
|
50
|
+
// set("socket_send", socket_send);
|
|
51
|
+
|
|
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
|
+
});
|
|
58
|
+
};
|
|
59
|
+
var _default = opcodes;
|
|
60
|
+
exports["default"] = _default;
|
package/build/privacy.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Function to validate a signature using elliptic
|
|
12
|
+
* @param {string} public_key - The public key of the user
|
|
13
|
+
* @param {string} message - The original message that was signed
|
|
14
|
+
* @param {string} signature - The signature to be validated
|
|
15
|
+
* @returns {boolean} - True if the signature is valid, false otherwise
|
|
16
|
+
*/
|
|
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 = {
|
|
21
|
+
r: signature.slice(0, 64),
|
|
22
|
+
s: signature.slice(64, 128)
|
|
23
|
+
};
|
|
24
|
+
return key.verify(hash, sig);
|
|
25
|
+
};
|
|
26
|
+
var _default = validate_signature;
|
|
27
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.post_request = void 0;
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
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
|
+
var http = require("http");
|
|
14
|
+
var post_request = function post_request(payload, cb) {
|
|
15
|
+
// let options = {
|
|
16
|
+
// hostname: 'example.com',
|
|
17
|
+
// port: 80,
|
|
18
|
+
// path: '/api/users',
|
|
19
|
+
// method: 'POST',
|
|
20
|
+
// headers: {
|
|
21
|
+
// 'Content-Type': 'application/json',
|
|
22
|
+
// 'Content-Length': Buffer.byteLength(postData),
|
|
23
|
+
// },
|
|
24
|
+
// };
|
|
25
|
+
|
|
26
|
+
var req = http.request(_objectSpread(_objectSpread({}, payload.options), {}, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
"Content-Length": Buffer.byteLength(payload.data)
|
|
31
|
+
}
|
|
32
|
+
}), function (res) {
|
|
33
|
+
var data = "";
|
|
34
|
+
res.on("data", function (chunk) {
|
|
35
|
+
data += chunk;
|
|
36
|
+
cb && cb(chunk);
|
|
37
|
+
});
|
|
38
|
+
res.on("end", function () {
|
|
39
|
+
cb && cb(data);
|
|
40
|
+
// console.log("Response:", data);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
req.on("error", function (e) {
|
|
44
|
+
cb(e.message);
|
|
45
|
+
console.error("Problem with request: ".concat(e.message));
|
|
46
|
+
});
|
|
47
|
+
req.write(payload.data);
|
|
48
|
+
req.end();
|
|
49
|
+
};
|
|
50
|
+
exports.post_request = post_request;
|