@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.
Files changed (94) hide show
  1. package/README.md +165 -6
  2. package/dist/esm/Provider.d.ts +4 -71
  3. package/dist/esm/Provider.js +4 -109
  4. package/dist/esm/Provider.js.map +1 -1
  5. package/dist/esm/Provider.native.d.ts +6 -0
  6. package/dist/esm/Provider.native.js +13 -0
  7. package/dist/esm/Provider.native.js.map +1 -0
  8. package/dist/esm/adapters/react-native.d.ts +6 -0
  9. package/dist/esm/adapters/react-native.js +132 -0
  10. package/dist/esm/adapters/react-native.js.map +1 -0
  11. package/dist/esm/adapters/types.d.ts +56 -0
  12. package/dist/esm/adapters/types.js +2 -0
  13. package/dist/esm/adapters/types.js.map +1 -0
  14. package/dist/esm/adapters/web.d.ts +6 -0
  15. package/dist/esm/adapters/web.js +71 -0
  16. package/dist/esm/adapters/web.js.map +1 -0
  17. package/dist/esm/adapters/web.native.d.ts +5 -0
  18. package/dist/esm/adapters/web.native.js +6 -0
  19. package/dist/esm/adapters/web.native.js.map +1 -0
  20. package/dist/esm/context/AlchemyContext.d.ts +71 -0
  21. package/dist/esm/context/AlchemyContext.js +115 -0
  22. package/dist/esm/context/AlchemyContext.js.map +1 -0
  23. package/dist/esm/hooks/internal/useEmbeddedWallet.d.ts +3 -4
  24. package/dist/esm/hooks/internal/useEmbeddedWallet.js +6 -13
  25. package/dist/esm/hooks/internal/useEmbeddedWallet.js.map +1 -1
  26. package/dist/esm/hooks/useAlchemyClient.js +17 -24
  27. package/dist/esm/hooks/useAlchemyClient.js.map +1 -1
  28. package/dist/esm/hooks/useAlchemySendTransaction.js +1 -1
  29. package/dist/esm/hooks/useAlchemySendTransaction.js.map +1 -1
  30. package/dist/esm/hooks/useAlchemySolanaTransaction.js +1 -1
  31. package/dist/esm/hooks/useAlchemySolanaTransaction.js.map +1 -1
  32. package/dist/esm/providers/ReactNativeProvider.d.ts +37 -0
  33. package/dist/esm/providers/ReactNativeProvider.js +41 -0
  34. package/dist/esm/providers/ReactNativeProvider.js.map +1 -0
  35. package/dist/esm/providers/WebProvider.d.ts +37 -0
  36. package/dist/esm/providers/WebProvider.js +41 -0
  37. package/dist/esm/providers/WebProvider.js.map +1 -0
  38. package/dist/esm/providers/WebProvider.native.d.ts +5 -0
  39. package/dist/esm/providers/WebProvider.native.js +9 -0
  40. package/dist/esm/providers/WebProvider.native.js.map +1 -0
  41. package/dist/esm/react-native.d.ts +11 -0
  42. package/dist/esm/react-native.js +13 -0
  43. package/dist/esm/react-native.js.map +1 -0
  44. package/dist/esm/types.d.ts +6 -0
  45. package/dist/esm/types.js.map +1 -1
  46. package/dist/esm/version.d.ts +1 -1
  47. package/dist/esm/version.js +1 -1
  48. package/dist/esm/version.js.map +1 -1
  49. package/dist/types/Provider.d.ts +4 -71
  50. package/dist/types/Provider.d.ts.map +1 -1
  51. package/dist/types/Provider.native.d.ts +7 -0
  52. package/dist/types/Provider.native.d.ts.map +1 -0
  53. package/dist/types/adapters/react-native.d.ts +7 -0
  54. package/dist/types/adapters/react-native.d.ts.map +1 -0
  55. package/dist/types/adapters/types.d.ts +57 -0
  56. package/dist/types/adapters/types.d.ts.map +1 -0
  57. package/dist/types/adapters/web.d.ts +7 -0
  58. package/dist/types/adapters/web.d.ts.map +1 -0
  59. package/dist/types/adapters/web.native.d.ts +6 -0
  60. package/dist/types/adapters/web.native.d.ts.map +1 -0
  61. package/dist/types/context/AlchemyContext.d.ts +72 -0
  62. package/dist/types/context/AlchemyContext.d.ts.map +1 -0
  63. package/dist/types/hooks/internal/useEmbeddedWallet.d.ts +3 -4
  64. package/dist/types/hooks/internal/useEmbeddedWallet.d.ts.map +1 -1
  65. package/dist/types/hooks/useAlchemyClient.d.ts.map +1 -1
  66. package/dist/types/providers/ReactNativeProvider.d.ts +38 -0
  67. package/dist/types/providers/ReactNativeProvider.d.ts.map +1 -0
  68. package/dist/types/providers/WebProvider.d.ts +38 -0
  69. package/dist/types/providers/WebProvider.d.ts.map +1 -0
  70. package/dist/types/providers/WebProvider.native.d.ts +6 -0
  71. package/dist/types/providers/WebProvider.native.d.ts.map +1 -0
  72. package/dist/types/react-native.d.ts +12 -0
  73. package/dist/types/react-native.d.ts.map +1 -0
  74. package/dist/types/types.d.ts +6 -0
  75. package/dist/types/types.d.ts.map +1 -1
  76. package/dist/types/version.d.ts +1 -1
  77. package/package.json +27 -4
  78. package/src/Provider.native.tsx +18 -0
  79. package/src/Provider.tsx +6 -0
  80. package/src/adapters/react-native.ts +210 -0
  81. package/src/adapters/types.ts +71 -0
  82. package/src/adapters/web.native.ts +6 -0
  83. package/src/adapters/web.ts +113 -0
  84. package/src/context/AlchemyContext.tsx +185 -0
  85. package/src/hooks/internal/useEmbeddedWallet.ts +6 -20
  86. package/src/hooks/useAlchemyClient.ts +24 -38
  87. package/src/hooks/useAlchemySendTransaction.ts +1 -1
  88. package/src/hooks/useAlchemySolanaTransaction.ts +1 -1
  89. package/src/providers/ReactNativeProvider.tsx +49 -0
  90. package/src/providers/WebProvider.native.tsx +11 -0
  91. package/src/providers/WebProvider.tsx +49 -0
  92. package/src/react-native.ts +29 -0
  93. package/src/types.ts +7 -0
  94. package/src/version.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"useAlchemySendTransaction.js","sourceRoot":"","sources":["../../../src/hooks/useAlchemySendTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAY,KAAK,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAQlD;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,KAA+B;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,KAAK,CAAC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CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useState } from \"react\";\nimport { type Hex, isHex } from \"viem\";\nimport { useAlchemyClient } from \"./useAlchemyClient.js\";\nimport { useAlchemyConfig } from \"../Provider.js\";\nimport type {\n UnsignedTransactionRequest,\n SendTransactionOptions,\n SendTransactionResult,\n UseSendTransactionResult,\n} from \"../types\";\n\n/**\n * Normalize value to hex format\n * Accepts bigint, number, decimal string, or hex string\n *\n * @param {string | number | bigint} value - Value to normalize\n * @returns {Hex} Hex string representation of the value\n */\nfunction normalizeValue(value: string | number | bigint): Hex {\n if (typeof value === \"bigint\") {\n return `0x${value.toString(16)}`;\n }\n if (typeof value === \"number\") {\n return `0x${BigInt(value).toString(16)}`;\n }\n if (isHex(value)) {\n return value;\n }\n // Assume decimal string\n return `0x${BigInt(value).toString(16)}`;\n}\n\n/**\n * Hook to send transactions with optional gas sponsorship via Alchemy\n * Supports both single transactions and batch transactions\n * Drop-in alternative to Privy's useSendTransaction hook\n *\n * @returns {UseSendTransactionResult} Hook result with sendTransaction function and state\n *\n * @example Single transaction\n * ```tsx\n * const { sendTransaction, isLoading, error, data } = useAlchemySendTransaction();\n *\n * const handleSend = async () => {\n * try {\n * const result = await sendTransaction({\n * to: '0x...',\n * data: '0x...',\n * value: '1000000000000000000', // 1 ETH\n * });\n * console.log('Transaction hash:', result.txnHash);\n * } catch (err) {\n * console.error('Transaction failed:', err);\n * }\n * };\n * ```\n *\n * @example Batch transactions\n * ```tsx\n * const { sendTransaction } = useAlchemySendTransaction();\n *\n * const result = await sendTransaction([\n * { to: '0x...', data: '0x...', value: '1000000000000000000' },\n * { to: '0x...', data: '0x...' },\n * ]);\n * ```\n */\nexport function useAlchemySendTransaction(): UseSendTransactionResult {\n const { getClient } = useAlchemyClient();\n const config = useAlchemyConfig();\n\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<SendTransactionResult | null>(null);\n\n const sendTransaction = useCallback(\n async (\n input: UnsignedTransactionRequest | UnsignedTransactionRequest[],\n options?: SendTransactionOptions,\n ): Promise<SendTransactionResult> => {\n setIsLoading(true);\n setError(null);\n\n try {\n const { client, account } = await getClient();\n\n // Determine if transaction should be sponsored\n const hasPolicyId = !!config.policyId;\n const enableSponsorship = !config.disableSponsorship;\n const shouldSponsor =\n options?.disableSponsorship !== undefined\n ? !options.disableSponsorship\n : hasPolicyId && enableSponsorship;\n\n // Format the transaction call(s)\n const inputs = Array.isArray(input) ? input : [input];\n const formattedCalls = inputs.map((txn) => ({\n to: txn.to,\n data: txn.data,\n value: txn.value ? normalizeValue(txn.value) : undefined,\n }));\n\n // Build capabilities based on sponsorship and auth mode\n const policyId = Array.isArray(config.policyId)\n ? config.policyId[0]\n : config.policyId;\n\n type Capabilities =\n | { eip7702Auth: true; paymasterService?: { policyId: string } }\n | { paymasterService?: { policyId: string } };\n const capabilities: Capabilities =\n config.accountAuthMode === \"eip7702\" ? { eip7702Auth: true } : {};\n\n if (shouldSponsor && policyId) {\n capabilities.paymasterService = { policyId };\n }\n\n // Send the transaction(s) from the smart account address\n const result = await client.sendCalls({\n from: account.address,\n calls: formattedCalls,\n capabilities,\n });\n\n if (!result.preparedCallIds || result.preparedCallIds.length === 0) {\n throw new Error(\n \"No prepared call IDs returned from transaction submission\",\n );\n }\n\n // Wait for the transaction to be confirmed\n const txStatus = await client.waitForCallsStatus({\n id: result.preparedCallIds[0],\n timeout: 60_000,\n });\n\n const txnHash = txStatus.receipts?.[0]?.transactionHash;\n if (!txnHash) {\n throw new Error(\"Transaction hash not found in receipt\");\n }\n\n const txResult: SendTransactionResult = { txnHash };\n setData(txResult);\n return txResult;\n } catch (err) {\n const errorObj =\n err instanceof Error ? err : new Error(\"Transaction failed\");\n setError(errorObj);\n throw errorObj;\n } finally {\n setIsLoading(false);\n }\n },\n [\n getClient,\n config.policyId,\n config.disableSponsorship,\n config.accountAuthMode,\n ],\n );\n\n const reset = useCallback(() => {\n setError(null);\n setData(null);\n setIsLoading(false);\n }, []);\n\n return {\n sendTransaction,\n isLoading,\n error,\n data,\n reset,\n };\n}\n"]}
