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/ao.js +6 -1
- package/cjs/aoconnect.js +236 -244
- package/cjs/ar.js +38 -64
- package/cjs/armem.js +4 -1
- package/cjs/tar.js +153 -111
- package/cjs/tgql.js +733 -0
- package/cjs/utils.js +1 -7
- package/esm/.cache/opt.json +1 -1
- package/esm/ao.js +4 -1
- package/esm/aoconnect.js +84 -60
- package/esm/ar.js +7 -23
- package/esm/armem.js +6 -1
- package/esm/gql.js +1 -0
- package/esm/tar.js +53 -26
- package/esm/tgql.js +283 -0
- package/esm/utils.js +0 -14
- package/package.json +1 -1
package/cjs/utils.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isData = exports.isCheckComplete = exports.getTagVal = exports.getTag = exports.dirname = exports.checkTag = exports.buildTags = exports.action = void 0;
|
|
7
7
|
exports.isJSON = isJSON;
|
|
8
|
-
exports.wait = exports.validAddress = exports.udl = exports.tags = exports.tagEq = exports.tag = exports.srcs = exports.searchTag = exports.
|
|
8
|
+
exports.wait = exports.validAddress = exports.udl = exports.tags = exports.tagEq = exports.tag = exports.srcs = exports.searchTag = exports.mergeOut = exports.mergeChecks = exports.ltags = exports.jsonToStr = exports.isRegExp = exports.isOutComplete = exports.isLocalhost = void 0;
|
|
9
9
|
var _ramda = require("ramda");
|
|
10
10
|
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; }
|
|
11
11
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
@@ -207,12 +207,6 @@ var isData = exports.isData = function isData(data, res) {
|
|
|
207
207
|
}
|
|
208
208
|
return false;
|
|
209
209
|
};
|
|
210
|
-
var query = exports.query = function query(txid) {
|
|
211
|
-
return "query {\n transactions(ids: [\"".concat(txid, "\"]) {\n edges { node { id tags { name value } owner { address } } }\n }\n}");
|
|
212
|
-
};
|
|
213
|
-
var queries = exports.queries = function queries(to) {
|
|
214
|
-
return "query {\n transactions (recipients: [\"".concat(to, "\"]){\n edges { node { id recipient tags { name value } owner { address } } }\n }\n}");
|
|
215
|
-
};
|
|
216
210
|
var isLocalhost = exports.isLocalhost = function isLocalhost(v) {
|
|
217
211
|
return (0, _ramda.includes)(v, ["localhost", "127.0.0.1"]);
|
|
218
212
|
};
|
package/esm/.cache/opt.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"ar":{"port":4000},"jwk":{"kty":"RSA","n":"
|
|
1
|
+
{"ar":{"port":4000},"jwk":{"kty":"RSA","n":"tBba3N1KKiDvu4TnAd_lhYDBXs0QrLH4Hgd6mHTeovFvZDLZHlNukT9SXeHx1_58hQWtcIPvS6F9tASdpMREKMVkG9hb6nMXtUCkTJE7PURvqeJf5VGJt9rUBtYaaJ_8eVJ3w98_RqUR0k0rYsYcJqiFFYaSFG2mIbyP7lBSUifF0dsOI1j1IRlvhZ02BOD7LJpwycX-fsXq7DAbpC6ywkuQ0EU830f3DefhfCQRRreZiKKNHRVvKhe9Z8LTjtMWHcAotg5-lLWLVUT1fO5tUnVwcJ_fGGFtLC1RGjryGg2ZOykktpDuALvZrZd3psIGQPnpuF75QYTVSbiadCK_JOelt8xcwIUphYAeWJQ6BNBmA8afPvVhS6rma0zp30ChXLQJEgtRWm9FpI-DQaM9PPcDlupsDFmmBtZGj0fLSTcpf00i0gpoDVJWcBVrd5aBiks0rRNUWRgWHadWBfBskUCrA1DG99seZOKKL9qLIknK3c6cTO068JegbwAW51eEH-etaoAvZ5mmyIB7LHKEomOQjeobek5_7OChwA66cS882gbFc3CfX0QdQRWWrNJ84hm3_xgHG6VjQOWNTh751WrVe4PnlLPvqKt8u2It4ZIlBxri7JklRxLL4Y1xkuV1a3gKllLVWizULPFN8Dms_7hjGSk1N3UUV3Bv_oxlRTk","e":"AQAB","d":"BQo4tAKraMdrZIhh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8f5-__2_pKhO5pvzRPCU-N-YLQH0NAKIYlSfWarObe84SW5Ds0OUb46WuoRGDqrLIokt2HxFi6uA_ZzuEvdmxZk9HWRRaPiKCif3uJfZtJ3_4WxpFvw-IYY3p8m3nt9qdU8EPhiZBEKdYdyAkHN6bIN9GbpUpUbEwYJXTCtqOgG4nuiWl8HWijk7QgcEO1gRG-pt4HzzFTa01BBIxdbelBii35uUoUVzco3dntUghotXOMGeCg"},"ao":{"module":"nrwqdbTzLYTALBkzLv9HwmF97b0eoGvlT3YwfJnyOjY","scheduler":"FKtGpY1kBbr8hBIocph3nMvadgBSQtQBTYnlAJetrDU","aoconnect":{"MU_URL":"http://localhost:4002","CU_URL":"http://localhost:4004","GATEWAY_URL":"http://localhost:4000"},"ar":{"port":4000},"authority":"7WspynohDWhx3_Q37pzHmDGStf2T_p8ghdk_XTSUm8s"},"ao2":{"module":"9Xx6YzV2-giIaD8b9HTewr0FxRjugwm5FCuaQU-kJvI","scheduler":"FKtGpY1kBbr8hBIocph3nMvadgBSQtQBTYnlAJetrDU","aoconnect":{"MU_URL":"http://localhost:4002","CU_URL":"http://localhost:4004","GATEWAY_URL":"http://localhost:4000"},"ar":{"port":4000},"authority":"7WspynohDWhx3_Q37pzHmDGStf2T_p8ghdk_XTSUm8s"},"authority":"7WspynohDWhx3_Q37pzHmDGStf2T_p8ghdk_XTSUm8s","targets":{"profile":false,"note":false,"asset":false},"modules":{"aos2":"9Xx6YzV2-giIaD8b9HTewr0FxRjugwm5FCuaQU-kJvI","aos1":"MSCReWoRQ3w3JmPvbsTvPFnJrdzPym0F61cdBGEsBgs","sqlite":"nrwqdbTzLYTALBkzLv9HwmF97b0eoGvlT3YwfJnyOjY"}}
|
package/esm/ao.js
CHANGED
|
@@ -384,7 +384,10 @@ class AO {
|
|
|
384
384
|
let ex = exRef(ref, txs)
|
|
385
385
|
if (!ex) {
|
|
386
386
|
if (!this.in_memory) await wait(1000)
|
|
387
|
-
txs = await this.ar.txs(
|
|
387
|
+
txs = await this.ar.gql.txs({
|
|
388
|
+
recipient: pid,
|
|
389
|
+
fields: ["id", "recipient", "tags", { owner: ["address"] }],
|
|
390
|
+
})
|
|
388
391
|
ex = exRef(ref, txs)
|
|
389
392
|
}
|
|
390
393
|
if (ex) return txs
|
package/esm/aoconnect.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DataItem } from "warp-arbundles"
|
|
2
|
+
import crypto from "crypto"
|
|
2
3
|
import base64url from "base64url"
|
|
4
|
+
|
|
3
5
|
import {
|
|
4
6
|
tags,
|
|
5
7
|
action,
|
|
@@ -121,6 +123,18 @@ export const connect = mem => {
|
|
|
121
123
|
mem.modmap[mod] = { handle, id: mod }
|
|
122
124
|
}
|
|
123
125
|
if (!mod) throw Error("module not found")
|
|
126
|
+
opt.tags = buildTags(
|
|
127
|
+
null,
|
|
128
|
+
mergeLeft(tags(opt.tags ?? []), {
|
|
129
|
+
"Data-Protocol": "ao",
|
|
130
|
+
Variant: "ao.TN.1",
|
|
131
|
+
Type: "Process",
|
|
132
|
+
SDK: "aoconnect",
|
|
133
|
+
Module: opt.module,
|
|
134
|
+
Scheduler: opt.scheduler,
|
|
135
|
+
"Content-Type": "text/plain",
|
|
136
|
+
}),
|
|
137
|
+
)
|
|
124
138
|
const _module = mem.modmap[mod]
|
|
125
139
|
let ex = false
|
|
126
140
|
opt.tags ??= []
|
|
@@ -137,8 +151,10 @@ export const connect = mem => {
|
|
|
137
151
|
let memory = null
|
|
138
152
|
let p = {
|
|
139
153
|
id: id,
|
|
154
|
+
epochs: [],
|
|
140
155
|
handle: _module.handle,
|
|
141
156
|
module: _module.id,
|
|
157
|
+
hash: id,
|
|
142
158
|
memory,
|
|
143
159
|
owner,
|
|
144
160
|
height: 0,
|
|
@@ -207,73 +223,50 @@ export const connect = mem => {
|
|
|
207
223
|
return id
|
|
208
224
|
}
|
|
209
225
|
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
signer: _opt.signer,
|
|
216
|
-
tags: tags(_opt.tags),
|
|
217
|
-
})
|
|
218
|
-
await ar.postItem(item, su.jwk)
|
|
219
|
-
try {
|
|
220
|
-
const msg = genMsg(
|
|
221
|
-
p,
|
|
222
|
-
_opt.data ?? "",
|
|
223
|
-
_opt.tags,
|
|
224
|
-
_opt.from ?? owner,
|
|
225
|
-
mu.addr,
|
|
226
|
-
)
|
|
227
|
-
const _env = genEnv({
|
|
228
|
-
pid: p.id,
|
|
229
|
-
owner: p.owner,
|
|
230
|
-
module: p.module,
|
|
231
|
-
auth: mu.addr,
|
|
232
|
-
})
|
|
233
|
-
const res = await p.handle(p.memory, msg, _env)
|
|
234
|
-
p.memory = res.Memory
|
|
235
|
-
delete res.Memory
|
|
236
|
-
p.res[id] = res
|
|
237
|
-
p.results.push(id)
|
|
238
|
-
p.txs.unshift({ id: id, ..._opt })
|
|
239
|
-
mem.msgs[id] = _opt
|
|
240
|
-
for (const v of res.Messages ?? []) {
|
|
241
|
-
if (mem.env[v.Target]) {
|
|
242
|
-
await message({
|
|
243
|
-
process: v.Target,
|
|
244
|
-
tags: v.Tags,
|
|
245
|
-
data: v.Data,
|
|
246
|
-
signer: mu.signer,
|
|
247
|
-
from: opt.process,
|
|
248
|
-
})
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return id
|
|
252
|
-
} catch (e) {
|
|
253
|
-
console.log(e)
|
|
226
|
+
function genHashChain(previousHash, previousMessageId = null) {
|
|
227
|
+
const hasher = crypto.createHash("sha256")
|
|
228
|
+
hasher.update(Buffer.from(previousHash, "base64url"))
|
|
229
|
+
if (previousMessageId) {
|
|
230
|
+
hasher.update(Buffer.from(previousMessageId, "base64url"))
|
|
254
231
|
}
|
|
255
|
-
return
|
|
232
|
+
return base64url(hasher.digest())
|
|
256
233
|
}
|
|
257
234
|
|
|
258
|
-
const
|
|
235
|
+
const assign = async opt => {
|
|
259
236
|
const p = mem.env[opt.process]
|
|
260
|
-
let
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
237
|
+
let _opt = mem.msgs[opt.message]
|
|
238
|
+
let hash = genHashChain(p.hash, opt.message)
|
|
239
|
+
p.hash = hash
|
|
240
|
+
opt.tags = buildTags(
|
|
241
|
+
null,
|
|
242
|
+
mergeLeft(tags(opt.tags ?? []), {
|
|
243
|
+
Timestamp: Date.now(),
|
|
244
|
+
Epoch: p.epochs.length,
|
|
245
|
+
Nonce: "0",
|
|
246
|
+
"Data-Protocol": "ao",
|
|
247
|
+
Variant: "ao.TN.1",
|
|
248
|
+
SDK: "aoconnect",
|
|
249
|
+
Type: "Assignment",
|
|
250
|
+
"Block-Height": mem.height,
|
|
251
|
+
Process: opt.process,
|
|
252
|
+
Message: opt.message,
|
|
253
|
+
"Hash-Chain": hash,
|
|
254
|
+
}),
|
|
255
|
+
)
|
|
256
|
+
p.epochs.push([opt.id])
|
|
257
|
+
const { id, owner, item } = await ar.dataitem({
|
|
265
258
|
data: opt.data,
|
|
266
259
|
signer: opt.signer,
|
|
267
260
|
tags: tags(opt.tags),
|
|
261
|
+
target: opt.process,
|
|
268
262
|
})
|
|
269
|
-
|
|
270
263
|
await ar.postItem(item, su.jwk)
|
|
271
264
|
try {
|
|
272
265
|
const msg = genMsg(
|
|
273
266
|
p,
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
opt.from ?? owner,
|
|
267
|
+
_opt.data ?? "",
|
|
268
|
+
_opt.tags,
|
|
269
|
+
_opt.from ?? opt.from ?? owner,
|
|
277
270
|
mu.addr,
|
|
278
271
|
)
|
|
279
272
|
const _env = genEnv({
|
|
@@ -285,10 +278,10 @@ export const connect = mem => {
|
|
|
285
278
|
const res = await p.handle(p.memory, msg, _env)
|
|
286
279
|
p.memory = res.Memory
|
|
287
280
|
delete res.Memory
|
|
288
|
-
p.res[
|
|
289
|
-
p.results.push(
|
|
290
|
-
p.txs.unshift({ id:
|
|
291
|
-
mem.msgs[
|
|
281
|
+
p.res[opt.message] = res
|
|
282
|
+
p.results.push(opt.message)
|
|
283
|
+
p.txs.unshift({ id: opt.message, ...opt })
|
|
284
|
+
mem.msgs[opt.message] = _opt
|
|
292
285
|
for (const v of res.Messages ?? []) {
|
|
293
286
|
if (mem.env[v.Target]) {
|
|
294
287
|
await message({
|
|
@@ -321,6 +314,7 @@ export const connect = mem => {
|
|
|
321
314
|
})
|
|
322
315
|
}
|
|
323
316
|
}
|
|
317
|
+
|
|
324
318
|
return id
|
|
325
319
|
} catch (e) {
|
|
326
320
|
console.log(e)
|
|
@@ -328,6 +322,36 @@ export const connect = mem => {
|
|
|
328
322
|
return null
|
|
329
323
|
}
|
|
330
324
|
|
|
325
|
+
const message = async opt => {
|
|
326
|
+
const p = mem.env[opt.process]
|
|
327
|
+
let ex = false
|
|
328
|
+
for (let v of opt.tags) if (v.name === "Type") ex = true
|
|
329
|
+
opt.tags = buildTags(
|
|
330
|
+
null,
|
|
331
|
+
mergeLeft(tags(opt.tags ?? []), {
|
|
332
|
+
"Data-Protocol": "ao",
|
|
333
|
+
Variant: "ao.TN.1",
|
|
334
|
+
Type: "Message",
|
|
335
|
+
SDK: "aoconnect",
|
|
336
|
+
}),
|
|
337
|
+
)
|
|
338
|
+
const { item, id, owner } = await ar.dataitem({
|
|
339
|
+
data: opt.data,
|
|
340
|
+
signer: opt.signer,
|
|
341
|
+
tags: tags(opt.tags),
|
|
342
|
+
target: opt.process,
|
|
343
|
+
})
|
|
344
|
+
await ar.postItem(item, su.jwk)
|
|
345
|
+
mem.msgs[id] = opt
|
|
346
|
+
await assign({
|
|
347
|
+
message: id,
|
|
348
|
+
process: opt.process,
|
|
349
|
+
from: owner,
|
|
350
|
+
signer: mu.signer,
|
|
351
|
+
})
|
|
352
|
+
return id
|
|
353
|
+
}
|
|
354
|
+
|
|
331
355
|
return {
|
|
332
356
|
message,
|
|
333
357
|
unmonitor: async opt => {
|
|
@@ -372,7 +396,7 @@ export const connect = mem => {
|
|
|
372
396
|
},
|
|
373
397
|
dryrun: async opt => {
|
|
374
398
|
const p = mem.env[opt.process]
|
|
375
|
-
const { id, owner } = await ar.dataitem(opt)
|
|
399
|
+
const { id, owner } = await ar.dataitem({ ...opt, target: opt.process })
|
|
376
400
|
try {
|
|
377
401
|
const msg = genMsg(p, opt.data ?? "", opt.tags, owner, mu.addr, true)
|
|
378
402
|
const _env = genEnv({
|
package/esm/ar.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import Arweave from "arweave"
|
|
2
2
|
import { ArweaveSigner, bundleAndSignData, createData } from "arbundles"
|
|
3
|
-
import { buildTags, tag,
|
|
3
|
+
import { buildTags, tag, isLocalhost } from "./utils.js"
|
|
4
4
|
import { is } from "ramda"
|
|
5
|
+
import GQL from "./gql.js"
|
|
5
6
|
|
|
6
7
|
class AR {
|
|
7
8
|
constructor({ host, port = 443, protocol } = {}) {
|
|
8
9
|
this.__type__ = "ar"
|
|
9
10
|
let _arweave = { host, port, protocol }
|
|
10
11
|
if (!_arweave.host)
|
|
11
|
-
_arweave.host = port === 443 ? "arweave.net" : "
|
|
12
|
+
_arweave.host = port === 443 ? "arweave.net" : "localhost"
|
|
12
13
|
if (!_arweave.protocol)
|
|
13
14
|
_arweave.protocol = isLocalhost(_arweave.host) ? "http" : "https"
|
|
14
15
|
if (!_arweave.port) _arweave.port = isLocalhost(_arweave.host) ? 1984 : 443
|
|
@@ -16,6 +17,9 @@ class AR {
|
|
|
16
17
|
this.host = _arweave.host
|
|
17
18
|
this.protocol = _arweave.protocol
|
|
18
19
|
this.arweave = Arweave.init(_arweave)
|
|
20
|
+
this.gql = new GQL({
|
|
21
|
+
url: `${_arweave.protocol}://${_arweave.host}:${_arweave.port}/graphql`,
|
|
22
|
+
})
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
isArConnect(jwk) {
|
|
@@ -211,27 +215,7 @@ class AR {
|
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
async tx(txid) {
|
|
214
|
-
|
|
215
|
-
`${this.protocol}://${this.host}:${this.port}/graphql`,
|
|
216
|
-
{
|
|
217
|
-
method: "POST",
|
|
218
|
-
headers: { "Content-Type": "application/json" },
|
|
219
|
-
body: JSON.stringify({ query: query(txid) }),
|
|
220
|
-
},
|
|
221
|
-
).then(r => r.json())
|
|
222
|
-
return json.data.transactions.edges.map(v => v.node)[0] ?? null
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async txs(to) {
|
|
226
|
-
const json = await fetch(
|
|
227
|
-
`${this.protocol}://${this.host}:${this.port}/graphql`,
|
|
228
|
-
{
|
|
229
|
-
method: "POST",
|
|
230
|
-
headers: { "Content-Type": "application/json" },
|
|
231
|
-
body: JSON.stringify({ query: queries(to) }),
|
|
232
|
-
},
|
|
233
|
-
).then(r => r.json())
|
|
234
|
-
return json.data.transactions.edges.map(v => v.node)
|
|
218
|
+
return (await this.gql.txs({ id: txid }))[0] ?? null
|
|
235
219
|
}
|
|
236
220
|
|
|
237
221
|
async data(txid, string = false) {
|
package/esm/armem.js
CHANGED
|
@@ -6,12 +6,17 @@ export default class ArMem {
|
|
|
6
6
|
this.__type__ = "mem"
|
|
7
7
|
this.arweave = Arweave.init()
|
|
8
8
|
this.arweave.transactions.getTransactionAnchor = () => {
|
|
9
|
-
return this.blocks.length === 0
|
|
9
|
+
return this.blocks.length === 0
|
|
10
|
+
? ""
|
|
11
|
+
: last(this.blockmap[last(this.blocks)].txs)
|
|
10
12
|
}
|
|
11
13
|
this.arweave.transactions.getPrice = () => 0
|
|
14
|
+
this.addrmap = {}
|
|
12
15
|
this.txs = {}
|
|
16
|
+
this.jwks = {}
|
|
13
17
|
this.height = 0
|
|
14
18
|
this.blocks = []
|
|
19
|
+
this.blockmap = {}
|
|
15
20
|
this.env = {}
|
|
16
21
|
this.modules = {
|
|
17
22
|
aos2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
|
package/esm/gql.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { includes, map, is, isNil, last, clone } from "ramda"
|
|
2
|
+
|
|
2
3
|
const full = `id anchor signature recipient owner { address key } fee { winston ar } quantity { winston ar } data { size type } tags { name value } block { id timestamp height previous } parent { id }`
|
|
3
4
|
const full_blocks = `id timestamp height previous`
|
|
4
5
|
|
package/esm/tar.js
CHANGED
|
@@ -3,25 +3,20 @@ import { buildTags } from "./utils.js"
|
|
|
3
3
|
import { DataItem } from "warp-arbundles"
|
|
4
4
|
import base64url from "base64url"
|
|
5
5
|
import ArMem from "./armem.js"
|
|
6
|
-
|
|
6
|
+
import GQL from "./tgql.js"
|
|
7
|
+
import { last } from "ramda"
|
|
7
8
|
class AR extends MAR {
|
|
8
9
|
constructor(opt = {}) {
|
|
9
10
|
super({ ...opt, in_memory: true })
|
|
10
11
|
this.in_memory = true
|
|
11
12
|
this.mem = opt.mem ?? new ArMem()
|
|
13
|
+
this.gql = new GQL({ mem: this.mem })
|
|
14
|
+
this.arweave = this.mem.arweave
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
async
|
|
15
|
-
let _txs = []
|
|
16
|
-
for (let v of this.mem.env[pid].txs) {
|
|
17
|
-
_txs.push({ tags: v.tags, id: v.id })
|
|
18
|
-
}
|
|
19
|
-
return _txs
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async dataitem({ data = "1984", tags = {}, signer }) {
|
|
17
|
+
async dataitem({ target = "", data = "1984", tags = {}, signer }) {
|
|
23
18
|
const _tags = buildTags(tags)
|
|
24
|
-
const item = await signer({ data, tags: _tags })
|
|
19
|
+
const item = await signer({ data, tags: _tags, target })
|
|
25
20
|
const di = new DataItem(item.raw)
|
|
26
21
|
const raw_owner = di.rawOwner
|
|
27
22
|
const hashBuffer = Buffer.from(
|
|
@@ -35,54 +30,86 @@ class AR extends MAR {
|
|
|
35
30
|
let tx = await this.arweave.createTransaction({ data: data })
|
|
36
31
|
let _tags = buildTags(null, tags)
|
|
37
32
|
for (const v of _tags) tx.addTag(v.name, v.value)
|
|
38
|
-
this.
|
|
33
|
+
const owner = await this.arweave.wallets.jwkToAddress(jwk)
|
|
34
|
+
this.mem.addrmap[owner] = jwk.n
|
|
39
35
|
return await this.postTx(tx, jwk, {
|
|
40
|
-
|
|
36
|
+
recipient: "",
|
|
41
37
|
tags: _tags,
|
|
42
38
|
data,
|
|
39
|
+
owner,
|
|
43
40
|
})
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
async postItem(item, jwk) {
|
|
47
|
-
const tx = await this.mem.arweave.createTransaction({
|
|
48
|
-
data: item.raw,
|
|
49
|
-
})
|
|
44
|
+
const tx = await this.mem.arweave.createTransaction({ data: item.raw }, jwk)
|
|
50
45
|
tx.addTag("Bundle-Format", "binary")
|
|
51
46
|
tx.addTag("Bundle-Version", "2.0.0")
|
|
52
47
|
const di = new DataItem(item.raw)
|
|
48
|
+
const data_size = Buffer.byteLength(di.rawData).toString()
|
|
49
|
+
let data_type = ""
|
|
50
|
+
for (const t of di.tags) if (t.name === "Content-Type") data_type = t.value
|
|
53
51
|
const rowner = di.rawOwner
|
|
54
52
|
const hashBuffer = Buffer.from(
|
|
55
53
|
await crypto.subtle.digest("SHA-256", rowner),
|
|
56
54
|
)
|
|
57
55
|
const owner = base64url.encode(hashBuffer)
|
|
58
|
-
this.mem.
|
|
56
|
+
this.mem.addrmap[owner] = di.owner
|
|
59
57
|
let data = di.data
|
|
60
58
|
try {
|
|
61
59
|
data = base64url.decode(di.data)
|
|
62
60
|
} catch (e) {}
|
|
63
|
-
|
|
61
|
+
let _item = {
|
|
62
|
+
_data: { size: data_size, type: data_type },
|
|
63
|
+
anchor: di.anchor,
|
|
64
|
+
signature: di.signature,
|
|
65
|
+
recipient: di.target,
|
|
64
66
|
id: item.id,
|
|
65
67
|
item: di,
|
|
66
68
|
owner,
|
|
67
|
-
height: this.mem.height,
|
|
68
69
|
tags: di.tags,
|
|
69
70
|
data,
|
|
70
71
|
}
|
|
71
|
-
this.mem.
|
|
72
|
-
return await this.postTx(tx, jwk)
|
|
72
|
+
this.mem.txs[item.id] = _item
|
|
73
|
+
return await this.postTx(tx, jwk, _item)
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
async postTx(tx, jwk, item) {
|
|
76
77
|
let [res, err] = [null, null]
|
|
77
78
|
await this.mem.arweave.transactions.sign(tx, jwk)
|
|
78
79
|
if (item) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
this.mem.height += 1
|
|
81
|
+
const block = {
|
|
82
|
+
id: tx.id,
|
|
83
|
+
timestamp: Date.now(),
|
|
84
|
+
height: this.mem.height,
|
|
85
|
+
previous: last(this.mem.blocks) ?? "",
|
|
86
|
+
}
|
|
87
|
+
if (!item.id) {
|
|
88
|
+
item.id = tx.id
|
|
89
|
+
this.mem.txs[item.id] = item
|
|
90
|
+
this.mem.txs[item.id].parent = null
|
|
91
|
+
this.mem.txs[item.id].signature = tx.signature
|
|
92
|
+
this.mem.txs[item.id].anchor = tx.last_tx
|
|
93
|
+
let data_type = ""
|
|
94
|
+
for (const v of tx.tags) {
|
|
95
|
+
if (
|
|
96
|
+
v.get("name", { decode: true, string: true }) === "Content-Type"
|
|
97
|
+
) {
|
|
98
|
+
data_type = v.get("value", { decode: true, string: true })
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
this.mem.txs[item.id]._data = { size: tx.data_size, type: data_type }
|
|
102
|
+
} else {
|
|
103
|
+
this.mem.txs[item.id].parent = { id: block.id }
|
|
104
|
+
}
|
|
105
|
+
block.txs = [item.id]
|
|
106
|
+
this.mem.txs[item.id].block = block.id
|
|
107
|
+
this.mem.blocks.push(block.id)
|
|
108
|
+
this.mem.blockmap[block.id] = block
|
|
82
109
|
}
|
|
83
110
|
res = { id: tx.id, status: 200, statusText: "200" }
|
|
84
|
-
|
|
85
|
-
|
|
111
|
+
const owner = await this.arweave.wallets.jwkToAddress(jwk)
|
|
112
|
+
this.mem.addrmap[owner] = jwk.n
|
|
86
113
|
return { res, err, id: tx.id }
|
|
87
114
|
}
|
|
88
115
|
|