Skip to content

Commit c2e28a6

Browse files
feat(wrapped-keys-lit-actions): LIT-3995 - Add sign transaction capability to actions array processed by batchGenerateEncryptedKeys LIT action
1 parent 45e19d7 commit c2e28a6

File tree

2 files changed

+84
-31
lines changed

2 files changed

+84
-31
lines changed

packages/wrapped-keys-lit-actions/src/lib/internal/ethereum/signTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export async function signTransactionEthereumKey({
163163
privateKey: string;
164164
validatedTx: ValidatedTransaction;
165165
unsignedTransaction: UnsignedTransaction;
166-
}) {
166+
}): Promise<string> {
167167
const wallet = new ethers.Wallet(privateKey);
168168

169169
validatedTx.from = wallet.address;

packages/wrapped-keys-lit-actions/src/lib/raw-action-functions/common/batchGenerateEncryptedKeys.ts

Lines changed: 83 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import { encryptPrivateKey } from '../../internal/common/encryptKey';
22
import { generateEthereumPrivateKey } from '../../internal/ethereum/generatePrivateKey';
33
import { signMessageEthereumKey } from '../../internal/ethereum/signMessage';
4+
import {
5+
getValidatedUnsignedTx,
6+
signTransactionEthereumKey,
7+
} from '../../internal/ethereum/signTransaction';
48
import { generateSolanaPrivateKey } from '../../internal/solana/generatePrivateKey';
59
import { signMessageSolanaKey } from '../../internal/solana/signMessage';
10+
import {
11+
signTransactionSolanaKey,
12+
type UnsignedTransaction as UnsignedTransactionSolana,
13+
} from '../../internal/solana/signTransaction';
614

7-
interface Action {
8-
network: 'evm' | 'solana';
15+
import type { UnsignedTransaction as UnsignedTransactionEthereum } from '../../internal/ethereum/signTransaction';
16+
17+
interface BaseAction {
918
generateKeyParams: {
1019
memo: string;
1120
};
@@ -14,6 +23,24 @@ interface Action {
1423
};
1524
}
1625

26+
interface ActionSolana extends BaseAction {
27+
network: 'solana';
28+
signTransactionParams?: {
29+
unsignedTransaction: UnsignedTransactionSolana;
30+
broadcast: boolean;
31+
};
32+
}
33+
34+
interface ActionEthereum extends BaseAction {
35+
network: 'evm';
36+
signTransactionParams?: {
37+
unsignedTransaction: UnsignedTransactionEthereum;
38+
broadcast: boolean;
39+
};
40+
}
41+
42+
type Action = ActionSolana | ActionEthereum;
43+
1744
export interface BatchGenerateEncryptedKeysParams {
1845
actions: Action[];
1946
accessControlConditions: string;
@@ -23,27 +50,38 @@ async function processEthereumAction({
2350
action,
2451
accessControlConditions,
2552
}: {
26-
action: Action;
53+
action: ActionEthereum;
2754
accessControlConditions: string;
2855
}) {
2956
const { network, generateKeyParams } = action;
3057
const messageToSign = action.signMessageParams?.messageToSign;
58+
const unsignedTransaction = action.signTransactionParams?.unsignedTransaction;
3159

3260
const ethereumKey = generateEthereumPrivateKey();
3361

34-
const [generatedPrivateKey, messageSignature] = await Promise.all([
35-
encryptPrivateKey({
36-
accessControlConditions,
37-
publicKey: ethereumKey.publicKey,
38-
privateKey: ethereumKey.privateKey,
39-
}),
40-
messageToSign
41-
? signMessageEthereumKey({
42-
messageToSign: messageToSign,
43-
privateKey: ethereumKey.privateKey,
44-
})
45-
: Promise.resolve(),
46-
]);
62+
const [generatedPrivateKey, messageSignature, transactionSignature] =
63+
await Promise.all([
64+
encryptPrivateKey({
65+
accessControlConditions,
66+
publicKey: ethereumKey.publicKey,
67+
privateKey: ethereumKey.privateKey,
68+
}),
69+
messageToSign
70+
? signMessageEthereumKey({
71+
messageToSign: messageToSign,
72+
privateKey: ethereumKey.privateKey,
73+
})
74+
: Promise.resolve(),
75+
76+
unsignedTransaction
77+
? signTransactionEthereumKey({
78+
unsignedTransaction,
79+
broadcast: action.signTransactionParams?.broadcast || false,
80+
privateKey: ethereumKey.privateKey,
81+
validatedTx: getValidatedUnsignedTx(unsignedTransaction),
82+
})
83+
: Promise.resolve(),
84+
]);
4785

4886
return {
4987
network,
@@ -54,35 +92,47 @@ async function processEthereumAction({
5492
...(messageSignature
5593
? { signMessage: { signature: messageSignature } }
5694
: {}),
95+
...(transactionSignature
96+
? { signTransaction: { signature: transactionSignature } }
97+
: {}),
5798
};
5899
}
59100

60101
async function processSolanaAction({
61102
action,
62103
accessControlConditions,
63104
}: {
64-
action: Action;
105+
action: ActionSolana;
65106
accessControlConditions: string;
66107
}) {
67108
const { network, generateKeyParams } = action;
68109

69110
const messageToSign = action.signMessageParams?.messageToSign;
111+
const unsignedTransaction = action.signTransactionParams?.unsignedTransaction;
70112

71113
const solanaKey = generateSolanaPrivateKey();
72114

73-
const [generatedPrivateKey, messageSignature] = await Promise.all([
74-
encryptPrivateKey({
75-
accessControlConditions,
76-
publicKey: solanaKey.publicKey,
77-
privateKey: solanaKey.privateKey,
78-
}),
79-
messageToSign
80-
? signMessageSolanaKey({
81-
messageToSign: messageToSign,
82-
privateKey: solanaKey.privateKey,
83-
})
84-
: Promise.resolve(),
85-
]);
115+
const [generatedPrivateKey, messageSignature, transactionSignature] =
116+
await Promise.all([
117+
encryptPrivateKey({
118+
accessControlConditions,
119+
publicKey: solanaKey.publicKey,
120+
privateKey: solanaKey.privateKey,
121+
}),
122+
messageToSign
123+
? signMessageSolanaKey({
124+
messageToSign: messageToSign,
125+
privateKey: solanaKey.privateKey,
126+
})
127+
: Promise.resolve(),
128+
unsignedTransaction
129+
? signTransactionSolanaKey({
130+
broadcast: action.signTransactionParams?.broadcast || false,
131+
unsignedTransaction,
132+
privateKey: solanaKey.privateKey,
133+
})
134+
: Promise.resolve(),
135+
]);
86136

87137
return {
88138
network,
@@ -93,6 +143,9 @@ async function processSolanaAction({
93143
...(messageSignature
94144
? { signMessage: { signature: messageSignature } }
95145
: {}),
146+
...(transactionSignature
147+
? { signTransaction: { signature: transactionSignature } }
148+
: {}),
96149
};
97150
}
98151

0 commit comments

Comments
 (0)