@moon-x/core 0.2.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.
Files changed (55) hide show
  1. package/README.md +39 -0
  2. package/dist/chain-C9dvKXUY.d.mts +48 -0
  3. package/dist/chain-C9dvKXUY.d.ts +48 -0
  4. package/dist/chunk-264CEGDS.mjs +46 -0
  5. package/dist/chunk-CDT4MC7S.mjs +1532 -0
  6. package/dist/chunk-CMYR6AOY.mjs +0 -0
  7. package/dist/chunk-GQKIA37O.mjs +20 -0
  8. package/dist/chunk-IMLBIIJ4.mjs +36 -0
  9. package/dist/chunk-MOREUKOG.mjs +18 -0
  10. package/dist/chunk-SOKLPX7V.mjs +270 -0
  11. package/dist/index.d.mts +4 -0
  12. package/dist/index.d.ts +4 -0
  13. package/dist/index.js +402 -0
  14. package/dist/index.mjs +33 -0
  15. package/dist/interfaces-9k0eKCc4.d.ts +120 -0
  16. package/dist/interfaces-fNhwnCeY.d.mts +120 -0
  17. package/dist/lib/index.d.mts +410 -0
  18. package/dist/lib/index.d.ts +410 -0
  19. package/dist/lib/index.js +1622 -0
  20. package/dist/lib/index.mjs +89 -0
  21. package/dist/passkey-cache-B9PT3AWX.d.mts +47 -0
  22. package/dist/passkey-cache-B9PT3AWX.d.ts +47 -0
  23. package/dist/passkey-metadata-QqFF2SWQ.d.mts +25 -0
  24. package/dist/passkey-metadata-QqFF2SWQ.d.ts +25 -0
  25. package/dist/post-message-C_99BCBh.d.mts +70 -0
  26. package/dist/post-message-C_99BCBh.d.ts +70 -0
  27. package/dist/react/ethereum.d.mts +26 -0
  28. package/dist/react/ethereum.d.ts +26 -0
  29. package/dist/react/ethereum.js +99 -0
  30. package/dist/react/ethereum.mjs +56 -0
  31. package/dist/react/index.d.mts +182 -0
  32. package/dist/react/index.d.ts +182 -0
  33. package/dist/react/index.js +586 -0
  34. package/dist/react/index.mjs +328 -0
  35. package/dist/react/solana.d.mts +17 -0
  36. package/dist/react/solana.d.ts +17 -0
  37. package/dist/react/solana.js +75 -0
  38. package/dist/react/solana.mjs +35 -0
  39. package/dist/sdk/index.d.mts +126 -0
  40. package/dist/sdk/index.d.ts +126 -0
  41. package/dist/sdk/index.js +864 -0
  42. package/dist/sdk/index.mjs +579 -0
  43. package/dist/types/index.d.mts +1190 -0
  44. package/dist/types/index.d.ts +1190 -0
  45. package/dist/types/index.js +64 -0
  46. package/dist/types/index.mjs +10 -0
  47. package/dist/utils/index.d.mts +11 -0
  48. package/dist/utils/index.d.ts +11 -0
  49. package/dist/utils/index.js +365 -0
  50. package/dist/utils/index.mjs +25 -0
  51. package/dist/web/index.d.mts +20 -0
  52. package/dist/web/index.d.ts +20 -0
  53. package/dist/web/index.js +470 -0
  54. package/dist/web/index.mjs +155 -0
  55. package/package.json +111 -0
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @moon-x/core
2
+
3
+ Shared foundation for the [MoonX](https://moonx.com) platform SDKs. This package is consumed by
4
+ [`@moon-x/react-sdk`](https://www.npmjs.com/package/@moon-x/react-sdk) and
5
+ [`@moon-x/react-native-sdk`](https://www.npmjs.com/package/@moon-x/react-native-sdk) —
6
+ **you almost certainly want one of those instead of installing this directly.**
7
+
8
+ ```sh
9
+ npm install @moon-x/react-sdk # web
10
+ npm install @moon-x/react-native-sdk # mobile
11
+ ```
12
+
13
+ ## What's here
14
+
15
+ This package owns everything that's identical between web and mobile:
16
+
17
+ - **Wire types and protocol** (`@moon-x/core/types`, `@moon-x/core/utils`) — `PublicWallet`, `Chain`, `AuthAppearance`, plus the `PostMessageType` / `PostMessageMethod` enums and the `PostMessageClient` / `PostMessageServer` classes used by every iframe ↔ SDK channel.
18
+ - **Headless SDK factories** (`@moon-x/core/sdk`) — platform-agnostic implementations of `signMessage`, `signTransaction`, `sendTransaction`, etc. that take a `Transport` + `PasskeyAssertor` + `KvStorage` via DI. Web and RN both wire their platform impls into these factories.
19
+ - **Web platform impls** (`@moon-x/core/web`) — `createIframeTransport`, `createWebAuthnPasskey`, `createLocalStorageKv`. React-native has its own equivalents inside `@moon-x/react-native-sdk/platform/*`.
20
+ - **Shared React hooks** (`@moon-x/core/react`) — hooks that run identically on web + RN (`useUser`, `useWallets`, `useLogout`, `useLoginWithEmail`, `usePasskeyStatus`, `useAddPasskey`, `useRemovePasskey`, `useCreateWallet`, `useImportKey`, plus per-chain hooks under `@moon-x/core/react/ethereum` and `@moon-x/core/react/solana`). The platform SDKs re-export these directly so consumers never import from core.
21
+ - **Pure utilities** (`@moon-x/core/lib`) — EVM chain/gas helpers (`getEvmGasPrice`, `estimateEvmGas`, `getEvmNonce`, `chains`), `prepareEvmSignTransaction` / `prepareEvmSendTransaction` (chain + RPC + nonce/gas/fee auto-fill), SIWE/SIWS message builders, passkey codec + cache (safe-by-default TTL=0; integrator opts in via `setAssertCacheTtlMs`) + AAGUID registry, Solana transaction log parser, etc.
22
+
23
+ ## Subpath exports
24
+
25
+ ```
26
+ @moon-x/core — core types barrel (rarely used directly)
27
+ @moon-x/core/types — Chain, PublicWallet, AuthAppearance, all wire shapes
28
+ @moon-x/core/utils — PostMessageClient/Server + protocol enums
29
+ @moon-x/core/lib — pure utilities (auth state, passkey, ethereum/*, solana/*)
30
+ @moon-x/core/sdk — DI interfaces + headless SDK factories
31
+ @moon-x/core/web — web platform implementations (iframe transport, WebAuthn)
32
+ @moon-x/core/react — shared React hooks
33
+ @moon-x/core/react/ethereum — chain-specific Ethereum hooks
34
+ @moon-x/core/react/solana — chain-specific Solana hooks
35
+ ```
36
+
37
+ ## License
38
+
39
+ MIT.
@@ -0,0 +1,48 @@
1
+ type RpcUrls = {
2
+ http: readonly string[];
3
+ webSocket?: readonly string[];
4
+ };
5
+ type NativeCurrency = {
6
+ name: string;
7
+ symbol: string;
8
+ decimals: number;
9
+ };
10
+ type BlockExplorer = {
11
+ name: string;
12
+ url: string;
13
+ };
14
+ type Chain = {
15
+ id: number;
16
+ name: string;
17
+ network?: string;
18
+ nativeCurrency: NativeCurrency;
19
+ blockExplorers?: {
20
+ [key: string]: BlockExplorer;
21
+ default: BlockExplorer;
22
+ };
23
+ rpcUrls: {
24
+ [key: string]: RpcUrls;
25
+ default: RpcUrls;
26
+ };
27
+ testnet?: boolean;
28
+ };
29
+ type ChainLikeWithId = {
30
+ id: number;
31
+ };
32
+ type RpcConfig = {
33
+ rpcUrls?: {
34
+ [chainId: number]: string;
35
+ };
36
+ rpcTimeout?: number;
37
+ };
38
+ interface EthereumChainConfig {
39
+ defaultChain?: any;
40
+ supportedChains?: any[];
41
+ rpcs?: {
42
+ 'ethereum:mainnet': {
43
+ rpc: string;
44
+ };
45
+ };
46
+ }
47
+
48
+ export type { BlockExplorer as B, Chain as C, EthereumChainConfig as E, NativeCurrency as N, RpcConfig as R, ChainLikeWithId as a, RpcUrls as b };
@@ -0,0 +1,48 @@
1
+ type RpcUrls = {
2
+ http: readonly string[];
3
+ webSocket?: readonly string[];
4
+ };
5
+ type NativeCurrency = {
6
+ name: string;
7
+ symbol: string;
8
+ decimals: number;
9
+ };
10
+ type BlockExplorer = {
11
+ name: string;
12
+ url: string;
13
+ };
14
+ type Chain = {
15
+ id: number;
16
+ name: string;
17
+ network?: string;
18
+ nativeCurrency: NativeCurrency;
19
+ blockExplorers?: {
20
+ [key: string]: BlockExplorer;
21
+ default: BlockExplorer;
22
+ };
23
+ rpcUrls: {
24
+ [key: string]: RpcUrls;
25
+ default: RpcUrls;
26
+ };
27
+ testnet?: boolean;
28
+ };
29
+ type ChainLikeWithId = {
30
+ id: number;
31
+ };
32
+ type RpcConfig = {
33
+ rpcUrls?: {
34
+ [chainId: number]: string;
35
+ };
36
+ rpcTimeout?: number;
37
+ };
38
+ interface EthereumChainConfig {
39
+ defaultChain?: any;
40
+ supportedChains?: any[];
41
+ rpcs?: {
42
+ 'ethereum:mainnet': {
43
+ rpc: string;
44
+ };
45
+ };
46
+ }
47
+
48
+ export type { BlockExplorer as B, Chain as C, EthereumChainConfig as E, NativeCurrency as N, RpcConfig as R, ChainLikeWithId as a, RpcUrls as b };
@@ -0,0 +1,46 @@
1
+ // src/utils/get-iframe-url.ts
2
+ var DEFAULT_IFRAME_PROJECT_NAME = "moonx-wallet-iframe";
3
+ var joinUrl = (baseUrl, path) => {
4
+ if (!path) return baseUrl;
5
+ const normalizedBase = baseUrl.replace(/\/$/, "");
6
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
7
+ return `${normalizedBase}${normalizedPath}`;
8
+ };
9
+ var withBypass = (url) => {
10
+ const bypass = process.env.NEXT_PUBLIC_VERCEL_PROTECTION_BYPASS;
11
+ if (!bypass) return url;
12
+ const separator = url.includes("?") ? "&" : "?";
13
+ return `${url}${separator}x-vercel-protection-bypass=${bypass}&x-vercel-set-bypass-cookie=samesitenone`;
14
+ };
15
+ var getIframeUrl = (path = "") => {
16
+ if (process.env.NEXT_PUBLIC_VERCEL_ENV === "preview" && process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL) {
17
+ const vercelUrl = process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL.replace(
18
+ /^https?:\/\//,
19
+ ""
20
+ ).replace(/\/$/, "");
21
+ const iframeProjectName = process.env.NEXT_PUBLIC_MOONKEY_IFRAME_PROJECT_NAME || DEFAULT_IFRAME_PROJECT_NAME;
22
+ const iframeUrl = /-git-/.test(vercelUrl) ? vercelUrl.replace(/^[^.]+?-git-/, `${iframeProjectName}-git-`) : (
23
+ // Fallback: legacy `{prefix}-{hash}.vercel.app` style
24
+ vercelUrl.replace(/^[^-]+-/, `${iframeProjectName}-`)
25
+ );
26
+ return withBypass(joinUrl(`https://${iframeUrl}`, path));
27
+ }
28
+ if (process.env.NEXT_PUBLIC_MOONKEY_IFRAME_URL) {
29
+ return joinUrl(process.env.NEXT_PUBLIC_MOONKEY_IFRAME_URL, path);
30
+ }
31
+ return joinUrl("https://iframe.moonx-dev.com", path);
32
+ };
33
+ var getIframeOrigin = (url) => {
34
+ try {
35
+ const urlObj = new URL(url);
36
+ return urlObj.origin;
37
+ } catch (error) {
38
+ console.error("Invalid URL:", url);
39
+ return "";
40
+ }
41
+ };
42
+
43
+ export {
44
+ getIframeUrl,
45
+ getIframeOrigin
46
+ };