Skip to content

Commit

Permalink
Improve security for authorizing principals
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanasa committed Apr 3, 2024
1 parent 5add34b commit 72c0188
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 2 additions & 1 deletion canisters/backend/Core.mo
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ module {

public func connectEthWallet(caller : Principal, wallet : Types.EthWallet, signedPrincipal : Types.SignedPrincipal) : async Types.Resp.ConnectEthWallet {
let log = logger.Begin(caller, #connectEthWallet(wallet, signedPrincipal));
let checkOutcome = await IcEth.verify_ecdsa(wallet, Principal.toText caller, signedPrincipal);
let message = "Authorized ICP principal: " # Principal.toText(caller);
let checkOutcome = await IcEth.verify_ecdsa(wallet, message, signedPrincipal);
log.internal(#verifyEcdsaOutcome(checkOutcome));
if (checkOutcome) {
ignore (state.putWalletSignsPrincipal(wallet, caller, signedPrincipal));
Expand Down
3 changes: 1 addition & 2 deletions src/services/addressService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { handleError, handlePromise } from '../utils/handlers';
import makeObservable from '../utils/makeObservable';
import { getBackend } from './backendService';
import { USER_STORE } from './userService';
import { applicationName } from '../setupApp';

export const ADDRESSES_STORE = makeObservable<string[] | null>();

Expand Down Expand Up @@ -50,7 +49,7 @@ async function verifyAddress(address: string, ethereum: any): Promise<boolean> {
return false;
}
const principal = user.client.getIdentity().getPrincipal().toString();
const message = `${applicationName}\n${principal}`;
const message = `Authorized ICP principal: ${principal}`;
const signature = await ethereum.request({
method: 'personal_sign',
params: [`0x${toHex(message)}`, address],
Expand Down

0 comments on commit 72c0188

Please sign in to comment.