From 242e323a08bf431820045bac08f925e8767a264b Mon Sep 17 00:00:00 2001 From: bochaco Date: Tue, 12 Mar 2019 12:28:31 -0300 Subject: [PATCH] feat/sytem-uri: use base32 encoding for the scheme generated to register in the system URI --- package.json | 1 + src/api/auth.js | 15 +++++---------- yarn.lock | 10 +++++++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index b4f611b..0b3642c 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "src/native/*.js" ], "dependencies": { + "base32": "0.0.6", "cids": "bochaco/js-cid#temp-use-bochaco-multicodec", "cross-env": "5.1.3", "deps_downloader": "https://s3.eu-west-2.amazonaws.com/deps-downloader/deps_downloader-0.3.0.tgz", diff --git a/src/api/auth.js b/src/api/auth.js index 3f8d526..5741c3d 100644 --- a/src/api/auth.js +++ b/src/api/auth.js @@ -18,6 +18,7 @@ const { useMockByDefault } = require('../helpers'); const { validateShareMDataPermissions } = require('../helpers'); const errConst = require('../error_const'); const makeError = require('../native/_error.js'); +const base32 = require('base32'); const makeAppInfo = nativeH.makeAppInfo; const makePermissions = nativeH.makePermissions; @@ -25,18 +26,12 @@ const makeShareMDataPermissions = nativeH.makeShareMDataPermissions; /** * @private -* Generates the app's URI converting the string into a base64 format, removing -* characters or symbols which are not valid for a URL like '=' sign, -* and making it lower case. +* Generates the app's URI converting the string into a base32 format +* which is case insensitive. */ const genAppUri = (str) => { - const urlSafeBase64 = (Buffer.from(str)) - .toString('base64') - .replace(/\+/g, '-') // Convert '+' to '-' - .replace(/\//g, '_') // Convert '/' to '_' - .replace(/=+$/, '') // Remove ending '=' - .toLowerCase(); - return `safe-${urlSafeBase64}`; + const urlSafeBase32 = base32.encode(str); + return `safe-${urlSafeBase32}`; }; /** diff --git a/yarn.lock b/yarn.lock index ace270f..7c93a01 100644 --- a/yarn.lock +++ b/yarn.lock @@ -285,6 +285,13 @@ base-x@^3.0.2: dependencies: safe-buffer "^5.0.1" +base32@0.0.6: + version "0.0.6" + resolved "https://registry.yarnpkg.com/base32/-/base32-0.0.6.tgz#79038bcb5aec2d8f22bcc1c28402924f50a6d2ac" + integrity sha1-eQOLy1rsLY8ivMHChAKST1Cm0qw= + dependencies: + optimist ">=0.1.0" + base64url@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/base64url/-/base64url-3.0.1.tgz#6399d572e2bc3f90a9a8b22d5dbb0a32d33f788d" @@ -1865,9 +1872,10 @@ onetime@^1.0.0: version "1.1.0" resolved "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz#a1f7838f8314c516f05ecefcbc4ccfe04b4ed789" -optimist@^0.6.1: +optimist@>=0.1.0, optimist@^0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" + integrity sha1-2j6nRob6IaGaERwybpDrFaAZZoY= dependencies: minimist "~0.0.1" wordwrap "~0.0.2"