Skip to content

Commit

Permalink
Update agent-js (#2624)
Browse files Browse the repository at this point in the history
* Update agent-js

`npm update` clashes with incompatible peer dependencies due to agent-js
being on version 1.x.x but `@dfinity/utils` wanting 2.x.x. Hence agent-js
and related dependencies are upgraded.

* Switch to new way of creating HttpAgents

* Bump auth client in using-dev-build
  • Loading branch information
Frederik Rothenberger authored Sep 24, 2024
1 parent 241c5f7 commit 3e49ba1
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 153 deletions.
248 changes: 164 additions & 84 deletions demos/using-dev-build/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demos/using-dev-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"vite": "^5.2.14"
},
"dependencies": {
"@dfinity/auth-client": "^0.15.5"
"@dfinity/auth-client": "^2.1.1"
}
}
2 changes: 1 addition & 1 deletion demos/using-dev-build/webapp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ document.getElementById("loginBtn")?.addEventListener("click", async () => {
// At this point we're authenticated, and we can get the identity from the auth client:
const identity = authClient.getIdentity();
// Using the identity obtained from the auth client, we can create an agent to interact with the IC.
const agent = new HttpAgent({ identity });
const agent = await HttpAgent.create({ identity, shouldFetchRootKey: true });
// Using the interface description of our webapp, we create an actor that we use to call the service methods.
const webapp: _SERVICE = Actor.createActor(webapp_idl, {
agent,
Expand Down
15 changes: 7 additions & 8 deletions demos/vc_issuer/app/issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ export class VcIssuer {
public constructor(readonly canisterId: string) {}

createActor = async (): Promise<ActorSubclass<_SERVICE>> => {
const agent = new HttpAgent();

// XXX: we always fetch the rootkey.
// Although this isn't necessary/recommended on mainnet,
// we do this for simplicity.
await agent.fetchRootKey();
const agent = await HttpAgent.create({
// XXX: we always fetch the rootkey.
// Although this isn't necessary/recommended on mainnet,
// we do this for simplicity.
shouldFetchRootKey: true,
});

const actor = Actor.createActor<_SERVICE>(vc_issuer_idl, {
return Actor.createActor<_SERVICE>(vc_issuer_idl, {
agent,
canisterId: this.canisterId,
});
return actor;
};

addEmployee = async ({
Expand Down
76 changes: 41 additions & 35 deletions package-lock.json

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

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
"webdriverio": "^8.39.0"
},
"dependencies": {
"@dfinity/agent": "^1.3.0",
"@dfinity/auth-client": "^1.3.0",
"@dfinity/candid": "^1.3.0",
"@dfinity/identity": "^1.3.0",
"@dfinity/agent": "^2.1.1",
"@dfinity/auth-client": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/identity": "^2.1.1",
"@dfinity/internet-identity-vc-api": "*",
"@dfinity/principal": "^1.3.0",
"@dfinity/utils": "^2.2.0",
"@dfinity/principal": "^2.1.1",
"@dfinity/utils": "^2.5.0",
"bip39": "^3.0.4",
"buffer": "^6.0.3",
"dompurify": "^3.1.3",
Expand Down
11 changes: 4 additions & 7 deletions src/frontend/src/flows/verifiableCredentials/vcIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ export class VcIssuer {
createActor = async (
identity?: Identity
): Promise<ActorSubclass<_SERVICE>> => {
const agent = new HttpAgent({
const agent = await HttpAgent.create({
host: inferHost(),
identity,
// Only fetch the root key when we're not in prod
shouldFetchRootKey: features.FETCH_ROOT_KEY,
});

// Only fetch the root key when we're not in prod
if (features.FETCH_ROOT_KEY) {
await agent.fetchRootKey();
}
const actor = Actor.createActor<_SERVICE>(vc_issuer_idl, {
return Actor.createActor<_SERVICE>(vc_issuer_idl, {
agent,
canisterId: this.canisterId,
});
return actor;
};

prepareCredential = async ({
Expand Down
6 changes: 4 additions & 2 deletions src/frontend/src/test-e2e/verifiableCredentials/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,10 @@ export const addEmployeeToIssuer = async ({
const createIssuerActor = async (
issuerCanisterId: string
): Promise<ActorSubclass<_SERVICE>> => {
const agent = new HttpAgent({ host: REPLICA_URL });
await agent.fetchRootKey();
const agent = await HttpAgent.create({
host: REPLICA_URL,
shouldFetchRootKey: true,
});
return Actor.createActor<_SERVICE>(vc_issuer_idl, {
agent: agent,
canisterId: issuerCanisterId,
Expand Down
15 changes: 6 additions & 9 deletions src/frontend/src/utils/iiConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { idlFactory as internet_identity_idl } from "$generated/internet_identity_idl";
import {
_SERVICE,
AddTentativeDeviceResponse,
AnchorCredentials,
Challenge,
Expand All @@ -28,7 +29,6 @@ import {
UserNumber,
VerifyTentativeDeviceResponse,
WebAuthnCredential,
_SERVICE,
} from "$generated/internet_identity_types";
import { fromMnemonicWithoutValidation } from "$src/crypto/ed25519";
import { features } from "$src/features";
Expand All @@ -53,7 +53,7 @@ import {
import { Principal } from "@dfinity/principal";
import { isNullish, nonNullish } from "@dfinity/utils";
import { MultiWebAuthnIdentity } from "./multiWebAuthnIdentity";
import { RecoveryDevice, isRecoveryDevice } from "./recoveryDevice";
import { isRecoveryDevice, RecoveryDevice } from "./recoveryDevice";
import { isWebAuthnCancel } from "./webAuthnErrorUtils";

/*
Expand Down Expand Up @@ -384,20 +384,17 @@ export class Connection {
createActor = async (
delegationIdentity?: DelegationIdentity
): Promise<ActorSubclass<_SERVICE>> => {
const agent = new HttpAgent({
const agent = await HttpAgent.create({
identity: delegationIdentity,
host: inferHost(),
// Only fetch the root key when we're not in prod
shouldFetchRootKey: features.FETCH_ROOT_KEY,
});

// Only fetch the root key when we're not in prod
if (features.FETCH_ROOT_KEY) {
await agent.fetchRootKey();
}
const actor = Actor.createActor<_SERVICE>(internet_identity_idl, {
return Actor.createActor<_SERVICE>(internet_identity_idl, {
agent,
canisterId: this.canisterId,
});
return actor;
};

requestFEDelegation = async (
Expand Down

0 comments on commit 3e49ba1

Please sign in to comment.