@layr-labs/ecloud-sdk 0.2.2-dev → 0.3.0-dev

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.
@@ -1,4 +1,4 @@
1
- import { a6 as EnvironmentConfig, ag as SubscriptionStatus, a5 as BillingEnvironmentConfig, ae as ProductID, ai as CreateSubscriptionOptions, aj as CreateSubscriptionResponse, ar as ProductSubscriptionResponse, G as GasEstimate, ab as Logger } from './index-DeQzn_yM.cjs';
1
+ import { a6 as EnvironmentConfig, ag as SubscriptionStatus, a5 as BillingEnvironmentConfig, ae as ProductID, ai as CreateSubscriptionOptions, aj as CreateSubscriptionResponse, ar as ProductSubscriptionResponse, G as GasEstimate, ab as Logger } from './index-C0w92tCs.js';
2
2
  import { Address, Hex, WalletClient, PublicClient, Chain } from 'viem';
3
3
 
4
4
  /**
@@ -538,32 +538,273 @@ declare class UserApiClient {
538
538
  getSiweSession(): Promise<SessionInfo>;
539
539
  }
540
540
 
541
+ /**
542
+ * Billing API Session Management
543
+ *
544
+ * This module provides utilities for managing authentication sessions with the billing API
545
+ * using SIWE (Sign-In with Ethereum).
546
+ *
547
+ * The billing API now supports the same SIWE-based session authentication as the compute API,
548
+ * allowing users to sign once and authenticate to both APIs simultaneously.
549
+ */
550
+
551
+ interface BillingApiConfig {
552
+ /** Base URL of the billing API (e.g., "https://billing.eigencloud.xyz") */
553
+ baseUrl: string;
554
+ }
555
+ interface BillingSessionInfo {
556
+ /** Whether the session is authenticated */
557
+ authenticated: boolean;
558
+ /** Authenticated wallet address (if authenticated) */
559
+ address?: Address;
560
+ /** Chain ID used for authentication (if authenticated) */
561
+ chainId?: number;
562
+ /** Unix timestamp when authentication occurred (if authenticated) */
563
+ authenticatedAt?: number;
564
+ }
565
+ interface BillingLoginResult {
566
+ /** Whether login was successful */
567
+ success: boolean;
568
+ /** Authenticated wallet address */
569
+ address: Address;
570
+ }
571
+ interface BillingLoginRequest {
572
+ /** SIWE message string */
573
+ message: string;
574
+ /** Hex-encoded signature (with or without 0x prefix) */
575
+ signature: Hex | string;
576
+ }
577
+ /**
578
+ * Error thrown when billing session operations fail
579
+ */
580
+ declare class BillingSessionError extends Error {
581
+ readonly code: "NETWORK_ERROR" | "INVALID_SIGNATURE" | "INVALID_MESSAGE" | "SESSION_EXPIRED" | "UNAUTHORIZED" | "UNKNOWN";
582
+ readonly statusCode?: number | undefined;
583
+ constructor(message: string, code: "NETWORK_ERROR" | "INVALID_SIGNATURE" | "INVALID_MESSAGE" | "SESSION_EXPIRED" | "UNAUTHORIZED" | "UNKNOWN", statusCode?: number | undefined);
584
+ }
585
+ /**
586
+ * Login to the billing API using SIWE
587
+ *
588
+ * This establishes a session with the billing API by verifying the SIWE message
589
+ * and signature. On success, a session cookie is set in the browser.
590
+ *
591
+ * The billing API accepts the same SIWE message format as the compute API,
592
+ * so users only need to sign once and can send the same message/signature
593
+ * to both APIs.
594
+ *
595
+ * @param config - Billing API configuration
596
+ * @param request - Login request containing SIWE message and signature
597
+ * @returns Login result with the authenticated address
598
+ *
599
+ * @example
600
+ * ```typescript
601
+ * import { createSiweMessage, loginToBillingApi } from "@layr-labs/ecloud-sdk/browser";
602
+ *
603
+ * const { message } = createSiweMessage({
604
+ * address: userAddress,
605
+ * chainId: 11155111,
606
+ * domain: window.location.host,
607
+ * uri: window.location.origin,
608
+ * });
609
+ *
610
+ * const signature = await signMessageAsync({ message });
611
+ *
612
+ * // Can send to both APIs with the same message/signature
613
+ * const [computeResult, billingResult] = await Promise.all([
614
+ * loginToComputeApi({ baseUrl: computeApiUrl }, { message, signature }),
615
+ * loginToBillingApi({ baseUrl: billingApiUrl }, { message, signature }),
616
+ * ]);
617
+ * ```
618
+ */
619
+ declare function loginToBillingApi(config: BillingApiConfig, request: BillingLoginRequest): Promise<BillingLoginResult>;
620
+ /**
621
+ * Get the current session status from the billing API
622
+ *
623
+ * @param config - Billing API configuration
624
+ * @returns Session information including authentication status and address
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * const session = await getBillingApiSession({ baseUrl: "https://billing.eigencloud.xyz" });
629
+ * if (session.authenticated) {
630
+ * console.log(`Logged in as ${session.address}`);
631
+ * }
632
+ * ```
633
+ */
634
+ declare function getBillingApiSession(config: BillingApiConfig): Promise<BillingSessionInfo>;
635
+ /**
636
+ * Logout from the billing API
637
+ *
638
+ * This destroys the current session and clears the session cookie.
639
+ *
640
+ * @param config - Billing API configuration
641
+ *
642
+ * @example
643
+ * ```typescript
644
+ * await logoutFromBillingApi({ baseUrl: "https://billing.eigencloud.xyz" });
645
+ * ```
646
+ */
647
+ declare function logoutFromBillingApi(config: BillingApiConfig): Promise<void>;
648
+ /**
649
+ * Check if a billing session is still valid (not expired)
650
+ *
651
+ * This is a convenience function that checks the session status
652
+ * and returns a boolean.
653
+ *
654
+ * @param config - Billing API configuration
655
+ * @returns True if session is authenticated, false otherwise
656
+ */
657
+ declare function isBillingSessionValid(config: BillingApiConfig): Promise<boolean>;
658
+ /**
659
+ * Login to both compute and billing APIs simultaneously
660
+ *
661
+ * This is a convenience function that sends the same SIWE message and signature
662
+ * to both APIs in parallel, establishing sessions with both services at once.
663
+ *
664
+ * @param computeConfig - Compute API configuration
665
+ * @param billingConfig - Billing API configuration
666
+ * @param request - Login request containing SIWE message and signature
667
+ * @returns Object containing login results for both APIs
668
+ *
669
+ * @example
670
+ * ```typescript
671
+ * import { createSiweMessage, loginToBothApis } from "@layr-labs/ecloud-sdk/browser";
672
+ *
673
+ * const { message } = createSiweMessage({
674
+ * address: userAddress,
675
+ * chainId: 11155111,
676
+ * domain: window.location.host,
677
+ * uri: window.location.origin,
678
+ * });
679
+ *
680
+ * const signature = await signMessageAsync({ message });
681
+ * const { compute, billing } = await loginToBothApis(
682
+ * { baseUrl: computeApiUrl },
683
+ * { baseUrl: billingApiUrl },
684
+ * { message, signature }
685
+ * );
686
+ * ```
687
+ */
688
+ declare function loginToBothApis(computeConfig: {
689
+ baseUrl: string;
690
+ }, billingConfig: BillingApiConfig, request: BillingLoginRequest): Promise<{
691
+ compute: BillingLoginResult;
692
+ billing: BillingLoginResult;
693
+ }>;
694
+ /**
695
+ * Logout from both compute and billing APIs simultaneously
696
+ *
697
+ * @param computeConfig - Compute API configuration
698
+ * @param billingConfig - Billing API configuration
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * await logoutFromBothApis(
703
+ * { baseUrl: computeApiUrl },
704
+ * { baseUrl: billingApiUrl }
705
+ * );
706
+ * ```
707
+ */
708
+ declare function logoutFromBothApis(computeConfig: {
709
+ baseUrl: string;
710
+ }, billingConfig: BillingApiConfig): Promise<void>;
711
+
541
712
  /**
542
713
  * BillingAPI Client to manage product subscriptions
543
714
  * Standalone client - does not depend on chain infrastructure
544
715
  *
545
716
  * Accepts viem's WalletClient which abstracts over both local accounts
546
717
  * (privateKeyToAccount) and external signers (MetaMask, etc.).
718
+ *
719
+ * Supports two authentication modes:
720
+ * 1. EIP-712 signature auth (default) - signs each request with typed data
721
+ * 2. Session auth (optional) - uses SIWE session cookies
547
722
  */
