Skip to content

Commit c2cfb89

Browse files
authored
Merge pull request #687 from LIT-Protocol/LIT-3959-raw-wrapped-keys-litaction-functions
LIT-3959 - Export raw wrapped-keys LIT action functions
2 parents 2211187 + 141f0a0 commit c2cfb89

39 files changed

+468
-330
lines changed

packages/wrapped-keys-lit-actions/esbuild.config.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ module.exports = {
5050
(async () => {
5151
await esbuild.build({
5252
entryPoints: [
53-
'./src/lib/solana/signTransactionWithEncryptedSolanaKey.js',
54-
'./src/lib/solana/signMessageWithEncryptedSolanaKey.js',
55-
'./src/lib/solana/generateEncryptedSolanaPrivateKey.js',
56-
'./src/lib/ethereum/signTransactionWithEncryptedEthereumKey.js',
57-
'./src/lib/ethereum/signMessageWithEncryptedEthereumKey.js',
58-
'./src/lib/ethereum/generateEncryptedEthereumPrivateKey.js',
59-
'./src/lib/common/exportPrivateKey.js',
60-
'./src/lib/common/batchGenerateEncryptedKeys.js',
53+
'./src/lib/self-executing-actions/solana/signTransactionWithEncryptedSolanaKey.js',
54+
'./src/lib/self-executing-actions/solana/signMessageWithEncryptedSolanaKey.js',
55+
'./src/lib/self-executing-actions/solana/generateEncryptedSolanaPrivateKey.js',
56+
'./src/lib/self-executing-actions/ethereum/signTransactionWithEncryptedEthereumKey.js',
57+
'./src/lib/self-executing-actions/ethereum/signMessageWithEncryptedEthereumKey.js',
58+
'./src/lib/self-executing-actions/ethereum/generateEncryptedEthereumPrivateKey.js',
59+
'./src/lib/self-executing-actions/common/exportPrivateKey.js',
60+
'./src/lib/self-executing-actions/common/batchGenerateEncryptedKeys.js',
6161
],
6262
bundle: true,
6363
minify: true,

packages/wrapped-keys-lit-actions/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as signTransactionWithEthereumEncryptedKey from './generated/ethereum/s
66
import * as generateEncryptedSolanaPrivateKey from './generated/solana/generateEncryptedSolanaPrivateKey';
77
import * as signMessageWithSolanaEncryptedKey from './generated/solana/signMessageWithEncryptedSolanaKey';
88
import * as signTransactionWithSolanaEncryptedKey from './generated/solana/signTransactionWithEncryptedSolanaKey';
9+
import { rawActionFunctions } from './lib/raw-action-functions';
910

1011
import type {
1112
LitActionCodeRepository,
@@ -36,6 +37,10 @@ const litActionRepositoryCommon: LitActionCodeRepositoryCommon = {
3637
};
3738

3839
export {
40+
// Raw functions, <not wrapped in IIFEs>, for consumers to be able to compose these into their own LIT actions
41+
// Facilitates running e.g. `batchGenerateEncryptedKeys` using `Lit.Actions.runOnce` inside of another action
42+
rawActionFunctions,
43+
3944
// Individual exports to allow tree-shaking and only importing the lit actions you need
4045
batchGenerateEncryptedKeys,
4146
exportPrivateKey,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class AbortError extends Error {
2+
name = 'AbortError';
3+
}
4+
5+
export const rethrowIfAbortError = (err) => {
6+
if (err instanceof AbortError) {
7+
throw err;
8+
}
9+
};

packages/wrapped-keys-lit-actions/src/lib/common/exportPrivateKey.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

packages/wrapped-keys-lit-actions/src/lib/common/internal/getDecryptedKeyToSingleNode.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/wrapped-keys-lit-actions/src/lib/ethereum/generateEncryptedEthereumPrivateKey.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/wrapped-keys-lit-actions/src/lib/ethereum/signMessageWithEncryptedEthereumKey.js

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* global Lit */
2+
3+
import { AbortError } from '../../abortError';
4+
import { removeSaltFromDecryptedKey } from '../../utils';
5+
6+
async function tryDecryptToSingleNode({
7+
accessControlConditions,
8+
ciphertext,
9+
dataToEncryptHash,
10+
}) {
11+
try {
12+
// May be undefined, since we're using `decryptToSingleNode`
13+
return await Lit.Actions.decryptToSingleNode({
14+
accessControlConditions,
15+
ciphertext,
16+
dataToEncryptHash,
17+
chain: 'ethereum',
18+
authSig: null,
19+
});
20+
} catch (err) {
21+
throw new Error(`When decrypting key to a single node - ${err.message}`);
22+
}
23+
}
24+
25+
export async function getDecryptedKeyToSingleNode({
26+
accessControlConditions,
27+
ciphertext,
28+
dataToEncryptHash,
29+
}) {
30+
const decryptedPrivateKey = await tryDecryptToSingleNode({
31+
accessControlConditions,
32+
ciphertext,
33+
dataToEncryptHash,
34+
});
35+
36+
if (!decryptedPrivateKey) {
37+
// Silently exit on nodes which didn't run the `decryptToSingleNode` code
38+
throw new AbortError();
39+
}
40+
41+
return removeSaltFromDecryptedKey(decryptedPrivateKey);
42+
}

0 commit comments

Comments
 (0)