Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@liquality/bitcoin-utils

Package Overview
Dependencies
Maintainers
4
Versions
190
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liquality/bitcoin-utils - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

148

dist/index.cjs.js

@@ -1,2 +0,146 @@

module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}([function(e,t){e.exports=require("@liquality/crypto")},function(e,t){e.exports=require("@liquality/bitcoin-networks")},function(e){e.exports={a:"0.2.0"}},function(e,t){e.exports=require("lodash")},function(e,t,r){"use strict";r.r(t),r.d(t,"calculateFee",function(){return i}),r.d(t,"toHexInt",function(){return h}),r.d(t,"compressPubKey",function(){return s}),r.d(t,"pubKeyToAddress",function(){return a}),r.d(t,"pubKeyHashToAddress",function(){return d}),r.d(t,"addressToPubKeyHash",function(){return l}),r.d(t,"reverseBuffer",function(){return b}),r.d(t,"scriptNumEncode",function(){return p}),r.d(t,"getAddressNetwork",function(){return g});var n=r(3),u=r(0),o=r(1),c=r.n(o),f=r(2);function i(e,t,r){return(148*e+34*t+10)*r}function s(e){const t=e.substring(2,66),r=e.substring(66,130);return(parseInt(r.substring(62,64),16)%2==0?"02":"03")+t}function a(e,t,r){return e=Object(u.ensureBuffer)(e),d(Object(u.hash160)(e),t,r)}function d(e,t,r){e=Object(u.ensureBuffer)(e);const n=Buffer.concat([Buffer.from(c.a[t][r],"hex"),e]),o=Buffer.from(Object(u.sha256)(Object(u.sha256)(n)).slice(0,8),"hex");return u.base58.encode(Buffer.concat([n,o]).slice(0,25))}function l(e){return u.base58.decode(e).toString("hex").substring(2,42)}function b(e){let t=Buffer.alloc(e.length);for(let r=0,n=e.length-1;r<=n;++r,--n)t[r]=e[n],t[n]=e[r];return t}function p(e){let t=Math.abs(e),r=(n=t)>2147483647?5:n>8388607?4:n>32767?3:n>127?2:n>0?1:0;var n;let u=Buffer.allocUnsafe(r),o=e<0;for(let e=0;e<r;++e)u.writeUInt8(255&t,e),t>>=8;return 128&u[r-1]?u.writeUInt8(o?128:0,r-1):o&&(u[r-1]|=128),u}function y(e){return"0123456789abcdef".charAt(e>>4)+"0123456789abcdef".charAt(15&e)}function h(e){return y(e>>24&255)+y(e>>16&255)+y(e>>8&255)+y(255&e)}function g(e){const t=u.base58.decode(e).toString("hex").substring(0,2).toUpperCase(),r=Object(n.findKey)(c.a,e=>[e.pubKeyHash,e.scriptHash].includes(t));return c.a[r]}r.d(t,"version",function(){return f.a})}]);
//# sourceMappingURL=index.cjs.js.map
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./lib/index.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./lib/index.js":
/*!**********************!*\
!*** ./lib/index.js ***!
\**********************/
/*! exports provided: calculateFee, toHexInt, compressPubKey, pubKeyToAddress, pubKeyHashToAddress, addressToPubKeyHash, reverseBuffer, scriptNumEncode, getAddressNetwork, version */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"calculateFee\", function() { return calculateFee; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"toHexInt\", function() { return toHexInt; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"compressPubKey\", function() { return compressPubKey; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"pubKeyToAddress\", function() { return pubKeyToAddress; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"pubKeyHashToAddress\", function() { return pubKeyHashToAddress; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"addressToPubKeyHash\", function() { return addressToPubKeyHash; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"reverseBuffer\", function() { return reverseBuffer; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"scriptNumEncode\", function() { return scriptNumEncode; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getAddressNetwork\", function() { return getAddressNetwork; });\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ \"lodash\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _liquality_crypto__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @liquality/crypto */ \"@liquality/crypto\");\n/* harmony import */ var _liquality_crypto__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_liquality_crypto__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _liquality_bitcoin_networks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @liquality/bitcoin-networks */ \"@liquality/bitcoin-networks\");\n/* harmony import */ var _liquality_bitcoin_networks__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_liquality_bitcoin_networks__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _package_json__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../package.json */ \"./package.json\");\nvar _package_json__WEBPACK_IMPORTED_MODULE_3___namespace = /*#__PURE__*/__webpack_require__.t(/*! ../package.json */ \"./package.json\", 1);\n/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, \"version\", function() { return _package_json__WEBPACK_IMPORTED_MODULE_3__[\"version\"]; });\n\n\n\n\n\n\nfunction calculateFee(numInputs, numOutputs, feePerByte) {\n return (numInputs * 148 + numOutputs * 34 + 10) * feePerByte;\n}\n/**\n * Get compressed pubKey from pubKey.\n * @param {!string} pubKey - 65 byte string with prefix, x, y.\n * @return {string} Returns the compressed pubKey of uncompressed pubKey.\n */\n\n\nfunction compressPubKey(pubKey) {\n const x = pubKey.substring(2, 66);\n const y = pubKey.substring(66, 130);\n const even = parseInt(y.substring(62, 64), 16) % 2 === 0;\n const prefix = even ? '02' : '03';\n return prefix + x;\n}\n/**\n * Get address from pubKey.\n * @param {!string|Buffer} pubKey - 65 byte uncompressed pubKey or 33 byte compressed pubKey.\n * @param {!string} network - bitcoin, testnet, or litecoin.\n * @param {!string} type - pubKeyHash or scriptHash.\n * @return {string} Returns the address of pubKey.\n */\n\n\nfunction pubKeyToAddress(pubKey, network, type) {\n pubKey = Object(_liquality_crypto__WEBPACK_IMPORTED_MODULE_1__[\"ensureBuffer\"])(pubKey);\n const pubKeyHash = Object(_liquality_crypto__WEBPACK_IMPORTED_MODULE_1__[\"hash160\"])(pubKey);\n const addr = pubKeyHashToAddress(pubKeyHash, network, type);\n return addr;\n}\n/**\n * Get address from pubKeyHash.\n * @param {!string} pubKeyHash - hash160 of pubKey.\n * @param {!string} network - bitcoin, testnet, or litecoin.\n * @param {!string} type - pubKeyHash or scriptHash.\n * @return {string} Returns the address derived from pubKeyHash.\n */\n\n\nfunction pubKeyHashToAddress(pubKeyHash, network, type) {\n pubKeyHash = Object(_liquality_crypto__WEBPACK_IMPORTED_MODULE_1__[\"ensureBuffer\"])(pubKeyHash);\n const prefixHash = Buffer.concat([Buffer.from(_liquality_bitcoin_networks__WEBPACK_IMPORTED_MODULE_2___default.a[network][type], 'hex'), pubKeyHash]);\n const checksum = Buffer.from(Object(_liquality_crypto__WEBPACK_IMPORTED_MODULE_1__[\"sha256\"])(Object(_liquality_crypto__WEBPACK_IMPORTED_MODULE_1__[\"sha256\"])(prefixHash)).slice(0, 8), 'hex');\n const addr = _liquality_crypto__WEBPACK_IMPORTED_MODULE_1__[\"base58\"].encode(Buffer.concat([prefixHash, checksum]).slice(0, 25));\n return addr;\n}\n/**\n * Get pubKeyHash from address.\n * @param {!string} address - bitcoin base58 encoded address.\n * @return {string} Returns the pubKeyHash of bitcoin address.\n */\n\n\nfunction addressToPubKeyHash(address) {\n return _liquality_crypto__WEBPACK_IMPORTED_MODULE_1__[\"base58\"].decode(address).toString('hex').substring(2, 42);\n}\n\nfunction reverseBuffer(src) {\n let buffer = Buffer.alloc(src.length);\n\n for (let i = 0, j = src.length - 1; i <= j; ++i, --j) {\n buffer[i] = src[j];\n buffer[j] = src[i];\n }\n\n return buffer;\n}\n\nfunction scriptNumSize(i) {\n return i > 0x7fffffff ? 5 : i > 0x7fffff ? 4 : i > 0x7fff ? 3 : i > 0x7f ? 2 : i > 0x00 ? 1 : 0;\n}\n\nfunction scriptNumEncode(number) {\n let value = Math.abs(number);\n let size = scriptNumSize(value);\n let buffer = Buffer.allocUnsafe(size);\n let negative = number < 0;\n\n for (let i = 0; i < size; ++i) {\n buffer.writeUInt8(value & 0xff, i);\n value >>= 8;\n }\n\n if (buffer[size - 1] & 0x80) {\n buffer.writeUInt8(negative ? 0x80 : 0x00, size - 1);\n } else if (negative) {\n buffer[size - 1] |= 0x80;\n }\n\n return buffer;\n}\n\nfunction toHexDigit(number) {\n const digits = '0123456789abcdef';\n return digits.charAt(number >> 4) + digits.charAt(number & 0x0f);\n}\n\nfunction toHexInt(number) {\n return toHexDigit(number >> 24 & 0xff) + toHexDigit(number >> 16 & 0xff) + toHexDigit(number >> 8 & 0xff) + toHexDigit(number & 0xff);\n}\n/**\n * Get a network object from an address\n * @param {string} address The bitcoin address\n * @return {Network}\n */\n\n\nfunction getAddressNetwork(address) {\n const prefix = _liquality_crypto__WEBPACK_IMPORTED_MODULE_1__[\"base58\"].decode(address).toString('hex').substring(0, 2).toUpperCase();\n const networkKey = Object(lodash__WEBPACK_IMPORTED_MODULE_0__[\"findKey\"])(_liquality_bitcoin_networks__WEBPACK_IMPORTED_MODULE_2___default.a, network => [network.pubKeyHash, network.scriptHash].includes(prefix));\n return _liquality_bitcoin_networks__WEBPACK_IMPORTED_MODULE_2___default.a[networkKey];\n}\n\n\n\n//# sourceURL=webpack:///./lib/index.js?");
/***/ }),
/***/ "./package.json":
/*!**********************!*\
!*** ./package.json ***!
\**********************/
/*! exports provided: name, umdName, version, description, module, main, files, scripts, author, license, dependencies, engines, homepage, repository, bugs, publishConfig, gitHead, default */
/***/ (function(module) {
eval("module.exports = {\"name\":\"@liquality/bitcoin-utils\",\"umdName\":\"BitcoinUtils\",\"version\":\"0.2.3\",\"description\":\"\",\"module\":\"lib/index.js\",\"main\":\"dist/index.cjs.js\",\"files\":[\"dist\",\"lib\"],\"scripts\":{\"build:node\":\"webpack --config ../../webpack/webpack.node.config.js\",\"build:browser\":\"webpack --config ../../webpack/webpack.browser.config.js\",\"build\":\"webpack --config ../../webpack/webpack.config.js\"},\"author\":\"Liquality <info@liquality.io>\",\"license\":\"MIT\",\"dependencies\":{\"@babel/runtime\":\"^7.4.3\",\"@liquality/bitcoin-networks\":\"^0.2.3\",\"@liquality/crypto\":\"^0.2.3\",\"lodash\":\"^4.17.11\"},\"engines\":{\"node\":\"~8.12.0\"},\"homepage\":\"https://github.com/liquality/chainabstractionlayer#readme\",\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/liquality/chainabstractionlayer.git\"},\"bugs\":{\"url\":\"https://github.com/liquality/chainabstractionlayer/issues\"},\"publishConfig\":{\"access\":\"public\"},\"gitHead\":\"23bd372c089ee6a5e7b0cd10672ba1b5ed03e4ba\"};\n\n//# sourceURL=webpack:///./package.json?");
/***/ }),
/***/ "@liquality/bitcoin-networks":
/*!**********************************************!*\
!*** external "@liquality/bitcoin-networks" ***!
\**********************************************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("module.exports = require(\"@liquality/bitcoin-networks\");\n\n//# sourceURL=webpack:///external_%22@liquality/bitcoin-networks%22?");
/***/ }),
/***/ "@liquality/crypto":
/*!************************************!*\
!*** external "@liquality/crypto" ***!
\************************************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("module.exports = require(\"@liquality/crypto\");\n\n//# sourceURL=webpack:///external_%22@liquality/crypto%22?");
/***/ }),
/***/ "lodash":
/*!*************************!*\
!*** external "lodash" ***!
\*************************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("module.exports = require(\"lodash\");\n\n//# sourceURL=webpack:///external_%22lodash%22?");
/***/ })
/******/ });

