@account-kit/privy-integration 4.75.4 → 4.76.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/README.md +165 -6
- package/dist/esm/Provider.d.ts +4 -71
- package/dist/esm/Provider.js +4 -109
- package/dist/esm/Provider.js.map +1 -1
- package/dist/esm/Provider.native.d.ts +6 -0
- package/dist/esm/Provider.native.js +13 -0
- package/dist/esm/Provider.native.js.map +1 -0
- package/dist/esm/adapters/react-native.d.ts +6 -0
- package/dist/esm/adapters/react-native.js +132 -0
- package/dist/esm/adapters/react-native.js.map +1 -0
- package/dist/esm/adapters/types.d.ts +56 -0
- package/dist/esm/adapters/types.js +2 -0
- package/dist/esm/adapters/types.js.map +1 -0
- package/dist/esm/adapters/web.d.ts +6 -0
- package/dist/esm/adapters/web.js +71 -0
- package/dist/esm/adapters/web.js.map +1 -0
- package/dist/esm/adapters/web.native.d.ts +5 -0
- package/dist/esm/adapters/web.native.js +6 -0
- package/dist/esm/adapters/web.native.js.map +1 -0
- package/dist/esm/context/AlchemyContext.d.ts +71 -0
- package/dist/esm/context/AlchemyContext.js +115 -0
- package/dist/esm/context/AlchemyContext.js.map +1 -0
- package/dist/esm/hooks/internal/useEmbeddedWallet.d.ts +3 -4
- package/dist/esm/hooks/internal/useEmbeddedWallet.js +6 -13
- package/dist/esm/hooks/internal/useEmbeddedWallet.js.map +1 -1
- package/dist/esm/hooks/useAlchemyClient.js +17 -24
- package/dist/esm/hooks/useAlchemyClient.js.map +1 -1
- package/dist/esm/hooks/useAlchemySendTransaction.js +1 -1
- package/dist/esm/hooks/useAlchemySendTransaction.js.map +1 -1
- package/dist/esm/hooks/useAlchemySolanaTransaction.js +1 -1
- package/dist/esm/hooks/useAlchemySolanaTransaction.js.map +1 -1
- package/dist/esm/providers/ReactNativeProvider.d.ts +37 -0
- package/dist/esm/providers/ReactNativeProvider.js +41 -0
- package/dist/esm/providers/ReactNativeProvider.js.map +1 -0
- package/dist/esm/providers/WebProvider.d.ts +37 -0
- package/dist/esm/providers/WebProvider.js +41 -0
- package/dist/esm/providers/WebProvider.js.map +1 -0
- package/dist/esm/providers/WebProvider.native.d.ts +5 -0
- package/dist/esm/providers/WebProvider.native.js +9 -0
- package/dist/esm/providers/WebProvider.native.js.map +1 -0
- package/dist/esm/react-native.d.ts +11 -0
- package/dist/esm/react-native.js +13 -0
- package/dist/esm/react-native.js.map +1 -0
- package/dist/esm/types.d.ts +6 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/Provider.d.ts +4 -71
- package/dist/types/Provider.d.ts.map +1 -1
- package/dist/types/Provider.native.d.ts +7 -0
- package/dist/types/Provider.native.d.ts.map +1 -0
- package/dist/types/adapters/react-native.d.ts +7 -0
- package/dist/types/adapters/react-native.d.ts.map +1 -0
- package/dist/types/adapters/types.d.ts +57 -0
- package/dist/types/adapters/types.d.ts.map +1 -0
- package/dist/types/adapters/web.d.ts +7 -0
- package/dist/types/adapters/web.d.ts.map +1 -0
- package/dist/types/adapters/web.native.d.ts +6 -0
- package/dist/types/adapters/web.native.d.ts.map +1 -0
- package/dist/types/context/AlchemyContext.d.ts +72 -0
- package/dist/types/context/AlchemyContext.d.ts.map +1 -0
- package/dist/types/hooks/internal/useEmbeddedWallet.d.ts +3 -4
- package/dist/types/hooks/internal/useEmbeddedWallet.d.ts.map +1 -1
- package/dist/types/hooks/useAlchemyClient.d.ts.map +1 -1
- package/dist/types/providers/ReactNativeProvider.d.ts +38 -0
- package/dist/types/providers/ReactNativeProvider.d.ts.map +1 -0
- package/dist/types/providers/WebProvider.d.ts +38 -0
- package/dist/types/providers/WebProvider.d.ts.map +1 -0
- package/dist/types/providers/WebProvider.native.d.ts +6 -0
- package/dist/types/providers/WebProvider.native.d.ts.map +1 -0
- package/dist/types/react-native.d.ts +12 -0
- package/dist/types/react-native.d.ts.map +1 -0
- package/dist/types/types.d.ts +6 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +27 -4
- package/src/Provider.native.tsx +18 -0
- package/src/Provider.tsx +6 -0
- package/src/adapters/react-native.ts +210 -0
- package/src/adapters/types.ts +71 -0
- package/src/adapters/web.native.ts +6 -0
- package/src/adapters/web.ts +113 -0
- package/src/context/AlchemyContext.tsx +185 -0
- package/src/hooks/internal/useEmbeddedWallet.ts +6 -20
- package/src/hooks/useAlchemyClient.ts +24 -38
- package/src/hooks/useAlchemySendTransaction.ts +1 -1
- package/src/hooks/useAlchemySolanaTransaction.ts +1 -1
- package/src/providers/ReactNativeProvider.tsx +49 -0
- package/src/providers/WebProvider.native.tsx +11 -0
- package/src/providers/WebProvider.tsx +49 -0
- package/src/react-native.ts +29 -0
- package/src/types.ts +7 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,qBAAqB;IACrB,OAAO,EAAE,OAAO,CAAC;IAEjB,6FAA6F;IAC7F,OAAO,EAAE,MAAM,CAAC;IAEhB,sCAAsC;IACtC,mBAAmB,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,aAAa,EAAE,OAAO,CAAC;IAEvB,mEAAmE;IACnE,IAAI,EAAE,GAAG,CAAC;CACX;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,cAAc,CAAC;IAEnE;;;OAGG;IACH,YAAY,IAAI,cAAc,CAAC;IAE/B;;;;;;OAMG;IACH,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAEhE;;;;;OAKG;IACH,sBAAsB,CAAC,CACrB,gBAAgB,CAAC,EAAE,MAAM,GAEvB,CAAC,CACC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,KAC/B,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,GAC1C,IAAI,CAAC;CACV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../../src/adapters/web.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAkC,MAAM,YAAY,CAAC;AAE/E;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,YAmFxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type PropsWithChildren } from "react";
|
|
2
|
+
import type { SmartWalletClient } from "@account-kit/wallet-client";
|
|
3
|
+
import type { SmartContractAccount } from "@aa-sdk/core";
|
|
4
|
+
import type { AlchemyProviderConfig } from "../types.js";
|
|
5
|
+
import type { PrivyAdapter } from "../adapters/types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Normalized config with defaults applied
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export type NormalizedAlchemyConfig = AlchemyProviderConfig & Required<Pick<AlchemyProviderConfig, "accountAuthMode">>;
|
|
12
|
+
/**
|
|
13
|
+
* Client cache stored in React tree (similar to QueryClient in React Query)
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
interface ClientCache {
|
|
18
|
+
client: SmartWalletClient | null;
|
|
19
|
+
account: SmartContractAccount | null;
|
|
20
|
+
cacheKey: string | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Props for AlchemyContextProvider
|
|
24
|
+
*/
|
|
25
|
+
interface AlchemyContextProviderProps extends PropsWithChildren {
|
|
26
|
+
config: AlchemyProviderConfig;
|
|
27
|
+
adapter: PrivyAdapter;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Internal provider component that manages Alchemy context
|
|
31
|
+
* Used by both web and React Native providers
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
* @param {AlchemyContextProviderProps} props - Component props
|
|
35
|
+
* @param {React.ReactNode} props.children - React children to wrap with context
|
|
36
|
+
* @param {AlchemyProviderConfig} props.config - Alchemy configuration
|
|
37
|
+
* @param {PrivyAdapter} props.adapter - Platform adapter
|
|
38
|
+
* @returns {JSX.Element} Context provider component
|
|
39
|
+
*/
|
|
40
|
+
export declare function AlchemyContextProvider({ children, config, adapter, }: AlchemyContextProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
41
|
+
/**
|
|
42
|
+
* Hook to access Alchemy provider configuration
|
|
43
|
+
* Must be used within an <AlchemyProvider> component
|
|
44
|
+
*
|
|
45
|
+
* @returns {NormalizedAlchemyConfig} The current Alchemy configuration with defaults applied
|
|
46
|
+
* @throws {Error} If used outside of AlchemyProvider
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* const config = useAlchemyConfig();
|
|
51
|
+
* console.log('Policy ID:', config.policyId);
|
|
52
|
+
* console.log('Auth Mode:', config.accountAuthMode); // Always defined
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function useAlchemyConfig(): NormalizedAlchemyConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Hook to access the platform adapter
|
|
58
|
+
* Must be used within an <AlchemyProvider> component
|
|
59
|
+
*
|
|
60
|
+
* @internal
|
|
61
|
+
* @returns {PrivyAdapter} The platform adapter
|
|
62
|
+
*/
|
|
63
|
+
export declare function useAdapter(): PrivyAdapter;
|
|
64
|
+
/**
|
|
65
|
+
* Hook to access the client cache (internal use only)
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
* @returns {ClientCache} The client cache object
|
|
69
|
+
*/
|
|
70
|
+
export declare function useClientCache(): ClientCache;
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=AlchemyContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG,qBAAqB,GACzD,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAc3D;;;;GAIG;AACH,UAAU,WAAW;IACnB,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACrC,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,2CA6D7B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,IAAI,uBAAuB,CAM1D;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,YAAY,CAQzC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAQ5C"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { type ConnectedWallet as PrivyWallet } from "@privy-io/react-auth";
|
|
2
1
|
/**
|
|
3
2
|
* Internal hook to get the Privy embedded wallet
|
|
4
|
-
*
|
|
3
|
+
* Uses the platform adapter to abstract differences between web and React Native
|
|
5
4
|
*
|
|
6
5
|
* @internal
|
|
7
|
-
* @returns {() =>
|
|
6
|
+
* @returns {() => EmbeddedWallet} Function that returns the embedded wallet
|
|
8
7
|
* @throws {Error} If embedded wallet is not found
|
|
9
8
|
*/
|
|
10
|
-
export declare function useEmbeddedWallet(): () =>
|
|
9
|
+
export declare function useEmbeddedWallet(): () => import("../../adapters/types.js").EmbeddedWallet;
|
|
11
10
|
//# sourceMappingURL=useEmbeddedWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEmbeddedWallet.d.ts","sourceRoot":"","sources":["../../../../src/hooks/internal/useEmbeddedWallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEmbeddedWallet.d.ts","sourceRoot":"","sources":["../../../../src/hooks/internal/useEmbeddedWallet.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,2DAIhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAlchemyClient.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAlchemyClient.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"useAlchemyClient.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAlchemyClient.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AAEtB,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,4BAA4B,CAAC;AAUpC,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,oBAAoB,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB;qBAQU,OAAO,CAAC,mBAAmB,CAAC;EAuHrE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
* @param {'eip7702' | 'owner'} [props.accountAuthMode] - Authorization mode for EVM smart accounts (default: 'eip7702')
|
|
17
|
+
* @param {string} [props.walletAddress] - Optional: Specify which wallet address to use (defaults to first wallet in array)
|
|
18
|
+
* @returns {JSX.Element} Provider component
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* import { PrivyProvider } from '@privy-io/expo';
|
|
23
|
+
* import { AlchemyProvider } from '@account-kit/privy-integration/react-native';
|
|
24
|
+
*
|
|
25
|
+
* <PrivyProvider appId="..." clientId="...">
|
|
26
|
+
* <AlchemyProvider
|
|
27
|
+
* apiKey="your-alchemy-api-key"
|
|
28
|
+
* policyId="your-gas-policy-id"
|
|
29
|
+
* accountAuthMode="eip7702"
|
|
30
|
+
* walletAddress="0x123..." // Optional: specify which wallet to use
|
|
31
|
+
* >
|
|
32
|
+
* <YourApp />
|
|
33
|
+
* </AlchemyProvider>
|
|
34
|
+
* </PrivyProvider>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function AlchemyProvider({ children, ...config }: PropsWithChildren<AlchemyProviderConfig>): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
//# sourceMappingURL=ReactNativeProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,GAAG,MAAM,EACV,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,2CAM1C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
* @param {'eip7702' | 'owner'} [props.accountAuthMode] - Authorization mode for EVM smart accounts (default: 'eip7702')
|
|
17
|
+
* @param {string} [props.walletAddress] - Optional: Specify which wallet address to use (defaults to first embedded wallet)
|
|
18
|
+
* @returns {JSX.Element} Provider component
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* import { PrivyProvider } from '@privy-io/react-auth';
|
|
23
|
+
* import { AlchemyProvider } from '@account-kit/privy-integration';
|
|
24
|
+
*
|
|
25
|
+
* <PrivyProvider appId="...">
|
|
26
|
+
* <AlchemyProvider
|
|
27
|
+
* apiKey="your-alchemy-api-key"
|
|
28
|
+
* policyId="your-gas-policy-id"
|
|
29
|
+
* accountAuthMode="eip7702"
|
|
30
|
+
* walletAddress="0x123..." // Optional: specify which wallet to use
|
|
31
|
+
* >
|
|
32
|
+
* <YourApp />
|
|
33
|
+
* </AlchemyProvider>
|
|
34
|
+
* </PrivyProvider>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function AlchemyProvider({ children, ...config }: PropsWithChildren<AlchemyProviderConfig>): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
//# sourceMappingURL=WebProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,GAAG,MAAM,EACV,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,2CAM1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebProvider.native.d.ts","sourceRoot":"","sources":["../../../src/providers/WebProvider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,eAAe,SAK9B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ export type AlchemyProviderConfig = z.infer<typeof ConnectionConfigSchema> & {
|
|
|
24
24
|
* Default: false (sponsorship enabled when policyId is provided)
|
|
25
25
|
*/
|
|
26
26
|
disableSponsorship?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Optional: Specify which wallet address to use
|
|
29
|
+
* - If provided, will use the wallet matching this address
|
|
30
|
+
* - If not provided, defaults to the first embedded wallet (web) or first wallet in array (React Native)
|
|
31
|
+
*/
|
|
32
|
+
walletAddress?: string;
|
|
27
33
|
};
|
|
28
34
|
/**
|
|
29
35
|
* Unsigned transaction request
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,GAAG;IAC3E,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE7B,8CAA8C;IAC9C,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEnC,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,eAAe,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAEtC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"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"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.76.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/privy-integration",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.76.0",
|
|
4
4
|
"description": "Use Alchemy gas sponsorship, swaps and more with Privy",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,9 +11,18 @@
|
|
|
11
11
|
"types": "./dist/types/index.d.ts",
|
|
12
12
|
"typings": "./dist/types/index.d.ts",
|
|
13
13
|
"sideEffects": false,
|
|
14
|
+
"react-native": {
|
|
15
|
+
"main": "./dist/esm/react-native.js",
|
|
16
|
+
"./dist/esm/adapters/web.js": "./dist/esm/adapters/web.native.js",
|
|
17
|
+
"./dist/esm/providers/WebProvider.js": "./dist/esm/providers/WebProvider.native.js",
|
|
18
|
+
"./dist/esm/Provider.js": "./dist/esm/Provider.native.js",
|
|
19
|
+
"@privy-io/react-auth": false,
|
|
20
|
+
"@privy-io/react-auth/solana": false
|
|
21
|
+
},
|
|
14
22
|
"files": [
|
|
15
23
|
"dist",
|
|
16
24
|
"src/**/*.ts",
|
|
25
|
+
"src/**/*.tsx",
|
|
17
26
|
"!dist/**/*.tsbuildinfo",
|
|
18
27
|
"!vitest.config.ts",
|
|
19
28
|
"!.env",
|
|
@@ -23,10 +32,16 @@
|
|
|
23
32
|
],
|
|
24
33
|
"exports": {
|
|
25
34
|
".": {
|
|
35
|
+
"react-native": "./dist/esm/react-native.js",
|
|
26
36
|
"types": "./dist/types/index.d.ts",
|
|
27
37
|
"import": "./dist/esm/index.js",
|
|
28
38
|
"default": "./dist/esm/index.js"
|
|
29
39
|
},
|
|
40
|
+
"./react-native": {
|
|
41
|
+
"types": "./dist/types/react-native.d.ts",
|
|
42
|
+
"import": "./dist/esm/react-native.js",
|
|
43
|
+
"default": "./dist/esm/react-native.js"
|
|
44
|
+
},
|
|
30
45
|
"./solana": {
|
|
31
46
|
"types": "./dist/types/solana.d.ts",
|
|
32
47
|
"import": "./dist/esm/solana.js",
|
|
@@ -44,18 +59,26 @@
|
|
|
44
59
|
"test:run": "vitest run --passWithNoTests"
|
|
45
60
|
},
|
|
46
61
|
"devDependencies": {
|
|
62
|
+
"@privy-io/expo": "0.58.1",
|
|
47
63
|
"@privy-io/react-auth": "3.3.0",
|
|
48
64
|
"typescript-template": "*"
|
|
49
65
|
},
|
|
50
66
|
"dependencies": {
|
|
51
|
-
"@account-kit/infra": "^4.
|
|
52
|
-
"@account-kit/wallet-client": "^4.
|
|
67
|
+
"@account-kit/infra": "^4.76.0",
|
|
68
|
+
"@account-kit/wallet-client": "^4.76.0"
|
|
53
69
|
},
|
|
54
70
|
"peerDependencies": {
|
|
71
|
+
"@privy-io/expo": "^0.58.1",
|
|
55
72
|
"@privy-io/react-auth": "^2.3.1 || ^3.0.0",
|
|
56
73
|
"viem": "^2.29.2"
|
|
57
74
|
},
|
|
58
75
|
"peerDependenciesMeta": {
|
|
76
|
+
"@privy-io/react-auth": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"@privy-io/expo": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
59
82
|
"@solana/web3.js": {
|
|
60
83
|
"optional": true
|
|
61
84
|
}
|
|
@@ -72,5 +95,5 @@
|
|
|
72
95
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
73
96
|
},
|
|
74
97
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
75
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "664b587d4ab2c3be0ff244a8a25b172a6d496a78"
|
|
76
99
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
"This module requires @privy-io/react-auth which 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
|
+
"This module requires @privy-io/react-auth which is not available in React Native. " +
|
|
16
|
+
'Import from "@account-kit/privy-integration/react-native" instead.',
|
|
17
|
+
);
|
|
18
|
+
}
|
package/src/Provider.tsx
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import {
|
|
3
|
+
usePrivy,
|
|
4
|
+
useEmbeddedEthereumWallet,
|
|
5
|
+
type PrivyEmbeddedWalletProvider,
|
|
6
|
+
} from "@privy-io/expo";
|
|
7
|
+
import { isAddressEqual, parseSignature, type Authorization } from "viem";
|
|
8
|
+
import { hashAuthorization } from "viem/utils";
|
|
9
|
+
import type { AuthorizationRequest } from "@aa-sdk/core";
|
|
10
|
+
import type { PrivyAdapter, EmbeddedWallet, PrivyAuthState } from "./types.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Wallet type from @privy-io/expo
|
|
14
|
+
* Based on the example app structure
|
|
15
|
+
*/
|
|
16
|
+
interface ExpoEmbeddedWallet {
|
|
17
|
+
address: string;
|
|
18
|
+
chainId?: string;
|
|
19
|
+
getProvider?: () => Promise<PrivyEmbeddedWalletProvider>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* React Native (Expo) adapter for @privy-io/expo
|
|
24
|
+
* Implements platform-specific hooks for React Native applications
|
|
25
|
+
*/
|
|
26
|
+
export const reactNativeAdapter: PrivyAdapter = {
|
|
27
|
+
useEmbeddedWallet(preferredAddress?: string) {
|
|
28
|
+
const { wallets } = useEmbeddedEthereumWallet();
|
|
29
|
+
|
|
30
|
+
const getEmbeddedWallet = useCallback((): EmbeddedWallet => {
|
|
31
|
+
if (!wallets || wallets.length === 0) {
|
|
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
|
+
// If a preferred address is specified, find that wallet
|
|
38
|
+
const wallet = preferredAddress
|
|
39
|
+
? wallets.find((w) =>
|
|
40
|
+
isAddressEqual(
|
|
41
|
+
w.address as `0x${string}`,
|
|
42
|
+
preferredAddress as `0x${string}`,
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
: wallets[0];
|
|
46
|
+
|
|
47
|
+
if (!wallet) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
preferredAddress
|
|
50
|
+
? `Privy embedded wallet with address ${preferredAddress} not found.`
|
|
51
|
+
: "Privy embedded wallet not found. Please ensure the user is authenticated and has created a wallet.",
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return adaptExpoWallet(wallet);
|
|
56
|
+
}, [wallets, preferredAddress]);
|
|
57
|
+
|
|
58
|
+
return getEmbeddedWallet;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
usePrivyAuth(): PrivyAuthState {
|
|
62
|
+
const { user } = usePrivy();
|
|
63
|
+
return { authenticated: !!user, user };
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
useWalletAddress(preferredAddress?: string): string | undefined {
|
|
67
|
+
const { wallets } = useEmbeddedEthereumWallet();
|
|
68
|
+
|
|
69
|
+
if (!wallets || wallets.length === 0) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// If a preferred address is specified, find that wallet
|
|
74
|
+
if (preferredAddress) {
|
|
75
|
+
const wallet = wallets.find((w) =>
|
|
76
|
+
isAddressEqual(
|
|
77
|
+
w.address as `0x${string}`,
|
|
78
|
+
preferredAddress as `0x${string}`,
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
return wallet?.address;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Otherwise return the first wallet
|
|
85
|
+
return wallets[0]?.address;
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
useAuthorizationSigner(preferredAddress?: string) {
|
|
89
|
+
const { wallets } = useEmbeddedEthereumWallet();
|
|
90
|
+
|
|
91
|
+
const signAuthorization = useCallback(
|
|
92
|
+
async (
|
|
93
|
+
unsignedAuth: AuthorizationRequest<number>,
|
|
94
|
+
): Promise<Authorization<number, true>> => {
|
|
95
|
+
if (!wallets || wallets.length === 0) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
"Privy embedded wallet not found. Please ensure the user is authenticated and has created a wallet.",
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// If a preferred address is specified, find that wallet
|
|
102
|
+
const wallet = preferredAddress
|
|
103
|
+
? wallets.find((w) =>
|
|
104
|
+
isAddressEqual(
|
|
105
|
+
w.address as `0x${string}`,
|
|
106
|
+
preferredAddress as `0x${string}`,
|
|
107
|
+
),
|
|
108
|
+
)
|
|
109
|
+
: wallets[0];
|
|
110
|
+
|
|
111
|
+
if (!wallet) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
preferredAddress
|
|
114
|
+
? `Privy embedded wallet with address ${preferredAddress} not found.`
|
|
115
|
+
: "Privy embedded wallet not found. Please ensure the user is authenticated and has created a wallet.",
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const provider = await wallet.getProvider?.();
|
|
120
|
+
if (!provider) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
"Provider not available on this wallet. Ensure you're using the embedded Ethereum wallet.",
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Extract the implementation address (handle both 'address' and 'contractAddress' fields)
|
|
127
|
+
const implementationAddress =
|
|
128
|
+
unsignedAuth.address ?? unsignedAuth.contractAddress;
|
|
129
|
+
|
|
130
|
+
if (!implementationAddress) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
"Implementation address is required for EIP-7702 authorization",
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Create the authorization structure (matches Privy's implementation)
|
|
137
|
+
const authorization = {
|
|
138
|
+
chainId: unsignedAuth.chainId,
|
|
139
|
+
address: implementationAddress,
|
|
140
|
+
nonce: unsignedAuth.nonce,
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// Hash the authorization using viem (same as Privy does)
|
|
144
|
+
const authorizationHash = hashAuthorization(authorization);
|
|
145
|
+
|
|
146
|
+
// Sign the hash directly with secp256k1_sign (same as Privy)
|
|
147
|
+
const signature = (await provider.request({
|
|
148
|
+
method: "secp256k1_sign",
|
|
149
|
+
params: [authorizationHash],
|
|
150
|
+
})) as `0x${string}`;
|
|
151
|
+
|
|
152
|
+
// Parse the signature using viem (same as Privy)
|
|
153
|
+
const parsedSignature = parseSignature(signature);
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
chainId: unsignedAuth.chainId,
|
|
157
|
+
address: implementationAddress,
|
|
158
|
+
nonce: unsignedAuth.nonce,
|
|
159
|
+
...parsedSignature,
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
[wallets, preferredAddress],
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
return signAuthorization;
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Adapts an Expo wallet to the common EmbeddedWallet interface
|
|
171
|
+
*
|
|
172
|
+
* @param {ExpoEmbeddedWallet} wallet - The Expo embedded wallet to adapt
|
|
173
|
+
* @returns {EmbeddedWallet} The adapted wallet following the common interface
|
|
174
|
+
*/
|
|
175
|
+
function adaptExpoWallet(wallet: ExpoEmbeddedWallet): EmbeddedWallet {
|
|
176
|
+
// Use closure to maintain up-to-date chain ID across chain switches
|
|
177
|
+
let cachedChainId = wallet.chainId || "1";
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
address: wallet.address as `0x${string}`,
|
|
181
|
+
get chainId() {
|
|
182
|
+
return cachedChainId;
|
|
183
|
+
},
|
|
184
|
+
getEthereumProvider: async () => {
|
|
185
|
+
if (!wallet.getProvider) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
"getProvider is not available on this wallet. Ensure you're using the embedded Ethereum wallet.",
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
const provider = await wallet.getProvider();
|
|
191
|
+
|
|
192
|
+
// Always fetch current chain ID when provider is accessed
|
|
193
|
+
// This ensures we have the latest chain after wallet_switchEthereumChain calls
|
|
194
|
+
try {
|
|
195
|
+
const currentChainId = (await provider.request({
|
|
196
|
+
method: "eth_chainId",
|
|
197
|
+
params: [],
|
|
198
|
+
})) as string;
|
|
199
|
+
|
|
200
|
+
// Convert hex to decimal string format (e.g., "0x1" -> "1")
|
|
201
|
+
cachedChainId = parseInt(currentChainId, 16).toString();
|
|
202
|
+
} catch {
|
|
203
|
+
// Fall back to cached value if fetch fails
|
|
204
|
+
// Chain ID fetch errors are non-critical and can happen during initialization
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return provider;
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|