wao 0.4.0 → 0.4.2

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/cjs/ar.js CHANGED
@@ -8,6 +8,7 @@ var _arweave2 = _interopRequireDefault(require("arweave"));
8
8
  var _arbundles = require("arbundles");
9
9
  var _utils = require("./utils.js");
10
10
  var _ramda = require("ramda");
11
+ var _gql = _interopRequireDefault(require("./gql.js"));
11
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
13
  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; }
13
14
  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; }
@@ -38,13 +39,16 @@ var AR = /*#__PURE__*/function () {
38
39
  port: port,
39
40
  protocol: protocol
40
41
  };
41
- if (!_arweave.host) _arweave.host = port === 443 ? "arweave.net" : "127.0.0.1";
42
+ if (!_arweave.host) _arweave.host = port === 443 ? "arweave.net" : "localhost";
42
43
  if (!_arweave.protocol) _arweave.protocol = (0, _utils.isLocalhost)(_arweave.host) ? "http" : "https";
43
44
  if (!_arweave.port) _arweave.port = (0, _utils.isLocalhost)(_arweave.host) ? 1984 : 443;
44
45
  this.port = _arweave.port;
45
46
  this.host = _arweave.host;
46
47
  this.protocol = _arweave.protocol;
47
48
  this.arweave = _arweave2["default"].init(_arweave);
49
+ this.gql = new _gql["default"]({
50
+ url: "".concat(_arweave.protocol, "://").concat(_arweave.host, ":").concat(_arweave.port, "/graphql")
51
+ });
48
52
  }
49
53
  return _createClass(AR, [{
50
54
  key: "isArConnect",
@@ -695,29 +699,35 @@ var AR = /*#__PURE__*/function () {
695
699
  key: "tx",
696
700
  value: function () {
697
701
  var _tx = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(txid) {
698
- var _json$data$transactio;
699
- var json;
702
+ var _yield$this$gql$txs$;
700
703
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
701
704
  while (1) switch (_context12.prev = _context12.next) {
702
705
  case 0:
703
706
  _context12.next = 2;
704
- return fetch("".concat(this.protocol, "://").concat(this.host, ":").concat(this.port, "/graphql"), {
705
- method: "POST",
706
- headers: {
707
- "Content-Type": "application/json"
708
- },
709
- body: JSON.stringify({
710
- query: (0, _utils.query)(txid)
711
- })
712
- }).then(function (r) {
713
- return r.json();
707
+ return this.gql.txs({
708
+ id: txid
714
709
  });
715
710
  case 2:
716
- json = _context12.sent;
717
- return _context12.abrupt("return", (_json$data$transactio = json.data.transactions.edges.map(function (v) {
718
- return v.node;
719
- })[0]) !== null && _json$data$transactio !== void 0 ? _json$data$transactio : null);
720
- case 4:
711
+ _context12.t1 = _yield$this$gql$txs$ = _context12.sent[0];
712
+ _context12.t0 = _context12.t1 !== null;
713
+ if (!_context12.t0) {
714
+ _context12.next = 6;
715
+ break;
716
+ }
717
+ _context12.t0 = _yield$this$gql$txs$ !== void 0;
718
+ case 6:
719
+ if (!_context12.t0) {
720
+ _context12.next = 10;
721
+ break;
722
+ }
723
+ _context12.t2 = _yield$this$gql$txs$;
724
+ _context12.next = 11;
725
+ break;
726
+ case 10:
727
+ _context12.t2 = null;
728
+ case 11:
729
+ return _context12.abrupt("return", _context12.t2);
730
+ case 12:
721
731
  case "end":
722
732
  return _context12.stop();
723
733
  }
@@ -728,66 +738,30 @@ var AR = /*#__PURE__*/function () {
728
738
  }
729
739
  return tx;
730
740
  }()
731
- }, {
732
- key: "txs",
733
- value: function () {
734
- var _txs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(to) {
735
- var json;
736
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
737
- while (1) switch (_context13.prev = _context13.next) {
738
- case 0:
739
- _context13.next = 2;
740
- return fetch("".concat(this.protocol, "://").concat(this.host, ":").concat(this.port, "/graphql"), {
741
- method: "POST",
742
- headers: {
743
- "Content-Type": "application/json"
744
- },
745
- body: JSON.stringify({
746
- query: (0, _utils.queries)(to)
747
- })
748
- }).then(function (r) {
749
- return r.json();
750
- });
751
- case 2:
752
- json = _context13.sent;
753
- return _context13.abrupt("return", json.data.transactions.edges.map(function (v) {
754
- return v.node;
755
- }));
756
- case 4:
757
- case "end":
758
- return _context13.stop();
759
- }
760
- }, _callee13, this);
761
- }));
762
- function txs(_x15) {
763
- return _txs.apply(this, arguments);
764
- }
765
- return txs;
766
- }()
767
741
  }, {
768
742
  key: "data",
769
743
  value: function () {
770
- var _data = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(txid) {
744
+ var _data = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(txid) {
771
745
  var string,
772
- _args14 = arguments;
773
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
774
- while (1) switch (_context14.prev = _context14.next) {
746
+ _args13 = arguments;
747
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
748
+ while (1) switch (_context13.prev = _context13.next) {
775
749
  case 0:
776
- string = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : false;
777
- _context14.next = 3;
750
+ string = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
751
+ _context13.next = 3;
778
752
  return this.arweave.transactions.getData(txid, {
779
753
  decode: true,
780
754
  string: string
781
755
  });
782
756
  case 3:
783
- return _context14.abrupt("return", _context14.sent);
757
+ return _context13.abrupt("return", _context13.sent);
784
758
  case 4:
785
759
  case "end":
786
- return _context14.stop();
760
+ return _context13.stop();
787
761
  }
788
- }, _callee14, this);
762
+ }, _callee13, this);
789
763
  }));
