{"id":22151435,"url":"https://github.com/chainside/btcnodejs","last_synced_at":"2025-09-01T01:32:31.450Z","repository":{"id":47894654,"uuid":"105996158","full_name":"chainside/btcnodejs","owner":"chainside","description":"A Nodejs SegWit-compliant library which provides tools to handle Bitcoin data structures in a simple fashion. ","archived":false,"fork":false,"pushed_at":"2021-08-12T01:42:16.000Z","size":858,"stargazers_count":37,"open_issues_count":3,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-26T10:04:17.982Z","etag":null,"topics":["bitcoin","javascript","nodejs"],"latest_commit_sha":null,"homepage":"https://www.chainside.net","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chainside.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-06T11:15:27.000Z","updated_at":"2024-07-22T19:26:35.000Z","dependencies_parsed_at":"2022-07-22T19:33:26.212Z","dependency_job_id":null,"html_url":"https://github.com/chainside/btcnodejs","commit_stats":null,"previous_names":["chainside/btcjs"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/chainside/btcnodejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainside%2Fbtcnodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainside%2Fbtcnodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainside%2Fbtcnodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainside%2Fbtcnodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chainside","download_url":"https://codeload.github.com/chainside/btcnodejs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainside%2Fbtcnodejs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273064243,"owners_count":25039259,"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","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","nodejs"],"created_at":"2024-12-02T00:33:08.813Z","updated_at":"2025-09-01T01:32:31.410Z","avatar_url":"https://github.com/chainside.png","language":"JavaScript","readme":"\u003cp\u003e\n\u003cimg src=\"https://www.chainside.net/wp-content/themes/chainside2018/assets/favicon//favicon-192.png\" alt=\"chainside\" width=\"80\"\u003e\n\u003cbr \\\u003e\u003cbr \\\u003e\ndeveloped with :heart: by \u003ca href=\"https://www.chainside.net\"\u003echainside\u003c/a\u003e\n\u003c/p\u003e\n\n# btcnodejs\n\n`btcnodejs` is a Segwit-compliant bitcoin library which provides tools for managing bitcoin data structures. It is the NodeJS version of [btcpy](https://github.com/chainside/btcpy).\n\n**This library is a work in progress and its usage in a production environment is highly discouraged. Also, as long as the version is 0.\\*, API breaking changes might occur**\n\nSome of the functionalities are a wrapping around  [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib), and their development is still in progress.\n\nIt makes usage of [bytebuffer.js](https://github.com/dcodeIO/bytebuffer.js) for representing most of the data structures\n\nTable of Contents\n=================\n* [Installation](#installation)\n* [Usage](#usage)\n* [Browserify](#browserify)\n* [API](#api)\n  * [Transactions](#transactions)\n  * [Scripts](#scripts)\n  * [Solvers](#solvers)\n  * [Crypto](#crypto)\n  * [HD](#hd)\n  * [Address](#address)\n  * [Block](#block)\n\n# Installation\n\nTo install the library, run `npm install btcnodejs`\n\n# Browserify\n\nThis library can be used in the browser with [browserify](https://github.com/browserify/browserify). If you are familiar with browserify, you can skip this.\n\nAssuming the entry point of the project is a file main.js like:\n\n```javascript\nconst btcnodejs = require(\"btcnodejs\");\nconst net = btcnodejs.network;\nnet.setup(\"testnet\");\nvar k = new btcnodejs.HDPrivateKey();\nconsole.log(k.privkey.toWIF());\n```\n\nGo into the main.js folder and run:\n\n```\nbrowserify main.js \u003e browser_main.js\n\n```\n\nNow you can load the 'browserified' main.js into your html:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eExample Browserify\u003c/title\u003e\n    \u003c/head\u003e\n  \u003cbody\u003e\n      \u003cscript src=\"browser_main.js\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n\n```\n# What it does\n\nThis library aims to manage bitcoin data structures. It offers functionalities for\n\n* Transactions and block headers deserialization\n\n* Scripts creation\n\n* Privatekeys, Publickeys and HDkeys management\n\n* Transactions signing\n\n# What it does not do\n\nThis library does not implement the following functionalities:\n\n* Validation : when transactions and scripts are parsed, only\nformat errors are reported. No proof-of-work validation, script execution,\ntransaction validation and signature verification is performed\n\n* Networking : this library does not provide functionalities to communicate with bitcoin nodes. Separates networking modules will be released soon.\n\n# Tests\n\nIn order to run tests, cd in the package directory and run\n\n`npm test`\n\nTo run tests in the browser, you first need [brfs](https://github.com/browserify/brfs) installed. Then you can run browserify on the tests file, by doing (within the package directory):\n\n`browserify -t brfs test/test.js \u003e test/browser_tests.js`\n\nNow you can create the .html file with the test script:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eMocha Tests\u003c/title\u003e\n    \u003clink rel=\"stylesheet\" href=\"node_modules/mocha/mocha.css\"\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"mocha\"\u003e\u003c/div\u003e\n    \u003cscript src=\"node_modules/mocha/mocha.js\"\u003e\u003c/script\u003e\n\n    \u003cscript\u003emocha.setup('bdd')\u003c/script\u003e\n    \u003cscript src=\"test/browser_tests.js\"\u003e\u003c/script\u003e\n    \u003cscript\u003e\n    mocha.run();\n    \u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n# Usage\nOn the first import, network setup must be executed. This is achieved by doing:\n\n```javascript\nconst network = require('btcnodejs').network\nnetwork.setup('testnet') //network can be either 'testnet' or 'mainnet'\n```\nOnce the network setup is executed, every subsequent setup will throw an exception.\n\nThe network module also exposes functionalities to get the current setup network\n\n ```javascript\n const network = require('btcnodejs').network\n network.setup('testnet')\n network.net_name()               //outputs 'testnet'\n network.is_mainnet()             //returns 'false'\n\n  ```\n\n\n# API\n\n## Transactions\n## `btcnodejs.Transaction`\n\nTransactions are immutable objects representing bitcoin transactions.\n\n#### Attributes\n\n* **version : Integer**\n\n* **inputs : list of Input objects**\n\n* **outputs : list of Output objects**\n\n* **locktime : Locktime object**\n\n* **segwit : Boolean**\n\n* **txid : String**\n\n#### new Transaction(version, inputs, outputs, locktime, segwit=false)\n\n#### toJSON()\nReturns the JSON representation of the transaction\n#### hash()\nComputes the double sha256 on the serialized transaction.\nReturns the hex string representing the hash\n#### segwitId()\nComputes the txid of a segwit transaction\nReturns the hex string representing the id of the transaction.\n#### static fromHex(hex)\n\n* **hex : Hexadecimal string**\n\nReturns a Transaction object\n\n```javascript\nconst btcnodejs = require('btcnodejs')\nconst Transaction = btcnodejs.Transaction\nbtcnodejs.network.setup('testnet')\n\nconst tx = Transaction.fromHex(\"0100000001e4da173fbefe5e60ff63dfd38566ade407532294db655463b77a783f379ce605000000006b4\" +\n                               \"83045022100af246c27890c2bc07a0b7450d3d82509702a44a4defdff766355240b114ee2ac02207bb67b\" +\n                               \"468452fa1b325dd5583879f5c1412e0bb4dae1c2c96c7a408796ab76f1012102ab9e8575536a1e99604a1\" +\n                               \"58fc60fe2ebd1cb1839e919b4ca42b8d050cfad71b2ffffffff0100c2eb0b000000001976a914df76c017\" +\n                               \"354ac39bde796abe4294d31de8b5788a88ac00000000\")\n\nconsole.log(tx.txid)           //'e977c07090c2a1dcaefd3f3c4ebf4e231f4116cb272f805b0b22a85e7eece09c'\n\n\n ```\n\n#### toHex()\n\nReturns the hexadecimal representation of the transactions\n\n#### serialize(segwit = this.segwit)\n\n* **segwit : Boolean**\n\nReturns a ByteBuffer containing the serialized transaction. If called with no parameter, the serialization is performed based on the transaction type. To perform a non-segwit serialization of a segwit transaction(i.e. to compute the segwit txid), false can be passed to the function.\n\n#### static deserialize(bytebuffer)\n\n* **bytebuffer : ByteBuffer object**\n\nReturns a Transaction object from a ByteBuffer object representing the serialized transaction\n\n#### toMutable()\n\nReturns a MutableTransaction object\n\n## `btcnodejs.MutableTransaction`\n\nMutable Transaction objects\n\n#### Attributes\n\n* **version : Integer**\n\n* **inputs : list of Input objects**\n\n* **outputs : list of Output objects**\n\n* **locktime : Locktime object**\n\n* **segwit : Boolean**\n\n* **txid : String**\n\n#### new MutableTransaction(version, inputs, outputs, locktime, segwit=false)\n\nReturns a MutableTransaction object\n\n#### toImmutable()\n\nReturns an immutable Transaction object\n\n#### spend(txouts, solvers)\n\n* **txouts : List of Output objects**\n\n* **solvers : List of Solver objects**\n\nReturns a Transaction object where the scriptSigs of its inputs are computed.\n\n```javascript\nconst btcnodejs = require('./lib/index')\nbtcnodejs.network.setup(network)\nvar t = new btcnodejs.Transaction(...)\nvar tospend = btcnodejs.Transaction.fromHex('...')\nvar key = btcnodejs.Privatekey.fromWIF(wif_key)\nvar solver = new btcnodejs.P2pkhSolver(key)\nvar unsigned = t.toMutable()\nvar spent = unsigned.spend([tospend.outputs[1]], [solver])\n```\n\n## `btcnodejs.Sighash`\n\nSighash object\n\n#### Attributes\n* **sighash : String**\n  * **values : 'ALL' | 'NONE' | 'SINGLE'\n\n* **anyonecanpay : Boolean**\n\n#### new Sighash(sighash, anyonecanpay = false)\n\nReturns a Sighash object\n\n## `btcnodejs.Input`\n\nTransaction Input object\n\n#### Attributes\n\n* **txid : String**\n\n* **out : Integer**\n\n* **scriptSig : ScriptSig object**\n\n* **sequence : Sequence object**\n\n* **witness : Witness object**\n\n#### new Input(txid, out, scriptSig, sequence, witness = undefined)\n\nReturns an Input object\n\n#### toJSON()\n\nReturns the JSON representation of the Input\n\n## `btcnodejs.Output`\n\nTransaction Output object\n\n#### Attributes\n\n* **amount : Integer**\n\n* **scriptPubKey : ScriptPubKey object**\n\n#### new Output(amount, scriptPubKey)\n\nReturns an Output object\n\n#### toJSON()\n\nReturns the JSON representation of the Output\n\n## `btcnodejs.Witness`\n\nInput Witness Object\n\n#### Attributes\n\n* **data : List of ByteBuffers**\n\n#### new Witness(data)\n\nReturns a Witness Object where data represents the required data to sign a transaction Input\n\n#### serialize()\n\nReturns a ByteBuffer representing the Witness serialization as it appears in a bitcoin transaction\n\n#### toScriptSig()\n\nReturns a ScriptSig object\n\n#### toHex()\n\nReturns the hexadecimal representation of the Witness object\n\n#### static fromHexArray([hex_wit_sig, hex_wit_pk])\n\nReturns a Witness object from an array of hexadecimal strings representing the siganture and the public key\n\n## `btcnodejs.Sequence`\n\nSequence object representing the sequence number of a transaction Input\n\n#### Attributes\n\n* **n : Integer**\n\n#### new Sequence(n)\n\nReturns a Sequence object\n\n#### isTime()\n\nReturns a Boolean which tells if the Sequence is measured in time\n\n#### isBlocks()\n\nReturns a Boolean which tells if the Sequence is measured in blocks\n\n#### isActive()\n\nReturns a Boolean which tells if a Sequence restriction is active\n\n## `btcnodejs.Locktime`\n\nLocktime object representing the locktime on a transaction\n\n#### Attributes\n\n* **n : Integer**\n\n#### new Locktime(n)\n\nReturns a Locktime object\n\n#### isTime()\n\nReturns a Boolean which tells if the Locktime is measured in time\n\n#### isBlocks()\n\nReturns a Boolean which tells if the Locktime is measured in blocks\n\n#### isActive()\n\nReturns a Boolean which tells if a Locktime restriction is active\n\n## Scripts\n\n\n\n## `btcnodejs.Script`\n\nBase Script object representing a general script as a ByteBuffer. Every Script class extends Script.\n\n#### Attributes\n\n* **body : ByteBuffer**\n\n#### new Script(body)\n\nReturns a Script object initialized from a bytebuffer representing the script\n\n#### serialize()\n\nReturns the body of the script_code\n\n## `btcnodejs.ScriptSig`\n\nScriptSig object\n\n#### toAsm()\n\nReturns a string representing the ASM of the script\n\n#### static fromAsm(asm)\n\nReturns a ScriptSig from an ASM string\n\n#### toHex()\n\nReturns the hexadecimal representation of the ScriptSig\n\n#### static fromHex(hex)\n\nReturns a ScriptSig object from an hexadecimal string representing the body of the script\n\n\n#### toWitness()\n\nReturns a Witness object where its data is retrieved from the ScriptSig body removing the push operations\n\n```javascript\nconst btcnodejs = require('btcnodejs')\nconst ScriptSig = btcnodejs.ScriptSig\nbtcnodejs.network.setup('testnet')\n\nconst sig = ScriptSig.fromHex(\"483045022100b7bf286e5f6ac6fa308e8876a8a59b289094851a26cf62c20abd174917eb7762022069b5269e584e4c7\" +\n                              \"6f207d1b789bff7171a663d795e49751c12cf07dceb2a94c70121024a0dcb0527c2751ea4dda3aa98f6eface16e978d\" +\n                              \"ba8062bcbed623f158c07691\")\n\nsig.toWitness().toHex()                           \n// \"02483045022100b7bf286e5f6ac6fa308e8876a8a59b289094851a26cf62c20abd174917eb7762022069b5269e584e4c76f207d1b789bff7171a663d795e49751c12c    f07dceb2a94c70121024a0dcb0527c2751ea4dda3aa98f6eface16e978dba8062bcbed623f158c07691\"\n ```\n\n## `btcnodejs.ScriptPubKey`\n\nScriptPubkey object representing a general script pubkey. It extends Script and is extended by specific ScriptPubkey types.\n\n#### toHex()\n\nReturns the hexadecimal representation of the ScriptPubKey\n\n#### static fromHex(hex)\n\nReturns a ScriptPubKey object from an hexadecimal string representing the body of the script. If the hex is representing an identifiable script, the fromHex() will return an instance of the specific ScriptPubKey. At the moment, identifiables scripts are P2pkh, P2sh, P2wpkhV0, P2wshV0, MultiSig\n\n```javascript\nconst btcnodejs = require('btcnodejs')\nconst ScriptPubKey = btcnodejs.ScriptPubKey\nbtcnodejs.network.setup('testnet')\n\nconst spk = ScriptPubKey.fromHex('76a9148b4912ec0496b5f759f3af5ab24d6f4779a52f9e88ac')\nspk instanceof btcnodejs.P2pkhScript         //true                             \n\n\n ```\n\n#### toAddress(network = undefined, segwitV = undefined)\n\n* **network : String**\n\n* **segwitV : Integer**\n\nReturns the p2sh/p2wsh address of the Script.\n* If network is not specified, the initial setup network will be considered as the address network.\n\n* If segwitV is specified, the address will be of type 'p2wsh', with segwitV value as the segwit version\n\n```javascript\nconst btcnodejs = require('btcnodejs')\nconst ScriptPubKey = btcnodejs.ScriptPubKey\nbtcnodejs.network.setup('testnet')\n\nconst spk = ScriptPubKey.fromHex('76a9148b4912ec0496b5f759f3af5ab24d6f4779a52f9e88ac')\nconst p2pkh_address = spk.toAddress()\np2pkh_address.hash          // \"029c09b86e1e4c3822bc71859af3300520d577c2\"\np2pkh_address.toBase58()    // \"2MsV2GNkfjxPjsp9ux2vwxW5HYaZh1HDtXJ\n\n\n ```\n\n## `btcnodejs.P2pkhScript`\n\nP2pkhScript object\n\n#### new P2pkhScript(source)\n\n* **source : Address object | Publickey object | ByteBuffer**\n\nReturns a P2pkhScript object. This can be obtained from an Address, a Publickey or a ByteBuffer representing a pubkeyhash\n\n#### Attributes\n\n* **type : String**\n\n* **pubkeyhash : ByteBuffer**\n\n#### getAddress()\n\nReturns an Address object representing the script Address\n\n## `btcnodejs.P2wpkhV0Script`\n\nSegwit version of P2pkhScript. It has the same interface of P2pkhScript but the source Address must be a Segwit Address object\n\n#### getScriptCode()\n\nReturns the ScriptCode of the P2wpkhV0Script\n\n## `btcnodejs.P2shScript`\n\nP2shScript object\n\n#### Attributes\n\n* **type : String**\n\n* **scripthash : ByteBuffer**\n\n#### new P2shScript(source)\n\n* **source : Address object | ScriptPubKey object | ByteBuffer**\n\nReturns a P2pkhScript object. This can be obtained from an Address, a ScriptPubKey or a ByteBuffer representing a scripthash\n\n#### getAddress()\n\nReturns an Address object representing the script Address\n\n## `btcnodejs.P2wshV0Script`\n\nSegwit version of P2shScript. It has the same interface of P2shScript but the source Address must be a Segwit Address object\n\n## `btcnodejs.IfElseScript`\n\nIfElseScript object\n\n\n#### new IfElseScript(source)\n\n* **source : Array of ScriptPubKey objects**\n\n\n#### Attributes\n\n* **type : String**\n\n* **if_script : ScriptPubKey object**\n\n* **else_script : ScriptPubKey object**\n\n\n```javascript\nconst btcnodejs = require('btcnodejs')\nbtcnodejs.network.setup('testnet')\n\nconst p2pkh = new btcnodejs.P2pkhScript(btcnodejs.Publickey.fromHex(\"026263992eda6538202047f1514e0f6155a229c3d61b066807664e9ef73d406d95\"))\nconst multisig = new btcnodejs.MultiSigScript([\n        2,\n        btcnodejs.Publickey.fromHex(\n          \"02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242\"\n        ),\n        btcnodejs.Publickey.fromHex(\n          \"033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f147eb4d069d\"\n        ),\n        btcnodejs.Publickey.fromHex(\n          \"036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a\"\n        ),\n        3\n      ])\nconst ie_script = new btcnodejs.IfElseScript([p2pkh, multisig])\n\n ```\n\n## `btcnodejs.RelativeTimelockScript`\n\nRelativeTimelockScript object\n\n#### new RelativeTimelockScript(source)\n\n* **source : Array[ScriptPubKey object, Sequence object]**\n\nReturns a RelativeTimelockScript object\n\n#### Attributes\n\n* **sequence : Sequence object**\n\n* **locked_script : ScriptPubKey object**\n\n* **type : String**\n\n## `btcnodejs.MultiSigScript`\n\nMultisigScript object\n\n#### new MultiSigScript(source)\n\n* **source : [m, Publickey_1, Publickey_2, ... , Publickey_n, n]**\n\nReturns a MultiSigScript object\n\n#### Attributes\n\n* **type : String**\n\n* **m : Integer**\n\n* **n : Integer**\n\n* **pubkeys : Array of Publickey objects**\n\n```javascript\nconst btcnodejs = require('btcnodejs')\nbtcnodejs.network.setup('testnet')\n\n//Creating a 2-of-3 Multisig Script\nconst multisig = new btcnodejs.MultiSigScript([\n        2,\n        btcnodejs.Publickey.fromHex(\n          \"02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242\"\n        ),\n        btcnodejs.Publickey.fromHex(\n          \"033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f147eb4d069d\"\n        ),\n        btcnodejs.Publickey.fromHex(\n          \"036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a\"\n        ),\n        3\n      ])\n\n\n ```\n\n## Solvers\n\nSolvers are objects which are able to compute the scriptSig and Witness from a given array of digests. They are an easy way to compute transaction input's signatures.\n\nThey all provide the method:\n#### solve(digests)\n\n* **digests : Array of digests**\n\nwhich returns an object :\n\n**{scriptSig : ScriptSig object , witness: Witness object}**\n\n```javascript\nconst btcnodejs = require('btcnodejs')\nbtcnodejs.network.setup('testnet')\n\nconst private_key = btcnodejs.Privatekey.fromHex('9b1b400e3b1211c6a56695cf1742f0a94ea38b995c1e1fb910458baa8a0874c4')\nconst p2pkh_solver = new btcnodejs.P2pkhSolver(private_key)\n\np2pkh_solver.solve([\"0e12bda8a692aefa29651e87af9f47127ab098be1c189284e41d8e17a0516add\"]).scriptSig.toHex()\n//\n'47304402202409f1f966c382f02e023ac828d7653e9268777bd1030e7101338f36a383fde302207ced2d14ff131d3b349bb00d3010a16f08831548e68750223cb8117cab553cab01210330e8ca46b7e5aa07d975ee152214431e419fac34e50becaf7e46db9a9c97d244'\n```\n\n## `btcnodejs.P2pkhSolver`\n\nSolver for P2pkh Scripts\n\n#### Attributes\n\n* **privkey : Privatekey object**\n\n* **sighash : Sighash object**\n\n#### new P2pkhSolver(privkey, sighash = new Sighash('ALL'))\n\nReturns a P2pkhSolver object\n\n```javascript\nconst btcnodejs = require('btcnodejs')\nbtcnodejs.network.setup('testnet')\n\nconst private_key = btcnodejs.Privatekey.fromHex('9b1b400e3b1211c6a56695cf1742f0a94ea38b995c1e1fb910458baa8a0874c4')\nconst p2pkh_solver = new btcnodejs.P2pkhSolver(private_key)\n\n```\n\n## `btcnodejs.P2wpkhV0Solver`\n\nSolver for P2wpkh version 0 scripts. It extends P2pkhSolver\n\n## `btcnodejs.P2shSolver`\n\nSolver for P2sh scripts\n\n#### Attributes\n\n* **redeemScript : ScriptPubKey object**\n\n* **redeemScriptSolver : Solver object**\n\n#### new P2shSolver(redeemScript, redeemScriptSolver)\n\n\n## `btcnodejs.P2wshV0Solver`\n\nSolver for P2wsh version 0 Scripts\n\n#### Attributes\n\n* **witnessScript : ScriptPubKey object**\n\n* **witnessScriptSolver : Solver object**\n\n#### new P2wshV0Solver(witnessScript, witnessScriptSolver)\n\n## `btcnodejs.MultiSigSolver`\n\nSolver for MultiSig Scripts\n\n#### Attributes\n\n* **privkeys : Array of Privatekey objects**\n\n* **sighashes : Array of Sighash objects**\n\n#### new MultiSigSolver(privkeys, sighashes = [new Sighash('ALL')])\n\nThe number of sigashes must be equal to the number of privatekeys.\n\n## `btcnodejs.IfElseSolver`\n\nSolver for If Else Scripts\n\n#### Attributes\n\n* **branch : Integer**\n\n* **innerSolver : Solver object**\n\n#### new IfElseSolver(branch, innerSolver)\n\n## `btcnodejs.RelativeTimelockSolver`\n\n#### Attributes\n\n* **innerSolver : Solver object**\n\n#### new RelativeTimelockSolver(innerSolver)\n\n## Crypto\n\nThe library provides structures and methods to handle Private and Public key objects\n\n## `btcnodejs.Privatekey`\n\n#### Attributes\n\n* **body : ByteBuffer**\n\n#### new Privatekey(bytebuffer)\n\nReturns a Privatekey object where the body is a bytebuffer representing the private key\n\n#### static fromHex(hex)\n\n* **hex : Hexadecimal String**\n\nReturns a Privatekey object from an hexadecimal string representing a private key\n\n#### toHex()\n\nReturns the Hexadecimal representation of the Privatekey\n\n#### serialize()\n\nReturns the body of the Privatekey\n\n#### getPublic(compressed = true)\n\n* **compressed : Boolean**\n\nReturns a Publickey object representing the public key associated with this Privatekey. By passing `compressed = false`, the public key will be of uncompressed type.\n\n#### sign(message)\n\n* **message : String**\n\nComputes the signature of a message, using the [elliptic](https://github.com/indutny/elliptic) nodejs library using the `secp256k1` curve.\n\n#### signDER(message)\n\nReturns the signature of the message in `DER` encoding\n\n#### toWIF(compressed = false)\n\nReturns the [Wallet import format](https://en.bitcoin.it/wiki/Wallet_import_format) string representing the private key. If `true` is passed in input, the WIF string will represent a private key associated with a compressed Publickey.\n\n#### fromWIF(wif_string)\n\n* **wif_string : String**\n\nReturn a Privatekey object from its Wallet import format string.\n\n#### fromBip32(bip32_string)\n\n* **bip32_string : String**\n\nReturns a Privatekey object from its Bip32 format string.\n\n## `btcnodejs.Publickey`\n\nPublickey object\n\n#### Attributes\n\n* **type: String**\n\n* **uncompressed : ByteBuffer**\n\n* **compressed : ByteBuffer**\n\n#### new Publickey(bytebuffer)\n\nReturns a Publickey object. Its type will be `odd`, `even`, `uncompressed` based on the the input bytebuffer data. It will keep both the uncompressed and compressed versions as its body, but its type will decide which version to use for any operation.\n\n#### hash()\n\nReturns the hash of the Publickey body.\n\n#### static fromHex(hex)\n\nReturns a Publickey object from its hexadecimal representation\n\n#### toHex(compressed = true)\n\nReturns the hexadecimal representation of its body. If `false` is passed as input it will return the hexadecimal representing its uncompressed version.\n\n#### toAddress(network = undefined, segwit = false)\n\n* **network : String**\n\n* **segwit : Boolean**\n\nReturns an Address object created from the Publickey hash.\n\n* If network is undefined, the first network name setup will be used.\n\n* If segwit is true, the Address type will be p2wpkh, otherwise it will be p2pkh\n\n#### serialize()\n\nReturns the Publickey body\n\n## HD\n\nThis library exposes functionalities to manage Hierarchical deterministic keys. It makes usage of [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib) for some functionalities\n\n## `btcnodejs.HDPrivateKey`\n\nHierarchical deterministic PrivateKey object\n\n#### Attributes\n\n* **privkey : Privatekey object**\n\n* **depth : Integer**\n\n* **fingerPrint : Integer**\n\n* **parentFingerPrint : Integer**\n\n* **childIndex : Integer**\n\n* **chainCode : String**\n\n* **checksum : Integer**\n\n* **xprivkey : String**\n\n#### new HDPrivateKey(source)\n\n* **source : String | undefined**\n\nReturns an HDPrivateKey object. If no parameter is given as input, a random HDPrivateKey is returned. Otherwise, a bip32 representation of an hd key can be passed\n\n#### derive(path)\n\n* **path : String**\n\nReturns a child HDPrivateKey derived as specified in BIP32. The path must be a string starting with 'm/'. To derive an hardened child, its index in the path is followed by `'` i.e derive('m/0'')\n\n#### getPublic()\n\nReturns the corresponding HDPublicKey\n\n#### static fromSeed(seed)\n\n* **seed : String**\n\nReturns a master HDPrivateKey generated from the hexadecimal string representing a seed\n\n## `btcnodejs.HDPublicKey`\n\nHierarchical deterministic Public key object\n\n#### Attributes\n\n* **pubkey : Privatekey object**\n\n* **depth : Integer**\n\n* **fingerPrint : Integer**\n\n* **parentFingerPrint : Integer**\n\n* **childIndex : Integer**\n\n* **chainCode : String**\n\n* **checksum : Integer**\n\n* **xpubkey : String**\n\n#### new HDPublicKey(source)\n\n* **source : String | undefined**\n\nReturns an HDPublicKey object. If no parameter is given as input, a random HDPublicKey is returned. Otherwise, a bip32 representation of an hd key can be passed.\n\n#### derive(path)\n\n* **path : String**\n\nReturns a child HDPublicKey derived as specified in BIP32.\n\n## Address\n\nThis library exposes functionalities to manage bitcoin addresses. It wraps [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib) for addresses encodings.\n\n## `btcnodejs.Address`\n\n#### Attributes\n\n* **network : String**\n\n* **type : String**\n\n* **hash : ByteBuffer**\n\n#### new Address(type, hash, network = undefined)\n\nReturns an Address object. If network is not specified, the first setup network name will be used.\n\n#### static fromBase58(base58string)\n\nReturns an Address object from its base58 encoding\n\n#### toBase58()\n\nReturns a Base58 encoded string representing the bitcoin address\n\n## `btcnodejs.SegwitAddress`\n\nSegwitAddress object extending Address. It has an extra `version` attribute specifying the segwit version.\n\n#### Attributes\n\n* **version : Integer**\n\n#### static fromBech32(bech32string)\n\nReturns a Segwit Address object from its bech32 encoding\n\n#### toBech32()\n\nReturns a Bech32 encoded string representing the bitcoin Segwit address\n\n## Block\n\n## `btcnodejs.BlockHeader`\n\nBlockHeader object\n\n#### Attributes\n\n* **version : Integer**\n\n* **prev_block : String**\n\n* **merkle_root : String**\n\n* **timestamp : Integer**\n\n* **bits : Integer**\n\n* **nonce : Integer**\n\n#### new BlockHeader(version, prev_block, merkle_root, timestamp, bits, nonce)\n\nReturns a BlockHeader objects\n\n#### static fromHex(hex)\n\nReturns a BlockHeader object from an hexadecimal string representing the associated BlockHeader\n\n#### serialize()\n\nReturns a ByteBuffer representing the serialized BlockHeader\n\n#### blockHash()\n\nReturns an hexadecimal string representing the hash of the associated Block\n\n## TODO\n\n* Expand the test vectors\n\n* Add docstrings to code\n\n* Manage Block and MerkleBlock structures\n\n* Add caching in segwit digests computation\n\n* Add further helpers for creating transactions\n\n* Implement the functionalities which are now wrappings around external libraries\n\n* Manage `OP_CODESEPARATOR` in transaction signatures\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainside%2Fbtcnodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchainside%2Fbtcnodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainside%2Fbtcnodejs/lists"}