diff --git a/package.json b/package.json index a142e22a..a98733d4 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/scripts/post-install.mjs b/scripts/post-install.mjs index 43177fd6..77df95f3 100644 --- a/scripts/post-install.mjs +++ b/scripts/post-install.mjs @@ -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/")); diff --git a/src/utils/base-encoding.js b/src/utils/base-encoding.js new file mode 100644 index 00000000..611ec043 --- /dev/null +++ b/src/utils/base-encoding.js @@ -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); diff --git a/yarn.lock b/yarn.lock index c3b84f26..60e500c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"