-
Notifications
You must be signed in to change notification settings - Fork 88
LIT-3959 - Export raw wrapped-keys LIT action functions #687
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
LIT-3959 - Export raw wrapped-keys LIT action functions #687
Conversation
| "types": [], | ||
| "allowJs": true, | ||
| "checkJs": true | ||
| "checkJs": false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this because typechecking on the .js files was failing. We should really convert this entire package to TS ASAP.
…layout to make file purposes explicit from their location in the package
…EncryptedKeys` from IIFE
…ptedEthereumPrivateKey` from IIFE
…thEncryptedEthereumKey` from IIFE
…onWithEncryptedEthereumKey` from IIFE
…ptedSolanaPrivateKey` from IIFE
…thEncryptedSolanaKey` from IIFE
…onWithEncryptedSolanaKey` from IIFE
…onHandler function definitions
…ngleNode() to throw `AbortError` and perform removal of salt before returning a value to callers
…ptedSolanaPrivateKey() to leverage litActionHandler()
…onWithEncryptedSolanaKey() to leverage litActionHandler() and to be aware of new getDecryptedKeyToSingleNode() behaviour
…thEncryptedSolanaKey() to leverage litActionHandler() and to be aware of new getDecryptedKeyToSingleNode() behaviour
…ptedEthereumPrivateKey() to leverage litActionHandler()
…thEncryptedEthereumKey() to leverage litActionHandler() and to be aware of new getDecryptedKeyToSingleNode() behaviour - Also removed unused imports in signMessageWithEncryptedSolanaKey
…onWithEncryptedEthereumKey() to leverage litActionHandler() and to be aware of new getDecryptedKeyToSingleNode() behaviour
…Key() to leverage litActionHandler() and to be aware of new getDecryptedKeyToSingleNode() behaviour
…EncryptedKeys() to leverage litActionHandler()
…tions from `wrapped-keys-lit-actions` package to allow composition into other actions
…ot escaped using JSON.stringify() in `litActionHandler()`
1c643e0 to
141f0a0
Compare
Ansonhkg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like writing Lit Action just like regular code! Let's have a follow up PR to support Typescript & Type definitions for Lit.Actions & Lit.Auth
|
FedericoAmura
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really like this new approach. Once we have the Lit namespaces mocked all this becomes testeable
| './src/lib/self-executing-actions/solana/signTransactionWithEncryptedSolanaKey.js', | ||
| './src/lib/self-executing-actions/solana/signMessageWithEncryptedSolanaKey.js', | ||
| './src/lib/self-executing-actions/solana/generateEncryptedSolanaPrivateKey.js', | ||
| './src/lib/self-executing-actions/ethereum/signTransactionWithEncryptedEthereumKey.js', | ||
| './src/lib/self-executing-actions/ethereum/signMessageWithEncryptedEthereumKey.js', | ||
| './src/lib/self-executing-actions/ethereum/generateEncryptedEthereumPrivateKey.js', | ||
| './src/lib/self-executing-actions/common/exportPrivateKey.js', | ||
| './src/lib/self-executing-actions/common/batchGenerateEncryptedKeys.js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "self-executing-actions" makes me think of a cron of that they don't have to be triggered
| export class AbortError extends Error { | ||
| name = 'AbortError'; | ||
| } | ||
|
|
||
| export const rethrowIfAbortError = (err) => { | ||
| if (err instanceof AbortError) { | ||
| throw err; | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved to errors.ts in constants in v7. As followup
Might be a long shot, because nodes are in the middle, but we can think of shared errors between SDK and LAs
|
nit: i think we should re-name |
Description
NOTE: Because this PR includes moving code around and modifying it, it is likely easiest to review it commit-by-commit.
Our
wrapped-keys-lit-actionspackage currently only exports IIFE-wrapped, bundled code as strings.In order to allow composition of the logic these LIT actions provides into other LIT Actions (for example, to embed generated wrapped keys in session sig generation), we need to export the LIT action functions themselves.
This PR refactors the
wrapped-keys-lit-actionspackage to facilitate this functionality in a non-breaking way for existing consumers of the package.Note that it wasn't quite as simple as 'unwrap the IIFE and export the function' because the existing LIT actions called Lit.Actions.setResponse() -- and if they were to be composed into any other LIT actions, this would be undesirable behaviour.
To handle this situation, I extracted all usage of
Lit.Actions.setResponseinto alitActionHandlerfunction, and modified the LIT action functions to always return -- which they need to if they are to be executed by another LIT action as aLit.Action.runOncetarget.I think this structure for code is a good best-practice pattern to generally follow when writing LA...
handleLitAction()to handle setResponse calls from the LIT action code it callsreturns orthrows -- like normal JS ;)- If child logic inside of a 'raw' LA function stack needs to do the equivalent of an 'early' setResponse(); return , e.g. in order to break out if somethin'g using decryptToSingleNode() and this node isn't that one, then we throw a specific type of error -- an
AbortError, defined in this PR, that thelitActionHandler()function knows should be caught, andreturnimmediately without calling setResponse SeegetDecryptedKeyToSingleNode()to see this in action.This pattern will encourage developers to encapsulate all of their LA coding like a 'standard' app, and leave calling
setResponseto the root IIFE that useslitActionHandler. In short, callingsetReponse()thenreturnis an anti-pattern that requires LA code is completely flat; as soon as you want to nest any code in sub-functions, it breaks down.I think we should ship this root handler function and the
AbortErrortype somewhere thejs-sdk, so devs don't have to write the boilerplate themselves and we show them the happy path to keeping code that is destined for LIT actions looking similar to code that they would write anywhere else.Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: