{"id":37103482,"url":"https://github.com/chrischo-h/bitcoin-sdk-js","last_synced_at":"2026-01-14T12:31:46.138Z","repository":{"id":202624809,"uuid":"700757655","full_name":"ChrisCho-H/bitcoin-sdk-js","owner":"ChrisCho-H","description":"Bitcoin TypeScript/JavaScript Library for NodeJS, Browser and Mobile. Segwit \u0026 Taproot support.✨","archived":false,"fork":false,"pushed_at":"2025-10-24T11:41:38.000Z","size":986,"stargazers_count":36,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-24T13:23:55.967Z","etag":null,"topics":["bitcoin","javascript","message-signing","nodejs","segwit","smart-contracts","taproot","typescript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/ChrisCho-H.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-10-05T08:32:14.000Z","updated_at":"2025-10-24T11:41:42.000Z","dependencies_parsed_at":"2023-12-18T16:04:26.206Z","dependency_job_id":"a2d16cdb-034d-4201-b080-98b23ff1e87c","html_url":"https://github.com/ChrisCho-H/bitcoin-sdk-js","commit_stats":null,"previous_names":["chrischo-h/dogecoin-js","chrischo-h/dogecoinjs-lib","chrischo-h/bitcoin-sdk-js"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/ChrisCho-H/bitcoin-sdk-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisCho-H%2Fbitcoin-sdk-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisCho-H%2Fbitcoin-sdk-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisCho-H%2Fbitcoin-sdk-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisCho-H%2Fbitcoin-sdk-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChrisCho-H","download_url":"https://codeload.github.com/ChrisCho-H/bitcoin-sdk-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisCho-H%2Fbitcoin-sdk-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28420778,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["bitcoin","javascript","message-signing","nodejs","segwit","smart-contracts","taproot","typescript"],"created_at":"2026-01-14T12:31:45.340Z","updated_at":"2026-01-14T12:31:46.089Z","avatar_url":"https://github.com/ChrisCho-H.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./bitcoin-sdk-js-logo.png\" width = 300 /\u003e\n\n**✨ Bitcoin TypeScript/JavaScript Library for NodeJS, Browser and Mobile ✨**\n\u003c/div\u003e\n\n_Bitcoin is hard. Especially for those not familiar with crypto, it is even hard\nto create a simple bitcoin transaction._\n\nbitcoin-sdk-js provides various features which help to **create various type of bitcoin transaction so easily🚀**,\nincluding **advanced smart contract like multisig, hashlock, timelock, combination of them, and even your own smart contract**.\n\n**Legacy, Segwit, Taproot features are all suppoted!**\n\n## Install\n``` bash\nnpm install bitcoin-sdk-js\n```\n## How To Use\n- [Generate Address](#generate-address-p2pkh-p2wpkh-p2sh-p2wsh-p2tr)\n  - [Address for Single Signer(P2PKH, P2WPKH, P2TR)](#1-address-for-single-signerp2pkh-p2wpkh-p2tr)\n  - [Address for Script(P2SH, P2WSH)](#2-address-for-scriptp2sh-p2wsh)\n- [Create Transaction](#create-transaction-p2pkh-p2wpkh-p2sh-p2wsh-p2tr)\n  - [Transaction for Single Signer(P2PKH, P2WPKH)](#1-transaction-for-single-signerp2pkh-p2wpkh)\n  - [Transaction for Multi Signer(P2SH, P2WSH)](#2-transaction-for-multi-signerp2sh-p2wsh)\n  - [Transaction for Single(or Multi) Signer with TimeLock (or || and) HashLock(P2SH, P2WSH)](#3-transaction-for-singleor-multi-signer-with-timelock-or--and-hashlockp2sh-p2wsh)\n  - [Transaction for TimeLock (or || and) HashLock without Signer(P2SH, P2WSH)](#4-transaction-for-timelock-or--and-hashlock-without-signerp2sh-p2wsh)\n  - [Custom smart contract(P2SH, P2WSH)](#5-custom-smart-contractp2sh-p2wsh)\n  - [Taproot and Tapscript spend(P2TR)](#6-taproot-and-tapscript-spendp2tr)\n- [Sign Message and Verify Signature - BIP322 (P2PKH, P2WPKH, P2TR)](#sign-message-and-verify-signature---bip322-p2pkh-p2wpkh-p2tr)\n### Generate Address (P2PKH, P2WPKH, P2SH, P2WSH, P2TR)\n#### 1. Address for Single Signer(P2PKH, P2WPKH, P2TR)\n``` javascript\n\nimport * as bitcoin from 'bitcoin-sdk-js'\n\n// if you need to generate key pair\nconst keyPair = await bitcoin.wallet.generateKeyPair();\n// p2pkh\nconst legacyAddress = await bitcoin.address.generateAddress(\n  keyPair.publicKey,\n  'legacy',\n);\n// p2wpkh\nconst segwitAddress = await bitcoin.address.generateAddress(\n  keyPair.publicKey,\n  'segwit',\n);\n// p2tr\nconst taprootAddress = await bitcoin.address.generateAddress(\n  (\n    // It's recommended to tweak public key to generate taproot address\n    await bitcoin.tapscript.getTapTweakedPubkey(\n      // Schnorr key is same with any bitcoin key pair, except it does not use public key prefix byte '02' or '03'.\n      keyPair.publicKey.slice(2),\n      await bitcoin.tapscript.getTapTweak(keyPair.publicKey.slice(2)),\n    )\n  ).tweakedPubKey,\n  'taproot',\n);\n// p2pkh - testnet\nconst legacyAddressTestnet = await bitcoin.address.generateAddress(\n  keyPair.publicKey,\n  'legacy',\n  'testnet',\n);\n// p2wpkh - testnet\nconst segwitAddressTestnet = await bitcoin.address.generateAddress(\n  keyPair.publicKey,\n  'segwit',\n  'testnet',\n);\n// p2tr - testnet\nconst taprootAddressTestnet = await bitcoin.address.generateAddress(\n  (\n    // It's recommended to tweak public key to generate taproot address\n    await bitcoin.tapscript.getTapTweakedPubkey(\n      // Schnorr key is same with any bitcoin key pair, except it does not use public key prefix byte '02' or '03'.\n      keyPair.publicKey.slice(2),\n      await bitcoin.tapscript.getTapTweak(keyPair.publicKey.slice(2)),\n    )\n  ).tweakedPubKey,\n  'taproot',\n  'testnet',\n);\n\n```\n#### 2. Address for Script(P2SH, P2WSH)\n``` javascript\n\nimport * as bitcoin from 'bitcoin-sdk-js'\n\n// if you need to generate key pair\nconst keyPair = await bitcoin.wallet.generateKeyPair();\n// Script can be any of bitcoin script opcode! bitcoin-sdk-js provides an easy way to build script.\n// Below script is timelock + single sig\nconst script = \n      await bitcoin.script.generateTimeLockScript(2542622) + await bitcoin.script.generateSingleSigScript(keyPair.publicKey);\n// p2sh\nconst legacyScriptAddress = await bitcoin.address.generateScriptAddress(\n  script,\n  'legacy',\n);\n// p2wsh\nconst segwitScriptAddress = await bitcoin.address.generateScriptAddress(\n  script,\n  'segwit',\n);\n// p2sh - testnet\nconst legacyScriptAddressTestnet = await bitcoin.address.generateScriptAddress(\n  script,\n  'legacy',\n  'testnet',\n);\n// p2wsh - testnet\nconst segwitScriptAddressTestnet = await bitcoin.address.generateScriptAddress(\n  script,\n  'segwit',\n  'testnet',\n);\n\n```\n### Create Transaction (P2PKH, P2WPKH, P2SH, P2WSH, P2TR)\n#### 1. Transaction for Single Signer(P2PKH, P2WPKH)\n``` javascript\n\nimport * as bitcoin from 'bitcoin-sdk-js';\n\n// if you need to generate key pair\nconst keyPair = await bitcoin.wallet.generateKeyPair();\nconst pubkey = keyPair.publicKey;\nconst privkey = keyPair.privateKey;\n\n// initialize Bitcoin Transaction object\nconst tx = new bitcoin.Transaction();\n\n// add UTXO to spend as an input\nawait tx.addInput({\n  txHash: txId, // transaction id of utxo\n  index: 0, // index of utxo in transaction\n  value: value, // value of utxo(unit is satoshi)\n} as bitcoin.UTXO);\n\n// add Target output to send Bitcoin\n// most common transaction which sends bitcoin to single sig address\nawait tx.addOutput({\n    address: await bitcoin.address.generateAddress(pubkey),\n    value: value - fee, // value of utxo - fee\n} as bitcoin.Target);\n\n// if input utxo only requires single sig(p2wpkh or p2pkh)\nawait tx.signInput(privkey, 0);\n\n// You can broadcast signed tx here: https://blockstream.info/testnet/tx/push\nconst txToBroadcast: string = await tx.getSignedHex();\n\n```\n#### 2. Transaction for Multi Signer(P2SH, P2WSH)\n``` javascript\n\nimport * as bitcoin from 'bitcoin-sdk-js';\n\n// initialize Bitcoin Transaction object\nconst tx = new bitcoin.Transaction();\n\n// add UTXO to spend as an input\nawait tx.addInput({\n  txHash: txId, // transaction id of utxo\n  index: 0, // index of utxo in transaction\n  value: value, // value of utxo(unit is satoshi)\n} as bitcoin.UTXO);\n\n// add Target output to send Bitcoin\n// sends bitcoin to 2-of-3 multisig transaction\nawait tx.addOutput({\n    // all the smart contract output is recommended to use script address!\n    address: await bitcoin.address.generateScriptAddress(\n        // this generate multisig smart contract, which is possible up to 15-of-15 \n        await bitcoin.script.generateMultiSigScript(2, [pubkey1, pubkey2, pubkey3]),\n    ),\n    value: value - fee, // value of utxo - fee\n} as bitcoin.Target);\n\n// if input utxo requires multi sig(p2wsh or p2sh)\nawait tx.multiSignInput(\n    [pubkey1, pubkey2, pubkey3],\n    [privkey1, privkey2],\n    0, // input index to sign\n);\n\n// You can broadcast signed tx here: https://blockstream.info/testnet/tx/push\nconst txToBroadcast: string = await tx.getSignedHex();\n\n```\n\n#### 3. Transaction for Single(or Multi) Signer with TimeLock (or || and) HashLock(P2SH, P2WSH)\n``` javascript\n\nimport * as bitcoin from 'bitcoin-sdk-js';\n\n// initialize Bitcoin Transaction object\nconst tx = new bitcoin.Transaction();\n\n// add UTXO to spend as an input\nawait tx.addInput({\n  txHash: txId, // transaction id of utxo\n  index: 0, // index of utxo in transaction\n  value: value, // value of utxo(unit is satoshi)\n} as bitcoin.UTXO);\n\n// add Target output to send Bitcoin\n// sends bitcoin to single(or multi) sig script with timelock\nawait tx.addOutput({\n    address: await bitcoin.address.generateScriptAddress(\n        // able to spend this output after given block height\n        (await bitcoin.script.generateTimeLockScript(2542622)) +\n        // you can use generateMultiSigScript instead of single sig here\n        (await bitcoin.script.generateSingleSigScript(pubkey)),\n    ),\n    value: value - fee, // value of utxo - fee\n} as bitcoin.Target);\n\n// sends bitcoin to single(or multi) sig script with hashlock\nawait tx.addOutput({\n    address: await bitcoin.address.generateScriptAddress(\n        // able to spend this output if 'secretHex' is given\n        (await bitcoin.script.generateHashLockScript('secretHex')) + \n        // you can use generateMultiSigScript instead of single sig here\n        (await bitcoin.script.generateSingleSigScript(pubkey)),\n    ),\n    value: value - fee, // value of utxo - fee\n} as bitcoin.Target);\n\n// sends bitcoin to single(or multi) sig script with timelock + hashlock\nawait tx.addOutput({\n    address: await bitcoin.address.generateScriptAddress(\n        /* \n        WATCH OUT! Order matters. You must place script in the order of\n        timelock, hashlock and single(or multi) sig\n        to spend this output with bitcoin-sdk-js\n        */\n        (await bitcoin.script.generateTimeLockScript(2542622)) +\n        (await bitcoin.script.generateHashLockScript('secretHex')) +\n        // you can use generateMultiSigScript instead of single sig here\n        (await bitcoin.script.generateSingleSigScript(pubkey)),\n    ),\n    value: value - fee, // value of utxo - fee\n} as bitcoin.Target);\n\n// if transaction use timelock input, must set tx locktime bigger than input timelock\nawait tx.setLocktime(2542622);\n\n// if input utxo requires single sig with smart contract(p2wsh or p2sh)\nawait tx.signInput(\n    privkey,\n    0, // input index to sign\n    'segwit', // default is segwit, you might use legacy if necessary\n    await bitcoin.script.generateTimeLockScript(2542622), // is timelock input? provide script\n    'secretHex', // is hashlock input? provide secretHex to unlock\n);\n\n// or if input utxo requires multi sig with smart contract(p2wsh or p2sh)\nawait tx.multiSignInput(\n    [pubkey1, pubkey2, pubkey3],\n    [privkey1, privkey2],\n    0, // input index to sign\n    'segwit', // default is segwit, you might use legacy if necessary\n    await bitcoin.script.generateTimeLockScript(2542622), // is timelock input? provide script\n    'secretHex', // is hashlock input? provide secretHex to unlock\n);\n\n// You can broadcast signed tx here: https://blockstream.info/testnet/tx/push\nconst txToBroadcast: string = await tx.getSignedHex();\n```\n#### 4. Transaction for TimeLock (or || and) HashLock without Signer(P2SH, P2WSH)\n``` javascript\n\nimport * as bitcoin from 'bitcoin-sdk-js';\n\n// initialize Bitcoin Transaction object\nconst tx = new bitcoin.Transaction();\n\n// add UTXO to spend as an input\nawait tx.addInput({\n  txHash: txId, // transaction id of utxo\n  index: 0, // index of utxo in transaction\n  value: value, // value of utxo(unit is satoshi)\n} as bitcoin.UTXO);\n\n// add Target output to send Bitcoin\n// sends bitcoin to script with timelock + hashlock (no sig required)\nawait tx.addOutput({\n    address: await bitcoin.address.generateScriptAddress(\n        // if you only want hashlock, you can remove generateTimeLockScript\n        (await bitcoin.script.generateTimeLockScript(2542622)) +\n        (await bitcoin.script.generateHashLockScript('secretHex')),   \n    ),\n    value: value - fee, // value of utxo - fee\n} as bitcoin.Target);\n\n// if transaction use timelock input, must set tx locktime bigger than input timelock\nawait tx.setLocktime(2542622);\n\n// if input utxo requires to unlock hash with smart contract(p2wsh or p2sh)\nawait tx.unlockHashInput(\n    'secretHex',\n    0,\n    'segwit', // default is segwit, you might use legacy if necessary\n    await bitcoin.script.generateTimeLockScript(2542622),// is timelock input? provide script\n);\n\n// You can broadcast signed tx here: https://blockstream.info/testnet/tx/push\nconst txToBroadcast: string = await tx.getSignedHex();\n\n```\n#### 5. Custom smart contract(P2SH, P2WSH)\nYou might use tapscript for this!\n``` javascript\n\nimport * as bitcoin from 'bitcoin-sdk-js';\n\n// You can send and spend any smart contract. Below example is classic HTLC\nconst HTLC = bitcoin.Opcode.OP_IF +\n        (await bitcoin.script.generateTimeLockScript(2576085)) +\n        (await bitcoin.data.pushData(pubkey1)) + // must specify data to read(if not opcode)\n        pubkey1 +\n        bitcoin.Opcode.OP_ELSE +\n        (await bitcoin.script.generateHashLockScript('abcdef')) +\n        (await bitcoin.data.pushData(pubkey2)) + // must specify data to read(if not opcode)\n        pubkey2 +\n        bitcoin.Opcode.OP_ENDIF +\n        bitcoin.Opcode.OP_CHECKSIG\n// p2wsh address, custom contract address must be p2wsh(p2sh) (or taproot address, check next chapter!)\nconst toAddress = await bitcoin.address.generateScriptAddress(HTLC);\n\n// Then, can be spent as an input by signing by scriptSig!\n// initialize Bitcoin Transaction object\nconst tx = new bitcoin.Transaction();\n\n// if transaction use timelock input, must set tx locktime bigger than input timelock\nawait tx.setLocktime(2576085); \n\n// spend by executing OP_IF branch\nawait tx.signInputByScriptSig(\n    // script sig list(order matters!!! bitcoin script is stack-based LIFO)\n    [\n      await bitcoin.crypto.sign(\n        // method to get input message hash to sign\n        await tx.getInputHashToSign(\n          HTLC, // redeem script as p2wsh\n          0, // input index\n        ),\n        privkey1, // signer private key\n      ),\n      '01', // execute OP_IF\n      HTLC, // redeem script as p2wsh\n    ],\n    0, // input index\n  );\n// Or spend by executing OP_ELSE branch\nawait tx.signInputByScriptSig(\n    // script sig list(order matters!!! bitcoin script is stack-based LIFO)\n    [\n      await bitcoin.crypto.sign(\n        // method to get input message hash to sign\n        await tx.getInputHashToSign(\n          HTLC, // redeem script as p2wsh\n          0, // input index\n        ),\n        privkey2, // signer private key\n      ),\n      'abcdef', // unlock hash\n      '', // execute OP_ELSE\n      HTLC, // redeem script as p2sh\n    ],\n    0, // input index\n  );\n\n// You can broadcast signed tx here: https://blockstream.info/testnet/tx/push\nconst txToBroadcast: string = await tx.getSignedHex();\n\n```\n\n#### 6. Taproot and Tapscript spend(P2TR)\n``` javascript\n\n\nimport * as bitcoin from 'bitcoin-sdk-js';\n\n// Let's send and spend above HTLC in taproot and tapscript way!\n/*\n  Schnorr key is same with any bitcoin key pair, except it does not use public key prefix byte '02' or '03'.\n  This key pair will be used as a master key to spend UTXO in taproot, after tweaked(will explain how to step by step).\n*/\nconst keyPair = await bitcoin.wallet.generateKeyPair();\nconst schnorrPubkey = keyPair.publicKey.slice(2); // remove first byte (which is parity bit)\nconst schnorrPrivkey = keyPair.privateKey;\n\n/*\n  HTLC consists of conditional branch, in which OP_IF contains Time Lock Contract and OP_ELSE contains Hash Lock.\n  We can construct tapscript tree where each leaf has its own contract(script), enable unlimited spending branches.\n*/\n// Originally OP_IF branch Time Lock Contract\nconst timeLockContract =\n    (await bitcoin.script.generateTimeLockScript(2576085)) +\n    (await bitcoin.data.pushData(schnorrPubkey1)) + // must specify data to read(if not opcode)\n    schnorrPubkey1 + // you must use schnorr key even in tapscript\n    bitcoin.Opcode.OP_CHECKSIG;\n// Originally OP_ELSE branch Hash Lock Contract\nconst hashLockContract =\n    (await bitcoin.script.generateHashLockScript('abcdef')) +\n    (await bitcoin.data.pushData(schnorrPubkey2)) + // must specify data to read(if not opcode)\n    schnorrPubkey2 + // you must use schnorr key even in tapscript\n    bitcoin.Opcode.OP_CHECKSIG;\n\n/*\n  You can get tapbranch from a pair of script, and repeat over to reach to the root of tree(which is 'taproot') \n  Here we have only a single pair of script, so tapbranch of it is taproot\n*/\nconst taproot = await bitcoin.tapscript.getTapBranch([\n    await bitcoin.tapscript.getTapLeaf(timeLockContract),\n    await bitcoin.tapscript.getTapLeaf(hashLockContract),\n]);\n// Then, get taptweak with schnorr key generated above\nconst tapTweak = await bitcoin.tapscript.getTapTweak(\n    schnorrPubkey,\n    taproot,\n);\n// Finally, you can tweak schnorr public key, which can be used as taproot key!\nconst tapTweakedPubkey = await bitcoin.tapscript.getTapTweakedPubkey(\n    schnorrPubkey,\n    tapTweak,\n);\n// generate taproot address with taproot key(and send to it!)\nconst toAddress = await bitcoin.address.generateAddress(tapTweakedPubkey.tweakedPubKey, 'taproot');\n\n// initialize Bitcoin Transaction object\nconst tx = new bitcoin.Transaction();\n\nawait tx.setLocktime(2576085); // if transaction use timelock input, must set tx locktime bigger than input timelock\n\n// Then, can be spent as an input!\n// one thing to keep in mind, taproot or tapscript spend needs to provide all the script public key of input\nawait tx.addInput({\n    txHash: txId,\n    index: 0,\n    value: value,\n    script: await bitcoin.script.getScriptByAddress(toAddress),\n});\n\n// taproot spend? just sign input with tweaked schnorr key(which is, taproot private key)\nawait tx.signInput(\n    await bitcoin.tapscript.getTapTweakedPrivkey(schnorrPrivkey, tapTweak), // provide tweaked private key\n    0,\n    'taproot',\n);\n\n// Or tapscript spend? Let's spend by hash lock script!\nconst sigStack = [\n    await bitcoin.crypto.sign(\n      await tx.getInputHashToSign(hashLockContract, 0, 'tapscript'),\n      schnorrPrivkey2,\n      'schnorr',\n    ), // schnorr signature\n    'abcdef', // hash to unlock\n    hashLockContract, // spend script\n    // you must specify path to find taproot with provided script(For more detail, check BIP341!)\n    await bitcoin.tapscript.getTapControlBlock(\n      schnorrPubkey,\n      tapTweakedPubkey.parityBit,\n      await bitcoin.tapscript.getTapLeaf(timeLockContract), // path to find taproot\n    ),\n];\n\nawait tx.signInputByScriptSig(sigStack, 0, 'tapscript');\n\n// You can broadcast signed tx here: https://blockstream.info/testnet/tx/push\nconst txToBroadcast: string = await tx.getSignedHex();\n\n```\n\n### Sign Message and Verify Signature - BIP322 (P2PKH, P2WPKH, P2TR)\n\n``` javascript\n\nimport * as bitcoin from 'bitcoin-sdk-js'\n\n// if you need to generate key pair\nconst keyPair = await bitcoin.wallet.generateKeyPair();\nconst pubkey = keyPair.publicKey;\nconst privkey = keyPair.privateKey;\n\n// address to verify(legacy p2pkh, segwit p2wpkh, taproot p2tr are all supported!)\nconst legacyAddress = await bitcoin.address.generateAddress(\n  pubkey,\n  'legacy',\n);\nconst segwitAddress = await bitcoin.address.generateAddress(\n  pubkey,\n  'segwit',\n);\nconst tapAddress = await bitcoin.address.generateAddress(\n  (\n    await bitcoin.tapscript.getTapTweakedPubkey(\n      pubkey.slice(2),\n      await bitcoin.tapscript.getTapTweak(pubkey.slice(2)),\n    )\n  ).tweakedPubKey,\n  'taproot',\n);\n// message to sign\nconst msg = \"message to sign\";\n// sign messsage with private key and address\nconst sigLegacy = await bitcoin.crypto.signMessage(\n  msg,\n  privkey,\n  legacyAddress,\n);\nconst sigSegwit = await bitcoin.crypto.signMessage(\n  msg,\n  privkey,\n  segwitAddress,\n);\nconst sigTap = await bitcoin.crypto.signMessage(msg, privkey, tapAddress);\n// verify signature from address, returning boolean.\nawait bitcoin.crypto.verifyMessage(msg, sigLegacy, legacyAddress);\nawait bitcoin.crypto.verifyMessage(msg, sigSegwit, segwitAddress);\nawait bitcoin.crypto.verifyMessage(msg, sigTap, tapAddress);\n\n```\n\n\n\n## 📜 License\nThis software is licensed under the MIT ©.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrischo-h%2Fbitcoin-sdk-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrischo-h%2Fbitcoin-sdk-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrischo-h%2Fbitcoin-sdk-js/lists"}