@palliora.org/chainsdk 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +320 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +413 -225
- package/dist/index.d.ts +413 -225
- package/dist/index.js +295 -95
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -230,7 +230,7 @@ var API_TYPES = {
|
|
|
230
230
|
pk_bytes: "Vec<u8>",
|
|
231
231
|
tau_params: "Vec<u8>"
|
|
232
232
|
},
|
|
233
|
-
|
|
233
|
+
ThresholdParams: {
|
|
234
234
|
_enum: {
|
|
235
235
|
SilentThreshold: "SilentThresholdParams"
|
|
236
236
|
}
|
|
@@ -241,24 +241,61 @@ var API_TYPES = {
|
|
|
241
241
|
Aes256GcmParams: {
|
|
242
242
|
nonce: "[u8; 12]"
|
|
243
243
|
},
|
|
244
|
-
|
|
244
|
+
SymmetricParams: {
|
|
245
245
|
_enum: {
|
|
246
246
|
ChaCha20Poly1305: "ChaCha20Poly1305Params",
|
|
247
247
|
Aes256Gcm: "Aes256GcmParams"
|
|
248
248
|
}
|
|
249
249
|
},
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
250
|
+
KdfParams: {
|
|
251
|
+
_enum: {
|
|
252
|
+
HkdfSha256: "Null",
|
|
253
|
+
HkdfSha512: "Null"
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
Secp256k1Params: {
|
|
257
|
+
recipient_public_key: "Vec<u8>",
|
|
258
|
+
ephemeral_public_key: "Option<Vec<u8>>",
|
|
259
|
+
compressed: "bool",
|
|
260
|
+
kdf: "KdfParams",
|
|
261
|
+
salt: "Option<Vec<u8>>",
|
|
262
|
+
info: "Option<Vec<u8>>"
|
|
263
|
+
},
|
|
264
|
+
Ed25519Params: {
|
|
265
|
+
recipient_public_key: "Vec<u8>",
|
|
266
|
+
ephemeral_public_key: "Option<Vec<u8>>",
|
|
267
|
+
kdf: "KdfParams",
|
|
268
|
+
salt: "Option<Vec<u8>>",
|
|
269
|
+
info: "Option<Vec<u8>>"
|
|
270
|
+
},
|
|
271
|
+
AsymmetricParams: {
|
|
272
|
+
_enum: {
|
|
273
|
+
Secp256k1: "Secp256k1Params",
|
|
274
|
+
Ed25519: "Ed25519Params"
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
ThresholdHybridParams: {
|
|
278
|
+
threshold_params: "ThresholdParams",
|
|
279
|
+
symmetric_params: "SymmetricParams"
|
|
280
|
+
},
|
|
281
|
+
AsymmetricHybridParams: {
|
|
282
|
+
asymmetric_params: "AsymmetricParams",
|
|
283
|
+
symmetric_params: "SymmetricParams"
|
|
253
284
|
},
|
|
254
285
|
CipherSuite: {
|
|
255
286
|
_enum: {
|
|
256
287
|
Plaintext: "Null",
|
|
257
|
-
|
|
288
|
+
ThresholdHybrid: "ThresholdHybridParams",
|
|
289
|
+
AsymmetricHybrid: "AsymmetricHybridParams"
|
|
258
290
|
}
|
|
259
291
|
},
|
|
260
292
|
ConfidentialityLevel: {
|
|
261
|
-
_enum:
|
|
293
|
+
_enum: {
|
|
294
|
+
Trusted: "u32",
|
|
295
|
+
TEE: "Null",
|
|
296
|
+
FHE: "Null",
|
|
297
|
+
SMPC: "Null"
|
|
298
|
+
}
|
|
262
299
|
},
|
|
263
300
|
NativeExecuteDA: {
|
|
264
301
|
_enum: ["Inference"]
|
|
@@ -284,6 +321,7 @@ var API_TYPES = {
|
|
|
284
321
|
},
|
|
285
322
|
DAInput: {
|
|
286
323
|
_enum: {
|
|
324
|
+
Null: "Null",
|
|
287
325
|
Inline: "DAInputInline",
|
|
288
326
|
ChainTransaction: "DAInputChainTransaction",
|
|
289
327
|
Ipfs: "DAInputIpfs",
|
|
@@ -294,16 +332,16 @@ var API_TYPES = {
|
|
|
294
332
|
},
|
|
295
333
|
ContractType: {
|
|
296
334
|
_enum: {
|
|
297
|
-
Dormant: "
|
|
298
|
-
Active: "
|
|
335
|
+
Dormant: "Null",
|
|
336
|
+
Active: "Null"
|
|
299
337
|
}
|
|
300
338
|
},
|
|
301
339
|
StoreType: {
|
|
302
340
|
_enum: {
|
|
303
|
-
Dataset: "
|
|
304
|
-
Model: "
|
|
305
|
-
Agent: "
|
|
306
|
-
Other: "
|
|
341
|
+
Dataset: "Null",
|
|
342
|
+
Model: "Null",
|
|
343
|
+
Agent: "Null",
|
|
344
|
+
Other: "Null"
|
|
307
345
|
}
|
|
308
346
|
},
|
|
309
347
|
ComputeMetadata: {
|
|
@@ -718,16 +756,19 @@ function assert(condition, message) {
|
|
|
718
756
|
}
|
|
719
757
|
|
|
720
758
|
// src/config.ts
|
|
759
|
+
|
|
721
760
|
var env = typeof process !== "undefined" && process.env ? process.env : {};
|
|
722
761
|
var PALLIORA_WS = env.PALLIORA_WS || "wss://manas-rpc.palliora.org";
|
|
723
762
|
var PALLIORA_RPC_URL = env.PALLIORA_RPC_URL || "wss://manas-rpc.palliora.org";
|
|
724
763
|
var DEBUG = env.DEBUG === "true" || false;
|
|
725
764
|
var TX_WAIT_FINALIZATION = env.TX_WAIT_FINALIZATION === "true" || false;
|
|
765
|
+
var provider = new (0, _api2.WsProvider)(PALLIORA_WS, 1e4);
|
|
726
766
|
function configure(opts) {
|
|
727
767
|
if (opts.pallioraWs !== void 0) PALLIORA_WS = exports.PALLIORA_WS = opts.pallioraWs;
|
|
728
768
|
if (opts.pallioraRpcUrl !== void 0) PALLIORA_RPC_URL = exports.PALLIORA_RPC_URL = opts.pallioraRpcUrl;
|
|
729
769
|
if (opts.debug !== void 0) DEBUG = exports.DEBUG = opts.debug;
|
|
730
770
|
if (opts.txWaitFinalization !== void 0) TX_WAIT_FINALIZATION = exports.TX_WAIT_FINALIZATION = opts.txWaitFinalization;
|
|
771
|
+
provider = exports.provider = new (0, _api2.WsProvider)(PALLIORA_WS, 1e4);
|
|
731
772
|
}
|
|
732
773
|
|
|
733
774
|
// src/utils/helper.ts
|
|
@@ -830,19 +871,23 @@ var tokenToBigint = toAtomicPaliAmount;
|
|
|
830
871
|
// src/chain/singleton.ts
|
|
831
872
|
|
|
832
873
|
|
|
833
|
-
// src/chain/wsProvider.ts
|
|
834
|
-
|
|
835
|
-
var provider = new (0, _api2.WsProvider)(PALLIORA_WS, 1e4);
|
|
836
|
-
|
|
837
|
-
// src/chain/singleton.ts
|
|
838
|
-
|
|
839
874
|
var api = null;
|
|
875
|
+
var apiUrl = null;
|
|
840
876
|
var keyring = null;
|
|
841
877
|
var encKeyring = null;
|
|
842
878
|
var apiListenersAttached = false;
|
|
843
879
|
var apiTeardownInProgress = false;
|
|
844
880
|
async function getApi(cb) {
|
|
845
881
|
if (!provider) return;
|
|
882
|
+
if (api && PALLIORA_WS !== apiUrl) {
|
|
883
|
+
const staleApi = api;
|
|
884
|
+
api = null;
|
|
885
|
+
apiUrl = null;
|
|
886
|
+
apiListenersAttached = false;
|
|
887
|
+
apiTeardownInProgress = false;
|
|
888
|
+
await staleApi.disconnect().catch(() => {
|
|
889
|
+
});
|
|
890
|
+
}
|
|
846
891
|
if (!api) {
|
|
847
892
|
api = await _api2.ApiPromise.create({
|
|
848
893
|
provider,
|
|
@@ -850,6 +895,7 @@ async function getApi(cb) {
|
|
|
850
895
|
types: API_TYPES,
|
|
851
896
|
signedExtensions: API_EXTENSIONS
|
|
852
897
|
});
|
|
898
|
+
apiUrl = PALLIORA_WS;
|
|
853
899
|
}
|
|
854
900
|
const isNode = typeof process !== "undefined" && typeof process.exit === "function";
|
|
855
901
|
const isTest = typeof process !== "undefined" && _optionalChain([process, 'access', _37 => _37.env, 'optionalAccess', _38 => _38.NODE_ENV]) === "test";
|
|
@@ -929,18 +975,55 @@ var createGuardianGroup = async (account, selectedGuardians) => {
|
|
|
929
975
|
);
|
|
930
976
|
const result = await signAndSend(tx, account);
|
|
931
977
|
debugLog("Guardian group created:", result);
|
|
978
|
+
return result;
|
|
932
979
|
} catch (error) {
|
|
933
980
|
console.error("Error creating guardian group:", error);
|
|
934
981
|
throw new Error(`Failed to create guardian group: ${error instanceof Error ? error.message : error}`);
|
|
935
982
|
}
|
|
936
983
|
};
|
|
984
|
+
var createGuardianGroupAndWatch = async (account, guardians, maxBlocks = 20) => {
|
|
985
|
+
assert(guardians.length === 3, "Exactly 3 guardians are required");
|
|
986
|
+
assert(account, "Failed to load account");
|
|
987
|
+
const api2 = await getApi();
|
|
988
|
+
assert(api2, "Failed to initialize API");
|
|
989
|
+
debugLog(`Submitting guardian group creation...`);
|
|
990
|
+
const creationResult = await createGuardianGroup(account, guardians);
|
|
991
|
+
const startBlock = (_nullishCoalesce(_optionalChain([creationResult, 'optionalAccess', _45 => _45.blockNumber]), () => ( 0))) + 1;
|
|
992
|
+
debugLog(`Group creation tx confirmed at block ${startBlock - 1}. Listening for DaccGuardianGroup event from block ${startBlock}...`);
|
|
993
|
+
const match = await scanForBlockEvent(
|
|
994
|
+
api2,
|
|
995
|
+
{
|
|
996
|
+
predicate: async (block2, event, phase) => {
|
|
997
|
+
if (event.section.toLowerCase() !== "dataavailability" || event.method.toLowerCase() !== "daccguardiangroup") return false;
|
|
998
|
+
if (!phase.isApplyExtrinsic) return false;
|
|
999
|
+
const ext2 = block2.block.extrinsics[phase.asApplyExtrinsic.toNumber()];
|
|
1000
|
+
return _optionalChain([ext2, 'optionalAccess', _46 => _46.method, 'optionalAccess', _47 => _47.section, 'optionalAccess', _48 => _48.toLowerCase, 'call', _49 => _49()]) === "dataavailability" && _optionalChain([ext2, 'optionalAccess', _50 => _50.method, 'optionalAccess', _51 => _51.method, 'optionalAccess', _52 => _52.toLowerCase, 'call', _53 => _53()]) === "daccguardiangroupinfo";
|
|
1001
|
+
}
|
|
1002
|
+
},
|
|
1003
|
+
startBlock,
|
|
1004
|
+
maxBlocks
|
|
1005
|
+
);
|
|
1006
|
+
assert(match.extrinsicIndex !== null, "DaccGuardianGroup event was not emitted by an extrinsic");
|
|
1007
|
+
debugLog(`DaccGuardianGroup event found at block ${match.blockNumber}, extrinsic index ${match.extrinsicIndex}. Decoding args...`);
|
|
1008
|
+
const block = await match.block();
|
|
1009
|
+
const ext = block.block.extrinsics[match.extrinsicIndex];
|
|
1010
|
+
const [group_id, group_pk, tau_params, agg_key] = ext.method.args;
|
|
1011
|
+
debugLog(`Guardian group parameters decoded: group_id=${group_id.toHex()}`);
|
|
1012
|
+
return {
|
|
1013
|
+
groupId: group_id.toHex(),
|
|
1014
|
+
groupPk: group_pk.toHex(),
|
|
1015
|
+
tauParams: tau_params.toHex(),
|
|
1016
|
+
aggKey: agg_key.toHex(),
|
|
1017
|
+
guardians
|
|
1018
|
+
};
|
|
1019
|
+
};
|
|
937
1020
|
|
|
938
1021
|
// src/guardian/join.ts
|
|
939
1022
|
async function joinGuardian(account, prefs) {
|
|
940
1023
|
const api2 = await getApi();
|
|
941
1024
|
assert(api2, "API not initialized");
|
|
942
1025
|
assert(account, "Account not initialized");
|
|
943
|
-
const computeOpts = _optionalChain([prefs, 'access',
|
|
1026
|
+
const computeOpts = _optionalChain([prefs, 'access', _54 => _54.compute, 'optionalAccess', _55 => _55.split, 'call', _56 => _56(","), 'access', _57 => _57.map, 'call', _58 => _58((s) => s.trim()), 'access', _59 => _59.filter, 'call', _60 => _60((s) => s.length > 0)]) || void 0;
|
|
944
1027
|
const feeThreshold = typeof prefs.fee === "bigint" ? prefs.fee : BigInt(prefs.fee || "0");
|
|
945
1028
|
const guardianPrefs = {
|
|
946
1029
|
pubKey: account.publicKey,
|
|
@@ -948,11 +1031,11 @@ async function joinGuardian(account, prefs) {
|
|
|
948
1031
|
verifier: prefs.verifier,
|
|
949
1032
|
compute: prefs.compute ? true : false,
|
|
950
1033
|
computePrefs: {
|
|
951
|
-
trusted: _optionalChain([computeOpts, 'optionalAccess',
|
|
952
|
-
tee: _optionalChain([computeOpts, 'optionalAccess',
|
|
953
|
-
mpc: _optionalChain([computeOpts, 'optionalAccess',
|
|
954
|
-
fhe: _optionalChain([computeOpts, 'optionalAccess',
|
|
955
|
-
zkp: _optionalChain([computeOpts, 'optionalAccess',
|
|
1034
|
+
trusted: _optionalChain([computeOpts, 'optionalAccess', _61 => _61.includes, 'call', _62 => _62("trusted")]) || false,
|
|
1035
|
+
tee: _optionalChain([computeOpts, 'optionalAccess', _63 => _63.includes, 'call', _64 => _64("tee")]) || false,
|
|
1036
|
+
mpc: _optionalChain([computeOpts, 'optionalAccess', _65 => _65.includes, 'call', _66 => _66("mpc")]) || false,
|
|
1037
|
+
fhe: _optionalChain([computeOpts, 'optionalAccess', _67 => _67.includes, 'call', _68 => _68("fhe")]) || false,
|
|
1038
|
+
zkp: _optionalChain([computeOpts, 'optionalAccess', _69 => _69.includes, 'call', _70 => _70("zkp")]) || false
|
|
956
1039
|
},
|
|
957
1040
|
feeThreshold
|
|
958
1041
|
};
|
|
@@ -980,7 +1063,7 @@ var signAndSend = async (request, account, opts = DEFAULT_COMPUTE_PAYLOAD) => {
|
|
|
980
1063
|
});
|
|
981
1064
|
});
|
|
982
1065
|
if (tx_result.isError) {
|
|
983
|
-
throw new Error(`Transaction failed with error: ${tx_result.
|
|
1066
|
+
throw new Error(`Transaction failed with error: ${tx_result.dispatchError}`);
|
|
984
1067
|
}
|
|
985
1068
|
if (tx_result.dispatchError) {
|
|
986
1069
|
throw new Error(
|
|
@@ -991,8 +1074,8 @@ var signAndSend = async (request, account, opts = DEFAULT_COMPUTE_PAYLOAD) => {
|
|
|
991
1074
|
`Transaction ${tx_result.txHash.toHex()} included in timepoint ${tx_result.blockNumber}-${tx_result.txIndex}`
|
|
992
1075
|
);
|
|
993
1076
|
return {
|
|
994
|
-
blockNumber: _optionalChain([tx_result, '
|
|
995
|
-
index:
|
|
1077
|
+
blockNumber: _nullishCoalesce(_optionalChain([tx_result, 'access', _71 => _71.blockNumber, 'optionalAccess', _72 => _72.toNumber, 'call', _73 => _73()]), () => ( 0)),
|
|
1078
|
+
index: _nullishCoalesce(tx_result.txIndex, () => ( 0)),
|
|
996
1079
|
hash: tx_result.txHash.toHex(),
|
|
997
1080
|
tx_result
|
|
998
1081
|
};
|
|
@@ -1010,14 +1093,14 @@ var getGuardianAddress = async () => {
|
|
|
1010
1093
|
const api2 = await getApi();
|
|
1011
1094
|
if (!api2) throw new Error("API not initialized");
|
|
1012
1095
|
assert(
|
|
1013
|
-
_util.isFunction.call(void 0, _optionalChain([api2, 'access',
|
|
1014
|
-
`api.query.guardian.
|
|
1096
|
+
_util.isFunction.call(void 0, _optionalChain([api2, 'access', _74 => _74.query, 'access', _75 => _75["guardian"], 'optionalAccess', _76 => _76["workerByKey"]])),
|
|
1097
|
+
`api.query.guardian.workerByKey does not exist`
|
|
1015
1098
|
);
|
|
1016
1099
|
const list = await getGuardianList();
|
|
1017
1100
|
const addresses = await Promise.all(
|
|
1018
1101
|
list.map(async (item) => {
|
|
1019
|
-
const peerid = _bs582.default.decode(item).slice(
|
|
1020
|
-
return (await api2.query["guardian"]["
|
|
1102
|
+
const peerid = _bs582.default.decode(item).slice(6, 38);
|
|
1103
|
+
return (await api2.query["guardian"]["workerByKey"](peerid)).toString();
|
|
1021
1104
|
})
|
|
1022
1105
|
);
|
|
1023
1106
|
return list.map((peerid, index) => ({ peerid, address: addresses[index] }));
|
|
@@ -1030,7 +1113,7 @@ var getGuardianNwParams = async () => {
|
|
|
1030
1113
|
const section = "guardian";
|
|
1031
1114
|
const method = "guardianNwParams";
|
|
1032
1115
|
assert(
|
|
1033
|
-
_util.isFunction.call(void 0, _optionalChain([rpc, 'access',
|
|
1116
|
+
_util.isFunction.call(void 0, _optionalChain([rpc, 'access', _77 => _77[section], 'optionalAccess', _78 => _78[method]])),
|
|
1034
1117
|
`api.rpc.${section}.guardianNwParams does not exist`
|
|
1035
1118
|
);
|
|
1036
1119
|
const guardianNwParams = await rpc[section][method]();
|
|
@@ -1044,6 +1127,149 @@ var getGuardianNwParams = async () => {
|
|
|
1044
1127
|
throw error;
|
|
1045
1128
|
}
|
|
1046
1129
|
};
|
|
1130
|
+
async function fetchAndDecodeExtrinsic(blockHeight, extrinsicIndex) {
|
|
1131
|
+
const api2 = await getApi();
|
|
1132
|
+
if (!api2) throw new Error("API not initialized");
|
|
1133
|
+
const blockHash = await api2.rpc.chain.getBlockHash(blockHeight);
|
|
1134
|
+
const signedBlock = await api2.rpc.chain.getBlock(blockHash);
|
|
1135
|
+
const extrinsics = signedBlock.block.extrinsics;
|
|
1136
|
+
if (extrinsicIndex >= extrinsics.length) {
|
|
1137
|
+
throw new Error(
|
|
1138
|
+
`extrinsic index ${extrinsicIndex} out of range \u2014 block ${blockHeight} has ${extrinsics.length} extrinsics`
|
|
1139
|
+
);
|
|
1140
|
+
}
|
|
1141
|
+
const raw = extrinsics[extrinsicIndex];
|
|
1142
|
+
const decoded = raw.toHuman();
|
|
1143
|
+
return { raw, decoded };
|
|
1144
|
+
}
|
|
1145
|
+
var scanForBlockEvent = (api2, filter, startBlock, maxBlocks = 20) => {
|
|
1146
|
+
const hasPredicate = "predicate" in filter;
|
|
1147
|
+
let blocksScanned = 0;
|
|
1148
|
+
let done = false;
|
|
1149
|
+
return new Promise((resolve, reject) => {
|
|
1150
|
+
const unsubPromise = api2.rpc.chain.subscribeNewHeads(
|
|
1151
|
+
async (header) => {
|
|
1152
|
+
if (done) return;
|
|
1153
|
+
const currentBlock = header.number.toNumber();
|
|
1154
|
+
if (startBlock !== void 0 && currentBlock < startBlock) return;
|
|
1155
|
+
blocksScanned++;
|
|
1156
|
+
if (maxBlocks > 0 && blocksScanned > maxBlocks) {
|
|
1157
|
+
done = true;
|
|
1158
|
+
unsubPromise.then((unsub) => unsub());
|
|
1159
|
+
reject(new Error(`No matching event found within ${maxBlocks} blocks`));
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
try {
|
|
1163
|
+
const blockHash = await api2.rpc.chain.getBlockHash(currentBlock);
|
|
1164
|
+
const eventsResult = await api2.query.system.events.at(blockHash);
|
|
1165
|
+
const events = eventsResult;
|
|
1166
|
+
const blockData = await (hasPredicate ? api2.rpc.chain.getBlock(blockHash) : Promise.resolve(null));
|
|
1167
|
+
for (const record of events) {
|
|
1168
|
+
const { event, phase } = record;
|
|
1169
|
+
const matched = hasPredicate ? await filter.predicate(blockData, event, phase) : event.section.toLowerCase() === filter.section.toLowerCase() && event.method.toLowerCase() === filter.method.toLowerCase();
|
|
1170
|
+
if (!matched) continue;
|
|
1171
|
+
done = true;
|
|
1172
|
+
unsubPromise.then((unsub) => unsub());
|
|
1173
|
+
resolve({
|
|
1174
|
+
blockHash: blockHash.toHex(),
|
|
1175
|
+
blockNumber: currentBlock,
|
|
1176
|
+
extrinsicIndex: phase.isApplyExtrinsic ? phase.asApplyExtrinsic.toNumber() : null,
|
|
1177
|
+
block: blockData ? () => Promise.resolve(blockData) : () => api2.rpc.chain.getBlock(blockHash),
|
|
1178
|
+
events
|
|
1179
|
+
});
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
} catch (err) {
|
|
1183
|
+
debugLog(`scanForBlockEvent: error scanning block ${currentBlock}: ${err}`);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
);
|
|
1187
|
+
});
|
|
1188
|
+
};
|
|
1189
|
+
async function watchForSubmissionReceipt(requestId, timeoutMs = 10 * 60 * 1e3) {
|
|
1190
|
+
const api2 = await getApi();
|
|
1191
|
+
if (!api2) throw new Error("API not initialized");
|
|
1192
|
+
return new Promise((resolve, reject) => {
|
|
1193
|
+
let unsubFn;
|
|
1194
|
+
let settled = false;
|
|
1195
|
+
const cleanup = (settleFn) => {
|
|
1196
|
+
if (settled) return;
|
|
1197
|
+
settled = true;
|
|
1198
|
+
_optionalChain([unsubFn, 'optionalCall', _79 => _79()]);
|
|
1199
|
+
settleFn();
|
|
1200
|
+
};
|
|
1201
|
+
const timer = setTimeout(
|
|
1202
|
+
() => cleanup(() => reject(new Error(`receipt watch timed out for requestId=${requestId}`))),
|
|
1203
|
+
timeoutMs
|
|
1204
|
+
);
|
|
1205
|
+
api2.rpc.chain.subscribeNewHeads(async (header) => {
|
|
1206
|
+
if (settled) return;
|
|
1207
|
+
try {
|
|
1208
|
+
const blockNumber = header.number.toNumber();
|
|
1209
|
+
const blockHash = header.hash;
|
|
1210
|
+
const signedBlock = await api2.rpc.chain.getBlock(blockHash);
|
|
1211
|
+
const extrinsics = signedBlock.block.extrinsics;
|
|
1212
|
+
for (let i = 0; i < extrinsics.length; i++) {
|
|
1213
|
+
const ext = extrinsics[i];
|
|
1214
|
+
const decoded = ext.toHuman();
|
|
1215
|
+
const method = _optionalChain([decoded, 'optionalAccess', _80 => _80.method]);
|
|
1216
|
+
if (String(_nullishCoalesce(_optionalChain([method, 'optionalAccess', _81 => _81.section]), () => ( ""))).toLowerCase() === "compute" && String(_nullishCoalesce(_optionalChain([method, 'optionalAccess', _82 => _82.method]), () => ( ""))).toLowerCase() === "result") {
|
|
1217
|
+
const args = _optionalChain([method, 'optionalAccess', _83 => _83.args]);
|
|
1218
|
+
const onChainId = String(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([args, 'optionalAccess', _84 => _84.request_id]), () => ( _optionalChain([args, 'optionalAccess', _85 => _85.requestId]))), () => ( _optionalChain([args, 'optionalAccess', _86 => _86[0]]))), () => ( "")));
|
|
1219
|
+
if (onChainId === requestId) {
|
|
1220
|
+
clearTimeout(timer);
|
|
1221
|
+
cleanup(
|
|
1222
|
+
() => resolve({
|
|
1223
|
+
extrinsicHash: ext.hash.toHex(),
|
|
1224
|
+
blockHeight: blockNumber,
|
|
1225
|
+
extrinsicIndex: i
|
|
1226
|
+
})
|
|
1227
|
+
);
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
} catch (err) {
|
|
1233
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1234
|
+
console.warn(`[watchReceipt] block check failed requestId=${requestId}: ${msg}`);
|
|
1235
|
+
}
|
|
1236
|
+
}).then((fn) => {
|
|
1237
|
+
if (settled) {
|
|
1238
|
+
fn();
|
|
1239
|
+
} else {
|
|
1240
|
+
unsubFn = fn;
|
|
1241
|
+
}
|
|
1242
|
+
}).catch((err) => {
|
|
1243
|
+
clearTimeout(timer);
|
|
1244
|
+
cleanup(() => reject(err));
|
|
1245
|
+
});
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
async function getAgreementCreatedRequestId(blockHeight, extrinsicIndex) {
|
|
1249
|
+
const api2 = await getApi();
|
|
1250
|
+
if (!api2) throw new Error("API not initialized");
|
|
1251
|
+
const blockHash = await api2.rpc.chain.getBlockHash(blockHeight);
|
|
1252
|
+
const apiAt = await api2.at(blockHash);
|
|
1253
|
+
const allEvents = await apiAt.query.system.events();
|
|
1254
|
+
for (const record of allEvents) {
|
|
1255
|
+
const { phase, event } = record;
|
|
1256
|
+
if (!phase.isApplyExtrinsic || phase.asApplyExtrinsic.toNumber() !== extrinsicIndex) {
|
|
1257
|
+
continue;
|
|
1258
|
+
}
|
|
1259
|
+
if (String(_nullishCoalesce(event.section, () => ( ""))).toLowerCase() !== "compute" || String(_nullishCoalesce(event.method, () => ( ""))).toLowerCase() !== "agreementcreated") {
|
|
1260
|
+
continue;
|
|
1261
|
+
}
|
|
1262
|
+
const dataHuman = event.data.toHuman();
|
|
1263
|
+
if (Array.isArray(dataHuman)) {
|
|
1264
|
+
const first = dataHuman[0];
|
|
1265
|
+
if (first != null) return String(first);
|
|
1266
|
+
} else if (dataHuman !== null && typeof dataHuman === "object") {
|
|
1267
|
+
const id = _nullishCoalesce(_nullishCoalesce(dataHuman["requestId"], () => ( dataHuman["request_id"])), () => ( dataHuman["id"]));
|
|
1268
|
+
if (id != null) return String(id);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
return null;
|
|
1272
|
+
}
|
|
1047
1273
|
|
|
1048
1274
|
// src/chain/onchainfs.ts
|
|
1049
1275
|
var getBlock2 = async (api2, blockNumber) => {
|
|
@@ -1082,12 +1308,10 @@ var MCryptFs = class _MCryptFs {
|
|
|
1082
1308
|
this._metaRef = metadataRef;
|
|
1083
1309
|
this._metadata = metadata;
|
|
1084
1310
|
this._init = true;
|
|
1311
|
+
this._chunkRefs = [];
|
|
1085
1312
|
}
|
|
1086
1313
|
static dummyInstance(mcryptApi) {
|
|
1087
|
-
return new _MCryptFs(mcryptApi, null,
|
|
1088
|
-
name: "on-chain-file-name.txt",
|
|
1089
|
-
description: "File uploaded using mcrypt-onchain-fs"
|
|
1090
|
-
});
|
|
1314
|
+
return new _MCryptFs(mcryptApi, null, null);
|
|
1091
1315
|
}
|
|
1092
1316
|
isValid() {
|
|
1093
1317
|
if (!this._metaRef) {
|
|
@@ -1151,8 +1375,8 @@ var MCryptFsWriter = class {
|
|
|
1151
1375
|
request.signAndSend(this._account, { app_id: 1 }, (result) => {
|
|
1152
1376
|
if (result.isInBlock || result.isFinalized || result.isError) {
|
|
1153
1377
|
resolve({
|
|
1154
|
-
blockNumber: _optionalChain([result, 'access',
|
|
1155
|
-
index: result.txIndex
|
|
1378
|
+
blockNumber: _nullishCoalesce(_optionalChain([result, 'access', _87 => _87.blockNumber, 'optionalAccess', _88 => _88.toNumber, 'call', _89 => _89()]), () => ( 0)),
|
|
1379
|
+
index: _nullishCoalesce(result.txIndex, () => ( 0))
|
|
1156
1380
|
});
|
|
1157
1381
|
}
|
|
1158
1382
|
});
|
|
@@ -1174,7 +1398,7 @@ var MCryptFsWriter = class {
|
|
|
1174
1398
|
ciphertext: uint8ArrayToBase64(Uint8Array.from(ciphertext)),
|
|
1175
1399
|
td_params,
|
|
1176
1400
|
group_pk: this._guardianInfo.groupPk,
|
|
1177
|
-
tau_params: this._guardianInfo.
|
|
1401
|
+
tau_params: this._guardianInfo.tauParams,
|
|
1178
1402
|
chosen_guardians: this._guardianInfo.guardians,
|
|
1179
1403
|
blobRef: [blobRef.blockNumber, blobRef.extrinsicIndex]
|
|
1180
1404
|
});
|
|
@@ -1217,7 +1441,7 @@ var MCryptFsWriter = class {
|
|
|
1217
1441
|
const metadataRef = await this.writeMetadata();
|
|
1218
1442
|
return await FileFromMetadataRef(this._api, [
|
|
1219
1443
|
metadataRef.blockNumber,
|
|
1220
|
-
metadataRef.index
|
|
1444
|
+
_nullishCoalesce(metadataRef.index, () => ( 0))
|
|
1221
1445
|
]);
|
|
1222
1446
|
}
|
|
1223
1447
|
};
|
|
@@ -1229,6 +1453,9 @@ var MCryptFsReader = class {
|
|
|
1229
1453
|
}
|
|
1230
1454
|
async downloadFile() {
|
|
1231
1455
|
const chunks = [];
|
|
1456
|
+
if (!this._onChainFile._metadata) {
|
|
1457
|
+
throw new Error("Metadata not loaded");
|
|
1458
|
+
}
|
|
1232
1459
|
let _blockNumber = this._onChainFile._metadata.startRef[0];
|
|
1233
1460
|
let _extIndex = this._onChainFile._metadata.startRef[1];
|
|
1234
1461
|
while (_blockNumber !== 0) {
|
|
@@ -1260,21 +1487,13 @@ var FileFromMetadataRef = async (mcryptApi, metadataRef) => {
|
|
|
1260
1487
|
};
|
|
1261
1488
|
|
|
1262
1489
|
// src/compute/agreement.ts
|
|
1263
|
-
|
|
1264
1490
|
async function createAgreement(contract, account) {
|
|
1265
1491
|
const api2 = await getApi();
|
|
1266
1492
|
if (!api2) throw new Error("Api not initialized");
|
|
1267
|
-
const
|
|
1268
|
-
const agreement = guardians.map((g) => _bs582.default.decode(g.peerid).subarray(6));
|
|
1269
|
-
const txContract = {
|
|
1270
|
-
...contract,
|
|
1271
|
-
guardians: guardians.map((g) => g.address)
|
|
1272
|
-
};
|
|
1273
|
-
const tx = api2.tx.compute.agreement(txContract);
|
|
1493
|
+
const tx = api2.tx["compute"]["agreement"](contract);
|
|
1274
1494
|
const opts = {
|
|
1275
1495
|
compute: {
|
|
1276
1496
|
da_type: 1,
|
|
1277
|
-
agreement,
|
|
1278
1497
|
verification: 0,
|
|
1279
1498
|
compute: contract.contract_type === "Active" ? 1 : 0
|
|
1280
1499
|
}
|
|
@@ -1285,28 +1504,27 @@ async function createAgreement(contract, account) {
|
|
|
1285
1504
|
opts
|
|
1286
1505
|
);
|
|
1287
1506
|
if (!tx_result.isError) {
|
|
1288
|
-
const agreementCreatedEvent = tx_result.events.find(
|
|
1289
|
-
|
|
1290
|
-
|
|
1507
|
+
const agreementCreatedEvent = tx_result.events.find(
|
|
1508
|
+
(event) => {
|
|
1509
|
+
return event.event.section === "compute" && event.event.method === "AgreementCreated";
|
|
1510
|
+
}
|
|
1511
|
+
);
|
|
1291
1512
|
if (agreementCreatedEvent) {
|
|
1292
|
-
debugLog(
|
|
1293
|
-
"Agreement data:",
|
|
1294
|
-
agreementCreatedEvent.event.data.toString()
|
|
1295
|
-
);
|
|
1513
|
+
debugLog("Agreement data:", agreementCreatedEvent.event.data.toString());
|
|
1296
1514
|
return {
|
|
1297
1515
|
blockNumber,
|
|
1298
|
-
index,
|
|
1516
|
+
index: _nullishCoalesce(index, () => ( 0)),
|
|
1299
1517
|
hash,
|
|
1300
|
-
agreementId: _nullishCoalesce(_optionalChain([agreementCreatedEvent, 'access',
|
|
1518
|
+
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()))
|
|
1301
1519
|
};
|
|
1302
1520
|
} else {
|
|
1303
1521
|
debugLog("AgreementCreated event not found");
|
|
1304
1522
|
}
|
|
1305
1523
|
}
|
|
1306
|
-
return { blockNumber, index, hash };
|
|
1524
|
+
return { blockNumber, index: _nullishCoalesce(index, () => ( 0)), hash };
|
|
1307
1525
|
}
|
|
1308
1526
|
async function createSimpleAgreement() {
|
|
1309
|
-
const guardianIds = (await getGuardianAddress()).slice(0, 3);
|
|
1527
|
+
const guardianIds = (await getGuardianAddress()).slice(0, 3).map((g) => g.address);
|
|
1310
1528
|
assert(guardianIds.length === 3, "Not enough guardians to create agreement");
|
|
1311
1529
|
const contract = {
|
|
1312
1530
|
contract_type: "Dormant",
|
|
@@ -1315,9 +1533,9 @@ async function createSimpleAgreement() {
|
|
|
1315
1533
|
compute: {
|
|
1316
1534
|
cipher: "Plaintext",
|
|
1317
1535
|
computer_indices: [0, 1, 2],
|
|
1318
|
-
fees:
|
|
1536
|
+
fees: toAtomicPaliAmount("0.01"),
|
|
1319
1537
|
deadline: 0,
|
|
1320
|
-
confidentiality: { Trusted:
|
|
1538
|
+
confidentiality: { Trusted: 0 },
|
|
1321
1539
|
fee_function: null,
|
|
1322
1540
|
input: null,
|
|
1323
1541
|
program: { NativeData: "DaFalse" },
|
|
@@ -1332,9 +1550,7 @@ async function createSimpleAgreement() {
|
|
|
1332
1550
|
}
|
|
1333
1551
|
|
|
1334
1552
|
// src/compute/data.ts
|
|
1335
|
-
async function dataContract(params) {
|
|
1336
|
-
const keyring2 = await getKeyring();
|
|
1337
|
-
const account = keyring2.getPairs()[0];
|
|
1553
|
+
async function dataContract(params, account) {
|
|
1338
1554
|
const plaintextCipher = "Plaintext";
|
|
1339
1555
|
const atomicFees = toAtomicPaliAmount(_nullishCoalesce(params.fees, () => ( "0")));
|
|
1340
1556
|
const computeStep = {
|
|
@@ -1342,11 +1558,7 @@ async function dataContract(params) {
|
|
|
1342
1558
|
computer_indices: params.guardians.map((_, i) => i),
|
|
1343
1559
|
fees: atomicFees,
|
|
1344
1560
|
deadline: _nullishCoalesce(params.deadline, () => ( 0)),
|
|
1345
|
-
confidentiality: {
|
|
1346
|
-
Trusted: {
|
|
1347
|
-
trust_index: _nullishCoalesce(params.trustIndex, () => ( 0))
|
|
1348
|
-
}
|
|
1349
|
-
},
|
|
1561
|
+
confidentiality: { Trusted: _nullishCoalesce(params.trustIndex, () => ( 0)) },
|
|
1350
1562
|
fee_function: null,
|
|
1351
1563
|
input: {
|
|
1352
1564
|
Url: {
|
|
@@ -1369,9 +1581,7 @@ async function dataContract(params) {
|
|
|
1369
1581
|
}
|
|
1370
1582
|
|
|
1371
1583
|
// src/compute/inference.ts
|
|
1372
|
-
async function inferenceCompute(params) {
|
|
1373
|
-
const keyring2 = await getKeyring();
|
|
1374
|
-
const account = keyring2.getPairs()[0];
|
|
1584
|
+
async function inferenceCompute(params, account) {
|
|
1375
1585
|
const inputData = typeof params.input === "string" ? Array.from(new TextEncoder().encode(params.input)) : Array.from(params.input);
|
|
1376
1586
|
const atomicFees = toAtomicPaliAmount(_nullishCoalesce(params.fees, () => ( "0")));
|
|
1377
1587
|
const plaintextCipher = "Plaintext";
|
|
@@ -1380,7 +1590,7 @@ async function inferenceCompute(params) {
|
|
|
1380
1590
|
computer_indices: params.guardians.map((_, i) => i),
|
|
1381
1591
|
fees: atomicFees,
|
|
1382
1592
|
deadline: _nullishCoalesce(params.deadline, () => ( 0)),
|
|
1383
|
-
confidentiality: { Trusted:
|
|
1593
|
+
confidentiality: { Trusted: 0 },
|
|
1384
1594
|
fee_function: null,
|
|
1385
1595
|
input: { Inline: { data: inputData } },
|
|
1386
1596
|
program: { NativeExecute: "Inference" }
|
|
@@ -1406,10 +1616,10 @@ async function getGuardianParticipants() {
|
|
|
1406
1616
|
const currentIndex = await api2.query.guardian.currentIndex();
|
|
1407
1617
|
const peerid = await api2.rpc.system.localPeerId();
|
|
1408
1618
|
const _peerid = _bs582.default.decode((peerid || "").toString());
|
|
1409
|
-
const account = await api2.query.guardian.
|
|
1619
|
+
const account = await api2.query.guardian.workerByKey(_peerid.slice(6, 38));
|
|
1410
1620
|
const nextIndex = currentIndex ? Number(currentIndex) + 1 : 1;
|
|
1411
|
-
const guardiansList = _optionalChain([guardians, 'optionalAccess',
|
|
1412
|
-
const nextGuardiansList = _optionalChain([nextGuardians, 'optionalAccess',
|
|
1621
|
+
const guardiansList = _optionalChain([guardians, 'optionalAccess', _95 => _95.toJSON, 'call', _96 => _96()]) || [];
|
|
1622
|
+
const nextGuardiansList = _optionalChain([nextGuardians, 'optionalAccess', _97 => _97.toJSON, 'call', _98 => _98()]) || [];
|
|
1413
1623
|
const buildDetails = async (list) => {
|
|
1414
1624
|
return Promise.all(
|
|
1415
1625
|
list.map(async (guardian) => {
|
|
@@ -1418,21 +1628,21 @@ async function getGuardianParticipants() {
|
|
|
1418
1628
|
const bonded = await api2.query.staking.bonded(guardian);
|
|
1419
1629
|
const payee = await api2.query.staking.payee(guardian);
|
|
1420
1630
|
const stakersOverview = await api2.query.staking.erasStakersOverview(
|
|
1421
|
-
_optionalChain([currentEra, 'optionalAccess',
|
|
1631
|
+
_optionalChain([currentEra, 'optionalAccess', _99 => _99.toPrimitive, 'call', _100 => _100()]),
|
|
1422
1632
|
guardian
|
|
1423
1633
|
);
|
|
1424
1634
|
const guardianErasPrefs = await api2.query.staking.erasGuardianPrefs(
|
|
1425
|
-
_optionalChain([currentEra, 'optionalAccess',
|
|
1635
|
+
_optionalChain([currentEra, 'optionalAccess', _101 => _101.toPrimitive, 'call', _102 => _102()]),
|
|
1426
1636
|
guardian
|
|
1427
1637
|
);
|
|
1428
1638
|
return {
|
|
1429
1639
|
guardian,
|
|
1430
|
-
rewardDestination: _optionalChain([payee, 'optionalAccess',
|
|
1431
|
-
currentPreferences: _optionalChain([guardianErasPrefs, 'optionalAccess',
|
|
1432
|
-
upcomingPreferences: _optionalChain([guardianPrefs, 'optionalAccess',
|
|
1433
|
-
stash: _optionalChain([bonded, 'optionalAccess',
|
|
1434
|
-
currentStakeOverview: _optionalChain([stakersOverview, 'optionalAccess',
|
|
1435
|
-
upcomingStakeOverview: _optionalChain([ledger, 'optionalAccess',
|
|
1640
|
+
rewardDestination: _optionalChain([payee, 'optionalAccess', _103 => _103.toHuman]) ? payee.toHuman() : null,
|
|
1641
|
+
currentPreferences: _optionalChain([guardianErasPrefs, 'optionalAccess', _104 => _104.toHuman]) ? guardianErasPrefs.toHuman() : null,
|
|
1642
|
+
upcomingPreferences: _optionalChain([guardianPrefs, 'optionalAccess', _105 => _105.toHuman]) ? guardianPrefs.toHuman() : null,
|
|
1643
|
+
stash: _optionalChain([bonded, 'optionalAccess', _106 => _106.toHuman]) ? bonded.toHuman() : null,
|
|
1644
|
+
currentStakeOverview: _optionalChain([stakersOverview, 'optionalAccess', _107 => _107.toHuman]) ? stakersOverview.toHuman() : null,
|
|
1645
|
+
upcomingStakeOverview: _optionalChain([ledger, 'optionalAccess', _108 => _108.toHuman]) ? ledger.toHuman() : null
|
|
1436
1646
|
};
|
|
1437
1647
|
})
|
|
1438
1648
|
);
|
|
@@ -1441,12 +1651,12 @@ async function getGuardianParticipants() {
|
|
|
1441
1651
|
const upcomingGuardians = await buildDetails(nextGuardiansList);
|
|
1442
1652
|
return {
|
|
1443
1653
|
nwState: {
|
|
1444
|
-
localPeerId: _optionalChain([peerid, 'optionalAccess',
|
|
1445
|
-
worker: _optionalChain([account, 'optionalAccess',
|
|
1446
|
-
currentEra: _optionalChain([currentEra, 'optionalAccess',
|
|
1447
|
-
guardians: JSON.stringify(_optionalChain([guardians, 'optionalAccess',
|
|
1448
|
-
nextGuardians: JSON.stringify(_optionalChain([nextGuardians, 'optionalAccess',
|
|
1449
|
-
currentIndex: _optionalChain([currentIndex, 'optionalAccess',
|
|
1654
|
+
localPeerId: _optionalChain([peerid, 'optionalAccess', _109 => _109.toString, 'call', _110 => _110()]),
|
|
1655
|
+
worker: _optionalChain([account, 'optionalAccess', _111 => _111.toHuman]) ? account.toHuman() : null,
|
|
1656
|
+
currentEra: _optionalChain([currentEra, 'optionalAccess', _112 => _112.toHuman]) ? currentEra.toHuman() : null,
|
|
1657
|
+
guardians: JSON.stringify(_optionalChain([guardians, 'optionalAccess', _113 => _113.toHuman]) ? guardians.toHuman() : null, null, 2),
|
|
1658
|
+
nextGuardians: JSON.stringify(_optionalChain([nextGuardians, 'optionalAccess', _114 => _114.toHuman]) ? nextGuardians.toHuman() : null, null, 2),
|
|
1659
|
+
currentIndex: _optionalChain([currentIndex, 'optionalAccess', _115 => _115.toHuman]) ? currentIndex.toHuman() : null,
|
|
1450
1660
|
nextIndex
|
|
1451
1661
|
},
|
|
1452
1662
|
currentGuardians,
|
|
@@ -1458,9 +1668,7 @@ async function getGuardianParticipants() {
|
|
|
1458
1668
|
}
|
|
1459
1669
|
|
|
1460
1670
|
// src/compute/simple.ts
|
|
1461
|
-
async function simpleCompute(params) {
|
|
1462
|
-
const keyring2 = await getKeyring();
|
|
1463
|
-
const account = keyring2.getPairs()[0];
|
|
1671
|
+
async function simpleCompute(params, account) {
|
|
1464
1672
|
const plaintextCipher = "Plaintext";
|
|
1465
1673
|
const atomicFees = toAtomicPaliAmount(_nullishCoalesce(params.fees, () => ( "0")));
|
|
1466
1674
|
const computeStep = {
|
|
@@ -1468,18 +1676,9 @@ async function simpleCompute(params) {
|
|
|
1468
1676
|
computer_indices: params.guardians.map((_, i) => i),
|
|
1469
1677
|
fees: atomicFees,
|
|
1470
1678
|
deadline: _nullishCoalesce(params.deadline, () => ( 0)),
|
|
1471
|
-
confidentiality: {
|
|
1472
|
-
Trusted: {
|
|
1473
|
-
trust_index: _nullishCoalesce(params.trustIndex, () => ( 0))
|
|
1474
|
-
}
|
|
1475
|
-
},
|
|
1679
|
+
confidentiality: { Trusted: _nullishCoalesce(params.trustIndex, () => ( 0)) },
|
|
1476
1680
|
fee_function: null,
|
|
1477
|
-
input:
|
|
1478
|
-
ChainTransaction: {
|
|
1479
|
-
block_number: params.inputBlockNumber,
|
|
1480
|
-
extrinsic_index: params.inputExtrinsicIndex
|
|
1481
|
-
}
|
|
1482
|
-
},
|
|
1681
|
+
input: null,
|
|
1483
1682
|
program: {
|
|
1484
1683
|
Url: {
|
|
1485
1684
|
url: Array.from(new TextEncoder().encode(params.programUrl))
|
|
@@ -1551,11 +1750,7 @@ async function registerDataAgreement(account, params) {
|
|
|
1551
1750
|
computer_indices: params.guardians.map((_, i) => i),
|
|
1552
1751
|
fees: params.fees,
|
|
1553
1752
|
deadline: _nullishCoalesce(params.deadline, () => ( 0)),
|
|
1554
|
-
confidentiality: {
|
|
1555
|
-
Trusted: {
|
|
1556
|
-
trust_index: _nullishCoalesce(params.trustIndex, () => ( 0))
|
|
1557
|
-
}
|
|
1558
|
-
},
|
|
1753
|
+
confidentiality: { Trusted: _nullishCoalesce(params.trustIndex, () => ( 0)) },
|
|
1559
1754
|
fee_function: null,
|
|
1560
1755
|
input: {
|
|
1561
1756
|
ChainTransaction: {
|
|
@@ -1657,15 +1852,15 @@ async function submitTEDataWithCipher(account, data, chosenGuardians, tau_params
|
|
|
1657
1852
|
return {
|
|
1658
1853
|
ref,
|
|
1659
1854
|
cipher: {
|
|
1660
|
-
|
|
1661
|
-
|
|
1855
|
+
ThresholdHybrid: {
|
|
1856
|
+
threshold_params: {
|
|
1662
1857
|
SilentThreshold: {
|
|
1663
1858
|
td_params: Array.from(hexToUint8Array(encryptedKey)),
|
|
1664
1859
|
pk_bytes: Array.from(hexToUint8Array(group_pk)),
|
|
1665
1860
|
tau_params: Array.from(hexToUint8Array(tau_params))
|
|
1666
1861
|
}
|
|
1667
1862
|
},
|
|
1668
|
-
|
|
1863
|
+
symmetric_params: {
|
|
1669
1864
|
ChaCha20Poly1305: { nonce: Array.from(nonce) }
|
|
1670
1865
|
}
|
|
1671
1866
|
}
|
|
@@ -1830,9 +2025,9 @@ async function removeStake(account) {
|
|
|
1830
2025
|
const api2 = await getApi();
|
|
1831
2026
|
assert(api2, "API not initialized");
|
|
1832
2027
|
assert(account, "Account not initialized");
|
|
1833
|
-
const stakeAmount = await _asyncOptionalChain([(await api2.query.staking.ledger(account.address)), 'optionalAccess', async
|
|
1834
|
-
debugLog("Removing entire stake amount:", formatPaliAmount(_optionalChain([stakeAmount, 'optionalAccess',
|
|
1835
|
-
const unstakeTx = api2.tx.staking.unbond(_optionalChain([stakeAmount, 'optionalAccess',
|
|
2028
|
+
const stakeAmount = await _asyncOptionalChain([(await api2.query.staking.ledger(account.address)), 'optionalAccess', async _116 => _116.toPrimitive, 'call', async _117 => _117()]);
|
|
2029
|
+
debugLog("Removing entire stake amount:", formatPaliAmount(_optionalChain([stakeAmount, 'optionalAccess', _118 => _118.active]) || 0n));
|
|
2030
|
+
const unstakeTx = api2.tx.staking.unbond(_optionalChain([stakeAmount, 'optionalAccess', _119 => _119.active]) || 0n);
|
|
1836
2031
|
const hash = await signAndSend(unstakeTx, account);
|
|
1837
2032
|
debugLog(`Unstake transaction sent with hash: ${hash.hash}`);
|
|
1838
2033
|
}
|
|
@@ -1901,7 +2096,7 @@ async function rotateAndSetKeys(account) {
|
|
|
1901
2096
|
_assert2.default.call(void 0, api2, "API not initialized");
|
|
1902
2097
|
debugLog(`Rotating session keys for ${account.meta.name} on ${provider.endpoint}`);
|
|
1903
2098
|
const newKeys = await api2.rpc.author.rotateKeys();
|
|
1904
|
-
debugLog(`${account.meta.name} rotated keys on ${provider.endpoint}:`, _nullishCoalesce(_optionalChain([newKeys, 'optionalAccess',
|
|
2099
|
+
debugLog(`${account.meta.name} rotated keys on ${provider.endpoint}:`, _nullishCoalesce(_optionalChain([newKeys, 'optionalAccess', _120 => _120.toHex, 'optionalCall', _121 => _121()]), () => ( newKeys)));
|
|
1905
2100
|
const setKeysTx = api2.tx.session.setKeys(newKeys, []);
|
|
1906
2101
|
const hash = await signAndSend(setKeysTx, account);
|
|
1907
2102
|
debugLog(`Rotate session transaction sent with hash: ${hash.hash}`);
|
|
@@ -1910,7 +2105,7 @@ async function setWorker(account) {
|
|
|
1910
2105
|
const api2 = await getApi();
|
|
1911
2106
|
_assert2.default.call(void 0, api2, "API not initialized");
|
|
1912
2107
|
const peerid = _bs582.default.decode((await api2.rpc.system.localPeerId()).toString());
|
|
1913
|
-
const setWorkerTx = api2.tx.guardian.setWorker(peerid.slice(
|
|
2108
|
+
const setWorkerTx = api2.tx.guardian.setWorker(peerid.slice(6, 38));
|
|
1914
2109
|
const hash = await signAndSend(setWorkerTx, account);
|
|
1915
2110
|
debugLog(`Set worker id transaction sent with hash: ${hash.hash}`);
|
|
1916
2111
|
}
|
|
@@ -2007,5 +2202,10 @@ async function setWorker(account) {
|
|
|
2007
2202
|
|
|
2008
2203
|
|
|
2009
2204
|
|
|
2010
|
-
|
|
2205
|
+
|
|
2206
|
+
|
|
2207
|
+
|
|
2208
|
+
|
|
2209
|
+
|
|
2210
|
+
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.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;
|
|
2011
2211
|
//# sourceMappingURL=index.cjs.map
|