From 1621b3b6085ce86b067dff80961f9a30bfbbdb14 Mon Sep 17 00:00:00 2001 From: Josh Long Date: Fri, 25 Aug 2023 08:04:43 -0400 Subject: [PATCH] fix loading from storage for decrypt and unit test --- .../getlit-sdk/src/lib/getlit-sdk.spec.ts | 19 +++++++++++-------- packages/getlit-sdk/src/lib/lit.ts | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/getlit-sdk/src/lib/getlit-sdk.spec.ts b/packages/getlit-sdk/src/lib/getlit-sdk.spec.ts index e932ea9af7..ca97422ef9 100644 --- a/packages/getlit-sdk/src/lib/getlit-sdk.spec.ts +++ b/packages/getlit-sdk/src/lib/getlit-sdk.spec.ts @@ -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((res, rej) => { - setTimeout(() => res(), 1_000); - }); + await loadLit(); } catch (e) { console.log( "You probably will need to run 'yarn build' before running this test.'" @@ -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: [ @@ -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, }); diff --git a/packages/getlit-sdk/src/lib/lit.ts b/packages/getlit-sdk/src/lib/lit.ts index 6a8f50a12c..398fbc5c18 100644 --- a/packages/getlit-sdk/src/lib/lit.ts +++ b/packages/getlit-sdk/src/lib/lit.ts @@ -261,7 +261,7 @@ ${LitMessages.persistentStorageExample}`; } // -- using decryption context - if (opts.decryptionContext) { + if (opts.decryptionContext && !material) { material = opts.decryptionContext as unknown as Material; }