0.10.7 • Published 2 months ago

@pier-wallet/mpc-lib v0.10.7

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
2 months ago

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),
);
0.10.7

2 months ago

0.10.6

2 months ago

0.10.5

2 months ago

0.10.4-stores.2

3 months ago

0.10.4

3 months ago

0.10.4-stores.1

3 months ago

0.10.4-jwt.1

4 months ago

0.10.4-jwt.0

4 months ago

0.10.1

4 months ago

0.10.2

4 months ago

0.10.3

4 months ago

0.10.4-stores.0

4 months ago

0.10.0

4 months ago

0.9.0-stores.6

4 months ago

0.9.0-stores.7

4 months ago

0.9.0-stores.5

4 months ago

0.9.0-stores.2

4 months ago

0.9.0-stores.3

4 months ago

0.9.0-stores.1

4 months ago

0.9.0-stores.4

4 months ago

0.8.3-stores.5

4 months ago

0.8.3-stores.4

4 months ago

0.8.3-stores.3

4 months ago

0.8.3-stores.2

4 months ago

0.9.0

4 months ago

0.9.0-stores.0

4 months ago

0.8.3-stores.1

4 months ago

0.8.3-stores.0

4 months ago

0.8.2

5 months ago

0.8.2-ts.0

5 months ago

0.8.1

5 months ago

0.8.0

5 months ago

0.7.2

5 months ago

0.7.1

5 months ago

0.7.0

5 months ago

0.6.14

6 months ago

0.6.13

6 months ago

0.6.12

6 months ago

0.6.11

6 months ago

0.6.10

6 months ago

0.6.9

6 months ago

0.6.8

6 months ago

0.6.7

6 months ago

0.6.7-android.0

6 months ago

0.6.6

6 months ago

0.6.5

6 months ago

0.6.4

6 months ago

0.6.3

6 months ago

0.6.2

6 months ago

0.6.1

6 months ago

0.6.0

6 months ago

0.5.7

6 months ago

0.5.6

6 months ago

0.5.5

6 months ago

0.5.4

6 months ago

0.5.3

6 months ago

0.5.2

6 months ago

0.5.1

6 months ago

0.5.0

6 months ago

0.4.0

6 months ago

0.4.0-alpha.3

6 months ago

0.4.0-alpha.2

6 months ago

0.4.0-alpha.1

6 months ago

0.3.5

6 months ago

0.3.4

6 months ago

0.3.3

6 months ago

0.3.2

6 months ago

0.3.1

6 months ago

0.3.1-bitcore.0

6 months ago

0.3.0

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.1.0

6 months ago

0.0.17-bitcoin.5

6 months ago

0.0.17-bitcoin.4

6 months ago

0.0.17-bitcoin.3

6 months ago

0.0.17-bitcoin.2

6 months ago

0.0.17-bitcoin.1

6 months ago

0.0.17-bitcoin.0

6 months ago

0.0.16-auth.5

7 months ago

0.0.16-auth.4

7 months ago

0.0.16-auth.3

7 months ago

0.0.16-auth.2

7 months ago

0.0.16-auth.1

7 months ago

0.0.16-auth.0

7 months ago

0.0.15

7 months ago

0.0.14-webview.16

7 months ago

0.0.14-webview.15

7 months ago

0.0.14-webview.14

7 months ago

0.0.14-webview.13

7 months ago

0.0.14-webview.12

7 months ago

0.0.14-webview.11

7 months ago

0.0.14-webview.10

7 months ago

0.0.14-webview.9

7 months ago

0.0.14-webview.8

7 months ago

0.0.14-webview.7

7 months ago

0.0.14-webview.6

7 months ago

0.0.14-webview.4

7 months ago

0.0.14-webview.3

7 months ago

0.0.14-webview.2

7 months ago

0.0.14-webview.1

7 months ago

0.0.14-webview.0

7 months ago

0.0.14-webview

7 months ago

0.0.13

7 months ago

0.0.12-cjs.4

7 months ago

0.0.12-cjs.3

7 months ago

0.0.12-cjs.2

7 months ago

0.0.12-cjs.1

7 months ago

0.0.12-cjs.0

7 months ago

0.0.12

7 months ago

0.0.12-transport.0

7 months ago

0.0.11

7 months ago

0.0.9

8 months ago

0.0.8

8 months ago

0.0.7

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago