Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

feat/sytem-uri: use base32 encoding for the scheme generated to register in the system URI #356

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 5 additions & 10 deletions src/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,20 @@ 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;
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}`;
};

/**
Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ base-x@^3.0.2:
dependencies:
safe-buffer "^5.0.1"

[email protected]:
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"
Expand Down Expand Up @@ -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"
Expand Down