1
+ {"version":3,"file":"useAlchemySendTransaction.js","sourceRoot":"","sources":["../../../src/hooks/useAlchemySendTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAY,KAAK,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAQhE;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,KAA+B;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IACnC,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IAC3C,CAAC;IACD,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,wBAAwB;IACxB,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAC3C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,yBAAyB;IACvC,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACzC,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;IAElC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAA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CAAC,QAAQ,CAAC,CAAC;YACnB,MAAM,QAAQ,CAAC;QACjB,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,EACD;QACE,SAAS;QACT,MAAM,CAAC,QAAQ;QACf,MAAM,CAAC,kBAAkB;QACzB,MAAM,CAAC,eAAe;KACvB,CACF,CAAC;IAEF,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,CAAC;QACd,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,eAAe;QACf,SAAS;QACT,KAAK;QACL,IAAI;QACJ,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useState } from \"react\";\nimport { type Hex, isHex } from \"viem\";\nimport { useAlchemyClient } from \"./useAlchemyClient.js\";\nimport { useAlchemyConfig } from \"../context/AlchemyContext.js\";\nimport type {\n UnsignedTransactionRequest,\n SendTransactionOptions,\n SendTransactionResult,\n UseSendTransactionResult,\n} from \"../types\";\n\n/**\n * Normalize value to hex format\n * Accepts bigint, number, decimal string, or hex string\n *\n * @param {string | number | bigint} value - Value to normalize\n * @returns {Hex} Hex string representation of the value\n */\nfunction normalizeValue(value: string | number | bigint): Hex {\n if (typeof value === \"bigint\") {\n return `0x${value.toString(16)}`;\n }\n if (typeof value === \"number\") {\n return `0x${BigInt(value).toString(16)}`;\n }\n if (isHex(value)) {\n return value;\n }\n // Assume decimal string\n return `0x${BigInt(value).toString(16)}`;\n}\n\n/**\n * Hook to send transactions with optional gas sponsorship via Alchemy\n * Supports both single transactions and batch transactions\n * Drop-in alternative to Privy's useSendTransaction hook\n *\n * @returns {UseSendTransactionResult} Hook result with sendTransaction function and state\n *\n * @example Single transaction\n * ```tsx\n * const { sendTransaction, isLoading, error, data } = useAlchemySendTransaction();\n *\n * const handleSend = async () => {\n * try {\n * const result = await sendTransaction({\n * to: '0x...',\n * data: '0x...',\n * value: '1000000000000000000', // 1 ETH\n * });\n * console.log('Transaction hash:', result.txnHash);\n * } catch (err) {\n * console.error('Transaction failed:', err);\n * }\n * };\n * ```\n *\n * @example Batch transactions\n * ```tsx\n * const { sendTransaction } = useAlchemySendTransaction();\n *\n * const result = await sendTransaction([\n * { to: '0x...', data: '0x...', value: '1000000000000000000' },\n * { to: '0x...', data: '0x...' },\n * ]);\n * ```\n */\nexport function useAlchemySendTransaction(): UseSendTransactionResult {\n const { getClient } = useAlchemyClient();\n const config = useAlchemyConfig();\n\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<SendTransactionResult | null>(null);\n\n const sendTransaction = useCallback(\n async (\n input: UnsignedTransactionRequest | UnsignedTransactionRequest[],\n options?: SendTransactionOptions,\n ): Promise<SendTransactionResult> => {\n setIsLoading(true);\n setError(null);\n\n try {\n const { client, account } = await getClient();\n\n // Determine if transaction should be sponsored\n const hasPolicyId = !!config.policyId;\n const enableSponsorship = !config.disableSponsorship;\n const shouldSponsor =\n options?.disableSponsorship !== undefined\n ? !options.disableSponsorship\n : hasPolicyId && enableSponsorship;\n\n // Format the transaction call(s)\n const inputs = Array.isArray(input) ? input : [input];\n const formattedCalls = inputs.map((txn) => ({\n to: txn.to,\n data: txn.data,\n value: txn.value ? normalizeValue(txn.value) : undefined,\n }));\n\n // Build capabilities based on sponsorship and auth mode\n const policyId = Array.isArray(config.policyId)\n ? config.policyId[0]\n : config.policyId;\n\n type Capabilities =\n | { eip7702Auth: true; paymasterService?: { policyId: string } }\n | { paymasterService?: { policyId: string } };\n const capabilities: Capabilities =\n config.accountAuthMode === \"eip7702\" ? { eip7702Auth: true } : {};\n\n if (shouldSponsor && policyId) {\n capabilities.paymasterService = { policyId };\n }\n\n // Send the transaction(s) from the smart account address\n const result = await client.sendCalls({\n from: account.address,\n calls: formattedCalls,\n capabilities,\n });\n\n if (!result.preparedCallIds || result.preparedCallIds.length === 0) {\n throw new Error(\n \"No prepared call IDs returned from transaction submission\",\n );\n }\n\n // Wait for the transaction to be confirmed\n const txStatus = await client.waitForCallsStatus({\n id: result.preparedCallIds[0],\n timeout: 60_000,\n });\n\n const txnHash = txStatus.receipts?.[0]?.transactionHash;\n if (!txnHash) {\n throw new Error(\"Transaction hash not found in receipt\");\n }\n\n const txResult: SendTransactionResult = { txnHash };\n setData(txResult);\n return txResult;\n } catch (err) {\n const errorObj =\n err instanceof Error ? err : new Error(\"Transaction failed\");\n setError(errorObj);\n throw errorObj;\n } finally {\n setIsLoading(false);\n }\n },\n [\n getClient,\n config.policyId,\n config.disableSponsorship,\n config.accountAuthMode,\n ],\n );\n\n const reset = useCallback(() => {\n setError(null);\n setData(null);\n setIsLoading(false);\n }, []);\n\n return {\n sendTransaction,\n isLoading,\n error,\n data,\n reset,\n };\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useMemo, useState } from "react";
2
2
  import { Connection, PublicKey, SystemProgram, Transaction, TransactionInstruction, VersionedTransaction, } from "@solana/web3.js";
3
- import { useAlchemyConfig } from "../Provider.js";
3
+ import { useAlchemyConfig } from "../context/AlchemyContext.js";
4
4
  import { createSolanaSponsoredTransaction } from "../util/createSolanaSponsoredTransaction.js";
5
5
  import { useSignTransaction, useWallets } from "@privy-io/react-auth/solana";
6
6
  import { createSolanaTransaction } from "../util/createSolanaTransaction.js";
@@ -1 +1 @@
1
- {"version":3,"file":"useAlchemySolanaTransaction.js","sourceRoot":"","sources":["../../../src/hooks/useAlchemySolanaTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EACL,UAAU,EACV,SAAS,EACT,aAAa,EACb,WAAW,EACX,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAA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CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC/C,CAAC,EACD,CAAC,oBAAoB,CAAC,CACvB,CAAC;IAEF,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,CAAC,SAAS,CAAC,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,UAAU;QACV,IAAI;QACJ,SAAS;QACT,KAAK;QACL,KAAK;QACL,eAAe;QACf,oBAAoB;KACrB,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,OAAe;IAC9B,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { useCallback, useMemo, useState } from \"react\";\nimport {\n Connection,\n PublicKey,\n SystemProgram,\n Transaction,\n TransactionInstruction,\n VersionedTransaction,\n} from \"@solana/web3.js\";\nimport { useAlchemyConfig } from \"../Provider.js\";\nimport { createSolanaSponsoredTransaction } from \"../util/createSolanaSponsoredTransaction.js\";\nimport { useSignTransaction, useWallets } from \"@privy-io/react-auth/solana\";\nimport { createSolanaTransaction } from \"../util/createSolanaTransaction.js\";\n\n/**\n * Type helper for values that can be synchronous or asynchronous\n *\n * @template T - The value type\n */\nexport type PromiseOrValue<T> = T | Promise<T>;\n\n/**\n * Callback to modify a transaction before it's signed\n * Useful for adding additional signatures or metadata\n *\n * @param transaction - The unsigned transaction to modify\n * @returns The modified transaction\n */\nexport type PreSend = (\n this: void,\n transaction: VersionedTransaction | Transaction,\n) => PromiseOrValue<VersionedTransaction | Transaction>;\n\n/**\n * Callback to transform instructions into a custom transaction\n * Useful for advanced transaction construction (e.g., multi-sig, custom versioning)\n *\n * @param instructions - Array of Solana transaction instructions\n * @returns Constructed transaction (legacy or versioned)\n */\nexport type TransformInstruction = (\n this: void,\n instructions: TransactionInstruction[],\n) => PromiseOrValue<Transaction | VersionedTransaction>;\n\n/**\n * Optional transaction lifecycle hooks for advanced use cases\n */\nexport type SolanaTransactionParamOptions = {\n /** Hook called before signing the transaction */\n preSend?: PreSend;\n /** Custom transaction builder from instructions */\n transformInstruction?: TransformInstruction;\n};\n\n/**\n * Parameters for sending a Solana transaction\n * Supports either a simple transfer or custom instructions\n */\nexport type SolanaTransactionParams =\n | {\n /** Simple SOL transfer parameters */\n transfer: {\n /** Amount in lamports (accepts number or bigint) */\n amount: number | bigint;\n /** Recipient's base58-encoded address */\n toAddress: string;\n };\n /** Optional transaction lifecycle hooks */\n transactionComponents?: SolanaTransactionParamOptions;\n /** Options for confirming the transaction on-chain */\n confirmationOptions?: Parameters<Connection[\"confirmTransaction\"]>[1];\n }\n | {\n /** Custom Solana transaction instructions */\n instructions: TransactionInstruction[];\n /** Optional transaction lifecycle hooks */\n transactionComponents?: SolanaTransactionParamOptions;\n /** Options for confirming the transaction on-chain */\n confirmationOptions?: Parameters<Connection[\"confirmTransaction\"]>[1];\n };\n\n/**\n * Result of a successful Solana transaction\n */\nexport interface SolanaTransactionResult {\n /** Base58-encoded transaction signature (hash) */\n hash: string;\n}\n\n/**\n * Configuration options for useAlchemySolanaTransaction hook\n */\nexport interface UseAlchemySolanaTransactionOptions {\n /** Solana RPC URL (overrides provider config) */\n rpcUrl?: string;\n /** Gas sponsorship policy ID (overrides provider config) */\n policyId?: string | void;\n /** Transaction confirmation options */\n confirmationOptions?: Parameters<Connection[\"confirmTransaction\"]>[1];\n /** Specific wallet address to use (defaults to first available wallet) */\n walletAddress?: string;\n}\n\n/**\n * Return type of useAlchemySolanaTransaction hook\n */\nexport interface UseAlchemySolanaTransactionResult {\n /** Active Solana connection instance */\n readonly connection: Connection | null;\n /** Transaction result if successful */\n readonly data: void | SolanaTransactionResult;\n /** Whether a transaction is currently being sent */\n readonly isPending: boolean;\n /** Error if transaction failed */\n readonly error: Error | null;\n /** Reset hook state (clears error, data, isPending) */\n reset(): void;\n /** Send transaction (fire-and-forget, errors caught internally) */\n sendTransaction(params: SolanaTransactionParams): void;\n /** Send transaction and await result (throws on error) */\n sendTransactionAsync(\n params: SolanaTransactionParams,\n ): Promise<SolanaTransactionResult>;\n}\n\n/**\n * Hook to send Solana transactions with optional gas sponsorship via Alchemy\n * Works with Privy's Solana wallet integration for signing transactions\n * Supports both simple transfers and custom instruction sets\n *\n * @param {UseAlchemySolanaTransactionOptions} [opts] - Configuration options\n * @param {string} [opts.rpcUrl] - Solana RPC URL (overrides provider config)\n * @param {string} [opts.policyId] - Gas sponsorship policy ID (overrides provider config)\n * @param {string} [opts.walletAddress] - Specific wallet address to use (defaults to first wallet)\n * @param {Parameters<Connection[\"confirmTransaction\"]>[1]} [opts.confirmationOptions] - Transaction confirmation options\n * @returns {UseAlchemySolanaTransactionResult} Hook result with transaction functions and state\n *\n * @example Simple SOL transfer\n * ```tsx\n * const { sendTransactionAsync, isPending, error, data } = useAlchemySolanaTransaction({\n * rpcUrl: 'https://solana-mainnet.g.alchemy.com/v2/your-api-key',\n * policyId: 'your-policy-id', // Optional: for gas sponsorship\n * });\n *\n * const handleTransfer = async () => {\n * try {\n * const result = await sendTransactionAsync({\n * transfer: {\n * amount: 1_000_000_000, // 1 SOL in lamports\n * toAddress: 'recipient-address',\n * },\n * });\n * console.log('Transaction hash:', result.hash);\n * } catch (err) {\n * console.error('Transaction failed:', err);\n * }\n * };\n * ```\n *\n * @example Custom instructions\n * ```tsx\n * import { SystemProgram, PublicKey } from '@solana/web3.js';\n *\n * const { sendTransactionAsync } = useAlchemySolanaTransaction();\n *\n * // Build your custom instructions\n * const transferIx = SystemProgram.transfer({\n * fromPubkey: new PublicKey(walletAddress),\n * toPubkey: new PublicKey(recipientAddress),\n * lamports: 1_000_000,\n * });\n *\n * // Pass instructions array to the hook\n * const result = await sendTransactionAsync({\n * instructions: [transferIx],\n * });\n * ```\n *\n * @example With provider configuration\n * ```tsx\n * // In your provider setup\n * <AlchemyProvider\n * solanaRpcUrl=\"https://solana-mainnet.g.alchemy.com/v2/...\"\n * solanaPolicyId=\"your-solana-policy-id\"\n * >\n * <YourApp />\n * </AlchemyProvider>\n *\n * // In your component - uses provider config automatically\n * const { sendTransactionAsync } = useAlchemySolanaTransaction();\n * ```\n */\nexport function useAlchemySolanaTransaction(\n opts: UseAlchemySolanaTransactionOptions = {},\n): UseAlchemySolanaTransactionResult {\n const config = useAlchemyConfig();\n const { wallets } = useWallets();\n const { signTransaction } = useSignTransaction();\n\n // Resolve the Privy Solana wallet to use\n const embeddedWallet = useMemo(() => {\n if (opts.walletAddress) {\n const w = wallets.find((w) => w.address === opts.walletAddress);\n if (!w) throw new Error(\"Specified Solana wallet not found\");\n return w;\n }\n return wallets[0];\n }, [wallets, opts.walletAddress]);\n\n // Build Solana connection from rpcUrl (hook override or provider default)\n const connection = useMemo(() => {\n const url = opts.rpcUrl || config.solanaRpcUrl;\n return url ? new Connection(url) : null;\n }, [opts.rpcUrl, config.solanaRpcUrl]);\n\n const [isPending, setIsPending] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<void | SolanaTransactionResult>(undefined);\n\n const resolvedPolicyId = useMemo(() => {\n if (opts.policyId != null) return opts.policyId || undefined;\n // Use solanaPolicyId from config, fallback to policyId for backwards compat\n const configPolicy = config.solanaPolicyId || config.policyId;\n return Array.isArray(configPolicy) ? configPolicy[0] : configPolicy;\n }, [opts.policyId, config.solanaPolicyId, config.policyId]);\n\n const mapTransformInstructions = useMemo(() => {\n const addSponsorship: TransformInstruction = async (instructions) => {\n const policyId = resolvedPolicyId;\n if (!policyId)\n throw new Error(\n \"Gas sponsorship requires a policyId (see provider or hook options).\",\n );\n const localConnection = connection || missing(\"connection\");\n const fromAddress = embeddedWallet?.address;\n if (!fromAddress) throw new Error(\"No embedded Solana wallet connected\");\n return createSolanaSponsoredTransaction(\n instructions,\n localConnection,\n policyId,\n fromAddress,\n );\n };\n const createTx: TransformInstruction = async (instructions) => {\n const localConnection = connection || missing(\"connection\");\n const fromAddress = embeddedWallet?.address;\n if (!fromAddress) throw new Error(\"No embedded Solana wallet connected\");\n return createSolanaTransaction(\n instructions,\n localConnection,\n fromAddress,\n );\n };\n const defaultTransform =\n !!resolvedPolicyId && !config.disableSponsorship\n ? addSponsorship\n : createTx;\n return {\n addSponsorship,\n createTransaction: createTx,\n default: defaultTransform,\n } as const;\n }, [\n resolvedPolicyId,\n config.disableSponsorship,\n connection,\n embeddedWallet?.address,\n ]);\n\n const buildInstructions = useCallback(\n (\n params: SolanaTransactionParams,\n fromAddress: string,\n ): TransactionInstruction[] => {\n if (\"instructions\" in params) return params.instructions;\n return [\n SystemProgram.transfer({\n fromPubkey: new PublicKey(fromAddress),\n toPubkey: new PublicKey(params.transfer.toAddress),\n lamports:\n typeof params.transfer.amount === \"bigint\"\n ? Number(params.transfer.amount) // web3.js currently expects number; callers can pass bigint safely\n : params.transfer.amount,\n }),\n ];\n },\n [],\n );\n\n function toUnsignedBytes(tx: VersionedTransaction | Transaction): Uint8Array {\n // Serialize the full transaction structure (with placeholder signatures)\n // Privy expects the complete transaction format, not just the message\n if (tx instanceof VersionedTransaction) {\n // VersionedTransaction.serialize() includes signature slots\n return tx.serialize();\n }\n // Legacy Transaction: serialize without requiring all signatures\n const buf = tx.serialize({\n requireAllSignatures: false,\n verifySignatures: false,\n });\n return buf instanceof Uint8Array ? buf : new Uint8Array(buf);\n }\n\n const sendTransactionAsync = useCallback(\n async (\n params: SolanaTransactionParams,\n ): Promise<SolanaTransactionResult> => {\n setIsPending(true);\n setError(null);\n try {\n const localConnection = connection || missing(\"connection\");\n if (!embeddedWallet?.address) {\n throw new Error(\"No Solana wallet connected via Privy\");\n }\n\n const fromAddress = embeddedWallet.address;\n const {\n transactionComponents: { preSend, transformInstruction } = {},\n confirmationOptions,\n } = params;\n\n const instructions = buildInstructions(params, fromAddress);\n\n let transaction: VersionedTransaction | Transaction;\n if (transformInstruction) {\n transaction = await transformInstruction(instructions);\n } else {\n transaction = await mapTransformInstructions.default(instructions);\n }\n\n transaction = (await preSend?.(transaction)) || transaction;\n\n // Sign the transaction using Privy's useSignTransaction hook\n const unsignedBytes = toUnsignedBytes(transaction);\n const { signedTransaction } = await signTransaction({\n transaction: unsignedBytes,\n wallet: embeddedWallet,\n });\n\n // Broadcast the signed transaction\n const hash = await localConnection.sendRawTransaction(\n signedTransaction,\n { skipPreflight: false },\n );\n\n if (confirmationOptions || opts.confirmationOptions) {\n await localConnection.confirmTransaction(\n hash,\n confirmationOptions || opts.confirmationOptions,\n );\n }\n\n setData({ hash });\n return { hash };\n } catch (err) {\n const e = err instanceof Error ? err : new Error(String(err));\n setError(e);\n throw e;\n } finally {\n setIsPending(false);\n }\n },\n [\n embeddedWallet,\n connection,\n buildInstructions,\n mapTransformInstructions,\n opts.confirmationOptions,\n signTransaction,\n ],\n );\n\n const sendTransaction = useCallback(\n (params: SolanaTransactionParams) => {\n // Prevent unhandled rejection warnings; error state is already set in sendTransactionAsync\n sendTransactionAsync(params).catch(() => {});\n },\n [sendTransactionAsync],\n );\n\n const reset = useCallback(() => {\n setIsPending(false);\n setError(null);\n setData(undefined);\n }, []);\n\n return {\n connection,\n data,\n isPending,\n error,\n reset,\n sendTransaction,\n sendTransactionAsync,\n };\n}\n\nfunction missing(message: string): never {\n throw new Error(message);\n}\n"]}
1
+ {"version":3,"file":"useAlchemySolanaTransaction.js","sourceRoot":"","sources":["../../../src/hooks/useAlchemySolanaTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EACL,UAAU,EACV,SAAS,EACT,aAAa,EACb,WAAW,EACX,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,gCAAgC,EAAE,MAAM,6CAA6C,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAAE,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,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,CAAC,SAAS,CAAC,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,UAAU;QACV,IAAI;QACJ,SAAS;QACT,KAAK;QACL,KAAK;QACL,eAAe;QACf,oBAAoB;KACrB,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,OAAe;IAC9B,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { useCallback, useMemo, useState } from \"react\";\nimport {\n Connection,\n PublicKey,\n SystemProgram,\n Transaction,\n TransactionInstruction,\n VersionedTransaction,\n} from \"@solana/web3.js\";\nimport { useAlchemyConfig } from \"../context/AlchemyContext.js\";\nimport { createSolanaSponsoredTransaction } from \"../util/createSolanaSponsoredTransaction.js\";\nimport { useSignTransaction, useWallets } from \"@privy-io/react-auth/solana\";\nimport { createSolanaTransaction } from \"../util/createSolanaTransaction.js\";\n\n/**\n * Type helper for values that can be synchronous or asynchronous\n *\n * @template T - The value type\n */\nexport type PromiseOrValue<T> = T | Promise<T>;\n\n/**\n * Callback to modify a transaction before it's signed\n * Useful for adding additional signatures or metadata\n *\n * @param transaction - The unsigned transaction to modify\n * @returns The modified transaction\n */\nexport type PreSend = (\n this: void,\n transaction: VersionedTransaction | Transaction,\n) => PromiseOrValue<VersionedTransaction | Transaction>;\n\n/**\n * Callback to transform instructions into a custom transaction\n * Useful for advanced transaction construction (e.g., multi-sig, custom versioning)\n *\n * @param instructions - Array of Solana transaction instructions\n * @returns Constructed transaction (legacy or versioned)\n */\nexport type TransformInstruction = (\n this: void,\n instructions: TransactionInstruction[],\n) => PromiseOrValue<Transaction | VersionedTransaction>;\n\n/**\n * Optional transaction lifecycle hooks for advanced use cases\n */\nexport type SolanaTransactionParamOptions = {\n /** Hook called before signing the transaction */\n preSend?: PreSend;\n /** Custom transaction builder from instructions */\n transformInstruction?: TransformInstruction;\n};\n\n/**\n * Parameters for sending a Solana transaction\n * Supports either a simple transfer or custom instructions\n */\nexport type SolanaTransactionParams =\n | {\n /** Simple SOL transfer parameters */\n transfer: {\n /** Amount in lamports (accepts number or bigint) */\n amount: number | bigint;\n /** Recipient's base58-encoded address */\n toAddress: string;\n };\n /** Optional transaction lifecycle hooks */\n transactionComponents?: SolanaTransactionParamOptions;\n /** Options for confirming the transaction on-chain */\n confirmationOptions?: Parameters<Connection[\"confirmTransaction\"]>[1];\n }\n | {\n /** Custom Solana transaction instructions */\n instructions: TransactionInstruction[];\n /** Optional transaction lifecycle hooks */\n transactionComponents?: SolanaTransactionParamOptions;\n /** Options for confirming the transaction on-chain */\n confirmationOptions?: Parameters<Connection[\"confirmTransaction\"]>[1];\n };\n\n/**\n * Result of a successful Solana transaction\n */\nexport interface SolanaTransactionResult {\n /** Base58-encoded transaction signature (hash) */\n hash: string;\n}\n\n/**\n * Configuration options for useAlchemySolanaTransaction hook\n */\nexport interface UseAlchemySolanaTransactionOptions {\n /** Solana RPC URL (overrides provider config) */\n rpcUrl?: string;\n /** Gas sponsorship policy ID (overrides provider config) */\n policyId?: string | void;\n /** Transaction confirmation options */\n confirmationOptions?: Parameters<Connection[\"confirmTransaction\"]>[1];\n /** Specific wallet address to use (defaults to first available wallet) */\n walletAddress?: string;\n}\n\n/**\n * Return type of useAlchemySolanaTransaction hook\n */\nexport interface UseAlchemySolanaTransactionResult {\n /** Active Solana connection instance */\n readonly connection: Connection | null;\n /** Transaction result if successful */\n readonly data: void | SolanaTransactionResult;\n /** Whether a transaction is currently being sent */\n readonly isPending: boolean;\n /** Error if transaction failed */\n readonly error: Error | null;\n /** Reset hook state (clears error, data, isPending) */\n reset(): void;\n /** Send transaction (fire-and-forget, errors caught internally) */\n sendTransaction(params: SolanaTransactionParams): void;\n /** Send transaction and await result (throws on error) */\n sendTransactionAsync(\n params: SolanaTransactionParams,\n ): Promise<SolanaTransactionResult>;\n}\n\n/**\n * Hook to send Solana transactions with optional gas sponsorship via Alchemy\n * Works with Privy's Solana wallet integration for signing transactions\n * Supports both simple transfers and custom instruction sets\n *\n * @param {UseAlchemySolanaTransactionOptions} [opts] - Configuration options\n * @param {string} [opts.rpcUrl] - Solana RPC URL (overrides provider config)\n * @param {string} [opts.policyId] - Gas sponsorship policy ID (overrides provider config)\n * @param {string} [opts.walletAddress] - Specific wallet address to use (defaults to first wallet)\n * @param {Parameters<Connection[\"confirmTransaction\"]>[1]} [opts.confirmationOptions] - Transaction confirmation options\n * @returns {UseAlchemySolanaTransactionResult} Hook result with transaction functions and state\n *\n * @example Simple SOL transfer\n * ```tsx\n * const { sendTransactionAsync, isPending, error, data } = useAlchemySolanaTransaction({\n * rpcUrl: 'https://solana-mainnet.g.alchemy.com/v2/your-api-key',\n * policyId: 'your-policy-id', // Optional: for gas sponsorship\n * });\n *\n * const handleTransfer = async () => {\n * try {\n * const result = await sendTransactionAsync({\n * transfer: {\n * amount: 1_000_000_000, // 1 SOL in lamports\n * toAddress: 'recipient-address',\n * },\n * });\n * console.log('Transaction hash:', result.hash);\n * } catch (err) {\n * console.error('Transaction failed:', err);\n * }\n * };\n * ```\n *\n * @example Custom instructions\n * ```tsx\n * import { SystemProgram, PublicKey } from '@solana/web3.js';\n *\n * const { sendTransactionAsync } = useAlchemySolanaTransaction();\n *\n * // Build your custom instructions\n * const transferIx = SystemProgram.transfer({\n * fromPubkey: new PublicKey(walletAddress),\n * toPubkey: new PublicKey(recipientAddress),\n * lamports: 1_000_000,\n * });\n *\n * // Pass instructions array to the hook\n * const result = await sendTransactionAsync({\n * instructions: [transferIx],\n * });\n * ```\n *\n * @example With provider configuration\n * ```tsx\n * // In your provider setup\n * <AlchemyProvider\n * solanaRpcUrl=\"https://solana-mainnet.g.alchemy.com/v2/...\"\n * solanaPolicyId=\"your-solana-policy-id\"\n * >\n * <YourApp />\n * </AlchemyProvider>\n *\n * // In your component - uses provider config automatically\n * const { sendTransactionAsync } = useAlchemySolanaTransaction();\n * ```\n */\nexport function useAlchemySolanaTransaction(\n opts: UseAlchemySolanaTransactionOptions = {},\n): UseAlchemySolanaTransactionResult {\n const config = useAlchemyConfig();\n const { wallets } = useWallets();\n const { signTransaction } = useSignTransaction();\n\n // Resolve the Privy Solana wallet to use\n const embeddedWallet = useMemo(() => {\n if (opts.walletAddress) {\n const w = wallets.find((w) => w.address === opts.walletAddress);\n if (!w) throw new Error(\"Specified Solana wallet not found\");\n return w;\n }\n return wallets[0];\n }, [wallets, opts.walletAddress]);\n\n // Build Solana connection from rpcUrl (hook override or provider default)\n const connection = useMemo(() => {\n const url = opts.rpcUrl || config.solanaRpcUrl;\n return url ? new Connection(url) : null;\n }, [opts.rpcUrl, config.solanaRpcUrl]);\n\n const [isPending, setIsPending] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<void | SolanaTransactionResult>(undefined);\n\n const resolvedPolicyId = useMemo(() => {\n if (opts.policyId != null) return opts.policyId || undefined;\n // Use solanaPolicyId from config, fallback to policyId for backwards compat\n const configPolicy = config.solanaPolicyId || config.policyId;\n return Array.isArray(configPolicy) ? configPolicy[0] : configPolicy;\n }, [opts.policyId, config.solanaPolicyId, config.policyId]);\n\n const mapTransformInstructions = useMemo(() => {\n const addSponsorship: TransformInstruction = async (instructions) => {\n const policyId = resolvedPolicyId;\n if (!policyId)\n throw new Error(\n \"Gas sponsorship requires a policyId (see provider or hook options).\",\n );\n const localConnection = connection || missing(\"connection\");\n const fromAddress = embeddedWallet?.address;\n if (!fromAddress) throw new Error(\"No embedded Solana wallet connected\");\n return createSolanaSponsoredTransaction(\n instructions,\n localConnection,\n policyId,\n fromAddress,\n );\n };\n const createTx: TransformInstruction = async (instructions) => {\n const localConnection = connection || missing(\"connection\");\n const fromAddress = embeddedWallet?.address;\n if (!fromAddress) throw new Error(\"No embedded Solana wallet connected\");\n return createSolanaTransaction(\n instructions,\n localConnection,\n fromAddress,\n );\n };\n const defaultTransform =\n !!resolvedPolicyId && !config.disableSponsorship\n ? addSponsorship\n : createTx;\n return {\n addSponsorship,\n createTransaction: createTx,\n default: defaultTransform,\n } as const;\n }, [\n resolvedPolicyId,\n config.disableSponsorship,\n connection,\n embeddedWallet?.address,\n ]);\n\n const buildInstructions = useCallback(\n (\n params: SolanaTransactionParams,\n fromAddress: string,\n ): TransactionInstruction[] => {\n if (\"instructions\" in params) return params.instructions;\n return [\n SystemProgram.transfer({\n fromPubkey: new PublicKey(fromAddress),\n toPubkey: new PublicKey(params.transfer.toAddress),\n lamports:\n typeof params.transfer.amount === \"bigint\"\n ? Number(params.transfer.amount) // web3.js currently expects number; callers can pass bigint safely\n : params.transfer.amount,\n }),\n ];\n },\n [],\n );\n\n function toUnsignedBytes(tx: VersionedTransaction | Transaction): Uint8Array {\n // Serialize the full transaction structure (with placeholder signatures)\n // Privy expects the complete transaction format, not just the message\n if (tx instanceof VersionedTransaction) {\n // VersionedTransaction.serialize() includes signature slots\n return tx.serialize();\n }\n // Legacy Transaction: serialize without requiring all signatures\n const buf = tx.serialize({\n requireAllSignatures: false,\n verifySignatures: false,\n });\n return buf instanceof Uint8Array ? buf : new Uint8Array(buf);\n }\n\n const sendTransactionAsync = useCallback(\n async (\n params: SolanaTransactionParams,\n ): Promise<SolanaTransactionResult> => {\n setIsPending(true);\n setError(null);\n try {\n const localConnection = connection || missing(\"connection\");\n if (!embeddedWallet?.address) {\n throw new Error(\"No Solana wallet connected via Privy\");\n }\n\n const fromAddress = embeddedWallet.address;\n const {\n transactionComponents: { preSend, transformInstruction } = {},\n confirmationOptions,\n } = params;\n\n const instructions = buildInstructions(params, fromAddress);\n\n let transaction: VersionedTransaction | Transaction;\n if (transformInstruction) {\n transaction = await transformInstruction(instructions);\n } else {\n transaction = await mapTransformInstructions.default(instructions);\n }\n\n transaction = (await preSend?.(transaction)) || transaction;\n\n // Sign the transaction using Privy's useSignTransaction hook\n const unsignedBytes = toUnsignedBytes(transaction);\n const { signedTransaction } = await signTransaction({\n transaction: unsignedBytes,\n wallet: embeddedWallet,\n });\n\n // Broadcast the signed transaction\n const hash = await localConnection.sendRawTransaction(\n signedTransaction,\n { skipPreflight: false },\n );\n\n if (confirmationOptions || opts.confirmationOptions) {\n await localConnection.confirmTransaction(\n hash,\n confirmationOptions || opts.confirmationOptions,\n );\n }\n\n setData({ hash });\n return { hash };\n } catch (err) {\n const e = err instanceof Error ? err : new Error(String(err));\n setError(e);\n throw e;\n } finally {\n setIsPending(false);\n }\n },\n [\n embeddedWallet,\n connection,\n buildInstructions,\n mapTransformInstructions,\n opts.confirmationOptions,\n signTransaction,\n ],\n );\n\n const sendTransaction = useCallback(\n (params: SolanaTransactionParams) => {\n // Prevent unhandled rejection warnings; error state is already set in sendTransactionAsync\n sendTransactionAsync(params).catch(() => {});\n },\n [sendTransactionAsync],\n );\n\n const reset = useCallback(() => {\n setIsPending(false);\n setError(null);\n setData(undefined);\n }, []);\n\n return {\n connection,\n data,\n isPending,\n error,\n reset,\n sendTransaction,\n sendTransactionAsync,\n };\n}\n\nfunction missing(message: string): never {\n throw new Error(message);\n}\n"]}
@@ -0,0 +1,37 @@
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;
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AlchemyContextProvider } from "../context/AlchemyContext.js";
3
+ import { reactNativeAdapter } from "../adapters/react-native.js";
4
+ /**
5
+ * Provider component for React Native (Expo) applications
6
+ * Must be nested INSIDE PrivyProvider from @privy-io/expo
7
+ *
8
+ * @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props
9
+ * @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration
10
+ * @param {string} [props.apiKey] - Your Alchemy API key
11
+ * @param {string} [props.jwt] - JWT token for authentication
12
+ * @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains
13
+ * @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana
14
+ * @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains
15
+ * @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana
16
+ * @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)
17
+ * @param {'eip7702' | 'owner'} [props.accountAuthMode] - Authorization mode for EVM smart accounts (default: 'eip7702')
18
+ * @param {string} [props.walletAddress] - Optional: Specify which wallet address to use (defaults to first wallet in array)
19
+ * @returns {JSX.Element} Provider component
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * import { PrivyProvider } from '@privy-io/expo';
24
+ * import { AlchemyProvider } from '@account-kit/privy-integration/react-native';
25
+ *
26
+ * <PrivyProvider appId="..." clientId="...">
27
+ * <AlchemyProvider
28
+ * apiKey="your-alchemy-api-key"
29
+ * policyId="your-gas-policy-id"
30
+ * accountAuthMode="eip7702"
31
+ * walletAddress="0x123..." // Optional: specify which wallet to use
32
+ * >
33
+ * <YourApp />
34
+ * </AlchemyProvider>
35
+ * </PrivyProvider>
36
+ * ```
37
+ */
38
+ export function AlchemyProvider({ children, ...config }) {
39
+ return (_jsx(AlchemyContextProvider, { config: config, adapter: reactNativeAdapter, children: children }));
40
+ }
41
+ //# sourceMappingURL=ReactNativeProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeProvider.js","sourceRoot":"","sources":["../../../src/providers/ReactNativeProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,QAAQ,EACR,GAAG,MAAM,EACgC;IACzC,OAAO,CACL,KAAC,sBAAsB,IAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,YAChE,QAAQ,GACc,CAC1B,CAAC;AACJ,CAAC","sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport { AlchemyContextProvider } from \"../context/AlchemyContext.js\";\nimport { reactNativeAdapter } from \"../adapters/react-native.js\";\nimport type { AlchemyProviderConfig } from \"../types.js\";\n\n/**\n * Provider component for React Native (Expo) applications\n * Must be nested INSIDE PrivyProvider from @privy-io/expo\n *\n * @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props\n * @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration\n * @param {string} [props.apiKey] - Your Alchemy API key\n * @param {string} [props.jwt] - JWT token for authentication\n * @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains\n * @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana\n * @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains\n * @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana\n * @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)\n * @param {'eip7702' | 'owner'} [props.accountAuthMode] - Authorization mode for EVM smart accounts (default: 'eip7702')\n * @param {string} [props.walletAddress] - Optional: Specify which wallet address to use (defaults to first wallet in array)\n * @returns {JSX.Element} Provider component\n *\n * @example\n * ```tsx\n * import { PrivyProvider } from '@privy-io/expo';\n * import { AlchemyProvider } from '@account-kit/privy-integration/react-native';\n *\n * <PrivyProvider appId=\"...\" clientId=\"...\">\n * <AlchemyProvider\n * apiKey=\"your-alchemy-api-key\"\n * policyId=\"your-gas-policy-id\"\n * accountAuthMode=\"eip7702\"\n * walletAddress=\"0x123...\" // Optional: specify which wallet to use\n * >\n * <YourApp />\n * </AlchemyProvider>\n * </PrivyProvider>\n * ```\n */\nexport function AlchemyProvider({\n children,\n ...config\n}: PropsWithChildren<AlchemyProviderConfig>) {\n return (\n <AlchemyContextProvider config={config} adapter={reactNativeAdapter}>\n {children}\n </AlchemyContextProvider>\n );\n}\n"]}
@@ -0,0 +1,37 @@
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;
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AlchemyContextProvider } from "../context/AlchemyContext.js";
3
+ import { webAdapter } from "../adapters/web.js";
4
+ /**
5
+ * Provider component for React web applications
6
+ * Must be nested INSIDE PrivyProvider from @privy-io/react-auth
7
+ *
8
+ * @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props
9
+ * @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration
10
+ * @param {string} [props.apiKey] - Your Alchemy API key
11
+ * @param {string} [props.jwt] - JWT token for authentication
12
+ * @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains
13
+ * @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana
14
+ * @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains
15
+ * @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana
16
+ * @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)
17
+ * @param {'eip7702' | 'owner'} [props.accountAuthMode] - Authorization mode for EVM smart accounts (default: 'eip7702')
18
+ * @param {string} [props.walletAddress] - Optional: Specify which wallet address to use (defaults to first embedded wallet)
19
+ * @returns {JSX.Element} Provider component
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * import { PrivyProvider } from '@privy-io/react-auth';
24
+ * import { AlchemyProvider } from '@account-kit/privy-integration';
25
+ *
26
+ * <PrivyProvider appId="...">
27
+ * <AlchemyProvider
28
+ * apiKey="your-alchemy-api-key"
29
+ * policyId="your-gas-policy-id"
30
+ * accountAuthMode="eip7702"
31
+ * walletAddress="0x123..." // Optional: specify which wallet to use
32
+ * >
33
+ * <YourApp />
34
+ * </AlchemyProvider>
35
+ * </PrivyProvider>
36
+ * ```
37
+ */
38
+ export function AlchemyProvider({ children, ...config }) {
39
+ return (_jsx(AlchemyContextProvider, { config: config, adapter: webAdapter, children: children }));
40
+ }
41
+ //# sourceMappingURL=WebProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebProvider.js","sourceRoot":"","sources":["../../../src/providers/WebProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,QAAQ,EACR,GAAG,MAAM,EACgC;IACzC,OAAO,CACL,KAAC,sBAAsB,IAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,YACxD,QAAQ,GACc,CAC1B,CAAC;AACJ,CAAC","sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport { AlchemyContextProvider } from \"../context/AlchemyContext.js\";\nimport { webAdapter } from \"../adapters/web.js\";\nimport type { AlchemyProviderConfig } from \"../types.js\";\n\n/**\n * Provider component for React web applications\n * Must be nested INSIDE PrivyProvider from @privy-io/react-auth\n *\n * @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props\n * @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration\n * @param {string} [props.apiKey] - Your Alchemy API key\n * @param {string} [props.jwt] - JWT token for authentication\n * @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains\n * @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana\n * @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains\n * @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana\n * @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)\n * @param {'eip7702' | 'owner'} [props.accountAuthMode] - Authorization mode for EVM smart accounts (default: 'eip7702')\n * @param {string} [props.walletAddress] - Optional: Specify which wallet address to use (defaults to first embedded wallet)\n * @returns {JSX.Element} Provider component\n *\n * @example\n * ```tsx\n * import { PrivyProvider } from '@privy-io/react-auth';\n * import { AlchemyProvider } from '@account-kit/privy-integration';\n *\n * <PrivyProvider appId=\"...\">\n * <AlchemyProvider\n * apiKey=\"your-alchemy-api-key\"\n * policyId=\"your-gas-policy-id\"\n * accountAuthMode=\"eip7702\"\n * walletAddress=\"0x123...\" // Optional: specify which wallet to use\n * >\n * <YourApp />\n * </AlchemyProvider>\n * </PrivyProvider>\n * ```\n */\nexport function AlchemyProvider({\n children,\n ...config\n}: PropsWithChildren<AlchemyProviderConfig>) {\n return (\n <AlchemyContextProvider config={config} adapter={webAdapter}>\n {children}\n </AlchemyContextProvider>\n );\n}\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * React Native stub for WebProvider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+ export declare function AlchemyProvider(): void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * React Native stub for WebProvider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+ export function AlchemyProvider() {
6
+ throw new Error("This module requires @privy-io/react-auth which is not available in React Native. " +
7
+ 'Import from "@account-kit/privy-integration/react-native" instead.');
8
+ }
9
+ //# sourceMappingURL=WebProvider.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebProvider.native.js","sourceRoot":"","sources":["../../../src/providers/WebProvider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,UAAU,eAAe;IAC7B,MAAM,IAAI,KAAK,CACb,oFAAoF;QAClF,oEAAoE,CACvE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * React Native stub for WebProvider\n * This file prevents Metro from importing web-specific code\n */\n\nexport function AlchemyProvider() {\n throw new Error(\n \"This module requires @privy-io/react-auth which is not available in React Native. \" +\n 'Import from \"@account-kit/privy-integration/react-native\" instead.',\n );\n}\n"]}
@@ -0,0 +1,11 @@
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";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * React Native (Expo) entry point
3
+ * Import from '@account-kit/privy-integration/react-native' in Expo apps
4
+ */
5
+ // Provider
6
+ export { AlchemyProvider } from "./providers/ReactNativeProvider.js";
7
+ export { useAlchemyConfig } from "./context/AlchemyContext.js";
8
+ // Hooks
9
+ export { useAlchemyClient } from "./hooks/useAlchemyClient.js";
10
+ export { useAlchemySendTransaction } from "./hooks/useAlchemySendTransaction.js";
11
+ export { useAlchemyPrepareSwap } from "./hooks/useAlchemyPrepareSwap.js";
12
+ export { useAlchemySubmitSwap } from "./hooks/useAlchemySubmitSwap.js";
13
+ //# sourceMappingURL=react-native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-native.js","sourceRoot":"","sources":["../../src/react-native.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,WAAW;AACX,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,QAAQ;AACR,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","sourcesContent":["/**\n * React Native (Expo) entry point\n * Import from '@account-kit/privy-integration/react-native' in Expo apps\n */\n\n// Provider\nexport { AlchemyProvider } from \"./providers/ReactNativeProvider.js\";\nexport { useAlchemyConfig } from \"./context/AlchemyContext.js\";\n\n// Hooks\nexport { useAlchemyClient } from \"./hooks/useAlchemyClient.js\";\nexport { useAlchemySendTransaction } from \"./hooks/useAlchemySendTransaction.js\";\nexport { useAlchemyPrepareSwap } from \"./hooks/useAlchemyPrepareSwap.js\";\nexport { useAlchemySubmitSwap } from \"./hooks/useAlchemySubmitSwap.js\";\n\n// Types\nexport type {\n AlchemyProviderConfig,\n UnsignedTransactionRequest,\n SendTransactionOptions,\n SendTransactionResult,\n UseSendTransactionResult,\n PrepareSwapRequest,\n PrepareSwapResult,\n UsePrepareSwapResult,\n SubmitSwapResult,\n UseSubmitSwapResult,\n SwapQuote,\n} from \"./types.js\";\n"]}
@@ -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.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC","sourcesContent":["import type { Address, Hash, Hex } from \"viem\";\nimport type { swapActions } from \"@account-kit/wallet-client/experimental\";\nimport { ConnectionConfigSchema } from \"@aa-sdk/core\";\nimport type { z } from \"zod\";\n\n/**\n * Configuration for the Alchemy provider\n * Uses ConnectionConfigSchema to ensure valid transport configuration\n */\nexport type AlchemyProviderConfig = z.infer<typeof ConnectionConfigSchema> & {\n /** Policy ID(s) for EVM gas sponsorship */\n policyId?: string | string[];\n\n /** Policy ID(s) for Solana gas sponsorship */\n solanaPolicyId?: string | string[];\n\n /** Solana RPC URL (separate from EVM rpcUrl) */\n solanaRpcUrl?: string;\n\n /**\n * How EVM smart account calls should be authorized.\n * - 'eip7702' (default): delegated authorization via EIP-7702.\n * - 'owner': sign as the account owner (Privy embedded wallet), no 7702.\n */\n accountAuthMode?: \"eip7702\" | \"owner\";\n\n /**\n * Set to true to disable gas sponsorship by default\n * Default: false (sponsorship enabled when policyId is provided)\n */\n disableSponsorship?: boolean;\n};\n\n/**\n * Unsigned transaction request\n */\nexport interface UnsignedTransactionRequest {\n /** Recipient address */\n to: Address;\n\n /** Transaction data (calldata) */\n data?: Hex;\n\n /** Transaction value - accepts string | number | bigint */\n value?: string | number | bigint;\n}\n\n/**\n * Options for sending a transaction\n */\nexport interface SendTransactionOptions {\n /**\n * Set to true to disable sponsorship for this specific transaction\n * Default: false (follows provider's disableSponsorship setting)\n */\n disableSponsorship?: boolean;\n}\n\n/**\n * Result of a successful transaction\n */\nexport interface SendTransactionResult {\n /** EVM transaction hash (first receipt hash) */\n txnHash: Hash;\n}\n\n/**\n * Hook result for sending transactions\n */\nexport interface UseSendTransactionResult {\n /** Whether the transaction is currently being sent */\n isLoading: boolean;\n\n /** Error if transaction failed */\n error: Error | null;\n\n /** Transaction result if successful */\n data: SendTransactionResult | null;\n\n /** Reset the hook state */\n reset(): void;\n\n /** Send a single transaction or batch of transactions */\n sendTransaction(\n input: UnsignedTransactionRequest | UnsignedTransactionRequest[],\n options?: SendTransactionOptions,\n ): Promise<SendTransactionResult>;\n}\n\n/**\n * Request parameters for preparing a swap\n * Derived directly from the SDK to ensure type safety\n *\n * Note: Provide either `fromAmount` OR `minimumToAmount`, not both.\n * - Use `fromAmount` to specify exact amount to swap FROM\n * - Use `minimumToAmount` to specify minimum amount to receive TO\n */\nexport type PrepareSwapRequest = Parameters<\n ReturnType<typeof swapActions>[\"requestQuoteV0\"]\n>[0];\n\n/**\n * Response from requestQuoteV0\n * Derived directly from the SDK to ensure type safety\n */\nexport type RequestQuoteV0Result = Awaited<\n ReturnType<ReturnType<typeof swapActions>[\"requestQuoteV0\"]>\n>;\n\n/**\n * Swap quote information extracted from prepared swap calls\n * Derived directly from the SDK response\n */\nexport type SwapQuote = NonNullable<RequestQuoteV0Result[\"quote\"]>;\n\n/**\n * Result of preparing a swap (full response from requestQuoteV0)\n * Contains quote and prepared calls ready for signing\n */\nexport type PrepareSwapResult = Extract<\n RequestQuoteV0Result,\n { rawCalls?: false | undefined }\n>;\n\n/**\n * Hook result for preparing swaps\n */\nexport interface UsePrepareSwapResult {\n /** Whether the swap is being prepared */\n isLoading: boolean;\n\n /** Error if preparation failed */\n error: Error | null;\n\n /** Prepared swap data if successful */\n data: PrepareSwapResult | null;\n\n /** Reset the hook state */\n reset(): void;\n\n /** Request a swap quote and prepare calls */\n prepareSwap(request: PrepareSwapRequest): Promise<PrepareSwapResult>;\n}\n\n/**\n * Result of submitting a swap\n * Simplified wrapper that extracts the transaction hash\n */\nexport interface SubmitSwapResult {\n /** Transaction hash of the swap */\n txnHash: Hash;\n}\n\n/**\n * Hook result for submitting swaps\n */\nexport interface UseSubmitSwapResult {\n /** Whether the swap is being submitted */\n isLoading: boolean;\n\n /** Error if submission failed */\n error: Error | null;\n\n /** Swap submission result if successful */\n data: SubmitSwapResult | null;\n\n /** Reset the hook state */\n reset(): void;\n\n /** Sign and submit prepared swap calls */\n submitSwap(preparedSwap: PrepareSwapResult): Promise<SubmitSwapResult>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC","sourcesContent":["import type { Address, Hash, Hex } from \"viem\";\nimport type { swapActions } from \"@account-kit/wallet-client/experimental\";\nimport { ConnectionConfigSchema } from \"@aa-sdk/core\";\nimport type { z } from \"zod\";\n\n/**\n * Configuration for the Alchemy provider\n * Uses ConnectionConfigSchema to ensure valid transport configuration\n */\nexport type AlchemyProviderConfig = z.infer<typeof ConnectionConfigSchema> & {\n /** Policy ID(s) for EVM gas sponsorship */\n policyId?: string | string[];\n\n /** Policy ID(s) for Solana gas sponsorship */\n solanaPolicyId?: string | string[];\n\n /** Solana RPC URL (separate from EVM rpcUrl) */\n solanaRpcUrl?: string;\n\n /**\n * How EVM smart account calls should be authorized.\n * - 'eip7702' (default): delegated authorization via EIP-7702.\n * - 'owner': sign as the account owner (Privy embedded wallet), no 7702.\n */\n accountAuthMode?: \"eip7702\" | \"owner\";\n\n /**\n * Set to true to disable gas sponsorship by default\n * Default: false (sponsorship enabled when policyId is provided)\n */\n disableSponsorship?: boolean;\n\n /**\n * Optional: Specify which wallet address to use\n * - If provided, will use the wallet matching this address\n * - If not provided, defaults to the first embedded wallet (web) or first wallet in array (React Native)\n */\n walletAddress?: string;\n};\n\n/**\n * Unsigned transaction request\n */\nexport interface UnsignedTransactionRequest {\n /** Recipient address */\n to: Address;\n\n /** Transaction data (calldata) */\n data?: Hex;\n\n /** Transaction value - accepts string | number | bigint */\n value?: string | number | bigint;\n}\n\n/**\n * Options for sending a transaction\n */\nexport interface SendTransactionOptions {\n /**\n * Set to true to disable sponsorship for this specific transaction\n * Default: false (follows provider's disableSponsorship setting)\n */\n disableSponsorship?: boolean;\n}\n\n/**\n * Result of a successful transaction\n */\nexport interface SendTransactionResult {\n /** EVM transaction hash (first receipt hash) */\n txnHash: Hash;\n}\n\n/**\n * Hook result for sending transactions\n */\nexport interface UseSendTransactionResult {\n /** Whether the transaction is currently being sent */\n isLoading: boolean;\n\n /** Error if transaction failed */\n error: Error | null;\n\n /** Transaction result if successful */\n data: SendTransactionResult | null;\n\n /** Reset the hook state */\n reset(): void;\n\n /** Send a single transaction or batch of transactions */\n sendTransaction(\n input: UnsignedTransactionRequest | UnsignedTransactionRequest[],\n options?: SendTransactionOptions,\n ): Promise<SendTransactionResult>;\n}\n\n/**\n * Request parameters for preparing a swap\n * Derived directly from the SDK to ensure type safety\n *\n * Note: Provide either `fromAmount` OR `minimumToAmount`, not both.\n * - Use `fromAmount` to specify exact amount to swap FROM\n * - Use `minimumToAmount` to specify minimum amount to receive TO\n */\nexport type PrepareSwapRequest = Parameters<\n ReturnType<typeof swapActions>[\"requestQuoteV0\"]\n>[0];\n\n/**\n * Response from requestQuoteV0\n * Derived directly from the SDK to ensure type safety\n */\nexport type RequestQuoteV0Result = Awaited<\n ReturnType<ReturnType<typeof swapActions>[\"requestQuoteV0\"]>\n>;\n\n/**\n * Swap quote information extracted from prepared swap calls\n * Derived directly from the SDK response\n */\nexport type SwapQuote = NonNullable<RequestQuoteV0Result[\"quote\"]>;\n\n/**\n * Result of preparing a swap (full response from requestQuoteV0)\n * Contains quote and prepared calls ready for signing\n */\nexport type PrepareSwapResult = Extract<\n RequestQuoteV0Result,\n { rawCalls?: false | undefined }\n>;\n\n/**\n * Hook result for preparing swaps\n */\nexport interface UsePrepareSwapResult {\n /** Whether the swap is being prepared */\n isLoading: boolean;\n\n /** Error if preparation failed */\n error: Error | null;\n\n /** Prepared swap data if successful */\n data: PrepareSwapResult | null;\n\n /** Reset the hook state */\n reset(): void;\n\n /** Request a swap quote and prepare calls */\n prepareSwap(request: PrepareSwapRequest): Promise<PrepareSwapResult>;\n}\n\n/**\n * Result of submitting a swap\n * Simplified wrapper that extracts the transaction hash\n */\nexport interface SubmitSwapResult {\n /** Transaction hash of the swap */\n txnHash: Hash;\n}\n\n/**\n * Hook result for submitting swaps\n */\nexport interface UseSubmitSwapResult {\n /** Whether the swap is being submitted */\n isLoading: boolean;\n\n /** Error if submission failed */\n error: Error | null;\n\n /** Swap submission result if successful */\n data: SubmitSwapResult | null;\n\n /** Reset the hook state */\n reset(): void;\n\n /** Sign and submit prepared swap calls */\n submitSwap(preparedSwap: PrepareSwapResult): Promise<SubmitSwapResult>;\n}\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "4.75.4";
1
+ export declare const VERSION = "4.76.0";
@@ -1,4 +1,4 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.75.4";
3
+ export const VERSION = "4.76.0";
4
4
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.75.4\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.76.0\";\n"]}
@@ -1,74 +1,7 @@
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
1
  /**
6
- * Normalized config with defaults applied
7
- *
8
- * @internal
2
+ * Web-specific exports
3
+ * Re-exports the web provider and hooks for React applications
9
4
  */
