@palliora.org/chainsdk 0.3.2 → 0.4.0

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/dist/index.cjs CHANGED
@@ -201,9 +201,16 @@ var API_TYPES = {
201
201
  active: "u32",
202
202
  maximum: "u32"
203
203
  },
204
+ CurrencyId: {
205
+ _enum: {
206
+ Native: "Null",
207
+ USDC: "Null",
208
+ ForeignAsset: "u32"
209
+ }
210
+ },
204
211
  GuardianNwParams: {
205
212
  kzg: "Vec<u8>",
206
- agg_key: "Vec<u8>"
213
+ aggKey: "Vec<u8>"
207
214
  },
208
215
  AppId: "Compact<u32>",
209
216
  DataLookupItem: {
@@ -254,9 +261,9 @@ var API_TYPES = {
254
261
  verifier: "u128"
255
262
  },
256
263
  SilentThresholdParams: {
257
- td_params: "Vec<u8>",
258
- pk_bytes: "Vec<u8>",
259
- tau_params: "Vec<u8>"
264
+ tdParams: "Vec<u8>",
265
+ pkBytes: "Vec<u8>",
266
+ tauParams: "Vec<u8>"
260
267
  },
261
268
  ThresholdParams: {
262
269
  _enum: {
@@ -282,16 +289,16 @@ var API_TYPES = {
282
289
  }
283
290
  },
284
291
  Secp256k1Params: {
285
- recipient_public_key: "Vec<u8>",
286
- ephemeral_public_key: "Option<Vec<u8>>",
292
+ recipientPublicKey: "Vec<u8>",
293
+ ephemeralPublicKey: "Option<Vec<u8>>",
287
294
  compressed: "bool",
288
295
  kdf: "KdfParams",
289
296
  salt: "Option<Vec<u8>>",
290
297
  info: "Option<Vec<u8>>"
291
298
  },
292
299
  Ed25519Params: {
293
- recipient_public_key: "Vec<u8>",
294
- ephemeral_public_key: "Option<Vec<u8>>",
300
+ recipientPublicKey: "Vec<u8>",
301
+ ephemeralPublicKey: "Option<Vec<u8>>",
295
302
  kdf: "KdfParams",
296
303
  salt: "Option<Vec<u8>>",
297
304
  info: "Option<Vec<u8>>"
@@ -303,12 +310,12 @@ var API_TYPES = {
303
310
  }
304
311
  },
305
312
  ThresholdHybridParams: {
306
- threshold_params: "ThresholdParams",
307
- symmetric_params: "SymmetricParams"
313
+ thresholdParams: "ThresholdParams",
314
+ symmetricParams: "SymmetricParams"
308
315
  },
309
316
  AsymmetricHybridParams: {
310
- asymmetric_params: "AsymmetricParams",
311
- symmetric_params: "SymmetricParams"
317
+ asymmetricParams: "AsymmetricParams",
318
+ symmetricParams: "SymmetricParams"
312
319
  },
313
320
  CipherSuite: {
314
321
  _enum: {
@@ -326,7 +333,7 @@ var API_TYPES = {
326
333
  }
327
334
  },
328
335
  NativeExecuteDA: {
329
- _enum: ["Inference"]
336
+ _enum: ["Inference", "ContractAccess"]
330
337
  },
331
338
  NativeDataDA: {
332
339
  _enum: ["DaFalse", "DaTrue"]
@@ -335,8 +342,11 @@ var API_TYPES = {
335
342
  data: "Vec<u8>"
336
343
  },
337
344
  DAInputChainTransaction: {
338
- block_number: "u64",
339
- extrinsic_index: "u32"
345
+ blockNumber: "u64",
346
+ extrinsicIndex: "u32"
347
+ },
348
+ DAInputContractId: {
349
+ id: "[u8; 32]"
340
350
  },
341
351
  DAInputIpfs: {
342
352
  cid: "Vec<u8>",
@@ -352,6 +362,7 @@ var API_TYPES = {
352
362
  Null: "Null",
353
363
  Inline: "DAInputInline",
354
364
  ChainTransaction: "DAInputChainTransaction",
365
+ ContractId: "DAInputContractId",
355
366
  Ipfs: "DAInputIpfs",
356
367
  Url: "DAInputUrl",
357
368
  NativeExecute: "NativeExecuteDA",
@@ -361,7 +372,8 @@ var API_TYPES = {
361
372
  ContractType: {
362
373
  _enum: {
363
374
  Dormant: "Null",
364
- Active: "Null"
375
+ Active: "Null",
376
+ Subscription: "Null"
365
377
  }
366
378
  },
367
379
  StoreType: {
@@ -375,28 +387,30 @@ var API_TYPES = {
375
387
  ComputeMetadata: {
376
388
  name: "Vec<u8>",
377
389
  description: "Vec<u8>",
378
- store_type: "StoreType",
379
- group_id: "H256"
390
+ storeType: "StoreType",
391
+ groupId: "H256"
380
392
  },
381
393
  ComputeInfo: {
382
394
  cipher: "CipherSuite",
383
- computer_indices: "Vec<u32>",
395
+ computerIndices: "Vec<u32>",
384
396
  fees: "u128",
397
+ computeRate: "u128",
385
398
  deadline: "u64",
386
399
  confidentiality: "ConfidentialityLevel",
387
- fee_function: "Option<u8>",
388
- program_env: "Option<Vec<u8>>",
400
+ feeFunction: "Option<u8>",
401
+ programEnv: "Option<Vec<u8>>",
389
402
  input: "DAInput",
390
403
  program: "DAInput",
391
404
  metadata: "Option<ComputeMetadata>"
392
405
  },
393
406
  Contract: {
394
- contract_type: "ContractType",
407
+ contractType: "ContractType",
395
408
  guardians: "Vec<AccountId>",
396
- pre_check: "Option<ComputeInfo>",
409
+ preCheck: "Option<ComputeInfo>",
397
410
  compute: "ComputeInfo",
398
- post_check: "Option<ComputeInfo>",
399
- result_cipher: "CipherSuite"
411
+ postCheck: "Option<ComputeInfo>",
412
+ resultCipher: "CipherSuite",
413
+ currencyId: "CurrencyId"
400
414
  },
401
415
  AgreementInfo: {
402
416
  status: "AgreementStatus",
@@ -404,7 +418,7 @@ var API_TYPES = {
404
418
  index: "u32"
405
419
  },
406
420
  ComputePayload: {
407
- da_type: "u8",
421
+ daType: "u8",
408
422
  agreement: "Option<BoundedVec<[u8; 32], 10>>",
409
423
  verification: "u8",
410
424
  compute: "u8"
@@ -480,10 +494,46 @@ var API_TYPES = {
480
494
  GRawScalar: "U256",
481
495
  GProof: "[u8; 48]",
482
496
  GRow: "Vec<GRawScalar>",
483
- GDataProof: "(GRawScalar, GProof)"
497
+ GDataProof: "(GRawScalar, GProof)",
498
+ AgreementStatus: {
499
+ _enum: ["NotFound", "Pending", "Accepted", "Rejected", "Settled"]
500
+ },
501
+ AcceptedSubStatus: {
502
+ _enum: ["Running", "AwaitingTopUp", "TopUpReceived", "RejectedInsufficientBudget", "RejectedRateMismatch"]
503
+ },
504
+ RejectedSubStatus: {
505
+ _enum: ["InsufficientBudget", "RateMismatch"]
506
+ },
507
+ SettlementReason: {
508
+ _enum: ["ResultReceived", "DeadlineReached", "BudgetExhausted"]
509
+ },
510
+ ExecutionOutcome: {
511
+ _enum: ["FullSettlement", "PartialSettlement", "Success", "Failed", "Terminated", "TopUpTimeout"]
512
+ },
513
+ ContractInfo: {
514
+ status: "AgreementStatus",
515
+ owner: "AccountId",
516
+ originBlock: "u32",
517
+ invocationBlock: "u32",
518
+ index: "u32",
519
+ usagePrice: "u128",
520
+ contractType: "ContractType"
521
+ },
522
+ SettlementInfo: {
523
+ computeRate: "u128",
524
+ inputContractId: "Option<[u8; 32]>",
525
+ guardians: "Vec<AccountId>"
526
+ },
527
+ AppKeyInfo: {
528
+ owner: "AccountId",
529
+ id: "AppId"
530
+ },
531
+ DataType: {
532
+ _enum: ["Dataset", "Model", "Agent"]
533
+ }
484
534
  };
485
- var DEFAULT_COMPUTE_PAYLOAD = { compute: { da_type: 0, verification: 0, compute: 0 } };
486
- var DEFAULT_EMPTY_PAYLOAD = { compute: { da_type: 0, verification: 0, compute: 0, agreement: [] } };
535
+ var DEFAULT_COMPUTE_PAYLOAD = { compute: { daType: 0, verification: 0, compute: 0 } };
536
+ var DEFAULT_EMPTY_PAYLOAD = { compute: { daType: 0, verification: 0, compute: 0, agreement: [] } };
487
537
  var API_EXTENSIONS = {
488
538
  CheckAppId: {
489
539
  extrinsic: {
@@ -496,6 +546,18 @@ var API_EXTENSIONS = {
496
546
  compute: "ComputePayload"
497
547
  },
498
548
  payload: {}
549
+ },
550
+ // Replaces pallet_transaction_payment::ChargeTransactionPayment. Since this
551
+ // identifier isn't one @polkadot/api knows natively, this definition entirely
552
+ // replaces (not merges with) the built-in one, so `tip` must be re-declared
553
+ // here alongside the new `currencyId` field or it silently drops from the
554
+ // encoded extra bytes, shifting every extrinsic out of alignment.
555
+ ChargeCurrencyTransactionPayment: {
556
+ extrinsic: {
557
+ tip: "Compact<Balance>",
558
+ currencyId: "Option<CurrencyId>"
559
+ },
560
+ payload: {}
499
561
  }
500
562
  };
501
563
 
@@ -1079,8 +1141,9 @@ async function joinGuardian(account, prefs) {
1079
1141
 
1080
1142
  // src/chain/utils.ts
1081
1143
  var signAndSend = async (request, account, opts = DEFAULT_COMPUTE_PAYLOAD) => {
1144
+ const signOpts = { currencyId: null, ...opts };
1082
1145
  const tx_result = await new Promise((res, err) => {
1083
- request.signAndSend(account, opts, (result) => {
1146
+ request.signAndSend(account, signOpts, (result) => {
1084
1147
  if (result.isFinalized) {
1085
1148
  res(result);
1086
1149
  }
@@ -1400,7 +1463,7 @@ var MCryptFsWriter = class {
1400
1463
  );
1401
1464
  console.log("account: ", this._account);
1402
1465
  return new Promise((resolve) => {
1403
- request.signAndSend(this._account, { app_id: 1 }, (result) => {
1466
+ request.signAndSend(this._account, { app_id: 1, currencyId: null }, (result) => {
1404
1467
  if (result.isInBlock || result.isFinalized || result.isError) {
1405
1468
  resolve({
1406
1469
  blockNumber: _nullishCoalesce(_optionalChain([result, 'access', _87 => _87.blockNumber, 'optionalAccess', _88 => _88.toNumber, 'call', _89 => _89()]), () => ( 0)),
@@ -1515,15 +1578,22 @@ var FileFromMetadataRef = async (mcryptApi, metadataRef) => {
1515
1578
  };
1516
1579
 
1517
1580
  // src/compute/agreement.ts
1518
- async function createAgreement(contract, account) {
1581
+ function buildFee(fee) {
1582
+ return {
1583
+ fees: toAtomicPaliAmount(_nullishCoalesce(_optionalChain([fee, 'optionalAccess', _90 => _90.amount]), () => ( "0"))),
1584
+ computeRate: toAtomicPaliAmount(_nullishCoalesce(_optionalChain([fee, 'optionalAccess', _91 => _91.computeRate]), () => ( "0")))
1585
+ };
1586
+ }
1587
+ async function createAgreement(contract, account, oracle_quore_id = void 0) {
1519
1588
  const api2 = await getApi();
1520
1589
  if (!api2) throw new Error("Api not initialized");
1521
- const tx = api2.tx["compute"]["agreement"](contract);
1590
+ const onChainContract = { currencyId: "Native", ...contract };
1591
+ const tx = api2.tx["compute"]["agreement"](onChainContract, _nullishCoalesce(oracle_quore_id, () => ( null)));
1522
1592
  const opts = {
1523
1593
  compute: {
1524
- da_type: 1,
1594
+ daType: 1,
1525
1595
  verification: 0,
1526
- compute: contract.contract_type === "Active" ? 1 : 0
1596
+ compute: contract.contractType === "Active" ? 1 : 0
1527
1597
  }
1528
1598
  };
1529
1599
  const { tx_result, blockNumber, index, hash } = await signAndSend(
@@ -1543,7 +1613,7 @@ async function createAgreement(contract, account) {
1543
1613
  blockNumber,
1544
1614
  index: _nullishCoalesce(index, () => ( 0)),
1545
1615
  hash,
1546
- agreementId: _nullishCoalesce(_optionalChain([agreementCreatedEvent, 'access', _90 => _90.event, 'access', _91 => _91.data, 'access', _92 => _92[0], 'optionalAccess', _93 => _93.toHex, 'optionalCall', _94 => _94()]), () => ( agreementCreatedEvent.event.data.toString()))
1616
+ agreementId: _nullishCoalesce(_optionalChain([agreementCreatedEvent, 'access', _92 => _92.event, 'access', _93 => _93.data, 'access', _94 => _94[0], 'optionalAccess', _95 => _95.toHex, 'optionalCall', _96 => _96()]), () => ( agreementCreatedEvent.event.data.toString()))
1547
1617
  };
1548
1618
  } else {
1549
1619
  debugLog("AgreementCreated event not found");
@@ -1555,22 +1625,22 @@ async function createSimpleAgreement() {
1555
1625
  const guardianIds = (await getGuardianAddress()).slice(0, 3).map((g) => g.address);
1556
1626
  assert(guardianIds.length === 3, "Not enough guardians to create agreement");
1557
1627
  const contract = {
1558
- contract_type: "Dormant",
1628
+ contractType: "Dormant",
1559
1629
  guardians: guardianIds,
1560
- pre_check: null,
1630
+ preCheck: null,
1561
1631
  compute: {
1562
1632
  cipher: "Plaintext",
1563
- computer_indices: [0, 1, 2],
1564
- fees: toAtomicPaliAmount("0.01"),
1633
+ computerIndices: [0, 1, 2],
1634
+ ...buildFee({ amount: "0", computeRate: "0" }),
1565
1635
  deadline: 0,
1566
1636
  confidentiality: { Trusted: 0 },
1567
- fee_function: null,
1637
+ feeFunction: null,
1568
1638
  input: null,
1569
1639
  program: { NativeData: "DaFalse" },
1570
1640
  metadata: null
1571
1641
  },
1572
- post_check: null,
1573
- result_cipher: "Plaintext"
1642
+ postCheck: null,
1643
+ resultCipher: "Plaintext"
1574
1644
  };
1575
1645
  const keyring2 = await getKeyring();
1576
1646
  const account = keyring2.getPairs()[0];
@@ -1580,14 +1650,13 @@ async function createSimpleAgreement() {
1580
1650
  // src/compute/data.ts
1581
1651
  async function dataContract(params, account) {
1582
1652
  const plaintextCipher = "Plaintext";
1583
- const atomicFees = toAtomicPaliAmount(_nullishCoalesce(params.fees, () => ( "0")));
1584
1653
  const computeStep = {
1585
1654
  cipher: plaintextCipher,
1586
- computer_indices: params.guardians.map((_, i) => i),
1587
- fees: atomicFees,
1655
+ computerIndices: params.guardians.map((_, i) => i),
1656
+ ...buildFee(params.fee),
1588
1657
  deadline: _nullishCoalesce(params.deadline, () => ( 0)),
1589
1658
  confidentiality: { Trusted: _nullishCoalesce(params.trustIndex, () => ( 0)) },
1590
- fee_function: null,
1659
+ feeFunction: null,
1591
1660
  input: {
1592
1661
  Url: {
1593
1662
  url: Array.from(new TextEncoder().encode(params.url))
@@ -1598,36 +1667,132 @@ async function dataContract(params, account) {
1598
1667
  }
1599
1668
  };
1600
1669
  const contract = {
1601
- contract_type: "Dormant",
1670
+ contractType: "Dormant",
1671
+ guardians: params.guardians,
1672
+ preCheck: null,
1673
+ compute: computeStep,
1674
+ postCheck: null,
1675
+ resultCipher: plaintextCipher
1676
+ };
1677
+ return createAgreement(contract, account);
1678
+ }
1679
+
1680
+ // src/compute/encryptedInference.ts
1681
+
1682
+
1683
+ // src/crypto/random.ts
1684
+ function generateRandomBytes(length = 32) {
1685
+ const bytes = new Uint8Array(length);
1686
+ const cr = globalThis.crypto;
1687
+ if (!cr || typeof cr.getRandomValues !== "function") {
1688
+ throw new Error(
1689
+ "crypto.getRandomValues is not available. Ensure you're running in a supported environment (browser or Node.js 18+)."
1690
+ );
1691
+ }
1692
+ cr.getRandomValues(bytes);
1693
+ return bytes;
1694
+ }
1695
+
1696
+ // src/compute/encryptedInference.ts
1697
+ async function encryptedInferenceSubscription(params, account) {
1698
+ const computeStep = {
1699
+ cipher: "Plaintext",
1700
+ computerIndices: params.guardians.map((_, i) => i),
1701
+ ...buildFee(params.fee),
1702
+ deadline: _nullishCoalesce(params.deadline, () => ( 0)),
1703
+ confidentiality: { Trusted: 0 },
1704
+ feeFunction: null,
1705
+ input: null,
1706
+ program: { NativeExecute: "Inference" }
1707
+ };
1708
+ const contract = {
1709
+ contractType: "Dormant",
1602
1710
  guardians: params.guardians,
1603
- pre_check: null,
1711
+ preCheck: null,
1604
1712
  compute: computeStep,
1605
- post_check: null,
1606
- result_cipher: plaintextCipher
1713
+ postCheck: null,
1714
+ resultCipher: "Plaintext"
1607
1715
  };
1608
1716
  return createAgreement(contract, account);
1609
1717
  }
1718
+ async function encryptedInferenceSubscriptionInvocation(params, encAccount, account) {
1719
+ const api2 = await getApi();
1720
+ if (!api2) throw new Error("Api not initialized");
1721
+ const inputBytes = typeof params.input === "string" ? new TextEncoder().encode(params.input) : params.input;
1722
+ const { encoded: cyphtxt, ikm } = testCrypt(
1723
+ params.guardianInfo.tauParams,
1724
+ params.guardianInfo.aggKey
1725
+ );
1726
+ const sharedKey = gen_stretched_key(hexToUint8Array(ikm));
1727
+ const { ciphertext, nonce } = encrypt2(inputBytes, sharedKey);
1728
+ const cyphtxtBytes = hexToUint8Array(cyphtxt);
1729
+ const groupPkBytes = hexToUint8Array(params.guardianInfo.groupPk);
1730
+ const tauParamsBytes = hexToUint8Array(params.guardianInfo.tauParams);
1731
+ const tx = api2.tx["dataAvailability"]["daccComputeRequest"](
1732
+ _ed25519.edwardsToMontgomeryPub.call(void 0, encAccount.publicKey),
1733
+ nonce,
1734
+ Array.from(ciphertext),
1735
+ params.guardians[0],
1736
+ Array.from(cyphtxtBytes),
1737
+ Array.from(groupPkBytes),
1738
+ Array.from(tauParamsBytes),
1739
+ params.guardians
1740
+ );
1741
+ const idHex = params.agreementId.startsWith("0x") ? params.agreementId.slice(2) : params.agreementId;
1742
+ const opts = {
1743
+ compute: {
1744
+ da_type: 4,
1745
+ agreement: [Buffer.from(idHex, "hex")],
1746
+ verification: 0,
1747
+ compute: 1
1748
+ }
1749
+ };
1750
+ return signAndSend(tx, account, opts);
1751
+ }
1752
+ async function encryptedInferenceCompute(params, encAccount, account) {
1753
+ const subscription = await encryptedInferenceSubscription(
1754
+ {
1755
+ guardians: params.guardians,
1756
+ fee: params.fee,
1757
+ deadline: params.deadline
1758
+ },
1759
+ account
1760
+ );
1761
+ if (!subscription.agreementId) {
1762
+ throw new Error("Subscription creation did not return an agreement ID");
1763
+ }
1764
+ const invocation = await encryptedInferenceSubscriptionInvocation(
1765
+ {
1766
+ agreementId: subscription.agreementId,
1767
+ input: params.input,
1768
+ guardians: params.guardians,
1769
+ guardianInfo: params.guardianInfo
1770
+ },
1771
+ encAccount,
1772
+ account
1773
+ );
1774
+ return { subscription, invocation };
1775
+ }
1610
1776
 
1611
1777
  // src/compute/inference.ts
1612
1778
  async function inferenceCompute(params, account) {
1613
1779
  const inputData = typeof params.input === "string" ? Array.from(new TextEncoder().encode(params.input)) : Array.from(params.input);
1614
- const atomicFees = toAtomicPaliAmount(_nullishCoalesce(params.fees, () => ( "0")));
1615
1780
  const plaintextCipher = "Plaintext";
1616
1781
  const computeStep = {
1617
1782
  cipher: plaintextCipher,
1618
- computer_indices: params.guardians.map((_, i) => i),
1619
- fees: atomicFees,
1783
+ computerIndices: params.guardians.map((_, i) => i),
1784
+ ...buildFee(params.fee),
1620
1785
  deadline: _nullishCoalesce(params.deadline, () => ( 0)),
1621
1786
  confidentiality: { Trusted: 0 },
1622
- fee_function: null,
1787
+ feeFunction: null,
1623
1788
  input: { Inline: { data: inputData } },
1624
1789
  program: { NativeExecute: "Inference" }
1625
1790
  };
1626
1791
  const contract = {
1627
- contract_type: "Active",
1792
+ contractType: "Active",
1628
1793
  guardians: params.guardians,
1629
1794
  compute: computeStep,
1630
- result_cipher: plaintextCipher
1795
+ resultCipher: plaintextCipher
1631
1796
  };
1632
1797
  return createAgreement(contract, account);
1633
1798
  }
@@ -1646,8 +1811,8 @@ async function getGuardianParticipants() {
1646
1811
  const _peerid = _bs582.default.decode((peerid || "").toString());
1647
1812
  const account = await api2.query.guardian.workerByKey(_peerid.slice(6, 38));
1648
1813
  const nextIndex = currentIndex ? Number(currentIndex) + 1 : 1;
1649
- const guardiansList = _optionalChain([guardians, 'optionalAccess', _95 => _95.toJSON, 'call', _96 => _96()]) || [];
1650
- const nextGuardiansList = _optionalChain([nextGuardians, 'optionalAccess', _97 => _97.toJSON, 'call', _98 => _98()]) || [];
1814
+ const guardiansList = _optionalChain([guardians, 'optionalAccess', _97 => _97.toJSON, 'call', _98 => _98()]) || [];
1815
+ const nextGuardiansList = _optionalChain([nextGuardians, 'optionalAccess', _99 => _99.toJSON, 'call', _100 => _100()]) || [];
1651
1816
  const buildDetails = async (list) => {
1652
1817
  return Promise.all(
1653
1818
  list.map(async (guardian) => {
@@ -1656,21 +1821,21 @@ async function getGuardianParticipants() {
1656
1821
  const bonded = await api2.query.staking.bonded(guardian);
1657
1822
  const payee = await api2.query.staking.payee(guardian);
1658
1823
  const stakersOverview = await api2.query.staking.erasStakersOverview(
1659
- _optionalChain([currentEra, 'optionalAccess', _99 => _99.toPrimitive, 'call', _100 => _100()]),
1824
+ _optionalChain([currentEra, 'optionalAccess', _101 => _101.toPrimitive, 'call', _102 => _102()]),
1660
1825
  guardian
1661
1826
  );
1662
1827
  const guardianErasPrefs = await api2.query.staking.erasGuardianPrefs(
1663
- _optionalChain([currentEra, 'optionalAccess', _101 => _101.toPrimitive, 'call', _102 => _102()]),
1828
+ _optionalChain([currentEra, 'optionalAccess', _103 => _103.toPrimitive, 'call', _104 => _104()]),
1664
1829
  guardian
1665
1830
  );
1666
1831
  return {
1667
1832
  guardian,
1668
- rewardDestination: _optionalChain([payee, 'optionalAccess', _103 => _103.toHuman]) ? payee.toHuman() : null,
1669
- currentPreferences: _optionalChain([guardianErasPrefs, 'optionalAccess', _104 => _104.toHuman]) ? guardianErasPrefs.toHuman() : null,
1670
- upcomingPreferences: _optionalChain([guardianPrefs, 'optionalAccess', _105 => _105.toHuman]) ? guardianPrefs.toHuman() : null,
1671
- stash: _optionalChain([bonded, 'optionalAccess', _106 => _106.toHuman]) ? bonded.toHuman() : null,
1672
- currentStakeOverview: _optionalChain([stakersOverview, 'optionalAccess', _107 => _107.toHuman]) ? stakersOverview.toHuman() : null,
1673
- upcomingStakeOverview: _optionalChain([ledger, 'optionalAccess', _108 => _108.toHuman]) ? ledger.toHuman() : null
1833
+ rewardDestination: _optionalChain([payee, 'optionalAccess', _105 => _105.toHuman]) ? payee.toHuman() : null,
1834
+ currentPreferences: _optionalChain([guardianErasPrefs, 'optionalAccess', _106 => _106.toHuman]) ? guardianErasPrefs.toHuman() : null,
1835
+ upcomingPreferences: _optionalChain([guardianPrefs, 'optionalAccess', _107 => _107.toHuman]) ? guardianPrefs.toHuman() : null,
1836
+ stash: _optionalChain([bonded, 'optionalAccess', _108 => _108.toHuman]) ? bonded.toHuman() : null,
1837
+ currentStakeOverview: _optionalChain([stakersOverview, 'optionalAccess', _109 => _109.toHuman]) ? stakersOverview.toHuman() : null,
1838
+ upcomingStakeOverview: _optionalChain([ledger, 'optionalAccess', _110 => _110.toHuman]) ? ledger.toHuman() : null
1674
1839
  };
1675
1840
  })
1676
1841
  );
@@ -1679,12 +1844,12 @@ async function getGuardianParticipants() {
1679
1844
  const upcomingGuardians = await buildDetails(nextGuardiansList);
1680
1845
  return {
1681
1846
  nwState: {
1682
- localPeerId: _optionalChain([peerid, 'optionalAccess', _109 => _109.toString, 'call', _110 => _110()]),
1683
- worker: _optionalChain([account, 'optionalAccess', _111 => _111.toHuman]) ? account.toHuman() : null,
1684
- currentEra: _optionalChain([currentEra, 'optionalAccess', _112 => _112.toHuman]) ? currentEra.toHuman() : null,
1685
- guardians: JSON.stringify(_optionalChain([guardians, 'optionalAccess', _113 => _113.toHuman]) ? guardians.toHuman() : null, null, 2),
1686
- nextGuardians: JSON.stringify(_optionalChain([nextGuardians, 'optionalAccess', _114 => _114.toHuman]) ? nextGuardians.toHuman() : null, null, 2),
1687
- currentIndex: _optionalChain([currentIndex, 'optionalAccess', _115 => _115.toHuman]) ? currentIndex.toHuman() : null,
1847
+ localPeerId: _optionalChain([peerid, 'optionalAccess', _111 => _111.toString, 'call', _112 => _112()]),
1848
+ worker: _optionalChain([account, 'optionalAccess', _113 => _113.toHuman]) ? account.toHuman() : null,
1849
+ currentEra: _optionalChain([currentEra, 'optionalAccess', _114 => _114.toHuman]) ? currentEra.toHuman() : null,
1850
+ guardians: JSON.stringify(_optionalChain([guardians, 'optionalAccess', _115 => _115.toHuman]) ? guardians.toHuman() : null, null, 2),
1851
+ nextGuardians: JSON.stringify(_optionalChain([nextGuardians, 'optionalAccess', _116 => _116.toHuman]) ? nextGuardians.toHuman() : null, null, 2),
1852
+ currentIndex: _optionalChain([currentIndex, 'optionalAccess', _117 => _117.toHuman]) ? currentIndex.toHuman() : null,
1688
1853
  nextIndex
1689
1854
  },
1690
1855
  currentGuardians,
@@ -1698,14 +1863,13 @@ async function getGuardianParticipants() {
1698
1863
  // src/compute/simple.ts
1699
1864
  async function simpleCompute(params, account) {
1700
1865
  const plaintextCipher = "Plaintext";
1701
- const atomicFees = toAtomicPaliAmount(_nullishCoalesce(params.fees, () => ( "0")));
1702
1866
  const computeStep = {
1703
1867
  cipher: plaintextCipher,
1704
- computer_indices: params.guardians.map((_, i) => i),
1705
- fees: atomicFees,
1868
+ computerIndices: params.guardians.map((_, i) => i),
1869
+ ...buildFee(params.fee),
1706
1870
  deadline: _nullishCoalesce(params.deadline, () => ( 0)),
1707
1871
  confidentiality: { Trusted: _nullishCoalesce(params.trustIndex, () => ( 0)) },
1708
- fee_function: null,
1872
+ feeFunction: null,
1709
1873
  input: null,
1710
1874
  program: {
1711
1875
  Url: {
@@ -1714,29 +1878,16 @@ async function simpleCompute(params, account) {
1714
1878
  }
1715
1879
  };
1716
1880
  const contract = {
1717
- contract_type: "Active",
1881
+ contractType: "Active",
1718
1882
  guardians: params.guardians,
1719
- pre_check: null,
1883
+ preCheck: null,
1720
1884
  compute: computeStep,
1721
- post_check: null,
1722
- result_cipher: plaintextCipher
1885
+ postCheck: null,
1886
+ resultCipher: plaintextCipher
1723
1887
  };
1724
1888
  return createAgreement(contract, account);
1725
1889
  }
1726
1890
 
1727
- // src/crypto/random.ts
1728
- function generateRandomBytes(length = 32) {
1729
- const bytes = new Uint8Array(length);
1730
- const cr = globalThis.crypto;
1731
- if (!cr || typeof cr.getRandomValues !== "function") {
1732
- throw new Error(
1733
- "crypto.getRandomValues is not available. Ensure you're running in a supported environment (browser or Node.js 18+)."
1734
- );
1735
- }
1736
- cr.getRandomValues(bytes);
1737
- return bytes;
1738
- }
1739
-
1740
1891
  // src/da/register.ts
1741
1892
  async function writeMetadata(account, name, description, ref, price, dataType, l2Owner, groupId) {
1742
1893
  const blobRef = [ref.blockNumber, ref.index];
@@ -1762,7 +1913,7 @@ async function writeMetadata(account, name, description, ref, price, dataType, l
1762
1913
  }
1763
1914
  async function registerDataAgreement(account, params) {
1764
1915
  debugLog(
1765
- `Registering data agreement for DA ref ${params.ref.blockNumber}-${params.ref.index} at ${formatPaliAmount(params.fees)}`
1916
+ `Registering data agreement for DA ref ${params.ref.blockNumber}-${params.ref.index} at ${formatPaliAmount(toAtomicPaliAmount(_nullishCoalesce(params.fee.amount, () => ( "0"))))}`
1766
1917
  );
1767
1918
  const cipher = _nullishCoalesce(params.cipher, () => ( "Plaintext"));
1768
1919
  const resultCipher = _nullishCoalesce(params.resultCipher, () => ( "Plaintext"));
@@ -1770,20 +1921,20 @@ async function registerDataAgreement(account, params) {
1770
1921
  const computeMetadata = params.metadata ? {
1771
1922
  name: Array.from(encoder.encode(params.metadata.name)),
1772
1923
  description: Array.from(encoder.encode(params.metadata.description)),
1773
- store_type: params.metadata.storeType,
1774
- group_id: params.metadata.groupId
1924
+ storeType: params.metadata.storeType,
1925
+ groupId: params.metadata.groupId
1775
1926
  } : null;
1776
1927
  const computeStep = {
1777
1928
  cipher,
1778
- computer_indices: params.guardians.map((_, i) => i),
1779
- fees: params.fees,
1929
+ computerIndices: params.guardians.map((_, i) => i),
1930
+ ...buildFee(params.fee),
1780
1931
  deadline: _nullishCoalesce(params.deadline, () => ( 0)),
1781
1932
  confidentiality: { Trusted: _nullishCoalesce(params.trustIndex, () => ( 0)) },
1782
- fee_function: null,
1933
+ feeFunction: null,
1783
1934
  input: {
1784
1935
  ChainTransaction: {
1785
- block_number: params.ref.blockNumber,
1786
- extrinsic_index: params.ref.index
1936
+ blockNumber: params.ref.blockNumber,
1937
+ extrinsicIndex: params.ref.index
1787
1938
  }
1788
1939
  },
1789
1940
  program: {
@@ -1792,12 +1943,12 @@ async function registerDataAgreement(account, params) {
1792
1943
  metadata: computeMetadata
1793
1944
  };
1794
1945
  const contract = {
1795
- contract_type: "Dormant",
1946
+ contractType: "Dormant",
1796
1947
  guardians: params.guardians,
1797
- pre_check: null,
1948
+ preCheck: null,
1798
1949
  compute: computeStep,
1799
- post_check: null,
1800
- result_cipher: resultCipher
1950
+ postCheck: null,
1951
+ resultCipher
1801
1952
  };
1802
1953
  return createAgreement(contract, account);
1803
1954
  }
@@ -1822,7 +1973,7 @@ async function runAgent(account, agentRef, nonce, ciphertext, tdParams, pkBytes,
1822
1973
  );
1823
1974
  const opts = {
1824
1975
  compute: {
1825
- da_type: 4,
1976
+ daType: 4,
1826
1977
  verification: 0,
1827
1978
  compute: 1,
1828
1979
  agreement: [agreementId]
@@ -1881,14 +2032,14 @@ async function submitTEDataWithCipher(account, data, chosenGuardians, tau_params
1881
2032
  ref,
1882
2033
  cipher: {
1883
2034
  ThresholdHybrid: {
1884
- threshold_params: {
2035
+ thresholdParams: {
1885
2036
  SilentThreshold: {
1886
- td_params: Array.from(hexToUint8Array(encryptedKey)),
1887
- pk_bytes: Array.from(hexToUint8Array(group_pk)),
1888
- tau_params: Array.from(hexToUint8Array(tau_params))
2037
+ tdParams: Array.from(hexToUint8Array(encryptedKey)),
2038
+ pkBytes: Array.from(hexToUint8Array(group_pk)),
2039
+ tauParams: Array.from(hexToUint8Array(tau_params))
1889
2040
  }
1890
2041
  },
1891
- symmetric_params: {
2042
+ symmetricParams: {
1892
2043
  ChaCha20Poly1305: { nonce: Array.from(nonce) }
1893
2044
  }
1894
2045
  }
@@ -1907,7 +2058,6 @@ async function uploadData(options) {
1907
2058
  );
1908
2059
  console.log("Guardian group info:", guardianGroupInfo);
1909
2060
  const account = (await getKeyring()).pairs[0];
1910
- const atomicPrice = toAtomicPaliAmount(price);
1911
2061
  if (filePath) {
1912
2062
  throw new Error("uploadData: file path upload is not implemented");
1913
2063
  } else {
@@ -1923,7 +2073,7 @@ async function uploadData(options) {
1923
2073
  await registerDataAgreement(account, {
1924
2074
  ref: dataRef,
1925
2075
  guardians: guardianGroupInfo.guardians,
1926
- fees: atomicPrice,
2076
+ fee: { amount: price },
1927
2077
  cipher,
1928
2078
  metadata: {
1929
2079
  name,
@@ -2053,9 +2203,9 @@ async function removeStake(account) {
2053
2203
  const api2 = await getApi();
2054
2204
  assert(api2, "API not initialized");
2055
2205
  assert(account, "Account not initialized");
2056
- const stakeAmount = await _asyncOptionalChain([(await api2.query.staking.ledger(account.address)), 'optionalAccess', async _116 => _116.toPrimitive, 'call', async _117 => _117()]);
2057
- debugLog("Removing entire stake amount:", formatPaliAmount(_optionalChain([stakeAmount, 'optionalAccess', _118 => _118.active]) || 0n));
2058
- const unstakeTx = api2.tx.staking.unbond(_optionalChain([stakeAmount, 'optionalAccess', _119 => _119.active]) || 0n);
2206
+ const stakeAmount = await _asyncOptionalChain([(await api2.query.staking.ledger(account.address)), 'optionalAccess', async _118 => _118.toPrimitive, 'call', async _119 => _119()]);
2207
+ debugLog("Removing entire stake amount:", formatPaliAmount(_optionalChain([stakeAmount, 'optionalAccess', _120 => _120.active]) || 0n));
2208
+ const unstakeTx = api2.tx.staking.unbond(_optionalChain([stakeAmount, 'optionalAccess', _121 => _121.active]) || 0n);
2059
2209
  const hash = await signAndSend(unstakeTx, account);
2060
2210
  debugLog(`Unstake transaction sent with hash: ${hash.hash}`);
2061
2211
  }
@@ -2124,7 +2274,7 @@ async function rotateAndSetKeys(account) {
2124
2274
  _assert2.default.call(void 0, api2, "API not initialized");
2125
2275
  debugLog(`Rotating session keys for ${account.meta.name} on ${provider.endpoint}`);
2126
2276
  const newKeys = await api2.rpc.author.rotateKeys();
2127
- debugLog(`${account.meta.name} rotated keys on ${provider.endpoint}:`, _nullishCoalesce(_optionalChain([newKeys, 'optionalAccess', _120 => _120.toHex, 'optionalCall', _121 => _121()]), () => ( newKeys)));
2277
+ debugLog(`${account.meta.name} rotated keys on ${provider.endpoint}:`, _nullishCoalesce(_optionalChain([newKeys, 'optionalAccess', _122 => _122.toHex, 'optionalCall', _123 => _123()]), () => ( newKeys)));
2128
2278
  const setKeysTx = api2.tx.session.setKeys(newKeys, []);
2129
2279
  const hash = await signAndSend(setKeysTx, account);
2130
2280
  debugLog(`Rotate session transaction sent with hash: ${hash.hash}`);
@@ -2694,5 +2844,9 @@ _ss58 = new WeakMap();
2694
2844
 
2695
2845
 
2696
2846
 
2697
- exports.API_EXTENSIONS = API_EXTENSIONS; exports.API_RPC = API_RPC; exports.API_TYPES = API_TYPES; exports.AccountSourceType = AccountSourceType; exports.ApiPromise = _api2.ApiPromise; exports.CryptoType = CryptoType; exports.DEBUG = DEBUG; exports.DEFAULT_COMPUTE_PAYLOAD = DEFAULT_COMPUTE_PAYLOAD; exports.DEFAULT_EMPTY_PAYLOAD = DEFAULT_EMPTY_PAYLOAD; exports.FileFromMetadataRef = FileFromMetadataRef; exports.HttpProvider = _api2.HttpProvider; exports.Keyring = Keyring3; exports.MCryptFs = MCryptFs; exports.MCryptFsReader = MCryptFsReader; exports.MCryptFsWriter = MCryptFsWriter; exports.PALI_DECIMALS = PALI_DECIMALS; exports.PALI_SYMBOL = PALI_SYMBOL; exports.PALLIORA_RPC_URL = PALLIORA_RPC_URL; exports.PALLIORA_WS = PALLIORA_WS; exports.TX_WAIT_FINALIZATION = TX_WAIT_FINALIZATION; exports.WsProvider = _api2.WsProvider; exports.addStake = addStake; exports.base64ToUint8Array = base64ToUint8Array; exports.clearTokenCache = clearTokenCache; exports.configure = configure; exports.createAccount = createAccount; exports.createAgreement = createAgreement; exports.createGuardianGroup = createGuardianGroup; exports.createGuardianGroupAndWatch = createGuardianGroupAndWatch; exports.createSimpleAgreement = createSimpleAgreement; exports.dataContract = dataContract; exports.debugLog = debugLog; exports.decodeAggregateKey = decodeAggregateKey; exports.decodeField = decodeField; exports.decodePowersOfTau = decodePowersOfTau; exports.decrypt = decrypt; exports.ecncryptTest = encrypt; exports.encodeCiphertext = encodeCiphertext; exports.encrypt = encrypt2; exports.fetchAndDecodeExtrinsic = fetchAndDecodeExtrinsic; exports.fetchTokenProperties = fetchTokenProperties; exports.formatBalanceWithTokenProperties = formatBalanceWithTokenProperties; exports.formatPaliAmount = formatPaliAmount; exports.fromAtomicPaliAmount = fromAtomicPaliAmount; exports.fundAccount = fundAccount; exports.gen_shared_key = gen_shared_key; exports.gen_stretched_key = gen_stretched_key; exports.generateRandomBytes = generateRandomBytes; exports.getAgreementCreatedRequestId = getAgreementCreatedRequestId; exports.getApi = getApi; exports.getCachedTokenProperties = getCachedTokenProperties; exports.getEncKeyring = getEncKeyring; exports.getFileMetadataCall = getFileMetadataCall; exports.getGuardianAddress = getGuardianAddress; exports.getGuardianList = getGuardianList; exports.getGuardianNwParams = getGuardianNwParams; exports.getGuardianParticipants = getGuardianParticipants; exports.getKeyring = getKeyring; exports.hexToUint8Array = hexToUint8Array; exports.inferenceCompute = inferenceCompute; exports.joinGuardian = joinGuardian; exports.joinIdleStaker = joinIdleStaker; exports.joinValidator = joinValidator; exports.newStake = newStake; exports.pairFromPrivateKeyHex = pairFromPrivateKeyHex; exports.payoutStake = payoutStake; exports.provider = provider; exports.reduceStake = reduceStake; exports.registerDataAgreement = registerDataAgreement; exports.removeStake = removeStake; exports.rotateAndSetKeys = rotateAndSetKeys; exports.runAgent = runAgent; exports.scanForBlockEvent = scanForBlockEvent; exports.setIdentity = setIdentity; exports.setWorker = setWorker; exports.signAndSend = signAndSend; exports.simpleCompute = simpleCompute; exports.submitData = submitData; exports.submitTEData = submitTEData; exports.submitTEDataWithCipher = submitTEDataWithCipher; exports.testCrypt = testCrypt; exports.toAtomicPaliAmount = toAtomicPaliAmount; exports.tokenToBigint = tokenToBigint; exports.transfer = transfer; exports.uint8ArrayToBase64 = uint8ArrayToBase64; exports.uploadData = uploadData; exports.uploadDataLegacy = uploadDataLegacy; exports.utilCrypto = utilCrypto; exports.wasmCrypto = wasmCrypto; exports.watchForSubmissionReceipt = watchForSubmissionReceipt; exports.withdrawStake = withdrawStake; exports.writeMetadata = writeMetadata;
2847
+
2848
+
2849
+
2850
+
2851
+ exports.API_EXTENSIONS = API_EXTENSIONS; exports.API_RPC = API_RPC; exports.API_TYPES = API_TYPES; exports.AccountSourceType = AccountSourceType; exports.ApiPromise = _api2.ApiPromise; exports.CryptoType = CryptoType; exports.DEBUG = DEBUG; exports.DEFAULT_COMPUTE_PAYLOAD = DEFAULT_COMPUTE_PAYLOAD; exports.DEFAULT_EMPTY_PAYLOAD = DEFAULT_EMPTY_PAYLOAD; exports.FileFromMetadataRef = FileFromMetadataRef; exports.HttpProvider = _api2.HttpProvider; exports.Keyring = Keyring3; exports.MCryptFs = MCryptFs; exports.MCryptFsReader = MCryptFsReader; exports.MCryptFsWriter = MCryptFsWriter; exports.PALI_DECIMALS = PALI_DECIMALS; exports.PALI_SYMBOL = PALI_SYMBOL; exports.PALLIORA_RPC_URL = PALLIORA_RPC_URL; exports.PALLIORA_WS = PALLIORA_WS; exports.TX_WAIT_FINALIZATION = TX_WAIT_FINALIZATION; exports.WsProvider = _api2.WsProvider; exports.addStake = addStake; exports.base64ToUint8Array = base64ToUint8Array; exports.buildFee = buildFee; exports.clearTokenCache = clearTokenCache; exports.configure = configure; exports.createAccount = createAccount; exports.createAgreement = createAgreement; exports.createGuardianGroup = createGuardianGroup; exports.createGuardianGroupAndWatch = createGuardianGroupAndWatch; exports.createSimpleAgreement = createSimpleAgreement; exports.dataContract = dataContract; exports.debugLog = debugLog; exports.decodeAggregateKey = decodeAggregateKey; exports.decodeField = decodeField; exports.decodePowersOfTau = decodePowersOfTau; exports.decrypt = decrypt; exports.ecncryptTest = encrypt; exports.encodeCiphertext = encodeCiphertext; exports.encrypt = encrypt2; exports.encryptedInferenceCompute = encryptedInferenceCompute; exports.encryptedInferenceSubscription = encryptedInferenceSubscription; exports.encryptedInferenceSubscriptionInvocation = encryptedInferenceSubscriptionInvocation; exports.fetchAndDecodeExtrinsic = fetchAndDecodeExtrinsic; exports.fetchTokenProperties = fetchTokenProperties; exports.formatBalanceWithTokenProperties = formatBalanceWithTokenProperties; exports.formatPaliAmount = formatPaliAmount; exports.fromAtomicPaliAmount = fromAtomicPaliAmount; exports.fundAccount = fundAccount; exports.gen_shared_key = gen_shared_key; exports.gen_stretched_key = gen_stretched_key; exports.generateRandomBytes = generateRandomBytes; exports.getAgreementCreatedRequestId = getAgreementCreatedRequestId; exports.getApi = getApi; exports.getCachedTokenProperties = getCachedTokenProperties; exports.getEncKeyring = getEncKeyring; exports.getFileMetadataCall = getFileMetadataCall; exports.getGuardianAddress = getGuardianAddress; exports.getGuardianList = getGuardianList; exports.getGuardianNwParams = getGuardianNwParams; exports.getGuardianParticipants = getGuardianParticipants; exports.getKeyring = getKeyring; exports.hexToUint8Array = hexToUint8Array; exports.inferenceCompute = inferenceCompute; exports.joinGuardian = joinGuardian; exports.joinIdleStaker = joinIdleStaker; exports.joinValidator = joinValidator; exports.newStake = newStake; exports.pairFromPrivateKeyHex = pairFromPrivateKeyHex; exports.payoutStake = payoutStake; exports.provider = provider; exports.reduceStake = reduceStake; exports.registerDataAgreement = registerDataAgreement; exports.removeStake = removeStake; exports.rotateAndSetKeys = rotateAndSetKeys; exports.runAgent = runAgent; exports.scanForBlockEvent = scanForBlockEvent; exports.setIdentity = setIdentity; exports.setWorker = setWorker; exports.signAndSend = signAndSend; exports.simpleCompute = simpleCompute; exports.submitData = submitData; exports.submitTEData = submitTEData; exports.submitTEDataWithCipher = submitTEDataWithCipher; exports.testCrypt = testCrypt; exports.toAtomicPaliAmount = toAtomicPaliAmount; exports.tokenToBigint = tokenToBigint; exports.transfer = transfer; exports.uint8ArrayToBase64 = uint8ArrayToBase64; exports.uploadData = uploadData; exports.uploadDataLegacy = uploadDataLegacy; exports.utilCrypto = utilCrypto; exports.wasmCrypto = wasmCrypto; exports.watchForSubmissionReceipt = watchForSubmissionReceipt; exports.withdrawStake = withdrawStake; exports.writeMetadata = writeMetadata;
2698
2852
  //# sourceMappingURL=index.cjs.map