@typeberry/jam 0.2.0-8017bfd → 0.2.0-adde0dd
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/bootstrap-generator.mjs +14 -14
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +147 -147
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +18 -18
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +158 -158
- package/index.js.map +1 -1
- package/package.json +1 -1
package/bootstrap-network.mjs
CHANGED
|
@@ -24333,7 +24333,7 @@ function result_resultToString(res) {
|
|
|
24333
24333
|
if (res.isOk) {
|
|
24334
24334
|
return `OK: ${typeof res.ok === "symbol" ? res.ok.toString() : res.ok}`;
|
|
24335
24335
|
}
|
|
24336
|
-
return `${res.details}\nError: ${maybeTaggedErrorToString(res.error)}`;
|
|
24336
|
+
return `${res.details()}\nError: ${maybeTaggedErrorToString(res.error)}`;
|
|
24337
24337
|
}
|
|
24338
24338
|
/** An indication of two possible outcomes returned from a function. */
|
|
24339
24339
|
const result_Result = {
|
|
@@ -24347,7 +24347,7 @@ const result_Result = {
|
|
|
24347
24347
|
};
|
|
24348
24348
|
},
|
|
24349
24349
|
/** Create new [`Result`] with `Error` status. */
|
|
24350
|
-
error: (error, details
|
|
24350
|
+
error: (error, details) => {
|
|
24351
24351
|
debug_check `${error !== undefined} 'Error' type cannot be undefined.`;
|
|
24352
24352
|
return {
|
|
24353
24353
|
isOk: false,
|
|
@@ -24466,7 +24466,7 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
|
|
|
24466
24466
|
}
|
|
24467
24467
|
if (actual.isError && expected.isError) {
|
|
24468
24468
|
deepEqual(actual.error, expected.error, { context: ctx.concat(["error"]), errorsCollector: errors, ignore });
|
|
24469
|
-
deepEqual(actual.details, expected.details, {
|
|
24469
|
+
deepEqual(actual.details(), expected.details(), {
|
|
24470
24470
|
context: ctx.concat(["details"]),
|
|
24471
24471
|
errorsCollector: errors,
|
|
24472
24472
|
// display details when error does not match
|
|
@@ -33228,7 +33228,7 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
33228
33228
|
const { kind } = update.action;
|
|
33229
33229
|
const service = this.services.get(serviceId);
|
|
33230
33230
|
if (service === undefined) {
|
|
33231
|
-
return result_Result.error(in_memory_state_UpdateError.NoService, `Attempting to update storage of non-existing service: ${serviceId}`);
|
|
33231
|
+
return result_Result.error(in_memory_state_UpdateError.NoService, () => `Attempting to update storage of non-existing service: ${serviceId}`);
|
|
33232
33232
|
}
|
|
33233
33233
|
if (kind === state_update_UpdateStorageKind.Set) {
|
|
33234
33234
|
const { key, value } = update.action.storage;
|
|
@@ -33256,14 +33256,14 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
33256
33256
|
for (const [serviceId, updates] of preimagesUpdates.entries()) {
|
|
33257
33257
|
const service = this.services.get(serviceId);
|
|
33258
33258
|
if (service === undefined) {
|
|
33259
|
-
return result_Result.error(in_memory_state_UpdateError.NoService, `Attempting to update preimage of non-existing service: ${serviceId}`);
|
|
33259
|
+
return result_Result.error(in_memory_state_UpdateError.NoService, () => `Attempting to update preimage of non-existing service: ${serviceId}`);
|
|
33260
33260
|
}
|
|
33261
33261
|
for (const update of updates) {
|
|
33262
33262
|
const { kind } = update.action;
|
|
33263
33263
|
if (kind === state_update_UpdatePreimageKind.Provide) {
|
|
33264
33264
|
const { preimage, slot } = update.action;
|
|
33265
33265
|
if (service.data.preimages.has(preimage.hash)) {
|
|
33266
|
-
return result_Result.error(in_memory_state_UpdateError.PreimageExists, `Overwriting existing preimage at ${serviceId}: ${preimage}`);
|
|
33266
|
+
return result_Result.error(in_memory_state_UpdateError.PreimageExists, () => `Overwriting existing preimage at ${serviceId}: ${preimage}`);
|
|
33267
33267
|
}
|
|
33268
33268
|
service.data.preimages.set(preimage.hash, preimage);
|
|
33269
33269
|
if (slot !== null) {
|
|
@@ -33314,7 +33314,7 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
33314
33314
|
if (kind === state_update_UpdateServiceKind.Create) {
|
|
33315
33315
|
const { lookupHistory } = update.action;
|
|
33316
33316
|
if (this.services.has(serviceId)) {
|
|
33317
|
-
return result_Result.error(in_memory_state_UpdateError.DuplicateService, `${serviceId} already exists!`);
|
|
33317
|
+
return result_Result.error(in_memory_state_UpdateError.DuplicateService, () => `${serviceId} already exists!`);
|
|
33318
33318
|
}
|
|
33319
33319
|
this.services.set(serviceId, new InMemoryService(serviceId, {
|
|
33320
33320
|
info: account,
|
|
@@ -33326,7 +33326,7 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
33326
33326
|
else if (kind === state_update_UpdateServiceKind.Update) {
|
|
33327
33327
|
const existingService = this.services.get(serviceId);
|
|
33328
33328
|
if (existingService === undefined) {
|
|
33329
|
-
return result_Result.error(in_memory_state_UpdateError.NoService, `Cannot update ${serviceId} because it does not exist.`);
|
|
33329
|
+
return result_Result.error(in_memory_state_UpdateError.NoService, () => `Cannot update ${serviceId} because it does not exist.`);
|
|
33330
33330
|
}
|
|
33331
33331
|
existingService.data.info = account;
|
|
33332
33332
|
}
|
|
@@ -34956,13 +34956,13 @@ class leaf_db_LeafDb {
|
|
|
34956
34956
|
*/
|
|
34957
34957
|
static fromLeavesBlob(blob, db) {
|
|
34958
34958
|
if (blob.length % TRIE_NODE_BYTES !== 0) {
|
|
34959
|
-
return Result.error(LeafDbError.InvalidLeafData, `${blob.length} is not a multiply of ${TRIE_NODE_BYTES}: ${blob}`);
|
|
34959
|
+
return Result.error(LeafDbError.InvalidLeafData, () => `${blob.length} is not a multiply of ${TRIE_NODE_BYTES}: ${blob}`);
|
|
34960
34960
|
}
|
|
34961
34961
|
const leaves = SortedSet.fromArray(leafComparator, []);
|
|
34962
34962
|
for (const nodeData of blob.chunks(TRIE_NODE_BYTES)) {
|
|
34963
34963
|
const node = new TrieNode(nodeData.raw);
|
|
34964
34964
|
if (node.getNodeType() === NodeType.Branch) {
|
|
34965
|
-
return Result.error(LeafDbError.InvalidLeafData, `Branch node detected: ${nodeData}`);
|
|
34965
|
+
return Result.error(LeafDbError.InvalidLeafData, () => `Branch node detected: ${nodeData}`);
|
|
34966
34966
|
}
|
|
34967
34967
|
leaves.insert(node.asLeafNode());
|
|
34968
34968
|
}
|
|
@@ -35355,7 +35355,7 @@ class LmdbStates {
|
|
|
35355
35355
|
}
|
|
35356
35356
|
catch (e) {
|
|
35357
35357
|
states_logger.error `${e}`;
|
|
35358
|
-
return Result.error(StateUpdateError.Commit);
|
|
35358
|
+
return Result.error(StateUpdateError.Commit, () => `Failed to commit state update: ${e}`);
|
|
35359
35359
|
}
|
|
35360
35360
|
return Result.ok(OK);
|
|
35361
35361
|
}
|
|
@@ -36622,20 +36622,20 @@ async function verifyCertificate(certs) {
|
|
|
36622
36622
|
// Must present exactly one cert
|
|
36623
36623
|
if (certs.length !== 1) {
|
|
36624
36624
|
certificate_logger.log `Rejecting peer: expected exactly one certificate, got: ${certs.length}`;
|
|
36625
|
-
return result_Result.error(VerifyCertError.NoCertificate);
|
|
36625
|
+
return result_Result.error(VerifyCertError.NoCertificate, () => `Certificate validation failed: expected exactly one certificate, got ${certs.length}`);
|
|
36626
36626
|
}
|
|
36627
36627
|
// Parse with Node's X509Certificate (accepts PEM or DER)
|
|
36628
36628
|
const xc = new (external_node_crypto_default()).X509Certificate(certs[0]);
|
|
36629
36629
|
// Must be Ed25519 key
|
|
36630
36630
|
if (xc.publicKey.asymmetricKeyType !== CURVE_NAME.toLowerCase()) {
|
|
36631
36631
|
certificate_logger.log `Rejecting peer using non-ed25519 certificate: ${xc.publicKey.asymmetricKeyType}`;
|
|
36632
|
-
return result_Result.error(VerifyCertError.NotEd25519);
|
|
36632
|
+
return result_Result.error(VerifyCertError.NotEd25519, () => `Certificate validation failed: expected Ed25519 key, got ${xc.publicKey.asymmetricKeyType}`);
|
|
36633
36633
|
}
|
|
36634
36634
|
// Extract raw public key via JWK export
|
|
36635
36635
|
const jwk = xc.publicKey.export({ format: "jwk" });
|
|
36636
36636
|
if (jwk.kty !== KEY_TYPE || jwk.crv !== CURVE_NAME) {
|
|
36637
36637
|
certificate_logger.log `Public key type mismatch: ${jwk.kty}, ${jwk.crv}`;
|
|
36638
|
-
return result_Result.error(VerifyCertError.PublicKeyTypeMismatch);
|
|
36638
|
+
return result_Result.error(VerifyCertError.PublicKeyTypeMismatch, () => `Certificate validation failed: public key type mismatch (kty: ${jwk.kty}, crv: ${jwk.crv})`);
|
|
36639
36639
|
}
|
|
36640
36640
|
// SAN must be exactly 'e'+base32(rawPub)
|
|
36641
36641
|
const expectedSan = altNameJwk(jwk);
|
|
@@ -36643,11 +36643,11 @@ async function verifyCertificate(certs) {
|
|
|
36643
36643
|
const m = sanField.match(/DNS:([^,]+)/);
|
|
36644
36644
|
if (m === null || m[1] !== expectedSan) {
|
|
36645
36645
|
certificate_logger.log `AltName mismatch. Expected: '${expectedSan}', got: '${m?.[1]}'`;
|
|
36646
|
-
return result_Result.error(VerifyCertError.AltNameMismatch);
|
|
36646
|
+
return result_Result.error(VerifyCertError.AltNameMismatch, () => `Certificate validation failed: altName mismatch (expected: ${expectedSan}, got: ${m?.[1] ?? "none"})`);
|
|
36647
36647
|
}
|
|
36648
36648
|
const key = Buffer.from(jwk.x ?? "", "base64url");
|
|
36649
36649
|
if (!xc.verify(xc.publicKey)) {
|
|
36650
|
-
return result_Result.error(VerifyCertError.IncorrectSignature);
|
|
36650
|
+
return result_Result.error(VerifyCertError.IncorrectSignature, () => "Certificate validation failed: incorrect signature");
|
|
36651
36651
|
}
|
|
36652
36652
|
const publicKey = bytes_Bytes.fromBlob(new Uint8Array(key), ED25519_KEY_BYTES);
|
|
36653
36653
|
return result_Result.ok({
|
|
@@ -37681,7 +37681,7 @@ function handleGetBlockSequence(chainSpec, blocks, startHash, direction, limit)
|
|
|
37681
37681
|
};
|
|
37682
37682
|
const startBlock = getBlockView(startHash);
|
|
37683
37683
|
if (startBlock === null) {
|
|
37684
|
-
return result_Result.error(BlockSequenceError.NoStartBlock);
|
|
37684
|
+
return result_Result.error(BlockSequenceError.NoStartBlock, () => `Block sequence error: start block ${startHash} not found`);
|
|
37685
37685
|
}
|
|
37686
37686
|
if (direction === Direction.AscExcl) {
|
|
37687
37687
|
// Since we don't have an index of all blocks, we need to start from
|
|
@@ -37693,7 +37693,7 @@ function handleGetBlockSequence(chainSpec, blocks, startHash, direction, limit)
|
|
|
37693
37693
|
const currentHeader = blocks.getHeader(currentHash);
|
|
37694
37694
|
// some errornuous situation, we didn't really reach the block?
|
|
37695
37695
|
if (currentHeader === null || currentHeader.timeSlotIndex.materialize() < startIndex) {
|
|
37696
|
-
return result_Result.error(BlockSequenceError.BlockOnFork);
|
|
37696
|
+
return result_Result.error(BlockSequenceError.BlockOnFork, () => `Block sequence error: start block ${startHash} appears to be on a fork`);
|
|
37697
37697
|
}
|
|
37698
37698
|
// we have everything we need, let's return it now
|
|
37699
37699
|
if (startHash.isEqualTo(currentHash)) {
|