@moon-x/core 0.13.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/{chunk-QBEPYAYB.mjs → chunk-7UGU27T3.mjs} +246 -4
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/index.d.mts +38 -2
- package/dist/lib/index.d.ts +38 -2
- package/dist/lib/index.js +251 -4
- package/dist/lib/index.mjs +11 -1
- package/dist/react/index.d.mts +10 -6
- package/dist/react/index.d.ts +10 -6
- package/dist/react/index.js +8 -0
- package/dist/react/index.mjs +1 -1
- package/dist/react/tron.d.mts +16 -0
- package/dist/react/tron.d.ts +16 -0
- package/dist/react/tron.js +95 -0
- package/dist/react/tron.mjs +55 -0
- package/dist/sdk/index.d.mts +17 -5
- package/dist/sdk/index.d.ts +17 -5
- package/dist/sdk/index.js +141 -0
- package/dist/sdk/index.mjs +106 -1
- package/dist/types/index.d.mts +97 -7
- package/dist/types/index.d.ts +97 -7
- package/dist/types/index.mjs +1 -1
- package/package.json +6 -1
- /package/dist/{chunk-IMLBIIJ4.mjs → chunk-CEL3U6EI.mjs} +0 -0
package/dist/lib/index.js
CHANGED
|
@@ -38,11 +38,13 @@ __export(lib_exports, {
|
|
|
38
38
|
authState: () => authState,
|
|
39
39
|
broadcastEthereumRaw: () => broadcastEthereumRaw,
|
|
40
40
|
broadcastSolanaSigned: () => broadcastSolanaSigned,
|
|
41
|
+
broadcastTronSigned: () => broadcastTronSigned,
|
|
41
42
|
bs58ToBytes: () => bs58ToBytes,
|
|
42
43
|
buildChainIndex: () => buildChainIndex,
|
|
43
44
|
buildUrl: () => buildUrl,
|
|
44
45
|
canonicalAlgorithmFor: () => canonicalAlgorithmFor,
|
|
45
46
|
createManualSiweMessage: () => createManualSiweMessage,
|
|
47
|
+
decodeTronRawData: () => decodeTronRawData,
|
|
46
48
|
entryCaip2: () => entryCaip2,
|
|
47
49
|
estimateEvmGas: () => estimateEvmGas,
|
|
48
50
|
estimateEvmGasReserve: () => estimateEvmGasReserve,
|
|
@@ -59,6 +61,7 @@ __export(lib_exports, {
|
|
|
59
61
|
getTransferInfoFromInstructions: () => getTransferInfoFromInstructions,
|
|
60
62
|
isChainSupported: () => isChainSupported,
|
|
61
63
|
isEvmEntry: () => isEvmEntry,
|
|
64
|
+
isTronEntry: () => isTronEntry,
|
|
62
65
|
normalizeChainItem: () => normalizeChainItem,
|
|
63
66
|
normalizeChainKey: () => normalizeChainKey,
|
|
64
67
|
parseDerivationPath: () => parseDerivationPath,
|
|
@@ -70,10 +73,12 @@ __export(lib_exports, {
|
|
|
70
73
|
resolvePasskeyMetadata: () => resolvePasskeyMetadata,
|
|
71
74
|
resolveRpcUrl: () => resolveRpcUrl,
|
|
72
75
|
resolveSolanaChainEntry: () => resolveSolanaChainEntry,
|
|
76
|
+
resolveTronChainEntry: () => resolveTronChainEntry,
|
|
73
77
|
resolveWsUrl: () => resolveWsUrl,
|
|
74
78
|
sanitizeUserData: () => sanitizeUserData,
|
|
75
79
|
serializeEthereumTransaction: () => serializeEthereumTransaction,
|
|
76
80
|
toB64url: () => toB64url,
|
|
81
|
+
tronAddressFromPublicKey: () => tronAddressFromPublicKey,
|
|
77
82
|
validateChainConfig: () => validateChainConfig,
|
|
78
83
|
verifyIdToken: () => verifyIdToken
|
|
79
84
|
});
|
|
@@ -515,6 +520,9 @@ function isChainSupported(chains, chainId) {
|
|
|
515
520
|
function isEvmEntry(entry) {
|
|
516
521
|
return "chain" in entry;
|
|
517
522
|
}
|
|
523
|
+
function isTronEntry(entry) {
|
|
524
|
+
return !isEvmEntry(entry) && entry.id.split(":")[0].toLowerCase() === "tron";
|
|
525
|
+
}
|
|
518
526
|
function normalizeChainItem(item) {
|
|
519
527
|
if ("chain" in item) return item;
|
|
520
528
|
if (typeof item.id === "number") {
|
|
@@ -543,8 +551,14 @@ function aliasesFor(entry) {
|
|
|
543
551
|
}
|
|
544
552
|
} else {
|
|
545
553
|
keys.push(entry.id);
|
|
546
|
-
const cluster = entry.id.split(":")
|
|
547
|
-
if (cluster)
|
|
554
|
+
const [ns, cluster] = entry.id.split(":");
|
|
555
|
+
if (cluster) {
|
|
556
|
+
if (ns.toLowerCase() === "tron") {
|
|
557
|
+
keys.push(`tron:${cluster}`, `trx:${cluster}`);
|
|
558
|
+
} else {
|
|
559
|
+
keys.push(`solana:${cluster}`, `sol:${cluster}`, cluster);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
548
562
|
}
|
|
549
563
|
return keys;
|
|
550
564
|
}
|
|
@@ -583,10 +597,20 @@ function resolveSolanaChainEntry(chains, selector, defaultSelector) {
|
|
|
583
597
|
const asSolana = (k) => {
|
|
584
598
|
if (k == null) return void 0;
|
|
585
599
|
const e = index.byAlias.get(normalizeChainKey(k));
|
|
586
|
-
return e && !isEvmEntry(e) ? e : void 0;
|
|
600
|
+
return e && !isEvmEntry(e) && !isTronEntry(e) ? e : void 0;
|
|
587
601
|
};
|
|
588
602
|
if (selector != null) return asSolana(selector);
|
|
589
|
-
return asSolana(defaultSelector) ?? index.entries.find((e) => !isEvmEntry(e));
|
|
603
|
+
return asSolana(defaultSelector) ?? index.entries.find((e) => !isEvmEntry(e) && !isTronEntry(e));
|
|
604
|
+
}
|
|
605
|
+
function resolveTronChainEntry(chains, selector, defaultSelector) {
|
|
606
|
+
const index = buildChainIndex(chains ?? []);
|
|
607
|
+
const asTron = (k) => {
|
|
608
|
+
if (k == null) return void 0;
|
|
609
|
+
const e = index.byAlias.get(normalizeChainKey(k));
|
|
610
|
+
return e && isTronEntry(e) ? e : void 0;
|
|
611
|
+
};
|
|
612
|
+
if (selector != null) return asTron(selector);
|
|
613
|
+
return asTron(defaultSelector) ?? index.entries.find(isTronEntry);
|
|
590
614
|
}
|
|
591
615
|
function resolveEvmChainEntry(opts) {
|
|
592
616
|
const index = buildChainIndex(opts.chains ?? []);
|
|
@@ -1522,6 +1546,195 @@ async function getSOLTransfersFromInstructions(base64Transaction, logs, solPrice
|
|
|
1522
1546
|
return transfers;
|
|
1523
1547
|
}
|
|
1524
1548
|
|
|
1549
|
+
// src/lib/tron/tron-address.ts
|
|
1550
|
+
var import_secp256k1 = require("@noble/curves/secp256k1");
|
|
1551
|
+
var import_sha3 = require("@noble/hashes/sha3");
|
|
1552
|
+
var import_sha256 = require("@noble/hashes/sha256");
|
|
1553
|
+
async function tronAddressFromPublicKey(publicKeyHex) {
|
|
1554
|
+
const { default: bs58 } = await import("bs58");
|
|
1555
|
+
const clean = publicKeyHex.replace(/^0x/, "");
|
|
1556
|
+
const uncompressed = import_secp256k1.secp256k1.ProjectivePoint.fromHex(clean).toRawBytes(
|
|
1557
|
+
false
|
|
1558
|
+
);
|
|
1559
|
+
const hash = (0, import_sha3.keccak_256)(uncompressed.subarray(1));
|
|
1560
|
+
const payload = new Uint8Array(21);
|
|
1561
|
+
payload[0] = 65;
|
|
1562
|
+
payload.set(hash.subarray(12), 1);
|
|
1563
|
+
const checksum = (0, import_sha256.sha256)((0, import_sha256.sha256)(payload)).subarray(0, 4);
|
|
1564
|
+
const full = new Uint8Array(25);
|
|
1565
|
+
full.set(payload);
|
|
1566
|
+
full.set(checksum, 21);
|
|
1567
|
+
return bs58.encode(full);
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
// src/lib/tron/decode-raw-data.ts
|
|
1571
|
+
var import_sha2562 = require("@noble/hashes/sha256");
|
|
1572
|
+
function readVarint(buf, pos) {
|
|
1573
|
+
let result = BigInt(0);
|
|
1574
|
+
let shift = BigInt(0);
|
|
1575
|
+
for (; ; ) {
|
|
1576
|
+
const b = buf[pos++];
|
|
1577
|
+
if (b === void 0) throw new Error("truncated varint");
|
|
1578
|
+
result |= BigInt(b & 127) << shift;
|
|
1579
|
+
if ((b & 128) === 0) return [result, pos];
|
|
1580
|
+
shift += BigInt(7);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
function readFields(buf) {
|
|
1584
|
+
const fields = [];
|
|
1585
|
+
let pos = 0;
|
|
1586
|
+
while (pos < buf.length) {
|
|
1587
|
+
const [tag, p1] = readVarint(buf, pos);
|
|
1588
|
+
const num = Number(tag >> BigInt(3));
|
|
1589
|
+
const wire = Number(tag & BigInt(7));
|
|
1590
|
+
pos = p1;
|
|
1591
|
+
if (wire === 0) {
|
|
1592
|
+
const [v, p2] = readVarint(buf, pos);
|
|
1593
|
+
fields.push({ num, wire, varint: v });
|
|
1594
|
+
pos = p2;
|
|
1595
|
+
} else if (wire === 2) {
|
|
1596
|
+
const [len, p2] = readVarint(buf, pos);
|
|
1597
|
+
const end = p2 + Number(len);
|
|
1598
|
+
if (end > buf.length) throw new Error("truncated field");
|
|
1599
|
+
fields.push({ num, wire, bytes: buf.subarray(p2, end) });
|
|
1600
|
+
pos = end;
|
|
1601
|
+
} else if (wire === 5 || wire === 1) {
|
|
1602
|
+
const n = wire === 5 ? 4 : 8;
|
|
1603
|
+
if (pos + n > buf.length) throw new Error("truncated fixed field");
|
|
1604
|
+
fields.push({ num, wire, bytes: buf.subarray(pos, pos + n) });
|
|
1605
|
+
pos += n;
|
|
1606
|
+
} else {
|
|
1607
|
+
throw new Error(`unsupported wire type ${wire}`);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
return fields;
|
|
1611
|
+
}
|
|
1612
|
+
var toHex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
1613
|
+
async function addressFromBytes(b) {
|
|
1614
|
+
const { default: bs58 } = await import("bs58");
|
|
1615
|
+
const checksum = (0, import_sha2562.sha256)((0, import_sha2562.sha256)(b)).subarray(0, 4);
|
|
1616
|
+
const full = new Uint8Array(b.length + 4);
|
|
1617
|
+
full.set(b);
|
|
1618
|
+
full.set(checksum, b.length);
|
|
1619
|
+
return bs58.encode(full);
|
|
1620
|
+
}
|
|
1621
|
+
async function fieldValue(f, addressy) {
|
|
1622
|
+
if (f.wire === 0) return f.varint.toString();
|
|
1623
|
+
const b = f.bytes;
|
|
1624
|
+
if (addressy && b.length === 21 && b[0] === 65) return addressFromBytes(b);
|
|
1625
|
+
return toHex(b);
|
|
1626
|
+
}
|
|
1627
|
+
var CONTRACT_TYPES = {
|
|
1628
|
+
0: "AccountCreateContract",
|
|
1629
|
+
1: "TransferContract",
|
|
1630
|
+
2: "TransferAssetContract",
|
|
1631
|
+
4: "VoteWitnessContract",
|
|
1632
|
+
11: "FreezeBalanceContract",
|
|
1633
|
+
12: "UnfreezeBalanceContract",
|
|
1634
|
+
13: "WithdrawBalanceContract",
|
|
1635
|
+
31: "TriggerSmartContract",
|
|
1636
|
+
54: "FreezeBalanceV2Contract",
|
|
1637
|
+
55: "UnfreezeBalanceV2Contract",
|
|
1638
|
+
57: "DelegateResourceContract",
|
|
1639
|
+
58: "UnDelegateResourceContract"
|
|
1640
|
+
};
|
|
1641
|
+
var CONTRACT_FIELDS = {
|
|
1642
|
+
TransferContract: { 1: "owner_address", 2: "to_address", 3: "amount" },
|
|
1643
|
+
TransferAssetContract: {
|
|
1644
|
+
1: "asset_name",
|
|
1645
|
+
2: "owner_address",
|
|
1646
|
+
3: "to_address",
|
|
1647
|
+
4: "amount"
|
|
1648
|
+
},
|
|
1649
|
+
TriggerSmartContract: {
|
|
1650
|
+
1: "owner_address",
|
|
1651
|
+
2: "contract_address",
|
|
1652
|
+
3: "call_value",
|
|
1653
|
+
4: "data",
|
|
1654
|
+
5: "call_token_value",
|
|
1655
|
+
6: "token_id"
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
async function decodeContract(buf) {
|
|
1659
|
+
const out = {};
|
|
1660
|
+
let typeName = "";
|
|
1661
|
+
let anyValue;
|
|
1662
|
+
for (const f of readFields(buf)) {
|
|
1663
|
+
if (f.num === 1 && f.wire === 0) {
|
|
1664
|
+
const n = Number(f.varint);
|
|
1665
|
+
typeName = CONTRACT_TYPES[n] ?? `ContractType(${n})`;
|
|
1666
|
+
out.type = typeName;
|
|
1667
|
+
} else if (f.num === 2 && f.bytes) {
|
|
1668
|
+
for (const a of readFields(f.bytes)) {
|
|
1669
|
+
if (a.num === 1 && a.bytes) {
|
|
1670
|
+
out.type_url = new TextDecoder().decode(a.bytes);
|
|
1671
|
+
} else if (a.num === 2 && a.bytes) {
|
|
1672
|
+
anyValue = a.bytes;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
} else if (f.num === 5) {
|
|
1676
|
+
out.Permission_id = await fieldValue(f, false);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
if (anyValue) {
|
|
1680
|
+
const names = CONTRACT_FIELDS[typeName];
|
|
1681
|
+
if (names) {
|
|
1682
|
+
const value = {};
|
|
1683
|
+
for (const f of readFields(anyValue)) {
|
|
1684
|
+
const name = names[f.num] ?? `field_${f.num}`;
|
|
1685
|
+
value[name] = await fieldValue(f, name.endsWith("_address"));
|
|
1686
|
+
}
|
|
1687
|
+
out.parameter = value;
|
|
1688
|
+
} else {
|
|
1689
|
+
out.parameter_hex = toHex(anyValue);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
return out;
|
|
1693
|
+
}
|
|
1694
|
+
async function decodeTronRawData(rawDataHex) {
|
|
1695
|
+
const clean = rawDataHex.replace(/^0x/i, "");
|
|
1696
|
+
if (!/^[0-9a-fA-F]*$/.test(clean) || clean.length % 2 !== 0) {
|
|
1697
|
+
throw new Error("raw_data_hex is not valid hex");
|
|
1698
|
+
}
|
|
1699
|
+
const buf = Uint8Array.from(
|
|
1700
|
+
clean.match(/.{2}/g)?.map((h) => parseInt(h, 16)) ?? []
|
|
1701
|
+
);
|
|
1702
|
+
const out = {};
|
|
1703
|
+
const contracts = [];
|
|
1704
|
+
for (const f of readFields(buf)) {
|
|
1705
|
+
switch (f.num) {
|
|
1706
|
+
case 1:
|
|
1707
|
+
out.ref_block_bytes = toHex(f.bytes);
|
|
1708
|
+
break;
|
|
1709
|
+
case 3:
|
|
1710
|
+
out.ref_block_num = f.varint.toString();
|
|
1711
|
+
break;
|
|
1712
|
+
case 4:
|
|
1713
|
+
out.ref_block_hash = toHex(f.bytes);
|
|
1714
|
+
break;
|
|
1715
|
+
case 8:
|
|
1716
|
+
out.expiration = Number(f.varint);
|
|
1717
|
+
break;
|
|
1718
|
+
case 10:
|
|
1719
|
+
out.data = new TextDecoder().decode(f.bytes);
|
|
1720
|
+
break;
|
|
1721
|
+
case 11:
|
|
1722
|
+
contracts.push(await decodeContract(f.bytes));
|
|
1723
|
+
break;
|
|
1724
|
+
case 14:
|
|
1725
|
+
out.timestamp = Number(f.varint);
|
|
1726
|
+
break;
|
|
1727
|
+
case 18:
|
|
1728
|
+
out.fee_limit = f.varint.toString();
|
|
1729
|
+
break;
|
|
1730
|
+
default:
|
|
1731
|
+
out[`field_${f.num}`] = f.wire === 0 ? f.varint.toString() : toHex(f.bytes);
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
out.contract = contracts;
|
|
1735
|
+
return out;
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1525
1738
|
// src/lib/build-url.ts
|
|
1526
1739
|
var buildUrl = (baseUrl, sdkConfig, enableCaptcha, captchaSitekey) => {
|
|
1527
1740
|
if (!sdkConfig.publishableKey) {
|
|
@@ -1664,11 +1877,40 @@ var broadcastSolanaSigned = async (rpcUrl, signedBase58) => {
|
|
|
1664
1877
|
}
|
|
1665
1878
|
return result.result;
|
|
1666
1879
|
};
|
|
1880
|
+
var broadcastTronSigned = async (rpcUrl, signedTransaction) => {
|
|
1881
|
+
const response = await fetch(
|
|
1882
|
+
`${rpcUrl.replace(/\/$/, "")}/wallet/broadcasttransaction`,
|
|
1883
|
+
{
|
|
1884
|
+
method: "POST",
|
|
1885
|
+
headers: { "Content-Type": "application/json" },
|
|
1886
|
+
body: JSON.stringify(signedTransaction)
|
|
1887
|
+
}
|
|
1888
|
+
);
|
|
1889
|
+
const result = await response.json();
|
|
1890
|
+
if (!result.result) {
|
|
1891
|
+
let message = result.message ?? "";
|
|
1892
|
+
if (/^[0-9a-fA-F]+$/.test(message) && message.length % 2 === 0) {
|
|
1893
|
+
try {
|
|
1894
|
+
message = new TextDecoder().decode(
|
|
1895
|
+
Uint8Array.from(
|
|
1896
|
+
message.match(/.{2}/g).map((h) => parseInt(h, 16))
|
|
1897
|
+
)
|
|
1898
|
+
);
|
|
1899
|
+
} catch {
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
throw new Error(
|
|
1903
|
+
`Tron broadcast failed: ${result.code ?? "UNKNOWN"} ${message}`.trim()
|
|
1904
|
+
);
|
|
1905
|
+
}
|
|
1906
|
+
return result.txid ?? signedTransaction.txID;
|
|
1907
|
+
};
|
|
1667
1908
|
|
|
1668
1909
|
// src/lib/wallet-algorithm.ts
|
|
1669
1910
|
function canonicalAlgorithmFor(chain) {
|
|
1670
1911
|
switch (chain) {
|
|
1671
1912
|
case "ethereum":
|
|
1913
|
+
case "tron":
|
|
1672
1914
|
return "ecdsa";
|
|
1673
1915
|
case "solana":
|
|
1674
1916
|
return "exportable-ed25519";
|
|
@@ -1719,11 +1961,13 @@ var bs58ToBytes = async (value) => {
|
|
|
1719
1961
|
authState,
|
|
1720
1962
|
broadcastEthereumRaw,
|
|
1721
1963
|
broadcastSolanaSigned,
|
|
1964
|
+
broadcastTronSigned,
|
|
1722
1965
|
bs58ToBytes,
|
|
1723
1966
|
buildChainIndex,
|
|
1724
1967
|
buildUrl,
|
|
1725
1968
|
canonicalAlgorithmFor,
|
|
1726
1969
|
createManualSiweMessage,
|
|
1970
|
+
decodeTronRawData,
|
|
1727
1971
|
entryCaip2,
|
|
1728
1972
|
estimateEvmGas,
|
|
1729
1973
|
estimateEvmGasReserve,
|
|
@@ -1740,6 +1984,7 @@ var bs58ToBytes = async (value) => {
|
|
|
1740
1984
|
getTransferInfoFromInstructions,
|
|
1741
1985
|
isChainSupported,
|
|
1742
1986
|
isEvmEntry,
|
|
1987
|
+
isTronEntry,
|
|
1743
1988
|
normalizeChainItem,
|
|
1744
1989
|
normalizeChainKey,
|
|
1745
1990
|
parseDerivationPath,
|
|
@@ -1751,10 +1996,12 @@ var bs58ToBytes = async (value) => {
|
|
|
1751
1996
|
resolvePasskeyMetadata,
|
|
1752
1997
|
resolveRpcUrl,
|
|
1753
1998
|
resolveSolanaChainEntry,
|
|
1999
|
+
resolveTronChainEntry,
|
|
1754
2000
|
resolveWsUrl,
|
|
1755
2001
|
sanitizeUserData,
|
|
1756
2002
|
serializeEthereumTransaction,
|
|
1757
2003
|
toB64url,
|
|
2004
|
+
tronAddressFromPublicKey,
|
|
1758
2005
|
validateChainConfig,
|
|
1759
2006
|
verifyIdToken
|
|
1760
2007
|
});
|
package/dist/lib/index.mjs
CHANGED
|
@@ -7,11 +7,13 @@ import {
|
|
|
7
7
|
authState,
|
|
8
8
|
broadcastEthereumRaw,
|
|
9
9
|
broadcastSolanaSigned,
|
|
10
|
+
broadcastTronSigned,
|
|
10
11
|
bs58ToBytes,
|
|
11
12
|
buildChainIndex,
|
|
12
13
|
buildUrl,
|
|
13
14
|
canonicalAlgorithmFor,
|
|
14
15
|
createManualSiweMessage,
|
|
16
|
+
decodeTronRawData,
|
|
15
17
|
entryCaip2,
|
|
16
18
|
estimateEvmGas,
|
|
17
19
|
estimateEvmGasReserve,
|
|
@@ -28,6 +30,7 @@ import {
|
|
|
28
30
|
getTransferInfoFromInstructions,
|
|
29
31
|
isChainSupported,
|
|
30
32
|
isEvmEntry,
|
|
33
|
+
isTronEntry,
|
|
31
34
|
normalizeChainItem,
|
|
32
35
|
normalizeChainKey,
|
|
33
36
|
parseDerivationPath,
|
|
@@ -39,13 +42,15 @@ import {
|
|
|
39
42
|
resolvePasskeyMetadata,
|
|
40
43
|
resolveRpcUrl,
|
|
41
44
|
resolveSolanaChainEntry,
|
|
45
|
+
resolveTronChainEntry,
|
|
42
46
|
resolveWsUrl,
|
|
43
47
|
sanitizeUserData,
|
|
44
48
|
serializeEthereumTransaction,
|
|
45
49
|
toB64url,
|
|
50
|
+
tronAddressFromPublicKey,
|
|
46
51
|
validateChainConfig,
|
|
47
52
|
verifyIdToken
|
|
48
|
-
} from "../chunk-
|
|
53
|
+
} from "../chunk-7UGU27T3.mjs";
|
|
49
54
|
import "../chunk-LP55IGPN.mjs";
|
|
50
55
|
export {
|
|
51
56
|
DEFAULT_AUTH_URL,
|
|
@@ -56,11 +61,13 @@ export {
|
|
|
56
61
|
authState,
|
|
57
62
|
broadcastEthereumRaw,
|
|
58
63
|
broadcastSolanaSigned,
|
|
64
|
+
broadcastTronSigned,
|
|
59
65
|
bs58ToBytes,
|
|
60
66
|
buildChainIndex,
|
|
61
67
|
buildUrl,
|
|
62
68
|
canonicalAlgorithmFor,
|
|
63
69
|
createManualSiweMessage,
|
|
70
|
+
decodeTronRawData,
|
|
64
71
|
entryCaip2,
|
|
65
72
|
estimateEvmGas,
|
|
66
73
|
estimateEvmGasReserve,
|
|
@@ -77,6 +84,7 @@ export {
|
|
|
77
84
|
getTransferInfoFromInstructions,
|
|
78
85
|
isChainSupported,
|
|
79
86
|
isEvmEntry,
|
|
87
|
+
isTronEntry,
|
|
80
88
|
normalizeChainItem,
|
|
81
89
|
normalizeChainKey,
|
|
82
90
|
parseDerivationPath,
|
|
@@ -88,10 +96,12 @@ export {
|
|
|
88
96
|
resolvePasskeyMetadata,
|
|
89
97
|
resolveRpcUrl,
|
|
90
98
|
resolveSolanaChainEntry,
|
|
99
|
+
resolveTronChainEntry,
|
|
91
100
|
resolveWsUrl,
|
|
92
101
|
sanitizeUserData,
|
|
93
102
|
serializeEthereumTransaction,
|
|
94
103
|
toB64url,
|
|
104
|
+
tronAddressFromPublicKey,
|
|
95
105
|
validateChainConfig,
|
|
96
106
|
verifyIdToken
|
|
97
107
|
};
|
package/dist/react/index.d.mts
CHANGED
|
@@ -29,9 +29,13 @@ interface MoonXHookSDK {
|
|
|
29
29
|
sendSolanaTransactionHeadless: (params: unknown) => Promise<unknown>;
|
|
30
30
|
getSolanaBalance: (params: unknown) => Promise<unknown>;
|
|
31
31
|
getSolanaTokenAccountsByOwner?: (params: unknown) => Promise<unknown>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
signTronMessageHeadless?: (params: unknown) => Promise<unknown>;
|
|
33
|
+
signTronTransactionHeadless?: (params: unknown) => Promise<unknown>;
|
|
34
|
+
sendTronTransactionHeadless?: (params: unknown) => Promise<unknown>;
|
|
35
|
+
getTronBalance?: (params: unknown) => Promise<unknown>;
|
|
36
|
+
getWallets: (walletType: "ethereum" | "solana" | "tron") => Promise<unknown>;
|
|
37
|
+
createWallet: (walletType: "ethereum" | "solana" | "tron", options?: unknown) => Promise<unknown>;
|
|
38
|
+
importKey: (walletType: "ethereum" | "solana" | "tron", key: string) => Promise<unknown>;
|
|
35
39
|
getUser: () => Promise<unknown>;
|
|
36
40
|
logout: () => Promise<unknown>;
|
|
37
41
|
getPasskeyStatus: () => Promise<unknown>;
|
|
@@ -114,7 +118,7 @@ declare const useUser: () => {
|
|
|
114
118
|
refreshUser: () => Promise<void>;
|
|
115
119
|
};
|
|
116
120
|
|
|
117
|
-
declare const useWallets: (walletType: "ethereum" | "solana") => {
|
|
121
|
+
declare const useWallets: (walletType: "ethereum" | "solana" | "tron") => {
|
|
118
122
|
wallets: unknown[];
|
|
119
123
|
loading: boolean;
|
|
120
124
|
error: Error | null;
|
|
@@ -127,7 +131,7 @@ declare const useLogout: () => {
|
|
|
127
131
|
};
|
|
128
132
|
|
|
129
133
|
declare const useCreateWallet: () => {
|
|
130
|
-
createWallet: (walletType: "ethereum" | "solana", options?: {
|
|
134
|
+
createWallet: (walletType: "ethereum" | "solana" | "tron", options?: {
|
|
131
135
|
createAdditional?: boolean;
|
|
132
136
|
walletIndex?: number;
|
|
133
137
|
}) => Promise<{
|
|
@@ -136,7 +140,7 @@ declare const useCreateWallet: () => {
|
|
|
136
140
|
};
|
|
137
141
|
|
|
138
142
|
declare const useImportKey: () => {
|
|
139
|
-
importKey: (walletType: "ethereum" | "solana", key: string) => Promise<{
|
|
143
|
+
importKey: (walletType: "ethereum" | "solana" | "tron", key: string) => Promise<{
|
|
140
144
|
wallet: PublicWallet;
|
|
141
145
|
}>;
|
|
142
146
|
};
|
package/dist/react/index.d.ts
CHANGED
|
@@ -29,9 +29,13 @@ interface MoonXHookSDK {
|
|
|
29
29
|
sendSolanaTransactionHeadless: (params: unknown) => Promise<unknown>;
|
|
30
30
|
getSolanaBalance: (params: unknown) => Promise<unknown>;
|
|
31
31
|
getSolanaTokenAccountsByOwner?: (params: unknown) => Promise<unknown>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
signTronMessageHeadless?: (params: unknown) => Promise<unknown>;
|
|
33
|
+
signTronTransactionHeadless?: (params: unknown) => Promise<unknown>;
|
|
34
|
+
sendTronTransactionHeadless?: (params: unknown) => Promise<unknown>;
|
|
35
|
+
getTronBalance?: (params: unknown) => Promise<unknown>;
|
|
36
|
+
getWallets: (walletType: "ethereum" | "solana" | "tron") => Promise<unknown>;
|
|
37
|
+
createWallet: (walletType: "ethereum" | "solana" | "tron", options?: unknown) => Promise<unknown>;
|
|
38
|
+
importKey: (walletType: "ethereum" | "solana" | "tron", key: string) => Promise<unknown>;
|
|
35
39
|
getUser: () => Promise<unknown>;
|
|
36
40
|
logout: () => Promise<unknown>;
|
|
37
41
|
getPasskeyStatus: () => Promise<unknown>;
|
|
@@ -114,7 +118,7 @@ declare const useUser: () => {
|
|
|
114
118
|
refreshUser: () => Promise<void>;
|
|
115
119
|
};
|
|
116
120
|
|
|
117
|
-
declare const useWallets: (walletType: "ethereum" | "solana") => {
|
|
121
|
+
declare const useWallets: (walletType: "ethereum" | "solana" | "tron") => {
|
|
118
122
|
wallets: unknown[];
|
|
119
123
|
loading: boolean;
|
|
120
124
|
error: Error | null;
|
|
@@ -127,7 +131,7 @@ declare const useLogout: () => {
|
|
|
127
131
|
};
|
|
128
132
|
|
|
129
133
|
declare const useCreateWallet: () => {
|
|
130
|
-
createWallet: (walletType: "ethereum" | "solana", options?: {
|
|
134
|
+
createWallet: (walletType: "ethereum" | "solana" | "tron", options?: {
|
|
131
135
|
createAdditional?: boolean;
|
|
132
136
|
walletIndex?: number;
|
|
133
137
|
}) => Promise<{
|
|
@@ -136,7 +140,7 @@ declare const useCreateWallet: () => {
|
|
|
136
140
|
};
|
|
137
141
|
|
|
138
142
|
declare const useImportKey: () => {
|
|
139
|
-
importKey: (walletType: "ethereum" | "solana", key: string) => Promise<{
|
|
143
|
+
importKey: (walletType: "ethereum" | "solana" | "tron", key: string) => Promise<{
|
|
140
144
|
wallet: PublicWallet;
|
|
141
145
|
}>;
|
|
142
146
|
};
|
package/dist/react/index.js
CHANGED
|
@@ -552,6 +552,14 @@ var nacl = __toESM(require("tweetnacl"));
|
|
|
552
552
|
var import_web3 = require("@solana/web3.js");
|
|
553
553
|
var import_bn = __toESM(require("bn.js"));
|
|
554
554
|
|
|
555
|
+
// src/lib/tron/tron-address.ts
|
|
556
|
+
var import_secp256k1 = require("@noble/curves/secp256k1");
|
|
557
|
+
var import_sha3 = require("@noble/hashes/sha3");
|
|
558
|
+
var import_sha256 = require("@noble/hashes/sha256");
|
|
559
|
+
|
|
560
|
+
// src/lib/tron/decode-raw-data.ts
|
|
561
|
+
var import_sha2562 = require("@noble/hashes/sha256");
|
|
562
|
+
|
|
555
563
|
// src/react/use-passkey-status.ts
|
|
556
564
|
var import_react8 = require("react");
|
|
557
565
|
var sharedHasPasskey = null;
|
package/dist/react/index.mjs
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TronGetBalanceParams, TronGetBalanceResult, TronSendTransactionParams, TronSendTransactionResult, TronSignMessageParams, TronSignMessageResult, TronSignTransactionParams, TronSignTransactionResult } from '../types/index.mjs';
|
|
2
|
+
|
|
3
|
+
declare const useSignMessage: () => {
|
|
4
|
+
signMessage: (params: TronSignMessageParams) => Promise<TronSignMessageResult>;
|
|
5
|
+
};
|
|
6
|
+
declare const useSignTransaction: () => {
|
|
7
|
+
signTransaction: (params: TronSignTransactionParams) => Promise<TronSignTransactionResult>;
|
|
8
|
+
};
|
|
9
|
+
declare const useSendTransaction: () => {
|
|
10
|
+
sendTransaction: (params: TronSendTransactionParams) => Promise<TronSendTransactionResult>;
|
|
11
|
+
};
|
|
12
|
+
declare const useGetBalance: () => {
|
|
13
|
+
getBalance: (params: TronGetBalanceParams) => Promise<TronGetBalanceResult>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { useGetBalance, useSendTransaction, useSignMessage, useSignTransaction };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TronGetBalanceParams, TronGetBalanceResult, TronSendTransactionParams, TronSendTransactionResult, TronSignMessageParams, TronSignMessageResult, TronSignTransactionParams, TronSignTransactionResult } from '../types/index.js';
|
|
2
|
+
|
|
3
|
+
declare const useSignMessage: () => {
|
|
4
|
+
signMessage: (params: TronSignMessageParams) => Promise<TronSignMessageResult>;
|
|
5
|
+
};
|
|
6
|
+
declare const useSignTransaction: () => {
|
|
7
|
+
signTransaction: (params: TronSignTransactionParams) => Promise<TronSignTransactionResult>;
|
|
8
|
+
};
|
|
9
|
+
declare const useSendTransaction: () => {
|
|
10
|
+
sendTransaction: (params: TronSendTransactionParams) => Promise<TronSendTransactionResult>;
|
|
11
|
+
};
|
|
12
|
+
declare const useGetBalance: () => {
|
|
13
|
+
getBalance: (params: TronGetBalanceParams) => Promise<TronGetBalanceResult>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { useGetBalance, useSendTransaction, useSignMessage, useSignTransaction };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/react/tron.ts
|
|
21
|
+
var tron_exports = {};
|
|
22
|
+
__export(tron_exports, {
|
|
23
|
+
useGetBalance: () => useGetBalance,
|
|
24
|
+
useSendTransaction: () => useSendTransaction,
|
|
25
|
+
useSignMessage: () => useSignMessage,
|
|
26
|
+
useSignTransaction: () => useSignTransaction
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(tron_exports);
|
|
29
|
+
|
|
30
|
+
// src/react/sdk-context.ts
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
var SDKContext = (0, import_react.createContext)(null);
|
|
33
|
+
var SDKProvider = SDKContext.Provider;
|
|
34
|
+
var useMoonXSDK = () => {
|
|
35
|
+
const sdk = (0, import_react.useContext)(SDKContext);
|
|
36
|
+
if (!sdk) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
"MoonX hook called outside a <MoonXProvider> \u2014 wrap your app in the provider from @moon-x/react-sdk (web) or @moon-x/react-native-sdk (RN)."
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return sdk;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// src/react/tron.ts
|
|
45
|
+
var useSignMessage = () => {
|
|
46
|
+
const sdk = useMoonXSDK();
|
|
47
|
+
return {
|
|
48
|
+
signMessage: (params) => {
|
|
49
|
+
if (!sdk.signTronMessageHeadless) {
|
|
50
|
+
throw new Error("Tron signing is not available on this SDK instance");
|
|
51
|
+
}
|
|
52
|
+
return sdk.signTronMessageHeadless(params);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
var useSignTransaction = () => {
|
|
57
|
+
const sdk = useMoonXSDK();
|
|
58
|
+
return {
|
|
59
|
+
signTransaction: (params) => {
|
|
60
|
+
if (!sdk.signTronTransactionHeadless) {
|
|
61
|
+
throw new Error("Tron signing is not available on this SDK instance");
|
|
62
|
+
}
|
|
63
|
+
return sdk.signTronTransactionHeadless(params);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
var useSendTransaction = () => {
|
|
68
|
+
const sdk = useMoonXSDK();
|
|
69
|
+
return {
|
|
70
|
+
sendTransaction: (params) => {
|
|
71
|
+
if (!sdk.sendTronTransactionHeadless) {
|
|
72
|
+
throw new Error("Tron send is not available on this SDK instance");
|
|
73
|
+
}
|
|
74
|
+
return sdk.sendTronTransactionHeadless(params);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
var useGetBalance = () => {
|
|
79
|
+
const sdk = useMoonXSDK();
|
|
80
|
+
return {
|
|
81
|
+
getBalance: (params) => {
|
|
82
|
+
if (!sdk.getTronBalance) {
|
|
83
|
+
throw new Error("Tron balance is not available on this SDK instance");
|
|
84
|
+
}
|
|
85
|
+
return sdk.getTronBalance(params);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
useGetBalance,
|
|
92
|
+
useSendTransaction,
|
|
93
|
+
useSignMessage,
|
|
94
|
+
useSignTransaction
|
|
95
|
+
});
|