8

package.json
{
"name": "@liquality/bitcoin-utils",
"umdName": "BitcoinUtils",
"version": "0.2.2",
"version": "0.2.3",
"description": "",

@@ -21,4 +21,4 @@ "module": "lib/index.js",

"@babel/runtime": "^7.4.3",
"@liquality/bitcoin-networks": "^0.2.2",
"@liquality/crypto": "^0.2.2",
"@liquality/bitcoin-networks": "^0.2.3",
"@liquality/crypto": "^0.2.3",
"lodash": "^4.17.11"

@@ -40,3 +40,3 @@ },

},
"gitHead": "68759c7523db17caa03f0129c18d0bc472810e5d"
"gitHead": "23bd372c089ee6a5e7b0cd10672ba1b5ed03e4ba"
}

@@ -29,4 +29,4 @@ # `@liquality/bitcoin-utils` <img align="right" src="https://raw.githubusercontent.com/liquality/chainabstractionlayer/master/liquality-logo.png" height="80px" />

```html
<script src="https://cdn.jsdelivr.net/npm/@liquality/bitcoin-utils@0.2.2/dist/bitcoin-utils.min.js"></script>
<!-- sourceMap at https://cdn.jsdelivr.net/npm/@liquality/bitcoin-utils@0.2.2/dist/bitcoin-utils.min.js.map -->
<script src="https://cdn.jsdelivr.net/npm/@liquality/bitcoin-utils@0.2.3/dist/bitcoin-utils.min.js"></script>
<!-- sourceMap at https://cdn.jsdelivr.net/npm/@liquality/bitcoin-utils@0.2.3/dist/bitcoin-utils.min.js.map -->
<!-- available as window.BitcoinUtils -->

@@ -33,0 +33,0 @@ ```

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc