cabalspy-id 0.0.0-stage → 0.5.1
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/CHANGELOG.md +112 -0
- package/LICENSE +21 -0
- package/README.md +475 -3
- package/dist/api.cjs +72 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +193 -0
- package/dist/api.d.ts +193 -0
- package/dist/api.js +72 -0
- package/dist/api.js.map +1 -0
- package/dist/chunk-3LKLY5WQ.js +1392 -0
- package/dist/chunk-3LKLY5WQ.js.map +1 -0
- package/dist/chunk-3P7QK2PG.js +385 -0
- package/dist/chunk-3P7QK2PG.js.map +1 -0
- package/dist/chunk-A2ZAFAWC.cjs +1 -0
- package/dist/chunk-A2ZAFAWC.cjs.map +1 -0
- package/dist/chunk-CJFIOVBA.js +1 -0
- package/dist/chunk-CJFIOVBA.js.map +1 -0
- package/dist/chunk-L4RHSWOA.cjs +1392 -0
- package/dist/chunk-L4RHSWOA.cjs.map +1 -0
- package/dist/chunk-P3MDLWLN.cjs +385 -0
- package/dist/chunk-P3MDLWLN.cjs.map +1 -0
- package/dist/chunk-X3OFGGSE.cjs +398 -0
- package/dist/chunk-X3OFGGSE.cjs.map +1 -0
- package/dist/chunk-Z3UPDOBY.js +398 -0
- package/dist/chunk-Z3UPDOBY.js.map +1 -0
- package/dist/index.cjs +97 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +97 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +308 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +292 -0
- package/dist/react.d.ts +292 -0
- package/dist/react.js +280 -0
- package/dist/react.js.map +1 -0
- package/dist/thesis.cjs +68 -0
- package/dist/thesis.cjs.map +1 -0
- package/dist/thesis.d.cts +190 -0
- package/dist/thesis.d.ts +190 -0
- package/dist/thesis.js +68 -0
- package/dist/thesis.js.map +1 -0
- package/dist/types-UZeY9n1e.d.cts +689 -0
- package/dist/types-UZeY9n1e.d.ts +689 -0
- package/dist/users-BDLkwW1p.d.cts +767 -0
- package/dist/users-CDlDRuyv.d.ts +767 -0
- package/dist/widget.cjs +217 -0
- package/dist/widget.cjs.map +1 -0
- package/dist/widget.d.cts +195 -0
- package/dist/widget.d.ts +195 -0
- package/dist/widget.js +217 -0
- package/dist/widget.js.map +1 -0
- package/package.json +147 -6
package/dist/api.cjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkX3OFGGSEcjs = require('./chunk-X3OFGGSE.cjs');
|
|
9
|
+
require('./chunk-A2ZAFAWC.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
var _chunkL4RHSWOAcjs = require('./chunk-L4RHSWOA.cjs');
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
exports.AuthenticationError = _chunkL4RHSWOAcjs.AuthenticationError; exports.BadRequestError = _chunkL4RHSWOAcjs.BadRequestError; exports.CHAINS = _chunkL4RHSWOAcjs.CHAINS; exports.CURRENCY_BY_CHAIN = _chunkL4RHSWOAcjs.CURRENCY_BY_CHAIN; exports.CabalSpyID = _chunkL4RHSWOAcjs.CabalSpyID; exports.CabalSpyIDAuth = _chunkX3OFGGSEcjs.CabalSpyIDAuth; exports.CabalSpyIDError = _chunkL4RHSWOAcjs.CabalSpyIDError; exports.CabalSpyIDStream = _chunkL4RHSWOAcjs.CabalSpyIDStream; exports.ConnectionError = _chunkL4RHSWOAcjs.ConnectionError; exports.DEFAULT_BASE_URL = _chunkL4RHSWOAcjs.DEFAULT_BASE_URL; exports.DEFAULT_ISSUER = _chunkX3OFGGSEcjs.DEFAULT_ISSUER; exports.DEFAULT_STREAM_URL = _chunkL4RHSWOAcjs.DEFAULT_STREAM_URL; exports.InvalidResponseError = _chunkL4RHSWOAcjs.InvalidResponseError; exports.JwksCache = _chunkX3OFGGSEcjs.JwksCache; exports.LEADERBOARD_SORTS = _chunkL4RHSWOAcjs.LEADERBOARD_SORTS; exports.NotFoundError = _chunkL4RHSWOAcjs.NotFoundError; exports.OAuthError = _chunkL4RHSWOAcjs.OAuthError; exports.PERIODS = _chunkL4RHSWOAcjs.PERIODS; exports.PermissionError = _chunkL4RHSWOAcjs.PermissionError; exports.PlanUserLimitError = _chunkL4RHSWOAcjs.PlanUserLimitError; exports.RateLimitError = _chunkL4RHSWOAcjs.RateLimitError; exports.SDK_VERSION = _chunkL4RHSWOAcjs.SDK_VERSION; exports.ServerError = _chunkL4RHSWOAcjs.ServerError; exports.TokenVerificationError = _chunkL4RHSWOAcjs.TokenVerificationError; exports.WebhookVerificationError = _chunkL4RHSWOAcjs.WebhookVerificationError; exports.decodeJwt = _chunkX3OFGGSEcjs.decodeJwt; exports.generatePkce = _chunkX3OFGGSEcjs.generatePkce; exports.handleKind = _chunkL4RHSWOAcjs.handleKind; exports.hasX = _chunkL4RHSWOAcjs.hasX; exports.isLimited = _chunkX3OFGGSEcjs.isLimited; exports.signWebhook = _chunkL4RHSWOAcjs.signWebhook; exports.verifyWebhook = _chunkL4RHSWOAcjs.verifyWebhook;
|
|
72
|
+
//# sourceMappingURL=api.cjs.map
|
package/dist/api.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["c:\\Users\\davis\\Desktop\\cabalspy-web\\github\\cabalspy-id-js\\dist\\api.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,m0DAAC","file":"C:\\Users\\davis\\Desktop\\cabalspy-web\\github\\cabalspy-id-js\\dist\\api.cjs"}
|
package/dist/api.d.cts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
export { A as ApiErrorBody, a as AuthenticationError, B as BadRequestError, C as CabalSpyID, b as CabalSpyIDError, c as CabalSpyIDErrorOptions, d as CabalSpyIDOptions, e as CabalSpyIDStream, f as CloseEvent, g as ConnectionError, D as DEFAULT_BASE_URL, h as DEFAULT_STREAM_URL, E as Envelope, H as HandleKind, k as HeaderSource, l as HeartbeatEvent, m as HistoryParams, I as InvalidResponseError, n as LatestTransactionsParams, o as LeaderboardParams, N as NotFoundError, O as OAuthError, P as PermissionError, q as PlanUserLimitError, s as ProfileParams, Q as Query, R as RateLimitError, t as RateLimitInfo, v as ReconnectEvent, S as SDK_VERSION, y as ScopedParams, z as ServerError, F as StreamEvent, G as StreamEventMap, J as StreamOptions, K as StreamTopic, T as SubscribedEvent, a3 as TokenVerificationError, a4 as TrackerParams, a5 as UserLike, a7 as UsersParams, a8 as VerifyWebhookOptions, a9 as WalletParams, aa as WebhookVerificationError, ab as handleKind, ac as hasX, ad as signWebhook, ae as verifyWebhook } from './users-BDLkwW1p.cjs';
|
|
2
|
+
import { O as OidcScope, D as DiscoveryDocument, a8 as TokenResponse, c as CabalSpyIDClaims } from './types-UZeY9n1e.cjs';
|
|
3
|
+
export { A as ActiveTokens, a as ApiResponse, C as CHAINS, b as CURRENCY_BY_CHAIN, d as Chain, e as Currency, H as HealthResponse, f as HistoryResponse, g as HistoryToken, h as HistoryTrade, i as HoldingToken, j as HoldingsResponse, L as LEADERBOARD_SORTS, k as LeaderboardEntry, l as LeaderboardResponse, m as LeaderboardSort, n as LifetimeStats, M as MeResponse, P as PERIODS, o as Pagination, p as Period, q as PeriodStats, r as PnlCalendarDay, s as PnlCalendarMonth, t as PnlCalendarResponse, u as PnlChartPoint, v as Profile, R as ResponseMeta, S as Scope, a7 as TokenOverview, a9 as TrackerResponse, aa as TrackerTrade, ab as Trade, ac as TradeOwner, ad as TraderProfile, ae as VerifiedWallet, af as WalletClaim, ag as WalletLookupResponse, ah as WebhookEvent, ai as WebhookEventType, aj as WinRateBuckets, ak as WinRateDistribution, al as XProfileClaim } from './types-UZeY9n1e.cjs';
|
|
4
|
+
|
|
5
|
+
/** ES256 JWT verification against a JWKS, with WebCrypto only (no dependencies). */
|
|
6
|
+
interface EcJwk {
|
|
7
|
+
kty: 'EC';
|
|
8
|
+
crv: 'P-256';
|
|
9
|
+
x: string;
|
|
10
|
+
y: string;
|
|
11
|
+
kid?: string;
|
|
12
|
+
alg?: string;
|
|
13
|
+
use?: string;
|
|
14
|
+
}
|
|
15
|
+
interface Jwks {
|
|
16
|
+
keys: EcJwk[];
|
|
17
|
+
}
|
|
18
|
+
interface JwtHeader {
|
|
19
|
+
alg: string;
|
|
20
|
+
kid?: string;
|
|
21
|
+
typ?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface DecodedJwt<P = Record<string, unknown>> {
|
|
25
|
+
header: JwtHeader;
|
|
26
|
+
payload: P;
|
|
27
|
+
}
|
|
28
|
+
/** Decodes a JWT without verifying it. Never trust the result. */
|
|
29
|
+
declare function decodeJwt<P = Record<string, unknown>>(token: string): DecodedJwt<P>;
|
|
30
|
+
/**
|
|
31
|
+
* Caches the provider's public keys. An unknown `kid` triggers one refetch
|
|
32
|
+
* (key rotation), at most once per `cooldownMs`.
|
|
33
|
+
*/
|
|
34
|
+
declare class JwksCache {
|
|
35
|
+
private readonly load;
|
|
36
|
+
private readonly cooldownMs;
|
|
37
|
+
private keys;
|
|
38
|
+
private loaded;
|
|
39
|
+
private inflight;
|
|
40
|
+
constructor(load: () => Promise<Jwks>, cooldownMs?: number);
|
|
41
|
+
private refresh;
|
|
42
|
+
getKey(kid: string | undefined): Promise<CryptoKey>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare const DEFAULT_ISSUER = "https://id.cabalspy.xyz";
|
|
46
|
+
type TokenEndpointAuthMethod = 'client_secret_basic' | 'client_secret_post' | 'none';
|
|
47
|
+
interface CabalSpyIDAuthOptions {
|
|
48
|
+
/** Your instance's client_id (`csid_…`). */
|
|
49
|
+
clientId: string;
|
|
50
|
+
/** Client secret (`csid_sk_…`) of a server-side app. Omit for public clients. */
|
|
51
|
+
clientSecret?: string;
|
|
52
|
+
/** Default redirect URI. Must exactly match one registered in the dashboard. */
|
|
53
|
+
redirectUri?: string;
|
|
54
|
+
/** Default: https://id.cabalspy.xyz (env CABALSPY_ID_ISSUER) */
|
|
55
|
+
issuer?: string;
|
|
56
|
+
/** Default: client_secret_basic with a secret, else none. */
|
|
57
|
+
tokenEndpointAuthMethod?: TokenEndpointAuthMethod;
|
|
58
|
+
/** Accepted clock skew in seconds when checking tokens. Default: 60 */
|
|
59
|
+
clockTolerance?: number;
|
|
60
|
+
/** Per-request timeout in milliseconds. Default: 15_000 */
|
|
61
|
+
timeout?: number;
|
|
62
|
+
fetch?: typeof globalThis.fetch;
|
|
63
|
+
}
|
|
64
|
+
interface PkcePair {
|
|
65
|
+
codeVerifier: string;
|
|
66
|
+
codeChallenge: string;
|
|
67
|
+
}
|
|
68
|
+
/** A fresh PKCE verifier (64 chars) and its S256 challenge. */
|
|
69
|
+
declare function generatePkce(): Promise<PkcePair>;
|
|
70
|
+
interface AuthorizationUrlParams {
|
|
71
|
+
/** Default: ['openid', 'profile']. `openid` is added when missing. */
|
|
72
|
+
scope?: OidcScope[] | string;
|
|
73
|
+
redirectUri?: string;
|
|
74
|
+
/** 'none' (silent, live apps only) or 'consent'. */
|
|
75
|
+
prompt?: 'none' | 'consent';
|
|
76
|
+
/** Your own state value; generated when omitted. */
|
|
77
|
+
state?: string;
|
|
78
|
+
/** Your own nonce; generated when omitted. */
|
|
79
|
+
nonce?: string;
|
|
80
|
+
/** Additional query parameters. */
|
|
81
|
+
extraParams?: Record<string, string>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* What you must keep (e.g. in a signed, http-only cookie or the server
|
|
85
|
+
* session) until the user comes back to your redirect URI.
|
|
86
|
+
*/
|
|
87
|
+
interface AuthorizationRequest {
|
|
88
|
+
url: string;
|
|
89
|
+
state: string;
|
|
90
|
+
nonce: string;
|
|
91
|
+
codeVerifier: string;
|
|
92
|
+
redirectUri: string;
|
|
93
|
+
}
|
|
94
|
+
interface CallbackChecks {
|
|
95
|
+
state: string;
|
|
96
|
+
nonce: string;
|
|
97
|
+
codeVerifier: string;
|
|
98
|
+
redirectUri?: string;
|
|
99
|
+
}
|
|
100
|
+
interface VerifyIdTokenOptions {
|
|
101
|
+
/** The nonce you sent; required after an authorization request. */
|
|
102
|
+
nonce?: string;
|
|
103
|
+
/** Maximum seconds since the user authenticated (checks auth_time). */
|
|
104
|
+
maxAge?: number;
|
|
105
|
+
}
|
|
106
|
+
interface LoginResult {
|
|
107
|
+
tokens: TokenResponse;
|
|
108
|
+
/** Verified ID token claims. Check `claims.limited` before using profile data. */
|
|
109
|
+
claims: CabalSpyIDClaims;
|
|
110
|
+
}
|
|
111
|
+
/** True when the platform is over its plan's user limit: anonymous sub, no profile data. */
|
|
112
|
+
declare function isLimited(claims: Pick<CabalSpyIDClaims, 'limited' | 'sub'>): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* OpenID Connect client for "Login with CabalSpy ID".
|
|
115
|
+
*
|
|
116
|
+
* const auth = new CabalSpyIDAuth({ clientId, clientSecret, redirectUri });
|
|
117
|
+
* const req = await auth.createAuthorizationUrl({ scope: ['openid', 'profile', 'wallets'] });
|
|
118
|
+
* // store req.state, req.nonce, req.codeVerifier; redirect to req.url
|
|
119
|
+
* const { tokens, claims } = await auth.handleCallback(callbackUrl, stored);
|
|
120
|
+
*/
|
|
121
|
+
declare class CabalSpyIDAuth {
|
|
122
|
+
readonly clientId: string;
|
|
123
|
+
readonly issuer: string;
|
|
124
|
+
readonly redirectUri?: string;
|
|
125
|
+
readonly authMethod: TokenEndpointAuthMethod;
|
|
126
|
+
private readonly clientSecret?;
|
|
127
|
+
private readonly clockTolerance;
|
|
128
|
+
private readonly timeout;
|
|
129
|
+
private readonly fetchImpl;
|
|
130
|
+
private discovery;
|
|
131
|
+
private readonly jwks;
|
|
132
|
+
constructor(options: CabalSpyIDAuthOptions);
|
|
133
|
+
private send;
|
|
134
|
+
private fetchJson;
|
|
135
|
+
private clientAuth;
|
|
136
|
+
private postForm;
|
|
137
|
+
/** The provider's discovery document (cached for the life of this object). */
|
|
138
|
+
discover(): Promise<DiscoveryDocument>;
|
|
139
|
+
/** The provider's public signing keys. */
|
|
140
|
+
getJwks(): Promise<Jwks>;
|
|
141
|
+
/**
|
|
142
|
+
* Builds the authorization URL with PKCE (S256), state and nonce.
|
|
143
|
+
* Store `state`, `nonce` and `codeVerifier` until the callback.
|
|
144
|
+
*/
|
|
145
|
+
createAuthorizationUrl(params?: AuthorizationUrlParams): Promise<AuthorizationRequest>;
|
|
146
|
+
/**
|
|
147
|
+
* Completes the login on your redirect URI: checks `error`, `state` and
|
|
148
|
+
* `iss`, exchanges the code and verifies the ID token (signature, iss, aud,
|
|
149
|
+
* exp, nonce).
|
|
150
|
+
*
|
|
151
|
+
* @param callback the full callback URL, its query string or URLSearchParams
|
|
152
|
+
*/
|
|
153
|
+
handleCallback(callback: string | URL | URLSearchParams, checks: CallbackChecks): Promise<LoginResult>;
|
|
154
|
+
/** POST /oauth/token with grant_type=authorization_code. */
|
|
155
|
+
exchangeCode(params: {
|
|
156
|
+
code: string;
|
|
157
|
+
codeVerifier: string;
|
|
158
|
+
redirectUri?: string;
|
|
159
|
+
}): Promise<TokenResponse>;
|
|
160
|
+
/**
|
|
161
|
+
* POST /oauth/token with grant_type=refresh_token. Refresh tokens rotate:
|
|
162
|
+
* always store the new `refresh_token`. Reusing an old one revokes the whole
|
|
163
|
+
* chain.
|
|
164
|
+
*/
|
|
165
|
+
refresh(refreshToken: string): Promise<TokenResponse>;
|
|
166
|
+
/** POST /oauth/revoke (RFC 7009). Revoking a refresh token ends its whole chain. */
|
|
167
|
+
revoke(token: string): Promise<void>;
|
|
168
|
+
/** GET /oauth/userinfo — full claims for the access token's scopes (x, wallets, onchain …). */
|
|
169
|
+
userinfo(accessToken: string): Promise<CabalSpyIDClaims>;
|
|
170
|
+
/**
|
|
171
|
+
* Verifies an ID token: ES256 signature (JWKS), iss, aud, azp, exp, nonce.
|
|
172
|
+
* Use it for tokens from your own callback and for `idToken` sent from the
|
|
173
|
+
* browser widget's `csid:login` event.
|
|
174
|
+
*
|
|
175
|
+
* When the platform is over its plan's user limit, `sub` is `anon_…` and
|
|
176
|
+
* `limited` is true; see isLimited().
|
|
177
|
+
*/
|
|
178
|
+
verifyIdToken(idToken: string, options?: VerifyIdTokenOptions): Promise<CabalSpyIDClaims>;
|
|
179
|
+
/**
|
|
180
|
+
* Verifies a CabalSpy ID access token (typ at+jwt) issued to this client,
|
|
181
|
+
* e.g. one your frontend sends to your API. Returns its claims
|
|
182
|
+
* (sub, scope, client_id, exp, jti).
|
|
183
|
+
*/
|
|
184
|
+
verifyAccessToken(accessToken: string): Promise<{
|
|
185
|
+
sub: string;
|
|
186
|
+
scope: string;
|
|
187
|
+
client_id: string;
|
|
188
|
+
exp: number;
|
|
189
|
+
jti: string;
|
|
190
|
+
} & Record<string, unknown>>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { type AuthorizationRequest, type AuthorizationUrlParams, CabalSpyIDAuth, type CabalSpyIDAuthOptions, CabalSpyIDClaims, type CallbackChecks, DEFAULT_ISSUER, type DecodedJwt, DiscoveryDocument, type EcJwk, type Jwks, JwksCache, type JwtHeader, type LoginResult, OidcScope, type PkcePair, type TokenEndpointAuthMethod, TokenResponse, type VerifyIdTokenOptions, decodeJwt, generatePkce, isLimited };
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
export { A as ApiErrorBody, a as AuthenticationError, B as BadRequestError, C as CabalSpyID, b as CabalSpyIDError, c as CabalSpyIDErrorOptions, d as CabalSpyIDOptions, e as CabalSpyIDStream, f as CloseEvent, g as ConnectionError, D as DEFAULT_BASE_URL, h as DEFAULT_STREAM_URL, E as Envelope, H as HandleKind, k as HeaderSource, l as HeartbeatEvent, m as HistoryParams, I as InvalidResponseError, n as LatestTransactionsParams, o as LeaderboardParams, N as NotFoundError, O as OAuthError, P as PermissionError, q as PlanUserLimitError, s as ProfileParams, Q as Query, R as RateLimitError, t as RateLimitInfo, v as ReconnectEvent, S as SDK_VERSION, y as ScopedParams, z as ServerError, F as StreamEvent, G as StreamEventMap, J as StreamOptions, K as StreamTopic, T as SubscribedEvent, a3 as TokenVerificationError, a4 as TrackerParams, a5 as UserLike, a7 as UsersParams, a8 as VerifyWebhookOptions, a9 as WalletParams, aa as WebhookVerificationError, ab as handleKind, ac as hasX, ad as signWebhook, ae as verifyWebhook } from './users-CDlDRuyv.js';
|
|
2
|
+
import { O as OidcScope, D as DiscoveryDocument, a8 as TokenResponse, c as CabalSpyIDClaims } from './types-UZeY9n1e.js';
|
|
3
|
+
export { A as ActiveTokens, a as ApiResponse, C as CHAINS, b as CURRENCY_BY_CHAIN, d as Chain, e as Currency, H as HealthResponse, f as HistoryResponse, g as HistoryToken, h as HistoryTrade, i as HoldingToken, j as HoldingsResponse, L as LEADERBOARD_SORTS, k as LeaderboardEntry, l as LeaderboardResponse, m as LeaderboardSort, n as LifetimeStats, M as MeResponse, P as PERIODS, o as Pagination, p as Period, q as PeriodStats, r as PnlCalendarDay, s as PnlCalendarMonth, t as PnlCalendarResponse, u as PnlChartPoint, v as Profile, R as ResponseMeta, S as Scope, a7 as TokenOverview, a9 as TrackerResponse, aa as TrackerTrade, ab as Trade, ac as TradeOwner, ad as TraderProfile, ae as VerifiedWallet, af as WalletClaim, ag as WalletLookupResponse, ah as WebhookEvent, ai as WebhookEventType, aj as WinRateBuckets, ak as WinRateDistribution, al as XProfileClaim } from './types-UZeY9n1e.js';
|
|
4
|
+
|
|
5
|
+
/** ES256 JWT verification against a JWKS, with WebCrypto only (no dependencies). */
|
|
6
|
+
interface EcJwk {
|
|
7
|
+
kty: 'EC';
|
|
8
|
+
crv: 'P-256';
|
|
9
|
+
x: string;
|
|
10
|
+
y: string;
|
|
11
|
+
kid?: string;
|
|
12
|
+
alg?: string;
|
|
13
|
+
use?: string;
|
|
14
|
+
}
|
|
15
|
+
interface Jwks {
|
|
16
|
+
keys: EcJwk[];
|
|
17
|
+
}
|
|
18
|
+
interface JwtHeader {
|
|
19
|
+
alg: string;
|
|
20
|
+
kid?: string;
|
|
21
|
+
typ?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface DecodedJwt<P = Record<string, unknown>> {
|
|
25
|
+
header: JwtHeader;
|
|
26
|
+
payload: P;
|
|
27
|
+
}
|
|
28
|
+
/** Decodes a JWT without verifying it. Never trust the result. */
|
|
29
|
+
declare function decodeJwt<P = Record<string, unknown>>(token: string): DecodedJwt<P>;
|
|
30
|
+
/**
|
|
31
|
+
* Caches the provider's public keys. An unknown `kid` triggers one refetch
|
|
32
|
+
* (key rotation), at most once per `cooldownMs`.
|
|
33
|
+
*/
|
|
34
|
+
declare class JwksCache {
|
|
35
|
+
private readonly load;
|
|
36
|
+
private readonly cooldownMs;
|
|
37
|
+
private keys;
|
|
38
|
+
private loaded;
|
|
39
|
+
private inflight;
|
|
40
|
+
constructor(load: () => Promise<Jwks>, cooldownMs?: number);
|
|
41
|
+
private refresh;
|
|
42
|
+
getKey(kid: string | undefined): Promise<CryptoKey>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare const DEFAULT_ISSUER = "https://id.cabalspy.xyz";
|
|
46
|
+
type TokenEndpointAuthMethod = 'client_secret_basic' | 'client_secret_post' | 'none';
|
|
47
|
+
interface CabalSpyIDAuthOptions {
|
|
48
|
+
/** Your instance's client_id (`csid_…`). */
|
|
49
|
+
clientId: string;
|
|
50
|
+
/** Client secret (`csid_sk_…`) of a server-side app. Omit for public clients. */
|
|
51
|
+
clientSecret?: string;
|
|
52
|
+
/** Default redirect URI. Must exactly match one registered in the dashboard. */
|
|
53
|
+
redirectUri?: string;
|
|
54
|
+
/** Default: https://id.cabalspy.xyz (env CABALSPY_ID_ISSUER) */
|
|
55
|
+
issuer?: string;
|
|
56
|
+
/** Default: client_secret_basic with a secret, else none. */
|
|
57
|
+
tokenEndpointAuthMethod?: TokenEndpointAuthMethod;
|
|
58
|
+
/** Accepted clock skew in seconds when checking tokens. Default: 60 */
|
|
59
|
+
clockTolerance?: number;
|
|
60
|
+
/** Per-request timeout in milliseconds. Default: 15_000 */
|
|
61
|
+
timeout?: number;
|
|
62
|
+
fetch?: typeof globalThis.fetch;
|
|
63
|
+
}
|
|
64
|
+
interface PkcePair {
|
|
65
|
+
codeVerifier: string;
|
|
66
|
+
codeChallenge: string;
|
|
67
|
+
}
|
|
68
|
+
/** A fresh PKCE verifier (64 chars) and its S256 challenge. */
|
|
69
|
+
declare function generatePkce(): Promise<PkcePair>;
|
|
70
|
+
interface AuthorizationUrlParams {
|
|
71
|
+
/** Default: ['openid', 'profile']. `openid` is added when missing. */
|
|
72
|
+
scope?: OidcScope[] | string;
|
|
73
|
+
redirectUri?: string;
|
|
74
|
+
/** 'none' (silent, live apps only) or 'consent'. */
|
|
75
|
+
prompt?: 'none' | 'consent';
|
|
76
|
+
/** Your own state value; generated when omitted. */
|
|
77
|
+
state?: string;
|
|
78
|
+
/** Your own nonce; generated when omitted. */
|
|
79
|
+
nonce?: string;
|
|
80
|
+
/** Additional query parameters. */
|
|
81
|
+
extraParams?: Record<string, string>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* What you must keep (e.g. in a signed, http-only cookie or the server
|
|
85
|
+
* session) until the user comes back to your redirect URI.
|
|
86
|
+
*/
|
|
87
|
+
interface AuthorizationRequest {
|
|
88
|
+
url: string;
|
|
89
|
+
state: string;
|
|
90
|
+
nonce: string;
|
|
91
|
+
codeVerifier: string;
|
|
92
|
+
redirectUri: string;
|
|
93
|
+
}
|
|
94
|
+
interface CallbackChecks {
|
|
95
|
+
state: string;
|
|
96
|
+
nonce: string;
|
|
97
|
+
codeVerifier: string;
|
|
98
|
+
redirectUri?: string;
|
|
99
|
+
}
|
|
100
|
+
interface VerifyIdTokenOptions {
|
|
101
|
+
/** The nonce you sent; required after an authorization request. */
|
|
102
|
+
nonce?: string;
|
|
103
|
+
/** Maximum seconds since the user authenticated (checks auth_time). */
|
|
104
|
+
maxAge?: number;
|
|
105
|
+
}
|
|
106
|
+
interface LoginResult {
|
|
107
|
+
tokens: TokenResponse;
|
|
108
|
+
/** Verified ID token claims. Check `claims.limited` before using profile data. */
|
|
109
|
+
claims: CabalSpyIDClaims;
|
|
110
|
+
}
|
|
111
|
+
/** True when the platform is over its plan's user limit: anonymous sub, no profile data. */
|
|
112
|
+
declare function isLimited(claims: Pick<CabalSpyIDClaims, 'limited' | 'sub'>): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* OpenID Connect client for "Login with CabalSpy ID".
|
|
115
|
+
*
|
|
116
|
+
* const auth = new CabalSpyIDAuth({ clientId, clientSecret, redirectUri });
|
|
117
|
+
* const req = await auth.createAuthorizationUrl({ scope: ['openid', 'profile', 'wallets'] });
|
|
118
|
+
* // store req.state, req.nonce, req.codeVerifier; redirect to req.url
|
|
119
|
+
* const { tokens, claims } = await auth.handleCallback(callbackUrl, stored);
|
|
120
|
+
*/
|
|
121
|
+
declare class CabalSpyIDAuth {
|
|
122
|
+
readonly clientId: string;
|
|
123
|
+
readonly issuer: string;
|
|
124
|
+
readonly redirectUri?: string;
|
|
125
|
+
readonly authMethod: TokenEndpointAuthMethod;
|
|
126
|
+
private readonly clientSecret?;
|
|
127
|
+
private readonly clockTolerance;
|
|
128
|
+
private readonly timeout;
|
|
129
|
+
private readonly fetchImpl;
|
|
130
|
+
private discovery;
|
|
131
|
+
private readonly jwks;
|
|
132
|
+
constructor(options: CabalSpyIDAuthOptions);
|
|
133
|
+
private send;
|
|
134
|
+
private fetchJson;
|
|
135
|
+
private clientAuth;
|
|
136
|
+
private postForm;
|
|
137
|
+
/** The provider's discovery document (cached for the life of this object). */
|
|
138
|
+
discover(): Promise<DiscoveryDocument>;
|
|
139
|
+
/** The provider's public signing keys. */
|
|
140
|
+
getJwks(): Promise<Jwks>;
|
|
141
|
+
/**
|
|
142
|
+
* Builds the authorization URL with PKCE (S256), state and nonce.
|
|
143
|
+
* Store `state`, `nonce` and `codeVerifier` until the callback.
|
|
144
|
+
*/
|
|
145
|
+
createAuthorizationUrl(params?: AuthorizationUrlParams): Promise<AuthorizationRequest>;
|
|
146
|
+
/**
|
|
147
|
+
* Completes the login on your redirect URI: checks `error`, `state` and
|
|
148
|
+
* `iss`, exchanges the code and verifies the ID token (signature, iss, aud,
|
|
149
|
+
* exp, nonce).
|
|
150
|
+
*
|
|
151
|
+
* @param callback the full callback URL, its query string or URLSearchParams
|
|
152
|
+
*/
|
|
153
|
+
handleCallback(callback: string | URL | URLSearchParams, checks: CallbackChecks): Promise<LoginResult>;
|
|
154
|
+
/** POST /oauth/token with grant_type=authorization_code. */
|
|
155
|
+
exchangeCode(params: {
|
|
156
|
+
code: string;
|
|
157
|
+
codeVerifier: string;
|
|
158
|
+
redirectUri?: string;
|
|
159
|
+
}): Promise<TokenResponse>;
|
|
160
|
+
/**
|
|
161
|
+
* POST /oauth/token with grant_type=refresh_token. Refresh tokens rotate:
|
|
162
|
+
* always store the new `refresh_token`. Reusing an old one revokes the whole
|
|
163
|
+
* chain.
|
|
164
|
+
*/
|
|
165
|
+
refresh(refreshToken: string): Promise<TokenResponse>;
|
|
166
|
+
/** POST /oauth/revoke (RFC 7009). Revoking a refresh token ends its whole chain. */
|
|
167
|
+
revoke(token: string): Promise<void>;
|
|
168
|
+
/** GET /oauth/userinfo — full claims for the access token's scopes (x, wallets, onchain …). */
|
|
169
|
+
userinfo(accessToken: string): Promise<CabalSpyIDClaims>;
|
|
170
|
+
/**
|
|
171
|
+
* Verifies an ID token: ES256 signature (JWKS), iss, aud, azp, exp, nonce.
|
|
172
|
+
* Use it for tokens from your own callback and for `idToken` sent from the
|
|
173
|
+
* browser widget's `csid:login` event.
|
|
174
|
+
*
|
|
175
|
+
* When the platform is over its plan's user limit, `sub` is `anon_…` and
|
|
176
|
+
* `limited` is true; see isLimited().
|
|
177
|
+
*/
|
|
178
|
+
verifyIdToken(idToken: string, options?: VerifyIdTokenOptions): Promise<CabalSpyIDClaims>;
|
|
179
|
+
/**
|
|
180
|
+
* Verifies a CabalSpy ID access token (typ at+jwt) issued to this client,
|
|
181
|
+
* e.g. one your frontend sends to your API. Returns its claims
|
|
182
|
+
* (sub, scope, client_id, exp, jti).
|
|
183
|
+
*/
|
|
184
|
+
verifyAccessToken(accessToken: string): Promise<{
|
|
185
|
+
sub: string;
|
|
186
|
+
scope: string;
|
|
187
|
+
client_id: string;
|
|
188
|
+
exp: number;
|
|
189
|
+
jti: string;
|
|
190
|
+
} & Record<string, unknown>>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { type AuthorizationRequest, type AuthorizationUrlParams, CabalSpyIDAuth, type CabalSpyIDAuthOptions, CabalSpyIDClaims, type CallbackChecks, DEFAULT_ISSUER, type DecodedJwt, DiscoveryDocument, type EcJwk, type Jwks, JwksCache, type JwtHeader, type LoginResult, OidcScope, type PkcePair, type TokenEndpointAuthMethod, TokenResponse, type VerifyIdTokenOptions, decodeJwt, generatePkce, isLimited };
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CabalSpyIDAuth,
|
|
3
|
+
DEFAULT_ISSUER,
|
|
4
|
+
JwksCache,
|
|
5
|
+
decodeJwt,
|
|
6
|
+
generatePkce,
|
|
7
|
+
isLimited
|
|
8
|
+
} from "./chunk-Z3UPDOBY.js";
|
|
9
|
+
import "./chunk-CJFIOVBA.js";
|
|
10
|
+
import {
|
|
11
|
+
AuthenticationError,
|
|
12
|
+
BadRequestError,
|
|
13
|
+
CHAINS,
|
|
14
|
+
CURRENCY_BY_CHAIN,
|
|
15
|
+
CabalSpyID,
|
|
16
|
+
CabalSpyIDError,
|
|
17
|
+
CabalSpyIDStream,
|
|
18
|
+
ConnectionError,
|
|
19
|
+
DEFAULT_BASE_URL,
|
|
20
|
+
DEFAULT_STREAM_URL,
|
|
21
|
+
InvalidResponseError,
|
|
22
|
+
LEADERBOARD_SORTS,
|
|
23
|
+
NotFoundError,
|
|
24
|
+
OAuthError,
|
|
25
|
+
PERIODS,
|
|
26
|
+
PermissionError,
|
|
27
|
+
PlanUserLimitError,
|
|
28
|
+
RateLimitError,
|
|
29
|
+
SDK_VERSION,
|
|
30
|
+
ServerError,
|
|
31
|
+
TokenVerificationError,
|
|
32
|
+
WebhookVerificationError,
|
|
33
|
+
handleKind,
|
|
34
|
+
hasX,
|
|
35
|
+
signWebhook,
|
|
36
|
+
verifyWebhook
|
|
37
|
+
} from "./chunk-3LKLY5WQ.js";
|
|
38
|
+
export {
|
|
39
|
+
AuthenticationError,
|
|
40
|
+
BadRequestError,
|
|
41
|
+
CHAINS,
|
|
42
|
+
CURRENCY_BY_CHAIN,
|
|
43
|
+
CabalSpyID,
|
|
44
|
+
CabalSpyIDAuth,
|
|
45
|
+
CabalSpyIDError,
|
|
46
|
+
CabalSpyIDStream,
|
|
47
|
+
ConnectionError,
|
|
48
|
+
DEFAULT_BASE_URL,
|
|
49
|
+
DEFAULT_ISSUER,
|
|
50
|
+
DEFAULT_STREAM_URL,
|
|
51
|
+
InvalidResponseError,
|
|
52
|
+
JwksCache,
|
|
53
|
+
LEADERBOARD_SORTS,
|
|
54
|
+
NotFoundError,
|
|
55
|
+
OAuthError,
|
|
56
|
+
PERIODS,
|
|
57
|
+
PermissionError,
|
|
58
|
+
PlanUserLimitError,
|
|
59
|
+
RateLimitError,
|
|
60
|
+
SDK_VERSION,
|
|
61
|
+
ServerError,
|
|
62
|
+
TokenVerificationError,
|
|
63
|
+
WebhookVerificationError,
|
|
64
|
+
decodeJwt,
|
|
65
|
+
generatePkce,
|
|
66
|
+
handleKind,
|
|
67
|
+
hasX,
|
|
68
|
+
isLimited,
|
|
69
|
+
signWebhook,
|
|
70
|
+
verifyWebhook
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|