@zama-fhe/react-sdk 3.0.0-alpha.7 → 3.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +73 -81
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/wagmi/index.js +1 -1
- package/dist/wagmi/index.js.map +1 -1
- package/package.json +2 -2
package/dist/wagmi/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{TransactionRevertedError as e}from"@zama-fhe/sdk";import{getAccount as
|
|
1
|
+
"use client";import{TransactionRevertedError as e}from"@zama-fhe/sdk";import*as t from"wagmi/actions";import{getAccount as n,getBlock as r,getChainId as i,readContract as a,signTypedData as o,waitForTransactionReceipt as s,watchAccount as c,writeContract as l}from"wagmi/actions";import*as u from"wagmi";import"wagmi";`useConnection`in u&&u.useConnection;const d=`getConnection`in t?t.getConnection:n,f=`watchConnection`in t?t.watchConnection:c;var p=class{config;constructor(e){this.config=e.config}async getChainId(){return i(this.config)}async getAddress(){let e=d(this.config);if(!e?.address)throw TypeError(`Invalid address`);return e.address}async signTypedData(e){let{EIP712Domain:t,...n}=e.types;return o(this.config,{primaryType:e.primaryType,types:n,domain:e.domain,message:{...e.message,startTimestamp:BigInt(e.message.startTimestamp),durationDays:BigInt(e.message.durationDays)}})}async writeContract(e){return l(this.config,e)}async readContract(e){return a(this.config,e)}async waitForTransactionReceipt(t){try{return await s(this.config,{hash:t})}catch(n){let r=n instanceof Error?n.message:String(n);throw r.includes(`could not be found`)||r.includes(`Transaction not found`)?new e(`Could not find transaction receipt for hash "${t.slice(0,10)}…". If using ERC-4337 with a bundler, your connector may be returning a UserOperation hash instead of a transaction hash.`,{cause:n instanceof Error?n:void 0}):n}}async getBlockTimestamp(){return(await r(this.config)).timestamp}subscribe({onDisconnect:e=()=>{},onAccountChange:t=()=>{},onChainChange:n=()=>{}}){return f(this.config,{onChange(r,i){r.status===`disconnected`&&i.status!==`disconnected`&&e(),i.address&&r.address&&r.address!==i.address&&t(r.address),typeof i.chainId==`number`&&typeof r.chainId==`number`&&r.chainId!==i.chainId&&n(r.chainId)}})}};export{p as WagmiSigner};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/wagmi/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/wagmi/wagmi-signer.ts"],"sourcesContent":["import type {\n Address,\n ContractAbi,\n EIP712TypedData,\n GenericSigner,\n Hex,\n ReadContractArgs,\n ReadContractConfig,\n ReadContractReturnType,\n ReadFunctionName,\n SignerLifecycleCallbacks,\n TransactionReceipt,\n WriteContractArgs,\n WriteFunctionName,\n WriteContractConfig,\n} from \"@zama-fhe/sdk\";\nimport { TransactionRevertedError } from \"@zama-fhe/sdk\";\nimport type { Config } from \"wagmi\";\nimport {\n getBlock,\n getChainId,\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/wagmi/compat.ts","../../src/wagmi/wagmi-signer.ts"],"sourcesContent":["import * as wagmi from \"wagmi\";\nimport { useAccount } from \"wagmi\";\nimport * as actions from \"wagmi/actions\";\nimport { getAccount, watchAccount } from \"wagmi/actions\";\n\n// wagmi v3 renamed useAccount → useConnection\nexport const useConnection = \"useConnection\" in wagmi ? wagmi.useConnection : useAccount;\n\n// wagmi v3 renamed getAccount → getConnection\nexport const getConnection = \"getConnection\" in actions ? actions.getConnection : getAccount;\n\n// wagmi v3 renamed watchAccount → watchConnection\nexport const watchConnection =\n \"watchConnection\" in actions ? actions.watchConnection : watchAccount;\n","import type {\n Address,\n ContractAbi,\n EIP712TypedData,\n GenericSigner,\n Hex,\n ReadContractArgs,\n ReadContractConfig,\n ReadContractReturnType,\n ReadFunctionName,\n SignerLifecycleCallbacks,\n TransactionReceipt,\n WriteContractArgs,\n WriteFunctionName,\n WriteContractConfig,\n} from \"@zama-fhe/sdk\";\nimport { TransactionRevertedError } from \"@zama-fhe/sdk\";\nimport type { Config } from \"wagmi\";\nimport {\n getBlock,\n getChainId,\n readContract,\n signTypedData,\n waitForTransactionReceipt,\n writeContract,\n} from \"wagmi/actions\";\nimport { getConnection, watchConnection } from \"./compat\";\n\n/** Configuration for {@link WagmiSigner}. */\nexport interface WagmiSignerConfig {\n config: Config;\n}\n\n/**\n * GenericSigner backed by wagmi.\n *\n * @param signerConfig - {@link WagmiSignerConfig} with wagmi config\n */\nexport class WagmiSigner implements GenericSigner {\n private readonly config: Config;\n\n constructor(signerConfig: WagmiSignerConfig) {\n this.config = signerConfig.config;\n }\n\n async getChainId(): Promise<number> {\n return getChainId(this.config);\n }\n\n async getAddress(): Promise<Address> {\n const account = getConnection(this.config);\n if (!account?.address) {\n throw new TypeError(\"Invalid address\");\n }\n return account.address;\n }\n\n async signTypedData(typedData: EIP712TypedData): Promise<Hex> {\n const { EIP712Domain: _, ...sigTypes } = typedData.types;\n return signTypedData(this.config, {\n primaryType: typedData.primaryType,\n types: sigTypes,\n domain: typedData.domain,\n message: {\n ...typedData.message,\n startTimestamp: BigInt(typedData.message.startTimestamp),\n durationDays: BigInt(typedData.message.durationDays),\n },\n // Cast: EIP712TypedData is a union; viem cannot correlate primaryType/types/message across union members, so the inferred `message` collapses to `never`.\n } as Parameters<typeof signTypedData>[1]);\n }\n\n async writeContract<\n const TAbi extends ContractAbi,\n TFunctionName extends WriteFunctionName<TAbi>,\n const TArgs extends WriteContractArgs<TAbi, TFunctionName>,\n >(config: WriteContractConfig<TAbi, TFunctionName, TArgs>): Promise<Hex> {\n return writeContract(this.config, config as Parameters<typeof writeContract>[1]);\n }\n\n async readContract<\n const TAbi extends ContractAbi,\n TFunctionName extends ReadFunctionName<TAbi>,\n const TArgs extends ReadContractArgs<TAbi, TFunctionName>,\n >(\n config: ReadContractConfig<TAbi, TFunctionName, TArgs>,\n ): Promise<ReadContractReturnType<TAbi, TFunctionName, TArgs>> {\n return readContract(this.config, config);\n }\n\n async waitForTransactionReceipt(hash: Hex): Promise<TransactionReceipt> {\n try {\n return await waitForTransactionReceipt(this.config, { hash });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (message.includes(\"could not be found\") || message.includes(\"Transaction not found\")) {\n throw new TransactionRevertedError(\n `Could not find transaction receipt for hash \"${hash.slice(0, 10)}…\". ` +\n \"If using ERC-4337 with a bundler, your connector may be returning a UserOperation hash \" +\n \"instead of a transaction hash.\",\n { cause: error instanceof Error ? error : undefined },\n );\n }\n throw error;\n }\n }\n\n async getBlockTimestamp(): Promise<bigint> {\n const block = await getBlock(this.config);\n return block.timestamp;\n }\n\n subscribe({\n onDisconnect = () => {},\n onAccountChange = () => {},\n onChainChange = () => {},\n }: SignerLifecycleCallbacks): () => void {\n return watchConnection(this.config, {\n onChange(connection, prevConnection) {\n if (connection.status === \"disconnected\" && prevConnection.status !== \"disconnected\") {\n onDisconnect();\n }\n if (\n prevConnection.address &&\n connection.address &&\n connection.address !== prevConnection.address\n ) {\n onAccountChange(connection.address);\n }\n if (\n typeof prevConnection.chainId === \"number\" &&\n typeof connection.chainId === \"number\" &&\n connection.chainId !== prevConnection.chainId\n ) {\n onChainChange(connection.chainId);\n }\n },\n });\n }\n}\n"],"mappings":"8TAM6B,kBAAmB,GAAQ,EAAM,cAG9D,MAAa,EAAgB,kBAAmB,EAAU,EAAQ,cAAgB,EAGrE,EACX,oBAAqB,EAAU,EAAQ,gBAAkB,ECyB3D,IAAa,EAAb,KAAkD,CAChD,OAEA,YAAY,EAAiC,CAC3C,KAAK,OAAS,EAAa,OAG7B,MAAM,YAA8B,CAClC,OAAO,EAAW,KAAK,OAAO,CAGhC,MAAM,YAA+B,CACnC,IAAM,EAAU,EAAc,KAAK,OAAO,CAC1C,GAAI,CAAC,GAAS,QACZ,MAAU,UAAU,kBAAkB,CAExC,OAAO,EAAQ,QAGjB,MAAM,cAAc,EAA0C,CAC5D,GAAM,CAAE,aAAc,EAAG,GAAG,GAAa,EAAU,MACnD,OAAO,EAAc,KAAK,OA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|
|
4
4
|
"description": "React hooks for Zama SDK",
|
|
5
5
|
"license": "BSD-3-Clause-Clear",
|
|
6
6
|
"author": "Zama",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@tanstack/react-query": ">=5",
|
|
67
|
-
"@zama-fhe/sdk": "^3.0.0-alpha.
|
|
67
|
+
"@zama-fhe/sdk": "^3.0.0-alpha.9",
|
|
68
68
|
"react": ">=18",
|
|
69
69
|
"viem": "^2.47.0",
|
|
70
70
|
"wagmi": ">=2"
|