init
This commit is contained in:
22
node_modules/base-x/LICENSE.md
generated
vendored
Normal file
22
node_modules/base-x/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 base-x contributors
|
||||
Copyright (c) 2014-2018 The Bitcoin Core developers
|
||||
|
||||
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.
|
||||
74
node_modules/base-x/README.md
generated
vendored
Normal file
74
node_modules/base-x/README.md
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
# base-x
|
||||
|
||||
[](https://www.npmjs.org/package/base-x)
|
||||
[](https://travis-ci.org/cryptocoinjs/base-x)
|
||||
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
Fast base encoding / decoding of any given alphabet using bitcoin style leading
|
||||
zero compression.
|
||||
|
||||
**WARNING:** This module is **NOT RFC3548** compliant, it cannot be used for base16 (hex), base32, or base64 encoding in a standards compliant manner.
|
||||
|
||||
## Example
|
||||
|
||||
Base58
|
||||
|
||||
``` javascript
|
||||
var BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
||||
import basex from 'base-x'
|
||||
var bs58 = basex(BASE58)
|
||||
|
||||
var decoded = bs58.decode('5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr')
|
||||
|
||||
console.log(decoded)
|
||||
// => Uint8Array(33) [
|
||||
// 128, 237, 219, 220, 17, 104, 241, 218,
|
||||
// 234, 219, 211, 228, 76, 30, 63, 143,
|
||||
// 90, 40, 76, 32, 41, 247, 138, 210,
|
||||
// 106, 249, 133, 131, 164, 153, 222, 91,
|
||||
// 25
|
||||
// ]
|
||||
|
||||
console.log(bs58.encode(decoded))
|
||||
// => 5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr
|
||||
```
|
||||
|
||||
### Alphabets
|
||||
|
||||
See below for a list of commonly recognized alphabets, and their respective base.
|
||||
|
||||
Base | Alphabet
|
||||
------------- | -------------
|
||||
2 | `01`
|
||||
8 | `01234567`
|
||||
11 | `0123456789a`
|
||||
16 | `0123456789abcdef`
|
||||
32 | `0123456789ABCDEFGHJKMNPQRSTVWXYZ`
|
||||
32 | `ybndrfg8ejkmcpqxot1uwisza345h769` (z-base-32)
|
||||
36 | `0123456789abcdefghijklmnopqrstuvwxyz`
|
||||
58 | `123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`
|
||||
62 | `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`
|
||||
64 | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`
|
||||
67 | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~`
|
||||
|
||||
|
||||
## How it works
|
||||
|
||||
It encodes octet arrays by doing long divisions on all significant digits in the
|
||||
array, creating a representation of that number in the new base. Then for every
|
||||
leading zero in the input (not significant as a number) it will encode as a
|
||||
single leader character. This is the first in the alphabet and will decode as 8
|
||||
bits. The other characters depend upon the base. For example, a base58 alphabet
|
||||
packs roughly 5.858 bits per character.
|
||||
|
||||
This means the encoded string 000f (using a base16, 0-f alphabet) will actually decode
|
||||
to 4 bytes unlike a canonical hex encoding which uniformly packs 4 bits into each
|
||||
character.
|
||||
|
||||
While unusual, this does mean that no padding is required and it works for bases
|
||||
like 43.
|
||||
|
||||
|
||||
## LICENSE [MIT](LICENSE)
|
||||
A direct derivation of the base58 implementation from [`bitcoin/bitcoin`](https://github.com/bitcoin/bitcoin/blob/f1e2f2a85962c1664e4e55471061af0eaa798d40/src/base58.cpp), generalized for variable length alphabets.
|
||||
58
node_modules/base-x/package.json
generated
vendored
Normal file
58
node_modules/base-x/package.json
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "base-x",
|
||||
"version": "5.0.1",
|
||||
"description": "Fast base encoding / decoding of any given alphabet",
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
"base-x",
|
||||
"base58",
|
||||
"base62",
|
||||
"base64",
|
||||
"crypto",
|
||||
"crytography",
|
||||
"decode",
|
||||
"decoding",
|
||||
"encode",
|
||||
"encoding"
|
||||
],
|
||||
"homepage": "https://github.com/cryptocoinjs/base-x",
|
||||
"bugs": {
|
||||
"url": "https://github.com/cryptocoinjs/base-x/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "Daniel Cousens",
|
||||
"files": [
|
||||
"src"
|
||||
],
|
||||
"main": "src/cjs/index.cjs",
|
||||
"module": "src/esm/index.js",
|
||||
"types": "src/cjs/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./src/cjs/index.cjs",
|
||||
"import": "./src/esm/index.js",
|
||||
"types": "./src/cjs/index.d.ts"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cryptocoinjs/base-x.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run clean && tsc -p ./tsconfig.json && tsc -p ./tsconfig.cjs.json; npm run standard -- --fix",
|
||||
"clean": "rimraf src",
|
||||
"postbuild": "find src/cjs -type f -name \"*.js\" -exec bash -c 'mv \"$0\" \"${0%.js}.cjs\"' {} \\;",
|
||||
"gitdiff": "npm run build && git diff --exit-code",
|
||||
"prepublish": "npm run gitdiff",
|
||||
"standard": "standard --ignore test",
|
||||
"test": "npm run unit && npm run standard",
|
||||
"unit": "tape test/*.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "12.0.10",
|
||||
"rimraf": "^3.0.2",
|
||||
"standard": "^17.1.0",
|
||||
"tape": "^5.3.0",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
}
|
||||
126
node_modules/base-x/src/cjs/index.cjs
generated
vendored
Normal file
126
node_modules/base-x/src/cjs/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
'use strict'
|
||||
// base-x encoding / decoding
|
||||
// Copyright (c) 2018 base-x contributors
|
||||
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
Object.defineProperty(exports, '__esModule', { value: true })
|
||||
function base (ALPHABET) {
|
||||
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
||||
const BASE_MAP = new Uint8Array(256)
|
||||
for (let j = 0; j < BASE_MAP.length; j++) {
|
||||
BASE_MAP[j] = 255
|
||||
}
|
||||
for (let i = 0; i < ALPHABET.length; i++) {
|
||||
const x = ALPHABET.charAt(i)
|
||||
const xc = x.charCodeAt(0)
|
||||
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
||||
BASE_MAP[xc] = i
|
||||
}
|
||||
const BASE = ALPHABET.length
|
||||
const LEADER = ALPHABET.charAt(0)
|
||||
const FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up
|
||||
const iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up
|
||||
function encode (source) {
|
||||
// eslint-disable-next-line no-empty
|
||||
if (source instanceof Uint8Array) { } else if (ArrayBuffer.isView(source)) {
|
||||
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength)
|
||||
} else if (Array.isArray(source)) {
|
||||
source = Uint8Array.from(source)
|
||||
}
|
||||
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
||||
if (source.length === 0) { return '' }
|
||||
// Skip & count leading zeroes.
|
||||
let zeroes = 0
|
||||
let length = 0
|
||||
let pbegin = 0
|
||||
const pend = source.length
|
||||
while (pbegin !== pend && source[pbegin] === 0) {
|
||||
pbegin++
|
||||
zeroes++
|
||||
}
|
||||
// Allocate enough space in big-endian base58 representation.
|
||||
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0
|
||||
const b58 = new Uint8Array(size)
|
||||
// Process the bytes.
|
||||
while (pbegin !== pend) {
|
||||
let carry = source[pbegin]
|
||||
// Apply "b58 = b58 * 256 + ch".
|
||||
let i = 0
|
||||
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
||||
carry += (256 * b58[it1]) >>> 0
|
||||
b58[it1] = (carry % BASE) >>> 0
|
||||
carry = (carry / BASE) >>> 0
|
||||
}
|
||||
if (carry !== 0) { throw new Error('Non-zero carry') }
|
||||
length = i
|
||||
pbegin++
|
||||
}
|
||||
// Skip leading zeroes in base58 result.
|
||||
let it2 = size - length
|
||||
while (it2 !== size && b58[it2] === 0) {
|
||||
it2++
|
||||
}
|
||||
// Translate the result into a string.
|
||||
let str = LEADER.repeat(zeroes)
|
||||
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]) }
|
||||
return str
|
||||
}
|
||||
function decodeUnsafe (source) {
|
||||
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
||||
if (source.length === 0) { return new Uint8Array() }
|
||||
let psz = 0
|
||||
// Skip and count leading '1's.
|
||||
let zeroes = 0
|
||||
let length = 0
|
||||
while (source[psz] === LEADER) {
|
||||
zeroes++
|
||||
psz++
|
||||
}
|
||||
// Allocate enough space in big-endian base256 representation.
|
||||
const size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up.
|
||||
const b256 = new Uint8Array(size)
|
||||
// Process the characters.
|
||||
while (psz < source.length) {
|
||||
// Find code of next character
|
||||
const charCode = source.charCodeAt(psz)
|
||||
// Base map can not be indexed using char code
|
||||
if (charCode > 255) { return }
|
||||
// Decode character
|
||||
let carry = BASE_MAP[charCode]
|
||||
// Invalid character
|
||||
if (carry === 255) { return }
|
||||
let i = 0
|
||||
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
||||
carry += (BASE * b256[it3]) >>> 0
|
||||
b256[it3] = (carry % 256) >>> 0
|
||||
carry = (carry / 256) >>> 0
|
||||
}
|
||||
if (carry !== 0) { throw new Error('Non-zero carry') }
|
||||
length = i
|
||||
psz++
|
||||
}
|
||||
// Skip leading zeroes in b256.
|
||||
let it4 = size - length
|
||||
while (it4 !== size && b256[it4] === 0) {
|
||||
it4++
|
||||
}
|
||||
const vch = new Uint8Array(zeroes + (size - it4))
|
||||
let j = zeroes
|
||||
while (it4 !== size) {
|
||||
vch[j++] = b256[it4++]
|
||||
}
|
||||
return vch
|
||||
}
|
||||
function decode (string) {
|
||||
const buffer = decodeUnsafe(string)
|
||||
if (buffer) { return buffer }
|
||||
throw new Error('Non-base' + BASE + ' character')
|
||||
}
|
||||
return {
|
||||
encode,
|
||||
decodeUnsafe,
|
||||
decode
|
||||
}
|
||||
}
|
||||
exports.default = base
|
||||
9
node_modules/base-x/src/cjs/index.d.ts
generated
vendored
Normal file
9
node_modules/base-x/src/cjs/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
declare function base(ALPHABET: string): base.BaseConverter;
|
||||
export default base;
|
||||
declare namespace base {
|
||||
interface BaseConverter {
|
||||
encode(buffer: Uint8Array | number[]): string;
|
||||
decodeUnsafe(string: string): Uint8Array | undefined;
|
||||
decode(string: string): Uint8Array;
|
||||
}
|
||||
}
|
||||
124
node_modules/base-x/src/esm/index.js
generated
vendored
Normal file
124
node_modules/base-x/src/esm/index.js
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
// base-x encoding / decoding
|
||||
// Copyright (c) 2018 base-x contributors
|
||||
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
function base (ALPHABET) {
|
||||
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
||||
const BASE_MAP = new Uint8Array(256)
|
||||
for (let j = 0; j < BASE_MAP.length; j++) {
|
||||
BASE_MAP[j] = 255
|
||||
}
|
||||
for (let i = 0; i < ALPHABET.length; i++) {
|
||||
const x = ALPHABET.charAt(i)
|
||||
const xc = x.charCodeAt(0)
|
||||
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
||||
BASE_MAP[xc] = i
|
||||
}
|
||||
const BASE = ALPHABET.length
|
||||
const LEADER = ALPHABET.charAt(0)
|
||||
const FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up
|
||||
const iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up
|
||||
function encode (source) {
|
||||
// eslint-disable-next-line no-empty
|
||||
if (source instanceof Uint8Array) { } else if (ArrayBuffer.isView(source)) {
|
||||
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength)
|
||||
} else if (Array.isArray(source)) {
|
||||
source = Uint8Array.from(source)
|
||||
}
|
||||
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
||||
if (source.length === 0) { return '' }
|
||||
// Skip & count leading zeroes.
|
||||
let zeroes = 0
|
||||
let length = 0
|
||||
let pbegin = 0
|
||||
const pend = source.length
|
||||
while (pbegin !== pend && source[pbegin] === 0) {
|
||||
pbegin++
|
||||
zeroes++
|
||||
}
|
||||
// Allocate enough space in big-endian base58 representation.
|
||||
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0
|
||||
const b58 = new Uint8Array(size)
|
||||
// Process the bytes.
|
||||
while (pbegin !== pend) {
|
||||
let carry = source[pbegin]
|
||||
// Apply "b58 = b58 * 256 + ch".
|
||||
let i = 0
|
||||
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
||||
carry += (256 * b58[it1]) >>> 0
|
||||
b58[it1] = (carry % BASE) >>> 0
|
||||
carry = (carry / BASE) >>> 0
|
||||
}
|
||||
if (carry !== 0) { throw new Error('Non-zero carry') }
|
||||
length = i
|
||||
pbegin++
|
||||
}
|
||||
// Skip leading zeroes in base58 result.
|
||||
let it2 = size - length
|
||||
while (it2 !== size && b58[it2] === 0) {
|
||||
it2++
|
||||
}
|
||||
// Translate the result into a string.
|
||||
let str = LEADER.repeat(zeroes)
|
||||
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]) }
|
||||
return str
|
||||
}
|
||||
function decodeUnsafe (source) {
|
||||
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
||||
if (source.length === 0) { return new Uint8Array() }
|
||||
let psz = 0
|
||||
// Skip and count leading '1's.
|
||||
let zeroes = 0
|
||||
let length = 0
|
||||
while (source[psz] === LEADER) {
|
||||
zeroes++
|
||||
psz++
|
||||
}
|
||||
// Allocate enough space in big-endian base256 representation.
|
||||
const size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up.
|
||||
const b256 = new Uint8Array(size)
|
||||
// Process the characters.
|
||||
while (psz < source.length) {
|
||||
// Find code of next character
|
||||
const charCode = source.charCodeAt(psz)
|
||||
// Base map can not be indexed using char code
|
||||
if (charCode > 255) { return }
|
||||
// Decode character
|
||||
let carry = BASE_MAP[charCode]
|
||||
// Invalid character
|
||||
if (carry === 255) { return }
|
||||
let i = 0
|
||||
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
||||
carry += (BASE * b256[it3]) >>> 0
|
||||
b256[it3] = (carry % 256) >>> 0
|
||||
carry = (carry / 256) >>> 0
|
||||
}
|
||||
if (carry !== 0) { throw new Error('Non-zero carry') }
|
||||
length = i
|
||||
psz++
|
||||
}
|
||||
// Skip leading zeroes in b256.
|
||||
let it4 = size - length
|
||||
while (it4 !== size && b256[it4] === 0) {
|
||||
it4++
|
||||
}
|
||||
const vch = new Uint8Array(zeroes + (size - it4))
|
||||
let j = zeroes
|
||||
while (it4 !== size) {
|
||||
vch[j++] = b256[it4++]
|
||||
}
|
||||
return vch
|
||||
}
|
||||
function decode (string) {
|
||||
const buffer = decodeUnsafe(string)
|
||||
if (buffer) { return buffer }
|
||||
throw new Error('Non-base' + BASE + ' character')
|
||||
}
|
||||
return {
|
||||
encode,
|
||||
decodeUnsafe,
|
||||
decode
|
||||
}
|
||||
}
|
||||
export default base
|
||||
Reference in New Issue
Block a user