@typeberry/convert 0.5.7 → 0.5.8-2073cb2
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/index.js +90 -67
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4500,6 +4500,12 @@ function assertEmpty(value) {
|
|
|
4500
4500
|
}
|
|
4501
4501
|
/** Debug print an object. */
|
|
4502
4502
|
function debug_inspect(val) {
|
|
4503
|
+
return inspectInternal(val, new WeakSet());
|
|
4504
|
+
}
|
|
4505
|
+
/**
|
|
4506
|
+
* Internal implementation of inspect with circular reference detection.
|
|
4507
|
+
*/
|
|
4508
|
+
function inspectInternal(val, seen) {
|
|
4503
4509
|
const nest = (v) => v
|
|
4504
4510
|
.split("\n")
|
|
4505
4511
|
.map((x) => ` ${x}`)
|
|
@@ -4512,10 +4518,10 @@ function debug_inspect(val) {
|
|
|
4512
4518
|
return "<undefined>";
|
|
4513
4519
|
}
|
|
4514
4520
|
if (Array.isArray(val)) {
|
|
4515
|
-
return `[${val.map((x) =>
|
|
4521
|
+
return `[${val.map((x) => inspectInternal(x, seen))}]`;
|
|
4516
4522
|
}
|
|
4517
4523
|
if (val instanceof Map) {
|
|
4518
|
-
return
|
|
4524
|
+
return inspectInternal(Array.from(val.entries()), seen);
|
|
4519
4525
|
}
|
|
4520
4526
|
if (typeof val === "number") {
|
|
4521
4527
|
return `${val} (0x${val.toString(16)})`;
|
|
@@ -4523,6 +4529,11 @@ function debug_inspect(val) {
|
|
|
4523
4529
|
if (typeof val !== "object") {
|
|
4524
4530
|
return `${val}`;
|
|
4525
4531
|
}
|
|
4532
|
+
// Check for circular references
|
|
4533
|
+
if (seen.has(val)) {
|
|
4534
|
+
return "<circular>";
|
|
4535
|
+
}
|
|
4536
|
+
seen.add(val);
|
|
4526
4537
|
if ("toString" in val &&
|
|
4527
4538
|
Object.prototype.toString !== val.toString &&
|
|
4528
4539
|
WithDebug.prototype.toString !== val.toString) {
|
|
@@ -4535,7 +4546,7 @@ function debug_inspect(val) {
|
|
|
4535
4546
|
for (const k of keys) {
|
|
4536
4547
|
if (typeof k === "string") {
|
|
4537
4548
|
v += oneLine ? "" : "\n ";
|
|
4538
|
-
v += `${k}: ${nest(
|
|
4549
|
+
v += `${k}: ${nest(inspectInternal(val[k], seen))}`;
|
|
4539
4550
|
v += oneLine ? "," : "";
|
|
4540
4551
|
}
|
|
4541
4552
|
}
|
|
@@ -4615,7 +4626,7 @@ function seeThrough(v) {
|
|
|
4615
4626
|
}
|
|
4616
4627
|
|
|
4617
4628
|
;// CONCATENATED MODULE: ./packages/core/utils/package.json
|
|
4618
|
-
const package_namespaceObject = {"rE":"0.5.
|
|
4629
|
+
const package_namespaceObject = {"rE":"0.5.8"};
|
|
4619
4630
|
;// CONCATENATED MODULE: ./packages/core/utils/result.ts
|
|
4620
4631
|
|
|
4621
4632
|
/**
|
|
@@ -10187,16 +10198,24 @@ const guaranteesExtrinsicCodec = codecWithContext((context) => codecKnownSizeArr
|
|
|
10187
10198
|
|
|
10188
10199
|
|
|
10189
10200
|
|
|
10190
|
-
function tryAsTicketAttempt(x) {
|
|
10201
|
+
function tryAsTicketAttempt(x, chainSpec) {
|
|
10202
|
+
if (x >= chainSpec.ticketsPerValidator) {
|
|
10203
|
+
throw new Error(`Ticket attempt ${x} is out of bounds [0, ${chainSpec.ticketsPerValidator})`);
|
|
10204
|
+
}
|
|
10191
10205
|
return opaque_asOpaqueType(tryAsU8(x));
|
|
10192
10206
|
}
|
|
10207
|
+
const ticketAttemptCodec = codecWithContext((context) => {
|
|
10208
|
+
return codec_codec.varU32.convert((x) => {
|
|
10209
|
+
tryAsTicketAttempt(x, context);
|
|
10210
|
+
return numbers_tryAsU32(x);
|
|
10211
|
+
}, (x) => tryAsTicketAttempt(x, context));
|
|
10212
|
+
});
|
|
10193
10213
|
/* Bandersnatch-signed ticket contest entry. */
|
|
10194
10214
|
class SignedTicket extends WithDebug {
|
|
10195
10215
|
attempt;
|
|
10196
10216
|
signature;
|
|
10197
10217
|
static Codec = codec_codec.Class(SignedTicket, {
|
|
10198
|
-
|
|
10199
|
-
attempt: codec_codec.u8.asOpaque(),
|
|
10218
|
+
attempt: ticketAttemptCodec,
|
|
10200
10219
|
signature: codec_codec.bytes(BANDERSNATCH_PROOF_BYTES).asOpaque(),
|
|
10201
10220
|
});
|
|
10202
10221
|
static create({ attempt, signature }) {
|
|
@@ -10218,8 +10237,7 @@ class Ticket extends WithDebug {
|
|
|
10218
10237
|
attempt;
|
|
10219
10238
|
static Codec = codec_codec.Class(Ticket, {
|
|
10220
10239
|
id: codec_codec.bytes(hash_HASH_SIZE),
|
|
10221
|
-
|
|
10222
|
-
attempt: codec_codec.u8.asOpaque(),
|
|
10240
|
+
attempt: ticketAttemptCodec,
|
|
10223
10241
|
});
|
|
10224
10242
|
static create({ id, attempt }) {
|
|
10225
10243
|
return new Ticket(id, attempt);
|
|
@@ -10857,11 +10875,8 @@ var fromJson;
|
|
|
10857
10875
|
fromJson.bytesBlob = json.fromString(bytes_BytesBlob.parseBlob);
|
|
10858
10876
|
fromJson.bytesBlobNoPrefix = json.fromString(bytes_BytesBlob.parseBlobNoPrefix);
|
|
10859
10877
|
fromJson.ed25519Signature = json.fromString((v) => bytes_Bytes.parseBytes(v, 64).asOpaque());
|
|
10860
|
-
fromJson.ticketAttempt = json.fromNumber((v) => {
|
|
10861
|
-
|
|
10862
|
-
throw new Error("Invalid TicketAttempt value.");
|
|
10863
|
-
}
|
|
10864
|
-
return tryAsTicketAttempt(v);
|
|
10878
|
+
fromJson.ticketAttempt = (spec) => json.fromNumber((v) => {
|
|
10879
|
+
return tryAsTicketAttempt(v, spec);
|
|
10865
10880
|
});
|
|
10866
10881
|
fromJson.uint8Array = json.fromAny((v) => {
|
|
10867
10882
|
if (Array.isArray(v)) {
|
|
@@ -11101,11 +11116,13 @@ const preimagesExtrinsicFromJson = json.array(preimageFromJson);
|
|
|
11101
11116
|
|
|
11102
11117
|
|
|
11103
11118
|
|
|
11104
|
-
const
|
|
11105
|
-
|
|
11106
|
-
|
|
11107
|
-
|
|
11108
|
-
|
|
11119
|
+
const ticketsExtrinsicFromJson = (spec) => {
|
|
11120
|
+
const ticketEnvelopeFromJson = json.object({
|
|
11121
|
+
attempt: fromJson.ticketAttempt(spec),
|
|
11122
|
+
signature: json.fromString((v) => bytes_Bytes.parseBytes(v, BANDERSNATCH_PROOF_BYTES).asOpaque()),
|
|
11123
|
+
}, (x) => SignedTicket.create({ attempt: x.attempt, signature: x.signature }));
|
|
11124
|
+
return json.array(ticketEnvelopeFromJson);
|
|
11125
|
+
};
|
|
11109
11126
|
|
|
11110
11127
|
;// CONCATENATED MODULE: ./packages/jam/block-json/extrinsic.ts
|
|
11111
11128
|
|
|
@@ -11116,7 +11133,7 @@ const ticketsExtrinsicFromJson = json.array(ticketEnvelopeFromJson);
|
|
|
11116
11133
|
|
|
11117
11134
|
|
|
11118
11135
|
const getExtrinsicFromJson = (ctx) => json.object({
|
|
11119
|
-
tickets: ticketsExtrinsicFromJson,
|
|
11136
|
+
tickets: ticketsExtrinsicFromJson(ctx),
|
|
11120
11137
|
preimages: preimagesExtrinsicFromJson,
|
|
11121
11138
|
guarantees: guaranteesExtrinsicFromJson,
|
|
11122
11139
|
assurances: getAssurancesExtrinsicFromJson(ctx),
|
|
@@ -11140,39 +11157,41 @@ const epochMark = json.object({
|
|
|
11140
11157
|
tickets_entropy: fromJson.bytes32(),
|
|
11141
11158
|
validators: json.array(validatorKeysFromJson),
|
|
11142
11159
|
}, (x) => EpochMarker.create({ entropy: x.entropy, ticketsEntropy: x.tickets_entropy, validators: x.validators }));
|
|
11143
|
-
const
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
|
|
11148
|
-
|
|
11149
|
-
|
|
11150
|
-
|
|
11151
|
-
|
|
11152
|
-
|
|
11153
|
-
|
|
11154
|
-
|
|
11155
|
-
|
|
11156
|
-
|
|
11157
|
-
|
|
11158
|
-
|
|
11159
|
-
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
|
|
11163
|
-
|
|
11164
|
-
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
|
|
11172
|
-
|
|
11173
|
-
|
|
11160
|
+
const headerFromJson = (spec) => {
|
|
11161
|
+
const ticket = json.object({
|
|
11162
|
+
id: fromJson.bytes32(),
|
|
11163
|
+
attempt: fromJson.ticketAttempt(spec),
|
|
11164
|
+
}, (x) => Ticket.create({ id: x.id, attempt: x.attempt }));
|
|
11165
|
+
return json.object({
|
|
11166
|
+
parent: fromJson.bytes32(),
|
|
11167
|
+
parent_state_root: fromJson.bytes32(),
|
|
11168
|
+
extrinsic_hash: fromJson.bytes32(),
|
|
11169
|
+
slot: "number",
|
|
11170
|
+
epoch_mark: json.optional(epochMark),
|
|
11171
|
+
tickets_mark: json.optional(json.array(ticket)),
|
|
11172
|
+
offenders_mark: json.array(fromJson.bytes32()),
|
|
11173
|
+
author_index: "number",
|
|
11174
|
+
entropy_source: bandersnatchVrfSignature,
|
|
11175
|
+
seal: bandersnatchVrfSignature,
|
|
11176
|
+
}, ({ parent, parent_state_root, extrinsic_hash, slot, epoch_mark, tickets_mark, offenders_mark, author_index, entropy_source, seal, }) => {
|
|
11177
|
+
const epochMarker = epoch_mark ?? null;
|
|
11178
|
+
const ticketsMarker = tickets_mark === undefined || tickets_mark === null
|
|
11179
|
+
? null
|
|
11180
|
+
: TicketsMarker.create({ tickets: opaque_asOpaqueType(tickets_mark) });
|
|
11181
|
+
return header_Header.create({
|
|
11182
|
+
parentHeaderHash: parent,
|
|
11183
|
+
priorStateRoot: parent_state_root,
|
|
11184
|
+
extrinsicHash: extrinsic_hash,
|
|
11185
|
+
timeSlotIndex: slot,
|
|
11186
|
+
epochMarker,
|
|
11187
|
+
ticketsMarker,
|
|
11188
|
+
offendersMarker: offenders_mark,
|
|
11189
|
+
bandersnatchBlockAuthorIndex: author_index,
|
|
11190
|
+
entropySource: entropy_source,
|
|
11191
|
+
seal,
|
|
11192
|
+
});
|
|
11174
11193
|
});
|
|
11175
|
-
}
|
|
11194
|
+
};
|
|
11176
11195
|
|
|
11177
11196
|
;// CONCATENATED MODULE: ./packages/jam/block-json/block.ts
|
|
11178
11197
|
|
|
@@ -11180,7 +11199,7 @@ const headerFromJson = json.object({
|
|
|
11180
11199
|
|
|
11181
11200
|
|
|
11182
11201
|
const blockFromJson = (spec) => json.object({
|
|
11183
|
-
header: headerFromJson,
|
|
11202
|
+
header: headerFromJson(spec),
|
|
11184
11203
|
extrinsic: getExtrinsicFromJson(spec),
|
|
11185
11204
|
}, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
|
|
11186
11205
|
const blockViewFromJson = (spec) => {
|
|
@@ -14032,15 +14051,17 @@ const recentBlocksHistoryFromJson = json.object({
|
|
|
14032
14051
|
|
|
14033
14052
|
|
|
14034
14053
|
|
|
14035
|
-
const ticketFromJson = json.object({
|
|
14054
|
+
const ticketFromJson = (spec) => json.object({
|
|
14036
14055
|
id: fromJson.bytes32(),
|
|
14037
|
-
attempt: fromJson.ticketAttempt,
|
|
14056
|
+
attempt: fromJson.ticketAttempt(spec),
|
|
14038
14057
|
}, Ticket.create);
|
|
14039
14058
|
class TicketsOrKeys {
|
|
14040
|
-
static fromJson
|
|
14041
|
-
|
|
14042
|
-
|
|
14043
|
-
|
|
14059
|
+
static fromJson(spec) {
|
|
14060
|
+
return {
|
|
14061
|
+
keys: json.optional(json.array(fromJson.bytes32())),
|
|
14062
|
+
tickets: json.optional(json.array(ticketFromJson(spec))),
|
|
14063
|
+
};
|
|
14064
|
+
}
|
|
14044
14065
|
keys;
|
|
14045
14066
|
tickets;
|
|
14046
14067
|
static toSafroleSealingKeys(data, chainSpec) {
|
|
@@ -14214,8 +14235,8 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
14214
14235
|
beta: json.nullable(recentBlocksHistoryFromJson),
|
|
14215
14236
|
gamma: {
|
|
14216
14237
|
gamma_k: json.array(validatorDataFromJson),
|
|
14217
|
-
gamma_a: json.array(ticketFromJson),
|
|
14218
|
-
gamma_s: TicketsOrKeys.fromJson,
|
|
14238
|
+
gamma_a: json.array(ticketFromJson(spec)),
|
|
14239
|
+
gamma_s: TicketsOrKeys.fromJson(spec),
|
|
14219
14240
|
gamma_z: json.fromString((v) => bytes_Bytes.parseBytes(v, BANDERSNATCH_RING_ROOT_BYTES).asOpaque()),
|
|
14220
14241
|
},
|
|
14221
14242
|
psi: disputesRecordsFromJson,
|
|
@@ -16068,10 +16089,12 @@ class TestState {
|
|
|
16068
16089
|
keyvals;
|
|
16069
16090
|
}
|
|
16070
16091
|
class StateTransitionGenesis {
|
|
16071
|
-
static fromJson = {
|
|
16072
|
-
|
|
16073
|
-
|
|
16074
|
-
|
|
16092
|
+
static fromJson(spec = chain_spec_tinyChainSpec) {
|
|
16093
|
+
return {
|
|
16094
|
+
header: headerFromJson(spec),
|
|
16095
|
+
state: TestState.fromJson,
|
|
16096
|
+
};
|
|
16097
|
+
}
|
|
16075
16098
|
static Codec = codec_codec.object({
|
|
16076
16099
|
header: header_Header.Codec,
|
|
16077
16100
|
state: TestState.Codec,
|
|
@@ -20131,7 +20154,7 @@ const SUPPORTED_TYPES = [
|
|
|
20131
20154
|
name: "header",
|
|
20132
20155
|
encode: header_Header.Codec,
|
|
20133
20156
|
decode: header_Header.Codec,
|
|
20134
|
-
json: (
|
|
20157
|
+
json: (spec) => headerFromJson(spec),
|
|
20135
20158
|
process: {
|
|
20136
20159
|
options: ["as-hash"],
|
|
20137
20160
|
run(spec, data, option, blake2b) {
|
|
@@ -20204,7 +20227,7 @@ const SUPPORTED_TYPES = [
|
|
|
20204
20227
|
name: "stf-genesis",
|
|
20205
20228
|
encode: StateTransitionGenesis.Codec,
|
|
20206
20229
|
decode: StateTransitionGenesis.Codec,
|
|
20207
|
-
json: () => StateTransitionGenesis.fromJson,
|
|
20230
|
+
json: (spec) => StateTransitionGenesis.fromJson(spec),
|
|
20208
20231
|
process: {
|
|
20209
20232
|
options: ["as-state", "as-jip4", "as-fuzz-message"],
|
|
20210
20233
|
run(spec, data, option, blake2b) {
|