MPC Authenticator JS library
Getting started
Install the SDK:
npm i --save @silencelaboratories/universal-mpc-auth
Overview:
The library provides the following 2 main components:
- MpcAuthenticator
- MpcSigner
MpcAuthenticator
The MpcAuthenticator
class is designed to handle authentication processes using MPC SDK for {2,2} TSS.
import {
MpcAuthenticator,
StoragePlatform,
WalletId,
} from "@silencelaboratories/universal-mpc-auth";
const storage = new CliStorage();
const mpcAuth = MpcAuthenticator.instance({
walletId: WalletId.Biconomy,
storagePlatform: StoragePlatform.CLI,
customStorage: storage,
isDev: process.env.NEXT_PUBLIC_SDK_MODE === "development",
});
const qrCode = await mpcAuth.initPairing();
const pairingSessionData = await mpcAuth.runStartPairingSession();
await mpcAuth.runEndPairingSession(pairingSessionData);
const keygenResult = await mpcAuth.runKeygen();
await mpcAuth.runBackup("demopassword");
MpcAuthenticator options
walletId
- Supported Wallet ID to use for identifying the wallet. Check WalletId
enum for available options.
storagePlatform
- Supported Storage platform to use for storing keyshares and pairing data. Check StoragePlatform
enum for available options.
customStorage
- Custom storage object to use for storing keyshares and pairing data. If not provided, the library will use the default storage, which is localStorage
(assuming the library is used in the browser).
isDev
- Development mode flag. If set to true
, the library will use the development mode for the MPC SDK.
Custom Storage
The library provides a way to use custom storage for data storing. The custom storage must implement IStorage
interface, MpcAuthenticator
will access the storage using the provided methods.
interface IStorage {
clearStorageData: () => Promise<void>;
setStorageData: (data: StorageData) => Promise<void>;
getStorageData: () => Promise<StorageData>;
migrate?(): void;
}
MpcSigner
The MpcSigner
class is designed for signing Ethereum transactions and messages using MpcAuthenticator
keyshares.
An example of MpcSigner
with Biconomy
account creation:
const provider = new providers.JsonRpcProvider("https://rpc.sepolia.org");
const mpcSigner = await MpcSigner.instance(mpcAuth, provider);
const biconomySmartAccount = await createSmartAccountClient({
signer: client as SupportedSigner,
bundlerUrl: `https://bundler.biconomy.io/api/v2/11155111/${process.env.API_KEY}`,
});
ViemSigner
The ViemSigner
class is designed to facilitate signing Ethereum transactions and messages using a MpcAuthenticator for key management. This signer integrates with the viem library to provide a seamless signing experience.
An example of ViemSigner
with Pimlico
account creation:
const client = await ViemSigner.instance(mpcAuth);
const signer = await client.getViemAccount();
const walletClient = createWalletClient({
account: signer,
chain: sepolia,
transport: http(
`https://rpc.zerodev.app/api/v2/bundler/${process.env.API_KEY}`
),
});
const smartAccountSigner = walletClientToSmartAccountSigner(walletClient);
Error codes
The library provides the following error codes:
enum BaseErrorCode {
StorageWriteFailed = 1,
StorageFetchFailed = 2,
HttpError = 3,
PairingFailed = 4,
KeygenFailed = 5,
BackupFailed = 6,
SignFailed = 7,
RecoverFailed = 8,
KeygenResourceBusy = 9,
SignResourceBusy = 10,
InternalLibError = 11,
PhoneDenied = 12,
InvalidBackupData = 13,
InvalidMessageHashLength = 14,
WalletNotCreated = 15,
UnknownError = 16,
}