@hfunlabs/hypurr-connect 0.1.11 → 0.1.13
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 +27 -2
- package/dist/index.d.ts +174 -10
- package/dist/index.js +2732 -23
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/DeleteWalletModal.tsx +344 -0
- package/src/HypurrConnectProvider.tsx +205 -41
- package/src/RenameWalletModal.tsx +325 -0
- package/src/UserProfileModal.tsx +982 -0
- package/src/WalletSelectorDropdown.tsx +797 -0
- package/src/agent.ts +2 -2
- package/src/icons/lucide.tsx +197 -0
- package/src/index.ts +16 -0
- package/src/privateKeySigner.ts +32 -0
- package/src/profileStyles.ts +213 -0
- package/src/types.ts +48 -10
- package/src/TelegramLoginWidget.tsx +0 -62
package/README.md
CHANGED
|
@@ -220,6 +220,24 @@ connectEoa(address); // no signer — only L1 actions after manual approval
|
|
|
220
220
|
await approveAgent(signTypedDataAsync, chainId);
|
|
221
221
|
```
|
|
222
222
|
|
|
223
|
+
### EVM Transaction Signing
|
|
224
|
+
|
|
225
|
+
`signEvmTransaction(transaction)` signs a JSON-RPC-style EVM transaction and returns the raw serialized transaction. In Telegram mode it calls the `EVMSignTransaction` gRPC endpoint for the selected private-key wallet; in EOA mode it calls the `signTransaction` or EIP-1193 `request` function supplied to `connectEoa`.
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
const { signEvmTransaction } = useHypurrConnect();
|
|
229
|
+
|
|
230
|
+
const raw = await signEvmTransaction({
|
|
231
|
+
to: "0x0000000000000000000000000000000000000000",
|
|
232
|
+
data: "0x",
|
|
233
|
+
value: "0x0",
|
|
234
|
+
chainId: "0x66eee",
|
|
235
|
+
nonce: "0x1",
|
|
236
|
+
gas: "0x5208",
|
|
237
|
+
gasPrice: "0x3b9aca00",
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
223
241
|
### Using the Exchange Client
|
|
224
242
|
|
|
225
243
|
Once authenticated, the `exchange` object from `useHypurrConnect()` is a fully functional `ExchangeClient` from `@hfunlabs/hyperliquid`. For EOA users with a signer, it handles **both** L1 and user-signed actions transparently:
|
|
@@ -381,12 +399,12 @@ Returns the full auth and exchange state. Throws if used outside `HypurrConnectP
|
|
|
381
399
|
| `openLoginModal` | `() => void` | Show the login modal |
|
|
382
400
|
| `closeLoginModal` | `() => void` | Hide the login modal |
|
|
383
401
|
| `connectEoa` | `(address: \`0x\${string}\`, signer?: EoaSigner) => void` | Connect EOA wallet (sync); pass signer to enable user-signed actions and auto-provisioning |
|
|
402
|
+
| `signEvmTransaction` | `(transaction: EvmTransactionRequest) => Promise<\`0x\${string}\`>` | Sign an EVM transaction through EOA wallet provider or Telegram RPC |
|
|
384
403
|
| `approveAgent` | `(signTypedDataAsync: SignTypedDataFn, chainId: number) => Promise<void>` | Approve a named agent key (async, triggers wallet prompt) |
|
|
385
404
|
| `logout` | `() => void` | Clear all auth state and localStorage |
|
|
386
405
|
| `agent` | `StoredAgent \| null` | Current agent key (EOA flow only) |
|
|
387
406
|
| `agentReady` | `boolean` | Whether the exchange client can sign (true for TG, or EOA+agent) |
|
|
388
407
|
| `clearAgent` | `() => void` | Remove the agent key from state and storage |
|
|
389
|
-
| `botId` | `string` | Deprecated legacy Telegram bot ID from config |
|
|
390
408
|
| `authDataMap` | `Record<string, string>` | Deprecated; empty when using hub JWT auth |
|
|
391
409
|
| `authToken` | `string \| null` | JWT returned by the auth hub |
|
|
392
410
|
| `telegramRpcOptions` | `RpcOptions \| undefined` | gRPC call options containing `Authorization: Bearer <jwt>` metadata |
|
|
@@ -473,11 +491,13 @@ Encapsulates the master wallet's EIP-712 signing function and chain ID. Pass to
|
|
|
473
491
|
```typescript
|
|
474
492
|
interface EoaSigner {
|
|
475
493
|
signTypedData: SignTypedDataFn;
|
|
494
|
+
signTransaction?: (transaction: EvmTransactionRequest) => Promise<unknown>;
|
|
495
|
+
request?: (args: { method: string; params?: unknown[] }) => Promise<unknown>;
|
|
476
496
|
chainId: number;
|
|
477
497
|
}
|
|
478
498
|
```
|
|
479
499
|
|
|
480
|
-
#### `createEoaSigner(signTypedData, chainId): EoaSigner`
|
|
500
|
+
#### `createEoaSigner(signTypedData, chainId, options?): EoaSigner`
|
|
481
501
|
|
|
482
502
|
Helper to create an `EoaSigner` from wagmi's `signTypedDataAsync` (or any compatible function). Accepts either a direct function or a `{ current: Function }` ref to avoid stale closures with React hooks:
|
|
483
503
|
|
|
@@ -489,6 +509,11 @@ const signer = createEoaSigner(signerRef, chainId);
|
|
|
489
509
|
|
|
490
510
|
// With a direct function (fine for stable references)
|
|
491
511
|
const signer = createEoaSigner(signTypedDataAsync, chainId);
|
|
512
|
+
|
|
513
|
+
// With an EIP-1193 provider for EVM transaction signing
|
|
514
|
+
const signer = createEoaSigner(signTypedDataAsync, chainId, {
|
|
515
|
+
request: provider.request.bind(provider),
|
|
516
|
+
});
|
|
492
517
|
```
|
|
493
518
|
|
|
494
519
|
#### `SignTypedDataFn`
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { TelegramChatWalletPack } from 'hypurr-grpc/ts/hypurr/user';
|
|
|
11
11
|
export { TelegramChatWalletPack } from 'hypurr-grpc/ts/hypurr/user';
|
|
12
12
|
import { HyperliquidWallet } from 'hypurr-grpc/ts/hypurr/wallet';
|
|
13
13
|
export { HyperliquidWallet } from 'hypurr-grpc/ts/hypurr/wallet';
|
|
14
|
+
import { AbstractViemLocalAccount } from '@hfunlabs/hyperliquid/signing';
|
|
14
15
|
|
|
15
16
|
interface HypurrConnectConfig {
|
|
16
17
|
/** gRPC-web base URL. Defaults to https://grpc.hypurr.fun. */
|
|
@@ -21,19 +22,15 @@ interface HypurrConnectConfig {
|
|
|
21
22
|
isTestnet?: boolean;
|
|
22
23
|
/** Polling interval in ms for TWAP/Scale session updates. Default 5000. Set 0 to disable. */
|
|
23
24
|
sessionPollInterval?: number;
|
|
24
|
-
telegram
|
|
25
|
-
/** Deprecated for the hub flow; retained for older consumers. */
|
|
26
|
-
botUsername?: string;
|
|
27
|
-
/** Deprecated for the hub flow; retained for older consumers. */
|
|
28
|
-
botId?: string;
|
|
29
|
-
/** Deprecated: Telegram login is now handled by the auth hub. */
|
|
30
|
-
useWidget?: boolean;
|
|
25
|
+
telegram?: {
|
|
31
26
|
/** Auth hub login URL. Defaults to https://auth.hypurr.fun/login. */
|
|
32
27
|
authHubUrl?: string;
|
|
33
28
|
/** Optional callback URL. Defaults to the current page without auth query params. */
|
|
34
29
|
returnTo?: string | (() => string);
|
|
35
30
|
/** Requested hub scopes. Defaults to the scopes required by this SDK. */
|
|
36
31
|
scope?: string | string[];
|
|
32
|
+
/** @deprecated Telegram login is handled by the auth hub; this option is ignored. */
|
|
33
|
+
useWidget?: boolean;
|
|
37
34
|
};
|
|
38
35
|
}
|
|
39
36
|
/** @deprecated Telegram login is handled by the auth hub; raw Telegram data is no longer used by the provider. */
|
|
@@ -73,11 +70,41 @@ type SignTypedDataFn = (params: {
|
|
|
73
70
|
primaryType: string;
|
|
74
71
|
message: Record<string, unknown>;
|
|
75
72
|
}) => Promise<`0x${string}`>;
|
|
73
|
+
type Hex = `0x${string}`;
|
|
74
|
+
interface EvmTransactionRequest {
|
|
75
|
+
from?: Hex;
|
|
76
|
+
to?: Hex;
|
|
77
|
+
gas?: Hex;
|
|
78
|
+
gasPrice?: Hex;
|
|
79
|
+
value?: Hex;
|
|
80
|
+
data?: Hex;
|
|
81
|
+
nonce?: Hex;
|
|
82
|
+
chainId?: Hex;
|
|
83
|
+
maxFeePerGas?: Hex;
|
|
84
|
+
maxPriorityFeePerGas?: Hex;
|
|
85
|
+
type?: Hex;
|
|
86
|
+
accessList?: unknown;
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}
|
|
89
|
+
type EvmRequestFn = (args: {
|
|
90
|
+
method: string;
|
|
91
|
+
params?: unknown[];
|
|
92
|
+
}) => Promise<unknown>;
|
|
93
|
+
type SignEvmTransactionFn = (transaction: EvmTransactionRequest) => Promise<Hex>;
|
|
94
|
+
type EoaSignTransactionFn = (transaction: EvmTransactionRequest) => Promise<unknown>;
|
|
76
95
|
/** Wallet signer provided at EOA connect time for user-signed actions. */
|
|
77
96
|
interface EoaSigner {
|
|
78
97
|
signTypedData: SignTypedDataFn;
|
|
98
|
+
/** Optional raw EVM transaction signer. Used by `signEvmTransaction()` in EOA mode. */
|
|
99
|
+
signTransaction?: EoaSignTransactionFn;
|
|
100
|
+
/** Optional EIP-1193 provider request function. Used as a fallback for `eth_signTransaction`. */
|
|
101
|
+
request?: EvmRequestFn;
|
|
79
102
|
chainId: number;
|
|
80
103
|
}
|
|
104
|
+
interface EoaSignerOptions {
|
|
105
|
+
signTransaction?: EoaSignTransactionFn;
|
|
106
|
+
request?: EvmRequestFn;
|
|
107
|
+
}
|
|
81
108
|
/**
|
|
82
109
|
* Create an {@link EoaSigner} from any EIP-712 signing function.
|
|
83
110
|
*
|
|
@@ -103,7 +130,7 @@ interface EoaSigner {
|
|
|
103
130
|
*/
|
|
104
131
|
declare function createEoaSigner(signTypedDataAsync: ((args: Record<string, unknown>) => Promise<`0x${string}`>) | {
|
|
105
132
|
current: (args: Record<string, unknown>) => Promise<`0x${string}`>;
|
|
106
|
-
}, chainId: number): EoaSigner;
|
|
133
|
+
}, chainId: number, options?: EoaSignerOptions): EoaSigner;
|
|
107
134
|
type TwapCreateParams = Omit<HyperliquidTwapCreateRequest, "authData" | "walletId">;
|
|
108
135
|
type TwapModifyParams = Omit<HyperliquidTwapModifyRequest, "authData" | "walletId">;
|
|
109
136
|
type ScaleCreateParams = Omit<HyperliquidScaleCreateRequest, "authData" | "walletId">;
|
|
@@ -119,6 +146,7 @@ interface HypurrConnectState {
|
|
|
119
146
|
selectWallet: (walletId: number) => void;
|
|
120
147
|
createWallet: (name: string) => Promise<HyperliquidWallet>;
|
|
121
148
|
deleteWallet: (walletId: number) => Promise<void>;
|
|
149
|
+
renameWallet: (walletId: number, name: string) => Promise<void>;
|
|
122
150
|
refreshWallets: () => void;
|
|
123
151
|
packs: TelegramChatWalletPack[];
|
|
124
152
|
createWalletPack: (name: string) => Promise<number>;
|
|
@@ -145,12 +173,12 @@ interface HypurrConnectState {
|
|
|
145
173
|
openLoginModal: () => void;
|
|
146
174
|
closeLoginModal: () => void;
|
|
147
175
|
connectEoa: (address: `0x${string}`, signer?: EoaSigner) => void;
|
|
176
|
+
signEvmTransaction: SignEvmTransactionFn;
|
|
148
177
|
approveAgent: (signTypedDataAsync: SignTypedDataFn, chainId: number) => Promise<void>;
|
|
149
178
|
logout: () => void;
|
|
150
179
|
agent: StoredAgent | null;
|
|
151
180
|
agentReady: boolean;
|
|
152
181
|
clearAgent: () => void;
|
|
153
|
-
botId: string;
|
|
154
182
|
/** Deprecated: JWT auth leaves authData empty; use `telegramRpcOptions` for low-level calls. */
|
|
155
183
|
authDataMap: Record<string, string>;
|
|
156
184
|
authToken: string | null;
|
|
@@ -171,6 +199,129 @@ interface LoginModalProps {
|
|
|
171
199
|
}
|
|
172
200
|
declare function LoginModal({ onConnectWallet, walletIcon }: LoginModalProps): react_jsx_runtime.JSX.Element;
|
|
173
201
|
|
|
202
|
+
interface PrincipalColors {
|
|
203
|
+
accent: string;
|
|
204
|
+
accentText: string;
|
|
205
|
+
accentBackground: string;
|
|
206
|
+
accentBorder: string;
|
|
207
|
+
accentHoverBackground: string;
|
|
208
|
+
}
|
|
209
|
+
type PrincipalColorOverrides = Partial<PrincipalColors>;
|
|
210
|
+
|
|
211
|
+
interface SlippageOption {
|
|
212
|
+
label: string;
|
|
213
|
+
value: number;
|
|
214
|
+
}
|
|
215
|
+
interface UserProfileModalProps {
|
|
216
|
+
isOpen: boolean;
|
|
217
|
+
onClose: () => void;
|
|
218
|
+
/** Current value for the "Animations" toggle. */
|
|
219
|
+
animationsEnabled: boolean;
|
|
220
|
+
/** Called when the user flips the animations toggle. */
|
|
221
|
+
onToggleAnimations: () => void;
|
|
222
|
+
/** Current default slippage value (e.g. 0.01 = 1%). */
|
|
223
|
+
defaultSlippage: number;
|
|
224
|
+
/** Called when the user picks a slippage option. */
|
|
225
|
+
onSlippageChange: (value: number) => void;
|
|
226
|
+
/** Override the slippage choices. Defaults to 0.5/1/2/5/10%. */
|
|
227
|
+
slippageOptions?: SlippageOption[];
|
|
228
|
+
/**
|
|
229
|
+
* Fired after the SDK successfully deletes a wallet. Use this for extra
|
|
230
|
+
* side effects on the host (e.g. invalidating React Query caches).
|
|
231
|
+
*/
|
|
232
|
+
onWalletDeleted?: (walletId: number) => void;
|
|
233
|
+
/**
|
|
234
|
+
* Fired after the SDK successfully renames a wallet. Use this for extra
|
|
235
|
+
* side effects on the host (e.g. invalidating React Query caches).
|
|
236
|
+
*/
|
|
237
|
+
onWalletRenamed?: (walletId: number, name: string) => void;
|
|
238
|
+
/**
|
|
239
|
+
* If provided, each wallet row in the Wallets tab gets a "View portfolio"
|
|
240
|
+
* button that fires this callback. The host is expected to open its own
|
|
241
|
+
* portfolio UI in response.
|
|
242
|
+
*/
|
|
243
|
+
onShowPortfolio?: (wallet: HyperliquidWallet) => void;
|
|
244
|
+
/** Optional toast callback. SDK fires success on rename/delete; errors stay inline in sub-modals. */
|
|
245
|
+
onNotify?: (n: {
|
|
246
|
+
type: "success" | "error";
|
|
247
|
+
message: string;
|
|
248
|
+
}) => void;
|
|
249
|
+
/** Shorthand for `principalColors.accent`. Defaults to `#a855f7`. */
|
|
250
|
+
accentColor?: string;
|
|
251
|
+
/** Principal accent colors used for switches, action text, and wallet icon surfaces. */
|
|
252
|
+
principalColors?: PrincipalColorOverrides;
|
|
253
|
+
}
|
|
254
|
+
declare function UserProfileModal({ isOpen, onClose, animationsEnabled, onToggleAnimations, defaultSlippage, onSlippageChange, slippageOptions, onWalletDeleted, onWalletRenamed, onShowPortfolio, onNotify, accentColor, principalColors, }: UserProfileModalProps): ReactNode;
|
|
255
|
+
|
|
256
|
+
interface WalletSelectorDropdownProps {
|
|
257
|
+
isOpen: boolean;
|
|
258
|
+
onClose: () => void;
|
|
259
|
+
/** Called when the user clicks "Add Wallet". Host renders the add-wallet UI. */
|
|
260
|
+
onAddWallet?: () => void;
|
|
261
|
+
/** Called when the user clicks the portfolio icon on a wallet row. */
|
|
262
|
+
onShowPortfolio?: (wallet: HyperliquidWallet) => void;
|
|
263
|
+
/**
|
|
264
|
+
* Called before the SDK's `logout()` runs. Host can do extra cleanup
|
|
265
|
+
* (e.g. wagmi `disconnect()`).
|
|
266
|
+
*/
|
|
267
|
+
onLogout?: () => void;
|
|
268
|
+
/** Toast callback. Fires "Address copied" success on copy-address clicks. */
|
|
269
|
+
onNotify?: (n: {
|
|
270
|
+
type: "success" | "error";
|
|
271
|
+
message: string;
|
|
272
|
+
}) => void;
|
|
273
|
+
/** HFun score threshold for the VIP crown. Defaults to 10. */
|
|
274
|
+
vipThreshold?: number;
|
|
275
|
+
/** Current value for the "Animations" toggle. */
|
|
276
|
+
animationsEnabled: boolean;
|
|
277
|
+
/** Called when the user flips the animations toggle. */
|
|
278
|
+
onToggleAnimations: () => void;
|
|
279
|
+
/** Current default slippage value (e.g. 0.01 = 1%). */
|
|
280
|
+
defaultSlippage: number;
|
|
281
|
+
/** Called when the user picks a slippage option. */
|
|
282
|
+
onSlippageChange: (value: number) => void;
|
|
283
|
+
/** Override the slippage choices. Defaults to 0.5/1/2/5/10%. */
|
|
284
|
+
slippageOptions?: SlippageOption[];
|
|
285
|
+
/** Fired after the SDK successfully deletes a wallet. */
|
|
286
|
+
onWalletDeleted?: (walletId: number) => void;
|
|
287
|
+
/** Fired after the SDK successfully renames a wallet. */
|
|
288
|
+
onWalletRenamed?: (walletId: number, name: string) => void;
|
|
289
|
+
/** Shorthand for `principalColors.accent`. Defaults to `#a855f7`. */
|
|
290
|
+
accentColor?: string;
|
|
291
|
+
/** Principal accent colors used for add-wallet text, wallet icon surfaces, and the Profile & Settings modal. */
|
|
292
|
+
principalColors?: PrincipalColorOverrides;
|
|
293
|
+
/** CSS color used as the dropdown panel background. Defaults to `rgba(20,20,20,0.95)`. */
|
|
294
|
+
backgroundColor?: string;
|
|
295
|
+
}
|
|
296
|
+
declare function WalletSelectorDropdown({ isOpen, onClose, onAddWallet, onShowPortfolio, onLogout, onNotify, vipThreshold, animationsEnabled, onToggleAnimations, defaultSlippage, onSlippageChange, slippageOptions, onWalletDeleted, onWalletRenamed, accentColor, principalColors, backgroundColor, }: WalletSelectorDropdownProps): ReactNode;
|
|
297
|
+
|
|
298
|
+
interface DeleteWalletModalProps {
|
|
299
|
+
isOpen: boolean;
|
|
300
|
+
onClose: () => void;
|
|
301
|
+
wallet: HyperliquidWallet | null;
|
|
302
|
+
onConfirm: (walletId: number) => Promise<void>;
|
|
303
|
+
/** Optional toast callback. Fires `{type:"success"}` on delete; errors are shown inline. */
|
|
304
|
+
onNotify?: (n: {
|
|
305
|
+
type: "success" | "error";
|
|
306
|
+
message: string;
|
|
307
|
+
}) => void;
|
|
308
|
+
}
|
|
309
|
+
declare function DeleteWalletModal({ isOpen, onClose, wallet, onConfirm, onNotify, }: DeleteWalletModalProps): ReactNode;
|
|
310
|
+
|
|
311
|
+
interface RenameWalletModalProps {
|
|
312
|
+
isOpen: boolean;
|
|
313
|
+
onClose: () => void;
|
|
314
|
+
wallet: HyperliquidWallet | null;
|
|
315
|
+
onConfirm: (walletId: number, name: string) => Promise<void>;
|
|
316
|
+
onNotify?: (n: {
|
|
317
|
+
type: "success" | "error";
|
|
318
|
+
message: string;
|
|
319
|
+
}) => void;
|
|
320
|
+
/** Kept for compatibility. Profile modal actions now use the shared app raised button style. */
|
|
321
|
+
accentColor?: string;
|
|
322
|
+
}
|
|
323
|
+
declare function RenameWalletModal({ isOpen, onClose, wallet, onConfirm, onNotify, }: RenameWalletModalProps): ReactNode;
|
|
324
|
+
|
|
174
325
|
interface GrpcExchangeTransportConfig {
|
|
175
326
|
isTestnet?: boolean;
|
|
176
327
|
telegramClient: TelegramClient;
|
|
@@ -201,4 +352,17 @@ declare class GrpcExchangeTransport implements IRequestTransport {
|
|
|
201
352
|
declare function createTelegramClient(config: HypurrConnectConfig): TelegramClient;
|
|
202
353
|
declare function createStaticClient(config: HypurrConnectConfig): StaticClient;
|
|
203
354
|
|
|
204
|
-
|
|
355
|
+
type SignTypedDataParams = Parameters<AbstractViemLocalAccount["signTypedData"]>[0];
|
|
356
|
+
/**
|
|
357
|
+
* Compatibility wrapper for SDK versions that removed PrivateKeySigner.
|
|
358
|
+
*
|
|
359
|
+
* It exposes the viem local-account shape accepted by the Hyperliquid SDK.
|
|
360
|
+
*/
|
|
361
|
+
declare class PrivateKeySigner implements AbstractViemLocalAccount {
|
|
362
|
+
#private;
|
|
363
|
+
readonly address: Hex;
|
|
364
|
+
constructor(privateKey: string);
|
|
365
|
+
signTypedData(params: SignTypedDataParams): Promise<Hex>;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export { type AuthMethod, DeleteWalletModal, type DeleteWalletModalProps, type EoaSignTransactionFn, type EoaSigner, type EoaSignerOptions, type EvmRequestFn, type EvmTransactionRequest, GrpcExchangeTransport, type GrpcExchangeTransportConfig, type Hex, type HypurrConnectConfig, HypurrConnectProvider, type HypurrConnectState, type HypurrUser, LoginModal, type LoginModalProps, type PrincipalColorOverrides, type PrincipalColors, PrivateKeySigner, RenameWalletModal, type RenameWalletModalProps, type ScaleCreateParams, type SignEvmTransactionFn, type SignTypedDataFn, type SlippageOption, type StoredAgent, type TelegramLoginData, type TwapCreateParams, type TwapModifyParams, UserProfileModal, type UserProfileModalProps, WalletSelectorDropdown, type WalletSelectorDropdownProps, createEoaSigner, createStaticClient, createTelegramClient, useHypurrConnect };
|