Skip to content

Commit 7212b4a

Browse files
committed
updates
1 parent b27b44a commit 7212b4a

File tree

1 file changed

+33
-48
lines changed

1 file changed

+33
-48
lines changed

src/pages/guides/bitcoin-taproot-mpc.mdx

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,22 @@ started. Let’s dive in!
3434
[instructions on setting up the Web3Auth Dashboard](/docs/dashboard-setup).
3535
- Web3Auth MPC CoreKit SDK: This guide assumes that you already know how to integrate the MPC
3636
CoreKit SDK in your project and able to set up the login flow. If not, you can learn how to
37-
[integrate Web3Auth in your web app](/docs/sdk/mpc-core-kit/mpc-core-kit-js).
37+
[integrate Web3Auth MPC Core Kit SDK in your web app](/docs/sdk/mpc-core-kit/mpc-core-kit-js).
38+
39+
## TLDR;
40+
41+
- **Web3Auth MPC CoreKit**: Initialize the CoreKit instance and set up the login flow.
42+
- **Bitcoin Signer**: Create a BitcoinJS-compatible signer for BIP340 Schnorr signatures.
43+
- **Bitcoin Operations**: Implement Bitcoin-specific operations like address generation and
44+
transaction signing.
45+
- **Usage Guide**: Learn how to use the application to interact with Bitcoin Taproot.
46+
47+
Get a clone of the [example repository](https://github.com/Web3Auth/web3auth-core-kit-examples/mpc-core-kit-web/mpc-core-kit-bitcoin-taproot) to follow along with the guide.
3848

3949
## Initialization
4050

41-
Before interacting with Web3Auth MPC CoreKit, we need to initialize it. This is done in the App.tsx
42-
file, where we configure the CoreKit instance with the necessary parameters.
51+
Before interacting with Web3Auth MPC CoreKit, we need to initialize it. This is done in the
52+
`App.tsx` file, where we configure the CoreKit instance with the necessary parameters.
4353

4454
### Setting Up Web3Auth MPC CoreKit
4555

@@ -53,22 +63,23 @@ import { tssLibFrostBip340 } from "@toruslabs/tss-frost-lib-bip340";
5363
let coreKitInstance: Web3AuthMPCCoreKit;
5464
if (typeof window !== "undefined") {
5565
coreKitInstance = new Web3AuthMPCCoreKit({
56-
web3AuthClientId, // Your Web3Auth Client ID
57-
web3AuthNetwork: WEB3AUTH_NETWORK.DEVNET, // Connects to Web3Auth's DEVNET environment
66+
web3AuthClientId, // Your Web3Auth Client ID, get it from the Web3Auth dashboard
67+
web3AuthNetwork: WEB3AUTH_NETWORK.DEVNET, // Web3Auth's DEVNET environment
5868
storage: window.localStorage, // Uses localStorage for persisting user session
5969
manualSync: true, // Requires manual syncing of key shares
6070
tssLib: tssLibFrostBip340, // Uses Frost-BIP340 for threshold signature scheme (TSS)
6171
});
6272
}
6373
```
6474

65-
Here’s what each parameter does:
75+
The parameters for initializing the Web3Auth MPC CoreKit instance are as follows:
6676

67-
* web3AuthClientId – Your unique Web3Auth Client ID.
68-
* web3AuthNetwork – Specifies the Web3Auth network (DEVNET in this case).
69-
* storage – Determines where session data is stored; here, we use localStorage.
70-
* manualSync – Enables manual synchronization of key shares for added control.
71-
* tssLibFrostBip340 – Defines the threshold signature scheme (TSS) library, in this case, Frost-BIP340, which is optimized for Bitcoin Taproot.
77+
- `web3AuthClientId` is your unique Web3Auth Client ID,
78+
- `web3AuthNetwork` specifies the Web3Auth network (DEVNET in this case),
79+
- `storage` determines where session data is stored (using localStorage here),
80+
- `manualSync` enables manual synchronization of key shares for added control, and
81+
- `tssLibFrostBip340` defines the threshold signature scheme (TSS) library, specifically
82+
Frost-BIP340, optimized for Bitcoin Taproot.
7283

7384
### Initializing the CoreKit Instance
7485

@@ -86,18 +97,12 @@ useEffect(() => {
8697
}, []);
8798
```
8899

89-
Here’s how it works:
90-
91-
* setIsLoading(true) – Sets a loading state while initialization is in progress.
92-
* coreKitInstance.init() – Calls the initialization method, which connects CoreKit to Web3Auth.
93-
* setCoreKitStatus(coreKitInstance.status) – Stores the current status of CoreKit after initialization.
94-
* setIsLoading(false) – Removes the loading state once the process is complete.
95-
96100
## Authentication
97101

98102
The project uses Firebase for authentication, allowing users to log in securely using their Google
99-
accounts. The login function, implemented in App.tsx, handles this authentication flow and
100-
integrates with Web3Auth MPC CoreKit.
103+
accounts. You can choose any authentication provider that suits your needs, but for this example, we
104+
using Firebase for its ease of integration. The login function, implemented in `App.tsx`, handles
105+
this authentication flow and integrates with Web3Auth MPC CoreKit.
101106

102107
### Logging in with Google
103108

@@ -186,19 +191,17 @@ export const signInWithGoogle = async (): Promise<UserCredential> => {
186191
</TabItem>
187192
</Tabs>
188193

189-
Explanation
194+
The login function performs the following steps:
190195

191-
1. Check CoreKit Instance – Ensures coreKitInstance is initialized before proceeding.
196+
1. Checks the CoreKit Instance – Ensures coreKitInstance is initialized before proceeding.
192197
2. Sign in with Google – Calls signInWithGoogle() to authenticate the user via Firebase.
193-
3. Retrieve ID Token – After login, the Firebase ID token is fetched for authentication.
194-
4. Parse Token – Decodes the ID token to extract user information, including the sub field (a unique user identifier).
195-
5. Authenticate with Web3Auth – Calls loginWithJWT(), passing the Firebase ID token to Web3Auth for authentication.
198+
3. Retrieve ID Token – After login, the Firebase ID token is fetched.
199+
4. Parse Token – Decodes the ID token to extract user information, including the sub field (a unique user identifier) used during login with Web3Auth.
200+
5. Authenticate with Web3Auth – Calls loginWithJWT(), passing the Firebase ID token(JWT) to Web3Auth for authentication.
196201
6. Commit Changes (If Needed) – If the user is logging in for the first time, commitChanges() ensures key shares are properly stored.
197202
7. Handle Recovery (If Needed) – If Web3Auth requires additional shares to reconstruct the key, the UI prompts the user for recovery options.
198203
8. Update Application State – The current CoreKit status is stored for UI updates.
199204

200-
Here’s the explanation in the style of your reference:
201-
202205
## Bitcoin Signer
203206

204207
To enable Bitcoin Taproot signing with Web3Auth MPC CoreKit, we need to create a
@@ -246,7 +249,7 @@ export function createBitcoinJsSignerBip340(props: { coreKitInstance: Web3AuthMP
246249
}
247250
```
248251

249-
### Explanation
252+
The createBitcoinJsSignerBip340 function performs the following steps:
250253

251254
1️⃣ Import Required Libraries
252255

@@ -312,16 +315,9 @@ return {
312315

313316
* The signer returns the tweaked Taproot public key and the associated Bitcoin network configuration.
314317

315-
Summary
316-
317-
- This function derives a Taproot-compatible public key using Web3Auth MPC CoreKit.
318-
- It implements both standard and Schnorr signing for Bitcoin transactions.
319-
- The returned object integrates seamlessly with bitcoinjs-lib, making it easy to use in Bitcoin
320-
applications.
321-
322318
## Bitcoin Operations
323319

324-
The BitcoinComponent.tsx file implements Bitcoin-specific operations, allowing users to:
320+
The `BitcoinComponent.tsx` file implements Bitcoin-specific operations, allowing users to:
325321

326322
- showAddress – Display the Taproot (BIP340) Bitcoin address.
327323
- showBalance – Fetch and display the balance for the generated Bitcoin address.
@@ -331,8 +327,6 @@ The BitcoinComponent.tsx file implements Bitcoin-specific operations, allowing u
331327
This component integrates BitcoinJS (bitcoinjs-lib), Schnorr signatures (@bitcoinerlab/secp256k1),
332328
and Web3Auth MPC for Taproot-compatible signing.
333329

334-
Code Implementation
335-
336330
```js
337331
import { Web3AuthMPCCoreKit } from "@web3auth/mpc-core-kit";
338332
import { useEffect, useState } from "react";
@@ -342,11 +336,9 @@ import * as bitcoinjs from "bitcoinjs-lib";
342336
import { createBitcoinJsSignerBip340 } from "./BitcoinSigner";
343337
import axios from "axios";
344338
import { BlurredLoading } from "./Loading";
345-
346-
bitcoinjs.initEccLib(ecc);
347339
```
348340

349-
### Explanation
341+
The BitcoinComponent.tsx file imports the necessary libraries and components for Bitcoin operations:
350342

351343
1️⃣ Dependencies and Libraries
352344

@@ -554,13 +546,6 @@ const showBalance = async () => {
554546
</button>
555547
```
556548

557-
Summary
558-
559-
- Derives a Taproot-compatible address using MPC-based signing.
560-
- Fetches UTXOs and balance via Blockstream API.
561-
- Signs transactions with Schnorr signatures (BIP340).
562-
- Broadcasts transactions using a centralized testnet API (for now).
563-
564549
## Usage Guide
565550

566551
1. **Login**: Click the "Login" button to authenticate using Firebase.

0 commit comments

Comments
 (0)