@lightconexyz/lightcone-sdk 0.8.1-rc.8 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +198 -10
- package/dist/auth/client.d.ts +27 -1
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +94 -4
- package/dist/auth/client.js.map +1 -1
- package/dist/auth/index.d.ts +59 -5
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +31 -5
- package/dist/auth/index.js.map +1 -1
- package/dist/client.d.ts +49 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +70 -2
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +59 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +303 -6
- package/dist/context.js.map +1 -1
- package/dist/domain/market/client.d.ts +16 -0
- package/dist/domain/market/client.d.ts.map +1 -1
- package/dist/domain/market/client.js +33 -0
- package/dist/domain/market/client.js.map +1 -1
- package/dist/domain/market/convert.d.ts.map +1 -1
- package/dist/domain/market/convert.js +24 -10
- package/dist/domain/market/convert.js.map +1 -1
- package/dist/domain/market/index.d.ts +18 -4
- package/dist/domain/market/index.d.ts.map +1 -1
- package/dist/domain/market/index.js.map +1 -1
- package/dist/domain/market/outcome.d.ts +9 -3
- package/dist/domain/market/outcome.d.ts.map +1 -1
- package/dist/domain/market/outcome.js +10 -7
- package/dist/domain/market/outcome.js.map +1 -1
- package/dist/domain/market/tokens.js +8 -2
- package/dist/domain/market/tokens.js.map +1 -1
- package/dist/domain/market/wire.d.ts +20 -3
- package/dist/domain/market/wire.d.ts.map +1 -1
- package/dist/domain/market/wire.js.map +1 -1
- package/dist/domain/order/client.d.ts +8 -7
- package/dist/domain/order/client.d.ts.map +1 -1
- package/dist/domain/order/client.js +23 -8
- package/dist/domain/order/client.js.map +1 -1
- package/dist/domain/orderbook/client.d.ts +7 -1
- package/dist/domain/orderbook/client.d.ts.map +1 -1
- package/dist/domain/orderbook/client.js +54 -1
- package/dist/domain/orderbook/client.js.map +1 -1
- package/dist/domain/orderbook/index.d.ts +7 -9
- package/dist/domain/orderbook/index.d.ts.map +1 -1
- package/dist/domain/orderbook/index.js +28 -24
- package/dist/domain/orderbook/index.js.map +1 -1
- package/dist/domain/orderbook/state.d.ts +21 -16
- package/dist/domain/orderbook/state.d.ts.map +1 -1
- package/dist/domain/orderbook/state.js +36 -15
- package/dist/domain/orderbook/state.js.map +1 -1
- package/dist/domain/orderbook/ticker.d.ts +1 -0
- package/dist/domain/orderbook/ticker.d.ts.map +1 -1
- package/dist/domain/orderbook/ticker.js.map +1 -1
- package/dist/domain/orderbook/wire.d.ts +34 -10
- package/dist/domain/orderbook/wire.d.ts.map +1 -1
- package/dist/domain/orderbook/wire.js +47 -0
- package/dist/domain/orderbook/wire.js.map +1 -1
- package/dist/domain/position/builders.d.ts +6 -2
- package/dist/domain/position/builders.d.ts.map +1 -1
- package/dist/domain/position/builders.js +24 -8
- package/dist/domain/position/builders.js.map +1 -1
- package/dist/domain/position/client.d.ts +166 -12
- package/dist/domain/position/client.d.ts.map +1 -1
- package/dist/domain/position/client.js +614 -15
- package/dist/domain/position/client.js.map +1 -1
- package/dist/domain/position/index.d.ts +58 -3
- package/dist/domain/position/index.d.ts.map +1 -1
- package/dist/domain/position/index.js +1 -0
- package/dist/domain/position/index.js.map +1 -1
- package/dist/domain/position/state.d.ts +118 -0
- package/dist/domain/position/state.d.ts.map +1 -0
- package/dist/domain/position/state.js +262 -0
- package/dist/domain/position/state.js.map +1 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +2 -2
- package/dist/env.js.map +1 -1
- package/dist/error.d.ts +32 -2
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +59 -1
- package/dist/error.js.map +1 -1
- package/dist/http/client.d.ts +76 -1
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +259 -39
- package/dist/http/client.js.map +1 -1
- package/dist/http/credentialRestorer.d.ts +49 -0
- package/dist/http/credentialRestorer.d.ts.map +1 -0
- package/dist/http/credentialRestorer.js +3 -0
- package/dist/http/credentialRestorer.js.map +1 -0
- package/dist/http/index.d.ts +1 -0
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/prelude.d.ts +10 -7
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js +12 -2
- package/dist/prelude.js.map +1 -1
- package/dist/privy/client.d.ts +4 -0
- package/dist/privy/client.d.ts.map +1 -1
- package/dist/privy/client.js +4 -0
- package/dist/privy/client.js.map +1 -1
- package/dist/privy/index.d.ts +4 -4
- package/dist/privy/index.d.ts.map +1 -1
- package/dist/privy/index.js +11 -16
- package/dist/privy/index.js.map +1 -1
- package/dist/program/builder.d.ts +13 -11
- package/dist/program/builder.d.ts.map +1 -1
- package/dist/program/builder.js +31 -16
- package/dist/program/builder.js.map +1 -1
- package/dist/program/constants.d.ts +1 -0
- package/dist/program/constants.d.ts.map +1 -1
- package/dist/program/constants.js +1 -0
- package/dist/program/constants.js.map +1 -1
- package/dist/program/envelope.d.ts +14 -16
- package/dist/program/envelope.d.ts.map +1 -1
- package/dist/program/envelope.js +48 -39
- package/dist/program/envelope.js.map +1 -1
- package/dist/program/index.d.ts +2 -2
- package/dist/program/index.d.ts.map +1 -1
- package/dist/program/index.js +6 -4
- package/dist/program/index.js.map +1 -1
- package/dist/program/instructions.d.ts +17 -9
- package/dist/program/instructions.d.ts.map +1 -1
- package/dist/program/instructions.js +40 -19
- package/dist/program/instructions.js.map +1 -1
- package/dist/program/orders.d.ts +7 -8
- package/dist/program/orders.d.ts.map +1 -1
- package/dist/program/orders.js +20 -22
- package/dist/program/orders.js.map +1 -1
- package/dist/program/types.d.ts +4 -3
- package/dist/program/types.d.ts.map +1 -1
- package/dist/program/types.js.map +1 -1
- package/dist/rpc.d.ts +89 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +285 -4
- package/dist/rpc.js.map +1 -1
- package/dist/shared/api_response.d.ts +16 -1
- package/dist/shared/api_response.d.ts.map +1 -1
- package/dist/shared/api_response.js +26 -1
- package/dist/shared/api_response.js.map +1 -1
- package/dist/shared/index.d.ts +3 -3
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +13 -6
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/json.d.ts +5 -0
- package/dist/shared/json.d.ts.map +1 -0
- package/dist/shared/json.js +38 -0
- package/dist/shared/json.js.map +1 -0
- package/dist/shared/rejection.d.ts.map +1 -1
- package/dist/shared/rejection.js +8 -0
- package/dist/shared/rejection.js.map +1 -1
- package/dist/shared/scaling.d.ts +30 -18
- package/dist/shared/scaling.d.ts.map +1 -1
- package/dist/shared/scaling.js +153 -95
- package/dist/shared/scaling.js.map +1 -1
- package/dist/shared/signing.d.ts +17 -0
- package/dist/shared/signing.d.ts.map +1 -1
- package/dist/shared/signing.js +27 -0
- package/dist/shared/signing.js.map +1 -1
- package/dist/shared/types.d.ts +9 -7
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/types.js +12 -4
- package/dist/shared/types.js.map +1 -1
- package/dist/ws/client.browser.d.ts +4 -0
- package/dist/ws/client.browser.d.ts.map +1 -1
- package/dist/ws/client.browser.js +13 -1
- package/dist/ws/client.browser.js.map +1 -1
- package/dist/ws/client.node.d.ts +4 -0
- package/dist/ws/client.node.d.ts.map +1 -1
- package/dist/ws/client.node.js +13 -1
- package/dist/ws/client.node.js.map +1 -1
- package/dist/ws/index.d.ts +24 -0
- package/dist/ws/index.d.ts.map +1 -1
- package/dist/ws/index.js +176 -2
- package/dist/ws/index.js.map +1 -1
- package/dist/ws/subscriptions.d.ts +12 -1
- package/dist/ws/subscriptions.d.ts.map +1 -1
- package/dist/ws/subscriptions.js +11 -0
- package/dist/ws/subscriptions.js.map +1 -1
- package/dist/ws/types.d.ts +5 -0
- package/dist/ws/types.d.ts.map +1 -1
- package/dist/ws/types.js.map +1 -1
- package/package.json +6 -2
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,6CAA8E;AAC9E,iCAAoD;AAEpD,uCAAiE;AAEjE,4CAA0C;AAC1C,8CAA2C;AAC3C,wDAAsD;AACtD,0CAAwC;AACxC,kDAAgD;AAChD,gDAA8C;AAC9C,0DAA4D;AAC5D,gDAA8C;AAC9C,0CAAwC;AACxC,iCAAoD;AACpD,+BAAuF;AACvF,mCAAgC;AAChC,+BAA4B;AAC5B,+CAAiD;AACjD,qCAAyD;AAEzD,6BAA+C;AAE/C,MAAM,SAAS;IACL,gBAAgB,CAA8B;IAEtD,YAAY,OAAyB;QACnC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC;IAClC,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED,cAAc,CAAC,WAAwC;QACrD,IAAI,CAAC,gBAAgB,GAAG,WAAW,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,WAAW;QACf,6EAA6E;IAC/E,CAAC;CACF;AAED,MAAa,eAAe;IACjB,IAAI,CAAgB;IACpB,SAAS,CAAY;IACrB,iBAAiB,CAAc;IAC/B,gBAAgB,CAAc;IAC9B,gBAAgB,CAAmB;IACpC,kBAAkB,CAAgB;IAClC,oBAAoB,CAAmB;IACvC,eAAe,CAAqB;IAC3B,aAAa,CAAW;IACxB,cAAc,CAAY;IAE3C,yEAAyE;IACzE,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED,YAAY,MAYX;QACC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,IAAA,eAAY,EAAC,kBAAY,CAAC,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AI;gBACf,oBAAoB,EAAE,EAAE;gBACxB,oBAAoB,EAAE,KAAK;gBAC3B,cAAc,EAAE,MAAM;gBACtB,aAAa,EAAE,MAAM;aACtB;YACD,SAAS,EAAE,IAAI,CAAC,cAAc;YAC9B,aAAa,EAAE,IAAI,CAAC,kBAAkB;YACtC,eAAe,EAAE,IAAI,CAAC,oBAAoB;YAC1C,iBAAiB,EAAE,IAAI,CAAC,kBAAkB;gBACxC,CAAC,CAAC,IAAI,oBAAU,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;gBACtE,CAAC,CAAC,SAAS;YACb,gBAAgB,EAAE,IAAI,CAAC,iBAAiB;gBACtC,CAAC,CAAC,IAAI,oBAAU,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;gBACrE,CAAC,CAAC,SAAS;YACb,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC,CAAC;IACL,CAAC;CACF;AA/GD,wDA+GC","sourcesContent":["import { Connection, Keypair, PublicKey, Transaction } from \"@solana/web3.js\";\nimport { Auth, type AuthCredentials } from \"./auth\";\nimport type { ClientContext } from \"./context\";\nimport { signAndSubmitTx as signAndSubmitTxFn } from \"./context\";\nimport type { FaucetRequest, FaucetResponse } from \"./domain/faucet\";\nimport { Markets } from \"./domain/market\";\nimport { Metrics } from \"./domain/metrics\";\nimport { Notifications } from \"./domain/notification\";\nimport { Orders } from \"./domain/order\";\nimport { Orderbooks } from \"./domain/orderbook\";\nimport { Positions } from \"./domain/position\";\nimport { PriceHistoryClient } from \"./domain/price_history\";\nimport { Referrals } from \"./domain/referral\";\nimport { Trades } from \"./domain/trade\";\nimport { LightconeHttp, RetryPolicy } from \"./http\";\nimport { LightconeEnv, apiUrl, wsUrl, rpcUrl, programId as envProgramId } from \"./env\";\nimport { Privy } from \"./privy\";\nimport { Rpc } from \"./rpc\";\nimport { RpcFailoverState } from \"./rpcFailover\";\nimport { DepositSource, type PubkeyStr } from \"./shared\";\nimport { type ExternalSigner, type SigningStrategy } from \"./shared/signing\";\nimport { WsClient, type WsConfig } from \"./ws\";\n\nclass AuthState {\n private credentialsValue: AuthCredentials | undefined;\n\n constructor(initial?: AuthCredentials) {\n this.credentialsValue = initial;\n }\n\n getCredentials(): AuthCredentials | undefined {\n return this.credentialsValue;\n }\n\n setCredentials(credentials: AuthCredentials | undefined): void {\n this.credentialsValue = credentials;\n }\n\n async clearCaches(): Promise<void> {\n // No caches to clear — decimals are derived locally from orderbook metadata.\n }\n}\n\nexport class LightconeClient implements ClientContext {\n readonly http: LightconeHttp;\n readonly programId: PublicKey;\n readonly primaryConnection?: Connection;\n readonly backupConnection?: Connection;\n readonly rpcFailoverState: RpcFailoverState;\n private depositSourceValue: DepositSource;\n private signingStrategyValue?: SigningStrategy;\n private orderNonceValue: number | undefined;\n private readonly wsConfigValue: WsConfig;\n private readonly authStateStore: AuthState;\n\n /** @deprecated Use primaryConnection — kept for ClientContext compat. */\n get connection(): Connection | undefined {\n return this.primaryConnection;\n }\n\n constructor(params: {\n http: LightconeHttp;\n wsConfig: WsConfig;\n programId?: PublicKey;\n primaryConnection?: Connection;\n backupConnection?: Connection;\n rpcFailoverState?: RpcFailoverState;\n depositSource?: DepositSource;\n signingStrategy?: SigningStrategy;\n orderNonce?: number;\n authCredentials?: AuthCredentials;\n authState?: AuthState;\n }) {\n this.http = params.http;\n this.programId = params.programId ?? envProgramId(LightconeEnv.Prod);\n this.primaryConnection = params.primaryConnection;\n this.backupConnection = params.backupConnection;\n this.rpcFailoverState =\n params.rpcFailoverState ?? new RpcFailoverState();\n this.depositSourceValue = params.depositSource ?? DepositSource.Global;\n this.signingStrategyValue = params.signingStrategy;\n this.orderNonceValue = params.orderNonce;\n this.wsConfigValue = params.wsConfig;\n this.authStateStore =\n params.authState ??\n new AuthState(params.authCredentials);\n }\n\n // ── Deposit source ──────────────────────────────────────────────────\n\n get depositSource(): DepositSource {\n return this.depositSourceValue;\n }\n\n setDepositSource(source: DepositSource): void {\n this.depositSourceValue = source;\n }\n\n // ── Signing strategy ────────────────────────────────────────────────\n\n get signingStrategy(): SigningStrategy | undefined {\n return this.signingStrategyValue;\n }\n\n setSigningStrategy(strategy: SigningStrategy): void {\n this.signingStrategyValue = strategy;\n }\n\n clearSigningStrategy(): void {\n this.signingStrategyValue = undefined;\n }\n\n // ── Nonce cache ──────────────────────────────────────────────────────\n\n orderNonce(): number | undefined {\n return this.orderNonceValue;\n }\n\n setOrderNonce(nonce: number): void {\n this.orderNonceValue = nonce;\n }\n\n clearOrderNonce(): void {\n this.orderNonceValue = undefined;\n }\n\n // ── Auth token (cookie) ─────────────────────────────────────────────\n\n /**\n * Get the current `lightcone-token` cookie value, if any. Populated by the SDK\n * after a successful login, then attached on every authed request. Useful\n * for forwarding the token through the `*WithCookies` methods, or\n * persisting the session across processes.\n */\n async authToken(): Promise<string | undefined> {\n return this.http.authTokenRef()();\n }\n\n /**\n * Clear the cached `lightcone-token`. Subsequent authed calls will go out\n * without a `Cookie` header (and 401) unless they use a\n * `*WithCookies` variant.\n */\n async clearAuthToken(): Promise<void> {\n await this.http.clearAuthToken();\n }\n\n // ── Transaction signing + submission ────────────────────────────────\n\n async signAndSubmitTx(tx: Transaction): Promise<string> {\n return signAndSubmitTxFn(this, tx);\n }\n\n static builder(): LightconeClientBuilder {\n return new LightconeClientBuilder();\n }\n\n // ── Sub-client accessors ─────────────────────────────────────────────\n\n markets(): Markets {\n return new Markets(this);\n }\n\n orderbooks(): Orderbooks {\n return new Orderbooks(this);\n }\n\n orders(): Orders {\n return new Orders(this);\n }\n\n positions(): Positions {\n return new Positions(this);\n }\n\n trades(): Trades {\n return new Trades(this);\n }\n\n priceHistory(): PriceHistoryClient {\n return new PriceHistoryClient(this);\n }\n\n notifications(): Notifications {\n return new Notifications(this);\n }\n\n /**\n * Metrics sub-client — platform / market / orderbook / category / deposit-token\n * volume metrics, market leaderboard, and time-series history.\n */\n metrics(): Metrics {\n return new Metrics(this);\n }\n\n /**\n * Request testnet SOL and whitelisted deposit tokens for a wallet.\n *\n * Only active on environments whose backend has the faucet enabled (typically\n * local and staging).\n *\n * `POST /api/claim`\n */\n async claim(walletAddress: PubkeyStr): Promise<FaucetResponse> {\n const url = `${this.http.baseUrl()}/api/claim`;\n return this.http.post<FaucetResponse, FaucetRequest>(\n url,\n { wallet_address: walletAddress },\n RetryPolicy.None\n );\n }\n\n auth(): Auth {\n return new Auth({\n http: this.http,\n authState: this.authStateStore,\n });\n }\n\n privy(): Privy {\n return new Privy(this);\n }\n\n referrals(): Referrals {\n return new Referrals(this);\n }\n\n rpc(): Rpc {\n return new Rpc(this);\n }\n\n wsConfig(): WsConfig {\n return this.wsConfigValue;\n }\n\n ws(): WsClient {\n return new WsClient(this.wsConfigValue, this.http.authTokenRef());\n }\n\n clone(): LightconeClient {\n return new LightconeClient({\n http: this.http,\n wsConfig: { ...this.wsConfigValue },\n programId: this.programId,\n primaryConnection: this.primaryConnection\n ? new Connection(this.primaryConnection.rpcEndpoint, { commitment: \"confirmed\" })\n : undefined,\n backupConnection: this.backupConnection\n ? new Connection(this.backupConnection.rpcEndpoint, { commitment: \"confirmed\" })\n : undefined,\n rpcFailoverState: this.rpcFailoverState,\n depositSource: this.depositSourceValue,\n signingStrategy: this.signingStrategyValue,\n orderNonce: this.orderNonceValue,\n authState: this.authStateStore,\n });\n }\n}\n\nexport class LightconeClientBuilder {\n private baseUrlValue: string = apiUrl(LightconeEnv.Prod);\n private wsUrlValue: string = wsUrl(LightconeEnv.Prod);\n private authCredentials?: AuthCredentials;\n private programIdValue: PublicKey = envProgramId(LightconeEnv.Prod);\n private depositSourceValue: DepositSource = DepositSource.Global;\n private signingStrategyValue?: SigningStrategy;\n private primaryRpcUrlValue?: string = rpcUrl(LightconeEnv.Prod);\n private backupRpcUrlValue?: string;\n\n /**\n * Set the deployment environment. Configures the API URL, WebSocket URL,\n * RPC URL, and program ID for the given environment.\n *\n * Individual URL overrides (e.g. `.baseUrl()`) take precedence when\n * called **after** `.env()`.\n */\n env(environment: LightconeEnv): LightconeClientBuilder {\n this.baseUrlValue = apiUrl(environment);\n this.wsUrlValue = wsUrl(environment);\n this.programIdValue = envProgramId(environment);\n this.primaryRpcUrlValue = rpcUrl(environment);\n return this;\n }\n\n baseUrl(url: string): LightconeClientBuilder {\n return this.withBaseUrl(url);\n }\n\n withBaseUrl(url: string): LightconeClientBuilder {\n this.baseUrlValue = url;\n return this;\n }\n\n wsUrl(url: string): LightconeClientBuilder {\n return this.withWsUrl(url);\n }\n\n withWsUrl(url: string): LightconeClientBuilder {\n this.wsUrlValue = url;\n return this;\n }\n\n auth(credentials: AuthCredentials): LightconeClientBuilder {\n return this.withAuth(credentials);\n }\n\n withAuth(credentials: AuthCredentials): LightconeClientBuilder {\n this.authCredentials = credentials;\n return this;\n }\n\n programId(id: PublicKey): LightconeClientBuilder {\n this.programIdValue = id;\n return this;\n }\n\n depositSource(source: DepositSource): LightconeClientBuilder {\n this.depositSourceValue = source;\n return this;\n }\n\n nativeSigner(keypair: Keypair): LightconeClientBuilder {\n this.signingStrategyValue = { type: \"native\", keypair };\n return this;\n }\n\n externalSigner(signer: ExternalSigner): LightconeClientBuilder {\n this.signingStrategyValue = { type: \"walletAdapter\", signer };\n return this;\n }\n\n privyWalletId(walletId: string): LightconeClientBuilder {\n this.signingStrategyValue = { type: \"privy\", walletId };\n return this;\n }\n\n rpcUrl(url: string): LightconeClientBuilder {\n this.primaryRpcUrlValue = url;\n return this;\n }\n\n /** Set a backup Solana RPC URL for automatic failover. */\n backupRpcUrl(url: string): LightconeClientBuilder {\n this.backupRpcUrlValue = url;\n return this;\n }\n\n build(): LightconeClient {\n return new LightconeClient({\n http: new LightconeHttp(this.baseUrlValue),\n wsConfig: {\n url: this.wsUrlValue,\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 10_000,\n },\n programId: this.programIdValue,\n depositSource: this.depositSourceValue,\n signingStrategy: this.signingStrategyValue,\n primaryConnection: this.primaryRpcUrlValue\n ? new Connection(this.primaryRpcUrlValue, { commitment: \"confirmed\" })\n : undefined,\n backupConnection: this.backupRpcUrlValue\n ? new Connection(this.backupRpcUrlValue, { commitment: \"confirmed\" })\n : undefined,\n authCredentials: this.authCredentials,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,6CAA8E;AAC9E,iCAAoD;AAEpD,uCAKmB;AAGnB,4CAA0C;AAC1C,8CAA2C;AAC3C,wDAAsD;AACtD,0CAAwC;AACxC,kDAAgD;AAChD,gDAA8C;AAC9C,0DAA4D;AAC5D,gDAA8C;AAC9C,0CAAwC;AACxC,iCAA6E;AAC7E,+BAAuF;AACvF,mCAAgC;AAChC,+BAA4B;AAC5B,+CAAiD;AACjD,qCAA8E;AAE9E,6BAA+C;AAE/C,MAAM,SAAS;IACL,gBAAgB,CAA8B;IAEtD,YAAY,OAAyB;QACnC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC;IAClC,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED,cAAc,CAAC,WAAwC;QACrD,IAAI,CAAC,gBAAgB,GAAG,WAAW,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,WAAW;QACf,6EAA6E;IAC/E,CAAC;CACF;AAED,MAAa,eAAe;IACjB,IAAI,CAAgB;IACpB,SAAS,CAAY;IACrB,iBAAiB,CAAc;IAC/B,gBAAgB,CAAc;IAC9B,gBAAgB,CAAmB;IACpC,kBAAkB,CAAgB;IAClC,oBAAoB,CAAmB;IACvC,kCAAkC,CAAU;IAC5C,eAAe,CAAqB;IAC3B,aAAa,CAAW;IACxB,cAAc,CAAY;IAClC,mBAAmB,CAAuC;IAEnE,yEAAyE;IACzE,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,iB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ACtB,IAAI,CAAC,iBAAiB,GAAG,GAAG,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,eAAe,CAAC;YACzB,IAAI,EAAE,IAAI,oBAAa,CAAC,IAAI,CAAC,YAAY,CAAC;YAC1C,QAAQ,EAAE;gBACR,GAAG,EAAE,IAAI,CAAC,UAAU;gBACpB,SAAS,EAAE,IAAI;gBACf,oBAAoB,EAAE,EAAE;gBACxB,oBAAoB,EAAE,KAAK;gBAC3B,cAAc,EAAE,MAAM;gBACtB,aAAa,EAAE,MAAM;aACtB;YACD,SAAS,EAAE,IAAI,CAAC,cAAc;YAC9B,aAAa,EAAE,IAAI,CAAC,kBAAkB;YACtC,eAAe,EAAE,IAAI,CAAC,oBAAoB;YAC1C,6BAA6B,EAAE,IAAI,CAAC,kCAAkC;YACtE,iBAAiB,EAAE,IAAI,CAAC,kBAAkB;gBACxC,CAAC,CAAC,IAAI,oBAAU,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;gBACtE,CAAC,CAAC,SAAS;YACb,gBAAgB,EAAE,IAAI,CAAC,iBAAiB;gBACtC,CAAC,CAAC,IAAI,oBAAU,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;gBACrE,CAAC,CAAC,SAAS;YACb,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC,CAAC;IACL,CAAC;CACF;AA1HD,wDA0HC","sourcesContent":["import { Connection, Keypair, PublicKey, Transaction } from \"@solana/web3.js\";\nimport { Auth, type AuthCredentials } from \"./auth\";\nimport type { ClientContext } from \"./context\";\nimport {\n signAndSubmitTx as signAndSubmitTxFn,\n signAndSubmitTxConfirmed as signAndSubmitTxConfirmedFn,\n signAndSubmitTxConfirmedWithSlot as signAndSubmitTxConfirmedWithSlotFn,\n signAndSubmitPreparedTxConfirmedWithSlot as signAndSubmitPreparedTxConfirmedWithSlotFn,\n} from \"./context\";\nimport type { ConfirmedTransaction } from \"./context\";\nimport type { FaucetRequest, FaucetResponse } from \"./domain/faucet\";\nimport { Markets } from \"./domain/market\";\nimport { Metrics } from \"./domain/metrics\";\nimport { Notifications } from \"./domain/notification\";\nimport { Orders } from \"./domain/order\";\nimport { Orderbooks } from \"./domain/orderbook\";\nimport { Positions } from \"./domain/position\";\nimport { PriceHistoryClient } from \"./domain/price_history\";\nimport { Referrals } from \"./domain/referral\";\nimport { Trades } from \"./domain/trade\";\nimport { LightconeHttp, RetryPolicy, type CredentialRestorer } from \"./http\";\nimport { LightconeEnv, apiUrl, wsUrl, rpcUrl, programId as envProgramId } from \"./env\";\nimport { Privy } from \"./privy\";\nimport { Rpc } from \"./rpc\";\nimport { RpcFailoverState } from \"./rpcFailover\";\nimport { DepositSource, type OrderbookRules, type PubkeyStr } from \"./shared\";\nimport { type ExternalSigner, type SigningStrategy } from \"./shared/signing\";\nimport { WsClient, type WsConfig } from \"./ws\";\n\nclass AuthState {\n private credentialsValue: AuthCredentials | undefined;\n\n constructor(initial?: AuthCredentials) {\n this.credentialsValue = initial;\n }\n\n getCredentials(): AuthCredentials | undefined {\n return this.credentialsValue;\n }\n\n setCredentials(credentials: AuthCredentials | undefined): void {\n this.credentialsValue = credentials;\n }\n\n async clearCaches(): Promise<void> {\n // No caches to clear — decimals are derived locally from orderbook metadata.\n }\n}\n\nexport class LightconeClient implements ClientContext {\n readonly http: LightconeHttp;\n readonly programId: PublicKey;\n readonly primaryConnection?: Connection;\n readonly backupConnection?: Connection;\n readonly rpcFailoverState: RpcFailoverState;\n private depositSourceValue: DepositSource;\n private signingStrategyValue?: SigningStrategy;\n private transactionSponsorshipEnabledValue: boolean;\n private orderNonceValue: number | undefined;\n private readonly wsConfigValue: WsConfig;\n private readonly authStateStore: AuthState;\n readonly orderbookRulesCache: Map<string, Promise<OrderbookRules>>;\n\n /** @deprecated Use primaryConnection — kept for ClientContext compat. */\n get connection(): Connection | undefined {\n return this.primaryConnection;\n }\n\n constructor(params: {\n http: LightconeHttp;\n wsConfig: WsConfig;\n programId?: PublicKey;\n primaryConnection?: Connection;\n backupConnection?: Connection;\n rpcFailoverState?: RpcFailoverState;\n depositSource?: DepositSource;\n signingStrategy?: SigningStrategy;\n transactionSponsorshipEnabled?: boolean;\n orderNonce?: number;\n authCredentials?: AuthCredentials;\n authState?: AuthState;\n orderbookRulesCache?: Map<string, Promise<OrderbookRules>>;\n }) {\n this.http = params.http;\n this.programId = params.programId ?? envProgramId(LightconeEnv.Prod);\n this.primaryConnection = params.primaryConnection;\n this.backupConnection = params.backupConnection;\n this.rpcFailoverState =\n params.rpcFailoverState ?? new RpcFailoverState();\n this.depositSourceValue = params.depositSource ?? DepositSource.Global;\n this.signingStrategyValue = params.signingStrategy;\n this.transactionSponsorshipEnabledValue =\n params.transactionSponsorshipEnabled ?? false;\n this.orderNonceValue = params.orderNonce;\n this.wsConfigValue = params.wsConfig;\n this.authStateStore =\n params.authState ??\n new AuthState(params.authCredentials);\n this.orderbookRulesCache = params.orderbookRulesCache ?? new Map();\n }\n\n // ── Deposit source ──────────────────────────────────────────────────\n\n get depositSource(): DepositSource {\n return this.depositSourceValue;\n }\n\n setDepositSource(source: DepositSource): void {\n this.depositSourceValue = source;\n }\n\n // ── Signing strategy ────────────────────────────────────────────────\n\n get signingStrategy(): SigningStrategy | undefined {\n return this.signingStrategyValue;\n }\n\n /**\n * Cached authenticated identity shared by domain sub-clients.\n *\n * This is distinct from the HTTP cookie token and may be expired; fund-moving\n * operations must re-check its lifetime and wallet before signing.\n */\n get authCredentials(): AuthCredentials | undefined {\n return this.authStateStore.getCredentials();\n }\n\n setSigningStrategy(strategy: SigningStrategy): void {\n this.signingStrategyValue = strategy;\n }\n\n clearSigningStrategy(): void {\n this.signingStrategyValue = undefined;\n }\n\n /** Return the client-wide trusted assertion that an external sponsor pays fees. */\n get transactionSponsorshipEnabled(): boolean {\n return this.transactionSponsorshipEnabledValue;\n }\n\n /** Replace the Transaction Sponsorship Capability for subsequent submissions. */\n setTransactionSponsorshipEnabled(enabled: boolean): void {\n this.transactionSponsorshipEnabledValue = enabled;\n }\n\n // ── Nonce cache ──────────────────────────────────────────────────────\n\n orderNonce(): number | undefined {\n return this.orderNonceValue;\n }\n\n setOrderNonce(nonce: number): void {\n this.orderNonceValue = nonce;\n }\n\n clearOrderNonce(): void {\n this.orderNonceValue = undefined;\n }\n\n // ── Auth token (cookie) ─────────────────────────────────────────────\n\n /**\n * Get the current `lightcone-token` cookie value, if any. Populated by the SDK\n * after a successful login, then attached on every authed request. Useful\n * for forwarding the token through the `*WithCookies` methods, or\n * persisting the session across processes.\n */\n async authToken(): Promise<string | undefined> {\n return this.http.authTokenRef()();\n }\n\n /**\n * Clear the cached `lightcone-token`. Subsequent authed calls will go out\n * without a `Cookie` header (and 401) unless they use a\n * `*WithCookies` variant.\n */\n async clearAuthToken(): Promise<void> {\n await this.http.clearAuthToken();\n }\n\n /**\n * Register the credential restorer consulted when a request fails with\n * HTTP 401: it attempts to restore credentials (e.g. refresh the app's\n * auth session so the auth cookie is valid again); on success the\n * transport replays the request once IF it declared itself retry-safe\n * (RetryPolicy.None mutations are never auto-replayed). See {@link CredentialRestorer}.\n * Without a restorer, 401s propagate to callers unchanged.\n *\n * Common use: set once at app startup, alongside the signing strategy.\n */\n setCredentialRestorer(restorer: CredentialRestorer): void {\n this.http.setCredentialRestorer(restorer);\n }\n\n /** Remove the credential restorer (e.g. in tests); 401s propagate again. */\n clearCredentialRestorer(): void {\n this.http.clearCredentialRestorer();\n }\n\n // ── Transaction signing + submission ────────────────────────────────\n\n async signAndSubmitTx(tx: Transaction): Promise<string> {\n return signAndSubmitTxFn(this, tx);\n }\n\n /**\n * Sign and submit a transaction, then wait until it reaches `confirmed`\n * commitment on-chain. Prefer this over {@link signAndSubmitTx} when a\n * follow-up transaction depends on this one's state.\n */\n async signAndSubmitTxConfirmed(tx: Transaction): Promise<string> {\n return signAndSubmitTxConfirmedFn(this, tx);\n }\n\n /** Sign, submit, confirm, and return the transaction's processing slot. */\n async signAndSubmitTxConfirmedWithSlot(\n tx: Transaction\n ): Promise<ConfirmedTransaction> {\n return signAndSubmitTxConfirmedWithSlotFn(this, tx);\n }\n\n /** Confirm a fee-prepared transaction without replacing its message. */\n async signAndSubmitPreparedTxConfirmedWithSlot(\n tx: Transaction\n ): Promise<ConfirmedTransaction> {\n return signAndSubmitPreparedTxConfirmedWithSlotFn(this, tx);\n }\n\n static builder(): LightconeClientBuilder {\n return new LightconeClientBuilder();\n }\n\n // ── Sub-client accessors ─────────────────────────────────────────────\n\n markets(): Markets {\n return new Markets(this);\n }\n\n orderbooks(): Orderbooks {\n return new Orderbooks(this);\n }\n\n orders(): Orders {\n return new Orders(this);\n }\n\n positions(): Positions {\n return new Positions(this);\n }\n\n trades(): Trades {\n return new Trades(this);\n }\n\n priceHistory(): PriceHistoryClient {\n return new PriceHistoryClient(this);\n }\n\n notifications(): Notifications {\n return new Notifications(this);\n }\n\n /**\n * Metrics sub-client — platform / market / orderbook / category / deposit-token\n * volume metrics, market leaderboard, and time-series history.\n */\n metrics(): Metrics {\n return new Metrics(this);\n }\n\n /**\n * Request testnet SOL and whitelisted deposit tokens for a wallet.\n *\n * Only active on environments whose backend has the faucet enabled (typically\n * local and staging).\n *\n * `POST /api/claim`\n */\n async claim(walletAddress: PubkeyStr): Promise<FaucetResponse> {\n const url = `${this.http.baseUrl()}/api/claim`;\n return this.http.post<FaucetResponse, FaucetRequest>(\n url,\n { wallet_address: walletAddress },\n RetryPolicy.None\n );\n }\n\n auth(): Auth {\n return new Auth({\n http: this.http,\n authState: this.authStateStore,\n });\n }\n\n privy(): Privy {\n return new Privy(this);\n }\n\n referrals(): Referrals {\n return new Referrals(this);\n }\n\n rpc(): Rpc {\n return new Rpc(this);\n }\n\n wsConfig(): WsConfig {\n return this.wsConfigValue;\n }\n\n ws(): WsClient {\n return new WsClient(this.wsConfigValue, this.http.authTokenRef());\n }\n\n /**\n * Return a client whose Transaction Sponsorship Capability starts at this value.\n * Later runtime changes remain local to each clone, matching other mutable settings.\n */\n clone(): LightconeClient {\n return new LightconeClient({\n http: this.http,\n wsConfig: { ...this.wsConfigValue },\n programId: this.programId,\n primaryConnection: this.primaryConnection\n ? new Connection(this.primaryConnection.rpcEndpoint, { commitment: \"confirmed\" })\n : undefined,\n backupConnection: this.backupConnection\n ? new Connection(this.backupConnection.rpcEndpoint, { commitment: \"confirmed\" })\n : undefined,\n rpcFailoverState: this.rpcFailoverState,\n depositSource: this.depositSourceValue,\n signingStrategy: this.signingStrategyValue,\n transactionSponsorshipEnabled: this.transactionSponsorshipEnabledValue,\n orderNonce: this.orderNonceValue,\n authState: this.authStateStore,\n orderbookRulesCache: this.orderbookRulesCache,\n });\n }\n}\n\nexport class LightconeClientBuilder {\n private baseUrlValue: string = apiUrl(LightconeEnv.Prod);\n private wsUrlValue: string = wsUrl(LightconeEnv.Prod);\n private authCredentials?: AuthCredentials;\n private programIdValue: PublicKey = envProgramId(LightconeEnv.Prod);\n private depositSourceValue: DepositSource = DepositSource.Global;\n private signingStrategyValue?: SigningStrategy;\n private transactionSponsorshipEnabledValue = false;\n private primaryRpcUrlValue?: string = rpcUrl(LightconeEnv.Prod);\n private backupRpcUrlValue?: string;\n\n /**\n * Set the deployment environment. Configures the API URL, WebSocket URL,\n * RPC URL, and program ID for the given environment.\n *\n * Individual URL overrides (e.g. `.baseUrl()`) take precedence when\n * called **after** `.env()`.\n */\n env(environment: LightconeEnv): LightconeClientBuilder {\n this.baseUrlValue = apiUrl(environment);\n this.wsUrlValue = wsUrl(environment);\n this.programIdValue = envProgramId(environment);\n this.primaryRpcUrlValue = rpcUrl(environment);\n return this;\n }\n\n baseUrl(url: string): LightconeClientBuilder {\n return this.withBaseUrl(url);\n }\n\n withBaseUrl(url: string): LightconeClientBuilder {\n this.baseUrlValue = url;\n return this;\n }\n\n wsUrl(url: string): LightconeClientBuilder {\n return this.withWsUrl(url);\n }\n\n withWsUrl(url: string): LightconeClientBuilder {\n this.wsUrlValue = url;\n return this;\n }\n\n auth(credentials: AuthCredentials): LightconeClientBuilder {\n return this.withAuth(credentials);\n }\n\n withAuth(credentials: AuthCredentials): LightconeClientBuilder {\n this.authCredentials = credentials;\n return this;\n }\n\n programId(id: PublicKey): LightconeClientBuilder {\n this.programIdValue = id;\n return this;\n }\n\n depositSource(source: DepositSource): LightconeClientBuilder {\n this.depositSourceValue = source;\n return this;\n }\n\n nativeSigner(keypair: Keypair): LightconeClientBuilder {\n this.signingStrategyValue = { type: \"native\", keypair };\n return this;\n }\n\n externalSigner(signer: ExternalSigner): LightconeClientBuilder {\n this.signingStrategyValue = { type: \"walletAdapter\", signer };\n return this;\n }\n\n privyWalletId(\n walletId: string,\n walletAddress?: string\n ): LightconeClientBuilder {\n this.signingStrategyValue = { type: \"privy\", walletId, walletAddress };\n return this;\n }\n\n /** Set the initial trusted Transaction Sponsorship Capability; defaults to false. */\n transactionSponsorship(enabled: boolean): LightconeClientBuilder {\n this.transactionSponsorshipEnabledValue = enabled;\n return this;\n }\n\n rpcUrl(url: string): LightconeClientBuilder {\n this.primaryRpcUrlValue = url;\n return this;\n }\n\n /** Set a backup Solana RPC URL for automatic failover. */\n backupRpcUrl(url: string): LightconeClientBuilder {\n this.backupRpcUrlValue = url;\n return this;\n }\n\n build(): LightconeClient {\n return new LightconeClient({\n http: new LightconeHttp(this.baseUrlValue),\n wsConfig: {\n url: this.wsUrlValue,\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 10_000,\n },\n programId: this.programIdValue,\n depositSource: this.depositSourceValue,\n signingStrategy: this.signingStrategyValue,\n transactionSponsorshipEnabled: this.transactionSponsorshipEnabledValue,\n primaryConnection: this.primaryRpcUrlValue\n ? new Connection(this.primaryRpcUrlValue, { commitment: \"confirmed\" })\n : undefined,\n backupConnection: this.backupRpcUrlValue\n ? new Connection(this.backupRpcUrlValue, { commitment: \"confirmed\" })\n : undefined,\n authCredentials: this.authCredentials,\n });\n }\n}\n"]}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Connection, type PublicKey } from "@solana/web3.js";
|
|
2
2
|
import type { LightconeHttp } from "./http";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { AuthCredentials } from "./auth";
|
|
4
|
+
import type { DepositSource, OrderbookRules } from "./shared";
|
|
5
|
+
import { type SigningStrategy } from "./shared/signing";
|
|
5
6
|
import { type RpcFailoverState } from "./rpcFailover";
|
|
6
7
|
export interface ClientContext {
|
|
7
8
|
readonly http: LightconeHttp;
|
|
@@ -11,8 +12,13 @@ export interface ClientContext {
|
|
|
11
12
|
readonly rpcFailoverState: RpcFailoverState;
|
|
12
13
|
readonly depositSource: DepositSource;
|
|
13
14
|
readonly signingStrategy?: SigningStrategy;
|
|
15
|
+
/** Trusted application assertion that an external sponsor pays fees; omission is false. */
|
|
16
|
+
readonly transactionSponsorshipEnabled?: boolean;
|
|
17
|
+
/** Optional cached identity for auth-bound operations; callers must check expiry. */
|
|
18
|
+
readonly authCredentials?: AuthCredentials;
|
|
14
19
|
orderNonce?(): number | undefined;
|
|
15
20
|
setOrderNonce?(nonce: number): void;
|
|
21
|
+
readonly orderbookRulesCache?: Map<string, Promise<OrderbookRules>>;
|
|
16
22
|
/** @deprecated Use primaryConnection — kept for backward compat in domain sub-clients. */
|
|
17
23
|
readonly connection?: Connection;
|
|
18
24
|
}
|
|
@@ -20,5 +26,55 @@ export declare function requireConnection(ctx: ClientContext): Connection;
|
|
|
20
26
|
export declare function connectionWithFailover<T>(ctx: ClientContext, operation: (conn: Connection) => Promise<T>): Promise<T>;
|
|
21
27
|
export declare function resolveDepositSource(ctx: ClientContext, overrideSource: DepositSource | undefined): DepositSource;
|
|
22
28
|
export declare function requireSigningStrategy(ctx: ClientContext): SigningStrategy;
|
|
29
|
+
/**
|
|
30
|
+
* Sign and submit a transaction using the client's signing strategy.
|
|
31
|
+
*
|
|
32
|
+
* Fetches a recent blockhash automatically. Returns as soon as the RPC
|
|
33
|
+
* accepts the transaction — inclusion is not awaited. When follow-up work
|
|
34
|
+
* depends on this transaction's on-chain effects, use
|
|
35
|
+
* {@link signAndSubmitTxConfirmed} instead.
|
|
36
|
+
* Unsponsored submission checks exact fee funding before signing when both
|
|
37
|
+
* required RPC observations are available.
|
|
38
|
+
*/
|
|
23
39
|
export declare function signAndSubmitTx(ctx: ClientContext, tx: import("@solana/web3.js").Transaction): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Sign and submit a transaction, then wait until it reaches `confirmed`
|
|
42
|
+
* commitment on-chain.
|
|
43
|
+
*
|
|
44
|
+
* Sequential flows should prefer this over {@link signAndSubmitTx}: a
|
|
45
|
+
* transaction that depends on a prior transaction's state is only safe to
|
|
46
|
+
* send once that prior transaction has confirmed. See `Rpc.confirmSignature`
|
|
47
|
+
* for the terminal error taxonomy.
|
|
48
|
+
*
|
|
49
|
+
* Expiry (`"TransactionExpired"`) is only ever reported when the submitted
|
|
50
|
+
* transaction provably still carries the blockhash this function fetched:
|
|
51
|
+
* always true for `native`, verified against the signed bytes for
|
|
52
|
+
* `walletAdapter`, and never assumed for `privy` (the backend signs and
|
|
53
|
+
* submits out of the SDK's sight) — those cases end in
|
|
54
|
+
* `"ConfirmationTimeout"` at the poll cap instead.
|
|
55
|
+
*/
|
|
56
|
+
export declare function signAndSubmitTxConfirmed(ctx: ClientContext, tx: import("@solana/web3.js").Transaction): Promise<string>;
|
|
57
|
+
export interface ConfirmedTransaction {
|
|
58
|
+
signature: string;
|
|
59
|
+
slot: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sign and submit a transaction, wait for confirmed commitment, and return
|
|
63
|
+
* both its signature and processing slot.
|
|
64
|
+
*/
|
|
65
|
+
export declare function signAndSubmitTxConfirmedWithSlot(ctx: ClientContext, tx: import("@solana/web3.js").Transaction): Promise<ConfirmedTransaction>;
|
|
66
|
+
/**
|
|
67
|
+
* Sign, submit once, and confirm a transaction whose message was fee-estimated.
|
|
68
|
+
*
|
|
69
|
+
* This function preserves the prepared blockhash. A wallet adapter may add
|
|
70
|
+
* signatures but may not replace any message field. Signed bytes are sent once to
|
|
71
|
+
* the active RPC because a transport failure may occur after acceptance.
|
|
72
|
+
* The unchanged message receives the same best-effort fee-funding preflight as an
|
|
73
|
+
* ordinary transaction before the signer runs. A sponsored external signer may
|
|
74
|
+
* differ from the declared fee payer. The caller-owned transaction is snapshotted
|
|
75
|
+
* before the first await so later caller mutation cannot change fee authority.
|
|
76
|
+
*/
|
|
77
|
+
export declare function signAndSubmitPreparedTxConfirmedWithSlot(ctx: ClientContext, tx: import("@solana/web3.js").Transaction): Promise<ConfirmedTransaction>;
|
|
78
|
+
/** @internal Submit with a strategy already validated for an identity-bound operation. */
|
|
79
|
+
export declare function signAndSubmitTxConfirmedUsingStrategy(ctx: ClientContext, tx: import("@solana/web3.js").Transaction, strategy: SigningStrategy): Promise<string>;
|
|
24
80
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,K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G;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,OAAO,iBAAiB,EAAE,WAAW,GACxC,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,OAAO,iBAAiB,EAAE,WAAW,GACxC,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,OAAO,iBAAiB,EAAE,WAAW,GACxC,OAAO,CAAC,oBAAoB,CAAC,CAQ/B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,wCAAwC,CAC5D,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,OAAO,iBAAiB,EAAE,WAAW,GACxC,OAAO,CAAC,oBAAoB,CAAC,CAwB/B;AAED,0FAA0F;AAC1F,wBAAsB,qCAAqC,CACzD,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,OAAO,iBAAiB,EAAE,WAAW,EACzC,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC,CASjB"}
|
package/dist/context.js
CHANGED
|
@@ -38,7 +38,13 @@ exports.connectionWithFailover = connectionWithFailover;
|
|
|
38
38
|
exports.resolveDepositSource = resolveDepositSource;
|
|
39
39
|
exports.requireSigningStrategy = requireSigningStrategy;
|
|
40
40
|
exports.signAndSubmitTx = signAndSubmitTx;
|
|
41
|
+
exports.signAndSubmitTxConfirmed = signAndSubmitTxConfirmed;
|
|
42
|
+
exports.signAndSubmitTxConfirmedWithSlot = signAndSubmitTxConfirmedWithSlot;
|
|
43
|
+
exports.signAndSubmitPreparedTxConfirmedWithSlot = signAndSubmitPreparedTxConfirmedWithSlot;
|
|
44
|
+
exports.signAndSubmitTxConfirmedUsingStrategy = signAndSubmitTxConfirmedUsingStrategy;
|
|
45
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
41
46
|
const error_1 = require("./error");
|
|
47
|
+
const signing_1 = require("./shared/signing");
|
|
42
48
|
const rpcFailover_1 = require("./rpcFailover");
|
|
43
49
|
function requireConnection(ctx) {
|
|
44
50
|
ctx.rpcFailoverState.maybeRecoverToPrimary();
|
|
@@ -107,20 +113,226 @@ function requireSigningStrategy(ctx) {
|
|
|
107
113
|
}
|
|
108
114
|
return ctx.signingStrategy;
|
|
109
115
|
}
|
|
116
|
+
/** Capture one signer and sponsorship assertion before transaction work can yield. */
|
|
117
|
+
function requireTransactionSigningContext(ctx) {
|
|
118
|
+
return {
|
|
119
|
+
strategy: requireSigningStrategy(ctx),
|
|
120
|
+
sponsorshipEnabled: ctx.transactionSponsorshipEnabled ?? false,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Reject invalid payer and sponsorship combinations before submission can yield.
|
|
125
|
+
* Unsponsored known signers must control the payer being classified; sponsored
|
|
126
|
+
* external flows may intentionally use a different payer, while native sponsorship
|
|
127
|
+
* is rejected before blockhash RPC or caller-transaction mutation.
|
|
128
|
+
*/
|
|
129
|
+
function validateTransactionFeeFundingContext(tx, strategy, sponsorshipEnabled) {
|
|
130
|
+
if (!tx.feePayer) {
|
|
131
|
+
throw error_1.SdkError.validation("transaction is missing a declared fee payer");
|
|
132
|
+
}
|
|
133
|
+
if (sponsorshipEnabled) {
|
|
134
|
+
if (strategy.type === "native") {
|
|
135
|
+
throw error_1.SdkError.validation("transaction sponsorship is not supported with local-keypair signing");
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const signingAddress = (0, signing_1.signingStrategyWalletAddress)(strategy);
|
|
140
|
+
if (signingAddress && signingAddress !== tx.feePayer.toBase58()) {
|
|
141
|
+
throw error_1.SdkError.validation("signing strategy does not control transaction fee payer");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Own the transaction message before asynchronous submission work begins.
|
|
146
|
+
* A placeholder blockhash exists only long enough to serialize an ordinary
|
|
147
|
+
* transaction that has not received its fresh blockhash yet.
|
|
148
|
+
*/
|
|
149
|
+
function snapshotTransaction(tx) {
|
|
150
|
+
if (tx.recentBlockhash || tx.nonceInfo) {
|
|
151
|
+
return web3_js_1.Transaction.from(tx.serialize({ requireAllSignatures: false, verifySignatures: false }));
|
|
152
|
+
}
|
|
153
|
+
const serializable = new web3_js_1.Transaction({
|
|
154
|
+
feePayer: tx.feePayer,
|
|
155
|
+
blockhash: "11111111111111111111111111111111",
|
|
156
|
+
lastValidBlockHeight: tx.lastValidBlockHeight ?? 0,
|
|
157
|
+
signatures: tx.signatures,
|
|
158
|
+
});
|
|
159
|
+
serializable.instructions = tx.instructions;
|
|
160
|
+
const snapshot = web3_js_1.Transaction.from(serializable.serialize({ requireAllSignatures: false, verifySignatures: false }));
|
|
161
|
+
snapshot.recentBlockhash = undefined;
|
|
162
|
+
snapshot.lastValidBlockHeight = undefined;
|
|
163
|
+
return snapshot;
|
|
164
|
+
}
|
|
165
|
+
/** Publish local signatures only when the caller still holds the submitted message. */
|
|
166
|
+
function copySignaturesIfMessageUnchanged(signed, callerTransaction) {
|
|
167
|
+
try {
|
|
168
|
+
if (!Buffer.from(signed.serializeMessage()).equals(Buffer.from(callerTransaction.serializeMessage()))) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
callerTransaction.signatures = signed.signatures.map(({ publicKey, signature }) => ({
|
|
176
|
+
publicKey,
|
|
177
|
+
signature: signature ? Buffer.from(signature) : null,
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Reject proven fee shortfalls before signing while preserving submission on unknown evidence.
|
|
182
|
+
*
|
|
183
|
+
* The transaction's prepared message supplies the exact fee and declared fee
|
|
184
|
+
* payer. Fee or balance lookup failure is deliberately best-effort; planner-owned
|
|
185
|
+
* SOL admission remains fail-closed before reaching this shared boundary. The
|
|
186
|
+
* signer and sponsorship value were captured together before RPC work.
|
|
187
|
+
*/
|
|
188
|
+
async function preflightTransactionFeeFunding(ctx, tx, strategy, sponsorshipEnabled) {
|
|
189
|
+
validateTransactionFeeFundingContext(tx, strategy, sponsorshipEnabled);
|
|
190
|
+
if (sponsorshipEnabled)
|
|
191
|
+
return;
|
|
192
|
+
const feePayer = tx.feePayer;
|
|
193
|
+
if (!feePayer) {
|
|
194
|
+
throw error_1.SdkError.validation("transaction is missing a declared fee payer");
|
|
195
|
+
}
|
|
196
|
+
const { Rpc } = await Promise.resolve().then(() => __importStar(require("./rpc")));
|
|
197
|
+
const rpc = new Rpc(ctx);
|
|
198
|
+
let requiredLamports;
|
|
199
|
+
try {
|
|
200
|
+
requiredLamports = await rpc.estimatePreparedTransactionFee(tx);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
let availableLamports;
|
|
206
|
+
try {
|
|
207
|
+
availableLamports = await rpc.balanceLamports(feePayer);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (availableLamports < requiredLamports) {
|
|
213
|
+
throw error_1.SdkError.insufficientSolForTransactionFees(availableLamports, requiredLamports);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Sign and submit a transaction using the client's signing strategy.
|
|
218
|
+
*
|
|
219
|
+
* Fetches a recent blockhash automatically. Returns as soon as the RPC
|
|
220
|
+
* accepts the transaction — inclusion is not awaited. When follow-up work
|
|
221
|
+
* depends on this transaction's on-chain effects, use
|
|
222
|
+
* {@link signAndSubmitTxConfirmed} instead.
|
|
223
|
+
* Unsponsored submission checks exact fee funding before signing when both
|
|
224
|
+
* required RPC observations are available.
|
|
225
|
+
*/
|
|
110
226
|
async function signAndSubmitTx(ctx, tx) {
|
|
227
|
+
const { strategy, sponsorshipEnabled } = requireTransactionSigningContext(ctx);
|
|
228
|
+
const { signature } = await signAndSubmitTxInner(ctx, tx, strategy, sponsorshipEnabled);
|
|
229
|
+
return signature;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Sign and submit a transaction, then wait until it reaches `confirmed`
|
|
233
|
+
* commitment on-chain.
|
|
234
|
+
*
|
|
235
|
+
* Sequential flows should prefer this over {@link signAndSubmitTx}: a
|
|
236
|
+
* transaction that depends on a prior transaction's state is only safe to
|
|
237
|
+
* send once that prior transaction has confirmed. See `Rpc.confirmSignature`
|
|
238
|
+
* for the terminal error taxonomy.
|
|
239
|
+
*
|
|
240
|
+
* Expiry (`"TransactionExpired"`) is only ever reported when the submitted
|
|
241
|
+
* transaction provably still carries the blockhash this function fetched:
|
|
242
|
+
* always true for `native`, verified against the signed bytes for
|
|
243
|
+
* `walletAdapter`, and never assumed for `privy` (the backend signs and
|
|
244
|
+
* submits out of the SDK's sight) — those cases end in
|
|
245
|
+
* `"ConfirmationTimeout"` at the poll cap instead.
|
|
246
|
+
*/
|
|
247
|
+
async function signAndSubmitTxConfirmed(ctx, tx) {
|
|
248
|
+
const confirmed = await signAndSubmitTxConfirmedWithSlot(ctx, tx);
|
|
249
|
+
return confirmed.signature;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Sign and submit a transaction, wait for confirmed commitment, and return
|
|
253
|
+
* both its signature and processing slot.
|
|
254
|
+
*/
|
|
255
|
+
async function signAndSubmitTxConfirmedWithSlot(ctx, tx) {
|
|
256
|
+
const { strategy, sponsorshipEnabled } = requireTransactionSigningContext(ctx);
|
|
257
|
+
return signAndSubmitTxConfirmedWithSlotUsingStrategy(ctx, tx, strategy, sponsorshipEnabled);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Sign, submit once, and confirm a transaction whose message was fee-estimated.
|
|
261
|
+
*
|
|
262
|
+
* This function preserves the prepared blockhash. A wallet adapter may add
|
|
263
|
+
* signatures but may not replace any message field. Signed bytes are sent once to
|
|
264
|
+
* the active RPC because a transport failure may occur after acceptance.
|
|
265
|
+
* The unchanged message receives the same best-effort fee-funding preflight as an
|
|
266
|
+
* ordinary transaction before the signer runs. A sponsored external signer may
|
|
267
|
+
* differ from the declared fee payer. The caller-owned transaction is snapshotted
|
|
268
|
+
* before the first await so later caller mutation cannot change fee authority.
|
|
269
|
+
*/
|
|
270
|
+
async function signAndSubmitPreparedTxConfirmedWithSlot(ctx, tx) {
|
|
271
|
+
if (!tx.recentBlockhash) {
|
|
272
|
+
throw error_1.SdkError.validation("prepared transaction is missing a recent blockhash");
|
|
273
|
+
}
|
|
274
|
+
const { strategy, sponsorshipEnabled } = requireTransactionSigningContext(ctx);
|
|
275
|
+
if (!tx.feePayer) {
|
|
276
|
+
throw error_1.SdkError.validation("prepared transaction is missing a fee payer");
|
|
277
|
+
}
|
|
278
|
+
validateTransactionFeeFundingContext(tx, strategy, sponsorshipEnabled);
|
|
279
|
+
if (!sponsorshipEnabled && !(0, signing_1.signingStrategyWalletAddress)(strategy)) {
|
|
280
|
+
throw error_1.SdkError.validation("signing strategy wallet identity is required");
|
|
281
|
+
}
|
|
282
|
+
const callerTransaction = tx;
|
|
283
|
+
tx = snapshotTransaction(tx);
|
|
284
|
+
await preflightTransactionFeeFunding(ctx, tx, strategy, sponsorshipEnabled);
|
|
285
|
+
const signature = await signAndSubmitPreparedTxInner(ctx, tx, strategy, callerTransaction);
|
|
286
|
+
const { Rpc } = await Promise.resolve().then(() => __importStar(require("./rpc")));
|
|
287
|
+
const status = await new Rpc(ctx).confirmSignatureStatus(signature, null);
|
|
288
|
+
return { signature, slot: status.slot };
|
|
289
|
+
}
|
|
290
|
+
/** @internal Submit with a strategy already validated for an identity-bound operation. */
|
|
291
|
+
async function signAndSubmitTxConfirmedUsingStrategy(ctx, tx, strategy) {
|
|
292
|
+
const sponsorshipEnabled = ctx.transactionSponsorshipEnabled ?? false;
|
|
293
|
+
const confirmed = await signAndSubmitTxConfirmedWithSlotUsingStrategy(ctx, tx, strategy, sponsorshipEnabled);
|
|
294
|
+
return confirmed.signature;
|
|
295
|
+
}
|
|
296
|
+
async function signAndSubmitTxConfirmedWithSlotUsingStrategy(ctx, tx, strategy, sponsorshipEnabled) {
|
|
297
|
+
const { signature, lastValidBlockHeight } = await signAndSubmitTxInner(ctx, tx, strategy, sponsorshipEnabled);
|
|
298
|
+
const { Rpc } = await Promise.resolve().then(() => __importStar(require("./rpc")));
|
|
299
|
+
const status = await new Rpc(ctx).confirmSignatureStatus(signature, lastValidBlockHeight);
|
|
300
|
+
return { signature, slot: status.slot };
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Prepare funding evidence, sign, send, and return the signature and expiry bound.
|
|
304
|
+
*
|
|
305
|
+
* The fresh blockhash feeds best-effort fee preflight before any signer runs.
|
|
306
|
+
* Submission operates on a pre-await snapshot. The fresh blockhash is copied to
|
|
307
|
+
* the caller transaction; local signatures follow only if its message still matches.
|
|
308
|
+
* `lastValidBlockHeight` is `null` when the submitted wire bytes cannot be proven
|
|
309
|
+
* to retain that blockhash because an external signer replaced it or the final
|
|
310
|
+
* bytes were never visible to the SDK.
|
|
311
|
+
*/
|
|
312
|
+
async function signAndSubmitTxInner(ctx, tx, strategy, sponsorshipEnabled) {
|
|
313
|
+
validateTransactionFeeFundingContext(tx, strategy, sponsorshipEnabled);
|
|
314
|
+
const callerTransaction = tx;
|
|
315
|
+
tx = snapshotTransaction(tx);
|
|
111
316
|
const { isUserCancellation } = await Promise.resolve().then(() => __importStar(require("./shared/signing")));
|
|
112
317
|
const { SdkError } = await Promise.resolve().then(() => __importStar(require("./error")));
|
|
113
318
|
const { RetryPolicy } = await Promise.resolve().then(() => __importStar(require("./http")));
|
|
114
|
-
|
|
115
|
-
//
|
|
116
|
-
const { blockhash } = await connectionWithFailover(ctx, (conn) => conn.getLatestBlockhash());
|
|
319
|
+
// Get blockhash with failover, at `confirmed` commitment (pinned, not the
|
|
320
|
+
// Connection's default — matching the Rust and Python SDKs).
|
|
321
|
+
const { blockhash, lastValidBlockHeight } = await connectionWithFailover(ctx, (conn) => conn.getLatestBlockhash("confirmed"));
|
|
117
322
|
tx.recentBlockhash = blockhash;
|
|
323
|
+
tx.lastValidBlockHeight = lastValidBlockHeight;
|
|
324
|
+
callerTransaction.recentBlockhash = blockhash;
|
|
325
|
+
callerTransaction.lastValidBlockHeight = lastValidBlockHeight;
|
|
326
|
+
await preflightTransactionFeeFunding(ctx, tx, strategy, sponsorshipEnabled);
|
|
118
327
|
switch (strategy.type) {
|
|
119
328
|
case "native": {
|
|
120
329
|
tx.partialSign(strategy.keypair);
|
|
121
|
-
|
|
330
|
+
copySignaturesIfMessageUnchanged(tx, callerTransaction);
|
|
331
|
+
const signature = await connectionWithFailover(ctx, (conn) => conn.sendRawTransaction(tx.serialize()));
|
|
332
|
+
return { signature, lastValidBlockHeight };
|
|
122
333
|
}
|
|
123
334
|
case "walletAdapter": {
|
|
335
|
+
const expectedMessage = tx.serializeMessage();
|
|
124
336
|
const txBytes = tx.serialize({ requireAllSignatures: false });
|
|
125
337
|
const signedBytes = await strategy.signer
|
|
126
338
|
.signTransaction(txBytes)
|
|
@@ -130,15 +342,100 @@ async function signAndSubmitTx(ctx, tx) {
|
|
|
130
342
|
throw SdkError.userCancelled();
|
|
131
343
|
throw SdkError.signing(msg);
|
|
132
344
|
});
|
|
133
|
-
|
|
345
|
+
const signedBlockhashIsUnchanged = await validateOrdinarySignedTransaction(signedBytes, expectedMessage, blockhash);
|
|
346
|
+
const signature = await connectionWithFailover(ctx, (conn) => conn.sendRawTransaction(signedBytes));
|
|
347
|
+
return {
|
|
348
|
+
signature,
|
|
349
|
+
lastValidBlockHeight: signedBlockhashIsUnchanged
|
|
350
|
+
? lastValidBlockHeight
|
|
351
|
+
: null,
|
|
352
|
+
};
|
|
134
353
|
}
|
|
135
354
|
case "privy": {
|
|
136
355
|
const txBytes = tx.serialize({ requireAllSignatures: false });
|
|
137
356
|
const base64Tx = Buffer.from(txBytes).toString("base64");
|
|
138
357
|
const url = `${ctx.http.baseUrl()}/api/privy/sign_and_send_tx`;
|
|
139
358
|
const result = await ctx.http.post(url, { wallet_id: strategy.walletId, base64_tx: base64Tx }, RetryPolicy.None);
|
|
140
|
-
|
|
359
|
+
// The backend signs and submits server-side; the SDK never sees the
|
|
360
|
+
// final wire bytes, so the blockhash it set cannot be trusted for
|
|
361
|
+
// expiry detection.
|
|
362
|
+
return { signature: result.hash, lastValidBlockHeight: null };
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Sign and submit once without replacing the planner's prepared blockhash.
|
|
368
|
+
*
|
|
369
|
+
* Native signing preserves the message by construction. Wallet-adapter bytes are
|
|
370
|
+
* compared with the prepared message before submission. Privy is excluded because
|
|
371
|
+
* this SDK cannot inspect its final wire message. The native signature is published
|
|
372
|
+
* to an unchanged caller message before the one-shot send so an uncertain outcome
|
|
373
|
+
* remains reconcilable. Both admitted strategies use the active connection directly.
|
|
374
|
+
*/
|
|
375
|
+
async function signAndSubmitPreparedTxInner(ctx, tx, strategy, callerTransaction) {
|
|
376
|
+
const { isUserCancellation } = await Promise.resolve().then(() => __importStar(require("./shared/signing")));
|
|
377
|
+
switch (strategy.type) {
|
|
378
|
+
case "native":
|
|
379
|
+
tx.partialSign(strategy.keypair);
|
|
380
|
+
copySignaturesIfMessageUnchanged(tx, callerTransaction);
|
|
381
|
+
return requireConnection(ctx).sendRawTransaction(tx.serialize());
|
|
382
|
+
case "walletAdapter": {
|
|
383
|
+
const expectedMessage = tx.serializeMessage();
|
|
384
|
+
const txBytes = tx.serialize({ requireAllSignatures: false });
|
|
385
|
+
const signedBytes = await strategy.signer
|
|
386
|
+
.signTransaction(txBytes)
|
|
387
|
+
.catch((error) => {
|
|
388
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
389
|
+
if (isUserCancellation(message))
|
|
390
|
+
throw error_1.SdkError.userCancelled();
|
|
391
|
+
throw error_1.SdkError.signing(message);
|
|
392
|
+
});
|
|
393
|
+
await assertPreparedSignedMessage(signedBytes, expectedMessage);
|
|
394
|
+
return requireConnection(ctx).sendRawTransaction(signedBytes);
|
|
141
395
|
}
|
|
396
|
+
case "privy":
|
|
397
|
+
throw error_1.SdkError.validation("prepared transaction submission cannot verify a Privy-signed message");
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Enforce the fee-preflight authority boundary after wallet-adapter signing.
|
|
402
|
+
* Signatures may change, but any account, instruction, fee payer, or blockhash
|
|
403
|
+
* change rejects the bytes before they reach RPC.
|
|
404
|
+
*/
|
|
405
|
+
async function assertPreparedSignedMessage(signedBytes, expectedMessage) {
|
|
406
|
+
const { Transaction } = await Promise.resolve().then(() => __importStar(require("@solana/web3.js")));
|
|
407
|
+
let signedMessage;
|
|
408
|
+
try {
|
|
409
|
+
signedMessage = Transaction.from(signedBytes).serializeMessage();
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
throw error_1.SdkError.signing(`signed transaction is invalid: ${error instanceof Error ? error.message : String(error)}`);
|
|
413
|
+
}
|
|
414
|
+
if (!Buffer.from(signedMessage).equals(Buffer.from(expectedMessage))) {
|
|
415
|
+
throw error_1.SdkError.validation("wallet changed the fee-prepared transaction message");
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Allow an external signer to replace only the ordinary transaction blockhash.
|
|
420
|
+
*
|
|
421
|
+
* Fee payer, accounts, and instructions are the authority used by fee preflight
|
|
422
|
+
* and must survive signing. A replacement blockhash remains allowed, but its
|
|
423
|
+
* original expiry bound is discarded.
|
|
424
|
+
*/
|
|
425
|
+
async function validateOrdinarySignedTransaction(signedBytes, expectedMessage, expectedBlockhash) {
|
|
426
|
+
const { Transaction } = await Promise.resolve().then(() => __importStar(require("@solana/web3.js")));
|
|
427
|
+
let signed;
|
|
428
|
+
try {
|
|
429
|
+
signed = Transaction.from(signedBytes);
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
throw error_1.SdkError.signing(`signed transaction is invalid: ${error instanceof Error ? error.message : String(error)}`);
|
|
433
|
+
}
|
|
434
|
+
const blockhashUnchanged = signed.recentBlockhash === expectedBlockhash;
|
|
435
|
+
signed.recentBlockhash = expectedBlockhash;
|
|
436
|
+
if (!Buffer.from(signed.serializeMessage()).equals(Buffer.from(expectedMessage))) {
|
|
437
|
+
throw error_1.SdkError.validation("wallet changed the transaction message beyond recent blockhash");
|
|
142
438
|
}
|
|
439
|
+
return blockhashUnchanged;
|
|
143
440
|
}
|
|
144
441
|
//# sourceMappingURL=context.js.map
|