790
- function data(_x16) {
764
+ function data(_x15) {
791
765
  return _data.apply(this, arguments);
792
766
  }
793
767
  return data;
package/cjs/armem.js CHANGED
@@ -19,14 +19,17 @@ var ArMem = exports["default"] = /*#__PURE__*/_createClass(function ArMem() {
19
19
  this.__type__ = "mem";
20
20
  this.arweave = _arweave["default"].init();
21
21
  this.arweave.transactions.getTransactionAnchor = function () {
22
- return _this.blocks.length === 0 ? "" : (0, _ramda.last)(_this.blocks);
22
+ return _this.blocks.length === 0 ? "" : (0, _ramda.last)(_this.blockmap[(0, _ramda.last)(_this.blocks)].txs);
23
23
  };
24
24
  this.arweave.transactions.getPrice = function () {
25
25
  return 0;
26
26
  };
27
+ this.addrmap = {};
27
28
  this.txs = {};
29
+ this.jwks = {};
28
30
  this.height = 0;
29
31
  this.blocks = [];
32
+ this.blockmap = {};
30
33
  this.env = {};
31
34
  this.modules = {
32
35
  aos2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
package/cjs/tar.js CHANGED
@@ -10,11 +10,13 @@ var _utils = require("./utils.js");
10
10
  var _warpArbundles = require("warp-arbundles");
11
11
  var _base64url = _interopRequireDefault(require("base64url"));
12
12
  var _armem = _interopRequireDefault(require("./armem.js"));
13
+ var _tgql = _interopRequireDefault(require("./tgql.js"));
14
+ var _ramda = require("ramda");
13
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
- 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; }
15
16
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
16
17
  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; } }
17
18
  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; }
19
+ 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; }
18
20
  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); }
19
21
  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); }); }; }
20
22
  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; }
@@ -43,82 +45,52 @@ var AR = /*#__PURE__*/function (_MAR) {
43
45
  })]);
44
46
  _this.in_memory = true;
45
47
  _this.mem = (_opt$mem = opt.mem) !== null && _opt$mem !== void 0 ? _opt$mem : new _armem["default"]();
48
+ _this.gql = new _tgql["default"]({
49
+ mem: _this.mem
50
+ });
51
+ _this.arweave = _this.mem.arweave;
46
52
  return _this;
47
53
  }
48
54
  _inherits(AR, _MAR);
