{"id":24909132,"url":"https://github.com/wangshouh/musig","last_synced_at":"2025-09-23T19:45:32.376Z","repository":{"id":44478004,"uuid":"512725727","full_name":"wangshouh/musig","owner":"wangshouh","description":"A simple Typescript package for multi-signature.","archived":false,"fork":false,"pushed_at":"2022-07-14T10:11:09.000Z","size":67,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T02:35:44.214Z","etag":null,"topics":["bip-0340","multisig","musig","schnorr","schnorr-signatures","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wangshouh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-11T11:17:52.000Z","updated_at":"2024-03-22T04:14:52.000Z","dependencies_parsed_at":"2022-09-15T18:21:41.429Z","dependency_job_id":null,"html_url":"https://github.com/wangshouh/musig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangshouh%2Fmusig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangshouh%2Fmusig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangshouh%2Fmusig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangshouh%2Fmusig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wangshouh","download_url":"https://codeload.github.com/wangshouh/musig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245949561,"owners_count":20698920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bip-0340","multisig","musig","schnorr","schnorr-signatures","typescript"],"created_at":"2025-02-02T02:35:48.997Z","updated_at":"2025-09-23T19:45:27.326Z","avatar_url":"https://github.com/wangshouh.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typescript Musig\n\n## Introduction\n\nThe project is based on schnorr signatures to implement the multi-signature part of [BIP-0340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#Multisignatures_and_Threshold_Signatures), using the specific algorithm **musig**.The implementation of the algorithm refers to the implementation of Musig in [this repository](https://github.com/guggero/bip-schnorr).You can also read [this blog](https://blog.blockstream.com/en-musig-key-aggregation-schnorr-signatures/) or [paper](https://eprint.iacr.org/2018/068) to get more content about musig.\n\nIn order to improve the speed and reduce the size of the code, I used a lot of functions and classes from [noble-secp256k1](https://github.com/paulmillr/noble-secp256k1) in the implementation of musig.You can find these code in `src\\@noble\\secp256k1` path.\n\nWarn: The underlying functions and classes from `noble-secp256k1` of this repository are cryptographically secure and audited, but the code implementation process is unaudited by my personal code writing, which may have vulnerabilities such as timing attacks so it is not recommended for production environments.\n\n## Usage\n\nYou need to compile this code yourself, you can `tsc` command.\n\nThe sample code is as follows:\n```javascript\nimport { utils, schnorr } from \"./@noble/secp256k1/index.js\"\nimport { SessionData, aggregateTranserData, partialSigCombine, partialSign } from \"./index.js\"\n\nconst pubKeys= [\n    utils.hexToBytes('846f34fdb2345f4bf932cb4b7d278fb3af24f44224fb52ae551781c3a3cad68a'),\n    utils.hexToBytes('50cebaa0efcb443f366240beb66504e14df69dc66aae829af80aa03ea25e1802'),\n];\n\nconst privateKey1 = BigInt('0xadd2b25e2d356bec3770305391cbc80cab3a40057ad836bcb49ef3eed74a3fee')\nconst privateKey2 = BigInt('0xc5487234745cebddf6c6588995c16cebc029beed9f7affbb13d5cbe6c7a9e129')\n\nconst message = await utils.sha256('muSig is awesome!');\n\nconst session1 = new SessionData(0, privateKey1, pubKeys, message);\nconst session2 = new SessionData(1, privateKey2, pubKeys, message);\n\nlet sessions = [\n    await session1.exportSession(),\n    await session2.exportSession()\n]\n\nlet aggregationTranser = aggregateTranserData(sessions);\n\nlet partialSignature1 = await partialSign(aggregationTranser, session1);\nlet partialSignature2 = await partialSign(aggregationTranser, session2);\n\nlet signature = await partialSigCombine(aggregationTranser, [partialSignature1, partialSignature2]);\n\nlet isValid = await schnorr.verify(signature, session1.message, utils.numTo32bStr(await session1.pubKeyCombined))\n\nconsole.log(isValid)\n```\n\nTo use this code under application, you need to complete 3 rounds of message exchange. In the first round of message exchange, each signer shoud exchange `publickey` and generate `pubKeys`. In the second round of message exchange, signer should exchange `session.exportSession()` and finish `partialSign` method. In the third round of message exchange, each signer should exchange `partialSignature`. After completing three rounds of information exchange, each signer can run the function `partialSigCombine` locally to obtain the final complete signature after obtaining partial signature information and each signer can run `schnorr.verify` to verify the signature.\n\nDuring the use of this code, you may encounter this error:\n```\nError: hexToBytes: received invalid unpadded hex63\n```\n\nThis error occurs because the generated value of the random number does not satisfy certain conditions, I have not handled this error in the code, if you encounter this error, you can rerun the code to get a random number that meets the criteria.\n\nIf you can fix this error, please send a PR.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangshouh%2Fmusig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwangshouh%2Fmusig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangshouh%2Fmusig/lists"}