@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 +273 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +218 -53
- package/dist/index.d.ts +218 -53
- package/dist/index.js +251 -97
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
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
|
-
|
|
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
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
286
|
-
|
|
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
|
-
|
|
294
|
-
|
|
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
|
-
|
|
307
|
-
|
|
313
|
+
thresholdParams: "ThresholdParams",
|
|
314
|
+
symmetricParams: "SymmetricParams"
|
|
308
315
|
},
|
|
309
316
|
AsymmetricHybridParams: {
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
|
|
339
|
-
|
|
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
|
-
|
|
379
|
-
|
|
390
|
+
storeType: "StoreType",
|
|
391
|
+
groupId: "H256"
|
|
380
392
|
},
|
|
381
393
|
ComputeInfo: {
|
|
382
394
|
cipher: "CipherSuite",
|
|
383
|
-
|
|
395
|
+
computerIndices: "Vec<u32>",
|
|
384
396
|
fees: "u128",
|
|
397
|
+
computeRate: "u128",
|
|
385
398
|
deadline: "u64",
|
|
386
399
|
confidentiality: "ConfidentialityLevel",
|
|
387
|
-
|
|
388
|
-
|
|
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
|
-
|
|
407
|
+
contractType: "ContractType",
|
|
395
408
|
guardians: "Vec<AccountId>",
|
|
396
|
-
|
|
409
|
+
preCheck: "Option<ComputeInfo>",
|
|
397
410
|
compute: "ComputeInfo",
|
|
398
|
-
|
|
399
|
-
|
|
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
|
-
|
|
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: {
|
|
486
|
-
var DEFAULT_EMPTY_PAYLOAD = { compute: {
|
|
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,
|
|
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: result.blockNumber?.toNumber() ?? 0,
|
|
@@ -1515,15 +1578,22 @@ var FileFromMetadataRef = async (mcryptApi, metadataRef) => {
|
|
|
1515
1578
|
};
|
|
1516
1579
|
|
|
1517
1580
|
// src/compute/agreement.ts
|
|
1518
|
-
|
|
1581
|
+
function buildFee(fee) {
|
|
1582
|
+
return {
|
|
1583
|
+
fees: toAtomicPaliAmount(fee?.amount ?? "0"),
|
|
1584
|
+
computeRate: toAtomicPaliAmount(fee?.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
|
|
1590
|
+
const onChainContract = { currencyId: "Native", ...contract };
|
|
1591
|
+
const tx = api2.tx["compute"]["agreement"](onChainContract, oracle_quore_id ?? null);
|
|
1522
1592
|
const opts = {
|
|
1523
1593
|
compute: {
|
|
1524
|
-
|
|
1594
|
+
daType: 1,
|
|
1525
1595
|
verification: 0,
|
|
1526
|
-
compute: contract.
|
|
1596
|
+
compute: contract.contractType === "Active" ? 1 : 0
|
|
1527
1597
|
}
|
|
1528
1598
|
};
|
|
1529
1599
|
const { tx_result, blockNumber, index, hash } = await signAndSend(
|
|
@@ -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
|
-
|
|
1628
|
+
contractType: "Dormant",
|
|
1559
1629
|
guardians: guardianIds,
|
|
1560
|
-
|
|
1630
|
+
preCheck: null,
|
|
1561
1631
|
compute: {
|
|
1562
1632
|
cipher: "Plaintext",
|
|
1563
|
-
|
|
1564
|
-
|
|
1633
|
+
computerIndices: [0, 1, 2],
|
|
1634
|
+
...buildFee({ amount: "0", computeRate: "0" }),
|
|
1565
1635
|
deadline: 0,
|
|
1566
1636
|
confidentiality: { Trusted: 0 },
|
|
1567
|
-
|
|
1637
|
+
feeFunction: null,
|
|
1568
1638
|
input: null,
|
|
1569
1639
|
program: { NativeData: "DaFalse" },
|
|
1570
1640
|
metadata: null
|
|
1571
1641
|
},
|
|
1572
|
-
|
|
1573
|
-
|
|
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(params.fees ?? "0");
|
|
1584
1653
|
const computeStep = {
|
|
1585
1654
|
cipher: plaintextCipher,
|
|
1586
|
-
|
|
1587
|
-
|
|
1655
|
+
computerIndices: params.guardians.map((_, i) => i),
|
|
1656
|
+
...buildFee(params.fee),
|
|
1588
1657
|
deadline: params.deadline ?? 0,
|
|
1589
1658
|
confidentiality: { Trusted: params.trustIndex ?? 0 },
|
|
1590
|
-
|
|
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
|
-
|
|
1670
|
+
contractType: "Dormant",
|
|
1602
1671
|
guardians: params.guardians,
|
|
1603
|
-
|
|
1672
|
+
preCheck: null,
|
|
1604
1673
|
compute: computeStep,
|
|
1605
|
-
|
|
1606
|
-
|
|
1674
|
+
postCheck: null,
|
|
1675
|
+
resultCipher: plaintextCipher
|
|
1607
1676
|
};
|
|
1608
1677
|
return createAgreement(contract, account);
|
|
1609
1678
|
}
|
|
1610
1679
|
|
|
1680
|
+
// src/compute/encryptedInference.ts
|
|
1681
|
+
import { edwardsToMontgomeryPub as edwardsToMontgomeryPub2 } from "@noble/curves/ed25519";
|
|
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: 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
|
+
edwardsToMontgomeryPub2(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
|
+
|
|
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(params.fees ?? "0");
|
|
1615
1780
|
const plaintextCipher = "Plaintext";
|
|
1616
1781
|
const computeStep = {
|
|
1617
1782
|
cipher: plaintextCipher,
|
|
1618
|
-
|
|
1619
|
-
|
|
1783
|
+
computerIndices: params.guardians.map((_, i) => i),
|
|
1784
|
+
...buildFee(params.fee),
|
|
1620
1785
|
deadline: params.deadline ?? 0,
|
|
1621
1786
|
confidentiality: { Trusted: 0 },
|
|
1622
|
-
|
|
1787
|
+
feeFunction: null,
|
|
1623
1788
|
input: { Inline: { data: inputData } },
|
|
1624
1789
|
program: { NativeExecute: "Inference" }
|
|
1625
1790
|
};
|
|
1626
1791
|
const contract = {
|
|
1627
|
-
|
|
1792
|
+
contractType: "Active",
|
|
1628
1793
|
guardians: params.guardians,
|
|
1629
1794
|
compute: computeStep,
|
|
1630
|
-
|
|
1795
|
+
resultCipher: plaintextCipher
|
|
1631
1796
|
};
|
|
1632
1797
|
return createAgreement(contract, account);
|
|
1633
1798
|
}
|
|
@@ -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(params.fees ?? "0");
|
|
1702
1866
|
const computeStep = {
|
|
1703
1867
|
cipher: plaintextCipher,
|
|
1704
|
-
|
|
1705
|
-
|
|
1868
|
+
computerIndices: params.guardians.map((_, i) => i),
|
|
1869
|
+
...buildFee(params.fee),
|
|
1706
1870
|
deadline: params.deadline ?? 0,
|
|
1707
1871
|
confidentiality: { Trusted: params.trustIndex ?? 0 },
|
|
1708
|
-
|
|
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
|
-
|
|
1881
|
+
contractType: "Active",
|
|
1718
1882
|
guardians: params.guardians,
|
|
1719
|
-
|
|
1883
|
+
preCheck: null,
|
|
1720
1884
|
compute: computeStep,
|
|
1721
|
-
|
|
1722
|
-
|
|
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.
|
|
1916
|
+
`Registering data agreement for DA ref ${params.ref.blockNumber}-${params.ref.index} at ${formatPaliAmount(toAtomicPaliAmount(params.fee.amount ?? "0"))}`
|
|
1766
1917
|
);
|
|
1767
1918
|
const cipher = params.cipher ?? "Plaintext";
|
|
1768
1919
|
const resultCipher = 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
|
-
|
|
1774
|
-
|
|
1924
|
+
storeType: params.metadata.storeType,
|
|
1925
|
+
groupId: params.metadata.groupId
|
|
1775
1926
|
} : null;
|
|
1776
1927
|
const computeStep = {
|
|
1777
1928
|
cipher,
|
|
1778
|
-
|
|
1779
|
-
|
|
1929
|
+
computerIndices: params.guardians.map((_, i) => i),
|
|
1930
|
+
...buildFee(params.fee),
|
|
1780
1931
|
deadline: params.deadline ?? 0,
|
|
1781
1932
|
confidentiality: { Trusted: params.trustIndex ?? 0 },
|
|
1782
|
-
|
|
1933
|
+
feeFunction: null,
|
|
1783
1934
|
input: {
|
|
1784
1935
|
ChainTransaction: {
|
|
1785
|
-
|
|
1786
|
-
|
|
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
|
-
|
|
1946
|
+
contractType: "Dormant",
|
|
1796
1947
|
guardians: params.guardians,
|
|
1797
|
-
|
|
1948
|
+
preCheck: null,
|
|
1798
1949
|
compute: computeStep,
|
|
1799
|
-
|
|
1800
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2035
|
+
thresholdParams: {
|
|
1885
2036
|
SilentThreshold: {
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2076
|
+
fee: { amount: price },
|
|
1927
2077
|
cipher,
|
|
1928
2078
|
metadata: {
|
|
1929
2079
|
name,
|
|
@@ -2625,6 +2775,7 @@ export {
|
|
|
2625
2775
|
WsProvider3 as WsProvider,
|
|
2626
2776
|
addStake,
|
|
2627
2777
|
base64ToUint8Array,
|
|
2778
|
+
buildFee,
|
|
2628
2779
|
clearTokenCache,
|
|
2629
2780
|
configure,
|
|
2630
2781
|
createAccount,
|
|
@@ -2641,6 +2792,9 @@ export {
|
|
|
2641
2792
|
encrypt as ecncryptTest,
|
|
2642
2793
|
encodeCiphertext,
|
|
2643
2794
|
encrypt2 as encrypt,
|
|
2795
|
+
encryptedInferenceCompute,
|
|
2796
|
+
encryptedInferenceSubscription,
|
|
2797
|
+
encryptedInferenceSubscriptionInvocation,
|
|
2644
2798
|
fetchAndDecodeExtrinsic,
|
|
2645
2799
|
fetchTokenProperties,
|
|
2646
2800
|
formatBalanceWithTokenProperties,
|