Skip to content

feat:implement createMultiSigAddrwss for P2SH and P2SH-P2WSH - #32

Open
RiH-137 wants to merge 2 commits into
Swapso-App:dev-branchfrom
RiH-137:feat/multisig-p2sh
Open

feat:implement createMultiSigAddrwss for P2SH and P2SH-P2WSH#32
RiH-137 wants to merge 2 commits into
Swapso-App:dev-branchfrom
RiH-137:feat/multisig-p2sh

Conversation

@RiH-137

@RiH-137 RiH-137 commented Mar 19, 2026

Copy link
Copy Markdown

Multisig Address Support Update

What Changed

  • Implemented createMultiSigAddress utility for:
    • Legacy P2SH
    • Nested SegWit P2SH-P2WSH multisig address generation
  • Added input validation for:
    • P2SH
    • P2SH-P2WSH
  • Exported the new utility via the helper utils index

Tests Added

  • Unit tests covering:
    • Correct P2SH address generation
    • Correct P2SH-P2WSH address generation
    • Validation failure when required signatures exceed public key count

Validation

  • Ran full btc-controller test suite
  • ✅ Result: All tests passing, including new multisig tests

Copilot AI review requested due to automatic review settings March 19, 2026 14:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new multisig address generation utility to btc-controller and exposes it through the helper utils barrel export, alongside unit tests for legacy (P2SH) and nested SegWit (P2SH-P2WSH) flows.

Changes:

  • Added createMultiSigAddress utility with support for P2SH and P2SH-P2WSH (and currently also includes a P2WSH branch).
  • Added input validation (e.g., requiredSignatures <= publicKeys.length) and returns relevant scripts.
  • Added Mocha unit tests for P2SH and P2SH-P2WSH address generation and a validation failure case.

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
btc-controller/test/createMultiSigAddress.js Adds unit tests for P2SH and P2SH-P2WSH multisig address generation and basic validation.
btc-controller/src/helper/utils/createMultiSigAddress.ts Implements multisig address creation and returns scripts for spending (redeem/witness).
btc-controller/src/helper/utils/createMultiSigAddress.js Compiled JS output for the new multisig utility.
btc-controller/src/helper/utils/createMultiSigAddress.d.ts Type declarations for the new multisig utility.
btc-controller/src/helper/utils/index.ts Exports createMultiSigAddress from the utils barrel.
btc-controller/src/helper/utils/index.js Updates compiled barrel exports (but inline source map appears stale).
btc-controller/src/helper/utils/index.d.ts Updates type declarations barrel export to include createMultiSigAddress.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +13 to 14
Object.defineProperty(exports, "createMultiSigAddress", { enumerable: true, get: function () { return createMultiSigAddress_1.createMultiSigAddress; } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSw2Q0FBMEM7QUFLakMsMkZBTEEsdUJBQVUsT0FLQTtBQUpuQix1REFBb0Q7QUFJL0IsZ0dBSlosaUNBQWUsT0FJWTtBQUhwQyxtRUFBZ0U7QUFHMUIsc0dBSDdCLDZDQUFxQixPQUc2QjtBQUYzRCx5REFBc0Q7QUFFTyxpR0FGcEQsbUNBQWdCLE9BRW9EIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgZ2V0TmV0d29yayB9IGZyb20gXCIuL2dldE5ldHdvcmtcIjtcclxuaW1wb3J0IHsgZ2VuZXJhdGVBZGRyZXNzIH0gZnJvbSBcIi4vZ2VuZXJhdGVBZGRyZXNzXCI7XHJcbmltcG9ydCB7IGNhbGNCaXAzMkV4dGVuZGVkS2V5cyB9IGZyb20gXCIuL2NhbGNCaXAzMkV4dGVuZGVkS2V5c1wiO1xyXG5pbXBvcnQgeyBnZXRBZGRyZXNzRnJvbVBrIH0gZnJvbSBcIi4vZ2V0QWRkcmVzc0Zyb21Qa1wiO1xyXG5cclxuZXhwb3J0IHsgZ2V0TmV0d29yaywgZ2VuZXJhdGVBZGRyZXNzLCBjYWxjQmlwMzJFeHRlbmRlZEtleXMsIGdldEFkZHJlc3NGcm9tUGsgfTtcclxuIl19 No newline at end of file
Comment on lines +8 to +12
getNetwork,
generateAddress,
calcBip32ExtendedKeys,
getAddressFromPk,
createMultiSigAddress,
Comment on lines +30 to +35
if (typeof publicKey === "string") {
return Buffer.from(publicKey, "hex");
}

throw new Error("Invalid public key format.");
}
@@ -0,0 +1,124 @@
import * as bitcoinjs from "bitcoinjs-lib";

export type MultiSigAddressType = "P2SH" | "P2SH-P2WSH" | "P2WSH";
Comment on lines +106 to +120
if (type === "P2WSH") {
const p2wsh = bitcoinjs.payments.p2wsh({
redeem: p2ms,
network,
});

if (!p2wsh.address) {
throw new Error("Failed to generate P2WSH multisig address.");
}

return {
type,
address: p2wsh.address,
witnessScript: p2ms.output.toString("hex"),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants