@warganetwork/sdk 0.0.0-stage → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/LICENSE +21 -0
- package/README.md +189 -2
- package/assets/logo-transparent.png +0 -0
- package/assets/wrg-256.png +0 -0
- package/assets/wrg-token.png +0 -0
- package/dist/index.cjs +660 -0
- package/examples/escrow/lock-and-release.js +38 -0
- package/examples/foundry/foundry.toml +10 -0
- package/examples/hardhat/hardhat.config.js +41 -0
- package/examples/kyc-badge/check-and-mint-badge.js +35 -0
- package/examples/merchant-webhook/verify-webhook.js +29 -0
- package/examples/quantum/mldsa65-sign-and-verify.js +54 -0
- package/examples/swap/quote-and-swap.js +39 -0
- package/openapi/warga-public-api.yaml +233 -0
- package/package.json +74 -4
- package/src/abis/IDRToken.abi.json +530 -0
- package/src/abis/JPYToken.abi.json +530 -0
- package/src/abis/MerchantEscrow.abi.json +581 -0
- package/src/abis/MerchantKYCBadgeNFT.abi.json +697 -0
- package/src/abis/QuantumGuardVault.abi.json +326 -0
- package/src/abis/USDTToken.abi.json +530 -0
- package/src/abis/ValidatorRegistry.abi.json +239 -0
- package/src/abis/WargaCoin.abi.json +478 -0
- package/src/abis/WargaSwapV3Pool.abi.json +768 -0
- package/src/abis/WrgVault.abi.json +299 -0
- package/src/abis/index.js +35 -0
- package/src/helpers.js +124 -0
- package/src/index.d.ts +150 -0
- package/src/index.js +536 -0
- package/tokenlist/warga.tokenlist.json +55 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ABIS,
|
|
3
|
+
WargaCoinAbi,
|
|
4
|
+
WrgVaultAbi,
|
|
5
|
+
MerchantEscrowAbi,
|
|
6
|
+
ValidatorRegistryAbi,
|
|
7
|
+
MerchantKYCBadgeNFTAbi,
|
|
8
|
+
IDRTokenAbi,
|
|
9
|
+
USDTTokenAbi,
|
|
10
|
+
JPYTokenAbi,
|
|
11
|
+
WargaSwapV3PoolAbi,
|
|
12
|
+
QuantumGuardVaultAbi,
|
|
13
|
+
} from "./abis/index.js";
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
ABIS,
|
|
17
|
+
WargaCoinAbi,
|
|
18
|
+
WrgVaultAbi,
|
|
19
|
+
MerchantEscrowAbi,
|
|
20
|
+
ValidatorRegistryAbi,
|
|
21
|
+
MerchantKYCBadgeNFTAbi,
|
|
22
|
+
IDRTokenAbi,
|
|
23
|
+
USDTTokenAbi,
|
|
24
|
+
JPYTokenAbi,
|
|
25
|
+
WargaSwapV3PoolAbi,
|
|
26
|
+
QuantumGuardVaultAbi,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Warga Network Layer-1 Mainnet configuration (compatible with browsers, ethers v6, & viem).
|
|
31
|
+
*/
|
|
32
|
+
export const WARGA_MAINNET = Object.freeze({
|
|
33
|
+
id: 882026,
|
|
34
|
+
chainIdHex: "0xd756a",
|
|
35
|
+
name: "Warga Network Mainnet",
|
|
36
|
+
network: "warga-mainnet",
|
|
37
|
+
nativeCurrency: {
|
|
38
|
+
name: "WargaCoin",
|
|
39
|
+
symbol: "WRG",
|
|
40
|
+
decimals: 18,
|
|
41
|
+
},
|
|
42
|
+
rpcUrls: {
|
|
43
|
+
default: { http: ["https://warganetwork.org/rpc"] },
|
|
44
|
+
public: { http: ["https://warganetwork.org/rpc"] },
|
|
45
|
+
},
|
|
46
|
+
blockExplorers: {
|
|
47
|
+
default: {
|
|
48
|
+
name: "WargaScan",
|
|
49
|
+
url: "https://warganetwork.org/explorer",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
iconUrls: [
|
|
53
|
+
"https://warganetwork.org/wrg-token.png",
|
|
54
|
+
"https://warganetwork.org/wrg-256.png",
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Warga Network Public Testnet configuration.
|
|
60
|
+
*/
|
|
61
|
+
export const WARGA_TESTNET = Object.freeze({
|
|
62
|
+
id: 2027,
|
|
63
|
+
chainIdHex: "0x7eb",
|
|
64
|
+
name: "Warga Network Testnet",
|
|
65
|
+
network: "warga-testnet",
|
|
66
|
+
nativeCurrency: {
|
|
67
|
+
name: "Test WargaCoin",
|
|
68
|
+
symbol: "tWRG",
|
|
69
|
+
decimals: 18,
|
|
70
|
+
},
|
|
71
|
+
rpcUrls: {
|
|
72
|
+
default: { http: ["https://warganetwork.org/rpc/testnet"] },
|
|
73
|
+
public: { http: ["https://warganetwork.org/rpc/testnet"] },
|
|
74
|
+
},
|
|
75
|
+
blockExplorers: {
|
|
76
|
+
default: {
|
|
77
|
+
name: "WargaScan Testnet",
|
|
78
|
+
url: "https://warganetwork.org/explorer",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
testnet: true,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Verified live Warga Network L1 (Chain ID 882026) Vyper 0.4.3 contract addresses.
|
|
86
|
+
*/
|
|
87
|
+
export const CONTRACTS = Object.freeze({
|
|
88
|
+
WargaCoin: "0x71c7656ec7ab88b098defb751b7401b5f6d8976f",
|
|
89
|
+
WrgVault: "0xb59057f75ab910c587993d84a56da7c5b8442fdc",
|
|
90
|
+
MerchantEscrow: "0x8fab0a68e8f0722c20f1285c30fb97d735e575fe",
|
|
91
|
+
ValidatorRegistry: "0x069ccee0cb1fc3ee67eb0772188b1fdd1103df9e",
|
|
92
|
+
MerchantKYCBadgeNFT: "0x05c622c9664b2876e0dd69fcbb20f0aaef3becc1",
|
|
93
|
+
IDRToken: "0x4044b274536c7e4d371cfe47f9c3dd4d7811b26c",
|
|
94
|
+
USDTToken: "0x99ed79a6435be307d025d61831c8688b2a7ff7cb",
|
|
95
|
+
JPYToken: "0xbae92c718537c5e4eb8b230bc060af4a43450536",
|
|
96
|
+
WargaSwapV3Pool: "0xc6e96ec9b017e3c924e6a0332a89e839dffcbbe7",
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Structured error thrown by WargaClient on RPC / HTTP / timeout failures.
|
|
101
|
+
*/
|
|
102
|
+
export class WargaRpcError extends Error {
|
|
103
|
+
constructor(message, { code = null, method = null, status = null } = {}) {
|
|
104
|
+
super(message);
|
|
105
|
+
this.name = "WargaRpcError";
|
|
106
|
+
this.code = code;
|
|
107
|
+
this.method = method;
|
|
108
|
+
this.status = status;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const WEI_PER_WRG = 10n ** 18n;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Format wei (bigint, hex string, or decimal string) into human-readable WRG string.
|
|
116
|
+
*/
|
|
117
|
+
export function formatWrg(wei, maxDecimals = 6) {
|
|
118
|
+
const val = typeof wei === "bigint" ? wei : BigInt(wei);
|
|
119
|
+
const negative = val < 0n;
|
|
120
|
+
const abs = negative ? -val : val;
|
|
121
|
+
const whole = abs / WEI_PER_WRG;
|
|
122
|
+
const frac = abs % WEI_PER_WRG;
|
|
123
|
+
if (frac === 0n || maxDecimals <= 0) {
|
|
124
|
+
return `${negative ? "-" : ""}${whole.toString()}`;
|
|
125
|
+
}
|
|
126
|
+
const fracStr = frac.toString().padStart(18, "0").slice(0, maxDecimals).replace(/0+$/, "");
|
|
127
|
+
return fracStr ? `${negative ? "-" : ""}${whole.toString()}.${fracStr}` : `${negative ? "-" : ""}${whole.toString()}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Parse a decimal WRG amount (string or number) into exact wei bigint.
|
|
132
|
+
*/
|
|
133
|
+
export function parseWrg(amount) {
|
|
134
|
+
const str = String(amount).trim();
|
|
135
|
+
if (!/^\d+(\.\d+)?$/.test(str)) {
|
|
136
|
+
throw new Error(`Invalid WRG amount: ${amount}`);
|
|
137
|
+
}
|
|
138
|
+
const [wholePart, fracPart = ""] = str.split(".");
|
|
139
|
+
if (fracPart.length > 18) {
|
|
140
|
+
throw new Error(`WRG amount exceeds 18 decimals: ${amount}`);
|
|
141
|
+
}
|
|
142
|
+
return BigInt(wholePart) * WEI_PER_WRG + BigInt(fracPart.padEnd(18, "0"));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Validate a 20-byte hexadecimal EVM address.
|
|
147
|
+
*/
|
|
148
|
+
export function isValidAddress(address) {
|
|
149
|
+
return typeof address === "string" && /^0x[0-9a-fA-F]{40}$/.test(address);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Browser-native (WebCrypto SHA-256) helper to compute a QuantumGuardVault.vy anchor
|
|
154
|
+
* from a 32-byte+ secret preimage (string, 0x-hex, or Uint8Array). Zero Node.js imports!
|
|
155
|
+
*/
|
|
156
|
+
export async function computeQuantumAnchor(secretPreimage) {
|
|
157
|
+
if (!globalThis.crypto?.subtle) {
|
|
158
|
+
throw new Error("WebCrypto crypto.subtle is unavailable in this runtime.");
|
|
159
|
+
}
|
|
160
|
+
let bytes;
|
|
161
|
+
if (secretPreimage instanceof Uint8Array) {
|
|
162
|
+
bytes = secretPreimage;
|
|
163
|
+
} else if (typeof secretPreimage === "string" && /^0x[0-9a-fA-F]+$/.test(secretPreimage)) {
|
|
164
|
+
const clean = secretPreimage.slice(2);
|
|
165
|
+
if (clean.length % 2 !== 0) throw new Error("Invalid hex preimage length");
|
|
166
|
+
bytes = new Uint8Array(clean.length / 2);
|
|
167
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
168
|
+
bytes[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
bytes = new TextEncoder().encode(String(secretPreimage));
|
|
172
|
+
}
|
|
173
|
+
if (bytes.length < 32) {
|
|
174
|
+
throw new Error("Quantum preimage must be at least 32 bytes (256-bit entropy)");
|
|
175
|
+
}
|
|
176
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
177
|
+
return "0x" + Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Pure offline, zero-dependency transaction drainer / phishing heuristic scanner.
|
|
182
|
+
* Runs 100% locally in browser or Node.js with strict input schema validation (no backend required).
|
|
183
|
+
*/
|
|
184
|
+
export function scanTransactionLocal(tx) {
|
|
185
|
+
if (!tx || typeof tx !== "object") {
|
|
186
|
+
throw new Error("Transaction payload must be a non-null object");
|
|
187
|
+
}
|
|
188
|
+
if (tx.to !== undefined && tx.to !== null && !isValidAddress(tx.to)) {
|
|
189
|
+
throw new Error(`Invalid transaction recipient address: ${tx.to}`);
|
|
190
|
+
}
|
|
191
|
+
const rawData = String(tx.data ?? tx.input ?? "0x").trim();
|
|
192
|
+
if (!/^0x[0-9a-fA-F]*$/.test(rawData) || rawData.length % 2 !== 0) {
|
|
193
|
+
throw new Error("Invalid hex calldata in transaction payload");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const data = rawData.toLowerCase();
|
|
197
|
+
const reasons = [];
|
|
198
|
+
let riskLevel = "LOW";
|
|
199
|
+
let drainerDetected = false;
|
|
200
|
+
|
|
201
|
+
// 1. Unlimited ERC-20 approve(address,uint256) selector: 0x095ea7b3
|
|
202
|
+
if (data.startsWith("0x095ea7b3") && data.length >= 138) {
|
|
203
|
+
const amountHex = data.slice(74, 138);
|
|
204
|
+
if (/^f{10,}/i.test(amountHex) || amountHex.includes("ffffffffffffffffffff")) {
|
|
205
|
+
riskLevel = "HIGH";
|
|
206
|
+
drainerDetected = true;
|
|
207
|
+
reasons.push("Unlimited ERC-20 allowance approval detected (approve max uint256)");
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 2. Full NFT collection control setApprovalForAll(address,bool) selector: 0xa22cb465
|
|
212
|
+
if (data.startsWith("0xa22cb465") && data.length >= 138) {
|
|
213
|
+
const approvedWord = data.slice(74, 138);
|
|
214
|
+
if (!/^0+$/.test(approvedWord)) {
|
|
215
|
+
riskLevel = "CRITICAL";
|
|
216
|
+
drainerDetected = true;
|
|
217
|
+
reasons.push("Full NFT collection operator approval detected (setApprovalForAll=true)");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// 3. Gasless ERC-2612 permit(...) selector: 0xd5054bfd
|
|
222
|
+
if (data.startsWith("0xd5054bfd")) {
|
|
223
|
+
if (riskLevel === "LOW") riskLevel = "MEDIUM";
|
|
224
|
+
reasons.push("ERC-2612 gasless permit signature detected — verify spender & deadline carefully");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 4. Known phishing domain keyword patterns
|
|
228
|
+
const origin = String(tx.origin ?? tx.domain ?? "").toLowerCase();
|
|
229
|
+
for (const kw of ["free-airdrop", "claim-gift", "bonus-wrg-drain", "login-metamask-verify", "recovery-phrase"]) {
|
|
230
|
+
if (origin.includes(kw)) {
|
|
231
|
+
riskLevel = "CRITICAL";
|
|
232
|
+
drainerDetected = true;
|
|
233
|
+
reasons.push(`Suspicious phishing origin pattern detected: ${kw}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
isSafe: !drainerDetected,
|
|
239
|
+
riskLevel,
|
|
240
|
+
drainerDetected,
|
|
241
|
+
reasons,
|
|
242
|
+
source: "local-offline",
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Pure zero-dependency JSON-RPC & Explorer REST client for Warga Network Layer-1.
|
|
248
|
+
* Browser-native (zero Node.js built-ins), works in Chrome/Safari/Firefox, Edge Workers, Deno, Bun, and Node >= 18.
|
|
249
|
+
*/
|
|
250
|
+
export class WargaClient {
|
|
251
|
+
constructor(options = {}) {
|
|
252
|
+
const net = options.testnet ? WARGA_TESTNET : WARGA_MAINNET;
|
|
253
|
+
this.rpcUrl = options.rpcUrl || net.rpcUrls.default.http[0];
|
|
254
|
+
this.fallbackRpcUrls = Array.isArray(options.fallbackRpcUrls)
|
|
255
|
+
? options.fallbackRpcUrls.filter(Boolean)
|
|
256
|
+
: options.testnet
|
|
257
|
+
? []
|
|
258
|
+
: ["https://warganetwork.org/rpc2", "https://umkmrumahan.com/rpc"];
|
|
259
|
+
this.apiBaseUrl = (options.apiBaseUrl || "https://warganetwork.org").replace(/\/+$/, "");
|
|
260
|
+
this.timeoutMs = options.timeoutMs || 10000;
|
|
261
|
+
this.retries = options.retries ?? 2;
|
|
262
|
+
this.retryDelayMs = options.retryDelayMs ?? 250;
|
|
263
|
+
this.fetchImpl = options.fetch || globalThis.fetch;
|
|
264
|
+
this._rpcId = 1;
|
|
265
|
+
if (typeof this.fetchImpl !== "function") {
|
|
266
|
+
throw new Error("Fetch API is unavailable. Use a modern browser, Node.js >= 18, or pass options.fetch.");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async _fetchWithRetry(url, init, methodLabel) {
|
|
271
|
+
let lastErr;
|
|
272
|
+
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
|
273
|
+
const controller = new AbortController();
|
|
274
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
275
|
+
try {
|
|
276
|
+
const res = await this.fetchImpl(url, { ...init, signal: controller.signal });
|
|
277
|
+
if (res.ok) return res;
|
|
278
|
+
const transient = res.status === 429 || res.status >= 500;
|
|
279
|
+
lastErr = new WargaRpcError(`HTTP ${res.status} on ${methodLabel}`, { status: res.status, method: methodLabel });
|
|
280
|
+
if (!transient || attempt === this.retries) throw lastErr;
|
|
281
|
+
} catch (err) {
|
|
282
|
+
if (err instanceof WargaRpcError) {
|
|
283
|
+
lastErr = err;
|
|
284
|
+
if (!err.status || (err.status !== 429 && err.status < 500) || attempt === this.retries) throw err;
|
|
285
|
+
} else if (err && err.name === "AbortError") {
|
|
286
|
+
lastErr = new WargaRpcError(`RPC timeout after ${this.timeoutMs}ms on ${methodLabel}`, { code: "ETIMEDOUT", method: methodLabel });
|
|
287
|
+
if (attempt === this.retries) throw lastErr;
|
|
288
|
+
} else {
|
|
289
|
+
lastErr = new WargaRpcError(err?.message || `Network error on ${methodLabel}`, { method: methodLabel });
|
|
290
|
+
if (attempt === this.retries) throw lastErr;
|
|
291
|
+
}
|
|
292
|
+
} finally {
|
|
293
|
+
clearTimeout(timer);
|
|
294
|
+
}
|
|
295
|
+
await new Promise((r) => setTimeout(r, this.retryDelayMs * (attempt + 1)));
|
|
296
|
+
}
|
|
297
|
+
throw lastErr;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async rpc(method, params = []) {
|
|
301
|
+
const endpoints = [this.rpcUrl, ...this.fallbackRpcUrls.filter((u) => u !== this.rpcUrl)];
|
|
302
|
+
const payload = JSON.stringify({
|
|
303
|
+
jsonrpc: "2.0",
|
|
304
|
+
id: this._rpcId++,
|
|
305
|
+
method,
|
|
306
|
+
params,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
let lastErr;
|
|
310
|
+
for (let i = 0; i < endpoints.length; i++) {
|
|
311
|
+
try {
|
|
312
|
+
const res = await this._fetchWithRetry(
|
|
313
|
+
endpoints[i],
|
|
314
|
+
{ method: "POST", headers: { "Content-Type": "application/json" }, body: payload },
|
|
315
|
+
method
|
|
316
|
+
);
|
|
317
|
+
const data = await res.json();
|
|
318
|
+
if (data.error) {
|
|
319
|
+
throw new WargaRpcError(data.error.message || `RPC error ${data.error.code}`, {
|
|
320
|
+
code: data.error.code,
|
|
321
|
+
method,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
return data.result;
|
|
325
|
+
} catch (err) {
|
|
326
|
+
lastErr = err;
|
|
327
|
+
// Deterministic JSON-RPC application error (e.g., -32601, revert) should NOT fail over
|
|
328
|
+
if (err instanceof WargaRpcError && typeof err.code === "number") {
|
|
329
|
+
throw err;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
throw lastErr;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Execute multiple JSON-RPC calls concurrently.
|
|
338
|
+
*/
|
|
339
|
+
async batchRpc(calls) {
|
|
340
|
+
if (!Array.isArray(calls) || calls.length === 0) return [];
|
|
341
|
+
return Promise.all(calls.map((c) => this.rpc(c.method, c.params || [])));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
async getTransactionCount(address, blockTag = "pending") {
|
|
345
|
+
if (!isValidAddress(address)) throw new Error(`Invalid EVM address: ${address}`);
|
|
346
|
+
const hex = await this.rpc("eth_getTransactionCount", [address, blockTag]);
|
|
347
|
+
return Number(BigInt(hex));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async estimateGas(txObject) {
|
|
351
|
+
if (!txObject || typeof txObject !== "object") throw new Error("txObject is required");
|
|
352
|
+
const hex = await this.rpc("eth_estimateGas", [txObject]);
|
|
353
|
+
return BigInt(hex);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async sendRawTransaction(signedTxHex) {
|
|
357
|
+
if (typeof signedTxHex !== "string" || !/^0x[0-9a-fA-F]+$/.test(signedTxHex)) {
|
|
358
|
+
throw new Error("signedTxHex must be a valid 0x-prefixed hex string");
|
|
359
|
+
}
|
|
360
|
+
return this.rpc("eth_sendRawTransaction", [signedTxHex]);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async getTransactionReceipt(txHash) {
|
|
364
|
+
if (typeof txHash !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(txHash)) {
|
|
365
|
+
throw new Error(`Invalid transaction hash: ${txHash}`);
|
|
366
|
+
}
|
|
367
|
+
return this.rpc("eth_getTransactionReceipt", [txHash]);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
async waitForTransaction(txHash, { timeoutMs = 30000, pollMs = 1500 } = {}) {
|
|
371
|
+
const deadline = Date.now() + timeoutMs;
|
|
372
|
+
while (Date.now() <= deadline) {
|
|
373
|
+
const receipt = await this.getTransactionReceipt(txHash);
|
|
374
|
+
if (receipt) return receipt;
|
|
375
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
376
|
+
}
|
|
377
|
+
throw new WargaRpcError(`Timed out waiting for transaction ${txHash}`, { code: "ETIMEDOUT", method: "eth_getTransactionReceipt" });
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async getLogs(filter = {}) {
|
|
381
|
+
return this.rpc("eth_getLogs", [filter]);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Browser-native event log poller (no WebSocket required). Returns an unsubscribe function.
|
|
386
|
+
*/
|
|
387
|
+
pollLogs(filter, onLogs, { intervalMs = 3000 } = {}) {
|
|
388
|
+
let active = true;
|
|
389
|
+
let lastBlock = null;
|
|
390
|
+
const tick = async () => {
|
|
391
|
+
if (!active) return;
|
|
392
|
+
try {
|
|
393
|
+
const current = await this.getBlockNumber();
|
|
394
|
+
const fromBlock = lastBlock === null ? current : lastBlock + 1;
|
|
395
|
+
if (fromBlock <= current) {
|
|
396
|
+
const logs = await this.getLogs({
|
|
397
|
+
...filter,
|
|
398
|
+
fromBlock: "0x" + fromBlock.toString(16),
|
|
399
|
+
toBlock: "0x" + current.toString(16),
|
|
400
|
+
});
|
|
401
|
+
if (Array.isArray(logs) && logs.length > 0) onLogs(logs);
|
|
402
|
+
lastBlock = current;
|
|
403
|
+
}
|
|
404
|
+
} catch (_) {
|
|
405
|
+
// Non-fatal polling retry on next tick
|
|
406
|
+
}
|
|
407
|
+
if (active) setTimeout(tick, intervalMs);
|
|
408
|
+
};
|
|
409
|
+
tick();
|
|
410
|
+
return () => {
|
|
411
|
+
active = false;
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
async getChainId() {
|
|
416
|
+
const hex = await this.rpc("eth_chainId");
|
|
417
|
+
return Number(BigInt(hex));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
async getBlockNumber() {
|
|
421
|
+
const hex = await this.rpc("eth_blockNumber");
|
|
422
|
+
return Number(BigInt(hex));
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
async getGasPrice() {
|
|
426
|
+
const hex = await this.rpc("eth_gasPrice");
|
|
427
|
+
return BigInt(hex);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
async getBalance(address, blockTag = "latest") {
|
|
431
|
+
if (!isValidAddress(address)) {
|
|
432
|
+
throw new Error(`Invalid EVM address: ${address}`);
|
|
433
|
+
}
|
|
434
|
+
const hex = await this.rpc("eth_getBalance", [address, blockTag]);
|
|
435
|
+
const wei = BigInt(hex);
|
|
436
|
+
return {
|
|
437
|
+
address,
|
|
438
|
+
wei,
|
|
439
|
+
wrg: formatWrg(wei),
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async lookupWallet(query) {
|
|
444
|
+
const res = await this.fetchImpl(
|
|
445
|
+
`${this.apiBaseUrl}/api/warganetwork/explorer/lookup?q=${encodeURIComponent(query)}`
|
|
446
|
+
);
|
|
447
|
+
if (!res.ok) {
|
|
448
|
+
throw new WargaRpcError(`Explorer lookup HTTP ${res.status}`, { status: res.status });
|
|
449
|
+
}
|
|
450
|
+
return res.json();
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
async getPqcStatus() {
|
|
454
|
+
const res = await this.fetchImpl(`${this.apiBaseUrl}/api/pqc/status`);
|
|
455
|
+
if (!res.ok) {
|
|
456
|
+
throw new WargaRpcError(`PQC status HTTP ${res.status}`, { status: res.status });
|
|
457
|
+
}
|
|
458
|
+
return res.json();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
async getPqcPubKey() {
|
|
462
|
+
const res = await this.fetchImpl(`${this.apiBaseUrl}/api/pqc/pubkey`);
|
|
463
|
+
if (!res.ok) {
|
|
464
|
+
throw new WargaRpcError(`PQC pubkey HTTP ${res.status}`, { status: res.status });
|
|
465
|
+
}
|
|
466
|
+
return res.json();
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async getPqcAttestation() {
|
|
470
|
+
const res = await this.fetchImpl(`${this.apiBaseUrl}/api/pqc/attestation`);
|
|
471
|
+
if (!res.ok) {
|
|
472
|
+
throw new WargaRpcError(`PQC attestation HTTP ${res.status}`, { status: res.status });
|
|
473
|
+
}
|
|
474
|
+
return res.json();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
async verifyMLDSA65(message, signatureHex, publicKeyHex = null) {
|
|
478
|
+
const res = await this.fetchImpl(`${this.apiBaseUrl}/api/pqc/verify`, {
|
|
479
|
+
method: "POST",
|
|
480
|
+
headers: { "Content-Type": "application/json" },
|
|
481
|
+
body: JSON.stringify({
|
|
482
|
+
message,
|
|
483
|
+
signature_hex: signatureHex,
|
|
484
|
+
...(publicKeyHex ? { public_key_hex: publicKeyHex } : {}),
|
|
485
|
+
}),
|
|
486
|
+
});
|
|
487
|
+
if (!res.ok) {
|
|
488
|
+
throw new WargaRpcError(`ML-DSA-65 verify HTTP ${res.status}`, { status: res.status });
|
|
489
|
+
}
|
|
490
|
+
return res.json();
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
async scanTransaction(txPayload, { localOnly = false } = {}) {
|
|
494
|
+
// Always validate schema & run deterministic offline scanner first (zero external trust!)
|
|
495
|
+
const localAnalysis = scanTransactionLocal(txPayload);
|
|
496
|
+
if (localOnly) {
|
|
497
|
+
return { success: true, analysis: localAnalysis };
|
|
498
|
+
}
|
|
499
|
+
try {
|
|
500
|
+
const res = await this.fetchImpl(`${this.apiBaseUrl}/api/pqc/scan-tx`, {
|
|
501
|
+
method: "POST",
|
|
502
|
+
headers: { "Content-Type": "application/json" },
|
|
503
|
+
body: JSON.stringify({
|
|
504
|
+
to: txPayload.to,
|
|
505
|
+
data: txPayload.data ?? txPayload.input ?? "0x",
|
|
506
|
+
...(txPayload.origin ? { origin: txPayload.origin } : {}),
|
|
507
|
+
}),
|
|
508
|
+
});
|
|
509
|
+
if (!res.ok) return { success: true, analysis: localAnalysis };
|
|
510
|
+
const remote = await res.json();
|
|
511
|
+
return {
|
|
512
|
+
success: true,
|
|
513
|
+
analysis: remote?.analysis?.drainerDetected ? remote.analysis : localAnalysis,
|
|
514
|
+
remote: remote?.analysis || null,
|
|
515
|
+
};
|
|
516
|
+
} catch (_) {
|
|
517
|
+
return { success: true, analysis: localAnalysis };
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
export { WargaEscrow, WargaPool, WargaKycBadge } from "./helpers.js";
|
|
523
|
+
|
|
524
|
+
export default {
|
|
525
|
+
WARGA_MAINNET,
|
|
526
|
+
WARGA_TESTNET,
|
|
527
|
+
CONTRACTS,
|
|
528
|
+
ABIS,
|
|
529
|
+
WargaClient,
|
|
530
|
+
WargaRpcError,
|
|
531
|
+
formatWrg,
|
|
532
|
+
parseWrg,
|
|
533
|
+
isValidAddress,
|
|
534
|
+
computeQuantumAnchor,
|
|
535
|
+
scanTransactionLocal,
|
|
536
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Warga Network Official Token List",
|
|
3
|
+
"timestamp": "2026-12-03T07:00:00.000Z",
|
|
4
|
+
"version": {
|
|
5
|
+
"major": 1,
|
|
6
|
+
"minor": 0,
|
|
7
|
+
"patch": 0
|
|
8
|
+
},
|
|
9
|
+
"logoURI": "https://warganetwork.org/wrg-256.png",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"warga-network",
|
|
12
|
+
"umkm",
|
|
13
|
+
"indonesia",
|
|
14
|
+
"vyper",
|
|
15
|
+
"l1"
|
|
16
|
+
],
|
|
17
|
+
"tokens": [
|
|
18
|
+
{
|
|
19
|
+
"chainId": 882026,
|
|
20
|
+
"address": "0x71c7656ec7ab88b098defb751b7401b5f6d8976f",
|
|
21
|
+
"name": "Warga Coin",
|
|
22
|
+
"symbol": "WRG",
|
|
23
|
+
"decimals": 18,
|
|
24
|
+
"logoURI": "https://warganetwork.org/wrg-256.png",
|
|
25
|
+
"tags": ["native-wrapper", "fixed-genesis-supply"]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"chainId": 882026,
|
|
29
|
+
"address": "0x4044b274536c7e4d371cfe47f9c3dd4d7811b26c",
|
|
30
|
+
"name": "Warga Rupiah",
|
|
31
|
+
"symbol": "IDR",
|
|
32
|
+
"decimals": 18,
|
|
33
|
+
"logoURI": "https://warganetwork.org/wrg-256.png",
|
|
34
|
+
"tags": ["custodial-settlement"]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"chainId": 882026,
|
|
38
|
+
"address": "0x99ed79a6435be307d025d61831c8688b2a7ff7cb",
|
|
39
|
+
"name": "Warga USD Settlement",
|
|
40
|
+
"symbol": "USDT",
|
|
41
|
+
"decimals": 18,
|
|
42
|
+
"logoURI": "https://warganetwork.org/wrg-256.png",
|
|
43
|
+
"tags": ["custodial-settlement"]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"chainId": 882026,
|
|
47
|
+
"address": "0xbae92c718537c5e4eb8b230bc060af4a43450536",
|
|
48
|
+
"name": "Warga Yen Settlement",
|
|
49
|
+
"symbol": "JPY",
|
|
50
|
+
"decimals": 18,
|
|
51
|
+
"logoURI": "https://warganetwork.org/wrg-256.png",
|
|
52
|
+
"tags": ["custodial-settlement"]
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|