Skip to content

Commit

Permalink
fix(buffer): Update Buffer methods to use Buffer.from
Browse files Browse the repository at this point in the history
Avoids JS deprecation error.
  • Loading branch information
joshuef committed Apr 10, 2019
1 parent 4c65f32 commit fb25539
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
2 changes: 0 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
runtime = electron
target = 2.0.7
target_arch = x64
disturl = https://atom.io/download/atom-shell
tag-version-prefix=""
24 changes: 12 additions & 12 deletions app/extensions/safe/ffi/authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const _decodeReqPool = Symbol( 'decodeReqPool' );
* characters or symbols which are not valid for a URL like '=' sign,
* and making it lower case.
*/
const genAppUri = str => {
const urlSafeBase64 = new Buffer( str )
const genAppUri = ( str ) => {
const urlSafeBase64 = new Buffer.from( str )
.toString( 'base64' )
.replace( /\+/g, '-' ) // Convert '+' to '-'
.replace( /\//g, '_' ) // Convert '/' to '_'
Expand Down Expand Up @@ -454,7 +454,7 @@ class Authenticator extends SafeLib {
authReq
};
logger.info( 'Authenticator.js decoded authReq result: ', result );
return this._isAlreadyAuthorised( authReq ).then( resolved => {
return this._isAlreadyAuthorised( authReq ).then( ( resolved ) => {
if ( resolved.isAuthorised ) {
result.isAuthorised = true;
if ( resolved.previouslyAuthorisedContainers ) {
Expand Down Expand Up @@ -491,7 +491,7 @@ class Authenticator extends SafeLib {
logger.info( 'Authenticator.js decoded contReq result: ', result );

return this._isAlreadyAuthorisedContainer( contReq ).then(
isAuthorised => {
( isAuthorised ) => {
if ( isAuthorised ) {
result.isAuthorised = true;
}
Expand Down Expand Up @@ -528,12 +528,12 @@ class Authenticator extends SafeLib {
}

await Promise.all(
tempArr.map( i => {
tempArr.map( ( i ) => {
const mdata = mDataReq.mdata[i];
return this._appsAccessingMData(
mdata.name,
mdata.type_tag
).then( res => {
).then( ( res ) => {
appAccess[i] = res;
} );
} )
Expand Down Expand Up @@ -934,7 +934,7 @@ class Authenticator extends SafeLib {
}

_updateAppList() {
this.getRegisteredApps().then( apps => {
this.getRegisteredApps().then( ( apps ) => {
if (
this[_appListUpdateListener] &&
this[_appListUpdateListener].len() !== 0
Expand Down Expand Up @@ -1013,7 +1013,7 @@ class Authenticator extends SafeLib {
}

const appId = ref.reinterpret( appIdPtr, appIdLen );
return this._encodeUnRegisteredResp( reqId, appId ).then( res =>
return this._encodeUnRegisteredResp( reqId, appId ).then( ( res ) =>
resolve( res )
);
}
Expand All @@ -1026,9 +1026,9 @@ class Authenticator extends SafeLib {
return new Promise( ( resolve, reject ) => {
try {
this.getRegisteredApps()
.then( authorisedApps => {
.then( ( authorisedApps ) => {
let previouslyAuthorisedContainers;
const isAuthorised = authorisedApps.some( app => {
const isAuthorised = authorisedApps.some( ( app ) => {
const appIsPresent = lodash.isEqual( app.app_info, req.app );
if ( appIsPresent && app.containers ) {
previouslyAuthorisedContainers = app.containers;
Expand All @@ -1052,8 +1052,8 @@ class Authenticator extends SafeLib {
let app = null;
return new Promise( ( resolve, reject ) => {
try {
this.getRegisteredApps().then( authorisedApps => {
app = authorisedApps.filter( apps =>
this.getRegisteredApps().then( ( authorisedApps ) => {
app = authorisedApps.filter( ( apps ) =>
lodash.isEqual( apps.app_info, req.app )
);
// Return false if no apps found match with requested app
Expand Down
30 changes: 15 additions & 15 deletions app/extensions/safe/ffi/refs/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ export const parseArray = ( type, arrayBuf, len ) => {
return ArrType( arrPtr );
};

export const parseAppExchangeInfo = appExchangeInfo => ( {
export const parseAppExchangeInfo = ( appExchangeInfo ) => ( {
id: appExchangeInfo.id,
scope: appExchangeInfo.scope,
name: appExchangeInfo.name,
vendor: appExchangeInfo.vendor
} );

const parsePermissionSet = perms => ( {
const parsePermissionSet = ( perms ) => ( {
read: perms.read,
insert: perms.insert,
update: perms.update,
delete: perms.delete,
manage_permissions: perms.manage_permissions
} );

export const parseContainerPermissions = containerPermissions => ( {
export const parseContainerPermissions = ( containerPermissions ) => ( {
cont_name: containerPermissions.cont_name,
access: parsePermissionSet( containerPermissions.access )
} );
Expand All @@ -48,7 +48,7 @@ export const parseContainerPermissionsArray = (
return res;
};

export const parseRegisteredApp = registeredApp => ( {
export const parseRegisteredApp = ( registeredApp ) => ( {
app_info: parseAppExchangeInfo( registeredApp.app_info ),
containers: parseContainerPermissionsArray(
registeredApp.containers,
Expand All @@ -72,7 +72,7 @@ export const parseRegisteredAppArray = ( registeredAppArray, len ) => {
return res;
};

export const parseAuthReq = authReq => ( {
export const parseAuthReq = ( authReq ) => ( {
app: parseAppExchangeInfo( authReq.app ),
app_container: authReq.app_container,
containers: parseContainerPermissionsArray(
Expand All @@ -83,7 +83,7 @@ export const parseAuthReq = authReq => ( {
containers_cap: authReq.containers_cap
} );

export const parseContainerReq = containersReq => ( {
export const parseContainerReq = ( containersReq ) => ( {
app: parseAppExchangeInfo( containersReq.app ),
containers: parseContainerPermissionsArray(
containersReq.containers,
Expand All @@ -93,14 +93,14 @@ export const parseContainerReq = containersReq => ( {
containers_cap: containersReq.containers_cap
} );

const parseXorName = str => {
const b = new Buffer( str );
const parseXorName = ( str ) => {
const b = new Buffer.from( str );
if ( b.length !== 32 ) throw Error( 'XOR Names _must be_ 32 bytes long.' );
const name = types.XorName( b );
return new Buffer( name ).toString( 'hex' );
return new Buffer.from( name ).toString( 'hex' );
};

const parseShareMData = shareMData => ( {
const parseShareMData = ( shareMData ) => ( {
type_tag: shareMData.type_tag,
name: parseXorName( shareMData.name ),
perms: parsePermissionSet( shareMData.perms )
Expand All @@ -116,13 +116,13 @@ const parseSharedMDataArray = ( shareMData, len ) => {
return res;
};

export const parseShareMDataReq = shareMDataReq => ( {
export const parseShareMDataReq = ( shareMDataReq ) => ( {
app: parseAppExchangeInfo( shareMDataReq.app ),
mdata: parseSharedMDataArray( shareMDataReq.mdata, shareMDataReq.mdata_len ),
mdata_len: shareMDataReq.mdata_len
} );

const parseUserMetaData = meta => ( {
const parseUserMetaData = ( meta ) => ( {
name: meta.name,
description: meta.description
} );
Expand All @@ -137,9 +137,9 @@ export const parseUserMetaDataArray = ( metaArr, len ) => {
return res;
};

const parseAppAccessInfo = appAccess => {
let signKey = types.U8Array( new Buffer( appAccess.sign_key ) );
signKey = new Buffer( signKey ).toString( 'hex' );
const parseAppAccessInfo = ( appAccess ) => {
let signKey = types.U8Array( new Buffer.from( appAccess.sign_key ) );
signKey = new Buffer.from( signKey ).toString( 'hex' );
return {
sign_key: signKey,
permissions: parsePermissionSet( appAccess.permissions ),
Expand Down

0 comments on commit fb25539

Please sign in to comment.