Skip to content

Commit

Permalink
merge hostnames, update export key msg dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Feb 9, 2024
1 parent d945ee4 commit b039122
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
11 changes: 1 addition & 10 deletions packages/snap/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const SUPPORTED_CHAINS: Record<number, ChainInfo> = {
},
};

export const GET_CREDENTIALS_ALLOWED_HOSTNAMES = [
export const HOSTNAMES_WHITELIST = [
// Local
'localhost',
// Staging
Expand All @@ -100,13 +100,4 @@ export const GET_CREDENTIALS_ALLOWED_HOSTNAMES = [
'app.rarime.com',
];

export const MANAGE_IDENTITY_ALLOWED_HOSTNAMES = [
// Local
'localhost',
// Staging
'app.stage.rarime.com',
// Production
'app.rarime.com',
];

export const CERAMIC_URL = 'https://ceramic.rarimo.com';
6 changes: 5 additions & 1 deletion packages/snap/src/helpers/common-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { providers } from 'ethers';
import { config, SUPPORTED_CHAINS } from '../config';
import { config, HOSTNAMES_WHITELIST, SUPPORTED_CHAINS } from '../config';
import { ChainInfo } from '../types';

export const getChainInfo = (chainId: number): ChainInfo => {
Expand Down Expand Up @@ -38,6 +38,10 @@ export const getHostname = (origin: string): string => {
return new URL(origin).hostname;
};

export const isOriginInWhitelist = (origin: string) => {
return HOSTNAMES_WHITELIST.includes(getHostname(origin));
};

export const uniqBy = (arr: any[], predicate: string) => {
return [
...arr
Expand Down
12 changes: 4 additions & 8 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import {
checkIfStateSynced,
getClaimIdFromVCId,
getCoreOperationByIndex,
getHostname,
getProviderChainInfo,
getRarimoCoreUrl,
isDidSupported,
isOriginInWhitelist,
loadDataFromRarimoCore,
migrateVCsToLastCeramicModel,
parseDidV2,
Expand All @@ -45,10 +45,6 @@ import {
isValidCreateProofRequest,
isValidSaveCredentialsOfferRequest,
} from './typia-generated';
import {
GET_CREDENTIALS_ALLOWED_HOSTNAMES,
MANAGE_IDENTITY_ALLOWED_HOSTNAMES,
} from './config';

export const onRpcRequest = async ({
request,
Expand Down Expand Up @@ -432,7 +428,7 @@ export const onRpcRequest = async ({
}

case RPCMethods.GetCredentials: {
if (!GET_CREDENTIALS_ALLOWED_HOSTNAMES.includes(getHostname(origin))) {
if (!isOriginInWhitelist(origin)) {
throw new Error('This origin does not have access to credentials');
}

Expand All @@ -442,7 +438,7 @@ export const onRpcRequest = async ({
}

case RPCMethods.ExportIdentity: {
if (!MANAGE_IDENTITY_ALLOWED_HOSTNAMES.includes(getHostname(origin))) {
if (!isOriginInWhitelist(origin)) {
throw new Error('This origin does not have access to export identity');
}

Expand All @@ -457,7 +453,7 @@ export const onRpcRequest = async ({
params: {
type: 'alert',
content: panel([
heading('Your identity private key'),
heading('Your RariMe private key'),
divider(),
text('Сopy:'),
copyable(identityStorage.privateKeyHex),
Expand Down

0 comments on commit b039122

Please sign in to comment.