Skip to content

Commit

Permalink
feat: agent-js v2.0.0 (#679)
Browse files Browse the repository at this point in the history
# Motivation

Bump agent-js v2.0.0 ([release
notes](https://github.com/dfinity/agent-js/releases/tag/v2.0.0)) and
update `HttpAgent` creation accordingly.

# Changes

- `npm run update:agent`
- Defer fetching root key to `HttpAgent.create` in the `createAgent`
which per extension also improve the creation of the agent by also
calling `syncTime`
- For `defaultAgent` simply replace contructor call with synchronous
`HttpAgent.createSync`

---------

Signed-off-by: David Dal Busco <david.dalbusco@dfinity.org>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
peterpeterparker and github-actions[bot] authored Aug 26, 2024
1 parent e0c7606 commit 497c8ba
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 89 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- Provide a new utility to convert Candid `Nat` to `BigInt`. This utility is useful for interpreting the fees provided by the SNS Aggregator.
- Support conversion of `InstallCode`, `StopOrStartCanister` and `UpdateCanisterSettings` actions, `SetVisibility` neuron operation, and `Neuron::visibility` attribute.

## Build

- Upgrade `agent-js` dependencies to `v2.0.0`.

# 2024.07.22-0645Z

## Overview
Expand Down
96 changes: 48 additions & 48 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions packages/ckbtc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
],
"homepage": "https://github.com/dfinity/ic-js#readme",
"peerDependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/principal": "^1.4.0",
"@dfinity/agent": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/principal": "^2.0.0",
"@dfinity/utils": "^2.4.0"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/cketh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
],
"homepage": "https://github.com/dfinity/ic-js#readme",
"peerDependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/principal": "^1.4.0",
"@dfinity/agent": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/principal": "^2.0.0",
"@dfinity/utils": "^2.4.0"
}
}
6 changes: 3 additions & 3 deletions packages/cmc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
],
"homepage": "https://github.com/dfinity/ic-js#readme",
"peerDependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/principal": "^1.4.0",
"@dfinity/agent": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/principal": "^2.0.0",
"@dfinity/utils": "^2.4.0"
}
}
6 changes: 3 additions & 3 deletions packages/ic-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
],
"homepage": "https://github.com/dfinity/ic-js#readme",
"peerDependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/principal": "^1.4.0",
"@dfinity/agent": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/principal": "^2.0.0",
"@dfinity/utils": "^2.4.0"
}
}
6 changes: 3 additions & 3 deletions packages/ledger-icp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
],
"homepage": "https://github.com/dfinity/ic-js#readme",
"peerDependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/principal": "^1.4.0",
"@dfinity/agent": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/principal": "^2.0.0",
"@dfinity/utils": "^2.4.0"
}
}
6 changes: 3 additions & 3 deletions packages/ledger-icrc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
],
"homepage": "https://github.com/dfinity/ic-js#readme",
"peerDependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/principal": "^1.4.0",
"@dfinity/agent": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/principal": "^2.0.0",
"@dfinity/utils": "^2.4.0"
}
}
6 changes: 3 additions & 3 deletions packages/nns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
"network-nervous-system"
],
"peerDependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/agent": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/ledger-icp": "^2.4.0",
"@dfinity/principal": "^1.4.0",
"@dfinity/principal": "^2.0.0",
"@dfinity/utils": "^2.4.0"
}
}
6 changes: 3 additions & 3 deletions packages/sns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"sns"
],
"peerDependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/agent": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/ledger-icrc": "^2.4.0",
"@dfinity/principal": "^1.4.0",
"@dfinity/principal": "^2.0.0",
"@dfinity/utils": "^2.4.0"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"service-nervous-system"
],
"peerDependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/principal": "^1.4.0"
"@dfinity/agent": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/principal": "^2.0.0"
}
}
11 changes: 3 additions & 8 deletions packages/utils/src/utils/agent.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { nonNullish } from "./nullish.utils";
* @returns The default agent to use
*/
export const defaultAgent = (): Agent =>
new HttpAgent({
HttpAgent.createSync({
host: "https://icp-api.io",
identity: new AnonymousIdentity(),
});
Expand All @@ -34,16 +34,11 @@ export const createAgent = async ({
verifyQuerySignatures?: boolean;
retryTimes?: number;
}): Promise<HttpAgent> => {
const agent: HttpAgent = new HttpAgent({
return await HttpAgent.create({
identity,
...(nonNullish(host) && { host }),
verifyQuerySignatures,
...(nonNullish(retryTimes) && { retryTimes }),
shouldFetchRootKey: fetchRootKey,
});

if (fetchRootKey) {
await agent.fetchRootKey();
}

return agent;
};
8 changes: 3 additions & 5 deletions scripts/refreshNeuron.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import fetch from "node-fetch";
import pkg from "../packages/nns/dist/index.cjs.js";
const { GovernanceCanister } = pkg;

const refreshNeuron = async (neuronId, fetchRotkey) => {
const refreshNeuron = async (neuronId, shouldFetchRootKey) => {
try {
const agent = new HttpAgent({
const agent = await HttpAgent.create({
fetch,
host: "https://ic0.app",
// host: "https://nnsdapp.dfinity.network",
shouldFetchRootKey,
});
if (fetchRotkey) {
await agent.fetchRootKey();
}
const canister = GovernanceCanister.create({
agent,
canisterId: Principal.fromText("rrkah-fqaaa-aaaaa-aaaaq-cai"),
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-vectors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { MAINNET_GOVERNANCE_CANISTER_ID } from "../../packages/nns/src/constants
* - Change `sender` in the `createCallRequest` to the one commented.
*
* In the hardware-wallet-cli
* - `disableNonce: true` in `getAgent` when creating the `new HttpAgent(...)`.
* - `disableNonce: true` in `getAgent` when creating the `HttpAgent.create(...)`.
* - `console.log(Buffer.from(blob).toString("hex"));` inside the `sign` method in LedgerIdentity
*
* Go to cbor.me and decode both blobs.
Expand Down

0 comments on commit 497c8ba

Please sign in to comment.