Strategy

A Strategy combines all possible configuration parameters for using CBD. It takes the following parameters:

  • cohort - a Cohort object

  • conditionSet? - an optional ConditionSet. If used, all encryptions made via this strategy have a default Condition Set assigned

  • aliceSecretKey? - an optional Secret Key for the encrypter

  • bobSecretKey? - an optional SecretKey for decrypter

If the optional secret keys are not provided, new ones will be generated instead.

Create a Strategy

Assuming we have a Cohort already defined, we can construct a Strategy:

import { Cohort, Strategy } from '@nucypher/nucypher-ts';

const config = {
  threshold: 3,
  shares: 5,
  porterUri: 'https://porter-ibex.nucypher.community',
};
const newCohort = await Cohort.create(config);

const newStrategy = Strategy.create(
  newCohort
);

Deploy a Strategy

Before we can encrypt/decrypt, the Threshold network needs to be made aware of our Strategy. We do this by deploying:

Strategy.deploy takes 2 parameters:

  • label - this is a string that the network uses to identify the strategy

  • provider - deploying a Strategy requires writing to the smart contract, so a connection to a wallet is required via a Web3 provider

Deploying a strategy returns a new DeployedStrategy object. This object grants us access to the encrypter and decrypter which can then be used throughout an application.

Import and Export Strategies

Strategies can be exported allowing them to be reused easily. The syntax is the same whether the strategy has been deployed or not.

Similarly, we can import and export the decrypter objects to JSON. This allows us to rebuild the decrypter on a client facing application:

Last updated

Was this helpful?