@account-kit/privy-integration 4.73.1-alpha.9 → 4.75.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.
Files changed (105) hide show
  1. package/README.md +61 -21
  2. package/dist/esm/Provider.d.ts +71 -4
  3. package/dist/esm/Provider.js +109 -4
  4. package/dist/esm/Provider.js.map +1 -1
  5. package/dist/esm/hooks/internal/useEmbeddedWallet.d.ts +4 -3
  6. package/dist/esm/hooks/internal/useEmbeddedWallet.js +13 -5
  7. package/dist/esm/hooks/internal/useEmbeddedWallet.js.map +1 -1
  8. package/dist/esm/hooks/useAlchemyClient.d.ts +10 -5
  9. package/dist/esm/hooks/useAlchemyClient.js +46 -25
  10. package/dist/esm/hooks/useAlchemyClient.js.map +1 -1
  11. package/dist/esm/hooks/useAlchemyPrepareSwap.js +3 -6
  12. package/dist/esm/hooks/useAlchemyPrepareSwap.js.map +1 -1
  13. package/dist/esm/hooks/useAlchemySendTransaction.js +12 -10
  14. package/dist/esm/hooks/useAlchemySendTransaction.js.map +1 -1
  15. package/dist/esm/hooks/useAlchemySolanaTransaction.js +1 -1
  16. package/dist/esm/hooks/useAlchemySolanaTransaction.js.map +1 -1
  17. package/dist/esm/hooks/useAlchemySubmitSwap.js +1 -1
  18. package/dist/esm/hooks/useAlchemySubmitSwap.js.map +1 -1
  19. package/dist/esm/types.d.ts +6 -0
  20. package/dist/esm/types.js.map +1 -1
  21. package/dist/esm/version.d.ts +1 -1
  22. package/dist/esm/version.js +1 -1
  23. package/dist/esm/version.js.map +1 -1
  24. package/dist/types/Provider.d.ts +71 -4
  25. package/dist/types/Provider.d.ts.map +1 -1
  26. package/dist/types/hooks/internal/useEmbeddedWallet.d.ts +4 -3
  27. package/dist/types/hooks/internal/useEmbeddedWallet.d.ts.map +1 -1
  28. package/dist/types/hooks/useAlchemyClient.d.ts +10 -5
  29. package/dist/types/hooks/useAlchemyClient.d.ts.map +1 -1
  30. package/dist/types/hooks/useAlchemyPrepareSwap.d.ts.map +1 -1
  31. package/dist/types/hooks/useAlchemySendTransaction.d.ts.map +1 -1
  32. package/dist/types/types.d.ts +6 -0
  33. package/dist/types/types.d.ts.map +1 -1
  34. package/dist/types/version.d.ts +1 -1
  35. package/dist/types/version.d.ts.map +1 -1
  36. package/package.json +4 -27
  37. package/src/hooks/internal/useEmbeddedWallet.ts +20 -5
  38. package/src/hooks/useAlchemyClient.ts +71 -35
  39. package/src/hooks/useAlchemyPrepareSwap.ts +3 -6
  40. package/src/hooks/useAlchemySendTransaction.ts +17 -14
  41. package/src/hooks/useAlchemySolanaTransaction.ts +1 -1
  42. package/src/hooks/useAlchemySubmitSwap.ts +1 -1
  43. package/src/types.ts +7 -0
  44. package/src/version.ts +1 -1
  45. package/dist/esm/Provider.native.d.ts +0 -6
  46. package/dist/esm/Provider.native.js +0 -13
  47. package/dist/esm/Provider.native.js.map +0 -1
  48. package/dist/esm/adapters/react-native.d.ts +0 -6
  49. package/dist/esm/adapters/react-native.js +0 -130
  50. package/dist/esm/adapters/react-native.js.map +0 -1
  51. package/dist/esm/adapters/types.d.ts +0 -44
  52. package/dist/esm/adapters/types.js +0 -2
  53. package/dist/esm/adapters/types.js.map +0 -1
  54. package/dist/esm/adapters/web.d.ts +0 -6
  55. package/dist/esm/adapters/web.js +0 -50
  56. package/dist/esm/adapters/web.js.map +0 -1
  57. package/dist/esm/adapters/web.native.d.ts +0 -5
  58. package/dist/esm/adapters/web.native.js +0 -6
  59. package/dist/esm/adapters/web.native.js.map +0 -1
  60. package/dist/esm/context/AlchemyContext.d.ts +0 -62
  61. package/dist/esm/context/AlchemyContext.js +0 -105
  62. package/dist/esm/context/AlchemyContext.js.map +0 -1
  63. package/dist/esm/providers/ReactNativeProvider.d.ts +0 -33
  64. package/dist/esm/providers/ReactNativeProvider.js +0 -37
  65. package/dist/esm/providers/ReactNativeProvider.js.map +0 -1
  66. package/dist/esm/providers/WebProvider.d.ts +0 -33
  67. package/dist/esm/providers/WebProvider.js +0 -37
  68. package/dist/esm/providers/WebProvider.js.map +0 -1
  69. package/dist/esm/providers/WebProvider.native.d.ts +0 -5
  70. package/dist/esm/providers/WebProvider.native.js +0 -9
  71. package/dist/esm/providers/WebProvider.native.js.map +0 -1
  72. package/dist/esm/react-native.d.ts +0 -11
  73. package/dist/esm/react-native.js +0 -13
  74. package/dist/esm/react-native.js.map +0 -1
  75. package/dist/types/Provider.native.d.ts +0 -7
  76. package/dist/types/Provider.native.d.ts.map +0 -1
  77. package/dist/types/adapters/react-native.d.ts +0 -7
  78. package/dist/types/adapters/react-native.d.ts.map +0 -1
  79. package/dist/types/adapters/types.d.ts +0 -45
  80. package/dist/types/adapters/types.d.ts.map +0 -1
  81. package/dist/types/adapters/web.d.ts +0 -7
  82. package/dist/types/adapters/web.d.ts.map +0 -1
  83. package/dist/types/adapters/web.native.d.ts +0 -6
  84. package/dist/types/adapters/web.native.d.ts.map +0 -1
  85. package/dist/types/context/AlchemyContext.d.ts +0 -63
  86. package/dist/types/context/AlchemyContext.d.ts.map +0 -1
  87. package/dist/types/providers/ReactNativeProvider.d.ts +0 -34
  88. package/dist/types/providers/ReactNativeProvider.d.ts.map +0 -1
  89. package/dist/types/providers/WebProvider.d.ts +0 -34
  90. package/dist/types/providers/WebProvider.d.ts.map +0 -1
  91. package/dist/types/providers/WebProvider.native.d.ts +0 -6
  92. package/dist/types/providers/WebProvider.native.d.ts.map +0 -1
  93. package/dist/types/react-native.d.ts +0 -12
  94. package/dist/types/react-native.d.ts.map +0 -1
  95. package/src/Provider.native.tsx +0 -18
  96. package/src/Provider.tsx +0 -6
  97. package/src/adapters/react-native.ts +0 -190
  98. package/src/adapters/types.ts +0 -56
  99. package/src/adapters/web.native.ts +0 -6
  100. package/src/adapters/web.ts +0 -73
  101. package/src/context/AlchemyContext.tsx +0 -162
  102. package/src/providers/ReactNativeProvider.tsx +0 -45
  103. package/src/providers/WebProvider.native.tsx +0 -11
  104. package/src/providers/WebProvider.tsx +0 -45
  105. package/src/react-native.ts +0 -29
