Skip to content

Commit

Permalink
docs: update fhevmjs
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Jun 30, 2024
1 parent 0200bba commit 568f9b3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/fundamentals/inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function myExample(
On client side for the previous function, using [fhevmjs](https://github.com/zama-ai/fhevmjs), the code will be:

```javascript
const instance = createInstance({ networkUrl: "https://devnet.zama.ai" });
const instance = await createInstance({ networkUrl: "http://localhost:8545" });

const input = instance.createEncryptedInput(contractAddress, userAddress);
const { inputs, data } = input.add64(64).addBool(true).add8(4).encrypt(); // Encrypt the three parameters
Expand Down
6 changes: 4 additions & 2 deletions docs/guides/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ pnpm add fhevmjs

An instance receives an object containing:

- `chainId`: the chainId of the network
- `networkUrl` (optional): the URL of the network (used to fetch the public key)
- `chainId` (optional): the chainId of the network
- `network` (optional): the Eip1193 object provided by `window.ethereum` (used to fetch the public key and/or chain id)
- `networkUrl` (optional): the URL of the network (used to fetch the public key and/or chain id)
- `publicKey` (optional): if the public key has been fetched separately (cache), you can provide it
- `gatewayUrl` (optional): the URL of the gateway to retrieve a reencryption
- `coprocessorUrl` (optional): the URL of the coprocessor

## Create an instance

Expand Down
25 changes: 9 additions & 16 deletions docs/guides/webapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,28 @@ To use the library in your project, you need to load the WASM of [TFHE](https://
import { initFhevm } from "fhevmjs";

const init = async () => {
await initFhevm(); // Load TFHE
await initFhevm(); // Load needed WASM
};

init().then((instance) => {
console.log(instance);
});
```

Once the WASM is loaded, you can now create an instance. An instance receives an object containing:

- `chainId`: the chainId of the network
- `networkUrl` (optional): the URL of the network (used to fetch the public key)
- `chainId` (optional): the chainId of the network
- `network` (optional): the Eip1193 object provided by `window.ethereum` (used to fetch the public key and/or chain id)
- `networkUrl` (optional): the URL of the network (used to fetch the public key and/or chain id)
- `publicKey` (optional): if the public key has been fetched separately (cache), you can provide it
- `gatewayUrl` (optional): the URL of the gateway to retrieve a reencryption
- `coprocessorUrl` (optional): the URL of the coprocessor

```javascript
import { initFhevm, createInstance } from "fhevmjs";

const createFhevmInstance = async () => {
return createInstance({
chainId: 8009,
networkUrl: "https://devnet.zama.ai/",
gatewayUrl: "https://gateway.zama.ai",
});
};

const init = async () => {
await initFhevm(); // Load TFHE
return createFhevmInstance();
return createInstance({
network: window.ethereum,
gatewayUrl: "https://gateway.zama.ai/",
});
};

init().then((instance) => {
Expand Down
17 changes: 14 additions & 3 deletions docs/references/fhevmjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ initFhevm().then(() => {

This function returns an instance of fhevmjs, which accepts an object containing:

- `chainId`: the chainId of the network
- `networkUrl` (optional): the URL of the network (used to fetch the public key)
- `chainId` (optional): the chainId of the network
- `network` (optional): the Eip1193 object provided by `window.ethereum` (used to fetch the public key and/or chain id)
- `networkUrl` (optional): the URL of the network (used to fetch the public key and/or chain id)
- `publicKey` (optional): if the public key has been fetched separately (cache), you can provide it
- `gatewayUrl` (optional): the URL of the gateway to retrieve a reencryption
- `coprocessorUrl` (optional): the URL of the coprocessor
Expand All @@ -33,12 +34,22 @@ This function returns an instance of fhevmjs, which accepts an object containing
import { createInstance } from "fhevmjs";

const instance = await createInstance({
chainId: 8009,
networkUrl: "https://devnet.zama.ai/",
gatewayUrl: "https://gateway.zama.ai/",
});
```

Using `window.ethereum` object:

```javascript
import { createInstance } from "fhevmjs";

const instance = await createInstance({
network: window.ethereum,
gatewayUrl: "https://gateway.zama.ai/",
});
```

## Input

This method creates an encrypted input and returns an input object. It requires both the user address and the contract address to ensure the encrypted input isn't reused inappropriately in a different context.
Expand Down

0 comments on commit 568f9b3

Please sign in to comment.