Skip to content

Commit

Permalink
Added support for custom access control conditions for posts
Browse files Browse the repository at this point in the history
  • Loading branch information
baptistegreve committed Sep 19, 2022
1 parent 6f1c89b commit 1c82c55
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,13 @@ export class Orbis {

/** Check if posts should be encrypted */
let _encryptedContent;
if(encryptionRules) {
if(encryptionRules && encryptionRules.type) {

try {
_encryptedContent = await encryptPost(encryptionRules, content.body);
/** Encrypt the content */
_encryptedContent = await encryptPost(content.body, encryptionRules);

/** Save encrypted content in `content` object to be stored in Ceramic */
content.encryptedBody = _encryptedContent;
content.body = "";
} catch(e) {
Expand Down Expand Up @@ -553,7 +557,10 @@ export class Orbis {
let _encryptedContent;
if(encryptionRules) {
try {
_encryptedContent = await encryptPost(encryptionRules, content.body);
/** Encrypt the content */
_encryptedContent = await encryptPost(content.body, encryptionRules);

/** Save encrypted content in `content` object to be stored in Ceramic */
content.encryptedBody = _encryptedContent;
content.body = "";
} catch(e) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orbisclub/orbis-sdk",
"version": "0.3.41",
"version": "0.3.42",
"description": "Official package to implement quickly an Orbis powered decentralized social layer within your application.",
"author": "Baptiste Grève",
"license": "ISC",
Expand Down
25 changes: 21 additions & 4 deletions utils/lit-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,28 @@ export async function encryptDM(recipients, body) {
}

/** Encrypt post based on the encryptionRules added by the user */
export async function encryptPost(encryptionRules, body) {
/** Step 1: Retrieve access control conditions from recipients */
let accessControlConditions = generateAccessControlConditionsForPosts(encryptionRules);
export async function encryptPost(body, encryptionRules) {
/**
* Step 1:
* Retrieve access control conditions based on the encryptionRules are used custom conditions
* passed as a parameter
*/
let accessControlConditions;
if(encryptionRules && encryptionRules.accessControlConditions) {
accessControlConditions = encryptionRules.accessControlConditions;
} else {
accessControlConditions = generateAccessControlConditionsForPosts(encryptionRules);
}

/** Step 2: Encrypt string and return result */
/** Step 2: Check if accessControlConditions are valid */
if(!accessControlConditions) {
return {
status: 300,
result: "You must use valid access control conditions to encrypt posts."
}
}

/** Step 3: Encrypt string and return result */
try {
let result = await encryptString(accessControlConditions, body);
return result
Expand Down

0 comments on commit 1c82c55

Please sign in to comment.