@orbinum/sdk 0.1.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.js CHANGED
@@ -23,9 +23,11 @@ __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,
30
+ KNOWN_PRECOMPILES: () => KNOWN_PRECOMPILES,
29
31
  MerkleModule: () => MerkleModule,
30
32
  NoteBuilder: () => NoteBuilder,
31
33
  OrbinumClient: () => OrbinumClient,
@@ -53,9 +55,12 @@ __export(index_exports, {
53
55
  evmAddressToAccountId: () => evmAddressToAccountId,
54
56
  evmToImplicitSubstrate: () => evmToImplicitSubstrate,
55
57
  evmToSubstrate: () => evmToSubstrate,
58
+ formatBalance: () => formatBalance,
59
+ formatORB: () => formatORB,
56
60
  fromHex: () => fromHex,
57
61
  getPolkadotSigner: () => import_signer.getPolkadotSigner,
58
62
  getPolkadotSignerFromPjs: () => import_pjs_signer.getPolkadotSignerFromPjs,
63
+ getPrecompileLabel: () => getPrecompileLabel,
59
64
  implicitSubstrateToEvm: () => implicitSubstrateToEvm,
60
65
  isEvmAddress: () => isEvmAddress,
61
66
  isImplicitEvmAccount: () => isImplicitEvmAccount,
@@ -1581,6 +1586,57 @@ var SP_SEL = {
1581
1586
  // unshield(bytes,bytes32,bytes32,uint32,uint256,bytes32) → 0xdcf1bff2
1582
1587
  UNSHIELD: new Uint8Array([220, 241, 191, 242])
1583
1588
  };
1589
+ var KNOWN_PRECOMPILES = {
1590
+ // ── Ethereum standard (EIP) ─────────────────────────────────────────────
1591
+ "0x0000000000000000000000000000000000000001": {
1592
+ name: "ECRecover",
1593
+ functions: { "00000000": "ecrecover(bytes32,uint8,bytes32,bytes32)" }
1594
+ },
1595
+ "0x0000000000000000000000000000000000000002": { name: "SHA256", functions: {} },
1596
+ "0x0000000000000000000000000000000000000003": { name: "RIPEMD160", functions: {} },
1597
+ "0x0000000000000000000000000000000000000004": { name: "Identity", functions: {} },
1598
+ "0x0000000000000000000000000000000000000005": { name: "ModExp", functions: {} },
1599
+ // ── Frontier / non-standard ─────────────────────────────────────────────
1600
+ "0x0000000000000000000000000000000000000400": { name: "SHA3FIPS256", functions: {} },
1601
+ "0x0000000000000000000000000000000000000401": { name: "ECRecoverPublicKey", functions: {} },
1602
+ "0x0000000000000000000000000000000000000402": { name: "Curve25519Add", functions: {} },
1603
+ "0x0000000000000000000000000000000000000403": { name: "Curve25519ScalarMul", functions: {} },
1604
+ // ── Orbinum custom ───────────────────────────────────────────────────────
1605
+ "0x0000000000000000000000000000000000000800": {
1606
+ name: "AccountMapping",
1607
+ functions: {
1608
+ d03149ab: "resolveAlias(string)",
1609
+ "7a0ed62c": "getAliasOf(address)",
1610
+ "47e05c6c": "hasPrivateLink(string,bytes32)",
1611
+ dca49d0e: "mapAccount()",
1612
+ "08f57367": "unmapAccount()",
1613
+ "7fac359e": "releaseAlias()",
1614
+ "4d023ab9": "cancelSale()",
1615
+ "2f8839c3": "registerAlias(string)",
1616
+ "5ac998e7": "transferAlias(address)",
1617
+ "1625df3a": "buyAlias(string)",
1618
+ "32091192": "putAliasOnSale(uint256,address[])",
1619
+ "6f579c0c": "removeChainLink(uint32)",
1620
+ "5f3e837c": "addChainLink(uint32,bytes,bytes)",
1621
+ c04e98f4: "registerPrivateLink(uint32,bytes32)",
1622
+ dfd8b57e: "removePrivateLink(bytes32)",
1623
+ "4df1f33d": "revealPrivateLink(bytes32,bytes,bytes32,bytes)",
1624
+ "776cf9ff": "setAccountMetadata(bytes,bytes,bytes)"
1625
+ }
1626
+ },
1627
+ "0x0000000000000000000000000000000000000801": {
1628
+ name: "ShieldedPool",
1629
+ functions: {
1630
+ "781442b9": "shield(uint32,uint256,bytes32,bytes)",
1631
+ dcd5b898: "privateTransfer(bytes,bytes32,bytes32[],bytes32[],bytes[])",
1632
+ dcf1bff2: "unshield(bytes,bytes32,bytes32,uint32,uint256,bytes32)"
1633
+ }
1634
+ }
1635
+ };
1636
+ function getPrecompileLabel(address) {
1637
+ if (!address) return null;
1638
+ return KNOWN_PRECOMPILES[address.toLowerCase()]?.name ?? null;
1639
+ }
1584
1640
 
1585
1641
  // src/precompiles/ShieldedPoolPrecompile.ts
1586
1642
  var ShieldedPoolPrecompile = class {
@@ -2336,9 +2392,78 @@ async function decryptJson(key, iv, ciphertext) {
2336
2392
  return JSON.parse(new TextDecoder().decode(plainBuf), vaultReviver);
2337
2393
  }
2338
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
+
2339
2456
  // src/types.ts
2340
2457
  var SLIP0044_NAMESPACE = 2147483648;
2341
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
+
2342
2467
  // src/index.ts
2343
2468
  var import_signer = require("polkadot-api/signer");
2344
2469
  var import_pjs_signer = require("polkadot-api/pjs-signer");
@@ -2347,9 +2472,11 @@ var import_pjs_signer = require("polkadot-api/pjs-signer");
2347
2472
  AccountMappingModule,
2348
2473
  AccountMappingPrecompile,
2349
2474
  ChainModule,
2475
+ CircuitId,
2350
2476
  CryptoPrecompiles,
2351
2477
  EncryptedMemo,
2352
2478
  EvmClient,
2479
+ KNOWN_PRECOMPILES,
2353
2480
  MerkleModule,
2354
2481
  NoteBuilder,
2355
2482
  OrbinumClient,
@@ -2377,9 +2504,12 @@ var import_pjs_signer = require("polkadot-api/pjs-signer");
2377
2504
  evmAddressToAccountId,
2378
2505
  evmToImplicitSubstrate,
2379
2506
  evmToSubstrate,
2507
+ formatBalance,
2508
+ formatORB,
2380
2509
  fromHex,
2381
2510
  getPolkadotSigner,
2382
2511
  getPolkadotSignerFromPjs,
2512
+ getPrecompileLabel,
2383
2513
  implicitSubstrateToEvm,
2384
2514
  isEvmAddress,
2385
2515
  isImplicitEvmAccount,
package/dist/index.mjs CHANGED
@@ -1509,6 +1509,57 @@ var SP_SEL = {
1509
1509
  // unshield(bytes,bytes32,bytes32,uint32,uint256,bytes32) → 0xdcf1bff2
1510
1510
  UNSHIELD: new Uint8Array([220, 241, 191, 242])
1511
1511
  };
1512
+ var KNOWN_PRECOMPILES = {
1513
+ // ── Ethereum standard (EIP) ─────────────────────────────────────────────
1514
+ "0x0000000000000000000000000000000000000001": {
1515
+ name: "ECRecover",
1516
+ functions: { "00000000": "ecrecover(bytes32,uint8,bytes32,bytes32)" }
1517
+ },
1518
+ "0x0000000000000000000000000000000000000002": { name: "SHA256", functions: {} },
1519
+ "0x0000000000000000000000000000000000000003": { name: "RIPEMD160", functions: {} },
1520
+ "0x0000000000000000000000000000000000000004": { name: "Identity", functions: {} },
1521
+ "0x0000000000000000000000000000000000000005": { name: "ModExp", functions: {} },
1522
+ // ── Frontier / non-standard ─────────────────────────────────────────────
1523
+ "0x0000000000000000000000000000000000000400": { name: "SHA3FIPS256", functions: {} },
1524
+ "0x0000000000000000000000000000000000000401": { name: "ECRecoverPublicKey", functions: {} },
1525
+ "0x0000000000000000000000000000000000000402": { name: "Curve25519Add", functions: {} },
1526
+ "0x0000000000000000000000000000000000000403": { name: "Curve25519ScalarMul", functions: {} },
1527
+ // ── Orbinum custom ───────────────────────────────────────────────────────
1528
+ "0x0000000000000000000000000000000000000800": {
1529
+ name: "AccountMapping",
1530
+ functions: {
1531
+ d03149ab: "resolveAlias(string)",
1532
+ "7a0ed62c": "getAliasOf(address)",
1533
+ "47e05c6c": "hasPrivateLink(string,bytes32)",
1534
+ dca49d0e: "mapAccount()",
1535
+ "08f57367": "unmapAccount()",
1536
+ "7fac359e": "releaseAlias()",
1537
+ "4d023ab9": "cancelSale()",
1538
+ "2f8839c3": "registerAlias(string)",
1539
+ "5ac998e7": "transferAlias(address)",
1540
+ "1625df3a": "buyAlias(string)",
1541
+ "32091192": "putAliasOnSale(uint256,address[])",
1542
+ "6f579c0c": "removeChainLink(uint32)",
1543
+ "5f3e837c": "addChainLink(uint32,bytes,bytes)",
1544
+ c04e98f4: "registerPrivateLink(uint32,bytes32)",
1545
+ dfd8b57e: "removePrivateLink(bytes32)",
1546
+ "4df1f33d": "revealPrivateLink(bytes32,bytes,bytes32,bytes)",
1547
+ "776cf9ff": "setAccountMetadata(bytes,bytes,bytes)"
1548
+ }
1549
+ },
1550
+ "0x0000000000000000000000000000000000000801": {
1551
+ name: "ShieldedPool",
1552
+ functions: {
1553
+ "781442b9": "shield(uint32,uint256,bytes32,bytes)",
1554
+ dcd5b898: "privateTransfer(bytes,bytes32,bytes32[],bytes32[],bytes[])",
1555
+ dcf1bff2: "unshield(bytes,bytes32,bytes32,uint32,uint256,bytes32)"
1556
+ }
1557
+ }
1558
+ };
1559
+ function getPrecompileLabel(address) {
1560
+ if (!address) return null;
1561
+ return KNOWN_PRECOMPILES[address.toLowerCase()]?.name ?? null;
1562
+ }
1512
1563
 
1513
1564
  // src/precompiles/ShieldedPoolPrecompile.ts
1514
1565
  var ShieldedPoolPrecompile = class {
@@ -2264,9 +2315,78 @@ async function decryptJson(key, iv, ciphertext) {
2264
2315
  return JSON.parse(new TextDecoder().decode(plainBuf), vaultReviver);
2265
2316
  }
2266
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
+
2267
2379
  // src/types.ts
2268
2380
  var SLIP0044_NAMESPACE = 2147483648;
2269
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
+
2270
2390
  // src/index.ts
2271
2391
  import { getPolkadotSigner } from "polkadot-api/signer";
2272
2392
  import { getPolkadotSignerFromPjs } from "polkadot-api/pjs-signer";
@@ -2274,9 +2394,11 @@ export {
2274
2394
  AccountMappingModule,
2275
2395
  AccountMappingPrecompile,
2276
2396
  ChainModule,
2397
+ CircuitId,
2277
2398
  CryptoPrecompiles,
2278
2399
  EncryptedMemo,
2279
2400
  EvmClient,
2401
+ KNOWN_PRECOMPILES,
2280
2402
  MerkleModule,
2281
2403
  NoteBuilder,
2282
2404
  OrbinumClient,
@@ -2304,9 +2426,12 @@ export {
2304
2426
  evmAddressToAccountId,
2305
2427
  evmToImplicitSubstrate,
2306
2428
  evmToSubstrate,
2429
+ formatBalance,
2430
+ formatORB,
2307
2431
  fromHex,
2308
2432
  getPolkadotSigner,
2309
2433
  getPolkadotSignerFromPjs,
2434
+ getPrecompileLabel,
2310
2435
  implicitSubstrateToEvm,
2311
2436
  isEvmAddress,
2312
2437
  isImplicitEvmAccount,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbinum/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Official TypeScript SDK for Orbinum.",
5
5
  "author": "Orbinum",
6
6
  "license": "ISC",