10
- export type NormalizedAlchemyConfig = AlchemyProviderConfig & Required<Pick<AlchemyProviderConfig, "accountAuthMode">>;
11
- /**
12
- * Client cache stored in React tree (similar to QueryClient in React Query)
13
- *
14
- * @internal
15
- */
16
- interface ClientCache {
17
- client: SmartWalletClient | null;
18
- account: SmartContractAccount | null;
19
- cacheKey: string | null;
20
- }
21
- /**
22
- * Provider component that configures Alchemy infrastructure for transaction handling
23
- * Must be nested INSIDE PrivyProvider to access authentication state
24
- * Automatically manages client cache lifecycle and resets on logout
25
- *
26
- * @param {PropsWithChildren<AlchemyProviderConfig>} props - Component props
27
- * @param {React.ReactNode} props.children - React children to wrap with Alchemy configuration
28
- * @param {string} [props.apiKey] - Your Alchemy API key
29
- * @param {string} [props.jwt] - JWT token for authentication
30
- * @param {string} [props.rpcUrl] - Custom RPC URL for EVM chains
31
- * @param {string} [props.solanaRpcUrl] - Custom RPC URL for Solana
32
- * @param {string | string[]} [props.policyId] - Gas Manager policy ID(s) for EVM chains
33
- * @param {string | string[]} [props.solanaPolicyId] - Gas Manager policy ID(s) for Solana
34
- * @param {boolean} [props.disableSponsorship] - Set to true to disable sponsorship by default (default: false)
35
- * @param {'eip7702' | 'owner'} [props.accountAuthMode] - Authorization mode for EVM smart accounts (default: 'eip7702')
36
- * @returns {JSX.Element} Provider component
37
- *
38
- * @example
39
- * ```tsx
40
- * <PrivyProvider appId="...">
41
- * <AlchemyProvider
42
- * apiKey="your-alchemy-api-key"
43
- * policyId="your-gas-policy-id"
44
- * >
45
- * <YourApp />
46
- * </AlchemyProvider>
47
- * </PrivyProvider>
48
- * ```
49
- */
50
- export declare function AlchemyProvider({ children, accountAuthMode, ...config }: PropsWithChildren<AlchemyProviderConfig>): import("react/jsx-runtime").JSX.Element;
51
- /**
52
- * Hook to access Alchemy provider configuration
53
- * Must be used within an <AlchemyProvider> component
54
- *
55
- * @returns {NormalizedAlchemyConfig} The current Alchemy configuration with defaults applied
56
- * @throws {Error} If used outside of AlchemyProvider
57
- *
58
- * @example
59
- * ```tsx
60
- * const config = useAlchemyConfig();
61
- * console.log('Policy ID:', config.policyId);
62
- * console.log('Auth Mode:', config.accountAuthMode); // Always defined
63
- * ```
64
- */
65
- export declare function useAlchemyConfig(): NormalizedAlchemyConfig;
66
- /**
67
- * Hook to access the client cache (internal use only)
68
- *
69
- * @internal
70
- * @returns {ClientCache} The client cache object
71
- */
72
- export declare function useClientCache(): ClientCache;
73
- export {};
5
+ export { AlchemyProvider } from "./providers/WebProvider.js";
6
+ export { useAlchemyConfig } from "./context/AlchemyContext.js";
74
7
  //# sourceMappingURL=Provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../src/Provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EAKvB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG,qBAAqB,GACzD,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAI3D;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,eAA2B,EAC3B,GAAG,MAAM,EACV,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,2CA0D1C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,IAAI,uBAAuB,CAM1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAQ5C"}
