-
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
Changes from all commits
20caa66
b78a54e
b704210
53bf8c2
a9689c8
3a93825
fc797d1
bd24619
c211e59
ea8d913
f80ef12
a5f2604
34ab5b8
88a18c2
6c37c93
451f906
4971a20
b728850
81c3a72
f8dc375
141f0a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export class AbortError extends Error { | ||
| name = 'AbortError'; | ||
| } | ||
|
|
||
| export const rethrowIfAbortError = (err) => { | ||
| if (err instanceof AbortError) { | ||
| throw err; | ||
| } | ||
| }; | ||
|
Comment on lines
+1
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be moved to Might be a long shot, because nodes are in the middle, but we can think of shared errors between SDK and LAs |
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* global Lit */ | ||
|
|
||
| import { AbortError } from '../../abortError'; | ||
| import { removeSaltFromDecryptedKey } from '../../utils'; | ||
|
|
||
| async function tryDecryptToSingleNode({ | ||
| accessControlConditions, | ||
| ciphertext, | ||
| dataToEncryptHash, | ||
| }) { | ||
| try { | ||
| // May be undefined, since we're using `decryptToSingleNode` | ||
| return await Lit.Actions.decryptToSingleNode({ | ||
| accessControlConditions, | ||
| ciphertext, | ||
| dataToEncryptHash, | ||
| chain: 'ethereum', | ||
| authSig: null, | ||
| }); | ||
| } catch (err) { | ||
| throw new Error(`When decrypting key to a single node - ${err.message}`); | ||
| } | ||
| } | ||
|
|
||
| export async function getDecryptedKeyToSingleNode({ | ||
| accessControlConditions, | ||
| ciphertext, | ||
| dataToEncryptHash, | ||
| }) { | ||
| const decryptedPrivateKey = await tryDecryptToSingleNode({ | ||
| accessControlConditions, | ||
| ciphertext, | ||
| dataToEncryptHash, | ||
| }); | ||
|
|
||
| if (!decryptedPrivateKey) { | ||
| // Silently exit on nodes which didn't run the `decryptToSingleNode` code | ||
| throw new AbortError(); | ||
| } | ||
|
|
||
| return removeSaltFromDecryptedKey(decryptedPrivateKey); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* global Lit */ | ||
|
|
||
| import { AbortError } from './abortError'; | ||
|
|
||
| export async function litActionHandler(actionFunc) { | ||
| try { | ||
| const litActionResult = await actionFunc(); | ||
| // Don't re-stringify a string; we don't want to double-escape it | ||
| const response = | ||
| typeof litActionResult === 'string' | ||
| ? litActionResult | ||
| : JSON.stringify(litActionResult); | ||
|
|
||
| Lit.Actions.setResponse({ response }); | ||
| } catch (err) { | ||
| // AbortError means exit immediately and do _NOT_ set a response | ||
| // Nested code should really only throw this in cases where using e.g. `decryptToSingleNode` | ||
| // And this execution isn't that node. | ||
| if (err instanceof AbortError) { | ||
| return; | ||
| } | ||
|
|
||
| Lit.Actions.setResponse({ response: `Error: ${err.message}` }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| const { | ||
| getDecryptedKeyToSingleNode, | ||
| } = require('../../internal/common/getDecryptedKeyToSingleNode'); | ||
|
|
||
| /** | ||
| * | ||
| * Exports the private key after decrypting and removing the salt from it. | ||
| * | ||
| * @jsParam pkpAddress - The Eth address of the PKP which is associated with the Wrapped Key | ||
| * @jsParam ciphertext - For the encrypted Wrapped Key | ||
| * @jsParam dataToEncryptHash - For the encrypted Wrapped Key | ||
| * @jsParam accessControlConditions - The access control condition that allows only the pkpAddress to decrypt the Wrapped Key | ||
| * | ||
| * @returns { Promise<string> } - Returns a decrypted private key. | ||
| */ | ||
|
|
||
| export async function exportPrivateKey({ | ||
| accessControlConditions, | ||
| ciphertext, | ||
| dataToEncryptHash, | ||
| }) { | ||
| return getDecryptedKeyToSingleNode({ | ||
| accessControlConditions, | ||
| ciphertext, | ||
| dataToEncryptHash, | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /** | ||
| * | ||
| * Generates a random Ethers private key and only allows the provided PKP to decrypt it | ||
| * | ||
| * @jsParam pkpAddress - The Eth address of the PKP which is associated with the Wrapped Key | ||
| * @jsParam accessControlConditions - The access control condition that allows only the pkpAddress to decrypt the Wrapped Key | ||
| * | ||
| * @returns { Promise<{ciphertext: string, dataToEncryptHash: string, publicKey: string}> } - Returns object with ciphertext & dataToEncryptHash which are the result of the encryption. Also returns the publicKey of the newly generated Ethers Wrapped Key. | ||
| */ | ||
| import { encryptPrivateKey } from '../../internal/common/encryptKey'; | ||
| import { generateEthereumPrivateKey } from '../../internal/ethereum/generatePrivateKey'; | ||
|
|
||
| export async function generateEncryptedEthereumPrivateKey({ | ||
| accessControlConditions, | ||
| }) { | ||
| const { privateKey, publicKey } = generateEthereumPrivateKey(); | ||
| return encryptPrivateKey({ | ||
| accessControlConditions, | ||
| privateKey, | ||
| publicKey, | ||
| }); | ||
| } |
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