godprotocol 1.0.799 → 1.0.831
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/Loader_sequence/main.js +77 -5
- package/Objects/Account.js +62 -5
- package/Objects/Block.js +12 -1
- package/Objects/Chain.js +7 -0
- package/Objects/Filesystem.js +4 -4
- package/Objects/Manager.js +15 -28
- package/Objects/Opcodes.js +13 -4
- package/Objects/Oracle.js +61 -4
- package/Objects/Virtual_machine.js +12 -2
- package/framer.js +45 -49
- package/opcodes/add.js +0 -5
- package/opcodes/indices.js +28 -0
- package/opcodes/jmp.js +10 -11
- package/opcodes/std.js +3 -1
- package/opcodes.js +18 -4
- package/package.json +3 -2
- package/types/Oracle.d.ts +2 -2
- package/types/index.d.ts +1 -1
- package/.babelrc +0 -3
- package/build/Account.js +0 -162
- package/build/Block.js +0 -65
- package/build/Blockweb.js +0 -36
- package/build/Chain.js +0 -119
- package/build/Explorer.js +0 -47
- package/build/Filesystem.js +0 -127
- package/build/Frame.js +0 -52
- package/build/Index.js +0 -15
- package/build/Manager.js +0 -99
- package/build/Opcodes.js +0 -39
- package/build/Oracle.js +0 -42
- package/build/Virtual_machine.js +0 -128
- package/build/add.js +0 -41
- package/build/create_server.js +0 -119
- package/build/framer.js +0 -57
- package/build/functions.js +0 -82
- package/build/hash.js +0 -14
- package/build/jmp.js +0 -19
- package/build/main.js +0 -283
- package/build/opcodes.js +0 -42
- package/build/privacy.js +0 -27
- package/build/services.js +0 -50
- package/build/std.js +0 -11
package/build/main.js
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
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, "parse_opcode", function (line) {
|
|
198
|
-
var tokens = Array.isArray(line) ? line : _this.parse_tokens(line);
|
|
199
|
-
var op = tokens[0];
|
|
200
|
-
if (op.type !== "opcode") return _this.parse(op);
|
|
201
|
-
_this.push_instruction(["link Accounts/".concat(_this.account.name, "/Opcodes/").concat(op.value), "link Accounts/".concat(_this.account.name, "/Datatypes/Twain")]);
|
|
202
|
-
tokens.slice(1).map(function (tok, i) {
|
|
203
|
-
_this.parse(tok);
|
|
204
|
-
_this.push_instruction(["cursor op".concat(i), "write ".concat(_this.is_not_literal(tok.type) ? "{metadata.output:-1}" : "{datapath:-1}")]);
|
|
205
|
-
});
|
|
206
|
-
_this.push_instruction(["pop Twain", "cursor inputs", "write {datapath:-1}", op.value, "cursor {output}", "write {datapath:-1}", "pop ".concat(op.value)]);
|
|
207
|
-
});
|
|
208
|
-
_defineProperty(this, "resolve_addr", function (addr) {
|
|
209
|
-
addr = addr.split("/");
|
|
210
|
-
var real_addr = "";
|
|
211
|
-
if (addr[0] === "@") {
|
|
212
|
-
addr[0] = _this.account.physical_address;
|
|
213
|
-
real_addr = addr.join("/");
|
|
214
|
-
} else if (addr[0] === ".." || addr[0] === ".") {
|
|
215
|
-
var curr_addr = _this.stacks.slice(-1)[0].split("/");
|
|
216
|
-
while (addr[0] === ".." || addr[0] === ".") {
|
|
217
|
-
if (addr[0] === "..") curr_addr.splice(-1);
|
|
218
|
-
delete addr[0];
|
|
219
|
-
}
|
|
220
|
-
real_addr = curr_addr.join("/") + "".concat(addr.join("/"));
|
|
221
|
-
}
|
|
222
|
-
return real_addr;
|
|
223
|
-
});
|
|
224
|
-
_defineProperty(this, "new_stack_instructions", function (new_stack) {
|
|
225
|
-
var curr_stack = _this.stacks.slice(-1)[0].split("/");
|
|
226
|
-
new_stack = new_stack.split("/");
|
|
227
|
-
if (curr_stack[1] !== new_stack[1]) {} else {
|
|
228
|
-
var i = 0;
|
|
229
|
-
while (curr_stack[i] === new_stack[i]) i++;
|
|
230
|
-
for (var j = 2; j < new_stack.length; j++) _this.stack_instruction("chain ".concat(new_stack[j]));
|
|
231
|
-
_this.stack_instruction("link ".concat(_this.account.physical_address, "/Datatypes/Array"));
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
_defineProperty(this, "parse_routine", function (line) {
|
|
235
|
-
var addr = _this.resolve_addr(line);
|
|
236
|
-
_this.instruction_stacks.push([]);
|
|
237
|
-
_this.new_stack_instructions(addr);
|
|
238
|
-
_this.new_stack(addr);
|
|
239
|
-
_this.instruction_indexes.push(-1);
|
|
240
|
-
});
|
|
241
|
-
_defineProperty(this, "pop", function () {
|
|
242
|
-
var _this$instructions;
|
|
243
|
-
var addr = _this.stacks.splice(-1)[0].split("/");
|
|
244
|
-
_this.stack_instruction(["pop Array", "cursor {program}", "write {datapath:-1}"]);
|
|
245
|
-
for (var j = 2; j < addr.length; j++) _this.stack_instruction("pop ".concat(addr[j]));
|
|
246
|
-
(_this$instructions = _this.instructions).push.apply(_this$instructions, _toConsumableArray(_this.instruction_stacks.splice(-1)[0]));
|
|
247
|
-
_this.instruction_indexes.pop();
|
|
248
|
-
});
|
|
249
|
-
_defineProperty(this, "compile", function (codes) {
|
|
250
|
-
var code_array = codes.split("\n");
|
|
251
|
-
for (var c = 0; c < code_array.length; c++) {
|
|
252
|
-
var line = code_array[c].trim();
|
|
253
|
-
if (!line) continue;
|
|
254
|
-
if (line === ";") _this.pop();else if (line.startsWith("link ")) _this.parse_routine(line);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);
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
_defineProperty(this, "run", function (codes, cb) {
|
|
258
|
-
if (typeof cb === "boolean") {
|
|
259
|
-
_this.pure = cb;
|
|
260
|
-
cb = null;
|
|
261
|
-
}
|
|
262
|
-
_this.compile(codes);
|
|
263
|
-
|
|
264
|
-
// console.log(JSON.stringify(this.instructions, null, 2), "hiya");
|
|
265
|
-
|
|
266
|
-
_this.account.load({
|
|
267
|
-
program: {
|
|
268
|
-
instructions: _toConsumableArray(_this.instructions)
|
|
269
|
-
},
|
|
270
|
-
callback: cb
|
|
271
|
-
});
|
|
272
|
-
_this.instructions = [];
|
|
273
|
-
_this.pure = false;
|
|
274
|
-
});
|
|
275
|
-
this.account = account;
|
|
276
|
-
this.opcodes = new Array();
|
|
277
|
-
this.instructions = new Array();
|
|
278
|
-
this.instruction_indexes = new Array();
|
|
279
|
-
this.instruction_stacks = [[]];
|
|
280
|
-
this.stacks = new Array(account.physical_address);
|
|
281
|
-
});
|
|
282
|
-
var _default = Loader;
|
|
283
|
-
exports["default"] = _default;
|
package/build/opcodes.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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 _jmp = require("./opcodes/jmp");
|
|
9
|
-
var _std = require("./opcodes/std");
|
|
10
|
-
var _services = require("./utils/services");
|
|
11
|
-
// import { socket_send } from "./Socket";
|
|
12
|
-
|
|
13
|
-
var opcodes = function opcodes(account) {
|
|
14
|
-
var set = account.vm.set;
|
|
15
|
-
_add.ops.map(function (op) {
|
|
16
|
-
set(op.name, function (args) {
|
|
17
|
-
if (!args) return;
|
|
18
|
-
try {
|
|
19
|
-
var result = eval("".concat(args.op0, " ").concat(op.sign, " ").concat(args.op1));
|
|
20
|
-
return result;
|
|
21
|
-
} catch (e) {
|
|
22
|
-
console.log(e.message);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
set("hold", _jmp.hold);
|
|
27
|
-
set("jmp", _jmp.jmp);
|
|
28
|
-
set("jmp_if", _jmp.jmp_if);
|
|
29
|
-
set("send", function (data) {
|
|
30
|
-
return (0, _services.post_request)(data, account.vm.stdin);
|
|
31
|
-
});
|
|
32
|
-
// set("socket_send", socket_send);
|
|
33
|
-
|
|
34
|
-
set("stdout", _std.stdout);
|
|
35
|
-
["run", "load", "parse", "create_account"].map(function (op) {
|
|
36
|
-
return set(op, function (arg) {
|
|
37
|
-
return arg && arg.op0 && account[op](arg && arg.op0);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
var _default = opcodes;
|
|
42
|
-
exports["default"] = _default;
|
package/build/privacy.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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;
|
package/build/services.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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;
|
package/build/std.js
DELETED