Skip to content

Commit

Permalink
Merge pull request #25 from lighthouse-web3/staging
Browse files Browse the repository at this point in the history
Code refactoring
  • Loading branch information
ravish1729 authored Jul 16, 2024
2 parents ec3d0d7 + 1d5ed97 commit 7ca7d61
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lighthouse-web3/kavach",
"version": "0.1.8",
"version": "0.1.9",
"description": "Encryption SDK: Build your trustless, decentralized and fault resistance Application using distributed key shades with threshold cryptography",
"author": "xlassix",
"main": "./dist/methods/index.js",
Expand Down
2 changes: 1 addition & 1 deletion readme.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Kavach <img src="https://img.shields.io/badge/BETA-v0.1.8-green"/>
# Kavach <img src="https://img.shields.io/badge/BETA-v0.1.9-green"/>

Kavach is an encryption SDK that allows you to build your trustless, decentralized and fault-tolerant Applications using distributed key shards with threshold cryptography

Expand Down
4 changes: 2 additions & 2 deletions src/methods/accessControl/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ const updateConditionSchema = Joi.object({
.allow("", null)
.empty(["", null])
.default("EVM")
.valid("EVM", "SOLANA")
.valid("EVM", "SOLANA", "COREUM")
.insensitive(),
conditions: Joi.when("chainType", {
is: Joi.equal("EVM"),
Expand Down Expand Up @@ -254,7 +254,7 @@ const accessConditionSchema = Joi.object({
.allow("", null)
.empty(["", null])
.default("EVM")
.valid("EVM", "SOLANA")
.valid("EVM", "SOLANA", "COREUM")
.insensitive(),
decryptionType: Joi.string()
.allow("", null)
Expand Down
29 changes: 23 additions & 6 deletions src/methods/revokeAccess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,32 @@ export const revokeAccess = async (
const nodeUrl = nodeId.map((elem) => `/api/setSharedKey/${elem}`);

// send encryption key
const data = await Promise.all(
nodeUrl.map((url) => {
return API_NODE_HANDLER(url, "DELETE", auth_token, {
const requestData = async (url: any) => {
try {
const response = await API_NODE_HANDLER(url, "DELETE", auth_token, {
address,
cid,
revokeTo,
});
})
);
return response;
} catch (error: any) {
return {
error,
};
}
};
const data = [];
for (const [index, url] of nodeUrl.entries()) {
const response = await requestData(url);
if (response.error) {
return {
isSuccess: false,
error: JSON.parse(response?.error?.message),
};
}
await new Promise((resolve) => setTimeout(resolve, 1000));
data.push(response);
}
const temp = data.map((elem, index) => ({ ...elem, data: null }));
return {
isSuccess: isEqual(...temp),
Expand All @@ -36,7 +53,7 @@ export const revokeAccess = async (
} catch (err: any) {
return {
isSuccess: false,
error: JSON.parse(err?.message),
error: err,
};
}
};
29 changes: 23 additions & 6 deletions src/methods/shareToAddress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,32 @@ export const shareToAddress = async (
const nodeId = [1, 2, 3, 4, 5];
const nodeUrl = nodeId.map((elem) => `/api/setSharedKey/${elem}`);
// send encryption key
const data = await Promise.all(
nodeUrl.map((url) => {
return API_NODE_HANDLER(url, "PUT", auth_token, {
const requestData = async (url: any) => {
try {
const response = await API_NODE_HANDLER(url, "PUT", auth_token, {
address,
cid: cid,
shareTo,
});
})
);
return response;
} catch (error: any) {
return {
error,
};
}
};
const data = [];
for (const [index, url] of nodeUrl.entries()) {
const response = await requestData(url);
if (response.error) {
return {
isSuccess: false,
error: JSON.parse(response?.error?.message),
};
}
await new Promise((resolve) => setTimeout(resolve, 1000));
data.push(response);
}
const temp = data.map((elem, index) => ({ ...elem, data: null }));
return {
isSuccess: isEqual(...temp) && temp[0]?.message === "success",
Expand All @@ -35,7 +52,7 @@ export const shareToAddress = async (
} catch (err: any) {
return {
isSuccess: false,
error: JSON.parse(err.message),
error: err,
};
}
};
29 changes: 23 additions & 6 deletions src/methods/transferOwnership/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,41 @@ export const transferOwnership = async (
(elem) => `/api/transferOwnership/${elem}`
);
// send encryption key
const data = await Promise.all(
nodeUrl.map((url) => {
return API_NODE_HANDLER(url, "POST", auth_token, {
const requestData = async (url: any) => {
try {
const response = await API_NODE_HANDLER(url, "POST", auth_token, {
address,
cid,
newOwner,
resetSharedTo,
});
})
);
return response;
} catch (error: any) {
return {
error,
};
}
};
const data = [];
for (const [index, url] of nodeUrl.entries()) {
const response = await requestData(url);
if (response.error) {
return {
isSuccess: false,
error: JSON.parse(response?.error?.message),
};
}
await new Promise((resolve) => setTimeout(resolve, 1000));
data.push(response);
}
return {
isSuccess: isEqual(...data) && data[0]?.message === "success",
error: null,
};
} catch (err: any) {
return {
isSuccess: false,
error: JSON.parse(err.message),
error: err,
};
}
};

0 comments on commit 7ca7d61

Please sign in to comment.