Migrating from 6.x.x to 7.x.x
Breaking Changes & Important Updates
Removal of Encryption Inclusion
Reference: Pull Request #608
Changes:
- Encryption Functions:
- Added
encryptUint8ArrayanddecryptToUint8Arrayin@lit-protocol/encryptionfor handlingUint8Arraydata types. - These functions unify encryption and decryption interfaces within the
@lit-protocol/encryptionpackage.
- Added
- Function Relocations:
- The following have been moved from
@lit-protocol/encryptionto@lit-protocol/misc:isTokenOperatorisValidBooleanExpressionsafeParamsAccessControlConditionsValidatorPropsAuthMaterialValidatorPropsParamsValidatorsType
- The following have been moved from
- Export Changes:
- Removed re-exports of
@lit-protocol/encryptionfunctions in@lit-protocol/lit-node-client-nodejs.
- Removed re-exports of
Migration Steps:
- Encrypting and Decrypting
Uint8Array:- Replace usage of
encryptanddecryptfunctions inLitNodeClientwithencryptUint8ArrayanddecryptToUint8Arrayfrom@lit-protocol/encryption.import { encryptUint8Array, decryptToUint8Array } from '@lit-protocol/encryption';
- Replace usage of
- String and File Encryption/Decryption:
- Functions like
encryptString,encryptFile,decryptString, anddecryptFileare no longer exported from@lit-protocol/lit-node-client-nodejsor@lit-protocol/lit-node-client. - Import these exclusively from
@lit-protocol/encryption.import { encryptString, decryptString } from '@lit-protocol/encryption';
- Functions like
- Moved Functions and Interfaces:
- Import the following from
@lit-protocol/misc:import {
isTokenOperator,
isValidBooleanExpression,
safeParams,
AccessControlConditionsValidatorProps,
AuthMaterialValidatorProps,
ParamsValidatorsType,
} from '@lit-protocol/misc';
- Import the following from
Changes to Enums and Constants
Reference: Pull Request #579
Changes:
- Enums Replaced with Constants:
- All enums are now constants in
@lit-protocol/constants. - Types representing keys and values are exported with
_TYPEand_VALUEsuffixes.
- All enums are now constants in
- Adjusted Network Configurations:
- Constants no longer include
localhostorinternalDev. - Use the
.Customproperty for custom networks.
- Constants no longer include
Migration Steps:
Update Enums to Constants:
- Replace old enums with new constants.
- Use corresponding types for type safety.
Specific Enum to Constant Replacements:
Old Enum/Constant New Constant WALLET_ERRORWALLET_ERROR(as a constant)LitAbilityLIT_ABILITYLitNamespaceLIT_NAMESPACELitRecapAbilityLIT_RECAP_ABILITYLitResourcePrefixLIT_RESOURCE_PREFIXAuthMethodScopeAUTH_METHOD_SCOPEAuthMethodTypeAUTH_METHOD_TYPECENTRALISATION_BY_NETWORKUse CENTRALISATION_BY_NETWORK.CustomEITHER_TYPEEITHER_TYPEGENERAL_WORKER_URL_BY_NETWORKUse GENERAL_WORKER_URL_BY_NETWORK.CustomHTTP_BY_NETWORKUse HTTP_BY_NETWORK.CustomLIT_CURVELIT_CURVELIT_ENDPOINT_VERSIONLIT_ENDPOINT_VERSIONLIT_NETWORKSUse LIT_NETWORKS.CustomLitErrorKindLIT_ERROR_KINDLitNetworkLIT_NETWORKMETAMASK_CHAIN_INFO_BY_NETWORKUse METAMASK_CHAIN_INFO_BY_NETWORK.CustomProviderTypePROVIDER_TYPERELAYER_URL_BY_NETWORKUse RELAYER_URL_BY_NETWORK.CustomRPC_URL_BY_NETWORKUse RPC_URL_BY_NETWORK.CustomStakingStatesSTAKING_STATESVMTYPEVMTYPEmetamaskChainInfoMETAMASK_CHAIN_INFOLogLevelLOG_LEVELIRelayAuthStatusRELAY_AUTH_STATUSExample of Updating Imports:
// Old import
import { LitNetwork } from '@lit-protocol/constants';
// New import
import { LIT_NETWORK, LIT_NETWORK_TYPE, LIT_NETWORK_VALUE } from '@lit-protocol/constants';Handling Custom Networks:
- For configurations no longer including
localhost, use the.Customproperty.const network = LIT_NETWORKS.Custom;
const rpcUrl = RPC_URL_BY_NETWORK.Custom;
- For configurations no longer including
Backwards Compatibility:
- Old names are temporarily available but will be removed in the future.
- Update your code to use the new constants.
Replacement of throwError Function
Reference: Pull Request #576migr
Changes:
- Error Handling:
- The
throwErrorfunction has been removed from the SDK. - Custom error classes based on
VErrorare now used throughout the SDK for error handling.
- The
- TypeScript and ESLint Improvements:
- Types across the SDK have been improved to enhance TypeScript and ESLint validations.
Migration Steps:
Error Handling with
VError:- Update your error handling logic to work with
VErrorinstances. - Errors thrown by the SDK can now be treated as
VErrors, allowing for extended error information. - Errors thrown from the SDK will all be
instanceof Error(VError extends Error), and will include a.stackproperty
- Update your error handling logic to work with
Update Error Catch Blocks:
import { VError } from '@openagenda/verror';
try {
// SDK operations
} catch (error) {
if (error instanceof VError) {
// Extract extended error information
const info = VError.info(error);
console.error('Error message:', error.message);
console.error('Error info:', info);
} else {
// Handle other errors
console.error('An unexpected error occurred:', error);
}
}Refer to Documentation:
- Check the project
README.mdor official documentation for detailed instructions on handlingVErrorinstances to obtain extended error information.
- Check the project
Removal of LitAuthClient
Reference: Pull Request #547
Changes:
- Removal of
LitAuthClient:- The
LitAuthClientclass has been removed from the SDK. - Users should now initialize providers directly.
- The
- Function Relocations:
- Static method
LitAuthClient.getAuthIdByAuthMethodis now a standalone function in@lit-protocol/lit-auth-client. - Method
mintPKPWithAuthMethodsinLitAuthClientis now a method inLitRelay.
- Static method
- Export Changes:
LitRelayis now exported from@lit-protocol/lit-auth-client.- Added
LitRelay.getRelayUrl(litNetwork: LitNetwork)static method.
- Deprecations and Additions:
- Marked
BaseProvider.fetchPKPsThroughRelayeras deprecated. - Added
BaseProvider.getPKPsForAuthMethodandBaseProvider.fetchPKPsinstance methods.
- Marked
Migration Steps:
Initializing Providers Directly:
- Old Way with
LitAuthClient:const someProvider = litAuthClient.initProvider<SomeProvider>(ProviderType.ProviderType); - New Way Without
LitAuthClient:import { LitRelay, EthWalletProvider } from '@lit-protocol/lit-auth-client';
import { LitNodeClient } from '@lit-protocol/lit-node-client';
const litNodeClient = new LitNodeClient();
await litNodeClient.connect();
const relay = new LitRelay({ litNetwork: LIT_NETWORK.MAINNET });
const ethWalletProvider = new EthWalletProvider({ relay, litNodeClient });
- Old Way with
Replacing
LitAuthClient.getAuthIdByAuthMethod:import { getAuthIdByAuthMethod } from '@lit-protocol/lit-auth-client';
const authId = getAuthIdByAuthMethod(authMethod);Minting PKPs with
LitRelay:import { LitRelay } from '@lit-protocol/lit-auth-client';
const relay = new LitRelay({ litNetwork: LIT_NETWORK.MAINNET });
relay.mintPKPWithAuthMethods(authMethods, options);Updating Provider Methods:
- Deprecated Method:
provider.fetchPKPsThroughRelayer(...); - Replacement Methods:
// Fetch PKPs directly from the blockchain
const pkps = await provider.fetchPKPs(...);
// Or get PKPs for a specific auth method
const pkps = await provider.getPKPsForAuthMethod(authMethod);
- Deprecated Method:
Using
LitRelay.getRelayUrl:import { LitRelay } from '@lit-protocol/lit-auth-client';
import { LIT_NETWORK } from '@lit-protocol/constants';
const relayUrl = LitRelay.getRelayUrl(LIT_NETWORK.MAINNET);
Removal of PKPClient
Reference: Pull Request #541
Changes:
- Removal of
PKPClient:PKPClienthas been removed from the SDK.- Previously,
PKPClientwas used to abstract different wallet types.
- Updates to
PKPWalletConnect:- Now uses
PKPEthersWalletinstead ofPKPClient, as only Ethereum wallets are supported. - Methods in
PKPWalletConnecthave been updated to reflect this change. - Improved type definitions in
PKPWalletConnect.
- Now uses
Migration Steps:
Replace Usage of
PKPClient:// Old
const pkpClient = new PKPClient(...);
// New
const pkpEthersWallet = new PKPEthersWallet(...);Update Methods in
PKPWalletConnect:Old Method New Method addPKPClientaddPKPEthersWalletfindPKPClientByRequestParamsfindPKPEthersWalletByRequestParamsgetPKPClientsgetPKPEthersWalletssetPKPClientssetPKPEthersWallets- All methods now work with
PKPEthersWalletinstances instead ofPKPClient.
- All methods now work with
Adjust Types and Interfaces:
- Update any types or interfaces that used
PKPClientto usePKPEthersWalletorPKPCosmosWallet.
- Update any types or interfaces that used
Example of Updating Code:
// Old way
const pkpWalletConnect = new PKPWalletConnect();
pkpWalletConnect.addPKPClient(pkpClient);
// New way
const pkpWalletConnect = new PKPWalletConnect();
pkpWalletConnect.addPKPEthersWallet(pkpEthersWallet);Note on Supported Wallets:
- Since only Ethereum wallets (
PKPEthersWallet) are currently supported, ensure that your implementation aligns with this.
- Since only Ethereum wallets (
Updates to PKP Wallet Classes
Reference: Pull Request #509
Changes:
- Class Structure Adjustments:
PKPBaseclass has been made final (private constructor) to prevent extension.PKPEthersWallet,PKPCosmosWallet, andPKPSuiWalletno longer extendPKPBasebut implement a shared interface.- Public interfaces of these classes have been restricted for better encapsulation.
- Initialization Changes:
litNodeClientis now a required parameter when initializing PKP wallets.- Fields to create
litNodeClientwithin PKP wallets have been removed; responsibility is delegated to the user.
- Removal of Redundant Instances:
- Removed redundant
litNodeClientinstance insideauthContext.
- Removed redundant
- Updates to
PKPClient:- Updated
PKPClientdue to changes in PKP wallet classes.
- Updated
- Type Definitions:
- Fixed several type definitions for improved type safety.
- Demo App Updates:
- Updated session signatures demo app to use all PKP wallet classes for testing signing.
Migration Steps:
- Initialize PKP Wallets with
litNodeClient:- Old Way:
const pkpEthersWallet = new PKPEthersWallet({ pkpPublicKey, controllerAuthSig }); - New Way:
import { LitNodeClient } from '@lit-protocol/lit-node-client';
const litNodeClient = new LitNodeClient();
await litNodeClient.connect();
const pkpEthersWallet = new PKPEthersWallet({
pkpPublicKey,
controllerAuthSig,
litNodeClient,
});
- Old Way:
- Adjust Class Extensions and Interfaces:
- If you extended
PKPBase, refactor your code as extendingPKPBaseis no longer supported. - Implement the shared interface if custom PKP wallet functionality is needed.
- If you extended
- Removal of
WalletFactory:- Since
WalletFactoryhas been removed, instantiate PKP wallets directly.// Old way
const pkpWallet = WalletFactory.createWallet(...);
// New way
const pkpWallet = new PKPEthersWallet({ ... });
- Since
- Update
PKPClientUsage:- If you use
PKPClient, update it to align with the new PKP wallet classes.
- If you use
- Review Type Definitions:
- Update any type definitions that may have changed due to stricter typing.
- Demo App Testing:
- If you have custom demo apps or tests, update them to use the new PKP wallet classes accordingly.
Migration of WASM Packages and Updates to Crypto Module
Reference: Pull Request #503
Changes:
- Consolidation of WASM Packages:
- Migrated the following repositories into a single
packages/wasmdirectory within the SDK:lit-bls-wasmlit-ecdsa-wasm-combinesev-snp-utils-wasm
- Migrated the following repositories into a single
- Build Process Updates:
- The
packages/wasmis now built with each run of the build pipelines. - Emits type declarations and new compiled binaries embedded into the binding wrapper.
- Reduced the size of binding + WASM to approximately 393 KB.
- The
- Cryptographic Implementations Upgrade:
- Upgraded cryptographic implementations.
- Now using the
hd-keys-curveslibrary over hand-migrated implementations for HD key derivation.
- Async Implementations in Crypto Module:
- Migrated
packages/cryptoto async implementations. - Scoped invocation of
loadModuleto lazy-load the WASM module.
- Migrated
- CI/CD Pipeline Updates:
- Updated GitHub Action jobs to use Rust toolchains for building
packages/wasm.
- Updated GitHub Action jobs to use Rust toolchains for building
Migration Steps:
- Update Imports for WASM Modules:
- Update your imports to point to the new
@lit-protocol/wasmpackage.// Old import
import { someFunction } from 'lit-bls-wasm';
// New import
import { someFunction } from '@lit-protocol/wasm';
- Update your imports to point to the new
- Handle Async Implementations in Crypto Module:
- Ensure that you await functions in the crypto module as they are now async.
// Old synchronous usage
const result = cryptoFunction(data);
// New async usage
const result = await cryptoFunction(data);
- Ensure that you await functions in the crypto module as they are now async.
- Initialization of WASM Modules:
- WASM modules now lazy-load when their functions are called. No manual initialization is required.
- Update HD Key Derivation Usage:
- Review any key derivation logic to ensure compatibility with the
hd-keys-curveslibrary.
- Review any key derivation logic to ensure compatibility with the
- Review Bundle Sizes:
- With the consolidation, your application's bundle size may be reduced.
- Testing:
- Thoroughly test cryptographic functionalities in your application.
Renaming of getRequestId Method
Reference: Latest Pull Request
Changes:
- Method Renaming:
- The method
getRequestIdhas been renamed to_getNewRequestIdto avoid confusion withgetRequestIds. - The method
_getNewRequestIdis now a protected method.
- The method
Migration Steps:
- Update Method Calls:
- If you were using
getRequestId, you need to update your code as follows:- Old Method:
const requestId = this.getRequestId(); - New Method:
- Since
_getNewRequestIdis now a protected method, it cannot be called from outside the class or subclass. - If you need a new request ID within a subclass, you can call:
const requestId = this._getNewRequestId(); - If you're outside the class and previously relied on
getRequestId, you will need to refactor your code since the method is no longer publicly accessible.
- Since
- Old Method:
- If you were using
- Avoid Misuse of Request IDs:
- The change aims to prevent consumers from generating request IDs that are not used.
- Review your code to ensure that request IDs are managed appropriately within the SDK's classes.
- Refactor Code if Necessary:
- If your code relied on obtaining a new request ID from
getRequestId, consider whether this is necessary. - The SDK likely manages request IDs internally, and external generation is probably not needed.
- If your code relied on obtaining a new request ID from
Removal of Compression Functions
Reference: Pull Request #621
Changes:
- Removed Functions from
@lit-protocol/encryption:- The following functions have been removed:
encryptZipzipAndEncryptStringzipAndEncryptFilesencryptFileAndZipWithMetadatadecryptToZipdecryptZipFileWithMetadata
- The following functions have been removed:
- Dependency Removal:
- Removed
jszipfrom the bundle to reduce the bundle size.
- Removed
Migration Steps:
- Handle Compression Yourself:
- If you are using any of the removed functions, you now need to handle compression separately.
- Removed Functions:
encryptZipzipAndEncryptStringzipAndEncryptFilesencryptFileAndZipWithMetadatadecryptToZipdecryptZipFileWithMetadata
- Removed Functions:
- If you are using any of the removed functions, you now need to handle compression separately.
- Steps to Replace Removed Functions:
- Compression:
Use a compression library like
jsziporpakodirectly in your application.Compress your data before encryption or decompress after decryption.
import { zip, unzip } from 'your-preferred-compression-library';
import { encryptUint8Array, decryptToUint8Array } from '@lit-protocol/encryption';
// Compress data
const compressedData = zip(data);
// Encrypt compressed data
const encryptedData = await encryptUint8Array({
uint8Array: compressedData,
// ...other parameters
});
// Decrypt data
const decryptedData = await decryptToUint8Array({
// ...parameters
});
// Decompress data
const originalData = unzip(decryptedData);
- Encryption:
- Use the encryption functions provided in
@lit-protocol/encryptionafter you handle compression.
- Use the encryption functions provided in
- Compression:
- Update Your Dependencies:
- Add your chosen compression library to your project's dependencies.
- Review Bundle Size:
- By managing compression separately, you can optimize your bundle size based on your application's needs.
- Testing:
- Test your compression and encryption/decryption flows thoroughly to ensure data integrity.
General Recommendations
- Review and Update All Imports:
- Ensure all your imports reference the correct packages and updated constants or functions.
- Type Safety:
- Utilize the provided
_TYPEand_VALUEtypes for enhanced type checking.
- Utilize the provided
- Avoid Deprecated References:
- Do not use old enums, classes, methods, or duplicated exports to benefit from reduced bundle sizes and future compatibility.
- Error Handling:
- Update your error handling to accommodate the new custom error classes based on
VError.
- Update your error handling to accommodate the new custom error classes based on
- Async Adjustments:
- Update your code to handle async functions, especially in the crypto module.
- Compression Handling:
- Manage compression independently using a library that suits your needs.
- Testing:
- Thoroughly test your application after making these changes to ensure everything functions as expected.
Summary
By following this migration guide, you will align your codebase with the latest updates to the Lit Protocol SDK, ensuring better modularity, type safety, enhanced error handling, and reduced bundle sizes. The updates simplify provider and wallet initialization, improve cryptographic implementations, enforce better encapsulation and method usage, and give you control over compression handling.
Note: While backward compatibility is temporarily maintained for some constants and functions, it is advisable to update your code promptly to use the new constants, functions, and error handling mechanisms to prevent future breaking changes.