@gibme/base58 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +13 -0
- package/dist/base58.d.ts +30 -0
- package/dist/base58.js +55 -0
- package/dist/cryptonote_base58.d.ts +46 -0
- package/dist/cryptonote_base58.js +161 -0
- package/dist/helpers.d.ts +14 -0
- package/dist/helpers.js +88 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +5 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018-2022 Brandon Lehmann
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Simple Base58 Library
|
|
2
|
+
|
|
3
|
+
```typescript
|
|
4
|
+
import Base58 from '@gibme/base58';
|
|
5
|
+
|
|
6
|
+
const encoded = Base58.encode('02c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cfeb05f9d2');
|
|
7
|
+
|
|
8
|
+
console.log(encoded);
|
|
9
|
+
|
|
10
|
+
const decoded = Base58.decode(encoded);
|
|
11
|
+
|
|
12
|
+
console.log(decoded.toString('hex'));
|
|
13
|
+
```
|
package/dist/base58.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Base58Handler } from './types';
|
|
3
|
+
import CryptoNoteBase58 from './cryptonote_base58';
|
|
4
|
+
export default class Base58 implements Base58Handler {
|
|
5
|
+
static get CryptoNote(): CryptoNoteBase58;
|
|
6
|
+
/**
|
|
7
|
+
* Decodes the Base58 encoded string into a Buffer
|
|
8
|
+
*
|
|
9
|
+
* @param encoded
|
|
10
|
+
*/
|
|
11
|
+
static decode(encoded: string): Buffer;
|
|
12
|
+
/**
|
|
13
|
+
* Encodes the data into Base58
|
|
14
|
+
*
|
|
15
|
+
* @param data
|
|
16
|
+
*/
|
|
17
|
+
static encode(data: string | Uint8Array | Buffer): string;
|
|
18
|
+
/**
|
|
19
|
+
* Decodes the Base58 encoded string into a Buffer
|
|
20
|
+
*
|
|
21
|
+
* @param encoded
|
|
22
|
+
*/
|
|
23
|
+
decode(encoded: string): Buffer;
|
|
24
|
+
/**
|
|
25
|
+
* Encodes the data into Base58
|
|
26
|
+
*
|
|
27
|
+
* @param data
|
|
28
|
+
*/
|
|
29
|
+
encode(data: string | Uint8Array | Buffer): string;
|
|
30
|
+
}
|
package/dist/base58.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2018-2022 Brandon Lehmann
|
|
3
|
+
//
|
|
4
|
+
// Please see the included LICENSE file for more information.
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const cryptonote_base58_1 = __importDefault(require("./cryptonote_base58"));
|
|
10
|
+
/** @ignore */
|
|
11
|
+
const { base58_to_binary, binary_to_base58 } = require('base58-js');
|
|
12
|
+
class Base58 {
|
|
13
|
+
static get CryptoNote() {
|
|
14
|
+
return new cryptonote_base58_1.default();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Decodes the Base58 encoded string into a Buffer
|
|
18
|
+
*
|
|
19
|
+
* @param encoded
|
|
20
|
+
*/
|
|
21
|
+
static decode(encoded) {
|
|
22
|
+
return Buffer.from(base58_to_binary(encoded));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Encodes the data into Base58
|
|
26
|
+
*
|
|
27
|
+
* @param data
|
|
28
|
+
*/
|
|
29
|
+
static encode(data) {
|
|
30
|
+
if (data instanceof Buffer) {
|
|
31
|
+
data = data.valueOf();
|
|
32
|
+
}
|
|
33
|
+
else if (typeof data === 'string') {
|
|
34
|
+
data = Buffer.from(data, 'hex').valueOf();
|
|
35
|
+
}
|
|
36
|
+
return binary_to_base58(data);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Decodes the Base58 encoded string into a Buffer
|
|
40
|
+
*
|
|
41
|
+
* @param encoded
|
|
42
|
+
*/
|
|
43
|
+
decode(encoded) {
|
|
44
|
+
return Base58.decode(encoded);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Encodes the data into Base58
|
|
48
|
+
*
|
|
49
|
+
* @param data
|
|
50
|
+
*/
|
|
51
|
+
encode(data) {
|
|
52
|
+
return Base58.encode(data);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.default = Base58;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Base58Handler } from './types';
|
|
3
|
+
export default class CryptoNoteBase58 implements Base58Handler {
|
|
4
|
+
/**
|
|
5
|
+
* Decodes the Base58 encoded string into a Buffer
|
|
6
|
+
*
|
|
7
|
+
* @param encoded
|
|
8
|
+
*/
|
|
9
|
+
static decode(encoded: string): Buffer;
|
|
10
|
+
/**
|
|
11
|
+
* Encodes the data into Base58
|
|
12
|
+
*
|
|
13
|
+
* @param data
|
|
14
|
+
*/
|
|
15
|
+
static encode(data: string | Uint8Array | Buffer): string;
|
|
16
|
+
/**
|
|
17
|
+
* Decodes a Base58 block
|
|
18
|
+
*
|
|
19
|
+
* @param data
|
|
20
|
+
* @param buffer
|
|
21
|
+
* @param index
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
private static decodeBlock;
|
|
25
|
+
/**
|
|
26
|
+
* Encodes the data into a block for Base58
|
|
27
|
+
*
|
|
28
|
+
* @param data
|
|
29
|
+
* @param buffer
|
|
30
|
+
* @param index
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private static encodeBlock;
|
|
34
|
+
/**
|
|
35
|
+
* Decodes the Base58 encoded string into a Buffer
|
|
36
|
+
*
|
|
37
|
+
* @param encoded
|
|
38
|
+
*/
|
|
39
|
+
decode(encoded: string): Buffer;
|
|
40
|
+
/**
|
|
41
|
+
* Encodes the data into Base58
|
|
42
|
+
*
|
|
43
|
+
* @param data
|
|
44
|
+
*/
|
|
45
|
+
encode(data: string | Uint8Array | Buffer): string;
|
|
46
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2018-2022 Brandon Lehmann
|
|
3
|
+
//
|
|
4
|
+
// Please see the included LICENSE file for more information.
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const bytepack_1 = require("@gibme/bytepack");
|
|
10
|
+
const helpers_1 = __importDefault(require("./helpers"));
|
|
11
|
+
/** @ignore */
|
|
12
|
+
const ALPHABET = (() => {
|
|
13
|
+
const str = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
14
|
+
return str.split('')
|
|
15
|
+
.map(char => char.charCodeAt(0));
|
|
16
|
+
})();
|
|
17
|
+
/** @ignore */
|
|
18
|
+
const ENCODED_BLOCK_SIZES = [0, 2, 3, 5, 6, 7, 9, 10, 11];
|
|
19
|
+
/** @ignore */
|
|
20
|
+
const FULL_BLOCK_SIZE = 8;
|
|
21
|
+
/** @ignore */
|
|
22
|
+
const FULL_ENCODED_BLOCK_SIZE = 11;
|
|
23
|
+
/** @ignore */
|
|
24
|
+
const UINT64_MAX = (0, bytepack_1.BytePackBigInt)(2).pow(64);
|
|
25
|
+
class CryptoNoteBase58 {
|
|
26
|
+
/**
|
|
27
|
+
* Decodes the Base58 encoded string into a Buffer
|
|
28
|
+
*
|
|
29
|
+
* @param encoded
|
|
30
|
+
*/
|
|
31
|
+
static decode(encoded) {
|
|
32
|
+
const enc = helpers_1.default.stringToBin(encoded);
|
|
33
|
+
if (enc.length === 0) {
|
|
34
|
+
return Buffer.alloc(0);
|
|
35
|
+
}
|
|
36
|
+
const fullBlockCount = Math.floor(enc.length / FULL_ENCODED_BLOCK_SIZE);
|
|
37
|
+
const lastBlockSize = enc.length % FULL_ENCODED_BLOCK_SIZE;
|
|
38
|
+
const lastBlockDecodedSize = ENCODED_BLOCK_SIZES.indexOf(lastBlockSize);
|
|
39
|
+
if (lastBlockDecodedSize < 0) {
|
|
40
|
+
throw new Error('Invalid encoded length');
|
|
41
|
+
}
|
|
42
|
+
const dataSize = fullBlockCount * FULL_BLOCK_SIZE + lastBlockDecodedSize;
|
|
43
|
+
let result = new Uint8Array(dataSize);
|
|
44
|
+
for (let i = 0; i < fullBlockCount; i++) {
|
|
45
|
+
result = CryptoNoteBase58.decodeBlock(enc.subarray(i * FULL_ENCODED_BLOCK_SIZE, i * FULL_ENCODED_BLOCK_SIZE + FULL_ENCODED_BLOCK_SIZE), result, i * FULL_BLOCK_SIZE);
|
|
46
|
+
}
|
|
47
|
+
if (lastBlockSize > 0) {
|
|
48
|
+
result = CryptoNoteBase58.decodeBlock(enc.subarray(fullBlockCount * FULL_ENCODED_BLOCK_SIZE, fullBlockCount * FULL_ENCODED_BLOCK_SIZE + lastBlockSize), result, fullBlockCount * FULL_BLOCK_SIZE);
|
|
49
|
+
}
|
|
50
|
+
return Buffer.from(result);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Encodes the data into Base58
|
|
54
|
+
*
|
|
55
|
+
* @param data
|
|
56
|
+
*/
|
|
57
|
+
static encode(data) {
|
|
58
|
+
if (data instanceof Buffer) {
|
|
59
|
+
data = data.toString('hex');
|
|
60
|
+
}
|
|
61
|
+
else if (data instanceof Uint8Array) {
|
|
62
|
+
data = Buffer.from(data).toString('hex');
|
|
63
|
+
}
|
|
64
|
+
const _data = helpers_1.default.hexToBin(data);
|
|
65
|
+
if (_data.length === 0) {
|
|
66
|
+
return '';
|
|
67
|
+
}
|
|
68
|
+
const fullBlockCount = Math.floor(_data.length / FULL_BLOCK_SIZE);
|
|
69
|
+
const lastBlockSize = _data.length % FULL_BLOCK_SIZE;
|
|
70
|
+
const resSize = fullBlockCount * FULL_ENCODED_BLOCK_SIZE + ENCODED_BLOCK_SIZES[lastBlockSize];
|
|
71
|
+
let result = new Uint8Array(resSize);
|
|
72
|
+
let i;
|
|
73
|
+
for (i = 0; i < resSize; ++i) {
|
|
74
|
+
result[i] = ALPHABET[0];
|
|
75
|
+
}
|
|
76
|
+
for (i = 0; i < fullBlockCount; i++) {
|
|
77
|
+
result = CryptoNoteBase58.encodeBlock(_data.subarray(i * FULL_BLOCK_SIZE, i * FULL_BLOCK_SIZE + FULL_BLOCK_SIZE), result, i *
|
|
78
|
+
FULL_ENCODED_BLOCK_SIZE);
|
|
79
|
+
}
|
|
80
|
+
if (lastBlockSize > 0) {
|
|
81
|
+
result = CryptoNoteBase58.encodeBlock(_data.subarray(fullBlockCount * FULL_BLOCK_SIZE, fullBlockCount * FULL_BLOCK_SIZE + lastBlockSize), result, fullBlockCount * FULL_ENCODED_BLOCK_SIZE);
|
|
82
|
+
}
|
|
83
|
+
return helpers_1.default.binToString(result);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Decodes a Base58 block
|
|
87
|
+
*
|
|
88
|
+
* @param data
|
|
89
|
+
* @param buffer
|
|
90
|
+
* @param index
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
static decodeBlock(data, buffer, index) {
|
|
94
|
+
if (data.length < 1 || data.length > FULL_ENCODED_BLOCK_SIZE) {
|
|
95
|
+
throw new Error('Invalid block length: ' + data.length);
|
|
96
|
+
}
|
|
97
|
+
const resSize = ENCODED_BLOCK_SIZES.indexOf(data.length);
|
|
98
|
+
if (resSize <= 0) {
|
|
99
|
+
throw new Error('Invalid block size');
|
|
100
|
+
}
|
|
101
|
+
let resNum = bytepack_1.BytePackBigInt.zero;
|
|
102
|
+
let order = bytepack_1.BytePackBigInt.one;
|
|
103
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
104
|
+
const digit = ALPHABET.indexOf(data[i]);
|
|
105
|
+
if (digit < 0) {
|
|
106
|
+
throw new Error('Invalid symbol');
|
|
107
|
+
}
|
|
108
|
+
const product = order.multiply(digit).add(resNum);
|
|
109
|
+
if (product.compare(UINT64_MAX) === 1) {
|
|
110
|
+
throw new Error('Overflow');
|
|
111
|
+
}
|
|
112
|
+
resNum = product;
|
|
113
|
+
order = order.multiply(ALPHABET.length);
|
|
114
|
+
}
|
|
115
|
+
if (resSize < FULL_BLOCK_SIZE && ((0, bytepack_1.BytePackBigInt)(2).pow(8 * resSize).compare(resNum) <= 0)) {
|
|
116
|
+
throw new Error('Overflow 2');
|
|
117
|
+
}
|
|
118
|
+
buffer.set(helpers_1.default.uint64To8be(resNum, resSize), index);
|
|
119
|
+
return buffer;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Encodes the data into a block for Base58
|
|
123
|
+
*
|
|
124
|
+
* @param data
|
|
125
|
+
* @param buffer
|
|
126
|
+
* @param index
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
|
+
static encodeBlock(data, buffer, index) {
|
|
130
|
+
if (data.length < 1 || data.length > FULL_ENCODED_BLOCK_SIZE) {
|
|
131
|
+
throw new Error('Invalid block length: ' + data.length);
|
|
132
|
+
}
|
|
133
|
+
let num = helpers_1.default.uint8BeTo64(data);
|
|
134
|
+
let i = ENCODED_BLOCK_SIZES[data.length] - 1;
|
|
135
|
+
while (num.compare(0) === 1) {
|
|
136
|
+
const div = num.divmod(ALPHABET.length);
|
|
137
|
+
const remainder = div.remainder;
|
|
138
|
+
num = div.quotient;
|
|
139
|
+
buffer[index + i] = ALPHABET[remainder.toJSNumber()];
|
|
140
|
+
i--;
|
|
141
|
+
}
|
|
142
|
+
return buffer;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Decodes the Base58 encoded string into a Buffer
|
|
146
|
+
*
|
|
147
|
+
* @param encoded
|
|
148
|
+
*/
|
|
149
|
+
decode(encoded) {
|
|
150
|
+
return CryptoNoteBase58.decode(encoded);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Encodes the data into Base58
|
|
154
|
+
*
|
|
155
|
+
* @param data
|
|
156
|
+
*/
|
|
157
|
+
encode(data) {
|
|
158
|
+
return CryptoNoteBase58.encode(data);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.default = CryptoNoteBase58;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BigInteger } from '@gibme/bytepack';
|
|
2
|
+
/** @ignore */
|
|
3
|
+
export default class Helpers {
|
|
4
|
+
/** @ignore */
|
|
5
|
+
static binToString(binary: Uint8Array): string;
|
|
6
|
+
/** @ignore */
|
|
7
|
+
static hexToBin(hex: string): Uint8Array;
|
|
8
|
+
/** @ignore */
|
|
9
|
+
static stringToBin(str: string): Uint8Array;
|
|
10
|
+
/** @ignore */
|
|
11
|
+
static uint8BeTo64(data: Uint8Array): BigInteger;
|
|
12
|
+
/** @ignore */
|
|
13
|
+
static uint64To8be(num: BigInteger, size: number): Uint8Array;
|
|
14
|
+
}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2018-2022 Brandon Lehmann
|
|
3
|
+
//
|
|
4
|
+
// Please see the included LICENSE file for more information.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const bytepack_1 = require("@gibme/bytepack");
|
|
7
|
+
/** @ignore */
|
|
8
|
+
class Helpers {
|
|
9
|
+
/** @ignore */
|
|
10
|
+
static binToString(binary) {
|
|
11
|
+
const result = [];
|
|
12
|
+
binary.forEach(bit => {
|
|
13
|
+
result.push(String.fromCharCode(bit));
|
|
14
|
+
});
|
|
15
|
+
return result.join('');
|
|
16
|
+
}
|
|
17
|
+
/** @ignore */
|
|
18
|
+
static hexToBin(hex) {
|
|
19
|
+
if (hex.length % 2 !== 0) {
|
|
20
|
+
throw new Error('hex string has invalid length!');
|
|
21
|
+
}
|
|
22
|
+
const result = new Uint8Array(hex.length / 2);
|
|
23
|
+
for (let i = 0; i < hex.length / 2; ++i) {
|
|
24
|
+
result[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
/** @ignore */
|
|
29
|
+
static stringToBin(str) {
|
|
30
|
+
const result = new Uint8Array(str.length);
|
|
31
|
+
for (let i = 0; i < str.length; i++) {
|
|
32
|
+
result[i] = str.charCodeAt(i);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
/** @ignore */
|
|
37
|
+
static uint8BeTo64(data) {
|
|
38
|
+
if (data.length < 1 || data.length > 8) {
|
|
39
|
+
throw new Error('Invalid input length');
|
|
40
|
+
}
|
|
41
|
+
let res = bytepack_1.BytePackBigInt.zero;
|
|
42
|
+
const twoPow8 = (0, bytepack_1.BytePackBigInt)(2).pow(8);
|
|
43
|
+
let i = 0;
|
|
44
|
+
switch (9 - data.length) {
|
|
45
|
+
case 1:
|
|
46
|
+
res = res.add(data[i++]);
|
|
47
|
+
/* falls through */
|
|
48
|
+
case 2:
|
|
49
|
+
res = res.multiply(twoPow8).add(data[i++]);
|
|
50
|
+
/* falls through */
|
|
51
|
+
case 3:
|
|
52
|
+
res = res.multiply(twoPow8).add(data[i++]);
|
|
53
|
+
/* falls through */
|
|
54
|
+
case 4:
|
|
55
|
+
res = res.multiply(twoPow8).add(data[i++]);
|
|
56
|
+
/* falls through */
|
|
57
|
+
case 5:
|
|
58
|
+
res = res.multiply(twoPow8).add(data[i++]);
|
|
59
|
+
/* falls through */
|
|
60
|
+
case 6:
|
|
61
|
+
res = res.multiply(twoPow8).add(data[i++]);
|
|
62
|
+
/* falls through */
|
|
63
|
+
case 7:
|
|
64
|
+
res = res.multiply(twoPow8).add(data[i++]);
|
|
65
|
+
/* falls through */
|
|
66
|
+
case 8:
|
|
67
|
+
res = res.multiply(twoPow8).add(data[i++]);
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
throw new Error('Impossible condition');
|
|
71
|
+
}
|
|
72
|
+
return res;
|
|
73
|
+
}
|
|
74
|
+
/** @ignore */
|
|
75
|
+
static uint64To8be(num, size) {
|
|
76
|
+
const res = new Uint8Array(size);
|
|
77
|
+
if (size < 1 || size > 8) {
|
|
78
|
+
throw new Error('Invalid input length');
|
|
79
|
+
}
|
|
80
|
+
const twopow8 = (0, bytepack_1.BytePackBigInt)(2).pow(8);
|
|
81
|
+
for (let i = size - 1; i >= 0; i--) {
|
|
82
|
+
res[i] = num.remainder(twopow8).toJSNumber();
|
|
83
|
+
num = num.divide(twopow8);
|
|
84
|
+
}
|
|
85
|
+
return res;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.default = Helpers;
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gibme/base58",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A simple base58 helper",
|
|
5
|
+
"main": "dist/base58.js",
|
|
6
|
+
"types": "dist/base58.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/*"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "./node_modules/.bin/tsc",
|
|
13
|
+
"test": "yarn test:style && yarn test:mocha",
|
|
14
|
+
"test:style": "yarn style",
|
|
15
|
+
"test:mocha": "./node_modules/.bin/mocha --exit --timeout 30000 --require ts-node/register test/test.ts",
|
|
16
|
+
"style": "./node_modules/.bin/eslint src/**/*.ts test/**/*.ts",
|
|
17
|
+
"fix-style": "./node_modules/.bin/eslint --fix src/**/*.ts test/**/*.ts",
|
|
18
|
+
"fix:style": "yarn fix-style",
|
|
19
|
+
"prepublishOnly": "yarn build"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/gibme-npm/base58.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/gibme-npm/base58/issues"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=16"
|
|
30
|
+
},
|
|
31
|
+
"engineStrict": true,
|
|
32
|
+
"author": {
|
|
33
|
+
"name": "Brandon Lehmann",
|
|
34
|
+
"email": "brandonlehmann@gmail.com"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/mocha": "^10.0.0",
|
|
38
|
+
"@types/node": "^18.11.9",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
40
|
+
"@typescript-eslint/parser": "^5.42.0",
|
|
41
|
+
"eslint": "^8.26.0",
|
|
42
|
+
"eslint-config-standard": "^17.0.0",
|
|
43
|
+
"eslint-plugin-import": "^2.26.0",
|
|
44
|
+
"eslint-plugin-n": "^15.4.0",
|
|
45
|
+
"eslint-plugin-node": "^11.1.0",
|
|
46
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
47
|
+
"mocha": "^10.1.0",
|
|
48
|
+
"ts-node": "^10.9.1",
|
|
49
|
+
"typescript": "^4.8.4"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@gibme/bytepack": "^1.0.0",
|
|
53
|
+
"base58-js": "^1.0.5"
|
|
54
|
+
}
|
|
55
|
+
}
|