@xyo-network/xl1-protocol-sdk 4.0.0 → 4.0.1

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.
@@ -11,6 +11,7 @@ export * from './CreatableProvider/index.ts';
11
11
  export * from './createDeclarationPayload.ts';
12
12
  export * from './createTransferPayload.ts';
13
13
  export * from './eip-712/index.ts';
14
+ export * from './getFileConfig.ts';
14
15
  export * from './instances/index.ts';
15
16
  export * from './model/index.ts';
16
17
  export * from './multipliers.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gCAAgC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gCAAgC,CAAA"}
@@ -3795,6 +3795,31 @@ var verifyEIP712Message = async (data, sig) => {
3795
3795
  return recoveredAddress.toLowerCase() === address.toLowerCase();
3796
3796
  };
3797
3797
 
3798
+ // src/getFileConfig.ts
3799
+ import { isDefined as isDefined17, isNull as isNull2 } from "@xylabs/sdk";
3800
+ import { cosmiconfig } from "cosmiconfig";
3801
+ import { z as z25 } from "zod/mini";
3802
+ var configName = "xyo";
3803
+ var configSection = "xl1";
3804
+ async function getFileConfig(searchPlaces) {
3805
+ const explorer = cosmiconfig(
3806
+ configName,
3807
+ {
3808
+ cache: true,
3809
+ searchPlaces
3810
+ }
3811
+ );
3812
+ const searchResult = await explorer.search();
3813
+ const result = searchResult?.config;
3814
+ if (!isNull2(result)) {
3815
+ const section = result[configSection];
3816
+ if (isDefined17(section) && typeof section === "object") {
3817
+ return z25.looseObject(ConfigZod.shape).parse(section);
3818
+ }
3819
+ }
3820
+ return ConfigZod.parse({});
3821
+ }
3822
+
3798
3823
  // src/multipliers.ts
3799
3824
  import { asAttoXL1 as asAttoXL14 } from "@xyo-network/xl1-protocol-lib";
3800
3825
  var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS = asAttoXL14(1343884111859145740576652n);
@@ -3861,7 +3886,7 @@ import {
3861
3886
  asHash as asHash4,
3862
3887
  assertEx as assertEx34,
3863
3888
  exists as exists3,
3864
- isDefined as isDefined17,
3889
+ isDefined as isDefined18,
3865
3890
  ZERO_ADDRESS
3866
3891
  } from "@xylabs/sdk";
3867
3892
  import {
@@ -4360,7 +4385,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
4360
4385
  block[1].find((p) => p._hash === hash),
4361
4386
  () => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
4362
4387
  );
4363
- }).filter(exists3).filter((t) => t.from === address || isDefined17(t.transfers[address]));
4388
+ }).filter(exists3).filter((t) => t.from === address || isDefined18(t.transfers[address]));
4364
4389
  if (transfers.length === 0) {
4365
4390
  continue;
4366
4391
  }
@@ -4479,7 +4504,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
4479
4504
  return await this.spanAsync("qualifiedAccountBalanceHistory", async () => {
4480
4505
  const range = asRange(headOrRange);
4481
4506
  const headHash = asHash4(headOrRange);
4482
- const [head] = assertEx34(isDefined17(headHash) ? await this.blockViewer.blockByHash(headHash) : await this.blockViewer.currentBlock(), () => "Could not resolve head block");
4507
+ const [head] = assertEx34(isDefined18(headHash) ? await this.blockViewer.blockByHash(headHash) : await this.blockViewer.currentBlock(), () => "Could not resolve head block");
4483
4508
  const startingRange = asXL1BlockRange10(range ?? [0, head.block], true);
4484
4509
  const blockNumbers = await this.distillTransferHistory(address, startingRange);
4485
4510
  const blockResults = await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)));
@@ -4493,7 +4518,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
4493
4518
  block[1].find((p) => p._hash === hash),
4494
4519
  () => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
4495
4520
  );
4496
- }).filter(exists3).filter((t) => t.from === address || isDefined17(t.transfers[address]));
4521
+ }).filter(exists3).filter((t) => t.from === address || isDefined18(t.transfers[address]));
4497
4522
  if (transfers.length === 0) {
4498
4523
  continue;
4499
4524
  }
@@ -4562,12 +4587,12 @@ var HydratedCache = class {
4562
4587
  };
4563
4588
 
4564
4589
  // src/utils/isZodError.ts
