use base-x to support both base64 and base58

This commit is contained in:
Bruno Windels 2020-09-17 11:36:54 +02:00
parent abfde76e24
commit 4ec0e67384
4 changed files with 31 additions and 13 deletions

View File

@ -49,7 +49,7 @@
"dependencies": {
"aes-js": "^3.1.2",
"another-json": "^0.2.0",
"bs58": "^4.0.1",
"base-x": "^3.0.8",
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz"
}
}

View File

@ -75,11 +75,11 @@ async function populateLib() {
path.join(modulesDir, 'another-json/another-json.js'),
path.join(libDir, "another-json/index.js")
);
// transpile bs58 to esm
await fs.mkdir(path.join(libDir, "bs58/"));
// transpile base-x to esm
await fs.mkdir(path.join(libDir, "base-x/"));
await commonjsToESM(
path.join(modulesDir, 'bs58/index.js'),
path.join(libDir, "bs58/index.js")
path.join(modulesDir, 'base-x/src/index.js'),
path.join(libDir, "base-x/index.js")
);
// transpile aesjs to esm
await fs.mkdir(path.join(libDir, "aes-js/"));

View File

@ -0,0 +1,25 @@
/*
Copyright 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import base from "../../lib/base-x/index.js";
// Dictionaries come from https://github.com/cryptocoinjs/base-x/, MIT licenced.
const BASE58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
export const base58 = base(BASE58);
export const base64 = base(BASE64);

View File

@ -945,7 +945,7 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
base-x@^3.0.2:
base-x@^3.0.8:
version "3.0.8"
resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.8.tgz#1e1106c2537f0162e8b52474a557ebb09000018d"
integrity sha512-Rl/1AWP4J/zRrk54hhlxH4drNxPJXYUaKffODVI53/dAsV4t9fBxyxYKAVPU1XBHxYwOWP9h9H0hM2MVw4YfJA==
@ -975,13 +975,6 @@ browserslist@^4.12.0, browserslist@^4.8.5:
escalade "^3.0.2"
node-releases "^1.1.60"
bs58@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a"
integrity sha1-vhYedsNU9veIrkBx9j806MTwpCo=
dependencies:
base-x "^3.0.2"
builtin-modules@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.1.0.tgz#aad97c15131eb76b65b50ef208e7584cd76a7484"