@pyratzlabs/react-fhevm-utils 3.5.2 → 3.5.4

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 (59) hide show
  1. package/dist/package.json +40 -0
  2. package/dist/{client → src/client}/context/FhevmProvider.js +11 -11
  3. package/dist/src/config.d.ts +2 -0
  4. package/dist/src/config.js +3 -0
  5. package/dist/src/config.test.js +57 -0
  6. package/dist/{index.d.ts → src/index.d.ts} +1 -0
  7. package/dist/{index.js → src/index.js} +2 -0
  8. package/dist/{lib → src/lib}/fhevm.js +1 -1
  9. package/package.json +4 -2
  10. package/dist/config.d.ts +0 -6
  11. package/dist/config.js +0 -6
  12. package/dist/workers/encryption.worker.js +0 -35
  13. /package/dist/{client → src/client}/context/FhevmProvider.d.ts +0 -0
  14. /package/dist/{client → src/client}/hooks/useAccount.d.ts +0 -0
  15. /package/dist/{client → src/client}/hooks/useAccount.js +0 -0
  16. /package/dist/{client → src/client}/hooks/useDecryptHandles.d.ts +0 -0
  17. /package/dist/{client → src/client}/hooks/useDecryptHandles.js +0 -0
  18. /package/dist/{client → src/client}/hooks/useEncryptValue.d.ts +0 -0
  19. /package/dist/{client → src/client}/hooks/useEncryptValue.js +0 -0
  20. /package/dist/{client → src/client}/hooks/useEncryptedBatchTransfer.d.ts +0 -0
  21. /package/dist/{client → src/client}/hooks/useEncryptedBatchTransfer.js +0 -0
  22. /package/dist/{client → src/client}/hooks/useEncryptedTransfer.d.ts +0 -0
  23. /package/dist/{client → src/client}/hooks/useEncryptedTransfer.js +0 -0
  24. /package/dist/{client → src/client}/hooks/useFhevmInstance.d.ts +0 -0
  25. /package/dist/{client → src/client}/hooks/useFhevmInstance.js +0 -0
  26. /package/dist/{client → src/client}/hooks/useFinalizeUnwrap.d.ts +0 -0
  27. /package/dist/{client → src/client}/hooks/useFinalizeUnwrap.js +0 -0
  28. /package/dist/{client → src/client}/hooks/useGetEncryptedBalance.d.ts +0 -0
  29. /package/dist/{client → src/client}/hooks/useGetEncryptedBalance.js +0 -0
  30. /package/dist/{client → src/client}/hooks/useGetFhevmConfig.d.ts +0 -0
  31. /package/dist/{client → src/client}/hooks/useGetFhevmConfig.js +0 -0
  32. /package/dist/{client → src/client}/hooks/usePerformTransaction.d.ts +0 -0
  33. /package/dist/{client → src/client}/hooks/usePerformTransaction.js +0 -0
  34. /package/dist/{client → src/client}/hooks/usePublicDecrypt.d.ts +0 -0
  35. /package/dist/{client → src/client}/hooks/usePublicDecrypt.js +0 -0
  36. /package/dist/{client → src/client}/hooks/useSetOperator.d.ts +0 -0
  37. /package/dist/{client → src/client}/hooks/useSetOperator.js +0 -0
  38. /package/dist/{client → src/client}/hooks/useUnwrap.d.ts +0 -0
  39. /package/dist/{client → src/client}/hooks/useUnwrap.js +0 -0
  40. /package/dist/{types/fhevmConfig.js → src/config.test.d.ts} +0 -0
  41. /package/dist/{lib → src/lib}/fhevm.d.ts +0 -0
  42. /package/dist/{server → src/server}/encrypt.d.ts +0 -0
  43. /package/dist/{server → src/server}/encrypt.js +0 -0
  44. /package/dist/{server.d.ts → src/server.d.ts} +0 -0
  45. /package/dist/{server.js → src/server.js} +0 -0
  46. /package/dist/{types → src/types}/ABI/FeeManager.abi.d.ts +0 -0
  47. /package/dist/{types → src/types}/ABI/FeeManager.abi.js +0 -0
  48. /package/dist/{types → src/types}/ABI/TransferBatcher.abi.d.ts +0 -0
  49. /package/dist/{types → src/types}/ABI/TransferBatcher.abi.js +0 -0
  50. /package/dist/{types → src/types}/ABI/Wrapper.abi.d.ts +0 -0
  51. /package/dist/{types → src/types}/ABI/Wrapper.abi.js +0 -0
  52. /package/dist/{types → src/types}/ABI/encryptedABI.d.ts +0 -0
  53. /package/dist/{types → src/types}/ABI/encryptedABI.js +0 -0
  54. /package/dist/{types → src/types}/fhevmConfig.d.ts +0 -0
  55. /package/dist/{workers/encryption.worker.d.ts → src/types/fhevmConfig.js} +0 -0
  56. /package/dist/{utils → src/utils}/number.utils.d.ts +0 -0
  57. /package/dist/{utils → src/utils}/number.utils.js +0 -0
  58. /package/dist/{utils → src/utils}/string.utils.d.ts +0 -0
  59. /package/dist/{utils → src/utils}/string.utils.js +0 -0
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@pyratzlabs/react-fhevm-utils",
3
+ "version": "3.5.3",
4
+ "description": "React hooks and utilities for Fhevmjs",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "test": "node --import tsx --test src/**/*.test.ts",
18
+ "clean": "rm -rf dist",
19
+ "preversion": "npm run build"
20
+ },
21
+ "keywords": [
22
+ "fhevm"
23
+ ],
24
+ "author": "Pyratzlabs",
25
+ "license": "MIT",
26
+ "devDependencies": {
27
+ "@types/node": "^22.10.5",
28
+ "@types/react": "^19.1.0",
29
+ "ts-node": "^10.9.2",
30
+ "tsx": "^4.19.2",
31
+ "typescript": "^5.8.2"
32
+ },
33
+ "dependencies": {
34
+ "@tanstack/react-query": "^5.71.5",
35
+ "@zama-fhe/relayer-sdk": "^0.4.0-3",
36
+ "react": "^19.1.0",
37
+ "viem": "^2.25.0",
38
+ "wagmi": "^2.14.16"
39
+ }
40
+ }
@@ -16,18 +16,18 @@ export const FhevmContext = createContext({
16
16
  });
