wao 0.32.1 → 0.32.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/send.js CHANGED
@@ -4,6 +4,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.httpSigName = void 0;
7
8
  exports.send = send;
8
9
  exports.toHttpSigner = void 0;
9
10
  var _base64url = _interopRequireDefault(require("base64url"));
@@ -99,7 +100,7 @@ function _send() {
99
100
  }));
100
101
  return _send.apply(this, arguments);
101
102
  }
102
- var httpSigName = function httpSigName(address) {
103
+ var httpSigName = exports.httpSigName = function httpSigName(address) {
103
104
  var decoded = _base64url["default"].toBuffer(address);
104
105
  var hexString = _toConsumableArray(decoded.subarray(1, 9)).map(function (_byte) {
105
106
  return _byte.toString(16).padStart(2, "0");
@@ -135,8 +136,11 @@ var toHttpSigner = exports.toHttpSigner = function toHttpSigner(signer) {
135
136
  alg: alg
136
137
  }
137
138
  });
139
+
140
+ // SORT THE FIELDS HERE to match Erlang's lists:sort(maps:keys(Enc))
141
+ var sortedFields = _toConsumableArray(fields).sort();
138
142
  var signatureBaseArray = createSignatureBase({
139
- fields: fields
143
+ fields: sortedFields
140
144
  }, request);
141
145
  signatureInput = (0, _structuredHeaders.serializeList)([[signatureBaseArray.map(function (_ref3) {
142
146
  var _ref4 = _slicedToArray(_ref3, 1),
@@ -9,6 +9,6 @@
9
9
  "deploy": "node scripts/deploy.js"
10
10
  },
11
11
  "dependencies": {
12
- "wao": "^0.32.1"
12
+ "wao": "^0.32.2"
13
13
  }
14
14
  }
package/esm/hb.js CHANGED
@@ -53,6 +53,7 @@ class HB {
53
53
  if (!this._info) {
54
54
  try {
55
55
  this._info = await this.g("/~meta@1.0/info")
56
+ this.operator = this._info.address
56
57
  } catch (e) {}
57
58
  }
58
59
  }
@@ -109,44 +110,15 @@ class HB {
109
110
  return JSON.parse(json.results.json.body)
110
111
  }
111
112
 
112
- async spawn(tags = {}) {
113
- const addr = await this.g("/~meta@1.0/info/address")
114
- this.scheduler ??= addr
115
- const res = await this.post({
116
- path: "/~process@1.0/schedule",
117
- body: mergeLeft(tags, {
118
- device: "process@1.0",
119
- "random-seed": seed(16),
120
- type: "Process",
121
- "execution-device": "test-device@1.0",
122
- }),
123
- scheduler: this.scheduler,
124
- })
125
- return { res, pid: res.out.process }
126
- }
127
- async spawn2(tags = {}) {
128
- const addr = await this.g("/~meta@1.0/info/address")
129
- this.scheduler ??= addr
130
- const _tags = mergeLeft(tags, {
131
- path: "/~process@1.0/schedule",
132
- scheduler: this.scheduler,
133
- "random-seed": seed(16),
134
- type: "Process",
135
- "execution-device": "test-device@1.0",
136
- })
137
- const res = await this.post(_tags, { path: false })
138
- return { res, pid: res.headers.process }
139
- }
140
-
141
113
  async cacheScript(data, type = "application/lua") {
142
114
  if (!this.cache) {
143
115
  const { pid } = await this.spawn({})
144
116
  this.cache = pid
145
117
  }
146
- const { slot } = await this.schedule({
118
+ const { slot } = await this.scheduleFlat({
147
119
  data,
148
120
  pid: this.cache,
149
- "content-type": type,
121
+ tags: { "content-type": type },
150
122
  })
151
123
  const msgs = await this.messages({ pid: this.cache, from: slot, limit: 1 })
152
124
  return msgs.edges[0].node.message.Id
@@ -154,7 +126,7 @@ class HB {
154
126
 
155
127
  async cacheBinary(data, type) {
156
128
  const res = await this.post({ path: "/~wao@1.0/cache_module", data, type })
157
- return res.headers.id
129
+ return res.out.id
158
130
  }
159
131
 
160
132
  async message(args) {
@@ -163,70 +135,49 @@ class HB {
163
135
  const res = await this.compute({ pid, slot })
164
136
  return { slot, pid, res }
165
137
  }
166
- async schedule2({ pid, tags = {}, data } = {}) {
167
- let _tags = mergeLeft(tags, {
168
- method: "POST",
169
- path: `/${pid}/schedule`,
170
- type: "Message",
171
- target: pid,
172
- })
138
+
139
+ async scheduleFlat({ pid, tags = {}, data } = {}) {
140
+ let _tags = mergeLeft(tags, { type: "Message", target: pid })
173
141
  if (data) _tags.data = data
174
- let res = await this.post(_tags, { path: false })
175
- return { slot: res.headers.slot, res, pid }
176
- }
177
- async scheduleLegacy2({
178
- pid,
179
- action = "Eval",
180
- tags = {},
181
- data,
182
- scheduler,
183
- } = {}) {
184
- return await this.scheduleLua({ pid, action, tags, data, scheduler })
142
+ let res = await this.post({ path: "/~process@1.0/schedule", body: _tags })
143
+ return { slot: res.out.slot, res, pid }
185
144
  }
186
145
 
187
- async scheduleLua({ pid, action = "Eval", tags = {}, data, scheduler }) {
188
- if (action) tags.Action = action
189
- let _tags = mergeLeft(tags, {
190
- path: `/${pid}/schedule`,
191
- type: "Message",
192
- target: pid,
146
+ async scheduleNP({ pid, tags = {}, data } = {}) {
147
+ if (data) tags.data = data
148
+ let res = await this.post({
149
+ path: `/${pid}~node-process@1.0/schedule`,
150
+ body: await this.commit(tags),
193
151
  })
152
+ return { slot: res.out.slot, res, pid }
153
+ }
154
+ async schedule({ pid, tags = {}, data } = {}) {
155
+ let _tags = mergeLeft(tags, { type: "Message", target: pid })
194
156
  if (data) _tags.data = data
195
- let res = await this.post(_tags, { path: false })
196
- return { slot: res.headers.slot, res, pid }
157
+ let res = await this.post({
158
+ path: `/${pid}/schedule`,
159
+ body: await this.commit(_tags, { path: false }),
160
+ })
161
+ return { slot: res.out.slot, res, pid }
197
162
  }
198
163
 
199
- async schedule({ pid, tags = {}, data } = {}) {
200
- let body = mergeLeft(tags, { type: "Message", target: pid })
201
- if (data) body.data = data
202
- let res = await this.post({ path: "/~process@1.0/schedule", body })
203
- return { slot: res.headers.slot, res, pid }
164
+ async scheduleLua({ action = "Eval", tags = {}, ...rest }) {
165
+ if (action) tags.Action = action
166
+ return await this.schedule({ tags, ...rest })
204
167
  }
205
168
 
206
169
  async spawnLua(lua) {
207
- const addr = await this.g("/~meta@1.0/info/address")
208
- this.scheduler ??= addr
209
- lua ??= this.lua ?? (await this.getLua())
210
- const res = await this.post(
211
- {
212
- device: "process@1.0",
213
- path: "/schedule",
214
- scheduler: this.scheduler,
215
- "data-protocol": "ao",
216
- variant: "ao.N.1",
217
- "scheduler-location": this.scheduler,
218
- authority: this.scheduler,
219
- "random-seed": seed(16),
220
- type: "Process",
221
- module: lua,
222
- "execution-device": "lua@5.3a",
223
- "push-device": "push@1.0",
224
- "patch-from": "/results/outbox",
225
- },
226
- { path: false }
227
- )
228
- const pid = res.headers.process
229
- return { pid, res }
170
+ await this.setInfo()
171
+ const tags = {
172
+ "data-protocol": "ao",
173
+ variant: "ao.N.1",
174
+ authority: this.operator,
175
+ module: this.lua ?? (await this.getLua()),
176
+ "execution-device": "lua@5.3a",
177
+ "push-device": "push@1.0",
178
+ "patch-from": "/results/outbox",
179
+ }
180
+ return this.spawn(tags)
230
181
  }
231
182
 
232
183
  async now({ pid, path = "" }) {
@@ -255,65 +206,42 @@ class HB {
255
206
  }
256
207
  return res
257
208
  }
209
+ async spawn(tags = {}) {
210
+ const res = await this.post({
211
+ path: "/~process@1.0/schedule",
212
+ body: await this.commit(
213
+ mergeLeft(tags, {
214
+ "random-seed": seed(16),
215
+ type: "Process",
216
+ "execution-device": "test-device@1.0",
217
+ device: "process@1.0",
218
+ scheduler: this.addr,
219
+ }),
220
+ { path: false }
221
+ ),
222
+ scheduler: this.operator,
223
+ })
224
+ return { res, pid: res.out.process }
225
+ }
258
226
  async spawnLegacy({ module, tags = {}, data } = {}) {
259
227
  await this.setInfo()
260
- let t = {
261
- type: "Process",
228
+ let t = mergeLeft(tags, {
262
229
  "data-protocol": "ao",
263
230
  variant: "ao.TN.1",
264
- scheduler: this._info.address,
265
231
  authority: this._info.address,
266
- "scheduler-location": this._info.address,
267
- "random-seed": seed(16),
268
232
  module: module ?? "ISShJH1ij-hPPt9St5UFFr_8Ys3Kj5cyg7zrMGt7H9s",
269
233
  device: "process@1.0",
270
- "scheduler-device": "scheduler@1.0",
271
234
  "execution-device": "stack@1.0",
272
235
  "push-device": "push@1.0",
273
236
  "device-stack": ["genesis-wasm@1.0", "patch@1.0"],
274
237
  "patch-from": "/results/outbox",
275
- "stack-keys": ["init", "compute", "snapshot", "normalize"],
276
- }
238
+ })
277
239
  if (data) t.data = data
278
- tags = mergeLeft(tags, t)
279
- return await this.spawn2(tags)
280
- }
281
- async scheduleLegacy({
282
- pid,
283
- action = "Eval",
284
- tags = {},
285
- data,
286
- scheduler,
287
- } = {}) {
288
- if (action) tags.Action = action
289
- return await this.schedule2({ pid, tags, data, scheduler })
240
+ return await this.spawn(t)
290
241
  }
291
-
292
- async spawnLegacy2({ module, tags = {}, data } = {}) {
293
- await this.setInfo()
294
- let t = {
295
- type: "Process",
296
- "data-protocol": "ao",
297
- variant: "ao.TN.1",
298
- scheduler: this._info.address,
299
- authority: this._info.address,
300
- "scheduler-location": this._info.address,
301
- "random-seed": seed(16),
302
- module: module ?? "ISShJH1ij-hPPt9St5UFFr_8Ys3Kj5cyg7zrMGt7H9s",
303
- device: "process@1.0",
304
- "scheduler-device": "scheduler@1.0",
305
- "execution-device": "stack@1.0",
306
- "push-device": "push@1.0",
307
- "device-stack": ["genesis-wasm@1.0", "patch@1.0"],
308
- "patch-from": "/results/outbox",
309
- "stack-keys": ["init", "compute", "snapshot", "normalize"],
310
- path: "/~process@1.0/schedule",
311
- }
312
- if (data) t.data = data
313
- tags = mergeLeft(tags, t)
314
- const res = await this.post(t, { path: false })
315
- const pid = res.headers.process
316
- return { pid, res }
242
+ async scheduleLegacy({ action = "Eval", tags = {}, ...rest } = {}) {
243
+ if (action) tags.Action = action
244
+ return await this.schedule({ tags, ...rest })
317
245
  }
318
246
 
319
247
  async results({ process, limit, sort = "DESC", from, to } = {}) {
@@ -426,84 +354,12 @@ class HB {
426
354
  return JSON.parse(res.body)
427
355
  }
428
356
  async spawnAOS(image) {
429
- const addr = await this.g("/~meta@1.0/info/address")
430
- this.scheduler ??= addr
431
- image ??= this.image ?? (await this.getImage())
432
- const res = await this.post(
433
- {
434
- device: "process@1.0",
435
- path: "/schedule",
436
- scheduler: this.scheduler,
437
- "data-protocol": "ao",
438
- variant: "ao.N.1",
439
- "scheduler-location": this.scheduler,
440
- authority: this.scheduler,
441
- "random-seed": seed(16),
442
- type: "Process",
443
- image,
444
- "execution-device": "stack@1.0",
445
- "push-device": "push@1.0",
446
- "device-stack": [
447
- "wasi@1.0",
448
- "json-iface@1.0",
449
- "wasm-64@1.0",
450
- "patch@1.0",
451
- "multipass@1.0",
452
- ],
453
- "output-prefix": "wasm",
454
- "patch-from": "/results/outbox",
455
- "patch-mode": "patches",
456
- "stack-keys": ["init", "compute", "snapshot", "normalize"],
457
- passes: 2,
458
- },
459
- { path: false }
460
- )
461
- const pid = res.headers.process
462
- return { pid, res }
463
- }
464
- async scheduleAOS({ pid, action = "Eval", tags = {}, data }) {
465
- let _tags = mergeLeft(tags, {
466
- device: "process@1.0",
467
- method: "POST",
468
- path: `/${pid}~process@1.0/schedule`,
469
- scheduler: this.scheduler,
470
- type: "Message",
471
- Action: action,
472
- target: pid,
473
- })
474
- if (data) _tags.data = data
475
- let res = await this.post(_tags, { path: false })
476
- const slot = res.headers.slot
477
- return { slot, res, pid }
478
- }
479
- /*
480
- async scheduleAOS2({ pid, action = "Eval", tags = {}, data }) {
481
- let _tags = mergeLeft(tags, {
482
- device: "process@1.0",
483
- type: "Message",
484
- Action: action,
485
- target: pid,
486
- })
487
-
488
- if (data) _tags.data = data
489
- const msg = { body: _tags, path: `/${pid}~process@1.0/schedule` }
490
- let res = await this.post(msg, { path: false })
491
- const slot = res.headers.slot
492
- return { slot, res, pid }
493
- }
494
- async spawnAOS2(image) {
495
- const addr = await this.g("/~meta@1.0/info/address")
496
- this.scheduler ??= addr
357
+ await this.setInfo()
497
358
  image ??= this.image ?? (await this.getImage())
498
- const _tags = {
499
- device: "process@1.0",
500
- scheduler: this.scheduler,
359
+ const tags = {
501
360
  "data-protocol": "ao",
502
361
  variant: "ao.N.1",
503
- "scheduler-location": this.scheduler,
504
- authority: this.scheduler,
505
- "random-seed": seed(16),
506
- type: "Process",
362
+ authority: this.operator,
507
363
  image,
508
364
  "execution-device": "stack@1.0",
509
365
  "push-device": "push@1.0",
@@ -517,21 +373,15 @@ class HB {
517
373
  "output-prefix": "wasm",
518
374
  "patch-from": "/results/outbox",
519
375
  "patch-mode": "patches",
520
- "stack-keys": ["init", "compute", "snapshot", "normalize"],
521
376
  passes: 2,
522
377
  }
523
- const msg = {
524
- device: "process@1.0",
525
- path: "schedule",
526
- body: _tags,
527
- scheduler: this.scheduler,
528
- }
378
+ return await this.spawn(tags)
379
+ }
529
380
 
530
- const res = await this.post(msg, { path: false })
531
- const pid = res.headers.process
532
- return { pid, res }
381
+ async scheduleAOS({ action = "Eval", tags = {}, ...rest }) {
382
+ if (action) tags.Action = action
383
+ return await this.schedule({ tags, ...rest })
533
384
  }
534
- */
535
385
  }
536
386
 
537
387
  export default HB
package/esm/send.js CHANGED
@@ -36,7 +36,7 @@ export async function send(signedMsg, fetchImpl = fetch) {
36
36
  return { ...from(http), ...http }
37
37
  }
38
38
 
39
- const httpSigName = address => {
39
+ export const httpSigName = address => {
40
40
  const decoded = base64url.toBuffer(address)
41
41
  const hexString = [...decoded.subarray(1, 9)]
42
42
  .map(byte => byte.toString(16).padStart(2, "0"))
@@ -76,7 +76,13 @@ export const toHttpSigner = signer => {
76
76
  },
77
77
  })
78
78
 
79
- const signatureBaseArray = createSignatureBase({ fields }, request)
79
+ // SORT THE FIELDS HERE to match Erlang's lists:sort(maps:keys(Enc))
80
+ const sortedFields = [...fields].sort()
81
+
82
+ const signatureBaseArray = createSignatureBase(
83
+ { fields: sortedFields },
84
+ request
85
+ )
80
86
  signatureInput = serializeList([
81
87
  [
82
88
  signatureBaseArray.map(([item]) => parseItem(item)),
@@ -89,7 +95,6 @@ export const toHttpSigner = signer => {
89
95
  return new TextEncoder().encode(signatureBase)
90
96
  }
91
97
  const result = await signer(create, "httpsig")
92
-
93
98
  if (!createCalled) {
94
99
  throw new Error(
95
100
  "create() must be invoked in order to construct the data to sign"
@@ -107,7 +112,6 @@ export const toHttpSigner = signer => {
107
112
  signatureInput,
108
113
  httpSigName(result.address)
109
114
  )
110
-
111
115
  const finalHeaders = {}
112
116
  for (const [key, value] of Object.entries(signedHeaders)) {
113
117
  if (key === "Signature" || key === "Signature-Input") {
package/esm/signer.js CHANGED
@@ -52,7 +52,6 @@ async function _sign({
52
52
  return key !== "body-keys" && key !== "path" && !bodyKeys.includes(key)
53
53
  })
54
54
  if (_path !== false && isPath) signingFields.push("@path")
55
-
56
55
  const signedRequest = await toHttpSigner(signer)({
57
56
  request: { url: _url, method, headers: lowercaseHeaders },
58
57
  fields: signingFields,
@@ -9,6 +9,6 @@
9
9
  "deploy": "node scripts/deploy.js"
10
10
  },
11
11
  "dependencies": {
12
- "wao": "^0.32.1"
12
+ "wao": "^0.32.2"
13
13
  }
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wao",
3
- "version": "0.32.1",
3
+ "version": "0.32.2",
4
4
  "bin": {
5
5
  "wao": "./cjs/cli.js",
6
6
  "wao-esm": "./esm/cli.js"