Skip to content

Commit

Permalink
Adds support for encryptedWith.encryptedPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarenaldi committed Sep 11, 2023
1 parent cb14c90 commit eb7f323
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 509 deletions.
4 changes: 3 additions & 1 deletion packages/gated-content/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ config:
CreateHandle: string
Cursor: string
DateTime: string
EncryptedPath: string
EncryptedValue: string
Ens: string
EvmAddress: string
Expand All @@ -45,11 +46,12 @@ config:
TxId: string
UnixTimestamp: string
URI: string
UUID: string
URL: string
Void: string

schema:
- https://api-v2-mumbai.lens.dev/graphql
- http://localhost:4000/graphql

generates:
src/graphql/generated.ts:
Expand Down
2 changes: 1 addition & 1 deletion packages/gated-content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"license": "MIT",
"dependencies": {
"@lens-protocol/metadata": "0.1.0-alpha.12",
"@lens-protocol/metadata": "0.1.0-alpha.13",
"@lens-protocol/shared-kernel": "workspace:*",
"@lens-protocol/storage": "workspace:*",
"@lit-protocol/constants": "2.1.62",
Expand Down
29 changes: 17 additions & 12 deletions packages/gated-content/src/GatedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export class GatedClient {
this.litClient = new NodeClient({ debug: false });
}

async encryptPublicationMetadata(
metadata: raw.PublicationMetadata,
async encryptPublicationMetadata<T extends raw.PublicationMetadata>(
metadata: T,
accessCondition: raw.AccessCondition,
): PromiseResult<raw.PublicationMetadata, never> {
): PromiseResult<T, never> {
await this.ensureLitConnection();

const cipher = await this.encryptionProvider.createCipher();
Expand All @@ -92,15 +92,20 @@ export class GatedClient {

const enc = new PublicationMetadataEncryptor(cipher);

const strategy: raw.LitEncryptionStrategy = {
encryptionKey,
accessCondition,
provider: raw.EncryptionProvider.LIT_PROTOCOL,
};

const encryptedMetadata = await enc.encrypt(metadata, strategy);

return success(encryptedMetadata);
const { encrypted, paths } = await enc.encrypt(metadata);

return success({
...encrypted,
lens: {
...encrypted.lens,
encryptedWith: {
encryptionKey,
accessCondition,
provider: raw.EncryptionProvider.LIT_PROTOCOL,
encryptedPaths: paths,
},
},
});
}

async decryptPublicationMetadataFragment(
Expand Down
1 change: 1 addition & 0 deletions packages/gated-content/src/__tests__/GatedClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe(`Given an instance of the ${GatedClient.name}`, () => {
content: encrypted.lens.content as string,
encryptedWith: gql.mockPublicationMetadataV3LitEncryption({
encryptionKey: encrypted.lens.encryptedWith?.encryptionKey,
encryptedPaths: encrypted.lens.encryptedWith?.encryptedPaths,
accessCondition: gql.mockOrCondition({
criteria: [
gql.mockProfileOwnershipCondition({ profileId: ownerId }),
Expand Down
Loading

0 comments on commit eb7f323

Please sign in to comment.