@lifi/perps-sdk-provider-lighter 17.0.1 → 17.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/LighterProvider.d.ts.map +1 -1
- package/dist/cjs/LighterProvider.js +1 -0
- package/dist/cjs/LighterProvider.js.map +1 -1
- package/dist/cjs/accountConfig.d.ts.map +1 -1
- package/dist/cjs/accountConfig.js +12 -4
- package/dist/cjs/accountConfig.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.d.ts.map +1 -1
- package/dist/cjs/constants.js +2 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/signers/LighterKeyStore.d.ts +2 -1
- package/dist/cjs/signers/LighterKeyStore.d.ts.map +1 -1
- package/dist/cjs/signers/LighterKeyStore.js +8 -6
- package/dist/cjs/signers/LighterKeyStore.js.map +1 -1
- package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts +42 -0
- package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
- package/dist/cjs/signers/LighterReadOnlyTokenManager.js +87 -6
- package/dist/cjs/signers/LighterReadOnlyTokenManager.js.map +1 -1
- package/dist/cjs/signers/signActions.d.ts.map +1 -1
- package/dist/cjs/signers/signActions.js +9 -5
- package/dist/cjs/signers/signActions.js.map +1 -1
- package/dist/cjs/types/fill.d.ts +2 -0
- package/dist/cjs/types/fill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js +8 -0
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/esm/LighterProvider.d.ts.map +1 -1
- package/dist/esm/LighterProvider.js +1 -0
- package/dist/esm/LighterProvider.js.map +1 -1
- package/dist/esm/accountConfig.d.ts.map +1 -1
- package/dist/esm/accountConfig.js +29 -16
- package/dist/esm/accountConfig.js.map +1 -1
- package/dist/esm/constants.d.ts +9 -0
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +9 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/signers/LighterKeyStore.d.ts +12 -4
- package/dist/esm/signers/LighterKeyStore.d.ts.map +1 -1
- package/dist/esm/signers/LighterKeyStore.js +16 -15
- package/dist/esm/signers/LighterKeyStore.js.map +1 -1
- package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts +112 -12
- package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
- package/dist/esm/signers/LighterReadOnlyTokenManager.js +119 -8
- package/dist/esm/signers/LighterReadOnlyTokenManager.js.map +1 -1
- package/dist/esm/signers/signActions.d.ts.map +1 -1
- package/dist/esm/signers/signActions.js +15 -9
- package/dist/esm/signers/signActions.js.map +1 -1
- package/dist/esm/types/fill.d.ts +2 -0
- package/dist/esm/types/fill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +16 -1
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/types/LighterProvider.d.ts.map +1 -1
- package/dist/types/accountConfig.d.ts.map +1 -1
- package/dist/types/constants.d.ts +9 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/signers/LighterKeyStore.d.ts +12 -4
- package/dist/types/signers/LighterKeyStore.d.ts.map +1 -1
- package/dist/types/signers/LighterReadOnlyTokenManager.d.ts +112 -12
- package/dist/types/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
- package/dist/types/signers/signActions.d.ts.map +1 -1
- package/dist/types/types/fill.d.ts +2 -0
- package/dist/types/types/fill.d.ts.map +1 -1
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/LighterProvider.ts +1 -0
- package/src/accountConfig.ts +33 -16
- package/src/constants.ts +10 -0
- package/src/signers/LighterKeyStore.ts +50 -29
- package/src/signers/LighterReadOnlyTokenManager.ts +245 -18
- package/src/signers/signActions.ts +18 -11
- package/src/types/fill.ts +6 -0
- package/src/utils/mapFill.ts +21 -1
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { readValidatedRecord } from '@lifi/perps-sdk';
|
|
2
2
|
import { LIGHTER_PROVIDER_KEY } from '../constants.js';
|
|
3
3
|
// The private key here is a Lighter custom keypair — generated via WASM
|
|
4
|
-
// GenerateAPIKey — not an Ethereum private key.
|
|
5
|
-
// by the resolved provider instance key so two Lighter instances sharing a
|
|
6
|
-
// storage adapter (e.g. `lighter` and `lighter-rh`) never clobber each other's
|
|
7
|
-
// API key.
|
|
4
|
+
// GenerateAPIKey — not an Ethereum private key.
|
|
8
5
|
const STORAGE_PREFIX = 'lifi-perps-lighter-key';
|
|
9
|
-
const
|
|
6
|
+
const isLighterApiKeyOf = (owner) => (value) => {
|
|
10
7
|
if (typeof value !== 'object' || value === null) {
|
|
11
8
|
return false;
|
|
12
9
|
}
|
|
13
|
-
const { accountIndex, apiKeyIndex, apiKeyPrivateKey, apiKeyPublicKey } = value;
|
|
14
|
-
return (
|
|
10
|
+
const { providerKey, accountIndex, apiKeyIndex, apiKeyPrivateKey, apiKeyPublicKey, } = value;
|
|
11
|
+
return (providerKey === owner &&
|
|
12
|
+
typeof accountIndex === 'number' &&
|
|
15
13
|
Number.isFinite(accountIndex) &&
|
|
16
14
|
typeof apiKeyIndex === 'number' &&
|
|
17
15
|
Number.isFinite(apiKeyIndex) &&
|
|
@@ -22,8 +20,9 @@ const isLighterApiKey = (value) => {
|
|
|
22
20
|
};
|
|
23
21
|
/**
|
|
24
22
|
* Storage-backed cache for Lighter API keys. Records are namespaced by L1
|
|
25
|
-
* address and provider instance
|
|
26
|
-
* {@link StorageAdapter}
|
|
23
|
+
* address and provider instance, and each record names its own instance, so
|
|
24
|
+
* multiple Lighter deployments can share one {@link StorageAdapter} and no
|
|
25
|
+
* instance ever reads another instance's key material.
|
|
27
26
|
*
|
|
28
27
|
* @public
|
|
29
28
|
*/
|
|
@@ -49,8 +48,8 @@ export class LighterKeyStore {
|
|
|
49
48
|
bindProviderKey(providerKey) {
|
|
50
49
|
this.providerKey = providerKey;
|
|
51
50
|
}
|
|
52
|
-
// The default instance keeps the legacy, un-namespaced
|
|
53
|
-
//
|
|
51
|
+
// The default instance keeps the legacy, un-namespaced slot name; only
|
|
52
|
+
// additional instances get a segment.
|
|
54
53
|
storageKey(address) {
|
|
55
54
|
const lower = address.toLowerCase();
|
|
56
55
|
return this.providerKey === LIGHTER_PROVIDER_KEY
|
|
@@ -67,7 +66,7 @@ export class LighterKeyStore {
|
|
|
67
66
|
if (cached) {
|
|
68
67
|
return cached;
|
|
69
68
|
}
|
|
70
|
-
const parsed = await readValidatedRecord(this.storage, key,
|
|
69
|
+
const parsed = await readValidatedRecord(this.storage, key, isLighterApiKeyOf(this.providerKey));
|
|
71
70
|
if (!parsed) {
|
|
72
71
|
return null;
|
|
73
72
|
}
|
|
@@ -76,12 +75,14 @@ export class LighterKeyStore {
|
|
|
76
75
|
}
|
|
77
76
|
/**
|
|
78
77
|
* Persist an API key for an L1 address, replacing any existing record under
|
|
79
|
-
* that provider namespace.
|
|
78
|
+
* that provider namespace. The store stamps the record with its own instance
|
|
79
|
+
* key, so callers never name the instance themselves.
|
|
80
80
|
*/
|
|
81
81
|
async set(address, value) {
|
|
82
82
|
const key = this.storageKey(address);
|
|
83
|
-
this.
|
|
84
|
-
|
|
83
|
+
const record = { ...value, providerKey: this.providerKey };
|
|
84
|
+
this.cache.set(key, record);
|
|
85
|
+
await this.storage.set(key, JSON.stringify(record));
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
87
88
|
* Remove the persisted API key for an L1 address and clear its in-memory
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LighterKeyStore.js","sourceRoot":"","sources":["../../../src/signers/LighterKeyStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAuB,MAAM,iBAAiB,CAAA;AAG1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEtD,wEAAwE;AACxE,
|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OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;IACrD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,OAAgB;QAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QACpC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACtB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;CACF"}
|
|
@@ -5,7 +5,7 @@ import type { Address } from 'viem';
|
|
|
5
5
|
* Default token name persisted alongside Lighter's `tokens/create` row.
|
|
6
6
|
* Lighter requires a non-empty `name` form field; the literal here is what
|
|
7
7
|
* surfaces in Lighter's UI listing under `app.lighter.xyz/read-only-tokens`.
|
|
8
|
-
* @
|
|
8
|
+
* @internal
|
|
9
9
|
*/
|
|
10
10
|
export declare const DEFAULT_READ_ONLY_TOKEN_NAME = "LI.FI Perps";
|
|
11
11
|
/**
|
|
@@ -13,7 +13,7 @@ export declare const DEFAULT_READ_ONLY_TOKEN_NAME = "LI.FI Perps";
|
|
|
13
13
|
* Lighter's opaque `ro:{accountIndex}:{scope}:{expiry}:{rand}` bearer; the
|
|
14
14
|
* SDK never parses it — `expiry`/`scope`/`accountIndex` are create-time inputs
|
|
15
15
|
* we keep alongside so consumers can render expiry UX without re-fetching.
|
|
16
|
-
* @
|
|
16
|
+
* @internal
|
|
17
17
|
*/
|
|
18
18
|
export interface LighterReadOnlyToken {
|
|
19
19
|
/** Opaque bearer string — never parse client-side. */
|
|
@@ -24,25 +24,33 @@ export interface LighterReadOnlyToken {
|
|
|
24
24
|
scope: 'single' | 'all';
|
|
25
25
|
/** Lighter L2 account index the token authorises. */
|
|
26
26
|
accountIndex: number;
|
|
27
|
+
/**
|
|
28
|
+
* Lighter's monotonic registry row id. Optional: a record persisted without
|
|
29
|
+
* it stays valid, and the cleanup pass then identifies its row by the
|
|
30
|
+
* bearer string instead.
|
|
31
|
+
*/
|
|
32
|
+
tokenId?: number;
|
|
27
33
|
}
|
|
28
34
|
/**
|
|
29
|
-
* Lighter `POST /api/v1/tokens/create` response shape
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* @
|
|
35
|
+
* Lighter `POST /api/v1/tokens/create` response shape — the subset of
|
|
36
|
+
* Lighter's `RespPostApiToken` the SDK consumes. Lighter documents further
|
|
37
|
+
* fields (`name`, `revoked`, `sub_account_access`) the SDK does not need.
|
|
38
|
+
* @internal
|
|
33
39
|
*/
|
|
34
40
|
export interface LighterCreateTokenResponse {
|
|
35
41
|
api_token: string;
|
|
36
42
|
account_index: number;
|
|
37
43
|
expiry: number;
|
|
38
44
|
scopes: string;
|
|
45
|
+
/** Monotonic registry row id Lighter assigns to the new row. */
|
|
46
|
+
token_id: number;
|
|
39
47
|
}
|
|
40
48
|
/**
|
|
41
49
|
* Function injected for the HTTP boundary against Lighter's `tokens/create`
|
|
42
50
|
* endpoint. Returning a parsed {@link LighterCreateTokenResponse} keeps the
|
|
43
51
|
* create code free of fetch/multipart plumbing and lets tests drop a fixture
|
|
44
52
|
* in without spinning a mock server.
|
|
45
|
-
* @
|
|
53
|
+
* @internal
|
|
46
54
|
*/
|
|
47
55
|
export type LighterTokenFetcher = (params: {
|
|
48
56
|
url: string;
|
|
@@ -53,12 +61,71 @@ export type LighterTokenFetcher = (params: {
|
|
|
53
61
|
subAccountAccess: boolean;
|
|
54
62
|
scopes: string;
|
|
55
63
|
}) => Promise<LighterCreateTokenResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* One row of Lighter's read-only token registry, matching Lighter's
|
|
66
|
+
* `ApiToken`. `name` carries the label supplied at create time, which is how
|
|
67
|
+
* the SDK recognises a row it owns.
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export interface LighterApiToken {
|
|
71
|
+
token_id: number;
|
|
72
|
+
api_token: string;
|
|
73
|
+
name: string;
|
|
74
|
+
account_index: number;
|
|
75
|
+
expiry: number;
|
|
76
|
+
sub_account_access: boolean;
|
|
77
|
+
revoked: boolean;
|
|
78
|
+
scopes: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Lighter `GET /api/v1/tokens` response shape, matching `RespGetApiTokens`.
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
export interface LighterListTokensResponse {
|
|
85
|
+
code: number;
|
|
86
|
+
message?: string;
|
|
87
|
+
api_tokens: LighterApiToken[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Lighter `POST /api/v1/tokens/revoke` response shape, matching Lighter's
|
|
91
|
+
* `RespRevokeApiToken`.
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
export interface LighterRevokeTokenResponse {
|
|
95
|
+
code: number;
|
|
96
|
+
message?: string;
|
|
97
|
+
token_id: number;
|
|
98
|
+
revoked: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Function injected for the HTTP boundary against Lighter's
|
|
102
|
+
* `GET /api/v1/tokens` endpoint. Injected for the same reason as
|
|
103
|
+
* {@link LighterTokenFetcher}: a unit spec supplies a registry fixture
|
|
104
|
+
* without a mock server.
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
export type LighterTokenListFetcher = (params: {
|
|
108
|
+
url: string;
|
|
109
|
+
authorization: string;
|
|
110
|
+
accountIndex: number;
|
|
111
|
+
}) => Promise<LighterListTokensResponse>;
|
|
112
|
+
/**
|
|
113
|
+
* Function injected for the HTTP boundary against Lighter's
|
|
114
|
+
* `POST /api/v1/tokens/revoke` endpoint.
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
export type LighterTokenRevokeFetcher = (params: {
|
|
118
|
+
url: string;
|
|
119
|
+
authorization: string;
|
|
120
|
+
tokenId: number;
|
|
121
|
+
accountIndex: number;
|
|
122
|
+
}) => Promise<LighterRevokeTokenResponse>;
|
|
56
123
|
/**
|
|
57
124
|
* Dependencies and overrides for {@link LighterReadOnlyTokenManager}.
|
|
58
125
|
* Storage and token-fetching defaults target the browser's local storage and
|
|
59
126
|
* Lighter's mainnet REST API.
|
|
60
127
|
*
|
|
61
|
-
* @
|
|
128
|
+
* @internal
|
|
62
129
|
*/
|
|
63
130
|
export interface LighterReadOnlyTokenManagerOptions {
|
|
64
131
|
storage?: StorageAdapter;
|
|
@@ -73,6 +140,10 @@ export interface LighterReadOnlyTokenManagerOptions {
|
|
|
73
140
|
lighterApiUrl?: string;
|
|
74
141
|
/** Override the multipart POST. Defaults to a `fetch`-based implementation. */
|
|
75
142
|
fetcher?: LighterTokenFetcher;
|
|
143
|
+
/** Override the registry list GET. Defaults to a `fetch`-based implementation. */
|
|
144
|
+
listFetcher?: LighterTokenListFetcher;
|
|
145
|
+
/** Override the revoke POST. Defaults to a `fetch`-based implementation. */
|
|
146
|
+
revokeFetcher?: LighterTokenRevokeFetcher;
|
|
76
147
|
/** Clock injection for testing expiry logic. Defaults to `Date.now`. */
|
|
77
148
|
now?: () => number;
|
|
78
149
|
}
|
|
@@ -80,7 +151,7 @@ export interface LighterReadOnlyTokenManagerOptions {
|
|
|
80
151
|
* Input to the read-only-token approval flow. Extends the shared approval
|
|
81
152
|
* parameters with the L1 address whose wallet authorizes token creation.
|
|
82
153
|
*
|
|
83
|
-
* @
|
|
154
|
+
* @internal
|
|
84
155
|
*/
|
|
85
156
|
export interface ApproveReadOnlyTokenInputs extends ApproveReadOnlyTokenParams {
|
|
86
157
|
/** L1 wallet address that signs the create message. */
|
|
@@ -90,7 +161,7 @@ export interface ApproveReadOnlyTokenInputs extends ApproveReadOnlyTokenParams {
|
|
|
90
161
|
* Result of approving or creating a Lighter read-only token. `config` is the
|
|
91
162
|
* account-state projection callers can persist alongside the token.
|
|
92
163
|
*
|
|
93
|
-
* @
|
|
164
|
+
* @internal
|
|
94
165
|
*/
|
|
95
166
|
export interface ApproveReadOnlyTokenResult {
|
|
96
167
|
token: LighterReadOnlyToken;
|
|
@@ -114,18 +185,22 @@ export interface ApproveReadOnlyTokenResult {
|
|
|
114
185
|
* a fully compromised page — a same-origin script can still drive this manager
|
|
115
186
|
* to decrypt. Blast radius is limited to reads: the token cannot sign orders
|
|
116
187
|
* or move funds.
|
|
117
|
-
* @
|
|
188
|
+
* @internal
|
|
118
189
|
*/
|
|
119
190
|
export declare class LighterReadOnlyTokenManager {
|
|
120
191
|
private readonly storage;
|
|
121
192
|
private readonly providerKey;
|
|
122
193
|
private readonly lighterApiUrl;
|
|
123
194
|
private readonly fetcher;
|
|
195
|
+
private readonly listFetcher;
|
|
196
|
+
private readonly revokeFetcher;
|
|
124
197
|
private readonly now;
|
|
125
198
|
private readonly cache;
|
|
126
199
|
constructor(options?: LighterReadOnlyTokenManagerOptions);
|
|
127
200
|
private storageKey;
|
|
128
201
|
private isExpired;
|
|
202
|
+
/** Stored record for the pair, whether or not it is past its `expiry`. */
|
|
203
|
+
private readStoredToken;
|
|
129
204
|
/**
|
|
130
205
|
* Return the stored token for the `(address, accountIndex)` pair, or
|
|
131
206
|
* `undefined` if absent or past its `expiry`. Never surfaces an expired
|
|
@@ -157,6 +232,9 @@ export declare class LighterReadOnlyTokenManager {
|
|
|
157
232
|
* and persists the returned `ro:` bearer alongside its
|
|
158
233
|
* `expiry`/`scope`/`accountIndex`.
|
|
159
234
|
*
|
|
235
|
+
* Before the create call, the flow revokes this SDK's own stale registry
|
|
236
|
+
* rows. That pass is best-effort: a failure is logged and the create runs.
|
|
237
|
+
*
|
|
160
238
|
* `authorization` MUST be a **standard** Lighter auth token — one created by
|
|
161
239
|
* the account's API key (`createAuthToken` / the WASM signer), NOT an L1
|
|
162
240
|
* wallet signature. Lighter authenticates the create request with that token
|
|
@@ -175,13 +253,35 @@ export declare class LighterReadOnlyTokenManager {
|
|
|
175
253
|
* @param inputs Token-create parameters plus the owning `address`.
|
|
176
254
|
*/
|
|
177
255
|
approve(authorization: string, inputs: ApproveReadOnlyTokenInputs): Promise<ApproveReadOnlyTokenResult>;
|
|
256
|
+
/**
|
|
257
|
+
* Revoke the registry rows this SDK owns and no longer needs. Lighter's
|
|
258
|
+
* `tokens/create` appends a row on every call, so without this pass the
|
|
259
|
+
* user's registry grows on every rotation.
|
|
260
|
+
*/
|
|
261
|
+
private revokeStaleOwnTokens;
|
|
178
262
|
}
|
|
179
263
|
/**
|
|
180
264
|
* Default fetcher: posts a multipart/form-data request to Lighter's
|
|
181
265
|
* `tokens/create` endpoint and returns the parsed response. Throws a
|
|
182
266
|
* {@link PerpsError} with the Lighter-side body when the response is
|
|
183
267
|
* non-2xx.
|
|
184
|
-
* @
|
|
268
|
+
* @internal
|
|
185
269
|
*/
|
|
186
270
|
export declare const defaultLighterTokenFetcher: LighterTokenFetcher;
|
|
271
|
+
/**
|
|
272
|
+
* Default list fetcher: `GET /api/v1/tokens` with `account_index` as a query
|
|
273
|
+
* parameter. Lighter's OpenAPI defines no request body for this route. Throws
|
|
274
|
+
* a {@link PerpsError} with the Lighter-side body when the response is
|
|
275
|
+
* non-2xx.
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
export declare const defaultLighterTokenListFetcher: LighterTokenListFetcher;
|
|
279
|
+
/**
|
|
280
|
+
* Default revoke fetcher: posts `application/x-www-form-urlencoded` to
|
|
281
|
+
* Lighter's `tokens/revoke` endpoint, which is the content type Lighter's
|
|
282
|
+
* OpenAPI declares for that route. Throws a {@link PerpsError} with the
|
|
283
|
+
* Lighter-side body when the response is non-2xx.
|
|
284
|
+
* @internal
|
|
285
|
+
*/
|
|
286
|
+
export declare const defaultLighterTokenRevokeFetcher: LighterTokenRevokeFetcher;
|
|
187
287
|
//# sourceMappingURL=LighterReadOnlyTokenManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LighterReadOnlyTokenManager.d.ts","sourceRoot":"","sources":["../../../src/signers/LighterReadOnlyTokenManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EACV,0BAA0B,EAC1B,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAGnC;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,gBAAgB,CAAA;AAEzD;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAA;IACb,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAA;IACd,sEAAsE;IACtE,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAA;IACvB,qDAAqD;IACrD,YAAY,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"LighterReadOnlyTokenManager.d.ts","sourceRoot":"","sources":["../../../src/signers/LighterReadOnlyTokenManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EACV,0BAA0B,EAC1B,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAGnC;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,gBAAgB,CAAA;AAEzD;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAA;IACb,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAA;IACd,sEAAsE;IACtE,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAA;IACvB,qDAAqD;IACrD,YAAY,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EA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isted alongside Lighter's `tokens/create` row.
|
|
6
6
|
* Lighter requires a non-empty `name` form field; the literal here is what
|
|
7
7
|
* surfaces in Lighter's UI listing under `app.lighter.xyz/read-only-tokens`.
|
|
8
|
-
* @
|
|
8
|
+
* @internal
|
|
9
9
|
*/
|
|
10
10
|
export const DEFAULT_READ_ONLY_TOKEN_NAME = 'LI.FI Perps';
|
|
11
11
|
const SECONDS_PER_DAY = 86_400;
|
|
@@ -13,15 +13,21 @@ const isLighterReadOnlyToken = (value) => {
|
|
|
13
13
|
if (typeof value !== 'object' || value === null) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
const { token, expiry, scope, accountIndex } = value;
|
|
16
|
+
const { token, expiry, scope, accountIndex, tokenId } = value;
|
|
17
|
+
// Accept a record that carries no `tokenId`: rejecting one would discard a
|
|
18
|
+
// usable token and force an unnecessary replacement.
|
|
17
19
|
return (typeof token === 'string' &&
|
|
18
20
|
token.length > 0 &&
|
|
19
21
|
typeof expiry === 'number' &&
|
|
20
22
|
Number.isFinite(expiry) &&
|
|
21
23
|
(scope === 'single' || scope === 'all') &&
|
|
22
24
|
typeof accountIndex === 'number' &&
|
|
23
|
-
Number.isFinite(accountIndex)
|
|
25
|
+
Number.isFinite(accountIndex) &&
|
|
26
|
+
(tokenId === undefined ||
|
|
27
|
+
(typeof tokenId === 'number' && Number.isFinite(tokenId))));
|
|
24
28
|
};
|
|
29
|
+
const isLiveRow = (row, live) => live !== undefined &&
|
|
30
|
+
(row.token_id === live.tokenId || row.api_token === live.token);
|
|
25
31
|
/**
|
|
26
32
|
* Manage the per-account Lighter read-only token alongside the existing
|
|
27
33
|
* `(L1 address, account index)`-scoped storage adapter pattern. Takes an
|
|
@@ -39,13 +45,15 @@ const isLighterReadOnlyToken = (value) => {
|
|
|
39
45
|
* a fully compromised page — a same-origin script can still drive this manager
|
|
40
46
|
* to decrypt. Blast radius is limited to reads: the token cannot sign orders
|
|
41
47
|
* or move funds.
|
|
42
|
-
* @
|
|
48
|
+
* @internal
|
|
43
49
|
*/
|
|
44
50
|
export class LighterReadOnlyTokenManager {
|
|
45
51
|
storage;
|
|
46
52
|
providerKey;
|
|
47
53
|
lighterApiUrl;
|
|
48
54
|
fetcher;
|
|
55
|
+
listFetcher;
|
|
56
|
+
revokeFetcher;
|
|
49
57
|
now;
|
|
50
58
|
cache = new Map();
|
|
51
59
|
constructor(options = {}) {
|
|
@@ -53,6 +61,9 @@ export class LighterReadOnlyTokenManager {
|
|
|
53
61
|
this.providerKey = options.providerKey ?? LIGHTER_PROVIDER_KEY;
|
|
54
62
|
this.lighterApiUrl = options.lighterApiUrl ?? DEFAULT_LIGHTER_REST_URL;
|
|
55
63
|
this.fetcher = options.fetcher ?? defaultLighterTokenFetcher;
|
|
64
|
+
this.listFetcher = options.listFetcher ?? defaultLighterTokenListFetcher;
|
|
65
|
+
this.revokeFetcher =
|
|
66
|
+
options.revokeFetcher ?? defaultLighterTokenRevokeFetcher;
|
|
56
67
|
this.now = options.now ?? (() => Date.now());
|
|
57
68
|
}
|
|
58
69
|
storageKey(address, accountIndex) {
|
|
@@ -61,6 +72,13 @@ export class LighterReadOnlyTokenManager {
|
|
|
61
72
|
isExpired(token) {
|
|
62
73
|
return token.expiry * 1000 <= this.now();
|
|
63
74
|
}
|
|
75
|
+
/** Stored record for the pair, whether or not it is past its `expiry`. */
|
|
76
|
+
async readStoredToken(address, accountIndex) {
|
|
77
|
+
const key = this.storageKey(address, accountIndex);
|
|
78
|
+
return (this.cache.get(key) ??
|
|
79
|
+
(await readValidatedRecord(this.storage, key, isLighterReadOnlyToken)) ??
|
|
80
|
+
undefined);
|
|
81
|
+
}
|
|
64
82
|
/**
|
|
65
83
|
* Return the stored token for the `(address, accountIndex)` pair, or
|
|
66
84
|
* `undefined` if absent or past its `expiry`. Never surfaces an expired
|
|
@@ -86,9 +104,7 @@ export class LighterReadOnlyTokenManager {
|
|
|
86
104
|
* has more than `thresholdDays` of life left.
|
|
87
105
|
*/
|
|
88
106
|
async isReadOnlyTokenExpiringSoon(address, accountIndex, thresholdDays = 30) {
|
|
89
|
-
const
|
|
90
|
-
const token = this.cache.get(key) ??
|
|
91
|
-
(await readValidatedRecord(this.storage, key, isLighterReadOnlyToken));
|
|
107
|
+
const token = await this.readStoredToken(address, accountIndex);
|
|
92
108
|
if (!token) {
|
|
93
109
|
return false;
|
|
94
110
|
}
|
|
@@ -124,6 +140,9 @@ export class LighterReadOnlyTokenManager {
|
|
|
124
140
|
* and persists the returned `ro:` bearer alongside its
|
|
125
141
|
* `expiry`/`scope`/`accountIndex`.
|
|
126
142
|
*
|
|
143
|
+
* Before the create call, the flow revokes this SDK's own stale registry
|
|
144
|
+
* rows. That pass is best-effort: a failure is logged and the create runs.
|
|
145
|
+
*
|
|
127
146
|
* `authorization` MUST be a **standard** Lighter auth token — one created by
|
|
128
147
|
* the account's API key (`createAuthToken` / the WASM signer), NOT an L1
|
|
129
148
|
* wallet signature. Lighter authenticates the create request with that token
|
|
@@ -143,6 +162,7 @@ export class LighterReadOnlyTokenManager {
|
|
|
143
162
|
*/
|
|
144
163
|
async approve(authorization, inputs) {
|
|
145
164
|
const { address, accountIndex, expirySeconds, scope } = inputs;
|
|
165
|
+
await this.revokeStaleOwnTokens(authorization, address, accountIndex);
|
|
146
166
|
const response = await this.fetcher({
|
|
147
167
|
url: `${this.lighterApiUrl}/api/v1/tokens/create`,
|
|
148
168
|
authorization,
|
|
@@ -160,6 +180,12 @@ export class LighterReadOnlyTokenManager {
|
|
|
160
180
|
// `get()` looks up by, else a divergent echo orphans the token and re-creates every read.
|
|
161
181
|
scope,
|
|
162
182
|
accountIndex,
|
|
183
|
+
// Lighter declares `token_id` required but the response is unvalidated.
|
|
184
|
+
// A non-numeric id must degrade to the bearer-string match: persisting it
|
|
185
|
+
// would fail record validation and re-create the token on every read.
|
|
186
|
+
tokenId: Number.isFinite(response.token_id)
|
|
187
|
+
? response.token_id
|
|
188
|
+
: undefined,
|
|
163
189
|
};
|
|
164
190
|
await this.set(address, token.accountIndex, token);
|
|
165
191
|
return {
|
|
@@ -173,13 +199,54 @@ export class LighterReadOnlyTokenManager {
|
|
|
173
199
|
},
|
|
174
200
|
};
|
|
175
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Revoke the registry rows this SDK owns and no longer needs. Lighter's
|
|
204
|
+
* `tokens/create` appends a row on every call, so without this pass the
|
|
205
|
+
* user's registry grows on every rotation.
|
|
206
|
+
*/
|
|
207
|
+
async revokeStaleOwnTokens(authorization, address, accountIndex) {
|
|
208
|
+
try {
|
|
209
|
+
const live = await this.readStoredToken(address, accountIndex);
|
|
210
|
+
const { api_tokens: rows } = await this.listFetcher({
|
|
211
|
+
url: `${this.lighterApiUrl}/api/v1/tokens`,
|
|
212
|
+
authorization,
|
|
213
|
+
accountIndex,
|
|
214
|
+
});
|
|
215
|
+
const nowSeconds = Math.floor(this.now() / 1000);
|
|
216
|
+
const stale = rows
|
|
217
|
+
// A row is ours only when its name matches the name we create rows
|
|
218
|
+
// under. Any other name belongs to the user and must survive.
|
|
219
|
+
.filter((row) => row.name === DEFAULT_READ_ONLY_TOKEN_NAME)
|
|
220
|
+
.filter((row) => !row.revoked)
|
|
221
|
+
// Keep the row the local store holds; with no stored record every owned
|
|
222
|
+
// row is stale, and a peer client's row self-heals via `retryOnRevoked`.
|
|
223
|
+
.filter((row) => row.expiry <= nowSeconds || !isLiveRow(row, live))
|
|
224
|
+
.sort((a, b) => a.token_id - b.token_id);
|
|
225
|
+
for (const row of stale) {
|
|
226
|
+
try {
|
|
227
|
+
await this.revokeFetcher({
|
|
228
|
+
url: `${this.lighterApiUrl}/api/v1/tokens/revoke`,
|
|
229
|
+
authorization,
|
|
230
|
+
tokenId: row.token_id,
|
|
231
|
+
accountIndex,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
console.warn(`[lighter] could not revoke stale read-only token ${row.token_id}; continuing.`, err);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (err) {
|
|
240
|
+
console.warn('[lighter] could not clean up stale read-only tokens; creating the new one anyway.', err);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
176
243
|
}
|
|
177
244
|
/**
|
|
178
245
|
* Default fetcher: posts a multipart/form-data request to Lighter's
|
|
179
246
|
* `tokens/create` endpoint and returns the parsed response. Throws a
|
|
180
247
|
* {@link PerpsError} with the Lighter-side body when the response is
|
|
181
248
|
* non-2xx.
|
|
182
|
-
* @
|
|
249
|
+
* @internal
|
|
183
250
|
*/
|
|
184
251
|
export const defaultLighterTokenFetcher = async ({ url, authorization, name, accountIndex, expiry, subAccountAccess, scopes, }) => {
|
|
185
252
|
const form = new FormData();
|
|
@@ -199,4 +266,48 @@ export const defaultLighterTokenFetcher = async ({ url, authorization, name, acc
|
|
|
199
266
|
}
|
|
200
267
|
return (await response.json());
|
|
201
268
|
};
|
|
269
|
+
/**
|
|
270
|
+
* Default list fetcher: `GET /api/v1/tokens` with `account_index` as a query
|
|
271
|
+
* parameter. Lighter's OpenAPI defines no request body for this route. Throws
|
|
272
|
+
* a {@link PerpsError} with the Lighter-side body when the response is
|
|
273
|
+
* non-2xx.
|
|
274
|
+
* @internal
|
|
275
|
+
*/
|
|
276
|
+
export const defaultLighterTokenListFetcher = async ({ url, authorization, accountIndex, }) => {
|
|
277
|
+
const query = new URLSearchParams({ account_index: String(accountIndex) });
|
|
278
|
+
const response = await fetch(`${url}?${query.toString()}`, {
|
|
279
|
+
headers: { authorization },
|
|
280
|
+
});
|
|
281
|
+
if (!response.ok) {
|
|
282
|
+
const body = await response.text();
|
|
283
|
+
throw new PerpsError(PerpsErrorCode.ServerError, `Lighter tokens returned ${response.status}: ${body || '<empty>'}`);
|
|
284
|
+
}
|
|
285
|
+
return (await response.json());
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Default revoke fetcher: posts `application/x-www-form-urlencoded` to
|
|
289
|
+
* Lighter's `tokens/revoke` endpoint, which is the content type Lighter's
|
|
290
|
+
* OpenAPI declares for that route. Throws a {@link PerpsError} with the
|
|
291
|
+
* Lighter-side body when the response is non-2xx.
|
|
292
|
+
* @internal
|
|
293
|
+
*/
|
|
294
|
+
export const defaultLighterTokenRevokeFetcher = async ({ url, authorization, tokenId, accountIndex }) => {
|
|
295
|
+
const form = new URLSearchParams({
|
|
296
|
+
token_id: String(tokenId),
|
|
297
|
+
account_index: String(accountIndex),
|
|
298
|
+
});
|
|
299
|
+
const response = await fetch(url, {
|
|
300
|
+
method: 'POST',
|
|
301
|
+
headers: {
|
|
302
|
+
authorization,
|
|
303
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
304
|
+
},
|
|
305
|
+
body: form,
|
|
306
|
+
});
|
|
307
|
+
if (!response.ok) {
|
|
308
|
+
const body = await response.text();
|
|
309
|
+
throw new PerpsError(PerpsErrorCode.ServerError, `Lighter tokens/revoke returned ${response.status}: ${body || '<empty>'}`);
|
|
310
|
+
}
|
|
311
|
+
return (await response.json());
|
|
312
|
+
};
|
|
202
313
|
//# sourceMappingURL=LighterReadOnlyTokenManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LighterReadOnlyTokenManager.js","sourceRoot":"","sources":["../../../src/signers/LighterReadOnlyTokenManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,mBAAmB,GAEpB,MAAM,iBAAiB,CAAA;AAMxB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEhF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"LighterReadOnlyTokenManager.js","sourceRoot":"","sources":["../../../src/signers/LighterReadOnlyTokenManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,mBAAmB,GAEp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,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,UAAU,EAAE,EACnB,OAAO,EAAE,OAAO,EAChB,GAAG,CAAC,EAAE,kBAAkB,GACvB,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAsB7B"}
|
|
@@ -12,7 +12,7 @@ import { fetchRegisteredApiKey, normalizeLighterPublicKey, } from '../utils/regi
|
|
|
12
12
|
*/
|
|
13
13
|
const TOKEN_AUTH_MUTATION_KINDS = new Set(['changeAccountTier', 'referralUse']);
|
|
14
14
|
/**
|
|
15
|
-
* Lifetime of the per-call auth token
|
|
15
|
+
* Lifetime of the per-call auth token issued for a token-authenticated venue
|
|
16
16
|
* mutation. Minutes, not the read endpoints' hours: it authenticates one POST
|
|
17
17
|
* that completes immediately, so it never lingers usable.
|
|
18
18
|
*/
|
|
@@ -55,15 +55,22 @@ export const createLighterApiKeyFreshness = () => {
|
|
|
55
55
|
checkedAtMs.set(windowKey, Date.now());
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
// An answered read that names no entry is a verdict, not a gap: the slot
|
|
59
|
+
// holds no key the stored one can match, so a signature it produces
|
|
60
|
+
// cannot verify.
|
|
61
|
+
if (registered === undefined) {
|
|
62
|
+
throw new PerpsError(PerpsErrorCode.SDKError, `The Lighter API key stored for ${address} is not registered: ` +
|
|
63
|
+
`account ${apiKey.accountIndex} holds no key in API-key slot ` +
|
|
64
|
+
`${apiKey.apiKeyIndex}. Run prepareAccount / REGISTER_API_KEY to ` +
|
|
65
|
+
'register a fresh key.');
|
|
66
|
+
}
|
|
67
|
+
if (normalizeLighterPublicKey(registered.public_key) !== storedKey) {
|
|
61
68
|
throw new PerpsError(PerpsErrorCode.SDKError, `The Lighter API key stored for ${address} is no longer registered: ` +
|
|
62
69
|
`API-key slot ${apiKey.apiKeyIndex} now holds a different key. ` +
|
|
63
70
|
'Run prepareAccount / REGISTER_API_KEY to register a fresh key.');
|
|
64
71
|
}
|
|
65
72
|
// Every read the venue answered counts against the window, so a burst
|
|
66
|
-
// costs one read whatever the verdict. A
|
|
73
|
+
// costs one read whatever the verdict. A rejection throws above, so it
|
|
67
74
|
// never records and the next batch reads again.
|
|
68
75
|
checkedAtMs.set(windowKey, Date.now());
|
|
69
76
|
},
|
|
@@ -161,13 +168,12 @@ async function signRegisterApiKey(deps, address, step, ctx) {
|
|
|
161
168
|
message: changePubKey.messageToSign,
|
|
162
169
|
});
|
|
163
170
|
const txInfoWithL1Sig = deps.signer.embedL1Signature(changePubKey.txInfo, l1Signature);
|
|
164
|
-
|
|
171
|
+
await deps.keyStore.set(address, {
|
|
165
172
|
accountIndex,
|
|
166
173
|
apiKeyIndex,
|
|
167
174
|
apiKeyPrivateKey: keypair.privateKey,
|
|
168
175
|
apiKeyPublicKey: keypair.publicKey,
|
|
169
|
-
};
|
|
170
|
-
await deps.keyStore.set(address, apiKey);
|
|
176
|
+
});
|
|
171
177
|
return {
|
|
172
178
|
action: step.action,
|
|
173
179
|
wasmSignParams: {
|
|
@@ -246,7 +252,7 @@ async function signTransfer(deps, address, step, ctx) {
|
|
|
246
252
|
*
|
|
247
253
|
* Neither endpoint consumes a wasm-signed transaction — both authenticate with
|
|
248
254
|
* a Lighter auth token and enforce their business rules (open positions,
|
|
249
|
-
* pending orders, 24h tier cooldown) server-side. We
|
|
255
|
+
* pending orders, 24h tier cooldown) server-side. We create a fresh short-lived
|
|
250
256
|
* token per call (never the stored read-only token, never persisted) and POST
|
|
251
257
|
* the mirror of the backend's form body directly to Lighter, so no auth token
|
|
252
258
|
* ever transits the LI.FI backend. A non-success verdict surfaces Lighter's
|