Skip to content

Commit

Permalink
GitBook: [#118] Update code examples for adding conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
theref authored and gitbook-bot committed Dec 7, 2022
1 parent 190cbd8 commit 0e68f72
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const NFTOwnership = new Conditions.ERC721Ownership({
```

{% hint style="info" %}
There are other [`Condition` types](references/conditions.md), and it is possible to combine multiple conditions into a [`ConditionSet`](references/condition-set.md)``
There are multiple [Condition types](references/conditions.md) and it is possible combine multiple conditions into a [ConditionSet](references/condition-set.md). 
{% endhint %}

```javascript
Expand Down Expand Up @@ -104,17 +104,30 @@ if (MMprovider) {
Deploying a `Strategy` requires writing to the blockchain. This requires a wallet funded with testnet MATIC and connection to the blockchain via an `provider`(e.g. MetaMask).
{% endhint %}

## 5. Encrypt the plaintext & add predominant Conditions
## 5. Encrypt the plaintext & update Conditions

We can now encrypt data using the newly deployed `Strategy`. At this point, we can specify new conditions on which data access will be predicated. These take a higher precedence and will override the default conditions contained in the Strategy. In this case, we will require the requester's wallet to hold a minimum number (3) of the same NFTs as before. Note that Threshold nodes will check this using the `balanceOf` method. 

To encrypt the data, use the following code:

```javascript
const NFTBalanceConfig = {
contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',
standardContractType: 'ERC721',
chain: 5,
method: 'balanceOf',
parameters: [':userAddress'],
returnValueTest: {
comparator: '>=',
value: 3,
},
};
const NFTBalance = new Conditions.Condition(NFTBalanceConfig);

const encrypter = newDeployed.encrypter;

const plaintext = 'this is a secret';
const encryptedMessageKit = encrypter.encryptMessage(plaintext);
const encryptedMessageKit = encrypter.encryptMessage(plaintext, new ConditionSet([NFTBalance]));
```

## 6. Request decryption rights
Expand Down

0 comments on commit 0e68f72

Please sign in to comment.