@palliora.org/chainsdk 0.1.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/README.md +254 -0
- package/dist/index.cjs +1687 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +811 -0
- package/dist/index.d.ts +811 -0
- package/dist/index.js +1687 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
import * as _polkadot_util_crypto_types from '@polkadot/util-crypto/types';
|
|
2
|
+
import { ApiPromise, Keyring, WsProvider } from '@polkadot/api';
|
|
3
|
+
export { ApiPromise, HttpProvider, WsProvider } from '@polkadot/api';
|
|
4
|
+
import * as _noble_curves_abstract_weierstrass from '@noble/curves/abstract/weierstrass';
|
|
5
|
+
import { ProjPointType } from '@noble/curves/abstract/weierstrass';
|
|
6
|
+
import { Fp, Fp2, Fp12 } from '@noble/curves/abstract/tower';
|
|
7
|
+
export * from '@polkadot/util';
|
|
8
|
+
import * as utilCrypto from '@polkadot/util-crypto';
|
|
9
|
+
export { utilCrypto };
|
|
10
|
+
import * as wasmCrypto from '@polkadot/wasm-crypto';
|
|
11
|
+
export { wasmCrypto };
|
|
12
|
+
|
|
13
|
+
declare enum CryptoType {
|
|
14
|
+
SR25519 = "sr25519",
|
|
15
|
+
ED25519 = "ed25519",
|
|
16
|
+
ECDSA = "ecdsa"
|
|
17
|
+
}
|
|
18
|
+
declare enum AccountSourceType {
|
|
19
|
+
PRIVATE_KEY = "privateKey",
|
|
20
|
+
SEED = "seed",
|
|
21
|
+
MNEMONIC = "mnemonic",
|
|
22
|
+
DERIVED = "derived",
|
|
23
|
+
ADDRESS = "address"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a Substrate account from a private key, seed, or mnemonic.
|
|
28
|
+
* @param input - The input string (private key hex, seed hex, or mnemonic phrase).
|
|
29
|
+
* @param type - The type of input: 'privateKey', 'seed', or 'mnemonic'.
|
|
30
|
+
* @param cryptoType - The crypto type: 'sr25519' | 'ed25519' | 'ecdsa' (default: 'sr25519').
|
|
31
|
+
* @returns The keypair object.
|
|
32
|
+
*/
|
|
33
|
+
declare function createAccount(input: any, type: AccountSourceType, name?: string, cryptoType?: CryptoType): Promise<any>;
|
|
34
|
+
declare function pairFromPrivateKeyHex(privateKeyHex: string, cryptoType: CryptoType): _polkadot_util_crypto_types.Keypair;
|
|
35
|
+
|
|
36
|
+
declare const API_RPC: {
|
|
37
|
+
kate: {
|
|
38
|
+
queryRows: {
|
|
39
|
+
description: string;
|
|
40
|
+
params: ({
|
|
41
|
+
name: string;
|
|
42
|
+
type: string;
|
|
43
|
+
isOptional?: undefined;
|
|
44
|
+
} | {
|
|
45
|
+
name: string;
|
|
46
|
+
type: string;
|
|
47
|
+
isOptional: boolean;
|
|
48
|
+
})[];
|
|
49
|
+
type: string;
|
|
50
|
+
};
|
|
51
|
+
queryProof: {
|
|
52
|
+
description: string;
|
|
53
|
+
params: ({
|
|
54
|
+
name: string;
|
|
55
|
+
type: string;
|
|
56
|
+
isOptional?: undefined;
|
|
57
|
+
} | {
|
|
58
|
+
name: string;
|
|
59
|
+
type: string;
|
|
60
|
+
isOptional: boolean;
|
|
61
|
+
})[];
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
blockLength: {
|
|
65
|
+
description: string;
|
|
66
|
+
params: {
|
|
67
|
+
name: string;
|
|
68
|
+
type: string;
|
|
69
|
+
isOptional: boolean;
|
|
70
|
+
}[];
|
|
71
|
+
type: string;
|
|
72
|
+
};
|
|
73
|
+
queryDataProof: {
|
|
74
|
+
description: string;
|
|
75
|
+
params: ({
|
|
76
|
+
name: string;
|
|
77
|
+
type: string;
|
|
78
|
+
isOptional?: undefined;
|
|
79
|
+
} | {
|
|
80
|
+
name: string;
|
|
81
|
+
type: string;
|
|
82
|
+
isOptional: boolean;
|
|
83
|
+
})[];
|
|
84
|
+
type: string;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
guardian: {
|
|
88
|
+
runtimeInfo: {
|
|
89
|
+
description: string;
|
|
90
|
+
params: {
|
|
91
|
+
name: string;
|
|
92
|
+
type: string;
|
|
93
|
+
isOptional: boolean;
|
|
94
|
+
}[];
|
|
95
|
+
type: string;
|
|
96
|
+
};
|
|
97
|
+
guardianList: {
|
|
98
|
+
description: string;
|
|
99
|
+
params: never[];
|
|
100
|
+
type: string;
|
|
101
|
+
};
|
|
102
|
+
guardianNwParams: {
|
|
103
|
+
description: string;
|
|
104
|
+
params: never[];
|
|
105
|
+
type: string;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
declare const API_TYPES: {
|
|
110
|
+
GuardianInfo: {
|
|
111
|
+
active: string;
|
|
112
|
+
maximum: string;
|
|
113
|
+
};
|
|
114
|
+
GuardianNwParams: {
|
|
115
|
+
kzg: string;
|
|
116
|
+
agg_key: string;
|
|
117
|
+
};
|
|
118
|
+
AppId: string;
|
|
119
|
+
DataLookupItem: {
|
|
120
|
+
appId: string;
|
|
121
|
+
start: string;
|
|
122
|
+
};
|
|
123
|
+
CompactDataLookup: {
|
|
124
|
+
size: string;
|
|
125
|
+
index: string;
|
|
126
|
+
};
|
|
127
|
+
KateCommitment: {
|
|
128
|
+
rows: string;
|
|
129
|
+
cols: string;
|
|
130
|
+
commitment: string;
|
|
131
|
+
dataRoot: string;
|
|
132
|
+
};
|
|
133
|
+
V3HeaderExtension: {
|
|
134
|
+
appLookup: string;
|
|
135
|
+
commitment: string;
|
|
136
|
+
};
|
|
137
|
+
HeaderExtension: {
|
|
138
|
+
_enum: {
|
|
139
|
+
V1: null;
|
|
140
|
+
V2: null;
|
|
141
|
+
V3: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
DaHeader: {
|
|
145
|
+
parentHash: string;
|
|
146
|
+
number: string;
|
|
147
|
+
stateRoot: string;
|
|
148
|
+
extrinsicsRoot: string;
|
|
149
|
+
digest: string;
|
|
150
|
+
extension: string;
|
|
151
|
+
};
|
|
152
|
+
Header: string;
|
|
153
|
+
CheckAppIdExtra: {
|
|
154
|
+
appId: string;
|
|
155
|
+
};
|
|
156
|
+
CheckAppIdTypes: {};
|
|
157
|
+
CheckAppId: {
|
|
158
|
+
extra: string;
|
|
159
|
+
types: string;
|
|
160
|
+
};
|
|
161
|
+
ComputePayload: {
|
|
162
|
+
da_type: string;
|
|
163
|
+
agreement: string;
|
|
164
|
+
verification: string;
|
|
165
|
+
compute: string;
|
|
166
|
+
};
|
|
167
|
+
BlockLengthColumns: string;
|
|
168
|
+
BlockLengthRows: string;
|
|
169
|
+
BlockLength: {
|
|
170
|
+
max: string;
|
|
171
|
+
cols: string;
|
|
172
|
+
rows: string;
|
|
173
|
+
chunkSize: string;
|
|
174
|
+
};
|
|
175
|
+
PerDispatchClass: {
|
|
176
|
+
normal: string;
|
|
177
|
+
operational: string;
|
|
178
|
+
mandatory: string;
|
|
179
|
+
};
|
|
180
|
+
TxDataRoots: {
|
|
181
|
+
dataRoot: string;
|
|
182
|
+
blobRoot: string;
|
|
183
|
+
bridgeRoot: string;
|
|
184
|
+
};
|
|
185
|
+
DataProof: {
|
|
186
|
+
roots: string;
|
|
187
|
+
proof: string;
|
|
188
|
+
numberOfLeaves: string;
|
|
189
|
+
leafIndex: string;
|
|
190
|
+
leaf: string;
|
|
191
|
+
};
|
|
192
|
+
ProofResponse: {
|
|
193
|
+
dataProof: string;
|
|
194
|
+
message: string;
|
|
195
|
+
};
|
|
196
|
+
AddressedMessage: {
|
|
197
|
+
message: string;
|
|
198
|
+
from: string;
|
|
199
|
+
to: string;
|
|
200
|
+
originDomain: string;
|
|
201
|
+
destinationDomain: string;
|
|
202
|
+
id: string;
|
|
203
|
+
};
|
|
204
|
+
Message: {
|
|
205
|
+
_enum: {
|
|
206
|
+
ArbitraryMessage: string;
|
|
207
|
+
FungibleToken: string;
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
FungibleToken: {
|
|
211
|
+
assetId: string;
|
|
212
|
+
amount: string;
|
|
213
|
+
};
|
|
214
|
+
BoundedData: string;
|
|
215
|
+
ArbitraryMessage: string;
|
|
216
|
+
Cell: {
|
|
217
|
+
row: string;
|
|
218
|
+
col: string;
|
|
219
|
+
};
|
|
220
|
+
GRawScalar: string;
|
|
221
|
+
GProof: string;
|
|
222
|
+
GRow: string;
|
|
223
|
+
GDataProof: string;
|
|
224
|
+
};
|
|
225
|
+
declare const DEFAULT_COMPUTE_PAYLOAD: {
|
|
226
|
+
compute: {
|
|
227
|
+
da_type: number;
|
|
228
|
+
verification: number;
|
|
229
|
+
compute: number;
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
declare const DEFAULT_EMPTY_PAYLOAD: {
|
|
233
|
+
compute: {
|
|
234
|
+
da_type: number;
|
|
235
|
+
verification: number;
|
|
236
|
+
compute: number;
|
|
237
|
+
agreement: never[];
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
declare const API_EXTENSIONS: {
|
|
241
|
+
CheckAppId: {
|
|
242
|
+
extrinsic: {
|
|
243
|
+
appId: string;
|
|
244
|
+
};
|
|
245
|
+
payload: {};
|
|
246
|
+
};
|
|
247
|
+
CheckCompute: {
|
|
248
|
+
extrinsic: {
|
|
249
|
+
compute: string;
|
|
250
|
+
};
|
|
251
|
+
payload: {};
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
type OnChainFileOptions = {
|
|
256
|
+
file: File;
|
|
257
|
+
filePath: string;
|
|
258
|
+
fileName: string;
|
|
259
|
+
description: string;
|
|
260
|
+
baseCost: bigint;
|
|
261
|
+
ownerL2Address: string;
|
|
262
|
+
guardianInfo: any;
|
|
263
|
+
};
|
|
264
|
+
declare class MCryptFs {
|
|
265
|
+
_api: any;
|
|
266
|
+
_init: boolean;
|
|
267
|
+
_metaRef: any;
|
|
268
|
+
_metadata: any;
|
|
269
|
+
_chunkRefs: any;
|
|
270
|
+
_startRef: any;
|
|
271
|
+
constructor(mcryptApi: any, metadataRef: any, metadata: any);
|
|
272
|
+
static dummyInstance(mcryptApi: any): MCryptFs;
|
|
273
|
+
isValid(): void;
|
|
274
|
+
getMetadata(): any;
|
|
275
|
+
}
|
|
276
|
+
declare class MCryptFsWriter {
|
|
277
|
+
_file: File;
|
|
278
|
+
_filePath: string;
|
|
279
|
+
_description: string;
|
|
280
|
+
_chunkSize: number;
|
|
281
|
+
_fileKey: string;
|
|
282
|
+
_fileName: string;
|
|
283
|
+
_baseCost: bigint;
|
|
284
|
+
_ownerL2Address: string;
|
|
285
|
+
_guardianInfo: any;
|
|
286
|
+
_api: any;
|
|
287
|
+
_account: any;
|
|
288
|
+
_chunkRefs: any[];
|
|
289
|
+
_blockNumber: number;
|
|
290
|
+
_extrinsicIndex: number;
|
|
291
|
+
_progress: {
|
|
292
|
+
iFileSize: number;
|
|
293
|
+
iBlocksWritten: number;
|
|
294
|
+
};
|
|
295
|
+
_error: any;
|
|
296
|
+
constructor(fileOptions: OnChainFileOptions, chunkSize: number | undefined, mcryptApi: any, account: any);
|
|
297
|
+
prependMetadata(chunk: any): Blob;
|
|
298
|
+
writeChunk(chunk: any): Promise<unknown>;
|
|
299
|
+
submitKey(account: any, data: any): Promise<{
|
|
300
|
+
blockNumber: any;
|
|
301
|
+
index: any;
|
|
302
|
+
hash: any;
|
|
303
|
+
tx_result: any;
|
|
304
|
+
}>;
|
|
305
|
+
writeMetadata(): Promise<{
|
|
306
|
+
blockNumber: any;
|
|
307
|
+
index: any;
|
|
308
|
+
hash: any;
|
|
309
|
+
tx_result: any;
|
|
310
|
+
}>;
|
|
311
|
+
writeFile(): Promise<MCryptFs>;
|
|
312
|
+
}
|
|
313
|
+
declare class MCryptFsReader {
|
|
314
|
+
_filename: string;
|
|
315
|
+
_api: any;
|
|
316
|
+
_onChainFile: any;
|
|
317
|
+
constructor(filename: string, mcryptApi: any, onChainFile: any);
|
|
318
|
+
downloadFile(): Promise<Blob>;
|
|
319
|
+
}
|
|
320
|
+
declare const FileFromMetadataRef: (mcryptApi: any, metadataRef: any) => Promise<MCryptFs>;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Module providing singleton access to Polkadot API, WebSocket provider, and keyring.
|
|
324
|
+
*
|
|
325
|
+
* This module ensures that only one instance of the WsProvider, ApiPromise and Keyring
|
|
326
|
+
* are created and reused across the application. It exposes a class-based wrapper
|
|
327
|
+
* (RpcApi) for managed connect/disconnect flows and convenience functions for directly
|
|
328
|
+
* obtaining the singleton instances.
|
|
329
|
+
*
|
|
330
|
+
* Notes:
|
|
331
|
+
* - The API is created with custom RPC, types and signed extensions provided by
|
|
332
|
+
* {@link API_RPC}, {@link API_TYPES} and {@link API_EXTENSIONS}.
|
|
333
|
+
* - In non-test environments, the module attaches fatal handlers to the API that call
|
|
334
|
+
* `process.exit(0)` on error/disconnect to allow an external supervisor to restart
|
|
335
|
+
* the process.
|
|
336
|
+
* - The keyring is created for `sr25519` keys. The convenience getter populates a
|
|
337
|
+
* default development account derived from the well-known dev URI `//Bob`
|
|
338
|
+
* (named "Bob default"). This is a development-only seed and MUST NOT be used
|
|
339
|
+
* in production.
|
|
340
|
+
*/
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Lightweight manager that holds and controls the lifecycle of the singleton
|
|
344
|
+
* WsProvider, ApiPromise and Keyring instances.
|
|
345
|
+
*
|
|
346
|
+
* @remarks
|
|
347
|
+
* - Instances are created lazily when {@link RpcApi.connect} is called.
|
|
348
|
+
* - The class maintains simple connection state via `isConnected`, `isConnecting`,
|
|
349
|
+
* and `error` fields so callers can inspect the status without directly
|
|
350
|
+
* interrogating the underlying API/provider.
|
|
351
|
+
* - Event handlers are attached to both the provider and the API to update `error`
|
|
352
|
+
* and `isConnected` appropriately when runtime errors or disconnects occur.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* const rpc = getRpcApi();
|
|
356
|
+
* await rpc.connect("wss://example.com");
|
|
357
|
+
* const { api, keyring } = await rpc.getApi();
|
|
358
|
+
*
|
|
359
|
+
* @public
|
|
360
|
+
*/
|
|
361
|
+
declare class RpcApi {
|
|
362
|
+
isConnected: boolean;
|
|
363
|
+
isConnecting: boolean;
|
|
364
|
+
error: string | null;
|
|
365
|
+
constructor();
|
|
366
|
+
/**
|
|
367
|
+
* Establishes a connection to a node at `endpoint` and returns the singleton
|
|
368
|
+
* API and Keyring instances.
|
|
369
|
+
*
|
|
370
|
+
* @param endpoint - WebSocket endpoint URL to connect to (e.g. "wss://...").
|
|
371
|
+
* @returns A promise resolving to an object containing the singleton {@link ApiPromise}
|
|
372
|
+
* instance and the singleton {@link Keyring} instance.
|
|
373
|
+
*
|
|
374
|
+
* @remarks
|
|
375
|
+
* - If a connection already exists (`isConnected === true`) the method returns
|
|
376
|
+
* the already-initialized instances without recreating them.
|
|
377
|
+
* - The method sets `isConnecting` to true while establishing the connection and
|
|
378
|
+
* clears it in a `finally` block.
|
|
379
|
+
* - Provider and API event listeners update the instance `error` and `isConnected`
|
|
380
|
+
* fields on runtime errors and disconnects.
|
|
381
|
+
* - The Keyring created here uses `sr25519` keys. If the standalone `getKeyring`
|
|
382
|
+
* helper is used elsewhere, it will additionally add a default development
|
|
383
|
+
* account derived from the well-known dev URI `//Bob` (named "Bob default").
|
|
384
|
+
*
|
|
385
|
+
* @throws Will re-throw underlying errors encountered while creating the provider
|
|
386
|
+
* or API. In that case `error` will contain the textual error message.
|
|
387
|
+
*/
|
|
388
|
+
connect(endpoint: string): Promise<{
|
|
389
|
+
api: ApiPromise | null;
|
|
390
|
+
keyring: Keyring | null;
|
|
391
|
+
}>;
|
|
392
|
+
/**
|
|
393
|
+
* Gracefully disconnects and nullifies the singleton API, provider and keyring
|
|
394
|
+
* instances managed by this RpcApi instance.
|
|
395
|
+
*
|
|
396
|
+
* @remarks
|
|
397
|
+
* - The method calls `api.disconnect()` and `wsProvider.disconnect()` if they
|
|
398
|
+
* exist, then sets the internal singletons to `null` and `isConnected` to false.
|
|
399
|
+
* - Any error during disconnect is captured in `error`.
|
|
400
|
+
*/
|
|
401
|
+
disconnect(): Promise<void>;
|
|
402
|
+
getApi(): ApiPromise | null;
|
|
403
|
+
getKeyring(): Keyring | null;
|
|
404
|
+
getEncKeyring(): Keyring | null;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* getApi()
|
|
408
|
+
*
|
|
409
|
+
* Returns the singleton {@link ApiPromise} instance, creating it if necessary.
|
|
410
|
+
*
|
|
411
|
+
* @remarks
|
|
412
|
+
* - If no underlying `provider` is configured (the module-level `provider`
|
|
413
|
+
* imported from "./wsProvider"), this function returns `undefined`.
|
|
414
|
+
* - When creating the API, the configured `rpc`, `types` and `signedExtensions`
|
|
415
|
+
* are applied.
|
|
416
|
+
* - In non-test environments, top-level API `error` and `disconnected` events
|
|
417
|
+
* cause the process to exit so that an external supervisor can restart the
|
|
418
|
+
* process.
|
|
419
|
+
*
|
|
420
|
+
* @returns The singleton {@link ApiPromise} instance (or `undefined` if no provider).
|
|
421
|
+
*/
|
|
422
|
+
declare function getApi(): Promise<ApiPromise | undefined>;
|
|
423
|
+
/**
|
|
424
|
+
* getKeyring()
|
|
425
|
+
*
|
|
426
|
+
* Returns the singleton {@link Keyring} instance, creating it if necessary.
|
|
427
|
+
*
|
|
428
|
+
* @remarks
|
|
429
|
+
* - Ensures {@link waitReady} has resolved before constructing the keyring so
|
|
430
|
+
* that WASM crypto is initialized.
|
|
431
|
+
* - The keyring is created with `type: "sr25519"`.
|
|
432
|
+
* - The function also adds a default development account from the dev seed URI
|
|
433
|
+
* `//Bob` and labels it "Bob default".
|
|
434
|
+
*
|
|
435
|
+
* @important
|
|
436
|
+
* The seed URI `//Bob` is a well-known development seed. It is convenient for
|
|
437
|
+
* local testing but is insecure for any real funds or production use. Replace
|
|
438
|
+
* or remove this default account when deploying to production.
|
|
439
|
+
*
|
|
440
|
+
* @returns The singleton {@link Keyring} instance.
|
|
441
|
+
*/
|
|
442
|
+
declare function getKeyring(): Promise<Keyring>;
|
|
443
|
+
/**
|
|
444
|
+
* getEncKeyring()
|
|
445
|
+
*
|
|
446
|
+
* Returns the singleton encryption-focused {@link Keyring} instance, creating it
|
|
447
|
+
* if necessary.
|
|
448
|
+
*
|
|
449
|
+
* @remarks
|
|
450
|
+
* - Ensures {@link waitReady} has resolved before constructing the keyring so
|
|
451
|
+
* that WASM crypto is initialized.
|
|
452
|
+
* - The keyring is created with `type: "sr25519"` and a development default
|
|
453
|
+
* account derived from the dev seed URI `//Bob` is added and labeled
|
|
454
|
+
* "Bob default (enc)".
|
|
455
|
+
*
|
|
456
|
+
* @important
|
|
457
|
+
* The seed URI `//Bob` is a well-known development seed and MUST NOT be used
|
|
458
|
+
* in production for real funds. Replace or remove this default when deploying
|
|
459
|
+
* to production.
|
|
460
|
+
*
|
|
461
|
+
* @returns The singleton {@link Keyring} instance used for encryption keys.
|
|
462
|
+
*/
|
|
463
|
+
declare function getEncKeyring(): Promise<Keyring>;
|
|
464
|
+
/**
|
|
465
|
+
* Returns the singleton {@link RpcApi} manager instance, creating it on first use.
|
|
466
|
+
*
|
|
467
|
+
* @returns The singleton {@link RpcApi}.
|
|
468
|
+
*/
|
|
469
|
+
declare function getRpcApi(): RpcApi;
|
|
470
|
+
|
|
471
|
+
declare const signAndSend: (request: any, account: any, opts?: {
|
|
472
|
+
compute: {
|
|
473
|
+
da_type: number;
|
|
474
|
+
verification: number;
|
|
475
|
+
compute: number;
|
|
476
|
+
};
|
|
477
|
+
}) => Promise<{
|
|
478
|
+
blockNumber: any;
|
|
479
|
+
index: any;
|
|
480
|
+
hash: any;
|
|
481
|
+
tx_result: any;
|
|
482
|
+
}>;
|
|
483
|
+
declare const getFileMetadataCall: (api: any, metadataRef: [number, number]) => Promise<any>;
|
|
484
|
+
declare const getGuardianAddress: () => Promise<{
|
|
485
|
+
peerid: string;
|
|
486
|
+
address: string;
|
|
487
|
+
}[]>;
|
|
488
|
+
declare const getGuardianNwParams: () => Promise<any>;
|
|
489
|
+
|
|
490
|
+
declare const provider: WsProvider;
|
|
491
|
+
|
|
492
|
+
declare function createAgreement(): Promise<void>;
|
|
493
|
+
|
|
494
|
+
declare function getGuardianParticipants(): Promise<any>;
|
|
495
|
+
|
|
496
|
+
declare const gen_stretched_key: (input: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
497
|
+
declare const gen_shared_key: (key: Uint8Array, pk: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
498
|
+
declare const encrypt$1: (plaintext: Uint8Array, key: Uint8Array) => {
|
|
499
|
+
ciphertext: Uint8Array<ArrayBufferLike>;
|
|
500
|
+
nonce: Uint8Array<ArrayBuffer>;
|
|
501
|
+
};
|
|
502
|
+
declare const decrypt: (ciphertext: Uint8Array, key: Uint8Array, nonce: Uint8Array) => Uint8Array<ArrayBufferLike> | null;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Summary of porting the Silent Threshold encryption scheme from Rust to JavaScript.
|
|
506
|
+
*
|
|
507
|
+
* The Silent Threshold encryption scheme is a threshold encryption scheme that uses BLS12-381 as the underlying elliptic curve.
|
|
508
|
+
* The scheme is based on the BLS signature scheme and uses the BLS pairing to encrypt and decrypt data.
|
|
509
|
+
*
|
|
510
|
+
* The types ported from the original Rust implementation are:
|
|
511
|
+
* - E::ScalarField -> BigInt
|
|
512
|
+
* - QuadExtField -> Fp2
|
|
513
|
+
* - CubicExtField -> Fp6
|
|
514
|
+
* - E::G1 -> ProjPointType<Fp>
|
|
515
|
+
* - E::G2 -> ProjPointType<Fp2>
|
|
516
|
+
* - PairingOutput -> ProjPointType<Fp12>
|
|
517
|
+
*/
|
|
518
|
+
/**
|
|
519
|
+
* @typedef {Object} PublicKey
|
|
520
|
+
* @property {number} id - The identifier for the public key.
|
|
521
|
+
* @property {ProjPointType<Fp>} bls_pk - The BLS public key.
|
|
522
|
+
* @property {ProjPointType<Fp>} sk_li - The secret key component li.
|
|
523
|
+
* @property {ProjPointType<Fp>} sk_li_minus0 - The secret key component li minus 0.
|
|
524
|
+
* @property {ProjPointType<Fp>} sk_li_x - The secret key component li x.
|
|
525
|
+
* @property {Array<ProjPointType<Fp>>} sk_li_lj_z - The secret key components li lj z.
|
|
526
|
+
*/
|
|
527
|
+
type PublicKey = {
|
|
528
|
+
id: number;
|
|
529
|
+
bls_pk: ProjPointType<Fp>;
|
|
530
|
+
sk_li: ProjPointType<Fp>;
|
|
531
|
+
sk_li_minus0: ProjPointType<Fp>;
|
|
532
|
+
sk_li_lj_z: Array<ProjPointType<Fp>>;
|
|
533
|
+
sk_li_x: ProjPointType<Fp>;
|
|
534
|
+
};
|
|
535
|
+
/**
|
|
536
|
+
* @typedef {Object} AggregateKey
|
|
537
|
+
* @property {Array<PublicKey>} pk - The array of public keys.
|
|
538
|
+
* @property {Array<ProjPointType<Fp>>} agg_sk_li_lj_z - The aggregated secret key components li lj z.
|
|
539
|
+
* @property {ProjPointType<Fp>} ask - The aggregated secret key.
|
|
540
|
+
* @property {ProjPointType<Fp2>} z_g2 - The z_g2 component.
|
|
541
|
+
* @property {ProjPointType<Fp2>} h_minus1 - The h_minus1 component.
|
|
542
|
+
* @property {PairingOutput} e_gh - The preprocessed pairing output.
|
|
543
|
+
*/
|
|
544
|
+
type AggregateKey = {
|
|
545
|
+
pk: Array<PublicKey>;
|
|
546
|
+
agg_sk_li_lj_z: Array<ProjPointType<Fp>>;
|
|
547
|
+
ask: ProjPointType<Fp>;
|
|
548
|
+
z_g2: ProjPointType<Fp2>;
|
|
549
|
+
h_minus1: ProjPointType<Fp2>;
|
|
550
|
+
e_gh: Fp12;
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* @typedef {Object} Ciphertext
|
|
554
|
+
* @property {ProjPointType<Fp2>} gamma_g2 - The gamma_g2 component.
|
|
555
|
+
* @property {Array<ProjPointType<Fp>>} sa1 - The sa1 components (2 elements).
|
|
556
|
+
* @property {Array<ProjPointType<Fp2>>} sa2 - The sa2 components (6 elements).
|
|
557
|
+
* @property {PairingOutput} enc_key - The encryption key.
|
|
558
|
+
* @property {number} t - The threshold value.
|
|
559
|
+
*/
|
|
560
|
+
type Ciphertext = {
|
|
561
|
+
gamma_g2: ProjPointType<Fp2>;
|
|
562
|
+
sa1: ProjPointType<Fp>[];
|
|
563
|
+
sa2: ProjPointType<Fp2>[];
|
|
564
|
+
enc_key: Fp12;
|
|
565
|
+
t: number;
|
|
566
|
+
};
|
|
567
|
+
/**
|
|
568
|
+
* @typedef {Object} PowersOfTau
|
|
569
|
+
* @property {ArrayLike<ProjPointType<Fp>>} powers_of_g - The powers of g.
|
|
570
|
+
* @property {ArrayLike<ProjPointType<Fp2>>} powers_of_h - The powers of h.
|
|
571
|
+
*/
|
|
572
|
+
type PowersOfTau = {
|
|
573
|
+
powers_of_g: ArrayLike<ProjPointType<Fp>>;
|
|
574
|
+
powers_of_h: ArrayLike<ProjPointType<Fp2>>;
|
|
575
|
+
};
|
|
576
|
+
/**
|
|
577
|
+
* Encrypts data using the provided parameters and aggregate public key.
|
|
578
|
+
*
|
|
579
|
+
* @param params - The PowersOfTau parameters containing powers of g and h.
|
|
580
|
+
* @param apk - The AggregateKey containing the aggregated public key and preprocessed values.
|
|
581
|
+
* @param t - The threshold value for encryption.
|
|
582
|
+
* @returns A Ciphertext object containing the encrypted data.
|
|
583
|
+
*/
|
|
584
|
+
declare const encrypt: (params: PowersOfTau, apk: AggregateKey, t: number) => {
|
|
585
|
+
gamma_g2: _noble_curves_abstract_weierstrass.WeierstrassPoint<Fp2>;
|
|
586
|
+
sa1: _noble_curves_abstract_weierstrass.WeierstrassPoint<bigint>[];
|
|
587
|
+
sa2: ProjPointType<Fp2>[];
|
|
588
|
+
enc_key: Fp12;
|
|
589
|
+
t: number;
|
|
590
|
+
};
|
|
591
|
+
/**
|
|
592
|
+
* Decodes a hex string into a PowersOfTau object.
|
|
593
|
+
*
|
|
594
|
+
* @param input - The hex string to decode.
|
|
595
|
+
* @returns A PowersOfTau object containing the decoded data.
|
|
596
|
+
*/
|
|
597
|
+
declare const decodePowersOfTau: (input: string) => PowersOfTau;
|
|
598
|
+
/**
|
|
599
|
+
* Decodes a hex string into an AggregateKey object.
|
|
600
|
+
*
|
|
601
|
+
* @param input - The hex string to decode.
|
|
602
|
+
* @returns An AggregateKey object containing the decoded data.
|
|
603
|
+
*/
|
|
604
|
+
declare const decodeAggregateKey: (input: string) => AggregateKey;
|
|
605
|
+
/**
|
|
606
|
+
* Encode a Ciphertext object into a hex string.
|
|
607
|
+
*
|
|
608
|
+
* @param input - The Ciphertext object to encode.
|
|
609
|
+
* @returns A hex string containing the encoded data.
|
|
610
|
+
*/
|
|
611
|
+
declare const encodeCiphertext: (input: Ciphertext) => string;
|
|
612
|
+
declare const testCrypt: (kzg: string, agg_key: string) => {
|
|
613
|
+
encoded: string;
|
|
614
|
+
ikm: string;
|
|
615
|
+
ciph: Ciphertext;
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Generates random bytes of the specified length.
|
|
620
|
+
* Uses Web Crypto API (crypto.getRandomValues) - available in all modern browsers
|
|
621
|
+
* and Node.js 18+.
|
|
622
|
+
*
|
|
623
|
+
* @param length Number of bytes.
|
|
624
|
+
* @returns Uint8Array containing random bytes.
|
|
625
|
+
*/
|
|
626
|
+
declare function generateRandomBytes(length?: number): Uint8Array;
|
|
627
|
+
|
|
628
|
+
interface OnChainRef {
|
|
629
|
+
blockNumber: number;
|
|
630
|
+
index: number;
|
|
631
|
+
}
|
|
632
|
+
interface GuardianGroupInfo {
|
|
633
|
+
groupId: string;
|
|
634
|
+
guardians: any[];
|
|
635
|
+
tauParams: string;
|
|
636
|
+
aggKey: string;
|
|
637
|
+
groupPk: string;
|
|
638
|
+
}
|
|
639
|
+
interface UploadOptions {
|
|
640
|
+
name: string;
|
|
641
|
+
description: string;
|
|
642
|
+
price: string;
|
|
643
|
+
type: "model" | "dataset" | "agent";
|
|
644
|
+
guardianGroupInfo: GuardianGroupInfo;
|
|
645
|
+
ref?: string;
|
|
646
|
+
filePath?: string;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
declare function writeMetadata(account: any, name: string, description: string, ref: OnChainRef, price: bigint, dataType: number, l2Owner: string, groupId: string): Promise<{
|
|
650
|
+
blockNumber: any;
|
|
651
|
+
index: any;
|
|
652
|
+
hash: any;
|
|
653
|
+
tx_result: any;
|
|
654
|
+
}>;
|
|
655
|
+
|
|
656
|
+
declare function submitData(account: any, data: string): Promise<void>;
|
|
657
|
+
declare function submitTEData(account: any, data: string, chosenGuardians: any[], tau_params: string, agg_key: string, group_pk: string): Promise<OnChainRef>;
|
|
658
|
+
|
|
659
|
+
declare function uploadData(options: UploadOptions): Promise<void>;
|
|
660
|
+
|
|
661
|
+
declare const getGuardianList: () => Promise<string[]>;
|
|
662
|
+
|
|
663
|
+
declare const createGuardianGroup: (account: any, selectedGuardians: any) => Promise<void>;
|
|
664
|
+
|
|
665
|
+
declare function joinGuardian(account: any, prefs: any): Promise<void>;
|
|
666
|
+
|
|
667
|
+
declare function addStake(account: any, amount: bigint): Promise<void>;
|
|
668
|
+
|
|
669
|
+
declare function joinIdleStaker(account: any): Promise<void>;
|
|
670
|
+
|
|
671
|
+
declare function newStake(account: any, amount: bigint, rewardDestination?: string): Promise<void>;
|
|
672
|
+
|
|
673
|
+
declare function payoutStake(account: any, eras: Array<number>, address?: string): Promise<void>;
|
|
674
|
+
|
|
675
|
+
declare function reduceStake(account: any, amount: bigint): Promise<void>;
|
|
676
|
+
|
|
677
|
+
declare function removeStake(account: any): Promise<void>;
|
|
678
|
+
|
|
679
|
+
declare function withdrawStake(account: any): Promise<void>;
|
|
680
|
+
|
|
681
|
+
declare function fundAccount(account: any, amount: bigint, address?: string): Promise<void>;
|
|
682
|
+
|
|
683
|
+
declare function transfer(account: any, amount: bigint, address: string): Promise<void>;
|
|
684
|
+
|
|
685
|
+
type Hex = `0x${string}`;
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Converts a token amount expressed in milliPALI into the smallest PALI denomination (10^-18 PALI) as a bigint.
|
|
689
|
+
*
|
|
690
|
+
* The function takes milliPALI denomination and returns the bigint value in the lowest denomination of the PALI token which is 10^-18.
|
|
691
|
+
*
|
|
692
|
+
* @param arg - The token amount to convert. Can be a string, number, or bigint representing an amount in milliPALI.
|
|
693
|
+
* @returns The token amount converted to the smallest PALI unit (10^-18 PALI) as a bigint.
|
|
694
|
+
*
|
|
695
|
+
* @example
|
|
696
|
+
* // 1 milliPALI => 10^15 lowest-denomination units
|
|
697
|
+
* tokenToBigint("1"); // => 1000000000000000n
|
|
698
|
+
*/
|
|
699
|
+
declare const tokenToBigint: (arg: string | number | bigint) => bigint;
|
|
700
|
+
/**
|
|
701
|
+
* Converts a hex string into a Uint8Array.
|
|
702
|
+
*
|
|
703
|
+
* @param hex - A hex-encoded string (must contain only hexadecimal characters, without any 0x prefix).
|
|
704
|
+
* @returns A Uint8Array containing the byte values represented by the hex string.
|
|
705
|
+
* @throws {Error} If the provided hex string has an odd length (invalid hex string).
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* hexToUint8Array("ff00a1"); // => Uint8Array [255, 0, 161]
|
|
709
|
+
*/
|
|
710
|
+
declare function hexToUint8Array(hex: Hex): Uint8Array<ArrayBuffer>;
|
|
711
|
+
/**
|
|
712
|
+
* Encodes a Uint8Array into a Base64 string using the browser btoa API.
|
|
713
|
+
*
|
|
714
|
+
* Note: This implementation builds a binary string via String.fromCharCode for each byte and then calls btoa.
|
|
715
|
+
* It is intended for browser environments where btoa is available. For very large arrays consider alternative approaches to avoid high memory usage.
|
|
716
|
+
*
|
|
717
|
+
* @param uint8Array - The bytes to encode as Base64.
|
|
718
|
+
* @returns A Base64-encoded string representing the input bytes.
|
|
719
|
+
*
|
|
720
|
+
* @example
|
|
721
|
+
* uint8ArrayToBase64(new Uint8Array([72, 101, 108, 108, 111])); // => "SGVsbG8="
|
|
722
|
+
*/
|
|
723
|
+
declare function uint8ArrayToBase64(uint8Array: Uint8Array): string;
|
|
724
|
+
/**
|
|
725
|
+
* Decodes a Base64 (or URL-safe Base64) string into a Uint8Array.
|
|
726
|
+
*
|
|
727
|
+
* This function normalizes URL-safe base64 by replacing '-' with '+' and '_' with '/', and it adds padding if missing
|
|
728
|
+
* before decoding with atob. Works in browser environments where atob is available.
|
|
729
|
+
*
|
|
730
|
+
* @param base64 - A Base64 or URL-safe Base64 encoded string.
|
|
731
|
+
* @returns The decoded bytes as a Uint8Array.
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* base64ToUint8Array("SGVsbG8="); // => Uint8Array [72, 101, 108, 108, 111]
|
|
735
|
+
*/
|
|
736
|
+
declare const base64ToUint8Array: (base64: string) => Uint8Array;
|
|
737
|
+
/**
|
|
738
|
+
* Decodes a Base64-encoded field into a Uint8Array and handles possible double-encoding.
|
|
739
|
+
*
|
|
740
|
+
* If expectedLength is provided and the decoded byte length does not match, this helper checks whether the decoded result
|
|
741
|
+
* is exactly twice the expected length. If so, it treats the decoded bytes as a UTF-8 string containing another Base64 value,
|
|
742
|
+
* decodes that second Base64 string, and returns it if it matches the expected length. Otherwise the initially decoded bytes are returned.
|
|
743
|
+
*
|
|
744
|
+
* @param field - The Base64 (or URL-safe Base64) encoded field to decode.
|
|
745
|
+
* @param expectedLength - Optional expected length of the final decoded byte array. When provided, enables the double-decoding heuristic.
|
|
746
|
+
* @returns The decoded bytes as a Uint8Array. If double-encoding is detected and validated, the inner decoded bytes are returned.
|
|
747
|
+
*
|
|
748
|
+
* @example
|
|
749
|
+
* // Single-encoded
|
|
750
|
+
* decodeField("SGVsbG8=", 5); // => Uint8Array [72, 101, 108, 108, 111]
|
|
751
|
+
*
|
|
752
|
+
* @example
|
|
753
|
+
* // Double-encoded: base64(base64(bytes))
|
|
754
|
+
* decodeField("U0dWc2JHOGU=", 5); // => Uint8Array [72, 101, 108, 108, 111]
|
|
755
|
+
*/
|
|
756
|
+
declare const decodeField: (field: string, expectedLength?: number) => Uint8Array;
|
|
757
|
+
/**
|
|
758
|
+
* Conditional debug logging utility.
|
|
759
|
+
* Only logs when DEBUG flag is enabled in config.
|
|
760
|
+
*
|
|
761
|
+
* @param message - The message to log
|
|
762
|
+
* @param optionalParams - Additional parameters to log
|
|
763
|
+
*/
|
|
764
|
+
declare const debugLog: (message?: any, ...optionalParams: any[]) => void;
|
|
765
|
+
|
|
766
|
+
interface TokenProperties {
|
|
767
|
+
symbol: string;
|
|
768
|
+
decimals: number;
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Fetch token name and decimals from RPC system properties
|
|
772
|
+
* Results are cached for subsequent calls
|
|
773
|
+
* @param rpc - RPC provider instance with system.properties method
|
|
774
|
+
* @returns Promise<TokenProperties> with symbol and decimals
|
|
775
|
+
*/
|
|
776
|
+
declare function fetchTokenProperties(): Promise<TokenProperties>;
|
|
777
|
+
/**
|
|
778
|
+
* Get cached token properties without making an RPC call
|
|
779
|
+
* @returns TokenProperties or null if not yet cached
|
|
780
|
+
*/
|
|
781
|
+
declare function getCachedTokenProperties(): TokenProperties | null;
|
|
782
|
+
/**
|
|
783
|
+
* Clear the token properties cache
|
|
784
|
+
*/
|
|
785
|
+
declare function clearTokenCache(): void;
|
|
786
|
+
/**
|
|
787
|
+
* Format balance using cached token properties
|
|
788
|
+
* @param balance - The balance value to format
|
|
789
|
+
* @returns Formatted balance string
|
|
790
|
+
*/
|
|
791
|
+
declare function formatBalanceWithTokenProperties(balance: string | number): Promise<string>;
|
|
792
|
+
|
|
793
|
+
declare function joinValidator(account: any, commission: number): Promise<void>;
|
|
794
|
+
|
|
795
|
+
declare let PALLIORA_WS: string;
|
|
796
|
+
declare let PALLIORA_RPC_URL: string;
|
|
797
|
+
declare let DEBUG: boolean;
|
|
798
|
+
declare let TX_WAIT_FINALIZATION: boolean;
|
|
799
|
+
declare function configure(opts: {
|
|
800
|
+
pallioraWs?: string;
|
|
801
|
+
pallioraRpcUrl?: string;
|
|
802
|
+
debug?: boolean;
|
|
803
|
+
txWaitFinalization?: boolean;
|
|
804
|
+
}): void;
|
|
805
|
+
|
|
806
|
+
declare function setIdentity(account: any, { display }: any): Promise<void>;
|
|
807
|
+
|
|
808
|
+
declare function rotateAndSetKeys(account: any): Promise<void>;
|
|
809
|
+
declare function setWorker(account: any): Promise<void>;
|
|
810
|
+
|
|
811
|
+
export { API_EXTENSIONS, API_RPC, API_TYPES, AccountSourceType, CryptoType, DEBUG, DEFAULT_COMPUTE_PAYLOAD, DEFAULT_EMPTY_PAYLOAD, FileFromMetadataRef, type GuardianGroupInfo, MCryptFs, MCryptFsReader, MCryptFsWriter, type OnChainRef, PALLIORA_RPC_URL, PALLIORA_WS, RpcApi, TX_WAIT_FINALIZATION, type UploadOptions, addStake, base64ToUint8Array, clearTokenCache, configure, createAccount, createAgreement, createGuardianGroup, debugLog, decodeAggregateKey, decodeField, decodePowersOfTau, decrypt, encrypt as ecncryptTest, encodeCiphertext, encrypt$1 as encrypt, fetchTokenProperties, formatBalanceWithTokenProperties, fundAccount, gen_shared_key, gen_stretched_key, generateRandomBytes, getApi, getCachedTokenProperties, getEncKeyring, getFileMetadataCall, getGuardianAddress, getGuardianList, getGuardianNwParams, getGuardianParticipants, getKeyring, getRpcApi, hexToUint8Array, joinGuardian, joinIdleStaker, joinValidator, newStake, pairFromPrivateKeyHex, payoutStake, provider, reduceStake, removeStake, rotateAndSetKeys, setIdentity, setWorker, signAndSend, submitData, submitTEData, testCrypt, tokenToBigint, transfer, uint8ArrayToBase64, uploadData, withdrawStake, writeMetadata };
|