Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V3] Upgrade ACC-based encryption + JWT signing #145

Closed
wants to merge 26 commits into from

Conversation

hwrdtm
Copy link
Contributor

@hwrdtm hwrdtm commented Jun 14, 2023

What

Closes LIT-804.
Closes LIT-695.
Related to LIT-951.

⚠️ This is a massive PR. Brace yourself with some 🍿 and 🍵 !! ⚠️

This PR:

  • Deserves a major version bump. We are completely overhauling the ACC-based encryption and JWT signing schemes with new schemes, and are bringing in a number of incompatible changes.
  • ID-based encryption: This new scheme is also known as Timelock Encryption, or TimeCrypt, where there exists an Identity Parameter, and the signature over it is a decryption key over a ciphertext that has been generated with this Identity Parameter. In other words, signature shares - with the Identity Parameter as the signature payload - are combined into a signature, and this signature can be used to decrypt an associated ciphertext. Read more in the spec here: https://www.notion.so/litprotocol/Switch-from-Signcryption-to-BLS-signature-is-key-scheme-b75c21927ed64511b523c8a93b870a65.
    • Note that the encryption step is non-interactive and happens entirely client-side.
  • ACC-based JWT Signing (V2): This new scheme simplifies the overall flow by baking into each dapp endpoint the required access control conditions directly. This means that there is no "store signing condition" step as dapp developers just write it into their dapp code and an additional check against the access control condition is performed there. When clients request for a signed JWT with claims of the specified access control condition, the signature of this JWT is only provided when the nodes determine that the user satisfy this access control condition. Read more in the spec here: https://www.notion.so/litprotocol/ACC-based-JWT-signing-V2-a4db1446bac54eea90b7ab08e5455246.
  • The BLS WASM (bls-sdk.ts) is entirely replaced with new code. Unit tests are added to this package.
  • The SDK no longer supports the jalapeno network moving forward. Developers can use the old SDK versions to continue using the old encryption and JWT signing schemes. serrano network is the new default.
  • Updated crypto package to be a lightweight wrapper over bls-sdk package with minor conversion logic.
  • Updated encryption package to replace the old encryption + JWT signing logic with the new schemes. This is becoming more a helper library over lit-node-client-nodejs and crypto.
  • Refactored params-validators to use a plugin-based approach with various *Validators.
  • Updated all manual tests in apps/html to use the new ID-based encryption and JWT signing schemes. You will notice quite a few test cases are removed since we no longer need to store encryption keys, or store signing conditions respectively.
  • demo-encrypt-decrypt-react:
    • Turned this into a TS project.
    • Updated this demo to use the new ID-based encryption scheme - just a encryptString and decryptToString call.
  • Implement demo-locked-express-app to demo the new JWT signing flow. Instructions in its README.md.
  • Made use of generics in a number of places, eg. IEither, SuccessNodePromises and benchmark()

Testing

  • A large number of HTML manual tests have been tested (against local network)
  • E2E tests pass
  • Unit tests pass

TODO

  • Re-test demo-encrypt-decrypt-react after rebasing
  • Re-test demo-locked-express-app after rebasing
  • Update demo-encrypt-decrypt-react/package.json to use newly published SDK version.
  • Update demo-locked-express-app/package.json to use newly published SDK version.
  • Remove support for serrano too and introduce cayenne as the new default.

@hwrdtm hwrdtm self-assigned this Jun 14, 2023
@vercel
Copy link

vercel bot commented Jun 14, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
html-test-app-lit-js-sdk-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2023 5:44pm

@@ -0,0 +1,47 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the types don't seem to be linking properly...

await savedParams.litNodeClient.saveEncryptionKey({
describe('Encrypt and Decrypt', () => {
it('encrypts', async () => {
cy.window().then(async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why, but without wrapping each functionality with this cy.window() the wasm is undefined and not initialized

@@ -4,13 +4,18 @@
"private": true,
"dependencies": {
"@lit-protocol/lit-node-client": "^2.1.158",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: need to update version once published.

"main": "index.js",
"license": "MIT",
"dependencies": {
"@lit-protocol/lit-node-client-nodejs": "file:../../packages/lit-node-client-nodejs",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: need to update version once published.

@hwrdtm hwrdtm force-pushed the hwrdtm/upgrade-acc-based-decryption-signing branch from da294a2 to 958d035 Compare June 24, 2023 23:32
@hwrdtm hwrdtm force-pushed the hwrdtm/upgrade-acc-based-decryption-signing branch from 958d035 to 014d8d8 Compare June 24, 2023 23:33
@hwrdtm hwrdtm changed the title Upgrade ACC-based encryption + signing Upgrade ACC-based encryption + JWT signing Jun 24, 2023
@hwrdtm hwrdtm marked this pull request as ready for review June 24, 2023 23:55
@hwrdtm
Copy link
Contributor Author

hwrdtm commented Jun 25, 2023

Not sure why CI is failing, can't repro locally too with npx nx run auth-helpers:test

apps/demo-locked-express-app/index.ts Show resolved Hide resolved
apps/demo-encrypt-decrypt-react/src/App.tsx Show resolved Hide resolved
apps/demo-locked-express-app/index.ts Show resolved Hide resolved
@@ -105,9 +106,11 @@ export const checkAndSignSolAuthMessage = async (): Promise<AuthSig> => {

try {
// when it's not in local storage, it's a string
// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to refactor the IEither type at some point so we don't have to do this

glitch003
glitch003 previously approved these changes Jun 29, 2023
];

// execute
const plaintext = blsSdk.verify_and_decrypt_with_signature_shares(
Copy link
Contributor

@sarahzdev sarahzdev Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(can't seem to comment on the packages/bls-sdk/src/lib/bls-sdk.ts file directly)

maybe we should strive to keep casing consistent across the sdk

@hwrdtm hwrdtm force-pushed the hwrdtm/upgrade-acc-based-decryption-signing branch from 10dd561 to 9ad5af3 Compare July 11, 2023 17:43
@Ansonhkg Ansonhkg changed the title Upgrade ACC-based encryption + JWT signing [V3] Upgrade ACC-based encryption + JWT signing Jul 17, 2023
@joshLong145
Copy link
Collaborator

Closing as functionality has been merged into: https://github.com/LIT-Protocol/js-sdk/tree/feat/SDK-V3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants