Toniq-Labs / stoic-identity

Identity for DFINITY's IC HttpAgent (to connect to a Stoic wallet via Stoic Connect)
MIT License
27 stars 16 forks source link

"msg.caller" always ends up being default wallet principal in locally deployed project #8

Closed ayjayem closed 2 years ago

ayjayem commented 2 years ago

I have two canisters deployed locally: a Motoko canister and an assets canister with a TypeScript frontend.

When I use a seed-phrase-based, logged-in, Stoic Identity in the frontend to call into the (backend) Motoko canister, the backend canister always reports that "msg.caller" is my default local wallet principal - not the Stoic Identity principal.

The key code looks like this:

----- TypeScript Frontend -----

StoicIdentity.load().then(async (identity: any) => {

      const agent = new HttpAgent({
         host: 'http://localhost:3000',  // host doesn't seem to matter for this issue
         identity
      });  

      await agent.fetchRootKey();  // for local development only

      const testActor = Actor.createActor(actorIdl, {
        agent: agent,
        canisterId: canisterId
      });

     const res = await testActor.doStuff()
}

----- Motoko Backend: "testActor" -----

public func doStuff() : async Bool {
    ...
    Debug.print(debug_show(msg.caller));  // prints default local wallet principal, not Stoic Identity principal
    ...
    return true;
}

Am I right to expect that "msg.caller" should be the Stoic Identity principal, and not my default local wallet principal?

ayjayem commented 2 years ago

I don't know what changed, but this is no longer an issue for me.