@palliora.org/chainsdk 0.3.2 → 0.3.3

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.js CHANGED
@@ -203,7 +203,7 @@ var API_TYPES = {
203
203
  },
204
204
  GuardianNwParams: {
205
205
  kzg: "Vec<u8>",
206
- agg_key: "Vec<u8>"
206
+ aggKey: "Vec<u8>"
207
207
  },
208
208
  AppId: "Compact<u32>",
209
209
  DataLookupItem: {
@@ -254,9 +254,9 @@ var API_TYPES = {
254
254
  verifier: "u128"
255
255
  },
256
256
  SilentThresholdParams: {
257
- td_params: "Vec<u8>",
258
- pk_bytes: "Vec<u8>",
259
- tau_params: "Vec<u8>"
257
+ tdParams: "Vec<u8>",
258
+ pkBytes: "Vec<u8>",
259
+ tauParams: "Vec<u8>"
260
260
  },
261
261
  ThresholdParams: {
262
262
  _enum: {
@@ -282,16 +282,16 @@ var API_TYPES = {
282
282
  }
283
283
  },
284
284
  Secp256k1Params: {
285
- recipient_public_key: "Vec<u8>",
286
- ephemeral_public_key: "Option<Vec<u8>>",
285
+ recipientPublicKey: "Vec<u8>",
286
+ ephemeralPublicKey: "Option<Vec<u8>>",
287
287
  compressed: "bool",
288
288
  kdf: "KdfParams",
289
289
  salt: "Option<Vec<u8>>",
290
290
  info: "Option<Vec<u8>>"
291
291
  },
292
292
  Ed25519Params: {
293
- recipient_public_key: "Vec<u8>",
294
- ephemeral_public_key: "Option<Vec<u8>>",
293
+ recipientPublicKey: "Vec<u8>",
294
+ ephemeralPublicKey: "Option<Vec<u8>>",
295
295
  kdf: "KdfParams",
296
296
  salt: "Option<Vec<u8>>",
297
297
  info: "Option<Vec<u8>>"
@@ -303,12 +303,12 @@ var API_TYPES = {
303
303
  }
304
304
  },
305
305
  ThresholdHybridParams: {
306
- threshold_params: "ThresholdParams",
307
- symmetric_params: "SymmetricParams"
306
+ thresholdParams: "ThresholdParams",
307
+ symmetricParams: "SymmetricParams"
308
308
  },
309
309
  AsymmetricHybridParams: {
310
- asymmetric_params: "AsymmetricParams",
311
- symmetric_params: "SymmetricParams"
310
+ asymmetricParams: "AsymmetricParams",
311
+ symmetricParams: "SymmetricParams"
312
312
  },
313
313
  CipherSuite: {
314
314
  _enum: {
@@ -326,7 +326,7 @@ var API_TYPES = {
326
326
  }
327
327
  },
328
328
  NativeExecuteDA: {
329
- _enum: ["Inference"]
329
+ _enum: ["Inference", "ContractAccess"]
330
330
  },
331
331
  NativeDataDA: {
332
332
  _enum: ["DaFalse", "DaTrue"]
@@ -335,8 +335,11 @@ var API_TYPES = {
335
335
  data: "Vec<u8>"
336
336
  },
337
337
  DAInputChainTransaction: {
338
- block_number: "u64",
339
- extrinsic_index: "u32"
338
+ blockNumber: "u64",
339
+ extrinsicIndex: "u32"
340
+ },
341
+ DAInputContractId: {
342
+ id: "[u8; 32]"
340
343
  },
341
344
  DAInputIpfs: {
342
345
  cid: "Vec<u8>",
@@ -352,6 +355,7 @@ var API_TYPES = {
352
355
  Null: "Null",
353
356
  Inline: "DAInputInline",
354
357
  ChainTransaction: "DAInputChainTransaction",
358
+ ContractId: "DAInputContractId",
355
359
  Ipfs: "DAInputIpfs",
356
360
  Url: "DAInputUrl",
357
361
  NativeExecute: "NativeExecuteDA",
@@ -361,7 +365,8 @@ var API_TYPES = {
361
365
  ContractType: {
362
366
  _enum: {
363
367
  Dormant: "Null",
364
- Active: "Null"
368
+ Active: "Null",
369
+ Subscription: "Null"
365
370
  }
366
371
  },
367
372
  StoreType: {
@@ -375,28 +380,29 @@ var API_TYPES = {
375
380
  ComputeMetadata: {
376
381
  name: "Vec<u8>",
377
382
  description: "Vec<u8>",
378
- store_type: "StoreType",
379
- group_id: "H256"
383
+ storeType: "StoreType",
384
+ groupId: "H256"
380
385
  },
381
386
  ComputeInfo: {
382
387
  cipher: "CipherSuite",
383
- computer_indices: "Vec<u32>",
388
+ computerIndices: "Vec<u32>",
384
389
  fees: "u128",
390
+ computeRate: "u128",
385
391
  deadline: "u64",
386
392
  confidentiality: "ConfidentialityLevel",
387
- fee_function: "Option<u8>",
388
- program_env: "Option<Vec<u8>>",
393
+ feeFunction: "Option<u8>",
394
+ programEnv: "Option<Vec<u8>>",
389
395
  input: "DAInput",
390
396
  program: "DAInput",
391
397
  metadata: "Option<ComputeMetadata>"
392
398
  },
393
399
  Contract: {
394
- contract_type: "ContractType",
400
+ contractType: "ContractType",
395
401
  guardians: "Vec<AccountId>",
396
- pre_check: "Option<ComputeInfo>",
402
+ preCheck: "Option<ComputeInfo>",
397
403
  compute: "ComputeInfo",
398
- post_check: "Option<ComputeInfo>",
399
- result_cipher: "CipherSuite"
404
+ postCheck: "Option<ComputeInfo>",
405
+ resultCipher: "CipherSuite"
400
406
  },
401
407
  AgreementInfo: {
402
408
  status: "AgreementStatus",
@@ -404,7 +410,7 @@ var API_TYPES = {
404
410
  index: "u32"
405
411
  },
406
412
  ComputePayload: {
407
- da_type: "u8",
413
+ daType: "u8",
408
414
  agreement: "Option<BoundedVec<[u8; 32], 10>>",
409
415
  verification: "u8",
410
416
  compute: "u8"
@@ -480,10 +486,46 @@ var API_TYPES = {
480
486
  GRawScalar: "U256",
481
487
  GProof: "[u8; 48]",
482
488
  GRow: "Vec<GRawScalar>",
483
- GDataProof: "(GRawScalar, GProof)"
489
+ GDataProof: "(GRawScalar, GProof)",
490
+ AgreementStatus: {
491
+ _enum: ["NotFound", "Pending", "Accepted", "Rejected", "Settled"]
492
+ },
493
+ AcceptedSubStatus: {
494
+ _enum: ["Running", "AwaitingTopUp", "TopUpReceived", "RejectedInsufficientBudget", "RejectedRateMismatch"]
495
+ },
496
+ RejectedSubStatus: {
497
+ _enum: ["InsufficientBudget", "RateMismatch"]
498
+ },
499
+ SettlementReason: {
500
+ _enum: ["ResultReceived", "DeadlineReached", "BudgetExhausted"]
501
+ },
502
+ ExecutionOutcome: {
503
+ _enum: ["FullSettlement", "PartialSettlement", "Success", "Failed", "Terminated", "TopUpTimeout"]
504
+ },
505
+ ContractInfo: {
506
+ status: "AgreementStatus",
507
+ owner: "AccountId",
508
+ originBlock: "u32",
509
+ invocationBlock: "u32",
510
+ index: "u32",
511
+ usagePrice: "u128",
512
+ contractType: "ContractType"
513
+ },
514
+ SettlementInfo: {
515
+ computeRate: "u128",
516
+ inputContractId: "Option<[u8; 32]>",
517
+ guardians: "Vec<AccountId>"
518
+ },
519
+ AppKeyInfo: {
520
+ owner: "AccountId",
521
+ id: "AppId"
522
+ },
523
+ DataType: {
524
+ _enum: ["Dataset", "Model", "Agent"]
525
+ }
484
526
  };
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: [] } };
527
+ var DEFAULT_COMPUTE_PAYLOAD = { compute: { daType: 0, verification: 0, compute: 0 } };
528
+ var DEFAULT_EMPTY_PAYLOAD = { compute: { daType: 0, verification: 0, compute: 0, agreement: [] } };
487
529
  var API_EXTENSIONS = {
488
530
  CheckAppId: {
489
531
  extrinsic: {
@@ -1515,15 +1557,21 @@ var FileFromMetadataRef = async (mcryptApi, metadataRef) => {
1515
1557
  };
1516
1558
 
1517
1559
  // src/compute/agreement.ts
1518
- async function createAgreement(contract, account) {
1560
+ function buildFee(fee) {
1561
+ return {
1562
+ fees: toAtomicPaliAmount(fee?.amount ?? "0"),
1563
+ computeRate: toAtomicPaliAmount(fee?.computeRate ?? "0")
1564
+ };
1565
+ }
1566
+ async function createAgreement(contract, account, oracle_quore_id = void 0) {
1519
1567
  const api2 = await getApi();
1520
1568
  if (!api2) throw new Error("Api not initialized");
1521
- const tx = api2.tx["compute"]["agreement"](contract);
1569
+ const tx = api2.tx["compute"]["agreement"](contract, oracle_quore_id ?? null);
1522
1570
  const opts = {
1523
1571
  compute: {
1524
- da_type: 1,
1572
+ daType: 1,
1525
1573
  verification: 0,
1526
- compute: contract.contract_type === "Active" ? 1 : 0
1574
+ compute: contract.contractType === "Active" ? 1 : 0
1527
1575
  }
1528
1576
  };
1529
1577
  const { tx_result, blockNumber, index, hash } = await signAndSend(
@@ -1555,22 +1603,22 @@ async function createSimpleAgreement() {
1555
1603
  const guardianIds = (await getGuardianAddress()).slice(0, 3).map((g) => g.address);
1556
1604
  assert(guardianIds.length === 3, "Not enough guardians to create agreement");
1557
1605
  const contract = {
1558
- contract_type: "Dormant",
1606
+ contractType: "Dormant",
1559
1607
  guardians: guardianIds,
1560
- pre_check: null,
1608
+ preCheck: null,
1561
1609
  compute: {
1562
1610
  cipher: "Plaintext",
1563
- computer_indices: [0, 1, 2],
1564
- fees: toAtomicPaliAmount("0.01"),
1611
+ computerIndices: [0, 1, 2],
1612
+ ...buildFee({ amount: "0", computeRate: "0" }),
1565
1613
  deadline: 0,
1566
1614
  confidentiality: { Trusted: 0 },
1567
- fee_function: null,
1615
+ feeFunction: null,
1568
1616
  input: null,
1569
1617
  program: { NativeData: "DaFalse" },
1570
1618
  metadata: null
1571
1619
  },
1572
- post_check: null,
1573
- result_cipher: "Plaintext"
1620
+ postCheck: null,
1621
+ resultCipher: "Plaintext"
1574
1622
  };
1575
1623
  const keyring2 = await getKeyring();
1576
1624
  const account = keyring2.getPairs()[0];
@@ -1580,14 +1628,13 @@ async function createSimpleAgreement() {
1580
1628
  // src/compute/data.ts
1581
1629
  async function dataContract(params, account) {
1582
1630
  const plaintextCipher = "Plaintext";
1583
- const atomicFees = toAtomicPaliAmount(params.fees ?? "0");
1584
1631
  const computeStep = {
1585
1632
  cipher: plaintextCipher,
1586
- computer_indices: params.guardians.map((_, i) => i),
1587
- fees: atomicFees,
1633
+ computerIndices: params.guardians.map((_, i) => i),
1634
+ ...buildFee(params.fee),
1588
1635
  deadline: params.deadline ?? 0,
1589
1636
  confidentiality: { Trusted: params.trustIndex ?? 0 },
1590
- fee_function: null,
1637
+ feeFunction: null,
1591
1638
  input: {
1592
1639
  Url: {
1593
1640
  url: Array.from(new TextEncoder().encode(params.url))
@@ -1598,12 +1645,12 @@ async function dataContract(params, account) {
1598
1645
  }
1599
1646
  };
1600
1647
  const contract = {
1601
- contract_type: "Dormant",
1648
+ contractType: "Dormant",
1602
1649
  guardians: params.guardians,
1603
- pre_check: null,
1650
+ preCheck: null,
1604
1651
  compute: computeStep,
1605
- post_check: null,
1606
- result_cipher: plaintextCipher
1652
+ postCheck: null,
1653
+ resultCipher: plaintextCipher
1607
1654
  };
1608
1655
  return createAgreement(contract, account);
1609
1656
  }
@@ -1611,23 +1658,22 @@ async function dataContract(params, account) {
1611
1658
  // src/compute/inference.ts
1612
1659
  async function inferenceCompute(params, account) {
1613
1660
  const inputData = typeof params.input === "string" ? Array.from(new TextEncoder().encode(params.input)) : Array.from(params.input);
1614
- const atomicFees = toAtomicPaliAmount(params.fees ?? "0");
1615
1661
  const plaintextCipher = "Plaintext";
1616
1662
  const computeStep = {
1617
1663
  cipher: plaintextCipher,
1618
- computer_indices: params.guardians.map((_, i) => i),
1619
- fees: atomicFees,
1664
+ computerIndices: params.guardians.map((_, i) => i),
1665
+ ...buildFee(params.fee),
1620
1666
  deadline: params.deadline ?? 0,
1621
1667
  confidentiality: { Trusted: 0 },
1622
- fee_function: null,
1668
+ feeFunction: null,
1623
1669
  input: { Inline: { data: inputData } },
1624
1670
  program: { NativeExecute: "Inference" }
1625
1671
  };
1626
1672
  const contract = {
1627
- contract_type: "Active",
1673
+ contractType: "Active",
1628
1674
  guardians: params.guardians,
1629
1675
  compute: computeStep,
1630
- result_cipher: plaintextCipher
1676
+ resultCipher: plaintextCipher
1631
1677
  };
1632
1678
  return createAgreement(contract, account);
1633
1679
  }
@@ -1698,14 +1744,13 @@ async function getGuardianParticipants() {
1698
1744
  // src/compute/simple.ts
1699
1745
  async function simpleCompute(params, account) {
1700
1746
  const plaintextCipher = "Plaintext";
1701
- const atomicFees = toAtomicPaliAmount(params.fees ?? "0");
1702
1747
  const computeStep = {
1703
1748
  cipher: plaintextCipher,
1704
- computer_indices: params.guardians.map((_, i) => i),
1705
- fees: atomicFees,
1749
+ computerIndices: params.guardians.map((_, i) => i),
1750
+ ...buildFee(params.fee),
1706
1751
  deadline: params.deadline ?? 0,
1707
1752
  confidentiality: { Trusted: params.trustIndex ?? 0 },
1708
- fee_function: null,
1753
+ feeFunction: null,
1709
1754
  input: null,
1710
1755
  program: {
1711
1756
  Url: {
@@ -1714,12 +1759,12 @@ async function simpleCompute(params, account) {
1714
1759
  }
1715
1760
  };
1716
1761
  const contract = {
1717
- contract_type: "Active",
1762
+ contractType: "Active",
1718
1763
  guardians: params.guardians,
1719
- pre_check: null,
1764
+ preCheck: null,
1720
1765
  compute: computeStep,
1721
- post_check: null,
1722
- result_cipher: plaintextCipher
1766
+ postCheck: null,
1767
+ resultCipher: plaintextCipher
1723
1768
  };
1724
1769
  return createAgreement(contract, account);
1725
1770
  }
@@ -1762,7 +1807,7 @@ async function writeMetadata(account, name, description, ref, price, dataType, l
1762
1807
  }
1763
1808
  async function registerDataAgreement(account, params) {
1764
1809
  debugLog(
1765
- `Registering data agreement for DA ref ${params.ref.blockNumber}-${params.ref.index} at ${formatPaliAmount(params.fees)}`
1810
+ `Registering data agreement for DA ref ${params.ref.blockNumber}-${params.ref.index} at ${formatPaliAmount(toAtomicPaliAmount(params.fee.amount ?? "0"))}`
1766
1811
  );
1767
1812
  const cipher = params.cipher ?? "Plaintext";
1768
1813
  const resultCipher = params.resultCipher ?? "Plaintext";
@@ -1770,20 +1815,20 @@ async function registerDataAgreement(account, params) {
1770
1815
  const computeMetadata = params.metadata ? {
1771
1816
  name: Array.from(encoder.encode(params.metadata.name)),
1772
1817
  description: Array.from(encoder.encode(params.metadata.description)),
1773
- store_type: params.metadata.storeType,
1774
- group_id: params.metadata.groupId
1818
+ storeType: params.metadata.storeType,
1819
+ groupId: params.metadata.groupId
1775
1820
  } : null;
1776
1821
  const computeStep = {
1777
1822
  cipher,
1778
- computer_indices: params.guardians.map((_, i) => i),
1779
- fees: params.fees,
1823
+ computerIndices: params.guardians.map((_, i) => i),
1824
+ ...buildFee(params.fee),
1780
1825
  deadline: params.deadline ?? 0,
1781
1826
  confidentiality: { Trusted: params.trustIndex ?? 0 },
1782
- fee_function: null,
1827
+ feeFunction: null,
1783
1828
  input: {
1784
1829
  ChainTransaction: {
1785
- block_number: params.ref.blockNumber,
1786
- extrinsic_index: params.ref.index
1830
+ blockNumber: params.ref.blockNumber,
1831
+ extrinsicIndex: params.ref.index
1787
1832
  }
1788
1833
  },
1789
1834
  program: {
@@ -1792,12 +1837,12 @@ async function registerDataAgreement(account, params) {
1792
1837
  metadata: computeMetadata
1793
1838
  };
1794
1839
  const contract = {
1795
- contract_type: "Dormant",
1840
+ contractType: "Dormant",
1796
1841
  guardians: params.guardians,
1797
- pre_check: null,
1842
+ preCheck: null,
1798
1843
  compute: computeStep,
1799
- post_check: null,
1800
- result_cipher: resultCipher
1844
+ postCheck: null,
1845
+ resultCipher
1801
1846
  };
1802
1847
  return createAgreement(contract, account);
1803
1848
  }
@@ -1822,7 +1867,7 @@ async function runAgent(account, agentRef, nonce, ciphertext, tdParams, pkBytes,
1822
1867
  );
1823
1868
  const opts = {
1824
1869
  compute: {
1825
- da_type: 4,
1870
+ daType: 4,
1826
1871
  verification: 0,
1827
1872
  compute: 1,
1828
1873
  agreement: [agreementId]
@@ -1881,14 +1926,14 @@ async function submitTEDataWithCipher(account, data, chosenGuardians, tau_params
1881
1926
  ref,
1882
1927
  cipher: {
1883
1928
  ThresholdHybrid: {
1884
- threshold_params: {
1929
+ thresholdParams: {
1885
1930
  SilentThreshold: {
1886
- td_params: Array.from(hexToUint8Array(encryptedKey)),
1887
- pk_bytes: Array.from(hexToUint8Array(group_pk)),
1888
- tau_params: Array.from(hexToUint8Array(tau_params))
1931
+ tdParams: Array.from(hexToUint8Array(encryptedKey)),
1932
+ pkBytes: Array.from(hexToUint8Array(group_pk)),
1933
+ tauParams: Array.from(hexToUint8Array(tau_params))
1889
1934
  }
1890
1935
  },
1891
- symmetric_params: {
1936
+ symmetricParams: {
1892
1937
  ChaCha20Poly1305: { nonce: Array.from(nonce) }
1893
1938
  }
1894
1939
  }
@@ -1907,7 +1952,6 @@ async function uploadData(options) {
1907
1952
  );
1908
1953
  console.log("Guardian group info:", guardianGroupInfo);
1909
1954
  const account = (await getKeyring()).pairs[0];
1910
- const atomicPrice = toAtomicPaliAmount(price);
1911
1955
  if (filePath) {
1912
1956
  throw new Error("uploadData: file path upload is not implemented");
1913
1957
  } else {
@@ -1923,7 +1967,7 @@ async function uploadData(options) {
1923
1967
  await registerDataAgreement(account, {
1924
1968
  ref: dataRef,
1925
1969
  guardians: guardianGroupInfo.guardians,
1926
- fees: atomicPrice,
1970
+ fee: { amount: price },
1927
1971
  cipher,
1928
1972
  metadata: {
1929
1973
  name,
@@ -2625,6 +2669,7 @@ export {
2625
2669
  WsProvider3 as WsProvider,
2626
2670
  addStake,
2627
2671
  base64ToUint8Array,
2672
+ buildFee,
2628
2673
  clearTokenCache,
2629
2674
  configure,
2630
2675
  createAccount,