Dfinity/agent @0.6.16/17

these functions are not available anymore in the latest versions is there any docs or could help me what is the replacement fn of them

setAuthTransform()
makeAuthTransform()
HttpAgent.requestStatus is not a function

thenx in advance

1 Like

In these newer versions of @dfinity/agent npm package, the authTransform went away in favor of new identity objects (SignIdentity interface) that should be passed to the HttpAgent constructor. So you no longer need makeAuthTransform() or setAuthTransform().

A SignIdentity has a getPublicKey(): { toDER(): ArrayBuffer } method, and a sign(challenge: ArrayBuffer) => ArrayBuffer method.

import {
  AnonymousIdentity,
  HttpAgent,
  makeExpiryTransform,
  makeNonceTransform,
} from "@dfinity/agent";
async function PolyfillAgent({ log = console } = {}): Promise<HttpAgent> {
  const agentOptions = {
    identity: new AnonymousIdentity(),
  };
  const agent = new HttpAgent(agentOptions);
  agent.addTransform(makeNonceTransform());
  agent.addTransform(makeExpiryTransform(5 * 60 * 1000));
  return agent;
}

This uses AnonymousIdentity, which is basically like no identity at all. All instance of AnonymousIdentity will make requests that are indistinguishable from one another.

If your canister wants to distinguish between different caller.principals, you’ll need to use an Identity with a unique Ed25519 publicKey (and a sign() method that signs with the corresponding secretKey).

5 Likes

Hey @bengo -

I’m struggling to figure out how to replace the injected agent. My naive approach was as follows.

// index.js
const agentOptions = {
  identity: new AnonymousIdentity(),
};
agent = new HttpAgent(agentOptions);
agent.addTransform(makeNonceTransform());
agent.addTransform(makeExpiryTransform(5 * 60 * 1000));
window.ic.agent = agent;

I noticed the injected ic.agent is a ProxyAgent class, which I can’t find anywhere.

I have deployed an app here https://rndfa-pyaaa-aaaab-qadua-cai.ic0.app/

window.anotherAgent is set to the above code, and window.ic.agent is naturally the default

Any thoughts?

Not super familiar with the anonymous identity thing, but when I visit your app page, it allows me to enter a user name that is unique to each of my browsers. Is that not what you want?

Interestingly using Microsoft Edge I was met with an account that is already registered… Using firefox (and its multi container feature) has no such problems. Something is not right here…

Anyway, manually setting "identity: new AnonymousIdentity()" in your JS code is most likely not what you wanted, because your canister will assume any message it receives is from the same special identity, and cannot differentiate between different users.