-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNative-Segwit_Multi-Sig.ts
More file actions
35 lines (32 loc) · 937 Bytes
/
Native-Segwit_Multi-Sig.ts
File metadata and controls
35 lines (32 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as bitcoin from "bitcoinjs-lib";
const network = bitcoin.networks.testnet; // Otherwise, bitcoin = mainnet and regnet = local
export async function createNativeSegwit(
originPubkeys: string[], // Singer pubkeys list
threshold: number // Number of Co-Signers
) {
try {
const hexedPubkeys = originPubkeys.map((pubkey) =>
Buffer.from(pubkey, "hex")
);
const p2ms = bitcoin.payments.p2ms({
m: parseInt(threshold.toString()),
pubkeys: hexedPubkeys,
network,
});
const p2wsh = bitcoin.payments.p2wsh({ redeem: p2ms, network });
return {
success: true,
message: "Create Musig Wallet successfully.",
payload: {
address: p2wsh.address,
},
};
} catch (error: any) {
console.log("error in creating segwit address ==> ", error);
return {
success: false,
message: "There is something error",
payload: null,
};
}
}