4565
- import { z as z25 } from "zod";
4590
+ import { z as z26 } from "zod";
4566
4591
  var isZodError = (error) => {
4567
- return error instanceof z25.ZodError;
4592
+ return error instanceof z26.ZodError;
4568
4593
  };
4569
4594
  var prettifyZodError = (error) => {
4570
- return z25.prettifyError(error);
4595
+ return z26.prettifyError(error);
4571
4596
  };
4572
4597
 
4573
4598
  // src/simple/block/SimpleBlockViewer.ts
@@ -5062,14 +5087,14 @@ var SimpleXyoClient = class {
5062
5087
  import { assertEx as assertEx39, exists as exists6 } from "@xylabs/sdk";
5063
5088
  import { isAnyPayload as isAnyPayload8, PayloadZodLoose } from "@xyo-network/sdk-js";
5064
5089
  import { DataLakeRunnerMoniker } from "@xyo-network/xl1-protocol-lib";
5065
- import { z as z26 } from "zod/mini";
5090
+ import { z as z27 } from "zod/mini";
5066
5091
 
5067
5092
  // src/simple/datalake/AbstractRestDataLake.ts
5068
5093
  import { FetchClientError, FetchJsonClient } from "@xylabs/sdk";
5069
5094
  import {
5070
5095
  assertEx as assertEx38,
5071
5096
  exists as exists5,
5072
- isDefined as isDefined18
5097
+ isDefined as isDefined19
5073
5098
  } from "@xylabs/sdk";
5074
5099
  import { asAnyPayload as asAnyPayload4, isAnyPayload as isAnyPayload7 } from "@xyo-network/sdk-js";
5075
5100
  var AbstractRestDataLake = class extends AbstractCreatableProvider {
@@ -5087,7 +5112,7 @@ var AbstractRestDataLake = class extends AbstractCreatableProvider {
5087
5112
  }
5088
5113
  static async paramsHandler(params = {}) {
5089
5114
  const moniker = this.defaultMoniker;
5090
- const endpoint = isDefined18(params.endpoint) && params.endpoint !== "" ? params.endpoint : resolveRestConnectionEndpoint(
5115
+ const endpoint = isDefined19(params.endpoint) && params.endpoint !== "" ? params.endpoint : resolveRestConnectionEndpoint(
5091
5116
  assertEx38(params.context?.config, () => "Context config is required to resolve REST data lake endpoint"),
5092
5117
  moniker
5093
5118
  );
@@ -5150,7 +5175,7 @@ var RestDataLakeRunner = class extends AbstractRestDataLake {
5150
5175
  }).filter(exists6);
5151
5176
  if (allowedItems.length > 0) {
5152
5177
  const result = await this.client.post(`${this.params.endpoint}/insert`, allowedItems);
5153
- return z26.array(PayloadZodLoose).parse(result.data);
5178
+ return z27.array(PayloadZodLoose).parse(result.data);
5154
5179
  }
5155
5180
  return [];
5156
5181
  }
@@ -5427,7 +5452,7 @@ var SimpleXyoGateway = class _SimpleXyoGateway extends AbstractCreatableProvider
5427
5452
  import {
5428
5453
  assertEx as assertEx42,
5429
5454
  BigIntToJsonZod,
5430
- isDefined as isDefined19
5455
+ isDefined as isDefined20
5431
5456
  } from "@xylabs/sdk";
5432
5457
  import { PayloadBuilder as PayloadBuilder20 } from "@xyo-network/sdk-js";
5433
5458
  import {
@@ -5465,9 +5490,9 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
5465
5490
  chain,
5466
5491
  fees
5467
5492
  } = options ?? {};
5468
- const resolvedChainId = isDefined19(chain) ? chain : await viewer.chainId();
5469
- const resolvedNbf = asXL1BlockNumber10(isDefined19(nbf) ? nbf : await viewer.currentBlockNumber(), true);
5470
- const resolvedExp = asXL1BlockNumber10(isDefined19(exp) ? exp : resolvedNbf + 10, true);
5493
+ const resolvedChainId = isDefined20(chain) ? chain : await viewer.chainId();
5494
+ const resolvedNbf = asXL1BlockNumber10(isDefined20(nbf) ? nbf : await viewer.currentBlockNumber(), true);
5495
+ const resolvedExp = asXL1BlockNumber10(isDefined20(exp) ? exp : resolvedNbf + 10, true);
5471
5496
  const tx = await buildUnsignedTransaction(resolvedChainId, onChain, offChain, resolvedNbf, resolvedExp, await this.signer.address(), fees);
5472
5497
  return await this.addTransactionToChain(tx, await PayloadBuilder20.addHashMeta(offChain));
5473
5498
  }
@@ -5965,7 +5990,7 @@ SimpleMempoolRunner = __decorateClass([
5965
5990
  import {
5966
5991
  assertEx as assertEx44,
5967
5992
  exists as exists9,
5968
- isDefined as isDefined20,
5993
+ isDefined as isDefined21,
5969
5994
  isHash as isHash2
5970
5995
  } from "@xylabs/sdk";
5971
5996
  import { isHashMeta as isHashMeta2, isPayloadBundle as isPayloadBundle2 } from "@xyo-network/sdk-js";
@@ -6036,7 +6061,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
6036
6061
  let cursor;
6037
6062
  if (isHash2(providedCursor)) {
6038
6063
  const [p] = await this.pendingBlocksArchivist.get([providedCursor]);
6039
- if (isDefined20(p)) {
6064
+ if (isDefined21(p)) {
6040
6065
  cursor = p._sequence;
6041
6066
  }
6042
6067
  }
@@ -6056,7 +6081,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
6056
6081
  let cursor;
6057
6082
  if (isHash2(providedCursor)) {
6058
6083
  const [p] = await this.pendingTransactionsArchivist.get([providedCursor]);
6059
- if (isDefined20(p)) {
6084
+ if (isDefined21(p)) {
6060
6085
  cursor = p._sequence;
6061
6086
  }
6062
6087
  }
@@ -6129,7 +6154,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
6129
6154
  const hydratedResults = await Promise.all(
6130
6155
  filteredBundles.map(async (bundle3) => {
6131
6156
  const tx = await bundledPayloadToHydratedTransaction(bundle3);
6132
- return isDefined20(tx) ? { bundle: bundle3, tx } : void 0;
6157
+ return isDefined21(tx) ? { bundle: bundle3, tx } : void 0;
6133
6158
  })
6134
6159
  );
6135
6160
  return hydratedResults.filter(exists9);
@@ -6425,7 +6450,7 @@ var SimpleXyoSigner = class _SimpleXyoSigner extends AbstractCreatableProvider {
6425
6450
  };
6426
6451
 
6427
6452
  // src/simple/StakeEventsViewer/SimpleStakeEventsViewer.ts
6428
- import { isDefined as isDefined21 } from "@xylabs/sdk";
6453
+ import { isDefined as isDefined22 } from "@xylabs/sdk";
6429
6454
  import { StakeEventsViewerMoniker } from "@xyo-network/xl1-protocol-lib";
6430
6455
  var SimpleStakeEventsViewer = class extends AbstractCreatableProvider {
6431
6456
  moniker = SimpleStakeEventsViewer.defaultMoniker;
@@ -6438,7 +6463,7 @@ var SimpleStakeEventsViewer = class extends AbstractCreatableProvider {
6438
6463
  stakeEvents(range, { name } = {}) {
6439
6464
  const positions = this.positionsFromRange(range);
6440
6465
  const events = this.eventsFromPositions(positions);
6441
- if (isDefined21(name)) {
6466
+ if (isDefined22(name)) {
6442
6467
  return events.filter((event) => event.name === name);
6443
6468
  }
6444
6469
  return events;
@@ -6825,7 +6850,7 @@ SimpleSystemStatusViewer = __decorateClass([
6825
6850
  import {
6826
6851
  asHash as asHash5,
6827
6852
  assertEx as assertEx51,
6828
- isDefined as isDefined22
6853
+ isDefined as isDefined23
6829
6854
  } from "@xylabs/sdk";
6830
6855
  import {
6831
6856
  asTimePayload as asTimePayload2,
@@ -6849,7 +6874,7 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
6849
6874
  const [block, payloads] = assertEx51(await this.blockViewer.blockByNumber(asXL1BlockNumber11(from, true)), () => "Block not found");
6850
6875
  const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
6851
6876
  const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
6852
- const timePayload = asTimePayload2(isDefined22(hash) ? payloads.find((p) => p._hash === hash) : void 0);
6877
+ const timePayload = asTimePayload2(isDefined23(hash) ? payloads.find((p) => p._hash === hash) : void 0);
6853
6878
  if (timePayload === void 0) return 0;
6854
6879
  switch (toDomain) {
6855
6880
  case "xl1": {
@@ -6923,7 +6948,7 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
6923
6948
  xl1Hash: assertEx51(xl1Hash, () => "No xl1 hash available from time sync service"),
6924
6949
  epoch: Date.now()
6925
6950
  };
6926
- if (isDefined22(this.ethProvider)) {
6951
+ if (isDefined23(this.ethProvider)) {
6927
6952
  const [ethereum, ethHashOrNull] = await this.currentTimeAndHash("ethereum");
6928
6953
  const ethereumHash = asHash5(ethHashOrNull, () => "No ethereum hash available from time sync service");
6929
6954
  timePayload.ethereum = ethereum;
@@ -7152,7 +7177,7 @@ SimpleTransactionViewer = __decorateClass([
7152
7177
  import {
7153
7178
  assertEx as assertEx54,
7154
7179
  exists as exists11,
7155
- isNull as isNull2
7180
+ isNull as isNull3
7156
7181
  } from "@xylabs/sdk";
7157
7182
  import { MemoryMap as MemoryMap2 } from "@xyo-network/xl1-driver-memory";
7158
7183
  import {
@@ -7303,10 +7328,10 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
7303
7328
  let cursor = await this._blockViewer.currentBlock();
7304
7329
  const previousHead = this._chain.length > 0 ? await this.currentBlockHash() : null;
7305
7330
  const newBlocks = [];
7306
- while (!isNull2(cursor) && cursor[0]._hash !== previousHead && newBlocks.length < this.maxWindowSize) {
7331
+ while (!isNull3(cursor) && cursor[0]._hash !== previousHead && newBlocks.length < this.maxWindowSize) {
7307
7332
  newBlocks.unshift(cursor);
7308
7333
  const previousHash = newBlocks[0][0].previous;
7309
- cursor = isNull2(previousHash) ? null : await this._blockViewer.blockByHash(previousHash);
7334
+ cursor = isNull3(previousHash) ? null : await this._blockViewer.blockByHash(previousHash);
7310
7335
  }
7311
7336
  for (const block of newBlocks) {
7312
7337
  this.addBlock(block);
@@ -7483,7 +7508,7 @@ import {
7483
7508
  } from "@xyo-network/xl1-protocol-lib";
7484
7509
 
7485
7510
  // src/test/buildBlock.ts
7486
- import { assertEx as assertEx55, isDefined as isDefined23 } from "@xylabs/sdk";
7511
+ import { assertEx as assertEx55, isDefined as isDefined24 } from "@xylabs/sdk";
7487
7512
  import {
7488
7513
  asAnyPayload as asAnyPayload5,
7489
7514
  BoundWitnessBuilder as BoundWitnessBuilder4,
@@ -7567,7 +7592,7 @@ function buildStepHashes(blockNumber, inStepHashes, previousBlockHash, chainStep
7567
7592
  completedStepRewardTransfers.push(createTransferPayload(chainStepRewardAddress2, { [completedStepRewardHolderAddress]: completedStepReward }));
7568
7593
  }
7569
7594
  step_hashes.push(assertEx55(previousBlockHash, () => `Previous block hash is required for step ${step} at block ${blockNumber}`));
7570
- } else if (isDefined23(inStepHashes.at(i))) {
7595
+ } else if (isDefined24(inStepHashes.at(i))) {
7571
7596
  step_hashes.push(inStepHashes[i]);
7572
7597
  }
7573
7598
  }
@@ -7869,8 +7894,8 @@ var getUrl = (host, port) => {
7869
7894
  var TODO = true;
7870
7895
 
7871
7896
  // src/validation/schema/Mnemonic.ts
7872
- import { z as z27 } from "zod";
7873
- var MnemonicStringZod = z27.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine(
7897
+ import { z as z28 } from "zod";
7898
+ var MnemonicStringZod = z28.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine(
7874
7899
  (s) => [12, 15, 18, 21, 24].includes(s.split(" ").length),
7875
7900
  { message: "Mnemonic must contain 12, 15, 18, 21, or 24 words." }
7876
7901
  ).describe("BIP-39 mnemonic string");
@@ -8102,6 +8127,7 @@ export {
8102
8127
  generateXyoBaseWalletFromPhrase,
8103
8128
  getArchivistFactory,
8104
8129
  getBlockRateBlocks,
8130
+ getFileConfig,
8105
8131
  getProducerKey,
8106
8132
  getTestProviderContext2 as getTestProviderContext,
8107
8133
  getTestSimpleBlockViewerLocator,