49
55
  return _createClass(AR, [{
50
- key: "txs",
56
+ key: "dataitem",
51
57
  value: function () {
52
- var _txs2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(pid) {
53
- var _txs, _iterator, _step, v;
58
+ var _dataitem = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
59
+ var _ref$target, target, _ref$data, data, _ref$tags, tags, signer, _tags, item, di, raw_owner, hashBuffer, owner;
54
60
  return _regeneratorRuntime().wrap(function _callee$(_context) {
55
61
  while (1) switch (_context.prev = _context.next) {
56
62
  case 0:
57
- _txs = [];
58
- _iterator = _createForOfIteratorHelper(this.mem.env[pid].txs);
59
- try {
60
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
61
- v = _step.value;
62
- _txs.push({
63
- tags: v.tags,
64
- id: v.id
65
- });
66
- }
67
- } catch (err) {
68
- _iterator.e(err);
69
- } finally {
70
- _iterator.f();
71
- }
72
- return _context.abrupt("return", _txs);
73
- case 4:
74
- case "end":
75
- return _context.stop();
76
- }
77
- }, _callee, this);
78
- }));
79
- function txs(_x) {
80
- return _txs2.apply(this, arguments);
81
- }
82
- return txs;
83
- }()
84
- }, {
85
- key: "dataitem",
86
- value: function () {
87
- var _dataitem = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
88
- var _ref$data, data, _ref$tags, tags, signer, _tags, item, di, raw_owner, hashBuffer, owner;
89
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
90
- while (1) switch (_context2.prev = _context2.next) {
91
- case 0:
92
- _ref$data = _ref.data, data = _ref$data === void 0 ? "1984" : _ref$data, _ref$tags = _ref.tags, tags = _ref$tags === void 0 ? {} : _ref$tags, signer = _ref.signer;
63
+ _ref$target = _ref.target, target = _ref$target === void 0 ? "" : _ref$target, _ref$data = _ref.data, data = _ref$data === void 0 ? "1984" : _ref$data, _ref$tags = _ref.tags, tags = _ref$tags === void 0 ? {} : _ref$tags, signer = _ref.signer;
93
64
  _tags = (0, _utils.buildTags)(tags);
94
- _context2.next = 4;
65
+ _context.next = 4;
95
66
  return signer({
96
67
  data: data,
97
- tags: _tags
68
+ tags: _tags,
69
+ target: target
98
70
  });
99
71
  case 4:
100
- item = _context2.sent;
72
+ item = _context.sent;
101
73
  di = new _warpArbundles.DataItem(item.raw);
102
74
  raw_owner = di.rawOwner;
103
- _context2.t0 = Buffer;
104
- _context2.next = 10;
75
+ _context.t0 = Buffer;
76
+ _context.next = 10;
105
77
  return crypto.subtle.digest("SHA-256", raw_owner);
106
78
  case 10:
107
- _context2.t1 = _context2.sent;
108
- hashBuffer = _context2.t0.from.call(_context2.t0, _context2.t1);
79
+ _context.t1 = _context.sent;
80
+ hashBuffer = _context.t0.from.call(_context.t0, _context.t1);
109
81
  owner = _base64url["default"].encode(hashBuffer);
110
- return _context2.abrupt("return", {
82
+ return _context.abrupt("return", {
111
83
  id: item.id,
112
84
  owner: owner,
113
85
  item: item
114
86
  });
115
87
  case 14:
116
88
  case "end":
117
- return _context2.stop();
89
+ return _context.stop();
118
90
  }
119
- }, _callee2);
91
+ }, _callee);
120
92
  }));
121
- function dataitem(_x2) {
93
+ function dataitem(_x) {
122
94
  return _dataitem.apply(this, arguments);
123
95
  }
124
96
  return dataitem;
@@ -126,46 +98,51 @@ var AR = /*#__PURE__*/function (_MAR) {
126
98
  }, {
127
99
  key: "post",
128
100
  value: function () {
129
- var _post = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
130
- var _ref2$data, data, _ref2$tags, tags, jwk, tx, _tags, _iterator2, _step2, v;
131
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
132
- while (1) switch (_context3.prev = _context3.next) {
101
+ var _post = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
102
+ var _ref2$data, data, _ref2$tags, tags, jwk, tx, _tags, _iterator, _step, v, owner;
103
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
104
+ while (1) switch (_context2.prev = _context2.next) {
133
105
  case 0:
134
106
  _ref2$data = _ref2.data, data = _ref2$data === void 0 ? "1984" : _ref2$data, _ref2$tags = _ref2.tags, tags = _ref2$tags === void 0 ? {} : _ref2$tags, jwk = _ref2.jwk;
135
- _context3.next = 3;
107
+ _context2.next = 3;
136
108
  return this.arweave.createTransaction({
137
109
  data: data
138
110
  });
139
111
  case 3:
140
- tx = _context3.sent;
112
+ tx = _context2.sent;
141
113
  _tags = (0, _utils.buildTags)(null, tags);
142
- _iterator2 = _createForOfIteratorHelper(_tags);
114
+ _iterator = _createForOfIteratorHelper(_tags);
143
115
  try {
144
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
145
- v = _step2.value;
116
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
117
+ v = _step.value;
146
118
  tx.addTag(v.name, v.value);
147
119
  }
148
120
  } catch (err) {
149
- _iterator2.e(err);
121
+ _iterator.e(err);
150
122
  } finally {
151
- _iterator2.f();
123
+ _iterator.f();
152
124
  }
153
- this.mem.height += 1;
154
- _context3.next = 10;
125
+ _context2.next = 9;
126
+ return this.arweave.wallets.jwkToAddress(jwk);
127
+ case 9:
128
+ owner = _context2.sent;
129
+ this.mem.addrmap[owner] = jwk.n;
130
+ _context2.next = 13;
155
131
  return this.postTx(tx, jwk, {
156
- height: this.mem.height,
132
+ recipient: "",
157
133
  tags: _tags,
158
- data: data
134
+ data: data,
135
+ owner: owner
159
136
  });
160
- case 10:
161
- return _context3.abrupt("return", _context3.sent);
162
- case 11:
137
+ case 13:
138
+ return _context2.abrupt("return", _context2.sent);
139
+ case 14:
163
140
  case "end":
164
- return _context3.stop();
141
+ return _context2.stop();
165
142
  }
166
- }, _callee3, this);
143
+ }, _callee2, this);
167
144
  }));
