@hfunlabs/hypurr-connect 0.1.21 → 0.1.22
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 +6 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/HypurrConnectProvider.tsx +10 -0
- package/src/grpc.ts +5 -1
- package/src/types.ts +2 -0
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ pnpm add @hfunlabs/hyperliquid @protobuf-ts/grpcweb-transport @protobuf-ts/runti
|
|
|
44
44
|
import { HypurrConnectProvider } from "@hfunlabs/hypurr-connect";
|
|
45
45
|
|
|
46
46
|
const config = {
|
|
47
|
+
client_id: "your-client-id",
|
|
47
48
|
isTestnet: false,
|
|
48
49
|
grpcUrl: "https://grpc.hypurr.fun",
|
|
49
50
|
telegram: {
|
|
@@ -118,6 +119,7 @@ function AppShell() {
|
|
|
118
119
|
|
|
119
120
|
```typescript
|
|
120
121
|
interface HypurrConnectConfig {
|
|
122
|
+
client_id: string; // Auth hub client identifier
|
|
121
123
|
grpcUrl?: string; // gRPC-web base URL (default: https://grpc.hypurr.fun)
|
|
122
124
|
mediaUrl?: string; // Media base URL (default: https://media.hypurr.fun)
|
|
123
125
|
grpcTimeout?: number; // Request timeout in ms (default: 15000)
|
|
@@ -144,8 +146,8 @@ for generated protobuf service clients.
|
|
|
144
146
|
### Telegram Login
|
|
145
147
|
|
|
146
148
|
1. User clicks "Telegram" in the `LoginModal`.
|
|
147
|
-
2. The SDK opens the configured auth hub in a popup with `
|
|
148
|
-
and requested `scope`.
|
|
149
|
+
2. The SDK opens the configured auth hub in a popup with `client_id`,
|
|
150
|
+
`return_to`, `state`, and requested `scope`.
|
|
149
151
|
3. The auth hub performs Telegram login and redirects back to `return_to` with
|
|
150
152
|
a scoped JWT.
|
|
151
153
|
4. The popup callback page posts `{ token, state }` to the opener with
|
|
@@ -579,8 +581,8 @@ Creates a gRPC-Web client for the Telegram service.
|
|
|
579
581
|
|
|
580
582
|
Creates a gRPC-Web client for the Static service.
|
|
581
583
|
|
|
582
|
-
Both use `GrpcWebFetchTransport` with `config.grpcUrl`
|
|
583
|
-
`config.grpcTimeout` as `timeout`.
|
|
584
|
+
Both use `GrpcWebFetchTransport` with `config.grpcUrl` or the default gRPC URL
|
|
585
|
+
as `baseUrl`, and `config.grpcTimeout` as `timeout`.
|
|
584
586
|
|
|
585
587
|
## localStorage Keys
|
|
586
588
|
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export { HyperliquidWallet } from 'hypurr-grpc/ts/hypurr/wallet';
|
|
|
14
14
|
import { AbstractViemLocalAccount } from '@hfunlabs/hyperliquid/signing';
|
|
15
15
|
|
|
16
16
|
interface HypurrConnectConfig {
|
|
17
|
+
/** Auth hub client identifier. Sent as `client_id` during Telegram login. */
|
|
18
|
+
client_id: string;
|
|
17
19
|
/** gRPC-web base URL. Defaults to https://grpc.hypurr.fun. */
|
|
18
20
|
grpcUrl?: string;
|
|
19
21
|
/** Media base URL for user-uploaded assets. Defaults to https://media.hypurr.fun. */
|
package/dist/index.js
CHANGED
|
@@ -140,9 +140,12 @@ import { GrpcWebFetchTransport } from "@protobuf-ts/grpcweb-transport";
|
|
|
140
140
|
import { StaticClient } from "hypurr-grpc/ts/hypurr/static/static_service.client";
|
|
141
141
|
import { TelegramClient } from "hypurr-grpc/ts/hypurr/telegram/telegram_service.client";
|
|
142
142
|
var DEFAULT_GRPC_URL = "https://grpc.hypurr.fun";
|
|
143
|
+
function resolveGrpcUrl(config) {
|
|
144
|
+
return config.grpcUrl?.trim() || DEFAULT_GRPC_URL;
|
|
145
|
+
}
|
|
143
146
|
function createTransport(config) {
|
|
144
147
|
return new GrpcWebFetchTransport({
|
|
145
|
-
baseUrl: config
|
|
148
|
+
baseUrl: resolveGrpcUrl(config),
|
|
146
149
|
timeout: config.grpcTimeout ?? 15e3
|
|
147
150
|
});
|
|
148
151
|
}
|
|
@@ -448,6 +451,13 @@ function normalizeScopes(scope) {
|
|
|
448
451
|
if (Array.isArray(scope)) return scope.join(" ");
|
|
449
452
|
return scope?.trim() || DEFAULT_TELEGRAM_SCOPES.join(" ");
|
|
450
453
|
}
|
|
454
|
+
function normalizeClientId(clientId) {
|
|
455
|
+
const normalized = typeof clientId === "string" ? clientId.trim() : "";
|
|
456
|
+
if (!normalized) {
|
|
457
|
+
throw new Error("[HypurrConnect] config.client_id is required.");
|
|
458
|
+
}
|
|
459
|
+
return normalized;
|
|
460
|
+
}
|
|
451
461
|
function isTelegramAuthMessage(data) {
|
|
452
462
|
return typeof data === "object" && data !== null && "type" in data && "token" in data && "state" in data && data.type === TELEGRAM_AUTH_MESSAGE && typeof data.token === "string" && typeof data.state === "string";
|
|
453
463
|
}
|
|
@@ -1313,6 +1323,7 @@ function HypurrConnectProvider({
|
|
|
1313
1323
|
const authUrl = new URL(
|
|
1314
1324
|
config.telegram?.authHubUrl || DEFAULT_AUTH_HUB_URL
|
|
1315
1325
|
);
|
|
1326
|
+
authUrl.searchParams.set("client_id", normalizeClientId(config.client_id));
|
|
1316
1327
|
authUrl.searchParams.set("return_to", returnTo);
|
|
1317
1328
|
authUrl.searchParams.set("state", state);
|
|
1318
1329
|
authUrl.searchParams.set("scope", normalizeScopes(config.telegram?.scope));
|
|
@@ -1338,6 +1349,7 @@ function HypurrConnectProvider({
|
|
|
1338
1349
|
}
|
|
1339
1350
|
window.location.assign(authUrl.toString());
|
|
1340
1351
|
}, [
|
|
1352
|
+
config.client_id,
|
|
1341
1353
|
config.telegram?.authHubUrl,
|
|
1342
1354
|
config.telegram?.returnTo,
|
|
1343
1355
|
config.telegram?.scope
|