@account-kit/privy-integration 4.75.4 → 4.75.5-alpha.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/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 +70 -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/dist/types/version.d.ts.map +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 +202 -0
- package/src/adapters/types.ts +71 -0
- package/src/adapters/web.native.ts +6 -0
- package/src/adapters/web.ts +107 -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,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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OAAO,CAAC,iBAAiB,CAAC,CAAC;CACtE;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mCAAmC;IACnC,OAAO,EAAE,IAAI,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,SAAS,EAAE,OAAO,CAAC;IAEnB,iCAAiC;IACjC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB,2CAA2C;IAC3C,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAE9B,2BAA2B;IAC3B,KAAK,IAAI,IAAI,CAAC;IAEd,0CAA0C;IAC1C,UAAU,CAAC,YAAY,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACxE"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "4.75.
|
|
1
|
+
export declare const VERSION = "4.75.5-alpha.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/privy-integration",
|
|
3
|
-
"version": "4.75.
|
|
3
|
+
"version": "4.75.5-alpha.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.75.
|
|
52
|
-
"@account-kit/wallet-client": "^4.75.
|
|
67
|
+
"@account-kit/infra": "^4.75.5-alpha.0",
|
|
68
|
+
"@account-kit/wallet-client": "^4.75.5-alpha.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": "9d26a842cfa9082ea7f303974276b8fc8d9f8f2f"
|
|
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,202 @@
|
|
|
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 { hashAuthorization } from "viem/utils";
|
|
9
|
+
import { parseSignature } from "viem";
|
|
10
|
+
import type { AuthorizationRequest } from "@aa-sdk/core";
|
|
11
|
+
import type { PrivyAdapter, EmbeddedWallet, PrivyAuthState } from "./types.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Wallet type from @privy-io/expo
|
|
15
|
+
* Based on the example app structure
|
|
16
|
+
*/
|
|
17
|
+
interface ExpoEmbeddedWallet {
|
|
18
|
+
address: string;
|
|
19
|
+
chainId?: string;
|
|
20
|
+
getProvider?: () => Promise<PrivyEmbeddedWalletProvider>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* React Native (Expo) adapter for @privy-io/expo
|
|
25
|
+
* Implements platform-specific hooks for React Native applications
|
|
26
|
+
*/
|
|
27
|
+
export const reactNativeAdapter: PrivyAdapter = {
|
|
28
|
+
useEmbeddedWallet(preferredAddress?: string) {
|
|
29
|
+
const { wallets } = useEmbeddedEthereumWallet();
|
|
30
|
+
|
|
31
|
+
const getEmbeddedWallet = useCallback((): EmbeddedWallet => {
|
|
32
|
+
if (!wallets || wallets.length === 0) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"Privy embedded wallet not found. Please ensure the user is authenticated and has created a wallet.",
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// If a preferred address is specified, find that wallet
|
|
39
|
+
const wallet = preferredAddress
|
|
40
|
+
? wallets.find(
|
|
41
|
+
(w) => w.address.toLowerCase() === preferredAddress.toLowerCase(),
|
|
42
|
+
)
|
|
43
|
+
: wallets[0];
|
|
44
|
+
|
|
45
|
+
if (!wallet) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
preferredAddress
|
|
48
|
+
? `Privy embedded wallet with address ${preferredAddress} not found.`
|
|
49
|
+
: "Privy embedded wallet not found. Please ensure the user is authenticated and has created a wallet.",
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return adaptExpoWallet(wallet);
|
|
54
|
+
}, [wallets, preferredAddress]);
|
|
55
|
+
|
|
56
|
+
return getEmbeddedWallet;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
usePrivyAuth(): PrivyAuthState {
|
|
60
|
+
const { user } = usePrivy();
|
|
61
|
+
return { authenticated: !!user, user };
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
useWalletAddress(preferredAddress?: string): string | undefined {
|
|
65
|
+
const { wallets } = useEmbeddedEthereumWallet();
|
|
66
|
+
|
|
67
|
+
if (!wallets || wallets.length === 0) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// If a preferred address is specified, find that wallet
|
|
72
|
+
if (preferredAddress) {
|
|
73
|
+
const wallet = wallets.find(
|
|
74
|
+
(w) => w.address.toLowerCase() === preferredAddress.toLowerCase(),
|
|
75
|
+
);
|
|
76
|
+
return wallet?.address;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Otherwise return the first wallet
|
|
80
|
+
return wallets[0]?.address;
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
useAuthorizationSigner(preferredAddress?: string) {
|
|
84
|
+
const { wallets } = useEmbeddedEthereumWallet();
|
|
85
|
+
|
|
86
|
+
const signAuthorization = useCallback(
|
|
87
|
+
async (
|
|
88
|
+
unsignedAuth: AuthorizationRequest<number>,
|
|
89
|
+
): Promise<Authorization<number, true>> => {
|
|
90
|
+
if (!wallets || wallets.length === 0) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
"Privy embedded wallet not found. Please ensure the user is authenticated and has created a wallet.",
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// If a preferred address is specified, find that wallet
|
|
97
|
+
const wallet = preferredAddress
|
|
98
|
+
? wallets.find(
|
|
99
|
+
(w) => w.address.toLowerCase() === preferredAddress.toLowerCase(),
|
|
100
|
+
)
|
|
101
|
+
: wallets[0];
|
|
102
|
+
|
|
103
|
+
if (!wallet) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
preferredAddress
|
|
106
|
+
? `Privy embedded wallet with address ${preferredAddress} not found.`
|
|
107
|
+
: "Privy embedded wallet not found. Please ensure the user is authenticated and has created a wallet.",
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const provider = await wallet.getProvider?.();
|
|
112
|
+
if (!provider) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
"Provider not available on this wallet. Ensure you're using the embedded Ethereum wallet.",
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Extract the implementation address (handle both 'address' and 'contractAddress' fields)
|
|
119
|
+
const implementationAddress =
|
|
120
|
+
unsignedAuth.address ?? unsignedAuth.contractAddress;
|
|
121
|
+
|
|
122
|
+
if (!implementationAddress) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
"Implementation address is required for EIP-7702 authorization",
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Create the authorization structure (matches Privy's implementation)
|
|
129
|
+
const authorization = {
|
|
130
|
+
chainId: unsignedAuth.chainId,
|
|
131
|
+
address: implementationAddress,
|
|
132
|
+
nonce: unsignedAuth.nonce,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// Hash the authorization using viem (same as Privy does)
|
|
136
|
+
const authorizationHash = hashAuthorization(authorization);
|
|
137
|
+
|
|
138
|
+
// Sign the hash directly with secp256k1_sign (same as Privy)
|
|
139
|
+
const signature = (await provider.request({
|
|
140
|
+
method: "secp256k1_sign",
|
|
141
|
+
params: [authorizationHash],
|
|
142
|
+
})) as `0x${string}`;
|
|
143
|
+
|
|
144
|
+
// Parse the signature using viem (same as Privy)
|
|
145
|
+
const parsedSignature = parseSignature(signature);
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
chainId: unsignedAuth.chainId,
|
|
149
|
+
address: implementationAddress,
|
|
150
|
+
nonce: unsignedAuth.nonce,
|
|
151
|
+
...parsedSignature,
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
[wallets, preferredAddress],
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
return signAuthorization;
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Adapts an Expo wallet to the common EmbeddedWallet interface
|
|
163
|
+
*
|
|
164
|
+
* @param {ExpoEmbeddedWallet} wallet - The Expo embedded wallet to adapt
|
|
165
|
+
* @returns {EmbeddedWallet} The adapted wallet following the common interface
|
|
166
|
+
*/
|
|
167
|
+
function adaptExpoWallet(wallet: ExpoEmbeddedWallet): EmbeddedWallet {
|
|
168
|
+
// Use closure to maintain up-to-date chain ID across chain switches
|
|
169
|
+
let cachedChainId = wallet.chainId || "1";
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
address: wallet.address as `0x${string}`,
|
|
173
|
+
get chainId() {
|
|
174
|
+
return cachedChainId;
|
|
175
|
+
},
|
|
176
|
+
getEthereumProvider: async () => {
|
|
177
|
+
if (!wallet.getProvider) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
"getProvider is not available on this wallet. Ensure you're using the embedded Ethereum wallet.",
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
const provider = await wallet.getProvider();
|
|
183
|
+
|
|
184
|
+
// Always fetch current chain ID when provider is accessed
|
|
185
|
+
// This ensures we have the latest chain after wallet_switchEthereumChain calls
|
|
186
|
+
try {
|
|
187
|
+
const currentChainId = (await provider.request({
|
|
188
|
+
method: "eth_chainId",
|
|
189
|
+
params: [],
|
|
190
|
+
})) as string;
|
|
191
|
+
|
|
192
|
+
// Convert hex to decimal string format (e.g., "0x1" -> "1")
|
|
193
|
+
cachedChainId = parseInt(currentChainId, 16).toString();
|
|
194
|
+
} catch {
|
|
195
|
+
// Fall back to cached value if fetch fails
|
|
196
|
+
// Chain ID fetch errors are non-critical and can happen during initialization
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return provider;
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 as a string (may be CAIP-2 format like "eip155:1" or numeric string like "1") */
|
|
13
|
+
chainId: string;
|
|
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
|
+
* @param preferredAddress - Optional address to find a specific wallet
|
|
40
|
+
*/
|
|
41
|
+
useEmbeddedWallet(preferredAddress?: string): () => EmbeddedWallet;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Hook to get Privy authentication state
|
|
45
|
+
* Must be called as a React hook (follows rules of hooks)
|
|
46
|
+
*/
|
|
47
|
+
usePrivyAuth(): PrivyAuthState;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Hook to get current wallet address (for cache invalidation)
|
|
51
|
+
* Returns undefined if no wallet is available
|
|
52
|
+
* Must be called as a React hook (follows rules of hooks)
|
|
53
|
+
*
|
|
54
|
+
* @param preferredAddress - Optional address to find a specific wallet
|
|
55
|
+
*/
|
|
56
|
+
useWalletAddress(preferredAddress?: string): string | undefined;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Hook to get EIP-7702 authorization signer (optional, web only)
|
|
60
|
+
* Must be called as a React hook (follows rules of hooks)
|
|
61
|
+
*
|
|
62
|
+
* @param preferredAddress - Optional address to find a specific wallet
|
|
63
|
+
*/
|
|
64
|
+
useAuthorizationSigner?(
|
|
65
|
+
preferredAddress?: string,
|
|
66
|
+
):
|
|
67
|
+
| ((
|
|
68
|
+
auth: AuthorizationRequest<number>,
|
|
69
|
+
) => Promise<Authorization<number, true>>)
|
|
70
|
+
| null;
|
|
71
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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(preferredAddress?: string) {
|
|
18
|
+
const { wallets } = useWallets();
|
|
19
|
+
|
|
20
|
+
const getEmbeddedWallet = useCallback((): EmbeddedWallet => {
|
|
21
|
+
const privyWallets = wallets.filter(
|
|
22
|
+
(w) => w.walletClientType === "privy",
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (privyWallets.length === 0) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
"Privy embedded wallet not found. Please ensure the user is authenticated.",
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// If a preferred address is specified, find that wallet
|
|
32
|
+
const embedded = preferredAddress
|
|
33
|
+
? privyWallets.find(
|
|
34
|
+
(w) => w.address.toLowerCase() === preferredAddress.toLowerCase(),
|
|
35
|
+
)
|
|
36
|
+
: privyWallets[0];
|
|
37
|
+
|
|
38
|
+
if (!embedded) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
preferredAddress
|
|
41
|
+
? `Privy embedded wallet with address ${preferredAddress} not found.`
|
|
42
|
+
: "Privy embedded wallet not found. Please ensure the user is authenticated.",
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return adaptWebWallet(embedded);
|
|
47
|
+
}, [wallets, preferredAddress]);
|
|
48
|
+
|
|
49
|
+
return getEmbeddedWallet;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
usePrivyAuth(): PrivyAuthState {
|
|
53
|
+
const { user } = usePrivy();
|
|
54
|
+
return { authenticated: !!user, user };
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
useWalletAddress(preferredAddress?: string): string | undefined {
|
|
58
|
+
const { wallets } = useWallets();
|
|
59
|
+
const privyWallets = wallets.filter((w) => w.walletClientType === "privy");
|
|
60
|
+
|
|
61
|
+
// If a preferred address is specified, find that wallet
|
|
62
|
+
if (preferredAddress) {
|
|
63
|
+
const wallet = privyWallets.find(
|
|
64
|
+
(w) => w.address.toLowerCase() === preferredAddress.toLowerCase(),
|
|
65
|
+
);
|
|
66
|
+
return wallet?.address;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Otherwise return the first embedded wallet
|
|
70
|
+
return privyWallets[0]?.address;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
useAuthorizationSigner(_preferredAddress?: string) {
|
|
74
|
+
const { signAuthorization } = useSign7702Authorization();
|
|
75
|
+
|
|
76
|
+
return useCallback(
|
|
77
|
+
async (
|
|
78
|
+
unsignedAuth: AuthorizationRequest<number>,
|
|
79
|
+
): Promise<Authorization<number, true>> => {
|
|
80
|
+
const signature = await signAuthorization({
|
|
81
|
+
...unsignedAuth,
|
|
82
|
+
contractAddress: unsignedAuth.address ?? unsignedAuth.contractAddress,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
...unsignedAuth,
|
|
87
|
+
...signature,
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
[signAuthorization],
|
|
91
|
+
);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Adapts a Privy web wallet to the common EmbeddedWallet interface
|
|
97
|
+
*
|
|
98
|
+
* @param {PrivyWallet} wallet - The Privy web wallet to adapt
|
|
99
|
+
* @returns {EmbeddedWallet} The adapted wallet following the common interface
|
|
100
|
+
*/
|
|
101
|
+
function adaptWebWallet(wallet: PrivyWallet): EmbeddedWallet {
|
|
102
|
+
return {
|
|
103
|
+
address: wallet.address as `0x${string}`,
|
|
104
|
+
chainId: wallet.chainId || "1",
|
|
105
|
+
getEthereumProvider: () => wallet.getEthereumProvider(),
|
|
106
|
+
};
|
|
107
|
+
}
|