@typeberry/convert 0.5.9 → 0.5.10
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 +89 -86
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4626,7 +4626,7 @@ function seeThrough(v) {
|
|
|
4626
4626
|
}
|
|
4627
4627
|
|
|
4628
4628
|
;// CONCATENATED MODULE: ./packages/core/utils/package.json
|
|
4629
|
-
const package_namespaceObject = {"rE":"0.5.
|
|
4629
|
+
const package_namespaceObject = {"rE":"0.5.10"};
|
|
4630
4630
|
;// CONCATENATED MODULE: ./packages/core/utils/result.ts
|
|
4631
4631
|
|
|
4632
4632
|
/**
|
|
@@ -9599,14 +9599,31 @@ class RefineContext extends WithDebug {
|
|
|
9599
9599
|
;// CONCATENATED MODULE: ./packages/jam/block/work-item-segment.ts
|
|
9600
9600
|
|
|
9601
9601
|
|
|
9602
|
-
/**
|
|
9602
|
+
/**
|
|
9603
|
+
* `W_E`: The basic size of erasure-coded pieces in octets. See equation H.6.
|
|
9604
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/449600449700?v=0.7.2
|
|
9605
|
+
*/
|
|
9603
9606
|
const W_E = 684;
|
|
9604
|
-
/**
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9607
|
+
/**
|
|
9608
|
+
* `W_P`: The size of an exported segment in erasure-coded pieces in octets.
|
|
9609
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/44b10044b200?v=0.7.2
|
|
9610
|
+
*/
|
|
9611
|
+
const W_P = 6;
|
|
9612
|
+
/**
|
|
9613
|
+
* `W_M`: The maximum number of imports in a work-package manifest.
|
|
9614
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/44ad0044ae00?v=0.7.2
|
|
9615
|
+
*/
|
|
9616
|
+
const MAX_NUMBER_OF_IMPORTS_WP = 3072;
|
|
9617
|
+
/**
|
|
9618
|
+
* `W_X`: The maximum number of exports in a work-package manifest.
|
|
9619
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/44be0044bf00?v=0.7.2
|
|
9620
|
+
*/
|
|
9621
|
+
const MAX_NUMBER_OF_EXPORTS_WP = 3072;
|
|
9622
|
+
/**
|
|
9623
|
+
* `W_G = W_E * W_P`: Exported segment size in bytes.
|
|
9624
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/449a00449b00?v=0.7.2
|
|
9625
|
+
*/
|
|
9626
|
+
const SEGMENT_BYTES = W_E * W_P;
|
|
9610
9627
|
/** Attempt to convert a number into `SegmentIndex`. */
|
|
9611
9628
|
const tryAsSegmentIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
9612
9629
|
|
|
@@ -9716,13 +9733,17 @@ class work_item_WorkItem extends WithDebug {
|
|
|
9716
9733
|
codeHash: codec_codec.bytes(hash_HASH_SIZE).asOpaque(),
|
|
9717
9734
|
refineGasLimit: codec_codec.u64.asOpaque(),
|
|
9718
9735
|
accumulateGasLimit: codec_codec.u64.asOpaque(),
|
|
9736
|
+
// TODO: [MaSo] It should be validated to not exceed W_X
|
|
9737
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/1a0b011a1c01?v=0.7.2
|
|
9719
9738
|
exportCount: codec_codec.u16,
|
|
9720
9739
|
payload: codec_codec.blob,
|
|
9721
9740
|
importSegments: codecKnownSizeArray(ImportSpec.Codec, {
|
|
9722
9741
|
minLength: 0,
|
|
9723
|
-
maxLength:
|
|
9724
|
-
typicalLength:
|
|
9742
|
+
maxLength: MAX_NUMBER_OF_IMPORTS_WP,
|
|
9743
|
+
typicalLength: MAX_NUMBER_OF_IMPORTS_WP,
|
|
9725
9744
|
}),
|
|
9745
|
+
// TODO: [MaSo] It should be validated to not exceed T = 128
|
|
9746
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/1a0b011a1c01?v=0.7.2
|
|
9726
9747
|
extrinsic: codec_codec.sequenceVarLen(WorkItemExtrinsicSpec.Codec),
|
|
9727
9748
|
});
|
|
9728
9749
|
static create({ service, codeHash, payload, refineGasLimit, accumulateGasLimit, importSegments, extrinsic, exportCount, }) {
|
|
@@ -9770,12 +9791,8 @@ class work_item_WorkItem extends WithDebug {
|
|
|
9770
9791
|
|
|
9771
9792
|
|
|
9772
9793
|
|
|
9773
|
-
/** Convert the value to `WorkItemsCount`
|
|
9794
|
+
/** Convert the value to `WorkItemsCount`. Validation is done at runtime by `isWorkItemsCount`. */
|
|
9774
9795
|
function tryAsWorkItemsCount(len) {
|
|
9775
|
-
debug_check `
|
|
9776
|
-
${isWorkItemsCount(len)}
|
|
9777
|
-
WorkItemsCount: Expected '${MIN_NUMBER_OF_WORK_ITEMS} <= count <= ${work_package_MAX_NUMBER_OF_WORK_ITEMS}' got ${len}
|
|
9778
|
-
`;
|
|
9779
9796
|
return tryAsU8(len);
|
|
9780
9797
|
}
|
|
9781
9798
|
/** Verify the value is within the `WorkItemsCount` bounds. */
|
|
@@ -10198,18 +10215,10 @@ const guaranteesExtrinsicCodec = codecWithContext((context) => codecKnownSizeArr
|
|
|
10198
10215
|
|
|
10199
10216
|
|
|
10200
10217
|
|
|
10201
|
-
function tryAsTicketAttempt(x
|
|
10202
|
-
if (x >= chainSpec.ticketsPerValidator) {
|
|
10203
|
-
throw new Error(`Ticket attempt ${x} is out of bounds [0, ${chainSpec.ticketsPerValidator})`);
|
|
10204
|
-
}
|
|
10218
|
+
function tryAsTicketAttempt(x) {
|
|
10205
10219
|
return opaque_asOpaqueType(tryAsU8(x));
|
|
10206
10220
|
}
|
|
10207
|
-
const ticketAttemptCodec =
|
|
10208
|
-
return codec_codec.varU32.convert((x) => {
|
|
10209
|
-
tryAsTicketAttempt(x, context);
|
|
10210
|
-
return numbers_tryAsU32(x);
|
|
10211
|
-
}, (x) => tryAsTicketAttempt(x, context));
|
|
10212
|
-
});
|
|
10221
|
+
const ticketAttemptCodec = codec_codec.varU32.convert((x) => numbers_tryAsU32(x), (x) => tryAsTicketAttempt(x));
|
|
10213
10222
|
/* Bandersnatch-signed ticket contest entry. */
|
|
10214
10223
|
class SignedTicket extends WithDebug {
|
|
10215
10224
|
attempt;
|
|
@@ -10875,8 +10884,8 @@ var fromJson;
|
|
|
10875
10884
|
fromJson.bytesBlob = json.fromString(bytes_BytesBlob.parseBlob);
|
|
10876
10885
|
fromJson.bytesBlobNoPrefix = json.fromString(bytes_BytesBlob.parseBlobNoPrefix);
|
|
10877
10886
|
fromJson.ed25519Signature = json.fromString((v) => bytes_Bytes.parseBytes(v, 64).asOpaque());
|
|
10878
|
-
fromJson.ticketAttempt =
|
|
10879
|
-
return tryAsTicketAttempt(v
|
|
10887
|
+
fromJson.ticketAttempt = json.fromNumber((v) => {
|
|
10888
|
+
return tryAsTicketAttempt(v);
|
|
10880
10889
|
});
|
|
10881
10890
|
fromJson.uint8Array = json.fromAny((v) => {
|
|
10882
10891
|
if (Array.isArray(v)) {
|
|
@@ -11005,13 +11014,13 @@ const workExecResultFromJson = json.object({
|
|
|
11005
11014
|
throw new Error("Invalid WorkExecResult");
|
|
11006
11015
|
});
|
|
11007
11016
|
const workRefineLoadFromJson = json.object({
|
|
11008
|
-
gas_used: json.
|
|
11017
|
+
gas_used: json.fromBigInt((x) => tryAsServiceGas(x)),
|
|
11009
11018
|
imports: "number",
|
|
11010
11019
|
extrinsic_count: "number",
|
|
11011
11020
|
extrinsic_size: "number",
|
|
11012
11021
|
exports: "number",
|
|
11013
11022
|
}, ({ gas_used, imports, extrinsic_count, extrinsic_size, exports }) => WorkRefineLoad.create({
|
|
11014
|
-
gasUsed:
|
|
11023
|
+
gasUsed: gas_used,
|
|
11015
11024
|
importedSegments: numbers_tryAsU32(imports),
|
|
11016
11025
|
extrinsicCount: numbers_tryAsU32(extrinsic_count),
|
|
11017
11026
|
extrinsicSize: numbers_tryAsU32(extrinsic_size),
|
|
@@ -11116,13 +11125,11 @@ const preimagesExtrinsicFromJson = json.array(preimageFromJson);
|
|
|
11116
11125
|
|
|
11117
11126
|
|
|
11118
11127
|
|
|
11119
|
-
const
|
|
11120
|
-
|
|
11121
|
-
|
|
11122
|
-
|
|
11123
|
-
|
|
11124
|
-
return json.array(ticketEnvelopeFromJson);
|
|
11125
|
-
};
|
|
11128
|
+
const ticketEnvelopeFromJson = json.object({
|
|
11129
|
+
attempt: fromJson.ticketAttempt,
|
|
11130
|
+
signature: json.fromString((v) => bytes_Bytes.parseBytes(v, BANDERSNATCH_PROOF_BYTES).asOpaque()),
|
|
11131
|
+
}, (x) => SignedTicket.create({ attempt: x.attempt, signature: x.signature }));
|
|
11132
|
+
const ticketsExtrinsicFromJson = json.array(ticketEnvelopeFromJson);
|
|
11126
11133
|
|
|
11127
11134
|
;// CONCATENATED MODULE: ./packages/jam/block-json/extrinsic.ts
|
|
11128
11135
|
|
|
@@ -11133,7 +11140,7 @@ const ticketsExtrinsicFromJson = (spec) => {
|
|
|
11133
11140
|
|
|
11134
11141
|
|
|
11135
11142
|
const getExtrinsicFromJson = (ctx) => json.object({
|
|
11136
|
-
tickets: ticketsExtrinsicFromJson
|
|
11143
|
+
tickets: ticketsExtrinsicFromJson,
|
|
11137
11144
|
preimages: preimagesExtrinsicFromJson,
|
|
11138
11145
|
guarantees: guaranteesExtrinsicFromJson,
|
|
11139
11146
|
assurances: getAssurancesExtrinsicFromJson(ctx),
|
|
@@ -11157,41 +11164,39 @@ const epochMark = json.object({
|
|
|
11157
11164
|
tickets_entropy: fromJson.bytes32(),
|
|
11158
11165
|
validators: json.array(validatorKeysFromJson),
|
|
11159
11166
|
}, (x) => EpochMarker.create({ entropy: x.entropy, ticketsEntropy: x.tickets_entropy, validators: x.validators }));
|
|
11160
|
-
const
|
|
11161
|
-
|
|
11162
|
-
|
|
11163
|
-
|
|
11164
|
-
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
|
|
11172
|
-
|
|
11173
|
-
|
|
11174
|
-
|
|
11175
|
-
|
|
11176
|
-
|
|
11177
|
-
|
|
11178
|
-
|
|
11179
|
-
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
|
|
11183
|
-
|
|
11184
|
-
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
seal,
|
|
11192
|
-
});
|
|
11167
|
+
const ticket = json.object({
|
|
11168
|
+
id: fromJson.bytes32(),
|
|
11169
|
+
attempt: fromJson.ticketAttempt,
|
|
11170
|
+
}, (x) => Ticket.create({ id: x.id, attempt: x.attempt }));
|
|
11171
|
+
const headerFromJson = json.object({
|
|
11172
|
+
parent: fromJson.bytes32(),
|
|
11173
|
+
parent_state_root: fromJson.bytes32(),
|
|
11174
|
+
extrinsic_hash: fromJson.bytes32(),
|
|
11175
|
+
slot: "number",
|
|
11176
|
+
epoch_mark: json.optional(epochMark),
|
|
11177
|
+
tickets_mark: json.optional(json.array(ticket)),
|
|
11178
|
+
offenders_mark: json.array(fromJson.bytes32()),
|
|
11179
|
+
author_index: "number",
|
|
11180
|
+
entropy_source: bandersnatchVrfSignature,
|
|
11181
|
+
seal: bandersnatchVrfSignature,
|
|
11182
|
+
}, ({ parent, parent_state_root, extrinsic_hash, slot, epoch_mark, tickets_mark, offenders_mark, author_index, entropy_source, seal, }) => {
|
|
11183
|
+
const epochMarker = epoch_mark ?? null;
|
|
11184
|
+
const ticketsMarker = tickets_mark === undefined || tickets_mark === null
|
|
11185
|
+
? null
|
|
11186
|
+
: TicketsMarker.create({ tickets: opaque_asOpaqueType(tickets_mark) });
|
|
11187
|
+
return header_Header.create({
|
|
11188
|
+
parentHeaderHash: parent,
|
|
11189
|
+
priorStateRoot: parent_state_root,
|
|
11190
|
+
extrinsicHash: extrinsic_hash,
|
|
11191
|
+
timeSlotIndex: slot,
|
|
11192
|
+
epochMarker,
|
|
11193
|
+
ticketsMarker,
|
|
11194
|
+
offendersMarker: offenders_mark,
|
|
11195
|
+
bandersnatchBlockAuthorIndex: author_index,
|
|
11196
|
+
entropySource: entropy_source,
|
|
11197
|
+
seal,
|
|
11193
11198
|
});
|
|
11194
|
-
};
|
|
11199
|
+
});
|
|
11195
11200
|
|
|
11196
11201
|
;// CONCATENATED MODULE: ./packages/jam/block-json/block.ts
|
|
11197
11202
|
|
|
@@ -11199,7 +11204,7 @@ const headerFromJson = (spec) => {
|
|
|
11199
11204
|
|
|
11200
11205
|
|
|
11201
11206
|
const blockFromJson = (spec) => json.object({
|
|
11202
|
-
header: headerFromJson
|
|
11207
|
+
header: headerFromJson,
|
|
11203
11208
|
extrinsic: getExtrinsicFromJson(spec),
|
|
11204
11209
|
}, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
|
|
11205
11210
|
const blockViewFromJson = (spec) => {
|
|
@@ -14051,15 +14056,15 @@ const recentBlocksHistoryFromJson = json.object({
|
|
|
14051
14056
|
|
|
14052
14057
|
|
|
14053
14058
|
|
|
14054
|
-
const ticketFromJson =
|
|
14059
|
+
const ticketFromJson = json.object({
|
|
14055
14060
|
id: fromJson.bytes32(),
|
|
14056
|
-
attempt: fromJson.ticketAttempt
|
|
14061
|
+
attempt: fromJson.ticketAttempt,
|
|
14057
14062
|
}, Ticket.create);
|
|
14058
14063
|
class TicketsOrKeys {
|
|
14059
|
-
static fromJson(
|
|
14064
|
+
static fromJson() {
|
|
14060
14065
|
return {
|
|
14061
14066
|
keys: json.optional(json.array(fromJson.bytes32())),
|
|
14062
|
-
tickets: json.optional(json.array(ticketFromJson
|
|
14067
|
+
tickets: json.optional(json.array(ticketFromJson)),
|
|
14063
14068
|
};
|
|
14064
14069
|
}
|
|
14065
14070
|
keys;
|
|
@@ -14235,8 +14240,8 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
14235
14240
|
beta: json.nullable(recentBlocksHistoryFromJson),
|
|
14236
14241
|
gamma: {
|
|
14237
14242
|
gamma_k: json.array(validatorDataFromJson),
|
|
14238
|
-
gamma_a: json.array(ticketFromJson
|
|
14239
|
-
gamma_s: TicketsOrKeys.fromJson(
|
|
14243
|
+
gamma_a: json.array(ticketFromJson),
|
|
14244
|
+
gamma_s: TicketsOrKeys.fromJson(),
|
|
14240
14245
|
gamma_z: json.fromString((v) => bytes_Bytes.parseBytes(v, BANDERSNATCH_RING_ROOT_BYTES).asOpaque()),
|
|
14241
14246
|
},
|
|
14242
14247
|
psi: disputesRecordsFromJson,
|
|
@@ -16089,12 +16094,10 @@ class TestState {
|
|
|
16089
16094
|
keyvals;
|
|
16090
16095
|
}
|
|
16091
16096
|
class StateTransitionGenesis {
|
|
16092
|
-
static fromJson
|
|
16093
|
-
|
|
16094
|
-
|
|
16095
|
-
|
|
16096
|
-
};
|
|
16097
|
-
}
|
|
16097
|
+
static fromJson = {
|
|
16098
|
+
header: headerFromJson,
|
|
16099
|
+
state: TestState.fromJson,
|
|
16100
|
+
};
|
|
16098
16101
|
static Codec = codec_codec.object({
|
|
16099
16102
|
header: header_Header.Codec,
|
|
16100
16103
|
state: TestState.Codec,
|
|
@@ -20154,7 +20157,7 @@ const SUPPORTED_TYPES = [
|
|
|
20154
20157
|
name: "header",
|
|
20155
20158
|
encode: header_Header.Codec,
|
|
20156
20159
|
decode: header_Header.Codec,
|
|
20157
|
-
json: (
|
|
20160
|
+
json: (_spec) => headerFromJson,
|
|
20158
20161
|
process: {
|
|
20159
20162
|
options: ["as-hash"],
|
|
20160
20163
|
run(spec, data, option, blake2b) {
|
|
@@ -20227,7 +20230,7 @@ const SUPPORTED_TYPES = [
|
|
|
20227
20230
|
name: "stf-genesis",
|
|
20228
20231
|
encode: StateTransitionGenesis.Codec,
|
|
20229
20232
|
decode: StateTransitionGenesis.Codec,
|
|
20230
|
-
json: (
|
|
20233
|
+
json: (_spec) => StateTransitionGenesis.fromJson,
|
|
20231
20234
|
process: {
|
|
20232
20235
|
options: ["as-state", "as-jip4", "as-fuzz-message"],
|
|
20233
20236
|
run(spec, data, option, blake2b) {
|