Skip to content

Commit 910537d

Browse files
chore: define default litActionHandler based on wrapped-keys default
1 parent cb38e04 commit 910537d

6 files changed

Lines changed: 394 additions & 10 deletions

File tree

packages/libs/lit-action-bundler/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
],
3131
"dependencies": {
3232
"esbuild": "^0.25.5",
33+
"ethers": "5.8.0",
3334
"ipfs-only-hash": "^4.0.0",
3435
"tslib": "^2.8.1"
3536
}

packages/libs/lit-action-bundler/src/lib/lit-action-bundler.spec.ts

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

packages/libs/lit-action-bundler/src/lib/lit-action-bundler.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 356 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,356 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import type { ethers } from 'ethers';
3+
4+
// @ts-nocheck - got this directly from the lit-assets repo
5+
export declare namespace LitNamespace {
6+
export namespace Actions {
7+
/**
8+
* Check if a given IPFS ID is permitted to sign using a given PKP tokenId
9+
* @function isPermittedAction
10+
* @param {Object} params
11+
* @param {string} params.tokenId The tokenId to check
12+
* @param {string} params.ipfsId The IPFS ID of some JS code (a lit action)
13+
* @returns {Promise<boolean>} A boolean indicating whether the IPFS ID is permitted to sign using the PKP tokenId
14+
*/
15+
function isPermittedAction({
16+
tokenId,
17+
ipfsId,
18+
}: {
19+
tokenId: string;
20+
ipfsId: string;
21+
}): Promise<boolean>;
22+
/**
23+
* Check if a given wallet address is permitted to sign using a given PKP tokenId
24+
* @function isPermittedAddress
25+
* @param {Object} params
26+
* @param {string} params.tokenId The tokenId to check
27+
* @param {string} params.address The wallet address to check
28+
* @returns {Promise<boolean>} A boolean indicating whether the wallet address is permitted to sign using the PKP tokenId
29+
*/
30+
function isPermittedAddress({
31+
tokenId,
32+
address,
33+
}: {
34+
tokenId: string;
35+
address: string;
36+
}): Promise<boolean>;
37+
/**
38+
* Check if a given auth method is permitted to sign using a given PKP tokenId
39+
* @function isPermittedAuthMethod
40+
* @param {Object} params
41+
* @param {string} params.tokenId The tokenId to check
42+
* @param {number} params.authMethodType The auth method type. This is an integer. This mapping shows the initial set but this set may be expanded over time without updating this contract: https://github.com/LIT-Protocol/LitNodeContracts/blob/main/contracts/PKPPermissions.sol#L25
43+
* @param {Uint8Array} params.userId The id of the auth method to check expressed as an array of unsigned 8-bit integers (a Uint8Array)
44+
* @returns {Promise<boolean>} A boolean indicating whether the auth method is permitted to sign using the PKP tokenId
45+
*/
46+
function isPermittedAuthMethod({
47+
tokenId,
48+
authMethodType,
49+
userId,
50+
}: {
51+
tokenId: string;
52+
authMethodType: number;
53+
userId: Uint8Array;
54+
}): Promise<boolean>;
55+
/**
56+
* Get the full list of actions that are permitted to sign using a given PKP tokenId
57+
* @function getPermittedActions
58+
* @param {Object} params
59+
* @param {string} params.tokenId The tokenId to check
60+
* @returns {Promise<Array<string>>} An array of IPFS IDs of lit actions that are permitted to sign using the PKP tokenId
61+
*/
62+
function getPermittedActions({ tokenId }: { tokenId: string }): Promise<string[]>;
63+
/**
64+
* Get the full list of addresses that are permitted to sign using a given PKP tokenId
65+
* @function getPermittedAddresses
66+
* @param {Object} params
67+
* @param {string} params.tokenId The tokenId to check
68+
* @returns {Promise<Array<string>>} An array of addresses that are permitted to sign using the PKP tokenId
69+
*/
70+
function getPermittedAddresses({ tokenId }: { tokenId: string }): Promise<string[]>;
71+
/**
72+
* Get the full list of auth methods that are permitted to sign using a given PKP tokenId
73+
* @function getPermittedAuthMethods
74+
* @param {Object} params
75+
* @param {string} params.tokenId The tokenId to check
76+
* @returns {Promise<Array<Object>>} An array of auth methods that are permitted to sign using the PKP tokenId. Each auth method is an object with the following properties: auth_method_type, id, and user_pubkey (used for web authn, this is the pubkey of the user's authentication keypair)
77+
*/
78+
function getPermittedAuthMethods({ tokenId }: { tokenId: string }): Promise<any[]>;
79+
/**
80+
* Get the permitted auth method scopes for a given PKP tokenId and auth method type + id
81+
* @function getPermittedAuthMethodScopes
82+
* @param {Object} params
83+
* @param {string} params.tokenId The tokenId to check
84+
* @param {string} params.authMethodType The auth method type to look up
85+
* @param {Uint8Array} params.userId The id of the auth method to check expressed as an array of unsigned 8-bit integers (a Uint8Array)
86+
* @param {number} params.maxScopeId The maximum scope id to check. This is an integer.
87+
* @returns {Promise<Array<boolean>>} An array of booleans that define if a given scope id is turned on. The index of the array is the scope id. For example, if the array is [true, false, true], then scope ids 0 and 2 are turned on, but scope id 1 is turned off.
88+
*/
89+
function getPermittedAuthMethodScopes({
90+
tokenId,
91+
authMethodType,
92+
userId,
93+
maxScopeId,
94+
}: {
95+
tokenId: string;
96+
authMethodType: string;
97+
userId: Uint8Array;
98+
maxScopeId: number;
99+
}): Promise<boolean[]>;
100+
/**
101+
* Converts a PKP public key to a PKP token ID by hashing it with keccak256
102+
* @function pubkeyToTokenId
103+
* @param {Object} params
104+
* @param {string} params.publicKey The public key to convert
105+
* @returns {Promise<string>} The token ID as a string
106+
*/
107+
function pubkeyToTokenId({ publicKey }: { publicKey: string }): Promise<string>;
108+
/**
109+
* Gets latest nonce for the given address on a supported chain
110+
* @function getLatestNonce
111+
* @param {Object} params
112+
* @param {string} params.address The wallet address for getting the nonce
113+
* @param {string} params.chain The chain of which the nonce is fetched
114+
* @returns {Promise<string>} The token ID as a string
115+
*/
116+
function getLatestNonce({
117+
address,
118+
chain,
119+
}: {
120+
address: string;
121+
chain: string;
122+
}): Promise<string>;
123+
/**
124+
* Ask the Lit Node to sign any data using the ECDSA Algorithm with it's private key share. The resulting signature share will be returned to the Lit JS SDK which will automatically combine the shares and give you the full signature to use.
125+
* @function signEcdsa
126+
* @param {Object} params
127+
* @param {Uint8Array} params.toSign The data to sign. Should be an array of 8-bit integers.
128+
* @param {string} params.publicKey The public key of the PKP you wish to sign with
129+
* @param {string} params.sigName You can put any string here. This is used to identify the signature in the response by the Lit JS SDK. This is useful if you are signing multiple messages at once. When you get the final signature out, it will be in an object with this signature name as the key.
130+
* @returns {Promise<string>} This function will return the string "success" if it works. The signature share is returned behind the scenes to the Lit JS SDK which will automatically combine the shares and give you the full signature to use.
131+
*/
132+
function signEcdsa({
133+
toSign,
134+
publicKey,
135+
sigName,
136+
}: {
137+
toSign: Uint8Array;
138+
publicKey: string;
139+
sigName: string;
140+
}): Promise<string>;
141+
/**
142+
* Ask the Lit Node to sign a message using the eth_personalSign algorithm. The resulting signature share will be returned to the Lit JS SDK which will automatically combine the shares and give you the full signature to use.
143+
* @function ethPersonalSignMessageEcdsa
144+
* @param {Object} params
145+
* @param {string} params.message The message to sign. Should be a string.
146+
* @param {string} params.publicKey The public key of the PKP you wish to sign with
147+
* @param {string} params.sigName You can put any string here. This is used to identify the signature in the response by the Lit JS SDK. This is useful if you are signing multiple messages at once. When you get the final signature out, it will be in an object with this signature name as the key.
148+
* @returns {Promise<string>} This function will return the string "success" if it works. The signature share is returned behind the scenes to the Lit JS SDK which will automatically combine the shares and give you the full signature to use.
149+
*/
150+
function ethPersonalSignMessageEcdsa({
151+
message,
152+
publicKey,
153+
sigName,
154+
}: {
155+
message: string;
156+
publicKey: string;
157+
sigName: string;
158+
}): Promise<string>;
159+
/**
160+
* Checks a condition using the Lit condition checking engine. This is the same engine that powers our Access Control product. You can use this to check any condition that you can express in our condition language. This is a powerful tool that allows you to build complex conditions that can be checked in a decentralized way. Visit https://developer.litprotocol.com and click on the "Access Control" section to learn more.
161+
* @function checkConditions
162+
* @param {Object} params
163+
* @param {Array<Object>} params.conditions An array of access control condition objects
164+
* @param {Object} params.authSig The AuthSig to use for the condition check. For example, if you were checking for NFT ownership, this AuthSig would be the signature from the NFT owner's wallet.
165+
* @param {string} params.chain The chain this AuthSig comes from
166+
* @returns {Promise<boolean>} A boolean indicating whether the condition check passed or failed
167+
*/
168+
function checkConditions({
169+
conditions,
170+
authSig,
171+
chain,
172+
}: {
173+
conditions: any[];
174+
authSig: any;
175+
chain: string;
176+
}): Promise<boolean>;
177+
/**
178+
* Set the response returned to the client
179+
* @function setResponse
180+
* @param {Object} params
181+
* @param {string} params.response The response to send to the client. You can put any string here, like you could use JSON.stringify on a JS object and send it here.
182+
*/
183+
function setResponse({ response }: { response: string }): any;
184+
/**
185+
* Call a child Lit Action
186+
* @function call
187+
* @param {Object} params
188+
* @param {string} params.ipfsId The IPFS ID of the Lit Action to call
189+
* @param {Object=} params.params Optional parameters to pass to the child Lit Action
190+
* @returns {Promise<string>} The response from the child Lit Action. Note that any signatures performed by the child Lit Action will be automatically combined and returned with the parent Lit Action to the Lit JS SDK client.
191+
*/
192+
function call({
193+
ipfsId,
194+
params,
195+
}: {
196+
ipfsId: string;
197+
params?: any | undefined;
198+
}): Promise<string>;
199+
/**
200+
* Call a smart contract
201+
* @function callContract
202+
* @param {Object} params
203+
* @param {string} params.chain The name of the chain to use. Check out the lit docs "Supported Blockchains" page to find the name. For example, "ethereum"
204+
* @param {string} params.txn The RLP Encoded txn, as a hex string
205+
* @returns {Promise<string>} The response from calling the contract
206+
*/
207+
function callContract({ chain, txn }: { chain: string; txn: string }): Promise<string>;
208+
/**
209+
* Convert a Uint8Array to a string. This is a re-export of this function: https://www.npmjs.com/package/uint8arrays#tostringarray-encoding--utf8
210+
* @function uint8arrayToString
211+
* @param {Uint8Array} array The Uint8Array to convert
212+
* @param {string} encoding The encoding to use. Defaults to "utf8"
213+
* @returns {string} The string representation of the Uint8Array
214+
*/
215+
function uint8arrayToString(...args: any[]): string;
216+
/**
217+
* Convert a string to a Uint8Array. This is a re-export of this function: https://www.npmjs.com/package/uint8arrays#fromstringstring-encoding--utf8
218+
* @function uint8arrayFromString
219+
* @param {string} string The string to convert
220+
* @param {string} encoding The encoding to use. Defaults to "utf8"
221+
* @returns {Uint8Array} The Uint8Array representation of the string
222+
*/
223+
function uint8arrayFromString(...args: any[]): Uint8Array;
224+
function aesDecrypt({ symmetricKey, ciphertext }: { symmetricKey: any; ciphertext: any }): any;
225+
/**
226+
* Claim a key through a key identifier, the result of the claim will be added to `claim_id`
227+
* under the `keyId` given.
228+
* @param {Object} params
229+
* @param {string} params.keyId user id of the claim
230+
*/
231+
function claimKey({ keyId }: { keyId: string }): any;
232+
/**
233+
* Broadcast a message to all connected clients and collect their responses
234+
* @param {string} name The name of the broadcast
235+
* @param {string} value The value to broadcast
236+
* @returns {string} The collected responses as a json array
237+
*/
238+
function broadcastAndCollect({ name, value }: string): string;
239+
/**
240+
* Decrypt and combine the provided
241+
* @param {string} accessControlConditions The access control conditions
242+
* @param {string} ciphertext The ciphertext to decrypt
243+
* @param {string} dataToEncryptHash The hash of the data to <encrypt />
244+
@ @param {string} authSig The auth signature
245+
* @param {string} chain The chain
246+
* @returns {string} The combined data
247+
*/
248+
function decryptAndCombine({
249+
accessControlConditions,
250+
ciphertext,
251+
dataToEncryptHash,
252+
authSig,
253+
chain,
254+
}: string): string;
255+
/**
256+
* Decrypt to a single node.
257+
* @param {string} accessControlConditions The access control conditions
258+
* @param {string} ciphertext The ciphertext to decrypt
259+
* @param {string} dataToEncryptHash The hash of the data to <encrypt />
260+
@ @param { any} authSig The auth signature
261+
* @param {string} chain The chain
262+
* @returns {string} The combined data
263+
*/
264+
function decryptToSingleNode({
265+
accessControlConditions,
266+
ciphertext,
267+
dataToEncryptHash,
268+
authSig,
269+
chain,
270+
}: {
271+
accessControlConditions: string;
272+
ciphertext: string;
273+
dataToEncryptHash: string;
274+
chain: string;
275+
authSig: any;
276+
}): Promise<string>;
277+
/**
278+
* @param {Uint8array} toSign the message to sign
279+
* @param {string} publicKey the public key of the PKP
280+
* @param {string} sigName the name of the signature
281+
* @returns {Uint8array} The resulting signature
282+
*/
283+
function signAndCombineEcdsa({ toSign, publicKey, sigName }: Uint8array): Uint8array;
284+
/**
285+
*
286+
* @param {bool} waitForResponse Whether to wait for a response or not - if false, the function will return immediately.
287+
* @returns {bool} Whether the node can run the code in the next block or not.
288+
*/
289+
function runOnce({ waitForResponse, name }: bool, async_fn: any): bool;
290+
/**
291+
*
292+
* @param {string} chain The chain to get the RPC URL for
293+
* @returns {string} The RPC URL for the chain
294+
*/
295+
function getRpcUrl({ chain }: { chain: string }): Promise<string>;
296+
/**
297+
*
298+
* @param {string} accessControlConditions The access control conditions
299+
* @param {string} to_encrypt The message to encrypt
300+
* @returns { {ciphertext: string, dataToEncryptHash: string} } Contains two items: The ciphertext result after encryption, named "ciphertext" and the dataToEncryptHash, named "dataToEncryptHash"
301+
*/
302+
function encrypt({
303+
accessControlConditions,
304+
to_encrypt,
305+
}: {
306+
accessControlConditions: string;
307+
to_encrypt: Uint8Array;
308+
}): {
309+
ciphertext: string;
310+
dataToEncryptHash: string;
311+
};
312+
}
313+
314+
export namespace Auth {
315+
/**
316+
* Array of action IPFS IDs.
317+
* @type {Array<`Qm${string}` | string>}
318+
*/
319+
const actionIpfsIds: (`Qm${string}` | string)[];
320+
321+
/**
322+
* Array of authentication method contexts.
323+
* @type {Array<{
324+
* userId: string;
325+
* appId: string;
326+
* authMethodType: number;
327+
* lastRetrievedAt: string;
328+
* expiration: number;
329+
* usedForSignSessionKeyRequest: boolean;
330+
* }>}
331+
*/
332+
const authMethodContexts: {
333+
userId: string;
334+
appId: string;
335+
authMethodType: number;
336+
lastRetrievedAt: string;
337+
expiration: number;
338+
usedForSignSessionKeyRequest: boolean;
339+
}[];
340+
341+
/**
342+
* Array of resources.
343+
* @type {Array<any>}
344+
*/
345+
const resources: any[];
346+
347+
/**
348+
* Custom authentication resource.
349+
* @type {string | `"\\(true,${string})\\"`}
350+
*/
351+
const customAuthResource: string | `"\\(true,${string})\\"`;
352+
}
353+
}
354+
export type EthersType = typeof ethers;
355+
356+
export {};
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+
override name = 'AbortError';
3+
}
4+
5+
export const rethrowIfAbortError = (err: unknown) => {
6+
if (err instanceof AbortError) {
7+
throw err;
8+
}
9+
};

0 commit comments

Comments
 (0)