npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pier-wallet/mpc-lib

v0.10.9

Published

The Pier Multi-Party Computation (MPC) Wallet SDK allows you to create and manage wallets that leverage multi-party computation protocols for enhanced security and privacy. This documentation provides an overview of the API and its components to help you

Downloads

245

Readme

Pier Multi-Party Computation (MPC) Wallet

The Pier Multi-Party Computation (MPC) Wallet SDK allows you to create and manage wallets that leverage multi-party computation protocols for enhanced security and privacy. This documentation provides an overview of the API and its components to help you integrate and utilize the SDK effectively.

Installation

To use the MPC Wallet SDK, you need to install it as a dependency in your project. You can use npm or yarn to install the required packages.

npm install @pier-wallet/mpc-lib

Usage

Initializing the SDK

import { createPierMpcSdkWasm } from "@pier-wallet/mpc-lib/wasm";

const pierMpcSdk = createPierMpcSdkWasm();

Creating a wallet

This section shows how to create a 2/2 MPC Ethereum wallet. Bitcoin wallet generation is exactly the same but uses a different class to instantiate the wallet.

To create an MPC wallet, you need to establish a connection with other parties. On the first computer, create a session for key generation using the establishConnection method. You can use the SessionKind.KEYGEN constant to specify the session type.

import { SessionKind } from "@pier-wallet/mpc-lib";

// PARTY 1
const party1Connection = await pierMpcSdk.establishConnection(
  SessionKind.KEYGEN,
  {
    type: "create",
    partiesParameters: {
      requiredPartiesToSign: 2,
      totalParties: 2,
    },
  },
);
// share this ID with the second party
console.log(party1Connection.sessionId);

On the second computer, join the session using establishConnection method, passing the session ID from the first party.

// PARTY 2
const sessionId = getSessionIdFromTheFirstParty();
const party2Connection = await pierMpcSdk.establishConnection(
  SessionKind.KEYGEN,
  {
    type: "join",
    sessionId,
  },
);

Once the connection is established, you can generate a key share for the wallet using the generateKeyShare method. On both parties, you can use the same code to generate a key share.

// PARTY 1
const party1KeyShare = await pierMpcSdk.generateKeyShare(party1Connection);
console.log(
  "Wallet Address:",
  ethers.utils.computeAddress(party1KeyShare.publicKey),
);
// PARTY 2
const party2KeyShare = await pierMpcSdk.generateKeyShare(party2Connection);
console.log(
  "Wallet Address:",
  ethers.utils.computeAddress(party2KeyShare.publicKey),
);

Addresses of party1KeyShare and party2KeyShare will be the same.

Store key share

When key share is generated, you can store it in a secure storage. Use .raw() method to get key share in JSON serializable format.

saveKeyShareToSecureStorage(JSON.stringify(party1KeyShare.raw()));

Instantiate an Ethereum wallet from a key share

Use PierMpcEthereumWallet to instantiate an Ethereum wallet from a key share. PierMpcEthereumWallet implements ethers.js Signer interface. You need to create and join a session in the same way as you did for key share generation except you pass SessionKind.SIGN as a parameter.

import { KeyShare } from "@pier-wallet/mpc-lib";
import { PierMpcEthereumWallet } from "@pier-wallet/mpc-lib/ethers-v5";

// PARTY 1
const party1KeyShare = new KeyShare(
  JSON.parse(loadKeyShareFromSecureStorage()),
);
const party1Connection = await pierMpcSdk.establishConnection(
  SessionKind.SIGN,
  {
    type: "create",
    partiesParameters: party1KeyShare.partiesParameters,
  },
);
const wallet = new PierMpcEthereumWallet(
  party1KeyShare,
  party1Connection,
  pierMpcSdk,
);
console.log("wallet address", wallet.address);
// PARTY 2
const party2KeyShare = new KeyShare(
  JSON.parse(loadKeyShareFromSecureStorage()),
);
const party2Connection = await pierMpcSdk.establishConnection(
  SessionKind.SIGN,
  {
    type: "join",
    sessionId: getSessionIdFromTheFirstParty(),
  },
);
const wallet = new PierMpcEthereumWallet(
  party2KeyShare,
  party2Connection,
  pierMpcSdk,
);
console.log("wallet address", wallet.address);

Getting wallet address

You can retrieve the Ethereum wallet address using the getAddress method or address property.

const walletAddress = await wallet.getAddress();
const walletAddress = wallet.address;

Signing a message

To sign a digest using Pier MPC wallet, you can use the signMessage method. You need to run signMessage on at least requiredPartiesToSign parties (2 in our case) for it to generate a signature.

// PARTY 1 and PARTY 2
const message = "hello world";
const signature = await wallet.signMessage(message);

// these two addresses will be the same
console.log(
  await wallet.getAddress(),
  ethers.utils.verifyMessage(message, signature),
);