@zama-fhe/react-sdk 1.0.0-alpha.13 → 1.0.0-alpha.15

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.
@@ -1,4 +1,4 @@
1
- import { GenericSigner, Address, EIP712TypedData, Hex, ContractCallConfig, TransactionReceipt, SignerLifecycleCallbacks } from '@zama-fhe/sdk';
1
+ import { GenericSigner, Address, EIP712TypedData, Hex, ContractAbi, WriteFunctionName, WriteContractArgs, WriteContractConfig, ReadFunctionName, ReadContractArgs, ReadContractConfig, ReadContractReturnType, TransactionReceipt, SignerLifecycleCallbacks } from '@zama-fhe/sdk';
2
2
  import { Config } from 'wagmi';
3
3
 
4
4
  /** Configuration for {@link WagmiSigner}. */
@@ -16,10 +16,10 @@ declare class WagmiSigner implements GenericSigner {
16
16
  getChainId(): Promise<number>;
17
17
  getAddress(): Promise<Address>;
18
18
  signTypedData(typedData: EIP712TypedData): Promise<Hex>;
19
- writeContract<C extends ContractCallConfig>(config: C): Promise<Hex>;
20
- readContract<T, C extends ContractCallConfig = ContractCallConfig>(config: C): Promise<T>;
19
+ writeContract<const TAbi extends ContractAbi, TFunctionName extends WriteFunctionName<TAbi>, const TArgs extends WriteContractArgs<TAbi, TFunctionName>>(config: WriteContractConfig<TAbi, TFunctionName, TArgs>): Promise<Hex>;
20
+ readContract<const TAbi extends ContractAbi, TFunctionName extends ReadFunctionName<TAbi>, const TArgs extends ReadContractArgs<TAbi, TFunctionName>>(config: ReadContractConfig<TAbi, TFunctionName, TArgs>): Promise<ReadContractReturnType<TAbi, TFunctionName, TArgs>>;
21
21
  waitForTransactionReceipt(hash: Hex): Promise<TransactionReceipt>;
22
- subscribe({ onDisconnect, onAccountChange, }: SignerLifecycleCallbacks): () => void;
22
+ subscribe({ onDisconnect, onAccountChange, onChainChange, }: SignerLifecycleCallbacks): () => void;
23
23
  }
24
24
 
25
25
  export { WagmiSigner, type WagmiSignerConfig };
@@ -1,11 +1,6 @@
1
1
  "use client";
2
2
  import { TransactionRevertedError } from '@zama-fhe/sdk';
3
- import * as actions from 'wagmi/actions';
4
- import { getChainId, signTypedData, writeContract, readContract, waitForTransactionReceipt, watchConnection, getAccount } from 'wagmi/actions';
5
- import 'wagmi';
6
-
7
- // src/wagmi/wagmi-signer.ts
8
- var getConnection2 = "getConnection" in actions ? actions.getConnection : getAccount;
3
+ import { getChainId, getAccount, signTypedData, writeContract, readContract, waitForTransactionReceipt, watchConnection } from 'wagmi/actions';
9
4
 
10
5
  // src/wagmi/wagmi-signer.ts
