Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples update #43

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions docs/devdocs/Encryption and Privacy/Permits-Access-Control.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ The inclusion of this public key into the permit enables a secure process of dat

#### How to Generate a Permit

Permits are generated using the `getPermit` method in `fhenix.js`. This method requires the following parameters:
Permits are generated using the `generatePermit` method in `fhenix.js`. This method receives the following parameters:

* `contractAddress` (required, string): The address of the contract.
* `provider` (required): An `ethers` (or compatible) object that can sign EIP-712 formatted data. (Note that if you want to unseal data using your wallet's encryption key you can't use "JsonRpcProvider")
* `provider` (optional): An `ethers` (or compatible) object that can sign EIP-712 formatted data. (Note that if you want to unseal data using your wallet's encryption key you can't use "JsonRpcProvider")
* `signer` (optional): Another `ethers` (or compatible) signer if you want to use a different signer than the one in the provider (chain-id requests are still made via the provider)

```javascript
const permit = await getPermit(contractAddress);
const permit = await generatePermit(contractAddress);

// passing a custom signer
let permit = await fhenixjs.generatePermit(
contractAddress,
undefined, // use the internal provider
signer, // created from, e.g. `ethers.getSigners()[0]`
);
```

#### What is a Permission?
Expand Down Expand Up @@ -57,9 +65,8 @@ import { FhenixClient, getPermit } from "fhenixjs";

const provider = new BrowserProvider(window.ethereum);
const client = new FhenixClient({ provider });
const permit = await getPermit(contractAddress, provider);
const permit = await generatePermit(contractAddress, provider);
const permission = client.extractPemitPermissions(permit);
client.storePermit(permit); // Stores a permit for a specific contract address.
const response = await contract.connect(owner).getValue(permission); // Calling "getValue" which is a view function in "contract"
const plaintext = await client.unseal(contractAddress, response);
```
2 changes: 1 addition & 1 deletion docs/devdocs/Examples and References/Templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ We compiled a list of a few templates that you can use as a reference to build y

https://github.com/FhenixProtocol/fhenix-hardhat-example

Has a basic contract, some tasks and a simple frontend (TODO: copy over from playground).
Has a basic contract, some tasks and a simple frontend.

### Nuxt 3 + Fhenixjs + Ethers.js + Bootstrap Starter

Expand Down
14 changes: 5 additions & 9 deletions docs/devdocs/FhenixJS/Decryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ This is done in 3 steps: generating a permit, querying the contract and unsealin
#### 1. Creating a Permit

```javascript
import { FhenixClient, getPermit } from 'fhenixjs';
import { FhenixClient, generatePermit } from 'fhenixjs';

const provider = new ethers.JsonRpcProvider('https://api.helium.fhenix.zone/');
const client = new FhenixClient({ provider });


const permit = await getPermit(contractAddress, provider);
client.storePermit(permit);
const permit = await generatePermit(contractAddress, provider);
```

:::tip[Did you know?]
Expand Down Expand Up @@ -74,18 +72,16 @@ Permits are currently limited to support a single contract
#### Putting it all Together

```typescript
import { FhenixClient, getPermit } from 'fhenixjs';
import { FhenixClient, generatePermit } from 'fhenixjs';
import { JsonRpcProvider } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://api.helium.fhenix.zone/');
const client = new FhenixClient({provider});

const permit = await getPermit(contractAddress, provider);
client.storePermit(permit);

const permit = await generatePermit(contractAddress, provider);
const permission = client.extractPermitPermission(permit);
const response = await contract.balanceOf(permission);

const response = await contract.balanceOf(permission);
const plaintext = client.unseal(contractAddress, response);

console.log(`My Balance: ${plaintext}`)
Expand Down
1 change: 1 addition & 0 deletions docs/devdocs/FhenixJS/Encryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The `EncryptedUint` types sound scary, but are actually pretty simple. It's just
```typescript
export interface EncryptedNumber {
data: Uint8Array;
securityZone: number; // defaults to 0
}

export interface EncryptedUint8 extends EncryptedNumber {}
Expand Down
4 changes: 2 additions & 2 deletions docs/devdocs/Writing Smart Contracts/Types-and-Operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The `ebool` type is not a real boolean type. It is implemented as a `euint8`


:::tip
A documented documentation of each and every function in FHE.sol (including inputs and outputs) can be found in [FHE.sol](../Solidity%20API/FHE.md)
A documentation of every function in FHE.sol (including inputs and outputs) can be found in [FHE.sol](../Solidity%20API/FHE.md)
:::

All operations supported by FHE.sol are listed in the table below. For performance reasons, not all operations are supported for all types.
Expand Down Expand Up @@ -142,4 +142,4 @@ Using require and decrypt in a TX is dangerous as it can break the confidentiali

:::tip
Division and Remainder by `0` will output with an encrypted representation of the maximal value of the uint that is used (Ex. encrypted 255 for euint8)
:::
:::
Loading