From 21cfaf35bdf15f7add6ec2882fcad65963e15c72 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Tue, 25 Jun 2024 15:59:18 +0100 Subject: [PATCH 01/30] chore(types): LIT-3125 - Run eslint --fix on types.ts --- packages/types/src/lib/types.ts | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/packages/types/src/lib/types.ts b/packages/types/src/lib/types.ts index 2cbba01483..a75f786ba4 100644 --- a/packages/types/src/lib/types.ts +++ b/packages/types/src/lib/types.ts @@ -1,4 +1,3 @@ -import { AuthMethodType } from './enums'; import * as ethers from 'ethers'; import { @@ -7,6 +6,8 @@ import { LPACC_SOL, LPACC_EVM_BASIC, } from '@lit-protocol/accs-schemas'; + +import { AuthMethodType } from './enums'; import { AuthMethod, LitRelayConfig, @@ -14,8 +15,6 @@ import { Signature, StytchOtpProviderOptions, WebAuthnProviderOptions, -} from './interfaces'; -import { AccsOperatorParams, EthWalletProviderOptions, JsonEncryptionRetrieveRequest, @@ -78,14 +77,14 @@ export type Chain = string; * * @typedef { Object } LITChainRequiredProps */ -export type LITChainRequiredProps = { +export interface LITChainRequiredProps { name: string; symbol: string; decimals: number; - rpcUrls: Array; - blockExplorerUrls: Array; + rpcUrls: string[]; + blockExplorerUrls: string[]; vmType: string; -}; +} /** * @typedef { Object } LITEVMChain @@ -117,9 +116,7 @@ export type LITCosmosChain = LITChainRequiredProps & { * @property {string} vmType - Either EVM for an Ethereum compatible chain or SVM for a Solana compatible chain * @property {string} name - The human readable name of the chain */ -export type LITChain = { - [chainName: string]: T; -}; +export type LITChain = Record; export type LIT_NETWORKS_KEYS = | 'cayenne' @@ -199,18 +196,18 @@ export type ClaimResult = { pubkey: string; } & (T extends 'relay' ? LitRelayConfig : { signer: ethers.Signer }); -export type LitContract = { +export interface LitContract { address?: string; abi?: any; name?: string; -}; +} /** * Defines a set of contract metadata for bootstrapping * network context and interfacing with contracts on Chroncile blockchain * */ -export type LitContractContext = { +export interface LitContractContext { [index: string]: string | any; Allowlist: LitContract; @@ -224,7 +221,7 @@ export type LitContractContext = { RateLimitNFT: LitContract; Staking: LitContract; StakingBalances: LitContract; -}; +} /** * Type for a contract resolver instance which will be used @@ -232,7 +229,7 @@ export type LitContractContext = { * an instance of LitContractContext can still be provided. which will be used for abi data. * */ -export type LitContractResolverContext = { +export interface LitContractResolverContext { [index: string]: | string | LitContractContext @@ -244,6 +241,6 @@ export type LitContractResolverContext = { environment: number; contractContext?: LitContractContext; provider?: ethers.providers.JsonRpcProvider; -}; +} export type ResponseStrategy = 'leastCommon' | 'mostCommon' | 'custom'; From d6c1a7b4d0453f781bdd508835f9a6c964374a6b Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Tue, 25 Jun 2024 16:00:29 +0100 Subject: [PATCH 02/30] types: LIT-3125 - Fix incorrect interface for SessionKeySignedMessage and add `AcssParams` to `AccessControlConditions` type for accuracy --- packages/types/src/lib/interfaces.ts | 2 +- packages/types/src/lib/types.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index e7f77aaafb..28ecbfe1d2 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -948,7 +948,7 @@ export interface DecryptZipFileWithMetadataProps extends SessionSigsOrAuthSig { export interface SessionKeySignedMessage { sessionKey: string; resources?: any[]; - capabilities: string[]; + capabilities: AuthSig[]; issuedAt: string; expiration: string; nodeAddress: string; diff --git a/packages/types/src/lib/types.ts b/packages/types/src/lib/types.ts index a75f786ba4..6d09f9d0d7 100644 --- a/packages/types/src/lib/types.ts +++ b/packages/types/src/lib/types.ts @@ -44,6 +44,7 @@ export type ConditionItem = AccsParams | AccsOperatorParams; export type AccessControlConditions = ( | AccsDefaultParams + | AccsParams | AccsOperatorParams | AccessControlConditions )[]; From 549cd84bc2d8efd067b8d655163b731ab40cc7ba Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Tue, 25 Jun 2024 23:37:59 +0100 Subject: [PATCH 03/30] feat(wrapped-keys): LIT-3125 - Add wrapped keys backend service client implementation - Responsible for communicating with off-chain storage that is authenticated with a valid LIT session signature --- .../src/lib/service-client/client.ts | 51 +++++++ .../src/lib/service-client/constants.ts | 17 +++ .../src/lib/service-client/index.ts | 9 ++ .../src/lib/service-client/types.ts | 39 +++++ .../src/lib/service-client/utils.ts | 134 ++++++++++++++++++ 5 files changed, 250 insertions(+) create mode 100644 packages/wrapped-keys/src/lib/service-client/client.ts create mode 100644 packages/wrapped-keys/src/lib/service-client/constants.ts create mode 100644 packages/wrapped-keys/src/lib/service-client/index.ts create mode 100644 packages/wrapped-keys/src/lib/service-client/types.ts create mode 100644 packages/wrapped-keys/src/lib/service-client/utils.ts diff --git a/packages/wrapped-keys/src/lib/service-client/client.ts b/packages/wrapped-keys/src/lib/service-client/client.ts new file mode 100644 index 0000000000..a07d245f7c --- /dev/null +++ b/packages/wrapped-keys/src/lib/service-client/client.ts @@ -0,0 +1,51 @@ +import { FetchKeyParams, StoredKeyMetadata, StoreKeyParams } from './types'; +import { getBaseRequestParams, makeRequest } from './utils'; + +/** Fetches previously stored private key metadata from the wrapped keys service + * + * @param { FetchKeyParams } params Parameters required to fetch the private key metadata + * @returns { Promise } The private key metadata object + */ +export async function fetchPrivateKeyMetadata( + params: FetchKeyParams +): Promise { + const { litNodeClient, sessionSig } = params; + + const { url, initParams } = getBaseRequestParams({ + litNetwork: litNodeClient.config.litNetwork, + sessionSig, + method: 'GET', + }); + + return makeRequest({ + url, + init: initParams, + }); +} + +/** Stores private key metadata into the wrapped keys service backend + * + * @param { StoreKeyParams } params Parameters required to store the private key metadata + * @returns { Promise } `true` on successful write to the service. Otherwise, this method throws an error. + */ +export async function storePrivateKeyMetadata( + params: StoreKeyParams +): Promise { + const { litNodeClient, sessionSig, storedKeyMetadata } = params; + + const { url, initParams } = getBaseRequestParams({ + litNetwork: litNodeClient.config.litNetwork, + sessionSig, + method: 'POST', + }); + + await makeRequest({ + url, + init: { + ...initParams, + body: JSON.stringify(storedKeyMetadata), + }, + }); + + return true; +} diff --git a/packages/wrapped-keys/src/lib/service-client/constants.ts b/packages/wrapped-keys/src/lib/service-client/constants.ts new file mode 100644 index 0000000000..ab22a4df80 --- /dev/null +++ b/packages/wrapped-keys/src/lib/service-client/constants.ts @@ -0,0 +1,17 @@ +import { LitNetwork } from '@lit-protocol/constants'; + +import { SupportedNetworks } from './types'; + +type NETWORK_TYPES = 'TestNetworks' | 'Production'; +const SERVICE_URL_BY_NETWORKTYPE: Record = { + TestNetworks: 'https://test.wrapped.litprotocol.com/encrypted', + Production: 'https://wrapped.litprotocol.com/encrypted', +}; + +export const SERVICE_URL_BY_LIT_NETWORK: Record = { + [LitNetwork.Cayenne]: SERVICE_URL_BY_NETWORKTYPE.TestNetworks, + [LitNetwork.Manzano]: SERVICE_URL_BY_NETWORKTYPE.TestNetworks, + [LitNetwork.Habanero]: SERVICE_URL_BY_NETWORKTYPE.Production, +}; + +export const LIT_SESSIONSIG_AUTHORIZATION_SCHEMA_PREFIX = 'LitSessionSig:'; diff --git a/packages/wrapped-keys/src/lib/service-client/index.ts b/packages/wrapped-keys/src/lib/service-client/index.ts new file mode 100644 index 0000000000..4571cc406c --- /dev/null +++ b/packages/wrapped-keys/src/lib/service-client/index.ts @@ -0,0 +1,9 @@ +import { fetchPrivateKeyMetadata, storePrivateKeyMetadata } from './client'; +import { StoredKeyMetadata, SupportedNetworks } from './types'; + +export { + fetchPrivateKeyMetadata, + storePrivateKeyMetadata, + StoredKeyMetadata, + SupportedNetworks, +}; diff --git a/packages/wrapped-keys/src/lib/service-client/types.ts b/packages/wrapped-keys/src/lib/service-client/types.ts new file mode 100644 index 0000000000..21ab56243a --- /dev/null +++ b/packages/wrapped-keys/src/lib/service-client/types.ts @@ -0,0 +1,39 @@ +import { + AuthSig, + ILitNodeClient, + LIT_NETWORKS_KEYS, +} from '@lit-protocol/types'; + +interface BaseApiParams { + sessionSig: AuthSig; + litNodeClient: ILitNodeClient; +} + +export type FetchKeyParams = BaseApiParams; + +export type SupportedNetworks = Extract< + LIT_NETWORKS_KEYS, + 'cayenne' | 'manzano' | 'habanero' +>; + +export interface StoredKeyMetadata { + ciphertext: string; + dataToEncryptHash: string; + address: string; + pkpAddress: string; + algo: string; + litNetwork: SupportedNetworks; +} + +export interface StoreKeyParams extends BaseApiParams { + storedKeyMetadata: Pick< + StoredKeyMetadata, + 'pkpAddress' | 'address' | 'algo' | 'dataToEncryptHash' | 'ciphertext' + >; +} + +export interface BaseRequestParams { + sessionSig: AuthSig; + method: 'GET' | 'POST'; + litNetwork: LIT_NETWORKS_KEYS; +} diff --git a/packages/wrapped-keys/src/lib/service-client/utils.ts b/packages/wrapped-keys/src/lib/service-client/utils.ts new file mode 100644 index 0000000000..d024cc9672 --- /dev/null +++ b/packages/wrapped-keys/src/lib/service-client/utils.ts @@ -0,0 +1,134 @@ +import { AuthSig, LIT_NETWORKS_KEYS } from '@lit-protocol/types'; +import { + uint8arrayFromString, + uint8ArrayToBase64, +} from '@lit-protocol/uint8arrays'; + +import { + LIT_SESSIONSIG_AUTHORIZATION_SCHEMA_PREFIX, + SERVICE_URL_BY_LIT_NETWORK, +} from './constants'; +import { BaseRequestParams, SupportedNetworks } from './types'; +import { getPkpAddressFromSessionSig } from '../utils'; + +function composeAuthHeader(sessionSig: AuthSig) { + const sessionSigUintArr = uint8arrayFromString(JSON.stringify(sessionSig)); + + return `${LIT_SESSIONSIG_AUTHORIZATION_SCHEMA_PREFIX}${uint8ArrayToBase64( + sessionSigUintArr + )}`; +} + +const supportedNetworks: SupportedNetworks[] = [ + 'cayenne', + 'manzano', + 'habanero', +]; + +function isSupportedLitNetwork( + litNetwork: LIT_NETWORKS_KEYS +): asserts litNetwork is SupportedNetworks { + // @ts-expect-error - This is an assert function; litNetwork by definition may be an invalid value + if (!supportedNetworks.includes(litNetwork)) { + throw new Error( + `Unsupported LitNetwork! (${supportedNetworks.join('|')}) are supported.` + ); + } +} + +function getServiceUrl({ sessionSig, method, litNetwork }: BaseRequestParams) { + isSupportedLitNetwork(litNetwork); + + if (method === 'POST') { + return SERVICE_URL_BY_LIT_NETWORK[litNetwork]; + } + + const pkpAddress = getPkpAddressFromSessionSig(sessionSig); + return `${SERVICE_URL_BY_LIT_NETWORK[litNetwork]}/${pkpAddress}`; +} + +export function getBaseRequestParams(requestParams: BaseRequestParams): { + initParams: RequestInit; + url: string; +} { + const { sessionSig, method, litNetwork } = requestParams; + + // NOTE: Although HTTP conventions use capitalized letters for header names + // Lambda backend events from API gateway receive all lowercased header keys + return { + url: getServiceUrl(requestParams), + initParams: { + method, + headers: { + 'Content-Type': 'application/json', + 'Lit-Network': litNetwork, + Authorization: composeAuthHeader(sessionSig), // As Base64 string to avoid escaping issues + }, + }, + }; +} + +/** + * This method gives us _either_ the `message` key from the backend error response _or_ the text of the response if + * it was not JSON formed. + * + * Under normal operations, the backend will return errors in JSON format + * + * However, because we can't be 100% sure that an error response actually came from our backend code rather than + * from interim infrastructure, we need to assume that we may be getting a generic error that is plain text. + * + * @param {Response} response The response we received from fetch() + * @returns {string} The error message from the response + */ +async function getResponseErrorMessage(response: Response): Promise { + try { + const parsedResponse = await response.json(); + if (parsedResponse.message) { + return parsedResponse.message as string; + } + return JSON.stringify(parsedResponse); + } catch (e) { + return response.text(); + } +} + +/** This method will give us the JSON parsed response if possible, otherwise the text of the response as a string + * Responses from the backend API should always be in JSON format + * However, some mis-behaving infrastructure could return a 200 OK response code, but with a text string in the body + * + * @param {Response} response The response we received from fetch() + * @returns {|string} The error message from the response + */ +async function getResponseJson(response: Response): Promise { + try { + return (await response.json()) as Promise; // NOTE: `await` here is necessary for errors to be caught by try{} + } catch (e) { + return await response.text(); + } +} + +export async function makeRequest({ + url, + init, +}: { + url: string; + init: RequestInit; +}) { + const response = await fetch(url, { ...init }); + + if (!response.ok) { + const errorMessage = await getResponseErrorMessage(response); + throw new Error(`Failed to make request for wrapped key: ${errorMessage}`); + } + + /** + * + */ + const result = await getResponseJson(response); + + if (typeof result === 'string') { + throw new Error(`Unexpected response from wrapped key service: ${result}`); + } + + return result; +} From 46faa910f92e2c7a007a8ea96c6998d67bcb4a73 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 00:22:44 +0100 Subject: [PATCH 04/30] feat(wrapped-keys): LIT-3125 - Add wrapped keys LIT actions client layer - Methods are responsible for performing generate, signMessage, signTransaction operations using LIT actions - `evm` and `solana` type `network` use our pre-defined actions IPFS CIDs - `custom` type `network` requires the caller provide either LIT action source code or an IPFS CID where the source can be found - Interfaces for executing the LIT actions directly are not exported from the package, so we can change our LIT actions APIs without making breaking changes to the top-level client APIs - Consistent error and response handling is executed for all LIT action executions using methods in `utils` in `lit-actions-client`. --- .../src/lib/lit-actions-client/constants.ts | 18 ++++++ .../lib/lit-actions-client/generate-key.ts | 60 ++++++++++++++++++ .../src/lib/lit-actions-client/index.ts | 9 +++ .../lib/lit-actions-client/sign-message.ts | 58 ++++++++++++++++++ .../lit-actions-client/sign-transaction.ts | 61 +++++++++++++++++++ .../src/lib/lit-actions-client/types.ts | 17 ++++++ .../src/lib/lit-actions-client/utils.ts | 55 +++++++++++++++++ 7 files changed, 278 insertions(+) create mode 100644 packages/wrapped-keys/src/lib/lit-actions-client/constants.ts create mode 100644 packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts create mode 100644 packages/wrapped-keys/src/lib/lit-actions-client/index.ts create mode 100644 packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts create mode 100644 packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts create mode 100644 packages/wrapped-keys/src/lib/lit-actions-client/types.ts create mode 100644 packages/wrapped-keys/src/lib/lit-actions-client/utils.ts diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts b/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts new file mode 100644 index 0000000000..ce90374dbe --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts @@ -0,0 +1,18 @@ +import { LitCidRepository } from './types'; + +const LIT_ACTION_CID_REPOSITORY: LitCidRepository = { + signTransaction: Object.freeze({ + ['evm']: 'QmdYUhPCCK5hpDWMK1NiDLNLG6RZQy61QE4J7dBm1Y2nbA', + ['solana']: 'QmSi9GL2weCFEP1SMAUw5PDpZRr436Zt3tLUNrSECPA5dT', + }), + signMessage: Object.freeze({ + ['evm']: 'QmTMGcyp77NeppGaqF2DmE1F8GXTSxQYzXCrbE7hNudUWx', + ['solana']: 'QmYQC6cd4EMvyB4XPkfEEAwNXJupRZWU5JsTCUrjey4ovp', + }), + generateEncryptedKey: Object.freeze({ + ['evm']: 'QmaoPMSqcze3NW3KSA75ecWSkcmWT1J7kVr8LyJPCKRvHd', + ['solana']: 'QmdRBXYLYvcNHrChmsZ2jFDY8dA99CcSdqHo3p1ES3UThL', + }), +}; + +export { LIT_ACTION_CID_REPOSITORY }; diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts b/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts new file mode 100644 index 0000000000..001bc52fc1 --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts @@ -0,0 +1,60 @@ +import { + ConditionItem, + ILitNodeClient, + SessionSigsMap, +} from '@lit-protocol/types'; + +import { postLitActionValidation } from './utils'; + +interface GeneratePrivateKeyLitActionParams { + pkpSessionSigs: SessionSigsMap; + pkpAddress: string; + litActionIpfsCid?: string; + litActionCode?: string; + accessControlConditions: ConditionItem[]; + litNodeClient: ILitNodeClient; +} + +interface GeneratePrivateKeyLitActionResult { + ciphertext: string; + dataToEncryptHash: string; + publicKey: string; +} + +export async function generateKeyWithLitAction({ + litNodeClient, + pkpSessionSigs, + litActionIpfsCid, + litActionCode, + accessControlConditions, + pkpAddress, +}: GeneratePrivateKeyLitActionParams): Promise { + if (!litActionIpfsCid && !litActionCode) { + throw new Error( + 'Have to provide either the litActionIpfsCid or litActionCode' + ); + } + + if (litActionIpfsCid && litActionCode) { + throw new Error("Can't provide both a litActionIpfsCid or litActionCode"); + } + + try { + const result = await litNodeClient.executeJs({ + sessionSigs: pkpSessionSigs, + ipfsId: litActionIpfsCid, + code: litActionCode, + jsParams: { + pkpAddress, + accessControlConditions, + }, + }); + + const response = postLitActionValidation(result); + return JSON.parse(response); + } catch (err: any) { + throw new Error( + `Lit Action threw an unexpected error: ${JSON.stringify(err)}` + ); + } +} diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/index.ts b/packages/wrapped-keys/src/lib/lit-actions-client/index.ts new file mode 100644 index 0000000000..518465e5bb --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/index.ts @@ -0,0 +1,9 @@ +import { generateKeyWithLitAction } from './generate-key'; +import { signMessageWithLitAction } from './sign-message'; +import { signTransactionWithLitAction } from './sign-transaction'; + +export { + generateKeyWithLitAction, + signTransactionWithLitAction, + signMessageWithLitAction, +}; diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts b/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts new file mode 100644 index 0000000000..711ca706ac --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts @@ -0,0 +1,58 @@ +import { + AccessControlConditions, + ILitNodeClient, + SessionSigsMap, +} from '@lit-protocol/types'; + +import { postLitActionValidation } from './utils'; +import { StoredKeyMetadata } from '../service-client'; +import { Network } from '../types'; + +interface SignMessageWithLitActionParams { + pkpSessionSigs: SessionSigsMap; + litNodeClient: ILitNodeClient; + accessControlConditions: AccessControlConditions; + storedKeyMetadata: StoredKeyMetadata; + network: Network; + litActionIpfsCid?: string; + litActionCode?: string; + params?: Record; + messageToSign: string | Uint8Array; +} + +export async function signMessageWithLitAction( + args: SignMessageWithLitActionParams +) { + const { + accessControlConditions, + litNodeClient, + messageToSign, + pkpSessionSigs, + litActionIpfsCid, + litActionCode, + storedKeyMetadata, + params, + } = args; + + try { + const { pkpAddress, ciphertext, dataToEncryptHash } = storedKeyMetadata; + const result = await litNodeClient.executeJs({ + sessionSigs: pkpSessionSigs, + ipfsId: litActionIpfsCid, + code: litActionCode, + jsParams: { + pkpAddress, + ciphertext, + dataToEncryptHash, + messageToSign, + accessControlConditions, + ...params, + }, + }); + return postLitActionValidation(result); + } catch (err: any) { + throw new Error( + `Lit Action threw an unexpected error: ${JSON.stringify(err)}` + ); + } +} diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts b/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts new file mode 100644 index 0000000000..7160fb2f95 --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts @@ -0,0 +1,61 @@ +import { + AccessControlConditions, + ILitNodeClient, + SessionSigsMap, +} from '@lit-protocol/types'; + +import { postLitActionValidation } from './utils'; +import { StoredKeyMetadata } from '../service-client'; +import { EthereumLitTransaction, SerializedTransaction } from '../types'; + +interface SignTransactionWithLitActionParams { + litNodeClient: ILitNodeClient; + pkpSessionSigs: SessionSigsMap; + litActionIpfsCid?: string; + litActionCode?: string; + unsignedTransaction: EthereumLitTransaction | SerializedTransaction; + storedKeyMetadata: StoredKeyMetadata; + accessControlConditions: AccessControlConditions; + broadcast: boolean; + params?: Record; +} + +export async function signTransactionWithLitAction( + args: SignTransactionWithLitActionParams +): Promise { + const { + storedKeyMetadata, + pkpSessionSigs, + litNodeClient, + unsignedTransaction, + broadcast, + accessControlConditions, + litActionCode, + litActionIpfsCid, + params, + } = args; + + const { ciphertext, dataToEncryptHash, pkpAddress } = storedKeyMetadata; + try { + const result = await litNodeClient.executeJs({ + sessionSigs: pkpSessionSigs, + ipfsId: litActionIpfsCid, + code: litActionCode, + jsParams: { + pkpAddress, + ciphertext, + dataToEncryptHash, + unsignedTransaction, + broadcast, + accessControlConditions, + ...params, + }, + }); + + return postLitActionValidation(result); + } catch (err: any) { + throw new Error( + `Lit Action threw an unexpected error: ${JSON.stringify(err)}` + ); + } +} diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/types.ts b/packages/wrapped-keys/src/lib/lit-actions-client/types.ts new file mode 100644 index 0000000000..1062ad36f8 --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/types.ts @@ -0,0 +1,17 @@ +import { Network } from '../types'; + +export type LitActionType = + | 'signTransaction' + | 'signMessage' + | 'generateEncryptedKey'; + +export type LitActionSupportedNetworks = Extract; + +// 'custom' have no entries in the CID repository, by definition they are external resources. +export type LitCidRepositoryEntry = Readonly< + Record +>; + +export type LitCidRepository = Readonly< + Record +>; diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts b/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts new file mode 100644 index 0000000000..2fc52a04f8 --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts @@ -0,0 +1,55 @@ +import { ExecuteJsResponse } from '@lit-protocol/types'; + +import { LIT_ACTION_CID_REPOSITORY } from './constants'; +import { LitActionSupportedNetworks, LitActionType } from './types'; + +/** + * + * Post processes the Lit Action result to ensure that the result is non-empty and a valid string + * + * @param result - The Lit Action result to be processes + * + * @returns { string } - The response field in the Lit Action result object + */ +export function postLitActionValidation( + result: ExecuteJsResponse | undefined +): string { + // console.log(`Lit Action result: ${JSON.stringify(result)}`); + + if (!result) { + throw new Error('There was an unknown error running the Lit Action.'); + } + + const { response } = result; + if (!response) { + throw new Error( + `Expected "response" in Lit Action result: ${JSON.stringify(result)}` + ); + } + console.log('response', response); + + if (typeof response !== 'string') { + // As the return value is a hex string + throw new Error( + `Lit Action should return a string response: ${JSON.stringify(result)}` + ); + } + + if (!result.success) { + throw new Error(`Expected "success" in res: ${JSON.stringify(result)}`); + } + + if (response.startsWith('Error:')) { + // Lit Action sets an error response + throw new Error(`Error executing the Signing Lit Action: ${response}`); + } + + return response; +} + +export function getLitActionCid( + network: LitActionSupportedNetworks, + actionType: LitActionType +) { + return LIT_ACTION_CID_REPOSITORY[actionType][network]; +} From b05917af05807e40007d5a5ad923a8f80c592b66 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 00:28:05 +0100 Subject: [PATCH 05/30] feat(wrapped-keys): LIT-3125 - Constants, types and tests updates - Update constants for multiple target network support - Move interfaces to more standard-named `types` file - Rename tests to `utils.spec.ts` since it only tests util functions - Update util functions imperative style to use declarative methods for better readability - Update getPkpAddressFromSessionSig() util function to permit more than 3 capabilities to be present without throwing an error - Update `getPkpAccessControlCondition()` to actually return _one condition_, not an array with one condition in it. Type updated accordingly. --- packages/wrapped-keys/src/lib/constants.ts | 35 +-- packages/wrapped-keys/src/lib/interfaces.ts | 99 -------- packages/wrapped-keys/src/lib/types.ts | 190 ++++++++++++++++ .../{wrapped-keys.spec.ts => utils.spec.ts} | 3 +- packages/wrapped-keys/src/lib/utils.ts | 214 ++++-------------- 5 files changed, 236 insertions(+), 305 deletions(-) delete mode 100644 packages/wrapped-keys/src/lib/interfaces.ts create mode 100644 packages/wrapped-keys/src/lib/types.ts rename packages/wrapped-keys/src/lib/{wrapped-keys.spec.ts => utils.spec.ts} (99%) diff --git a/packages/wrapped-keys/src/lib/constants.ts b/packages/wrapped-keys/src/lib/constants.ts index e24bcc721e..ce0ef37ef7 100644 --- a/packages/wrapped-keys/src/lib/constants.ts +++ b/packages/wrapped-keys/src/lib/constants.ts @@ -1,31 +1,8 @@ -const CHAIN_ETHEREUM = 'ethereum'; -const LIT_PREFIX = 'lit_'; -export const NETWORK_EVM = 'evm'; -export const NETWORK_SOLANA = 'solana'; -export type Network = typeof NETWORK_EVM | typeof NETWORK_SOLANA; +import { Network } from './types'; -// Update the endpoint to Wrapped Key project endpoint -const ENCRYPTED_PRIVATE_KEY_ENDPOINT = - 'https://8wugrwstu1.execute-api.us-east-2.amazonaws.com/encrypted'; +export const CHAIN_ETHEREUM = 'ethereum'; +export const LIT_PREFIX = 'lit_'; -const LIT_ACTION_CID_REPOSITORY = Object.freeze({ - signTransactionWithSolanaEncryptedKey: - 'QmSi9GL2weCFEP1SMAUw5PDpZRr436Zt3tLUNrSECPA5dT', - signTransactionWithEthereumEncryptedKey: - 'QmdYUhPCCK5hpDWMK1NiDLNLG6RZQy61QE4J7dBm1Y2nbA', - signMessageWithSolanaEncryptedKey: - 'QmYQC6cd4EMvyB4XPkfEEAwNXJupRZWU5JsTCUrjey4ovp', - signMessageWithEthereumEncryptedKey: - 'QmTMGcyp77NeppGaqF2DmE1F8GXTSxQYzXCrbE7hNudUWx', - generateEncryptedSolanaPrivateKey: - 'QmdRBXYLYvcNHrChmsZ2jFDY8dA99CcSdqHo3p1ES3UThL', - generateEncryptedEthereumPrivateKey: - 'QmaoPMSqcze3NW3KSA75ecWSkcmWT1J7kVr8LyJPCKRvHd', -}); - -export { - CHAIN_ETHEREUM, - ENCRYPTED_PRIVATE_KEY_ENDPOINT, - LIT_ACTION_CID_REPOSITORY, - LIT_PREFIX, -}; +export const NETWORK_EVM: Network = 'evm'; +export const NETWORK_SOLANA: Network = 'solana'; +export const NETWORK_CUSTOM: Network = 'custom'; diff --git a/packages/wrapped-keys/src/lib/interfaces.ts b/packages/wrapped-keys/src/lib/interfaces.ts deleted file mode 100644 index df2813bac0..0000000000 --- a/packages/wrapped-keys/src/lib/interfaces.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { ILitNodeClient, SessionSigsMap } from '@lit-protocol/types'; -import { Network } from './constants'; - -export interface StoreToDatabaseParams { - ciphertext: string; - dataToEncryptHash: string; -} - -export interface CustomGeneratePrivateKeyParams { - pkpSessionSigs: SessionSigsMap; - litActionIpfsCid?: string; - litActionCode?: string; - litNodeClient: ILitNodeClient; -} - -export interface GeneratePrivateKeyParams { - pkpSessionSigs: SessionSigsMap; - network: Network; - litNodeClient: ILitNodeClient; -} - -export interface GeneratePrivateKeyResponse { - pkpAddress: string; - generatedPublicKey: string; -} - -export interface ImportPrivateKeyParams { - pkpSessionSigs: SessionSigsMap; - privateKey: string; - litNodeClient: ILitNodeClient; -} - -export interface ImportPrivateKeyResponse { - pkpAddress: string; -} - -export interface ExportPrivateKeyParams { - pkpSessionSigs: SessionSigsMap; - litNodeClient: ILitNodeClient; -} - -export interface ExportPrivateKeyResponse { - pkpAddress: string; - ciphertext: string; - dataToEncryptHash: string; -} - -export interface CustomSignMessageWithEncryptedKeyParams { - pkpSessionSigs: SessionSigsMap; - litActionIpfsCid?: string; - litActionCode?: string; - messageToSign: string | Uint8Array; - params?: Record; - litNodeClient: ILitNodeClient; -} - -export interface SignMessageWithEncryptedKeyParams { - pkpSessionSigs: SessionSigsMap; - network: Network; - messageToSign: string | Uint8Array; - litNodeClient: ILitNodeClient; -} - -export interface SignTransactionWithEncryptedKeyParams { - pkpSessionSigs: SessionSigsMap; - network: Network; - unsignedTransaction: T; - broadcast: boolean; - litNodeClient: ILitNodeClient; -} - -export interface CustomSignTransactionWithEncryptedKeyParams { - pkpSessionSigs: SessionSigsMap; - litActionIpfsCid?: string; - litActionCode?: string; - serializedTransaction: string; - broadcast: boolean; - params?: Record; - litNodeClient: ILitNodeClient; -} - -interface BaseLitTransaction { - chain: string; -} - -export interface EthereumLitTransaction extends BaseLitTransaction { - toAddress: string; - value: string; - chainId: number; - gasPrice?: string; - gasLimit?: number; - dataHex?: string; -} - -export interface SolanaLitTransaction extends BaseLitTransaction { - serializedTransaction: string; -} - -export type LitTransaction = EthereumLitTransaction | SolanaLitTransaction; diff --git a/packages/wrapped-keys/src/lib/types.ts b/packages/wrapped-keys/src/lib/types.ts new file mode 100644 index 0000000000..4c313db404 --- /dev/null +++ b/packages/wrapped-keys/src/lib/types.ts @@ -0,0 +1,190 @@ +import { ILitNodeClient, SessionSigsMap } from '@lit-protocol/types'; + +/** @typedef Network + * The network type that the wrapped key is for. + * In case of 'evm' or 'solana', pre-written LIT actions will be used to perform operations + * In case of 'custom', you will need to provide a LIT action source code or an IPFS CID where LIT action source code exists in order to perform the operation when you call API methods + */ +export type Network = 'evm' | 'solana' | 'custom'; + +/** All API calls for the wrapped keys service require these arguments. + * + * @typedef BaseApiParams + * @property {SessionSigsMap} pkpSessionSigs - The PKP sessionSigs used to associate the PKP with the generated private key and authenticate with the wrapped keys backend service. + * @property {ILitNodeClient} litNodeClient - The Lit Node Client used for executing the Lit Action and identifying which wrapped keys backend service to communicate with. + */ +export interface BaseApiParams { + pkpSessionSigs: SessionSigsMap; + litNodeClient: ILitNodeClient; +} + +export interface ApiParamsSupportedNetworks { + network: Extract; +} + +export interface ApiParamsCustomIpfs extends BaseApiParams { + network: Extract; + litActionIpfsCid: string; + params?: Record; +} + +export interface ApiParamsCustomCode extends BaseApiParams { + network: Extract; + litActionCode: string; + params?: Record; +} + +/** Fetching a previously persisted key's metadata only requires valid pkpSessionSigs and a LIT Node Client instance configured for the appropriate network. + * + * @typedef GetEncryptedKeyMetadataParams + * @extends BaseApiParams + * + */ +export type GetEncryptedKeyMetadataParams = BaseApiParams; + +/** Exporting a previously persisted key only requires valid pkpSessionSigs and a LIT Node Client instance configured for the appropriate network. + * + * @typedef ExportPrivateKeyParams + * @extends BaseApiParams + * + */ +export type ExportPrivateKeyParams = BaseApiParams; + +type GeneratePrivateKeyParamsSupportedNetworks = BaseApiParams & + ApiParamsSupportedNetworks; +type GeneratePrivateKeyParamsCustomIpfs = BaseApiParams & ApiParamsCustomIpfs; +type GeneratePrivateKeyParamsCustomCode = BaseApiParams & ApiParamsCustomCode; + +/** @typedef GeneratePrivateKeyParams + * @extends BaseApiParams + * @property {Network} network The network for which the private key needs to be generated; keys are generated differently for different networks + * @property {string} [litActionIpfsCid] The IPFS CID of the LIT Action to run which will be responsible for generating the key + * @property {string} [litActionCode] A string of the raw source code of the LIT Action to run which will be responsible for generating the key + * @property {object} [params] Additional parameters to be passed through to the LIT action that is performing the key generation + */ +export type GeneratePrivateKeyParams = + | GeneratePrivateKeyParamsSupportedNetworks + | GeneratePrivateKeyParamsCustomIpfs + | GeneratePrivateKeyParamsCustomCode; + +/** @typedef GeneratePrivateKeyResult + * @property { string } pkpAddress The LIT PKP Address that the key was linked to; this is derived from the provided pkpSessionSigs + * @property { string } generatedPublicKey The public key component of the newly generated keypair + * + */ +export interface GeneratePrivateKeyResult { + pkpAddress: string; + generatedPublicKey: string; +} + +/** @typedef ImportPrivateKeyParams + * @extends BaseApiParams + * + * @property { string } privateKey The private key to be imported into the wrapped keys service + * @property { string } address The 'address' is typically the public key of the key being imported into the wrapped keys service + * @property { string } algo The algorithm type of the key; this might be K256, ed25519, or other key formats. The `algo` will be included in the metadata returned from the wrapped keys service + */ +export interface ImportPrivateKeyParams extends BaseApiParams { + privateKey: string; + address: string; + algo: string; +} + +interface SignMessageParams { + messageToSign: string | Uint8Array; +} + +type SignMessageWithEncryptedKeyParamsSupportedNetworks = BaseApiParams & + ApiParamsSupportedNetworks & + SignMessageParams; + +type SignMessageWithEncryptedKeyParamsCustomIpfs = BaseApiParams & + ApiParamsCustomIpfs & + SignMessageParams; + +type SignMessageWithEncryptedKeyParamsCustomCode = BaseApiParams & + ApiParamsCustomCode & + SignMessageParams; + +/** @typedef SignMessageWithEncryptedKeyParams + * @extends BaseApiParams + * + * @property { string | Uint8Array } messageToSign The message to be signed + * @property {string} [litActionIpfsCid] The IPFS CID of the LIT Action to run which will be responsible for generating the key. Only relevant when using network is `custom`. You can only include this OR litActionCode. + * @property {string} [litActionCode] A string of the raw source code of the LIT Action to run which will be responsible for generating the key. Only relevant when using `custom` network. You can only include this OR litActionIpfsCid. + * @property {object} [params] Additional parameters to be passed through to the LIT action that is signing the provided message + */ +export type SignMessageWithEncryptedKeyParams = + | SignMessageWithEncryptedKeyParamsSupportedNetworks + | SignMessageWithEncryptedKeyParamsCustomIpfs + | SignMessageWithEncryptedKeyParamsCustomCode; + +interface BaseLitTransaction { + chain: string; +} + +/** EthereumLitTransaction must be provided to the `SignTransaction` endpoint when `network` is `evm`. + * + * @typedef EthereumLitTransaction + * + * @property { string } toAddress The address the transaction is 'to' + * @property { string } value The value of the transaction to be sent + * @property { number } chainId The chain ID of the target chain that the transaction will be executed on + * @property { string } [gasPrice] The exact gas price that you are willing to pay to execute the transaction + * @property { string } [gasLimit] The maximum gas price that you are willing to pay to execute the transaction + * @property { string } [dataHex] Data in hex format to be included in the transaction + * + */ +export interface EthereumLitTransaction extends BaseLitTransaction { + toAddress: string; + value: string; + chainId: number; + gasPrice?: string; + gasLimit?: number; + dataHex?: string; +} + +export interface SerializedTransaction extends BaseLitTransaction { + serializedTransaction: string; +} + +interface SignTransactionParams extends BaseApiParams { + broadcast: boolean; +} + +interface SignTransactionParamsSupportedEvm extends SignTransactionParams { + unsignedTransaction: EthereumLitTransaction; + network: Extract; +} + +interface SignTransactionParamsSupportedSolana extends SignTransactionParams { + unsignedTransaction: SerializedTransaction; + network: Extract; +} + +interface SignTransactionWithEncryptedKeyParamsCustomIpfs + extends SignTransactionParams, + ApiParamsCustomIpfs { + unsignedTransaction: SerializedTransaction; +} + +interface SignTransactionWithEncryptedKeyParamsCustomCode + extends SignTransactionParams, + ApiParamsCustomCode { + unsignedTransaction: SerializedTransaction; +} + +/** @typedef SignTransactionWithEncryptedKeyParams + * @extends BaseApiParams + * @property { boolean } broadcast Whether the LIT action should broadcast the signed transaction to RPC, or only sign the transaction and return the signed transaction to the caller + * @property { EthereumLitTransaction | SerializedTransaction } unsignedTransaction The unsigned transaction to be signed. When network is 'solana' or 'custom', be sure to provided a {@link SerializedTransaction} instance. + * @property {string} [litActionIpfsCid] The IPFS CID of the LIT Action to run which will be responsible for generating the key. Only relevant when using network is `custom`. You can only include this OR litActionCode. + * @property {string} [litActionCode] A string of the raw source code of the LIT Action to run which will be responsible for generating the key. Only relevant when using `custom` network. You can only include this OR litActionIpfsCid. + * @property {object} [params] Additional parameters to be passed through to the LIT action that is signing the provided transaction + * + */ +export type SignTransactionWithEncryptedKeyParams = + | SignTransactionParamsSupportedEvm + | SignTransactionParamsSupportedSolana + | SignTransactionWithEncryptedKeyParamsCustomIpfs + | SignTransactionWithEncryptedKeyParamsCustomCode; diff --git a/packages/wrapped-keys/src/lib/wrapped-keys.spec.ts b/packages/wrapped-keys/src/lib/utils.spec.ts similarity index 99% rename from packages/wrapped-keys/src/lib/wrapped-keys.spec.ts rename to packages/wrapped-keys/src/lib/utils.spec.ts index cbf1461795..24dfe55b4f 100644 --- a/packages/wrapped-keys/src/lib/wrapped-keys.spec.ts +++ b/packages/wrapped-keys/src/lib/utils.spec.ts @@ -3,12 +3,13 @@ import { SessionKeySignedMessage, SessionSigsMap, } from '@lit-protocol/types'; + +import { CHAIN_ETHEREUM } from './constants'; import { getFirstSessionSig, getPkpAccessControlCondition, getPkpAddressFromSessionSig, } from './utils'; -import { CHAIN_ETHEREUM } from './constants'; describe('getFirstSessionSig from sessionSigs record', () => { const sessionSigs: SessionSigsMap = { diff --git a/packages/wrapped-keys/src/lib/utils.ts b/packages/wrapped-keys/src/lib/utils.ts index ae2a9aff04..0c4dd71e3e 100644 --- a/packages/wrapped-keys/src/lib/utils.ts +++ b/packages/wrapped-keys/src/lib/utils.ts @@ -1,39 +1,36 @@ +import { ethers } from 'ethers'; + +import { log } from '@lit-protocol/misc'; import { - AccessControlConditions, AuthSig, - ExecuteJsResponse, + ConditionItem, SessionKeySignedMessage, SessionSigsMap, } from '@lit-protocol/types'; -import { log, logError } from '@lit-protocol/misc'; -import { CHAIN_ETHEREUM, ENCRYPTED_PRIVATE_KEY_ENDPOINT } from './constants'; -import { ethers } from 'ethers'; -import { - ExportPrivateKeyResponse, - ImportPrivateKeyResponse, - StoreToDatabaseParams, -} from './interfaces'; + +import { CHAIN_ETHEREUM } from './constants'; /** * * Extracts the first SessionSig from the SessionSigsMap since we only pass a single SessionSig to the AWS endpoint * - * @param pkpSessionSigs - The PKP sessionSigs (map) used to associated the PKP with the generated private key + * @param pkpSessionSigs - The PKP sessionSigs (map) used to associate the PKP with the generated private key * * @returns { AuthSig } - The first SessionSig from the map */ export function getFirstSessionSig(pkpSessionSigs: SessionSigsMap): AuthSig { - const keys = Object.keys(pkpSessionSigs); - if (keys.length === 0) { + const sessionSigsEntries = Object.entries(pkpSessionSigs); + + if (sessionSigsEntries.length === 0) { throw new Error( `Invalid pkpSessionSigs, length zero: ${JSON.stringify(pkpSessionSigs)}` ); } - const firstSessionSig: AuthSig = pkpSessionSigs[keys[0]]; - log(`Session Sig being used: ${JSON.stringify(firstSessionSig)}`); + const [[, sessionSig]] = sessionSigsEntries; + log(`Session Sig being used: ${JSON.stringify(sessionSig)}`); - return firstSessionSig; + return sessionSig; } /** @@ -50,188 +47,53 @@ export function getPkpAddressFromSessionSig(pkpSessionSig: AuthSig): string { ); const capabilities = sessionSignedMessage.capabilities; - if (capabilities.length > 3) { + + if (!capabilities || capabilities.length === 0) { throw new Error( - `At max 3 elements can be in the capabilities array but there are: ${capabilities.length}` + `Capabilities in the session's signedMessage is empty, but required.` ); } - for (const innerAuthSig of capabilities) { - const delegationAuthSig: AuthSig = JSON.parse(JSON.stringify(innerAuthSig)); // Had to stringify as it was throwing SyntaxError: "[object Object]" is not valid JSON - - if (delegationAuthSig.algo !== 'LIT_BLS') { - continue; - } + const delegationAuthSig = capabilities.find(({ algo }) => algo === 'LIT_BLS'); - const pkpAddress = delegationAuthSig.address; - - log(`pkpAddress to permit decryption: ${pkpAddress}`); - - return pkpAddress; + if (!delegationAuthSig) { + throw new Error( + 'SessionSig is not from a PKP; no LIT_BLS capabilities found' + ); } - throw new Error('SessionSig is not from a PKP'); + const pkpAddress = delegationAuthSig.address; + log(`pkpAddress to permit decryption: ${pkpAddress}`); + + return pkpAddress; } /** * * Creates the access control condition used to gate the access for Wrapped Key decryption * - * @param pkpAddress - The wallet address of the PKP which can decrypt the encrypted Wrapped Key + * @param { string } pkpAddress - The wallet address of the PKP which can decrypt the encrypted Wrapped Key * - * @returns { AccessControlConditions } - The access control condition that only allows the PKP address to decrypt + * @returns { ConditionItem } - The access control condition that only allows the PKP address to decrypt */ export function getPkpAccessControlCondition( pkpAddress: string -): AccessControlConditions { +): ConditionItem { if (!ethers.utils.isAddress(pkpAddress)) { throw new Error( `pkpAddress is not a valid Ethereum Address: ${pkpAddress}` ); } - return [ - { - contractAddress: '', - standardContractType: '', - chain: CHAIN_ETHEREUM, - method: '', - parameters: [':userAddress'], - returnValueTest: { - comparator: '=', - value: pkpAddress, - }, + return { + contractAddress: '', + standardContractType: '', + chain: CHAIN_ETHEREUM, + method: '', + parameters: [':userAddress'], + returnValueTest: { + comparator: '=', + value: pkpAddress, }, - ]; -} - -/** - * - * Extracts the first SessionSig item from the map and uses it to fetch the stored database item - * - * @param pkpSessionSigs - The PKP which is used to fetch the DynamoDB item - * - * @returns { ExportPrivateKeyResponse } - The DynamoDB item with all its attributes - */ -export async function fetchPrivateKeyMedataFromDatabase( - pkpSessionSigs: SessionSigsMap -): Promise { - const firstSessionSig = getFirstSessionSig(pkpSessionSigs); - - try { - const response = await fetch(ENCRYPTED_PRIVATE_KEY_ENDPOINT, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - pkpsessionsig: JSON.stringify(firstSessionSig), - }, - }); - - if (!response.ok) { - const errorBody = await response.text(); - logError( - `Could not fetch the encrypted key due to the error: ${errorBody}` - ); - - throw new Error(errorBody); - } - - return await response.json(); - } catch (error) { - const errorMessage = `There was a problem fetching from the database: ${error}`; - console.error(errorMessage); - - throw new Error(errorMessage); - } -} - -/** - * - * Store the encrypted private key into the database - * - * @param data - The encrypted data to be stored in the database (ciphertext, dataToEncryptHash) - * @param pkpSessionSigs - The PKP which is used to fetch the DynamoDB item - * - * @returns { ImportPrivateKeyResponse } - The PKP EthAddress of the associated PKP - */ -export async function storePrivateKeyMetadataToDatabase( - data: StoreToDatabaseParams, - firstSessionSig: AuthSig -): Promise { - try { - const response = await fetch(ENCRYPTED_PRIVATE_KEY_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - pkpsessionsig: JSON.stringify(firstSessionSig), - }, - body: JSON.stringify(data), - }); - - if (!response.ok) { - const errorBody = await response.text(); - logError( - `Could not import the encrypted key due to the error: ${errorBody}` - ); - - throw new Error(errorBody); - } - - return await response.json(); - } catch (error) { - const errorMessage = `There was a problem fetching from the database: ${error}`; - console.error(errorMessage); - - throw new Error(errorMessage); - } -} - -/** - * - * Post processes the Lit Action result to ensure that the result is non-empty and a valid string - * - * @param result - The Lit Action result to be processes - * - * @returns { string } - The response field in the Lit Action result object - */ -export function postLitActionValidation( - result: ExecuteJsResponse | undefined -): string { - // console.log(`Lit Action result: ${JSON.stringify(result)}`); - - if (!result) { - throw new Error('There was some error running the Lit Action'); - } - - const response = result.response; - // console.log('response'); - // console.log(response); - - if (!response) { - throw new Error( - `Expected "response" in Lit Action result: ${JSON.stringify(result)}` - ); - } - - if (typeof response !== 'string') { - // As the return value is a hex string - throw new Error( - `Lit Action should return a string response: ${JSON.stringify(result)}` - ); - } - - if (!result.success) { - throw new Error(`Expected "success" in res: ${JSON.stringify(result)}`); - } - - if (result.success !== true) { - throw new Error(`Expected "success" to be true: ${JSON.stringify(result)}`); - } - - if (response.startsWith('Error:')) { - // Lit Action sets an error response - throw new Error(`Error executing the Signing Lit Action: ${response}`); - } - - return response; + }; } From ad58e5a9d79c7f27251f36c67faac5b97260f81b Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 01:00:00 +0100 Subject: [PATCH 06/30] chore(wrapped-keys): LIT-3125 - Add note to LIT action about missing txHash return in solana action --- local-tests/setup/tinny-operations.ts | 134 +++++++++--------- .../signTransactionWithSolanaEncryptedKey.js | 2 +- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/local-tests/setup/tinny-operations.ts b/local-tests/setup/tinny-operations.ts index c7667d61b2..28bc2b370e 100644 --- a/local-tests/setup/tinny-operations.ts +++ b/local-tests/setup/tinny-operations.ts @@ -61,35 +61,35 @@ export const runInBand = async ({ while (attempts < maxAttempts && !testPassed) { const startTime = performance.now(); - try { - console.log(`Attempt ${attempts + 1} for ${testName}...`); - - // @ts-ignore - await testFunction(devEnv); - testPassed = true; - - const endTime = performance.now(); - const timeTaken = (endTime - startTime).toFixed(2); - console.log(`${testName} - Passed (${timeTaken} ms)`); - passedTests.push(`${testName} (Passed in ${timeTaken} ms)`); - } catch (error) { - if (error.message === 'LIT_IGNORE_TEST') { - skippedTests.push(`${testName} (Skipped)`); - break; - } - attempts++; - if (attempts >= maxAttempts) { - const endTime = performance.now(); - const timeTaken = (endTime - startTime).toFixed(2); - console.error( - `${testName} - Failed after ${maxAttempts} attempts (${timeTaken} ms)` - ); - console.error(`Error: ${error}`); - failedTests.push( - `${testName} (Failed in ${timeTaken} ms) - Error: ${error}` - ); - } - } + // try { + console.log(`Attempt ${attempts + 1} for ${testName}...`); + + // @ts-ignore + await testFunction(devEnv); + testPassed = true; + + const endTime = performance.now(); + const timeTaken = (endTime - startTime).toFixed(2); + console.log(`${testName} - Passed (${timeTaken} ms)`); + passedTests.push(`${testName} (Passed in ${timeTaken} ms)`); + // } catch (error) { + // if (error.message === 'LIT_IGNORE_TEST') { + // skippedTests.push(`${testName} (Skipped)`); + // break; + // } + // attempts++; + // if (attempts >= maxAttempts) { + // const endTime = performance.now(); + // const timeTaken = (endTime - startTime).toFixed(2); + // console.error( + // `${testName} - Failed after ${maxAttempts} attempts (${timeTaken} ms)` + // ); + // console.error(`Error: ${error}`); + // failedTests.push( + // `${testName} (Failed in ${timeTaken} ms) - Error: ${error}` + // ); + // } + // } await new Promise((resolve) => setTimeout(resolve, devEnv.processEnvs.RUN_IN_BAND_INTERVAL) @@ -154,44 +154,44 @@ export const runTestsParallel = async ({ while (attempts < maxAttempts && !testPassed) { const startTime = performance.now(); - try { - console.log( - `\x1b[90m[runTestsParallel] Attempt ${attempts + 1} for ${ - testIndex + 1 - }. ${testName}...\x1b[0m` - ); - - // @ts-ignore - await testFunction(devEnv); - testPassed = true; - - const endTime = performance.now(); - const timeTaken = (endTime - startTime).toFixed(2); - console.log( - `\x1b[32m✔\x1b[90m ${ - testIndex + 1 - }. ${testName} - Passed (${timeTaken} ms)\x1b[0m` - ); - return `${testName} (Passed in ${timeTaken} ms)`; - } catch (error) { - if (error.message === 'LIT_IGNORE_TEST') { - return `${testName} (Skipped)`; - } - attempts++; - - // wait for at least 5 seconds - if (attempts >= maxAttempts) { - const endTime = performance.now(); - const timeTaken = (endTime - startTime).toFixed(2); - console.error( - `\x1b[31m✖\x1b[90m ${ - testIndex + 1 - }. ${testName} - Failed after ${maxAttempts} attempts (${timeTaken} ms)\x1b[0m` - ); - console.error(`\x1b[31m❌Error:\x1b[90m ${error}\x1b[0m`); - return `${testName} (Failed in ${timeTaken} ms) - Error: ${error}`; - } - } + // try { + console.log( + `\x1b[90m[runTestsParallel] Attempt ${attempts + 1} for ${ + testIndex + 1 + }. ${testName}...\x1b[0m` + ); + + // @ts-ignore + await testFunction(devEnv); + testPassed = true; + + const endTime = performance.now(); + const timeTaken = (endTime - startTime).toFixed(2); + console.log( + `\x1b[32m✔\x1b[90m ${ + testIndex + 1 + }. ${testName} - Passed (${timeTaken} ms)\x1b[0m` + ); + return `${testName} (Passed in ${timeTaken} ms)`; + // } catch (error) { + // if (error.message === 'LIT_IGNORE_TEST') { + // return `${testName} (Skipped)`; + // } + // attempts++; + // + // // wait for at least 5 seconds + // if (attempts >= maxAttempts) { + // const endTime = performance.now(); + // const timeTaken = (endTime - startTime).toFixed(2); + // console.error( + // `\x1b[31m✖\x1b[90m ${ + // testIndex + 1 + // }. ${testName} - Failed after ${maxAttempts} attempts (${timeTaken} ms)\x1b[0m` + // ); + // console.error(`\x1b[31m❌Error:\x1b[90m ${error}\x1b[0m`); + // return `${testName} (Failed in ${timeTaken} ms) - Error: ${error}`; + // } + // } } } ); diff --git a/packages/wrapped-keys/src/lib/litActions/solana/src/signTransactionWithSolanaEncryptedKey.js b/packages/wrapped-keys/src/lib/litActions/solana/src/signTransactionWithSolanaEncryptedKey.js index a1e8706ce7..c398eef491 100644 --- a/packages/wrapped-keys/src/lib/litActions/solana/src/signTransactionWithSolanaEncryptedKey.js +++ b/packages/wrapped-keys/src/lib/litActions/solana/src/signTransactionWithSolanaEncryptedKey.js @@ -82,7 +82,7 @@ const { clusterApiUrl(unsignedTransaction.chain), 'confirmed' ); - await solanaConnection.sendRawTransaction(transaction.serialize()); + await solanaConnection.sendRawTransaction(transaction.serialize()); // FIXME: Shouldn't this return the tx hash for consistency with the evm action? } } catch (error) { Lit.Actions.setResponse({ From cba8d1d7d0431134c0da779f32e5e78caf357b59 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 01:01:44 +0100 Subject: [PATCH 07/30] chore(wrapped-keys): LIT-3125 - Add return type interface for export private key action with JSDoc comment --- packages/wrapped-keys/src/lib/types.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/wrapped-keys/src/lib/types.ts b/packages/wrapped-keys/src/lib/types.ts index 4c313db404..9af360d6d4 100644 --- a/packages/wrapped-keys/src/lib/types.ts +++ b/packages/wrapped-keys/src/lib/types.ts @@ -1,4 +1,8 @@ -import { ILitNodeClient, SessionSigsMap } from '@lit-protocol/types'; +import { + ILitNodeClient, + LIT_NETWORKS_KEYS, + SessionSigsMap, +} from '@lit-protocol/types'; /** @typedef Network * The network type that the wrapped key is for. @@ -50,6 +54,24 @@ export type GetEncryptedKeyMetadataParams = BaseApiParams; */ export type ExportPrivateKeyParams = BaseApiParams; +/** Includes the decrypted private key and metadata that was stored alongside it in the wrapped keys service + * + * @typedef ExportPrivateKeyResult + * @property { LIT_NETWORKS_KEYS } litNetwork The LIT network that the LIT Node Client was configured for when the key was persisted to the wrapped keys service + * @property { string } decryptedPrivateKey The decrypted, plain text private key that was persisted to the wrapped keys service + * @property { string } pkpAddress The LIT PKP Address that the key was linked to; this is derived from the provided pkpSessionSigs + * @property { string } address The 'address' is typically based on the public key of the key being imported into the wrapped keys service + * @property { string } algo The algorithm type of the key; this might be K256, ed25519, or other key formats. The `algo` will be included in the metadata returned from the wrapped keys service + * + */ +export interface ExportPrivateKeyResult { + pkpAddress: string; + decryptedPrivateKey: string; + address: string; + litNetwork: LIT_NETWORKS_KEYS; + algo: string; +} + type GeneratePrivateKeyParamsSupportedNetworks = BaseApiParams & ApiParamsSupportedNetworks; type GeneratePrivateKeyParamsCustomIpfs = BaseApiParams & ApiParamsCustomIpfs; @@ -81,7 +103,7 @@ export interface GeneratePrivateKeyResult { * @extends BaseApiParams * * @property { string } privateKey The private key to be imported into the wrapped keys service - * @property { string } address The 'address' is typically the public key of the key being imported into the wrapped keys service + * @property { string } address The 'address' is typically based on the public key of the key being imported into the wrapped keys service * @property { string } algo The algorithm type of the key; this might be K256, ed25519, or other key formats. The `algo` will be included in the metadata returned from the wrapped keys service */ export interface ImportPrivateKeyParams extends BaseApiParams { From e3d2055e1776fc253a500bcca10bfa7d7c8c0217 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 01:04:39 +0100 Subject: [PATCH 08/30] feat(wrapped-keys): LIT-3125 - Implement main API layer for wrapped keys - Glues together service-client and lit-action-client appropriately with public API surface area to be exposed to consumers of the package - Updated JSDocs on exported functions to reference types instead of repeating mostly the same strings on each function's JSDoc - Added `getEncryptedKeyMetadata` method to facilitate arbitrary usage of the encrypted key without needing to use our built-in logic/assumptions around LIT actions, and to allow callers to fetch the `address` and other metadata that is being persisted to the backend - Remove legacy `wrapped-keys.ts` file as its logic has been migrated into `api` --- .../src/lib/api/export-private-key.ts | 55 ++ .../src/lib/api/generate-private-key.ts | 60 +++ .../src/lib/api/get-encrypted-key-metadata.ts | 19 + .../src/lib/api/import-private-key.ts | 53 ++ packages/wrapped-keys/src/lib/api/index.ts | 15 + .../api/sign-message-with-encrypted-key.ts | 43 ++ .../sign-transaction-with-encrypted-key.ts | 43 ++ packages/wrapped-keys/src/lib/wrapped-keys.ts | 485 ------------------ 8 files changed, 288 insertions(+), 485 deletions(-) create mode 100644 packages/wrapped-keys/src/lib/api/export-private-key.ts create mode 100644 packages/wrapped-keys/src/lib/api/generate-private-key.ts create mode 100644 packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts create mode 100644 packages/wrapped-keys/src/lib/api/import-private-key.ts create mode 100644 packages/wrapped-keys/src/lib/api/index.ts create mode 100644 packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts create mode 100644 packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts delete mode 100644 packages/wrapped-keys/src/lib/wrapped-keys.ts diff --git a/packages/wrapped-keys/src/lib/api/export-private-key.ts b/packages/wrapped-keys/src/lib/api/export-private-key.ts new file mode 100644 index 0000000000..4425a8d893 --- /dev/null +++ b/packages/wrapped-keys/src/lib/api/export-private-key.ts @@ -0,0 +1,55 @@ +import { decryptToString } from '@lit-protocol/encryption'; + +import { CHAIN_ETHEREUM, LIT_PREFIX } from '../constants'; +import { fetchPrivateKeyMetadata } from '../service-client'; +import { ExportPrivateKeyParams, ExportPrivateKeyResult } from '../types'; +import { + getFirstSessionSig, + getPkpAccessControlCondition, + getPkpAddressFromSessionSig, +} from '../utils'; + +/** Exports a previously persisted private key from the wrapped keys service for direct use by the caller, along with the keys metadata + * + * @param { ExportPrivateKeyParams } params Parameters required to export the private key + */ +export async function exportPrivateKey( + params: ExportPrivateKeyParams +): Promise { + const { pkpSessionSigs, litNodeClient } = params; + + const sessionSig = getFirstSessionSig(pkpSessionSigs); + const pkpAddress = getPkpAddressFromSessionSig(sessionSig); + const allowPkpAddressToDecrypt = getPkpAccessControlCondition(pkpAddress); + + const privateKeyMetadata = await fetchPrivateKeyMetadata({ + sessionSig, + litNodeClient, + }); + + const { ciphertext, dataToEncryptHash, ...privateKeyMetadataMinusEncrypted } = + privateKeyMetadata; + + const decryptedPrivateKey = await decryptToString( + { + accessControlConditions: [allowPkpAddressToDecrypt], + chain: CHAIN_ETHEREUM, // FIXME: This won't always be true. + ciphertext, + dataToEncryptHash, + sessionSigs: pkpSessionSigs, + }, + litNodeClient + ); + + // It will be of the form lit_ + if (!decryptedPrivateKey.startsWith(LIT_PREFIX)) { + throw new Error( + `PKey was not encrypted with salt; all wrapped keys must be prefixed with '${LIT_PREFIX}'` + ); + } + + return { + decryptedPrivateKey: decryptedPrivateKey.slice(LIT_PREFIX.length), + ...privateKeyMetadataMinusEncrypted, + }; +} diff --git a/packages/wrapped-keys/src/lib/api/generate-private-key.ts b/packages/wrapped-keys/src/lib/api/generate-private-key.ts new file mode 100644 index 0000000000..381ce3ee96 --- /dev/null +++ b/packages/wrapped-keys/src/lib/api/generate-private-key.ts @@ -0,0 +1,60 @@ +import { LIT_CURVE } from '@lit-protocol/constants'; + +import { generateKeyWithLitAction } from '../lit-actions-client'; +import { getLitActionCid } from '../lit-actions-client/utils'; +import { storePrivateKeyMetadata } from '../service-client'; +import { GeneratePrivateKeyParams, GeneratePrivateKeyResult } from '../types'; +import { + getFirstSessionSig, + getPkpAccessControlCondition, + getPkpAddressFromSessionSig, +} from '../utils'; + +/** + * Generates a random private key inside a Lit Action, and persists the key and its metadata to the wrapped keys service. + * Returns the public key of the random private key, and the PKP address that it was associated with. + * We don't return the generated wallet address since it can be derived from the publicKey + * + * The key will be associated with the PKP address embedded in the `pkpSessionSigs` you provide. One and only one wrapped key can be associated with a given LIT PKP. + * + * @param { GeneratePrivateKeyParams } params - Required parameters to generate the private key + * + * @returns { Promise } - The publicKey of the generated random private key and the LIT PKP Address associated with the Wrapped Key + */ +export async function generatePrivateKey( + params: GeneratePrivateKeyParams +): Promise { + const { pkpSessionSigs, network, litNodeClient } = params; + + const firstSessionSig = getFirstSessionSig(pkpSessionSigs); + const pkpAddress = getPkpAddressFromSessionSig(firstSessionSig); + const allowPkpAddressToDecrypt = getPkpAccessControlCondition(pkpAddress); + + const { ciphertext, dataToEncryptHash, publicKey } = + await generateKeyWithLitAction({ + litNodeClient, + pkpSessionSigs, + pkpAddress, + ...(network === 'evm' || network == 'solana' + ? { litActionIpfsCid: getLitActionCid(network, 'generateEncryptedKey') } + : {}), + accessControlConditions: [allowPkpAddressToDecrypt], + }); + + await storePrivateKeyMetadata({ + sessionSig: firstSessionSig, + storedKeyMetadata: { + ciphertext, + address: publicKey, // FIXME: If we're storing address and it is _not_ the publicKey directly, then we need the generate LIT action to return it for us + algo: LIT_CURVE.EcdsaK256, // FIXME: Should be returned by the LIT action; we won't know what it is unless it's provided. + dataToEncryptHash, + pkpAddress, + }, + litNodeClient, + }); + + return { + pkpAddress, + generatedPublicKey: publicKey, + }; +} diff --git a/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts b/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts new file mode 100644 index 0000000000..b9f43d04de --- /dev/null +++ b/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts @@ -0,0 +1,19 @@ +import { fetchPrivateKeyMetadata, StoredKeyMetadata } from '../service-client'; +import { GetEncryptedKeyMetadataParams } from '../types'; +import { getFirstSessionSig } from '../utils'; + +/** Get a previously encrypted and persisted private key and its metadata. + * Note that this method does _not_ decrypt the private key; only the _encrypted_ key and its metadata will be returned to the caller. + * + * @param { GetEncryptedKeyMetadataParams } params Parameters required to fetch the encrypted private key metadata + * @returns { Promise } The encrypted private key and its associated metadata + */ +export async function getEncryptedKeyMetadata( + params: GetEncryptedKeyMetadataParams +): Promise { + const { pkpSessionSigs, litNodeClient } = params; + return fetchPrivateKeyMetadata({ + sessionSig: getFirstSessionSig(pkpSessionSigs), + litNodeClient, + }); +} diff --git a/packages/wrapped-keys/src/lib/api/import-private-key.ts b/packages/wrapped-keys/src/lib/api/import-private-key.ts new file mode 100644 index 0000000000..43edfc1fdb --- /dev/null +++ b/packages/wrapped-keys/src/lib/api/import-private-key.ts @@ -0,0 +1,53 @@ +import { encryptString } from '@lit-protocol/encryption'; + +import { LIT_PREFIX } from '../constants'; +import { storePrivateKeyMetadata } from '../service-client'; +import { ImportPrivateKeyParams } from '../types'; +import { + getFirstSessionSig, + getPkpAccessControlCondition, + getPkpAddressFromSessionSig, +} from '../utils'; + +/** + * Import a provided private key into the wrapped keys service backend. + * First, the key is pre-pended with `LIT_PREFIX` for security reasons, then the salted key is encrypted and stored in the backend service. + * The key will be associated with the PKP address embedded in the `pkpSessionSigs` you provide. One and only one wrapped key can be associated with a given LIT PKP. + * + * @param { ImportPrivateKeyParams } params The parameters required to import the private key into the wrapped keys backend service + * + * @returns { Promise } - The LIT PKP Address associated with the Wrapped Key + */ +export async function importPrivateKey( + params: ImportPrivateKeyParams +): Promise { + const { pkpSessionSigs, privateKey, address, algo, litNodeClient } = params; + + const firstSessionSig = getFirstSessionSig(pkpSessionSigs); + const pkpAddress = getPkpAddressFromSessionSig(firstSessionSig); + const allowPkpAddressToDecrypt = getPkpAccessControlCondition(pkpAddress); + + const saltedPrivateKey = LIT_PREFIX + privateKey; + + const { ciphertext, dataToEncryptHash } = await encryptString( + { + accessControlConditions: [allowPkpAddressToDecrypt], + dataToEncrypt: saltedPrivateKey, + }, + litNodeClient + ); + + await storePrivateKeyMetadata({ + sessionSig: firstSessionSig, + litNodeClient, + storedKeyMetadata: { + ciphertext, + address, + algo, + dataToEncryptHash, + pkpAddress, + }, + }); + + return pkpAddress; +} diff --git a/packages/wrapped-keys/src/lib/api/index.ts b/packages/wrapped-keys/src/lib/api/index.ts new file mode 100644 index 0000000000..3f4970fd3d --- /dev/null +++ b/packages/wrapped-keys/src/lib/api/index.ts @@ -0,0 +1,15 @@ +import { exportPrivateKey } from './export-private-key'; +import { generatePrivateKey } from './generate-private-key'; +import { getEncryptedKeyMetadata } from './get-encrypted-key-metadata'; +import { importPrivateKey } from './import-private-key'; +import { signMessageWithEncryptedKey } from './sign-message-with-encrypted-key'; +import { signTransactionWithEncryptedKey } from './sign-transaction-with-encrypted-key'; + +export { + generatePrivateKey, + importPrivateKey, + signTransactionWithEncryptedKey, + exportPrivateKey, + signMessageWithEncryptedKey, + getEncryptedKeyMetadata, +}; diff --git a/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts b/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts new file mode 100644 index 0000000000..1c208ba2d2 --- /dev/null +++ b/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts @@ -0,0 +1,43 @@ +import { signMessageWithLitAction } from '../lit-actions-client'; +import { getLitActionCid } from '../lit-actions-client/utils'; +import { fetchPrivateKeyMetadata } from '../service-client'; +import { SignMessageWithEncryptedKeyParams } from '../types'; +import { getFirstSessionSig, getPkpAccessControlCondition } from '../utils'; + +/** + * Signs a message inside the Lit Action using the previously persisted wrapped key associated with the current LIT PK. + * This method fetches the encrypted key from the wrapped keys service, then executes a Lit Action that decrypts the key inside the LIT action and uses + * the decrypted key to sign the provided transaction + * + * NOTE: If you use `custom` as `network`, you must provide either an IPFS CID or the direct source code of the LIT action you want + * to be responsible for decrypting the encrypted key and signing the message + * + * @param { SignMessageWithEncryptedKeyParams } params Parameters to use for signing the message + * + * @returns { Promise } - The signed message + */ +export async function signMessageWithEncryptedKey( + params: SignMessageWithEncryptedKeyParams +): Promise { + const { litNodeClient, network, pkpSessionSigs } = params; + + const sessionSig = getFirstSessionSig(pkpSessionSigs); + const storedKeyMetadata = await fetchPrivateKeyMetadata({ + sessionSig, + litNodeClient, + }); + + const allowPkpAddressToDecrypt = getPkpAccessControlCondition( + storedKeyMetadata.pkpAddress + ); + + return signMessageWithLitAction({ + ...params, + ...(network === 'evm' || network == 'solana' + ? { litActionIpfsCid: getLitActionCid(network, 'signMessage') } + : {}), + accessControlConditions: [allowPkpAddressToDecrypt], + pkpSessionSigs, + storedKeyMetadata, + }); +} diff --git a/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts b/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts new file mode 100644 index 0000000000..c84da95bb3 --- /dev/null +++ b/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts @@ -0,0 +1,43 @@ +import { signTransactionWithLitAction } from '../lit-actions-client'; +import { getLitActionCid } from '../lit-actions-client/utils'; +import { fetchPrivateKeyMetadata } from '../service-client'; +import { SignTransactionWithEncryptedKeyParams } from '../types'; +import { getFirstSessionSig, getPkpAccessControlCondition } from '../utils'; + +/** + * Signs a transaction inside the Lit Action using the previously persisted wrapped key associated with the current LIT PK. + * This method fetches the encrypted key from the wrapped keys service, then executes a Lit Action that decrypts the key inside the LIT action and uses + * the decrypted key to sign the provided transaction + * Optionally, if you pass `broadcast: true`, the LIT action will also submit the signed transaction to the associated RPC endpoint on your behalf + * + * * NOTE: If you use `custom` as `network`, you must provide either an IPFS CID or the direct source code of the LIT action you want + * to be responsible for decrypting the encrypted key, signing the message, and supporting `broadcast: true` if you set it. + * + * @param { SignTransactionWithEncryptedKeyParams } params Parameters required to sign the requested transaction + * + * @returns { string } The signed transaction OR its transaction hash if you set `broadcast: true` and the LIT action supports this functionality. + */ +export async function signTransactionWithEncryptedKey( + params: SignTransactionWithEncryptedKeyParams +): Promise { + const { litNodeClient, network, pkpSessionSigs } = params; + const sessionSig = getFirstSessionSig(pkpSessionSigs); + + const storedKeyMetadata = await fetchPrivateKeyMetadata({ + sessionSig, + litNodeClient, + }); + + const allowPkpAddressToDecrypt = getPkpAccessControlCondition( + storedKeyMetadata.pkpAddress + ); + + return signTransactionWithLitAction({ + ...params, + ...(network === 'evm' || network == 'solana' + ? { litActionIpfsCid: getLitActionCid(network, 'signTransaction') } + : {}), + storedKeyMetadata, + accessControlConditions: [allowPkpAddressToDecrypt], + }); +} diff --git a/packages/wrapped-keys/src/lib/wrapped-keys.ts b/packages/wrapped-keys/src/lib/wrapped-keys.ts deleted file mode 100644 index 8ef40226db..0000000000 --- a/packages/wrapped-keys/src/lib/wrapped-keys.ts +++ /dev/null @@ -1,485 +0,0 @@ -import { - CHAIN_ETHEREUM, - ENCRYPTED_PRIVATE_KEY_ENDPOINT, - LIT_ACTION_CID_REPOSITORY, - LIT_PREFIX, - NETWORK_SOLANA, -} from './constants'; -import { decryptToString, encryptString } from '@lit-protocol/encryption'; -import { logError } from '@lit-protocol/misc'; -import { - fetchPrivateKeyMedataFromDatabase, - getFirstSessionSig, - getPkpAccessControlCondition, - getPkpAddressFromSessionSig, - postLitActionValidation, - storePrivateKeyMetadataToDatabase, -} from './utils'; -import { - LitTransaction, - ExportPrivateKeyParams, - ExportPrivateKeyResponse, - ImportPrivateKeyParams, - SignTransactionWithEncryptedKeyParams, - SignMessageWithEncryptedKeyParams, - GeneratePrivateKeyParams, - GeneratePrivateKeyResponse, - CustomGeneratePrivateKeyParams, - CustomSignMessageWithEncryptedKeyParams, - CustomSignTransactionWithEncryptedKeyParams, -} from './interfaces'; - -/** - * - * Generates a random Solana/EVM private key inside the corresponding Lit Action and returns the publicKey of the random private key. We don't return the generated wallet address since it can be derived from the publicKey - * - * @param pkpSessionSigs - The PKP sessionSigs used to associated the PKP with the generated private key - * @param network - The network for which the private key needs to be generated. This is used to call different Lit Actions since the keys will be of different types - * @param litNodeClient - The Lit Node Client used for executing the Lit Action - * - * @returns { Promise } - The publicKey of the generated random private key along with the PKP EthAddres associated with the Wrapped Key - */ -export async function generatePrivateKey({ - pkpSessionSigs, - network, - litNodeClient, -}: GeneratePrivateKeyParams): Promise { - const firstSessionSig = getFirstSessionSig(pkpSessionSigs); - const pkpAddress = getPkpAddressFromSessionSig(firstSessionSig); - const allowPkpAddressToDecrypt = getPkpAccessControlCondition(pkpAddress); - console.log( - 'accessControlConditions: ', - JSON.stringify(allowPkpAddressToDecrypt) - ); - - const ipfsId = - network === NETWORK_SOLANA - ? LIT_ACTION_CID_REPOSITORY.generateEncryptedSolanaPrivateKey - : LIT_ACTION_CID_REPOSITORY.generateEncryptedEthereumPrivateKey; - - let ciphertext, dataToEncryptHash, publicKey; - try { - const result = await litNodeClient.executeJs({ - sessionSigs: pkpSessionSigs, - ipfsId, - jsParams: { - pkpAddress, - accessControlConditions: allowPkpAddressToDecrypt, - }, - }); - - const response = postLitActionValidation(result); - ({ ciphertext, dataToEncryptHash, publicKey } = JSON.parse(response)); - } catch (err: any) { - throw new Error( - `Lit Action threw an unexpected error: ${JSON.stringify(err)}` - ); - } - - const data = { ciphertext, dataToEncryptHash }; - - const importedPrivateKey = await storePrivateKeyMetadataToDatabase( - data, - firstSessionSig - ); - return { - pkpAddress: importedPrivateKey.pkpAddress, - generatedPublicKey: publicKey, - }; -} - -/** - * - * Generates a random private key inside the provided Lit Action and returns the publicKey of the random private key. - * Lit Action should bundle the required wallet packages and encrypt the private key after prepending "lit_" to it. - * Access control condition should only allow the PKP Eth address of the provided PKP sessionSigs to decrypt. - * Lit Action should return a stringified JSON with ciphertext, dataToEncryptHash, publicKey. - * - * @param pkpSessionSigs - The PKP sessionSigs used to associated the PKP with the generated private key - * @param litActionIpfsCid - The IPFS CID of the Lit Action to be executed for generating the Wrapped Key. Can't provide this if already provided litActionCode - * @param litActionCode - The Lit Action code to be executed for generating the Wrapped Key. Can't provide this if already provided litActionIpfsCid - * @param litNodeClient - The Lit Node Client used for executing the Lit Action - * - * @returns { Promise } - The publicKey of the generated random private key along with the PKP EthAddres associated with the Wrapped Key - */ -export async function customGeneratePrivateKey({ - pkpSessionSigs, - litActionIpfsCid, - litActionCode, - litNodeClient, -}: CustomGeneratePrivateKeyParams): Promise { - if (!litActionIpfsCid && !litActionCode) { - throw new Error( - 'Have to provide either the litActionIpfsCid or litActionCode' - ); - } - - if (litActionIpfsCid && litActionCode) { - throw new Error("Can't provide both the litActionIpfsCid or litActionCode"); - } - - const firstSessionSig = getFirstSessionSig(pkpSessionSigs); - const pkpAddress = getPkpAddressFromSessionSig(firstSessionSig); - const allowPkpAddressToDecrypt = getPkpAccessControlCondition(pkpAddress); - console.log( - 'accessControlConditions: ', - JSON.stringify(allowPkpAddressToDecrypt) - ); - - let ciphertext, dataToEncryptHash, publicKey; - try { - const result = await litNodeClient.executeJs({ - sessionSigs: pkpSessionSigs, - ipfsId: litActionIpfsCid, - code: litActionCode, - jsParams: { - pkpAddress, - accessControlConditions: allowPkpAddressToDecrypt, - }, - }); - - const response = postLitActionValidation(result); - ({ ciphertext, dataToEncryptHash, publicKey } = JSON.parse(response)); - } catch (err: any) { - throw new Error( - `Lit Action threw an unexpected error: ${JSON.stringify(err)}` - ); - } - - const data = { ciphertext, dataToEncryptHash }; - - const importedPrivateKey = await storePrivateKeyMetadataToDatabase( - data, - firstSessionSig - ); - return { - pkpAddress: importedPrivateKey.pkpAddress, - generatedPublicKey: publicKey, - }; -} - -/** - * - * Import any provided private key into our DynamoDB instance. First the key is pre-pended with LIT_PREFIX for security reasons. Then the updated key is encrypted and stored in the database - * - * @param pkpSessionSigs - The PKP sessionSigs used to associated the PKP with the generated private key - * @param privateKey - The private key imported into the database - * @param litNodeClient - The Lit Node Client used for executing the Lit Action - * - * @returns { Promise } - The PKP EthAddres associated with the Wrapped Key - */ -export async function importPrivateKey({ - pkpSessionSigs, - privateKey, - litNodeClient, -}: ImportPrivateKeyParams): Promise { - const firstSessionSig = getFirstSessionSig(pkpSessionSigs); - const pkpAddress = getPkpAddressFromSessionSig(firstSessionSig); - const allowPkpAddressToDecrypt = getPkpAccessControlCondition(pkpAddress); - - const updatedPrivateKey = LIT_PREFIX + privateKey; - - const { ciphertext, dataToEncryptHash } = await encryptString( - { - accessControlConditions: allowPkpAddressToDecrypt, - dataToEncrypt: updatedPrivateKey, - }, - litNodeClient - ); - - const data = { - ciphertext, - dataToEncryptHash, - }; - - const importedPrivateKey = await storePrivateKeyMetadataToDatabase( - data, - firstSessionSig - ); - return importedPrivateKey.pkpAddress; -} - -/** - * - * Exports any imported private key. First the stored encrypted private key is fetched from the database. Then it's decrypted and returned to the user - * - * @param pkpSessionSigs - The PKP sessionSigs used to associated the PKP with the generated private key - * @param privateKey - The private key imported into the database - * @param litNodeClient - The Lit Node Client used for executing the Lit Action - * - * @returns { Promise } - The bare private key which was imported without any prefix - */ -export async function exportPrivateKey({ - pkpSessionSigs, - litNodeClient, -}: ExportPrivateKeyParams): Promise { - const firstSessionSig = getFirstSessionSig(pkpSessionSigs); - const pkpAddress = getPkpAddressFromSessionSig(firstSessionSig); - const allowPkpAddressToDecrypt = getPkpAccessControlCondition(pkpAddress); - - let exportedPrivateKeyData: ExportPrivateKeyResponse; - - try { - const response = await fetch(ENCRYPTED_PRIVATE_KEY_ENDPOINT, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - pkpsessionsig: JSON.stringify(firstSessionSig), - }, - }); - - if (!response.ok) { - const errorBody = await response.text(); - logError( - `Could not fetch the encrypted key due to the error: ${errorBody}` - ); - - throw new Error(errorBody); - } - - exportedPrivateKeyData = await response.json(); - } catch (error) { - const errorMessage = `There was a problem fetching from the database: ${error}`; - console.error(errorMessage); - - throw new Error(errorMessage); - } - - const decryptedPrivateKey = await decryptToString( - { - accessControlConditions: allowPkpAddressToDecrypt, - chain: CHAIN_ETHEREUM, - ciphertext: exportedPrivateKeyData.ciphertext, - dataToEncryptHash: exportedPrivateKeyData.dataToEncryptHash, - sessionSigs: pkpSessionSigs, - }, - litNodeClient - ); - - // It will be of the form lit_ - return decryptedPrivateKey.startsWith(LIT_PREFIX) - ? decryptedPrivateKey.slice(LIT_PREFIX.length) - : decryptedPrivateKey; -} - -/** - * - * Signs a transaction inside the Lit Action using the Solana/EVM key. First it fetches the encrypted key from database and then executes a Lit Action that signed the tx. - * - * @param pkpSessionSigs - The PKP sessionSigs used to associated the PKP with the generated private key - * @param network - The network for which the private key needs to be generated. This is used to call different Lit Actions since the keys will be of different types - * @param unsignedTransaction - The unsigned transaction which will be signed inside the Lit Action. It can be of type LitTransaction - * @param broadcast - Flag used to determine whether the Lit Action should broadcast the signed transaction or only return the signed transaction - * @param litNodeClient - The Lit Node Client used for executing the Lit Action - * - * @returns { Promise } - Either the signed Solana/EVM transaction which the user can use to broadcast themselves or the transaction hash or the broadcasted Solana/EVM transaction - */ -export async function signTransactionWithEncryptedKey({ - pkpSessionSigs, - network, - unsignedTransaction, - broadcast, - litNodeClient, -}: SignTransactionWithEncryptedKeyParams): Promise { - const { pkpAddress, ciphertext, dataToEncryptHash } = - await fetchPrivateKeyMedataFromDatabase(pkpSessionSigs); - - const ipfsId = - network === NETWORK_SOLANA - ? LIT_ACTION_CID_REPOSITORY.signTransactionWithSolanaEncryptedKey - : LIT_ACTION_CID_REPOSITORY.signTransactionWithEthereumEncryptedKey; - - let result; - try { - result = await litNodeClient.executeJs({ - sessionSigs: pkpSessionSigs, - ipfsId, - jsParams: { - pkpAddress, - ciphertext, - dataToEncryptHash, - unsignedTransaction, - broadcast, - accessControlConditions: getPkpAccessControlCondition(pkpAddress), - }, - }); - } catch (err: any) { - throw new Error( - `Lit Action threw an unexpected error: ${JSON.stringify(err)}` - ); - } - - return postLitActionValidation(result); -} - -/** - * - * Signs a transaction inside the provided Lit Action. First it fetches the encrypted key from database and then executes a Lit Action that signed the tx. - * Lit Action should bundle the required wallet packages and decrypt the private key which may be prepended with "lit_". - * It should create the corresponding wallet instance with the bundled package and sign the passed message with it. - * It should either return the signed transaction or the transaction hash of the broadcasted transaction. - * - * @param pkpSessionSigs - The PKP sessionSigs used to associated the PKP with the generated private key - * @param litActionIpfsCid - The IPFS CID of the Lit Action to be executed for generating the Wrapped Key. Can't provide this if already provided litActionCode - * @param litActionCode - The Lit Action code to be executed for generating the Wrapped Key. Can't provide this if already provided litActionIpfsCid - * @param serializedTransaction - The unsigned transaction which will be signed inside the Lit Action. It should be a serialized unsigned transaction - * @param broadcast - Flag used to determine whether the Lit Action should broadcast the signed transaction or only return the signed transaction - * @param params - Any other params passes to the Lit Action - * @param litNodeClient - The Lit Node Client used for executing the Lit Action - * - * @returns { Promise } - The signed signed transaction or the transaction hash of the broadcasted transaction by the Wrapped Key - */ -export async function customSignTransactionWithEncryptedKey({ - pkpSessionSigs, - litActionIpfsCid, - litActionCode, - serializedTransaction, - broadcast, - params, - litNodeClient, -}: CustomSignTransactionWithEncryptedKeyParams): Promise { - if (!litActionIpfsCid && !litActionCode) { - throw new Error( - 'Have to provide either the litActionIpfsCid or litActionCode' - ); - } - - if (litActionIpfsCid && litActionCode) { - throw new Error("Can't provide both the litActionIpfsCid or litActionCode"); - } - - const { pkpAddress, ciphertext, dataToEncryptHash } = - await fetchPrivateKeyMedataFromDatabase(pkpSessionSigs); - - let result; - try { - result = await litNodeClient.executeJs({ - sessionSigs: pkpSessionSigs, - ipfsId: litActionIpfsCid, - code: litActionCode, - jsParams: { - pkpAddress, - ciphertext, - dataToEncryptHash, - serializedTransaction, - broadcast, - accessControlConditions: getPkpAccessControlCondition(pkpAddress), - ...params, - }, - }); - } catch (err: any) { - throw new Error( - `Lit Action threw an unexpected error: ${JSON.stringify(err)}` - ); - } - - return postLitActionValidation(result); -} - -/** - * - * Signs a message inside the Lit Action using the Solana/EVM key. First it fetches the encrypted key from database and then executes a Lit Action that signed the tx - * - * @param pkpSessionSigs - The PKP sessionSigs used to associated the PKP with the generated private key - * @param network - The network for which the private key needs to be generated. This is used to call different Lit Actions since the keys will be of different types - * @param messageToSign - The unsigned message which will be signed inside the Lit Action - * @param litNodeClient - The Lit Node Client used for executing the Lit Action - * - * @returns { Promise } - The signed Solana/EVM message - */ -export async function signMessageWithEncryptedKey({ - pkpSessionSigs, - network, - messageToSign, - litNodeClient, -}: SignMessageWithEncryptedKeyParams): Promise { - const { pkpAddress, ciphertext, dataToEncryptHash } = - await fetchPrivateKeyMedataFromDatabase(pkpSessionSigs); - - const ipfsId = - network === NETWORK_SOLANA - ? LIT_ACTION_CID_REPOSITORY.signMessageWithSolanaEncryptedKey - : LIT_ACTION_CID_REPOSITORY.signMessageWithEthereumEncryptedKey; - - let result; - try { - result = await litNodeClient.executeJs({ - sessionSigs: pkpSessionSigs, - ipfsId, - jsParams: { - pkpAddress, - ciphertext, - dataToEncryptHash, - messageToSign, - accessControlConditions: getPkpAccessControlCondition(pkpAddress), - }, - }); - } catch (err: any) { - throw new Error( - `Lit Action threw an unexpected error: ${JSON.stringify(err)}` - ); - } - - return postLitActionValidation(result); -} - -/** - * - * Signs a message inside the provided Lit Action. First it fetches the encrypted key from database and then executes a Lit Action that signed the tx - * Lit Action should bundle the required wallet packages and decrypt the private key which may be prepended with "lit_". - * It should create the corresponding wallet instance with the bundled package and sign the passed message with it. - * It should return the signed message. - * - * @param pkpSessionSigs - The PKP sessionSigs used to associated the PKP with the generated private key - * @param litActionIpfsCid - The IPFS CID of the Lit Action to be executed for generating the Wrapped Key. Can't provide this if already provided litActionCode - * @param litActionCode - The Lit Action code to be executed for generating the Wrapped Key. Can't provide this if already provided litActionIpfsCid - * @param messageToSign - The unsigned message which will be signed inside the Lit Action - * @param params - Any other params passes to the Lit Action - * @param litNodeClient - The Lit Node Client used for executing the Lit Action - * - * @returns { Promise } - The signed message by the Wrapped Key - */ -export async function customSignMessageWithEncryptedKey({ - pkpSessionSigs, - litActionIpfsCid, - litActionCode, - messageToSign, - params, - litNodeClient, -}: CustomSignMessageWithEncryptedKeyParams): Promise { - if (!litActionIpfsCid && !litActionCode) { - throw new Error( - 'Have to provide either the litActionIpfsCid or litActionCode' - ); - } - - if (litActionIpfsCid && litActionCode) { - throw new Error("Can't provide both the litActionIpfsCid or litActionCode"); - } - - const { pkpAddress, ciphertext, dataToEncryptHash } = - await fetchPrivateKeyMedataFromDatabase(pkpSessionSigs); - - let result; - try { - result = await litNodeClient.executeJs({ - sessionSigs: pkpSessionSigs, - ipfsId: litActionIpfsCid, - code: litActionCode, - jsParams: { - pkpAddress, - ciphertext, - dataToEncryptHash, - messageToSign, - accessControlConditions: getPkpAccessControlCondition(pkpAddress), - ...params, - }, - }); - } catch (err: any) { - throw new Error( - `Lit Action threw an unexpected error: ${JSON.stringify(err)}` - ); - } - - return postLitActionValidation(result); -} From 5b5abb14c8e909e33d3dc9275810dcb2b0edbd30 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 01:05:59 +0100 Subject: [PATCH 09/30] chore(wrapped-keys): LIT-3125 - Update entrypoint exports to be explicit. - Namespaced API methods and constants separately from exported types - Only exported types, interfaces and constants that are part of the API layer that end consumers will interact with --- packages/wrapped-keys/src/index.ts | 63 ++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/packages/wrapped-keys/src/index.ts b/packages/wrapped-keys/src/index.ts index b3aca92af0..779998bd99 100644 --- a/packages/wrapped-keys/src/index.ts +++ b/packages/wrapped-keys/src/index.ts @@ -1,3 +1,60 @@ -export * from './lib/wrapped-keys'; -export * from './lib/interfaces'; -export { NETWORK_EVM, NETWORK_SOLANA } from './lib/constants'; +import { + signMessageWithEncryptedKey, + getEncryptedKeyMetadata, + exportPrivateKey, + generatePrivateKey, + importPrivateKey, + signTransactionWithEncryptedKey, +} from './lib/api'; +import { + NETWORK_SOLANA, + NETWORK_EVM, + NETWORK_CUSTOM, + CHAIN_ETHEREUM, + LIT_PREFIX, +} from './lib/constants'; + +import type { + StoredKeyMetadata, + SupportedNetworks, +} from './lib/service-client'; +import type { + SignMessageWithEncryptedKeyParams, + GetEncryptedKeyMetadataParams, + ExportPrivateKeyParams, + GeneratePrivateKeyParams, + ImportPrivateKeyParams, + SignTransactionWithEncryptedKeyParams, + ExportPrivateKeyResult, + GeneratePrivateKeyResult, +} from './lib/types'; + +export const constants = { + NETWORK_SOLANA, + NETWORK_EVM, + NETWORK_CUSTOM, + CHAIN_ETHEREUM, + LIT_PREFIX, +}; + +export const api = { + signMessageWithEncryptedKey, + getEncryptedKeyMetadata, + exportPrivateKey, + generatePrivateKey, + importPrivateKey, + signTransactionWithEncryptedKey, +}; + +export { + StoredKeyMetadata, + SupportedNetworks, + SignMessageWithEncryptedKeyParams, + GetEncryptedKeyMetadataParams, + ExportPrivateKeyParams, + ExportPrivateKeyResult, + GeneratePrivateKeyParams, + GeneratePrivateKeyResult, + ImportPrivateKeyParams, + SignTransactionWithEncryptedKeyParams, +}; From d1e49f8d919920ea0fdf1857cad14dc450f4e1ee Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 01:29:16 +0100 Subject: [PATCH 10/30] types(types): LIT-3125 - Revert change to AccessControlConditions type -- it breaks a ton of code in the `canonicalFormatter` - Replaced type on `getPkpAccessControlCondition()` with `AccsDefaultParams`, a narrower type instead. - Added `EthereumLitTransaction` type to exports --- packages/types/src/lib/types.ts | 1 - .../wrapped-keys/src/lib/lit-actions-client/generate-key.ts | 4 ++-- packages/wrapped-keys/src/lib/utils.ts | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/types/src/lib/types.ts b/packages/types/src/lib/types.ts index 6d09f9d0d7..a75f786ba4 100644 --- a/packages/types/src/lib/types.ts +++ b/packages/types/src/lib/types.ts @@ -44,7 +44,6 @@ export type ConditionItem = AccsParams | AccsOperatorParams; export type AccessControlConditions = ( | AccsDefaultParams - | AccsParams | AccsOperatorParams | AccessControlConditions )[]; diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts b/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts index 001bc52fc1..838fae17be 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts @@ -1,5 +1,5 @@ import { - ConditionItem, + AccessControlConditions, ILitNodeClient, SessionSigsMap, } from '@lit-protocol/types'; @@ -11,7 +11,7 @@ interface GeneratePrivateKeyLitActionParams { pkpAddress: string; litActionIpfsCid?: string; litActionCode?: string; - accessControlConditions: ConditionItem[]; + accessControlConditions: AccessControlConditions; litNodeClient: ILitNodeClient; } diff --git a/packages/wrapped-keys/src/lib/utils.ts b/packages/wrapped-keys/src/lib/utils.ts index 0c4dd71e3e..4a5727d207 100644 --- a/packages/wrapped-keys/src/lib/utils.ts +++ b/packages/wrapped-keys/src/lib/utils.ts @@ -2,8 +2,8 @@ import { ethers } from 'ethers'; import { log } from '@lit-protocol/misc'; import { + AccsDefaultParams, AuthSig, - ConditionItem, SessionKeySignedMessage, SessionSigsMap, } from '@lit-protocol/types'; @@ -74,11 +74,11 @@ export function getPkpAddressFromSessionSig(pkpSessionSig: AuthSig): string { * * @param { string } pkpAddress - The wallet address of the PKP which can decrypt the encrypted Wrapped Key * - * @returns { ConditionItem } - The access control condition that only allows the PKP address to decrypt + * @returns { AccsDefaultParams } - The access control condition that only allows the PKP address to decrypt */ export function getPkpAccessControlCondition( pkpAddress: string -): ConditionItem { +): AccsDefaultParams { if (!ethers.utils.isAddress(pkpAddress)) { throw new Error( `pkpAddress is not a valid Ethereum Address: ${pkpAddress}` From 5af043545a11484462e05963629742e8169f22fa Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 01:32:10 +0100 Subject: [PATCH 11/30] constants(wrapped-keys): LIT-3125 - Remove NETWORK_XXXX constants as they don't play nicely with string union types. --- packages/wrapped-keys/src/index.ts | 15 +++++---------- packages/wrapped-keys/src/lib/constants.ts | 6 ------ 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/packages/wrapped-keys/src/index.ts b/packages/wrapped-keys/src/index.ts index 779998bd99..133dfcee59 100644 --- a/packages/wrapped-keys/src/index.ts +++ b/packages/wrapped-keys/src/index.ts @@ -6,13 +6,7 @@ import { importPrivateKey, signTransactionWithEncryptedKey, } from './lib/api'; -import { - NETWORK_SOLANA, - NETWORK_EVM, - NETWORK_CUSTOM, - CHAIN_ETHEREUM, - LIT_PREFIX, -} from './lib/constants'; +import { CHAIN_ETHEREUM, LIT_PREFIX } from './lib/constants'; import type { StoredKeyMetadata, @@ -27,12 +21,11 @@ import type { SignTransactionWithEncryptedKeyParams, ExportPrivateKeyResult, GeneratePrivateKeyResult, + EthereumLitTransaction, + SerializedTransaction, } from './lib/types'; export const constants = { - NETWORK_SOLANA, - NETWORK_EVM, - NETWORK_CUSTOM, CHAIN_ETHEREUM, LIT_PREFIX, }; @@ -47,6 +40,8 @@ export const api = { }; export { + EthereumLitTransaction, + SerializedTransaction, StoredKeyMetadata, SupportedNetworks, SignMessageWithEncryptedKeyParams, diff --git a/packages/wrapped-keys/src/lib/constants.ts b/packages/wrapped-keys/src/lib/constants.ts index ce0ef37ef7..bd0cbfbb3d 100644 --- a/packages/wrapped-keys/src/lib/constants.ts +++ b/packages/wrapped-keys/src/lib/constants.ts @@ -1,8 +1,2 @@ -import { Network } from './types'; - export const CHAIN_ETHEREUM = 'ethereum'; export const LIT_PREFIX = 'lit_'; - -export const NETWORK_EVM: Network = 'evm'; -export const NETWORK_SOLANA: Network = 'solana'; -export const NETWORK_CUSTOM: Network = 'custom'; From 5d891706e2676df39ae923bfe3c4c58a479fead4 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 02:30:37 +0100 Subject: [PATCH 12/30] test(wrapped-keys): LIT-3125 - Update success tests to latest wrapped-keys API - Fixed missing logic in `generatePrivateKey` for handling `custom` case - Added some code to testCustomSignTransactionWrappedKey to bring it closer to doing what its title implies it does. It fails. --- .../tests/testCustomGenerateWrappedKey.ts | 15 +++-- .../testCustomSignTransactionWrappedKey.ts | 60 ++++++++++++++----- ...thereumBroadcastTransactionGeneratedKey.ts | 13 ++-- ...tEthereumBroadcastTransactionWrappedKey.ts | 13 ++-- ...umBroadcastWrappedKeyWithFetchGasParams.ts | 13 ++-- .../testEthereumSignMessageGeneratedKey.ts | 14 ++--- .../testEthereumSignMessageWrappedKey.ts | 14 ++--- .../testEthereumSignTransactionWrappedKey.ts | 15 ++--- local-tests/tests/testExportWrappedKey.ts | 7 ++- .../tests/testGenerateEthereumWrappedKey.ts | 7 ++- .../tests/testGenerateSolanaWrappedKey.ts | 12 ++-- local-tests/tests/testImportWrappedKey.ts | 6 +- .../testSignMessageWithSolanaEncryptedKey.ts | 12 ++-- ...stSignTransactionWithSolanaEncryptedKey.ts | 15 +++-- .../src/lib/api/generate-private-key.ts | 5 +- .../api/sign-message-with-encrypted-key.ts | 2 +- .../sign-transaction-with-encrypted-key.ts | 2 +- 17 files changed, 127 insertions(+), 98 deletions(-) diff --git a/local-tests/tests/testCustomGenerateWrappedKey.ts b/local-tests/tests/testCustomGenerateWrappedKey.ts index 2588d146f8..aed1ee9aaf 100644 --- a/local-tests/tests/testCustomGenerateWrappedKey.ts +++ b/local-tests/tests/testCustomGenerateWrappedKey.ts @@ -1,8 +1,10 @@ import { log } from '@lit-protocol/misc'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { customGeneratePrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { LIT_ACTION_CID_REPOSITORY } from 'packages/wrapped-keys/src/lib/constants'; + +import { LIT_ACTION_CID_REPOSITORY } from '../../packages/wrapped-keys/src/lib/lit-actions-client/constants'; +const { generatePrivateKey } = api; const CUSTOM_LIT_ACTION_CODE = ` (async () => { @@ -53,10 +55,10 @@ export const testCustomGenerateWrappedKey = async ( new Date(Date.now() + 1000 * 60 * 10).toISOString() ); // 10 mins expiry - const ipfsCustomPrivateKeys = await customGeneratePrivateKey({ + const ipfsCustomPrivateKeys = await generatePrivateKey({ + network: 'custom', pkpSessionSigs: alicePkpSessionSigs, - litActionIpfsCid: - LIT_ACTION_CID_REPOSITORY.generateEncryptedSolanaPrivateKey, + litActionIpfsCid: LIT_ACTION_CID_REPOSITORY.generateEncryptedKey.solana, litNodeClient: devEnv.litNodeClient, }); @@ -81,7 +83,8 @@ export const testCustomGenerateWrappedKey = async ( new Date(Date.now() + 1000 * 60 * 10).toISOString() ); // 10 mins expiry - const codeCustomPrivateKeys = await customGeneratePrivateKey({ + const codeCustomPrivateKeys = await generatePrivateKey({ + network: 'custom', pkpSessionSigs: bobPkpSessionSigs, litActionCode: CUSTOM_LIT_ACTION_CODE, litNodeClient: devEnv.litNodeClient, diff --git a/local-tests/tests/testCustomSignTransactionWrappedKey.ts b/local-tests/tests/testCustomSignTransactionWrappedKey.ts index 3534df8665..0d76f0c97b 100644 --- a/local-tests/tests/testCustomSignTransactionWrappedKey.ts +++ b/local-tests/tests/testCustomSignTransactionWrappedKey.ts @@ -2,12 +2,22 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; import { - importPrivateKey, - signTransactionWithEncryptedKey, + api, EthereumLitTransaction, + SerializedTransaction, } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; +import { + clusterApiUrl, + Connection, + Keypair, + LAMPORTS_PER_SOL, + PublicKey, + SystemProgram, + Transaction, +} from '@solana/web3.js'; + +const { importPrivateKey, signTransactionWithEncryptedKey } = api; const CUSTOM_LIT_ACTION_CODE = `(async () => { const LIT_PREFIX = 'lit_'; @@ -77,7 +87,7 @@ const CUSTOM_LIT_ACTION_CODE = `(async () => { * ✅ NETWORK=manzano yarn test:local --filter=testEthereumSignTransactionWrappedKey * ✅ NETWORK=localchain yarn test:local --filter=testEthereumSignTransactionWrappedKey */ -export const testEthereumSignTransactionWrappedKey = async ( +export const testCustomSignTransactionWrappedKey = async ( devEnv: TinnyEnvironment ) => { const alice = await devEnv.createRandomPerson(); @@ -91,12 +101,15 @@ export const testEthereumSignTransactionWrappedKey = async ( console.log(pkpSessionSigs); - const privateKey = ethers.Wallet.createRandom().privateKey; + const solanaKeypair = Keypair.generate(); + const privateKey = Buffer.from(solanaKeypair.secretKey).toString('hex'); const pkpAddress = await importPrivateKey({ pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -115,24 +128,39 @@ export const testEthereumSignTransactionWrappedKey = async ( console.log(pkpSessionSigsSigning); - const unsignedTransaction: EthereumLitTransaction = { - toAddress: alice.wallet.address, - value: '0.0001', // in ethers (Lit tokens) - chainId: 175177, // Chronicle - gasPrice: '50', - gasLimit: 21000, - dataHex: ethers.utils.hexlify( - ethers.utils.toUtf8Bytes('Test transaction from Alice to bob') - ), - chain: 'chronicleTestnet', + const solanaTransaction = new Transaction(); + solanaTransaction.add( + SystemProgram.transfer({ + fromPubkey: solanaKeypair.publicKey, + toPubkey: new PublicKey(solanaKeypair.publicKey), + lamports: LAMPORTS_PER_SOL / 100, // Transfer 0.01 SOL + }) + ); + solanaTransaction.feePayer = solanaKeypair.publicKey; + + const solanaConnection = new Connection(clusterApiUrl('devnet'), 'confirmed'); + const { blockhash } = await solanaConnection.getLatestBlockhash(); + solanaTransaction.recentBlockhash = blockhash; + + const serializedTransaction = solanaTransaction + .serialize({ + requireAllSignatures: false, // should be false as we're not signing the message + verifySignatures: false, // should be false as we're not signing the message + }) + .toString('base64'); + + const unsignedTransaction: SerializedTransaction = { + serializedTransaction, + chain: 'devnet', }; const signedTx = await signTransactionWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'custom', unsignedTransaction, broadcast: false, litNodeClient: devEnv.litNodeClient, + litActionCode: CUSTOM_LIT_ACTION_CODE, }); console.log('signedTx'); diff --git a/local-tests/tests/testEthereumBroadcastTransactionGeneratedKey.ts b/local-tests/tests/testEthereumBroadcastTransactionGeneratedKey.ts index 68d3135fa4..ef102b771c 100644 --- a/local-tests/tests/testEthereumBroadcastTransactionGeneratedKey.ts +++ b/local-tests/tests/testEthereumBroadcastTransactionGeneratedKey.ts @@ -1,13 +1,10 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - signTransactionWithEncryptedKey, - EthereumLitTransaction, - generatePrivateKey, -} from '@lit-protocol/wrapped-keys'; +import { api, EthereumLitTransaction } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; + +const { signTransactionWithEncryptedKey, generatePrivateKey } = api; /** * Test Commands: @@ -31,7 +28,7 @@ export const testEthereumBroadcastTransactionGeneratedKey = async ( const { pkpAddress, generatedPublicKey } = await generatePrivateKey({ pkpSessionSigs, - network: NETWORK_EVM, + network: 'evm', litNodeClient: devEnv.litNodeClient, }); @@ -70,7 +67,7 @@ export const testEthereumBroadcastTransactionGeneratedKey = async ( const signedTx = await signTransactionWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'evm', unsignedTransaction, broadcast: true, litNodeClient: devEnv.litNodeClient, diff --git a/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts b/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts index 95f6d5dc77..d552298195 100644 --- a/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts +++ b/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts @@ -1,13 +1,10 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - importPrivateKey, - signTransactionWithEncryptedKey, - EthereumLitTransaction, -} from '@lit-protocol/wrapped-keys'; +import { api, EthereumLitTransaction } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; + +const { importPrivateKey, signTransactionWithEncryptedKey } = api; /** * Test Commands: @@ -40,6 +37,8 @@ export const testEthereumBroadcastTransactionWrappedKey = async ( pkpSessionSigs, privateKey: wrappedKeysWalletPrivateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -72,7 +71,7 @@ export const testEthereumBroadcastTransactionWrappedKey = async ( const signedTx = await signTransactionWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'evm', unsignedTransaction, broadcast: true, litNodeClient: devEnv.litNodeClient, diff --git a/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts b/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts index 1657268a2d..91b85b3390 100644 --- a/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts +++ b/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts @@ -1,13 +1,10 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - importPrivateKey, - EthereumLitTransaction, - signTransactionWithEncryptedKey, -} from '@lit-protocol/wrapped-keys'; +import { api, EthereumLitTransaction } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; + +const { importPrivateKey, signTransactionWithEncryptedKey } = api; /** * Test Commands: @@ -40,6 +37,8 @@ export const testEthereumBroadcastWrappedKeyWithFetchGasParams = async ( pkpSessionSigs, privateKey: wrappedKeysWalletPrivateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -70,7 +69,7 @@ export const testEthereumBroadcastWrappedKeyWithFetchGasParams = async ( const signedTx = await signTransactionWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'evm', unsignedTransaction, broadcast: true, litNodeClient: devEnv.litNodeClient, diff --git a/local-tests/tests/testEthereumSignMessageGeneratedKey.ts b/local-tests/tests/testEthereumSignMessageGeneratedKey.ts index 8bf1f9e2e1..9d003b2ad5 100644 --- a/local-tests/tests/testEthereumSignMessageGeneratedKey.ts +++ b/local-tests/tests/testEthereumSignMessageGeneratedKey.ts @@ -1,12 +1,10 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - generatePrivateKey, - signMessageWithEncryptedKey, -} from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; + +const { generatePrivateKey, signMessageWithEncryptedKey } = api; /** * Test Commands: @@ -30,7 +28,7 @@ export const testEthereumSignMessageGeneratedKey = async ( const { pkpAddress, generatedPublicKey } = await generatePrivateKey({ pkpSessionSigs, - network: NETWORK_EVM, + network: 'evm', litNodeClient: devEnv.litNodeClient, }); @@ -54,7 +52,7 @@ export const testEthereumSignMessageGeneratedKey = async ( const signature = await signMessageWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'evm', messageToSign: unsignedStringMessage, litNodeClient: devEnv.litNodeClient, }); @@ -72,7 +70,7 @@ export const testEthereumSignMessageGeneratedKey = async ( const signatureBinary = await signMessageWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'evm', messageToSign: unsignedBinaryMessage, litNodeClient: devEnv.litNodeClient, }); diff --git a/local-tests/tests/testEthereumSignMessageWrappedKey.ts b/local-tests/tests/testEthereumSignMessageWrappedKey.ts index 9f77da06fa..b7f41a8481 100644 --- a/local-tests/tests/testEthereumSignMessageWrappedKey.ts +++ b/local-tests/tests/testEthereumSignMessageWrappedKey.ts @@ -1,12 +1,10 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - importPrivateKey, - signMessageWithEncryptedKey, -} from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; + +const { importPrivateKey, signMessageWithEncryptedKey } = api; /** * Test Commands: @@ -34,6 +32,8 @@ export const testEthereumSignMessageWrappedKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -56,7 +56,7 @@ export const testEthereumSignMessageWrappedKey = async ( const signature = await signMessageWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'evm', messageToSign: unsignedStringMessage, litNodeClient: devEnv.litNodeClient, }); @@ -74,7 +74,7 @@ export const testEthereumSignMessageWrappedKey = async ( const signatureBinary = await signMessageWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'evm', messageToSign: unsignedBinaryMessage, litNodeClient: devEnv.litNodeClient, }); diff --git a/local-tests/tests/testEthereumSignTransactionWrappedKey.ts b/local-tests/tests/testEthereumSignTransactionWrappedKey.ts index bb4395243c..481bc8ea54 100644 --- a/local-tests/tests/testEthereumSignTransactionWrappedKey.ts +++ b/local-tests/tests/testEthereumSignTransactionWrappedKey.ts @@ -1,13 +1,12 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - importPrivateKey, - signTransactionWithEncryptedKey, - EthereumLitTransaction, -} from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; + +import type { EthereumLitTransaction } from '@lit-protocol/wrapped-keys'; + +const { importPrivateKey, signTransactionWithEncryptedKey } = api; /** * Test Commands: @@ -35,6 +34,8 @@ export const testEthereumSignTransactionWrappedKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -67,7 +68,7 @@ export const testEthereumSignTransactionWrappedKey = async ( const signedTx = await signTransactionWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'evm', unsignedTransaction, broadcast: false, litNodeClient: devEnv.litNodeClient, diff --git a/local-tests/tests/testExportWrappedKey.ts b/local-tests/tests/testExportWrappedKey.ts index 4413bc9ba8..0ecbfa5893 100644 --- a/local-tests/tests/testExportWrappedKey.ts +++ b/local-tests/tests/testExportWrappedKey.ts @@ -1,9 +1,10 @@ import { log } from '@lit-protocol/misc'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { exportPrivateKey, importPrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; import { randomSolanaPrivateKey } from 'local-tests/setup/tinny-utils'; +const { exportPrivateKey, importPrivateKey } = api; /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testExportWrappedKey @@ -28,6 +29,8 @@ export const testExportWrappedKey = async (devEnv: TinnyEnvironment) => { pkpSessionSigs: pkpSessionSigsImport, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -46,7 +49,7 @@ export const testExportWrappedKey = async (devEnv: TinnyEnvironment) => { console.log(pkpSessionSigsExport); - const decryptedPrivateKey = await exportPrivateKey({ + const { decryptedPrivateKey } = await exportPrivateKey({ pkpSessionSigs: pkpSessionSigsExport, litNodeClient: devEnv.litNodeClient, }); diff --git a/local-tests/tests/testGenerateEthereumWrappedKey.ts b/local-tests/tests/testGenerateEthereumWrappedKey.ts index fed30a0879..379ede42bd 100644 --- a/local-tests/tests/testGenerateEthereumWrappedKey.ts +++ b/local-tests/tests/testGenerateEthereumWrappedKey.ts @@ -1,8 +1,9 @@ import { log } from '@lit-protocol/misc'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { generatePrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; + +const { generatePrivateKey } = api; /** * Test Commands: @@ -26,7 +27,7 @@ export const testGenerateEthereumWrappedKey = async ( const { pkpAddress, generatedPublicKey } = await generatePrivateKey({ pkpSessionSigs, - network: NETWORK_EVM, + network: 'evm', litNodeClient: devEnv.litNodeClient, }); diff --git a/local-tests/tests/testGenerateSolanaWrappedKey.ts b/local-tests/tests/testGenerateSolanaWrappedKey.ts index 253747edba..ff5217c4f0 100644 --- a/local-tests/tests/testGenerateSolanaWrappedKey.ts +++ b/local-tests/tests/testGenerateSolanaWrappedKey.ts @@ -1,14 +1,12 @@ import { log } from '@lit-protocol/misc'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - generatePrivateKey, - signMessageWithEncryptedKey, -} from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_SOLANA } from 'packages/wrapped-keys/src/lib/constants'; import nacl from 'tweetnacl'; import bs58 from 'bs58'; +const { generatePrivateKey, signMessageWithEncryptedKey } = api; + /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testGenerateSolanaWrappedKey @@ -31,7 +29,7 @@ export const testGenerateSolanaWrappedKey = async ( const { pkpAddress, generatedPublicKey } = await generatePrivateKey({ pkpSessionSigs, - network: NETWORK_SOLANA, + network: 'solana', litNodeClient: devEnv.litNodeClient, }); @@ -57,7 +55,7 @@ export const testGenerateSolanaWrappedKey = async ( const signature = await signMessageWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_SOLANA, + network: 'solana', messageToSign, litNodeClient: devEnv.litNodeClient, }); diff --git a/local-tests/tests/testImportWrappedKey.ts b/local-tests/tests/testImportWrappedKey.ts index a1025e3d75..6e2c6f3a07 100644 --- a/local-tests/tests/testImportWrappedKey.ts +++ b/local-tests/tests/testImportWrappedKey.ts @@ -1,9 +1,11 @@ import { log } from '@lit-protocol/misc'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { importPrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; import { randomSolanaPrivateKey } from 'local-tests/setup/tinny-utils'; +const { importPrivateKey } = api; + /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testImportWrappedKey @@ -29,6 +31,8 @@ export const testImportWrappedKey = async (devEnv: TinnyEnvironment) => { pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts b/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts index 12b64b7c49..799de2dc68 100644 --- a/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts +++ b/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts @@ -1,14 +1,12 @@ import { log } from '@lit-protocol/misc'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - importPrivateKey, - signMessageWithEncryptedKey, -} from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { Keypair } from '@solana/web3.js'; import bs58 from 'bs58'; import nacl from 'tweetnacl'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_SOLANA } from 'packages/wrapped-keys/src/lib/constants'; + +const { importPrivateKey, signMessageWithEncryptedKey } = api; /** * Test Commands: @@ -37,6 +35,8 @@ export const testSignMessageWithSolanaEncryptedKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -59,7 +59,7 @@ export const testSignMessageWithSolanaEncryptedKey = async ( const signature = await signMessageWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_SOLANA, + network: 'solana', messageToSign, litNodeClient: devEnv.litNodeClient, }); diff --git a/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts b/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts index 0948a77bf9..2c68e96850 100644 --- a/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts +++ b/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts @@ -1,10 +1,6 @@ import { log } from '@lit-protocol/misc'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - SolanaLitTransaction, - importPrivateKey, - signTransactionWithEncryptedKey, -} from '@lit-protocol/wrapped-keys'; +import { SerializedTransaction, api } from '@lit-protocol/wrapped-keys'; import { Connection, Keypair, @@ -15,7 +11,8 @@ import { clusterApiUrl, } from '@solana/web3.js'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_SOLANA } from 'packages/wrapped-keys/src/lib/constants'; + +const { importPrivateKey, signTransactionWithEncryptedKey } = api; /** * Test Commands: @@ -44,6 +41,8 @@ export const testSignTransactionWithSolanaEncryptedKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -81,14 +80,14 @@ export const testSignTransactionWithSolanaEncryptedKey = async ( }) .toString('base64'); - const unsignedTransaction: SolanaLitTransaction = { + const unsignedTransaction: SerializedTransaction = { serializedTransaction, chain: 'devnet', }; const signedTx = await signTransactionWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_SOLANA, + network: 'solana', unsignedTransaction, broadcast: false, litNodeClient: devEnv.litNodeClient, diff --git a/packages/wrapped-keys/src/lib/api/generate-private-key.ts b/packages/wrapped-keys/src/lib/api/generate-private-key.ts index 381ce3ee96..16ebd0fb46 100644 --- a/packages/wrapped-keys/src/lib/api/generate-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/generate-private-key.ts @@ -32,10 +32,9 @@ export async function generatePrivateKey( const { ciphertext, dataToEncryptHash, publicKey } = await generateKeyWithLitAction({ - litNodeClient, - pkpSessionSigs, + ...params, pkpAddress, - ...(network === 'evm' || network == 'solana' + ...(network === 'evm' || network === 'solana' ? { litActionIpfsCid: getLitActionCid(network, 'generateEncryptedKey') } : {}), accessControlConditions: [allowPkpAddressToDecrypt], diff --git a/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts b/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts index 1c208ba2d2..46236d1408 100644 --- a/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts +++ b/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts @@ -33,7 +33,7 @@ export async function signMessageWithEncryptedKey( return signMessageWithLitAction({ ...params, - ...(network === 'evm' || network == 'solana' + ...(network === 'evm' || network === 'solana' ? { litActionIpfsCid: getLitActionCid(network, 'signMessage') } : {}), accessControlConditions: [allowPkpAddressToDecrypt], diff --git a/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts b/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts index c84da95bb3..51a5eb1209 100644 --- a/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts +++ b/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts @@ -34,7 +34,7 @@ export async function signTransactionWithEncryptedKey( return signTransactionWithLitAction({ ...params, - ...(network === 'evm' || network == 'solana' + ...(network === 'evm' || network === 'solana' ? { litActionIpfsCid: getLitActionCid(network, 'signTransaction') } : {}), storedKeyMetadata, From b66af98e5b2de0908da7bf1c689d20173a8ddfd0 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 02:45:02 +0100 Subject: [PATCH 13/30] test(wrapped-keys): LIT-3125 - Update fail tests - Replace try/catch at top-level `tinny-operations` so that failed tests don't...fail. But they still do ?! --- local-tests/setup/tinny-operations.ts | 134 +++++++++--------- .../tests/testCustomSignMessageWrappedKey.ts | 12 +- ...ailCustomGenerateKeyWithBothIpfsAndCode.ts | 13 +- ...TransactionWrappedKeysInsufficientFunds.ts | 12 +- ...nTransactionWrappedKeyInvalidDecryption.ts | 15 +- ...gnTransactionWrappedKeyWithInvalidParam.ts | 12 +- ...gnTransactionWrappedKeyWithMissingParam.ts | 24 ++-- ...tFailImportWrappedKeysWithEoaSessionSig.ts | 6 +- ...lImportWrappedKeysWithExpiredSessionSig.ts | 6 +- ...lImportWrappedKeysWithInvalidSessionSig.ts | 6 +- ...mportWrappedKeysWithMaxExpirySessionSig.ts | 6 +- .../testFailImportWrappedKeysWithSamePkp.ts | 8 +- ...FailImportWrappedKeysWithSamePrivateKey.ts | 5 +- 13 files changed, 139 insertions(+), 120 deletions(-) diff --git a/local-tests/setup/tinny-operations.ts b/local-tests/setup/tinny-operations.ts index 28bc2b370e..c7667d61b2 100644 --- a/local-tests/setup/tinny-operations.ts +++ b/local-tests/setup/tinny-operations.ts @@ -61,35 +61,35 @@ export const runInBand = async ({ while (attempts < maxAttempts && !testPassed) { const startTime = performance.now(); - // try { - console.log(`Attempt ${attempts + 1} for ${testName}...`); - - // @ts-ignore - await testFunction(devEnv); - testPassed = true; - - const endTime = performance.now(); - const timeTaken = (endTime - startTime).toFixed(2); - console.log(`${testName} - Passed (${timeTaken} ms)`); - passedTests.push(`${testName} (Passed in ${timeTaken} ms)`); - // } catch (error) { - // if (error.message === 'LIT_IGNORE_TEST') { - // skippedTests.push(`${testName} (Skipped)`); - // break; - // } - // attempts++; - // if (attempts >= maxAttempts) { - // const endTime = performance.now(); - // const timeTaken = (endTime - startTime).toFixed(2); - // console.error( - // `${testName} - Failed after ${maxAttempts} attempts (${timeTaken} ms)` - // ); - // console.error(`Error: ${error}`); - // failedTests.push( - // `${testName} (Failed in ${timeTaken} ms) - Error: ${error}` - // ); - // } - // } + try { + console.log(`Attempt ${attempts + 1} for ${testName}...`); + + // @ts-ignore + await testFunction(devEnv); + testPassed = true; + + const endTime = performance.now(); + const timeTaken = (endTime - startTime).toFixed(2); + console.log(`${testName} - Passed (${timeTaken} ms)`); + passedTests.push(`${testName} (Passed in ${timeTaken} ms)`); + } catch (error) { + if (error.message === 'LIT_IGNORE_TEST') { + skippedTests.push(`${testName} (Skipped)`); + break; + } + attempts++; + if (attempts >= maxAttempts) { + const endTime = performance.now(); + const timeTaken = (endTime - startTime).toFixed(2); + console.error( + `${testName} - Failed after ${maxAttempts} attempts (${timeTaken} ms)` + ); + console.error(`Error: ${error}`); + failedTests.push( + `${testName} (Failed in ${timeTaken} ms) - Error: ${error}` + ); + } + } await new Promise((resolve) => setTimeout(resolve, devEnv.processEnvs.RUN_IN_BAND_INTERVAL) @@ -154,44 +154,44 @@ export const runTestsParallel = async ({ while (attempts < maxAttempts && !testPassed) { const startTime = performance.now(); - // try { - console.log( - `\x1b[90m[runTestsParallel] Attempt ${attempts + 1} for ${ - testIndex + 1 - }. ${testName}...\x1b[0m` - ); - - // @ts-ignore - await testFunction(devEnv); - testPassed = true; - - const endTime = performance.now(); - const timeTaken = (endTime - startTime).toFixed(2); - console.log( - `\x1b[32m✔\x1b[90m ${ - testIndex + 1 - }. ${testName} - Passed (${timeTaken} ms)\x1b[0m` - ); - return `${testName} (Passed in ${timeTaken} ms)`; - // } catch (error) { - // if (error.message === 'LIT_IGNORE_TEST') { - // return `${testName} (Skipped)`; - // } - // attempts++; - // - // // wait for at least 5 seconds - // if (attempts >= maxAttempts) { - // const endTime = performance.now(); - // const timeTaken = (endTime - startTime).toFixed(2); - // console.error( - // `\x1b[31m✖\x1b[90m ${ - // testIndex + 1 - // }. ${testName} - Failed after ${maxAttempts} attempts (${timeTaken} ms)\x1b[0m` - // ); - // console.error(`\x1b[31m❌Error:\x1b[90m ${error}\x1b[0m`); - // return `${testName} (Failed in ${timeTaken} ms) - Error: ${error}`; - // } - // } + try { + console.log( + `\x1b[90m[runTestsParallel] Attempt ${attempts + 1} for ${ + testIndex + 1 + }. ${testName}...\x1b[0m` + ); + + // @ts-ignore + await testFunction(devEnv); + testPassed = true; + + const endTime = performance.now(); + const timeTaken = (endTime - startTime).toFixed(2); + console.log( + `\x1b[32m✔\x1b[90m ${ + testIndex + 1 + }. ${testName} - Passed (${timeTaken} ms)\x1b[0m` + ); + return `${testName} (Passed in ${timeTaken} ms)`; + } catch (error) { + if (error.message === 'LIT_IGNORE_TEST') { + return `${testName} (Skipped)`; + } + attempts++; + + // wait for at least 5 seconds + if (attempts >= maxAttempts) { + const endTime = performance.now(); + const timeTaken = (endTime - startTime).toFixed(2); + console.error( + `\x1b[31m✖\x1b[90m ${ + testIndex + 1 + }. ${testName} - Failed after ${maxAttempts} attempts (${timeTaken} ms)\x1b[0m` + ); + console.error(`\x1b[31m❌Error:\x1b[90m ${error}\x1b[0m`); + return `${testName} (Failed in ${timeTaken} ms) - Error: ${error}`; + } + } } } ); diff --git a/local-tests/tests/testCustomSignMessageWrappedKey.ts b/local-tests/tests/testCustomSignMessageWrappedKey.ts index c0fd13cf7d..66d0d3eae1 100644 --- a/local-tests/tests/testCustomSignMessageWrappedKey.ts +++ b/local-tests/tests/testCustomSignMessageWrappedKey.ts @@ -1,12 +1,11 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - customSignMessageWithEncryptedKey, - importPrivateKey, -} from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; +const { signMessageWithEncryptedKey, importPrivateKey } = api; + const CUSTOM_LIT_ACTION_CODE = ` (async () => { const LIT_PREFIX = 'lit_'; @@ -86,6 +85,8 @@ export const testCustomignMessageWrappedKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -106,7 +107,8 @@ export const testCustomignMessageWrappedKey = async ( const unsignedStringMessage = 'This is a test message'; - const signature = await customSignMessageWithEncryptedKey({ + const signature = await signMessageWithEncryptedKey({ + network: 'custom', pkpSessionSigs: pkpSessionSigsSigning, litActionCode: CUSTOM_LIT_ACTION_CODE, messageToSign: unsignedStringMessage, diff --git a/local-tests/tests/testFailCustomGenerateKeyWithBothIpfsAndCode.ts b/local-tests/tests/testFailCustomGenerateKeyWithBothIpfsAndCode.ts index 5098278c89..3cfab09b9d 100644 --- a/local-tests/tests/testFailCustomGenerateKeyWithBothIpfsAndCode.ts +++ b/local-tests/tests/testFailCustomGenerateKeyWithBothIpfsAndCode.ts @@ -1,8 +1,11 @@ import { log } from '@lit-protocol/misc'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { customGeneratePrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { LIT_ACTION_CID_REPOSITORY } from 'packages/wrapped-keys/src/lib/constants'; + +const { generatePrivateKey } = api; + +import { LIT_ACTION_CID_REPOSITORY } from '../../packages/wrapped-keys/src/lib/lit-actions-client/constants'; const CUSTOM_LIT_ACTION_CODE = ` (async () => { @@ -53,10 +56,10 @@ export const testFailCustomGenerateKeyWithBothIpfsAndCode = async ( ); // 10 mins expiry try { - await customGeneratePrivateKey({ + await generatePrivateKey({ + network: 'custom', pkpSessionSigs: alicePkpSessionSigs, - litActionIpfsCid: - LIT_ACTION_CID_REPOSITORY.generateEncryptedSolanaPrivateKey, + litActionIpfsCid: LIT_ACTION_CID_REPOSITORY.generateEncryptedKey.solana, litActionCode: CUSTOM_LIT_ACTION_CODE, litNodeClient: devEnv.litNodeClient, }); diff --git a/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts b/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts index 1ce50f1d5e..39017f7af8 100644 --- a/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts +++ b/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts @@ -1,14 +1,10 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - importPrivateKey, - signTransactionWithEncryptedKey, - EthereumLitTransaction, -} from '@lit-protocol/wrapped-keys'; +import { api, EthereumLitTransaction } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; +const { importPrivateKey, signTransactionWithEncryptedKey } = api; /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds @@ -34,6 +30,8 @@ export const testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds = pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -67,7 +65,7 @@ export const testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds = try { const _res = await signTransactionWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'evm', unsignedTransaction, broadcast: true, litNodeClient: devEnv.litNodeClient, diff --git a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyInvalidDecryption.ts b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyInvalidDecryption.ts index 2800723fe8..1d23602c9f 100644 --- a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyInvalidDecryption.ts +++ b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyInvalidDecryption.ts @@ -5,10 +5,8 @@ import { EthereumLitTransaction } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; import { getPkpAccessControlCondition } from 'packages/wrapped-keys/src/lib/utils'; import { encryptString } from '@lit-protocol/encryption'; -import { - LIT_ACTION_CID_REPOSITORY, - LIT_PREFIX, -} from 'packages/wrapped-keys/src/lib/constants'; +import { LIT_PREFIX } from 'packages/wrapped-keys/src/lib/constants'; +import { LIT_ACTION_CID_REPOSITORY } from '../../packages/wrapped-keys/src/lib/lit-actions-client/constants'; /** * Test Commands: @@ -21,11 +19,11 @@ export const testFailEthereumSignTransactionWrappedKeyInvalidDecryption = const alice = await devEnv.createRandomPerson(); const privateKey = ethers.Wallet.createRandom().privateKey; const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; - const decryptionAccessControlConditions = + const decryptionAccessControlCondition = getPkpAccessControlCondition(alicePkpAddress); const { ciphertext, dataToEncryptHash } = await encryptString( { - accessControlConditions: decryptionAccessControlConditions, + accessControlConditions: [decryptionAccessControlCondition], dataToEncrypt: LIT_PREFIX + privateKey, }, devEnv.litNodeClient @@ -55,13 +53,12 @@ export const testFailEthereumSignTransactionWrappedKeyInvalidDecryption = try { const _res = await devEnv.litNodeClient.executeJs({ sessionSigs: pkpSessionSigsSigning, - ipfsId: - LIT_ACTION_CID_REPOSITORY.signTransactionWithEthereumEncryptedKey, + ipfsId: LIT_ACTION_CID_REPOSITORY.signTransaction.evm, jsParams: { ciphertext, dataToEncryptHash, unsignedTransaction, - accessControlConditions: decryptionAccessControlConditions, + accessControlConditions: [decryptionAccessControlCondition], }, }); } catch (e: any) { diff --git a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts index 78f4658519..b6dee3a46e 100644 --- a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts +++ b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts @@ -1,14 +1,10 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - importPrivateKey, - signTransactionWithEncryptedKey, - EthereumLitTransaction, -} from '@lit-protocol/wrapped-keys'; +import { api, EthereumLitTransaction } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; +const { importPrivateKey, signTransactionWithEncryptedKey } = api; /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testFailEthereumSignTransactionWrappedKeyWithInvalidParam @@ -35,6 +31,8 @@ export const testFailEthereumSignTransactionWrappedKeyWithInvalidParam = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -66,7 +64,7 @@ export const testFailEthereumSignTransactionWrappedKeyWithInvalidParam = async ( try { const _res = await signTransactionWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, + network: 'evm', unsignedTransaction, broadcast: false, litNodeClient: devEnv.litNodeClient, diff --git a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts index 1b8788a972..398c48316e 100644 --- a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts +++ b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts @@ -1,14 +1,10 @@ import { log } from '@lit-protocol/misc'; import { ethers } from 'ethers'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - importPrivateKey, - signTransactionWithEncryptedKey, - SolanaLitTransaction, -} from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { NETWORK_EVM } from 'packages/wrapped-keys/src/lib/constants'; +const { importPrivateKey, signTransactionWithEncryptedKey } = api; /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testFailEthereumSignTransactionWrappedKeyWithMissingParam @@ -35,6 +31,8 @@ export const testFailEthereumSignTransactionWrappedKeyWithMissingParam = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -53,17 +51,15 @@ export const testFailEthereumSignTransactionWrappedKeyWithMissingParam = async ( console.log(pkpSessionSigsSigning); - // Using SolanaLitTransaction to mimic a missing field (chainId) param as Typescript will complain about missing chainId - const unsignedTransaction: SolanaLitTransaction = { - chain: 'chronicleTestnet', - serializedTransaction: 'random-value', - }; - try { const _res = await signTransactionWithEncryptedKey({ pkpSessionSigs: pkpSessionSigsSigning, - network: NETWORK_EVM, - unsignedTransaction, + network: 'evm', + unsignedTransaction: { + chain: 'chronicleTestnet', + // @ts-expect-error This test is intentionally using the type incorrectly. + serializedTransaction: 'random-value', + }, broadcast: false, litNodeClient: devEnv.litNodeClient, }); diff --git a/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts index 5667d336c4..666a06a7f6 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts @@ -1,8 +1,10 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { importPrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getEoaSessionSigs } from 'local-tests/setup/session-sigs/get-eoa-session-sigs'; import { randomSolanaPrivateKey } from 'local-tests/setup/tinny-utils'; +const { importPrivateKey } = api; + /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testFailImportWrappedKeysWithEoaSessionSig @@ -25,6 +27,8 @@ export const testFailImportWrappedKeysWithEoaSessionSig = async ( pkpSessionSigs: eoaSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); diff --git a/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts index 3f4e015932..80c76e9f0f 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts @@ -1,8 +1,10 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { importPrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { randomSolanaPrivateKey } from 'local-tests/setup/tinny-utils'; import { SessionSigsMap } from '@lit-protocol/types'; +const { importPrivateKey } = api; + /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testFailImportWrappedKeysWithExpiredSessionSig @@ -46,6 +48,8 @@ export const testFailImportWrappedKeysWithExpiredSessionSig = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); console.log(res); } catch (e: any) { diff --git a/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts index 1d17e0c5d6..be4b4e2849 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts @@ -1,9 +1,11 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { importPrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; import { randomSolanaPrivateKey } from 'local-tests/setup/tinny-utils'; import { AuthSig, SessionSigsMap } from '@lit-protocol/types'; +const { importPrivateKey } = api; + /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testFailImportWrappedKeysWithInvalidSessionSig @@ -26,6 +28,8 @@ export const testFailImportWrappedKeysWithInvalidSessionSig = async ( pkpSessionSigs: tamperPkpSessionSigs(pkpSessionSigs), privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); diff --git a/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts index a000c9f94c..26d9f3f7c1 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts @@ -1,8 +1,10 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { importPrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; import { randomSolanaPrivateKey } from 'local-tests/setup/tinny-utils'; +const { importPrivateKey } = api; + /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testFailImportWrappedKeysWithMaxExpirySessionSig @@ -25,6 +27,8 @@ export const testFailImportWrappedKeysWithMaxExpirySessionSig = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); diff --git a/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts b/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts index 170e82adad..3a21c6067e 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts @@ -1,8 +1,10 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { importPrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; import { randomSolanaPrivateKey } from 'local-tests/setup/tinny-utils'; +const { importPrivateKey } = api; + /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testFailImportWrappedKeysWithSamePkp @@ -29,6 +31,8 @@ export const testFailImportWrappedKeysWithSamePkp = async ( pkpSessionSigs, privateKey: privateKey1, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -47,6 +51,8 @@ export const testFailImportWrappedKeysWithSamePkp = async ( pkpSessionSigs, privateKey: privateKey2, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); diff --git a/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts b/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts index 56caa62090..188d6acba3 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts @@ -1,7 +1,8 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { importPrivateKey } from '@lit-protocol/wrapped-keys'; +import { api } from '@lit-protocol/wrapped-keys'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; +const { importPrivateKey } = api; /** * Test Commands: * ✅ NETWORK=cayenne yarn test:local --filter=testFailImportWrappedKeysWithSamePrivateKey @@ -30,6 +31,8 @@ export const testFailImportWrappedKeysWithSamePrivateKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, + address: '0xdeadbeef', + algo: 'K256', }); } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); From d8d17cef9d0a4d7e265d1374517c11c96b839800 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 18:44:53 +0100 Subject: [PATCH 14/30] chore(wrapped-keys): LIT-3125 - Rename `algo` to `keyType` to avoid confusion with the `algo` key on sigs returned from the LIT network nodes --- README.md | 62 +++++++++---------- .../tests/testCustomSignMessageWrappedKey.ts | 2 +- .../testCustomSignTransactionWrappedKey.ts | 2 +- ...tEthereumBroadcastTransactionWrappedKey.ts | 2 +- ...umBroadcastWrappedKeyWithFetchGasParams.ts | 2 +- .../testEthereumSignMessageWrappedKey.ts | 2 +- .../testEthereumSignTransactionWrappedKey.ts | 2 +- local-tests/tests/testExportWrappedKey.ts | 2 +- ...TransactionWrappedKeysInsufficientFunds.ts | 2 +- ...gnTransactionWrappedKeyWithInvalidParam.ts | 2 +- ...gnTransactionWrappedKeyWithMissingParam.ts | 2 +- ...tFailImportWrappedKeysWithEoaSessionSig.ts | 2 +- ...lImportWrappedKeysWithExpiredSessionSig.ts | 2 +- ...lImportWrappedKeysWithInvalidSessionSig.ts | 2 +- ...mportWrappedKeysWithMaxExpirySessionSig.ts | 2 +- .../testFailImportWrappedKeysWithSamePkp.ts | 4 +- ...FailImportWrappedKeysWithSamePrivateKey.ts | 2 +- local-tests/tests/testImportWrappedKey.ts | 2 +- .../testSignMessageWithSolanaEncryptedKey.ts | 2 +- ...stSignTransactionWithSolanaEncryptedKey.ts | 2 +- .../src/lib/api/generate-private-key.ts | 2 +- .../src/lib/api/import-private-key.ts | 5 +- .../src/lib/service-client/types.ts | 4 +- packages/wrapped-keys/src/lib/types.ts | 8 +-- 24 files changed, 60 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 452f2d2023..5f0be3b400 100644 --- a/README.md +++ b/README.md @@ -50,41 +50,39 @@ yarn add @lit-protocol/lit-node-client -Package | Category | Download ---- | --- | --- -| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 "lit-node-client-nodejs") | -| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 "lit-node-client") | - +| Package | Category | Download | +| -------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 'lit-node-client-nodejs') | | +| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 'lit-node-client') | | If you're a tech-savvy user and wish to utilize only specific submodules that our main module relies upon, you can find individual packages listed below. This way, you can import only the necessary packages that cater to your specific use case:: - -Package | Category | Download ---- | --- | --- -| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 "access-control-conditions") | -| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 "auth-helpers") | -| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 "bls-sdk") | -| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 "constants") | -| [@lit-protocol/contracts-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/contracts-sdk) | ![contracts-sdk](https://img.shields.io/badge/-universal-8A6496 "contracts-sdk") | -| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 "core") | -| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 "crypto") | -| [@lit-protocol/ecdsa-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/ecdsa-sdk) | ![ecdsa-sdk](https://img.shields.io/badge/-universal-8A6496 "ecdsa-sdk") | -| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 "encryption") | -| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 "logger") | -| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 "misc") | -| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 "nacl") | -| [@lit-protocol/pkp-base](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-base) | ![pkp-base](https://img.shields.io/badge/-universal-8A6496 "pkp-base") | -| [@lit-protocol/pkp-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-client) | ![pkp-client](https://img.shields.io/badge/-universal-8A6496 "pkp-client") | -| [@lit-protocol/pkp-cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) | ![pkp-cosmos](https://img.shields.io/badge/-universal-8A6496 "pkp-cosmos") | -| [@lit-protocol/pkp-ethers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-ethers) | ![pkp-ethers](https://img.shields.io/badge/-universal-8A6496 "pkp-ethers") | -| [@lit-protocol/pkp-sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) | ![pkp-sui](https://img.shields.io/badge/-universal-8A6496 "pkp-sui") | -| [@lit-protocol/pkp-walletconnect](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-walletconnect) | ![pkp-walletconnect](https://img.shields.io/badge/-universal-8A6496 "pkp-walletconnect") | -| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 "sev-snp-utils-sdk") | -| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 "types") | -| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 "uint8arrays") | -| [@lit-protocol/wrapped-keys](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys) | ![wrapped-keys](https://img.shields.io/badge/-universal-8A6496 "wrapped-keys") | -| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 "auth-browser") | -| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 "misc-browser") | +| Package | Category | Download | +| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 'access-control-conditions') | | +| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 'auth-helpers') | | +| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 'bls-sdk') | | +| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 'constants') | | +| [@lit-protocol/contracts-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/contracts-sdk) | ![contracts-sdk](https://img.shields.io/badge/-universal-8A6496 'contracts-sdk') | | +| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 'core') | | +| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 'crypto') | | +| [@lit-protocol/ecdsa-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/ecdsa-sdk) | ![ecdsa-sdk](https://img.shields.io/badge/-universal-8A6496 'ecdsa-sdk') | | +| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 'encryption') | | +| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 'logger') | | +| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 'misc') | | +| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 'nacl') | | +| [@lit-protocol/pkp-base](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-base) | ![pkp-base](https://img.shields.io/badge/-universal-8A6496 'pkp-base') | | +| [@lit-protocol/pkp-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-client) | ![pkp-client](https://img.shields.io/badge/-universal-8A6496 'pkp-client') | | +| [@lit-protocol/pkp-cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) | ![pkp-cosmos](https://img.shields.io/badge/-universal-8A6496 'pkp-cosmos') | | +| [@lit-protocol/pkp-ethers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-ethers) | ![pkp-ethers](https://img.shields.io/badge/-universal-8A6496 'pkp-ethers') | | +| [@lit-protocol/pkp-sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) | ![pkp-sui](https://img.shields.io/badge/-universal-8A6496 'pkp-sui') | | +| [@lit-protocol/pkp-walletconnect](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-walletconnect) | ![pkp-walletconnect](https://img.shields.io/badge/-universal-8A6496 'pkp-walletconnect') | | +| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 'sev-snp-utils-sdk') | | +| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 'types') | | +| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 'uint8arrays') | | +| [@lit-protocol/wrapped-keys](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys) | ![wrapped-keys](https://img.shields.io/badge/-universal-8A6496 'wrapped-keys') | | +| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 'auth-browser') | | +| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 'misc-browser') | | diff --git a/local-tests/tests/testCustomSignMessageWrappedKey.ts b/local-tests/tests/testCustomSignMessageWrappedKey.ts index 66d0d3eae1..6f942d0e5b 100644 --- a/local-tests/tests/testCustomSignMessageWrappedKey.ts +++ b/local-tests/tests/testCustomSignMessageWrappedKey.ts @@ -86,7 +86,7 @@ export const testCustomignMessageWrappedKey = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testCustomSignTransactionWrappedKey.ts b/local-tests/tests/testCustomSignTransactionWrappedKey.ts index 0d76f0c97b..2988ca52eb 100644 --- a/local-tests/tests/testCustomSignTransactionWrappedKey.ts +++ b/local-tests/tests/testCustomSignTransactionWrappedKey.ts @@ -109,7 +109,7 @@ export const testCustomSignTransactionWrappedKey = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts b/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts index d552298195..1a4bee14eb 100644 --- a/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts +++ b/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts @@ -38,7 +38,7 @@ export const testEthereumBroadcastTransactionWrappedKey = async ( privateKey: wrappedKeysWalletPrivateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts b/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts index 91b85b3390..001d1dbfa3 100644 --- a/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts +++ b/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts @@ -38,7 +38,7 @@ export const testEthereumBroadcastWrappedKeyWithFetchGasParams = async ( privateKey: wrappedKeysWalletPrivateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testEthereumSignMessageWrappedKey.ts b/local-tests/tests/testEthereumSignMessageWrappedKey.ts index b7f41a8481..e51f8f8f0c 100644 --- a/local-tests/tests/testEthereumSignMessageWrappedKey.ts +++ b/local-tests/tests/testEthereumSignMessageWrappedKey.ts @@ -33,7 +33,7 @@ export const testEthereumSignMessageWrappedKey = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testEthereumSignTransactionWrappedKey.ts b/local-tests/tests/testEthereumSignTransactionWrappedKey.ts index 481bc8ea54..f3ca8ae207 100644 --- a/local-tests/tests/testEthereumSignTransactionWrappedKey.ts +++ b/local-tests/tests/testEthereumSignTransactionWrappedKey.ts @@ -35,7 +35,7 @@ export const testEthereumSignTransactionWrappedKey = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testExportWrappedKey.ts b/local-tests/tests/testExportWrappedKey.ts index 0ecbfa5893..8a9e70a87e 100644 --- a/local-tests/tests/testExportWrappedKey.ts +++ b/local-tests/tests/testExportWrappedKey.ts @@ -30,7 +30,7 @@ export const testExportWrappedKey = async (devEnv: TinnyEnvironment) => { privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts b/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts index 39017f7af8..509ad2da23 100644 --- a/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts +++ b/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts @@ -31,7 +31,7 @@ export const testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds = privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts index b6dee3a46e..e559fa70f4 100644 --- a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts +++ b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts @@ -32,7 +32,7 @@ export const testFailEthereumSignTransactionWrappedKeyWithInvalidParam = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts index 398c48316e..300dd07d19 100644 --- a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts +++ b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts @@ -32,7 +32,7 @@ export const testFailEthereumSignTransactionWrappedKeyWithMissingParam = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts index 666a06a7f6..1a184330fb 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts @@ -28,7 +28,7 @@ export const testFailImportWrappedKeysWithEoaSessionSig = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); diff --git a/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts index 80c76e9f0f..fe876ad52c 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts @@ -49,7 +49,7 @@ export const testFailImportWrappedKeysWithExpiredSessionSig = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); console.log(res); } catch (e: any) { diff --git a/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts index be4b4e2849..645cfe5d39 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts @@ -29,7 +29,7 @@ export const testFailImportWrappedKeysWithInvalidSessionSig = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); diff --git a/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts index 26d9f3f7c1..eaf067ada6 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts @@ -28,7 +28,7 @@ export const testFailImportWrappedKeysWithMaxExpirySessionSig = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); diff --git a/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts b/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts index 3a21c6067e..a41920a9d8 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts @@ -32,7 +32,7 @@ export const testFailImportWrappedKeysWithSamePkp = async ( privateKey: privateKey1, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; @@ -52,7 +52,7 @@ export const testFailImportWrappedKeysWithSamePkp = async ( privateKey: privateKey2, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); diff --git a/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts b/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts index 188d6acba3..1479c8b6be 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts @@ -32,7 +32,7 @@ export const testFailImportWrappedKeysWithSamePrivateKey = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); } catch (e: any) { console.log('❌ THIS IS EXPECTED: ', e); diff --git a/local-tests/tests/testImportWrappedKey.ts b/local-tests/tests/testImportWrappedKey.ts index 6e2c6f3a07..a12d58283d 100644 --- a/local-tests/tests/testImportWrappedKey.ts +++ b/local-tests/tests/testImportWrappedKey.ts @@ -32,7 +32,7 @@ export const testImportWrappedKey = async (devEnv: TinnyEnvironment) => { privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts b/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts index 799de2dc68..8fe1f46d3e 100644 --- a/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts +++ b/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts @@ -36,7 +36,7 @@ export const testSignMessageWithSolanaEncryptedKey = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts b/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts index 2c68e96850..be8cf15319 100644 --- a/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts +++ b/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts @@ -42,7 +42,7 @@ export const testSignTransactionWithSolanaEncryptedKey = async ( privateKey, litNodeClient: devEnv.litNodeClient, address: '0xdeadbeef', - algo: 'K256', + keyType: 'K256', }); const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; diff --git a/packages/wrapped-keys/src/lib/api/generate-private-key.ts b/packages/wrapped-keys/src/lib/api/generate-private-key.ts index 16ebd0fb46..cc54c640a5 100644 --- a/packages/wrapped-keys/src/lib/api/generate-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/generate-private-key.ts @@ -45,7 +45,7 @@ export async function generatePrivateKey( storedKeyMetadata: { ciphertext, address: publicKey, // FIXME: If we're storing address and it is _not_ the publicKey directly, then we need the generate LIT action to return it for us - algo: LIT_CURVE.EcdsaK256, // FIXME: Should be returned by the LIT action; we won't know what it is unless it's provided. + keyType: LIT_CURVE.EcdsaK256, // FIXME: Should be returned by the LIT action; we won't know what it is unless it's provided. dataToEncryptHash, pkpAddress, }, diff --git a/packages/wrapped-keys/src/lib/api/import-private-key.ts b/packages/wrapped-keys/src/lib/api/import-private-key.ts index 43edfc1fdb..d1baded028 100644 --- a/packages/wrapped-keys/src/lib/api/import-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/import-private-key.ts @@ -21,7 +21,8 @@ import { export async function importPrivateKey( params: ImportPrivateKeyParams ): Promise { - const { pkpSessionSigs, privateKey, address, algo, litNodeClient } = params; + const { pkpSessionSigs, privateKey, address, keyType, litNodeClient } = + params; const firstSessionSig = getFirstSessionSig(pkpSessionSigs); const pkpAddress = getPkpAddressFromSessionSig(firstSessionSig); @@ -43,7 +44,7 @@ export async function importPrivateKey( storedKeyMetadata: { ciphertext, address, - algo, + keyType, dataToEncryptHash, pkpAddress, }, diff --git a/packages/wrapped-keys/src/lib/service-client/types.ts b/packages/wrapped-keys/src/lib/service-client/types.ts index 21ab56243a..c453ef224f 100644 --- a/packages/wrapped-keys/src/lib/service-client/types.ts +++ b/packages/wrapped-keys/src/lib/service-client/types.ts @@ -21,14 +21,14 @@ export interface StoredKeyMetadata { dataToEncryptHash: string; address: string; pkpAddress: string; - algo: string; + keyType: string; litNetwork: SupportedNetworks; } export interface StoreKeyParams extends BaseApiParams { storedKeyMetadata: Pick< StoredKeyMetadata, - 'pkpAddress' | 'address' | 'algo' | 'dataToEncryptHash' | 'ciphertext' + 'pkpAddress' | 'address' | 'keyType' | 'dataToEncryptHash' | 'ciphertext' >; } diff --git a/packages/wrapped-keys/src/lib/types.ts b/packages/wrapped-keys/src/lib/types.ts index 9af360d6d4..1e86437922 100644 --- a/packages/wrapped-keys/src/lib/types.ts +++ b/packages/wrapped-keys/src/lib/types.ts @@ -61,7 +61,7 @@ export type ExportPrivateKeyParams = BaseApiParams; * @property { string } decryptedPrivateKey The decrypted, plain text private key that was persisted to the wrapped keys service * @property { string } pkpAddress The LIT PKP Address that the key was linked to; this is derived from the provided pkpSessionSigs * @property { string } address The 'address' is typically based on the public key of the key being imported into the wrapped keys service - * @property { string } algo The algorithm type of the key; this might be K256, ed25519, or other key formats. The `algo` will be included in the metadata returned from the wrapped keys service + * @property { string } keyType The algorithm type of the key; this might be K256, ed25519, or other key formats. The `keyType` will be included in the metadata returned from the wrapped keys service * */ export interface ExportPrivateKeyResult { @@ -69,7 +69,7 @@ export interface ExportPrivateKeyResult { decryptedPrivateKey: string; address: string; litNetwork: LIT_NETWORKS_KEYS; - algo: string; + keyType: string; } type GeneratePrivateKeyParamsSupportedNetworks = BaseApiParams & @@ -104,12 +104,12 @@ export interface GeneratePrivateKeyResult { * * @property { string } privateKey The private key to be imported into the wrapped keys service * @property { string } address The 'address' is typically based on the public key of the key being imported into the wrapped keys service - * @property { string } algo The algorithm type of the key; this might be K256, ed25519, or other key formats. The `algo` will be included in the metadata returned from the wrapped keys service + * @property { string } keyType The algorithm type of the key; this might be K256, ed25519, or other key formats. The `keyType` will be included in the metadata returned from the wrapped keys service */ export interface ImportPrivateKeyParams extends BaseApiParams { privateKey: string; address: string; - algo: string; + keyType: string; } interface SignMessageParams { From 9eb0f47fcedb250797b0a4a8d48fef0883d82967 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 19:30:23 +0100 Subject: [PATCH 15/30] chore(wrapped-keys): LIT-3125 - Remove 'custom' API behaviours and types in favour of composition for the 'custom' case --- .../src/lib/api/generate-private-key.ts | 4 +- .../api/sign-message-with-encrypted-key.ts | 7 +- .../sign-transaction-with-encrypted-key.ts | 7 +- .../lib/lit-actions-client/generate-key.ts | 26 ++------ .../lib/lit-actions-client/sign-message.ts | 23 ++----- .../lit-actions-client/sign-transaction.ts | 31 +++------ .../src/lib/lit-actions-client/types.ts | 7 +- packages/wrapped-keys/src/lib/types.ts | 64 ++----------------- 8 files changed, 29 insertions(+), 140 deletions(-) diff --git a/packages/wrapped-keys/src/lib/api/generate-private-key.ts b/packages/wrapped-keys/src/lib/api/generate-private-key.ts index cc54c640a5..4eed3edadb 100644 --- a/packages/wrapped-keys/src/lib/api/generate-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/generate-private-key.ts @@ -34,9 +34,7 @@ export async function generatePrivateKey( await generateKeyWithLitAction({ ...params, pkpAddress, - ...(network === 'evm' || network === 'solana' - ? { litActionIpfsCid: getLitActionCid(network, 'generateEncryptedKey') } - : {}), + litActionIpfsCid: getLitActionCid(network, 'generateEncryptedKey'), accessControlConditions: [allowPkpAddressToDecrypt], }); diff --git a/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts b/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts index 46236d1408..de3fa96f38 100644 --- a/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts +++ b/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts @@ -9,9 +9,6 @@ import { getFirstSessionSig, getPkpAccessControlCondition } from '../utils'; * This method fetches the encrypted key from the wrapped keys service, then executes a Lit Action that decrypts the key inside the LIT action and uses * the decrypted key to sign the provided transaction * - * NOTE: If you use `custom` as `network`, you must provide either an IPFS CID or the direct source code of the LIT action you want - * to be responsible for decrypting the encrypted key and signing the message - * * @param { SignMessageWithEncryptedKeyParams } params Parameters to use for signing the message * * @returns { Promise } - The signed message @@ -33,9 +30,7 @@ export async function signMessageWithEncryptedKey( return signMessageWithLitAction({ ...params, - ...(network === 'evm' || network === 'solana' - ? { litActionIpfsCid: getLitActionCid(network, 'signMessage') } - : {}), + litActionIpfsCid: getLitActionCid(network, 'signMessage'), accessControlConditions: [allowPkpAddressToDecrypt], pkpSessionSigs, storedKeyMetadata, diff --git a/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts b/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts index 51a5eb1209..2ba774dcdd 100644 --- a/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts +++ b/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts @@ -10,9 +10,6 @@ import { getFirstSessionSig, getPkpAccessControlCondition } from '../utils'; * the decrypted key to sign the provided transaction * Optionally, if you pass `broadcast: true`, the LIT action will also submit the signed transaction to the associated RPC endpoint on your behalf * - * * NOTE: If you use `custom` as `network`, you must provide either an IPFS CID or the direct source code of the LIT action you want - * to be responsible for decrypting the encrypted key, signing the message, and supporting `broadcast: true` if you set it. - * * @param { SignTransactionWithEncryptedKeyParams } params Parameters required to sign the requested transaction * * @returns { string } The signed transaction OR its transaction hash if you set `broadcast: true` and the LIT action supports this functionality. @@ -34,9 +31,7 @@ export async function signTransactionWithEncryptedKey( return signTransactionWithLitAction({ ...params, - ...(network === 'evm' || network === 'solana' - ? { litActionIpfsCid: getLitActionCid(network, 'signTransaction') } - : {}), + litActionIpfsCid: getLitActionCid(network, 'signTransaction'), storedKeyMetadata, accessControlConditions: [allowPkpAddressToDecrypt], }); diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts b/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts index 838fae17be..cf2097cbd0 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts @@ -1,18 +1,12 @@ -import { - AccessControlConditions, - ILitNodeClient, - SessionSigsMap, -} from '@lit-protocol/types'; +import { AccessControlConditions } from '@lit-protocol/types'; import { postLitActionValidation } from './utils'; +import { GeneratePrivateKeyParams } from '../../index'; -interface GeneratePrivateKeyLitActionParams { - pkpSessionSigs: SessionSigsMap; +interface GeneratePrivateKeyLitActionParams extends GeneratePrivateKeyParams { pkpAddress: string; - litActionIpfsCid?: string; - litActionCode?: string; accessControlConditions: AccessControlConditions; - litNodeClient: ILitNodeClient; + litActionIpfsCid: string; } interface GeneratePrivateKeyLitActionResult { @@ -25,25 +19,13 @@ export async function generateKeyWithLitAction({ litNodeClient, pkpSessionSigs, litActionIpfsCid, - litActionCode, accessControlConditions, pkpAddress, }: GeneratePrivateKeyLitActionParams): Promise { - if (!litActionIpfsCid && !litActionCode) { - throw new Error( - 'Have to provide either the litActionIpfsCid or litActionCode' - ); - } - - if (litActionIpfsCid && litActionCode) { - throw new Error("Can't provide both a litActionIpfsCid or litActionCode"); - } - try { const result = await litNodeClient.executeJs({ sessionSigs: pkpSessionSigs, ipfsId: litActionIpfsCid, - code: litActionCode, jsParams: { pkpAddress, accessControlConditions, diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts b/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts index 711ca706ac..c2817e982c 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts @@ -1,23 +1,14 @@ -import { - AccessControlConditions, - ILitNodeClient, - SessionSigsMap, -} from '@lit-protocol/types'; +import { AccessControlConditions } from '@lit-protocol/types'; import { postLitActionValidation } from './utils'; import { StoredKeyMetadata } from '../service-client'; -import { Network } from '../types'; +import { SignMessageWithEncryptedKeyParams } from '../types'; -interface SignMessageWithLitActionParams { - pkpSessionSigs: SessionSigsMap; - litNodeClient: ILitNodeClient; +interface SignMessageWithLitActionParams + extends SignMessageWithEncryptedKeyParams { accessControlConditions: AccessControlConditions; storedKeyMetadata: StoredKeyMetadata; - network: Network; - litActionIpfsCid?: string; - litActionCode?: string; - params?: Record; - messageToSign: string | Uint8Array; + litActionIpfsCid: string; } export async function signMessageWithLitAction( @@ -29,9 +20,7 @@ export async function signMessageWithLitAction( messageToSign, pkpSessionSigs, litActionIpfsCid, - litActionCode, storedKeyMetadata, - params, } = args; try { @@ -39,14 +28,12 @@ export async function signMessageWithLitAction( const result = await litNodeClient.executeJs({ sessionSigs: pkpSessionSigs, ipfsId: litActionIpfsCid, - code: litActionCode, jsParams: { pkpAddress, ciphertext, dataToEncryptHash, messageToSign, accessControlConditions, - ...params, }, }); return postLitActionValidation(result); diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts b/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts index 7160fb2f95..d9bf2a8512 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts @@ -11,36 +11,26 @@ import { EthereumLitTransaction, SerializedTransaction } from '../types'; interface SignTransactionWithLitActionParams { litNodeClient: ILitNodeClient; pkpSessionSigs: SessionSigsMap; - litActionIpfsCid?: string; - litActionCode?: string; + litActionIpfsCid: string; unsignedTransaction: EthereumLitTransaction | SerializedTransaction; storedKeyMetadata: StoredKeyMetadata; accessControlConditions: AccessControlConditions; broadcast: boolean; - params?: Record; } -export async function signTransactionWithLitAction( - args: SignTransactionWithLitActionParams -): Promise { - const { - storedKeyMetadata, - pkpSessionSigs, - litNodeClient, - unsignedTransaction, - broadcast, - accessControlConditions, - litActionCode, - litActionIpfsCid, - params, - } = args; - - const { ciphertext, dataToEncryptHash, pkpAddress } = storedKeyMetadata; +export async function signTransactionWithLitAction({ + accessControlConditions, + broadcast, + litActionIpfsCid, + litNodeClient, + pkpSessionSigs, + storedKeyMetadata: { ciphertext, dataToEncryptHash, pkpAddress }, + unsignedTransaction, +}: SignTransactionWithLitActionParams): Promise { try { const result = await litNodeClient.executeJs({ sessionSigs: pkpSessionSigs, ipfsId: litActionIpfsCid, - code: litActionCode, jsParams: { pkpAddress, ciphertext, @@ -48,7 +38,6 @@ export async function signTransactionWithLitAction( unsignedTransaction, broadcast, accessControlConditions, - ...params, }, }); diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/types.ts b/packages/wrapped-keys/src/lib/lit-actions-client/types.ts index 1062ad36f8..3b2f653b89 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/types.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/types.ts @@ -5,12 +5,7 @@ export type LitActionType = | 'signMessage' | 'generateEncryptedKey'; -export type LitActionSupportedNetworks = Extract; - -// 'custom' have no entries in the CID repository, by definition they are external resources. -export type LitCidRepositoryEntry = Readonly< - Record ->; +export type LitCidRepositoryEntry = Readonly>; export type LitCidRepository = Readonly< Record diff --git a/packages/wrapped-keys/src/lib/types.ts b/packages/wrapped-keys/src/lib/types.ts index 1e86437922..d3ae36c264 100644 --- a/packages/wrapped-keys/src/lib/types.ts +++ b/packages/wrapped-keys/src/lib/types.ts @@ -5,11 +5,9 @@ import { } from '@lit-protocol/types'; /** @typedef Network - * The network type that the wrapped key is for. - * In case of 'evm' or 'solana', pre-written LIT actions will be used to perform operations - * In case of 'custom', you will need to provide a LIT action source code or an IPFS CID where LIT action source code exists in order to perform the operation when you call API methods + * The network type that the wrapped key will be used on. */ -export type Network = 'evm' | 'solana' | 'custom'; +export type Network = 'evm' | 'solana'; /** All API calls for the wrapped keys service require these arguments. * @@ -23,19 +21,7 @@ export interface BaseApiParams { } export interface ApiParamsSupportedNetworks { - network: Extract; -} - -export interface ApiParamsCustomIpfs extends BaseApiParams { - network: Extract; - litActionIpfsCid: string; - params?: Record; -} - -export interface ApiParamsCustomCode extends BaseApiParams { - network: Extract; - litActionCode: string; - params?: Record; + network: Network; } /** Fetching a previously persisted key's metadata only requires valid pkpSessionSigs and a LIT Node Client instance configured for the appropriate network. @@ -74,20 +60,13 @@ export interface ExportPrivateKeyResult { type GeneratePrivateKeyParamsSupportedNetworks = BaseApiParams & ApiParamsSupportedNetworks; -type GeneratePrivateKeyParamsCustomIpfs = BaseApiParams & ApiParamsCustomIpfs; -type GeneratePrivateKeyParamsCustomCode = BaseApiParams & ApiParamsCustomCode; /** @typedef GeneratePrivateKeyParams * @extends BaseApiParams * @property {Network} network The network for which the private key needs to be generated; keys are generated differently for different networks - * @property {string} [litActionIpfsCid] The IPFS CID of the LIT Action to run which will be responsible for generating the key - * @property {string} [litActionCode] A string of the raw source code of the LIT Action to run which will be responsible for generating the key - * @property {object} [params] Additional parameters to be passed through to the LIT action that is performing the key generation */ export type GeneratePrivateKeyParams = - | GeneratePrivateKeyParamsSupportedNetworks - | GeneratePrivateKeyParamsCustomIpfs - | GeneratePrivateKeyParamsCustomCode; + GeneratePrivateKeyParamsSupportedNetworks; /** @typedef GeneratePrivateKeyResult * @property { string } pkpAddress The LIT PKP Address that the key was linked to; this is derived from the provided pkpSessionSigs @@ -120,26 +99,13 @@ type SignMessageWithEncryptedKeyParamsSupportedNetworks = BaseApiParams & ApiParamsSupportedNetworks & SignMessageParams; -type SignMessageWithEncryptedKeyParamsCustomIpfs = BaseApiParams & - ApiParamsCustomIpfs & - SignMessageParams; - -type SignMessageWithEncryptedKeyParamsCustomCode = BaseApiParams & - ApiParamsCustomCode & - SignMessageParams; - /** @typedef SignMessageWithEncryptedKeyParams * @extends BaseApiParams * * @property { string | Uint8Array } messageToSign The message to be signed - * @property {string} [litActionIpfsCid] The IPFS CID of the LIT Action to run which will be responsible for generating the key. Only relevant when using network is `custom`. You can only include this OR litActionCode. - * @property {string} [litActionCode] A string of the raw source code of the LIT Action to run which will be responsible for generating the key. Only relevant when using `custom` network. You can only include this OR litActionIpfsCid. - * @property {object} [params] Additional parameters to be passed through to the LIT action that is signing the provided message */ export type SignMessageWithEncryptedKeyParams = - | SignMessageWithEncryptedKeyParamsSupportedNetworks - | SignMessageWithEncryptedKeyParamsCustomIpfs - | SignMessageWithEncryptedKeyParamsCustomCode; + SignMessageWithEncryptedKeyParamsSupportedNetworks; interface BaseLitTransaction { chain: string; @@ -184,29 +150,11 @@ interface SignTransactionParamsSupportedSolana extends SignTransactionParams { network: Extract; } -interface SignTransactionWithEncryptedKeyParamsCustomIpfs - extends SignTransactionParams, - ApiParamsCustomIpfs { - unsignedTransaction: SerializedTransaction; -} - -interface SignTransactionWithEncryptedKeyParamsCustomCode - extends SignTransactionParams, - ApiParamsCustomCode { - unsignedTransaction: SerializedTransaction; -} - /** @typedef SignTransactionWithEncryptedKeyParams * @extends BaseApiParams * @property { boolean } broadcast Whether the LIT action should broadcast the signed transaction to RPC, or only sign the transaction and return the signed transaction to the caller * @property { EthereumLitTransaction | SerializedTransaction } unsignedTransaction The unsigned transaction to be signed. When network is 'solana' or 'custom', be sure to provided a {@link SerializedTransaction} instance. - * @property {string} [litActionIpfsCid] The IPFS CID of the LIT Action to run which will be responsible for generating the key. Only relevant when using network is `custom`. You can only include this OR litActionCode. - * @property {string} [litActionCode] A string of the raw source code of the LIT Action to run which will be responsible for generating the key. Only relevant when using `custom` network. You can only include this OR litActionIpfsCid. - * @property {object} [params] Additional parameters to be passed through to the LIT action that is signing the provided transaction - * */ export type SignTransactionWithEncryptedKeyParams = | SignTransactionParamsSupportedEvm - | SignTransactionParamsSupportedSolana - | SignTransactionWithEncryptedKeyParamsCustomIpfs - | SignTransactionWithEncryptedKeyParamsCustomCode; + | SignTransactionParamsSupportedSolana; From 900ede13d071e2bea7f0e2fb74a5dbfe92ff85c9 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 19:32:12 +0100 Subject: [PATCH 16/30] chore(wrapped-keys): LIT-3125 - Remove 'custom' tests --- local-tests/test.ts | 6 - .../tests/testCustomGenerateWrappedKey.ts | 105 ----------- .../tests/testCustomSignMessageWrappedKey.ts | 126 ------------- .../testCustomSignTransactionWrappedKey.ts | 174 ------------------ ...ailCustomGenerateKeyWithBothIpfsAndCode.ts | 81 -------- 5 files changed, 492 deletions(-) delete mode 100644 local-tests/tests/testCustomGenerateWrappedKey.ts delete mode 100644 local-tests/tests/testCustomSignMessageWrappedKey.ts delete mode 100644 local-tests/tests/testCustomSignTransactionWrappedKey.ts delete mode 100644 local-tests/tests/testFailCustomGenerateKeyWithBothIpfsAndCode.ts diff --git a/local-tests/test.ts b/local-tests/test.ts index f2f2ead32f..ce614fe364 100644 --- a/local-tests/test.ts +++ b/local-tests/test.ts @@ -85,7 +85,6 @@ import { testExecuteJsBroadcastAndCollect } from './tests/testExecuteJsBroadcast import { testEthereumSignMessageGeneratedKey } from './tests/testEthereumSignMessageGeneratedKey'; import { testEthereumBroadcastTransactionGeneratedKey } from './tests/testEthereumBroadcastTransactionGeneratedKey'; -import { testCustomignMessageWrappedKey } from './tests/testCustomSignMessageWrappedKey'; import { testEthereumSignMessageWrappedKey } from './tests/testEthereumSignMessageWrappedKey'; import { testFailEthereumSignTransactionWrappedKeyInvalidDecryption } from './tests/testFailEthereumSignTransactionWrappedKeyInvalidDecryption'; import { testEthereumSignTransactionWrappedKey } from './tests/testEthereumSignTransactionWrappedKey'; @@ -97,14 +96,12 @@ import { testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds } from import { testImportWrappedKey } from './tests/testImportWrappedKey'; import { testGenerateEthereumWrappedKey } from './tests/testGenerateEthereumWrappedKey'; import { testGenerateSolanaWrappedKey } from './tests/testGenerateSolanaWrappedKey'; -import { testCustomGenerateWrappedKey } from './tests/testCustomGenerateWrappedKey'; import { testFailImportWrappedKeysWithSamePkp } from './tests/testFailImportWrappedKeysWithSamePkp'; import { testFailImportWrappedKeysWithSamePrivateKey } from './tests/testFailImportWrappedKeysWithSamePrivateKey'; import { testFailImportWrappedKeysWithEoaSessionSig } from './tests/testFailImportWrappedKeysWithEoaSessionSig'; import { testFailImportWrappedKeysWithMaxExpirySessionSig } from './tests/testFailImportWrappedKeysWithMaxExpirySessionSig'; import { testFailImportWrappedKeysWithInvalidSessionSig } from './tests/testFailImportWrappedKeysWithInvalidSessionSig'; import { testFailImportWrappedKeysWithExpiredSessionSig } from './tests/testFailImportWrappedKeysWithExpiredSessionSig'; -import { testFailCustomGenerateKeyWithBothIpfsAndCode } from './tests/testFailCustomGenerateKeyWithBothIpfsAndCode'; import { testExportWrappedKey } from './tests/testExportWrappedKey'; import { testSignMessageWithSolanaEncryptedKey } from './tests/testSignMessageWithSolanaEncryptedKey'; import { testSignTransactionWithSolanaEncryptedKey } from './tests/testSignTransactionWithSolanaEncryptedKey'; @@ -120,7 +117,6 @@ import { testSignTransactionWithSolanaEncryptedKey } from './tests/testSignTrans testEthereumSignMessageGeneratedKey, testEthereumBroadcastTransactionGeneratedKey, testEthereumSignMessageWrappedKey, - testCustomignMessageWrappedKey, testEthereumSignTransactionWrappedKey, testEthereumBroadcastTransactionWrappedKey, testEthereumBroadcastWrappedKeyWithFetchGasParams, @@ -128,7 +124,6 @@ import { testSignTransactionWithSolanaEncryptedKey } from './tests/testSignTrans // -- generate wrapped keys testGenerateEthereumWrappedKey, testGenerateSolanaWrappedKey, - testCustomGenerateWrappedKey, // -- import wrapped keys testImportWrappedKey, @@ -146,7 +141,6 @@ import { testSignTransactionWithSolanaEncryptedKey } from './tests/testSignTrans testFailEthereumSignTransactionWrappedKeyWithInvalidParam, testFailEthereumSignTransactionWrappedKeyInvalidDecryption, testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds, - testFailCustomGenerateKeyWithBothIpfsAndCode, // -- import wrapped keys testFailImportWrappedKeysWithSamePkp, diff --git a/local-tests/tests/testCustomGenerateWrappedKey.ts b/local-tests/tests/testCustomGenerateWrappedKey.ts deleted file mode 100644 index aed1ee9aaf..0000000000 --- a/local-tests/tests/testCustomGenerateWrappedKey.ts +++ /dev/null @@ -1,105 +0,0 @@ -import { log } from '@lit-protocol/misc'; -import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { api } from '@lit-protocol/wrapped-keys'; -import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; - -import { LIT_ACTION_CID_REPOSITORY } from '../../packages/wrapped-keys/src/lib/lit-actions-client/constants'; -const { generatePrivateKey } = api; - -const CUSTOM_LIT_ACTION_CODE = ` -(async () => { - const LIT_PREFIX = 'lit_'; - - const resp = await Lit.Actions.runOnce( - { waitForResponse: true, name: 'encryptedPrivateKey' }, - async () => { - const wallet = ethers.Wallet.createRandom(); - const privateKey = LIT_PREFIX + wallet.privateKey.toString(); - let utf8Encode = new TextEncoder(); - const to_encrypt = utf8Encode.encode(privateKey); - - const { ciphertext, dataToEncryptHash } = await Lit.Actions.encrypt({ - accessControlConditions, - to_encrypt, - }); - return JSON.stringify({ - ciphertext, - dataToEncryptHash, - publicKey: wallet.publicKey, - }); - } - ); - - Lit.Actions.setResponse({ - response: resp, - }); -})(); -`; - -/** - * Test Commands: - * ✅ NETWORK=cayenne yarn test:local --filter=testCustomGenerateWrappedKey - * ✅ NETWORK=manzano yarn test:local --filter=testCustomGenerateWrappedKey - * ✅ NETWORK=localchain yarn test:local --filter=testCustomGenerateWrappedKey - */ -export const testCustomGenerateWrappedKey = async ( - devEnv: TinnyEnvironment -) => { - // Generate custom keys with IPFS CID - const alice = await devEnv.createRandomPerson(); - - const alicePkpSessionSigs = await getPkpSessionSigs( - devEnv, - alice, - null, - new Date(Date.now() + 1000 * 60 * 10).toISOString() - ); // 10 mins expiry - - const ipfsCustomPrivateKeys = await generatePrivateKey({ - network: 'custom', - pkpSessionSigs: alicePkpSessionSigs, - litActionIpfsCid: LIT_ACTION_CID_REPOSITORY.generateEncryptedKey.solana, - litNodeClient: devEnv.litNodeClient, - }); - - console.log( - `IPFS CID generatedPublicKey: ${ipfsCustomPrivateKeys.generatedPublicKey}` - ); - - const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; - if (ipfsCustomPrivateKeys.pkpAddress !== alicePkpAddress) { - throw new Error( - `Received address: ${ipfsCustomPrivateKeys.pkpAddress} doesn't match Alice's PKP address: ${alicePkpAddress}` - ); - } - - // Generate custom keys with code - const bob = await devEnv.createRandomPerson(); - - const bobPkpSessionSigs = await getPkpSessionSigs( - devEnv, - bob, - null, - new Date(Date.now() + 1000 * 60 * 10).toISOString() - ); // 10 mins expiry - - const codeCustomPrivateKeys = await generatePrivateKey({ - network: 'custom', - pkpSessionSigs: bobPkpSessionSigs, - litActionCode: CUSTOM_LIT_ACTION_CODE, - litNodeClient: devEnv.litNodeClient, - }); - - console.log( - `Code generatedPublicKey: ${codeCustomPrivateKeys.generatedPublicKey}` - ); - - const bobPkpAddress = bob.authMethodOwnedPkp.ethAddress; - if (codeCustomPrivateKeys.pkpAddress !== bobPkpAddress) { - throw new Error( - `Received address: ${codeCustomPrivateKeys.pkpAddress} doesn't match Bob's PKP address: ${bobPkpAddress}` - ); - } - - log('✅ testCustomGenerateWrappedKey'); -}; diff --git a/local-tests/tests/testCustomSignMessageWrappedKey.ts b/local-tests/tests/testCustomSignMessageWrappedKey.ts deleted file mode 100644 index 6f942d0e5b..0000000000 --- a/local-tests/tests/testCustomSignMessageWrappedKey.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { log } from '@lit-protocol/misc'; -import { ethers } from 'ethers'; -import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { api } from '@lit-protocol/wrapped-keys'; -import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; - -const { signMessageWithEncryptedKey, importPrivateKey } = api; - -const CUSTOM_LIT_ACTION_CODE = ` -(async () => { - const LIT_PREFIX = 'lit_'; - - let decryptedPrivateKey; - try { - decryptedPrivateKey = await Lit.Actions.decryptToSingleNode({ - accessControlConditions, - ciphertext, - dataToEncryptHash, - chain: 'ethereum', - authSig: null, - }); - } catch (err) { - const errorMessage = - 'Error: When decrypting to a single node- ' + err.message; - Lit.Actions.setResponse({ response: errorMessage }); - return; - } - - if (!decryptedPrivateKey) { - // Exit the nodes which don't have the decryptedData - return; - } - - const privateKey = decryptedPrivateKey.startsWith(LIT_PREFIX) - ? decryptedPrivateKey.slice(LIT_PREFIX.length) - : decryptedPrivateKey; - const wallet = new ethers.Wallet(privateKey); - - try { - const signature = await wallet.signMessage(messageToSign); - - const recoveredAddress = ethers.utils.verifyMessage( - messageToSign, - signature - ); - - if (recoveredAddress !== wallet.address) { - Lit.Actions.setResponse({ - response: "Error: Recovered address doesn't match the wallet address", - }); - return; - } - - Lit.Actions.setResponse({ response: signature }); - } catch (err) { - const errorMessage = 'Error: When signing message- ' + err.message; - Lit.Actions.setResponse({ response: errorMessage }); - } -})(); -`; - -/** - * Test Commands: - * ✅ NETWORK=cayenne yarn test:local --filter=testCustomignMessageWrappedKey - * ✅ NETWORK=manzano yarn test:local --filter=testCustomignMessageWrappedKey - * ✅ NETWORK=localchain yarn test:local --filter=testCustomignMessageWrappedKey - */ -export const testCustomignMessageWrappedKey = async ( - devEnv: TinnyEnvironment -) => { - const alice = await devEnv.createRandomPerson(); - - const pkpSessionSigs = await getPkpSessionSigs( - devEnv, - alice, - null, - new Date(Date.now() + 1000 * 60 * 10).toISOString() - ); // 10 mins expiry - - console.log(pkpSessionSigs); - - const privateKey = ethers.Wallet.createRandom().privateKey; - - const pkpAddress = await importPrivateKey({ - pkpSessionSigs, - privateKey, - litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', - keyType: 'K256', - }); - - const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; - if (pkpAddress !== alicePkpAddress) { - throw new Error( - `Received address: ${pkpAddress} doesn't match Alice's PKP address: ${alicePkpAddress}` - ); - } - - const pkpSessionSigsSigning = await getPkpSessionSigs( - devEnv, - alice, - null, - new Date(Date.now() + 1000 * 60 * 10).toISOString() - ); // 10 mins expiry - - console.log(pkpSessionSigsSigning); - - const unsignedStringMessage = 'This is a test message'; - - const signature = await signMessageWithEncryptedKey({ - network: 'custom', - pkpSessionSigs: pkpSessionSigsSigning, - litActionCode: CUSTOM_LIT_ACTION_CODE, - messageToSign: unsignedStringMessage, - litNodeClient: devEnv.litNodeClient, - }); - - console.log('signature'); - console.log(signature); - - if (!ethers.utils.isHexString(signature)) { - throw new Error(`signature isn't hex: ${signature}`); - } - - log('✅ testCustomignMessageWrappedKey'); -}; diff --git a/local-tests/tests/testCustomSignTransactionWrappedKey.ts b/local-tests/tests/testCustomSignTransactionWrappedKey.ts deleted file mode 100644 index 2988ca52eb..0000000000 --- a/local-tests/tests/testCustomSignTransactionWrappedKey.ts +++ /dev/null @@ -1,174 +0,0 @@ -import { log } from '@lit-protocol/misc'; -import { ethers } from 'ethers'; -import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { - api, - EthereumLitTransaction, - SerializedTransaction, -} from '@lit-protocol/wrapped-keys'; -import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; -import { - clusterApiUrl, - Connection, - Keypair, - LAMPORTS_PER_SOL, - PublicKey, - SystemProgram, - Transaction, -} from '@solana/web3.js'; - -const { importPrivateKey, signTransactionWithEncryptedKey } = api; - -const CUSTOM_LIT_ACTION_CODE = `(async () => { - const LIT_PREFIX = 'lit_'; - - let decryptedPrivateKey; - decryptedPrivateKey = await Lit.Actions.decryptToSingleNode({ - accessControlConditions, - ciphertext, - dataToEncryptHash, - chain: 'ethereum', - authSig: null, - }); - - if (!decryptedPrivateKey) { - // Exit the nodes which don't have the decryptedData - return; - } - - const privateKey = decryptedPrivateKey.startsWith(LIT_PREFIX) - ? decryptedPrivateKey.slice(LIT_PREFIX.length) - : decryptedPrivateKey; - const wallet = new ethers.Wallet(privateKey); - - const nonce = await Lit.Actions.getLatestNonce({ - address: wallet.address, - chain: unsignedTransaction.chain, - }); - - const tx = { - to: unsignedTransaction.toAddress, - from: wallet.address, - value: ethers.utils.hexlify( - ethers.utils.parseEther(unsignedTransaction.value) - ), - chainId: unsignedTransaction.chainId, - data: unsignedTransaction.dataHex, - nonce, - gasPrice: ethers.utils.parseUnits(unsignedTransaction.gasPrice, 'gwei'), - gasLimit: unsignedTransaction.gasLimit, - }; - - const rpcUrl = await Lit.Actions.getRpcUrl({ - chain: unsignedTransaction.chain, - }); - const provider = new ethers.providers.JsonRpcProvider(rpcUrl); - - try { - const signedTx = await wallet.signTransaction(tx); - - if (broadcast) { - const transactionResponse = await provider.sendTransaction(signedTx); - - Lit.Actions.setResponse({ response: transactionResponse.hash }); - } else { - Lit.Actions.setResponse({ response: signedTx }); - } - } catch (err) { - const errorMessage = 'Error: When signing transaction- ' + err.message; - Lit.Actions.setResponse({ response: errorMessage }); - } -})(); -`; - -/** - * Test Commands: - * ✅ NETWORK=cayenne yarn test:local --filter=testEthereumSignTransactionWrappedKey - * ✅ NETWORK=manzano yarn test:local --filter=testEthereumSignTransactionWrappedKey - * ✅ NETWORK=localchain yarn test:local --filter=testEthereumSignTransactionWrappedKey - */ -export const testCustomSignTransactionWrappedKey = async ( - devEnv: TinnyEnvironment -) => { - const alice = await devEnv.createRandomPerson(); - - const pkpSessionSigs = await getPkpSessionSigs( - devEnv, - alice, - null, - new Date(Date.now() + 1000 * 60 * 10).toISOString() - ); // 10 mins expiry - - console.log(pkpSessionSigs); - - const solanaKeypair = Keypair.generate(); - const privateKey = Buffer.from(solanaKeypair.secretKey).toString('hex'); - - const pkpAddress = await importPrivateKey({ - pkpSessionSigs, - privateKey, - litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', - keyType: 'K256', - }); - - const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; - if (pkpAddress !== alicePkpAddress) { - throw new Error( - `Received address: ${pkpAddress} doesn't match Alice's PKP address: ${alicePkpAddress}` - ); - } - - const pkpSessionSigsSigning = await getPkpSessionSigs( - devEnv, - alice, - null, - new Date(Date.now() + 1000 * 60 * 10).toISOString() - ); // 10 mins expiry - - console.log(pkpSessionSigsSigning); - - const solanaTransaction = new Transaction(); - solanaTransaction.add( - SystemProgram.transfer({ - fromPubkey: solanaKeypair.publicKey, - toPubkey: new PublicKey(solanaKeypair.publicKey), - lamports: LAMPORTS_PER_SOL / 100, // Transfer 0.01 SOL - }) - ); - solanaTransaction.feePayer = solanaKeypair.publicKey; - - const solanaConnection = new Connection(clusterApiUrl('devnet'), 'confirmed'); - const { blockhash } = await solanaConnection.getLatestBlockhash(); - solanaTransaction.recentBlockhash = blockhash; - - const serializedTransaction = solanaTransaction - .serialize({ - requireAllSignatures: false, // should be false as we're not signing the message - verifySignatures: false, // should be false as we're not signing the message - }) - .toString('base64'); - - const unsignedTransaction: SerializedTransaction = { - serializedTransaction, - chain: 'devnet', - }; - - const signedTx = await signTransactionWithEncryptedKey({ - pkpSessionSigs: pkpSessionSigsSigning, - network: 'custom', - unsignedTransaction, - broadcast: false, - litNodeClient: devEnv.litNodeClient, - litActionCode: CUSTOM_LIT_ACTION_CODE, - }); - - console.log('signedTx'); - console.log(signedTx); - - if (!ethers.utils.isHexString(signedTx)) { - throw new Error(`signedTx isn't hex: ${signedTx}`); - } - - log('✅ testEthereumSignTransactionWrappedKey'); -}; diff --git a/local-tests/tests/testFailCustomGenerateKeyWithBothIpfsAndCode.ts b/local-tests/tests/testFailCustomGenerateKeyWithBothIpfsAndCode.ts deleted file mode 100644 index 3cfab09b9d..0000000000 --- a/local-tests/tests/testFailCustomGenerateKeyWithBothIpfsAndCode.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { log } from '@lit-protocol/misc'; -import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; -import { api } from '@lit-protocol/wrapped-keys'; -import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; - -const { generatePrivateKey } = api; - -import { LIT_ACTION_CID_REPOSITORY } from '../../packages/wrapped-keys/src/lib/lit-actions-client/constants'; - -const CUSTOM_LIT_ACTION_CODE = ` -(async () => { - const LIT_PREFIX = 'lit_'; - - const resp = await Lit.Actions.runOnce( - { waitForResponse: true, name: 'encryptedPrivateKey' }, - async () => { - const wallet = ethers.Wallet.createRandom(); - const privateKey = LIT_PREFIX + wallet.privateKey.toString(); - let utf8Encode = new TextEncoder(); - const to_encrypt = utf8Encode.encode(privateKey); - - const { ciphertext, dataToEncryptHash } = await Lit.Actions.encrypt({ - accessControlConditions, - to_encrypt, - }); - return JSON.stringify({ - ciphertext, - dataToEncryptHash, - publicKey: wallet.publicKey, - }); - } - ); - - Lit.Actions.setResponse({ - response: resp, - }); -})(); -`; - -/** - * Test Commands: - * ✅ NETWORK=cayenne yarn test:local --filter=testFailCustomGenerateKeyWithBothIpfsAndCode - * ✅ NETWORK=manzano yarn test:local --filter=testFailCustomGenerateKeyWithBothIpfsAndCode - * ✅ NETWORK=localchain yarn test:local --filter=testFailCustomGenerateKeyWithBothIpfsAndCode - */ -export const testFailCustomGenerateKeyWithBothIpfsAndCode = async ( - devEnv: TinnyEnvironment -) => { - const alice = await devEnv.createRandomPerson(); - - const alicePkpSessionSigs = await getPkpSessionSigs( - devEnv, - alice, - null, - new Date(Date.now() + 1000 * 60 * 10).toISOString() - ); // 10 mins expiry - - try { - await generatePrivateKey({ - network: 'custom', - pkpSessionSigs: alicePkpSessionSigs, - litActionIpfsCid: LIT_ACTION_CID_REPOSITORY.generateEncryptedKey.solana, - litActionCode: CUSTOM_LIT_ACTION_CODE, - litNodeClient: devEnv.litNodeClient, - }); - } catch (e: any) { - console.log('❌ THIS IS EXPECTED: ', e); - - if ( - e.message === "Can't provide both the litActionIpfsCid or litActionCode" - ) { - console.log( - '✅ testFailImportWrappedKeysWithSamePrivateKey is expected to have an error' - ); - } else { - throw e; - } - } - - log('✅ testFailCustomGenerateKeyWithBothIpfsAndCode'); -}; From e9d771e188b7363a26a366c6b265f39e77c5198f Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 20:13:27 +0100 Subject: [PATCH 17/30] docs(wrapped-keys): LIT-3125 - Update exports for JSDocs --- packages/wrapped-keys/src/index.ts | 10 ++++++++++ packages/wrapped-keys/src/lib/types.ts | 24 ++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/wrapped-keys/src/index.ts b/packages/wrapped-keys/src/index.ts index 133dfcee59..4b89a04a1a 100644 --- a/packages/wrapped-keys/src/index.ts +++ b/packages/wrapped-keys/src/index.ts @@ -23,6 +23,11 @@ import type { GeneratePrivateKeyResult, EthereumLitTransaction, SerializedTransaction, + BaseApiParams, + ApiParamsSupportedNetworks, + SignTransactionParams, + SignTransactionParamsSupportedEvm, + SignTransactionParamsSupportedSolana, } from './lib/types'; export const constants = { @@ -40,6 +45,11 @@ export const api = { }; export { + SignTransactionParams, + SignTransactionParamsSupportedEvm, + SignTransactionParamsSupportedSolana, + ApiParamsSupportedNetworks, + BaseApiParams, EthereumLitTransaction, SerializedTransaction, StoredKeyMetadata, diff --git a/packages/wrapped-keys/src/lib/types.ts b/packages/wrapped-keys/src/lib/types.ts index d3ae36c264..d9eefdf066 100644 --- a/packages/wrapped-keys/src/lib/types.ts +++ b/packages/wrapped-keys/src/lib/types.ts @@ -58,15 +58,12 @@ export interface ExportPrivateKeyResult { keyType: string; } -type GeneratePrivateKeyParamsSupportedNetworks = BaseApiParams & - ApiParamsSupportedNetworks; - /** @typedef GeneratePrivateKeyParams * @extends BaseApiParams * @property {Network} network The network for which the private key needs to be generated; keys are generated differently for different networks */ -export type GeneratePrivateKeyParams = - GeneratePrivateKeyParamsSupportedNetworks; +export type GeneratePrivateKeyParams = BaseApiParams & + ApiParamsSupportedNetworks; /** @typedef GeneratePrivateKeyResult * @property { string } pkpAddress The LIT PKP Address that the key was linked to; this is derived from the provided pkpSessionSigs @@ -95,17 +92,14 @@ interface SignMessageParams { messageToSign: string | Uint8Array; } -type SignMessageWithEncryptedKeyParamsSupportedNetworks = BaseApiParams & - ApiParamsSupportedNetworks & - SignMessageParams; - /** @typedef SignMessageWithEncryptedKeyParams * @extends BaseApiParams * * @property { string | Uint8Array } messageToSign The message to be signed */ -export type SignMessageWithEncryptedKeyParams = - SignMessageWithEncryptedKeyParamsSupportedNetworks; +export type SignMessageWithEncryptedKeyParams = BaseApiParams & + ApiParamsSupportedNetworks & + SignMessageParams; interface BaseLitTransaction { chain: string; @@ -136,16 +130,18 @@ export interface SerializedTransaction extends BaseLitTransaction { serializedTransaction: string; } -interface SignTransactionParams extends BaseApiParams { +export interface SignTransactionParams extends BaseApiParams { broadcast: boolean; } -interface SignTransactionParamsSupportedEvm extends SignTransactionParams { +export interface SignTransactionParamsSupportedEvm + extends SignTransactionParams { unsignedTransaction: EthereumLitTransaction; network: Extract; } -interface SignTransactionParamsSupportedSolana extends SignTransactionParams { +export interface SignTransactionParamsSupportedSolana + extends SignTransactionParams { unsignedTransaction: SerializedTransaction; network: Extract; } From 8cff023cd5a65b93ddeb8bcdb79ea731afb6f268 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 20:40:59 +0100 Subject: [PATCH 18/30] feat(wrapped-keys): LIT-3125 - Add storeEncryptedKeyMetadata() method and params type --- packages/wrapped-keys/src/index.ts | 24 ++++++++------ packages/wrapped-keys/src/lib/api/index.ts | 2 ++ .../lib/api/store-encrypted-key-metadata.ts | 31 +++++++++++++++++++ .../src/lib/service-client/types.ts | 9 ++++++ packages/wrapped-keys/src/lib/types.ts | 16 +++++++++- 5 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts diff --git a/packages/wrapped-keys/src/index.ts b/packages/wrapped-keys/src/index.ts index 4b89a04a1a..7aeaddebc6 100644 --- a/packages/wrapped-keys/src/index.ts +++ b/packages/wrapped-keys/src/index.ts @@ -5,6 +5,7 @@ import { generatePrivateKey, importPrivateKey, signTransactionWithEncryptedKey, + storeEncryptedKeyMetadata, } from './lib/api'; import { CHAIN_ETHEREUM, LIT_PREFIX } from './lib/constants'; @@ -28,6 +29,7 @@ import type { SignTransactionParams, SignTransactionParamsSupportedEvm, SignTransactionParamsSupportedSolana, + StoreEncryptedKeyMetadataParams, } from './lib/types'; export const constants = { @@ -36,30 +38,32 @@ export const constants = { }; export const api = { - signMessageWithEncryptedKey, - getEncryptedKeyMetadata, exportPrivateKey, generatePrivateKey, + getEncryptedKeyMetadata, importPrivateKey, + signMessageWithEncryptedKey, signTransactionWithEncryptedKey, + storeEncryptedKeyMetadata, }; export { - SignTransactionParams, - SignTransactionParamsSupportedEvm, - SignTransactionParamsSupportedSolana, ApiParamsSupportedNetworks, BaseApiParams, EthereumLitTransaction, - SerializedTransaction, - StoredKeyMetadata, - SupportedNetworks, - SignMessageWithEncryptedKeyParams, - GetEncryptedKeyMetadataParams, ExportPrivateKeyParams, ExportPrivateKeyResult, + GetEncryptedKeyMetadataParams, GeneratePrivateKeyParams, GeneratePrivateKeyResult, ImportPrivateKeyParams, + SerializedTransaction, + SignTransactionParams, + SignTransactionParamsSupportedEvm, + SignTransactionParamsSupportedSolana, + SignMessageWithEncryptedKeyParams, SignTransactionWithEncryptedKeyParams, + StoreEncryptedKeyMetadataParams, + StoredKeyMetadata, + SupportedNetworks, }; diff --git a/packages/wrapped-keys/src/lib/api/index.ts b/packages/wrapped-keys/src/lib/api/index.ts index 3f4970fd3d..a20f61a866 100644 --- a/packages/wrapped-keys/src/lib/api/index.ts +++ b/packages/wrapped-keys/src/lib/api/index.ts @@ -4,6 +4,7 @@ import { getEncryptedKeyMetadata } from './get-encrypted-key-metadata'; import { importPrivateKey } from './import-private-key'; import { signMessageWithEncryptedKey } from './sign-message-with-encrypted-key'; import { signTransactionWithEncryptedKey } from './sign-transaction-with-encrypted-key'; +import { storeEncryptedKeyMetadata } from './store-encrypted-key-metadata'; export { generatePrivateKey, @@ -11,5 +12,6 @@ export { signTransactionWithEncryptedKey, exportPrivateKey, signMessageWithEncryptedKey, + storeEncryptedKeyMetadata, getEncryptedKeyMetadata, }; diff --git a/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts b/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts new file mode 100644 index 0000000000..31e33b9163 --- /dev/null +++ b/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts @@ -0,0 +1,31 @@ +import { storePrivateKeyMetadata } from '../service-client'; +import { StoreEncryptedKeyMetadataParams } from '../types'; +import { getFirstSessionSig, getPkpAddressFromSessionSig } from '../utils'; + +/** Get a previously encrypted and persisted private key and its metadata. + * Note that this method does _not_ decrypt the private key; only the _encrypted_ key and its metadata will be returned to the caller. + * + * @param { StoreEncryptedKeyMetadataParams } params Parameters required to fetch the encrypted private key metadata + * @returns { Promise } The encrypted private key and its associated metadata + */ +export async function storeEncryptedKeyMetadata( + params: StoreEncryptedKeyMetadataParams +): Promise { + const { pkpSessionSigs, litNodeClient } = params; + const sessionSig = getFirstSessionSig(pkpSessionSigs); + const pkpAddress = getPkpAddressFromSessionSig(sessionSig); + + const { address, keyType, dataToEncryptHash, ciphertext } = params; + + return storePrivateKeyMetadata({ + storedKeyMetadata: { + address, + keyType, + dataToEncryptHash, + ciphertext, + pkpAddress, + }, + sessionSig: getFirstSessionSig(pkpSessionSigs), + litNodeClient, + }); +} diff --git a/packages/wrapped-keys/src/lib/service-client/types.ts b/packages/wrapped-keys/src/lib/service-client/types.ts index c453ef224f..cd72183f08 100644 --- a/packages/wrapped-keys/src/lib/service-client/types.ts +++ b/packages/wrapped-keys/src/lib/service-client/types.ts @@ -16,6 +16,15 @@ export type SupportedNetworks = Extract< 'cayenne' | 'manzano' | 'habanero' >; +/** Metadata for a key that has been stored, encrypted, on the wrapped keys backend service + * + * @property { string } ciphertext The base64 encoded, salted & encrypted private key + * @property { string } dataToEncryptHash SHA-256 of the ciphertext + * @property { string } address The public address of the encrypted private key + * @property { string } pkpAddress The LIT PKP address that is associated with the encrypted private key + * @property { string } keyType The type of key that was encrypted -- e.g. ed25519, K256, etc. + * @property { LIT_NETWORKS_KEYS } litNetwork The LIT network that the client who stored the key was connected to + */ export interface StoredKeyMetadata { ciphertext: string; dataToEncryptHash: string; diff --git a/packages/wrapped-keys/src/lib/types.ts b/packages/wrapped-keys/src/lib/types.ts index d9eefdf066..3f73d46690 100644 --- a/packages/wrapped-keys/src/lib/types.ts +++ b/packages/wrapped-keys/src/lib/types.ts @@ -4,6 +4,8 @@ import { SessionSigsMap, } from '@lit-protocol/types'; +import { StoredKeyMetadata } from '../index'; + /** @typedef Network * The network type that the wrapped key will be used on. */ @@ -24,13 +26,25 @@ export interface ApiParamsSupportedNetworks { network: Network; } -/** Fetching a previously persisted key's metadata only requires valid pkpSessionSigs and a LIT Node Client instance configured for the appropriate network. +/** Fetch a previously persisted key's metadata only requires valid pkpSessionSigs and a LIT Node Client instance configured for the appropriate network. * * @typedef GetEncryptedKeyMetadataParams * @extends BaseApiParams * */ + export type GetEncryptedKeyMetadataParams = BaseApiParams; +/** Fetching a previously persisted key's metadata only requires valid pkpSessionSigs and a LIT Node Client instance configured for the appropriate network. + * + * @typedef StoreEncryptedKeyMetadataParams + * @extends BaseApiParams + * + */ +export type StoreEncryptedKeyMetadataParams = BaseApiParams & + Pick< + StoredKeyMetadata, + 'address' | 'keyType' | 'dataToEncryptHash' | 'ciphertext' + >; /** Exporting a previously persisted key only requires valid pkpSessionSigs and a LIT Node Client instance configured for the appropriate network. * From 241fa9740f14c005a98c17e2692e8a5e10700833 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 21:35:36 +0100 Subject: [PATCH 19/30] feat(wrapped-keys): LIT-3125 - Replace `address` with `publicKey` --- .../wrapped-keys/src/lib/api/generate-private-key.ts | 2 +- .../wrapped-keys/src/lib/api/import-private-key.ts | 4 ++-- .../src/lib/api/store-encrypted-key-metadata.ts | 4 ++-- packages/wrapped-keys/src/lib/service-client/types.ts | 6 +++--- packages/wrapped-keys/src/lib/types.ts | 10 +++++----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/wrapped-keys/src/lib/api/generate-private-key.ts b/packages/wrapped-keys/src/lib/api/generate-private-key.ts index 4eed3edadb..549f16526e 100644 --- a/packages/wrapped-keys/src/lib/api/generate-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/generate-private-key.ts @@ -42,7 +42,7 @@ export async function generatePrivateKey( sessionSig: firstSessionSig, storedKeyMetadata: { ciphertext, - address: publicKey, // FIXME: If we're storing address and it is _not_ the publicKey directly, then we need the generate LIT action to return it for us + publicKey, keyType: LIT_CURVE.EcdsaK256, // FIXME: Should be returned by the LIT action; we won't know what it is unless it's provided. dataToEncryptHash, pkpAddress, diff --git a/packages/wrapped-keys/src/lib/api/import-private-key.ts b/packages/wrapped-keys/src/lib/api/import-private-key.ts index d1baded028..b9f652f745 100644 --- a/packages/wrapped-keys/src/lib/api/import-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/import-private-key.ts @@ -21,7 +21,7 @@ import { export async function importPrivateKey( params: ImportPrivateKeyParams ): Promise { - const { pkpSessionSigs, privateKey, address, keyType, litNodeClient } = + const { pkpSessionSigs, privateKey, publicKey, keyType, litNodeClient } = params; const firstSessionSig = getFirstSessionSig(pkpSessionSigs); @@ -43,7 +43,7 @@ export async function importPrivateKey( litNodeClient, storedKeyMetadata: { ciphertext, - address, + publicKey, keyType, dataToEncryptHash, pkpAddress, diff --git a/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts b/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts index 31e33b9163..e828bfe8d5 100644 --- a/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts +++ b/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts @@ -15,11 +15,11 @@ export async function storeEncryptedKeyMetadata( const sessionSig = getFirstSessionSig(pkpSessionSigs); const pkpAddress = getPkpAddressFromSessionSig(sessionSig); - const { address, keyType, dataToEncryptHash, ciphertext } = params; + const { publicKey, keyType, dataToEncryptHash, ciphertext } = params; return storePrivateKeyMetadata({ storedKeyMetadata: { - address, + publicKey, keyType, dataToEncryptHash, ciphertext, diff --git a/packages/wrapped-keys/src/lib/service-client/types.ts b/packages/wrapped-keys/src/lib/service-client/types.ts index cd72183f08..f3cb35d9cc 100644 --- a/packages/wrapped-keys/src/lib/service-client/types.ts +++ b/packages/wrapped-keys/src/lib/service-client/types.ts @@ -20,7 +20,7 @@ export type SupportedNetworks = Extract< * * @property { string } ciphertext The base64 encoded, salted & encrypted private key * @property { string } dataToEncryptHash SHA-256 of the ciphertext - * @property { string } address The public address of the encrypted private key + * @property { string } publicKey The public key of the encrypted private key * @property { string } pkpAddress The LIT PKP address that is associated with the encrypted private key * @property { string } keyType The type of key that was encrypted -- e.g. ed25519, K256, etc. * @property { LIT_NETWORKS_KEYS } litNetwork The LIT network that the client who stored the key was connected to @@ -28,7 +28,7 @@ export type SupportedNetworks = Extract< export interface StoredKeyMetadata { ciphertext: string; dataToEncryptHash: string; - address: string; + publicKey: string; pkpAddress: string; keyType: string; litNetwork: SupportedNetworks; @@ -37,7 +37,7 @@ export interface StoredKeyMetadata { export interface StoreKeyParams extends BaseApiParams { storedKeyMetadata: Pick< StoredKeyMetadata, - 'pkpAddress' | 'address' | 'keyType' | 'dataToEncryptHash' | 'ciphertext' + 'pkpAddress' | 'publicKey' | 'keyType' | 'dataToEncryptHash' | 'ciphertext' >; } diff --git a/packages/wrapped-keys/src/lib/types.ts b/packages/wrapped-keys/src/lib/types.ts index 3f73d46690..e3e6a595be 100644 --- a/packages/wrapped-keys/src/lib/types.ts +++ b/packages/wrapped-keys/src/lib/types.ts @@ -43,7 +43,7 @@ export type GetEncryptedKeyMetadataParams = BaseApiParams; export type StoreEncryptedKeyMetadataParams = BaseApiParams & Pick< StoredKeyMetadata, - 'address' | 'keyType' | 'dataToEncryptHash' | 'ciphertext' + 'publicKey' | 'keyType' | 'dataToEncryptHash' | 'ciphertext' >; /** Exporting a previously persisted key only requires valid pkpSessionSigs and a LIT Node Client instance configured for the appropriate network. @@ -60,14 +60,14 @@ export type ExportPrivateKeyParams = BaseApiParams; * @property { LIT_NETWORKS_KEYS } litNetwork The LIT network that the LIT Node Client was configured for when the key was persisted to the wrapped keys service * @property { string } decryptedPrivateKey The decrypted, plain text private key that was persisted to the wrapped keys service * @property { string } pkpAddress The LIT PKP Address that the key was linked to; this is derived from the provided pkpSessionSigs - * @property { string } address The 'address' is typically based on the public key of the key being imported into the wrapped keys service + * @property { string } publicKey The public key of the key being imported into the wrapped keys service * @property { string } keyType The algorithm type of the key; this might be K256, ed25519, or other key formats. The `keyType` will be included in the metadata returned from the wrapped keys service * */ export interface ExportPrivateKeyResult { pkpAddress: string; decryptedPrivateKey: string; - address: string; + publicKey: string; litNetwork: LIT_NETWORKS_KEYS; keyType: string; } @@ -93,12 +93,12 @@ export interface GeneratePrivateKeyResult { * @extends BaseApiParams * * @property { string } privateKey The private key to be imported into the wrapped keys service - * @property { string } address The 'address' is typically based on the public key of the key being imported into the wrapped keys service + * @property { string } publicKey The public key of the key being imported into the wrapped keys service * @property { string } keyType The algorithm type of the key; this might be K256, ed25519, or other key formats. The `keyType` will be included in the metadata returned from the wrapped keys service */ export interface ImportPrivateKeyParams extends BaseApiParams { privateKey: string; - address: string; + publicKey: string; keyType: string; } From c3166a528bea5780a0630c815635b11d829fe361 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 21:38:49 +0100 Subject: [PATCH 20/30] test(wrapped-keys): LIT-3125 - Update tests to use `publicKey` instead of `address` --- .../tests/testEthereumBroadcastTransactionWrappedKey.ts | 2 +- .../testEthereumBroadcastWrappedKeyWithFetchGasParams.ts | 2 +- local-tests/tests/testEthereumSignMessageWrappedKey.ts | 2 +- local-tests/tests/testEthereumSignTransactionWrappedKey.ts | 2 +- local-tests/tests/testExportWrappedKey.ts | 2 +- ...thereumBroadcastTransactionWrappedKeysInsufficientFunds.ts | 2 +- ...stFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts | 2 +- ...stFailEthereumSignTransactionWrappedKeyWithMissingParam.ts | 2 +- .../tests/testFailImportWrappedKeysWithEoaSessionSig.ts | 2 +- .../tests/testFailImportWrappedKeysWithExpiredSessionSig.ts | 2 +- .../tests/testFailImportWrappedKeysWithInvalidSessionSig.ts | 2 +- .../tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts | 2 +- local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts | 4 ++-- .../tests/testFailImportWrappedKeysWithSamePrivateKey.ts | 2 +- local-tests/tests/testImportWrappedKey.ts | 2 +- local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts | 2 +- .../tests/testSignTransactionWithSolanaEncryptedKey.ts | 2 +- 17 files changed, 18 insertions(+), 18 deletions(-) diff --git a/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts b/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts index 1a4bee14eb..7ce84fee50 100644 --- a/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts +++ b/local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts @@ -37,7 +37,7 @@ export const testEthereumBroadcastTransactionWrappedKey = async ( pkpSessionSigs, privateKey: wrappedKeysWalletPrivateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); diff --git a/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts b/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts index 001d1dbfa3..26e0a1b5be 100644 --- a/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts +++ b/local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts @@ -37,7 +37,7 @@ export const testEthereumBroadcastWrappedKeyWithFetchGasParams = async ( pkpSessionSigs, privateKey: wrappedKeysWalletPrivateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); diff --git a/local-tests/tests/testEthereumSignMessageWrappedKey.ts b/local-tests/tests/testEthereumSignMessageWrappedKey.ts index e51f8f8f0c..b74ca6c865 100644 --- a/local-tests/tests/testEthereumSignMessageWrappedKey.ts +++ b/local-tests/tests/testEthereumSignMessageWrappedKey.ts @@ -32,7 +32,7 @@ export const testEthereumSignMessageWrappedKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); diff --git a/local-tests/tests/testEthereumSignTransactionWrappedKey.ts b/local-tests/tests/testEthereumSignTransactionWrappedKey.ts index f3ca8ae207..01f045d676 100644 --- a/local-tests/tests/testEthereumSignTransactionWrappedKey.ts +++ b/local-tests/tests/testEthereumSignTransactionWrappedKey.ts @@ -34,7 +34,7 @@ export const testEthereumSignTransactionWrappedKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); diff --git a/local-tests/tests/testExportWrappedKey.ts b/local-tests/tests/testExportWrappedKey.ts index 8a9e70a87e..660b721d60 100644 --- a/local-tests/tests/testExportWrappedKey.ts +++ b/local-tests/tests/testExportWrappedKey.ts @@ -29,7 +29,7 @@ export const testExportWrappedKey = async (devEnv: TinnyEnvironment) => { pkpSessionSigs: pkpSessionSigsImport, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); diff --git a/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts b/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts index 509ad2da23..d83dcf710e 100644 --- a/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts +++ b/local-tests/tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds.ts @@ -30,7 +30,7 @@ export const testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds = pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); diff --git a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts index e559fa70f4..2bc235417e 100644 --- a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts +++ b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam.ts @@ -31,7 +31,7 @@ export const testFailEthereumSignTransactionWrappedKeyWithInvalidParam = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); diff --git a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts index 300dd07d19..4bf1f54c1d 100644 --- a/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts +++ b/local-tests/tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam.ts @@ -31,7 +31,7 @@ export const testFailEthereumSignTransactionWrappedKeyWithMissingParam = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); diff --git a/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts index 1a184330fb..bcf072b2fd 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts @@ -27,7 +27,7 @@ export const testFailImportWrappedKeysWithEoaSessionSig = async ( pkpSessionSigs: eoaSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); } catch (e: any) { diff --git a/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts index fe876ad52c..2d95ba7deb 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithExpiredSessionSig.ts @@ -48,7 +48,7 @@ export const testFailImportWrappedKeysWithExpiredSessionSig = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); console.log(res); diff --git a/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts index 645cfe5d39..05eba31796 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithInvalidSessionSig.ts @@ -28,7 +28,7 @@ export const testFailImportWrappedKeysWithInvalidSessionSig = async ( pkpSessionSigs: tamperPkpSessionSigs(pkpSessionSigs), privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); } catch (e: any) { diff --git a/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts index eaf067ada6..08d5ddc4a9 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithMaxExpirySessionSig.ts @@ -27,7 +27,7 @@ export const testFailImportWrappedKeysWithMaxExpirySessionSig = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); } catch (e: any) { diff --git a/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts b/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts index a41920a9d8..8a13987b6b 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithSamePkp.ts @@ -31,7 +31,7 @@ export const testFailImportWrappedKeysWithSamePkp = async ( pkpSessionSigs, privateKey: privateKey1, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); @@ -51,7 +51,7 @@ export const testFailImportWrappedKeysWithSamePkp = async ( pkpSessionSigs, privateKey: privateKey2, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); } catch (e: any) { diff --git a/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts b/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts index 1479c8b6be..868beceea4 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithSamePrivateKey.ts @@ -31,7 +31,7 @@ export const testFailImportWrappedKeysWithSamePrivateKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); } catch (e: any) { diff --git a/local-tests/tests/testImportWrappedKey.ts b/local-tests/tests/testImportWrappedKey.ts index a12d58283d..3c168ecf7b 100644 --- a/local-tests/tests/testImportWrappedKey.ts +++ b/local-tests/tests/testImportWrappedKey.ts @@ -31,7 +31,7 @@ export const testImportWrappedKey = async (devEnv: TinnyEnvironment) => { pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); diff --git a/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts b/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts index 8fe1f46d3e..e6e68d8a77 100644 --- a/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts +++ b/local-tests/tests/testSignMessageWithSolanaEncryptedKey.ts @@ -35,7 +35,7 @@ export const testSignMessageWithSolanaEncryptedKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); diff --git a/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts b/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts index be8cf15319..ba0b701e93 100644 --- a/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts +++ b/local-tests/tests/testSignTransactionWithSolanaEncryptedKey.ts @@ -41,7 +41,7 @@ export const testSignTransactionWithSolanaEncryptedKey = async ( pkpSessionSigs, privateKey, litNodeClient: devEnv.litNodeClient, - address: '0xdeadbeef', + publicKey: '0xdeadbeef', keyType: 'K256', }); From ac8f17372a2c0a204286515e35b6abeb26e1effc Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Wed, 26 Jun 2024 21:54:51 +0100 Subject: [PATCH 21/30] chore(wrapped-keys): LIT-3125 - Make internal service client params include `litNetwork` rather than the entire LitNodeClient instance. Clarify types of `litNetwork` returned from previously persisted data --- .../wrapped-keys/src/lib/api/export-private-key.ts | 2 +- .../wrapped-keys/src/lib/api/generate-private-key.ts | 2 +- .../src/lib/api/get-encrypted-key-metadata.ts | 2 +- .../wrapped-keys/src/lib/api/import-private-key.ts | 2 +- .../src/lib/api/sign-message-with-encrypted-key.ts | 2 +- .../src/lib/api/sign-transaction-with-encrypted-key.ts | 2 +- .../src/lib/api/store-encrypted-key-metadata.ts | 2 +- packages/wrapped-keys/src/lib/service-client/client.ts | 8 ++++---- packages/wrapped-keys/src/lib/service-client/types.ts | 10 +++------- 9 files changed, 14 insertions(+), 18 deletions(-) diff --git a/packages/wrapped-keys/src/lib/api/export-private-key.ts b/packages/wrapped-keys/src/lib/api/export-private-key.ts index 4425a8d893..5a64fe51da 100644 --- a/packages/wrapped-keys/src/lib/api/export-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/export-private-key.ts @@ -24,7 +24,7 @@ export async function exportPrivateKey( const privateKeyMetadata = await fetchPrivateKeyMetadata({ sessionSig, - litNodeClient, + litNetwork: litNodeClient.config.litNetwork, }); const { ciphertext, dataToEncryptHash, ...privateKeyMetadataMinusEncrypted } = diff --git a/packages/wrapped-keys/src/lib/api/generate-private-key.ts b/packages/wrapped-keys/src/lib/api/generate-private-key.ts index 549f16526e..3cd205e6f0 100644 --- a/packages/wrapped-keys/src/lib/api/generate-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/generate-private-key.ts @@ -47,7 +47,7 @@ export async function generatePrivateKey( dataToEncryptHash, pkpAddress, }, - litNodeClient, + litNetwork: litNodeClient.config.litNetwork, }); return { diff --git a/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts b/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts index b9f43d04de..6d326548e0 100644 --- a/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts +++ b/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts @@ -14,6 +14,6 @@ export async function getEncryptedKeyMetadata( const { pkpSessionSigs, litNodeClient } = params; return fetchPrivateKeyMetadata({ sessionSig: getFirstSessionSig(pkpSessionSigs), - litNodeClient, + litNetwork: litNodeClient.config.litNetwork, }); } diff --git a/packages/wrapped-keys/src/lib/api/import-private-key.ts b/packages/wrapped-keys/src/lib/api/import-private-key.ts index b9f652f745..8fbf5ca824 100644 --- a/packages/wrapped-keys/src/lib/api/import-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/import-private-key.ts @@ -40,7 +40,7 @@ export async function importPrivateKey( await storePrivateKeyMetadata({ sessionSig: firstSessionSig, - litNodeClient, + litNetwork: litNodeClient.config.litNetwork, storedKeyMetadata: { ciphertext, publicKey, diff --git a/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts b/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts index de3fa96f38..65041197ed 100644 --- a/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts +++ b/packages/wrapped-keys/src/lib/api/sign-message-with-encrypted-key.ts @@ -21,7 +21,7 @@ export async function signMessageWithEncryptedKey( const sessionSig = getFirstSessionSig(pkpSessionSigs); const storedKeyMetadata = await fetchPrivateKeyMetadata({ sessionSig, - litNodeClient, + litNetwork: litNodeClient.config.litNetwork, }); const allowPkpAddressToDecrypt = getPkpAccessControlCondition( diff --git a/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts b/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts index 2ba774dcdd..d3c8970ee5 100644 --- a/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts +++ b/packages/wrapped-keys/src/lib/api/sign-transaction-with-encrypted-key.ts @@ -22,7 +22,7 @@ export async function signTransactionWithEncryptedKey( const storedKeyMetadata = await fetchPrivateKeyMetadata({ sessionSig, - litNodeClient, + litNetwork: litNodeClient.config.litNetwork, }); const allowPkpAddressToDecrypt = getPkpAccessControlCondition( diff --git a/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts b/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts index e828bfe8d5..f6cadd1b16 100644 --- a/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts +++ b/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts @@ -26,6 +26,6 @@ export async function storeEncryptedKeyMetadata( pkpAddress, }, sessionSig: getFirstSessionSig(pkpSessionSigs), - litNodeClient, + litNetwork: litNodeClient.config.litNetwork, }); } diff --git a/packages/wrapped-keys/src/lib/service-client/client.ts b/packages/wrapped-keys/src/lib/service-client/client.ts index a07d245f7c..e1031fae19 100644 --- a/packages/wrapped-keys/src/lib/service-client/client.ts +++ b/packages/wrapped-keys/src/lib/service-client/client.ts @@ -9,10 +9,10 @@ import { getBaseRequestParams, makeRequest } from './utils'; export async function fetchPrivateKeyMetadata( params: FetchKeyParams ): Promise { - const { litNodeClient, sessionSig } = params; + const { litNetwork, sessionSig } = params; const { url, initParams } = getBaseRequestParams({ - litNetwork: litNodeClient.config.litNetwork, + litNetwork, sessionSig, method: 'GET', }); @@ -31,10 +31,10 @@ export async function fetchPrivateKeyMetadata( export async function storePrivateKeyMetadata( params: StoreKeyParams ): Promise { - const { litNodeClient, sessionSig, storedKeyMetadata } = params; + const { litNetwork, sessionSig, storedKeyMetadata } = params; const { url, initParams } = getBaseRequestParams({ - litNetwork: litNodeClient.config.litNetwork, + litNetwork, sessionSig, method: 'POST', }); diff --git a/packages/wrapped-keys/src/lib/service-client/types.ts b/packages/wrapped-keys/src/lib/service-client/types.ts index f3cb35d9cc..fdf206dd9a 100644 --- a/packages/wrapped-keys/src/lib/service-client/types.ts +++ b/packages/wrapped-keys/src/lib/service-client/types.ts @@ -1,12 +1,8 @@ -import { - AuthSig, - ILitNodeClient, - LIT_NETWORKS_KEYS, -} from '@lit-protocol/types'; +import { AuthSig, LIT_NETWORKS_KEYS } from '@lit-protocol/types'; interface BaseApiParams { sessionSig: AuthSig; - litNodeClient: ILitNodeClient; + litNetwork: LIT_NETWORKS_KEYS; } export type FetchKeyParams = BaseApiParams; @@ -31,7 +27,7 @@ export interface StoredKeyMetadata { publicKey: string; pkpAddress: string; keyType: string; - litNetwork: SupportedNetworks; + litNetwork: LIT_NETWORKS_KEYS; } export interface StoreKeyParams extends BaseApiParams { From b48efc90c9a93ec2d9bf1053fc902c5bef1c96ee Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Thu, 27 Jun 2024 19:52:52 +0100 Subject: [PATCH 22/30] fix(wrapped-keys): LIT-3125 - Remove inadvertent imports from `index.ts` and eliminate circular type imports --- packages/wrapped-keys/src/index.ts | 6 ++---- .../src/lib/api/get-encrypted-key-metadata.ts | 4 ++-- .../lib/lit-actions-client/generate-key.ts | 2 +- .../lib/lit-actions-client/sign-message.ts | 3 +-- .../lit-actions-client/sign-transaction.ts | 7 +++++-- .../src/lib/lit-actions-client/utils.ts | 8 +++---- .../src/lib/service-client/client.ts | 3 ++- .../src/lib/service-client/index.ts | 8 +------ .../src/lib/service-client/types.ts | 20 ++---------------- packages/wrapped-keys/src/lib/types.ts | 21 +++++++++++++++++-- 10 files changed, 38 insertions(+), 44 deletions(-) diff --git a/packages/wrapped-keys/src/index.ts b/packages/wrapped-keys/src/index.ts index 7aeaddebc6..0cecb5a142 100644 --- a/packages/wrapped-keys/src/index.ts +++ b/packages/wrapped-keys/src/index.ts @@ -9,10 +9,7 @@ import { } from './lib/api'; import { CHAIN_ETHEREUM, LIT_PREFIX } from './lib/constants'; -import type { - StoredKeyMetadata, - SupportedNetworks, -} from './lib/service-client'; +import type { SupportedNetworks } from './lib/service-client/types'; import type { SignMessageWithEncryptedKeyParams, GetEncryptedKeyMetadataParams, @@ -30,6 +27,7 @@ import type { SignTransactionParamsSupportedEvm, SignTransactionParamsSupportedSolana, StoreEncryptedKeyMetadataParams, + StoredKeyMetadata, } from './lib/types'; export const constants = { diff --git a/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts b/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts index 6d326548e0..3b82540a93 100644 --- a/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts +++ b/packages/wrapped-keys/src/lib/api/get-encrypted-key-metadata.ts @@ -1,5 +1,5 @@ -import { fetchPrivateKeyMetadata, StoredKeyMetadata } from '../service-client'; -import { GetEncryptedKeyMetadataParams } from '../types'; +import { fetchPrivateKeyMetadata } from '../service-client'; +import { GetEncryptedKeyMetadataParams, StoredKeyMetadata } from '../types'; import { getFirstSessionSig } from '../utils'; /** Get a previously encrypted and persisted private key and its metadata. diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts b/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts index cf2097cbd0..097d3d3ee3 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/generate-key.ts @@ -1,7 +1,7 @@ import { AccessControlConditions } from '@lit-protocol/types'; import { postLitActionValidation } from './utils'; -import { GeneratePrivateKeyParams } from '../../index'; +import { GeneratePrivateKeyParams } from '../types'; interface GeneratePrivateKeyLitActionParams extends GeneratePrivateKeyParams { pkpAddress: string; diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts b/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts index c2817e982c..b6fc11021b 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/sign-message.ts @@ -1,8 +1,7 @@ import { AccessControlConditions } from '@lit-protocol/types'; import { postLitActionValidation } from './utils'; -import { StoredKeyMetadata } from '../service-client'; -import { SignMessageWithEncryptedKeyParams } from '../types'; +import { SignMessageWithEncryptedKeyParams, StoredKeyMetadata } from '../types'; interface SignMessageWithLitActionParams extends SignMessageWithEncryptedKeyParams { diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts b/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts index d9bf2a8512..63697b1601 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/sign-transaction.ts @@ -5,8 +5,11 @@ import { } from '@lit-protocol/types'; import { postLitActionValidation } from './utils'; -import { StoredKeyMetadata } from '../service-client'; -import { EthereumLitTransaction, SerializedTransaction } from '../types'; +import { + EthereumLitTransaction, + SerializedTransaction, + StoredKeyMetadata, +} from '../types'; interface SignTransactionWithLitActionParams { litNodeClient: ILitNodeClient; diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts b/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts index 2fc52a04f8..482d8d159d 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts @@ -1,7 +1,8 @@ import { ExecuteJsResponse } from '@lit-protocol/types'; import { LIT_ACTION_CID_REPOSITORY } from './constants'; -import { LitActionSupportedNetworks, LitActionType } from './types'; +import { LitActionType } from './types'; +import { Network } from '../types'; /** * @@ -47,9 +48,6 @@ export function postLitActionValidation( return response; } -export function getLitActionCid( - network: LitActionSupportedNetworks, - actionType: LitActionType -) { +export function getLitActionCid(network: Network, actionType: LitActionType) { return LIT_ACTION_CID_REPOSITORY[actionType][network]; } diff --git a/packages/wrapped-keys/src/lib/service-client/client.ts b/packages/wrapped-keys/src/lib/service-client/client.ts index e1031fae19..542ed03483 100644 --- a/packages/wrapped-keys/src/lib/service-client/client.ts +++ b/packages/wrapped-keys/src/lib/service-client/client.ts @@ -1,5 +1,6 @@ -import { FetchKeyParams, StoredKeyMetadata, StoreKeyParams } from './types'; +import { FetchKeyParams, StoreKeyParams } from './types'; import { getBaseRequestParams, makeRequest } from './utils'; +import { StoredKeyMetadata } from '../types'; /** Fetches previously stored private key metadata from the wrapped keys service * diff --git a/packages/wrapped-keys/src/lib/service-client/index.ts b/packages/wrapped-keys/src/lib/service-client/index.ts index 4571cc406c..a770c11569 100644 --- a/packages/wrapped-keys/src/lib/service-client/index.ts +++ b/packages/wrapped-keys/src/lib/service-client/index.ts @@ -1,9 +1,3 @@ import { fetchPrivateKeyMetadata, storePrivateKeyMetadata } from './client'; -import { StoredKeyMetadata, SupportedNetworks } from './types'; -export { - fetchPrivateKeyMetadata, - storePrivateKeyMetadata, - StoredKeyMetadata, - SupportedNetworks, -}; +export { fetchPrivateKeyMetadata, storePrivateKeyMetadata }; diff --git a/packages/wrapped-keys/src/lib/service-client/types.ts b/packages/wrapped-keys/src/lib/service-client/types.ts index fdf206dd9a..c4cff96e20 100644 --- a/packages/wrapped-keys/src/lib/service-client/types.ts +++ b/packages/wrapped-keys/src/lib/service-client/types.ts @@ -1,5 +1,7 @@ import { AuthSig, LIT_NETWORKS_KEYS } from '@lit-protocol/types'; +import { StoredKeyMetadata } from '../types'; + interface BaseApiParams { sessionSig: AuthSig; litNetwork: LIT_NETWORKS_KEYS; @@ -12,24 +14,6 @@ export type SupportedNetworks = Extract< 'cayenne' | 'manzano' | 'habanero' >; -/** Metadata for a key that has been stored, encrypted, on the wrapped keys backend service - * - * @property { string } ciphertext The base64 encoded, salted & encrypted private key - * @property { string } dataToEncryptHash SHA-256 of the ciphertext - * @property { string } publicKey The public key of the encrypted private key - * @property { string } pkpAddress The LIT PKP address that is associated with the encrypted private key - * @property { string } keyType The type of key that was encrypted -- e.g. ed25519, K256, etc. - * @property { LIT_NETWORKS_KEYS } litNetwork The LIT network that the client who stored the key was connected to - */ -export interface StoredKeyMetadata { - ciphertext: string; - dataToEncryptHash: string; - publicKey: string; - pkpAddress: string; - keyType: string; - litNetwork: LIT_NETWORKS_KEYS; -} - export interface StoreKeyParams extends BaseApiParams { storedKeyMetadata: Pick< StoredKeyMetadata, diff --git a/packages/wrapped-keys/src/lib/types.ts b/packages/wrapped-keys/src/lib/types.ts index e3e6a595be..27e403be9d 100644 --- a/packages/wrapped-keys/src/lib/types.ts +++ b/packages/wrapped-keys/src/lib/types.ts @@ -4,8 +4,6 @@ import { SessionSigsMap, } from '@lit-protocol/types'; -import { StoredKeyMetadata } from '../index'; - /** @typedef Network * The network type that the wrapped key will be used on. */ @@ -34,6 +32,25 @@ export interface ApiParamsSupportedNetworks { */ export type GetEncryptedKeyMetadataParams = BaseApiParams; + +/** Metadata for a key that has been stored, encrypted, on the wrapped keys backend service + * + * @property { string } ciphertext The base64 encoded, salted & encrypted private key + * @property { string } dataToEncryptHash SHA-256 of the ciphertext + * @property { string } publicKey The public key of the encrypted private key + * @property { string } pkpAddress The LIT PKP address that is associated with the encrypted private key + * @property { string } keyType The type of key that was encrypted -- e.g. ed25519, K256, etc. + * @property { LIT_NETWORKS_KEYS } litNetwork The LIT network that the client who stored the key was connected to + */ +export interface StoredKeyMetadata { + ciphertext: string; + dataToEncryptHash: string; + publicKey: string; + pkpAddress: string; + keyType: string; + litNetwork: LIT_NETWORKS_KEYS; +} + /** Fetching a previously persisted key's metadata only requires valid pkpSessionSigs and a LIT Node Client instance configured for the appropriate network. * * @typedef StoreEncryptedKeyMetadataParams From 81409643d46c800834afe39d5cbc0048286345f8 Mon Sep 17 00:00:00 2001 From: Adarsh-Kumar28 Date: Thu, 27 Jun 2024 22:23:50 -0700 Subject: [PATCH 23/30] Published version: 6.0.3@wrapped-keys --- README.md | 62 ++++++++++--------- lerna.json | 2 +- .../access-control-conditions/package.json | 2 +- packages/auth-browser/package.json | 2 +- packages/auth-helpers/package.json | 2 +- packages/bls-sdk/package.json | 2 +- packages/constants/package.json | 2 +- .../src/lib/constants/autogen_internal.ts | 16 ++--- packages/constants/src/lib/version.ts | 2 +- packages/contracts-sdk/package.json | 2 +- packages/core/package.json | 2 +- packages/crypto/package.json | 2 +- packages/ecdsa-sdk/package.json | 2 +- packages/encryption/package.json | 2 +- packages/lit-auth-client/package.json | 2 +- packages/lit-node-client-nodejs/package.json | 2 +- packages/lit-node-client/package.json | 2 +- packages/logger/package.json | 2 +- packages/misc-browser/package.json | 2 +- packages/misc/package.json | 2 +- packages/nacl/package.json | 2 +- packages/pkp-base/package.json | 2 +- packages/pkp-client/package.json | 2 +- packages/pkp-cosmos/package.json | 2 +- packages/pkp-ethers/package.json | 2 +- packages/pkp-sui/package.json | 2 +- packages/pkp-walletconnect/package.json | 2 +- packages/sev-snp-utils-sdk/package.json | 2 +- packages/types/package.json | 2 +- packages/uint8arrays/package.json | 2 +- packages/wrapped-keys/package.json | 2 +- 31 files changed, 65 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 5f0be3b400..452f2d2023 100644 --- a/README.md +++ b/README.md @@ -50,39 +50,41 @@ yarn add @lit-protocol/lit-node-client -| Package | Category | Download | -| -------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 'lit-node-client-nodejs') | | -| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 'lit-node-client') | | +Package | Category | Download +--- | --- | --- +| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 "lit-node-client-nodejs") | +| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 "lit-node-client") | + If you're a tech-savvy user and wish to utilize only specific submodules that our main module relies upon, you can find individual packages listed below. This way, you can import only the necessary packages that cater to your specific use case:: -| Package | Category | Download | -| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 'access-control-conditions') | | -| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 'auth-helpers') | | -| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 'bls-sdk') | | -| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 'constants') | | -| [@lit-protocol/contracts-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/contracts-sdk) | ![contracts-sdk](https://img.shields.io/badge/-universal-8A6496 'contracts-sdk') | | -| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 'core') | | -| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 'crypto') | | -| [@lit-protocol/ecdsa-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/ecdsa-sdk) | ![ecdsa-sdk](https://img.shields.io/badge/-universal-8A6496 'ecdsa-sdk') | | -| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 'encryption') | | -| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 'logger') | | -| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 'misc') | | -| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 'nacl') | | -| [@lit-protocol/pkp-base](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-base) | ![pkp-base](https://img.shields.io/badge/-universal-8A6496 'pkp-base') | | -| [@lit-protocol/pkp-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-client) | ![pkp-client](https://img.shields.io/badge/-universal-8A6496 'pkp-client') | | -| [@lit-protocol/pkp-cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) | ![pkp-cosmos](https://img.shields.io/badge/-universal-8A6496 'pkp-cosmos') | | -| [@lit-protocol/pkp-ethers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-ethers) | ![pkp-ethers](https://img.shields.io/badge/-universal-8A6496 'pkp-ethers') | | -| [@lit-protocol/pkp-sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) | ![pkp-sui](https://img.shields.io/badge/-universal-8A6496 'pkp-sui') | | -| [@lit-protocol/pkp-walletconnect](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-walletconnect) | ![pkp-walletconnect](https://img.shields.io/badge/-universal-8A6496 'pkp-walletconnect') | | -| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 'sev-snp-utils-sdk') | | -| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 'types') | | -| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 'uint8arrays') | | -| [@lit-protocol/wrapped-keys](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys) | ![wrapped-keys](https://img.shields.io/badge/-universal-8A6496 'wrapped-keys') | | -| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 'auth-browser') | | -| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 'misc-browser') | | + +Package | Category | Download +--- | --- | --- +| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 "access-control-conditions") | +| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 "auth-helpers") | +| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 "bls-sdk") | +| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 "constants") | +| [@lit-protocol/contracts-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/contracts-sdk) | ![contracts-sdk](https://img.shields.io/badge/-universal-8A6496 "contracts-sdk") | +| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 "core") | +| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 "crypto") | +| [@lit-protocol/ecdsa-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/ecdsa-sdk) | ![ecdsa-sdk](https://img.shields.io/badge/-universal-8A6496 "ecdsa-sdk") | +| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 "encryption") | +| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 "logger") | +| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 "misc") | +| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 "nacl") | +| [@lit-protocol/pkp-base](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-base) | ![pkp-base](https://img.shields.io/badge/-universal-8A6496 "pkp-base") | +| [@lit-protocol/pkp-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-client) | ![pkp-client](https://img.shields.io/badge/-universal-8A6496 "pkp-client") | +| [@lit-protocol/pkp-cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) | ![pkp-cosmos](https://img.shields.io/badge/-universal-8A6496 "pkp-cosmos") | +| [@lit-protocol/pkp-ethers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-ethers) | ![pkp-ethers](https://img.shields.io/badge/-universal-8A6496 "pkp-ethers") | +| [@lit-protocol/pkp-sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) | ![pkp-sui](https://img.shields.io/badge/-universal-8A6496 "pkp-sui") | +| [@lit-protocol/pkp-walletconnect](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-walletconnect) | ![pkp-walletconnect](https://img.shields.io/badge/-universal-8A6496 "pkp-walletconnect") | +| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 "sev-snp-utils-sdk") | +| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 "types") | +| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 "uint8arrays") | +| [@lit-protocol/wrapped-keys](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys) | ![wrapped-keys](https://img.shields.io/badge/-universal-8A6496 "wrapped-keys") | +| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 "auth-browser") | +| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 "misc-browser") | diff --git a/lerna.json b/lerna.json index 40bcbb86c5..0e4d62ecdf 100644 --- a/lerna.json +++ b/lerna.json @@ -2,5 +2,5 @@ "$schema": "node_modules/lerna/schemas/lerna-schema.json", "useNx": true, "useWorkspaces": true, - "version": "6.0.3-wrapped-keys.beta.3" + "version": "6.0.3-wrapped-keys.beta.4" } diff --git a/packages/access-control-conditions/package.json b/packages/access-control-conditions/package.json index c20b3a0c5d..d12be407ba 100644 --- a/packages/access-control-conditions/package.json +++ b/packages/access-control-conditions/package.json @@ -21,7 +21,7 @@ "tags": [ "universal" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/auth-browser/package.json b/packages/auth-browser/package.json index 082106509f..c818a6885e 100644 --- a/packages/auth-browser/package.json +++ b/packages/auth-browser/package.json @@ -30,7 +30,7 @@ "tags": [ "browser" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/auth-helpers/package.json b/packages/auth-helpers/package.json index 39fec04705..c422006881 100644 --- a/packages/auth-helpers/package.json +++ b/packages/auth-helpers/package.json @@ -28,7 +28,7 @@ "crypto": false, "stream": false }, - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/bls-sdk/package.json b/packages/bls-sdk/package.json index 5f6068541a..a66544c9b2 100644 --- a/packages/bls-sdk/package.json +++ b/packages/bls-sdk/package.json @@ -27,7 +27,7 @@ "buildOptions": { "genReact": false }, - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/constants/package.json b/packages/constants/package.json index 7bea4451af..b122426ee9 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -20,7 +20,7 @@ "tags": [ "universal" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/constants/src/lib/constants/autogen_internal.ts b/packages/constants/src/lib/constants/autogen_internal.ts index 3467eed024..ab0359d069 100644 --- a/packages/constants/src/lib/constants/autogen_internal.ts +++ b/packages/constants/src/lib/constants/autogen_internal.ts @@ -1,13 +1,9 @@ // This file is auto-generated by tools/scripts/gen-internal-dev.mjs export const INTERNAL_DEV = [ - 'https://167.114.17.201:443', - 'https://158.69.34.226:443', - 'https://51.195.27.82:443', - 'https://167.114.17.203:443', - 'https://167.114.17.204:443', 'https://51.38.90.145:443', 'https://167.114.17.205:443', - 'https://167.114.17.202:443', + 'https://167.114.17.204:443', + 'https://167.114.17.203:443', ]; export const INTERNAL_MIN_NODE_COUNT = 3; @@ -17,14 +13,10 @@ export const INTERNAL_DEFAULT_CONFIG = { minNodeCount: 3, debug: true, bootstrapUrls: [ - 'https://167.114.17.201:443', - 'https://158.69.34.226:443', - 'https://51.195.27.82:443', - 'https://167.114.17.203:443', - 'https://167.114.17.204:443', 'https://51.38.90.145:443', 'https://167.114.17.205:443', - 'https://167.114.17.202:443', + 'https://167.114.17.204:443', + 'https://167.114.17.203:443', ], litNetwork: 'internalDev', connectTimeout: 20000, diff --git a/packages/constants/src/lib/version.ts b/packages/constants/src/lib/version.ts index 4035e5fa36..2ef1c96f29 100644 --- a/packages/constants/src/lib/version.ts +++ b/packages/constants/src/lib/version.ts @@ -1 +1 @@ -export const version = '6.0.3-wrapped-keys.beta.3'; +export const version = '6.0.3-wrapped-keys.beta.4'; diff --git a/packages/contracts-sdk/package.json b/packages/contracts-sdk/package.json index ce819f4c96..226f06ad33 100644 --- a/packages/contracts-sdk/package.json +++ b/packages/contracts-sdk/package.json @@ -32,7 +32,7 @@ "tags": [ "universal" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/core/package.json b/packages/core/package.json index eba6ea0171..efe6a31e72 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@lit-protocol/core", - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "type": "commonjs", "license": "MIT", "homepage": "https://github.com/Lit-Protocol/js-sdk", diff --git a/packages/crypto/package.json b/packages/crypto/package.json index 822e91de15..15da64cdc5 100644 --- a/packages/crypto/package.json +++ b/packages/crypto/package.json @@ -21,7 +21,7 @@ "tags": [ "universal" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/ecdsa-sdk/package.json b/packages/ecdsa-sdk/package.json index 678106e818..2c3d1defd6 100644 --- a/packages/ecdsa-sdk/package.json +++ b/packages/ecdsa-sdk/package.json @@ -24,7 +24,7 @@ "tags": [ "universal" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/encryption/package.json b/packages/encryption/package.json index 55caa8b978..ce4afc86ca 100644 --- a/packages/encryption/package.json +++ b/packages/encryption/package.json @@ -25,7 +25,7 @@ "crypto": false, "stream": false }, - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/lit-auth-client/package.json b/packages/lit-auth-client/package.json index ad5c39414c..15de029072 100644 --- a/packages/lit-auth-client/package.json +++ b/packages/lit-auth-client/package.json @@ -1,6 +1,6 @@ { "name": "@lit-protocol/lit-auth-client", - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "type": "commonjs", "license": "MIT", "homepage": "https://github.com/Lit-Protocol/js-sdk", diff --git a/packages/lit-node-client-nodejs/package.json b/packages/lit-node-client-nodejs/package.json index 594a675835..741d9f2e7f 100644 --- a/packages/lit-node-client-nodejs/package.json +++ b/packages/lit-node-client-nodejs/package.json @@ -24,7 +24,7 @@ "tags": [ "nodejs" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/lit-node-client/package.json b/packages/lit-node-client/package.json index 9777625828..766a309ec7 100644 --- a/packages/lit-node-client/package.json +++ b/packages/lit-node-client/package.json @@ -28,7 +28,7 @@ "crypto": false, "stream": false }, - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/logger/package.json b/packages/logger/package.json index 0b8d92ade9..8c703a87e5 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -1,6 +1,6 @@ { "name": "@lit-protocol/logger", - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "type": "commonjs", "tags": [ "universal" diff --git a/packages/misc-browser/package.json b/packages/misc-browser/package.json index fc0a7941aa..2891a358cd 100644 --- a/packages/misc-browser/package.json +++ b/packages/misc-browser/package.json @@ -21,7 +21,7 @@ "tags": [ "browser" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/misc/package.json b/packages/misc/package.json index 66eafe1e04..c1e55c888d 100644 --- a/packages/misc/package.json +++ b/packages/misc/package.json @@ -24,7 +24,7 @@ "tags": [ "universal" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/nacl/package.json b/packages/nacl/package.json index 5fd6d520f3..46b1bebf9c 100644 --- a/packages/nacl/package.json +++ b/packages/nacl/package.json @@ -21,7 +21,7 @@ "access": "public", "directory": "../../dist/packages/nacl" }, - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/pkp-base/package.json b/packages/pkp-base/package.json index 9127dabb92..bf6f44f247 100644 --- a/packages/pkp-base/package.json +++ b/packages/pkp-base/package.json @@ -1,6 +1,6 @@ { "name": "@lit-protocol/pkp-base", - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "type": "commonjs", "license": "MIT", "homepage": "https://github.com/Lit-Protocol/js-sdk", diff --git a/packages/pkp-client/package.json b/packages/pkp-client/package.json index e650d84ef8..21d155ffb1 100644 --- a/packages/pkp-client/package.json +++ b/packages/pkp-client/package.json @@ -1,6 +1,6 @@ { "name": "@lit-protocol/pkp-client", - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "type": "commonjs", "license": "MIT", "homepage": "https://github.com/Lit-Protocol/js-sdk", diff --git a/packages/pkp-cosmos/package.json b/packages/pkp-cosmos/package.json index 80569582b4..954bad6c66 100644 --- a/packages/pkp-cosmos/package.json +++ b/packages/pkp-cosmos/package.json @@ -1,6 +1,6 @@ { "name": "@lit-protocol/pkp-cosmos", - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "type": "commonjs", "license": "MIT", "homepage": "https://github.com/Lit-Protocol/js-sdk", diff --git a/packages/pkp-ethers/package.json b/packages/pkp-ethers/package.json index 50c579a225..3697737341 100644 --- a/packages/pkp-ethers/package.json +++ b/packages/pkp-ethers/package.json @@ -20,7 +20,7 @@ "tags": [ "universal" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/pkp-sui/package.json b/packages/pkp-sui/package.json index 8113276455..dd68547b2e 100644 --- a/packages/pkp-sui/package.json +++ b/packages/pkp-sui/package.json @@ -1,6 +1,6 @@ { "name": "@lit-protocol/pkp-sui", - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "type": "commonjs", "license": "MIT", "homepage": "https://github.com/Lit-Protocol/js-sdk", diff --git a/packages/pkp-walletconnect/package.json b/packages/pkp-walletconnect/package.json index aa29c7ef27..4f7cd6d606 100644 --- a/packages/pkp-walletconnect/package.json +++ b/packages/pkp-walletconnect/package.json @@ -1,6 +1,6 @@ { "name": "@lit-protocol/pkp-walletconnect", - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "type": "commonjs", "license": "MIT", "homepage": "https://github.com/Lit-Protocol/js-sdk", diff --git a/packages/sev-snp-utils-sdk/package.json b/packages/sev-snp-utils-sdk/package.json index 62041dc81a..14d683c6ff 100644 --- a/packages/sev-snp-utils-sdk/package.json +++ b/packages/sev-snp-utils-sdk/package.json @@ -27,7 +27,7 @@ "buildOptions": { "genReact": false }, - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/types/package.json b/packages/types/package.json index cd671cd31f..64f9443be3 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -23,7 +23,7 @@ "buildOptions": { "genReact": false }, - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/uint8arrays/package.json b/packages/uint8arrays/package.json index 1f97108f65..9242bfd13d 100644 --- a/packages/uint8arrays/package.json +++ b/packages/uint8arrays/package.json @@ -21,7 +21,7 @@ "tags": [ "universal" ], - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" } \ No newline at end of file diff --git a/packages/wrapped-keys/package.json b/packages/wrapped-keys/package.json index 027e8f5ed9..f959cbc793 100644 --- a/packages/wrapped-keys/package.json +++ b/packages/wrapped-keys/package.json @@ -23,7 +23,7 @@ "buildOptions": { "genReact": false }, - "version": "6.0.3-wrapped-keys.beta.3", + "version": "6.0.3-wrapped-keys.beta.4", "scripts": { "bundle": "yarn node ./esbuild.config.js" }, From 878c4fa196f83df8fbb881f07392e284854e0474 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Fri, 28 Jun 2024 14:39:14 +0100 Subject: [PATCH 24/30] fix(wrapped-keys): LIT-3125 - Remove FIXME :) --- packages/wrapped-keys/src/lib/api/export-private-key.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wrapped-keys/src/lib/api/export-private-key.ts b/packages/wrapped-keys/src/lib/api/export-private-key.ts index 5a64fe51da..d672058a02 100644 --- a/packages/wrapped-keys/src/lib/api/export-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/export-private-key.ts @@ -33,7 +33,7 @@ export async function exportPrivateKey( const decryptedPrivateKey = await decryptToString( { accessControlConditions: [allowPkpAddressToDecrypt], - chain: CHAIN_ETHEREUM, // FIXME: This won't always be true. + chain: CHAIN_ETHEREUM, ciphertext, dataToEncryptHash, sessionSigs: pkpSessionSigs, From acb10f2e1da4533a4ebca28817d38dc0c4627769 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Fri, 28 Jun 2024 14:39:20 +0100 Subject: [PATCH 25/30] test(wrapped-keys): LIT-3125 - Fix actually-failing-fail test string check --- local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts b/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts index bcf072b2fd..c0328d5b95 100644 --- a/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts +++ b/local-tests/tests/testFailImportWrappedKeysWithEoaSessionSig.ts @@ -34,7 +34,7 @@ export const testFailImportWrappedKeysWithEoaSessionSig = async ( console.log('❌ THIS IS EXPECTED: ', e); console.log(e.message); - if (e.message === 'SessionSig is not from a PKP') { + if (e.message.includes('SessionSig is not from a PKP')) { console.log( '✅ testFailImportWrappedKeysWithEoaSessionSig is expected to have an error' ); From c3dafd0a4eb4ccf7bb93848686bbd04a01882fd0 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Fri, 28 Jun 2024 14:44:14 +0100 Subject: [PATCH 26/30] fix(wrapped-keys): LIT-3125 - Add strong type for `KeyType`, and compute correct keyType in `generatePrivateKey()` --- .../src/lib/api/generate-private-key.ts | 20 +++++++++++++++---- packages/wrapped-keys/src/lib/types.ts | 7 ++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/wrapped-keys/src/lib/api/generate-private-key.ts b/packages/wrapped-keys/src/lib/api/generate-private-key.ts index 3cd205e6f0..e36201fb02 100644 --- a/packages/wrapped-keys/src/lib/api/generate-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/generate-private-key.ts @@ -1,15 +1,27 @@ -import { LIT_CURVE } from '@lit-protocol/constants'; - import { generateKeyWithLitAction } from '../lit-actions-client'; import { getLitActionCid } from '../lit-actions-client/utils'; import { storePrivateKeyMetadata } from '../service-client'; -import { GeneratePrivateKeyParams, GeneratePrivateKeyResult } from '../types'; +import { + GeneratePrivateKeyParams, + GeneratePrivateKeyResult, + KeyType, + Network, +} from '../types'; import { getFirstSessionSig, getPkpAccessControlCondition, getPkpAddressFromSessionSig, } from '../utils'; +function getKeyTypeFromNetwork(network: Network): KeyType { + if (network === 'evm') { + return 'K256'; + } else if (network === 'solana') { + return 'ed25519'; + } else { + throw new Error('Network not implemented in generate-private-key'); + } +} /** * Generates a random private key inside a Lit Action, and persists the key and its metadata to the wrapped keys service. * Returns the public key of the random private key, and the PKP address that it was associated with. @@ -43,7 +55,7 @@ export async function generatePrivateKey( storedKeyMetadata: { ciphertext, publicKey, - keyType: LIT_CURVE.EcdsaK256, // FIXME: Should be returned by the LIT action; we won't know what it is unless it's provided. + keyType: getKeyTypeFromNetwork(network), dataToEncryptHash, pkpAddress, }, diff --git a/packages/wrapped-keys/src/lib/types.ts b/packages/wrapped-keys/src/lib/types.ts index 27e403be9d..5f031aa04f 100644 --- a/packages/wrapped-keys/src/lib/types.ts +++ b/packages/wrapped-keys/src/lib/types.ts @@ -8,6 +8,7 @@ import { * The network type that the wrapped key will be used on. */ export type Network = 'evm' | 'solana'; +export type KeyType = 'K256' | 'ed25519'; /** All API calls for the wrapped keys service require these arguments. * @@ -47,7 +48,7 @@ export interface StoredKeyMetadata { dataToEncryptHash: string; publicKey: string; pkpAddress: string; - keyType: string; + keyType: KeyType; litNetwork: LIT_NETWORKS_KEYS; } @@ -86,7 +87,7 @@ export interface ExportPrivateKeyResult { decryptedPrivateKey: string; publicKey: string; litNetwork: LIT_NETWORKS_KEYS; - keyType: string; + keyType: KeyType; } /** @typedef GeneratePrivateKeyParams @@ -116,7 +117,7 @@ export interface GeneratePrivateKeyResult { export interface ImportPrivateKeyParams extends BaseApiParams { privateKey: string; publicKey: string; - keyType: string; + keyType: KeyType; } interface SignMessageParams { From cbdc55685aa5aa3cb964861d8c52d6da198f6d90 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Fri, 28 Jun 2024 15:02:42 +0100 Subject: [PATCH 27/30] chore(wrapped-keys): LIT-3125 - Remove commented code and excess `console.log` --- packages/wrapped-keys/src/lib/lit-actions-client/utils.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts b/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts index 482d8d159d..c993199985 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/utils.ts @@ -15,8 +15,6 @@ import { Network } from '../types'; export function postLitActionValidation( result: ExecuteJsResponse | undefined ): string { - // console.log(`Lit Action result: ${JSON.stringify(result)}`); - if (!result) { throw new Error('There was an unknown error running the Lit Action.'); } @@ -27,7 +25,6 @@ export function postLitActionValidation( `Expected "response" in Lit Action result: ${JSON.stringify(result)}` ); } - console.log('response', response); if (typeof response !== 'string') { // As the return value is a hex string From 0be70bb3f1664ca44a0dc34341e3a6d5cb044c74 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Fri, 28 Jun 2024 15:34:21 +0100 Subject: [PATCH 28/30] docs(wrapped-keys): LIT-3125 - Fix JSDoc for `StoreEncryptedKeyMetadata()` --- .../wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts b/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts index f6cadd1b16..462bd349f1 100644 --- a/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts +++ b/packages/wrapped-keys/src/lib/api/store-encrypted-key-metadata.ts @@ -2,8 +2,7 @@ import { storePrivateKeyMetadata } from '../service-client'; import { StoreEncryptedKeyMetadataParams } from '../types'; import { getFirstSessionSig, getPkpAddressFromSessionSig } from '../utils'; -/** Get a previously encrypted and persisted private key and its metadata. - * Note that this method does _not_ decrypt the private key; only the _encrypted_ key and its metadata will be returned to the caller. +/** Stores an encrypted private key and its metadata to the wrapped keys backend service * * @param { StoreEncryptedKeyMetadataParams } params Parameters required to fetch the encrypted private key metadata * @returns { Promise } The encrypted private key and its associated metadata From 6b726343f056bf5692f8bbaebfad4bf07f4f3128 Mon Sep 17 00:00:00 2001 From: Daryl Collins Date: Fri, 28 Jun 2024 16:48:56 +0100 Subject: [PATCH 29/30] docs(wrapped-keys): LIT-3125 - Export constants for `keyType` and `network` --- packages/wrapped-keys/src/index.ts | 13 ++++++++++++- .../src/lib/api/generate-private-key.ts | 5 +++-- packages/wrapped-keys/src/lib/constants.ts | 8 ++++++++ .../src/lib/lit-actions-client/constants.ts | 12 ++++++------ packages/wrapped-keys/src/lib/types.ts | 2 +- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/packages/wrapped-keys/src/index.ts b/packages/wrapped-keys/src/index.ts index 0cecb5a142..fe605532cb 100644 --- a/packages/wrapped-keys/src/index.ts +++ b/packages/wrapped-keys/src/index.ts @@ -7,7 +7,14 @@ import { signTransactionWithEncryptedKey, storeEncryptedKeyMetadata, } from './lib/api'; -import { CHAIN_ETHEREUM, LIT_PREFIX } from './lib/constants'; +import { + CHAIN_ETHEREUM, + LIT_PREFIX, + NETWORK_EVM, + NETWORK_SOLANA, + KEYTYPE_K256, + KEYTYPE_ED25519, +} from './lib/constants'; import type { SupportedNetworks } from './lib/service-client/types'; import type { @@ -33,6 +40,10 @@ import type { export const constants = { CHAIN_ETHEREUM, LIT_PREFIX, + NETWORK_EVM, + NETWORK_SOLANA, + KEYTYPE_K256, + KEYTYPE_ED25519, }; export const api = { diff --git a/packages/wrapped-keys/src/lib/api/generate-private-key.ts b/packages/wrapped-keys/src/lib/api/generate-private-key.ts index e36201fb02..501840ebd7 100644 --- a/packages/wrapped-keys/src/lib/api/generate-private-key.ts +++ b/packages/wrapped-keys/src/lib/api/generate-private-key.ts @@ -1,3 +1,4 @@ +import { NETWORK_EVM, NETWORK_SOLANA } from '../constants'; import { generateKeyWithLitAction } from '../lit-actions-client'; import { getLitActionCid } from '../lit-actions-client/utils'; import { storePrivateKeyMetadata } from '../service-client'; @@ -14,9 +15,9 @@ import { } from '../utils'; function getKeyTypeFromNetwork(network: Network): KeyType { - if (network === 'evm') { + if (network === NETWORK_EVM) { return 'K256'; - } else if (network === 'solana') { + } else if (network === NETWORK_SOLANA) { return 'ed25519'; } else { throw new Error('Network not implemented in generate-private-key'); diff --git a/packages/wrapped-keys/src/lib/constants.ts b/packages/wrapped-keys/src/lib/constants.ts index bd0cbfbb3d..52b737cf12 100644 --- a/packages/wrapped-keys/src/lib/constants.ts +++ b/packages/wrapped-keys/src/lib/constants.ts @@ -1,2 +1,10 @@ +import { Network, KeyType } from './types'; + export const CHAIN_ETHEREUM = 'ethereum'; export const LIT_PREFIX = 'lit_'; + +export const NETWORK_EVM: Network = 'evm'; +export const NETWORK_SOLANA: Network = 'solana'; + +export const KEYTYPE_K256: KeyType = 'K256'; +export const KEYTYPE_ED25519: KeyType = 'ed25519'; diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts b/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts index ce90374dbe..133257b2fe 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts @@ -2,16 +2,16 @@ import { LitCidRepository } from './types'; const LIT_ACTION_CID_REPOSITORY: LitCidRepository = { signTransaction: Object.freeze({ - ['evm']: 'QmdYUhPCCK5hpDWMK1NiDLNLG6RZQy61QE4J7dBm1Y2nbA', - ['solana']: 'QmSi9GL2weCFEP1SMAUw5PDpZRr436Zt3tLUNrSECPA5dT', + evm: 'QmdYUhPCCK5hpDWMK1NiDLNLG6RZQy61QE4J7dBm1Y2nbA', + solana: 'QmSi9GL2weCFEP1SMAUw5PDpZRr436Zt3tLUNrSECPA5dT', }), signMessage: Object.freeze({ - ['evm']: 'QmTMGcyp77NeppGaqF2DmE1F8GXTSxQYzXCrbE7hNudUWx', - ['solana']: 'QmYQC6cd4EMvyB4XPkfEEAwNXJupRZWU5JsTCUrjey4ovp', + evm: 'QmTMGcyp77NeppGaqF2DmE1F8GXTSxQYzXCrbE7hNudUWx', + solana: 'QmYQC6cd4EMvyB4XPkfEEAwNXJupRZWU5JsTCUrjey4ovp', }), generateEncryptedKey: Object.freeze({ - ['evm']: 'QmaoPMSqcze3NW3KSA75ecWSkcmWT1J7kVr8LyJPCKRvHd', - ['solana']: 'QmdRBXYLYvcNHrChmsZ2jFDY8dA99CcSdqHo3p1ES3UThL', + evm: 'QmaoPMSqcze3NW3KSA75ecWSkcmWT1J7kVr8LyJPCKRvHd', + solana: 'QmdRBXYLYvcNHrChmsZ2jFDY8dA99CcSdqHo3p1ES3UThL', }), }; diff --git a/packages/wrapped-keys/src/lib/types.ts b/packages/wrapped-keys/src/lib/types.ts index 5f031aa04f..0f53555fc2 100644 --- a/packages/wrapped-keys/src/lib/types.ts +++ b/packages/wrapped-keys/src/lib/types.ts @@ -181,7 +181,7 @@ export interface SignTransactionParamsSupportedSolana /** @typedef SignTransactionWithEncryptedKeyParams * @extends BaseApiParams * @property { boolean } broadcast Whether the LIT action should broadcast the signed transaction to RPC, or only sign the transaction and return the signed transaction to the caller - * @property { EthereumLitTransaction | SerializedTransaction } unsignedTransaction The unsigned transaction to be signed. When network is 'solana' or 'custom', be sure to provided a {@link SerializedTransaction} instance. + * @property { EthereumLitTransaction | SerializedTransaction } unsignedTransaction The unsigned transaction to be signed. When network is 'solana', be sure to provide a {@link SerializedTransaction} instance. */ export type SignTransactionWithEncryptedKeyParams = | SignTransactionParamsSupportedEvm From 3a7c9432ef8e5271bbd2c1faeef62c8e3749ba62 Mon Sep 17 00:00:00 2001 From: Adarsh-Kumar28 Date: Sat, 29 Jun 2024 14:17:27 -0700 Subject: [PATCH 30/30] refac: Prettier --- README.md | 62 +++++++++---------- .../access-control-conditions/package.json | 2 +- packages/auth-browser/package.json | 2 +- packages/auth-helpers/package.json | 2 +- packages/bls-sdk/package.json | 2 +- packages/constants/package.json | 2 +- packages/contracts-sdk/package.json | 2 +- packages/core/package.json | 2 +- packages/crypto/package.json | 2 +- packages/ecdsa-sdk/package.json | 2 +- packages/encryption/package.json | 2 +- packages/lit-auth-client/package.json | 2 +- packages/lit-node-client-nodejs/package.json | 2 +- packages/lit-node-client/package.json | 2 +- packages/logger/package.json | 2 +- packages/misc-browser/package.json | 2 +- packages/misc/package.json | 2 +- packages/nacl/package.json | 2 +- packages/pkp-base/package.json | 2 +- packages/pkp-client/package.json | 2 +- packages/pkp-cosmos/package.json | 2 +- packages/pkp-ethers/package.json | 2 +- packages/pkp-sui/package.json | 2 +- packages/pkp-walletconnect/package.json | 2 +- packages/sev-snp-utils-sdk/package.json | 2 +- packages/types/package.json | 2 +- packages/uint8arrays/package.json | 2 +- packages/wrapped-keys/package.json | 2 +- 28 files changed, 57 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 452f2d2023..5f0be3b400 100644 --- a/README.md +++ b/README.md @@ -50,41 +50,39 @@ yarn add @lit-protocol/lit-node-client -Package | Category | Download ---- | --- | --- -| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 "lit-node-client-nodejs") | -| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 "lit-node-client") | - +| Package | Category | Download | +| -------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 'lit-node-client-nodejs') | | +| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 'lit-node-client') | | If you're a tech-savvy user and wish to utilize only specific submodules that our main module relies upon, you can find individual packages listed below. This way, you can import only the necessary packages that cater to your specific use case:: - -Package | Category | Download ---- | --- | --- -| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 "access-control-conditions") | -| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 "auth-helpers") | -| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 "bls-sdk") | -| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 "constants") | -| [@lit-protocol/contracts-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/contracts-sdk) | ![contracts-sdk](https://img.shields.io/badge/-universal-8A6496 "contracts-sdk") | -| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 "core") | -| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 "crypto") | -| [@lit-protocol/ecdsa-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/ecdsa-sdk) | ![ecdsa-sdk](https://img.shields.io/badge/-universal-8A6496 "ecdsa-sdk") | -| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 "encryption") | -| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 "logger") | -| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 "misc") | -| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 "nacl") | -| [@lit-protocol/pkp-base](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-base) | ![pkp-base](https://img.shields.io/badge/-universal-8A6496 "pkp-base") | -| [@lit-protocol/pkp-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-client) | ![pkp-client](https://img.shields.io/badge/-universal-8A6496 "pkp-client") | -| [@lit-protocol/pkp-cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) | ![pkp-cosmos](https://img.shields.io/badge/-universal-8A6496 "pkp-cosmos") | -| [@lit-protocol/pkp-ethers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-ethers) | ![pkp-ethers](https://img.shields.io/badge/-universal-8A6496 "pkp-ethers") | -| [@lit-protocol/pkp-sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) | ![pkp-sui](https://img.shields.io/badge/-universal-8A6496 "pkp-sui") | -| [@lit-protocol/pkp-walletconnect](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-walletconnect) | ![pkp-walletconnect](https://img.shields.io/badge/-universal-8A6496 "pkp-walletconnect") | -| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 "sev-snp-utils-sdk") | -| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 "types") | -| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 "uint8arrays") | -| [@lit-protocol/wrapped-keys](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys) | ![wrapped-keys](https://img.shields.io/badge/-universal-8A6496 "wrapped-keys") | -| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 "auth-browser") | -| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 "misc-browser") | +| Package | Category | Download | +| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 'access-control-conditions') | | +| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 'auth-helpers') | | +| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 'bls-sdk') | | +| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 'constants') | | +| [@lit-protocol/contracts-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/contracts-sdk) | ![contracts-sdk](https://img.shields.io/badge/-universal-8A6496 'contracts-sdk') | | +| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 'core') | | +| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 'crypto') | | +| [@lit-protocol/ecdsa-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/ecdsa-sdk) | ![ecdsa-sdk](https://img.shields.io/badge/-universal-8A6496 'ecdsa-sdk') | | +| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 'encryption') | | +| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 'logger') | | +| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 'misc') | | +| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 'nacl') | | +| [@lit-protocol/pkp-base](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-base) | ![pkp-base](https://img.shields.io/badge/-universal-8A6496 'pkp-base') | | +| [@lit-protocol/pkp-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-client) | ![pkp-client](https://img.shields.io/badge/-universal-8A6496 'pkp-client') | | +| [@lit-protocol/pkp-cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) | ![pkp-cosmos](https://img.shields.io/badge/-universal-8A6496 'pkp-cosmos') | | +| [@lit-protocol/pkp-ethers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-ethers) | ![pkp-ethers](https://img.shields.io/badge/-universal-8A6496 'pkp-ethers') | | +| [@lit-protocol/pkp-sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) | ![pkp-sui](https://img.shields.io/badge/-universal-8A6496 'pkp-sui') | | +| [@lit-protocol/pkp-walletconnect](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-walletconnect) | ![pkp-walletconnect](https://img.shields.io/badge/-universal-8A6496 'pkp-walletconnect') | | +| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 'sev-snp-utils-sdk') | | +| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 'types') | | +| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 'uint8arrays') | | +| [@lit-protocol/wrapped-keys](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys) | ![wrapped-keys](https://img.shields.io/badge/-universal-8A6496 'wrapped-keys') | | +| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 'auth-browser') | | +| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 'misc-browser') | | diff --git a/packages/access-control-conditions/package.json b/packages/access-control-conditions/package.json index d12be407ba..980b531c36 100644 --- a/packages/access-control-conditions/package.json +++ b/packages/access-control-conditions/package.json @@ -24,4 +24,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/auth-browser/package.json b/packages/auth-browser/package.json index c818a6885e..877736bad0 100644 --- a/packages/auth-browser/package.json +++ b/packages/auth-browser/package.json @@ -33,4 +33,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/auth-helpers/package.json b/packages/auth-helpers/package.json index c422006881..cbed31c757 100644 --- a/packages/auth-helpers/package.json +++ b/packages/auth-helpers/package.json @@ -31,4 +31,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/bls-sdk/package.json b/packages/bls-sdk/package.json index a66544c9b2..2cda12b09b 100644 --- a/packages/bls-sdk/package.json +++ b/packages/bls-sdk/package.json @@ -30,4 +30,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/constants/package.json b/packages/constants/package.json index b122426ee9..39bdf4feb0 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -23,4 +23,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/contracts-sdk/package.json b/packages/contracts-sdk/package.json index 226f06ad33..ee706bbf4f 100644 --- a/packages/contracts-sdk/package.json +++ b/packages/contracts-sdk/package.json @@ -35,4 +35,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/core/package.json b/packages/core/package.json index efe6a31e72..0019297540 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -27,4 +27,4 @@ ], "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/crypto/package.json b/packages/crypto/package.json index 15da64cdc5..38b99fec03 100644 --- a/packages/crypto/package.json +++ b/packages/crypto/package.json @@ -24,4 +24,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/ecdsa-sdk/package.json b/packages/ecdsa-sdk/package.json index 2c3d1defd6..48d6e0dc47 100644 --- a/packages/ecdsa-sdk/package.json +++ b/packages/ecdsa-sdk/package.json @@ -27,4 +27,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/encryption/package.json b/packages/encryption/package.json index ce4afc86ca..7be92762db 100644 --- a/packages/encryption/package.json +++ b/packages/encryption/package.json @@ -28,4 +28,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/lit-auth-client/package.json b/packages/lit-auth-client/package.json index 15de029072..c24f875b74 100644 --- a/packages/lit-auth-client/package.json +++ b/packages/lit-auth-client/package.json @@ -31,4 +31,4 @@ }, "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/lit-node-client-nodejs/package.json b/packages/lit-node-client-nodejs/package.json index 741d9f2e7f..33bd69f527 100644 --- a/packages/lit-node-client-nodejs/package.json +++ b/packages/lit-node-client-nodejs/package.json @@ -27,4 +27,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/lit-node-client/package.json b/packages/lit-node-client/package.json index 766a309ec7..8a5fd82d5d 100644 --- a/packages/lit-node-client/package.json +++ b/packages/lit-node-client/package.json @@ -31,4 +31,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/logger/package.json b/packages/logger/package.json index 8c703a87e5..dc76a839f4 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -11,4 +11,4 @@ }, "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/misc-browser/package.json b/packages/misc-browser/package.json index 2891a358cd..6e9e1961ae 100644 --- a/packages/misc-browser/package.json +++ b/packages/misc-browser/package.json @@ -24,4 +24,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/misc/package.json b/packages/misc/package.json index c1e55c888d..7900a5403e 100644 --- a/packages/misc/package.json +++ b/packages/misc/package.json @@ -27,4 +27,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/nacl/package.json b/packages/nacl/package.json index 46b1bebf9c..ac9fbe6829 100644 --- a/packages/nacl/package.json +++ b/packages/nacl/package.json @@ -24,4 +24,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/pkp-base/package.json b/packages/pkp-base/package.json index bf6f44f247..c771b780e9 100644 --- a/packages/pkp-base/package.json +++ b/packages/pkp-base/package.json @@ -27,4 +27,4 @@ ], "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/pkp-client/package.json b/packages/pkp-client/package.json index 21d155ffb1..64afcf556f 100644 --- a/packages/pkp-client/package.json +++ b/packages/pkp-client/package.json @@ -27,4 +27,4 @@ ], "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/pkp-cosmos/package.json b/packages/pkp-cosmos/package.json index 954bad6c66..314884feff 100644 --- a/packages/pkp-cosmos/package.json +++ b/packages/pkp-cosmos/package.json @@ -27,4 +27,4 @@ ], "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/pkp-ethers/package.json b/packages/pkp-ethers/package.json index 3697737341..b83aa801d3 100644 --- a/packages/pkp-ethers/package.json +++ b/packages/pkp-ethers/package.json @@ -23,4 +23,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/pkp-sui/package.json b/packages/pkp-sui/package.json index dd68547b2e..ac539dbff8 100644 --- a/packages/pkp-sui/package.json +++ b/packages/pkp-sui/package.json @@ -27,4 +27,4 @@ ], "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/pkp-walletconnect/package.json b/packages/pkp-walletconnect/package.json index 4f7cd6d606..d7bba4ea6e 100644 --- a/packages/pkp-walletconnect/package.json +++ b/packages/pkp-walletconnect/package.json @@ -34,4 +34,4 @@ ], "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/sev-snp-utils-sdk/package.json b/packages/sev-snp-utils-sdk/package.json index 14d683c6ff..3b9b58c409 100644 --- a/packages/sev-snp-utils-sdk/package.json +++ b/packages/sev-snp-utils-sdk/package.json @@ -30,4 +30,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/types/package.json b/packages/types/package.json index 64f9443be3..903319a7f4 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -26,4 +26,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/uint8arrays/package.json b/packages/uint8arrays/package.json index 9242bfd13d..73f7b35b2b 100644 --- a/packages/uint8arrays/package.json +++ b/packages/uint8arrays/package.json @@ -24,4 +24,4 @@ "version": "6.0.3-wrapped-keys.beta.4", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/wrapped-keys/package.json b/packages/wrapped-keys/package.json index f959cbc793..e071720405 100644 --- a/packages/wrapped-keys/package.json +++ b/packages/wrapped-keys/package.json @@ -29,4 +29,4 @@ }, "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" -} \ No newline at end of file +}