@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.
- package/README.md +39 -0
- package/dist/chain-C9dvKXUY.d.mts +48 -0
- package/dist/chain-C9dvKXUY.d.ts +48 -0
- package/dist/chunk-264CEGDS.mjs +46 -0
- package/dist/chunk-CDT4MC7S.mjs +1532 -0
- package/dist/chunk-CMYR6AOY.mjs +0 -0
- package/dist/chunk-GQKIA37O.mjs +20 -0
- package/dist/chunk-IMLBIIJ4.mjs +36 -0
- package/dist/chunk-MOREUKOG.mjs +18 -0
- package/dist/chunk-SOKLPX7V.mjs +270 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +402 -0
- package/dist/index.mjs +33 -0
- package/dist/interfaces-9k0eKCc4.d.ts +120 -0
- package/dist/interfaces-fNhwnCeY.d.mts +120 -0
- package/dist/lib/index.d.mts +410 -0
- package/dist/lib/index.d.ts +410 -0
- package/dist/lib/index.js +1622 -0
- package/dist/lib/index.mjs +89 -0
- package/dist/passkey-cache-B9PT3AWX.d.mts +47 -0
- package/dist/passkey-cache-B9PT3AWX.d.ts +47 -0
- package/dist/passkey-metadata-QqFF2SWQ.d.mts +25 -0
- package/dist/passkey-metadata-QqFF2SWQ.d.ts +25 -0
- package/dist/post-message-C_99BCBh.d.mts +70 -0
- package/dist/post-message-C_99BCBh.d.ts +70 -0
- package/dist/react/ethereum.d.mts +26 -0
- package/dist/react/ethereum.d.ts +26 -0
- package/dist/react/ethereum.js +99 -0
- package/dist/react/ethereum.mjs +56 -0
- package/dist/react/index.d.mts +182 -0
- package/dist/react/index.d.ts +182 -0
- package/dist/react/index.js +586 -0
- package/dist/react/index.mjs +328 -0
- package/dist/react/solana.d.mts +17 -0
- package/dist/react/solana.d.ts +17 -0
- package/dist/react/solana.js +75 -0
- package/dist/react/solana.mjs +35 -0
- package/dist/sdk/index.d.mts +126 -0
- package/dist/sdk/index.d.ts +126 -0
- package/dist/sdk/index.js +864 -0
- package/dist/sdk/index.mjs +579 -0
- package/dist/types/index.d.mts +1190 -0
- package/dist/types/index.d.ts +1190 -0
- package/dist/types/index.js +64 -0
- package/dist/types/index.mjs +10 -0
- package/dist/utils/index.d.mts +11 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +365 -0
- package/dist/utils/index.mjs +25 -0
- package/dist/web/index.d.mts +20 -0
- package/dist/web/index.d.ts +20 -0
- package/dist/web/index.js +470 -0
- package/dist/web/index.mjs +155 -0
- 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
|
+
};
|