@orbinum/sdk 0.12.0 → 0.14.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.d.mts +1 -532
- package/dist/index.d.ts +1 -532
- package/dist/index.js +62 -447
- package/dist/index.mjs +62 -446
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -41,18 +41,10 @@ var DEFAULT_MAX_RETRIES = 5;
|
|
|
41
41
|
var DEFAULT_BASE_BACKOFF_MS = 250;
|
|
42
42
|
var DEFAULT_MAX_BACKOFF_MS = 4e3;
|
|
43
43
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
44
|
-
async function
|
|
45
|
-
if (calls.length === 0) return [];
|
|
44
|
+
async function postJsonWithRetry(httpUrl, payload, options = {}) {
|
|
46
45
|
const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
47
46
|
const baseBackoffMs = options.baseBackoffMs ?? DEFAULT_BASE_BACKOFF_MS;
|
|
48
47
|
const maxBackoffMs = options.maxBackoffMs ?? DEFAULT_MAX_BACKOFF_MS;
|
|
49
|
-
const body = calls.map((c, i) => ({
|
|
50
|
-
id: i,
|
|
51
|
-
jsonrpc: "2.0",
|
|
52
|
-
method: c.method,
|
|
53
|
-
params: c.params ?? []
|
|
54
|
-
}));
|
|
55
|
-
const payload = JSON.stringify(body);
|
|
56
48
|
let attempt = 0;
|
|
57
49
|
for (; ; ) {
|
|
58
50
|
const res = await fetch(httpUrl, {
|
|
@@ -60,21 +52,28 @@ async function jsonRpcBatch(httpUrl, calls, options = {}) {
|
|
|
60
52
|
headers: { "Content-Type": "application/json" },
|
|
61
53
|
body: payload
|
|
62
54
|
});
|
|
63
|
-
if (res.ok) {
|
|
64
|
-
const arr = await res.json();
|
|
65
|
-
const byId = new Map(arr.map((r) => [r.id, r]));
|
|
66
|
-
return calls.map((_, i) => byId.get(i)?.result ?? null);
|
|
67
|
-
}
|
|
68
55
|
const retryable = res.status === 429 || res.status === 503;
|
|
69
|
-
if (!retryable || attempt >= maxRetries)
|
|
70
|
-
throw new Error(`JSON-RPC HTTP ${res.status}: ${res.statusText}`);
|
|
71
|
-
}
|
|
56
|
+
if (!retryable || attempt >= maxRetries) return res;
|
|
72
57
|
const retryAfter = Number(res.headers.get("retry-after"));
|
|
73
58
|
const delayMs = Number.isFinite(retryAfter) && retryAfter > 0 ? retryAfter * 1e3 : Math.min(baseBackoffMs * 2 ** attempt, maxBackoffMs);
|
|
74
59
|
await sleep(delayMs);
|
|
75
60
|
attempt++;
|
|
76
61
|
}
|
|
77
62
|
}
|
|
63
|
+
async function jsonRpcBatch(httpUrl, calls, options = {}) {
|
|
64
|
+
if (calls.length === 0) return [];
|
|
65
|
+
const body = calls.map((c, i) => ({
|
|
66
|
+
id: i,
|
|
67
|
+
jsonrpc: "2.0",
|
|
68
|
+
method: c.method,
|
|
69
|
+
params: c.params ?? []
|
|
70
|
+
}));
|
|
71
|
+
const res = await postJsonWithRetry(httpUrl, JSON.stringify(body), options);
|
|
72
|
+
if (!res.ok) throw new Error(`JSON-RPC HTTP ${res.status}: ${res.statusText}`);
|
|
73
|
+
const arr = await res.json();
|
|
74
|
+
const byId = new Map(arr.map((r) => [r.id, r]));
|
|
75
|
+
return calls.map((_, i) => byId.get(i)?.result ?? null);
|
|
76
|
+
}
|
|
78
77
|
function wsUrlToHttp(wsUrl) {
|
|
79
78
|
if (wsUrl.startsWith("wss://")) return "https://" + wsUrl.slice("wss://".length);
|
|
80
79
|
if (wsUrl.startsWith("ws://")) return "http://" + wsUrl.slice("ws://".length);
|
|
@@ -98,15 +97,26 @@ var SubstrateClient = class _SubstrateClient {
|
|
|
98
97
|
static async connect(wsUrl, timeoutMs = 15e3) {
|
|
99
98
|
const provider = getWsProvider(wsUrl);
|
|
100
99
|
const papi = createClient(provider);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
let timer;
|
|
101
|
+
try {
|
|
102
|
+
await Promise.race([
|
|
103
|
+
papi._request("system_name", []),
|
|
104
|
+
new Promise((_, reject) => {
|
|
105
|
+
timer = setTimeout(
|
|
106
|
+
() => reject(new Error(`Connection timeout (${timeoutMs}ms) to ${wsUrl}`)),
|
|
107
|
+
timeoutMs
|
|
108
|
+
);
|
|
109
|
+
})
|
|
110
|
+
]);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
try {
|
|
113
|
+
papi.destroy();
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
116
|
+
throw err;
|
|
117
|
+
} finally {
|
|
118
|
+
clearTimeout(timer);
|
|
119
|
+
}
|
|
110
120
|
return new _SubstrateClient(papi, wsUrlToHttp(wsUrl));
|
|
111
121
|
}
|
|
112
122
|
/**
|
|
@@ -481,11 +491,10 @@ var EvmClient = class {
|
|
|
481
491
|
* Throws on HTTP errors, RPC-level errors, or a `null` result.
|
|
482
492
|
*/
|
|
483
493
|
async request(method, params = []) {
|
|
484
|
-
const res = await
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
});
|
|
494
|
+
const res = await postJsonWithRetry(
|
|
495
|
+
this.rpcUrl,
|
|
496
|
+
JSON.stringify({ id: 1, jsonrpc: "2.0", method, params })
|
|
497
|
+
);
|
|
489
498
|
if (!res.ok) throw new Error(`EVM HTTP ${res.status}: ${res.statusText}`);
|
|
490
499
|
const json = await res.json();
|
|
491
500
|
if (json.error) {
|
|
@@ -507,11 +516,7 @@ var EvmClient = class {
|
|
|
507
516
|
method: c.method,
|
|
508
517
|
params: c.params ?? []
|
|
509
518
|
}));
|
|
510
|
-
const res = await
|
|
511
|
-
method: "POST",
|
|
512
|
-
headers: { "Content-Type": "application/json" },
|
|
513
|
-
body: JSON.stringify(body)
|
|
514
|
-
});
|
|
519
|
+
const res = await postJsonWithRetry(this.rpcUrl, JSON.stringify(body));
|
|
515
520
|
if (!res.ok) throw new Error(`EVM HTTP ${res.status}: ${res.statusText}`);
|
|
516
521
|
const arr = await res.json();
|
|
517
522
|
arr.sort((a, b) => (a.id ?? 0) - (b.id ?? 0));
|
|
@@ -560,16 +565,15 @@ var EvmClient = class {
|
|
|
560
565
|
}
|
|
561
566
|
/** Returns a transaction receipt by hash, or `null` if the transaction has not been mined yet. */
|
|
562
567
|
async getTransactionReceipt(txHash) {
|
|
563
|
-
const res = await
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
body: JSON.stringify({
|
|
568
|
+
const res = await postJsonWithRetry(
|
|
569
|
+
this.rpcUrl,
|
|
570
|
+
JSON.stringify({
|
|
567
571
|
id: 1,
|
|
568
572
|
jsonrpc: "2.0",
|
|
569
573
|
method: "eth_getTransactionReceipt",
|
|
570
574
|
params: [txHash]
|
|
571
575
|
})
|
|
572
|
-
|
|
576
|
+
);
|
|
573
577
|
if (!res.ok) throw new Error(`EVM HTTP ${res.status}: ${res.statusText}`);
|
|
574
578
|
const json = await res.json();
|
|
575
579
|
if (json.error) {
|
|
@@ -1019,397 +1023,6 @@ var EvmExplorer = class _EvmExplorer {
|
|
|
1019
1023
|
}
|
|
1020
1024
|
};
|
|
1021
1025
|
|
|
1022
|
-
// src/indexer/IndexerClient.ts
|
|
1023
|
-
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
1024
|
-
function normalizeBaseUrl(baseUrl) {
|
|
1025
|
-
let url;
|
|
1026
|
-
try {
|
|
1027
|
-
url = new URL(baseUrl);
|
|
1028
|
-
} catch {
|
|
1029
|
-
throw new Error(`IndexerClient: invalid baseUrl ${JSON.stringify(baseUrl)}`);
|
|
1030
|
-
}
|
|
1031
|
-
const isLocal = LOCAL_HOSTS.has(url.hostname);
|
|
1032
|
-
if (url.protocol !== "https:" && !(url.protocol === "http:" && isLocal)) {
|
|
1033
|
-
throw new Error(
|
|
1034
|
-
`IndexerClient: baseUrl must use https:// (got ${url.protocol}//${url.hostname}). Plain http is only allowed for localhost.`
|
|
1035
|
-
);
|
|
1036
|
-
}
|
|
1037
|
-
return baseUrl.replace(/\/$/, "");
|
|
1038
|
-
}
|
|
1039
|
-
var IndexerClient = class _IndexerClient {
|
|
1040
|
-
baseUrl;
|
|
1041
|
-
timeoutMs;
|
|
1042
|
-
constructor(config) {
|
|
1043
|
-
this.baseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1044
|
-
this.timeoutMs = config.timeoutMs ?? 1e4;
|
|
1045
|
-
}
|
|
1046
|
-
// ─── Internal helpers ──────────────────────────────────────────────────────
|
|
1047
|
-
async _fetchResponse(path) {
|
|
1048
|
-
const controller = new AbortController();
|
|
1049
|
-
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
1050
|
-
try {
|
|
1051
|
-
return await fetch(`${this.baseUrl}${path}`, { signal: controller.signal });
|
|
1052
|
-
} finally {
|
|
1053
|
-
clearTimeout(timer);
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
async get(path) {
|
|
1057
|
-
const res = await this._fetchResponse(path);
|
|
1058
|
-
if (!res.ok) {
|
|
1059
|
-
throw new Error(`IndexerClient: HTTP ${res.status} for ${path}`);
|
|
1060
|
-
}
|
|
1061
|
-
return res.json();
|
|
1062
|
-
}
|
|
1063
|
-
async getOrNull(path) {
|
|
1064
|
-
const res = await this._fetchResponse(path);
|
|
1065
|
-
if (res.status === 404) return null;
|
|
1066
|
-
if (!res.ok) {
|
|
1067
|
-
throw new Error(`IndexerClient: HTTP ${res.status} for ${path}`);
|
|
1068
|
-
}
|
|
1069
|
-
return res.json();
|
|
1070
|
-
}
|
|
1071
|
-
buildQuery(params) {
|
|
1072
|
-
const entries = Object.entries(params).filter(([, v]) => v !== void 0);
|
|
1073
|
-
if (entries.length === 0) return "";
|
|
1074
|
-
const qs = entries.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`).join("&");
|
|
1075
|
-
return `?${qs}`;
|
|
1076
|
-
}
|
|
1077
|
-
// ─── Commitments ───────────────────────────────────────────────────────────
|
|
1078
|
-
/** Returns the total count of shielded commitments. */
|
|
1079
|
-
async getCommitmentsCount() {
|
|
1080
|
-
const res = await this.get("/shielded/commitments/count");
|
|
1081
|
-
return res.total;
|
|
1082
|
-
}
|
|
1083
|
-
/** Returns a paginated list of shielded commitments. */
|
|
1084
|
-
async getCommitments(params) {
|
|
1085
|
-
const qs = this.buildQuery({
|
|
1086
|
-
page: params?.page,
|
|
1087
|
-
limit: params?.limit,
|
|
1088
|
-
since_leaf_index: params?.sinceLeafIndex
|
|
1089
|
-
});
|
|
1090
|
-
return this.get(`/shielded/commitments${qs}`);
|
|
1091
|
-
}
|
|
1092
|
-
/** Returns a single commitment by its hex string, or null if not found. */
|
|
1093
|
-
async getCommitmentByHex(hex) {
|
|
1094
|
-
return this.getOrNull(
|
|
1095
|
-
`/shielded/commitments/${encodeURIComponent(hex)}`
|
|
1096
|
-
);
|
|
1097
|
-
}
|
|
1098
|
-
/**
|
|
1099
|
-
* Returns a paginated list of stealth scan hints ordered ascending by leafIndex.
|
|
1100
|
-
* Each hint contains only the fields required for ECDH triage and decryption:
|
|
1101
|
-
* leafIndex, commitmentHex, assetId, ephPkHex, encryptedMemo, circuitVersion.
|
|
1102
|
-
*
|
|
1103
|
-
* Use `sinceLeafIndex` for incremental scans (cursor = last seen leafIndex + 1).
|
|
1104
|
-
*/
|
|
1105
|
-
async getScanHints(params) {
|
|
1106
|
-
const qs = this.buildQuery({
|
|
1107
|
-
page: params?.page,
|
|
1108
|
-
limit: params?.limit,
|
|
1109
|
-
since_leaf_index: params?.sinceLeafIndex
|
|
1110
|
-
});
|
|
1111
|
-
return this.get(`/shielded/scan-hints${qs}`);
|
|
1112
|
-
}
|
|
1113
|
-
// ─── Nullifiers ────────────────────────────────────────────────────────────
|
|
1114
|
-
/** Returns a paginated list of spent nullifiers. */
|
|
1115
|
-
async getNullifiers(params) {
|
|
1116
|
-
const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
|
|
1117
|
-
return this.get(`/shielded/nullifiers${qs}`);
|
|
1118
|
-
}
|
|
1119
|
-
/** Returns the spent/unspent status of a nullifier. */
|
|
1120
|
-
async getNullifierStatus(hex) {
|
|
1121
|
-
return this.get(
|
|
1122
|
-
`/shielded/nullifier/${encodeURIComponent(hex)}/status`
|
|
1123
|
-
);
|
|
1124
|
-
}
|
|
1125
|
-
/**
|
|
1126
|
-
* Downloads the full spent nullifier set and returns it as a Set of lowercase hex strings.
|
|
1127
|
-
*
|
|
1128
|
-
* The server sees an identical GET request regardless of which notes the wallet holds —
|
|
1129
|
-
* the intersection is computed locally (PIR-A privacy model).
|
|
1130
|
-
*
|
|
1131
|
-
* Kept as the FALLBACK for readers that don't serve sealed chunks yet (and for
|
|
1132
|
-
* small sets). New integrations should prefer the incremental chunk flow:
|
|
1133
|
-
* `getNullifierManifest` → `getNullifierChunk` for missing chunks →
|
|
1134
|
-
* `getNullifierTail`, persisting the set locally between rescans.
|
|
1135
|
-
*/
|
|
1136
|
-
async getAllSpentNullifiers() {
|
|
1137
|
-
const res = await this.get("/shielded/nullifiers/all");
|
|
1138
|
-
return new Set(res.data.map((h) => h.toLowerCase()));
|
|
1139
|
-
}
|
|
1140
|
-
/**
|
|
1141
|
-
* Universal index of the sealed nullifier chunks — identical request and
|
|
1142
|
-
* response for every caller (no client-supplied position: PIR-A preserved).
|
|
1143
|
-
*
|
|
1144
|
-
* Returns `null` when the reader does not serve chunks yet (404) — the
|
|
1145
|
-
* caller should fall back to `getAllSpentNullifiers`.
|
|
1146
|
-
*/
|
|
1147
|
-
async getNullifierManifest() {
|
|
1148
|
-
return this.getOrNull("/shielded/nullifiers/manifest");
|
|
1149
|
-
}
|
|
1150
|
-
/**
|
|
1151
|
-
* One sealed, immutable chunk of the spent-nullifier set (ascending hex,
|
|
1152
|
-
* lowercased). The digest comes from the manifest and lives in the URL, so
|
|
1153
|
-
* a corrected chunk is a different URL — safe to cache forever client-side.
|
|
1154
|
-
*/
|
|
1155
|
-
async getNullifierChunk(idx, digest) {
|
|
1156
|
-
const res = await this.get(
|
|
1157
|
-
`/shielded/nullifiers/chunks/${idx}/${encodeURIComponent(digest)}`
|
|
1158
|
-
);
|
|
1159
|
-
return res.data.map((h) => h.toLowerCase());
|
|
1160
|
-
}
|
|
1161
|
-
/**
|
|
1162
|
-
* The mutable remainder of the nullifier set after the last sealed chunk.
|
|
1163
|
-
* Identical request for every caller (no input). `afterChunks` lets the
|
|
1164
|
-
* client detect a chunk sealed between its manifest fetch and this one.
|
|
1165
|
-
*/
|
|
1166
|
-
async getNullifierTail() {
|
|
1167
|
-
const res = await this.get("/shielded/nullifiers/tail");
|
|
1168
|
-
return { afterChunks: res.afterChunks, data: res.data.map((h) => h.toLowerCase()) };
|
|
1169
|
-
}
|
|
1170
|
-
// ─── Private transfers ─────────────────────────────────────────────────────
|
|
1171
|
-
/** Server-enforced max items per by-nullifiers / by-commitments request. */
|
|
1172
|
-
static TRANSFER_LOOKUP_CHUNK = 50;
|
|
1173
|
-
/**
|
|
1174
|
-
* Chunked fetch for the transfer timestamp lookups. The reader silently
|
|
1175
|
-
* truncates each request to 50 items, so larger inputs MUST be split or
|
|
1176
|
-
* results are silently lost. Responses are merged per extrinsic
|
|
1177
|
-
* (`blockNumber:extrinsicIndex`), concatenating the matched arrays, and
|
|
1178
|
-
* sorted by block descending.
|
|
1179
|
-
*
|
|
1180
|
-
* Privacy note: these lookups send the wallet's own note identifiers to
|
|
1181
|
-
* the indexer — a bounded, documented linkage tradeoff for timestamp
|
|
1182
|
-
* recovery. They are NEVER used for spent-STATUS checks (PIR-A: status
|
|
1183
|
-
* comes from the anonymous full-set `/shielded/nullifiers/all` download).
|
|
1184
|
-
*/
|
|
1185
|
-
async fetchTransfersChunked(path, param, items, matchedField) {
|
|
1186
|
-
if (items.length === 0) return [];
|
|
1187
|
-
const normalized = items.map((i) => i.toLowerCase());
|
|
1188
|
-
const chunks = [];
|
|
1189
|
-
for (let i = 0; i < normalized.length; i += _IndexerClient.TRANSFER_LOOKUP_CHUNK) {
|
|
1190
|
-
chunks.push(normalized.slice(i, i + _IndexerClient.TRANSFER_LOOKUP_CHUNK));
|
|
1191
|
-
}
|
|
1192
|
-
const responses = await Promise.all(
|
|
1193
|
-
chunks.map((chunk) => {
|
|
1194
|
-
const qs = this.buildQuery({ [param]: chunk.join(",") });
|
|
1195
|
-
return this.get(
|
|
1196
|
-
`${path}${qs}`
|
|
1197
|
-
);
|
|
1198
|
-
})
|
|
1199
|
-
);
|
|
1200
|
-
const byExtrinsic = /* @__PURE__ */ new Map();
|
|
1201
|
-
for (const res of responses) {
|
|
1202
|
-
for (const transfer of res.data) {
|
|
1203
|
-
const key = `${transfer.blockNumber}:${transfer.extrinsicIndex ?? "null"}`;
|
|
1204
|
-
const existing = byExtrinsic.get(key);
|
|
1205
|
-
if (!existing) {
|
|
1206
|
-
byExtrinsic.set(key, transfer);
|
|
1207
|
-
continue;
|
|
1208
|
-
}
|
|
1209
|
-
const merged = /* @__PURE__ */ new Set([
|
|
1210
|
-
...existing[matchedField] ?? [],
|
|
1211
|
-
...transfer[matchedField] ?? []
|
|
1212
|
-
]);
|
|
1213
|
-
existing[matchedField] = [...merged];
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
return [...byExtrinsic.values()].sort((a, b) => b.blockNumber - a.blockNumber);
|
|
1217
|
-
}
|
|
1218
|
-
/**
|
|
1219
|
-
* Returns temporal metadata for private transfers that spent any of the given nullifiers.
|
|
1220
|
-
* Only blockNumber, extrinsicIndex, timestampMs, and hash are returned — no cross-link
|
|
1221
|
-
* between inputs and outputs to prevent graph reconstruction.
|
|
1222
|
-
* Inputs of any size are transparently chunked into requests of 50 (the server cap)
|
|
1223
|
-
* and merged per extrinsic.
|
|
1224
|
-
*/
|
|
1225
|
-
async getTransfersByNullifiers(nullifiers) {
|
|
1226
|
-
return this.fetchTransfersChunked(
|
|
1227
|
-
"/shielded/transfers/by-nullifiers",
|
|
1228
|
-
"nullifiers",
|
|
1229
|
-
nullifiers,
|
|
1230
|
-
"matchedNullifiers"
|
|
1231
|
-
);
|
|
1232
|
-
}
|
|
1233
|
-
/**
|
|
1234
|
-
* Returns temporal metadata for private transfers that produced any of the given commitments.
|
|
1235
|
-
* Only blockNumber, extrinsicIndex, timestampMs, and hash are returned — no cross-link
|
|
1236
|
-
* between outputs and inputs to prevent graph reconstruction.
|
|
1237
|
-
* Inputs of any size are transparently chunked into requests of 50 (the server cap)
|
|
1238
|
-
* and merged per extrinsic.
|
|
1239
|
-
*/
|
|
1240
|
-
async getTransfersByCommitments(commitments) {
|
|
1241
|
-
return this.fetchTransfersChunked(
|
|
1242
|
-
"/shielded/transfers/by-commitments",
|
|
1243
|
-
"commitments",
|
|
1244
|
-
commitments,
|
|
1245
|
-
"matchedCommitments"
|
|
1246
|
-
);
|
|
1247
|
-
}
|
|
1248
|
-
// ─── Unshields ─────────────────────────────────────────────────────────────
|
|
1249
|
-
/** Returns a paginated list of unshield events. */
|
|
1250
|
-
async getUnshields(params) {
|
|
1251
|
-
const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
|
|
1252
|
-
return this.get(`/shielded/unshields${qs}`);
|
|
1253
|
-
}
|
|
1254
|
-
// ─── Merkle roots ──────────────────────────────────────────────────────────
|
|
1255
|
-
/** Returns a paginated list of Merkle root checkpoints. */
|
|
1256
|
-
async getMerkleRoots(params) {
|
|
1257
|
-
const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
|
|
1258
|
-
return this.get(`/shielded/merkle-roots${qs}`);
|
|
1259
|
-
}
|
|
1260
|
-
/** Returns the latest Merkle root, or null if none exists. */
|
|
1261
|
-
async getLatestMerkleRoot() {
|
|
1262
|
-
return this.getOrNull("/shielded/merkle-roots/latest");
|
|
1263
|
-
}
|
|
1264
|
-
// ─── Address activity ──────────────────────────────────────────────────────
|
|
1265
|
-
/** Returns a paginated list of extrinsics signed by the given address. */
|
|
1266
|
-
async getAddressExtrinsics(address, params) {
|
|
1267
|
-
const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
|
|
1268
|
-
return this.get(
|
|
1269
|
-
`/address/${encodeURIComponent(address.toLowerCase())}/extrinsics${qs}`
|
|
1270
|
-
);
|
|
1271
|
-
}
|
|
1272
|
-
/** Returns a paginated list of EVM transactions filtered by address and/or block number. */
|
|
1273
|
-
async getEvmTransactions(params) {
|
|
1274
|
-
const qs = this.buildQuery({
|
|
1275
|
-
page: params?.page,
|
|
1276
|
-
limit: params?.limit,
|
|
1277
|
-
address: params?.address?.toLowerCase(),
|
|
1278
|
-
blockNumber: params?.blockNumber
|
|
1279
|
-
});
|
|
1280
|
-
return this.get(`/evm/transactions${qs}`);
|
|
1281
|
-
}
|
|
1282
|
-
/** Returns a single EVM transaction by hash, or null if not found. */
|
|
1283
|
-
async getEvmTransactionByHash(hash) {
|
|
1284
|
-
return this.getOrNull(
|
|
1285
|
-
`/evm/transactions/${encodeURIComponent(hash.toLowerCase())}`
|
|
1286
|
-
);
|
|
1287
|
-
}
|
|
1288
|
-
// ─── Blocks ────────────────────────────────────────────────────────────────
|
|
1289
|
-
/** Returns a paginated list of indexed blocks. */
|
|
1290
|
-
async getBlocks(params) {
|
|
1291
|
-
const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
|
|
1292
|
-
return this.get(`/blocks${qs}`);
|
|
1293
|
-
}
|
|
1294
|
-
/** Returns a single block by number or hash, or null if not found. */
|
|
1295
|
-
async getBlock(numberOrHash) {
|
|
1296
|
-
return this.getOrNull(`/blocks/${encodeURIComponent(String(numberOrHash))}`);
|
|
1297
|
-
}
|
|
1298
|
-
// ─── Address-scoped shielded activity ─────────────────────────────────────
|
|
1299
|
-
/**
|
|
1300
|
-
* Returns a paginated list of unshield events where the given address is the recipient.
|
|
1301
|
-
* Accepts a 0x-prefixed EVM address or an SS58 Substrate address.
|
|
1302
|
-
*/
|
|
1303
|
-
async getAddressUnshields(address, params) {
|
|
1304
|
-
const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
|
|
1305
|
-
return this.get(
|
|
1306
|
-
`/address/${encodeURIComponent(address)}/unshields${qs}`
|
|
1307
|
-
);
|
|
1308
|
-
}
|
|
1309
|
-
/**
|
|
1310
|
-
* Returns the shielded-pool BOUNDARY activity for an address: shields it
|
|
1311
|
-
* deposited and unshields it received, tagged `kind: 'shield' | 'unshield'`.
|
|
1312
|
-
* Only boundary fields are returned (block, asset, amount for unshields,
|
|
1313
|
-
* timestamp, tx hash) — note internals are never served per-address, and
|
|
1314
|
-
* private transfers carry no address at all (PIR-A).
|
|
1315
|
-
*/
|
|
1316
|
-
async getAddressShieldedActivity(address, params) {
|
|
1317
|
-
const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
|
|
1318
|
-
return this.get(
|
|
1319
|
-
`/shielded/address/${encodeURIComponent(address)}${qs}`
|
|
1320
|
-
);
|
|
1321
|
-
}
|
|
1322
|
-
// ─── Relayers ──────────────────────────────────────────────────────────────
|
|
1323
|
-
/** Returns a paginated list of relayers. Filter by active status with `active`. */
|
|
1324
|
-
async getRelayers(params) {
|
|
1325
|
-
const qs = this.buildQuery({
|
|
1326
|
-
page: params?.page,
|
|
1327
|
-
limit: params?.limit,
|
|
1328
|
-
active: params?.active === void 0 ? void 0 : params.active ? "true" : "false"
|
|
1329
|
-
});
|
|
1330
|
-
return this.get(`/relayers${qs}`);
|
|
1331
|
-
}
|
|
1332
|
-
/** Returns a single relayer by EVM address, or null if not found. */
|
|
1333
|
-
async getRelayer(evmAddress) {
|
|
1334
|
-
return this.getOrNull(`/relayers/${encodeURIComponent(evmAddress.toLowerCase())}`);
|
|
1335
|
-
}
|
|
1336
|
-
/** Returns a paginated list of relay fee events. */
|
|
1337
|
-
async getRelayFees(params) {
|
|
1338
|
-
const qs = this.buildQuery({
|
|
1339
|
-
page: params?.page,
|
|
1340
|
-
limit: params?.limit,
|
|
1341
|
-
relayer: params?.relayer,
|
|
1342
|
-
type: params?.type
|
|
1343
|
-
});
|
|
1344
|
-
return this.get(`/relayers/fees${qs}`);
|
|
1345
|
-
}
|
|
1346
|
-
/** Returns aggregated relay fee balances per asset for a given relayer account. */
|
|
1347
|
-
async getRelayFeesSummary(relayer) {
|
|
1348
|
-
return this.get(
|
|
1349
|
-
`/relayers/fees/summary/${encodeURIComponent(relayer)}`
|
|
1350
|
-
);
|
|
1351
|
-
}
|
|
1352
|
-
// ─── Registered assets ─────────────────────────────────────────────────────
|
|
1353
|
-
/** Returns a paginated list of assets registered via register_asset. */
|
|
1354
|
-
async getRegisteredAssets(params) {
|
|
1355
|
-
const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
|
|
1356
|
-
return this.get(`/shielded/assets${qs}`);
|
|
1357
|
-
}
|
|
1358
|
-
/** Returns a single registered asset by its ID, or null if not found. */
|
|
1359
|
-
async getRegisteredAsset(assetId) {
|
|
1360
|
-
return this.getOrNull(`/shielded/assets/${encodeURIComponent(assetId)}`);
|
|
1361
|
-
}
|
|
1362
|
-
// ─── Validators ────────────────────────────────────────────────────────────
|
|
1363
|
-
/** Returns a paginated list of validators. Filter by lifecycle status with `status`. */
|
|
1364
|
-
async getValidators(params) {
|
|
1365
|
-
const qs = this.buildQuery({
|
|
1366
|
-
page: params?.page,
|
|
1367
|
-
limit: params?.limit,
|
|
1368
|
-
status: params?.status
|
|
1369
|
-
});
|
|
1370
|
-
return this.get(`/validators${qs}`);
|
|
1371
|
-
}
|
|
1372
|
-
/** Returns a single validator by account address, or null if not found. */
|
|
1373
|
-
async getValidator(account) {
|
|
1374
|
-
return this.getOrNull(`/validators/${encodeURIComponent(account)}`);
|
|
1375
|
-
}
|
|
1376
|
-
// ─── Sessions ──────────────────────────────────────────────────────────────
|
|
1377
|
-
/** Returns a paginated list of session rotations, ordered by most recent first. */
|
|
1378
|
-
async getSessions(params) {
|
|
1379
|
-
const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
|
|
1380
|
-
return this.get(`/sessions${qs}`);
|
|
1381
|
-
}
|
|
1382
|
-
// ─── Stats & Health ────────────────────────────────────────────────────────
|
|
1383
|
-
/** Returns aggregated indexer statistics. */
|
|
1384
|
-
async getStats() {
|
|
1385
|
-
return this.get("/stats");
|
|
1386
|
-
}
|
|
1387
|
-
/**
|
|
1388
|
-
* Returns transaction activity bucketed per hour over the last `hours` hours
|
|
1389
|
-
* of chain time (default 24, max 168). For sparklines / activity charts.
|
|
1390
|
-
*/
|
|
1391
|
-
async getActivity(hours = 24) {
|
|
1392
|
-
return this.get(`/stats/activity?hours=${hours}`);
|
|
1393
|
-
}
|
|
1394
|
-
/** Returns true if the indexer health endpoint responds OK. */
|
|
1395
|
-
async isHealthy() {
|
|
1396
|
-
try {
|
|
1397
|
-
const controller = new AbortController();
|
|
1398
|
-
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
1399
|
-
try {
|
|
1400
|
-
const res = await fetch(`${this.baseUrl}/health`, {
|
|
1401
|
-
signal: controller.signal
|
|
1402
|
-
});
|
|
1403
|
-
return res.ok;
|
|
1404
|
-
} finally {
|
|
1405
|
-
clearTimeout(timer);
|
|
1406
|
-
}
|
|
1407
|
-
} catch {
|
|
1408
|
-
return false;
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
};
|
|
1412
|
-
|
|
1413
1026
|
// src/shielded-pool/pallet/ShieldedPoolModule.ts
|
|
1414
1027
|
import "polkadot-api";
|
|
1415
1028
|
|
|
@@ -3511,12 +3124,6 @@ var OrbinumClient = class _OrbinumClient {
|
|
|
3511
3124
|
* `null` when `evmRpc` is not configured.
|
|
3512
3125
|
*/
|
|
3513
3126
|
evmExplorer;
|
|
3514
|
-
/**
|
|
3515
|
-
* HTTP client for the Orbinum indexer REST API.
|
|
3516
|
-
* Provides paginated access to indexed blocks, extrinsics, shielded events, and nullifiers.
|
|
3517
|
-
* `null` when `indexerUrl` is not configured.
|
|
3518
|
-
*/
|
|
3519
|
-
indexer;
|
|
3520
3127
|
/** Shielded-pool extrinsics and Merkle tree queries (`shield`, `unshield`, `privateTransfer`, …). */
|
|
3521
3128
|
shieldedPool;
|
|
3522
3129
|
/** Account-mapping extrinsics: aliases, chain links, metadata, marketplace, and identity. */
|
|
@@ -3540,11 +3147,10 @@ var OrbinumClient = class _OrbinumClient {
|
|
|
3540
3147
|
*/
|
|
3541
3148
|
precompiles;
|
|
3542
3149
|
/** @internal Use `OrbinumClient.connect()` to obtain an instance. */
|
|
3543
|
-
constructor(substrate, evm,
|
|
3150
|
+
constructor(substrate, evm, circuitsBaseUrl) {
|
|
3544
3151
|
this.substrate = substrate;
|
|
3545
3152
|
this.evm = evm;
|
|
3546
3153
|
this.evmExplorer = evm ? new EvmExplorer(evm) : null;
|
|
3547
|
-
this.indexer = indexer;
|
|
3548
3154
|
this.shieldedPool = new ShieldedPoolModule(substrate);
|
|
3549
3155
|
this.accountMapping = new AccountMappingModule(substrate);
|
|
3550
3156
|
this.privacy = new PrivacyModule(substrate);
|
|
@@ -3570,8 +3176,7 @@ var OrbinumClient = class _OrbinumClient {
|
|
|
3570
3176
|
config.connectTimeoutMs ?? 15e3
|
|
3571
3177
|
);
|
|
3572
3178
|
const evm = config.evmRpc ? new EvmClient(config.evmRpc) : null;
|
|
3573
|
-
|
|
3574
|
-
return new _OrbinumClient(substrate, evm, indexer, config.circuitsBaseUrl);
|
|
3179
|
+
return new _OrbinumClient(substrate, evm, config.circuitsBaseUrl);
|
|
3575
3180
|
}
|
|
3576
3181
|
/** Closes the underlying Substrate WebSocket connection and releases all resources. */
|
|
3577
3182
|
destroy() {
|
|
@@ -3687,15 +3292,16 @@ var OrbinumClientProvider = class {
|
|
|
3687
3292
|
this.connectTimeoutMs
|
|
3688
3293
|
);
|
|
3689
3294
|
});
|
|
3295
|
+
let clientPromise = null;
|
|
3690
3296
|
try {
|
|
3691
3297
|
const connectConfig = {
|
|
3692
|
-
substrateWs: this.config.substrateWs
|
|
3298
|
+
substrateWs: this.config.substrateWs,
|
|
3299
|
+
connectTimeoutMs: this.connectTimeoutMs
|
|
3693
3300
|
};
|
|
3694
3301
|
if (this.config.evmRpc) connectConfig.evmRpc = this.config.evmRpc;
|
|
3695
|
-
if (this.config.indexerUrl) connectConfig.indexerUrl = this.config.indexerUrl;
|
|
3696
3302
|
if (this.config.circuitsBaseUrl)
|
|
3697
3303
|
connectConfig.circuitsBaseUrl = this.config.circuitsBaseUrl;
|
|
3698
|
-
|
|
3304
|
+
clientPromise = OrbinumClient.connect(connectConfig);
|
|
3699
3305
|
const client = await Promise.race([clientPromise, timeoutPromise]);
|
|
3700
3306
|
orphanClient = client;
|
|
3701
3307
|
clearTimeout(timeoutId);
|
|
@@ -3713,6 +3319,17 @@ var OrbinumClientProvider = class {
|
|
|
3713
3319
|
orphanClient.destroy();
|
|
3714
3320
|
} catch {
|
|
3715
3321
|
}
|
|
3322
|
+
} else if (clientPromise) {
|
|
3323
|
+
clientPromise.then(
|
|
3324
|
+
(c) => {
|
|
3325
|
+
try {
|
|
3326
|
+
c.destroy();
|
|
3327
|
+
} catch {
|
|
3328
|
+
}
|
|
3329
|
+
},
|
|
3330
|
+
() => {
|
|
3331
|
+
}
|
|
3332
|
+
);
|
|
3716
3333
|
}
|
|
3717
3334
|
this._connectingPromise = null;
|
|
3718
3335
|
this.setStatus(
|
|
@@ -5536,7 +5153,6 @@ export {
|
|
|
5536
5153
|
EncryptedMemo,
|
|
5537
5154
|
EvmClient,
|
|
5538
5155
|
EvmExplorer,
|
|
5539
|
-
IndexerClient,
|
|
5540
5156
|
KNOWN_PRECOMPILES,
|
|
5541
5157
|
Keccak256,
|
|
5542
5158
|
NoteBuilder,
|