@moon-x/core 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/{chunk-L7GL3PFM.mjs → chunk-7UGU27T3.mjs} +249 -7
- package/dist/{chunk-264CEGDS.mjs → chunk-HAEJD7NC.mjs} +4 -3
- package/dist/chunk-LP55IGPN.mjs +21 -0
- package/dist/{chunk-BJKWC4MG.mjs → chunk-PEIBEYMA.mjs} +3 -3
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -10
- package/dist/index.mjs +5 -5
- package/dist/lib/index.d.mts +40 -4
- package/dist/lib/index.d.ts +40 -4
- package/dist/lib/index.js +258 -10
- package/dist/lib/index.mjs +12 -2
- package/dist/react/ethereum.js +9 -9
- package/dist/react/ethereum.mjs +9 -9
- package/dist/react/index.d.mts +14 -10
- package/dist/react/index.d.ts +14 -10
- package/dist/react/index.js +23 -15
- package/dist/react/index.mjs +16 -16
- package/dist/react/solana.js +6 -6
- package/dist/react/solana.mjs +6 -6
- 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 +107 -2
- package/dist/types/index.d.mts +98 -8
- package/dist/types/index.d.ts +98 -8
- package/dist/types/index.mjs +1 -1
- package/dist/utils/index.d.mts +3 -3
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +12 -10
- package/dist/utils/index.mjs +4 -4
- package/dist/web/index.js +5 -4
- package/dist/web/index.mjs +2 -2
- package/package.json +6 -1
- package/dist/chunk-GQKIA37O.mjs +0 -20
- /package/dist/{chunk-IMLBIIJ4.mjs → chunk-CEL3U6EI.mjs} +0 -0
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { C as CachedAssertion, g as generatePasskeyUserId } from '../passkey-cache-WnDFQ-v4.js';
|
|
2
2
|
export { a as PasskeyFormFactor, P as PasskeyMetadata, b as PasskeyMetadataInput, f as formatPasskeyLabel, r as resolvePasskeyMetadata } from '../passkey-metadata-QqFF2SWQ.js';
|
|
3
|
-
import { ChainEntry, ChainConfigItem, Chain, EvmChainEntry, SolanaChainEntry, WalletChain } from '../types/index.js';
|
|
3
|
+
import { ChainEntry, ChainConfigItem, Chain, EvmChainEntry, TronChainEntry, SolanaChainEntry, WalletChain } from '../types/index.js';
|
|
4
4
|
import { SiweMessage } from 'siwe';
|
|
5
5
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
6
6
|
|
|
@@ -28,7 +28,7 @@ declare const authState: AuthenticationState;
|
|
|
28
28
|
declare function sanitizeUserData(userData: any): any;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Verify ID token with
|
|
31
|
+
* Verify ID token with MoonX API and retrieve user info.
|
|
32
32
|
*/
|
|
33
33
|
interface VerifyIdTokenResponse {
|
|
34
34
|
success: boolean;
|
|
@@ -42,7 +42,7 @@ declare const fromB64url: (b64url: string) => Uint8Array;
|
|
|
42
42
|
declare const toB64url: (bytes: Uint8Array) => string;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Chain utilities for
|
|
45
|
+
* Chain utilities for MoonX
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -131,6 +131,8 @@ declare function getChainById(chains: ChainConfigItem[], chainId: number): Chain
|
|
|
131
131
|
declare function isChainSupported(chains: ChainConfigItem[], chainId: number): boolean;
|
|
132
132
|
/** Type guard: is this normalized entry an EVM entry (carries a viem Chain)? */
|
|
133
133
|
declare function isEvmEntry(entry: ChainEntry): entry is EvmChainEntry;
|
|
134
|
+
/** Type guard: a string-id entry in the "tron" namespace (e.g. "tron:mainnet"). */
|
|
135
|
+
declare function isTronEntry(entry: ChainEntry): entry is TronChainEntry;
|
|
134
136
|
/**
|
|
135
137
|
* Coerce a `ChainConfigItem` to its normalized form. A bare viem `Chain`
|
|
136
138
|
* (numeric `id`) becomes an `EvmChainEntry`; `{ chain, … }` is already one;
|
|
@@ -176,6 +178,12 @@ declare function resolveChainEntry(chains: ChainConfigItem[] | undefined, select
|
|
|
176
178
|
* hooks throw a clear "no RPC URL" error.
|
|
177
179
|
*/
|
|
178
180
|
declare function resolveSolanaChainEntry(chains: ChainConfigItem[] | undefined, selector?: string | number, defaultSelector?: string | number): SolanaChainEntry | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Resolve a TRON entry, mirroring `resolveSolanaChainEntry`'s precedence and
|
|
183
|
+
* fail-closed semantics: an explicit selector that doesn't name a configured
|
|
184
|
+
* tron entry returns undefined rather than falling through to another chain.
|
|
185
|
+
*/
|
|
186
|
+
declare function resolveTronChainEntry(chains: ChainConfigItem[] | undefined, selector?: string | number, defaultSelector?: string | number): TronChainEntry | undefined;
|
|
179
187
|
/**
|
|
180
188
|
* Resolve the EVM entry to use, honoring (highest priority first):
|
|
181
189
|
* per-call `selector` → tx `requestedChainId` → `walletChainId` →
|
|
@@ -455,6 +463,24 @@ declare function getSOLTransfersFromInstructions(base64Transaction: string, logs
|
|
|
455
463
|
usdValue?: string;
|
|
456
464
|
}>>;
|
|
457
465
|
|
|
466
|
+
/**
|
|
467
|
+
* Derive the base58check Tron address from a secp256k1 public key
|
|
468
|
+
* (compressed or uncompressed hex, with or without 0x):
|
|
469
|
+
* keccak256(uncompressed pubkey body)[12:] prefixed with 0x41, then
|
|
470
|
+
* base58check (double-sha256 checksum).
|
|
471
|
+
*
|
|
472
|
+
* Async because `bs58` is an optional ESM-only peer of `@moon-x/core`
|
|
473
|
+
* and is lazy-imported, same as `bs58ToBytes` in wire-codec.ts.
|
|
474
|
+
*/
|
|
475
|
+
declare function tronAddressFromPublicKey(publicKeyHex: string): Promise<string>;
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Decode raw_data_hex (the signed bytes) into a labeled preview object.
|
|
479
|
+
* Throws on malformed input - callers fall back to showing the raw
|
|
480
|
+
* payload rather than a possibly-wrong decode.
|
|
481
|
+
*/
|
|
482
|
+
declare function decodeTronRawData(rawDataHex: string): Promise<Record<string, unknown>>;
|
|
483
|
+
|
|
458
484
|
interface BuildUrlConfig {
|
|
459
485
|
publishableKey: string;
|
|
460
486
|
config?: {
|
|
@@ -470,6 +496,15 @@ declare const DEFAULT_AUTH_URL = "https://iframe.moonx-dev.com";
|
|
|
470
496
|
declare const serializeEthereumTransaction: (transaction: any) => Promise<string>;
|
|
471
497
|
declare const broadcastEthereumRaw: (rpcUrl: string, signedSerialized: string) => Promise<string>;
|
|
472
498
|
declare const broadcastSolanaSigned: (rpcUrl: string, signedBase58: string) => Promise<string>;
|
|
499
|
+
/**
|
|
500
|
+
* Broadcast a signed Tron transaction (TronWeb JSON shape, signature
|
|
501
|
+
* attached) to a fullnode. Returns the txid. Tron reports failures as
|
|
502
|
+
* `{ result: false, code, message }` with `message` hex-encoded ASCII;
|
|
503
|
+
* decode it so callers see "Contract validate error: ..." instead of hex.
|
|
504
|
+
*/
|
|
505
|
+
declare const broadcastTronSigned: (rpcUrl: string, signedTransaction: {
|
|
506
|
+
txID: string;
|
|
507
|
+
} & Record<string, unknown>) => Promise<string>;
|
|
473
508
|
|
|
474
509
|
/**
|
|
475
510
|
* Canonical algorithm name written to `app_user_wallet_keyshares.algorithm`.
|
|
@@ -477,6 +512,7 @@ declare const broadcastSolanaSigned: (rpcUrl: string, signedBase58: string) => P
|
|
|
477
512
|
* Matches Sodot's Vertex API path segment exactly:
|
|
478
513
|
*
|
|
479
514
|
* ethereum → "ecdsa"
|
|
515
|
+
* tron → "ecdsa"
|
|
480
516
|
* solana → "exportable-ed25519"
|
|
481
517
|
*
|
|
482
518
|
* `Algorithm.name.toLowerCase()` from the Sodot SDK would give
|
|
@@ -519,4 +555,4 @@ declare const arrayLikeToBytes: (value: unknown) => Uint8Array;
|
|
|
519
555
|
*/
|
|
520
556
|
declare const bs58ToBytes: (value: unknown) => Promise<Uint8Array>;
|
|
521
557
|
|
|
522
|
-
export { type BuildUrlConfig, type ChainIndex, DEFAULT_AUTH_URL, EthereumSiweMessage, type EthereumSiweMessageProps, type EvmTransactionInput, type EvmTxPrepWallet, type ManualSiweMessageProps, SiwsMessage, SolanaTransactionParser, type VerifyIdTokenResponse, arrayLikeToBytes, authState, broadcastEthereumRaw, broadcastSolanaSigned, bs58ToBytes, buildChainIndex, buildUrl, canonicalAlgorithmFor, createManualSiweMessage, entryCaip2, estimateEvmGas, estimateEvmGasReserve, fromB64url, getChainById, getEvmGasPrice, getEvmMaxPriorityFeePerGas, getEvmNonce, getInstructionsForHTML, getRpcUrl, getSOLTransfersFromInstructions, getTransferInfoFromInstructions, isChainSupported, isEvmEntry, normalizeChainItem, normalizeChainKey, parseDerivationPath, prepareEvmSendTransaction, prepareEvmSignTransaction, resolveChainEntry, resolveEvmChain, resolveEvmChainEntry, resolveRpcUrl, resolveSolanaChainEntry, resolveWsUrl, sanitizeUserData, serializeEthereumTransaction, toB64url, validateChainConfig, verifyIdToken };
|
|
558
|
+
export { type BuildUrlConfig, type ChainIndex, DEFAULT_AUTH_URL, EthereumSiweMessage, type EthereumSiweMessageProps, type EvmTransactionInput, type EvmTxPrepWallet, type ManualSiweMessageProps, SiwsMessage, SolanaTransactionParser, type VerifyIdTokenResponse, arrayLikeToBytes, authState, broadcastEthereumRaw, broadcastSolanaSigned, broadcastTronSigned, bs58ToBytes, buildChainIndex, buildUrl, canonicalAlgorithmFor, createManualSiweMessage, decodeTronRawData, entryCaip2, estimateEvmGas, estimateEvmGasReserve, fromB64url, getChainById, getEvmGasPrice, getEvmMaxPriorityFeePerGas, getEvmNonce, getInstructionsForHTML, getRpcUrl, getSOLTransfersFromInstructions, getTransferInfoFromInstructions, isChainSupported, isEvmEntry, isTronEntry, normalizeChainItem, normalizeChainKey, parseDerivationPath, prepareEvmSendTransaction, prepareEvmSignTransaction, resolveChainEntry, resolveEvmChain, resolveEvmChainEntry, resolveRpcUrl, resolveSolanaChainEntry, resolveTronChainEntry, resolveWsUrl, sanitizeUserData, serializeEthereumTransaction, toB64url, tronAddressFromPublicKey, validateChainConfig, verifyIdToken };
|
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
|
});
|
|
@@ -124,12 +129,13 @@ function sanitizeUserData(userData) {
|
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
// src/utils/get-api-url.ts
|
|
127
|
-
var
|
|
128
|
-
|
|
129
|
-
|
|
132
|
+
var getMoonXApiUrl = () => {
|
|
133
|
+
const apiUrlOverride = process.env?.NEXT_PUBLIC_MOONX_API_URL || process.env?.NEXT_PUBLIC_MOONKEY_API_URL;
|
|
134
|
+
if (apiUrlOverride) {
|
|
135
|
+
return apiUrlOverride;
|
|
130
136
|
}
|
|
131
|
-
|
|
132
|
-
|
|
137
|
+
const iframeUrl = process.env?.NEXT_PUBLIC_MOONX_IFRAME_URL || process.env?.NEXT_PUBLIC_MOONKEY_IFRAME_URL;
|
|
138
|
+
if (iframeUrl) {
|
|
133
139
|
if (iframeUrl.includes("staging") || iframeUrl.includes("auth-staging")) {
|
|
134
140
|
return "https://api.moonx-dev.com";
|
|
135
141
|
}
|
|
@@ -143,7 +149,7 @@ var getMoonKeyApiUrl = () => {
|
|
|
143
149
|
// src/lib/auth/verify-id-token.ts
|
|
144
150
|
var verifyIdToken = async (publishableKey, idToken) => {
|
|
145
151
|
try {
|
|
146
|
-
const apiUrl =
|
|
152
|
+
const apiUrl = getMoonXApiUrl();
|
|
147
153
|
const response = await fetch(
|
|
148
154
|
`${apiUrl}/v1/auth/users/public/id_token/verify`,
|
|
149
155
|
{
|
|
@@ -514,6 +520,9 @@ function isChainSupported(chains, chainId) {
|
|
|
514
520
|
function isEvmEntry(entry) {
|
|
515
521
|
return "chain" in entry;
|
|
516
522
|
}
|
|
523
|
+
function isTronEntry(entry) {
|
|
524
|
+
return !isEvmEntry(entry) && entry.id.split(":")[0].toLowerCase() === "tron";
|
|
525
|
+
}
|
|
517
526
|
function normalizeChainItem(item) {
|
|
518
527
|
if ("chain" in item) return item;
|
|
519
528
|
if (typeof item.id === "number") {
|
|
@@ -542,8 +551,14 @@ function aliasesFor(entry) {
|
|
|
542
551
|
}
|
|
543
552
|
} else {
|
|
544
553
|
keys.push(entry.id);
|
|
545
|
-
const cluster = entry.id.split(":")
|
|
546
|
-
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
|
+
}
|
|
547
562
|
}
|
|
548
563
|
return keys;
|
|
549
564
|
}
|
|
@@ -582,10 +597,20 @@ function resolveSolanaChainEntry(chains, selector, defaultSelector) {
|
|
|
582
597
|
const asSolana = (k) => {
|
|
583
598
|
if (k == null) return void 0;
|
|
584
599
|
const e = index.byAlias.get(normalizeChainKey(k));
|
|
585
|
-
return e && !isEvmEntry(e) ? e : void 0;
|
|
600
|
+
return e && !isEvmEntry(e) && !isTronEntry(e) ? e : void 0;
|
|
586
601
|
};
|
|
587
602
|
if (selector != null) return asSolana(selector);
|
|
588
|
-
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);
|
|
589
614
|
}
|
|
590
615
|
function resolveEvmChainEntry(opts) {
|
|
591
616
|
const index = buildChainIndex(opts.chains ?? []);
|
|
@@ -1521,6 +1546,195 @@ async function getSOLTransfersFromInstructions(base64Transaction, logs, solPrice
|
|
|
1521
1546
|
return transfers;
|
|
1522
1547
|
}
|
|
1523
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
|
+
|
|
1524
1738
|
// src/lib/build-url.ts
|
|
1525
1739
|
var buildUrl = (baseUrl, sdkConfig, enableCaptcha, captchaSitekey) => {
|
|
1526
1740
|
if (!sdkConfig.publishableKey) {
|
|
@@ -1663,11 +1877,40 @@ var broadcastSolanaSigned = async (rpcUrl, signedBase58) => {
|
|
|
1663
1877
|
}
|
|
1664
1878
|
return result.result;
|
|
1665
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
|
+
};
|
|
1666
1908
|
|
|
1667
1909
|
// src/lib/wallet-algorithm.ts
|
|
1668
1910
|
function canonicalAlgorithmFor(chain) {
|
|
1669
1911
|
switch (chain) {
|
|
1670
1912
|
case "ethereum":
|
|
1913
|
+
case "tron":
|
|
1671
1914
|
return "ecdsa";
|
|
1672
1915
|
case "solana":
|
|
1673
1916
|
return "exportable-ed25519";
|
|
@@ -1718,11 +1961,13 @@ var bs58ToBytes = async (value) => {
|
|
|
1718
1961
|
authState,
|
|
1719
1962
|
broadcastEthereumRaw,
|
|
1720
1963
|
broadcastSolanaSigned,
|
|
1964
|
+
broadcastTronSigned,
|
|
1721
1965
|
bs58ToBytes,
|
|
1722
1966
|
buildChainIndex,
|
|
1723
1967
|
buildUrl,
|
|
1724
1968
|
canonicalAlgorithmFor,
|
|
1725
1969
|
createManualSiweMessage,
|
|
1970
|
+
decodeTronRawData,
|
|
1726
1971
|
entryCaip2,
|
|
1727
1972
|
estimateEvmGas,
|
|
1728
1973
|
estimateEvmGasReserve,
|
|
@@ -1739,6 +1984,7 @@ var bs58ToBytes = async (value) => {
|
|
|
1739
1984
|
getTransferInfoFromInstructions,
|
|
1740
1985
|
isChainSupported,
|
|
1741
1986
|
isEvmEntry,
|
|
1987
|
+
isTronEntry,
|
|
1742
1988
|
normalizeChainItem,
|
|
1743
1989
|
normalizeChainKey,
|
|
1744
1990
|
parseDerivationPath,
|
|
@@ -1750,10 +1996,12 @@ var bs58ToBytes = async (value) => {
|
|
|
1750
1996
|
resolvePasskeyMetadata,
|
|
1751
1997
|
resolveRpcUrl,
|
|
1752
1998
|
resolveSolanaChainEntry,
|
|
1999
|
+
resolveTronChainEntry,
|
|
1753
2000
|
resolveWsUrl,
|
|
1754
2001
|
sanitizeUserData,
|
|
1755
2002
|
serializeEthereumTransaction,
|
|
1756
2003
|
toB64url,
|
|
2004
|
+
tronAddressFromPublicKey,
|
|
1757
2005
|
validateChainConfig,
|
|
1758
2006
|
verifyIdToken
|
|
1759
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,14 +42,16 @@ 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-
|
|
49
|
-
import "../chunk-
|
|
53
|
+
} from "../chunk-7UGU27T3.mjs";
|
|
54
|
+
import "../chunk-LP55IGPN.mjs";
|
|
50
55
|
export {
|
|
51
56
|
DEFAULT_AUTH_URL,
|
|
52
57
|
EthereumSiweMessage,
|
|
@@ -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/ethereum.js
CHANGED
|
@@ -34,11 +34,11 @@ module.exports = __toCommonJS(ethereum_exports);
|
|
|
34
34
|
var import_react = require("react");
|
|
35
35
|
var SDKContext = (0, import_react.createContext)(null);
|
|
36
36
|
var SDKProvider = SDKContext.Provider;
|
|
37
|
-
var
|
|
37
|
+
var useMoonXSDK = () => {
|
|
38
38
|
const sdk = (0, import_react.useContext)(SDKContext);
|
|
39
39
|
if (!sdk) {
|
|
40
40
|
throw new Error(
|
|
41
|
-
"
|
|
41
|
+
"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)."
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
return sdk;
|
|
@@ -46,43 +46,43 @@ var useMoonKeySDK = () => {
|
|
|
46
46
|
|
|
47
47
|
// src/react/ethereum.ts
|
|
48
48
|
var useSignMessage = () => {
|
|
49
|
-
const sdk =
|
|
49
|
+
const sdk = useMoonXSDK();
|
|
50
50
|
return {
|
|
51
51
|
signMessage: (params) => sdk.signEthereumMessageHeadless(params)
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
54
|
var useSignTransaction = () => {
|
|
55
|
-
const sdk =
|
|
55
|
+
const sdk = useMoonXSDK();
|
|
56
56
|
return {
|
|
57
57
|
signTransaction: (params) => sdk.signEthereumTransactionHeadless(params)
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
60
|
var useSignTypedData = () => {
|
|
61
|
-
const sdk =
|
|
61
|
+
const sdk = useMoonXSDK();
|
|
62
62
|
return {
|
|
63
63
|
signTypedData: (params) => sdk.signEthereumTypedDataHeadless(params)
|
|
64
64
|
};
|
|
65
65
|
};
|
|
66
66
|
var useSignHash = () => {
|
|
67
|
-
const sdk =
|
|
67
|
+
const sdk = useMoonXSDK();
|
|
68
68
|
return {
|
|
69
69
|
signHash: (params) => sdk.signEthereumHashHeadless(params)
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
72
|
var useSign7702Authorization = () => {
|
|
73
|
-
const sdk =
|
|
73
|
+
const sdk = useMoonXSDK();
|
|
74
74
|
return {
|
|
75
75
|
signAuthorization: (params) => sdk.signEthereum7702AuthorizationHeadless(params)
|
|
76
76
|
};
|
|
77
77
|
};
|
|
78
78
|
var useSendTransaction = () => {
|
|
79
|
-
const sdk =
|
|
79
|
+
const sdk = useMoonXSDK();
|
|
80
80
|
return {
|
|
81
81
|
sendTransaction: (params) => sdk.sendEthereumTransactionHeadless(params)
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
84
|
var useGetBalance = () => {
|
|
85
|
-
const sdk =
|
|
85
|
+
const sdk = useMoonXSDK();
|
|
86
86
|
return {
|
|
87
87
|
getBalance: (params) => sdk.getEthereumBalance(params)
|
|
88
88
|
};
|
package/dist/react/ethereum.mjs
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
2
|
+
useMoonXSDK
|
|
3
|
+
} from "../chunk-PEIBEYMA.mjs";
|
|
4
4
|
|
|
5
5
|
// src/react/ethereum.ts
|
|
6
6
|
var useSignMessage = () => {
|
|
7
|
-
const sdk =
|
|
7
|
+
const sdk = useMoonXSDK();
|
|
8
8
|
return {
|
|
9
9
|
signMessage: (params) => sdk.signEthereumMessageHeadless(params)
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
var useSignTransaction = () => {
|
|
13
|
-
const sdk =
|
|
13
|
+
const sdk = useMoonXSDK();
|
|
14
14
|
return {
|
|
15
15
|
signTransaction: (params) => sdk.signEthereumTransactionHeadless(params)
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
var useSignTypedData = () => {
|
|
19
|
-
const sdk =
|
|
19
|
+
const sdk = useMoonXSDK();
|
|
20
20
|
return {
|
|
21
21
|
signTypedData: (params) => sdk.signEthereumTypedDataHeadless(params)
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
var useSignHash = () => {
|
|
25
|
-
const sdk =
|
|
25
|
+
const sdk = useMoonXSDK();
|
|
26
26
|
return {
|
|
27
27
|
signHash: (params) => sdk.signEthereumHashHeadless(params)
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
var useSign7702Authorization = () => {
|
|
31
|
-
const sdk =
|
|
31
|
+
const sdk = useMoonXSDK();
|
|
32
32
|
return {
|
|
33
33
|
signAuthorization: (params) => sdk.signEthereum7702AuthorizationHeadless(params)
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
var useSendTransaction = () => {
|
|
37
|
-
const sdk =
|
|
37
|
+
const sdk = useMoonXSDK();
|
|
38
38
|
return {
|
|
39
39
|
sendTransaction: (params) => sdk.sendEthereumTransactionHeadless(params)
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
42
|
var useGetBalance = () => {
|
|
43
|
-
const sdk =
|
|
43
|
+
const sdk = useMoonXSDK();
|
|
44
44
|
return {
|
|
45
45
|
getBalance: (params) => sdk.getEthereumBalance(params)
|
|
46
46
|
};
|