@leofcoin/chain 1.10.21 → 1.11.0
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/README.md +95 -0
- package/exports/browser/beacon-wire.js +2 -2
- package/exports/browser/{browser-CCfR9KOM-BGMMnVsR.js → browser-CCfR9KOM-CNWKLusu.js} +3 -3
- package/exports/browser/{browser-crypto-CH0ua22L.js → browser-crypto-B_UJguhk.js} +453 -35
- package/exports/browser/chain.js +1275 -996
- package/exports/browser/client-DbZBfpG6-C1cXgvfr.js +5943 -0
- package/exports/browser/{connection-monitor-D-krNiRH.js → connection-monitor-BzbeYGEt.js} +153 -24
- package/exports/browser/{index-dTQVgkpf-DOL2rIjp.js → index-dTQVgkpf-CkoAiRNX.js} +3 -3
- package/exports/browser/{index-DCbLvMKL.js → index-phv5KvaE.js} +238 -234
- package/exports/browser/{messages-DCePyqKC-BSvJxDWZ.js → messages-DZYCxoZI-B472zldo.js} +3 -3
- package/exports/browser/{node-browser-Ha4Lvntj.js → node-browser-BmyPBkL5.js} +55 -11
- package/exports/browser/node-browser.js +3 -3
- package/exports/browser/workers/block-worker.js +8 -9
- package/exports/browser/workers/machine-worker.js +141 -1195
- package/exports/{workers/worker-BDTWOCzS-COrAszCt.js → browser/workers/proposal.proto-8zgMfutf-B3So_tnS.js} +910 -398
- package/exports/chain.js +296 -1078
- package/exports/connection-monitor-BdFLRh-J.js +465 -0
- package/exports/connection-monitor.js +2 -324
- package/exports/{constants-Dy9i9S_o.js → constants-BQ6f-_OT.js} +1 -1
- package/exports/hash-format-state.js +3 -3
- package/exports/machine.js +550 -0
- package/exports/node.js +35 -2
- package/exports/state-checkpoint-BiQ1EXzo.js +110 -0
- package/exports/state-checkpoint.js +3 -0
- package/exports/workers/block-worker.js +8 -9
- package/exports/workers/machine-worker.js +141 -1195
- package/exports/{browser/workers/worker-BDTWOCzS-COrAszCt.js → workers/proposal.proto-8zgMfutf-B3So_tnS.js} +910 -398
- package/package.json +9 -7
- package/exports/browser/client-DKKzPSlb-C_1ug6ux.js +0 -2401
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { a as index$3, b as base58$1, i as index$4, f as fromBase58, c as fromHex, d as fromArrayLike, e as toBase32, t as toBase58, g as toHex } from './index-CvKt4UDE.js';
|
|
2
2
|
import { s as sha256 } from './sha2-BKcEJzgd.js';
|
|
3
3
|
|
|
4
|
-
var isHex = string => /^[A-F0-9]+$/i.test(
|
|
5
|
-
string.startsWith('0x') ?
|
|
6
|
-
string.slice(2) :
|
|
7
|
-
string
|
|
8
|
-
);
|
|
9
|
-
|
|
10
4
|
const MAX_BIGINT = (1n << 256n) - 1n;
|
|
11
5
|
function size(value) {
|
|
12
6
|
if (!Number.isSafeInteger(value) || value < 0)
|
|
@@ -31,6 +25,10 @@ function varBigIntLength(value) {
|
|
|
31
25
|
if (value < 0n || value > MAX_BIGINT)
|
|
32
26
|
throw new RangeError("Expected an unsigned 256-bit integer");
|
|
33
27
|
let length = 1;
|
|
28
|
+
while (value >= 0x100000000000000n) {
|
|
29
|
+
value >>= 56n;
|
|
30
|
+
length += 8;
|
|
31
|
+
}
|
|
34
32
|
while (value >= 128n) {
|
|
35
33
|
value >>= 7n;
|
|
36
34
|
length++;
|
|
@@ -209,6 +207,280 @@ function decodeFrames(buffer, prefixLength = 0, options = {}) {
|
|
|
209
207
|
return frames;
|
|
210
208
|
}
|
|
211
209
|
|
|
210
|
+
const MAGIC = new Uint8Array([76, 70, 67, 1]);
|
|
211
|
+
const utf8 = new TextEncoder();
|
|
212
|
+
const text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
213
|
+
const defaults = { maxBytes: 16 * 1024 * 1024, maxDepth: 64, maxNodes: 2e5 };
|
|
214
|
+
const BIGINT_LIMB = 1n << 49n;
|
|
215
|
+
const BIGINT_MASK = BIGINT_LIMB - 1n;
|
|
216
|
+
const limitsFor = (options) => {
|
|
217
|
+
const limits = { ...defaults, ...options };
|
|
218
|
+
for (const value of Object.values(limits))
|
|
219
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
220
|
+
throw new RangeError("Invalid binary limits");
|
|
221
|
+
return limits;
|
|
222
|
+
};
|
|
223
|
+
function stringLength(value, maximum) {
|
|
224
|
+
if (value.length > maximum)
|
|
225
|
+
throw new RangeError("Invalid binary string");
|
|
226
|
+
let length = value.length;
|
|
227
|
+
for (let index = 0; index < value.length; index++) {
|
|
228
|
+
const code = value.charCodeAt(index);
|
|
229
|
+
if (code < 128)
|
|
230
|
+
continue;
|
|
231
|
+
if (code < 2048) {
|
|
232
|
+
length++;
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (code >= 55296 && code <= 56319) {
|
|
236
|
+
const low = value.charCodeAt(++index);
|
|
237
|
+
if (!(low >= 56320 && low <= 57343))
|
|
238
|
+
throw new RangeError("Invalid binary string");
|
|
239
|
+
length += 2;
|
|
240
|
+
} else {
|
|
241
|
+
if (code >= 56320 && code <= 57343)
|
|
242
|
+
throw new RangeError("Invalid binary string");
|
|
243
|
+
length += 2;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return length;
|
|
247
|
+
}
|
|
248
|
+
function encodeValue(value, options = {}) {
|
|
249
|
+
return encodeValueWithPrefix(value, EMPTY, options);
|
|
250
|
+
}
|
|
251
|
+
const EMPTY = new Uint8Array();
|
|
252
|
+
function encodeValueWithPrefix(value, prefix, options = {}) {
|
|
253
|
+
if (!(prefix instanceof Uint8Array))
|
|
254
|
+
throw new TypeError("Expected Uint8Array prefix");
|
|
255
|
+
const limits = limitsFor(options);
|
|
256
|
+
const plan = [];
|
|
257
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
258
|
+
let size = MAGIC.length;
|
|
259
|
+
let nodes = 0;
|
|
260
|
+
const reserve = (length) => {
|
|
261
|
+
size += length;
|
|
262
|
+
if (size > limits.maxBytes)
|
|
263
|
+
throw new RangeError("Binary value exceeds byte limit");
|
|
264
|
+
};
|
|
265
|
+
const string = (value2, tag) => {
|
|
266
|
+
const length = stringLength(value2, limits.maxBytes);
|
|
267
|
+
reserve((tag === 7 ? 1 : 0) + varUintLength(length) + length);
|
|
268
|
+
plan.push(tag, value2, length);
|
|
269
|
+
};
|
|
270
|
+
const visit = (value2, depth) => {
|
|
271
|
+
if (++nodes > limits.maxNodes || depth > limits.maxDepth)
|
|
272
|
+
throw new RangeError("Binary value exceeds complexity limit");
|
|
273
|
+
if (value2 === void 0 || value2 === null || typeof value2 === "boolean") {
|
|
274
|
+
reserve(1);
|
|
275
|
+
plan.push(value2 === void 0 ? 0 : value2 === null ? 1 : value2 === false ? 2 : 3);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (typeof value2 === "number") {
|
|
279
|
+
if (!Number.isFinite(value2))
|
|
280
|
+
throw new TypeError("Binary numbers must be finite");
|
|
281
|
+
reserve(9);
|
|
282
|
+
plan.push(4, value2);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (typeof value2 === "bigint") {
|
|
286
|
+
const magnitude = value2 < 0n ? -value2 : value2;
|
|
287
|
+
reserve(1 + varBigIntLength(magnitude));
|
|
288
|
+
plan.push(value2 < 0n ? 6 : 5, magnitude);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (typeof value2 === "string")
|
|
292
|
+
return string(value2, 7);
|
|
293
|
+
if (value2 instanceof Uint8Array) {
|
|
294
|
+
reserve(1 + varUintLength(value2.length) + value2.length);
|
|
295
|
+
plan.push(8, value2, value2.length);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (typeof value2 !== "object")
|
|
299
|
+
throw new TypeError("Unsupported binary value");
|
|
300
|
+
if (ancestors.has(value2))
|
|
301
|
+
throw new TypeError("Cyclic binary value");
|
|
302
|
+
ancestors.add(value2);
|
|
303
|
+
try {
|
|
304
|
+
if (Array.isArray(value2)) {
|
|
305
|
+
if (value2.length > limits.maxNodes - nodes)
|
|
306
|
+
throw new RangeError("Binary array exceeds node limit");
|
|
307
|
+
if (Object.keys(value2).length !== value2.length || Object.getOwnPropertySymbols(value2).length)
|
|
308
|
+
throw new TypeError("Binary arrays cannot have extra properties or holes");
|
|
309
|
+
reserve(1 + varUintLength(value2.length));
|
|
310
|
+
plan.push(9, value2.length);
|
|
311
|
+
for (let index = 0; index < value2.length; index++) {
|
|
312
|
+
const entry = Object.getOwnPropertyDescriptor(value2, String(index));
|
|
313
|
+
if (!entry || !("value" in entry))
|
|
314
|
+
throw new TypeError("Sparse arrays and accessors are not binary values");
|
|
315
|
+
visit(entry.value, depth + 1);
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
const prototype = Object.getPrototypeOf(value2);
|
|
319
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
320
|
+
throw new TypeError("Binary maps must be plain objects");
|
|
321
|
+
const keys = Object.keys(value2).sort();
|
|
322
|
+
if (Object.getOwnPropertySymbols(value2).length)
|
|
323
|
+
throw new TypeError("Symbol keys are not binary values");
|
|
324
|
+
if (keys.length > limits.maxNodes - nodes)
|
|
325
|
+
throw new RangeError("Binary map exceeds node limit");
|
|
326
|
+
reserve(1 + varUintLength(keys.length));
|
|
327
|
+
plan.push(10, keys.length);
|
|
328
|
+
for (const key of keys) {
|
|
329
|
+
const entry = Object.getOwnPropertyDescriptor(value2, key);
|
|
330
|
+
if (!("value" in entry))
|
|
331
|
+
throw new TypeError("Accessors are not binary values");
|
|
332
|
+
string(key, 11);
|
|
333
|
+
visit(entry.value, depth + 1);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
} finally {
|
|
337
|
+
ancestors.delete(value2);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
visit(value, 0);
|
|
341
|
+
const capacity = prefix.length + size;
|
|
342
|
+
if (!Number.isSafeInteger(capacity))
|
|
343
|
+
throw new RangeError("Binary output is too large");
|
|
344
|
+
const output = new Uint8Array(capacity);
|
|
345
|
+
output.set(prefix);
|
|
346
|
+
output.set(MAGIC, prefix.length);
|
|
347
|
+
let position = prefix.length + MAGIC.length;
|
|
348
|
+
let view;
|
|
349
|
+
const uint = (value2) => {
|
|
350
|
+
while (value2 >= 128) {
|
|
351
|
+
output[position++] = value2 % 128 | 128;
|
|
352
|
+
value2 = Math.floor(value2 / 128);
|
|
353
|
+
}
|
|
354
|
+
output[position++] = value2;
|
|
355
|
+
};
|
|
356
|
+
for (let cursor = 0; cursor < plan.length; ) {
|
|
357
|
+
const tag = plan[cursor++];
|
|
358
|
+
if (tag !== 11)
|
|
359
|
+
output[position++] = tag;
|
|
360
|
+
if (tag < 4)
|
|
361
|
+
continue;
|
|
362
|
+
if (tag === 4) {
|
|
363
|
+
view ??= new DataView(output.buffer);
|
|
364
|
+
view.setFloat64(position, plan[cursor++], false);
|
|
365
|
+
position += 8;
|
|
366
|
+
} else if (tag === 5 || tag === 6) {
|
|
367
|
+
let value2 = plan[cursor++];
|
|
368
|
+
while (value2 >= BIGINT_LIMB) {
|
|
369
|
+
let limb = Number(value2 & BIGINT_MASK);
|
|
370
|
+
for (let index = 0; index < 7; index++) {
|
|
371
|
+
output[position++] = limb % 128 | 128;
|
|
372
|
+
limb = Math.floor(limb / 128);
|
|
373
|
+
}
|
|
374
|
+
value2 >>= 49n;
|
|
375
|
+
}
|
|
376
|
+
uint(Number(value2));
|
|
377
|
+
} else if (tag === 7 || tag === 11) {
|
|
378
|
+
const value2 = plan[cursor++];
|
|
379
|
+
const length = plan[cursor++];
|
|
380
|
+
uint(length);
|
|
381
|
+
if (length === value2.length) {
|
|
382
|
+
for (let index = 0; index < length; index++)
|
|
383
|
+
output[position++] = value2.charCodeAt(index);
|
|
384
|
+
} else {
|
|
385
|
+
const result = utf8.encodeInto(value2, output.subarray(position, position + length));
|
|
386
|
+
if (result.read !== value2.length || result.written !== length)
|
|
387
|
+
throw new Error("UTF-8 planning mismatch");
|
|
388
|
+
position += length;
|
|
389
|
+
}
|
|
390
|
+
} else if (tag === 8) {
|
|
391
|
+
const value2 = plan[cursor++];
|
|
392
|
+
const length = plan[cursor++];
|
|
393
|
+
if (value2.length !== length)
|
|
394
|
+
throw new RangeError("Byte input changed while encoding");
|
|
395
|
+
uint(length);
|
|
396
|
+
output.set(value2, position);
|
|
397
|
+
position += length;
|
|
398
|
+
} else {
|
|
399
|
+
uint(plan[cursor++]);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (position !== capacity)
|
|
403
|
+
throw new Error("Binary planning mismatch");
|
|
404
|
+
return output;
|
|
405
|
+
}
|
|
406
|
+
function decodeValue(input, options = {}) {
|
|
407
|
+
const limits = limitsFor(options);
|
|
408
|
+
if (!(input instanceof Uint8Array))
|
|
409
|
+
throw new TypeError("Wire payload must be Uint8Array");
|
|
410
|
+
if (input.length > limits.maxBytes)
|
|
411
|
+
throw new RangeError("Binary value exceeds byte limit");
|
|
412
|
+
const reader = new BinaryReader(input);
|
|
413
|
+
if (reader.readBytes(MAGIC.length).some((byte, index) => byte !== MAGIC[index]))
|
|
414
|
+
throw new TypeError("Unsupported binary wire version");
|
|
415
|
+
let nodes = 0;
|
|
416
|
+
const string = () => text.decode(reader.readFrame());
|
|
417
|
+
const read = (depth) => {
|
|
418
|
+
if (++nodes > limits.maxNodes || depth > limits.maxDepth)
|
|
419
|
+
throw new RangeError("Binary value exceeds complexity limit");
|
|
420
|
+
const tag = reader.readBytes(1)[0];
|
|
421
|
+
if (tag === 0)
|
|
422
|
+
return void 0;
|
|
423
|
+
if (tag === 1)
|
|
424
|
+
return null;
|
|
425
|
+
if (tag === 2)
|
|
426
|
+
return false;
|
|
427
|
+
if (tag === 3)
|
|
428
|
+
return true;
|
|
429
|
+
if (tag === 4) {
|
|
430
|
+
const bytes = reader.readBytes(8);
|
|
431
|
+
const value2 = new DataView(bytes.buffer, bytes.byteOffset, 8).getFloat64(0, false);
|
|
432
|
+
if (!Number.isFinite(value2))
|
|
433
|
+
throw new TypeError("Binary numbers must be finite");
|
|
434
|
+
return value2;
|
|
435
|
+
}
|
|
436
|
+
if (tag === 5 || tag === 6) {
|
|
437
|
+
const value2 = reader.readVarBigInt();
|
|
438
|
+
if (tag === 6 && value2 === 0n)
|
|
439
|
+
throw new TypeError("Non-canonical negative zero");
|
|
440
|
+
return tag === 6 ? -value2 : value2;
|
|
441
|
+
}
|
|
442
|
+
if (tag === 7)
|
|
443
|
+
return string();
|
|
444
|
+
if (tag === 8)
|
|
445
|
+
return new Uint8Array(reader.readFrame());
|
|
446
|
+
if (tag === 9 || tag === 10) {
|
|
447
|
+
const count = reader.readVarUint();
|
|
448
|
+
if (count > limits.maxNodes - nodes || count > reader.remaining)
|
|
449
|
+
throw new RangeError("Invalid binary collection size");
|
|
450
|
+
if (tag === 9)
|
|
451
|
+
return Array.from({ length: count }, () => read(depth + 1));
|
|
452
|
+
const result = {};
|
|
453
|
+
let previous;
|
|
454
|
+
for (let index = 0; index < count; index++) {
|
|
455
|
+
const key = string();
|
|
456
|
+
if (previous !== void 0 && key <= previous)
|
|
457
|
+
throw new TypeError("Non-canonical binary map keys");
|
|
458
|
+
previous = key;
|
|
459
|
+
Object.defineProperty(result, key, { value: read(depth + 1), enumerable: true, writable: true, configurable: true });
|
|
460
|
+
}
|
|
461
|
+
return result;
|
|
462
|
+
}
|
|
463
|
+
throw new TypeError("Unknown binary value tag");
|
|
464
|
+
};
|
|
465
|
+
const value = read(0);
|
|
466
|
+
if (reader.remaining)
|
|
467
|
+
throw new TypeError("Trailing binary data");
|
|
468
|
+
return value;
|
|
469
|
+
}
|
|
470
|
+
const encodeWire = (channel, value, limits) => encodeValue([channel, value], limits);
|
|
471
|
+
function decodeWire(channel, bytes, limits) {
|
|
472
|
+
const envelope = decodeValue(bytes, limits);
|
|
473
|
+
if (!Array.isArray(envelope) || envelope.length !== 2 || envelope[0] !== channel)
|
|
474
|
+
throw new TypeError("Wrong binary message channel");
|
|
475
|
+
return envelope[1];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
var isHex = string => /^[A-F0-9]+$/i.test(
|
|
479
|
+
string.startsWith('0x') ?
|
|
480
|
+
string.slice(2) :
|
|
481
|
+
string
|
|
482
|
+
);
|
|
483
|
+
|
|
212
484
|
const asBytes = (source) => {
|
|
213
485
|
if (source instanceof Uint8Array)
|
|
214
486
|
return source;
|
|
@@ -8869,7 +9141,9 @@ const FormatInterface = FormatInterface$1;
|
|
|
8869
9141
|
*/
|
|
8870
9142
|
const Codec = Codec$1;
|
|
8871
9143
|
|
|
8872
|
-
|
|
9144
|
+
const defineSchema = (proto) => Object.freeze(proto);
|
|
9145
|
+
|
|
9146
|
+
var proto$b = defineSchema({
|
|
8873
9147
|
index: BigInt(0),
|
|
8874
9148
|
previousHash: String(),
|
|
8875
9149
|
timestamp: Number(),
|
|
@@ -8880,50 +9154,189 @@ var proto$8 = {
|
|
|
8880
9154
|
producer: String(),
|
|
8881
9155
|
producerProof: String(),
|
|
8882
9156
|
protocolVersion: String()
|
|
8883
|
-
};
|
|
9157
|
+
});
|
|
9158
|
+
|
|
9159
|
+
const schemas = /* @__PURE__ */ new WeakMap();
|
|
9160
|
+
const kindOf = (value) => value === void 0 ? "any" : value instanceof Uint8Array ? "bytes" : Array.isArray(value) ? "array" : typeof value;
|
|
9161
|
+
function schemaFor(proto) {
|
|
9162
|
+
const cached = schemas.get(proto);
|
|
9163
|
+
if (cached)
|
|
9164
|
+
return cached;
|
|
9165
|
+
const keys = Object.keys(proto);
|
|
9166
|
+
const schema = {
|
|
9167
|
+
fields: keys.map((key) => ({
|
|
9168
|
+
key,
|
|
9169
|
+
name: key.endsWith("?") ? key.slice(0, -1) : key,
|
|
9170
|
+
kind: kindOf(proto[key])
|
|
9171
|
+
})),
|
|
9172
|
+
prefixes: /* @__PURE__ */ new Map()
|
|
9173
|
+
};
|
|
9174
|
+
if (Object.isFrozen(proto) && keys.every((key) => "value" in Object.getOwnPropertyDescriptor(proto, key)))
|
|
9175
|
+
schemas.set(proto, schema);
|
|
9176
|
+
return schema;
|
|
9177
|
+
}
|
|
9178
|
+
function codecPrefix(schema, name) {
|
|
9179
|
+
let prefix = schema.prefixes.get(name);
|
|
9180
|
+
if (!prefix) {
|
|
9181
|
+
const codec = new Codec(name);
|
|
9182
|
+
if (!codec.codecBuffer)
|
|
9183
|
+
throw new Error("invalid codec");
|
|
9184
|
+
prefix = new Uint8Array(codec.codecBuffer);
|
|
9185
|
+
schema.prefixes.set(name, prefix);
|
|
9186
|
+
}
|
|
9187
|
+
return prefix;
|
|
9188
|
+
}
|
|
9189
|
+
class BinaryFormat extends FormatInterface {
|
|
9190
|
+
field(key, value, kind) {
|
|
9191
|
+
if (value === void 0)
|
|
9192
|
+
return value;
|
|
9193
|
+
kind ??= kindOf(this.proto[key]);
|
|
9194
|
+
if (kind === "any")
|
|
9195
|
+
return value;
|
|
9196
|
+
if (kind === "bigint") {
|
|
9197
|
+
if (typeof value === "number" && !Number.isSafeInteger(value))
|
|
9198
|
+
throw new TypeError("Unsafe integer message field");
|
|
9199
|
+
if (!["number", "string", "bigint"].includes(typeof value))
|
|
9200
|
+
throw new TypeError("Invalid BigInt message field");
|
|
9201
|
+
return BigInt(value);
|
|
9202
|
+
}
|
|
9203
|
+
if (kind === "bytes") {
|
|
9204
|
+
if (!(value instanceof Uint8Array))
|
|
9205
|
+
throw new TypeError("Message byte field must be Uint8Array");
|
|
9206
|
+
} else if (kind === "array") {
|
|
9207
|
+
if (!Array.isArray(value))
|
|
9208
|
+
throw new TypeError("Message array field must be an array");
|
|
9209
|
+
} else if (typeof value !== kind || value === null)
|
|
9210
|
+
throw new TypeError("Message field type mismatch");
|
|
9211
|
+
return value;
|
|
9212
|
+
}
|
|
9213
|
+
create(value) {
|
|
9214
|
+
const { fields } = schemaFor(this.proto);
|
|
9215
|
+
this.decoded = Object.fromEntries(fields.map((field) => {
|
|
9216
|
+
const input = value?.[field.name];
|
|
9217
|
+
return [field.name, field.kind === "bigint" ? this.field(field.key, input, field.kind) : input];
|
|
9218
|
+
}));
|
|
9219
|
+
}
|
|
9220
|
+
tuple(value, fields) {
|
|
9221
|
+
const tuple = new Array(fields.length);
|
|
9222
|
+
for (let index = 0; index < fields.length; index++) {
|
|
9223
|
+
const field = fields[index];
|
|
9224
|
+
tuple[index] = this.field(field.key, value[field.name], field.kind);
|
|
9225
|
+
}
|
|
9226
|
+
return tuple;
|
|
9227
|
+
}
|
|
9228
|
+
protoEncode(value) {
|
|
9229
|
+
return encodeValue(this.tuple(value, schemaFor(this.proto).fields));
|
|
9230
|
+
}
|
|
9231
|
+
encode(value) {
|
|
9232
|
+
value = value || this.decoded;
|
|
9233
|
+
const schema = schemaFor(this.proto);
|
|
9234
|
+
const prefix = codecPrefix(schema, this.name);
|
|
9235
|
+
if (value instanceof Uint8Array) {
|
|
9236
|
+
const output = new Uint8Array(prefix.length + value.length);
|
|
9237
|
+
output.set(prefix);
|
|
9238
|
+
output.set(value, prefix.length);
|
|
9239
|
+
this.encoded = output;
|
|
9240
|
+
} else {
|
|
9241
|
+
this.encoded = encodeValueWithPrefix(this.tuple(value, schema.fields), prefix);
|
|
9242
|
+
}
|
|
9243
|
+
return this.encoded;
|
|
9244
|
+
}
|
|
9245
|
+
protoDecode(bytes) {
|
|
9246
|
+
const values = decodeValue(bytes);
|
|
9247
|
+
const { fields } = schemaFor(this.proto);
|
|
9248
|
+
if (!Array.isArray(values) || values.length !== fields.length)
|
|
9249
|
+
throw new TypeError("Binary message schema mismatch");
|
|
9250
|
+
return Object.fromEntries(fields.map((field, index) => {
|
|
9251
|
+
const value = this.field(field.key, values[index], field.kind);
|
|
9252
|
+
if (typeof value !== typeof values[index])
|
|
9253
|
+
throw new TypeError("Non-canonical message field type");
|
|
9254
|
+
return [field.name, value];
|
|
9255
|
+
}));
|
|
9256
|
+
}
|
|
9257
|
+
decode(bytes) {
|
|
9258
|
+
bytes ??= this.encoded;
|
|
9259
|
+
if (!(bytes instanceof Uint8Array))
|
|
9260
|
+
throw new TypeError("Message payload must be Uint8Array");
|
|
9261
|
+
const codec = new Codec(bytes);
|
|
9262
|
+
if (codec.name !== this.name)
|
|
9263
|
+
throw new TypeError("Wrong binary message codec");
|
|
9264
|
+
this.decoded = this.protoDecode(bytes.subarray(codec.codecBuffer.length));
|
|
9265
|
+
return this.decoded;
|
|
9266
|
+
}
|
|
9267
|
+
fromUint8Array(bytes) {
|
|
9268
|
+
this.encoded = bytes;
|
|
9269
|
+
return this.decode(bytes);
|
|
9270
|
+
}
|
|
9271
|
+
fromArrayBuffer(buffer) {
|
|
9272
|
+
return this.fromUint8Array(new Uint8Array(buffer));
|
|
9273
|
+
}
|
|
9274
|
+
}
|
|
8884
9275
|
|
|
8885
|
-
var proto$
|
|
9276
|
+
var proto$a = defineSchema({
|
|
8886
9277
|
address: String(),
|
|
8887
9278
|
reward: BigInt(0)
|
|
8888
|
-
};
|
|
9279
|
+
});
|
|
8889
9280
|
|
|
8890
|
-
({
|
|
8891
|
-
epoch: BigInt(0)
|
|
9281
|
+
defineSchema({
|
|
9282
|
+
epoch: BigInt(0),
|
|
9283
|
+
configDigest: String(),
|
|
9284
|
+
from: String(),
|
|
9285
|
+
signature: String()
|
|
9286
|
+
});
|
|
8892
9287
|
|
|
8893
|
-
({
|
|
9288
|
+
defineSchema({
|
|
8894
9289
|
epoch: BigInt(0),
|
|
8895
9290
|
threshold: BigInt(0),
|
|
8896
9291
|
participant: BigInt(0),
|
|
8897
|
-
|
|
9292
|
+
from: String(),
|
|
9293
|
+
commitments: Array(),
|
|
9294
|
+
signature: String()
|
|
9295
|
+
});
|
|
8898
9296
|
|
|
8899
|
-
({
|
|
9297
|
+
defineSchema({
|
|
8900
9298
|
epoch: BigInt(0),
|
|
8901
9299
|
round: BigInt(0),
|
|
8902
|
-
participant: BigInt(0)
|
|
9300
|
+
participant: BigInt(0),
|
|
9301
|
+
from: String(),
|
|
9302
|
+
signatureShare: String(),
|
|
9303
|
+
signature: String()
|
|
9304
|
+
});
|
|
9305
|
+
|
|
9306
|
+
var proto$9 = defineSchema({
|
|
9307
|
+
up: Number(),
|
|
9308
|
+
down: Number()
|
|
9309
|
+
});
|
|
9310
|
+
|
|
9311
|
+
var proto$8 = defineSchema({});
|
|
8903
9312
|
|
|
8904
|
-
var proto$
|
|
9313
|
+
var proto$7 = defineSchema({
|
|
8905
9314
|
creator: String(),
|
|
8906
9315
|
contract: new Uint8Array(),
|
|
8907
9316
|
constructorParameters: Array()
|
|
8908
|
-
};
|
|
9317
|
+
});
|
|
8909
9318
|
|
|
8910
|
-
class ContractMessage extends
|
|
9319
|
+
class ContractMessage extends BinaryFormat {
|
|
8911
9320
|
get messageName() {
|
|
8912
9321
|
return "ContractMessage";
|
|
8913
9322
|
}
|
|
8914
9323
|
constructor(buffer) {
|
|
8915
9324
|
if (buffer instanceof ContractMessage)
|
|
8916
9325
|
return buffer;
|
|
8917
|
-
|
|
9326
|
+
if (buffer && typeof buffer === "object" && !(buffer instanceof Uint8Array) && typeof buffer.contract === "string")
|
|
9327
|
+
buffer = { ...buffer, contract: new TextEncoder().encode(buffer.contract) };
|
|
9328
|
+
super(buffer, proto$7, { name: "contract-message" });
|
|
8918
9329
|
}
|
|
8919
9330
|
}
|
|
8920
9331
|
|
|
8921
|
-
var proto$
|
|
9332
|
+
var proto$6 = defineSchema({
|
|
8922
9333
|
hash: String(),
|
|
8923
9334
|
index: BigInt(0)
|
|
8924
|
-
};
|
|
9335
|
+
});
|
|
9336
|
+
|
|
9337
|
+
defineSchema({});
|
|
8925
9338
|
|
|
8926
|
-
var proto$
|
|
9339
|
+
var proto$5 = defineSchema({
|
|
8927
9340
|
timestamp: Number(),
|
|
8928
9341
|
from: String(),
|
|
8929
9342
|
to: String(),
|
|
@@ -8933,9 +9346,9 @@ var proto$4 = {
|
|
|
8933
9346
|
"nonce?": Number(),
|
|
8934
9347
|
"dependsOn?": Array(),
|
|
8935
9348
|
"priority?": Boolean()
|
|
8936
|
-
};
|
|
9349
|
+
});
|
|
8937
9350
|
|
|
8938
|
-
class TransactionMessage extends
|
|
9351
|
+
class TransactionMessage extends BinaryFormat {
|
|
8939
9352
|
get messageName() {
|
|
8940
9353
|
return "TransactionMessage";
|
|
8941
9354
|
}
|
|
@@ -8943,7 +9356,7 @@ class TransactionMessage extends FormatInterface {
|
|
|
8943
9356
|
if (buffer instanceof TransactionMessage)
|
|
8944
9357
|
return buffer;
|
|
8945
9358
|
const name = "transaction-message";
|
|
8946
|
-
super(buffer, proto$
|
|
9359
|
+
super(buffer, proto$5, { name });
|
|
8947
9360
|
}
|
|
8948
9361
|
beforeHashing(decoded) {
|
|
8949
9362
|
decoded = super.beforeHashing(decoded);
|
|
@@ -8954,38 +9367,43 @@ class TransactionMessage extends FormatInterface {
|
|
|
8954
9367
|
}
|
|
8955
9368
|
}
|
|
8956
9369
|
|
|
8957
|
-
var proto$
|
|
9370
|
+
var proto$4 = defineSchema({
|
|
8958
9371
|
timestamp: Number(),
|
|
8959
9372
|
from: String(),
|
|
8960
9373
|
to: String(),
|
|
8961
9374
|
method: String(),
|
|
8962
9375
|
params: Array(),
|
|
8963
9376
|
"nonce?": Number()
|
|
8964
|
-
};
|
|
9377
|
+
});
|
|
8965
9378
|
|
|
8966
|
-
var proto$
|
|
9379
|
+
var proto$3 = defineSchema({
|
|
9380
|
+
lastblock: Object(),
|
|
9381
|
+
values: Object()
|
|
9382
|
+
});
|
|
9383
|
+
|
|
9384
|
+
var proto$2 = defineSchema({
|
|
8967
9385
|
blockHash: String(),
|
|
8968
9386
|
index: BigInt(0),
|
|
8969
9387
|
round: BigInt(0),
|
|
8970
9388
|
from: String(),
|
|
8971
9389
|
signature: String()
|
|
8972
|
-
};
|
|
9390
|
+
});
|
|
8973
9391
|
|
|
8974
|
-
var proto$1 = {
|
|
9392
|
+
var proto$1 = defineSchema({
|
|
8975
9393
|
blockHash: String(),
|
|
8976
9394
|
index: BigInt(0),
|
|
8977
9395
|
round: BigInt(0),
|
|
8978
9396
|
from: String(),
|
|
8979
9397
|
signature: String()
|
|
8980
|
-
};
|
|
9398
|
+
});
|
|
8981
9399
|
|
|
8982
|
-
var proto = {
|
|
9400
|
+
var proto = defineSchema({
|
|
8983
9401
|
blockHash: String(),
|
|
8984
9402
|
index: BigInt(0),
|
|
8985
9403
|
round: BigInt(0),
|
|
8986
9404
|
from: String(),
|
|
8987
9405
|
signature: String()
|
|
8988
|
-
};
|
|
9406
|
+
});
|
|
8989
9407
|
|
|
8990
9408
|
const encoder = new TextEncoder();
|
|
8991
9409
|
const normalizeInput = (value) => {
|
|
@@ -9015,4 +9433,4 @@ const createHash = (algorithm) => {
|
|
|
9015
9433
|
};
|
|
9016
9434
|
};
|
|
9017
9435
|
|
|
9018
|
-
export {
|
|
9436
|
+
export { proto$3 as A, BinaryFormat as B, Codec as C, TransactionMessage as T, proto$1 as a, proto as b, jsonStringifyBigInt$1 as c, ContractMessage as d, decodeWire as e, encodeWire as f, proto$4 as g, index$1 as h, index$2 as i, jsonParseBigInt$1 as j, createRIPEMD160 as k, createHMAC as l, createSHA512 as m, createKeccak as n, BinaryWriter as o, proto$2 as p, BinaryReader as q, createHash as r, proto$8 as s, proto$a as t, proto$b as u, varUintLength as v, encodeFrames as w, decodeFrames as x, proto$9 as y, proto$6 as z };
|