17
17
  const FhevmProvider = ({ children, network = "sepolia", config, }) => {
18
18
  const [instance, setInstance] = useState();
19
- const initFhevm = () => __awaiter(void 0, void 0, void 0, function* () {
20
- try {
21
- const instance = yield getOrCreateFhevmInstance(network, config);
22
- setInstance(instance);
23
- }
24
- catch (error) {
25
- throw new Error(`Failed to initialize FHEVM: ${error}`);
26
- }
27
- });
28
19
  useEffect(() => {
29
- initFhevm();
30
- }, []);
20
+ const initFhevm = (config, network) => __awaiter(void 0, void 0, void 0, function* () {
21
+ try {
22
+ const instance = yield getOrCreateFhevmInstance(network, config);
23
+ setInstance(instance);
24
+ }
25
+ catch (error) {
26
+ throw new Error(`Failed to initialize FHEVM: ${error}. With config: ${JSON.stringify(config)}`);
27
+ }
28
+ });
29
+ initFhevm(config, network);
30
+ }, [config, network]);
31
31
  return (_jsx(FhevmContext.Provider, { value: { instance, config }, children: children }));
32
32
  };
33
33
  export const useFhevmContext = () => useContext(FhevmContext);
@@ -0,0 +1,2 @@
1
+ export declare const ZAMA_RELAYER_VERSION: string;
2
+ export declare const ZAMA_RELAYER_CDN_URL: string;
@@ -0,0 +1,3 @@
1
+ import packageJson from "../package.json";
2
+ export const ZAMA_RELAYER_VERSION = packageJson.dependencies["@zama-fhe/relayer-sdk"].replace(/^[\^~>=<]+/, "");
3
+ export const ZAMA_RELAYER_CDN_URL = `https://cdn.zama.org/relayer-sdk-js/${ZAMA_RELAYER_VERSION}/relayer-sdk-js.umd.cjs`;
@@ -0,0 +1,57 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert";
3
+ import { ZAMA_RELAYER_VERSION, ZAMA_RELAYER_CDN_URL } from "./config";
4
+ import packageJson from "../package.json";
5
+ describe("Config", () => {
6
+ describe("ZAMA_RELAYER_VERSION", () => {
7
+ it("should be defined and not empty", () => {
8
+ assert.ok(ZAMA_RELAYER_VERSION);
9
+ assert.ok(ZAMA_RELAYER_VERSION.length > 0);
10
+ });
11
+ it("should not contain special characters like ^, ~, >, <, =", () => {
12
+ assert.ok(!ZAMA_RELAYER_VERSION.match(/[\^~><= ]/));
13
+ });
14
+ it("should match the version format (semver-like)", () => {
15
+ // Matches version format like: 0.4.0-3, 1.2.3, 1.0.0-beta.1
16
+ const versionPattern = /^\d+\.\d+\.\d+(-[\w.-]+)?$/;
17
+ assert.ok(versionPattern.test(ZAMA_RELAYER_VERSION), `Version "${ZAMA_RELAYER_VERSION}" should match semver pattern`);
18
+ });
19
+ it("should match the cleaned version from package.json", () => {
20
+ const rawVersion = packageJson.dependencies["@zama-fhe/relayer-sdk"];
21
+ const cleanedVersion = rawVersion.replace(/^[\^~>=<]+/, "");
22
+ assert.strictEqual(ZAMA_RELAYER_VERSION, cleanedVersion);
23
+ });
24
+ });
25
+ describe("ZAMA_RELAYER_CDN_URL", () => {
26
+ it("should be defined and not empty", () => {
27
+ assert.ok(ZAMA_RELAYER_CDN_URL);
28
+ assert.ok(ZAMA_RELAYER_CDN_URL.length > 0);
29
+ });
30
+ it("should be a valid URL", () => {
31
+ assert.doesNotThrow(() => {
32
+ new URL(ZAMA_RELAYER_CDN_URL);
33
+ });
34
+ });
35
+ it("should start with https://cdn.zama.org", () => {
36
+ assert.ok(ZAMA_RELAYER_CDN_URL.startsWith("https://cdn.zama.org"));
37
+ });
38
+ it("should include the version number", () => {
39
+ assert.ok(ZAMA_RELAYER_CDN_URL.includes(ZAMA_RELAYER_VERSION));
40
+ });
41
+ it("should have the correct format", () => {
42
+ const expectedUrl = `https://cdn.zama.org/relayer-sdk-js/${ZAMA_RELAYER_VERSION}/relayer-sdk-js.umd.cjs`;
43
+ assert.strictEqual(ZAMA_RELAYER_CDN_URL, expectedUrl);
44
+ });
45
+ it("should end with .umd.cjs", () => {
46
+ assert.ok(ZAMA_RELAYER_CDN_URL.endsWith(".umd.cjs"));
47
+ });
48
+ });
49
+ describe("Version consistency", () => {
50
+ it("should ensure CDN URL updates when version changes", () => {
51
+ // This test ensures that if the version is updated in package.json,
52
+ // the CDN URL will also be updated accordingly
53
+ const expectedPattern = new RegExp(`https://cdn\\.zama\\.org/relayer-sdk-js/${ZAMA_RELAYER_VERSION.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/relayer-sdk-js\\.umd\\.cjs`);
54
+ assert.ok(expectedPattern.test(ZAMA_RELAYER_CDN_URL));
55
+ });
56
+ });
57
+ });
@@ -10,3 +10,4 @@ export { useSetOperator } from "./client/hooks/useSetOperator";
10
10
  export { usePublicDecrypt } from "./client/hooks/usePublicDecrypt";