1
+ {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../src/Provider.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * React Native stub for web Provider
3
+ * This file prevents Metro from importing web-specific code
4
+ */
5
+ export declare function AlchemyProvider(): void;
6
+ export declare function useAlchemyConfig(): void;
7
+ //# sourceMappingURL=Provider.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Provider.native.d.ts","sourceRoot":"","sources":["../../src/Provider.native.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,eAAe,SAK9B;AAED,wBAAgB,gBAAgB,SAK/B"}
@@ -0,0 +1,7 @@
1
+ import type { PrivyAdapter } from "./types.js";
2
+ /**
3
+ * React Native (Expo) adapter for @privy-io/expo
4
+ * Implements platform-specific hooks for React Native applications
5
+ */
6
+ export declare const reactNativeAdapter: PrivyAdapter;
7
+ //# sourceMappingURL=react-native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-native.d.ts","sourceRoot":"","sources":["../../../src/adapters/react-native.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAkC,MAAM,YAAY,CAAC;AAY/E;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,YA6IhC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import type { Address, Authorization } from "viem";
2
+ import type { AuthorizationRequest } from "@aa-sdk/core";
3
+ /**
4
+ * Platform-agnostic embedded wallet interface
5
+ * Abstracts differences between @privy-io/react-auth and @privy-io/expo
6
+ */
7
+ export interface EmbeddedWallet {
8
+ /** Wallet address */
9
+ address: Address;
10
+ /** Chain ID as a string (may be CAIP-2 format like "eip155:1" or numeric string like "1") */
11
+ chainId: string;
12
+ /** Get EVM provider for the wallet */
13
+ getEthereumProvider(): Promise<any>;
14
+ }
15
+ /**
16
+ * Platform-agnostic Privy auth state
17
+ */
18
+ export interface PrivyAuthState {
19
+ /** Whether user is authenticated */
20
+ authenticated: boolean;
21
+ /** User object (platform-specific, used for cache invalidation) */
22
+ user: any;
23
+ }
24
+ /**
25
+ * Adapter interface that each platform must implement
26
+ * Provides platform-specific Privy functionality
27
+ */
28
+ export interface PrivyAdapter {
29
+ /**
30
+ * Hook to get embedded wallet
31
+ * Must be called as a React hook (follows rules of hooks)
32
+ *
33
+ * @param preferredAddress - Optional address to find a specific wallet
34
+ */
35
+ useEmbeddedWallet(preferredAddress?: string): () => EmbeddedWallet;
36
+ /**
37
+ * Hook to get Privy authentication state
38
+ * Must be called as a React hook (follows rules of hooks)
39
+ */
40
+ usePrivyAuth(): PrivyAuthState;
41
+ /**
42
+ * Hook to get current wallet address (for cache invalidation)
43
+ * Returns undefined if no wallet is available
44
+ * Must be called as a React hook (follows rules of hooks)
45
+ *
46
+ * @param preferredAddress - Optional address to find a specific wallet
47
+ */
48
+ useWalletAddress(preferredAddress?: string): string | undefined;
49
+ /**
50
+ * Hook to get EIP-7702 authorization signer (optional, web only)
51
+ * Must be called as a React hook (follows rules of hooks)
52
+ *
53
+ * @param preferredAddress - Optional address to find a specific wallet
54
+ */
55
+ useAuthorizationSigner?(preferredAddress?: string): ((auth: AuthorizationRequest<number>) => Promise<Authorization<number, true>>) | null;
56
+ }
57
+ //# sourceMappingURL=types.d.ts.map