@lifi/perps-sdk-provider-lighter 0.2.0-alpha.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/LICENSE +201 -0
- package/README.md +176 -0
- package/dist/cjs/LighterProvider.d.ts +20 -0
- package/dist/cjs/LighterProvider.d.ts.map +1 -0
- package/dist/cjs/LighterProvider.js +592 -0
- package/dist/cjs/LighterProvider.js.map +1 -0
- package/dist/cjs/accountConfig.d.ts +3 -0
- package/dist/cjs/accountConfig.d.ts.map +1 -0
- package/dist/cjs/accountConfig.js +69 -0
- package/dist/cjs/accountConfig.js.map +1 -0
- package/dist/cjs/accountSummary.d.ts +3 -0
- package/dist/cjs/accountSummary.d.ts.map +1 -0
- package/dist/cjs/accountSummary.js +8 -0
- package/dist/cjs/accountSummary.js.map +1 -0
- package/dist/cjs/constants.d.ts +14 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +18 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/signers/LighterKeyStore.d.ts +18 -0
- package/dist/cjs/signers/LighterKeyStore.d.ts.map +1 -0
- package/dist/cjs/signers/LighterKeyStore.js +54 -0
- package/dist/cjs/signers/LighterKeyStore.js.map +1 -0
- package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts +56 -0
- package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts.map +1 -0
- package/dist/cjs/signers/LighterReadOnlyTokenManager.js +127 -0
- package/dist/cjs/signers/LighterReadOnlyTokenManager.js.map +1 -0
- package/dist/cjs/signers/LighterSigner.d.ts +41 -0
- package/dist/cjs/signers/LighterSigner.d.ts.map +1 -0
- package/dist/cjs/signers/LighterSigner.js +175 -0
- package/dist/cjs/signers/LighterSigner.js.map +1 -0
- package/dist/cjs/signers/createAuthToken.d.ts +12 -0
- package/dist/cjs/signers/createAuthToken.d.ts.map +1 -0
- package/dist/cjs/signers/createAuthToken.js +28 -0
- package/dist/cjs/signers/createAuthToken.js.map +1 -0
- package/dist/cjs/signers/index.d.ts +11 -0
- package/dist/cjs/signers/index.d.ts.map +1 -0
- package/dist/cjs/signers/index.js +19 -0
- package/dist/cjs/signers/index.js.map +1 -0
- package/dist/cjs/signers/signActions.d.ts +15 -0
- package/dist/cjs/signers/signActions.d.ts.map +1 -0
- package/dist/cjs/signers/signActions.js +142 -0
- package/dist/cjs/signers/signActions.js.map +1 -0
- package/dist/cjs/signers/wasmLoader.d.ts +42 -0
- package/dist/cjs/signers/wasmLoader.d.ts.map +1 -0
- package/dist/cjs/signers/wasmLoader.js +166 -0
- package/dist/cjs/signers/wasmLoader.js.map +1 -0
- package/dist/cjs/types/account.d.ts +97 -0
- package/dist/cjs/types/account.d.ts.map +1 -0
- package/dist/cjs/types/account.js +3 -0
- package/dist/cjs/types/account.js.map +1 -0
- package/dist/cjs/types/action.d.ts +72 -0
- package/dist/cjs/types/action.d.ts.map +1 -0
- package/dist/cjs/types/action.js +23 -0
- package/dist/cjs/types/action.js.map +1 -0
- package/dist/cjs/types/activity.d.ts +73 -0
- package/dist/cjs/types/activity.d.ts.map +1 -0
- package/dist/cjs/types/activity.js +3 -0
- package/dist/cjs/types/activity.js.map +1 -0
- package/dist/cjs/types/asset.d.ts +122 -0
- package/dist/cjs/types/asset.d.ts.map +1 -0
- package/dist/cjs/types/asset.js +3 -0
- package/dist/cjs/types/asset.js.map +1 -0
- package/dist/cjs/types/fill.d.ts +29 -0
- package/dist/cjs/types/fill.d.ts.map +1 -0
- package/dist/cjs/types/fill.js +3 -0
- package/dist/cjs/types/fill.js.map +1 -0
- package/dist/cjs/types/index.d.ts +9 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/index.js +25 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/order.d.ts +57 -0
- package/dist/cjs/types/order.d.ts.map +1 -0
- package/dist/cjs/types/order.js +3 -0
- package/dist/cjs/types/order.js.map +1 -0
- package/dist/cjs/types/submit.d.ts +39 -0
- package/dist/cjs/types/submit.d.ts.map +1 -0
- package/dist/cjs/types/submit.js +3 -0
- package/dist/cjs/types/submit.js.map +1 -0
- package/dist/cjs/types/ws.d.ts +84 -0
- package/dist/cjs/types/ws.d.ts.map +1 -0
- package/dist/cjs/types/ws.js +3 -0
- package/dist/cjs/types/ws.js.map +1 -0
- package/dist/cjs/utils/activityCursor.d.ts +12 -0
- package/dist/cjs/utils/activityCursor.d.ts.map +1 -0
- package/dist/cjs/utils/activityCursor.js +85 -0
- package/dist/cjs/utils/activityCursor.js.map +1 -0
- package/dist/cjs/utils/apiClient.d.ts +26 -0
- package/dist/cjs/utils/apiClient.d.ts.map +1 -0
- package/dist/cjs/utils/apiClient.js +94 -0
- package/dist/cjs/utils/apiClient.js.map +1 -0
- package/dist/cjs/utils/fetchDetailedAccount.d.ts +5 -0
- package/dist/cjs/utils/fetchDetailedAccount.d.ts.map +1 -0
- package/dist/cjs/utils/fetchDetailedAccount.js +22 -0
- package/dist/cjs/utils/fetchDetailedAccount.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +16 -0
- package/dist/cjs/utils/index.d.ts.map +1 -0
- package/dist/cjs/utils/index.js +45 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/lighterAsset.d.ts +3 -0
- package/dist/cjs/utils/lighterAsset.d.ts.map +1 -0
- package/dist/cjs/utils/lighterAsset.js +12 -0
- package/dist/cjs/utils/lighterAsset.js.map +1 -0
- package/dist/cjs/utils/liquidation.d.ts +4 -0
- package/dist/cjs/utils/liquidation.d.ts.map +1 -0
- package/dist/cjs/utils/liquidation.js +16 -0
- package/dist/cjs/utils/liquidation.js.map +1 -0
- package/dist/cjs/utils/mapFill.d.ts +4 -0
- package/dist/cjs/utils/mapFill.d.ts.map +1 -0
- package/dist/cjs/utils/mapFill.js +61 -0
- package/dist/cjs/utils/mapFill.js.map +1 -0
- package/dist/cjs/utils/mapOpenPositions.d.ts +4 -0
- package/dist/cjs/utils/mapOpenPositions.d.ts.map +1 -0
- package/dist/cjs/utils/mapOpenPositions.js +9 -0
- package/dist/cjs/utils/mapOpenPositions.js.map +1 -0
- package/dist/cjs/utils/mapOrder.d.ts +15 -0
- package/dist/cjs/utils/mapOrder.d.ts.map +1 -0
- package/dist/cjs/utils/mapOrder.js +164 -0
- package/dist/cjs/utils/mapOrder.js.map +1 -0
- package/dist/cjs/utils/mapPosition.d.ts +4 -0
- package/dist/cjs/utils/mapPosition.d.ts.map +1 -0
- package/dist/cjs/utils/mapPosition.js +30 -0
- package/dist/cjs/utils/mapPosition.js.map +1 -0
- package/dist/cjs/utils/ohlcvInterval.d.ts +2 -0
- package/dist/cjs/utils/ohlcvInterval.d.ts.map +1 -0
- package/dist/cjs/utils/ohlcvInterval.js +26 -0
- package/dist/cjs/utils/ohlcvInterval.js.map +1 -0
- package/dist/cjs/utils/orderFormatting.d.ts +4 -0
- package/dist/cjs/utils/orderFormatting.d.ts.map +1 -0
- package/dist/cjs/utils/orderFormatting.js +23 -0
- package/dist/cjs/utils/orderFormatting.js.map +1 -0
- package/dist/cjs/utils/time.d.ts +3 -0
- package/dist/cjs/utils/time.d.ts.map +1 -0
- package/dist/cjs/utils/time.js +8 -0
- package/dist/cjs/utils/time.js.map +1 -0
- package/dist/cjs/utils/wireEncoding.d.ts +9 -0
- package/dist/cjs/utils/wireEncoding.d.ts.map +1 -0
- package/dist/cjs/utils/wireEncoding.js +87 -0
- package/dist/cjs/utils/wireEncoding.js.map +1 -0
- package/dist/cjs/websocket/LighterWsProvider.d.ts +45 -0
- package/dist/cjs/websocket/LighterWsProvider.d.ts.map +1 -0
- package/dist/cjs/websocket/LighterWsProvider.js +396 -0
- package/dist/cjs/websocket/LighterWsProvider.js.map +1 -0
- package/dist/esm/LighterProvider.d.ts +105 -0
- package/dist/esm/LighterProvider.d.ts.map +1 -0
- package/dist/esm/LighterProvider.js +684 -0
- package/dist/esm/LighterProvider.js.map +1 -0
- package/dist/esm/accountConfig.d.ts +14 -0
- package/dist/esm/accountConfig.d.ts.map +1 -0
- package/dist/esm/accountConfig.js +135 -0
- package/dist/esm/accountConfig.js.map +1 -0
- package/dist/esm/accountSummary.d.ts +12 -0
- package/dist/esm/accountSummary.d.ts.map +1 -0
- package/dist/esm/accountSummary.js +14 -0
- package/dist/esm/accountSummary.js.map +1 -0
- package/dist/esm/constants.d.ts +74 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +73 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/signers/LighterKeyStore.d.ts +24 -0
- package/dist/esm/signers/LighterKeyStore.d.ts.map +1 -0
- package/dist/esm/signers/LighterKeyStore.js +55 -0
- package/dist/esm/signers/LighterKeyStore.js.map +1 -0
- package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts +157 -0
- package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts.map +1 -0
- package/dist/esm/signers/LighterReadOnlyTokenManager.js +194 -0
- package/dist/esm/signers/LighterReadOnlyTokenManager.js.map +1 -0
- package/dist/esm/signers/LighterSigner.d.ts +94 -0
- package/dist/esm/signers/LighterSigner.d.ts.map +1 -0
- package/dist/esm/signers/LighterSigner.js +228 -0
- package/dist/esm/signers/LighterSigner.js.map +1 -0
- package/dist/esm/signers/createAuthToken.d.ts +36 -0
- package/dist/esm/signers/createAuthToken.d.ts.map +1 -0
- package/dist/esm/signers/createAuthToken.js +42 -0
- package/dist/esm/signers/createAuthToken.js.map +1 -0
- package/dist/esm/signers/index.d.ts +11 -0
- package/dist/esm/signers/index.d.ts.map +1 -0
- package/dist/esm/signers/index.js +7 -0
- package/dist/esm/signers/index.js.map +1 -0
- package/dist/esm/signers/signActions.d.ts +54 -0
- package/dist/esm/signers/signActions.d.ts.map +1 -0
- package/dist/esm/signers/signActions.js +193 -0
- package/dist/esm/signers/signActions.js.map +1 -0
- package/dist/esm/signers/wasmLoader.d.ts +79 -0
- package/dist/esm/signers/wasmLoader.d.ts.map +1 -0
- package/dist/esm/signers/wasmLoader.js +180 -0
- package/dist/esm/signers/wasmLoader.js.map +1 -0
- package/dist/esm/types/account.d.ts +113 -0
- package/dist/esm/types/account.d.ts.map +1 -0
- package/dist/esm/types/account.js +4 -0
- package/dist/esm/types/account.js.map +1 -0
- package/dist/esm/types/action.d.ts +146 -0
- package/dist/esm/types/action.d.ts.map +1 -0
- package/dist/esm/types/action.js +50 -0
- package/dist/esm/types/action.js.map +1 -0
- package/dist/esm/types/activity.d.ts +83 -0
- package/dist/esm/types/activity.d.ts.map +1 -0
- package/dist/esm/types/activity.js +4 -0
- package/dist/esm/types/activity.js.map +1 -0
- package/dist/esm/types/asset.d.ts +134 -0
- package/dist/esm/types/asset.d.ts.map +1 -0
- package/dist/esm/types/asset.js +3 -0
- package/dist/esm/types/asset.js.map +1 -0
- package/dist/esm/types/fill.d.ts +31 -0
- package/dist/esm/types/fill.d.ts.map +1 -0
- package/dist/esm/types/fill.js +3 -0
- package/dist/esm/types/fill.js.map +1 -0
- package/dist/esm/types/index.d.ts +9 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/index.js +12 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/order.d.ts +61 -0
- package/dist/esm/types/order.d.ts.map +1 -0
- package/dist/esm/types/order.js +3 -0
- package/dist/esm/types/order.js.map +1 -0
- package/dist/esm/types/submit.d.ts +76 -0
- package/dist/esm/types/submit.d.ts.map +1 -0
- package/dist/esm/types/submit.js +3 -0
- package/dist/esm/types/submit.js.map +1 -0
- package/dist/esm/types/ws.d.ts +124 -0
- package/dist/esm/types/ws.d.ts.map +1 -0
- package/dist/esm/types/ws.js +11 -0
- package/dist/esm/types/ws.js.map +1 -0
- package/dist/esm/utils/activityCursor.d.ts +51 -0
- package/dist/esm/utils/activityCursor.d.ts.map +1 -0
- package/dist/esm/utils/activityCursor.js +99 -0
- package/dist/esm/utils/activityCursor.js.map +1 -0
- package/dist/esm/utils/apiClient.d.ts +65 -0
- package/dist/esm/utils/apiClient.d.ts.map +1 -0
- package/dist/esm/utils/apiClient.js +131 -0
- package/dist/esm/utils/apiClient.js.map +1 -0
- package/dist/esm/utils/fetchDetailedAccount.d.ts +11 -0
- package/dist/esm/utils/fetchDetailedAccount.d.ts.map +1 -0
- package/dist/esm/utils/fetchDetailedAccount.js +24 -0
- package/dist/esm/utils/fetchDetailedAccount.js.map +1 -0
- package/dist/esm/utils/index.d.ts +16 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/index.js +17 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/lighterAsset.d.ts +4 -0
- package/dist/esm/utils/lighterAsset.d.ts.map +1 -0
- package/dist/esm/utils/lighterAsset.js +9 -0
- package/dist/esm/utils/lighterAsset.js.map +1 -0
- package/dist/esm/utils/liquidation.d.ts +22 -0
- package/dist/esm/utils/liquidation.d.ts.map +1 -0
- package/dist/esm/utils/liquidation.js +31 -0
- package/dist/esm/utils/liquidation.js.map +1 -0
- package/dist/esm/utils/mapFill.d.ts +10 -0
- package/dist/esm/utils/mapFill.d.ts.map +1 -0
- package/dist/esm/utils/mapFill.js +72 -0
- package/dist/esm/utils/mapFill.js.map +1 -0
- package/dist/esm/utils/mapOpenPositions.d.ts +11 -0
- package/dist/esm/utils/mapOpenPositions.d.ts.map +1 -0
- package/dist/esm/utils/mapOpenPositions.js +12 -0
- package/dist/esm/utils/mapOpenPositions.js.map +1 -0
- package/dist/esm/utils/mapOrder.d.ts +72 -0
- package/dist/esm/utils/mapOrder.d.ts.map +1 -0
- package/dist/esm/utils/mapOrder.js +219 -0
- package/dist/esm/utils/mapOrder.js.map +1 -0
- package/dist/esm/utils/mapPosition.d.ts +9 -0
- package/dist/esm/utils/mapPosition.d.ts.map +1 -0
- package/dist/esm/utils/mapPosition.js +34 -0
- package/dist/esm/utils/mapPosition.js.map +1 -0
- package/dist/esm/utils/ohlcvInterval.d.ts +3 -0
- package/dist/esm/utils/ohlcvInterval.d.ts.map +1 -0
- package/dist/esm/utils/ohlcvInterval.js +30 -0
- package/dist/esm/utils/ohlcvInterval.js.map +1 -0
- package/dist/esm/utils/orderFormatting.d.ts +29 -0
- package/dist/esm/utils/orderFormatting.d.ts.map +1 -0
- package/dist/esm/utils/orderFormatting.js +41 -0
- package/dist/esm/utils/orderFormatting.js.map +1 -0
- package/dist/esm/utils/time.d.ts +5 -0
- package/dist/esm/utils/time.d.ts.map +1 -0
- package/dist/esm/utils/time.js +5 -0
- package/dist/esm/utils/time.js.map +1 -0
- package/dist/esm/utils/wireEncoding.d.ts +72 -0
- package/dist/esm/utils/wireEncoding.d.ts.map +1 -0
- package/dist/esm/utils/wireEncoding.js +129 -0
- package/dist/esm/utils/wireEncoding.js.map +1 -0
- package/dist/esm/websocket/LighterWsProvider.d.ts +97 -0
- package/dist/esm/websocket/LighterWsProvider.d.ts.map +1 -0
- package/dist/esm/websocket/LighterWsProvider.js +489 -0
- package/dist/esm/websocket/LighterWsProvider.js.map +1 -0
- package/dist/types/LighterProvider.d.ts +105 -0
- package/dist/types/LighterProvider.d.ts.map +1 -0
- package/dist/types/accountConfig.d.ts +14 -0
- package/dist/types/accountConfig.d.ts.map +1 -0
- package/dist/types/accountSummary.d.ts +12 -0
- package/dist/types/accountSummary.d.ts.map +1 -0
- package/dist/types/constants.d.ts +74 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/signers/LighterKeyStore.d.ts +24 -0
- package/dist/types/signers/LighterKeyStore.d.ts.map +1 -0
- package/dist/types/signers/LighterReadOnlyTokenManager.d.ts +157 -0
- package/dist/types/signers/LighterReadOnlyTokenManager.d.ts.map +1 -0
- package/dist/types/signers/LighterSigner.d.ts +94 -0
- package/dist/types/signers/LighterSigner.d.ts.map +1 -0
- package/dist/types/signers/createAuthToken.d.ts +36 -0
- package/dist/types/signers/createAuthToken.d.ts.map +1 -0
- package/dist/types/signers/index.d.ts +11 -0
- package/dist/types/signers/index.d.ts.map +1 -0
- package/dist/types/signers/signActions.d.ts +54 -0
- package/dist/types/signers/signActions.d.ts.map +1 -0
- package/dist/types/signers/wasmLoader.d.ts +79 -0
- package/dist/types/signers/wasmLoader.d.ts.map +1 -0
- package/dist/types/types/account.d.ts +113 -0
- package/dist/types/types/account.d.ts.map +1 -0
- package/dist/types/types/action.d.ts +146 -0
- package/dist/types/types/action.d.ts.map +1 -0
- package/dist/types/types/activity.d.ts +83 -0
- package/dist/types/types/activity.d.ts.map +1 -0
- package/dist/types/types/asset.d.ts +134 -0
- package/dist/types/types/asset.d.ts.map +1 -0
- package/dist/types/types/fill.d.ts +31 -0
- package/dist/types/types/fill.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +9 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/order.d.ts +61 -0
- package/dist/types/types/order.d.ts.map +1 -0
- package/dist/types/types/submit.d.ts +76 -0
- package/dist/types/types/submit.d.ts.map +1 -0
- package/dist/types/types/ws.d.ts +124 -0
- package/dist/types/types/ws.d.ts.map +1 -0
- package/dist/types/utils/activityCursor.d.ts +51 -0
- package/dist/types/utils/activityCursor.d.ts.map +1 -0
- package/dist/types/utils/apiClient.d.ts +65 -0
- package/dist/types/utils/apiClient.d.ts.map +1 -0
- package/dist/types/utils/fetchDetailedAccount.d.ts +11 -0
- package/dist/types/utils/fetchDetailedAccount.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +16 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/lighterAsset.d.ts +4 -0
- package/dist/types/utils/lighterAsset.d.ts.map +1 -0
- package/dist/types/utils/liquidation.d.ts +22 -0
- package/dist/types/utils/liquidation.d.ts.map +1 -0
- package/dist/types/utils/mapFill.d.ts +10 -0
- package/dist/types/utils/mapFill.d.ts.map +1 -0
- package/dist/types/utils/mapOpenPositions.d.ts +11 -0
- package/dist/types/utils/mapOpenPositions.d.ts.map +1 -0
- package/dist/types/utils/mapOrder.d.ts +72 -0
- package/dist/types/utils/mapOrder.d.ts.map +1 -0
- package/dist/types/utils/mapPosition.d.ts +9 -0
- package/dist/types/utils/mapPosition.d.ts.map +1 -0
- package/dist/types/utils/ohlcvInterval.d.ts +3 -0
- package/dist/types/utils/ohlcvInterval.d.ts.map +1 -0
- package/dist/types/utils/orderFormatting.d.ts +29 -0
- package/dist/types/utils/orderFormatting.d.ts.map +1 -0
- package/dist/types/utils/time.d.ts +5 -0
- package/dist/types/utils/time.d.ts.map +1 -0
- package/dist/types/utils/wireEncoding.d.ts +72 -0
- package/dist/types/utils/wireEncoding.d.ts.map +1 -0
- package/dist/types/websocket/LighterWsProvider.d.ts +97 -0
- package/dist/types/websocket/LighterWsProvider.d.ts.map +1 -0
- package/dist/wasm/lighter-signer.wasm +0 -0
- package/dist/wasm/wasm_exec.js +575 -0
- package/package.json +67 -0
- package/src/LighterProvider.ts +1167 -0
- package/src/accountConfig.ts +162 -0
- package/src/accountSummary.ts +22 -0
- package/src/constants.ts +89 -0
- package/src/index.ts +37 -0
- package/src/signers/LighterKeyStore.ts +79 -0
- package/src/signers/LighterReadOnlyTokenManager.ts +340 -0
- package/src/signers/LighterSigner.ts +400 -0
- package/src/signers/createAuthToken.ts +69 -0
- package/src/signers/index.ts +36 -0
- package/src/signers/signActions.ts +311 -0
- package/src/signers/wasmLoader.ts +293 -0
- package/src/types/account.ts +123 -0
- package/src/types/action.ts +163 -0
- package/src/types/activity.ts +94 -0
- package/src/types/asset.ts +146 -0
- package/src/types/fill.ts +42 -0
- package/src/types/index.ts +12 -0
- package/src/types/order.ts +65 -0
- package/src/types/submit.ts +83 -0
- package/src/types/ws.ts +136 -0
- package/src/utils/activityCursor.ts +150 -0
- package/src/utils/apiClient.ts +185 -0
- package/src/utils/fetchDetailedAccount.ts +46 -0
- package/src/utils/index.ts +38 -0
- package/src/utils/lighterAsset.ts +10 -0
- package/src/utils/liquidation.ts +39 -0
- package/src/utils/mapFill.ts +108 -0
- package/src/utils/mapOpenPositions.ts +18 -0
- package/src/utils/mapOrder.ts +258 -0
- package/src/utils/mapPosition.ts +42 -0
- package/src/utils/ohlcvInterval.ts +34 -0
- package/src/utils/orderFormatting.ts +46 -0
- package/src/utils/time.ts +6 -0
- package/src/utils/wireEncoding.ts +179 -0
- package/src/websocket/LighterWsProvider.ts +725 -0
- package/wasm/lighter-signer.wasm +0 -0
- package/wasm/wasm_exec.js +575 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { ActionType } from '@lifi/perps-types'
|
|
2
|
+
import {
|
|
3
|
+
type LighterWasmExports,
|
|
4
|
+
type LoadLighterWasmOptions,
|
|
5
|
+
loadLighterWasm,
|
|
6
|
+
type SignResult,
|
|
7
|
+
} from './wasmLoader.js'
|
|
8
|
+
|
|
9
|
+
// Every Sign* call needs the Go signer initialized with the API private key
|
|
10
|
+
// for a given (apiKeyIndex, accountIndex) pair via CreateClient. The context
|
|
11
|
+
// is process-global inside the Go runtime; we track which keys are already
|
|
12
|
+
// initialized so CreateClient runs once per keypair.
|
|
13
|
+
|
|
14
|
+
/** @public */
|
|
15
|
+
export interface LighterSignerContext {
|
|
16
|
+
/** Lighter-native private key (from GenerateAPIKey, NOT an Ethereum key). */
|
|
17
|
+
apiKeyPrivateKey: string
|
|
18
|
+
/** API key slot registered on-chain (0-255). */
|
|
19
|
+
apiKeyIndex: number
|
|
20
|
+
/** Lighter account index — looked up from the user's L1 Ethereum address. */
|
|
21
|
+
accountIndex: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @public */
|
|
25
|
+
export interface LighterSignerConfig extends LoadLighterWasmOptions {
|
|
26
|
+
/** Lighter REST API base URL. */
|
|
27
|
+
apiUrl?: string
|
|
28
|
+
/** Lighter chain ID (304 = mainnet). */
|
|
29
|
+
chainId?: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @public */
|
|
33
|
+
export interface LighterSignedBlob {
|
|
34
|
+
txType: number
|
|
35
|
+
txInfo: string
|
|
36
|
+
txHash: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @public */
|
|
40
|
+
export interface ChangePubKeyResult extends LighterSignedBlob {
|
|
41
|
+
/** EIP-191 message the L1 Ethereum wallet must sign to authorize the key rotation. */
|
|
42
|
+
messageToSign: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @public */
|
|
46
|
+
export interface ApiKeyPair {
|
|
47
|
+
publicKey: string
|
|
48
|
+
privateKey: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const DEFAULT_API_URL = 'https://mainnet.zklighter.elliot.ai'
|
|
52
|
+
const DEFAULT_CHAIN_ID = 304
|
|
53
|
+
|
|
54
|
+
/** @public */
|
|
55
|
+
export class LighterSigner {
|
|
56
|
+
private readonly apiUrl: string
|
|
57
|
+
private readonly chainId: number
|
|
58
|
+
private readonly loaderOptions: LoadLighterWasmOptions
|
|
59
|
+
private wasm: LighterWasmExports | undefined
|
|
60
|
+
private readonly registeredClients = new Set<string>()
|
|
61
|
+
|
|
62
|
+
constructor(config: LighterSignerConfig = {}) {
|
|
63
|
+
this.apiUrl = config.apiUrl ?? DEFAULT_API_URL
|
|
64
|
+
this.chainId = config.chainId ?? DEFAULT_CHAIN_ID
|
|
65
|
+
this.loaderOptions = {
|
|
66
|
+
wasmBinaryUrl: config.wasmBinaryUrl,
|
|
67
|
+
wasmExecJsUrl: config.wasmExecJsUrl,
|
|
68
|
+
wasmExecJsSource: config.wasmExecJsSource,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async initialize(): Promise<void> {
|
|
73
|
+
if (!this.wasm) {
|
|
74
|
+
this.wasm = await loadLighterWasm(this.loaderOptions)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Generate a fresh Lighter API keypair. Pass an optional 32-byte hex seed
|
|
80
|
+
* for deterministic generation (used in tests); omit for a random key.
|
|
81
|
+
*/
|
|
82
|
+
async generateAPIKey(seed?: string): Promise<ApiKeyPair> {
|
|
83
|
+
const wasm = await this.ensureLoaded()
|
|
84
|
+
const result = wasm.GenerateAPIKey(seed ?? '')
|
|
85
|
+
if (result.error) {
|
|
86
|
+
throw new Error(`Lighter GenerateAPIKey failed: ${result.error}`)
|
|
87
|
+
}
|
|
88
|
+
if (!result.publicKey || !result.privateKey) {
|
|
89
|
+
throw new Error('Lighter GenerateAPIKey returned an incomplete result')
|
|
90
|
+
}
|
|
91
|
+
return { publicKey: result.publicKey, privateKey: result.privateKey }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Sign an action blob with the provided (apiKeyPrivateKey, apiKeyIndex,
|
|
96
|
+
* accountIndex) context. `wasmSignParams` comes straight from the backend's
|
|
97
|
+
* `WasmBlobActionStep`. Returns the signed `{ txType, txInfo, txHash }`
|
|
98
|
+
* triple the backend forwards to Lighter's `sendTx` endpoint.
|
|
99
|
+
*
|
|
100
|
+
* For REGISTER_API_KEY use `signChangePubKey` instead — it returns an
|
|
101
|
+
* additional `messageToSign` the L1 wallet must countersign.
|
|
102
|
+
*/
|
|
103
|
+
async sign(
|
|
104
|
+
action: ActionType,
|
|
105
|
+
wasmSignParams: Record<string, unknown>,
|
|
106
|
+
context: LighterSignerContext
|
|
107
|
+
): Promise<LighterSignedBlob> {
|
|
108
|
+
if (action === ActionType.REGISTER_API_KEY) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
'Use signChangePubKey() for REGISTER_API_KEY — the L1 eth_sign hop ' +
|
|
111
|
+
'must be coordinated by the caller.'
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
const wasm = await this.ensureLoaded()
|
|
115
|
+
await this.ensureClient(context)
|
|
116
|
+
const result = this.dispatch(wasm, action, wasmSignParams, context)
|
|
117
|
+
return unwrap(result, action)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Step 1 of the REGISTER_API_KEY flow. Generates the WASM blob for a
|
|
122
|
+
* ChangePubKey tx with `L1Sig` left empty, plus the canonical EIP-191
|
|
123
|
+
* message the L1 Ethereum wallet must sign next.
|
|
124
|
+
*
|
|
125
|
+
* Requires the freshly-generated `privateKey` (returned by
|
|
126
|
+
* {@link generateAPIKey}) — the Go WASM signer registers a per-slot client
|
|
127
|
+
* keyed on `(apiKeyIndex, accountIndex)` before it'll sign anything for
|
|
128
|
+
* that slot, including the ChangePubKey that's about to register the key
|
|
129
|
+
* on-chain. This is purely client-side bookkeeping; it does not touch the
|
|
130
|
+
* Lighter API.
|
|
131
|
+
*/
|
|
132
|
+
async signChangePubKey(
|
|
133
|
+
pubKeyHex: string,
|
|
134
|
+
privateKey: string,
|
|
135
|
+
nonce: number,
|
|
136
|
+
apiKeyIndex: number,
|
|
137
|
+
accountIndex: number,
|
|
138
|
+
skipNonce: 0 | 1 = 0
|
|
139
|
+
): Promise<ChangePubKeyResult> {
|
|
140
|
+
const wasm = await this.ensureLoaded()
|
|
141
|
+
await this.ensureClient({
|
|
142
|
+
apiKeyPrivateKey: privateKey,
|
|
143
|
+
apiKeyIndex,
|
|
144
|
+
accountIndex,
|
|
145
|
+
})
|
|
146
|
+
// 5-arg call (matches lighter-python's signer wrapper). `skipNonce`:
|
|
147
|
+
// 0 — embed the supplied nonce and have Lighter enforce it on submit.
|
|
148
|
+
// 1 — embed the nonce but let Lighter pick / not enforce; used for
|
|
149
|
+
// ChangePubKey to sidestep `/nextNonce` vs `/sendTx` disagreement
|
|
150
|
+
// on slot re-claims.
|
|
151
|
+
const result = wasm.SignChangePubKey(
|
|
152
|
+
pubKeyHex,
|
|
153
|
+
skipNonce,
|
|
154
|
+
nonce,
|
|
155
|
+
apiKeyIndex,
|
|
156
|
+
accountIndex
|
|
157
|
+
)
|
|
158
|
+
if (result.error) {
|
|
159
|
+
throw new Error(`Lighter SignChangePubKey failed: ${result.error}`)
|
|
160
|
+
}
|
|
161
|
+
if (
|
|
162
|
+
result.txType === undefined ||
|
|
163
|
+
result.txInfo === undefined ||
|
|
164
|
+
result.txHash === undefined ||
|
|
165
|
+
!result.messageToSign
|
|
166
|
+
) {
|
|
167
|
+
throw new Error('Lighter SignChangePubKey returned incomplete result')
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
txType: result.txType,
|
|
171
|
+
txInfo: result.txInfo,
|
|
172
|
+
txHash: result.txHash,
|
|
173
|
+
messageToSign: result.messageToSign,
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Step 2 of REGISTER_API_KEY — inject the L1 signature produced by the
|
|
179
|
+
* user's Ethereum wallet into the ChangePubKey txInfo JSON. `L1Sig` is the
|
|
180
|
+
* only field in txInfo that depends on the L1 signature; txHash does NOT
|
|
181
|
+
* include it (so we do not recompute it).
|
|
182
|
+
*/
|
|
183
|
+
embedL1Signature(txInfo: string, l1Signature: string): string {
|
|
184
|
+
let parsed: Record<string, unknown>
|
|
185
|
+
try {
|
|
186
|
+
parsed = JSON.parse(txInfo) as Record<string, unknown>
|
|
187
|
+
} catch (err) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`Failed to parse ChangePubKey txInfo as JSON: ${(err as Error).message}`
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
parsed.L1Sig = l1Signature
|
|
193
|
+
return JSON.stringify(parsed)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Create an auth token for authenticated WebSocket subscriptions.
|
|
198
|
+
* `deadline` is a Unix timestamp in seconds — tokens have an 8h hard cap.
|
|
199
|
+
*/
|
|
200
|
+
async createAuthToken(
|
|
201
|
+
deadline: number,
|
|
202
|
+
context: LighterSignerContext
|
|
203
|
+
): Promise<string> {
|
|
204
|
+
const wasm = await this.ensureLoaded()
|
|
205
|
+
await this.ensureClient(context)
|
|
206
|
+
const result = wasm.CreateAuthToken(
|
|
207
|
+
deadline,
|
|
208
|
+
context.apiKeyIndex,
|
|
209
|
+
context.accountIndex
|
|
210
|
+
)
|
|
211
|
+
if (result.error) {
|
|
212
|
+
throw new Error(`Lighter CreateAuthToken failed: ${result.error}`)
|
|
213
|
+
}
|
|
214
|
+
if (!result.authToken) {
|
|
215
|
+
throw new Error('Lighter CreateAuthToken returned no token')
|
|
216
|
+
}
|
|
217
|
+
return result.authToken
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private async ensureLoaded(): Promise<LighterWasmExports> {
|
|
221
|
+
if (!this.wasm) {
|
|
222
|
+
await this.initialize()
|
|
223
|
+
}
|
|
224
|
+
return this.wasm as LighterWasmExports
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private async ensureClient(context: LighterSignerContext): Promise<void> {
|
|
228
|
+
const key = `${context.apiKeyIndex}:${context.accountIndex}:${context.apiKeyPrivateKey}`
|
|
229
|
+
if (this.registeredClients.has(key)) {
|
|
230
|
+
return
|
|
231
|
+
}
|
|
232
|
+
const wasm = await this.ensureLoaded()
|
|
233
|
+
const result = wasm.CreateClient(
|
|
234
|
+
this.apiUrl,
|
|
235
|
+
context.apiKeyPrivateKey,
|
|
236
|
+
this.chainId,
|
|
237
|
+
context.apiKeyIndex,
|
|
238
|
+
context.accountIndex
|
|
239
|
+
)
|
|
240
|
+
if (result.error) {
|
|
241
|
+
throw new Error(`Lighter CreateClient failed: ${result.error}`)
|
|
242
|
+
}
|
|
243
|
+
this.registeredClients.add(key)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Map an ActionType + backend-provided params object to the positional-arg
|
|
248
|
+
* WASM call. The Go signer exports take primitives in order, not an object
|
|
249
|
+
* — so we pick fields in the exact order the Go side expects. Unknown
|
|
250
|
+
* fields (e.g. backend's integrator_* hints) are ignored.
|
|
251
|
+
*/
|
|
252
|
+
private dispatch(
|
|
253
|
+
wasm: LighterWasmExports,
|
|
254
|
+
action: ActionType,
|
|
255
|
+
p: Record<string, unknown>,
|
|
256
|
+
ctx: LighterSignerContext
|
|
257
|
+
): SignResult {
|
|
258
|
+
const nonce = numberField(p, 'nonce')
|
|
259
|
+
switch (action) {
|
|
260
|
+
case ActionType.PLACE_ORDER:
|
|
261
|
+
case ActionType.PLACE_TRIGGER_ORDER:
|
|
262
|
+
return wasm.SignCreateOrder(
|
|
263
|
+
numberField(p, 'market_index'),
|
|
264
|
+
numberField(p, 'client_order_index'),
|
|
265
|
+
numberField(p, 'base_amount'),
|
|
266
|
+
numberField(p, 'price'),
|
|
267
|
+
numberField(p, 'is_ask'),
|
|
268
|
+
numberField(p, 'order_type'),
|
|
269
|
+
numberField(p, 'time_in_force'),
|
|
270
|
+
// WASM's error message lists "reduceOnly" as bool-like, but Go
|
|
271
|
+
// actually calls Value.Int() on every arg — passing an actual bool
|
|
272
|
+
// panics. Coerce to 0/1.
|
|
273
|
+
numberField(p, 'reduce_only'),
|
|
274
|
+
numberField(p, 'trigger_price'),
|
|
275
|
+
numberField(p, 'order_expiry'),
|
|
276
|
+
nonce,
|
|
277
|
+
ctx.apiKeyIndex,
|
|
278
|
+
ctx.accountIndex
|
|
279
|
+
)
|
|
280
|
+
case ActionType.CANCEL_ORDER:
|
|
281
|
+
return wasm.SignCancelOrder(
|
|
282
|
+
numberField(p, 'market_index'),
|
|
283
|
+
numberField(p, 'order_index'),
|
|
284
|
+
nonce,
|
|
285
|
+
ctx.apiKeyIndex,
|
|
286
|
+
ctx.accountIndex
|
|
287
|
+
)
|
|
288
|
+
case ActionType.CANCEL_ALL_ORDERS:
|
|
289
|
+
return wasm.SignCancelAllOrders(
|
|
290
|
+
numberField(p, 'time_in_force'),
|
|
291
|
+
numberField(p, 'timestamp_ms'),
|
|
292
|
+
nonce,
|
|
293
|
+
ctx.apiKeyIndex,
|
|
294
|
+
ctx.accountIndex
|
|
295
|
+
)
|
|
296
|
+
case ActionType.MODIFY_ORDER:
|
|
297
|
+
return wasm.SignModifyOrder(
|
|
298
|
+
numberField(p, 'market_index'),
|
|
299
|
+
numberField(p, 'order_index'),
|
|
300
|
+
numberField(p, 'base_amount'),
|
|
301
|
+
numberField(p, 'price'),
|
|
302
|
+
numberField(p, 'trigger_price'),
|
|
303
|
+
nonce,
|
|
304
|
+
ctx.apiKeyIndex,
|
|
305
|
+
ctx.accountIndex
|
|
306
|
+
)
|
|
307
|
+
case ActionType.UPDATE_LEVERAGE:
|
|
308
|
+
return wasm.SignUpdateLeverage(
|
|
309
|
+
numberField(p, 'market_index'),
|
|
310
|
+
numberField(p, 'fraction'),
|
|
311
|
+
numberField(p, 'margin_mode'),
|
|
312
|
+
nonce,
|
|
313
|
+
ctx.apiKeyIndex,
|
|
314
|
+
ctx.accountIndex
|
|
315
|
+
)
|
|
316
|
+
case ActionType.UPDATE_POSITION_MARGIN:
|
|
317
|
+
return wasm.SignUpdateMargin(
|
|
318
|
+
numberField(p, 'market_index'),
|
|
319
|
+
numberField(p, 'usdc_amount'),
|
|
320
|
+
numberField(p, 'direction'),
|
|
321
|
+
nonce,
|
|
322
|
+
ctx.apiKeyIndex,
|
|
323
|
+
ctx.accountIndex
|
|
324
|
+
)
|
|
325
|
+
case ActionType.WITHDRAWAL:
|
|
326
|
+
return wasm.SignWithdraw(
|
|
327
|
+
numberField(p, 'amount'),
|
|
328
|
+
nonce,
|
|
329
|
+
ctx.apiKeyIndex,
|
|
330
|
+
ctx.accountIndex
|
|
331
|
+
)
|
|
332
|
+
case ActionType.TRANSFER:
|
|
333
|
+
// SignTransfer's 7 positional args follow the Go binding order:
|
|
334
|
+
// `toAccount, usdcAmount, fee, memo, nonce, apiKeyIndex,
|
|
335
|
+
// accountIndex`. `memo` is copied directly into a `[32]byte`, so the
|
|
336
|
+
// backend MUST send a JS string whose UTF-8 byte length is exactly
|
|
337
|
+
// 32 (in practice: 32 ASCII characters) — anything else fails with
|
|
338
|
+
// "memo expected to be 32 bytes long".
|
|
339
|
+
return wasm.SignTransfer(
|
|
340
|
+
numberField(p, 'to_account'),
|
|
341
|
+
numberField(p, 'usdc_amount'),
|
|
342
|
+
numberField(p, 'fee'),
|
|
343
|
+
stringField(p, 'memo'),
|
|
344
|
+
nonce,
|
|
345
|
+
ctx.apiKeyIndex,
|
|
346
|
+
ctx.accountIndex
|
|
347
|
+
)
|
|
348
|
+
default:
|
|
349
|
+
throw new Error(
|
|
350
|
+
`Lighter WASM signer does not support action: ${action}`
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function unwrap(result: SignResult, action: ActionType): LighterSignedBlob {
|
|
357
|
+
if (result.error) {
|
|
358
|
+
throw new Error(`Lighter sign(${action}) failed: ${result.error}`)
|
|
359
|
+
}
|
|
360
|
+
if (
|
|
361
|
+
result.txType === undefined ||
|
|
362
|
+
result.txInfo === undefined ||
|
|
363
|
+
result.txHash === undefined
|
|
364
|
+
) {
|
|
365
|
+
throw new Error(
|
|
366
|
+
`Lighter sign(${action}) returned an incomplete signed blob`
|
|
367
|
+
)
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
txType: result.txType,
|
|
371
|
+
txInfo: result.txInfo,
|
|
372
|
+
txHash: result.txHash,
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function numberField(p: Record<string, unknown>, key: string): number {
|
|
377
|
+
const v = p[key]
|
|
378
|
+
if (typeof v === 'number') {
|
|
379
|
+
return v
|
|
380
|
+
}
|
|
381
|
+
if (typeof v === 'boolean') {
|
|
382
|
+
return v ? 1 : 0
|
|
383
|
+
}
|
|
384
|
+
if (typeof v === 'string' && v !== '' && !Number.isNaN(Number(v))) {
|
|
385
|
+
return Number(v)
|
|
386
|
+
}
|
|
387
|
+
throw new Error(
|
|
388
|
+
`Lighter sign params missing numeric field '${key}' (got ${typeof v})`
|
|
389
|
+
)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function stringField(p: Record<string, unknown>, key: string): string {
|
|
393
|
+
const v = p[key]
|
|
394
|
+
if (typeof v === 'string' && v !== '') {
|
|
395
|
+
return v
|
|
396
|
+
}
|
|
397
|
+
throw new Error(
|
|
398
|
+
`Lighter sign params missing string field '${key}' (got ${typeof v})`
|
|
399
|
+
)
|
|
400
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { LighterApiKey } from './LighterKeyStore.js'
|
|
2
|
+
import type { LighterReadOnlyToken } from './LighterReadOnlyTokenManager.js'
|
|
3
|
+
import type { LighterSigner } from './LighterSigner.js'
|
|
4
|
+
|
|
5
|
+
const DEFAULT_LIFETIME_SECONDS = 60 * 60
|
|
6
|
+
const DEFAULT_THRESHOLD_SECONDS = 30 * 86_400
|
|
7
|
+
|
|
8
|
+
/** @public */
|
|
9
|
+
export interface CreateAuthTokenInputs {
|
|
10
|
+
signer: LighterSigner
|
|
11
|
+
apiKey: Pick<
|
|
12
|
+
LighterApiKey,
|
|
13
|
+
'apiKeyPrivateKey' | 'apiKeyIndex' | 'accountIndex'
|
|
14
|
+
>
|
|
15
|
+
/**
|
|
16
|
+
* Token lifetime in seconds. Lighter caps standard tokens at 8 hours.
|
|
17
|
+
* Defaults to 1 hour, matching the previous `PerpsClient` behaviour.
|
|
18
|
+
*/
|
|
19
|
+
lifetimeSeconds?: number
|
|
20
|
+
/** Optional clock injection for tests. */
|
|
21
|
+
now?: () => number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a fresh Lighter standard auth token via the WASM signer. Returns the
|
|
26
|
+
* opaque bearer string Lighter will accept on its authenticated read
|
|
27
|
+
* endpoints (`getOrders`, `getOrder`, `getActivity`, etc.).
|
|
28
|
+
*
|
|
29
|
+
* This utility carries no SDK-wide coupling — pass an explicit `signer` +
|
|
30
|
+
* `apiKey` and consume the returned bearer however the caller likes
|
|
31
|
+
* (per-call `options.lighterAuthToken`, persisted cache, etc.).
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export async function createAuthToken(
|
|
35
|
+
inputs: CreateAuthTokenInputs
|
|
36
|
+
): Promise<string> {
|
|
37
|
+
const { signer, apiKey } = inputs
|
|
38
|
+
const lifetime = inputs.lifetimeSeconds ?? DEFAULT_LIFETIME_SECONDS
|
|
39
|
+
const now = inputs.now ?? (() => Date.now())
|
|
40
|
+
const deadline = Math.floor(now() / 1000) + lifetime
|
|
41
|
+
return signer.createAuthToken(deadline, {
|
|
42
|
+
apiKeyPrivateKey: apiKey.apiKeyPrivateKey,
|
|
43
|
+
apiKeyIndex: apiKey.apiKeyIndex,
|
|
44
|
+
accountIndex: apiKey.accountIndex,
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* True when `token` exists, has not already expired, and is within
|
|
50
|
+
* `thresholdSeconds` of its recorded `expiry`. Intended for widget renewal
|
|
51
|
+
* banners — `thresholdSeconds` defaults to 30 days. Returns `false` for an
|
|
52
|
+
* undefined or already-expired token, so callers may treat that as "no
|
|
53
|
+
* token / renewal not needed (yet)".
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export function isReadOnlyTokenExpiringSoon(
|
|
57
|
+
token: LighterReadOnlyToken | undefined | null,
|
|
58
|
+
thresholdSeconds: number = DEFAULT_THRESHOLD_SECONDS,
|
|
59
|
+
now: () => number = () => Date.now()
|
|
60
|
+
): boolean {
|
|
61
|
+
if (!token) {
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
const remaining = token.expiry - Math.floor(now() / 1000)
|
|
65
|
+
if (remaining <= 0) {
|
|
66
|
+
return false
|
|
67
|
+
}
|
|
68
|
+
return remaining <= thresholdSeconds
|
|
69
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// biome-ignore-all lint/performance/noBarrelFile: package-internal barrel.
|
|
2
|
+
|
|
3
|
+
export type { CreateAuthTokenInputs } from './createAuthToken.js'
|
|
4
|
+
export {
|
|
5
|
+
createAuthToken,
|
|
6
|
+
isReadOnlyTokenExpiringSoon,
|
|
7
|
+
} from './createAuthToken.js'
|
|
8
|
+
export type { LighterApiKey } from './LighterKeyStore.js'
|
|
9
|
+
export { LighterKeyStore } from './LighterKeyStore.js'
|
|
10
|
+
export type {
|
|
11
|
+
ApproveReadOnlyTokenInputs,
|
|
12
|
+
ApproveReadOnlyTokenResult,
|
|
13
|
+
LighterCreateTokenResponse,
|
|
14
|
+
LighterReadOnlyToken,
|
|
15
|
+
LighterReadOnlyTokenManagerOptions,
|
|
16
|
+
LighterTokenFetcher,
|
|
17
|
+
} from './LighterReadOnlyTokenManager.js'
|
|
18
|
+
export {
|
|
19
|
+
DEFAULT_LIGHTER_API_URL,
|
|
20
|
+
DEFAULT_READ_ONLY_TOKEN_NAME,
|
|
21
|
+
defaultLighterTokenFetcher,
|
|
22
|
+
LighterReadOnlyTokenManager,
|
|
23
|
+
} from './LighterReadOnlyTokenManager.js'
|
|
24
|
+
export type {
|
|
25
|
+
ApiKeyPair,
|
|
26
|
+
ChangePubKeyResult,
|
|
27
|
+
LighterSignedBlob,
|
|
28
|
+
LighterSignerConfig,
|
|
29
|
+
LighterSignerContext,
|
|
30
|
+
} from './LighterSigner.js'
|
|
31
|
+
export { LighterSigner } from './LighterSigner.js'
|
|
32
|
+
export type {
|
|
33
|
+
LighterWasmExports,
|
|
34
|
+
LoadLighterWasmOptions,
|
|
35
|
+
} from './wasmLoader.js'
|
|
36
|
+
export { loadLighterWasm, resetLighterWasmCache } from './wasmLoader.js'
|