wao 0.9.1 → 0.9.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/aoconnect-base.js +1332 -0
- package/cjs/aoconnect-web.js +15 -1317
- package/cjs/aoconnect.js +15 -1317
- package/cjs/ar-base.js +683 -0
- package/cjs/armem-base.js +438 -0
- package/cjs/armem-web.js +29 -560
- package/cjs/armem.js +30 -402
- package/cjs/bao.js +248 -0
- package/cjs/lfdb.js +165 -0
- package/cjs/tao.js +10 -222
- package/cjs/tar.js +8 -655
- package/cjs/wao.js +10 -222
- package/cjs/war.js +8 -655
- package/esm/aoconnect-base.js +482 -0
- package/esm/aoconnect-web.js +6 -482
- package/esm/aoconnect.js +6 -483
- package/esm/ar-base.js +215 -0
- package/esm/armem-base.js +172 -0
- package/esm/armem-web.js +8 -232
- package/esm/armem.js +7 -163
- package/esm/bao.js +125 -0
- package/esm/lfdb.js +68 -0
- package/esm/tao.js +4 -121
- package/esm/tar.js +3 -209
- package/esm/wao.js +4 -121
- package/esm/war.js +3 -209
- package/esm/web.js +0 -1
- package/package.json +1 -1
package/esm/war.js
CHANGED
|
@@ -1,215 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { buildTags, tags as t } from "./utils.js"
|
|
3
|
-
import * as WarpArBundles from "warp-arbundles"
|
|
4
|
-
const pkg = WarpArBundles.default ?? WarpArBundles
|
|
5
|
-
const { DataItem } = pkg
|
|
6
|
-
import { bundleAndSignData, ArweaveSigner } from "arbundles"
|
|
7
|
-
import base64url from "base64url"
|
|
1
|
+
import BAR from "./ar-base.js"
|
|
8
2
|
import ArMem from "./armem-web.js"
|
|
9
|
-
import GQL from "./tgql.js"
|
|
10
|
-
import { last, is, includes, isNil } from "ramda"
|
|
11
3
|
|
|
12
|
-
class AR extends
|
|
4
|
+
class AR extends BAR {
|
|
13
5
|
constructor(opt = {}) {
|
|
14
|
-
super({ ...opt,
|
|
15
|
-
this.log = opt.log === true
|
|
16
|
-
this.in_memory = true
|
|
17
|
-
this.mem = opt.mem ?? new ArMem()
|
|
18
|
-
this.gql = new GQL({ mem: this.mem })
|
|
19
|
-
this.arweave = this.mem.arweave
|
|
20
|
-
}
|
|
21
|
-
async owner(di) {
|
|
22
|
-
const raw_owner = di.rawOwner
|
|
23
|
-
const hashBuffer = Buffer.from(
|
|
24
|
-
await crypto.subtle.digest("SHA-256", raw_owner),
|
|
25
|
-
)
|
|
26
|
-
return base64url.encode(hashBuffer)
|
|
27
|
-
}
|
|
28
|
-
async dataitem({ target = "", data = "1984", tags = {}, signer, item }) {
|
|
29
|
-
let di = item
|
|
30
|
-
if (!di) {
|
|
31
|
-
const _tags = buildTags(tags)
|
|
32
|
-
const _item = await signer({ data, tags: _tags, target })
|
|
33
|
-
di = new DataItem(_item.raw)
|
|
34
|
-
} else {
|
|
35
|
-
tags = t(di.tags)
|
|
36
|
-
}
|
|
37
|
-
const owner = await this.owner(di)
|
|
38
|
-
return { id: await di.id, owner, item: di, tags }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async post({ data = "1984", tags = {}, jwk }) {
|
|
42
|
-
let err = null
|
|
43
|
-
;({ err, jwk } = await this.checkWallet({ jwk }))
|
|
44
|
-
if (err) return { err }
|
|
45
|
-
let tx = await this.arweave.createTransaction({ data: data })
|
|
46
|
-
let _tags = buildTags(null, tags)
|
|
47
|
-
for (const v of _tags) tx.addTag(v.name, v.value)
|
|
48
|
-
return await this.postTx(tx, jwk)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async postItems(items, jwk) {
|
|
52
|
-
let err = null
|
|
53
|
-
;({ err, jwk } = await this.checkWallet({ jwk }))
|
|
54
|
-
if (err) return { err }
|
|
55
|
-
if (!is(Array, items)) items = [items]
|
|
56
|
-
let _items = []
|
|
57
|
-
for (const di of items) {
|
|
58
|
-
di._id = await di.id
|
|
59
|
-
const data_size = Buffer.byteLength(di.rawData).toString()
|
|
60
|
-
let data_type = ""
|
|
61
|
-
for (const t of di.tags)
|
|
62
|
-
if (t.name === "Content-Type") data_type = t.value
|
|
63
|
-
const owner = await this.owner(di)
|
|
64
|
-
await this.mem.set({ key: di.owner, address: owner }, "addrmap", owner)
|
|
65
|
-
let data = di.data
|
|
66
|
-
let _item = {
|
|
67
|
-
_data: { size: data_size, type: data_type },
|
|
68
|
-
anchor: di.anchor,
|
|
69
|
-
signature: di.signature,
|
|
70
|
-
recipient: di.target,
|
|
71
|
-
id: await di.id,
|
|
72
|
-
item: di,
|
|
73
|
-
owner,
|
|
74
|
-
tags: di.tags,
|
|
75
|
-
data,
|
|
76
|
-
}
|
|
77
|
-
await this.mem.set(_item, "txs", await di.id)
|
|
78
|
-
_items.push(_item)
|
|
79
|
-
}
|
|
80
|
-
const bundle = await bundleAndSignData(items, new ArweaveSigner(jwk))
|
|
81
|
-
const tx = await this.mem.arweave.createTransaction(
|
|
82
|
-
{ data: bundle.binary },
|
|
83
|
-
jwk,
|
|
84
|
-
)
|
|
85
|
-
tx.addTag("Bundle-Format", "binary")
|
|
86
|
-
tx.addTag("Bundle-Version", "2.0.0")
|
|
87
|
-
return await this.postTx(tx, jwk, _items)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async postTx(tx, jwk, items = []) {
|
|
91
|
-
let err = null
|
|
92
|
-
;({ err, jwk } = await this.checkWallet({ jwk }))
|
|
93
|
-
if (err) return { err }
|
|
94
|
-
|
|
95
|
-
let res = null
|
|
96
|
-
if (!tx.id) await this.mem.arweave.transactions.sign(tx, jwk)
|
|
97
|
-
let height = (await this.mem.get("height")) + 1
|
|
98
|
-
await this.mem.set(height, "height")
|
|
99
|
-
let block = {
|
|
100
|
-
id: tx.id,
|
|
101
|
-
timestamp: Date.now(),
|
|
102
|
-
height,
|
|
103
|
-
previous: last(await this.mem.get("blocks")) ?? "",
|
|
104
|
-
txs: [],
|
|
105
|
-
}
|
|
106
|
-
let msg = null
|
|
107
|
-
if (items) {
|
|
108
|
-
for (const item of items) {
|
|
109
|
-
let _txs = item
|
|
110
|
-
_txs.parent = { id: tx.id }
|
|
111
|
-
_txs.bundledIn = { id: tx.id }
|
|
112
|
-
_txs.anchor = ""
|
|
113
|
-
const _tags = t(item.tags)
|
|
114
|
-
if (
|
|
115
|
-
includes(_tags.Type, [
|
|
116
|
-
"Message",
|
|
117
|
-
"Process",
|
|
118
|
-
"Module",
|
|
119
|
-
"Scheduler-Location",
|
|
120
|
-
"Attestation",
|
|
121
|
-
"Available",
|
|
122
|
-
])
|
|
123
|
-
) {
|
|
124
|
-
msg = { id: item.id, type: _tags.Type }
|
|
125
|
-
if (msg.type === "Process") msg.pid = item.recipient
|
|
126
|
-
}
|
|
127
|
-
let data_type = ""
|
|
128
|
-
for (const v of item.item.tags) {
|
|
129
|
-
if (v.name === "Content-Type") data_type = v.value
|
|
130
|
-
}
|
|
131
|
-
block.txs.push(item.id)
|
|
132
|
-
_txs.block = block.id
|
|
133
|
-
await this.mem.set(_txs, "txs", item.id)
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
let _tags = []
|
|
137
|
-
for (const v of tx.tags) {
|
|
138
|
-
_tags.push({
|
|
139
|
-
name: base64url.decode(v.name),
|
|
140
|
-
value: base64url.decode(v.value),
|
|
141
|
-
})
|
|
142
|
-
}
|
|
143
|
-
const __tags = t(_tags)
|
|
144
|
-
if (__tags.Type === "Module") {
|
|
145
|
-
await this.mem.set(
|
|
146
|
-
{
|
|
147
|
-
data: Buffer.from(tx.data, "base64"),
|
|
148
|
-
format: __tags["Module-Format"],
|
|
149
|
-
},
|
|
150
|
-
"wasms",
|
|
151
|
-
tx.id,
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
tx.tags = _tags
|
|
155
|
-
tx.owner = await this.arweave.wallets.jwkToAddress({ n: tx.owner })
|
|
156
|
-
let _txs = tx
|
|
157
|
-
block.txs.push(tx.id)
|
|
158
|
-
_txs.block = block.id
|
|
159
|
-
await this.mem.set(_txs, "txs", tx.id)
|
|
160
|
-
let blocks = await this.mem.get("blocks")
|
|
161
|
-
blocks.push(block.id)
|
|
162
|
-
await this.mem.set(blocks, "blocks")
|
|
163
|
-
await this.mem.set(block, "blockmap", block.id)
|
|
164
|
-
|
|
165
|
-
if (jwk) {
|
|
166
|
-
const owner = await this.arweave.wallets.jwkToAddress(jwk)
|
|
167
|
-
await this.mem.set({ address: owner, key: jwk.n }, "addrmap", owner)
|
|
168
|
-
}
|
|
169
|
-
res = { id: tx.id, status: 200, statusText: "200" }
|
|
170
|
-
if (this.log) {
|
|
171
|
-
if (msg) {
|
|
172
|
-
console.log(
|
|
173
|
-
`New ${msg.type}:\t${msg.id}${msg.pid ? ` > ${msg.pid}` : ""}`,
|
|
174
|
-
)
|
|
175
|
-
} else {
|
|
176
|
-
console.log(`New Post:\t${tx.id}`)
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return { res, err, id: tx.id }
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async tx(id) {
|
|
183
|
-
return await this.mem.get("txs", id)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async data(id, _string, log) {
|
|
187
|
-
let decode = true
|
|
188
|
-
let string = _string
|
|
189
|
-
if (is(Object, _string)) {
|
|
190
|
-
if (!isNil(_string.decode)) decode = _string.decode
|
|
191
|
-
if (!isNil(_string.string)) string = _string.string
|
|
192
|
-
}
|
|
193
|
-
let tx = await this.mem.get("txs", id)
|
|
194
|
-
let _data = tx?.data ?? null
|
|
195
|
-
if (tx?.format === 2 && _data) {
|
|
196
|
-
_data = Buffer.from(_data, "base64")
|
|
197
|
-
} else if (_data) {
|
|
198
|
-
_data = Buffer.from(base64url.decode(_data))
|
|
199
|
-
}
|
|
200
|
-
let isBuf = is(Uint8Array, _data) || is(ArrayBuffer, _data)
|
|
201
|
-
let isStr = is(String, _data)
|
|
202
|
-
if (decode === false) {
|
|
203
|
-
if (isStr) _data = new TextEncoder().encode(_data)
|
|
204
|
-
return base64url.encode(_data)
|
|
205
|
-
} else {
|
|
206
|
-
if (isBuf && string) {
|
|
207
|
-
return _data.toString()
|
|
208
|
-
} else if (isStr && string !== true) {
|
|
209
|
-
return new TextEncoder().encode(_data)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return _data
|
|
6
|
+
super({ ...opt, ArMem })
|
|
213
7
|
}
|
|
214
8
|
}
|
|
215
9
|
|
package/esm/web.js
CHANGED
|
@@ -5,7 +5,6 @@ import AR from "./war.js"
|
|
|
5
5
|
import GQL from "./tgql.js"
|
|
6
6
|
import ArMem from "./armem-web.js"
|
|
7
7
|
import { dirname } from "./utils.js"
|
|
8
|
-
|
|
9
8
|
const scheduler = "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA"
|
|
10
9
|
|
|
11
10
|
export { GQL, ArMem, AO, AR, connect, acc, mu, su, cu, scheduler }
|