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