@oasisprotocol/privana-sdk 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +253 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -2
- package/dist/index.d.ts +38 -2
- package/dist/index.js +253 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -663,6 +663,32 @@ interface SignWithdrawFromLockParams {
|
|
|
663
663
|
}
|
|
664
664
|
declare function signWithdrawFromLockMessage({ walletClient, chainId, verifyingContract, message, }: SignWithdrawFromLockParams): Promise<`0x${string}`>;
|
|
665
665
|
|
|
666
|
+
type SiweAuthSession = {
|
|
667
|
+
address: Address;
|
|
668
|
+
};
|
|
669
|
+
type SiweAuthTokens = Pick<SiweLoginResponse, 'siwe_token' | 'jwt_access_token' | 'jwt_refresh_token' | 'address'>;
|
|
670
|
+
interface SiweAuthContextValue {
|
|
671
|
+
isAuthenticated: boolean;
|
|
672
|
+
isLoading: boolean;
|
|
673
|
+
error: Error | null;
|
|
674
|
+
session: SiweAuthSession | null;
|
|
675
|
+
accessToken: string | undefined;
|
|
676
|
+
tokens: SiweAuthTokens | null;
|
|
677
|
+
login: () => Promise<void>;
|
|
678
|
+
logout: () => Promise<void>;
|
|
679
|
+
}
|
|
680
|
+
interface SiweAuthConfig {
|
|
681
|
+
autoLogin?: boolean;
|
|
682
|
+
statement?: string;
|
|
683
|
+
}
|
|
684
|
+
interface SiweAuthProviderProps extends SiweAuthConfig {
|
|
685
|
+
children: ReactNode;
|
|
686
|
+
client: PrivanaClient;
|
|
687
|
+
networkConfig: NetworkConfig;
|
|
688
|
+
}
|
|
689
|
+
declare function SiweAuthProvider({ children, client, networkConfig, autoLogin, statement, }: SiweAuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
690
|
+
declare function useSiweAuth(): SiweAuthContextValue;
|
|
691
|
+
|
|
666
692
|
type TokensStatus = 'loading' | 'ready' | 'error';
|
|
667
693
|
interface PrivanaContextValue {
|
|
668
694
|
client: PrivanaClient;
|
|
@@ -711,8 +737,16 @@ interface PrivanaProviderProps {
|
|
|
711
737
|
* Optional hosted redirect auth configuration for cross-domain browser apps.
|
|
712
738
|
*/
|
|
713
739
|
hostedAuth?: HostedAuthConfig;
|
|
740
|
+
/**
|
|
741
|
+
* Optional direct (in-app) SIWE auth. When provided, the connected wallet
|
|
742
|
+
* signs an EIP-4361 message in-app and `useSiweAuth()` becomes available.
|
|
743
|
+
* Mutually exclusive with `hostedAuth`: providing both throws, because
|
|
744
|
+
* `usePrivateReadRequest()` prefers `hostedAuthConfig` and would otherwise
|
|
745
|
+
* ignore the SIWE login.
|
|
746
|
+
*/
|
|
747
|
+
siweAuth?: SiweAuthConfig;
|
|
714
748
|
}
|
|
715
|
-
declare function PrivanaProvider({ children, networkConfig: networkConfigOverride, tokens, chains, pollingInterval, serviceAddress, hostedAuth, }: PrivanaProviderProps): react_jsx_runtime.JSX.Element;
|
|
749
|
+
declare function PrivanaProvider({ children, networkConfig: networkConfigOverride, tokens, chains, pollingInterval, serviceAddress, hostedAuth, siweAuth, }: PrivanaProviderProps): react_jsx_runtime.JSX.Element;
|
|
716
750
|
declare function usePrivanaContext(): PrivanaContextValue;
|
|
717
751
|
declare function useSafePrivanaContext(): PrivanaContextValue | null;
|
|
718
752
|
|
|
@@ -963,9 +997,11 @@ interface UseHistoryResult {
|
|
|
963
997
|
}
|
|
964
998
|
declare function useHistory(options?: UseHistoryOptions): UseHistoryResult;
|
|
965
999
|
|
|
1000
|
+
type AccountStatus = 'connecting' | 'reconnecting' | 'connected' | 'disconnected';
|
|
966
1001
|
interface SafeAccountResult {
|
|
967
1002
|
address: Address$1 | undefined;
|
|
968
1003
|
isConnected: boolean;
|
|
1004
|
+
status: AccountStatus;
|
|
969
1005
|
}
|
|
970
1006
|
declare function useSafeAccount(): SafeAccountResult;
|
|
971
1007
|
|
|
@@ -1057,4 +1093,4 @@ declare function Skeleton({ className, ...props }: React.ComponentProps<'div'>):
|
|
|
1057
1093
|
declare function getTokenIcon(symbol: string, size?: number): react_jsx_runtime.JSX.Element;
|
|
1058
1094
|
declare function getChainIcon(chainId: number, size?: number): react_jsx_runtime.JSX.Element;
|
|
1059
1095
|
|
|
1060
|
-
export { AccountingApiError, type Address, type BalanceResponse, type BatchBalancesRequest, type BatchBalancesResponse, Button, type Bytes32, type ChainConfig, type DepositAddressRequest, type DepositAddressResponse, type DepositCheckRequest, type DepositCheckResponse, type DepositParams, type EIP712Domain, type ExpiredLocksResponse, HOSTED_AUTH_CLOCK_SKEW_MS, type HexString, type HistoryEntry, type HistoryKind, type HistoryRequest, type HistoryResponse, type HostedAuthAuthorizeUrlRequest, type HostedAuthCallback, type HostedAuthCallbackError, type HostedAuthCallbackSuccess, type HostedAuthConfig, HostedAuthError, type HostedAuthPendingTransaction, HostedAuthRequiredError, type HostedAuthResponseMode, type HostedAuthSession, HostedAuthStateMismatchError, type HostedAuthTokenExchangeRequest, type HostedAuthTokenExchangeResponse, HttpClient, type HttpClientConfig, type IntegerLike, type JwtLogoutRequest, type JwtLogoutResponse, type JwtRefreshRequest, type JwtRefreshResponse, LOCK_TYPES, type LockFundsParams, type LockFundsRequest, type LockInfo, type LockMessage, type LockNonceResponse, type LockedFundsResponse, MODIFY_LOCK_TYPES, type MinDepositAmounts, type ModifyLockMessage, type ModifyLockNonceResponse, type ModifyLockParams, type ModifyLockRequest, NETWORK_CONFIG, type Network, type NetworkConfig, NetworkError, type PendingWithdrawalsResponse, PrivanaButton, type PrivanaButtonProps, PrivanaClient, type PrivanaClientConfig, type PrivanaContextValue, PrivanaInlineModal, PrivanaModal, PrivanaProvider, type PrivanaProviderProps, SUPPORTED_CHAINS, type SignLockParams, type SignModifyLockParams, type SignTransferLockedParams, type SignTransferParams, type SignWithdrawFromLockParams, type SignWithdrawParams, type SiweDomainResponse, type SiweLoginRequest, type SiweLoginResponse, type SiweNonceResponse, Skeleton, TRANSFER_LOCKED_TYPES, TRANSFER_TYPES, type TokenBalance, type TokenConfig, type TokenInfoResponse, type TokenListResponse, type TokensStatus, type TotalLockedBalanceResponse, type TransactionSubmissionResponse, type TransferFundsRequest, type TransferLockedFundsRequest, type TransferLockedMessage, type TransferLockedNonceResponse, type TransferLockedParams, type TransferMessage, type TransferNonceResponse, type TransferParams, type UnlockAllExpiredRequest, type UnlockFundsParams, type UnlockFundsRequest, type UseBalanceOptions, type UseBalanceResult, type UseBatchBalancesOptions, type UseBatchBalancesResult, type UseDepositOptions, type UseDepositResult, type UseExpiredLocksOptions, type UseExpiredLocksResult, type UseHistoryOptions, type UseHistoryResult, type UseHostedRedirectAuthResult, type UseLockFundsOptions, type UseLockFundsResult, type UseLockedFundsOptions, type UseLockedFundsResult, type UseModifyLockOptions, type UseModifyLockResult, type UsePendingWithdrawalsOptions, type UsePendingWithdrawalsResult, type UseTokenInfoOptions, type UseTokenInfoResult, type UseTokenListOptions, type UseTokenListResult, type UseTotalLockedBalanceOptions, type UseTotalLockedBalanceResult, type UseTransferOptions, type UseTransferResult, type UseUnlockFundsOptions, type UseUnlockFundsResult, type UseWithdrawOptions, type UseWithdrawResult, ValidationError, WITHDRAW_FROM_LOCK_TYPES, WITHDRAW_TYPES, type WithdrawFromLockMessage, type WithdrawFromLockRequest, type WithdrawMessage, type WithdrawParams, type WithdrawStep, type WithdrawalInfo, type WithdrawalInfoResponse, type WithdrawalNonceResponse, type WithdrawalRequest, applyRefreshResponse, buildHostedAuthSession, buttonVariants, clearHostedAuthPendingTransaction, createDomain, createHostedAuthPendingStorageKey, createHostedAuthState, createHostedAuthStorageKey, createLockExpiry, createPkceChallenge, createPkceVerifier, getAccountingContract, getApiUrl, getChainById, getChainIcon, getChainId, getExplorerAddressUrl, getTokenIcon, isHostedAuthRefreshActive, isHostedAuthSessionActive, normalizeAddress, normalizeHex, parseHostedAuthCallback, persistHostedAuthPendingTransaction, readHostedAuthPendingTransaction, readStoredHostedAuthSession, signLockMessage, signModifyLockMessage, signTransferLockedMessage, signTransferMessage, signWithdrawFromLockMessage, signWithdrawMessage, stripHostedAuthCallbackParams, syncHostedAuthSessionToClient, useBalance, useBatchBalances, useDeposit, useExpiredLocks, useHistory, useHostedRedirectAuth, useLockFunds, useLockedFunds, useModifyLock, usePendingWithdrawals, usePrivanaClient, usePrivanaContext, useSafeAccount, useSafePrivanaContext, useTokenInfo, useTokenList, useTotalLockedBalance, useTransfer, useUnlockFunds, useWithdraw };
|
|
1096
|
+
export { AccountingApiError, type Address, type BalanceResponse, type BatchBalancesRequest, type BatchBalancesResponse, Button, type Bytes32, type ChainConfig, type DepositAddressRequest, type DepositAddressResponse, type DepositCheckRequest, type DepositCheckResponse, type DepositParams, type EIP712Domain, type ExpiredLocksResponse, HOSTED_AUTH_CLOCK_SKEW_MS, type HexString, type HistoryEntry, type HistoryKind, type HistoryRequest, type HistoryResponse, type HostedAuthAuthorizeUrlRequest, type HostedAuthCallback, type HostedAuthCallbackError, type HostedAuthCallbackSuccess, type HostedAuthConfig, HostedAuthError, type HostedAuthPendingTransaction, HostedAuthRequiredError, type HostedAuthResponseMode, type HostedAuthSession, HostedAuthStateMismatchError, type HostedAuthTokenExchangeRequest, type HostedAuthTokenExchangeResponse, HttpClient, type HttpClientConfig, type IntegerLike, type JwtLogoutRequest, type JwtLogoutResponse, type JwtRefreshRequest, type JwtRefreshResponse, LOCK_TYPES, type LockFundsParams, type LockFundsRequest, type LockInfo, type LockMessage, type LockNonceResponse, type LockedFundsResponse, MODIFY_LOCK_TYPES, type MinDepositAmounts, type ModifyLockMessage, type ModifyLockNonceResponse, type ModifyLockParams, type ModifyLockRequest, NETWORK_CONFIG, type Network, type NetworkConfig, NetworkError, type PendingWithdrawalsResponse, PrivanaButton, type PrivanaButtonProps, PrivanaClient, type PrivanaClientConfig, type PrivanaContextValue, PrivanaInlineModal, PrivanaModal, PrivanaProvider, type PrivanaProviderProps, SUPPORTED_CHAINS, type SignLockParams, type SignModifyLockParams, type SignTransferLockedParams, type SignTransferParams, type SignWithdrawFromLockParams, type SignWithdrawParams, type SiweAuthConfig, type SiweAuthContextValue, SiweAuthProvider, type SiweAuthProviderProps, type SiweAuthSession, type SiweAuthTokens, type SiweDomainResponse, type SiweLoginRequest, type SiweLoginResponse, type SiweNonceResponse, Skeleton, TRANSFER_LOCKED_TYPES, TRANSFER_TYPES, type TokenBalance, type TokenConfig, type TokenInfoResponse, type TokenListResponse, type TokensStatus, type TotalLockedBalanceResponse, type TransactionSubmissionResponse, type TransferFundsRequest, type TransferLockedFundsRequest, type TransferLockedMessage, type TransferLockedNonceResponse, type TransferLockedParams, type TransferMessage, type TransferNonceResponse, type TransferParams, type UnlockAllExpiredRequest, type UnlockFundsParams, type UnlockFundsRequest, type UseBalanceOptions, type UseBalanceResult, type UseBatchBalancesOptions, type UseBatchBalancesResult, type UseDepositOptions, type UseDepositResult, type UseExpiredLocksOptions, type UseExpiredLocksResult, type UseHistoryOptions, type UseHistoryResult, type UseHostedRedirectAuthResult, type UseLockFundsOptions, type UseLockFundsResult, type UseLockedFundsOptions, type UseLockedFundsResult, type UseModifyLockOptions, type UseModifyLockResult, type UsePendingWithdrawalsOptions, type UsePendingWithdrawalsResult, type UseTokenInfoOptions, type UseTokenInfoResult, type UseTokenListOptions, type UseTokenListResult, type UseTotalLockedBalanceOptions, type UseTotalLockedBalanceResult, type UseTransferOptions, type UseTransferResult, type UseUnlockFundsOptions, type UseUnlockFundsResult, type UseWithdrawOptions, type UseWithdrawResult, ValidationError, WITHDRAW_FROM_LOCK_TYPES, WITHDRAW_TYPES, type WithdrawFromLockMessage, type WithdrawFromLockRequest, type WithdrawMessage, type WithdrawParams, type WithdrawStep, type WithdrawalInfo, type WithdrawalInfoResponse, type WithdrawalNonceResponse, type WithdrawalRequest, applyRefreshResponse, buildHostedAuthSession, buttonVariants, clearHostedAuthPendingTransaction, createDomain, createHostedAuthPendingStorageKey, createHostedAuthState, createHostedAuthStorageKey, createLockExpiry, createPkceChallenge, createPkceVerifier, getAccountingContract, getApiUrl, getChainById, getChainIcon, getChainId, getExplorerAddressUrl, getTokenIcon, isHostedAuthRefreshActive, isHostedAuthSessionActive, normalizeAddress, normalizeHex, parseHostedAuthCallback, persistHostedAuthPendingTransaction, readHostedAuthPendingTransaction, readStoredHostedAuthSession, signLockMessage, signModifyLockMessage, signTransferLockedMessage, signTransferMessage, signWithdrawFromLockMessage, signWithdrawMessage, stripHostedAuthCallbackParams, syncHostedAuthSessionToClient, useBalance, useBatchBalances, useDeposit, useExpiredLocks, useHistory, useHostedRedirectAuth, useLockFunds, useLockedFunds, useModifyLock, usePendingWithdrawals, usePrivanaClient, usePrivanaContext, useSafeAccount, useSafePrivanaContext, useSiweAuth, useTokenInfo, useTokenList, useTotalLockedBalance, useTransfer, useUnlockFunds, useWithdraw };
|
package/dist/index.d.ts
CHANGED
|
@@ -663,6 +663,32 @@ interface SignWithdrawFromLockParams {
|
|
|
663
663
|
}
|
|
664
664
|
declare function signWithdrawFromLockMessage({ walletClient, chainId, verifyingContract, message, }: SignWithdrawFromLockParams): Promise<`0x${string}`>;
|
|
665
665
|
|
|
666
|
+
type SiweAuthSession = {
|
|
667
|
+
address: Address;
|
|
668
|
+
};
|
|
669
|
+
type SiweAuthTokens = Pick<SiweLoginResponse, 'siwe_token' | 'jwt_access_token' | 'jwt_refresh_token' | 'address'>;
|
|
670
|
+
interface SiweAuthContextValue {
|
|
671
|
+
isAuthenticated: boolean;
|
|
672
|
+
isLoading: boolean;
|
|
673
|
+
error: Error | null;
|
|
674
|
+
session: SiweAuthSession | null;
|
|
675
|
+
accessToken: string | undefined;
|
|
676
|
+
tokens: SiweAuthTokens | null;
|
|
677
|
+
login: () => Promise<void>;
|
|
678
|
+
logout: () => Promise<void>;
|
|
679
|
+
}
|
|
680
|
+
interface SiweAuthConfig {
|
|
681
|
+
autoLogin?: boolean;
|
|
682
|
+
statement?: string;
|
|
683
|
+
}
|
|
684
|
+
interface SiweAuthProviderProps extends SiweAuthConfig {
|
|
685
|
+
children: ReactNode;
|
|
686
|
+
client: PrivanaClient;
|
|
687
|
+
networkConfig: NetworkConfig;
|
|
688
|
+
}
|
|
689
|
+
declare function SiweAuthProvider({ children, client, networkConfig, autoLogin, statement, }: SiweAuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
690
|
+
declare function useSiweAuth(): SiweAuthContextValue;
|
|
691
|
+
|
|
666
692
|
type TokensStatus = 'loading' | 'ready' | 'error';
|
|
667
693
|
interface PrivanaContextValue {
|
|
668
694
|
client: PrivanaClient;
|
|
@@ -711,8 +737,16 @@ interface PrivanaProviderProps {
|
|
|
711
737
|
* Optional hosted redirect auth configuration for cross-domain browser apps.
|
|
712
738
|
*/
|
|
713
739
|
hostedAuth?: HostedAuthConfig;
|
|
740
|
+
/**
|
|
741
|
+
* Optional direct (in-app) SIWE auth. When provided, the connected wallet
|
|
742
|
+
* signs an EIP-4361 message in-app and `useSiweAuth()` becomes available.
|
|
743
|
+
* Mutually exclusive with `hostedAuth`: providing both throws, because
|
|
744
|
+
* `usePrivateReadRequest()` prefers `hostedAuthConfig` and would otherwise
|
|
745
|
+
* ignore the SIWE login.
|
|
746
|
+
*/
|
|
747
|
+
siweAuth?: SiweAuthConfig;
|
|
714
748
|
}
|
|
715
|
-
declare function PrivanaProvider({ children, networkConfig: networkConfigOverride, tokens, chains, pollingInterval, serviceAddress, hostedAuth, }: PrivanaProviderProps): react_jsx_runtime.JSX.Element;
|
|
749
|
+
declare function PrivanaProvider({ children, networkConfig: networkConfigOverride, tokens, chains, pollingInterval, serviceAddress, hostedAuth, siweAuth, }: PrivanaProviderProps): react_jsx_runtime.JSX.Element;
|
|
716
750
|
declare function usePrivanaContext(): PrivanaContextValue;
|
|
717
751
|
declare function useSafePrivanaContext(): PrivanaContextValue | null;
|
|
718
752
|
|
|
@@ -963,9 +997,11 @@ interface UseHistoryResult {
|
|
|
963
997
|
}
|
|
964
998
|
declare function useHistory(options?: UseHistoryOptions): UseHistoryResult;
|
|
965
999
|
|
|
1000
|
+
type AccountStatus = 'connecting' | 'reconnecting' | 'connected' | 'disconnected';
|
|
966
1001
|
interface SafeAccountResult {
|
|
967
1002
|
address: Address$1 | undefined;
|
|
968
1003
|
isConnected: boolean;
|
|
1004
|
+
status: AccountStatus;
|
|
969
1005
|
}
|
|
970
1006
|
declare function useSafeAccount(): SafeAccountResult;
|
|
971
1007
|
|
|
@@ -1057,4 +1093,4 @@ declare function Skeleton({ className, ...props }: React.ComponentProps<'div'>):
|
|
|
1057
1093
|
declare function getTokenIcon(symbol: string, size?: number): react_jsx_runtime.JSX.Element;
|
|
1058
1094
|
declare function getChainIcon(chainId: number, size?: number): react_jsx_runtime.JSX.Element;
|
|
1059
1095
|
|
|
1060
|
-
export { AccountingApiError, type Address, type BalanceResponse, type BatchBalancesRequest, type BatchBalancesResponse, Button, type Bytes32, type ChainConfig, type DepositAddressRequest, type DepositAddressResponse, type DepositCheckRequest, type DepositCheckResponse, type DepositParams, type EIP712Domain, type ExpiredLocksResponse, HOSTED_AUTH_CLOCK_SKEW_MS, type HexString, type HistoryEntry, type HistoryKind, type HistoryRequest, type HistoryResponse, type HostedAuthAuthorizeUrlRequest, type HostedAuthCallback, type HostedAuthCallbackError, type HostedAuthCallbackSuccess, type HostedAuthConfig, HostedAuthError, type HostedAuthPendingTransaction, HostedAuthRequiredError, type HostedAuthResponseMode, type HostedAuthSession, HostedAuthStateMismatchError, type HostedAuthTokenExchangeRequest, type HostedAuthTokenExchangeResponse, HttpClient, type HttpClientConfig, type IntegerLike, type JwtLogoutRequest, type JwtLogoutResponse, type JwtRefreshRequest, type JwtRefreshResponse, LOCK_TYPES, type LockFundsParams, type LockFundsRequest, type LockInfo, type LockMessage, type LockNonceResponse, type LockedFundsResponse, MODIFY_LOCK_TYPES, type MinDepositAmounts, type ModifyLockMessage, type ModifyLockNonceResponse, type ModifyLockParams, type ModifyLockRequest, NETWORK_CONFIG, type Network, type NetworkConfig, NetworkError, type PendingWithdrawalsResponse, PrivanaButton, type PrivanaButtonProps, PrivanaClient, type PrivanaClientConfig, type PrivanaContextValue, PrivanaInlineModal, PrivanaModal, PrivanaProvider, type PrivanaProviderProps, SUPPORTED_CHAINS, type SignLockParams, type SignModifyLockParams, type SignTransferLockedParams, type SignTransferParams, type SignWithdrawFromLockParams, type SignWithdrawParams, type SiweDomainResponse, type SiweLoginRequest, type SiweLoginResponse, type SiweNonceResponse, Skeleton, TRANSFER_LOCKED_TYPES, TRANSFER_TYPES, type TokenBalance, type TokenConfig, type TokenInfoResponse, type TokenListResponse, type TokensStatus, type TotalLockedBalanceResponse, type TransactionSubmissionResponse, type TransferFundsRequest, type TransferLockedFundsRequest, type TransferLockedMessage, type TransferLockedNonceResponse, type TransferLockedParams, type TransferMessage, type TransferNonceResponse, type TransferParams, type UnlockAllExpiredRequest, type UnlockFundsParams, type UnlockFundsRequest, type UseBalanceOptions, type UseBalanceResult, type UseBatchBalancesOptions, type UseBatchBalancesResult, type UseDepositOptions, type UseDepositResult, type UseExpiredLocksOptions, type UseExpiredLocksResult, type UseHistoryOptions, type UseHistoryResult, type UseHostedRedirectAuthResult, type UseLockFundsOptions, type UseLockFundsResult, type UseLockedFundsOptions, type UseLockedFundsResult, type UseModifyLockOptions, type UseModifyLockResult, type UsePendingWithdrawalsOptions, type UsePendingWithdrawalsResult, type UseTokenInfoOptions, type UseTokenInfoResult, type UseTokenListOptions, type UseTokenListResult, type UseTotalLockedBalanceOptions, type UseTotalLockedBalanceResult, type UseTransferOptions, type UseTransferResult, type UseUnlockFundsOptions, type UseUnlockFundsResult, type UseWithdrawOptions, type UseWithdrawResult, ValidationError, WITHDRAW_FROM_LOCK_TYPES, WITHDRAW_TYPES, type WithdrawFromLockMessage, type WithdrawFromLockRequest, type WithdrawMessage, type WithdrawParams, type WithdrawStep, type WithdrawalInfo, type WithdrawalInfoResponse, type WithdrawalNonceResponse, type WithdrawalRequest, applyRefreshResponse, buildHostedAuthSession, buttonVariants, clearHostedAuthPendingTransaction, createDomain, createHostedAuthPendingStorageKey, createHostedAuthState, createHostedAuthStorageKey, createLockExpiry, createPkceChallenge, createPkceVerifier, getAccountingContract, getApiUrl, getChainById, getChainIcon, getChainId, getExplorerAddressUrl, getTokenIcon, isHostedAuthRefreshActive, isHostedAuthSessionActive, normalizeAddress, normalizeHex, parseHostedAuthCallback, persistHostedAuthPendingTransaction, readHostedAuthPendingTransaction, readStoredHostedAuthSession, signLockMessage, signModifyLockMessage, signTransferLockedMessage, signTransferMessage, signWithdrawFromLockMessage, signWithdrawMessage, stripHostedAuthCallbackParams, syncHostedAuthSessionToClient, useBalance, useBatchBalances, useDeposit, useExpiredLocks, useHistory, useHostedRedirectAuth, useLockFunds, useLockedFunds, useModifyLock, usePendingWithdrawals, usePrivanaClient, usePrivanaContext, useSafeAccount, useSafePrivanaContext, useTokenInfo, useTokenList, useTotalLockedBalance, useTransfer, useUnlockFunds, useWithdraw };
|
|
1096
|
+
export { AccountingApiError, type Address, type BalanceResponse, type BatchBalancesRequest, type BatchBalancesResponse, Button, type Bytes32, type ChainConfig, type DepositAddressRequest, type DepositAddressResponse, type DepositCheckRequest, type DepositCheckResponse, type DepositParams, type EIP712Domain, type ExpiredLocksResponse, HOSTED_AUTH_CLOCK_SKEW_MS, type HexString, type HistoryEntry, type HistoryKind, type HistoryRequest, type HistoryResponse, type HostedAuthAuthorizeUrlRequest, type HostedAuthCallback, type HostedAuthCallbackError, type HostedAuthCallbackSuccess, type HostedAuthConfig, HostedAuthError, type HostedAuthPendingTransaction, HostedAuthRequiredError, type HostedAuthResponseMode, type HostedAuthSession, HostedAuthStateMismatchError, type HostedAuthTokenExchangeRequest, type HostedAuthTokenExchangeResponse, HttpClient, type HttpClientConfig, type IntegerLike, type JwtLogoutRequest, type JwtLogoutResponse, type JwtRefreshRequest, type JwtRefreshResponse, LOCK_TYPES, type LockFundsParams, type LockFundsRequest, type LockInfo, type LockMessage, type LockNonceResponse, type LockedFundsResponse, MODIFY_LOCK_TYPES, type MinDepositAmounts, type ModifyLockMessage, type ModifyLockNonceResponse, type ModifyLockParams, type ModifyLockRequest, NETWORK_CONFIG, type Network, type NetworkConfig, NetworkError, type PendingWithdrawalsResponse, PrivanaButton, type PrivanaButtonProps, PrivanaClient, type PrivanaClientConfig, type PrivanaContextValue, PrivanaInlineModal, PrivanaModal, PrivanaProvider, type PrivanaProviderProps, SUPPORTED_CHAINS, type SignLockParams, type SignModifyLockParams, type SignTransferLockedParams, type SignTransferParams, type SignWithdrawFromLockParams, type SignWithdrawParams, type SiweAuthConfig, type SiweAuthContextValue, SiweAuthProvider, type SiweAuthProviderProps, type SiweAuthSession, type SiweAuthTokens, type SiweDomainResponse, type SiweLoginRequest, type SiweLoginResponse, type SiweNonceResponse, Skeleton, TRANSFER_LOCKED_TYPES, TRANSFER_TYPES, type TokenBalance, type TokenConfig, type TokenInfoResponse, type TokenListResponse, type TokensStatus, type TotalLockedBalanceResponse, type TransactionSubmissionResponse, type TransferFundsRequest, type TransferLockedFundsRequest, type TransferLockedMessage, type TransferLockedNonceResponse, type TransferLockedParams, type TransferMessage, type TransferNonceResponse, type TransferParams, type UnlockAllExpiredRequest, type UnlockFundsParams, type UnlockFundsRequest, type UseBalanceOptions, type UseBalanceResult, type UseBatchBalancesOptions, type UseBatchBalancesResult, type UseDepositOptions, type UseDepositResult, type UseExpiredLocksOptions, type UseExpiredLocksResult, type UseHistoryOptions, type UseHistoryResult, type UseHostedRedirectAuthResult, type UseLockFundsOptions, type UseLockFundsResult, type UseLockedFundsOptions, type UseLockedFundsResult, type UseModifyLockOptions, type UseModifyLockResult, type UsePendingWithdrawalsOptions, type UsePendingWithdrawalsResult, type UseTokenInfoOptions, type UseTokenInfoResult, type UseTokenListOptions, type UseTokenListResult, type UseTotalLockedBalanceOptions, type UseTotalLockedBalanceResult, type UseTransferOptions, type UseTransferResult, type UseUnlockFundsOptions, type UseUnlockFundsResult, type UseWithdrawOptions, type UseWithdrawResult, ValidationError, WITHDRAW_FROM_LOCK_TYPES, WITHDRAW_TYPES, type WithdrawFromLockMessage, type WithdrawFromLockRequest, type WithdrawMessage, type WithdrawParams, type WithdrawStep, type WithdrawalInfo, type WithdrawalInfoResponse, type WithdrawalNonceResponse, type WithdrawalRequest, applyRefreshResponse, buildHostedAuthSession, buttonVariants, clearHostedAuthPendingTransaction, createDomain, createHostedAuthPendingStorageKey, createHostedAuthState, createHostedAuthStorageKey, createLockExpiry, createPkceChallenge, createPkceVerifier, getAccountingContract, getApiUrl, getChainById, getChainIcon, getChainId, getExplorerAddressUrl, getTokenIcon, isHostedAuthRefreshActive, isHostedAuthSessionActive, normalizeAddress, normalizeHex, parseHostedAuthCallback, persistHostedAuthPendingTransaction, readHostedAuthPendingTransaction, readStoredHostedAuthSession, signLockMessage, signModifyLockMessage, signTransferLockedMessage, signTransferMessage, signWithdrawFromLockMessage, signWithdrawMessage, stripHostedAuthCallbackParams, syncHostedAuthSessionToClient, useBalance, useBatchBalances, useDeposit, useExpiredLocks, useHistory, useHostedRedirectAuth, useLockFunds, useLockedFunds, useModifyLock, usePendingWithdrawals, usePrivanaClient, usePrivanaContext, useSafeAccount, useSafePrivanaContext, useSiweAuth, useTokenInfo, useTokenList, useTotalLockedBalance, useTransfer, useUnlockFunds, useWithdraw };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createContext,
|
|
2
|
+
import { createContext, useContext, useRef, useCallback, useSyncExternalStore, useState, useEffect, useMemo, useId } from 'react';
|
|
3
3
|
import { zeroAddress, erc20Abi, hexToString } from 'viem';
|
|
4
|
+
import { createSiweMessage } from 'viem/siwe';
|
|
5
|
+
import { WagmiContext, useAccount, useWalletClient, useConfig, useWriteContract, useSendTransaction, useChainId, useSwitchChain, useBalance as useBalance$1, useReadContract } from 'wagmi';
|
|
6
|
+
import { watchAccount, getAccount, getWalletClient } from 'wagmi/actions';
|
|
4
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
8
|
import { QueryClientContext, useQuery, useQueryClient, useMutation, keepPreviousData } from '@tanstack/react-query';
|
|
6
9
|
import { clsx } from 'clsx';
|
|
7
10
|
import { twMerge } from 'tailwind-merge';
|
|
8
|
-
import { createSiweMessage } from 'viem/siwe';
|
|
9
|
-
import { WagmiContext, useAccount, useWalletClient, useConfig, useWriteContract, useSendTransaction, useChainId, useSwitchChain, useBalance as useBalance$1, useReadContract } from 'wagmi';
|
|
10
|
-
import { watchAccount, getAccount, getWalletClient } from 'wagmi/actions';
|
|
11
11
|
import { getTransactionReceipt as getTransactionReceipt$1, waitForTransactionReceipt as waitForTransactionReceipt$1, getTransaction, call } from 'viem/actions';
|
|
12
12
|
import { Slot } from '@radix-ui/react-slot';
|
|
13
13
|
import { cva } from 'class-variance-authority';
|
|
@@ -769,6 +769,235 @@ async function signWithdrawFromLockMessage({
|
|
|
769
769
|
});
|
|
770
770
|
return signature;
|
|
771
771
|
}
|
|
772
|
+
var defaultResult = {
|
|
773
|
+
address: void 0,
|
|
774
|
+
isConnected: false,
|
|
775
|
+
status: "disconnected"
|
|
776
|
+
};
|
|
777
|
+
function useSafeAccount() {
|
|
778
|
+
const context = useContext(WagmiContext);
|
|
779
|
+
const cacheRef = useRef(defaultResult);
|
|
780
|
+
const subscribe = useCallback(
|
|
781
|
+
(onChange) => {
|
|
782
|
+
if (!context) return () => {
|
|
783
|
+
};
|
|
784
|
+
return watchAccount(context, { onChange });
|
|
785
|
+
},
|
|
786
|
+
[context]
|
|
787
|
+
);
|
|
788
|
+
const getSnapshot = useCallback(() => {
|
|
789
|
+
if (!context) return defaultResult;
|
|
790
|
+
const account = getAccount(context);
|
|
791
|
+
if (cacheRef.current.address !== account.address || cacheRef.current.isConnected !== account.isConnected || cacheRef.current.status !== account.status) {
|
|
792
|
+
cacheRef.current = {
|
|
793
|
+
address: account.address,
|
|
794
|
+
isConnected: account.isConnected,
|
|
795
|
+
status: account.status
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
return cacheRef.current;
|
|
799
|
+
}, [context]);
|
|
800
|
+
const getServerSnapshot = useCallback(() => defaultResult, []);
|
|
801
|
+
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// src/sdk/hooks/private-read-token-store.ts
|
|
805
|
+
var AUTH_CLOCK_SKEW_MS = 3e4;
|
|
806
|
+
var cache = /* @__PURE__ */ new Map();
|
|
807
|
+
function createScopeKey(apiUrl, chainId, address) {
|
|
808
|
+
return `${apiUrl.replace(/\/$/, "")}:${chainId}:${address.toLowerCase()}`;
|
|
809
|
+
}
|
|
810
|
+
function getCachedPrivateReadToken(scopeKey) {
|
|
811
|
+
const cached = cache.get(scopeKey);
|
|
812
|
+
if (!cached) return null;
|
|
813
|
+
if (cached.expiresAt <= Date.now() + AUTH_CLOCK_SKEW_MS) {
|
|
814
|
+
cache.delete(scopeKey);
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
return cached.token;
|
|
818
|
+
}
|
|
819
|
+
function setCachedPrivateReadToken(scopeKey, token, expiresAt) {
|
|
820
|
+
cache.set(scopeKey, { token, expiresAt });
|
|
821
|
+
}
|
|
822
|
+
function deleteCachedPrivateReadToken(scopeKey) {
|
|
823
|
+
cache.delete(scopeKey);
|
|
824
|
+
}
|
|
825
|
+
var DEFAULT_SIWE_VALIDITY_MS = 24 * 60 * 60 * 1e3;
|
|
826
|
+
var DEFAULT_STATEMENT = "Sign in to access your private account data.";
|
|
827
|
+
var AUTH_REFRESH_SKEW_MS = 3e4;
|
|
828
|
+
var SiweAuthContext = createContext(null);
|
|
829
|
+
function SiweAuthProvider({
|
|
830
|
+
children,
|
|
831
|
+
client,
|
|
832
|
+
networkConfig,
|
|
833
|
+
autoLogin = true,
|
|
834
|
+
statement
|
|
835
|
+
}) {
|
|
836
|
+
const wagmiContext = useContext(WagmiContext);
|
|
837
|
+
const { address, isConnected, status } = useSafeAccount();
|
|
838
|
+
const [session, setSession] = useState(null);
|
|
839
|
+
const [tokens, setTokens] = useState(null);
|
|
840
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
841
|
+
const [error, setError] = useState(null);
|
|
842
|
+
const [accessTokenExpiresAt, setAccessTokenExpiresAt] = useState(null);
|
|
843
|
+
const loginInFlight = useRef(false);
|
|
844
|
+
const autoAttemptedAddress = useRef(null);
|
|
845
|
+
const refreshInFlight = useRef(false);
|
|
846
|
+
const refreshDataRef = useRef(null);
|
|
847
|
+
const clearSession = useCallback(() => {
|
|
848
|
+
refreshDataRef.current = null;
|
|
849
|
+
setAccessTokenExpiresAt(null);
|
|
850
|
+
client.clearPrivateReadToken();
|
|
851
|
+
client.clearBearerToken();
|
|
852
|
+
setSession(null);
|
|
853
|
+
setTokens(null);
|
|
854
|
+
setError(null);
|
|
855
|
+
autoAttemptedAddress.current = null;
|
|
856
|
+
}, [client]);
|
|
857
|
+
const logout = useCallback(async () => {
|
|
858
|
+
setError(null);
|
|
859
|
+
const refreshToken = refreshDataRef.current?.refreshToken;
|
|
860
|
+
try {
|
|
861
|
+
if (refreshToken) {
|
|
862
|
+
await client.logoutJwtSession({ refresh_token: refreshToken });
|
|
863
|
+
}
|
|
864
|
+
} finally {
|
|
865
|
+
clearSession();
|
|
866
|
+
autoAttemptedAddress.current = address ?? null;
|
|
867
|
+
}
|
|
868
|
+
}, [clearSession, client, address]);
|
|
869
|
+
const login = useCallback(async () => {
|
|
870
|
+
if (!wagmiContext) throw new Error("WagmiProvider is required for SIWE auth");
|
|
871
|
+
if (!address) throw new Error("No wallet connected");
|
|
872
|
+
if (loginInFlight.current) return;
|
|
873
|
+
loginInFlight.current = true;
|
|
874
|
+
setIsLoading(true);
|
|
875
|
+
setError(null);
|
|
876
|
+
try {
|
|
877
|
+
const walletClient = await getWalletClient(wagmiContext);
|
|
878
|
+
if (!walletClient) throw new Error("No wallet client available");
|
|
879
|
+
const [{ domain }, nonceRes] = await Promise.all([
|
|
880
|
+
client.getSiweDomain(),
|
|
881
|
+
client.getSiweNonce(address)
|
|
882
|
+
]);
|
|
883
|
+
const issuedAt = /* @__PURE__ */ new Date();
|
|
884
|
+
const expirationTime = new Date(issuedAt.getTime() + DEFAULT_SIWE_VALIDITY_MS);
|
|
885
|
+
const uri = typeof window !== "undefined" && window.location.origin ? window.location.origin : networkConfig.apiUrl;
|
|
886
|
+
const message = createSiweMessage({
|
|
887
|
+
address,
|
|
888
|
+
chainId: networkConfig.chainId,
|
|
889
|
+
domain,
|
|
890
|
+
uri,
|
|
891
|
+
version: "1",
|
|
892
|
+
nonce: nonceRes.nonce,
|
|
893
|
+
statement: statement ?? DEFAULT_STATEMENT,
|
|
894
|
+
issuedAt,
|
|
895
|
+
expirationTime
|
|
896
|
+
});
|
|
897
|
+
const signature = await walletClient.signMessage({
|
|
898
|
+
account: walletClient.account ?? address,
|
|
899
|
+
message
|
|
900
|
+
});
|
|
901
|
+
const res = await client.loginWithSiwe({ siwe_message: message, signature });
|
|
902
|
+
const loggedInAt = Date.now();
|
|
903
|
+
client.setPrivateReadToken(res.siwe_token);
|
|
904
|
+
client.setBearerToken(res.jwt_access_token);
|
|
905
|
+
refreshDataRef.current = {
|
|
906
|
+
refreshToken: res.jwt_refresh_token,
|
|
907
|
+
refreshExpiresAt: loggedInAt + res.jwt_refresh_expires_in * 1e3
|
|
908
|
+
};
|
|
909
|
+
setCachedPrivateReadToken(
|
|
910
|
+
createScopeKey(networkConfig.apiUrl, networkConfig.chainId, address),
|
|
911
|
+
res.siwe_token,
|
|
912
|
+
expirationTime.getTime()
|
|
913
|
+
);
|
|
914
|
+
setSession({ address: res.address });
|
|
915
|
+
setTokens({
|
|
916
|
+
siwe_token: res.siwe_token,
|
|
917
|
+
jwt_access_token: res.jwt_access_token,
|
|
918
|
+
jwt_refresh_token: res.jwt_refresh_token,
|
|
919
|
+
address: res.address
|
|
920
|
+
});
|
|
921
|
+
setAccessTokenExpiresAt(loggedInAt + res.jwt_expires_in * 1e3);
|
|
922
|
+
} catch (err) {
|
|
923
|
+
setError(err instanceof Error ? err : new Error("Sign-in failed"));
|
|
924
|
+
throw err;
|
|
925
|
+
} finally {
|
|
926
|
+
setIsLoading(false);
|
|
927
|
+
loginInFlight.current = false;
|
|
928
|
+
}
|
|
929
|
+
}, [wagmiContext, address, client, networkConfig.chainId, networkConfig.apiUrl, statement]);
|
|
930
|
+
const refreshAccessToken = useCallback(async () => {
|
|
931
|
+
const data = refreshDataRef.current;
|
|
932
|
+
if (!data || refreshInFlight.current) return;
|
|
933
|
+
if (Date.now() >= data.refreshExpiresAt - AUTH_REFRESH_SKEW_MS) {
|
|
934
|
+
clearSession();
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
refreshInFlight.current = true;
|
|
938
|
+
try {
|
|
939
|
+
const res = await client.refreshJwtSession({ refresh_token: data.refreshToken });
|
|
940
|
+
const refreshedAt = Date.now();
|
|
941
|
+
client.setBearerToken(res.token);
|
|
942
|
+
refreshDataRef.current = {
|
|
943
|
+
refreshToken: res.refresh_token,
|
|
944
|
+
refreshExpiresAt: refreshedAt + res.refresh_expires_in * 1e3
|
|
945
|
+
};
|
|
946
|
+
setTokens(
|
|
947
|
+
(prev) => prev ? { ...prev, jwt_access_token: res.token, jwt_refresh_token: res.refresh_token } : prev
|
|
948
|
+
);
|
|
949
|
+
setAccessTokenExpiresAt(refreshedAt + res.expires_in * 1e3);
|
|
950
|
+
} catch {
|
|
951
|
+
clearSession();
|
|
952
|
+
} finally {
|
|
953
|
+
refreshInFlight.current = false;
|
|
954
|
+
}
|
|
955
|
+
}, [client, clearSession]);
|
|
956
|
+
useEffect(() => {
|
|
957
|
+
if (accessTokenExpiresAt == null) return;
|
|
958
|
+
const delay = Math.max(accessTokenExpiresAt - AUTH_REFRESH_SKEW_MS - Date.now(), 0);
|
|
959
|
+
const timer = setTimeout(() => {
|
|
960
|
+
void refreshAccessToken();
|
|
961
|
+
}, delay);
|
|
962
|
+
return () => clearTimeout(timer);
|
|
963
|
+
}, [accessTokenExpiresAt, refreshAccessToken]);
|
|
964
|
+
useEffect(() => {
|
|
965
|
+
if (!autoLogin) return;
|
|
966
|
+
if (status === "connecting" || status === "reconnecting") return;
|
|
967
|
+
if (!isConnected && session) {
|
|
968
|
+
clearSession();
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
971
|
+
if (isConnected && address && session && address.toLowerCase() !== session.address.toLowerCase()) {
|
|
972
|
+
clearSession();
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
if (isConnected && address && !session && !isLoading && autoAttemptedAddress.current !== address) {
|
|
976
|
+
autoAttemptedAddress.current = address;
|
|
977
|
+
void login().catch(() => {
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
}, [autoLogin, status, isConnected, address, session, isLoading, login, clearSession]);
|
|
981
|
+
const value = useMemo(
|
|
982
|
+
() => ({
|
|
983
|
+
isAuthenticated: !!session,
|
|
984
|
+
isLoading,
|
|
985
|
+
error,
|
|
986
|
+
session,
|
|
987
|
+
accessToken: tokens?.jwt_access_token,
|
|
988
|
+
tokens,
|
|
989
|
+
login,
|
|
990
|
+
logout
|
|
991
|
+
}),
|
|
992
|
+
[session, isLoading, error, tokens, login, logout]
|
|
993
|
+
);
|
|
994
|
+
return /* @__PURE__ */ jsx(SiweAuthContext.Provider, { value, children });
|
|
995
|
+
}
|
|
996
|
+
function useSiweAuth() {
|
|
997
|
+
const ctx = useContext(SiweAuthContext);
|
|
998
|
+
if (!ctx) throw new Error("useSiweAuth must be used within SiweAuthProvider");
|
|
999
|
+
return ctx;
|
|
1000
|
+
}
|
|
772
1001
|
var PrivanaContext = createContext(null);
|
|
773
1002
|
function readStoredHostedAuthSession(storage, hostedAuthStorageKey, now = Date.now()) {
|
|
774
1003
|
const raw = storage.getItem(hostedAuthStorageKey);
|
|
@@ -809,8 +1038,14 @@ function PrivanaProvider({
|
|
|
809
1038
|
chains,
|
|
810
1039
|
pollingInterval = 1e4,
|
|
811
1040
|
serviceAddress,
|
|
812
|
-
hostedAuth
|
|
1041
|
+
hostedAuth,
|
|
1042
|
+
siweAuth
|
|
813
1043
|
}) {
|
|
1044
|
+
if (hostedAuth && siweAuth) {
|
|
1045
|
+
throw new Error(
|
|
1046
|
+
"PrivanaProvider: `hostedAuth` and `siweAuth` are mutually exclusive - provide only one. When both are set, private reads use hosted auth and the in-app SIWE login is ignored."
|
|
1047
|
+
);
|
|
1048
|
+
}
|
|
814
1049
|
const networkConfig = useMemo(() => {
|
|
815
1050
|
const config = {
|
|
816
1051
|
...DEFAULT_NETWORK_CONFIG,
|
|
@@ -1045,7 +1280,16 @@ function PrivanaProvider({
|
|
|
1045
1280
|
refreshHostedAuthSession
|
|
1046
1281
|
]
|
|
1047
1282
|
);
|
|
1048
|
-
return /* @__PURE__ */ jsx(PrivanaContext.Provider, { value, children
|
|
1283
|
+
return /* @__PURE__ */ jsx(PrivanaContext.Provider, { value, children: siweAuth ? /* @__PURE__ */ jsx(
|
|
1284
|
+
SiweAuthProvider,
|
|
1285
|
+
{
|
|
1286
|
+
client,
|
|
1287
|
+
networkConfig,
|
|
1288
|
+
autoLogin: siweAuth.autoLogin,
|
|
1289
|
+
statement: siweAuth.statement,
|
|
1290
|
+
children
|
|
1291
|
+
}
|
|
1292
|
+
) : children });
|
|
1049
1293
|
}
|
|
1050
1294
|
function usePrivanaContext() {
|
|
1051
1295
|
const context = useContext(PrivanaContext);
|
|
@@ -1305,40 +1549,10 @@ function formatTimeRemaining(expiryTimestamp) {
|
|
|
1305
1549
|
}
|
|
1306
1550
|
return `${minutes}m left`;
|
|
1307
1551
|
}
|
|
1308
|
-
var defaultResult = {
|
|
1309
|
-
address: void 0,
|
|
1310
|
-
isConnected: false
|
|
1311
|
-
};
|
|
1312
|
-
function useSafeAccount() {
|
|
1313
|
-
const context = useContext(WagmiContext);
|
|
1314
|
-
const cacheRef = useRef(defaultResult);
|
|
1315
|
-
const subscribe = useCallback(
|
|
1316
|
-
(onChange) => {
|
|
1317
|
-
if (!context) return () => {
|
|
1318
|
-
};
|
|
1319
|
-
return watchAccount(context, { onChange });
|
|
1320
|
-
},
|
|
1321
|
-
[context]
|
|
1322
|
-
);
|
|
1323
|
-
const getSnapshot = useCallback(() => {
|
|
1324
|
-
if (!context) return defaultResult;
|
|
1325
|
-
const account = getAccount(context);
|
|
1326
|
-
if (cacheRef.current.address !== account.address || cacheRef.current.isConnected !== account.isConnected) {
|
|
1327
|
-
cacheRef.current = { address: account.address, isConnected: account.isConnected };
|
|
1328
|
-
}
|
|
1329
|
-
return cacheRef.current;
|
|
1330
|
-
}, [context]);
|
|
1331
|
-
const getServerSnapshot = useCallback(() => defaultResult, []);
|
|
1332
|
-
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
// src/sdk/hooks/use-private-read-request.ts
|
|
1336
|
-
var AUTH_CLOCK_SKEW_MS = 3e4;
|
|
1337
1552
|
var INITIAL_AUTH_BACKOFF_MS = 5e3;
|
|
1338
1553
|
var MAX_AUTH_BACKOFF_MS = 6e4;
|
|
1339
1554
|
var DEFAULT_SIWE_AUTH_VALIDITY_MS = 24 * 60 * 60 * 1e3;
|
|
1340
1555
|
var PRIVATE_READ_STATEMENT = "Sign in to Privana to access private account data.";
|
|
1341
|
-
var privateReadTokenCache = /* @__PURE__ */ new Map();
|
|
1342
1556
|
var privateReadFailureCache = /* @__PURE__ */ new Map();
|
|
1343
1557
|
var privateReadInflight = /* @__PURE__ */ new Map();
|
|
1344
1558
|
async function executeHostedAuthPrivateReadRequest({
|
|
@@ -1372,20 +1586,8 @@ async function executeHostedAuthPrivateReadRequest({
|
|
|
1372
1586
|
return request();
|
|
1373
1587
|
}
|
|
1374
1588
|
}
|
|
1375
|
-
function createScopeKey(apiUrl, deploymentChainId, address) {
|
|
1376
|
-
return `${apiUrl.replace(/\/$/, "")}:${deploymentChainId}:${address.toLowerCase()}`;
|
|
1377
|
-
}
|
|
1378
|
-
function getCachedPrivateReadToken(scopeKey) {
|
|
1379
|
-
const cached = privateReadTokenCache.get(scopeKey);
|
|
1380
|
-
if (!cached) return null;
|
|
1381
|
-
if (cached.expiresAt <= Date.now() + AUTH_CLOCK_SKEW_MS) {
|
|
1382
|
-
privateReadTokenCache.delete(scopeKey);
|
|
1383
|
-
return null;
|
|
1384
|
-
}
|
|
1385
|
-
return cached.token;
|
|
1386
|
-
}
|
|
1387
1589
|
function clearPrivateReadScope(scopeKey, client) {
|
|
1388
|
-
|
|
1590
|
+
deleteCachedPrivateReadToken(scopeKey);
|
|
1389
1591
|
privateReadFailureCache.delete(scopeKey);
|
|
1390
1592
|
client.clearPrivateReadToken();
|
|
1391
1593
|
}
|
|
@@ -1484,10 +1686,7 @@ function usePrivateReadRequest() {
|
|
|
1484
1686
|
siwe_message: message,
|
|
1485
1687
|
signature
|
|
1486
1688
|
});
|
|
1487
|
-
|
|
1488
|
-
token: login.siwe_token,
|
|
1489
|
-
expiresAt: expirationTime.getTime()
|
|
1490
|
-
});
|
|
1689
|
+
setCachedPrivateReadToken(scopeKey, login.siwe_token, expirationTime.getTime());
|
|
1491
1690
|
privateReadFailureCache.delete(scopeKey);
|
|
1492
1691
|
client.setPrivateReadToken(login.siwe_token);
|
|
1493
1692
|
return login.siwe_token;
|
|
@@ -4437,6 +4636,6 @@ function Skeleton({ className, ...props }) {
|
|
|
4437
4636
|
);
|
|
4438
4637
|
}
|
|
4439
4638
|
|
|
4440
|
-
export { AccountingApiError, Button, HOSTED_AUTH_CLOCK_SKEW_MS, HostedAuthError, HostedAuthRequiredError, HostedAuthStateMismatchError, HttpClient, LOCK_TYPES, MODIFY_LOCK_TYPES, NETWORK_CONFIG, NetworkError, PrivanaButton, PrivanaClient, PrivanaInlineModal, PrivanaModal, PrivanaProvider, SUPPORTED_CHAINS, Skeleton, TRANSFER_LOCKED_TYPES, TRANSFER_TYPES, ValidationError, WITHDRAW_FROM_LOCK_TYPES, WITHDRAW_TYPES, applyRefreshResponse, buildHostedAuthSession, buttonVariants, clearHostedAuthPendingTransaction, createDomain, createHostedAuthPendingStorageKey, createHostedAuthState, createHostedAuthStorageKey, createLockExpiry, createPkceChallenge, createPkceVerifier, getAccountingContract, getApiUrl, getChainById, getChainIcon, getChainId, getExplorerAddressUrl, getTokenIcon, isHostedAuthRefreshActive, isHostedAuthSessionActive, normalizeAddress, normalizeHex, parseHostedAuthCallback, persistHostedAuthPendingTransaction, readHostedAuthPendingTransaction, readStoredHostedAuthSession, signLockMessage, signModifyLockMessage, signTransferLockedMessage, signTransferMessage, signWithdrawFromLockMessage, signWithdrawMessage, stripHostedAuthCallbackParams, syncHostedAuthSessionToClient, useBalance, useBatchBalances, useDeposit, useExpiredLocks, useHistory, useHostedRedirectAuth, useLockFunds, useLockedFunds, useModifyLock, usePendingWithdrawals, usePrivanaClient, usePrivanaContext, useSafeAccount, useSafePrivanaContext, useTokenInfo, useTokenList, useTotalLockedBalance, useTransfer, useUnlockFunds, useWithdraw };
|
|
4639
|
+
export { AccountingApiError, Button, HOSTED_AUTH_CLOCK_SKEW_MS, HostedAuthError, HostedAuthRequiredError, HostedAuthStateMismatchError, HttpClient, LOCK_TYPES, MODIFY_LOCK_TYPES, NETWORK_CONFIG, NetworkError, PrivanaButton, PrivanaClient, PrivanaInlineModal, PrivanaModal, PrivanaProvider, SUPPORTED_CHAINS, SiweAuthProvider, Skeleton, TRANSFER_LOCKED_TYPES, TRANSFER_TYPES, ValidationError, WITHDRAW_FROM_LOCK_TYPES, WITHDRAW_TYPES, applyRefreshResponse, buildHostedAuthSession, buttonVariants, clearHostedAuthPendingTransaction, createDomain, createHostedAuthPendingStorageKey, createHostedAuthState, createHostedAuthStorageKey, createLockExpiry, createPkceChallenge, createPkceVerifier, getAccountingContract, getApiUrl, getChainById, getChainIcon, getChainId, getExplorerAddressUrl, getTokenIcon, isHostedAuthRefreshActive, isHostedAuthSessionActive, normalizeAddress, normalizeHex, parseHostedAuthCallback, persistHostedAuthPendingTransaction, readHostedAuthPendingTransaction, readStoredHostedAuthSession, signLockMessage, signModifyLockMessage, signTransferLockedMessage, signTransferMessage, signWithdrawFromLockMessage, signWithdrawMessage, stripHostedAuthCallbackParams, syncHostedAuthSessionToClient, useBalance, useBatchBalances, useDeposit, useExpiredLocks, useHistory, useHostedRedirectAuth, useLockFunds, useLockedFunds, useModifyLock, usePendingWithdrawals, usePrivanaClient, usePrivanaContext, useSafeAccount, useSafePrivanaContext, useSiweAuth, useTokenInfo, useTokenList, useTotalLockedBalance, useTransfer, useUnlockFunds, useWithdraw };
|
|
4441
4640
|
//# sourceMappingURL=index.js.map
|
|
4442
4641
|
//# sourceMappingURL=index.js.map
|