Skip to content

Commit 2092f20

Browse files
committed
fml
1 parent 94329e7 commit 2092f20

16 files changed

+165
-59
lines changed

packages/wrapped-keys-lit-actions/global.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ethers as EthersType } from 'ethers';
22

33
// @ts-nocheck - got this directly from the lit-assets repo
44
declare global {
5-
65
export const ethers: typeof EthersType;
76

87
export declare namespace Lit {
@@ -334,7 +333,10 @@ declare global {
334333
* @param {string} to_encrypt The message to encrypt
335334
* @returns { {ciphertext: string, dataToEncryptHash: string} } Contains two items: The ciphertext result after encryption, named "ciphertext" and the dataToEncryptHash, named "dataToEncryptHash"
336335
*/
337-
function encrypt({ accessControlConditions, to_encrypt }: {
336+
function encrypt({
337+
accessControlConditions,
338+
to_encrypt,
339+
}: {
338340
accessControlConditions: string;
339341
to_encrypt: Uint8Array;
340342
}): {
@@ -344,7 +346,6 @@ declare global {
344346
}
345347

346348
export namespace Auth {
347-
348349
/**
349350
* Array of action IPFS IDs.
350351
* @type {Array<`Qm${string}` | string>}
@@ -386,4 +387,4 @@ declare global {
386387
}
387388
}
388389

389-
export { };
390+
export {};

packages/wrapped-keys-lit-actions/src/lib/internal/common/encryptKey.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export async function encryptPrivateKey({
1414
accessControlConditions: string;
1515
privateKey: string;
1616
publicKey: string;
17-
}): Promise<{ ciphertext: string; dataToEncryptHash: string; publicKey: string; }> {
17+
}): Promise<{
18+
ciphertext: string;
19+
dataToEncryptHash: string;
20+
publicKey: string;
21+
}> {
1822
const { ciphertext, dataToEncryptHash } = await Lit.Actions.encrypt({
1923
accessControlConditions,
2024
to_encrypt: new TextEncoder().encode(LIT_PREFIX + privateKey),

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* global ethers */
22

33
export function generateEthereumPrivateKey() {
4-
54
const wallet = ethers.Wallet.createRandom();
65

76
return {

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ interface VerifyMessageSignatureParams {
1010
signature: string;
1111
}
1212

13-
async function signMessage({ privateKey, messageToSign }: SignMessageParams): Promise<{ signature: string; walletAddress: string }> {
13+
async function signMessage({
14+
privateKey,
15+
messageToSign,
16+
}: SignMessageParams): Promise<{ signature: string; walletAddress: string }> {
1417
try {
1518
const wallet = new ethers.Wallet(privateKey);
1619
const signature = await wallet.signMessage(messageToSign);
@@ -21,17 +24,25 @@ async function signMessage({ privateKey, messageToSign }: SignMessageParams): Pr
2124
}
2225
}
2326

24-
function verifyMessageSignature({ messageToSign, signature }: VerifyMessageSignatureParams): string {
27+
function verifyMessageSignature({
28+
messageToSign,
29+
signature,
30+
}: VerifyMessageSignatureParams): string {
2531
try {
2632
return ethers.utils.verifyMessage(messageToSign, signature);
2733
} catch (err: unknown) {
2834
throw new Error(
29-
`When validating signed Ethereum message is valid: ${(err as Error).message}`
35+
`When validating signed Ethereum message is valid: ${
36+
(err as Error).message
37+
}`
3038
);
3139
}
3240
}
3341

34-
export async function signMessageEthereumKey({ privateKey, messageToSign }: SignMessageParams): Promise<string> {
42+
export async function signMessageEthereumKey({
43+
privateKey,
44+
messageToSign,
45+
}: SignMessageParams): Promise<string> {
3546
const { signature, walletAddress } = await signMessage({
3647
privateKey,
3748
messageToSign,

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

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ interface UnsignedTransaction {
1010
gasLimit?: number;
1111
}
1212

13-
export function getValidatedUnsignedTx(unsignedTransaction: UnsignedTransaction) {
13+
export function getValidatedUnsignedTx(
14+
unsignedTransaction: UnsignedTransaction
15+
) {
1416
try {
1517
if (!unsignedTransaction.toAddress) {
1618
throw new Error('Missing required field: toAddress');
@@ -41,7 +43,13 @@ export function getValidatedUnsignedTx(unsignedTransaction: UnsignedTransaction)
4143
}
4244
}
4345

44-
async function getLatestNonce({ walletAddress, chain }: { walletAddress: string; chain: string }) {
46+
async function getLatestNonce({
47+
walletAddress,
48+
chain,
49+
}: {
50+
walletAddress: string;
51+
chain: string;
52+
}) {
4553
try {
4654
const nonce = await Lit.Actions.getLatestNonce({
4755
address: walletAddress,
@@ -62,11 +70,19 @@ async function getEthersRPCProvider({ chain }: { chain: string }) {
6270

6371
return new ethers.providers.JsonRpcProvider(rpcUrl);
6472
} catch (err: unknown) {
65-
throw new Error(`Getting the rpc for the chain: ${chain} - ${(err as Error).message}`);
73+
throw new Error(
74+
`Getting the rpc for the chain: ${chain} - ${(err as Error).message}`
75+
);
6676
}
6777
}
6878

69-
async function getGasPrice({ userProvidedGasPrice, provider }: { userProvidedGasPrice?: string; provider: any }) {
79+
async function getGasPrice({
80+
userProvidedGasPrice,
81+
provider,
82+
}: {
83+
userProvidedGasPrice?: string;
84+
provider: any;
85+
}) {
7086
try {
7187
if (userProvidedGasPrice) {
7288
return ethers.utils.parseUnits(userProvidedGasPrice, 'gwei');
@@ -78,7 +94,15 @@ async function getGasPrice({ userProvidedGasPrice, provider }: { userProvidedGas
7894
}
7995
}
8096

81-
async function getGasLimit({ provider, userProvidedGasLimit, validatedTx }: { provider: any; userProvidedGasLimit?: number; validatedTx: any }) {
97+
async function getGasLimit({
98+
provider,
99+
userProvidedGasLimit,
100+
validatedTx,
101+
}: {
102+
provider: any;
103+
userProvidedGasLimit?: number;
104+
validatedTx: any;
105+
}) {
82106
if (userProvidedGasLimit) {
83107
return userProvidedGasLimit;
84108
} else {
@@ -90,15 +114,27 @@ async function getGasLimit({ provider, userProvidedGasLimit, validatedTx }: { pr
90114
}
91115
}
92116

93-
async function signTransaction({ validatedTx, wallet }: { validatedTx: any; wallet: any }) {
117+
async function signTransaction({
118+
validatedTx,
119+
wallet,
120+
}: {
121+
validatedTx: any;
122+
wallet: any;
123+
}) {
94124
try {
95125
return await wallet.signTransaction(validatedTx);
96126
} catch (err: unknown) {
97127
throw new Error(`When signing transaction - ${(err as Error).message}`);
98128
}
99129
}
100130

101-
async function broadcastTransaction({ provider, signedTx }: { provider: any; signedTx: string }) {
131+
async function broadcastTransaction({
132+
provider,
133+
signedTx,
134+
}: {
135+
provider: any;
136+
signedTx: string;
137+
}) {
102138
try {
103139
return await provider.sendTransaction(signedTx);
104140
} catch (err: unknown) {

packages/wrapped-keys-lit-actions/src/lib/internal/solana/signMessage.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ interface VerifyMessageSignatureParams {
1515
messageToSign: string;
1616
}
1717

18-
function signMessage({ messageToSign, solanaKeyPair }: SignMessageParams): { signature: Uint8Array } {
18+
function signMessage({ messageToSign, solanaKeyPair }: SignMessageParams): {
19+
signature: Uint8Array;
20+
} {
1921
try {
2022
const signature = nacl.sign.detached(
2123
new TextEncoder().encode(messageToSign),
@@ -28,7 +30,11 @@ function signMessage({ messageToSign, solanaKeyPair }: SignMessageParams): { sig
2830
}
2931
}
3032

31-
function verifyMessageSignature({ signature, solanaKeyPair, messageToSign }: VerifyMessageSignatureParams): boolean {
33+
function verifyMessageSignature({
34+
signature,
35+
solanaKeyPair,
36+
messageToSign,
37+
}: VerifyMessageSignatureParams): boolean {
3238
try {
3339
const isValid = nacl.sign.detached.verify(
3440
Buffer.from(messageToSign),
@@ -39,12 +45,20 @@ function verifyMessageSignature({ signature, solanaKeyPair, messageToSign }: Ver
3945
return isValid;
4046
} catch (err: unknown) {
4147
throw new Error(
42-
`When validating signed Solana message is valid: ${(err as Error).message}`
48+
`When validating signed Solana message is valid: ${
49+
(err as Error).message
50+
}`
4351
);
4452
}
4553
}
4654

47-
export async function signMessageSolanaKey({ messageToSign, privateKey }: { messageToSign: string; privateKey: string }): Promise<string> {
55+
export async function signMessageSolanaKey({
56+
messageToSign,
57+
privateKey,
58+
}: {
59+
messageToSign: string;
60+
privateKey: string;
61+
}): Promise<string> {
4862
const solanaKeyPair = Keypair.fromSecretKey(Buffer.from(privateKey, 'hex'));
4963

5064
const { signature } = signMessage({

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Cluster, clusterApiUrl, Connection, Keypair, Transaction } from '@solana/web3.js';
1+
import {
2+
Cluster,
3+
clusterApiUrl,
4+
Connection,
5+
Keypair,
6+
Transaction,
7+
} from '@solana/web3.js';
28

39
/* global ethers */
410

@@ -7,7 +13,9 @@ interface UnsignedTransaction {
713
serializedTransaction: string;
814
}
915

10-
export function validateUnsignedTransaction(unsignedTransaction: UnsignedTransaction) {
16+
export function validateUnsignedTransaction(
17+
unsignedTransaction: UnsignedTransaction
18+
) {
1119
const VALID_NETWORKS = ['devnet', 'testnet', 'mainnet-beta'];
1220

1321
if (!VALID_NETWORKS.includes(unsignedTransaction.chain)) {
@@ -24,7 +32,13 @@ export function validateUnsignedTransaction(unsignedTransaction: UnsignedTransac
2432
}
2533
}
2634

27-
function signTransaction({ solanaKeyPair, transaction }: { solanaKeyPair: Keypair; transaction: Transaction }) {
35+
function signTransaction({
36+
solanaKeyPair,
37+
transaction,
38+
}: {
39+
solanaKeyPair: Keypair;
40+
transaction: Transaction;
41+
}) {
2842
try {
2943
transaction.sign(solanaKeyPair);
3044

@@ -38,8 +52,13 @@ function signTransaction({ solanaKeyPair, transaction }: { solanaKeyPair: Keypai
3852
}
3953
}
4054

41-
async function sendTransaction({ chain, transaction }: { chain: Cluster; transaction: Transaction }) {
42-
55+
async function sendTransaction({
56+
chain,
57+
transaction,
58+
}: {
59+
chain: Cluster;
60+
transaction: Transaction;
61+
}) {
4362
try {
4463
const solanaConnection = new Connection(clusterApiUrl(chain), 'confirmed');
4564
return await solanaConnection.sendRawTransaction(transaction.serialize());
@@ -77,4 +96,4 @@ export async function signTransactionSolanaKey({
7796
chain,
7897
transaction,
7998
});
80-
}
99+
}

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

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { encryptPrivateKey } from '../../internal/common/encryptKey';
2-
import {
3-
generateEthereumPrivateKey,
4-
} from '../../internal/ethereum/generatePrivateKey';
5-
import {
6-
signMessageEthereumKey,
7-
} from '../../internal/ethereum/signMessage';
8-
import {
9-
generateSolanaPrivateKey,
10-
} from '../../internal/solana/generatePrivateKey';
2+
import { generateEthereumPrivateKey } from '../../internal/ethereum/generatePrivateKey';
3+
import { signMessageEthereumKey } from '../../internal/ethereum/signMessage';
4+
import { generateSolanaPrivateKey } from '../../internal/solana/generatePrivateKey';
115
import { signMessageSolanaKey } from '../../internal/solana/signMessage';
126

137
interface Action {
@@ -20,7 +14,13 @@ interface Action {
2014
};
2115
}
2216

23-
async function processEthereumAction({ action, accessControlConditions }: { action: Action; accessControlConditions: any }) {
17+
async function processEthereumAction({
18+
action,
19+
accessControlConditions,
20+
}: {
21+
action: Action;
22+
accessControlConditions: any;
23+
}) {
2424
const { network, generateKeyParams } = action;
2525
const messageToSign = action.signMessageParams?.messageToSign;
2626

@@ -34,9 +34,9 @@ async function processEthereumAction({ action, accessControlConditions }: { acti
3434
}),
3535
messageToSign
3636
? signMessageEthereumKey({
37-
messageToSign: messageToSign,
38-
privateKey: ethereumKey.privateKey,
39-
})
37+
messageToSign: messageToSign,
38+
privateKey: ethereumKey.privateKey,
39+
})
4040
: Promise.resolve(),
4141
]);
4242

@@ -52,7 +52,13 @@ async function processEthereumAction({ action, accessControlConditions }: { acti
5252
};
5353
}
5454

55-
async function processSolanaAction({ action, accessControlConditions }: { action: Action; accessControlConditions: any }) {
55+
async function processSolanaAction({
56+
action,
57+
accessControlConditions,
58+
}: {
59+
action: Action;
60+
accessControlConditions: any;
61+
}) {
5662
const { network, generateKeyParams } = action;
5763

5864
const messageToSign = action.signMessageParams?.messageToSign;
@@ -67,9 +73,9 @@ async function processSolanaAction({ action, accessControlConditions }: { action
6773
}),
6874
messageToSign
6975
? signMessageSolanaKey({
70-
messageToSign: messageToSign,
71-
privateKey: solanaKey.privateKey,
72-
})
76+
messageToSign: messageToSign,
77+
privateKey: solanaKey.privateKey,
78+
})
7379
: Promise.resolve(),
7480
]);
7581

@@ -85,7 +91,13 @@ async function processSolanaAction({ action, accessControlConditions }: { action
8591
};
8692
}
8793

88-
async function processActions({ actions, accessControlConditions }: { actions: Action[]; accessControlConditions: any }) {
94+
async function processActions({
95+
actions,
96+
accessControlConditions,
97+
}: {
98+
actions: Action[];
99+
accessControlConditions: any;
100+
}) {
89101
return Promise.all(
90102
actions.map(async (action, ndx) => {
91103
const { network } = action;

packages/wrapped-keys-lit-actions/src/lib/raw-action-functions/ethereum/generateEncryptedEthereumPrivateKey.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ interface GenerateEncryptedEthereumPrivateKeyParams {
1616

1717
export async function generateEncryptedEthereumPrivateKey({
1818
accessControlConditions,
19-
}: GenerateEncryptedEthereumPrivateKeyParams): Promise<{ciphertext: string, dataToEncryptHash: string, publicKey: string}> {
19+
}: GenerateEncryptedEthereumPrivateKeyParams): Promise<{
20+
ciphertext: string;
21+
dataToEncryptHash: string;
22+
publicKey: string;
23+
}> {
2024
const { privateKey, publicKey } = generateEthereumPrivateKey();
2125
return encryptPrivateKey({
2226
accessControlConditions,

0 commit comments

Comments
 (0)