11
11
  export { useFinalizeUnwrap } from "./client/hooks/useFinalizeUnwrap";
12
12
  export { type FhevmConfig, type Network } from "./types/fhevmConfig";
13
+ export { ZAMA_RELAYER_VERSION, ZAMA_RELAYER_CDN_URL } from "./config";
@@ -11,3 +11,5 @@ export { useEncryptedBatchTransfer } from "./client/hooks/useEncryptedBatchTrans
11
11
  export { useSetOperator } from "./client/hooks/useSetOperator";
12
12
  export { usePublicDecrypt } from "./client/hooks/usePublicDecrypt";
13
13
  export { useFinalizeUnwrap } from "./client/hooks/useFinalizeUnwrap";
14
+ // config
15
+ export { ZAMA_RELAYER_VERSION, ZAMA_RELAYER_CDN_URL } from "./config";
@@ -14,7 +14,7 @@ export const createFhevmInstance = (...args_1) => __awaiter(void 0, [...args_1],
14
14
  const defaultConfig = network === "mainnet"
15
15
  ? window.relayerSDK.MainnetConfig
16
16
  : window.relayerSDK.SepoliaConfig;
17
- fhevmInstance = yield window.relayerSDK.createInstance(Object.assign(Object.assign(Object.assign({}, defaultConfig), customConfig), { network: "https://ethereum-sepolia-rpc.publicnode.com" }));
17
+ fhevmInstance = yield window.relayerSDK.createInstance(Object.assign(Object.assign({}, defaultConfig), customConfig));
18
18
  }
