nucypher / taco-web

🌮 A TypeScript client for TACo (Threshold Access Control)
https://docs.threshold.network/app-development/threshold-access-control-tac
GNU General Public License v3.0
14 stars 22 forks source link

Decrypt API Rework #560

Closed derekpierre closed 3 weeks ago

derekpierre commented 1 month ago

Type of PR:

Required reviews:

What this does:

The updated use of the code will look like the following:

  1. Create condition context from message kit:

    const conditionContext = conditions.context.ConditionContext.fromMessageKit(messageKit);
  2. Add any required auth provider(s):

    • Add auth provider for :userAddress, if necessary:

      const authProvider = new EIP4361AuthProvider(web3Provider, web3Provider.getSigner());
      conditionContext.addAuthProvider(USER_ADDRESS_PARAM_DEFAULT, authProvider);
    • Add auth provider for :userAddressExternalEIP4361, if necessary:

      const singleSignOnEIP4361AuthProvider = await SingleSignOnEIP4361AuthProvider.fromExistingSiweInfo(messageStr, 
      signature);
      conditionContext.addAuthProvider(USER_ADDRESS_PARAM_EXTERNAL_EIP4361, authProvider);
  3. Add any required custom context variables, if necessary:

    const conditionContext = conditions.context.ConditionContext.fromMessageKit(messageKit);
    conditionContext.addCustomContextParameterValues({
    ":myCustomValue1": value_1,
    ":myCustomVallue2": value_2,
    ...
    });
  4. Call decrypt

    const decryptedMessage = await decrypt(web3Provider, domain, messageKit, conditionContext);

Additionally, developers can also better query what parameters are needed for a condition in a message kit. This helps when apps have various permutations of conditions that they use, which include different parameters:

const conditionContext = conditions.context.ConditionContext.fromMessageKit(messageKit);
requestedContextParameters = conditionContext.requestedContextParameters  // set of context variables required for underlying condition
// Devs can check for specific context parameters or loop over the set and populate context variables appropriately.

Issues fixed/closed:

  • Fixes #...

Why it's needed:

Explain how this PR fits in the greater context of the NuCypher Network. E.g., if this PR address a nucypher/productdev issue, let reviewers know!

Notes for reviewers:

What should reviewers focus on? Is there a particular commit/function/section of your PR that requires more attention from reviewers?

netlify[bot] commented 1 month ago

Deploy Preview for taco-demo canceled.

Name Link
Latest commit 1e528aa196c4a774a192a4dcde1d1f09e31d06cf
Latest deploy log https://app.netlify.com/sites/taco-demo/deploys/66c34d496107d700081b651e
netlify[bot] commented 1 month ago

Deploy Preview for taco-nft-demo canceled.

Name Link
Latest commit 1e528aa196c4a774a192a4dcde1d1f09e31d06cf
Latest deploy log https://app.netlify.com/sites/taco-nft-demo/deploys/66c34d49e5f0e00008da6d60
derekpierre commented 1 month ago

Replaces https://github.com/nucypher/taco-web/pull/554 which was auto-closed once epic-auth was merged.

codecov-commenter commented 1 month ago

Codecov Report

Attention: Patch coverage is 76.44231% with 49 lines in your changes missing coverage. Please review.

Project coverage is 79.10%. Comparing base (e8f9098) to head (1e528aa). Report is 155 commits behind head on main.

Files Patch % Lines
packages/test-utils/src/utils.ts 0.00% 34 Missing :warning:
packages/taco/examples/encrypt-decrypt.ts 0.00% 5 Missing :warning:
packages/taco/src/conditions/context/context.ts 96.77% 2 Missing and 1 partial :warning:
packages/taco/src/taco.ts 75.00% 1 Missing and 2 partials :warning:
packages/taco/src/tdec.ts 82.35% 1 Missing and 2 partials :warning:
...aco-auth/src/providers/eip4361/external-eip4361.ts 85.71% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #560 +/- ## =========================================== + Coverage 23.12% 79.10% +55.98% =========================================== Files 62 66 +4 Lines 10175 6801 -3374 Branches 260 300 +40 =========================================== + Hits 2353 5380 +3027 + Misses 7763 1377 -6386 + Partials 59 44 -15 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

derekpierre commented 3 weeks ago
requestedContextParameters = conditionContext.requestedContextParameters  // list of context variables required for underlying condition
// Devs can loop over the list and populate context variables appropriately.

Could we get an example of iterating over this?

Great idea - added an illustrative optional example to the nodejs example - see https://github.com/nucypher/taco-web/pull/560/commits/1e528aa196c4a774a192a4dcde1d1f09e31d06cf.