@palliora.org/chainsdk 0.3.3 → 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,6 +201,13 @@ 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
213
  aggKey: "Vec<u8>"
@@ -402,7 +409,8 @@ var API_TYPES = {
402
409
  preCheck: "Option<ComputeInfo>",
403
410
  compute: "ComputeInfo",
404
411
  postCheck: "Option<ComputeInfo>",
405
- resultCipher: "CipherSuite"
412
+ resultCipher: "CipherSuite",
413
+ currencyId: "CurrencyId"
406
414
  },
407
415
  AgreementInfo: {
408
416
  status: "AgreementStatus",
@@ -538,6 +546,18 @@ var API_EXTENSIONS = {
538
546
  compute: "ComputePayload"
539
547
  },
540
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: {}
541
561
  }
542
562
  };
543
563
 
@@ -1121,8 +1141,9 @@ async function joinGuardian(account, prefs) {
1121
1141
 
1122
1142
  // src/chain/utils.ts
1123
1143
  var signAndSend = async (request, account, opts = DEFAULT_COMPUTE_PAYLOAD) => {
1144
+ const signOpts = { currencyId: null, ...opts };
1124
1145
  const tx_result = await new Promise((res, err) => {
1125
- request.signAndSend(account, opts, (result) => {
1146
+ request.signAndSend(account, signOpts, (result) => {
1126
1147
  if (result.isFinalized) {
1127
1148
  res(result);
1128
1149
  }
@@ -1442,7 +1463,7 @@ var MCryptFsWriter = class {
1442
1463
  );
1443
1464
  console.log("account: ", this._account);
1444
1465
  return new Promise((resolve) => {
1445
- request.signAndSend(this._account, { app_id: 1 }, (result) => {
1466
+ request.signAndSend(this._account, { app_id: 1, currencyId: null }, (result) => {
1446
1467
  if (result.isInBlock || result.isFinalized || result.isError) {
1447
1468
  resolve({
1448
1469
  blockNumber: _nullishCoalesce(_optionalChain([result, 'access', _87 => _87.blockNumber, 'optionalAccess', _88 => _88.toNumber, 'call', _89 => _89()]), () => ( 0)),
@@ -1566,7 +1587,8 @@ function buildFee(fee) {
1566
1587
  async function createAgreement(contract, account, oracle_quore_id = void 0) {
1567
1588
  const api2 = await getApi();
1568
1589
  if (!api2) throw new Error("Api not initialized");
1569
- const tx = api2.tx["compute"]["agreement"](contract, _nullishCoalesce(oracle_quore_id, () => ( null)));
1590
+ const onChainContract = { currencyId: "Native", ...contract };
1591
+ const tx = api2.tx["compute"]["agreement"](onChainContract, _nullishCoalesce(oracle_quore_id, () => ( null)));
1570
1592
  const opts = {
1571
1593
  compute: {
1572
1594
  daType: 1,
@@ -1655,6 +1677,103 @@ async function dataContract(params, account) {
1655
1677
  return createAgreement(contract, account);
1656
1678
  }
1657
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",
1710
+ guardians: params.guardians,
1711
+ preCheck: null,
1712
+ compute: computeStep,
1713
+ postCheck: null,
1714
+ resultCipher: "Plaintext"
1715
+ };
1716
+ return createAgreement(contract, account);
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
+ }
1776
+
1658
1777
  // src/compute/inference.ts
1659
1778
  async function inferenceCompute(params, account) {
1660
1779
  const inputData = typeof params.input === "string" ? Array.from(new TextEncoder().encode(params.input)) : Array.from(params.input);
@@ -1769,19 +1888,6 @@ async function simpleCompute(params, account) {
1769
1888
  return createAgreement(contract, account);
1770
1889
  }
1771
1890
 
1772
- // src/crypto/random.ts
1773
- function generateRandomBytes(length = 32) {
1774
- const bytes = new Uint8Array(length);
1775
- const cr = globalThis.crypto;
1776
- if (!cr || typeof cr.getRandomValues !== "function") {
1777
- throw new Error(
1778
- "crypto.getRandomValues is not available. Ensure you're running in a supported environment (browser or Node.js 18+)."
1779
- );
1780
- }
1781
- cr.getRandomValues(bytes);
1782
- return bytes;
1783
- }
1784
-
1785
1891
  // src/da/register.ts
1786
1892
  async function writeMetadata(account, name, description, ref, price, dataType, l2Owner, groupId) {
1787
1893
  const blobRef = [ref.blockNumber, ref.index];
@@ -2739,5 +2845,8 @@ _ss58 = new WeakMap();
2739
2845
 
2740
2846
 
2741
2847
 
2742
- 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.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;
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;
2743
2852
  //# sourceMappingURL=index.cjs.map