-
Notifications
You must be signed in to change notification settings - Fork 88
LIT-3956 - wrapped-keys - Allow batch of keys to be stored atomically (storeEncryptedKeyBatch) #686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
27c0844
feat(wrapped-keys): LIT-3956 - Initial implementation of new `storeEn…
MaximusHaximus 85495f6
feat(wrapped-keys): LIT-3956 - Use new service method `storePrivateKe…
MaximusHaximus d16efa9
feat(wrapped-keys): LIT-3956 - Update URL for storePrivateKeyBatch to…
MaximusHaximus ff03458
test(wrapped-keys): LIT-3956 - Add `testFailStoreEncryptedKeyBatchIsA…
MaximusHaximus ccff8a9
feat(wrapped-keys): LIT-3956 - Fix encapsulation of `getPkpAddressFro…
MaximusHaximus f777a7e
chore(wrapped-keys): LIT-3956 - Fix comment
MaximusHaximus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
3 changes: 1 addition & 2 deletions
3
local-tests/tests/wrapped-keys/testFailEthereumSignTransactionWrappedKeyInvalidDecryption.ts
This file contains hidden or 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
130 changes: 130 additions & 0 deletions
130
local-tests/tests/wrapped-keys/testFailStoreEncryptedKeyBatchIsAtomic.ts
This file contains hidden or 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,130 @@ | ||
| import { log } from '@lit-protocol/misc'; | ||
| import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; | ||
| import { api } from '@lit-protocol/wrapped-keys'; | ||
| import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; | ||
| import { batchGenerateKeysWithLitAction } from '../../../packages/wrapped-keys/src/lib/lit-actions-client'; | ||
| import { getLitActionCodeOrCidCommon } from '../../../packages/wrapped-keys/src/lib/lit-actions-client/utils'; | ||
| import { | ||
| getFirstSessionSig, | ||
| getKeyTypeFromNetwork, | ||
| getPkpAccessControlCondition, | ||
| getPkpAddressFromSessionSig, | ||
| } from '../../../packages/wrapped-keys/src/lib/api/utils'; | ||
| import { listEncryptedKeyMetadata } from '../../../packages/wrapped-keys/src/lib/api'; | ||
|
|
||
| const { storeEncryptedKeyBatch } = api; | ||
|
|
||
| /** | ||
| * Test Commands: | ||
| * ✅ NETWORK=datil-dev yarn test:local --filter=testSignMessageWithSolanaEncryptedKey | ||
| * ✅ NETWORK=datil-test yarn test:local --filter=testSignMessageWithSolanaEncryptedKey | ||
| * ✅ NETWORK=localchain yarn test:local --filter=testSignMessageWithSolanaEncryptedKey | ||
| */ | ||
| export const testFailBatchGeneratePrivateKeysAtomic = async ( | ||
| devEnv: TinnyEnvironment | ||
| ) => { | ||
| const alice = await devEnv.createRandomPerson(); | ||
|
|
||
| try { | ||
| const pkpSessionSigsSigning = await getPkpSessionSigs( | ||
| devEnv, | ||
| alice, | ||
| null, | ||
| new Date(Date.now() + 1000 * 60 * 10).toISOString() | ||
| ); // 10 mins expiry | ||
|
|
||
| const solanaMessageToSign = 'This is a test solana message'; | ||
| const evmMessageToSign = 'This is a test evm message'; | ||
|
|
||
| const sessionSig = getFirstSessionSig(pkpSessionSigsSigning); | ||
| const pkpAddress = getPkpAddressFromSessionSig(sessionSig); | ||
|
|
||
| const allowPkpAddressToDecrypt = getPkpAccessControlCondition(pkpAddress); | ||
|
|
||
| const { litActionCode, litActionIpfsCid } = getLitActionCodeOrCidCommon( | ||
| 'batchGenerateEncryptedKeys' | ||
| ); | ||
|
|
||
| const actionResults = await batchGenerateKeysWithLitAction({ | ||
| litNodeClient: devEnv.litNodeClient, | ||
| litActionIpfsCid: litActionCode ? undefined : litActionIpfsCid, | ||
| litActionCode: litActionCode ? litActionCode : undefined, | ||
| accessControlConditions: [allowPkpAddressToDecrypt], | ||
| actions: [ | ||
| { | ||
| network: 'evm', | ||
| signMessageParams: { messageToSign: evmMessageToSign }, | ||
| generateKeyParams: { memo: 'Test evm key' }, | ||
| }, | ||
| { | ||
| network: 'solana', | ||
| signMessageParams: { messageToSign: solanaMessageToSign }, | ||
| generateKeyParams: { memo: 'Test solana key' }, | ||
| }, | ||
| ], | ||
| pkpSessionSigs: pkpSessionSigsSigning, | ||
| }); | ||
|
|
||
| const keyParamsBatch = actionResults.map((keyData) => { | ||
| const { generateEncryptedPrivateKey, network } = keyData; | ||
| return { | ||
| ...generateEncryptedPrivateKey, | ||
| keyType: getKeyTypeFromNetwork(network), | ||
| }; | ||
| }); | ||
|
|
||
| // Intentional failure to persist due to missing publicKey | ||
| delete keyParamsBatch[0].publicKey; | ||
|
|
||
| try { | ||
| await storeEncryptedKeyBatch({ | ||
| pkpSessionSigs: pkpSessionSigsSigning, | ||
| litNodeClient: devEnv.litNodeClient, | ||
| keyBatch: keyParamsBatch, | ||
| }); | ||
|
|
||
| throw new Error( | ||
| 'storeEncryptedKeyBatch() succeeded but we expected it to fail!' | ||
| ); | ||
| } catch (err) { | ||
| // We expect `storeEncryptedKeyBatch` to fail w/ a specific error | ||
| if ( | ||
| err.message.includes( | ||
| 'storeEncryptedKeyBatch() succeeded but we expected it to fail!' | ||
| ) || | ||
| !err.message.includes( | ||
| 'keyParamsBatch[0]: Missing "publicKey" parameter in request' | ||
| ) | ||
| ) { | ||
| throw err; | ||
| } | ||
|
|
||
| try { | ||
| const keys = await listEncryptedKeyMetadata({ | ||
| litNodeClient: devEnv.litNodeClient, | ||
| pkpSessionSigs: pkpSessionSigsSigning, | ||
| }); | ||
|
|
||
| console.error( | ||
| 'Got a value back we shouldnt have from listEncryptedKeyMetadata()', | ||
| keys | ||
| ); | ||
|
|
||
| throw new Error( | ||
| 'Expected `listEncryptedKeyMetadata() to fail, but it didnt!`' | ||
| ); | ||
| } catch (err) { | ||
| if (err.message.includes('No keys exist for pkpAddress')) { | ||
| log('✅ testFailBatchGeneratePrivateKeysAtomic'); | ||
| } else { | ||
| throw err; | ||
| } | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.log(err.message, err, err.stack); | ||
| throw err; | ||
| } finally { | ||
| devEnv.releasePrivateKeyFromUser(alice); | ||
| } | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.