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
encryptUint8Array
anddecryptToUint8Array
in@lit-protocol/encryption
for handlingUint8Array
data types. - These functions unify encryption and decryption interfaces within the
@lit-protocol/encryption
package.
- Added
- Function Relocations:
- The following have been moved from
@lit-protocol/encryption
to@lit-protocol/misc
:isTokenOperator
isValidBooleanExpression
safeParams
AccessControlConditionsValidatorProps
AuthMaterialValidatorProps
ParamsValidatorsType
- The following have been moved from
- Export Changes:
- Removed re-exports of
@lit-protocol/encryption
functions in@lit-protocol/lit-node-client-nodejs
.
- Removed re-exports of
Migration Steps:
- Encrypting and Decrypting
Uint8Array
:- Replace usage of
encrypt
anddecrypt
functions inLitNodeClient
withencryptUint8Array
anddecryptToUint8Array
from@lit-protocol/encryption
.import { encryptUint8Array, decryptToUint8Array } from '@lit-protocol/encryption';
- Replace usage of
- String and File Encryption/Decryption:
- Functions like
encryptString
,encryptFile
,decryptString
, anddecryptFile
are no longer exported from@lit-protocol/lit-node-client-nodejs
or@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
_TYPE
and_VALUE
suffixes.
- All enums are now constants in
- Adjusted Network Configurations:
- Constants no longer include
localhost
orinternalDev
. - Use the
.Custom
property 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_ERROR
WALLET_ERROR
(as a constant)LitAbility
LIT_ABILITY
LitNamespace
LIT_NAMESPACE
LitRecapAbility
LIT_RECAP_ABILITY
LitResourcePrefix
LIT_RESOURCE_PREFIX
AuthMethodScope
AUTH_METHOD_SCOPE
AuthMethodType
AUTH_METHOD_TYPE
CENTRALISATION_BY_NETWORK
Use CENTRALISATION_BY_NETWORK.Custom
EITHER_TYPE
EITHER_TYPE
GENERAL_WORKER_URL_BY_NETWORK
Use GENERAL_WORKER_URL_BY_NETWORK.Custom
HTTP_BY_NETWORK
Use HTTP_BY_NETWORK.Custom
LIT_CURVE
LIT_CURVE
LIT_ENDPOINT_VERSION
LIT_ENDPOINT_VERSION
LIT_NETWORKS
Use LIT_NETWORKS.Custom
LitErrorKind
LIT_ERROR_KIND
LitNetwork
LIT_NETWORK
METAMASK_CHAIN_INFO_BY_NETWORK
Use METAMASK_CHAIN_INFO_BY_NETWORK.Custom
ProviderType
PROVIDER_TYPE
RELAYER_URL_BY_NETWORK
Use RELAYER_URL_BY_NETWORK.Custom
RPC_URL_BY_NETWORK
Use RPC_URL_BY_NETWORK.Custom
StakingStates
STAKING_STATES
VMTYPE
VMTYPE
metamaskChainInfo
METAMASK_CHAIN_INFO
LogLevel
LOG_LEVEL
IRelayAuthStatus
RELAY_AUTH_STATUS
Example 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.Custom
property.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
throwError
function has been removed from the SDK. - Custom error classes based on
VError
are 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
VError
instances. - Errors thrown by the SDK can now be treated as
VError
s, allowing for extended error information. - Errors thrown from the SDK will all be
instanceof Error
(VError extends Error), and will include a.stack
property
- 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.md
or official documentation for detailed instructions on handlingVError
instances to obtain extended error information.
- Check the project
Removal of LitAuthClient
Reference: Pull Request #547
Changes:
- Removal of
LitAuthClient
:- The
LitAuthClient
class has been removed from the SDK. - Users should now initialize providers directly.
- The
- Function Relocations:
- Static method
LitAuthClient.getAuthIdByAuthMethod
is now a standalone function in@lit-protocol/lit-auth-client
. - Method
mintPKPWithAuthMethods
inLitAuthClient
is now a method inLitRelay
.
- Static method
- Export Changes:
LitRelay
is now exported from@lit-protocol/lit-auth-client
.- Added
LitRelay.getRelayUrl(litNetwork: LitNetwork)
static method.
- Deprecations and Additions:
- Marked
BaseProvider.fetchPKPsThroughRelayer
as deprecated. - Added
BaseProvider.getPKPsForAuthMethod
andBaseProvider.fetchPKPs
instance 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
:PKPClient
has been removed from the SDK.- Previously,
PKPClient
was used to abstract different wallet types.
- Updates to
PKPWalletConnect
:- Now uses
PKPEthersWallet
instead ofPKPClient
, as only Ethereum wallets are supported. - Methods in
PKPWalletConnect
have 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 addPKPClient
addPKPEthersWallet
findPKPClientByRequestParams
findPKPEthersWalletByRequestParams
getPKPClients
getPKPEthersWallets
setPKPClients
setPKPEthersWallets
- All methods now work with
PKPEthersWallet
instances instead ofPKPClient
.
- All methods now work with
Adjust Types and Interfaces:
- Update any types or interfaces that used
PKPClient
to usePKPEthersWallet
orPKPCosmosWallet
.
- 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:
PKPBase
class has been made final (private constructor) to prevent extension.PKPEthersWallet
,PKPCosmosWallet
, andPKPSuiWallet
no longer extendPKPBase
but implement a shared interface.- Public interfaces of these classes have been restricted for better encapsulation.
- Initialization Changes:
litNodeClient
is now a required parameter when initializing PKP wallets.- Fields to create
litNodeClient
within PKP wallets have been removed; responsibility is delegated to the user.
- Removal of Redundant Instances:
- Removed redundant
litNodeClient
instance insideauthContext
.
- Removed redundant
- Updates to
PKPClient
:- Updated
PKPClient
due 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 extendingPKPBase
is no longer supported. - Implement the shared interface if custom PKP wallet functionality is needed.
- If you extended
- Removal of
WalletFactory
:- Since
WalletFactory
has been removed, instantiate PKP wallets directly.// Old way
const pkpWallet = WalletFactory.createWallet(...);
// New way
const pkpWallet = new PKPEthersWallet({ ... });
- Since
- Update
PKPClient
Usage:- 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/wasm
directory within the SDK:lit-bls-wasm
lit-ecdsa-wasm-combine
sev-snp-utils-wasm
- Migrated the following repositories into a single
- Build Process Updates:
- The
packages/wasm
is 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-curves
library over hand-migrated implementations for HD key derivation.
- Async Implementations in Crypto Module:
- Migrated
packages/crypto
to async implementations. - Scoped invocation of
loadModule
to 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/wasm
package.// 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-curves
library.
- 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
getRequestId
has been renamed to_getNewRequestId
to avoid confusion withgetRequestIds
. - The method
_getNewRequestId
is 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
_getNewRequestId
is 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:
encryptZip
zipAndEncryptString
zipAndEncryptFiles
encryptFileAndZipWithMetadata
decryptToZip
decryptZipFileWithMetadata
- The following functions have been removed:
- Dependency Removal:
- Removed
jszip
from 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:
encryptZip
zipAndEncryptString
zipAndEncryptFiles
encryptFileAndZipWithMetadata
decryptToZip
decryptZipFileWithMetadata
- 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
jszip
orpako
directly 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/encryption
after 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
_TYPE
and_VALUE
types 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.