@orbinum/sdk 0.2.0 → 0.3.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 +1137 -70
- package/dist/index.d.ts +1137 -70
- package/dist/index.js +75 -0
- package/dist/index.mjs +72 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(index_exports, {
|
|
|
23
23
|
AccountMappingModule: () => AccountMappingModule,
|
|
24
24
|
AccountMappingPrecompile: () => AccountMappingPrecompile,
|
|
25
25
|
ChainModule: () => ChainModule,
|
|
26
|
+
CircuitId: () => CircuitId,
|
|
26
27
|
CryptoPrecompiles: () => CryptoPrecompiles,
|
|
27
28
|
EncryptedMemo: () => EncryptedMemo,
|
|
28
29
|
EvmClient: () => EvmClient,
|
|
@@ -54,6 +55,8 @@ __export(index_exports, {
|
|
|
54
55
|
evmAddressToAccountId: () => evmAddressToAccountId,
|
|
55
56
|
evmToImplicitSubstrate: () => evmToImplicitSubstrate,
|
|
56
57
|
evmToSubstrate: () => evmToSubstrate,
|
|
58
|
+
formatBalance: () => formatBalance,
|
|
59
|
+
formatORB: () => formatORB,
|
|
57
60
|
fromHex: () => fromHex,
|
|
58
61
|
getPolkadotSigner: () => import_signer.getPolkadotSigner,
|
|
59
62
|
getPolkadotSignerFromPjs: () => import_pjs_signer.getPolkadotSignerFromPjs,
|
|
@@ -2389,9 +2392,78 @@ async function decryptJson(key, iv, ciphertext) {
|
|
|
2389
2392
|
return JSON.parse(new TextDecoder().decode(plainBuf), vaultReviver);
|
|
2390
2393
|
}
|
|
2391
2394
|
|
|
2395
|
+
// src/utils/format.ts
|
|
2396
|
+
var LOCALE_DECIMAL_SEP = new Intl.NumberFormat(void 0).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
|
|
2397
|
+
function formatIntegerLocale(intPart) {
|
|
2398
|
+
try {
|
|
2399
|
+
return BigInt(intPart || "0").toLocaleString(void 0);
|
|
2400
|
+
} catch {
|
|
2401
|
+
return (intPart || "0").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
function normalizeDecimalForDisplay(raw, maxFractionDigits) {
|
|
2405
|
+
let value = raw.trim();
|
|
2406
|
+
if (!value) return null;
|
|
2407
|
+
let sign = "";
|
|
2408
|
+
if (value.startsWith("-")) {
|
|
2409
|
+
sign = "-";
|
|
2410
|
+
value = value.slice(1);
|
|
2411
|
+
}
|
|
2412
|
+
if (!/^\d*(\.\d*)?$/.test(value)) return null;
|
|
2413
|
+
let [integerPart = "0", fractionPart = ""] = value.split(".");
|
|
2414
|
+
integerPart = integerPart.replace(/^0+(?=\d)/, "") || "0";
|
|
2415
|
+
const limit = Math.max(0, maxFractionDigits);
|
|
2416
|
+
fractionPart = fractionPart.slice(0, limit).replace(/0+$/, "");
|
|
2417
|
+
const formattedInt = formatIntegerLocale(integerPart);
|
|
2418
|
+
return fractionPart ? `${sign}${formattedInt}${LOCALE_DECIMAL_SEP}${fractionPart}` : `${sign}${formattedInt}`;
|
|
2419
|
+
}
|
|
2420
|
+
function bigintFormatUnits(value, decimals) {
|
|
2421
|
+
const negative = value < 0n;
|
|
2422
|
+
const abs = negative ? -value : value;
|
|
2423
|
+
const divider = 10n ** BigInt(decimals);
|
|
2424
|
+
const intPart = abs / divider;
|
|
2425
|
+
const fracPart = abs % divider;
|
|
2426
|
+
const fracStr = fracPart.toString().padStart(decimals, "0");
|
|
2427
|
+
return (negative ? "-" : "") + intPart.toString() + "." + fracStr;
|
|
2428
|
+
}
|
|
2429
|
+
function formatBalance(raw, options = {}) {
|
|
2430
|
+
const opts = typeof options === "number" ? { decimals: options } : options;
|
|
2431
|
+
const { decimals = 18, symbol = "ORB", showSymbol = true, precision = 6 } = opts;
|
|
2432
|
+
const zero = showSymbol ? `0 ${symbol}` : "0";
|
|
2433
|
+
if (raw === null || raw === void 0) return zero;
|
|
2434
|
+
const rawStr = String(raw).trim().replace(/,/g, "");
|
|
2435
|
+
if (!rawStr || rawStr === "0" || rawStr === "0x0") return zero;
|
|
2436
|
+
if (rawStr.includes(".") && !rawStr.startsWith("0x")) {
|
|
2437
|
+
const formatted = normalizeDecimalForDisplay(rawStr, precision);
|
|
2438
|
+
if (!formatted || formatted === "0" || formatted === "-0") return zero;
|
|
2439
|
+
return showSymbol ? `${formatted} ${symbol}` : formatted;
|
|
2440
|
+
}
|
|
2441
|
+
try {
|
|
2442
|
+
const n = BigInt(rawStr);
|
|
2443
|
+
const decimalStr = bigintFormatUnits(n, decimals);
|
|
2444
|
+
const formatted = normalizeDecimalForDisplay(decimalStr, precision);
|
|
2445
|
+
if (!formatted || formatted === "0" || formatted === "-0") return zero;
|
|
2446
|
+
return showSymbol ? `${formatted} ${symbol}` : formatted;
|
|
2447
|
+
} catch (e) {
|
|
2448
|
+
console.warn("[formatBalance] Failed to parse:", raw, e);
|
|
2449
|
+
return zero;
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
function formatORB(raw, precision = 6) {
|
|
2453
|
+
return formatBalance(raw, { decimals: 18, symbol: "ORB", showSymbol: true, precision });
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2392
2456
|
// src/types.ts
|
|
2393
2457
|
var SLIP0044_NAMESPACE = 2147483648;
|
|
2394
2458
|
|
|
2459
|
+
// src/types/pallet-extrinsics/zk-verifier.ts
|
|
2460
|
+
var CircuitId = {
|
|
2461
|
+
Transfer: 1,
|
|
2462
|
+
Unshield: 2,
|
|
2463
|
+
Disclosure: 3,
|
|
2464
|
+
PrivateLink: 4
|
|
2465
|
+
};
|
|
2466
|
+
|
|
2395
2467
|
// src/index.ts
|
|
2396
2468
|
var import_signer = require("polkadot-api/signer");
|
|
2397
2469
|
var import_pjs_signer = require("polkadot-api/pjs-signer");
|
|
@@ -2400,6 +2472,7 @@ var import_pjs_signer = require("polkadot-api/pjs-signer");
|
|
|
2400
2472
|
AccountMappingModule,
|
|
2401
2473
|
AccountMappingPrecompile,
|
|
2402
2474
|
ChainModule,
|
|
2475
|
+
CircuitId,
|
|
2403
2476
|
CryptoPrecompiles,
|
|
2404
2477
|
EncryptedMemo,
|
|
2405
2478
|
EvmClient,
|
|
@@ -2431,6 +2504,8 @@ var import_pjs_signer = require("polkadot-api/pjs-signer");
|
|
|
2431
2504
|
evmAddressToAccountId,
|
|
2432
2505
|
evmToImplicitSubstrate,
|
|
2433
2506
|
evmToSubstrate,
|
|
2507
|
+
formatBalance,
|
|
2508
|
+
formatORB,
|
|
2434
2509
|
fromHex,
|
|
2435
2510
|
getPolkadotSigner,
|
|
2436
2511
|
getPolkadotSignerFromPjs,
|
package/dist/index.mjs
CHANGED
|
@@ -2315,9 +2315,78 @@ async function decryptJson(key, iv, ciphertext) {
|
|
|
2315
2315
|
return JSON.parse(new TextDecoder().decode(plainBuf), vaultReviver);
|
|
2316
2316
|
}
|
|
2317
2317
|
|
|
2318
|
+
// src/utils/format.ts
|
|
2319
|
+
var LOCALE_DECIMAL_SEP = new Intl.NumberFormat(void 0).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
|
|
2320
|
+
function formatIntegerLocale(intPart) {
|
|
2321
|
+
try {
|
|
2322
|
+
return BigInt(intPart || "0").toLocaleString(void 0);
|
|
2323
|
+
} catch {
|
|
2324
|
+
return (intPart || "0").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
function normalizeDecimalForDisplay(raw, maxFractionDigits) {
|
|
2328
|
+
let value = raw.trim();
|
|
2329
|
+
if (!value) return null;
|
|
2330
|
+
let sign = "";
|
|
2331
|
+
if (value.startsWith("-")) {
|
|
2332
|
+
sign = "-";
|
|
2333
|
+
value = value.slice(1);
|
|
2334
|
+
}
|
|
2335
|
+
if (!/^\d*(\.\d*)?$/.test(value)) return null;
|
|
2336
|
+
let [integerPart = "0", fractionPart = ""] = value.split(".");
|
|
2337
|
+
integerPart = integerPart.replace(/^0+(?=\d)/, "") || "0";
|
|
2338
|
+
const limit = Math.max(0, maxFractionDigits);
|
|
2339
|
+
fractionPart = fractionPart.slice(0, limit).replace(/0+$/, "");
|
|
2340
|
+
const formattedInt = formatIntegerLocale(integerPart);
|
|
2341
|
+
return fractionPart ? `${sign}${formattedInt}${LOCALE_DECIMAL_SEP}${fractionPart}` : `${sign}${formattedInt}`;
|
|
2342
|
+
}
|
|
2343
|
+
function bigintFormatUnits(value, decimals) {
|
|
2344
|
+
const negative = value < 0n;
|
|
2345
|
+
const abs = negative ? -value : value;
|
|
2346
|
+
const divider = 10n ** BigInt(decimals);
|
|
2347
|
+
const intPart = abs / divider;
|
|
2348
|
+
const fracPart = abs % divider;
|
|
2349
|
+
const fracStr = fracPart.toString().padStart(decimals, "0");
|
|
2350
|
+
return (negative ? "-" : "") + intPart.toString() + "." + fracStr;
|
|
2351
|
+
}
|
|
2352
|
+
function formatBalance(raw, options = {}) {
|
|
2353
|
+
const opts = typeof options === "number" ? { decimals: options } : options;
|
|
2354
|
+
const { decimals = 18, symbol = "ORB", showSymbol = true, precision = 6 } = opts;
|
|
2355
|
+
const zero = showSymbol ? `0 ${symbol}` : "0";
|
|
2356
|
+
if (raw === null || raw === void 0) return zero;
|
|
2357
|
+
const rawStr = String(raw).trim().replace(/,/g, "");
|
|
2358
|
+
if (!rawStr || rawStr === "0" || rawStr === "0x0") return zero;
|
|
2359
|
+
if (rawStr.includes(".") && !rawStr.startsWith("0x")) {
|
|
2360
|
+
const formatted = normalizeDecimalForDisplay(rawStr, precision);
|
|
2361
|
+
if (!formatted || formatted === "0" || formatted === "-0") return zero;
|
|
2362
|
+
return showSymbol ? `${formatted} ${symbol}` : formatted;
|
|
2363
|
+
}
|
|
2364
|
+
try {
|
|
2365
|
+
const n = BigInt(rawStr);
|
|
2366
|
+
const decimalStr = bigintFormatUnits(n, decimals);
|
|
2367
|
+
const formatted = normalizeDecimalForDisplay(decimalStr, precision);
|
|
2368
|
+
if (!formatted || formatted === "0" || formatted === "-0") return zero;
|
|
2369
|
+
return showSymbol ? `${formatted} ${symbol}` : formatted;
|
|
2370
|
+
} catch (e) {
|
|
2371
|
+
console.warn("[formatBalance] Failed to parse:", raw, e);
|
|
2372
|
+
return zero;
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
function formatORB(raw, precision = 6) {
|
|
2376
|
+
return formatBalance(raw, { decimals: 18, symbol: "ORB", showSymbol: true, precision });
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2318
2379
|
// src/types.ts
|
|
2319
2380
|
var SLIP0044_NAMESPACE = 2147483648;
|
|
2320
2381
|
|
|
2382
|
+
// src/types/pallet-extrinsics/zk-verifier.ts
|
|
2383
|
+
var CircuitId = {
|
|
2384
|
+
Transfer: 1,
|
|
2385
|
+
Unshield: 2,
|
|
2386
|
+
Disclosure: 3,
|
|
2387
|
+
PrivateLink: 4
|
|
2388
|
+
};
|
|
2389
|
+
|
|
2321
2390
|
// src/index.ts
|
|
2322
2391
|
import { getPolkadotSigner } from "polkadot-api/signer";
|
|
2323
2392
|
import { getPolkadotSignerFromPjs } from "polkadot-api/pjs-signer";
|
|
@@ -2325,6 +2394,7 @@ export {
|
|
|
2325
2394
|
AccountMappingModule,
|
|
2326
2395
|
AccountMappingPrecompile,
|
|
2327
2396
|
ChainModule,
|
|
2397
|
+
CircuitId,
|
|
2328
2398
|
CryptoPrecompiles,
|
|
2329
2399
|
EncryptedMemo,
|
|
2330
2400
|
EvmClient,
|
|
@@ -2356,6 +2426,8 @@ export {
|
|
|
2356
2426
|
evmAddressToAccountId,
|
|
2357
2427
|
evmToImplicitSubstrate,
|
|
2358
2428
|
evmToSubstrate,
|
|
2429
|
+
formatBalance,
|
|
2430
|
+
formatORB,
|
|
2359
2431
|
fromHex,
|
|
2360
2432
|
getPolkadotSigner,
|
|
2361
2433
|
getPolkadotSignerFromPjs,
|