-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from LIT-Protocol/LIT-2841
LIT-2841 - Remove `ipfs-http-client` and create encryption APIs for composition with any storage layer
- Loading branch information
Showing
32 changed files
with
446 additions
and
1,120 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
e2e-nodejs/group-pkp-encryption-decryption/test-pkp-encryption-decryption-json-file.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |
50 changes: 50 additions & 0 deletions
50
e2e-nodejs/group-pkp-encryption-decryption/test-pkp-encryption-decryption-json-string.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ----- |
Oops, something went wrong.