Skip to content

Commit 1d08f1e

Browse files
authored
Merge branch 'LIT-3920-batchGeneratePrivateKeys' into feature/lit-3945-js-sdk-add-sendtosinglenode-feature
2 parents 6a53064 + 53c67c2 commit 1d08f1e

File tree

6 files changed

+32
-42
lines changed

6 files changed

+32
-42
lines changed

local-tests/tests/wrapped-keys/testBatchGeneratePrivateKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const testBatchGeneratePrivateKeys = async (
9494
const solanaMessageToSign = 'This is a test solana message';
9595
const evmMessageToSign = 'This is a test evm message';
9696
const results = await batchGeneratePrivateKeys({
97+
const { results } = await batchGeneratePrivateKeys({
9798
pkpSessionSigs: pkpSessionSigsSigning,
9899
actions: [
99100
{

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

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,11 @@ async function processEthereumAction(action, ndx) {
1717
const ethereumKey = generateEthereumPrivateKey();
1818

1919
const [generatedPrivateKey, messageSignature] = await Promise.all([
20-
Lit.Actions.runOnce(
21-
{ waitForResponse: true, name: `encryptEthereumPrivateKey_${ndx}` },
22-
async () =>
23-
JSON.stringify(
24-
await encryptPrivateKey({
25-
accessControlConditions,
26-
publicKey: ethereumKey.publicKey,
27-
privateKey: ethereumKey.privateKey,
28-
})
29-
)
30-
),
20+
encryptPrivateKey({
21+
accessControlConditions,
22+
publicKey: ethereumKey.publicKey,
23+
privateKey: ethereumKey.privateKey,
24+
}),
3125
messageToSign
3226
? signMessageEthereumKey({
3327
messageToSign: messageToSign,
@@ -39,7 +33,7 @@ async function processEthereumAction(action, ndx) {
3933
return {
4034
network,
4135
generatedPrivateKey: {
42-
...JSON.parse(generatedPrivateKey),
36+
...generatedPrivateKey,
4337
memo: generateKeyParams.memo,
4438
},
4539
...(messageSignature
@@ -56,17 +50,11 @@ async function processSolanaAction(action, ndx) {
5650
const solanaKey = generateSolanaPrivateKey();
5751

5852
const [generatedPrivateKey, messageSignature] = await Promise.all([
59-
Lit.Actions.runOnce(
60-
{ waitForResponse: true, name: `encryptSolanaPrivateKey_${ndx}` },
61-
async () =>
62-
JSON.stringify(
63-
await encryptPrivateKey({
64-
accessControlConditions,
65-
publicKey: solanaKey.publicKey,
66-
privateKey: solanaKey.privateKey,
67-
})
68-
)
69-
),
53+
encryptPrivateKey({
54+
accessControlConditions,
55+
publicKey: solanaKey.publicKey,
56+
privateKey: solanaKey.privateKey,
57+
}),
7058
messageToSign
7159
? signMessageSolanaKey({
7260
messageToSign: messageToSign,
@@ -78,7 +66,7 @@ async function processSolanaAction(action, ndx) {
7866
return {
7967
network,
8068
generatedPrivateKey: {
81-
...JSON.parse(generatedPrivateKey),
69+
...generatedPrivateKey,
8270
memo: generateKeyParams.memo,
8371
},
8472
...(messageSignature
@@ -144,13 +132,10 @@ function validateParams(actions) {
144132
try {
145133
validateParams(actions);
146134

147-
const batchGeneratePrivateKeysActionResult = await Lit.Actions.runOnce(
148-
{ waitForResponse: true, name: `processActions` },
149-
async () => JSON.stringify(await processActions(actions))
150-
);
135+
const batchGeneratePrivateKeysActionResult = await processActions(actions);
151136

152137
Lit.Actions.setResponse({
153-
response: batchGeneratePrivateKeysActionResult,
138+
response: JSON.stringify(batchGeneratePrivateKeysActionResult),
154139
});
155140

156141
// 1. Generate both EVM and solana private keys

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ import { generateEthereumPrivateKey } from './internal/generatePrivateKey';
1313
import { encryptPrivateKey } from '../common/internal/encryptKey';
1414

1515
(async () => {
16-
const { privateKey, publicKey } = generateEthereumPrivateKey();
17-
1816
const encryptedKeyResultStr = await Lit.Actions.runOnce(
1917
{ waitForResponse: true, name: 'encryptEthereumPrivateKey' },
20-
async () =>
21-
JSON.stringify(
18+
async () => {
19+
const { privateKey, publicKey } = generateEthereumPrivateKey();
20+
return JSON.stringify(
2221
await encryptPrivateKey({
2322
accessControlConditions,
2423
privateKey,
2524
publicKey,
2625
})
27-
)
26+
);
27+
}
2828
);
2929

3030
Lit.Actions.setResponse({

packages/wrapped-keys-lit-actions/src/lib/solana/generateEncryptedSolanaPrivateKey.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ const { encryptPrivateKey } = require('../common/internal/encryptKey');
1212
* @returns { Promise<string> } - Returns a stringified JSON object with ciphertext & dataToEncryptHash which are the result of the encryption. Also returns the publicKey of the newly generated Solana Wrapped Key.
1313
*/
1414
(async () => {
15-
const { privateKey, publicKey } = generateSolanaPrivateKey();
16-
1715
const encryptedKeyResultStr = await Lit.Actions.runOnce(
1816
{ waitForResponse: true, name: 'encryptSolanaPrivateKey' },
19-
async () =>
20-
JSON.stringify(
17+
async () => {
18+
const { privateKey, publicKey } = generateSolanaPrivateKey();
19+
return JSON.stringify(
2120
await encryptPrivateKey({
2221
accessControlConditions,
2322
publicKey,
2423
privateKey,
2524
})
26-
)
25+
);
26+
}
2727
);
2828

2929
Lit.Actions.setResponse({

packages/wrapped-keys/src/lib/api/batch-generate-private-keys.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function batchGeneratePrivateKeys(
4141
pkpSessionSigs,
4242
});
4343

44-
return Promise.all(
44+
const results = await Promise.all(
4545
actionResults.map(
4646
async (result): Promise<BatchGeneratePrivateKeysActionResult> => {
4747
const { generatedPrivateKey, network } = result;
@@ -70,4 +70,6 @@ export async function batchGeneratePrivateKeys(
7070
}
7171
)
7272
);
73+
74+
return { pkpAddress, results };
7375
}

packages/wrapped-keys/src/lib/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ export interface BatchGeneratePrivateKeysActionResult {
157157
signedMessage?: { signature: string };
158158
}
159159

160-
export type BatchGeneratePrivateKeysResult =
161-
BatchGeneratePrivateKeysActionResult[];
160+
export interface BatchGeneratePrivateKeysResult {
161+
pkpAddress: string;
162+
results: BatchGeneratePrivateKeysActionResult[];
163+
}
162164

163165
/** @typedef GeneratePrivateKeyParams
164166
* @extends BaseApiParams

0 commit comments

Comments
 (0)