168
- function post(_x3) {
145
+ function post(_x2) {
169
146
  return _post.apply(this, arguments);
170
147
  }
171
148
  return post;
@@ -173,53 +150,72 @@ var AR = /*#__PURE__*/function (_MAR) {
173
150
  }, {
174
151
  key: "postItem",
175
152
  value: function () {
176
- var _postItem = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(item, jwk) {
177
- var tx, di, rowner, hashBuffer, owner, data;
178
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
179
- while (1) switch (_context4.prev = _context4.next) {
153
+ var _postItem = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(item, jwk) {
154
+ var tx, di, data_size, data_type, _iterator2, _step2, t, rowner, hashBuffer, owner, data, _item;
155
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
156
+ while (1) switch (_context3.prev = _context3.next) {
180
157
  case 0:
181
- _context4.next = 2;
158
+ _context3.next = 2;
182
159
  return this.mem.arweave.createTransaction({
183
160
  data: item.raw
184
- });
161
+ }, jwk);
185
162
  case 2:
186
- tx = _context4.sent;
163
+ tx = _context3.sent;
187
164
  tx.addTag("Bundle-Format", "binary");
188
165
  tx.addTag("Bundle-Version", "2.0.0");
189
166
  di = new _warpArbundles.DataItem(item.raw);
167
+ data_size = Buffer.byteLength(di.rawData).toString();
168
+ data_type = "";
169
+ _iterator2 = _createForOfIteratorHelper(di.tags);
170
+ try {
171
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
172
+ t = _step2.value;
173
+ if (t.name === "Content-Type") data_type = t.value;
174
+ }
175
+ } catch (err) {
176
+ _iterator2.e(err);
177
+ } finally {
178
+ _iterator2.f();
179
+ }
190
180
  rowner = di.rawOwner;
191
- _context4.t0 = Buffer;
192
- _context4.next = 10;
181
+ _context3.t0 = Buffer;
182
+ _context3.next = 14;
193
183
  return crypto.subtle.digest("SHA-256", rowner);
194
- case 10:
195
- _context4.t1 = _context4.sent;
196
- hashBuffer = _context4.t0.from.call(_context4.t0, _context4.t1);
184
+ case 14:
185
+ _context3.t1 = _context3.sent;
186
+ hashBuffer = _context3.t0.from.call(_context3.t0, _context3.t1);
197
187
  owner = _base64url["default"].encode(hashBuffer);
198
- this.mem.height += 1;
188
+ this.mem.addrmap[owner] = di.owner;
199
189
  data = di.data;
200
190
  try {
201
191
  data = _base64url["default"].decode(di.data);
202
192
  } catch (e) {}
203
- this.mem.txs[item.id] = {
193
+ _item = {
194
+ _data: {
195
+ size: data_size,
196
+ type: data_type
197
+ },
198
+ anchor: di.anchor,
199
+ signature: di.signature,
200
+ recipient: di.target,
204
201
  id: item.id,
205
202
  item: di,
206
203
  owner: owner,
207
- height: this.mem.height,
208
204
  tags: di.tags,
209
205
  data: data
210
206
  };
211
- this.mem.blocks.push(item.id);
212
- _context4.next = 20;
213
- return this.postTx(tx, jwk);
214
- case 20:
215
- return _context4.abrupt("return", _context4.sent);
216
- case 21:
207
+ this.mem.txs[item.id] = _item;
208
+ _context3.next = 24;
209
+ return this.postTx(tx, jwk, _item);
210
+ case 24:
211
+ return _context3.abrupt("return", _context3.sent);
212
+ case 25:
217
213
  case "end":
218
- return _context4.stop();
214
+ return _context3.stop();
219
215
  }
220
- }, _callee4, this);
216
+ }, _callee3, this);
221
217
  }));
