Skip to content

Commit

Permalink
Miscellaneous (#78)
Browse files Browse the repository at this point in the history
* Remove unused code in Motoko canister

* Improve security for authorizing principals

* Adjust ECDSA message

* Run 'npm audit fix'
  • Loading branch information
rvanasa committed Apr 10, 2024
1 parent 0a009ae commit 474df88
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 30 deletions.
11 changes: 3 additions & 8 deletions canisters/backend/Core.mo
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ import Nat64 "mo:base/Nat64";
import System "lib/System";
import Iter "lib/IterMore";
import IcEth "canister:ic_eth";
import Seq "mo:sequence/Sequence";
import Stream "mo:sequence/Stream";

module {
public class Core(installer : Principal, sys : System.System, _state : State.Stable.State, history : History.History) {

let state = State.OOOf(sys, _state);
public let logger = History.Logger(sys, history);

func unreachable() : None {
do { assert false; loop {} };
};

public func login(caller : Principal) : Types.Resp.Login {
let log = logger.Begin(caller, #login);
log.okWith(state.login(caller));
Expand All @@ -39,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 = "Associated 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 Expand Up @@ -116,7 +111,7 @@ module {
log.okWith(true);
};

public func getPublicHistory(caller : Principal) : [Types.PublicEvent] {
public func getPublicHistory(_caller : Principal) : [Types.PublicEvent] {
Iter.toArray(state.getPublicHistory());
};

Expand Down
2 changes: 0 additions & 2 deletions canisters/backend/History.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Error "mo:base/Error";
import Cycles "mo:base/ExperimentalCycles";
import Int "mo:base/Int";
import Iter "mo:base/Iter";
import Seq "mo:sequence/Sequence";
Expand Down
1 change: 0 additions & 1 deletion canisters/backend/Snapshot.mo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Types "Types";
import State "State";

import Int "mo:base/Int";
import Trie "mo:base/Trie";
import Iter "lib/IterMore";

Expand Down
93 changes: 75 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/services/addressService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function verifyAddress(address: string, ethereum: any): Promise<boolean> {
return false;
}
const principal = user.client.getIdentity().getPrincipal().toString();
const message = principal; // TODO: human-readable message?
const message = `Associated ICP principal: ${principal}`;
const signature = await ethereum.request({
method: 'personal_sign',
params: [`0x${toHex(message)}`, address],
Expand Down

0 comments on commit 474df88

Please sign in to comment.