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).

4 Likes