11
6
  var WagmiSigner = class {
@@ -17,7 +12,7 @@ var WagmiSigner = class {
17
12
  return getChainId(this.config);
18
13
  }
19
14
  async getAddress() {
20
- const account = getConnection2(this.config);
15
+ const account = getAccount(this.config);
21
16
  if (!account?.address) {
22
17
  throw new TypeError("Invalid address");
23
18
  }
@@ -56,6 +51,8 @@ var WagmiSigner = class {
56
51
  onDisconnect = () => {
57
52
  },
58
53
  onAccountChange = () => {
54
+ },
55
+ onChainChange = () => {
59
56
  }
60
57
  }) {
61
58
  return watchConnection(this.config, {
@@ -66,6 +63,9 @@ var WagmiSigner = class {
66
63
  if (prevConnection.address && connection.address && connection.address !== prevConnection.address) {
67
64
  onAccountChange(connection.address);
68
65
  }
66
+ if (typeof prevConnection.chainId === "number" && typeof connection.chainId === "number" && connection.chainId !== prevConnection.chainId) {
67
+ onChainChange(connection.chainId);
68
+ }
69
69
  }
70
70
  });
71
71
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/wagmi/compat.ts","../../src/wagmi/wagmi-signer.ts"],"names":["getConnection"],"mappings":";;;;;;AASO,IAAMA,cAAAA,GAAgB,eAAA,IAAmB,OAAA,GAAkB,OAAA,CAAA,aAAA,GAAgB,UAAA;;;ACsB3E,IAAM,cAAN,MAA2C;AAAA,EAC/B,MAAA;AAAA,EAEjB,YAAY,YAAA,EAAiC;AAC3C,IAAA,IAAA,CAAK,SAAS,YAAA,CAAa,MAAA;AAAA,EAC7B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Q,QAAA,CAAS,oBAAoB,KAAK,OAAA,CAAQ,QAAA,CAAS,uBAAuB,CAAA,EAAG;AACvF,QAAA,MAAM,IAAI,wBAAA;AAAA,UACR,CAAA,6CAAA,EAAgD,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,EAAE,CAAC,CAAA,8HAAA,CAAA;AAAA,UAGjE,EAAE,KAAA,EAAO,KAAA,YAAiB,KAAA,GAAQ,QAAQ,MAAA;AAAU,SACtD;AAAA,MACF;AACA,MAAA,MAAM,KAAA;AAAA,IACR;AAAA,EACF;AAAA,EAEA,SAAA,CAAU;AAAA,IACR,eAAe,MAAM;AAAA,IAAC,CAAA;AAAA,IACtB,kBAAkB,MAAM;AAAA,IAAC;AAAA,GAC3B,EAAyC;AACvC,IAAA,OAAO,eAAA,CAAgB,KAAK,MAAA,EAAQ;AAAA,MAClC,QAAA,CAAS,YAAY,cAAA,EAAgB;AACnC,QAAA,IAAI,UAAA,CAAW,MAAA,KAAW,cAAA,IAAkB,cAAA,CAAe,WAAW,cAAA,EAAgB;AACpF,UAAA,YAAA,EAAa;AAAA,QACf;AACA,QAAA,IACE,eAAe,OAAA,IACf,UAAA,CAAW,WACX,UAAA,CAAW,OAAA,KAAY,eAAe,OAAA,EACtC;AACA,UAAA,eAAA,CAAgB,WAAW,OAAO,CAAA;AAAA,QACpC;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"index.js","sourcesContent":["import * as wagmi from \"wagmi\";\nimport { useAccount } from \"wagmi\";\nimport * as actions from \"wagmi/actions\";\nimport { getAccount } 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","import type {\n Address,\n ContractCallConfig,\n EIP712TypedData,\n GenericSigner,\n Hex,\n SignerLifecycleCallbacks,\n TransactionReceipt,\n} from \"@zama-fhe/sdk\";\nimport { TransactionRevertedError } from \"@zama-fhe/sdk\";\nimport type { Config } from \"wagmi\";\nimport {\n getChainId,\n readContract,\n signTypedData,\n waitForTransactionReceipt,\n watchConnection,\n writeContract,\n} from \"wagmi/actions\";\nimport { getConnection } 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: Object.keys(sigTypes)[0]!,\n types: sigTypes,\n domain: typedData.domain,\n message: typedData.message,\n });\n }\n\n async writeContract<C extends ContractCallConfig>(config: C): Promise<Hex> {\n return writeContract(this.config, config as Parameters<typeof writeContract>[1]);\n }\n\n async readContract<T, C extends ContractCallConfig = ContractCallConfig>(config: C): Promise<T> {\n return readContract(this.config, config) as Promise<T>;\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 subscribe({\n onDisconnect = () => {},\n onAccountChange = () => {},\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 },\n });\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/wagmi/wagmi-signer.ts"],"names":[],"mappings":";;;;AAsCO,IAAM,cAAN,MAA2C;AAAA,EAC/B,MAAA;AAAA,EAEjB,YAAY,YAAA,EAAiC;AAC3C,IAAA,IAAA,CAAK,SAAS,YAAA,CAAa,MAAA;AAAA,EAC7B;AAAA,EAEA,MAAM,UAAA,GAA8B;AAClC,IAAA,OAAO,UAAA,CAAW,KAAK,MAAM,CAAA;AAAA,EAC/B;AAAA,EAEA,MAAM,UAAA,GAA+B;AACnC,IAAA,MAAM,OAAA,GAAU,UAAA,CAAW,IAAA,CAAK,MAAM,CAAA;AACtC,IAAA,IAAI,CAAC,SAAS,OAAA,EAAS;AACrB,MAAA,MAAM,IAAI,UAAU,iBAAiB,CAAA;AAAA,IACvC;AACA,IAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,EACjB;AAAA,EAEA,MAAM,cAAc,SAAA,EAA0C;AAC5D,IAAA,MAAM,EAAE,YAAA,EAAc,CAAA,EAAG,GAAG,QAAA,KAAa,SAAA,CAAU,KAAA;AACnD,IAAA,OAAO,aAAA,CAAc,KAAK,MAAA,EAAQ;AAAA,MAChC,WAAA,EAAa,MAAA,CAAO,IAAA,CAAK,QAAQ,EAAE,CAAC,CAAA;AAAA,MACpC,KAAA,EAAO,QAAA;AAAA,MACP,QAAQ,SAAA,CAAU,MAAA;AAAA,MAClB,SAAS,SAAA,CAAU;AAAA,KACpB,CAAA;AAAA,EACH;AAAA,EAEA,MAAM,cAIJ,MAAA,EAAuE;AACvE,IAAA,OAAO,aAAA,CAAc,IAAA,CAAK,MAAA,EAAQ,MAA6C,C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ACtC;AACA,UAAA,eAAA,CAAgB,WAAW,OAAO,CAAA;AAAA,QACpC;AACA,QAAA,IACE,OAAO,cAAA,CAAe,OAAA,KAAY,QAAA,IAClC,OAAO,UAAA,CAAW,OAAA,KAAY,QAAA,IAC9B,UAAA,CAAW,OAAA,KAAY,cAAA,CAAe,OAAA,EACtC;AACA,UAAA,aAAA,CAAc,WAAW,OAAO,CAAA;AAAA,QAClC;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"index.js","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 getChainId,\n getAccount,\n readContract,\n signTypedData,\n waitForTransactionReceipt,\n watchConnection,\n writeContract,\n} from \"wagmi/actions\";\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 = getAccount(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: Object.keys(sigTypes)[0]!,\n types: sigTypes,\n domain: typedData.domain,\n message: typedData.message,\n });\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 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zama-fhe/react-sdk",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.15",
4
4
  "description": "React hooks for Zama SDK",
5
5
  "license": "BSD-3-Clause-Clear",
6
6
  "author": "Zama",
@@ -56,7 +56,7 @@
56
56
  "tsup": "^8.5.1"
57
57
  },
58
58
  "peerDependencies": {
59
- "@zama-fhe/sdk": "^1.0.0-alpha.13",
59
+ "@zama-fhe/sdk": "^1.0.0-alpha.15",
60
60
  "react": ">=18",
61
61
  "@tanstack/react-query": ">=5",
62
62
  "wagmi": ">=2"