From 956c0bac9bc101cc40af31c0c7c736c8d25fd70b Mon Sep 17 00:00:00 2001 From: James Campbell Date: Wed, 7 Dec 2022 13:36:17 +0000 Subject: [PATCH] GitBook: [#120] Explain dependency on WASM. Address https://github.com/nucypher/nucypher-ts/issues/119 --- .../advanced-usage/condition-hierarchies.md | 64 ------------------- .../get-started-with-tac.md | 16 +++-- 2 files changed, 11 insertions(+), 69 deletions(-) diff --git a/docs/app-development/threshold-access-control-tac/advanced-usage/condition-hierarchies.md b/docs/app-development/threshold-access-control-tac/advanced-usage/condition-hierarchies.md index 93fd948..aa47288 100644 --- a/docs/app-development/threshold-access-control-tac/advanced-usage/condition-hierarchies.md +++ b/docs/app-development/threshold-access-control-tac/advanced-usage/condition-hierarchies.md @@ -1,66 +1,2 @@ # Condition Hierarchies -[Conditions](../references/conditions.md) can be attached at several steps in the TAC lifecycle, and they have a fixed hierarchy at runtime. This means default Conditions can be be specified and subsequently overwritten later on in the process. - -## Strategy Conditions - -Conditions can be attached directly to a [Strategy](../references/strategy.md). They have the lowest precedence and are a great place for including defaults or 'fall back' conditions. - -```javascript -import { Cohort, Conditions, ConditionSet, Strategy } from '@nucypher/nucypher-ts'; - -const config = { - threshold: 3, - shares: 5, - porterUri: 'https://porter-tapir.nucypher.community', -}; -const newCohort = await Cohort.create(config); - -const NFTOwnership = new Conditions.ERC721Ownership({ - contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', - chain: 5, // Tapir network uses Görli testnet - parameters: [5954], -}) -const conditions = new ConditionSet([NFTOwnership]); - -const newStrategy = Strategy.create( - newCohort, - conditions -); -``` - -All `encrypter` objects that a deployed Strategy produces will automatically have these conditions included. Therefore, all encrypted messages will require these conditions to be satisfied. - -## Encrypter Conditions - -This is the next level of precedence the hierarchy, where each encrypter object can have its own conditions. Assuming the above strategy has been deployed, we can attach conditions in the following way: - -```javascript -const encrypter = deployedStrategy.encrypter; - -const newNFTOwnership = new Conditions.ERC721Ownership({ - contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', - chain: 5, - parameters: [5000], // let's change the specific NFT -}) - -encrypter.conditions = new ConditionSet([newNFTOwnership] -``` - -This will **overwrite** the Strategy conditions we defined above - only the new Conditions will be evaluated, not both. All messages encrypted with `encrypter` will require `newNFTOwnership` to be satisfied. - -## Message Conditions - -This is the final, and highest priority, Condition type. When encrypting a message, Conditions can be added that apply **only** to this specific encryption. Again, they will overwrite any Conditions specified during Strategy creation or within the encrypter. - -```javascript -const NFTBalance = new Conditions.ERC721Balance({ - contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', - chain: 5, -}); - -const plaintext = 'this is a secret'; -const encryptedMessageKit = encrypter.encryptMessage(plaintext, new ConditionSet([NFTBalance])); -``` - -Here we've actually made our Condition more relaxed, and only require a non-zero balance with the NFT contract. diff --git a/docs/app-development/threshold-access-control-tac/get-started-with-tac.md b/docs/app-development/threshold-access-control-tac/get-started-with-tac.md index 0866594..c1bee9a 100644 --- a/docs/app-development/threshold-access-control-tac/get-started-with-tac.md +++ b/docs/app-development/threshold-access-control-tac/get-started-with-tac.md @@ -4,22 +4,28 @@ This tutorial is a quick way for developers to learn about the Threshold Access ## 1. Install `nucypher-ts` +{% hint style="warning" %} +`nucypher-ts` is under [active development](https://github.com/nucypher/nucypher-ts/pulls). +{% endhint %} + To start, we need to install the `nucypher-ts` library: ``` yarn add @nucypher/nucypher-ts ``` +One of the `nucypher-ts` dependencies takes advantage of [WASM](https://developer.mozilla.org/en-US/docs/WebAssembly). In order to run `nucypher-ts` in the browser, we have to [load WASM](https://developer.mozilla.org/en-US/docs/WebAssembly/Loading\_and\_running) from the source files. This process is mostly automated by the wrapper generated by [`wasm-pack`](https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/using-your-library.html) + +Visit [`nucypher-ts/examples`](https://github.com/nucypher/nucypher-ts/tree/main/examples) to find out how to use `nucypher-ts` in your web application. + + + Also, for this example we will need some extra packages: ``` yarn add ethers @metamask/detect-provider ``` -{% hint style="warning" %} -`nucypher-ts` is under [active development](https://github.com/nucypher/nucypher-ts/pulls). -{% endhint %} - ## 2. Build a Cohort Next, we will create a `Cohort` based on our risk preferences. A `Cohort` is a group of nodes that work together to control access to data. Threshold and Shares are two parameters used to create a `Cohort`. For example, a 3-of-5 `Cohort` needs at least 3 of the 5 members to provide shares to access the original data. @@ -60,7 +66,7 @@ const NFTOwnership = new Conditions.ERC721Ownership({ ``` {% hint style="info" %} -There are multiple [Condition types](references/conditions.md) and it is possible combine multiple conditions into a [ConditionSet](references/condition-set.md). +There are multiple [Condition types](references/conditions.md) and it is possible to combine multiple conditions into a [ConditionSet](references/condition-set.md). {% endhint %} ```javascript