@gibme/base58 1.0.1 → 1.0.4
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/dist/base58-js.d.ts +17 -0
- package/dist/base58-js.js +111 -0
- package/dist/base58-js.js.map +1 -0
- package/dist/base58.js +3 -4
- package/dist/base58.js.map +1 -1
- package/package.json +15 -15
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a base58 string to the corresponding binary representation
|
|
3
|
+
*
|
|
4
|
+
* @param base58String
|
|
5
|
+
*/
|
|
6
|
+
export declare const base58_to_binary: (base58String: string) => Uint8Array;
|
|
7
|
+
/**
|
|
8
|
+
* Converts a Uint8Array into a base58 string
|
|
9
|
+
*
|
|
10
|
+
* @param uint8array
|
|
11
|
+
*/
|
|
12
|
+
export declare const binary_to_base58: (uint8array: Uint8Array) => string;
|
|
13
|
+
declare const _default: {
|
|
14
|
+
binary_to_base58: (uint8array: Uint8Array) => string;
|
|
15
|
+
base58_to_binary: (base58String: string) => Uint8Array;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2021, pur3missh
|
|
3
|
+
// Copyright (c) 2023, Brandon Lehmann <brandonlehmann@gmail.com>
|
|
4
|
+
//
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
// furnished to do so, subject to the following conditions:
|
|
11
|
+
//
|
|
12
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
// copies or substantial portions of the Software.
|
|
14
|
+
//
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
// SOFTWARE.
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.binary_to_base58 = exports.base58_to_binary = void 0;
|
|
24
|
+
/**
|
|
25
|
+
* This code has been copied over from the base58-js package and translated to typescript
|
|
26
|
+
* as the author of base58-js has no included typings at this time and it is not available
|
|
27
|
+
* via @types/base58-js
|
|
28
|
+
*/
|
|
29
|
+
/** @ignore */
|
|
30
|
+
const base58_chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
31
|
+
/** @ignore */
|
|
32
|
+
const create_base58_map = () => {
|
|
33
|
+
const base58M = Array(256).fill(-1);
|
|
34
|
+
for (let i = 0; i < base58_chars.length; ++i) {
|
|
35
|
+
base58M[base58_chars.charCodeAt(i)] = i;
|
|
36
|
+
}
|
|
37
|
+
return base58M;
|
|
38
|
+
};
|
|
39
|
+
/** @ignore */
|
|
40
|
+
const base58Map = create_base58_map();
|
|
41
|
+
/**
|
|
42
|
+
* Converts a base58 string to the corresponding binary representation
|
|
43
|
+
*
|
|
44
|
+
* @param base58String
|
|
45
|
+
*/
|
|
46
|
+
const base58_to_binary = (base58String) => {
|
|
47
|
+
if (base58String.match(/[IOl0]/gmu)) {
|
|
48
|
+
throw new Error(`Invalid base58 character “${base58String.match(/[IOl0]/gmu)}”`);
|
|
49
|
+
}
|
|
50
|
+
const lz = base58String.match(/^1+/gmu);
|
|
51
|
+
const psz = lz ? lz[0].length : 0;
|
|
52
|
+
const size = ((base58String.length - psz) * (Math.log(58) / Math.log(256)) + 1) >>> 0;
|
|
53
|
+
const base58_match = base58String.match(/./gmu);
|
|
54
|
+
const psz_Uint = new Uint8Array(psz);
|
|
55
|
+
let base58_temp = new Uint8Array();
|
|
56
|
+
if (base58_match) {
|
|
57
|
+
base58_temp = base58_match.map(i => base58_chars.indexOf(i))
|
|
58
|
+
.reduce((acc, i) => {
|
|
59
|
+
acc = acc.map((j) => {
|
|
60
|
+
const x = j * 58 + i;
|
|
61
|
+
i = x >> 8;
|
|
62
|
+
return x;
|
|
63
|
+
});
|
|
64
|
+
return acc;
|
|
65
|
+
}, new Uint8Array(size))
|
|
66
|
+
.reverse()
|
|
67
|
+
.filter((lastValue => value =>
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
(lastValue = lastValue || value))(false));
|
|
71
|
+
}
|
|
72
|
+
return new Uint8Array([
|
|
73
|
+
...psz_Uint,
|
|
74
|
+
...base58_temp
|
|
75
|
+
]);
|
|
76
|
+
};
|
|
77
|
+
exports.base58_to_binary = base58_to_binary;
|
|
78
|
+
/**
|
|
79
|
+
* Converts a Uint8Array into a base58 string
|
|
80
|
+
*
|
|
81
|
+
* @param uint8array
|
|
82
|
+
*/
|
|
83
|
+
const binary_to_base58 = (uint8array) => {
|
|
84
|
+
const result = [];
|
|
85
|
+
for (const byte of uint8array) {
|
|
86
|
+
let carry = byte;
|
|
87
|
+
for (let j = 0; j < result.length; ++j) {
|
|
88
|
+
const x = (base58Map[result[j]] << 8) + carry;
|
|
89
|
+
result[j] = base58_chars.charCodeAt(x % 58);
|
|
90
|
+
carry = (x / 58) | 0;
|
|
91
|
+
}
|
|
92
|
+
while (carry) {
|
|
93
|
+
result.push(base58_chars.charCodeAt(carry % 58));
|
|
94
|
+
carry = (carry / 58) | 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const byte of uint8array) {
|
|
98
|
+
if (byte)
|
|
99
|
+
break;
|
|
100
|
+
else
|
|
101
|
+
result.push('1'.charCodeAt(0));
|
|
102
|
+
}
|
|
103
|
+
result.reverse();
|
|
104
|
+
return String.fromCharCode(...result);
|
|
105
|
+
};
|
|
106
|
+
exports.binary_to_base58 = binary_to_base58;
|
|
107
|
+
exports.default = {
|
|
108
|
+
binary_to_base58: exports.binary_to_base58,
|
|
109
|
+
base58_to_binary: exports.base58_to_binary
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=base58-js.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base58-js.js","sourceRoot":"","sources":["../src/base58-js.ts"],"names":[],"mappings":";AAAA,gCAAgC;AAChC,iEAAiE;AACjE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;;;AAEZ;;;;GAIG;AAEH,cAAc;AACd,MAAM,YAAY,GACd,4DAA4D,CAAC;AAEjE,cAAc;AACd,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QAC1C,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;KAC3C;IAED,OAAO,OAAO,CAAC;AACn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I;YAAE,MAAM;;YACX,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;KACvC;IAED,MAAM,CAAC,OAAO,EAAE,CAAC;IAEjB,OAAO,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,CAAC;AAC1C,CAAC,CAAC;AA7BW,QAAA,gBAAgB,oBA6B3B;AAEF,kBAAe;IACX,gBAAgB,EAAhB,wBAAgB;IAChB,gBAAgB,EAAhB,wBAAgB;CACnB,CAAC"}
|
package/dist/base58.js
CHANGED
|
@@ -24,8 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.Base58 = void 0;
|
|
26
26
|
const cryptonote_base58_1 = __importDefault(require("./cryptonote_base58"));
|
|
27
|
-
|
|
28
|
-
const { base58_to_binary, binary_to_base58 } = require('base58-js');
|
|
27
|
+
const base58_js_1 = require("./base58-js");
|
|
29
28
|
class Base58 extends cryptonote_base58_1.default {
|
|
30
29
|
/**
|
|
31
30
|
* Decodes the Base58 encoded string into a Buffer
|
|
@@ -33,7 +32,7 @@ class Base58 extends cryptonote_base58_1.default {
|
|
|
33
32
|
* @param encoded
|
|
34
33
|
*/
|
|
35
34
|
static decode(encoded) {
|
|
36
|
-
return Buffer.from(base58_to_binary(encoded));
|
|
35
|
+
return Buffer.from((0, base58_js_1.base58_to_binary)(encoded));
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
38
|
* Encodes the data into Base58
|
|
@@ -47,7 +46,7 @@ class Base58 extends cryptonote_base58_1.default {
|
|
|
47
46
|
else if (typeof data === 'string') {
|
|
48
47
|
data = Buffer.from(data, 'hex').valueOf();
|
|
49
48
|
}
|
|
50
|
-
return binary_to_base58(data);
|
|
49
|
+
return (0, base58_js_1.binary_to_base58)(data);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
exports.default = Base58;
|
package/dist/base58.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base58.js","sourceRoot":"","sources":["../src/base58.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;;;;;;AAEZ,4EAAmD;
|
|
1
|
+
{"version":3,"file":"base58.js","sourceRoot":"","sources":["../src/base58.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;;;;;;AAEZ,4EAAmD;AACnD,2CAAiE;AAEjE,MAA8B,MAAO,SAAQ,2BAAgB;IACzD;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAChB,OAAe;QAEf,OAAO,MAAM,CAAC,IAAI,CAAC,IAAA,4BAAgB,EAAC,OAAO,CAAC,CAAC,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAE,IAAkC;QACpD,IAAI,IAAI,YAAY,MAAM,EAAE;YACxB,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;SACzB;aAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YACjC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;SAC7C;QAED,OAAO,IAAA,4BAAgB,EAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACJ;AA1BD,yBA0BC;AAEQ,wBAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gibme/base58",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Base58 Library",
|
|
5
5
|
"main": "dist/base58.js",
|
|
6
6
|
"types": "dist/base58.d.ts",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"build": "yarn build:typescript",
|
|
13
13
|
"build:docs": "./node_modules/.bin/typedoc",
|
|
14
14
|
"build:typescript": "./node_modules/.bin/tsc",
|
|
15
|
-
"test": "yarn test:style && yarn test:mocha",
|
|
15
|
+
"test": "yarn test:style && yarn test:typecheck && yarn test:mocha",
|
|
16
|
+
"test:typecheck": "./node_modules/.bin/tsc --noEmit",
|
|
16
17
|
"test:style": "yarn style",
|
|
17
18
|
"test:mocha": "./node_modules/.bin/mocha --exit --timeout 30000 --require ts-node/register test/test.ts",
|
|
18
19
|
"style": "./node_modules/.bin/eslint src/**/*.ts test/**/*.ts",
|
|
@@ -37,23 +38,22 @@
|
|
|
37
38
|
"email": "brandonlehmann@gmail.com"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/mocha": "^10.0.
|
|
41
|
-
"@types/node": "^
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
43
|
-
"@typescript-eslint/parser": "^
|
|
44
|
-
"eslint": "^8.
|
|
45
|
-
"eslint-config-standard": "^17.
|
|
46
|
-
"eslint-plugin-import": "^2.
|
|
47
|
-
"eslint-plugin-n": "^
|
|
41
|
+
"@types/mocha": "^10.0.1",
|
|
42
|
+
"@types/node": "^20.4.8",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
44
|
+
"@typescript-eslint/parser": "^6.2.1",
|
|
45
|
+
"eslint": "^8.46.0",
|
|
46
|
+
"eslint-config-standard": "^17.1.0",
|
|
47
|
+
"eslint-plugin-import": "^2.28.0",
|
|
48
|
+
"eslint-plugin-n": "^16.0.1",
|
|
48
49
|
"eslint-plugin-node": "^11.1.0",
|
|
49
50
|
"eslint-plugin-promise": "^6.1.1",
|
|
50
|
-
"mocha": "^10.
|
|
51
|
+
"mocha": "^10.2.0",
|
|
51
52
|
"ts-node": "^10.9.1",
|
|
52
|
-
"typedoc": "^0.
|
|
53
|
-
"typescript": "^
|
|
53
|
+
"typedoc": "^0.24.8",
|
|
54
|
+
"typescript": "^5.1.6"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
|
-
"@gibme/bytepack": "^1.0.
|
|
57
|
-
"base58-js": "^1.0.5"
|
|
57
|
+
"@gibme/bytepack": "^1.0.4"
|
|
58
58
|
}
|
|
59
59
|
}
|