222
- function postItem(_x4, _x5) {
218
+ function postItem(_x3, _x4) {
223
219
  return _postItem.apply(this, arguments);
224
220
  }
225
221
  return postItem;
@@ -227,39 +223,85 @@ var AR = /*#__PURE__*/function (_MAR) {
227
223
  }, {
228
224
  key: "postTx",
229
225
  value: function () {
230
- var _postTx = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(tx, jwk, item) {
231
- var res, err;
232
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
233
- while (1) switch (_context5.prev = _context5.next) {
226
+ var _postTx = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tx, jwk, item) {
227
+ var res, err, _last, block, data_type, _iterator3, _step3, v, owner;
228
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
229
+ while (1) switch (_context4.prev = _context4.next) {
234
230
  case 0:
235
231
  res = null, err = null;
236
- _context5.next = 3;
232
+ _context4.next = 3;
237
233
  return this.mem.arweave.transactions.sign(tx, jwk);
238
234
  case 3:
239
235
  if (item) {
240
- if (!item.id) item.id = tx.id;
241
- this.mem.txs[item.id] = item;
242
- this.mem.blocks.push(item.id);
236
+ this.mem.height += 1;
237
+ block = {
238
+ id: tx.id,
239
+ timestamp: Date.now(),
240
+ height: this.mem.height,
241
+ previous: (_last = (0, _ramda.last)(this.mem.blocks)) !== null && _last !== void 0 ? _last : ""
242
+ };
243
+ if (!item.id) {
244
+ item.id = tx.id;
245
+ this.mem.txs[item.id] = item;
246
+ this.mem.txs[item.id].parent = null;
247
+ this.mem.txs[item.id].signature = tx.signature;
248
+ this.mem.txs[item.id].anchor = tx.last_tx;
249
+ data_type = "";
250
+ _iterator3 = _createForOfIteratorHelper(tx.tags);
251
+ try {
252
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
253
+ v = _step3.value;
254
+ if (v.get("name", {
255
+ decode: true,
256
+ string: true
257
+ }) === "Content-Type") {
258
+ data_type = v.get("value", {
259
+ decode: true,
260
+ string: true
261
+ });
262
+ }
263
+ }
264
+ } catch (err) {
265
+ _iterator3.e(err);
266
+ } finally {
267
+ _iterator3.f();
268
+ }
269
+ this.mem.txs[item.id]._data = {
270
+ size: tx.data_size,
271
+ type: data_type
272
+ };
273
+ } else {
274
+ this.mem.txs[item.id].parent = {
275
+ id: block.id
276
+ };
277
+ }
278
+ block.txs = [item.id];
279
+ this.mem.txs[item.id].block = block.id;
280
+ this.mem.blocks.push(block.id);
281
+ this.mem.blockmap[block.id] = block;
243
282
  }
244
283
  res = {
245
284
  id: tx.id,
246
285
  status: 200,
247
286
  statusText: "200"
248
287
  };
249
- //res = await this.arweave.transactions.post(tx)
250
- //if (res.status !== 200) err = res.statusText
251
- return _context5.abrupt("return", {
288
+ _context4.next = 7;
289
+ return this.arweave.wallets.jwkToAddress(jwk);
290
+ case 7:
291
+ owner = _context4.sent;
292
+ this.mem.addrmap[owner] = jwk.n;
293
+ return _context4.abrupt("return", {
252
294
  res: res,
253
295
  err: err,
254
296
  id: tx.id
255
297
  });
256
- case 6:
298
+ case 10:
257
299
  case "end":
258
- return _context5.stop();
300
+ return _context4.stop();
259
301
  }
260
- }, _callee5, this);
302
+ }, _callee4, this);
261
303
  }));
262
- function postTx(_x6, _x7, _x8) {
304
+ function postTx(_x5, _x6, _x7) {
263
305
  return _postTx.apply(this, arguments);
264
306
  }
265
307
  return postTx;