BIP322-JS (英语)
一个 Javascript 库,提供与 BIP-322 签名方案相關的公用功能. 这是叉子 https://github.com/ACken2/bip322-js (中文(简体) ) 为减少审计工作量而改变依赖性. 目前没有突破 API 的更改 .
限制
本库中仅支持P2PKH,P2SH-P2WPKH,P2WPKH,和单键相接P2TR.
文档
备查 https://acken2.github.io/bip322-js/ (中文(简体) )
支持的特性
- 生成原始的 BIP-322 交易
- 使用私钥签名 BIP-322 签名
- 验证一个简单的 BIP-322 签名
示例
// Import modules that are useful to you
const { BIP322, Signer, Verifier } = require('bip322-js')
// Signing a BIP-322 signature with a private key
const privateKey = 'L3VFeEujGtevx9w18HD1fhRbCH67Az2dpCymeRE1SoPK6XQtaN2k'
const address = 'bc1q9vza2e8x573nczrlzms0wvx3gsqjx7vavgkx0l'
const message = 'Hello World'
const signature = Signer.sign(privateKey, address, message)
console.log(signature)
// Verifying a simple BIP-322 signature
const validity = Verifier.verifySignature(address, message, signature)
console.log(validity) // True
// You can also get the raw unsigned BIP-322 toSpend and toSign transaction directly
const scriptPubKey = Buffer.from('00142b05d564e6a7a33c087f16e0f730d1440123799d', 'hex')
const toSpend = BIP322.buildToSpendTx(message, scriptPubKey) // bitcoin.Transaction
const toSpendTxId = toSpend.getId()
const toSign = BIP322.buildToSignTx(toSpendTxId, scriptPubKey) // bitcoin.Psbt
// Do whatever you want to do with the PSBT
在BIP322, Signer, 和验证器的单元测试中可以找到更多的工作实例.