Skip to content

Commit 985e069

Browse files
committed
feat: import ethers to lit actions BUT making it external in esBuild config
1 parent 8c8c8c8 commit 985e069

26 files changed

+88
-51
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ module.exports = {
6767
treeShaking: true,
6868
outdir: './src/generated/',
6969
inject: ['./buffer.shim.js'],
70+
external: ['ethers'],
7071
plugins: [wrapIIFEInStringPlugin],
7172
platform: 'browser',
7273
})

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { ethers as EthersType } from 'ethers';
2-
31
// @ts-nocheck - got this directly from the lit-assets repo
42
declare global {
5-
export const ethers: typeof EthersType;
63

74
export declare namespace Lit {
85
export namespace Actions {
@@ -387,4 +384,4 @@ declare global {
387384
}
388385
}
389386

390-
export {};
387+
export { };

packages/wrapped-keys-lit-actions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
"version": "6.10.0",
3030
"main": "./dist/src/index.js",
3131
"typings": "./dist/src/index.d.ts"
32-
}
32+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AbortError } from '../../abortError';
44
import { removeSaltFromDecryptedKey } from '../../utils';
55

66
interface TryDecryptToSingleNodeParams {
7-
accessControlConditions: any;
7+
accessControlConditions: string
88
ciphertext: string;
99
dataToEncryptHash: string;
1010
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/* global ethers */
1+
/**
2+
* The global ethers library (5.7.0) is available on Lit Action (Unbundled)
3+
*/
4+
import { ethers } from 'ethers';
25

36
export function generateEthereumPrivateKey() {
47
const wallet = ethers.Wallet.createRandom();

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/* global ethers */
1+
/**
2+
* The global ethers library (5.7.0) is available on Lit Action (Unbundled)
3+
*/
4+
import { ethers } from 'ethers';
25

36
interface SignMessageParams {
47
privateKey: string;
@@ -20,7 +23,11 @@ async function signMessage({
2023

2124
return { signature, walletAddress: wallet.address };
2225
} catch (err: unknown) {
23-
throw new Error(`When signing message - ${(err as Error).message}`);
26+
if (err instanceof Error) {
27+
throw new Error(`When signing message - ${err.message}`);
28+
} else {
29+
throw new Error(`An unexpected error occurred: ${err}`);
30+
}
2431
}
2532
}
2633

@@ -32,8 +39,7 @@ function verifyMessageSignature({
3239
return ethers.utils.verifyMessage(messageToSign, signature);
3340
} catch (err: unknown) {
3441
throw new Error(
35-
`When validating signed Ethereum message is valid: ${
36-
(err as Error).message
42+
`When validating signed Ethereum message is valid: ${(err as Error).message
3743
}`
3844
);
3945
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
/* global ethers, Lit */
22

3-
interface UnsignedTransaction {
3+
/**
4+
* The global ethers library (5.7.0) is available on Lit Action (Unbundled)
5+
*/
6+
import { ethers } from 'ethers';
7+
8+
// This is weird - ethers.UnsignedTransaction is not the same as the one being used here..
9+
export interface UnsignedTransaction {
410
toAddress: string;
511
chain: string;
612
value: string;
713
chainId: number;
814
dataHex?: string;
915
gasPrice?: string;
1016
gasLimit?: number;
17+
serializedTransaction?: any;
1118
}
1219

1320
export function getValidatedUnsignedTx(
@@ -81,7 +88,7 @@ async function getGasPrice({
8188
provider,
8289
}: {
8390
userProvidedGasPrice?: string;
84-
provider: any;
91+
provider: ethers.providers.JsonRpcProvider;
8592
}) {
8693
try {
8794
if (userProvidedGasPrice) {
@@ -99,7 +106,7 @@ async function getGasLimit({
99106
userProvidedGasLimit,
100107
validatedTx,
101108
}: {
102-
provider: any;
109+
provider: ethers.providers.JsonRpcProvider;
103110
userProvidedGasLimit?: number;
104111
validatedTx: any;
105112
}) {
@@ -132,7 +139,7 @@ async function broadcastTransaction({
132139
provider,
133140
signedTx,
134141
}: {
135-
provider: any;
142+
provider: ethers.providers.JsonRpcProvider;
136143
signedTx: string;
137144
}) {
138145
try {

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { Keypair } from '@solana/web3.js';
22
import nacl from 'tweetnacl';
33
import { Buffer } from 'buffer';
44

5-
/* global ethers */
5+
/**
6+
* The global ethers library (5.7.0) is available on Lit Action (Unbundled)
7+
*/
8+
import { ethers } from 'ethers';
69

710
interface SignMessageParams {
811
messageToSign: string;
@@ -26,7 +29,11 @@ function signMessage({ messageToSign, solanaKeyPair }: SignMessageParams): {
2629

2730
return { signature };
2831
} catch (err: unknown) {
29-
throw new Error(`When signing message - ${(err as Error).message}`);
32+
if (err instanceof Error) {
33+
throw new Error(`When signing message - ${err.message}`);
34+
} else {
35+
throw new Error(`An unexpected error occurred: ${err}`);
36+
}
3037
}
3138
}
3239

@@ -45,8 +52,7 @@ function verifyMessageSignature({
4552
return isValid;
4653
} catch (err: unknown) {
4754
throw new Error(
48-
`When validating signed Solana message is valid: ${
49-
(err as Error).message
55+
`When validating signed Solana message is valid: ${(err as Error).message
5056
}`
5157
);
5258
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import {
66
Transaction,
77
} from '@solana/web3.js';
88

9-
/* global ethers */
10-
11-
interface UnsignedTransaction {
12-
chain: string;
13-
serializedTransaction: string;
14-
}
9+
/**
10+
* The global ethers library (5.7.0) is available on Lit Action (Unbundled)
11+
*/
12+
import { ethers } from 'ethers';
13+
import { UnsignedTransaction } from '../ethereum/signTransaction';
1514

1615
export function validateUnsignedTransaction(
1716
unsignedTransaction: UnsignedTransaction

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function processEthereumAction({
1919
accessControlConditions,
2020
}: {
2121
action: Action;
22-
accessControlConditions: any;
22+
accessControlConditions: string
2323
}) {
2424
const { network, generateKeyParams } = action;
2525
const messageToSign = action.signMessageParams?.messageToSign;
@@ -57,7 +57,7 @@ async function processSolanaAction({
5757
accessControlConditions,
5858
}: {
5959
action: Action;
60-
accessControlConditions: any;
60+
accessControlConditions: string
6161
}) {
6262
const { network, generateKeyParams } = action;
6363

@@ -96,7 +96,7 @@ async function processActions({
9696
accessControlConditions,
9797
}: {
9898
actions: Action[];
99-
accessControlConditions: any;
99+
accessControlConditions: string
100100
}) {
101101
return Promise.all(
102102
actions.map(async (action, ndx) => {
@@ -161,7 +161,7 @@ export async function batchGenerateEncryptedKeys({
161161
accessControlConditions,
162162
}: {
163163
actions: Action[];
164-
accessControlConditions: any;
164+
accessControlConditions: string
165165
}) {
166166
validateParams(actions);
167167

0 commit comments

Comments
 (0)