19
19
  return fhevmInstance;
20
20
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyratzlabs/react-fhevm-utils",
3
- "version": "3.5.2",
3
+ "version": "3.5.4",
4
4
  "description": "React hooks and utilities for Fhevmjs",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "scripts": {
16
16
  "build": "tsc",
17
- "test": "npm run test",
17
+ "test": "node --import tsx --test src/**/*.test.ts",
18
18
  "clean": "rm -rf dist",
19
19
  "preversion": "npm run build"
20
20
  },
@@ -24,8 +24,10 @@
24
24
  "author": "Pyratzlabs",
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
+ "@types/node": "^22.10.5",
27
28
  "@types/react": "^19.1.0",
28
29
  "ts-node": "^10.9.2",
30
+ "tsx": "^4.19.2",
29
31
  "typescript": "^5.8.2"
30
32
  },
31
33
  "dependencies": {
package/dist/config.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export declare const config: {
2
- ACL_ADDRESS: string;
3
- KMS_ADDRESS: string;
4
- GATEWAY_URL: string;
5
- RPC_URL: string;
6
- };
package/dist/config.js DELETED
@@ -1,6 +0,0 @@
1
- export const config = {
2
- ACL_ADDRESS: "0xFee8407e2f5e3Ee68ad77cAE98c434e637f516e5",
3
- KMS_ADDRESS: "0x9D6891A6240D6130c54ae243d8005063D05fE14b",
4
- GATEWAY_URL: "https://gateway.sepolia.zama.ai/",
5
- RPC_URL: "https://eth-sepolia.g.alchemy.com/v2/z7ESc-2NGy8mOHByrhAENi2XbZHbW6dl",
6
- };
@@ -1,35 +0,0 @@
1
- /// <reference lib="webworker" />
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- import { getOrCreateFhevmInstance } from "../lib/fhevm";
12
- const ctx = self;
13
- ctx.onmessage = (event) => __awaiter(void 0, void 0, void 0, function* () {
14
- const { tokenAddress, address, value, chainId, networkUrl, network } = event.data;
15
- const instance = yield getOrCreateFhevmInstance({
16
- chainId,
17
- network,
18
- networkUrl,
19
- });
20
- if (!instance || !address) {
21
- ctx.postMessage({ error: "Instance or address is undefined" });
22
- return;
23
- }
24
- try {
25
- const result = yield instance
26
- .createEncryptedInput(tokenAddress, address)
27
- .add64(value)
28
- .encrypt();
29
- ctx.postMessage({ result });
30
- }
31
- catch (error) {
32
- console.error("Worker error", error);
33
- ctx.postMessage({ error });
34
- }
35
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes