-
Notifications
You must be signed in to change notification settings - Fork 88
feat: add types and convert lit actions to typescripts #699
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
Ansonhkg
merged 15 commits into
master
from
feat/convert-wrapped-keys-lit-actions-to-ts
Oct 23, 2024
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
faa4c69
feat: add types and convert lit actions to typescripts
Ansonhkg b6f004d
feat: declare global variables
Ansonhkg 94329e7
fix: type
Ansonhkg 2092f20
fml
Ansonhkg 8c8c8c8
feat: show the size of the bundle files
Ansonhkg 985e069
feat: import `ethers` to lit actions BUT making it `external` in esBu…
Ansonhkg a41448e
trigger my lost changes
Ansonhkg 828a72c
doc: add comment
Ansonhkg 4ff536f
fmt
Ansonhkg 809dd4e
Update packages/wrapped-keys-lit-actions/tsconfig.json
Ansonhkg 55339ec
fix: https://github.com/LIT-Protocol/js-sdk/pull/699#issuecomment-242…
Ansonhkg 52fffc9
fix: Use global.d.ts to define `ethers` existence globally
MaximusHaximus 15523a8
fix: Use local declarations instead of `declare global {}` in module …
MaximusHaximus 45e19d7
types: Replace `any` types with more explicit typing
MaximusHaximus 73c25e2
chore: Remove accidental 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
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...ed-keys-lit-actions/src/lib/abortError.js → ...ed-keys-lit-actions/src/lib/abortError.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
File renamed without changes.
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
File renamed without changes.
39 changes: 0 additions & 39 deletions
39
packages/wrapped-keys-lit-actions/src/lib/internal/ethereum/signMessage.js
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
packages/wrapped-keys-lit-actions/src/lib/internal/ethereum/signMessage.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,60 @@ | ||
| /* global ethers */ | ||
|
|
||
| interface SignMessageParams { | ||
| privateKey: string; | ||
| messageToSign: string; | ||
| } | ||
|
|
||
| interface VerifyMessageSignatureParams { | ||
| messageToSign: string; | ||
| signature: string; | ||
| } | ||
|
|
||
| async function signMessage({ | ||
| privateKey, | ||
| messageToSign, | ||
| }: SignMessageParams): Promise<{ signature: string; walletAddress: string }> { | ||
| try { | ||
| const wallet = new ethers.Wallet(privateKey); | ||
| const signature = await wallet.signMessage(messageToSign); | ||
|
|
||
| return { signature, walletAddress: wallet.address }; | ||
| } catch (err: unknown) { | ||
| throw new Error(`When signing message - ${(err as Error).message}`); | ||
| } | ||
| } | ||
|
|
||
| function verifyMessageSignature({ | ||
| messageToSign, | ||
| signature, | ||
| }: VerifyMessageSignatureParams): string { | ||
| try { | ||
| return ethers.utils.verifyMessage(messageToSign, signature); | ||
| } catch (err: unknown) { | ||
| throw new Error( | ||
| `When validating signed Ethereum message is valid: ${ | ||
| (err as Error).message | ||
| }` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export async function signMessageEthereumKey({ | ||
| privateKey, | ||
| messageToSign, | ||
| }: SignMessageParams): Promise<string> { | ||
| const { signature, walletAddress } = await signMessage({ | ||
| privateKey, | ||
| messageToSign, | ||
| }); | ||
|
|
||
| const recoveredAddress = verifyMessageSignature({ messageToSign, signature }); | ||
|
|
||
| if (recoveredAddress !== walletAddress) { | ||
| throw new Error( | ||
| "Recovered address from verifyMessage doesn't match the wallet address" | ||
| ); | ||
| } | ||
|
|
||
| return signature; | ||
| } | ||
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
File renamed without changes.
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.