feat:implement createMultiSigAddrwss for P2SH and P2SH-P2WSH - #32
Open
RiH-137 wants to merge 2 commits into
Open
feat:implement createMultiSigAddrwss for P2SH and P2SH-P2WSH#32RiH-137 wants to merge 2 commits into
RiH-137 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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
createMultiSigAddressutility 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"), | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Multisig Address Support Update
What Changed
createMultiSigAddressutility for:Tests Added
Validation
btc-controllertest suite