Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade agent-js #2373

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions demos/test-app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,13 @@ init();

whoamiBtn.addEventListener("click", async () => {
const canisterId = Principal.fromText(readCanisterId());
let agent = new HttpAgent({
frederikrothenberger marked this conversation as resolved.
Show resolved Hide resolved
host: hostUrlEl.value,
identity: delegationIdentity,
});
await agent.fetchRootKey();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fetching the root key is now necessary because the agent now verifies the replica signature on queries too.

const actor = Actor.createActor(idlFactory, {
agent: new HttpAgent({
host: hostUrlEl.value,
identity: delegationIdentity,
}),
agent,
canisterId,
});

Expand Down
92 changes: 54 additions & 38 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 @@ -57,13 +57,13 @@
"webdriverio": "8.32.3"
},
"dependencies": {
"@dfinity/agent": "^0.19.2",
"@dfinity/auth-client": "^0.19.2",
"@dfinity/candid": "^0.19.2",
"@dfinity/identity": "^0.19.2",
"@dfinity/agent": "^1.1.1",
"@dfinity/auth-client": "^1.1.1",
"@dfinity/candid": "^1.1.1",
"@dfinity/identity": "^1.1.1",
"@dfinity/internet-identity-vc-api": "*",
"@dfinity/principal": "^0.19.2",
"@dfinity/utils": "^0.0.20",
"@dfinity/principal": "^1.1.1",
"@dfinity/utils": "^2.1.2",
"bip39": "^3.0.4",
"buffer": "^6.0.3",
"dompurify": "^3.0.6",
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/src/crypto/ed25519.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fromHex } from "@dfinity/agent";
import { Ed25519PublicKey } from "@dfinity/identity";
import { fromHexString } from "@dfinity/identity/lib/cjs/buffer";
import * as ed25519 from "./ed25519";

type TestVector = {
Expand Down Expand Up @@ -66,9 +66,9 @@ const testVectorsSLIP10 = [
test("derive Ed25519 via SLIP 0010", async () => {
await Promise.all(
testVectorsSLIP10.map(async (testVector: TestVector) => {
const seedBlob = fromHexString(testVector.seed);
const expectedPrivateKey = fromHexString(testVector.privateKey);
const expectedPublicKey = fromHexString(testVector.publicKey);
const seedBlob = fromHex(testVector.seed);
frederikrothenberger marked this conversation as resolved.
Show resolved Hide resolved
const expectedPrivateKey = fromHex(testVector.privateKey);
const expectedPublicKey = fromHex(testVector.publicKey);

const identity = await ed25519.fromSeedWithSlip0010(
new Uint8Array(seedBlob),
Expand Down
7 changes: 2 additions & 5 deletions src/frontend/src/crypto/mnemonic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isUserNumber } from "$src/utils/userNumber";
import { toHexString } from "@dfinity/identity/lib/cjs/buffer";
import { toHex } from "@dfinity/agent";
import { entropyToMnemonic, validateMnemonic, wordlists } from "bip39";

/**
Expand All @@ -8,10 +8,7 @@ import { entropyToMnemonic, validateMnemonic, wordlists } from "bip39";
export function generate(): string {
const entropy = new Uint32Array(8); // NOTE: please change RECOVERYPHRASE_WORDCOUNT if this changes
crypto.getRandomValues(entropy);
return entropyToMnemonic(
toHexString(entropy.buffer),
RECOVERYPHRASE_WORDLIST
);
return entropyToMnemonic(toHex(entropy.buffer), RECOVERYPHRASE_WORDLIST);
}

/** How many words are expected in the recovery phrase */
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/src/utils/iiConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
} from "@dfinity/identity";
import { Principal } from "@dfinity/principal";
import { isNullish, nonNullish } from "@dfinity/utils";
import * as tweetnacl from "tweetnacl";
frederikrothenberger marked this conversation as resolved.
Show resolved Hide resolved
import { MultiWebAuthnIdentity } from "./multiWebAuthnIdentity";
import { RecoveryDevice, isRecoveryDevice } from "./recoveryDevice";
import { isWebAuthnCancel } from "./webAuthnErrorUtils";
Expand Down Expand Up @@ -719,7 +718,7 @@ export const creationOptions = (
name: "Internet Identity Service",
},
user: {
id: tweetnacl.randomBytes(16),
id: window.crypto.getRandomValues(new Uint8Array(16)),
peterpeterparker marked this conversation as resolved.
Show resolved Hide resolved
name: "Internet Identity",
displayName: "Internet Identity",
},
Expand Down
2 changes: 1 addition & 1 deletion src/vite-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"vite": "^4.5.2",
"undici": "*",
"vite-plugin-compression": "^0.5.1",
"@dfinity/utils": "^0.0.20",
"@dfinity/utils": "^2.1.2",
"@types/html-minifier-terser": "^7.0.0",
"html-minifier-terser": "^7.2.0"
}
Expand Down
Loading