
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
@cmdcode/musig2
Advanced tools
A simple and easy-to-use musig2 library, written in typescript.
sign, combine and verify to create and validate signatures.NOTE: This library is still under heavy development. Expect dragons!
More documentation coming soon!
This package is available on NPM for easy import into your nodejs or browser-based project:
# Node via NPM:
npm install @cmdcode/musig2
# Node via Yarn:
yarn add @cmdcode/musig2
Example import as an ES module:
import * as Musig2 from '@cmdcode/musig2'
Example import into a browser-based project:
<script src="https://unpkg.com/@cmdcode/musig2"></script>
<script> const Musig2 = window.musig2 </script>
Here is a basic example of using Musig2 for signing. The steps are as follows:
Check out test/src/demo.test.ts for a full reference implementation.
// Import the package.
import * as Musig2 from '@cmdcode/musig2'
// Encode an example string as bytes.
const encoder = new TextEncoder()
const message = encoder.encode('Hello world!')
// Let's create an example list of signing members.
const members = [ 'alice', 'bob', 'carol' ]
// We'll store each member's keys in an array.
const wallets : any[] = []
// Let's also add some additional key tweaks.
const tweak1 = Musig2.gen.random()
const tweak2 = Musig2.gen.random()
const options = { tweaks : [ tweak1, tweak2 ] }
// Setup a dummy wallet for each signer.
for (const name of members) {
// Generate some random secrets using WebCrypto.
const secret = Musig2.gen.random(32)
const nonce = Musig2.gen.random(64)
// Create a pair of signing keys.
const [ sec_key, pub_key ] = Musig2.gen.key_pair(secret)
// Create a pair of nonce values (numbers only used once).
const [ sec_nonce, pub_nonce ] = Musig2.gen.nonce_pair(nonce)
// Add the member's wallet to the array.
wallets.push({
name, sec_key, pub_key, sec_nonce, pub_nonce
})
}
// Collect public keys and nonces from all signers.
const group_keys = wallets.map(e => e.pub_key)
const group_nonces = wallets.map(e => e.pub_nonce)
// Combine all your collected keys into a signing session.
const session = Musig2.combine.keys(group_keys, group_nonces, message, options)
// Each member creates their own partial signature,
// using their own computed signing session.
const group_sigs = wallets.map(wallet => {
return Musig2.sign(
session,
wallet.sec_key,
wallet.sec_nonce
)
})
// Combine all the partial signatures into our final signature.
const signature = Musig2.combine.sigs(session, group_sigs)
// Check if the signature is valid.
const isValid1 = Musig2.verify.sig (
session,
signature
)
You can also verify the signature using an independent cryptography library, such as the excellent @noble/curves library by Paul Miller.
// BONUS: Check if the signature is valid using an independent library.
import { schnorr } from '@noble/curves/secp256k1'
const { group_pubkey } = session
const pubkey = group_pubkey.slice(1)
const isValid2 = schnorr.verify(signature, message, pubkey)
This library uses yarn for package management.
## Clean up any old builds.
yarn clean
## Run all tests in the suite.
yarn test
## Build a new release.
yarn release
If you run into any bugs or have any questions, please submit an issue ticket.
Feel free to fork and make contributions. Suggestions are welcome!
Use this library however you want!
You can find me on nostr at: npub1gg5uy8cpqx4u8wj9yvlpwm5ht757vudmrzn8y27lwunt5f2ytlusklulq3
FAQs
Create digital signatures based on the Musig2 protocol.
We found that @cmdcode/musig2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.