Skip to content

Commit

Permalink
Merge pull request #427 from LIT-Protocol/LIT-2841
Browse files Browse the repository at this point in the history
LIT-2841 - Remove `ipfs-http-client` and create encryption APIs for composition with any storage layer
  • Loading branch information
Ansonhkg authored Apr 18, 2024
2 parents 8efcb0f + 93cdeb3 commit 22293a2
Show file tree
Hide file tree
Showing 32 changed files with 446 additions and 1,120 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import path from 'path';
import * as LitJsSdk from '@lit-protocol/lit-node-client';
import { success, fail, testThis } from '../../tools/scripts/utils.mjs';
import { client } from '../00-setup.mjs';

export async function main() {
// ==================== Setup ====================
const chain = 'ethereum';
const accessControlConditions = [
{
contractAddress: '',
standardContractType: '',
chain,
method: 'eth_getBalance',
parameters: [':userAddress', 'latest'],
returnValueTest: {
comparator: '>=',
value: '0',
},
},
];
const message = 'Hello world';
const blob = new Blob([message], { type: 'text/plain' });
const blobArray = new Uint8Array(await blob.arrayBuffer());

// ==================== Test Logic ====================
const encryptedJsonStr = await LitJsSdk.encryptToJson({
accessControlConditions,
authSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
chain,
file: blob,
litNodeClient: client,
});

const decryptedFile = await LitJsSdk.decryptFromJson({
authSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
parsedJsonData: JSON.parse(encryptedJsonStr),
litNodeClient: client,
});

// ==================== Post-Validation ====================
if (blobArray.length !== decryptedFile.length) {
return fail(
`decrypted file should match the original file but received ${decryptedFile}`
);
}
for (let i = 0; i < blobArray.length; i++) {
if (blobArray[i] !== decryptedFile[i]) {
return fail(`decrypted file should match the original file`);
}
}

// ==================== Success ====================
return success('File was encrypted and then decrypted successfully');
}

await testThis({ name: path.basename(import.meta.url), fn: main });
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import path from 'path';
import * as LitJsSdk from '@lit-protocol/lit-node-client';
import { success, fail, testThis } from '../../tools/scripts/utils.mjs';
import { client } from '../00-setup.mjs';

export async function main() {
// ==================== Setup ====================
const chain = 'ethereum';
const accessControlConditions = [
{
contractAddress: '',
standardContractType: '',
chain,
method: 'eth_getBalance',
parameters: [':userAddress', 'latest'],
returnValueTest: {
comparator: '>=',
value: '0',
},
},
];
const message = 'Hello world';

// ==================== Test Logic ====================
const encryptedJsonStr = await LitJsSdk.encryptToJson({
accessControlConditions,
authSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
chain,
string: message,
litNodeClient: client,
});

const decryptedMessage = await LitJsSdk.decryptFromJson({
authSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
parsedJsonData: JSON.parse(encryptedJsonStr),
litNodeClient: client,
});

// ==================== Post-Validation ====================
if (message !== decryptedMessage) {
return fail(
`decryptedMessage should be ${message} but received ${decryptedMessage}`
);
}

// ==================== Success ====================
return success('Message was encrypted and then decrypted successfully');
}

await testThis({ name: path.basename(import.meta.url), fn: main });
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"commander": "^9.4.0",
"concurrently": "^7.4.0",
"core-js": "^3.6.5",
"cross-fetch": "^3.1.4",
"crypto-browserify": "^3.12.0",
"cypress-wait-until": "^1.7.2",
"cypress-watch-and-reload": "^1.10.3",
Expand All @@ -120,15 +121,12 @@
"find-config": "^1.0.0",
"g": "^2.0.1",
"https-browserify": "^1.0.0",
"ipfs-http-client": "56.0.0",
"ipfs-unixfs-importer": "^12.0.0",
"jose": "^4.14.4",
"jszip": "^3.10.1",
"micromodal": "^0.4.10",
"multiformats": "^9.7.1",
"nanoid": "3.3.4",
"next": "13.3.0",
"node-fetch": "^2.6.1",
"react": "18.0.0",
"react-dom": "18.0.0",
"regenerator-runtime": "0.13.7",
Expand All @@ -152,6 +150,8 @@
"@nx/jest": "17.3.0",
"@nx/js": "17.3.0",
"@nx/linter": "17.3.0",
"@nx/next": "17.3.0",
"@nx/node": "17.3.0",
"@nx/plugin": "17.3.0",
"@nx/react": "17.3.0",
"@nx/web": "17.3.0",
Expand Down Expand Up @@ -199,9 +199,7 @@
"ts-jest": "29.1.2",
"ts-node": "10.9.1",
"typedoc": "^0.23.10",
"typescript": "~4.7.2",
"@nx/next": "17.3.0",
"@nx/node": "17.3.0"
"typescript": "~4.7.2"
},
"workspaces": [
"packages/*"
Expand Down
4 changes: 0 additions & 4 deletions packages/auth-helpers/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// ----- autogen:polyfills:start -----
//
// ----- autogen:polyfills:end -----

export * from './lib/models';
export * from './lib/session-capability-object';
export * from './lib/resources';
Expand Down
8 changes: 0 additions & 8 deletions packages/contracts-sdk/polyfills.js

This file was deleted.

4 changes: 0 additions & 4 deletions packages/contracts-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
export * from './lib/contracts-sdk';
export * from './lib/addresses';
export * from './lib/utils';

// ----- autogen:polyfills:start -----
//
// ----- autogen:polyfills:end -----
Loading

0 comments on commit 22293a2

Please sign in to comment.