This commit is contained in:
nitowa
2023-08-15 22:28:03 +02:00
commit 1dae68b1c7
5529 changed files with 1659171 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017 Daniel Cousens
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+27
View File
@@ -0,0 +1,27 @@
# bs58check
[![NPM Package](https://img.shields.io/npm/v/bs58check.svg?style=flat-square)](https://www.npmjs.org/package/bs58check)
[![Build Status](https://img.shields.io/travis/bitcoinjs/bs58check.svg?branch=master&style=flat-square)](https://travis-ci.org/bitcoinjs/bs58check)
[![Dependency status](https://img.shields.io/david/bitcoinjs/bs58check.svg?style=flat-square)](https://david-dm.org/bitcoinjs/bs58check#info=dependencies)
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
A straight forward implementation of base58check extending upon bs58.
## Example
```javascript
var bs58check = require('bs58check')
var decoded = bs58check.decode('5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr')
console.log(decoded)
// => <Buffer 80 ed db dc 11 68 f1 da ea db d3 e4 4c 1e 3f 8f 5a 28 4c 20 29 f7 8a d2 6a f9 85 83 a4 99 de 5b 19>
console.log(bs58check.encode(decoded))
// => 5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr
```
## LICENSE [MIT](LICENSE)
+50
View File
@@ -0,0 +1,50 @@
'use strict'
var base58 = require('bs58')
var Buffer = require('safe-buffer').Buffer
module.exports = function (checksumFn) {
// Encode a buffer as a base58-check encoded string
function encode (payload) {
var checksum = checksumFn(payload)
return base58.encode(Buffer.concat([
payload,
checksum
], payload.length + 4))
}
function decodeRaw (buffer) {
var payload = buffer.slice(0, -4)
var checksum = buffer.slice(-4)
var newChecksum = checksumFn(payload)
if (checksum[0] ^ newChecksum[0] |
checksum[1] ^ newChecksum[1] |
checksum[2] ^ newChecksum[2] |
checksum[3] ^ newChecksum[3]) return
return payload
}
// Decode a base58-check encoded string to a buffer, no result if checksum is wrong
function decodeUnsafe (string) {
var buffer = base58.decodeUnsafe(string)
if (!buffer) return
return decodeRaw(buffer)
}
function decode (string) {
var buffer = base58.decode(string)
var payload = decodeRaw(buffer, checksumFn)
if (!payload) throw new Error('Invalid checksum')
return payload
}
return {
encode: encode,
decode: decode,
decodeUnsafe: decodeUnsafe
}
}
+12
View File
@@ -0,0 +1,12 @@
'use strict'
var createHash = require('create-hash')
var bs58checkBase = require('./base')
// SHA256(SHA256(buffer))
function sha256x2 (buffer) {
var tmp = createHash('sha256').update(buffer).digest()
return createHash('sha256').update(tmp).digest()
}
module.exports = bs58checkBase(sha256x2)
+52
View File
@@ -0,0 +1,52 @@
{
"name": "bs58check",
"version": "2.1.2",
"description": "A straightforward implementation of base58-check encoding",
"keywords": [
"base",
"base58",
"base58check",
"bitcoin",
"bs58",
"check",
"checksum",
"decode",
"decoding",
"encode",
"encoding",
"litecoin"
],
"homepage": "https://github.com/bitcoinjs/bs58check",
"bugs": {
"url": "https://github.com/bitcoinjs/bs58check/issues"
},
"license": "MIT",
"author": "Daniel Cousens",
"files": [
"index.js",
"base.js"
],
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/bitcoinjs/bs58check.git"
},
"scripts": {
"coverage-report": "nyc report --reporter=lcov",
"coverage": "nyc --check-coverage --branches 90 --functions 90 npm run unit",
"standard": "standard",
"test": "npm run standard && npm run coverage",
"unit": "tape test/*.js"
},
"dependencies": {
"bs58": "^4.0.0",
"create-hash": "^1.1.0",
"safe-buffer": "^5.1.2"
},
"devDependencies": {
"blake-hash": "^1.0.0",
"nyc": "^11.3.0",
"standard": "^10.0.3",
"tape": "^4.6.2"
}
}