548
723
 
724
+ interface BillingApiClientOptions {
725
+ /**
726
+ * Use session-based authentication instead of per-request signatures.
727
+ * When true, the client will rely on session cookies set by SIWE login.
728
+ * When false (default), uses EIP-712 typed data signatures for each request.
729
+ */
730
+ useSession?: boolean;
731
+ }
549
732
  /**
550
733
  * BillingAPI Client for managing product subscriptions.
551
734
  */
552
735
  declare class BillingApiClient {
553
736
  private readonly config;
554
737
  private readonly walletClient;
555
- constructor(config: BillingEnvironmentConfig, walletClient: WalletClient);
738
+ private readonly options;
739
+ private readonly useSession;
740
+ constructor(config: BillingEnvironmentConfig, walletClient: WalletClient | null, options?: BillingApiClientOptions);
556
741
  /**
557
742
  * Get the address of the connected wallet
743
+ * Returns undefined if using session auth without a wallet client
558
744
  */
559
- get address(): Address;
745
+ get address(): Address | undefined;
746
+ /**
747
+ * Get the base URL of the billing API
748
+ */
749
+ get baseUrl(): string;
750
+ /**
751
+ * Login to the billing API using SIWE
752
+ *
753
+ * This establishes a session with the billing API by verifying the SIWE message
754
+ * and signature. On success, a session cookie is set in the browser.
755
+ *
756
+ * @param request - Login request containing SIWE message and signature
757
+ * @returns Login result with the authenticated address
758
+ *
759
+ * @example
760
+ * ```typescript
761
+ * const { message } = createSiweMessage({
762
+ * address: userAddress,
763
+ * chainId: 11155111,
764
+ * domain: window.location.host,
765
+ * uri: window.location.origin,
766
+ * });
767
+ *
768
+ * const signature = await signMessageAsync({ message });
769
+ * const result = await billingClient.siweLogin({ message, signature });
770
+ * ```
771
+ */
772
+ siweLogin(request: BillingLoginRequest): Promise<BillingLoginResult>;
773
+ /**
774
+ * Logout from the billing API
775
+ *
776
+ * This destroys the current session and clears the session cookie.
777
+ */
778
+ siweLogout(): Promise<void>;
779
+ /**
780
+ * Get the current session status from the billing API
781
+ *
782
+ * @returns Session information including authentication status and address
783
+ */
784
+ getSession(): Promise<BillingSessionInfo>;
785
+ /**
786
+ * Check if there is a valid session
787
+ *
788
+ * @returns True if session is authenticated, false otherwise
789
+ */
790
+ isSessionValid(): Promise<boolean>;
560
791
  createSubscription(productId?: ProductID, options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
561
792
  getSubscription(productId?: ProductID): Promise<ProductSubscriptionResponse>;
562
793
  cancelSubscription(productId?: ProductID): Promise<void>;
563
794
  /**
564
795
  * Make an authenticated request to the billing API
796
+ *
797
+ * Uses session auth if useSession is true, otherwise uses EIP-712 signature auth.
565
798
  */
566
799
  private makeAuthenticatedRequest;
800
+ /**
801
+ * Make a request using session-based authentication (cookies)
802
+ */
803
+ private makeSessionAuthenticatedRequest;
804
+ /**
805
+ * Make a request using EIP-712 signature authentication
806
+ */
807
+ private makeSignatureAuthenticatedRequest;
567
808
  }
568
809
 
569
810
  /**
@@ -739,4 +980,4 @@ declare function addHexPrefix(value: string): Hex;
739
980
  */
740
981
  declare function stripHexPrefix(value: string): string;
741
982
 
742
- export { logoutFromComputeApi as $, type LogsParams as A, isSubscriptionActive as B, type ComputeApiConfig as C, generateNewPrivateKey as D, type UserApiClientOptions as E, type AppInfo as F, type GeneratedKey as G, type AppProfileInfo as H, type AppMetrics as I, type AppInfoResponse as J, BillingApiClient as K, type LogVisibility as L, estimateBatchGas as M, executeBatch as N, checkERC7702Delegation as O, type EstimateBatchGasOptions as P, type ExecuteBatchOptions as Q, type Execution as R, type SessionInfo as S, createSiweMessage as T, UserApiClient as U, parseSiweMessage as V, generateNonce as W, isSiweMessageExpired as X, isSiweMessageNotYetValid as Y, type SiweMessageResult as Z, loginToComputeApi as _, SessionError as a, getComputeApiSession as a0, isSessionValid as a1, type LoginResult as a2, type LoginRequest as a3, getChainFromID as a4, addHexPrefix as a5, stripHexPrefix as a6, type ResourceUsageMonitoring as a7, createClients as a8, type AppRelease as a9, type AppReleaseBuild as aa, type AppResponse as ab, validateFilePath as ac, assertValidFilePath as ad, validateImagePath as ae, validateResourceUsageMonitoring as af, type DeployParams as ag, validateDeployParams as ah, type UpgradeParams as ai, validateUpgradeParams as aj, type SiweMessageParams as b, getBillingEnvironmentConfig as c, getAvailableEnvironments as d, getBuildType as e, isMainnet as f, getEnvironmentConfig as g, validateImageReference as h, isEnvironmentAvailable as i, assertValidImageReference as j, extractAppNameFromImage as k, validateInstanceTypeSKU as l, validatePrivateKeyFormat as m, assertValidPrivateKey as n, validateURL as o, validateXURL as p, validateDescription as q, validateAppID as r, validateLogVisibility as s, sanitizeString as t, sanitizeURL as u, validateAppName as v, sanitizeXURL as w, validateCreateAppParams as x, validateLogsParams as y, type CreateAppParams as z };
983
+ export { loginToComputeApi as $, type LogsParams as A, isSubscriptionActive as B, type ComputeApiConfig as C, generateNewPrivateKey as D, type UserApiClientOptions as E, type AppInfo as F, type GeneratedKey as G, type AppProfileInfo as H, type AppMetrics as I, type AppInfoResponse as J, BillingApiClient as K, type LogVisibility as L, type BillingApiClientOptions as M, estimateBatchGas as N, executeBatch as O, checkERC7702Delegation as P, type EstimateBatchGasOptions as Q, type ExecuteBatchOptions as R, type SessionInfo as S, type Execution as T, UserApiClient as U, createSiweMessage as V, parseSiweMessage as W, generateNonce as X, isSiweMessageExpired as Y, isSiweMessageNotYetValid as Z, type SiweMessageResult as _, SessionError as a, logoutFromComputeApi as a0, getComputeApiSession as a1, isSessionValid as a2, type LoginResult as a3, type LoginRequest as a4, loginToBillingApi as a5, logoutFromBillingApi as a6, getBillingApiSession as a7, isBillingSessionValid as a8, loginToBothApis as a9, logoutFromBothApis as aa, BillingSessionError as ab, type BillingApiConfig as ac, type BillingSessionInfo as ad, type BillingLoginResult as ae, type BillingLoginRequest as af, getChainFromID as ag, addHexPrefix as ah, stripHexPrefix as ai, type ResourceUsageMonitoring as aj, createClients as ak, type AppRelease as al, type AppReleaseBuild as am, type AppResponse as an, validateFilePath as ao, assertValidFilePath as ap, validateImagePath as aq, validateResourceUsageMonitoring as ar, type DeployParams as as, validateDeployParams as at, type UpgradeParams as au, validateUpgradeParams as av, type SiweMessageParams as b, getBillingEnvironmentConfig as c, getAvailableEnvironments as d, getBuildType as e, isMainnet as f, getEnvironmentConfig as g, validateImageReference as h, isEnvironmentAvailable as i, assertValidImageReference as j, extractAppNameFromImage as k, validateInstanceTypeSKU as l, validatePrivateKeyFormat as m, assertValidPrivateKey as n, validateURL as o, validateXURL as p, validateDescription as q, validateAppID as r, validateLogVisibility as s, sanitizeString as t, sanitizeURL as u, validateAppName as v, sanitizeXURL as w, validateCreateAppParams as x, validateLogsParams as y, type CreateAppParams as z };
@@ -1,4 +1,4 @@
1
- import { a6 as EnvironmentConfig, ag as SubscriptionStatus, a5 as BillingEnvironmentConfig, ae as ProductID, ai as CreateSubscriptionOptions, aj as CreateSubscriptionResponse, ar as ProductSubscriptionResponse, G as GasEstimate, ab as Logger } from './index-DeQzn_yM.js';
1
+ import { a6 as EnvironmentConfig, ag as SubscriptionStatus, a5 as BillingEnvironmentConfig, ae as ProductID, ai as CreateSubscriptionOptions, aj as CreateSubscriptionResponse, ar as ProductSubscriptionResponse, G as GasEstimate, ab as Logger } from './index-C0w92tCs.cjs';
2
2
  import { Address, Hex, WalletClient, PublicClient, Chain } from 'viem';
3
3
 
4
4
  /**
@@ -538,32 +538,273 @@ declare class UserApiClient {
538
538
  getSiweSession(): Promise<SessionInfo>;
539
539
  }
540
540
 
541
+ /**
542
+ * Billing API Session Management
543
+ *
544
+ * This module provides utilities for managing authentication sessions with the billing API
545
+ * using SIWE (Sign-In with Ethereum).
546
+ *
547
+ * The billing API now supports the same SIWE-based session authentication as the compute API,
548
+ * allowing users to sign once and authenticate to both APIs simultaneously.
549
+ */
550
+
551
+ interface BillingApiConfig {
552
+ /** Base URL of the billing API (e.g., "https://billing.eigencloud.xyz") */
553
+ baseUrl: string;
554
+ }
555
+ interface BillingSessionInfo {
556
+ /** Whether the session is authenticated */
557
+ authenticated: boolean;
558
+ /** Authenticated wallet address (if authenticated) */
559
+ address?: Address;
560
+ /** Chain ID used for authentication (if authenticated) */
561
+ chainId?: number;
562
+ /** Unix timestamp when authentication occurred (if authenticated) */
563
+ authenticatedAt?: number;
564
+ }
565
+ interface BillingLoginResult {
566
+ /** Whether login was successful */
567
+ success: boolean;
568
+ /** Authenticated wallet address */
569
+ address: Address;
570
+ }
571
+ interface BillingLoginRequest {
572
+ /** SIWE message string */
573
+ message: string;
574
+ /** Hex-encoded signature (with or without 0x prefix) */
575
+ signature: Hex | string;
576
+ }
577
+ /**
578
+ * Error thrown when billing session operations fail
579
+ */
580
+ declare class BillingSessionError extends Error {
581
+ readonly code: "NETWORK_ERROR" | "INVALID_SIGNATURE" | "INVALID_MESSAGE" | "SESSION_EXPIRED" | "UNAUTHORIZED" | "UNKNOWN";
582
+ readonly statusCode?: number | undefined;
583
+ constructor(message: string, code: "NETWORK_ERROR" | "INVALID_SIGNATURE" | "INVALID_MESSAGE" | "SESSION_EXPIRED" | "UNAUTHORIZED" | "UNKNOWN", statusCode?: number | undefined);
584
+ }
585
+ /**
586
+ * Login to the billing API using SIWE
587
+ *
588
+ * This establishes a session with the billing API by verifying the SIWE message
589
+ * and signature. On success, a session cookie is set in the browser.
590
+ *
591
+ * The billing API accepts the same SIWE message format as the compute API,
592
+ * so users only need to sign once and can send the same message/signature
593
+ * to both APIs.
594
+ *
595
+ * @param config - Billing API configuration
596
+ * @param request - Login request containing SIWE message and signature
597
+ * @returns Login result with the authenticated address
598
+ *
599
+ * @example
600
+ * ```typescript
601
+ * import { createSiweMessage, loginToBillingApi } from "@layr-labs/ecloud-sdk/browser";
602
+ *
603
+ * const { message } = createSiweMessage({
604
+ * address: userAddress,
605
+ * chainId: 11155111,
606
+ * domain: window.location.host,
607
+ * uri: window.location.origin,
608
+ * });
609
+ *
610
+ * const signature = await signMessageAsync({ message });
611
+ *
612
+ * // Can send to both APIs with the same message/signature
613
+ * const [computeResult, billingResult] = await Promise.all([
614
+ * loginToComputeApi({ baseUrl: computeApiUrl }, { message, signature }),
615
+ * loginToBillingApi({ baseUrl: billingApiUrl }, { message, signature }),
616
+ * ]);
617
+ * ```
618
+ */
619
+ declare function loginToBillingApi(config: BillingApiConfig, request: BillingLoginRequest): Promise<BillingLoginResult>;
620
+ /**
621
+ * Get the current session status from the billing API
622
+ *
623
+ * @param config - Billing API configuration
624
+ * @returns Session information including authentication status and address
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * const session = await getBillingApiSession({ baseUrl: "https://billing.eigencloud.xyz" });
629
+ * if (session.authenticated) {
630
+ * console.log(`Logged in as ${session.address}`);
631
+ * }
632
+ * ```
633
+ */
634
+ declare function getBillingApiSession(config: BillingApiConfig): Promise<BillingSessionInfo>;
635
+ /**
636
+ * Logout from the billing API
637
+ *
638
+ * This destroys the current session and clears the session cookie.
639
+ *
640
+ * @param config - Billing API configuration
641
+ *
642
+ * @example
643
+ * ```typescript
644
+ * await logoutFromBillingApi({ baseUrl: "https://billing.eigencloud.xyz" });
645
+ * ```
646
+ */
647
+ declare function logoutFromBillingApi(config: BillingApiConfig): Promise<void>;
648
+ /**
649
+ * Check if a billing session is still valid (not expired)
650
+ *
651
+ * This is a convenience function that checks the session status
652
+ * and returns a boolean.
653
+ *
654
+ * @param config - Billing API configuration
655
+ * @returns True if session is authenticated, false otherwise
656
+ */
657
+ declare function isBillingSessionValid(config: BillingApiConfig): Promise<boolean>;
658
+ /**
659
+ * Login to both compute and billing APIs simultaneously
660
+ *
661
+ * This is a convenience function that sends the same SIWE message and signature
662
+ * to both APIs in parallel, establishing sessions with both services at once.
663
+ *
664
+ * @param computeConfig - Compute API configuration
665
+ * @param billingConfig - Billing API configuration
666
+ * @param request - Login request containing SIWE message and signature
667
+ * @returns Object containing login results for both APIs
668
+ *
669
+ * @example
670
+ * ```typescript
671
+ * import { createSiweMessage, loginToBothApis } from "@layr-labs/ecloud-sdk/browser";
672
+ *
673
+ * const { message } = createSiweMessage({
674
+ * address: userAddress,
675
+ * chainId: 11155111,
676
+ * domain: window.location.host,
677
+ * uri: window.location.origin,
678
+ * });
679
+ *
680
+ * const signature = await signMessageAsync({ message });
681
+ * const { compute, billing } = await loginToBothApis(
682
+ * { baseUrl: computeApiUrl },
683
+ * { baseUrl: billingApiUrl },
684
+ * { message, signature }
685
+ * );
686
+ * ```
687
+ */
688
+ declare function loginToBothApis(computeConfig: {
689
+ baseUrl: string;
690
+ }, billingConfig: BillingApiConfig, request: BillingLoginRequest): Promise<{
691
+ compute: BillingLoginResult;
692
+ billing: BillingLoginResult;
693
+ }>;
694
+ /**
695
+ * Logout from both compute and billing APIs simultaneously
696
+ *
697
+ * @param computeConfig - Compute API configuration
698
+ * @param billingConfig - Billing API configuration
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * await logoutFromBothApis(
703
+ * { baseUrl: computeApiUrl },
704
+ * { baseUrl: billingApiUrl }
705
+ * );
706
+ * ```
707
+ */
708
+ declare function logoutFromBothApis(computeConfig: {
709
+ baseUrl: string;
710
+ }, billingConfig: BillingApiConfig): Promise<void>;
711
+
541
712
  /**
542
713
  * BillingAPI Client to manage product subscriptions
543
714
  * Standalone client - does not depend on chain infrastructure
544
715
  *
545
716
  * Accepts viem's WalletClient which abstracts over both local accounts
546
717
  * (privateKeyToAccount) and external signers (MetaMask, etc.).
718
+ *
719
+ * Supports two authentication modes:
720
+ * 1. EIP-712 signature auth (default) - signs each request with typed data
721
+ * 2. Session auth (optional) - uses SIWE session cookies
547
722
  */
548
723
 
724
+ interface BillingApiClientOptions {
725
+ /**
726
+ * Use session-based authentication instead of per-request signatures.
727
+ * When true, the client will rely on session cookies set by SIWE login.
728
+ * When false (default), uses EIP-712 typed data signatures for each request.
729
+ */
730
+ useSession?: boolean;
731
+ }
549
732
  /**
550
733
  * BillingAPI Client for managing product subscriptions.
551
734
  */
552
735
  declare class BillingApiClient {
553
736
  private readonly config;
554
737
  private readonly walletClient;
555
- constructor(config: BillingEnvironmentConfig, walletClient: WalletClient);
738
+ private readonly options;
739
+ private readonly useSession;
740
+ constructor(config: BillingEnvironmentConfig, walletClient: WalletClient | null, options?: BillingApiClientOptions);
556
741
  /**
557
742
  * Get the address of the connected wallet
743
+ * Returns undefined if using session auth without a wallet client
558
744
  */
559
- get address(): Address;
745
+ get address(): Address | undefined;
746
+ /**
747
+ * Get the base URL of the billing API
748
+ */
749
+ get baseUrl(): string;
750
+ /**
751
+ * Login to the billing API using SIWE
752
+ *
753
+ * This establishes a session with the billing API by verifying the SIWE message
754
+ * and signature. On success, a session cookie is set in the browser.
755
+ *
756
+ * @param request - Login request containing SIWE message and signature
757
+ * @returns Login result with the authenticated address
758
+ *
759
+ * @example
760
+ * ```typescript
761
+ * const { message } = createSiweMessage({
762
+ * address: userAddress,
763
+ * chainId: 11155111,
764
+ * domain: window.location.host,
765
+ * uri: window.location.origin,
766
+ * });
767
+ *
768
+ * const signature = await signMessageAsync({ message });
769
+ * const result = await billingClient.siweLogin({ message, signature });
770
+ * ```
771
+ */
772
+ siweLogin(request: BillingLoginRequest): Promise<BillingLoginResult>;
773
+ /**
774
+ * Logout from the billing API
775
+ *
776
+ * This destroys the current session and clears the session cookie.
777
+ */
778
+ siweLogout(): Promise<void>;
779
+ /**
780
+ * Get the current session status from the billing API
781
+ *
782
+ * @returns Session information including authentication status and address
783
+ */
784
+ getSession(): Promise<BillingSessionInfo>;
785
+ /**
786
+ * Check if there is a valid session
787
+ *
788
+ * @returns True if session is authenticated, false otherwise
789
+ */
790
+ isSessionValid(): Promise<boolean>;
560
791
  createSubscription(productId?: ProductID, options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
561
792
  getSubscription(productId?: ProductID): Promise<ProductSubscriptionResponse>;
562
793
  cancelSubscription(productId?: ProductID): Promise<void>;
563
794
  /**
564
795
  * Make an authenticated request to the billing API
796
+ *
797
+ * Uses session auth if useSession is true, otherwise uses EIP-712 signature auth.
565
798
  */
566
799
  private makeAuthenticatedRequest;
800
+ /**
801
+ * Make a request using session-based authentication (cookies)
802
+ */
803
+ private makeSessionAuthenticatedRequest;
804
+ /**
805
+ * Make a request using EIP-712 signature authentication
806
+ */
807
+ private makeSignatureAuthenticatedRequest;
567
808
  }
568
809
 
569
810
  /**
@@ -739,4 +980,4 @@ declare function addHexPrefix(value: string): Hex;
739
980
  */
740
981
  declare function stripHexPrefix(value: string): string;
741
982
 
742
- export { logoutFromComputeApi as $, type LogsParams as A, isSubscriptionActive as B, type ComputeApiConfig as C, generateNewPrivateKey as D, type UserApiClientOptions as E, type AppInfo as F, type GeneratedKey as G, type AppProfileInfo as H, type AppMetrics as I, type AppInfoResponse as J, BillingApiClient as K, type LogVisibility as L, estimateBatchGas as M, executeBatch as N, checkERC7702Delegation as O, type EstimateBatchGasOptions as P, type ExecuteBatchOptions as Q, type Execution as R, type SessionInfo as S, createSiweMessage as T, UserApiClient as U, parseSiweMessage as V, generateNonce as W, isSiweMessageExpired as X, isSiweMessageNotYetValid as Y, type SiweMessageResult as Z, loginToComputeApi as _, SessionError as a, getComputeApiSession as a0, isSessionValid as a1, type LoginResult as a2, type LoginRequest as a3, getChainFromID as a4, addHexPrefix as a5, stripHexPrefix as a6, type ResourceUsageMonitoring as a7, createClients as a8, type AppRelease as a9, type AppReleaseBuild as aa, type AppResponse as ab, validateFilePath as ac, assertValidFilePath as ad, validateImagePath as ae, validateResourceUsageMonitoring as af, type DeployParams as ag, validateDeployParams as ah, type UpgradeParams as ai, validateUpgradeParams as aj, type SiweMessageParams as b, getBillingEnvironmentConfig as c, getAvailableEnvironments as d, getBuildType as e, isMainnet as f, getEnvironmentConfig as g, validateImageReference as h, isEnvironmentAvailable as i, assertValidImageReference as j, extractAppNameFromImage as k, validateInstanceTypeSKU as l, validatePrivateKeyFormat as m, assertValidPrivateKey as n, validateURL as o, validateXURL as p, validateDescription as q, validateAppID as r, validateLogVisibility as s, sanitizeString as t, sanitizeURL as u, validateAppName as v, sanitizeXURL as w, validateCreateAppParams as x, validateLogsParams as y, type CreateAppParams as z };
983
+ export { loginToComputeApi as $, type LogsParams as A, isSubscriptionActive as B, type ComputeApiConfig as C, generateNewPrivateKey as D, type UserApiClientOptions as E, type AppInfo as F, type GeneratedKey as G, type AppProfileInfo as H, type AppMetrics as I, type AppInfoResponse as J, BillingApiClient as K, type LogVisibility as L, type BillingApiClientOptions as M, estimateBatchGas as N, executeBatch as O, checkERC7702Delegation as P, type EstimateBatchGasOptions as Q, type ExecuteBatchOptions as R, type SessionInfo as S, type Execution as T, UserApiClient as U, createSiweMessage as V, parseSiweMessage as W, generateNonce as X, isSiweMessageExpired as Y, isSiweMessageNotYetValid as Z, type SiweMessageResult as _, SessionError as a, logoutFromComputeApi as a0, getComputeApiSession as a1, isSessionValid as a2, type LoginResult as a3, type LoginRequest as a4, loginToBillingApi as a5, logoutFromBillingApi as a6, getBillingApiSession as a7, isBillingSessionValid as a8, loginToBothApis as a9, logoutFromBothApis as aa, BillingSessionError as ab, type BillingApiConfig as ac, type BillingSessionInfo as ad, type BillingLoginResult as ae, type BillingLoginRequest as af, getChainFromID as ag, addHexPrefix as ah, stripHexPrefix as ai, type ResourceUsageMonitoring as aj, createClients as ak, type AppRelease as al, type AppReleaseBuild as am, type AppResponse as an, validateFilePath as ao, assertValidFilePath as ap, validateImagePath as aq, validateResourceUsageMonitoring as ar, type DeployParams as as, validateDeployParams as at, type UpgradeParams as au, validateUpgradeParams as av, type SiweMessageParams as b, getBillingEnvironmentConfig as c, getAvailableEnvironments as d, getBuildType as e, isMainnet as f, getEnvironmentConfig as g, validateImageReference as h, isEnvironmentAvailable as i, assertValidImageReference as j, extractAppNameFromImage as k, validateInstanceTypeSKU as l, validatePrivateKeyFormat as m, assertValidPrivateKey as n, validateURL as o, validateXURL as p, validateDescription as q, validateAppID as r, validateLogVisibility as s, sanitizeString as t, sanitizeURL as u, validateAppName as v, sanitizeXURL as w, validateCreateAppParams as x, validateLogsParams as y, type CreateAppParams as z };
@@ -708,6 +708,10 @@ interface ProductSubscriptionResponse {
708
708
  }
709
709
  interface SubscriptionOpts {
710
710
  productId?: ProductID;
711
+ /** URL to redirect to after successful checkout */
712
+ successUrl?: string;
713
+ /** URL to redirect to if checkout is canceled */
714
+ cancelUrl?: string;
711
715
  }
712
716
  interface BillingEnvironmentConfig {
713
717
  billingApiServerURL: string;
@@ -708,6 +708,10 @@ interface ProductSubscriptionResponse {
708
708
  }
709
709
  interface SubscriptionOpts {
710
710
  productId?: ProductID;
711
+ /** URL to redirect to after successful checkout */
712
+ successUrl?: string;
713
+ /** URL to redirect to if checkout is canceled */
714
+ cancelUrl?: string;
711
715
  }
712
716
  interface BillingEnvironmentConfig {
713
717
  billingApiServerURL: string;