@@ -1 +0,0 @@
1
- {"version":3,"file":"web.native.d.ts","sourceRoot":"","sources":["../../../src/adapters/web.native.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,UAAU,MAAO,CAAC"}
@@ -1,63 +0,0 @@
1
- import { type PropsWithChildren } from "react";
2
- import type { SmartWalletClient } from "@account-kit/wallet-client";
3
- import type { AlchemyProviderConfig } from "../types.js";
4
- import type { PrivyAdapter } from "../adapters/types.js";
5
- /**
6
- * Client cache stored in React tree (similar to QueryClient in React Query)
7
- *
8
- * @internal
9
- */
10
- interface ClientCache {
11
- client: SmartWalletClient | null;
12
- cacheKey: string | null;
13
- }
14
- /**
15
- * Props for AlchemyContextProvider
16
- */
17
- interface AlchemyContextProviderProps extends PropsWithChildren {
18
- config: AlchemyProviderConfig;
19
- adapter: PrivyAdapter;
20
- }
21
- /**
22
- * Internal provider component that manages Alchemy context
23
- * Used by both web and React Native providers
24
- *
25
- * @internal
26
- * @param {AlchemyContextProviderProps} props - Component props
27
- * @param {React.ReactNode} props.children - React children to wrap with context
28
- * @param {AlchemyProviderConfig} props.config - Alchemy configuration
29
- * @param {PrivyAdapter} props.adapter - Platform adapter
30
- * @returns {JSX.Element} Context provider component
31
- */
32
- export declare function AlchemyContextProvider({ children, config, adapter, }: AlchemyContextProviderProps): import("react/jsx-runtime").JSX.Element;
33
- /**
34
- * Hook to access Alchemy provider configuration
35
- * Must be used within an <AlchemyProvider> component
36
- *
37
- * @returns {AlchemyProviderConfig} The current Alchemy configuration
38
- * @throws {Error} If used outside of AlchemyProvider
39
- *
40
- * @example
41
- * ```tsx
42
- * const config = useAlchemyConfig();
43
- * console.log('Policy ID:', config.policyId);
44
- * ```
45
- */
46
- export declare function useAlchemyConfig(): AlchemyProviderConfig;
47
- /**
48
- * Hook to access the platform adapter
49
- * Must be used within an <AlchemyProvider> component
50
- *
51
- * @internal
52
- * @returns {PrivyAdapter} The platform adapter
53
- */
54
- export declare function useAdapter(): PrivyAdapter;
55
- /**
56
- * Hook to access the client cache (internal use only)
57
- *
58
- * @internal
59
- * @returns {ClientCache} The client cache object
60
- */
61
- export declare function useClientCache(): ClientCache;
62
- export {};
63
- //# sourceMappingURL=AlchemyContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AlchemyContext.d.ts","sourceRoot":"","sources":["../../../src/context/AlchemyContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EAKvB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAYzD;;;;GAIG;AACH,UAAU,WAAW;IACnB,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAID;;GAEG;AACH,UAAU,2BAA4B,SAAQ,iBAAiB;IAC7D,MAAM,EAAE,qBAAqB,CAAC;IAC9B,OAAO,EAAE,YAAY,CAAC;CACvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE,2BAA2B,2CAmD7B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,qBAAqB,CAMxD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,YAAY,CAQzC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAQ5C"}
@@ -1,34 +0,0 @@
1
- import type { PropsWithChildren } from "react";
2
- import type { AlchemyProviderConfig } from "../types.js";
3
- /**
4
- * Provider component for React Native (Expo) applications
5
- * Must be nested INSIDE PrivyProvider from @privy-io/expo
6
- *
7
- * @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props
8
- * @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration
9
- * @param {string} [props.apiKey] - Your Alchemy API key
10
- * @param {string} [props.jwt] - JWT token for authentication
11
- * @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains
12
- * @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana
13
- * @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains
14
- * @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana
15
- * @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)
16
- * @returns {JSX.Element} Provider component
17
- *
18
- * @example
19
- * ```tsx
20
- * import { PrivyProvider } from '@privy-io/expo';
21
- * import { AlchemyProvider } from '@account-kit/privy-integration/react-native';
22
- *
23
- * <PrivyProvider appId="..." clientId="...">
24
- * <AlchemyProvider
25
- * apiKey="your-alchemy-api-key"
26
- * policyId="your-gas-policy-id"
27
- * >
28
- * <YourApp />
29
- * </AlchemyProvider>
30
- * </PrivyProvider>
31
- * ```
32
- */
33
- export declare function AlchemyProvider({ children, ...config }: PropsWithChildren<AlchemyProviderConfig>): import("react/jsx-runtime").JSX.Element;
34
- //# sourceMappingURL=ReactNativeProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ReactNativeProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/ReactNativeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,GAAG,MAAM,EACV,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,2CAM1C"}
@@ -1,34 +0,0 @@
1
- import type { PropsWithChildren } from "react";
2
- import type { AlchemyProviderConfig } from "../types.js";
3
- /**
4
- * Provider component for React web applications
5
- * Must be nested INSIDE PrivyProvider from @privy-io/react-auth
6
- *
7
- * @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props
8
- * @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration
9
- * @param {string} [props.apiKey] - Your Alchemy API key
10
- * @param {string} [props.jwt] - JWT token for authentication
11
- * @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains
12
- * @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana
13
- * @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains
14
- * @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana
15
- * @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)
16
- * @returns {JSX.Element} Provider component
17
- *
18
- * @example
19
- * ```tsx
20
- * import { PrivyProvider } from '@privy-io/react-auth';
21
- * import { AlchemyProvider } from '@account-kit/privy-integration';
22
- *
23
- * <PrivyProvider appId="...">
24
- * <AlchemyProvider
25
- * apiKey="your-alchemy-api-key"
26
- * policyId="your-gas-policy-id"
27
- * >
28
- * <YourApp />
29
- * </AlchemyProvider>
30
- * </PrivyProvider>
31
- * ```
32
- */
33
- export declare function AlchemyProvider({ children, ...config }: PropsWithChildren<AlchemyProviderConfig>): import("react/jsx-runtime").JSX.Element;
34
- //# sourceMappingURL=WebProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/WebProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,GAAG,MAAM,EACV,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,2CAM1C"}
@@ -1,6 +0,0 @@
1
- /**
2
- * React Native stub for WebProvider
3
- * This file prevents Metro from importing web-specific code
4
- */
5
- export declare function AlchemyProvider(): void;
6
- //# sourceMappingURL=WebProvider.native.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebProvider.native.d.ts","sourceRoot":"","sources":["../../../src/providers/WebProvider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,eAAe,SAK9B"}
@@ -1,12 +0,0 @@
1
- /**
2
- * React Native (Expo) entry point
3
- * Import from '@account-kit/privy-integration/react-native' in Expo apps
4
- */
5
- export { AlchemyProvider } from "./providers/ReactNativeProvider.js";
6
- export { useAlchemyConfig } from "./context/AlchemyContext.js";
7
- export { useAlchemyClient } from "./hooks/useAlchemyClient.js";
8
- export { useAlchemySendTransaction } from "./hooks/useAlchemySendTransaction.js";
9
- export { useAlchemyPrepareSwap } from "./hooks/useAlchemyPrepareSwap.js";
10
- export { useAlchemySubmitSwap } from "./hooks/useAlchemySubmitSwap.js";
11
- export type { AlchemyProviderConfig, UnsignedTransactionRequest, SendTransactionOptions, SendTransactionResult, UseSendTransactionResult, PrepareSwapRequest, PrepareSwapResult, UsePrepareSwapResult, SubmitSwapResult, UseSubmitSwapResult, SwapQuote, } from "./types.js";
12
- //# sourceMappingURL=react-native.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-native.d.ts","sourceRoot":"","sources":["../../src/react-native.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,YAAY,EACV,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,SAAS,GACV,MAAM,YAAY,CAAC"}
@@ -1,18 +0,0 @@
1
- /**
2
- * React Native stub for web Provider
3
- * This file prevents Metro from importing web-specific code
4
- */
5
-
6
- export function AlchemyProvider() {
7
- throw new Error(
8
- "Web Provider is not available in React Native. " +
9
- 'Import from "@account-kit/privy-integration/react-native" instead.',
10
- );
11
- }
12
-
13
- export function useAlchemyConfig() {
14
- throw new Error(
15
- "useAlchemyConfig from web Provider is not available in React Native. " +
16
- 'Import from "@account-kit/privy-integration/react-native" instead.',
17
- );
18
- }
package/src/Provider.tsx DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Web-specific exports
3
- * Re-exports the web provider and hooks for React applications
4
- */
5
- export { AlchemyProvider } from "./providers/WebProvider.js";
6
- export { useAlchemyConfig } from "./context/AlchemyContext.js";
@@ -1,190 +0,0 @@
1
- import { useCallback } from "react";
2
- import {
3
- usePrivy,
4
- useEmbeddedEthereumWallet,
5
- type PrivyEmbeddedWalletProvider,
6
- } from "@privy-io/expo";
7
- import type { Authorization } from "viem";
8
- import type { AuthorizationRequest } from "@aa-sdk/core";
9
- import type { PrivyAdapter, EmbeddedWallet, PrivyAuthState } from "./types.js";
10
-
11
- /**
12
- * Wallet type from @privy-io/expo
13
- * Based on the example app structure
14
- */
15
- interface ExpoEmbeddedWallet {
16
- address: string;
17
- chainId?: string;
18
- getProvider?: () => Promise<PrivyEmbeddedWalletProvider>;
19
- }
20
-
21
- /**
22
- * React Native (Expo) adapter for @privy-io/expo
23
- * Implements platform-specific hooks for React Native applications
24
- */
25
- export const reactNativeAdapter: PrivyAdapter = {
26
- useEmbeddedWallet() {
27
- const { wallets } = useEmbeddedEthereumWallet();
28
-
29
- const getEmbeddedWallet = useCallback((): EmbeddedWallet => {
30
- const wallet = wallets?.[0];
31
- if (!wallet) {
32
- throw new Error(
33
- "Privy embedded wallet not found. Please ensure the user is authenticated and has created a wallet.",
34
- );
35
- }
36
-
37
- return adaptExpoWallet(wallet);
38
- }, [wallets]);
39
-
40
- return getEmbeddedWallet;
41
- },
42
-
43
- usePrivyAuth(): PrivyAuthState {
44
- const { user } = usePrivy();
45
- return { authenticated: !!user, user };
46
- },
47
-
48
- useAuthorizationSigner() {
49
- const { wallets } = useEmbeddedEthereumWallet();
50
-
51
- // Don't memoize the callback - create it fresh each time to ensure we have the latest wallets
52
- const signAuthorization = async (
53
- unsignedAuth: AuthorizationRequest<number>,
54
- ): Promise<Authorization<number, true>> => {
55
- console.log("[RN Adapter] signAuthorization called with:", unsignedAuth);
56
- console.log("[RN Adapter] Current wallets:", wallets);
57
-
58
- const wallet = wallets?.[0];
59
- if (!wallet) {
60
- throw new Error(
61
- "Privy embedded wallet not found. Please ensure the user is authenticated and has created a wallet.",
62
- );
63
- }
64
-
65
- console.log("[RN Adapter] Using wallet:", wallet.address);
66
-
67
- const provider = await wallet.getProvider?.();
68
- if (!provider) {
69
- throw new Error(
70
- "Provider not available on this wallet. Ensure you're using the embedded Ethereum wallet.",
71
- );
72
- }
73
-
74
- // Extract the implementation address (handle both 'address' and 'contractAddress' fields)
75
- const implementationAddress =
76
- unsignedAuth.address ?? unsignedAuth.contractAddress;
77
-
78
- if (!implementationAddress) {
79
- throw new Error(
80
- "Implementation address is required for EIP-7702 authorization",
81
- );
82
- }
83
-
84
- console.log(
85
- "[RN Adapter] Signing 7702 auth for address:",
86
- implementationAddress,
87
- );
88
-
89
- // EIP-7702 Authorization structure
90
- const authorization = {
91
- domain: {
92
- name: "EIP-7702",
93
- version: "1",
94
- chainId: unsignedAuth.chainId,
95
- },
96
- types: {
97
- Authorization: [
98
- { name: "chainId", type: "uint256" },
99
- { name: "address", type: "address" },
100
- { name: "nonce", type: "uint256" },
101
- ],
102
- },
103
- primaryType: "Authorization" as const,
104
- message: {
105
- chainId: unsignedAuth.chainId,
106
- address: implementationAddress,
107
- nonce: unsignedAuth.nonce,
108
- },
109
- };
110
-
111
- const signature = (await provider.request({
112
- method: "eth_signTypedData_v4",
113
- params: [wallet.address, JSON.stringify(authorization)],
114
- })) as `0x${string}`;
115
-
116
- console.log("[RN Adapter] Received signature:", signature);
117
-
118
- // Parse the signature into r, s, v components
119
- // Signature format: 0x[r(64)][s(64)][v(2)]
120
- const r = `0x${signature.slice(2, 66)}` as `0x${string}`;
121
- const s = `0x${signature.slice(66, 130)}` as `0x${string}`;
122
- const v = parseInt(signature.slice(130, 132), 16);
123
-
124
- // Convert v to yParity (0 or 1)
125
- // v can be 27/28 (legacy) or 0/1 (EIP-155)
126
- const yParity = v >= 27 ? v - 27 : v;
127
-
128
- const result = {
129
- chainId: unsignedAuth.chainId,
130
- address: implementationAddress,
131
- nonce: unsignedAuth.nonce,
132
- r,
133
- s,
134
- yParity,
135
- };
136
-
137
- console.log("[RN Adapter] Returning authorization:", result);
138
- return result;
139
- };
140
-
141
- return signAuthorization;
142
- },
143
- };
144
-
145
- /**
146
- * Adapts an Expo wallet to the common EmbeddedWallet interface
147
- *
148
- * @param {ExpoEmbeddedWallet} wallet - The Expo embedded wallet to adapt
149
- * @returns {EmbeddedWallet} The adapted wallet following the common interface
150
- */
151
- function adaptExpoWallet(wallet: ExpoEmbeddedWallet): EmbeddedWallet {
152
- // Use closure to maintain up-to-date chain ID across chain switches
153
- let cachedChainId = wallet.chainId || "1";
154
-
155
- return {
156
- address: wallet.address as `0x${string}`,
157
- get chainId() {
158
- return cachedChainId;
159
- },
160
- getEthereumProvider: async () => {
161
- if (!wallet.getProvider) {
162
- throw new Error(
163
- "getProvider is not available on this wallet. Ensure you're using the embedded Ethereum wallet.",
164
- );
165
- }
166
- const provider = await wallet.getProvider();
167
-
168
- // Always fetch current chain ID when provider is accessed
169
- // This ensures we have the latest chain after wallet_switchEthereumChain calls
170
- try {
171
- const currentChainId = (await provider.request({
172
- method: "eth_chainId",
173
- params: [],
174
- })) as string;
175
-
176
- // Convert hex to decimal string format (e.g., "0x1" -> "1")
177
- cachedChainId = parseInt(currentChainId, 16).toString();
178
- console.log("[RN Adapter] Updated chain ID to:", cachedChainId);
179
- } catch (err) {
180
- console.warn(
181
- "[Privy Integration] Failed to fetch current chain ID:",
182
- err,
183
- );
184
- // Fall back to cached value if fetch fails
185
- }
186
-
187
- return provider;
188
- },
189
- };
190
- }
@@ -1,56 +0,0 @@
1
- import type { Address, Authorization } from "viem";
2
- import type { AuthorizationRequest } from "@aa-sdk/core";
3
-
4
- /**
5
- * Platform-agnostic embedded wallet interface
6
- * Abstracts differences between @privy-io/react-auth and @privy-io/expo
7
- */
8
- export interface EmbeddedWallet {
9
- /** Wallet address */
10
- address: Address;
11
-
12
- /** Chain ID (may be CAIP-2 format like "eip155:1" or numeric) */
13
- chainId: string | number;
14
-
15
- /** Get EVM provider for the wallet */
16
- getEthereumProvider(): Promise<any>;
17
- }
18
-
19
- /**
20
- * Platform-agnostic Privy auth state
21
- */
22
- export interface PrivyAuthState {
23
- /** Whether user is authenticated */
24
- authenticated: boolean;
25
-
26
- /** User object (platform-specific, used for cache invalidation) */
27
- user: any;
28
- }
29
-
30
- /**
31
- * Adapter interface that each platform must implement
32
- * Provides platform-specific Privy functionality
33
- */
34
- export interface PrivyAdapter {
35
- /**
36
- * Hook to get embedded wallet
37
- * Must be called as a React hook (follows rules of hooks)
38
- */
39
- useEmbeddedWallet(): () => EmbeddedWallet;
40
-
41
- /**
42
- * Hook to get Privy authentication state
43
- * Must be called as a React hook (follows rules of hooks)
44
- */
45
- usePrivyAuth(): PrivyAuthState;
46
-
47
- /**
48
- * Hook to get EIP-7702 authorization signer (optional, web only)
49
- * Must be called as a React hook (follows rules of hooks)
50
- */
51
- useAuthorizationSigner?():
52
- | ((
53
- auth: AuthorizationRequest<number>,
54
- ) => Promise<Authorization<number, true>>)
55
- | null;
56
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * React Native stub for web adapter
3
- * This file prevents Metro from importing @privy-io/react-auth
4
- */
5
-
6
- export const webAdapter = null;
@@ -1,73 +0,0 @@
1
- import { useCallback } from "react";
2
- import {
3
- useWallets,
4
- usePrivy,
5
- useSign7702Authorization,
6
- type ConnectedWallet as PrivyWallet,
7
- } from "@privy-io/react-auth";
8
- import type { Authorization } from "viem";
9
- import type { AuthorizationRequest } from "@aa-sdk/core";
10
- import type { PrivyAdapter, EmbeddedWallet, PrivyAuthState } from "./types.js";
11
-
12
- /**
13
- * Web adapter for @privy-io/react-auth
14
- * Implements platform-specific hooks for React web applications
15
- */
16
- export const webAdapter: PrivyAdapter = {
17
- useEmbeddedWallet() {
18
- const { wallets } = useWallets();
19
-
20
- const getEmbeddedWallet = useCallback((): EmbeddedWallet => {
21
- const embedded = wallets.find((w) => w.walletClientType === "privy");
22
- if (!embedded) {
23
- throw new Error(
24
- "Privy embedded wallet not found. Please ensure the user is authenticated.",
25
- );
26
- }
27
-
28
- return adaptWebWallet(embedded);
29
- }, [wallets]);
30
-
31
- return getEmbeddedWallet;
32
- },
33
-
34
- usePrivyAuth(): PrivyAuthState {
35
- const { user } = usePrivy();
36
- return { authenticated: !!user, user };
37
- },
38
-
39
- useAuthorizationSigner() {
40
- const { signAuthorization } = useSign7702Authorization();
41
-
42
- return useCallback(
43
- async (
44
- unsignedAuth: AuthorizationRequest<number>,
45
- ): Promise<Authorization<number, true>> => {
46
- const signature = await signAuthorization({
47
- ...unsignedAuth,
48
- contractAddress: unsignedAuth.address ?? unsignedAuth.contractAddress,
49
- });
50
-
51
- return {
52
- ...unsignedAuth,
53
- ...signature,
54
- };
55
- },
56
- [signAuthorization],
57
- );
58
- },
59
- };
60
-
61
- /**
62
- * Adapts a Privy web wallet to the common EmbeddedWallet interface
63
- *
64
- * @param {PrivyWallet} wallet - The Privy web wallet to adapt
65
- * @returns {EmbeddedWallet} The adapted wallet following the common interface
66
- */
67
- function adaptWebWallet(wallet: PrivyWallet): EmbeddedWallet {
68
- return {
69
- address: wallet.address as `0x${string}`,
70
- chainId: wallet.chainId || "1",
71
- getEthereumProvider: () => wallet.getEthereumProvider(),
72
- };
73
- }