Skip to content

Commit

Permalink
bring networkPublicKey page up-to-date
Browse files Browse the repository at this point in the history
eshelB committed Sep 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8bac4a8 commit f858af2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions docs/devdocs/FhenixJS/Network Keys.mdx
Original file line number Diff line number Diff line change
@@ -18,22 +18,28 @@ If you're using fhenix.js you don't need to worry about this, as the public key

##### Fetching the Public Key Manually

However, if you're using interfacing with Fhenix directly, you'll need to fetch the public key from the network you're connecting to. This can be done by calling the `getPublicKey` function on the network you're connecting to.
However, if you're using interfacing with Fhenix directly, you'll need to fetch the public key from the network you're connecting to. This can be done by calling the `getNetworkPublicKey` function on the network you're connecting to.

The Public Key is constant for the lifetime of the network, but still has to be fetched once by the user to be able to encrypt data. To do this, we use a special precompiled function that can be accessed programmatically in the following way:

<Tabs>
<TabItem value="ethers.js" label="ethers.js">
```javascript
const networkPkAbi = new Interface(["function getNetworkPublicKey(int32 securityZone)"]);
const callData = networkPkAbi.encodeFunctionData("getNetworkPublicKey", [0]); // last param is the security zone, generally 0
let result = await provider.call({
to: "0x0000000000000000000000000000000000000080",
data: callData
});
```
</TabItem>
<TabItem value="web3.js" label="Web3.js">
```javascript
const networkPkSig = web3.eth.abi.encodeFunctionSignature("function getNetworkPublicKey(int32 securityZone)");
const param = web3.eth.abi.encodeParameter("int32", 0); // last param is the security zone, generally 0
let result = await web3.eth.call({
to: "0x0000000000000000000000000000000000000080"
to: "0x0000000000000000000000000000000000000080",
data: networkPkSig + param
});
```
</TabItem>

0 comments on commit f858af2

Please sign in to comment.