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

[WIP] LitEncryption Module #130

Draft
wants to merge 11 commits into
base: feat/ssx-modules
Choose a base branch
from

Conversation

Juliano1612
Copy link
Member

@Juliano1612 Juliano1612 commented Apr 25, 2023

Description

This adds support for the LitEncryption module.

Type

  • New feature (non-breaking change which adds functionality)

Diligence Checklist

  • This change requires a documentation update
  • I have included unit tests
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

skgbafa and others added 10 commits March 31, 2023 14:50
* ssx design pattern

* updated tests

* added sdk test command

* migrate SSX functions to UserAuthroization resource

* updated UserAuthorization logic + tests

* update tests

* renamed resources to modules

* setup SSX to import modules

* include modules in ssx

* correct typescript errors

* add module dependencies to tests

* cleanup

* fix provider reference

* remove ssx init + connected
* add signature encryption module

* update tests

* text box for ciphertext

* made changes to extension to fix tests

---------

Co-authored-by: franklovefrank <annaclaire.fields@spruceid.com>
* Signature Encryption Module (spruceid#113)

* add signature encryption module

* update tests

* text box for ciphertext

* made changes to extension to fix tests

---------

Co-authored-by: franklovefrank <annaclaire.fields@spruceid.com>

* added storage + datavault module

* added datavault

* added ssx-notepad-datavault

* move from blob to json

* encryption debugging changes

* fix build error

* updated example to use only datavault instead of server

* updated storage module to use indexedDB instead of localstorage

* prevent occasional install bug

* update indexeddb usage

* updated notepad example

* remove examples from workspace due to installation issues

* added helmet back for walleconnect

* added mock indexeddb

* cleanup

* add missing dependencies for test

* updated docstrings

* Add examples to monorepo and fix notepad example build

* Fix getSigner on tests

* configurable store name

* fixed tests

---------

Co-authored-by: franklovefrank <annaclaire.fields@spruceid.com>
Co-authored-by: Juliano <julianocezargyn@hotmail.com>
Comment on lines 77 to 87
test('Should be able to encrypt and decrypt a message', async () => {
const message = 'Hello World';
const encryptedMessage = await encryption.encrypt(message);
const decryptedMessage = await encryption.decrypt(encryptedMessage);
expect(decryptedMessage).toEqual(message);
const encryptedData = await encryption.encrypt({
content: message,
accessControlConditions: LIT_ENCRYPTION_ACCESS_CONTROL_CONDITIONS
});
const decryptedData = await encryption.decrypt({
...encryptedData,
accessControlConditions: LIT_ENCRYPTION_ACCESS_CONTROL_CONDITIONS
});
expect(decryptedData.decryptedString).toEqual(message);
Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the tests here, but I still have trouble with the crypto library. Left them disabled.

Comment on lines 120 to 127
if (
this.config?.modules?.encryption === true ||
(this.config?.modules?.encryption as SSXEncryptionModuleConfig)?.module === 'SignatureEncryption'
) {
this.encryption = new SignatureEncryption({}, this.userAuthorization);
} else if ((this.config?.modules?.encryption as SSXEncryptionModuleConfig)?.module === 'LitEncryption') {
this.encryption = new LitEncryption({}, this.userAuthorization);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a temporary approach until we define the way we configure the modules. I'm assuming SignatureEncryption as default

* @param chainId - Unique chain id.
* @returns - The chain name follwing the Lit Protocol docs.
*/
private getChainName = (chainId: number) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to create this to translate chainId -> chain string followingLit supported chains.

Comment on lines +186 to +197
// case ?:
// return "cosmos";
// case ?:
// return "kyve";
// case ?:
// return "evmosCosmos";
// case ?:
// return "evmosCosmosTestnet";
// case ?:
// return "cheqd";
// case ?:
// return "juno";
Copy link
Member Author

Choose a reason for hiding this comment

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

Couldn't find these chainIds

@@ -1,5 +1,6 @@
import * as jose from 'jose';
import { IUserAuthorization } from './UserAuthorization';
import { IUserAuthorization, UserAuthorization } from './UserAuthorization';
import * as LitJsSdk from '@lit-protocol/lit-node-client';
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm receiving this warning after the compilation:

WARNING in ../../node_modules/@lit-protocol/ecdsa-sdk/src/lib/ecdsa-sdk.js 428:22-61
Critical dependency: the request of a dependency is an expression
 @ ../../node_modules/@lit-protocol/ecdsa-sdk/src/index.js 4:21-47
 @ ../../node_modules/@lit-protocol/crypto/src/lib/crypto.js 7:18-52
 @ ../../node_modules/@lit-protocol/crypto/src/index.js 4:21-44
 @ ../../node_modules/@lit-protocol/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.js 9:17-48
 @ ../../node_modules/@lit-protocol/lit-node-client-nodejs/src/index.js 6:29-68 18:21-60
 @ ../../node_modules/@lit-protocol/lit-node-client/src/index.js 25:21-68
 @ ./src/modules/Encryption.ts 37:30-70
 @ ./src/modules/index.ts 20:13-36
 @ ./src/index.ts 19:13-33

And this is generating a warning on ssx-test-dapp:

Compiled with warnings.

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

WARNING in ../../packages/ssx-sdk/dist/index.js 59504:80-87
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

webpack compiled with 1 warning

@skgbafa or @w4ll3 have you ever seen this?

signedMessage: session.siwe,
};

const { encryptedString, symmetricKey } = await LitJsSdk.encryptString(data.content)
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm only encrypting strings here, but they have other methods to encrypt. We can add/change this call

@Juliano1612 Juliano1612 changed the title LitEncryption Module [WIP] LitEncryption Module May 3, 2023
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

2 participants