@nexus-cross/crossx-sdk-wagmi 3.0.0-beta.3 → 3.0.0-beta.4
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 +60 -206
- package/dist/__tests__/connector.test.d.ts +4 -0
- package/dist/__tests__/connector.test.d.ts.map +1 -1
- package/dist/connector.d.ts +18 -74
- package/dist/connector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +7 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +88 -379
- package/package.json +5 -7
- package/dist/__tests__/provider.test.d.ts +0 -2
- package/dist/__tests__/provider.test.d.ts.map +0 -1
- package/dist/provider.d.ts +0 -37
- package/dist/provider.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,250 +1,104 @@
|
|
|
1
1
|
# @nexus-cross/crossx-sdk-wagmi
|
|
2
2
|
|
|
3
|
-
[wagmi](https://wagmi.sh/) connector for the
|
|
3
|
+
[wagmi](https://wagmi.sh/) connector for the ONEpocket wallet — use standard wagmi hooks (`useAccount`, `useConnect`, `useSignMessage`, `useSendTransaction`, …).
|
|
4
|
+
|
|
5
|
+
**3.0:** the wallet SDK runs inside the ONEpocket secure frame (an iframe). This connector talks to it through the proxy SDK
|
|
6
|
+
([`@nexus-cross/crossx-sdk-proxy`](https://www.npmjs.com/package/@nexus-cross/crossx-sdk-proxy)), so sign-in, PIN and
|
|
7
|
+
signing confirmation screens are shown by the iframe. Tokens, PIN and keys never reach your page. The connector no longer
|
|
8
|
+
depends on `@nexus-cross/crossx-sdk-core`.
|
|
4
9
|
|
|
5
10
|
## Installation
|
|
6
11
|
|
|
7
12
|
```bash
|
|
8
|
-
|
|
9
|
-
# or
|
|
10
|
-
pnpm add @nexus-cross/crossx-sdk-wagmi @nexus-cross/crossx-sdk-core
|
|
13
|
+
pnpm add @nexus-cross/crossx-sdk-wagmi @nexus-cross/crossx-sdk-proxy
|
|
11
14
|
```
|
|
12
15
|
|
|
13
|
-
**Peer dependencies:** `wagmi >=2.0.0`, `viem >=2.0.0
|
|
16
|
+
**Peer dependencies:** `@nexus-cross/crossx-sdk-proxy ^3.0.0-0`, `wagmi >=2.0.0`, `viem >=2.0.0`. In advanced mode, pass a proxy SDK from the same installed package.
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
Your page origin must be registered in the secure frame (its `frame-ancestors` / allowed parent origins).
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
## Quick Start
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
### Simple mode
|
|
20
23
|
|
|
21
24
|
```ts
|
|
22
25
|
import { createConfig, http } from 'wagmi';
|
|
23
|
-
import {
|
|
24
|
-
import type { Chain } from 'viem';
|
|
25
|
-
|
|
26
|
-
const oneMainnet = {
|
|
27
|
-
id: 612055,
|
|
28
|
-
name: 'CROSS Mainnet',
|
|
29
|
-
nativeCurrency: { name: 'CROSS', symbol: 'CROSS', decimals: 18 },
|
|
30
|
-
rpcUrls: { default: { http: ['https://rpc.crossmainnet.io'] } },
|
|
31
|
-
} as const satisfies Chain;
|
|
26
|
+
import { onepocketConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
32
27
|
|
|
33
28
|
const config = createConfig({
|
|
34
29
|
chains: [oneMainnet],
|
|
35
30
|
connectors: [
|
|
36
|
-
|
|
31
|
+
onepocketConnector({
|
|
32
|
+
frameUrl: 'https://onepocket.onechain.nexus/', // secure frame URL for the environment
|
|
37
33
|
projectId: 'your-project-id',
|
|
38
34
|
appName: 'My DApp',
|
|
35
|
+
locale: 'en',
|
|
36
|
+
defaultChainId: 612055,
|
|
39
37
|
}),
|
|
40
38
|
],
|
|
41
|
-
transports: {
|
|
42
|
-
[oneMainnet.id]: http(),
|
|
43
|
-
},
|
|
39
|
+
transports: { [oneMainnet.id]: http() },
|
|
44
40
|
});
|
|
45
41
|
```
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
Create the SDK yourself for full control over configuration, then inject it.
|
|
43
|
+
The proxy SDK (and its hidden iframe) is created when wagmi's `createConfig` sets up the connector — in the browser only; on the server (SSR) `setup` does nothing.
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
import { createConfig, http } from 'wagmi';
|
|
53
|
-
import { createCROSSxSDK, ChainId } from '@nexus-cross/crossx-sdk-core';
|
|
54
|
-
import { createCROSSxConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
45
|
+
### Advanced mode
|
|
55
46
|
|
|
56
|
-
|
|
57
|
-
projectId: 'your-project-id',
|
|
58
|
-
appName: 'My DApp',
|
|
59
|
-
theme: 'dark',
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const config = createConfig({
|
|
63
|
-
chains: [oneMainnet],
|
|
64
|
-
connectors: [
|
|
65
|
-
createCROSSxConnector({
|
|
66
|
-
sdk,
|
|
67
|
-
defaultChainId: ChainId.ONE_MAINNET,
|
|
68
|
-
}),
|
|
69
|
-
],
|
|
70
|
-
transports: {
|
|
71
|
-
[oneMainnet.id]: http(),
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### Use with React
|
|
77
|
-
|
|
78
|
-
```tsx
|
|
79
|
-
import { WagmiProvider } from 'wagmi';
|
|
80
|
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
81
|
-
import { useAccount, useConnect, useDisconnect, useSendTransaction } from 'wagmi';
|
|
82
|
-
|
|
83
|
-
const queryClient = new QueryClient();
|
|
84
|
-
|
|
85
|
-
function App() {
|
|
86
|
-
return (
|
|
87
|
-
<WagmiProvider config={config}>
|
|
88
|
-
<QueryClientProvider client={queryClient}>
|
|
89
|
-
<Wallet />
|
|
90
|
-
</QueryClientProvider>
|
|
91
|
-
</WagmiProvider>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function Wallet() {
|
|
96
|
-
const { address, isConnected } = useAccount();
|
|
97
|
-
const { connect, connectors } = useConnect();
|
|
98
|
-
const { disconnect } = useDisconnect();
|
|
99
|
-
const { sendTransaction } = useSendTransaction();
|
|
100
|
-
|
|
101
|
-
if (isConnected) {
|
|
102
|
-
return (
|
|
103
|
-
<div>
|
|
104
|
-
<p>Connected: {address}</p>
|
|
105
|
-
<button onClick={() => disconnect()}>Disconnect</button>
|
|
106
|
-
<button onClick={() => sendTransaction({
|
|
107
|
-
to: '0x...',
|
|
108
|
-
value: 10000000000000000n, // 0.01 CROSS
|
|
109
|
-
})}>
|
|
110
|
-
Send
|
|
111
|
-
</button>
|
|
112
|
-
</div>
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return (
|
|
117
|
-
<button onClick={() => connect({ connector: connectors[0] })}>
|
|
118
|
-
Connect CROSSx
|
|
119
|
-
</button>
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
---
|
|
125
|
-
|
|
126
|
-
## API Reference
|
|
127
|
-
|
|
128
|
-
### `crossxConnector(options)` — Simple Mode
|
|
129
|
-
|
|
130
|
-
Creates a wagmi connector with automatic SDK creation.
|
|
47
|
+
Create the proxy SDK yourself, e.g. to share it with non-wagmi code.
|
|
131
48
|
|
|
132
49
|
```ts
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
projectId: 'your-project-id', // Required
|
|
136
|
-
appName: 'My DApp', // Required
|
|
137
|
-
theme: 'light',
|
|
138
|
-
themeTokens: { /* ... */ },
|
|
139
|
-
locale: 'en',
|
|
140
|
-
|
|
141
|
-
// Connector options
|
|
142
|
-
defaultChainId: 'eip155:612055',
|
|
143
|
-
getStoredWalletIndex: () => number,
|
|
144
|
-
onWalletIndexChanged: (index: number) => void,
|
|
145
|
-
getStoredWalletAddress: () => string | null,
|
|
146
|
-
onWalletAddressChanged: (address: string) => void,
|
|
147
|
-
openConnectOtherWallet: () => void,
|
|
148
|
-
})
|
|
149
|
-
```
|
|
50
|
+
import { createProxySDK } from '@nexus-cross/crossx-sdk-proxy';
|
|
51
|
+
import { createONEpocketConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
150
52
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
Creates a wagmi connector with an existing SDK instance.
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
createCROSSxConnector({
|
|
157
|
-
sdk: CROSSxSDK, // Required — pre-created SDK instance
|
|
158
|
-
defaultChainId: 'eip155:612055', // Default chain (CROSS Mainnet)
|
|
159
|
-
getStoredWalletIndex: () => number,
|
|
160
|
-
onWalletIndexChanged: (index: number) => void,
|
|
161
|
-
getStoredWalletAddress: () => string | null,
|
|
162
|
-
onWalletAddressChanged: (address: string) => void,
|
|
163
|
-
openConnectOtherWallet: () => void,
|
|
164
|
-
})
|
|
53
|
+
const proxy = createProxySDK({ frameUrl: 'https://onepocket.onechain.nexus/' });
|
|
54
|
+
const connector = createONEpocketConnector({ proxy, projectId: 'your-project-id', appName: 'My DApp' });
|
|
165
55
|
```
|
|
166
56
|
|
|
167
|
-
|
|
57
|
+
The connector calls `proxy.init(...)` once. If you already called it, the connector keeps using that session.
|
|
168
58
|
|
|
169
59
|
## Options
|
|
170
60
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
|
174
|
-
|
|
175
|
-
| `
|
|
176
|
-
| `
|
|
177
|
-
| `
|
|
178
|
-
| `
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
projectId: '...',
|
|
204
|
-
appName: 'MyDApp',
|
|
205
|
-
connectOtherWallets: ['metamask', 'binance'],
|
|
206
|
-
openConnectOtherWallet: () => openConnectModal(),
|
|
207
|
-
})
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
---
|
|
211
|
-
|
|
212
|
-
## Connector Behavior
|
|
213
|
-
|
|
214
|
-
| Feature | Behavior |
|
|
215
|
-
|---------|----------|
|
|
216
|
-
| `connect()` | Opens OAuth sign-in → creates/restores wallet → returns accounts |
|
|
217
|
-
| `disconnect()` | Calls `sdk.signOut()` → clears stored wallet data |
|
|
218
|
-
| `switchChain()` | Updates internal chain ID, emits `change` event |
|
|
219
|
-
| `isAuthorized()` | Waits for SDK ready, then checks `sdk.isAuthenticated()` |
|
|
220
|
-
| Auto-sync | Listens to SDK `authChanged` / `addressChanged` events |
|
|
221
|
-
|
|
222
|
-
---
|
|
61
|
+
| Option | Mode | Description |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| `frameUrl` | simple | Secure frame URL (required) |
|
|
64
|
+
| `readyTimeoutMs` · `requestTimeoutMs` | simple | Proxy SDK timeouts |
|
|
65
|
+
| `proxy` | advanced | Existing proxy SDK (required) |
|
|
66
|
+
| `projectId` | both | Required |
|
|
67
|
+
| `appName` · `theme` · `locale` | both | Passed to the wallet SDK in the iframe |
|
|
68
|
+
| `defaultChainId` | both | Number or CAIP-2 (`'eip155:612044'`). Default: the first of your wagmi `chains` |
|
|
69
|
+
|
|
70
|
+
## Connector behavior
|
|
71
|
+
|
|
72
|
+
| | Behavior |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `connect()` | Sign-in in the iframe → creates the wallet (PIN setup) if there is none → accounts. If a `chainId` is given, switches to it |
|
|
75
|
+
| auto reconnect | Shows no screen. Connects only when the restored session already has a wallet |
|
|
76
|
+
| `disconnect()` | `proxy.signOut()` (ONE ID sign-out in the iframe) |
|
|
77
|
+
| `switchChain()` | Must be in your wagmi `chains` and registered for the project in the iframe, otherwise `SwitchChainError`. The chain is not persisted — after a reload the connector starts on `defaultChainId` |
|
|
78
|
+
| `isAuthorized()` | `true` when the restored session has a wallet address |
|
|
79
|
+
| events | Wallet address change → `change` (checksummed); sign-out elsewhere or iframe reload → `disconnect` (once) |
|
|
80
|
+
| errors | Cancelled screens → viem `UserRejectedRequestError` |
|
|
81
|
+
|
|
82
|
+
Signing goes through the provider of the proxy SDK — see its README for supported JSON-RPC methods
|
|
83
|
+
(`personal_sign`, `eth_signTypedData_v4`, `eth_sendTransaction`, `eth_signTransaction`; `eth_sign` and typed data v1/v3 are not supported).
|
|
84
|
+
Reads go through your wagmi `transports`.
|
|
85
|
+
|
|
86
|
+
## Breaking changes from 2.x
|
|
87
|
+
|
|
88
|
+
- `crossxConnector` options: `frameUrl` is required; core `SDKConfig` fields are no longer accepted.
|
|
89
|
+
- `createCROSSxConnector({ sdk })` → `createCROSSxConnector({ proxy, projectId })`.
|
|
90
|
+
- Removed: `CROSSxEIP1193Provider` / `ONEpocketEIP1193Provider` (use the proxy SDK's `createEthereumProvider`),
|
|
91
|
+
`openConnectOtherWallet` (external wallet rows), wallet index / address persistence callbacks, and the
|
|
92
|
+
in-app-browser JS-injection sign-in wait. Wallet selection and session restore are handled by the secure frame.
|
|
223
93
|
|
|
224
94
|
## Exports
|
|
225
95
|
|
|
226
96
|
```ts
|
|
227
|
-
|
|
228
|
-
export { crossxConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
229
|
-
export {
|
|
230
|
-
|
|
231
|
-
// EIP-1193 Provider (advanced use)
|
|
232
|
-
export { CROSSxEIP1193Provider } from '@nexus-cross/crossx-sdk-wagmi';
|
|
233
|
-
|
|
234
|
-
// Types
|
|
235
|
-
export type { CrossxConnectorOptions } from '@nexus-cross/crossx-sdk-wagmi';
|
|
236
|
-
export type { CROSSxConnectorOptions } from '@nexus-cross/crossx-sdk-wagmi';
|
|
97
|
+
export { onepocketConnector, createONEpocketConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
98
|
+
export { crossxConnector, createCROSSxConnector } from '@nexus-cross/crossx-sdk-wagmi'; // same functions, deprecated names
|
|
99
|
+
export type { OnepocketConnectorOptions, ONEpocketConnectorOptions, CrossxConnectorOptions, CROSSxConnectorOptions } from '@nexus-cross/crossx-sdk-wagmi';
|
|
237
100
|
```
|
|
238
101
|
|
|
239
|
-
---
|
|
240
|
-
|
|
241
|
-
## Related Packages
|
|
242
|
-
|
|
243
|
-
| Package | Description |
|
|
244
|
-
|---------|-------------|
|
|
245
|
-
| [`@nexus-cross/crossx-sdk-core`](https://www.npmjs.com/package/@nexus-cross/crossx-sdk-core) | Core SDK (vanilla JS) |
|
|
246
|
-
| [`@nexus-cross/crossx-sdk-react`](https://www.npmjs.com/package/@nexus-cross/crossx-sdk-react) | React hooks (without wagmi) |
|
|
247
|
-
|
|
248
102
|
## License
|
|
249
103
|
|
|
250
104
|
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/connector.test.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"connector.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/connector.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/dist/connector.d.ts
CHANGED
|
@@ -1,88 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CROSSxEIP1193Provider } from './provider';
|
|
1
|
+
import { ProxyEthereumProvider, ProxyInitConfig, ProxySDK, ProxySDKOptions } from '@nexus-cross/crossx-sdk-proxy';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
sdk: CROSSxSDK;
|
|
3
|
+
interface CommonOptions extends ProxyInitConfig {
|
|
4
|
+
/** 처음 체인. 숫자 또는 CAIP-2(`'eip155:612044'`). 기본은 wagmi `chains` 의 첫 체인 */
|
|
7
5
|
defaultChainId?: string | number;
|
|
8
|
-
/** 저장된 지갑 인덱스를 반환하는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
9
|
-
getStoredWalletIndex?: () => number;
|
|
10
|
-
/** 활성 지갑 인덱스 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
11
|
-
onWalletIndexChanged?: (index: number) => void;
|
|
12
|
-
/** 저장된 지갑 주소를 반환하는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
13
|
-
getStoredWalletAddress?: () => string | null;
|
|
14
|
-
/** 활성 지갑 주소 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
15
|
-
onWalletAddressChanged?: (address: string) => void;
|
|
16
|
-
/** disconnect/signOut 시 저장된 지갑 주소를 제거하는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
17
|
-
clearStoredWalletAddress?: () => void;
|
|
18
|
-
/**
|
|
19
|
-
* 로그인 모달에서 외부 지갑 행 클릭 시 호출되는 콜백.
|
|
20
|
-
*
|
|
21
|
-
* SDK에 `connectOtherWallets` / `showConnectOtherWallets`가 없으면 외부 지갑 구역이 나오지 않습니다.
|
|
22
|
-
* `crossxConnector({ openConnectOtherWallet })`만 주면 `showConnectOtherWallets: true`가 자동 설정되어 Binance·MetaMask·CROSSx 행이 표시됩니다.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* createCROSSxConnector({
|
|
26
|
-
* sdk,
|
|
27
|
-
* openConnectOtherWallet: () => openConnectModal(),
|
|
28
|
-
* })
|
|
29
|
-
*/
|
|
30
|
-
openConnectOtherWallet?: () => void;
|
|
31
6
|
}
|
|
7
|
+
/** 고급 모드: 이미 만든 대리 SDK 를 넘긴다. init 은 커넥터가 한다(이미 했으면 그대로 쓴다) */
|
|
8
|
+
export interface CROSSxConnectorOptions extends CommonOptions {
|
|
9
|
+
proxy: ProxySDK;
|
|
10
|
+
}
|
|
11
|
+
/** 간편 모드: 보안 화면 앱 주소와 설정만 넘기면 커넥터가 대리 SDK 를 만든다 (wagmi createConfig 때, 브라우저에서만) */
|
|
12
|
+
export type CrossxConnectorOptions = CommonOptions & Omit<ProxySDKOptions, 'container'>;
|
|
32
13
|
/**
|
|
33
|
-
* 간편
|
|
34
|
-
* 이 모드로 만든 SDK 는 화면이 없다(headless) — PIN · 서명 확인이 필요하면
|
|
35
|
-
* `@nexus-cross/crossx-sdk-core/internal` 의 `createCROSSxSDKWithOverrides(config, { ui })` 로 SDK 를 만들어
|
|
36
|
-
* 고급 모드(`createCROSSxConnector({ sdk })`)로 넘긴다 (DEV2TF-2321).
|
|
37
|
-
*/
|
|
38
|
-
export type CrossxConnectorOptions = Omit<SDKConfig, 'useMockWallet'> & {
|
|
39
|
-
defaultChainId?: string | number;
|
|
40
|
-
/** 저장된 지갑 인덱스를 반환하는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
41
|
-
getStoredWalletIndex?: () => number;
|
|
42
|
-
/** 활성 지갑 인덱스 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
43
|
-
onWalletIndexChanged?: (index: number) => void;
|
|
44
|
-
/** 저장된 지갑 주소를 반환하는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
45
|
-
getStoredWalletAddress?: () => string | null;
|
|
46
|
-
/** 활성 지갑 주소 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
47
|
-
onWalletAddressChanged?: (address: string) => void;
|
|
48
|
-
/** disconnect/signOut 시 저장된 지갑 주소를 제거하는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
49
|
-
clearStoredWalletAddress?: () => void;
|
|
50
|
-
/**
|
|
51
|
-
* 로그인 모달에서 외부 지갑 행 클릭 시 호출되는 콜백.
|
|
52
|
-
*
|
|
53
|
-
* 제공 시 `showConnectOtherWallets`·`connectOtherWallets`가 없으면 `showConnectOtherWallets: true`가 자동 적용되며,
|
|
54
|
-
* SDK의 `connectExternalWallet` 이벤트에 자동 등록됩니다.
|
|
55
|
-
* 일부 지갑만 쓰려면 `connectOtherWallets: [ ... ]`로 좁히면 됩니다.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* crossxConnector({
|
|
59
|
-
* projectId: '...',
|
|
60
|
-
* appName: 'MyDApp',
|
|
61
|
-
* openConnectOtherWallet: () => openConnectModal(),
|
|
62
|
-
* })
|
|
63
|
-
*/
|
|
64
|
-
openConnectOtherWallet?: () => void;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* 간편 모드 커넥터 — SDK 설정만 전달하면 내부에서 SDK를 생성
|
|
14
|
+
* 간편 모드 커넥터
|
|
68
15
|
*
|
|
69
|
-
* @deprecated ONEpocket 리브랜드 — {@link onepocketConnector}를 사용하세요. 동작은
|
|
70
|
-
* 이 이름은 향후 major 버전에서 제거될 예정입니다.
|
|
16
|
+
* @deprecated ONEpocket 리브랜드 — {@link onepocketConnector}를 사용하세요. 동작은 같습니다.
|
|
71
17
|
*/
|
|
72
|
-
export declare function crossxConnector(options: CrossxConnectorOptions): import('wagmi').CreateConnectorFn<
|
|
18
|
+
export declare function crossxConnector(options: CrossxConnectorOptions): import('wagmi').CreateConnectorFn<ProxyEthereumProvider, Record<string, unknown>, Record<string, unknown>>;
|
|
73
19
|
/**
|
|
74
|
-
* 고급 모드 커넥터
|
|
20
|
+
* 고급 모드 커넥터
|
|
75
21
|
*
|
|
76
|
-
* @deprecated ONEpocket 리브랜드 — {@link createONEpocketConnector}를 사용하세요. 동작은
|
|
77
|
-
* 이 이름은 향후 major 버전에서 제거될 예정입니다.
|
|
22
|
+
* @deprecated ONEpocket 리브랜드 — {@link createONEpocketConnector}를 사용하세요. 동작은 같습니다.
|
|
78
23
|
*/
|
|
79
|
-
export declare function createCROSSxConnector(options: CROSSxConnectorOptions): import('wagmi').CreateConnectorFn<
|
|
80
|
-
/** 간편 모드 커넥터 (
|
|
24
|
+
export declare function createCROSSxConnector(options: CROSSxConnectorOptions): import('wagmi').CreateConnectorFn<ProxyEthereumProvider, Record<string, unknown>, Record<string, unknown>>;
|
|
25
|
+
/** 간편 모드 커넥터 (crossxConnector 와 같음) */
|
|
81
26
|
export declare const onepocketConnector: typeof crossxConnector;
|
|
82
|
-
/** 고급 모드 커넥터 (
|
|
27
|
+
/** 고급 모드 커넥터 (createCROSSxConnector 와 같음) */
|
|
83
28
|
export declare const createONEpocketConnector: typeof createCROSSxConnector;
|
|
84
|
-
/** 간편 모드 옵션 (ONEpocket 리브랜드 이름 — CrossxConnectorOptions와 동일) */
|
|
85
29
|
export type OnepocketConnectorOptions = CrossxConnectorOptions;
|
|
86
|
-
/** 고급 모드 옵션 (ONEpocket 리브랜드 이름 — CROSSxConnectorOptions와 동일) */
|
|
87
30
|
export type ONEpocketConnectorOptions = CROSSxConnectorOptions;
|
|
31
|
+
export {};
|
|
88
32
|
//# sourceMappingURL=connector.d.ts.map
|
package/dist/connector.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAGL,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,eAAe,EACrB,MAAM,+BAA+B,CAAC;AAQvC,UAAU,aAAc,SAAQ,eAAe;IAC7C,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC;AAED,+DAA+D;AAC/D,MAAM,WAAW,sBAAuB,SAAQ,aAAa;IAC3D,KAAK,EAAE,QAAQ,CAAC;CACjB;AAED,mFAAmF;AACnF,MAAM,MAAM,sBAAsB,GAAG,aAAa,GAAG,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;AAaxF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAG9D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAEpE;AAmKD,uCAAuC;AACvC,eAAO,MAAM,kBAAkB,EAAE,OAAO,eAAiC,CAAC;AAE1E,6CAA6C;AAC7C,eAAO,MAAM,wBAAwB,EAAE,OAAO,qBAA6C,CAAC;AAE5F,MAAM,MAAM,yBAAyB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,MAAM,yBAAyB,GAAG,sBAAsB,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("wagmi"),m=require("viem"),_=require("@nexus-cross/crossx-sdk-proxy"),R=612055,P="ONEpocket";function k(n){var c;const t=typeof n=="number"?n:Number((c=/^eip155:(\d+)$/.exec(n))==null?void 0:c[1]);if(!Number.isSafeInteger(t)||t<=0)throw new Error(`invalid defaultChainId: ${String(n)}`);return t}function b(n){const{projectId:t,appName:c,theme:a,locale:i}=n;return{projectId:t,appName:c,theme:a,locale:i}}function q(n){const{frameUrl:t,readyTimeoutMs:c,requestTimeoutMs:a,defaultChainId:i}=n;return O(()=>_.createProxySDK({frameUrl:t,readyTimeoutMs:c,requestTimeoutMs:a}),b(n),i)}function D(n){return O(()=>n.proxy,b(n),n.defaultChainId)}const E=n=>n.map(t=>m.getAddress(t));function L(n){const t=n==null?void 0:n.code;return t===4001?new m.UserRejectedRequestError(n):t===4902?new m.SwitchChainError(n):n}function O(n,t,c){const a=c===void 0?void 0:k(c);let i,s=null,g=null,h=null,r=null;function u(){return g||(s=n(),g=_.createEthereumProvider(s,{chainId:a??i??R}),s.onFrameReloaded(()=>{h=null})),g}function y(){return u(),h??(h=s.init(t).then(()=>{},o=>{if((o==null?void 0:o.code)!=="ALREADY_INITIALIZED")throw h=null,o})),h}async function d(o,l){await y();try{return await u().request({method:o,params:l})}catch(C){throw L(C)}}async function p(){return Number(await u().request({method:"eth_chainId"}))}return N.createConnector(o=>{var C;i??(i=(C=o.chains[0])==null?void 0:C.id);async function l(e){const w=o.chains.find(f=>f.id===e);if(!w)throw new m.SwitchChainError(new N.ChainNotConfiguredError);return await d("wallet_switchEthereumChain",[{chainId:`0x${e.toString(16)}`}]),w}return{id:"crossx",name:P,type:"crossx",async setup(){if(!(typeof window>"u"||typeof document>"u"))try{await y()}catch{}},async connect({chainId:e,isReconnecting:w}={}){const f=E(await d(w?"eth_accounts":"eth_requestAccounts"));if(f.length===0)throw new Error("CROSSx: no wallet session to restore");r==null||r();const x=u(),A=I=>this.onAccountsChanged(I),S=I=>this.onChainChanged(I),v=()=>this.onDisconnect();return x.on("accountsChanged",A).on("chainChanged",S).on("disconnect",v),r=()=>{x.removeListener("accountsChanged",A).removeListener("chainChanged",S).removeListener("disconnect",v),r=null},e!==void 0&&e!==await p()&&await l(e),{accounts:f,chainId:await p()}},async disconnect(){r==null||r(),await y(),await s.signOut()},async getAccounts(){return E(await d("eth_accounts"))},async getChainId(){return p()},async getProvider(){return u()},async isAuthorized(){try{return(await d("eth_accounts")).length>0}catch{return!1}},async switchChain({chainId:e}){return l(e)},onAccountsChanged(e){e.length!==0&&o.emitter.emit("change",{accounts:E(e)})},onChainChanged(e){o.emitter.emit("change",{chainId:Number(e)})},onDisconnect(){r==null||r(),o.emitter.emit("disconnect")}}})}const T=q,M=D;exports.createCROSSxConnector=D;exports.createONEpocketConnector=M;exports.crossxConnector=q;exports.onepocketConnector=T;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,31 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @nexus-cross/crossx-sdk-wagmi
|
|
2
|
+
* @nexus-cross/crossx-sdk-wagmi — 3.0 (DEV2TF-2782)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* ONEpocket 지갑을 wagmi 에 붙이는 Connector. 지갑 SDK 는 보안 화면 앱 iframe 에서 돌고,
|
|
5
|
+
* 이 패키지는 대리 SDK(`@nexus-cross/crossx-sdk-proxy`)의 EIP-1193 provider 를 쓴다.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
* import { crossxConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
7
|
+
* import { onepocketConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
8
8
|
* const config = createConfig({
|
|
9
9
|
* chains: [oneMainnet],
|
|
10
|
-
* connectors: [
|
|
11
|
-
* transports: { [oneMainnet.id]: http() },
|
|
12
|
-
* });
|
|
13
|
-
*
|
|
14
|
-
* 고급 모드 (SDK 직접 주입):
|
|
15
|
-
* import { createCROSSxConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
16
|
-
* import { createCROSSxSDK } from '@nexus-cross/crossx-sdk-core';
|
|
17
|
-
* const sdk = createCROSSxSDK({ projectId: 'YOUR_ID' });
|
|
18
|
-
* const config = createConfig({
|
|
19
|
-
* chains: [oneMainnet],
|
|
20
|
-
* connectors: [createCROSSxConnector({ sdk })],
|
|
10
|
+
* connectors: [onepocketConnector({ frameUrl: 'https://onepocket.onechain.nexus/', projectId: 'YOUR_ID' })],
|
|
21
11
|
* transports: { [oneMainnet.id]: http() },
|
|
22
12
|
* });
|
|
23
13
|
*/
|
|
24
|
-
export { crossxConnector, createCROSSxConnector } from './connector';
|
|
25
|
-
export type { CrossxConnectorOptions, CROSSxConnectorOptions, } from './connector';
|
|
26
|
-
export { CROSSxEIP1193Provider } from './provider';
|
|
27
|
-
export type { EIP1193RequestArguments } from './provider';
|
|
28
|
-
export { onepocketConnector, createONEpocketConnector } from './connector';
|
|
29
|
-
export type { OnepocketConnectorOptions, ONEpocketConnectorOptions, } from './connector';
|
|
30
|
-
export { CROSSxEIP1193Provider as ONEpocketEIP1193Provider } from './provider';
|
|
14
|
+
export { crossxConnector, createCROSSxConnector, onepocketConnector, createONEpocketConnector } from './connector';
|
|
15
|
+
export type { CrossxConnectorOptions, CROSSxConnectorOptions, OnepocketConnectorOptions, ONEpocketConnectorOptions, } from './connector';
|
|
31
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACnH,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,415 +1,124 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import { UserRejectedRequestError as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createConnector as S, ChainNotConfiguredError as b } from "wagmi";
|
|
2
|
+
import { SwitchChainError as x, getAddress as R, UserRejectedRequestError as q } from "viem";
|
|
3
|
+
import { createProxySDK as L, createEthereumProvider as O } from "@nexus-cross/crossx-sdk-proxy";
|
|
4
|
+
const P = 612055, T = "ONEpocket";
|
|
5
|
+
function k(n) {
|
|
6
|
+
var c;
|
|
7
|
+
const t = typeof n == "number" ? n : Number((c = /^eip155:(\d+)$/.exec(n)) == null ? void 0 : c[1]);
|
|
8
|
+
if (!Number.isSafeInteger(t) || t <= 0) throw new Error(`invalid defaultChainId: ${String(n)}`);
|
|
9
|
+
return t;
|
|
6
10
|
}
|
|
7
|
-
function
|
|
8
|
-
|
|
11
|
+
function _(n) {
|
|
12
|
+
const { projectId: t, appName: c, theme: a, locale: i } = n;
|
|
13
|
+
return { projectId: t, appName: c, theme: a, locale: i };
|
|
9
14
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
15
|
+
function M(n) {
|
|
16
|
+
const { frameUrl: t, readyTimeoutMs: c, requestTimeoutMs: a, defaultChainId: i } = n;
|
|
17
|
+
return D(() => L({ frameUrl: t, readyTimeoutMs: c, requestTimeoutMs: a }), _(n), i);
|
|
12
18
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
for (let n = 0; n < i.length; n++)
|
|
16
|
-
i[n] = parseInt(t.substring(n * 2, n * 2 + 2), 16);
|
|
17
|
-
return new TextDecoder().decode(i);
|
|
19
|
+
function U(n) {
|
|
20
|
+
return D(() => n.proxy, _(n), n.defaultChainId);
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const I = (n) => n.map((t) => R(t));
|
|
23
|
+
function $(n) {
|
|
24
|
+
const t = n == null ? void 0 : n.code;
|
|
25
|
+
return t === 4001 ? new q(n) : t === 4902 ? new x(n) : n;
|
|
26
|
+
}
|
|
27
|
+
function D(n, t, c) {
|
|
28
|
+
const a = c === void 0 ? void 0 : k(c);
|
|
29
|
+
let i, s = null, w = null, h = null, r = null;
|
|
30
|
+
function u() {
|
|
31
|
+
return w || (s = n(), w = O(s, { chainId: a ?? i ?? P }), s.onFrameReloaded(() => {
|
|
32
|
+
h = null;
|
|
33
|
+
})), w;
|
|
34
|
+
}
|
|
35
|
+
function g() {
|
|
36
|
+
return u(), h ?? (h = s.init(t).then(
|
|
37
|
+
() => {
|
|
38
|
+
},
|
|
39
|
+
(o) => {
|
|
40
|
+
if ((o == null ? void 0 : o.code) !== "ALREADY_INITIALIZED")
|
|
41
|
+
throw h = null, o;
|
|
42
|
+
}
|
|
43
|
+
)), h;
|
|
28
44
|
}
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
async function d(o, l) {
|
|
46
|
+
await g();
|
|
31
47
|
try {
|
|
32
|
-
return await
|
|
33
|
-
} catch (
|
|
34
|
-
throw
|
|
35
|
-
new Error("User rejected the request"),
|
|
36
|
-
{ code: 4001, data: n.details }
|
|
37
|
-
) : n;
|
|
48
|
+
return await u().request({ method: o, params: l });
|
|
49
|
+
} catch (f) {
|
|
50
|
+
throw $(f);
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
|
-
async
|
|
41
|
-
|
|
42
|
-
const n = i ?? [];
|
|
43
|
-
switch (t) {
|
|
44
|
-
// ── 계정 ──────────────────────────────────────────────────────────────
|
|
45
|
-
case "eth_requestAccounts":
|
|
46
|
-
case "eth_accounts": {
|
|
47
|
-
if (this.currentAccounts.length > 0)
|
|
48
|
-
return [...this.currentAccounts];
|
|
49
|
-
const e = await this.sdk.getAddress();
|
|
50
|
-
return e ? [e.address] : [];
|
|
51
|
-
}
|
|
52
|
-
// ── 체인 ──────────────────────────────────────────────────────────────
|
|
53
|
-
case "eth_chainId":
|
|
54
|
-
return q(this.chainId);
|
|
55
|
-
case "net_version":
|
|
56
|
-
return String(this.chainId);
|
|
57
|
-
// ── personal_sign ─────────────────────────────────────────────────────
|
|
58
|
-
case "personal_sign": {
|
|
59
|
-
const [e] = n, o = e.startsWith("0x") ? F(e) : e;
|
|
60
|
-
return (await this.sdk.signMessage(
|
|
61
|
-
k(this.chainId),
|
|
62
|
-
o,
|
|
63
|
-
{ index: this.walletIndex }
|
|
64
|
-
)).signature;
|
|
65
|
-
}
|
|
66
|
-
case "eth_sign": {
|
|
67
|
-
const [, e] = n, o = e.startsWith("0x") ? F(e) : e;
|
|
68
|
-
return (await this.sdk.signMessage(
|
|
69
|
-
k(this.chainId),
|
|
70
|
-
o,
|
|
71
|
-
{ index: this.walletIndex }
|
|
72
|
-
)).signature;
|
|
73
|
-
}
|
|
74
|
-
// ── EIP-712 Typed Data ────────────────────────────────────────────────
|
|
75
|
-
case "eth_signTypedData":
|
|
76
|
-
case "eth_signTypedData_v3":
|
|
77
|
-
case "eth_signTypedData_v4": {
|
|
78
|
-
const [, e] = n, o = typeof e == "string" ? JSON.parse(e) : e, f = (u = o == null ? void 0 : o.domain) == null ? void 0 : u.chainId, m = f == null || f === 0, A = m ? 0 : Number(f), p = { index: this.walletIndex };
|
|
79
|
-
return (m ? await this.sdk.signTypedDataOffchain(o, p) : await this.sdk.signTypedData(k(A), o, p)).signature;
|
|
80
|
-
}
|
|
81
|
-
// ── 트랜잭션 전송 ─────────────────────────────────────────────────────
|
|
82
|
-
case "eth_sendTransaction": {
|
|
83
|
-
const [e] = n, o = k(this.chainId);
|
|
84
|
-
return (await this.sdk.sendTransaction(o, {
|
|
85
|
-
from: e.from,
|
|
86
|
-
to: e.to,
|
|
87
|
-
value: e.value,
|
|
88
|
-
data: e.data,
|
|
89
|
-
gasLimit: e.gasLimit ?? e.gas,
|
|
90
|
-
gasPrice: e.gasPrice,
|
|
91
|
-
maxFeePerGas: e.maxFeePerGas,
|
|
92
|
-
maxPriorityFeePerGas: e.maxPriorityFeePerGas,
|
|
93
|
-
nonce: e.nonce !== void 0 ? parseInt(String(e.nonce), 16) : void 0,
|
|
94
|
-
chainId: this.chainId
|
|
95
|
-
}, { index: this.walletIndex })).txHash;
|
|
96
|
-
}
|
|
97
|
-
// ── 체인 전환 ─────────────────────────────────────────────────────────
|
|
98
|
-
case "wallet_switchEthereumChain": {
|
|
99
|
-
const [{ chainId: e }] = n, o = parseInt(e, 16);
|
|
100
|
-
return o !== this.chainId && (this.chainId = o, this.emit("chainChanged", q(o))), null;
|
|
101
|
-
}
|
|
102
|
-
case "wallet_addEthereumChain":
|
|
103
|
-
return null;
|
|
104
|
-
// ── 그 외 읽기 RPC → SDK walletRpc 프록시 ────────────────────────────
|
|
105
|
-
default:
|
|
106
|
-
return this.sdk.walletRpc(t, n, k(this.chainId));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
|
|
110
|
-
on(t, i) {
|
|
111
|
-
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(i), this;
|
|
112
|
-
}
|
|
113
|
-
removeListener(t, i) {
|
|
114
|
-
var n;
|
|
115
|
-
return (n = this.listeners.get(t)) == null || n.delete(i), this;
|
|
116
|
-
}
|
|
117
|
-
emit(t, ...i) {
|
|
118
|
-
var n;
|
|
119
|
-
(n = this.listeners.get(t)) == null || n.forEach((u) => u(...i));
|
|
120
|
-
}
|
|
121
|
-
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
122
|
-
notifyAccountsChanged(t) {
|
|
123
|
-
this.currentAccounts = t, this.emit("accountsChanged", t);
|
|
124
|
-
}
|
|
125
|
-
notifyDisconnect(t) {
|
|
126
|
-
this.currentAccounts = [], this.walletIndex = 0, this.emit("disconnect", t);
|
|
127
|
-
}
|
|
128
|
-
getCurrentChainId() {
|
|
129
|
-
return this.chainId;
|
|
130
|
-
}
|
|
131
|
-
setChainId(t) {
|
|
132
|
-
t !== this.chainId && (this.chainId = t, this.emit("chainChanged", q(t)));
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* 활성 지갑 인덱스 설정.
|
|
136
|
-
* Provider가 SDK 메서드를 호출할 때 이 인덱스를 전달합니다.
|
|
137
|
-
*/
|
|
138
|
-
setWalletIndex(t) {
|
|
139
|
-
var i;
|
|
140
|
-
this.walletIndex = t, (i = this.walletIndexChangeCallback) == null || i.call(this, t);
|
|
141
|
-
}
|
|
142
|
-
getWalletIndex() {
|
|
143
|
-
return this.walletIndex;
|
|
144
|
-
}
|
|
145
|
-
getCurrentAccounts() {
|
|
146
|
-
return [...this.currentAccounts];
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function et(r) {
|
|
150
|
-
return typeof r == "number" ? r : parseInt(r.split(":")[1] ?? "1", 10);
|
|
151
|
-
}
|
|
152
|
-
const M = "crossx-wallet-index";
|
|
153
|
-
function nt() {
|
|
154
|
-
try {
|
|
155
|
-
const r = typeof window < "u" ? localStorage.getItem(M) : null;
|
|
156
|
-
return r && Number(r) || 0;
|
|
157
|
-
} catch {
|
|
158
|
-
return 0;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
function st(r) {
|
|
162
|
-
try {
|
|
163
|
-
typeof window < "u" && localStorage.setItem(M, String(r));
|
|
164
|
-
} catch {
|
|
53
|
+
async function y() {
|
|
54
|
+
return Number(await u().request({ method: "eth_chainId" }));
|
|
165
55
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
const U = "crossx-wallet-address";
|
|
174
|
-
function rt() {
|
|
175
|
-
try {
|
|
176
|
-
return typeof window < "u" ? localStorage.getItem(U) : null;
|
|
177
|
-
} catch {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
function at(r) {
|
|
182
|
-
try {
|
|
183
|
-
typeof window < "u" && localStorage.setItem(U, r);
|
|
184
|
-
} catch {
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function it() {
|
|
188
|
-
try {
|
|
189
|
-
typeof window < "u" && localStorage.removeItem(U);
|
|
190
|
-
} catch {
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function ot(r) {
|
|
194
|
-
const { defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress: u, onWalletAddressChanged: e, clearStoredWalletAddress: o, openConnectOtherWallet: f, ...m } = r;
|
|
195
|
-
if (f) {
|
|
196
|
-
const p = m.connectOtherWallets, E = Array.isArray(p) && p.length > 0, x = m.showConnectOtherWallets === !0;
|
|
197
|
-
!E && !x && (m.showConnectOtherWallets = !0);
|
|
198
|
-
}
|
|
199
|
-
const A = V(m);
|
|
200
|
-
return Y({ sdk: A, defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress: u, onWalletAddressChanged: e, clearStoredWalletAddress: o, openConnectOtherWallet: f });
|
|
201
|
-
}
|
|
202
|
-
function Y(r) {
|
|
203
|
-
const {
|
|
204
|
-
sdk: t,
|
|
205
|
-
defaultChainId: i = K.ONE_MAINNET,
|
|
206
|
-
getStoredWalletIndex: n = nt,
|
|
207
|
-
onWalletIndexChanged: u = st,
|
|
208
|
-
getStoredWalletAddress: e = rt,
|
|
209
|
-
onWalletAddressChanged: o = at,
|
|
210
|
-
clearStoredWalletAddress: f = it,
|
|
211
|
-
openConnectOtherWallet: m
|
|
212
|
-
} = r, A = et(i);
|
|
213
|
-
let p = null, E = !1, x = null, z = !1, D = !1, P = !1, y = null, v = !1;
|
|
214
|
-
function N(I) {
|
|
215
|
-
const W = y;
|
|
216
|
-
return W ? (y = null, v = !1, W(I), !0) : !1;
|
|
217
|
-
}
|
|
218
|
-
function C() {
|
|
219
|
-
return p || (p = new tt(t, A), p._setWalletIndexChangeCallback(u)), p;
|
|
220
|
-
}
|
|
221
|
-
return B((I) => {
|
|
222
|
-
function W(s) {
|
|
223
|
-
if (z) return;
|
|
224
|
-
const l = C();
|
|
225
|
-
l.on("accountsChanged", s.onAccountsChanged.bind(s)), l.on("chainChanged", s.onChainChanged.bind(s)), l.on("disconnect", s.onDisconnect.bind(s)), z = !0;
|
|
226
|
-
}
|
|
227
|
-
function L(s) {
|
|
228
|
-
const l = C();
|
|
229
|
-
l.notifyAccountsChanged([s]), I.emitter.emit("connect", {
|
|
230
|
-
accounts: [s],
|
|
231
|
-
chainId: l.getCurrentChainId()
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
async function G() {
|
|
235
|
-
if (!E)
|
|
236
|
-
return x || (x = (async () => {
|
|
237
|
-
const s = n(), l = e() ?? void 0;
|
|
238
|
-
await t.initialize({ preferredWalletIndex: s, preferredWalletAddress: l }), t.on("addressChanged", ({ address: a, index: d }) => {
|
|
239
|
-
if (D) {
|
|
240
|
-
v && a && t.isAuthenticated() && y && (C().setWalletIndex(d), o(a), N(a));
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
const R = C();
|
|
244
|
-
R.setWalletIndex(d), a && (o(a), t.isAuthenticated() ? L(a) : R.notifyAccountsChanged([a]));
|
|
245
|
-
}), t.on("authChanged", (a) => {
|
|
246
|
-
if (a.isAuthenticated && a.source === "external" && y) {
|
|
247
|
-
if (a.address) {
|
|
248
|
-
N(a.address);
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
v = !0, t.getAddress().then((d) => {
|
|
252
|
-
d != null && d.address && t.isAuthenticated() && N(d.address);
|
|
253
|
-
}).catch(() => {
|
|
254
|
-
});
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
if (!(D || P)) {
|
|
258
|
-
if (a.isAuthenticated) {
|
|
259
|
-
if (a.address) {
|
|
260
|
-
L(a.address);
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
t.getAddress().then((d) => {
|
|
264
|
-
d != null && d.address && t.isAuthenticated() && L(d.address);
|
|
265
|
-
}).catch(() => {
|
|
266
|
-
});
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
C().notifyDisconnect(), j(), f(), u(0), I.emitter.emit("disconnect");
|
|
270
|
-
}
|
|
271
|
-
}), m && t.on("connectExternalWallet", m), E = !0;
|
|
272
|
-
})().finally(() => {
|
|
273
|
-
x = null;
|
|
274
|
-
}), x);
|
|
56
|
+
return S((o) => {
|
|
57
|
+
var f;
|
|
58
|
+
i ?? (i = (f = o.chains[0]) == null ? void 0 : f.id);
|
|
59
|
+
async function l(e) {
|
|
60
|
+
const m = o.chains.find((C) => C.id === e);
|
|
61
|
+
if (!m) throw new x(new b());
|
|
62
|
+
return await d("wallet_switchEthereumChain", [{ chainId: `0x${e.toString(16)}` }]), m;
|
|
275
63
|
}
|
|
276
64
|
return {
|
|
277
65
|
id: "crossx",
|
|
278
|
-
name:
|
|
66
|
+
name: T,
|
|
279
67
|
type: "crossx",
|
|
280
68
|
async setup() {
|
|
281
|
-
|
|
282
|
-
},
|
|
283
|
-
// ── connect ─────────────────────────────────────────────────────────────
|
|
284
|
-
async connect({ chainId: s, isReconnecting: l } = {}) {
|
|
285
|
-
const a = s ?? A;
|
|
286
|
-
D = !0;
|
|
287
|
-
const d = new Promise((w) => {
|
|
288
|
-
y = w;
|
|
289
|
-
}), R = this, $ = async () => {
|
|
290
|
-
await G(), W(R);
|
|
291
|
-
const w = C();
|
|
292
|
-
if (t.isAuthenticated()) {
|
|
293
|
-
const c = await t.getAddress();
|
|
294
|
-
if (c)
|
|
295
|
-
return w.setWalletIndex(c.index), w.notifyAccountsChanged([c.address]), {
|
|
296
|
-
accounts: [c.address],
|
|
297
|
-
chainId: a
|
|
298
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
299
|
-
};
|
|
300
|
-
if (l)
|
|
301
|
-
throw new Error(
|
|
302
|
-
"CROSSx reconnect: authenticated session has no active wallet address"
|
|
303
|
-
);
|
|
304
|
-
await t.signOut().catch(() => {
|
|
305
|
-
}), w.notifyDisconnect();
|
|
306
|
-
}
|
|
307
|
-
if (l)
|
|
308
|
-
throw new Error("CROSSx reconnect: no authenticated session to restore");
|
|
309
|
-
const _ = e();
|
|
310
|
-
let g;
|
|
69
|
+
if (!(typeof window > "u" || typeof document > "u"))
|
|
311
70
|
try {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
});
|
|
315
|
-
} catch (c) {
|
|
316
|
-
throw c instanceof H && c.code === J.EXTERNAL_WALLET_REQUESTED ? (w.notifyDisconnect(), new Q(c)) : (t.isAuthenticated() || (w.notifyDisconnect(), I.emitter.emit("disconnect")), c);
|
|
317
|
-
}
|
|
318
|
-
if (!g.success)
|
|
319
|
-
throw new Error(g.error ?? "CROSSx sign-in failed");
|
|
320
|
-
const h = g.address, S = g.addresses.map((c) => c.address).filter((c) => !h || c.toLowerCase() !== h.toLowerCase()), T = h ? [h, ...S] : S;
|
|
321
|
-
if (T.length === 0)
|
|
322
|
-
throw new Error("No address found after sign-in");
|
|
323
|
-
const O = g.addresses.find(
|
|
324
|
-
(c) => h && c.address.toLowerCase() === h.toLowerCase()
|
|
325
|
-
), b = (O == null ? void 0 : O.index) ?? 0;
|
|
326
|
-
return w.setWalletIndex(b), w.notifyAccountsChanged(T), h && o(h), {
|
|
327
|
-
accounts: T,
|
|
328
|
-
chainId: a
|
|
329
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
330
|
-
};
|
|
331
|
-
};
|
|
332
|
-
try {
|
|
333
|
-
const w = $();
|
|
334
|
-
w.catch(() => {
|
|
335
|
-
});
|
|
336
|
-
const _ = await Promise.race([
|
|
337
|
-
w.then((g) => ({ kind: "inner", value: g })),
|
|
338
|
-
d.then((g) => ({ kind: "external", address: g }))
|
|
339
|
-
]);
|
|
340
|
-
if (_.kind === "external") {
|
|
341
|
-
const g = C(), h = await t.getAddress().catch(() => null), S = (h == null ? void 0 : h.address) ?? _.address, O = (await t.getAddresses().catch(() => [])).map((c) => c.address).filter((c) => c.toLowerCase() !== S.toLowerCase()), b = [S, ...O];
|
|
342
|
-
return g.setWalletIndex((h == null ? void 0 : h.index) ?? 0), g.notifyAccountsChanged(b), o(S), {
|
|
343
|
-
accounts: b,
|
|
344
|
-
chainId: a
|
|
345
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
346
|
-
};
|
|
71
|
+
await g();
|
|
72
|
+
} catch {
|
|
347
73
|
}
|
|
348
|
-
return _.value;
|
|
349
|
-
} finally {
|
|
350
|
-
D = !1, y = null, v = !1;
|
|
351
|
-
}
|
|
352
74
|
},
|
|
353
|
-
|
|
75
|
+
async connect({ chainId: e, isReconnecting: m } = {}) {
|
|
76
|
+
const C = I(await d(m ? "eth_accounts" : "eth_requestAccounts"));
|
|
77
|
+
if (C.length === 0) throw new Error("CROSSx: no wallet session to restore");
|
|
78
|
+
r == null || r();
|
|
79
|
+
const A = u(), E = (p) => this.onAccountsChanged(p), N = (p) => this.onChainChanged(p), v = () => this.onDisconnect();
|
|
80
|
+
return A.on("accountsChanged", E).on("chainChanged", N).on("disconnect", v), r = () => {
|
|
81
|
+
A.removeListener("accountsChanged", E).removeListener("chainChanged", N).removeListener("disconnect", v), r = null;
|
|
82
|
+
}, e !== void 0 && e !== await y() && await l(e), { accounts: C, chainId: await y() };
|
|
83
|
+
},
|
|
354
84
|
async disconnect() {
|
|
355
|
-
|
|
356
|
-
try {
|
|
357
|
-
const s = C();
|
|
358
|
-
await t.signOut(), s.notifyDisconnect(), j(), f(), u(0), I.emitter.emit("disconnect");
|
|
359
|
-
} finally {
|
|
360
|
-
P = !1;
|
|
361
|
-
}
|
|
85
|
+
r == null || r(), await g(), await s.signOut();
|
|
362
86
|
},
|
|
363
|
-
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
364
87
|
async getAccounts() {
|
|
365
|
-
|
|
366
|
-
if (l.length > 0) return l;
|
|
367
|
-
const a = await t.getAddress();
|
|
368
|
-
return a ? [a.address] : [];
|
|
88
|
+
return I(await d("eth_accounts"));
|
|
369
89
|
},
|
|
370
|
-
// ── getChainId ──────────────────────────────────────────────────────────
|
|
371
90
|
async getChainId() {
|
|
372
|
-
return
|
|
91
|
+
return y();
|
|
373
92
|
},
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
return C();
|
|
93
|
+
async getProvider() {
|
|
94
|
+
return u();
|
|
377
95
|
},
|
|
378
|
-
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
379
96
|
async isAuthorized() {
|
|
380
|
-
|
|
97
|
+
try {
|
|
98
|
+
return (await d("eth_accounts")).length > 0;
|
|
99
|
+
} catch {
|
|
100
|
+
return !1;
|
|
101
|
+
}
|
|
381
102
|
},
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
C().setChainId(s), I.emitter.emit("change", { chainId: s });
|
|
385
|
-
const a = I.chains.find((d) => d.id === s);
|
|
386
|
-
if (!a)
|
|
387
|
-
throw new Error(`Chain ${s} is not configured`);
|
|
388
|
-
return a;
|
|
103
|
+
async switchChain({ chainId: e }) {
|
|
104
|
+
return l(e);
|
|
389
105
|
},
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
s.length === 0 ? I.emitter.emit("disconnect") : I.emitter.emit("change", {
|
|
393
|
-
accounts: s
|
|
394
|
-
});
|
|
106
|
+
onAccountsChanged(e) {
|
|
107
|
+
e.length !== 0 && o.emitter.emit("change", { accounts: I(e) });
|
|
395
108
|
},
|
|
396
|
-
onChainChanged(
|
|
397
|
-
|
|
398
|
-
chainId: Number(s)
|
|
399
|
-
});
|
|
109
|
+
onChainChanged(e) {
|
|
110
|
+
o.emitter.emit("change", { chainId: Number(e) });
|
|
400
111
|
},
|
|
401
112
|
onDisconnect() {
|
|
402
|
-
|
|
113
|
+
r == null || r(), o.emitter.emit("disconnect");
|
|
403
114
|
}
|
|
404
115
|
};
|
|
405
116
|
});
|
|
406
117
|
}
|
|
407
|
-
const
|
|
118
|
+
const B = M, H = U;
|
|
408
119
|
export {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
ot as crossxConnector,
|
|
414
|
-
ht as onepocketConnector
|
|
120
|
+
U as createCROSSxConnector,
|
|
121
|
+
H as createONEpocketConnector,
|
|
122
|
+
M as crossxConnector,
|
|
123
|
+
B as onepocketConnector
|
|
415
124
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
4
|
-
"description": "CROSSx SDK wagmi Connector —
|
|
3
|
+
"version": "3.0.0-beta.4",
|
|
4
|
+
"description": "CROSSx SDK wagmi Connector — 보안 화면 앱(iframe) 지갑을 대리 SDK 로 wagmi 에 통합",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -17,11 +17,8 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"sideEffects": false,
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@nexus-cross/crossx-sdk-core": "^3.0.0-beta.3"
|
|
22
|
-
},
|
|
23
20
|
"peerDependencies": {
|
|
24
|
-
"@nexus-cross/crossx-sdk-
|
|
21
|
+
"@nexus-cross/crossx-sdk-proxy": "^3.0.0-0",
|
|
25
22
|
"viem": ">=2.0.0",
|
|
26
23
|
"wagmi": ">=2.0.0"
|
|
27
24
|
},
|
|
@@ -31,7 +28,8 @@
|
|
|
31
28
|
"vite": "^6.4.3",
|
|
32
29
|
"vite-plugin-dts": "^3.7.1",
|
|
33
30
|
"vitest": "^3.2.0",
|
|
34
|
-
"wagmi": "^3.5.0"
|
|
31
|
+
"wagmi": "^3.5.0",
|
|
32
|
+
"@nexus-cross/crossx-sdk-proxy": "^3.0.0-beta.4"
|
|
35
33
|
},
|
|
36
34
|
"keywords": [
|
|
37
35
|
"crossx",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/provider.test.ts"],"names":[],"mappings":""}
|
package/dist/provider.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { CROSSxSDK } from '@nexus-cross/crossx-sdk-core';
|
|
2
|
-
|
|
3
|
-
type EventListener = (...args: any[]) => void;
|
|
4
|
-
export interface EIP1193RequestArguments {
|
|
5
|
-
method: string;
|
|
6
|
-
params?: readonly unknown[] | object;
|
|
7
|
-
}
|
|
8
|
-
export declare class CROSSxEIP1193Provider {
|
|
9
|
-
readonly sdk: CROSSxSDK;
|
|
10
|
-
private listeners;
|
|
11
|
-
private chainId;
|
|
12
|
-
private walletIndex;
|
|
13
|
-
private currentAccounts;
|
|
14
|
-
private walletIndexChangeCallback?;
|
|
15
|
-
constructor(sdk: CROSSxSDK, defaultChainId?: string | number);
|
|
16
|
-
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
17
|
-
_setWalletIndexChangeCallback(cb: (index: number) => void): void;
|
|
18
|
-
request({ method, params }: EIP1193RequestArguments): Promise<unknown>;
|
|
19
|
-
private _handleRequest;
|
|
20
|
-
on(event: string, listener: EventListener): this;
|
|
21
|
-
removeListener(event: string, listener: EventListener): this;
|
|
22
|
-
off: (event: string, listener: EventListener) => this;
|
|
23
|
-
emit(event: string, ...args: unknown[]): void;
|
|
24
|
-
notifyAccountsChanged(accounts: string[]): void;
|
|
25
|
-
notifyDisconnect(error?: Error): void;
|
|
26
|
-
getCurrentChainId(): number;
|
|
27
|
-
setChainId(id: number): void;
|
|
28
|
-
/**
|
|
29
|
-
* 활성 지갑 인덱스 설정.
|
|
30
|
-
* Provider가 SDK 메서드를 호출할 때 이 인덱스를 전달합니다.
|
|
31
|
-
*/
|
|
32
|
-
setWalletIndex(index: number): void;
|
|
33
|
-
getWalletIndex(): number;
|
|
34
|
-
getCurrentAccounts(): string[];
|
|
35
|
-
}
|
|
36
|
-
export {};
|
|
37
|
-
//# sourceMappingURL=provider.d.ts.map
|
package/dist/provider.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAI9D,KAAK,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAO9C,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAAC;CACtC;AA2BD,qBAAa,qBAAqB;IAQ9B,QAAQ,CAAC,GAAG,EAAE,SAAS;IAPzB,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,yBAAyB,CAAC,CAA0B;gBAGjD,GAAG,EAAE,SAAS,EACvB,cAAc,GAAE,MAAM,GAAG,MAA4B;IAavD,2CAA2C;IAC3C,6BAA6B,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAM1D,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC;YAe9D,cAAc;IAuG5B,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAQhD,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAK5D,GAAG,UALmB,MAAM,YAAY,aAAa,KAAG,IAAI,CAKvB;IAErC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM7C,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAK/C,gBAAgB,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;IAMrC,iBAAiB,IAAI,MAAM;IAI3B,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAO5B;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKnC,cAAc,IAAI,MAAM;IAIxB,kBAAkB,IAAI,MAAM,EAAE;CAG/B"}
|