@gibme/base58 1.0.0 → 1.0.1
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 -19
- package/README.md +35 -13
- package/dist/base58.d.ts +17 -30
- package/dist/base58.js +55 -55
- package/dist/base58.js.map +1 -0
- package/dist/cryptonote_base58.d.ts +34 -46
- package/dist/cryptonote_base58.js +163 -161
- package/dist/cryptonote_base58.js.map +1 -0
- package/package.json +59 -55
- package/dist/helpers.d.ts +0 -14
- package/dist/helpers.js +0 -88
- package/dist/types.d.ts +0 -6
- package/dist/types.js +0 -5
package/LICENSE
CHANGED
|
@@ -1,19 +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.
|
|
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
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
|
-
# Simple Base58 Library
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
# Simple Base58 Library
|
|
2
|
+
|
|
3
|
+
## Documentation
|
|
4
|
+
|
|
5
|
+
[https://gibme-npm.github.io/base58/](https://gibme-npm.github.io/base58/)
|
|
6
|
+
|
|
7
|
+
## Base58 Sample Code
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import Base58 from '@gibme/base58';
|
|
11
|
+
|
|
12
|
+
const encoded = Base58.encode('02c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cfeb05f9d2');
|
|
13
|
+
|
|
14
|
+
console.log(encoded);
|
|
15
|
+
|
|
16
|
+
const decoded = Base58.decode(encoded);
|
|
17
|
+
|
|
18
|
+
console.log(decoded.toString('hex'));
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## CryptoNote Base58 Sample Code
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import Base58 from '@gibme/base58';
|
|
25
|
+
|
|
26
|
+
const encoded = Base58.cn_encode(
|
|
27
|
+
'9df6ee01c179d13e2a0c52edd8b821e2d53d707e47ddcaaf696644a45563564c2934bd50' +
|
|
28
|
+
'a8faca00a94c5a4dcc3cf070898c2db6ff5990556d08f5a09c8787900dcecab3b77173c1');
|
|
29
|
+
|
|
30
|
+
console.log(encoded);
|
|
31
|
+
|
|
32
|
+
const decoded = Base58.cn_decode(encoded);
|
|
33
|
+
|
|
34
|
+
console.log(decoded.toString('hex'));
|
|
35
|
+
```
|
package/dist/base58.d.ts
CHANGED
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import CryptoNoteBase58 from './cryptonote_base58';
|
|
3
|
+
export default abstract class Base58 extends CryptoNoteBase58 {
|
|
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
|
+
export { Base58 };
|
package/dist/base58.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) 2018-2022 Brandon Lehmann
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @param
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2018-2022, Brandon Lehmann <brandonlehmann@gmail.com>
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.Base58 = void 0;
|
|
26
|
+
const cryptonote_base58_1 = __importDefault(require("./cryptonote_base58"));
|
|
27
|
+
/** @ignore */
|
|
28
|
+
const { base58_to_binary, binary_to_base58 } = require('base58-js');
|
|
29
|
+
class Base58 extends cryptonote_base58_1.default {
|
|
30
|
+
/**
|
|
31
|
+
* Decodes the Base58 encoded string into a Buffer
|
|
32
|
+
*
|
|
33
|
+
* @param encoded
|
|
34
|
+
*/
|
|
35
|
+
static decode(encoded) {
|
|
36
|
+
return Buffer.from(base58_to_binary(encoded));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Encodes the data into Base58
|
|
40
|
+
*
|
|
41
|
+
* @param data
|
|
42
|
+
*/
|
|
43
|
+
static encode(data) {
|
|
44
|
+
if (data instanceof Buffer) {
|
|
45
|
+
data = data.valueOf();
|
|
46
|
+
}
|
|
47
|
+
else if (typeof data === 'string') {
|
|
48
|
+
data = Buffer.from(data, 'hex').valueOf();
|
|
49
|
+
}
|
|
50
|
+
return binary_to_base58(data);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.default = Base58;
|
|
54
|
+
exports.Base58 = Base58;
|
|
55
|
+
//# sourceMappingURL=base58.js.map
|
|
@@ -0,0 +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;AAEnD,cAAc;AACd,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAEpE,MAA8B,MAAO,SAAQ,2BAAgB;IACzD;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAChB,OAAe;QAEf,OAAO,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,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,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACJ;AA1BD,yBA0BC;AAEQ,wBAAM"}
|
|
@@ -1,46 +1,34 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
* @
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export default abstract class CryptoNoteBase58 {
|
|
3
|
+
/**
|
|
4
|
+
* Decodes the CryptoNote Base58 encoded string into a Buffer
|
|
5
|
+
*
|
|
6
|
+
* @param encoded
|
|
7
|
+
*/
|
|
8
|
+
static cn_decode(encoded: string): Buffer;
|
|
9
|
+
/**
|
|
10
|
+
* Encodes the data into CryptoNote Base58 string
|
|
11
|
+
*
|
|
12
|
+
* @param data
|
|
13
|
+
*/
|
|
14
|
+
static cn_encode(data: string | Uint8Array | Buffer): string;
|
|
15
|
+
/**
|
|
16
|
+
* Decodes a Base58 block
|
|
17
|
+
*
|
|
18
|
+
* @param data
|
|
19
|
+
* @param buffer
|
|
20
|
+
* @param index
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private static decodeBlock;
|
|
24
|
+
/**
|
|
25
|
+
* Encodes the data into a block for Base58
|
|
26
|
+
*
|
|
27
|
+
* @param data
|
|
28
|
+
* @param buffer
|
|
29
|
+
* @param index
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
private static encodeBlock;
|
|
33
|
+
}
|
|
34
|
+
export { CryptoNoteBase58 };
|
|
@@ -1,161 +1,163 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) 2018-2022 Brandon Lehmann
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
exports.default = CryptoNoteBase58;
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2018-2022, Brandon Lehmann <brandonlehmann@gmail.com>
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.CryptoNoteBase58 = void 0;
|
|
23
|
+
const bytepack_1 = require("@gibme/bytepack");
|
|
24
|
+
/** @ignore */
|
|
25
|
+
const ALPHABET = (() => {
|
|
26
|
+
const str = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
27
|
+
return str.split('')
|
|
28
|
+
.map(char => char.charCodeAt(0));
|
|
29
|
+
})();
|
|
30
|
+
/** @ignore */
|
|
31
|
+
const ENCODED_BLOCK_SIZES = [0, 2, 3, 5, 6, 7, 9, 10, 11];
|
|
32
|
+
/** @ignore */
|
|
33
|
+
const FULL_BLOCK_SIZE = 8;
|
|
34
|
+
/** @ignore */
|
|
35
|
+
const FULL_ENCODED_BLOCK_SIZE = 11;
|
|
36
|
+
/** @ignore */
|
|
37
|
+
const UINT64_MAX = (0, bytepack_1.BytePackBigInt)(2).pow(64);
|
|
38
|
+
class CryptoNoteBase58 {
|
|
39
|
+
/**
|
|
40
|
+
* Decodes the CryptoNote Base58 encoded string into a Buffer
|
|
41
|
+
*
|
|
42
|
+
* @param encoded
|
|
43
|
+
*/
|
|
44
|
+
static cn_decode(encoded) {
|
|
45
|
+
const enc = Buffer.from(encoded).valueOf();
|
|
46
|
+
if (enc.length === 0) {
|
|
47
|
+
return Buffer.alloc(0);
|
|
48
|
+
}
|
|
49
|
+
const fullBlockCount = Math.floor(enc.length / FULL_ENCODED_BLOCK_SIZE);
|
|
50
|
+
const lastBlockSize = enc.length % FULL_ENCODED_BLOCK_SIZE;
|
|
51
|
+
const lastBlockDecodedSize = ENCODED_BLOCK_SIZES.indexOf(lastBlockSize);
|
|
52
|
+
if (lastBlockDecodedSize < 0) {
|
|
53
|
+
throw new Error('Invalid encoded length');
|
|
54
|
+
}
|
|
55
|
+
const dataSize = fullBlockCount * FULL_BLOCK_SIZE + lastBlockDecodedSize;
|
|
56
|
+
let result = new Uint8Array(dataSize);
|
|
57
|
+
for (let i = 0; i < fullBlockCount; i++) {
|
|
58
|
+
result = CryptoNoteBase58.decodeBlock(enc.subarray(i * FULL_ENCODED_BLOCK_SIZE, i * FULL_ENCODED_BLOCK_SIZE + FULL_ENCODED_BLOCK_SIZE), result, i * FULL_BLOCK_SIZE);
|
|
59
|
+
}
|
|
60
|
+
if (lastBlockSize > 0) {
|
|
61
|
+
result = CryptoNoteBase58.decodeBlock(enc.subarray(fullBlockCount * FULL_ENCODED_BLOCK_SIZE, fullBlockCount * FULL_ENCODED_BLOCK_SIZE + lastBlockSize), result, fullBlockCount * FULL_BLOCK_SIZE);
|
|
62
|
+
}
|
|
63
|
+
return Buffer.from(result);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Encodes the data into CryptoNote Base58 string
|
|
67
|
+
*
|
|
68
|
+
* @param data
|
|
69
|
+
*/
|
|
70
|
+
static cn_encode(data) {
|
|
71
|
+
if (data instanceof Buffer) {
|
|
72
|
+
data = data.toString('hex');
|
|
73
|
+
}
|
|
74
|
+
else if (data instanceof Uint8Array) {
|
|
75
|
+
data = Buffer.from(data).toString('hex');
|
|
76
|
+
}
|
|
77
|
+
const _data = Buffer.from(data, 'hex').valueOf();
|
|
78
|
+
if (_data.length === 0) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
const fullBlockCount = Math.floor(_data.length / FULL_BLOCK_SIZE);
|
|
82
|
+
const lastBlockSize = _data.length % FULL_BLOCK_SIZE;
|
|
83
|
+
const resSize = fullBlockCount * FULL_ENCODED_BLOCK_SIZE + ENCODED_BLOCK_SIZES[lastBlockSize];
|
|
84
|
+
let result = new Uint8Array(resSize);
|
|
85
|
+
for (let i = 0; i < resSize; ++i) {
|
|
86
|
+
result[i] = ALPHABET[0];
|
|
87
|
+
}
|
|
88
|
+
for (let i = 0; i < fullBlockCount; i++) {
|
|
89
|
+
result = CryptoNoteBase58.encodeBlock(_data.subarray(i * FULL_BLOCK_SIZE, i * FULL_BLOCK_SIZE + FULL_BLOCK_SIZE), result, i *
|
|
90
|
+
FULL_ENCODED_BLOCK_SIZE);
|
|
91
|
+
}
|
|
92
|
+
if (lastBlockSize > 0) {
|
|
93
|
+
result = CryptoNoteBase58.encodeBlock(_data.subarray(fullBlockCount * FULL_BLOCK_SIZE, fullBlockCount * FULL_BLOCK_SIZE + lastBlockSize), result, fullBlockCount * FULL_ENCODED_BLOCK_SIZE);
|
|
94
|
+
}
|
|
95
|
+
return Buffer.from(result).toString();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Decodes a Base58 block
|
|
99
|
+
*
|
|
100
|
+
* @param data
|
|
101
|
+
* @param buffer
|
|
102
|
+
* @param index
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
static decodeBlock(data, buffer, index) {
|
|
106
|
+
if (data.length < 1 || data.length > FULL_ENCODED_BLOCK_SIZE) {
|
|
107
|
+
throw new Error('Invalid block length: ' + data.length);
|
|
108
|
+
}
|
|
109
|
+
const resSize = ENCODED_BLOCK_SIZES.indexOf(data.length);
|
|
110
|
+
if (resSize <= 0) {
|
|
111
|
+
throw new Error('Invalid block size');
|
|
112
|
+
}
|
|
113
|
+
let resNum = bytepack_1.BytePackBigInt.zero;
|
|
114
|
+
let order = bytepack_1.BytePackBigInt.one;
|
|
115
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
116
|
+
const digit = ALPHABET.indexOf(data[i]);
|
|
117
|
+
if (digit < 0) {
|
|
118
|
+
throw new Error('Invalid symbol');
|
|
119
|
+
}
|
|
120
|
+
const product = order.multiply(digit).add(resNum);
|
|
121
|
+
if (product.compare(UINT64_MAX) === 1) {
|
|
122
|
+
throw new Error('Overflow');
|
|
123
|
+
}
|
|
124
|
+
resNum = product;
|
|
125
|
+
order = order.multiply(ALPHABET.length);
|
|
126
|
+
}
|
|
127
|
+
if (resSize < FULL_BLOCK_SIZE && ((0, bytepack_1.BytePackBigInt)(2).pow(8 * resSize).compare(resNum) <= 0)) {
|
|
128
|
+
throw new Error('Overflow 2');
|
|
129
|
+
}
|
|
130
|
+
const value = new bytepack_1.Writer()
|
|
131
|
+
.uint64_t(resNum, true)
|
|
132
|
+
.buffer
|
|
133
|
+
.valueOf();
|
|
134
|
+
buffer.set(value, index);
|
|
135
|
+
return buffer;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Encodes the data into a block for Base58
|
|
139
|
+
*
|
|
140
|
+
* @param data
|
|
141
|
+
* @param buffer
|
|
142
|
+
* @param index
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
static encodeBlock(data, buffer, index) {
|
|
146
|
+
if (data.length < 1 || data.length > FULL_ENCODED_BLOCK_SIZE) {
|
|
147
|
+
throw new Error('Invalid block length: ' + data.length);
|
|
148
|
+
}
|
|
149
|
+
let num = new bytepack_1.Reader(data).uint64_t(true);
|
|
150
|
+
let i = ENCODED_BLOCK_SIZES[data.length] - 1;
|
|
151
|
+
while (num.compare(0) === 1) {
|
|
152
|
+
const div = num.divmod(ALPHABET.length);
|
|
153
|
+
const remainder = div.remainder;
|
|
154
|
+
num = div.quotient;
|
|
155
|
+
buffer[index + i] = ALPHABET[remainder.toJSNumber()];
|
|
156
|
+
i--;
|
|
157
|
+
}
|
|
158
|
+
return buffer;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.default = CryptoNoteBase58;
|
|
162
|
+
exports.CryptoNoteBase58 = CryptoNoteBase58;
|
|
163
|
+
//# sourceMappingURL=cryptonote_base58.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cryptonote_base58.js","sourceRoot":"","sources":["../src/cryptonote_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,8CA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K,CAAC,CAAC;QAEzB,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;;;;OAOG;IACK,MAAM,CAAC,WAAW,CAAE,IAAgB,EAAE,MAAkB,EAAE,KAAa;QAC3E,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,uBAAuB,EAAE;YAC1D,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;SAC3D;QAED,IAAI,GAAG,GAAG,IAAI,iBAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAE1C,IAAI,CAAC,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAE7C,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;YACzB,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAExC,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;YAEhC,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC;YAEnB,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC;YAErD,CAAC,EAAE,CAAC;SACP;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AA/LD,mCA+LC;AAEQ,4CAAgB"}
|
package/package.json
CHANGED
|
@@ -1,55 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@gibme/base58",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "dist/base58.js",
|
|
6
|
-
"types": "dist/base58.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist/*"
|
|
9
|
-
],
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"test
|
|
16
|
-
"style": "
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"@
|
|
41
|
-
"
|
|
42
|
-
"eslint-
|
|
43
|
-
"eslint
|
|
44
|
-
"eslint
|
|
45
|
-
"eslint-
|
|
46
|
-
"eslint-plugin-
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
}
|
|
55
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@gibme/base58",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Base58 Library",
|
|
5
|
+
"main": "dist/base58.js",
|
|
6
|
+
"types": "dist/base58.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/*"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "yarn build:typescript",
|
|
13
|
+
"build:docs": "./node_modules/.bin/typedoc",
|
|
14
|
+
"build:typescript": "./node_modules/.bin/tsc",
|
|
15
|
+
"test": "yarn test:style && yarn test:mocha",
|
|
16
|
+
"test:style": "yarn style",
|
|
17
|
+
"test:mocha": "./node_modules/.bin/mocha --exit --timeout 30000 --require ts-node/register test/test.ts",
|
|
18
|
+
"style": "./node_modules/.bin/eslint src/**/*.ts test/**/*.ts",
|
|
19
|
+
"fix-style": "./node_modules/.bin/eslint --fix src/**/*.ts test/**/*.ts",
|
|
20
|
+
"fix:style": "yarn fix-style",
|
|
21
|
+
"prepublishOnly": "yarn build"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/gibme-npm/base58.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/gibme-npm/base58/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://gibme-npm.github.io/base58/",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=16"
|
|
33
|
+
},
|
|
34
|
+
"engineStrict": true,
|
|
35
|
+
"author": {
|
|
36
|
+
"name": "Brandon Lehmann",
|
|
37
|
+
"email": "brandonlehmann@gmail.com"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/mocha": "^10.0.0",
|
|
41
|
+
"@types/node": "^18.11.9",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
43
|
+
"@typescript-eslint/parser": "^5.42.0",
|
|
44
|
+
"eslint": "^8.26.0",
|
|
45
|
+
"eslint-config-standard": "^17.0.0",
|
|
46
|
+
"eslint-plugin-import": "^2.26.0",
|
|
47
|
+
"eslint-plugin-n": "^15.4.0",
|
|
48
|
+
"eslint-plugin-node": "^11.1.0",
|
|
49
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
50
|
+
"mocha": "^10.1.0",
|
|
51
|
+
"ts-node": "^10.9.1",
|
|
52
|
+
"typedoc": "^0.23.21",
|
|
53
|
+
"typescript": "^4.8.4"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@gibme/bytepack": "^1.0.2",
|
|
57
|
+
"base58-js": "^1.0.5"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/dist/helpers.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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
DELETED