{"_id":"@biut-block/biutjs-util","_rev":"2-3611bac4812e63d8e712cd0785276875","name":"@biut-block/biutjs-util","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@biut-block/biutjs-util","version":"1.0.0","description":"a collection of utility functions for BIUT Block","main":"src/index.js","scripts":{"lint":"standard","test":"mocha test/test.js","prepublishOnly":"npm run lint"},"repository":{"type":"git","url":"git+https://github.com/BIUT-Block/biutjs-util.git"},"keywords":["biut","utilties"],"author":"","license":"MPL-2.0","bugs":{"url":"https://github.com/BIUT-Block/biutjs-util/issues"},"homepage":"https://github.com/BIUT-Block/biutjs-util","dependencies":{"bip39":"^2.5.0","bn.js":"^4.11.0","bs58":"^4.0.1","create-hash":"^1.1.2","ethjs-util":"^0.1.6","keccak":"^1.0.2","rlp":"^2.1.0","safe-buffer":"^5.1.1","secp256k1":"3.6.1","strip-hex-prefix":"^1.0.0"},"devDependencies":{"babel-cli":"^6.26.0","babel-preset-env":"^1.6.1","babelify":"^8.0.0","browserify":"^14.0.0","chai":"^4.1.2","contributor":"^0.1.25","coveralls":"^3.0.2","documentation":"^5.2.0","istanbul":"^0.4.1","karma":"^2.0.5","karma-browserify":"^5.3.0","karma-chrome-launcher":"^2.0.0","karma-detect-browsers":"2.2.6","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.0.0","karma-mocha":"^1.3.0","mocha":"^5.2.0","standard":"^11.0.1"},"standard":{"globals":["describe","it"],"ignore":["dist/**"]},"gitHead":"479145775c5bf489cda6deb939385a867345dadd","_id":"@biut-block/biutjs-util@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.4","_npmUser":{"name":"zuweihan1992","email":"zuweihan1992@gmail.com"},"dist":{"integrity":"sha512-VAhtKkRG7YVvtdAvUDoAUIN5i6tSLflx92BfKCaNwhW9LLBfR1/Crb9HDqcMRZxM/LOppJVEnZUnEdHUiYQ7qw==","shasum":"2a3f0f9284ad50f9b7c2ed0e036dd90960aa3e3e","tarball":"https://registry.npmjs.org/@biut-block/biutjs-util/-/biutjs-util-1.0.0.tgz","fileCount":4,"unpackedSize":77479,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc1T+1CRA9TVsSAnZWagAAw/UQAJf0TIoiR6RIcVFcFGax\n0fGx4E01QxIrJy1Gb7q2IiuIDXnpBPPTSu0S//MMSxYmruRX8RQ716D/LGqC\nmkayRvYccnM2bmm4ZV3KwqfOeQoZNdpDhYVhF5kVNvC38+gm28HdJKPXmQgc\nfeNa0hLZyHo4w/idTrXfhZS0KjtxVzjintCcrJAvGYqNB/gtXKmhG0s9a/Ol\njYUIuZ3qa1V4M9XJKlcz5xIxo37cL4SAEbgWhHztYzAuXC1m9ZCLLTKi8enn\nfj8b5TOL1ECo74Sy7P7/YNQhBC4+WvrgyaG7RbKhACMloewGMJ0oH6IuaPy8\nXt+/vVPfegYiWwvt79TXqFzBKJynD/r49zbtJg2UybcRR8xrGFYQXYISdFBI\nbFArbtiSIQZNVmZSmtWCxQiSsGn6Vej7J1fQB/Z6qnIeJszcnby0ZC6TlZTv\nw/lnNb1eq5xWnnSzUpBY84JnyHHXLl0xo+CyrhaZLIe3s7C//bp3ZE5yipC6\ny/euKKs4UmBOFvu4jJhS720RVQ3nBqQH/yuUmU85lYSYSMYb6FbzXJNTc77W\nB/dZ+ah4LaCH3B/QhlU6Gnhn3QlOqf04qgtUhOHsuEDzFAZq0ekwNQFMiBuh\n+C2itz5y0l5mLdu1bbEp5bQZdKDoFW+Vh28arOXbeQrDZmVztzMIz8q1+FER\nqXbQ\r\n=kksv\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHo8fqghNUMr82R8yqnuEbnN/BDlvXIS6PhS33APapSWAiAZlJ0yyOROwmMEkONUq7j4mAljowdXUSWGcdr7dtOgmQ=="}]},"maintainers":[{"name":"zuweihan1992","email":"zuweihan1992@gmail.com"},{"name":"tornadoming","email":"ming1992liu@gmail.com"},{"name":"g277321","email":"g277321@gmail.com"},{"name":"feiminhao","email":"fei.minhao1990@gmail.com"},{"name":"abysmli","email":"abysmli@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/biutjs-util_1.0.0_1557479348426_0.42680465347819907"},"_hasShrinkwrap":false},"1.0.2":{"name":"@biut-block/biutjs-util","version":"1.0.2","description":"a collection of utility functions for BIUT Block","main":"src/index.js","scripts":{"lint":"standard","test":"mocha test/test.js","prepublishOnly":"npm run lint"},"repository":{"type":"git","url":"git+https://github.com/BIUT-Block/biutjs-util.git"},"keywords":["biut","utilties"],"author":"","license":"MPL-2.0","bugs":{"url":"https://github.com/BIUT-Block/biutjs-util/issues"},"homepage":"https://github.com/BIUT-Block/biutjs-util","dependencies":{"bip39":"^2.5.0","bn.js":"^4.11.0","bs58":"^4.0.1","create-hash":"^1.1.2","ethjs-util":"^0.1.6","keccak":"^1.0.2","rlp":"^2.1.0","safe-buffer":"^5.2.0","secp256k1":"3.6.1","strip-hex-prefix":"^1.0.0"},"devDependencies":{"babel-cli":"^6.26.0","babel-preset-env":"^1.6.1","babelify":"^8.0.0","browserify":"^14.0.0","chai":"^4.1.2","contributor":"^0.1.25","coveralls":"^3.0.6","documentation":"^5.2.0","istanbul":"^0.4.1","karma":"^2.0.5","karma-browserify":"^5.3.0","karma-chrome-launcher":"^2.0.0","karma-detect-browsers":"2.2.6","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.2.0","karma-mocha":"^1.3.0","mocha":"^5.2.0","standard":"^11.0.1"},"standard":{"globals":["describe","it"],"ignore":["dist/**"]},"gitHead":"a35f24ad939636d58f80dbeed0ddecad3e142b1c","_id":"@biut-block/biutjs-util@1.0.2","_npmVersion":"5.6.0","_nodeVersion":"8.11.4","_npmUser":{"name":"zuweihan1992","email":"zuweihan1992@gmail.com"},"dist":{"integrity":"sha512-bujA4kpOdcsecAgvK4oiO5OeqDwB8ivX8wUqR6zWYui+w+/nkcXqvcByv6YUJhMtgFxHiXrVCH1OsVwEocU2Vw==","shasum":"e2b05138a262b828997afcab34262245ab25c298","tarball":"https://registry.npmjs.org/@biut-block/biutjs-util/-/biutjs-util-1.0.2.tgz","fileCount":4,"unpackedSize":78423,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdnMyPCRA9TVsSAnZWagAAFJcQAIi6tkFb7z09qRsa7PDU\nEPFnMJ2CklZz2szW6X/4IlRye/+5KRLzaw+d5Bra1CTW2z9OC+RXcV/96cZz\nlJpcef3005J7OahMyS4XPUPZDkiPzWdpfK8qXCUWquEXpELVLrGPP5WeZZPL\nrtaf65jc92JYbFbC8PgffIYwjNPKn5hJvNPxLtk4Qdh1W7LY5oCRIq8Xe04o\n4Sjt/S26eMbDfF3PhHzNwrVsx9b/7YgFcfCUJfFdnas9/v42shSW19LwCU42\nF5js51Q2lpezfd2gkRGpxjCSB8FVB4QLcpra7MWG2Ac5+7+0BHqyUI5MGxvw\nIjSy2D2xTp+tswxE9uraPFVS8Qu378MjL9lQl0ZyrwwR2hEURwRmT5NbYYwl\n7lxTQl+TxSBAXtglNEt1pPAKaFXsoDxSRXWJvu3fot3uI6ZR/wMjoZBWkVPJ\n3HszgFUbzkEqnHZ93+/s+x33gV3fmdSlHPb657dN4TCwPVWZPSa0ThZ8oaTe\nKWfCK9AWA6W+JuHwFDl/8mQx37+DynApkCbZHieNQmc71dO24iLzyAbHdfLd\nIhEc4QNNvitwzuPvd0LWI197OcRiBVX7KIm6899xCyXhXMjEUZhO9J+a+8kp\nDTuvT17wu0NPxrs3ZX2WHY5epw9l9uQH7wr7T5JYISl824KosS7KocYW9XbD\nZeme\r\n=012I\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDQe3pkKSP+ab9y3eY+s93iealC5jSprtEPJE8uqLs1zwIgaWytaNeoB07Ckttu25FPm7pSgFKttEXkjvhyGh6NL6g="}]},"maintainers":[{"name":"abysmli","email":"abysmli@gmail.com"},{"name":"feiminhao","email":"fei.minhao1990@gmail.com"},{"name":"g277321","email":"g277321@gmail.com"},{"name":"tornadoming","email":"ming1992liu@gmail.com"},{"name":"zuweihan1992","email":"zuweihan1992@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/biutjs-util_1.0.2_1570557070953_0.851794173501339"},"_hasShrinkwrap":false}},"time":{"created":"2019-05-10T09:09:08.240Z","1.0.0":"2019-05-10T09:09:08.564Z","modified":"2022-04-04T19:14:54.040Z","1.0.2":"2019-10-08T17:51:11.078Z"},"maintainers":[{"name":"abysmli","email":"abysmli@gmail.com"},{"name":"feiminhao","email":"fei.minhao1990@gmail.com"},{"name":"g277321","email":"g277321@gmail.com"},{"name":"tornadoming","email":"ming1992liu@gmail.com"},{"name":"zuweihan1992","email":"zuweihan1992@gmail.com"}],"description":"a collection of utility functions for BIUT Block","homepage":"https://github.com/BIUT-Block/biutjs-util","keywords":["biut","utilties"],"repository":{"type":"git","url":"git+https://github.com/BIUT-Block/biutjs-util.git"},"bugs":{"url":"https://github.com/BIUT-Block/biutjs-util/issues"},"license":"MPL-2.0","readme":"<a name=\"SecUtils\"></a>\r\n\r\n* * *\r\n## SecUtils\r\n[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard) \r\n\r\n**Definition**: \r\nA collection of utility functions for secblock. It can be used in node.js or can be in the browser with browserify. -->\r\n\r\n**Kind**: global class\r\n* [SecUtils](#SecUtils)\r\n    * [.currentUnixTimeSecond()](#currentUnixTimeSecond)\r\n    * [.currentUnixTimeInMillisecond()](#currentUnixTimeInMillisecond)\r\n    * [.getDatetime()](#getDatetime) \r\n    * [.getUnixtime()](#getUnixtime)\r\n    * [.asyncGetUTCTimeFromServer()](#asyncGetUTCTimeFromServer) \r\n    * [.refreshTimeDifference(callback)](#refreshTimeDifference)\r\n    * [.hasha256(data)](#secUtil+hasha256)\r\n    * [.generatePrivateKey()](#secUtil+generatePrivateKey)\r\n    * [.generatePublicKey(key, addrVer)](#secUtil+generatePublicKey)\r\n    * [.generateAddress(publicKey, addrVer)](#secUtil+generateAddress)\r\n    * [.getPrivateKey()](#secUtil+getPrivateKey)\r\n    * [.generateContractAddress(from, nonce)](#generateContractAddress)\r\n    * [.defineProperties(self, fields, data)](#defineProperties)\r\n    * [.padToEven(value)](#padToEven)    \r\n    * [.toBuffer(v)](#toBuffer)\r\n    * [.baToJSON(ba)](#baToJSON)\r\n    * [.stripZeros(a)](#stripZeros)    \r\n    * [.unpad(a)](#unpad)\r\n    * [.isHexString(value, length)](#isHexString)\r\n    * [.intToBuffer(i)](#intToBuffer)    \r\n    * [.intToHex(i)](#intToHex)\r\n    * [.rlphash(a)](#rlphash)\r\n    * [.keccak(a, bits)](#keccak)    \r\n    * [.zeros(bytes)](#zeros)\r\n    * [.getBinarySize(str)](#getBinarySize)    \r\n    * [.arrayContainsArray(superset, subset, some)](#arrayContainsArray)\r\n    * [.toUtf8(hex)](#toUtf8)\r\n    * [.toAscii(hex)](#toAscii)    \r\n    * [.fromUtf8(stringValue)](#fromUtf8)\r\n    * [.fromAscii(stringValue)](#fromAscii)\r\n    * [.getKeys(params, key, allowEmpty)](#getKeys)    \r\n    * [.bufferToHex(buf)](#bufferToHex)\r\n    * [.zeroAddress()](#zeroAddress)\r\n    * [.setLengthLeft(msg, length, right)](#setLengthLeft)    \r\n    * [.setLength(msg, length, right)](#setLength)\r\n    * [.setLengthRight(msg, length)](#setLengthRight)\r\n    * [.bufferToInt(buf)](#bufferToInt)    \r\n    * [.fromSigned(num)](#fromSigned)\r\n    * [.toUnsigned(num)](#toUnsigned)\r\n    * [.keccak256(a)](#keccak256)    \r\n    * [.sha3()](#sha3)\r\n    * [.sha256()](#sha256)\r\n    * [.ripemd160(a, padded)](#ripemd160)    \r\n    * [.isValidPrivate(privateKey)](#isValidPrivate)\r\n    * [.isValidPublic(publicKey, sanitize)](#isValidPublic)\r\n    * [.publicToAddress(pubKey, sanitize)](#publicToAddress)    \r\n    * [.privateToPublic(privateKey)](#privateToPublic)\r\n    * [.importPublic(publicKey)](#importPublic)\r\n    * [.ecsign(msgHash,privatekey)](#ecsign)    \r\n    * [.hashPersonalMessage(message)](#hashPersonalMessage)\r\n    * [.ecrecover(msghash,v,r,s)](#ecrecover)\r\n    * [.toRpcSig(v,r,s)](#toRpcSig)    \r\n    * [.fromRpcSig(sig)](#fromRpcSig)\r\n    * [.privateToAddress(privateKey)](#privateToAddress)\r\n    * [.isValidAddress(address)](#isValidAddress)\r\n    * [.isZeroAddress(address)](#isZeroAddress)\r\n    * [.toChecksumAddress(address)](#toChecksumAddress)\r\n    * [.isValidChecksumAddress(address)](#isValidChecksumAddress)\r\n    * [.isPrecompiled(address)](#isPrecompiled)\r\n    * [.addHexPrefix(str)](#addHexPrefix)\r\n    * [.isValidSignature(v, r, s, homestead)](#isValidSignature)\r\n    * [.stripHexPrefix(str)](#stripHexPrefix)\r\n\r\n* * *\r\n**Install**\r\n```js\r\nnpm install @biut-block/biutjs-util --save \r\n```\r\n\r\n**Usage**\r\n```js\r\nclass SecUtils {\r\n    ...\r\n    func1()\r\n    func2()\r\n    ...\r\n}\r\nconst util = new SecUtils() \r\nutil.func1()           \r\n```\r\n\r\n* * *\r\n<a name=\"currentUnixTimeSecond\"></a>\r\n\r\n### currentUnixTimeSecond\r\nA utility function of getting a Unix timestamp in second.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.currentUnixTimeSecond()\r\n```\r\n* * *\r\n<a name=\"currentUnixTimeInMillisecond\"></a>\r\n\r\n### currentUnixTimeInMillisecond\r\nA utility function of getting a Unix timestamp in millisecond.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.currentUnixTimeInMillisecond()\r\n```\r\n\r\n* * *\r\n<a name=\"getDatetime\"></a>\r\n\r\n### getDatetime\r\nA utility function of converting a standard GMT time to a Unix timestamp.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.getDatetime()\r\n```\r\n* * *\r\n<a name=\"getUnixtime\"></a>\r\n\r\n### getUnixtime\r\nA utility function of converting a Unix timestamp to a standard GMT time.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.getUnixtime()\r\n```\r\n\r\n* * *\r\n<a name=\"asyncGetUTCTimeFromServer\"></a>\r\n\r\n### asyncGetUTCTimeFromServer\r\nA utility function of get utc time from ntp server.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.asyncGetUTCTimeFromeServer().then(callback).catch(err)\r\n```\r\n\r\n* * *\r\n<a name=\"refreshTimeDifference\"></a>\r\n\r\n### refreshTimeDifference\r\nA utility function to refresh the time difference between local host and ntp server.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.refreshTimeDifference( (err, timeDiff) => {\r\n    if (err) {\r\n        console.log(err)\r\n    }\r\n    console.log(timeDiff)\r\n})\r\n```\r\n\r\n* * *\r\n<a name=\"secUtil+hasha256\"></a>\r\n\r\n### hasha256(data)\r\nA small function created as there is a lot of sha256 hashing.\r\n\r\n**Kind**: instance method of [<code>secUtil</code>](#secUtil)  \r\n\r\n| Param | Type | Description |\r\n| --- | --- | --- |\r\n| data | <code>Buffer</code> | creat sha256 hash buffer |\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.hasha256(data)\r\n```\r\n* * *\r\n<a name=\"secUtil+generatePrivateKey\"></a>\r\n\r\n### generatePrivateKey()\r\n0x00 P2PKH Mainnet, 0x6f P2PKH Testnet\r\n0x80 Mainnet, 0xEF Testnet （or Test Network: 0x6f and Namecoin Net:0x34）\r\ngenerate private key through sha256 random values. and translate to hex\r\nget usedful private key. It will be used for secp256k1\r\ngenerate check code. two times SHA256 at privatKey.\r\nbase58(privat key + the version number + check code).\r\nit is used as WIF(Wallet import Format) privatKey\r\n\r\n**Kind**: instance method of [<code>secUtil</code>](#secUtil) \r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.generatePrivateKey()\r\n``` \r\n* * *\r\n<a name=\"secUtil+generatePublicKey\"></a>\r\n\r\n### generatePublicKey(key, addrVer)\r\ngenerate public key\r\n\r\n**Kind**: instance method of [<code>secUtil</code>](#secUtil)  \r\n\r\n| Param | Type | Description |\r\n| --- | --- | --- |\r\n| key | <code>Buffer</code> |  |\r\n| addrVer | <code>Buffer</code> | input addVer from generatePrivateKey() set elliptic point and x,y axis not sure whether useful let x = pubPoint.getX() let y = pubPoint.getY() use secp256k1. generate public key structe public key: 1(network ID) + 32bytes(from x axis) + 32bytes(from y axis) ripemd160(sha256(public key)) |\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.generatePublicKey(key, addrVer)\r\n``` \r\n* * *\r\n<a name=\"secUtil+generateAddress\"></a>\r\n\r\n### generateAddress(publicKey, addrVer)\r\ndouble sha256 generate hashExtRipe2. sha256(sha256(version number + hashBuffer)).\r\nthe first 4 bytes of hashExtRipe2 are used as a checksum and placed at the end of\r\nthe 21 byte array. structe secBinary: 1(network ID) + concatHash + 4 byte(checksum)\r\n\r\n**Kind**: instance method of [<code>secUtil</code>](#secUtil)  \r\n\r\n| Param | Type | Description |\r\n| --- | --- | --- |\r\n| publicKey | <code>Buffer</code> | input public key from generatePublicKey() |\r\n| addrVer | <code>Buffer</code> | input addVer from generatePrivateKey() generate WIF private key and translate to hex generate SEC Address and translate to hex |\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.generateAddress(publicKey, addrVer)\r\n``` \r\n* * *\r\n<a name=\"secUtil+getPrivateKey\"></a>\r\n\r\n### getPrivateKey()\r\nreturn four private key, wif private key, public key\r\nand sec address\r\n\r\n**Kind**: instance method of [<code>secUtil</code>](#secUtil)  \r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.getPrivateKey()\r\n``` \r\n* * *\r\n### generateContractAddress\r\nA utility function of generating an address of a newly created contract\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.generateContractAddress(from, nonce)\r\n```\r\n\r\n<a name=\"defineProperties\"></a>\r\n* * *\r\n### defineProperties\r\nA utility function of generating an address of a newly created contract\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.defineProperties(from, nonce)\r\n```\r\n* * *\r\n<a name=\"padToEven\"></a>\r\n\r\n### padToEven\r\nA utility function of adding a value in type of string. \r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.padToEven(value)\r\n```\r\n* * *\r\n<a name=\"toBuffer\"></a>\r\n\r\n### toBuffer\r\nA utility function of adding a value to buffer.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.toBuffer(v)\r\n```\r\n* * *\r\n<a name=\"baToJSON\"></a>\r\n\r\n### baToJSON\r\nA utility function of converting buffer value to JSON format.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.baToJSON(from, nonce)\r\n```\r\n* * *\r\n<a name=\"stripZeros\"></a>\r\n\r\n### stripZeros\r\nA utility function of stripping zeros.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.stripZeros(a)\r\n```\r\n* * *\r\n<a name=\"unpad\"></a>\r\n\r\n### unpad\r\nA utility function of leading zeros from a `Buffer` or an `Array`.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.unpad(a)\r\n```\r\n* * *\r\n<a name=\"isHexString\"></a>\r\n\r\n### isHexString\r\nA utility function of confirming a hex string.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.isHexString(value, length)\r\n```\r\n* * *\r\n<a name=\"intToBuffer\"></a>\r\n\r\n### intToBuffer\r\nA utility function of converting a `Number` to a `Buffer`.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.intToBuffer(i)\r\n```\r\n* * *\r\n<a name=\"intToHex\"></a>\r\n\r\n### intToHex\r\nA utility function of converting `Number` into a hex `String`.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.intToHex(i)\r\n```\r\n* * *\r\n<a name=\"rlphash\"></a>\r\n\r\n### rlphash\r\nA utility function of creating SHA-3 hash of the RLP encoded version of the input.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.rlphash(a)\r\n```\r\n* * *\r\n<a name=\"keccak\"></a>\r\n\r\n### keccak\r\nA utility function of creating Keccak hash of the input.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.keccak(a, bits)\r\n```\r\n* * *\r\n<a name=\"zeros\"></a>\r\n\r\n### zeros\r\nA utility function of returning a buffer filled with 0s.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.zeros(bytes)\r\n```\r\n* * *\r\n<a name=\"getBinarySize\"></a>\r\n\r\n### getBinarySize\r\nA utility function of getting the binary size of a string.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.getBinarySize(str)\r\n```\r\n* * *\r\n<a name=\"arrayContainsArray\"></a>\r\n\r\n### arrayContainsArray\r\nA utility function of returning 'TRUE' if the first specified array contains all elements from the second one and returning 'FALSE' otherwise.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.arrayContainsArray(superset, subset, some)\r\n```\r\n* * *\r\n<a name=\"toUtf8\"></a>\r\n\r\n### toUtf8\r\nA utility function of getting utf8 from its hex representation.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.toUtf8(hex)\r\n```\r\n* * *\r\n<a name=\"toAscii\"></a>\r\n\r\n### toAscii\r\nA utility function of getting ascii from its hex representation.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.toAscii(hex)\r\n```\r\n* * *\r\n<a name=\"fromUtf8\"></a>\r\n\r\n### fromUtf8\r\nA utility function of getting hex representation (prefixed by 0x) of utf8 string.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.fromUtf8(stringValue)\r\n```\r\n* * *\r\n<a name=\"fromAscii\"></a>\r\n\r\n### fromAscii\r\nA utility function of getting hex representation (prefixed by 0x) of ascii string.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.fromAscii(stringValue)\r\n```\r\n* * *\r\n<a name=\"getKeys\"></a>\r\n\r\n### getKeys\r\nA utility function of getting specific key from inner object array of objects.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.getKeys(params, key, allowEmptyfrom)\r\n```\r\n* * *\r\n<a name=\"bufferToHex\"></a>\r\n\r\n### bufferToHex\r\nA utility function of converting a `Buffer` into a hex `String`.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.bufferToHex(buff)\r\n```\r\n* * *\r\n<a name=\"zeroAddress\"></a>\r\n\r\n### zeroAddress\r\nA utility function of returning a zero address.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.zeroAddress()\r\n```\r\n* * *\r\n<a name=\"setLengthLeft\"></a>\r\n\r\n### setLengthLeft\r\nA utility function of left padding an `Array` or `Buffer` with leading zeros till it has `length` bytes.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.setLengthLeft(msg, length, right)\r\n```\r\n* * *\r\n<a name=\"setLength\"></a>\r\n\r\n### setLength\r\nA utility function of padding an `Array` or `Buffer` with leading zeros till it has `length` bytes.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.setLength(msg, length, right)\r\n```\r\n* * *\r\n<a name=\"setLengthRight\"></a>\r\n\r\n### setLengthRight\r\nA utility function of right padding an `Array` or `Buffer` with leading zeros till it has `length` bytes. Or it truncates the beginning if it exceeds.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.setLengthRight(msg, length)\r\n```\r\n* * *\r\n<a name=\"bufferToInt\"></a>\r\n\r\n### bufferToInt\r\nA utility function of Converting a `Buffer` to a `Number`.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.bufferToInt(buf)\r\n```\r\n* * *\r\n<a name=\"fromSigned\"></a>\r\n\r\n### fromSigned\r\nA utility function of interpreting a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.fromSigned(num)\r\n```\r\n* * *\r\n<a name=\"toUnsigned\"></a>\r\n\r\n### toUnsigned\r\nA utility function of converting a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.toUnsigned(num)\r\n```\r\n* * *\r\n<a name=\"keccak256\"></a>\r\n\r\n### keccak256\r\nA utility function of creating Keccak-256 hash of the input, alias for keccak(a, 256).\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.keccak256(a)\r\n```\r\n* * *\r\n<a name=\"sha3\"></a>\r\n\r\n### sha3\r\nA utility function of creating a keccak hash of input.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.sha3()\r\n```\r\n* * *\r\n<a name=\"sha256\"></a>\r\n\r\n### sha256\r\nA utility function of creating SHA256 hash of the input.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.sha256(a)\r\n```\r\n* * *\r\n<a name=\"ripemd160\"></a>\r\n\r\n### ripemd160\r\nA utility function of creating RIPEMD160 hash of the input.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.ripemd160(a,padded)\r\n```\r\n* * *\r\n<a name=\"isValidPrivate\"></a>\r\n\r\n### isValidPrivate\r\nA utility function of checking if the private key satisfies the rules of the curve secp256k1.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.isValidPrivate(privateKey)\r\n```\r\n* * *\r\n<a name=\"isValidPublic\"></a>\r\n\r\n### isValidPublic\r\nA utility function of checking if the public key satisfies the rules of the curve secp256k1 and the requirements of SEC.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.isValidPublic(publicKey, sanitize)\r\n```\r\n* * *\r\n<a name=\"publicToAddress\"></a>\r\n\r\n### publicToAddress\r\nA utility function of returning the SEC address of a given public key accepting \"SEC public keys\" and SEC1 encoded keys.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.publicToAddress(pubKey, sanitize)\r\n```\r\n* * *\r\n<a name=\"privateToPublic\"></a>\r\n\r\n### privateToPublic\r\nA utility function of returning the SEC public key of a given private key.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.privateToPublic(privateKey)\r\n```\r\n* * *\r\n<a name=\"importPublic\"></a>\r\n\r\n### importPublic\r\nA utility function of converting a public key to the SEC format.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.importPublic(publicKey)\r\n```\r\n* * *\r\n<a name=\"ecsign\"></a>\r\n\r\n### ecsign\r\nA utility function of ECDSA sign.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.ecsign(msgHash, privateKey)\r\n```\r\n* * *\r\n<a name=\"hashPersonalMessage\"></a>\r\n\r\n### hashPersonalMessage\r\nA utility function of Returns the keccak-256 hash of `message`, prefixed with the header used by the `SEC_sign` RPC call. The output of this function can be fed into `ecsign` to produce the same signature as the `SEC_sign` call for a given `message`, or fed to `ecrecover` along with a signature to recover the public key used to produce the signature.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.hashPersonalMessage(message)\r\n```\r\n* * *\r\n<a name=\"ecrecover\"></a>\r\n\r\n### ecrecover\r\nA utility function of ECDSA public key recovery from signature.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.ecrecover(msgHash, v, r, s)\r\n```\r\n* * *\r\n<a name=\"toRpcSig\"></a>\r\n\r\n### toRpcSig\r\nA utility function of converting signature parameters into the format of `SEC_sign` RPC method.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.toRpcSig(v, r, s)\r\n```\r\n* * *\r\n<a name=\"fromRpcSig\"></a>\r\n\r\n### fromRpcSig\r\nA utility function of converting signature format of the `SEC_sign` RPC method to signature parameters.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.fromRpcSig(sig)\r\n```\r\n* * *\r\n<a name=\"privateToAddress\"></a>\r\n\r\n### privateToAddress\r\nA utility function of returning the SEC address of a given private key.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.privateToAddress(privateKey)\r\n```\r\n* * *\r\n<a name=\"isValidAddress\"></a>\r\n\r\n### isValidAddress\r\nA utility function of checking if the address is a valid. Accepts checksummed addresses too.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.isValidAddress(address)\r\n```\r\n* * *\r\n<a name=\"isZeroAddress\"></a>\r\n\r\n### isZeroAddress\r\nA ultiity function of checking if a given address is a zero address.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.isZeroAddress(address)\r\n```\r\n* * *\r\n<a name=\"toChecksumAddress\"></a>\r\n\r\n### toChecksumAddress\r\nA utility function of returning a checksummed address.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.toChecksumAddress(address)\r\n```\r\n* * *\r\n<a name=\"isValidChecksumAddress\"></a>\r\n\r\n### isValidChecksumAddress\r\nA utility function of checking if the address is a valid checksummed address.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.isValidChecksumAddress(address)\r\n```\r\n* * *\r\n<a name=\"isPrecompiled\"></a>\r\n\r\n### isPrecompiled\r\nA utility function of returning true if the supplied address belongs to a precompiled account (Byzantium).\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.isPrecompiled(address)\r\n```\r\n* * *\r\n<a name=\"addHexPrefix\"></a>\r\n\r\n### addHexPrefix\r\nA utility function of adding \"0x\" to a given `String` if it does not already start with \"0x\".\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.addHexPrefix(str)\r\n```\r\n* * *\r\n<a name=\"isValidSignature\"></a>\r\n\r\n### isValidSignature\r\nA utility function of validating ECDSA signature.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.isValidSignature(v, r, s, homestead)\r\n```\r\n* * *\r\n<a name=\"stripHexPrefix\"></a>\r\n\r\n### stripHexPrefix\r\nA utility function of stripping hex sting.\r\n\r\n**Example**\r\n```js\r\nconst SecUtils = require('@biut-block/biutjs-util')\r\nconst util = new SecUtils({\r\n    timeServer: 'DE'\r\n})\r\nutil.stripHexPrefix()\r\n```\r\n### LICENSE\r\nMPL-2.0\r\n* * *\r\n# SEC工具库-中文简介\r\n\r\nUtils，是英语Utility（意思是功能，工具）的复数，Utilities的简写；是区块链开发的工具库；是内部由封装了多个功能函数（例如获取时间戳函数UnixTime等）的库组成。其作用是为进一步开发提供可直接调用的函数，可在下一步SEC区块数据结构和交易流程的开发中直接调用,使整个SEC区块链系统轻量、高效。\r\n\r\nSEC地址是为了减少接收方所需标识的字节数。SEC地址（secAddress）的生成步骤如下：\r\n\r\n1. 将公钥通过SHA256哈希算法处理得到32字节的哈希值，\r\n2. 后对得到的哈希值通过RIPEMD-160算法来得到20字节的哈希值 —— Hash160  即ripemd160（sha256（publicKey））\r\n3. 把版本号[2]+Hash160组成的21字节数组进行双次SHA256哈希运算，得到的哈希值的头4个字节作为校验和，放置21字节数组的末尾。\r\n4. 对组成25位数组进行Base58编码，就得到地址。","readmeFilename":"README.md"}