Skip to content

Commit

Permalink
fix loading from storage for decrypt and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Long committed Aug 25, 2023
1 parent b7ec632 commit 1621b3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions packages/getlit-sdk/src/lib/getlit-sdk.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { PKPEthersWallet } from '@lit-protocol/pkp-ethers';
import * as LITCONFIG from '../../../../lit.config.json';

import { loadLit } from '../../../../dist/packages/getlit-sdk/src/index';
import { ILitStorage, LitStorage } from '@lit-protocol/lit-storage';
describe('getlitSDK', () => {
beforeAll(async () => {
try {
await import('../../../../dist/packages/getlit-sdk');
await new Promise<void>((res, rej) => {
setTimeout(() => res(), 1_000);
});
await loadLit();
} catch (e) {
console.log(
"You probably will need to run 'yarn build' before running this test.'"
Expand Down Expand Up @@ -93,6 +91,8 @@ describe('getlitSDK', () => {
}, 10_000);

it('Should encrypt message and decrypt message as string', async () => {
globalThis.Lit.builder?.withCacheProvider(new LitStorage());
await globalThis.Lit.builder?.build();
const message: string = 'Hello World';
const enctyptedContent = await globalThis.Lit.encrypt({
accessControlConditions: [
Expand All @@ -115,17 +115,20 @@ describe('getlitSDK', () => {

expect(enctyptedContent).toBeDefined();
expect(
globalThis.Lit?.storage?.getItem(enctyptedContent.storageKey)
globalThis.Lit.storage?.getItem(enctyptedContent.storageKey)
).toBeDefined();
expect(
globalThis.Lit?.storage?.getItem(
enctyptedContent.storageContext.storageKey
enctyptedContent.storageKey
)
).toBeDefined();

const res = await globalThis.Lit.decrypt({
storageContext: {
storageKey: enctyptedContent.storageContext.storageKey,
storageKey: enctyptedContent.storageKey,
},
decryptionContext: {
decryptionMaterial: enctyptedContent.decryptionContext.decryptionMaterial
},
authMaterial: LITCONFIG.CONTROLLER_AUTHSIG,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/getlit-sdk/src/lib/lit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ ${LitMessages.persistentStorageExample}`;
}

// -- using decryption context
if (opts.decryptionContext) {
if (opts.decryptionContext && !material) {
material = opts.decryptionContext as unknown as Material;
}

Expand Down

0 comments on commit 1621b3b

Please sign in to comment.