Skip to content

Commit

Permalink
Merge branch 'main' into kai/pollforresponse-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
krpeacock authored Aug 23, 2024
2 parents 889dcb6 + 458e243 commit 3e68a89
Show file tree
Hide file tree
Showing 67 changed files with 9,557 additions and 7,660 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ dist
docs/agent
docs/assets
docs/auth-client
docs/use-auth-client
docs/authentication
docs/identity
docs/identity-secp256k1
Expand Down
12 changes: 12 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

## [Unreleased]

### Added

- feat: management canister interface updates for schnorr signatures
- feat: ensure that identity-secp256k1 seed phrase must produce a 64 byte seed
- docs: documentation and metadata for use-auth-client
- feat: adds optional `rootKey` to `HttpAgentOptions` to allow for a custom root key to be used for verifying signatures from other networks

### Changed
- feat: replaces hdkey and bip32 implementations with `@scure/bip39` and `@scure/bip32` due to vulnerability and lack of maintenance for `elliptic`
- chore: bumps dev dependency versions to remove warnings
- chore: addresses eslint errors uncovered by bumping eslint version

## [2.0.0] - 2024-07-16

### Changed
Expand Down
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<a href="/principal/index.html">Principal</a>
<a href="/candid/index.html">Candid</a>
<a href="/auth-client/index.html">Auth-Client</a>
<a href="/use-auth-client/index.html">useAuthClient (React Hook)</a>
<a href="/assets/index.html">Asset Manager</a>
<a href="/identity/index.html">Identity</a>
<a href="/identity-secp256k1/index.html">Secp256k1 Identity</a>
Expand Down
10 changes: 4 additions & 6 deletions e2e/node/basic/identity.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Actor, SignIdentity } from '@dfinity/agent';
import { IDL } from '@dfinity/candid';
import { Principal } from '@dfinity/principal';
import {
DelegationChain,
Expand Down Expand Up @@ -28,7 +27,7 @@ function createSecpIdentity(seed: number): SignIdentity {
async function createIdentityActor(
seed: number,
canisterId: Principal,
idl: IDL.InterfaceFactory,
idl,
): Promise<any> {
const identity = createIdentity(seed);
const agent1 = await makeAgent({ identity });
Expand All @@ -40,7 +39,7 @@ async function createIdentityActor(

async function createSecp256k1IdentityActor(
canisterId: Principal,
idl: IDL.InterfaceFactory,
idl,
seed?: number,
): Promise<any> {
let seed1: Uint8Array | undefined;
Expand All @@ -59,10 +58,9 @@ async function createSecp256k1IdentityActor(

async function createEcdsaIdentityActor(
canisterId: Principal,
idl: IDL.InterfaceFactory,
idl,
identity?: SignIdentity,
): Promise<any> {
global.crypto;
let effectiveIdentity: SignIdentity;
if (identity) {
effectiveIdentity = identity;
Expand All @@ -80,7 +78,7 @@ async function createEcdsaIdentityActor(

async function installIdentityCanister(): Promise<{
canisterId: Principal;
idl: IDL.InterfaceFactory;
idl;
}> {
const { canisterId, idl } = await identityCanister();
return {
Expand Down
25 changes: 22 additions & 3 deletions e2e/node/basic/mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const createWhoamiActor = async (identity: Identity) => {
const idlFactory = () => {
return IDL.Service({
whoami: IDL.Func([], [IDL.Principal], ['query']),
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as unknown as any;
};
vi.useFakeTimers();
new Date(Date.now());
Expand Down Expand Up @@ -136,7 +137,25 @@ describe('call forwarding', () => {
requestId,
defaultStrategy(),
);
certificate; // Certificate
reply; // ArrayBuffer
expect(certificate).toBeTruthy();
expect(reply).toBeTruthy();
}, 15_000);
});


test('it should allow you to set an incorrect root key', async () => {
const agent = HttpAgent.createSync({
rootKey: new Uint8Array(31),
});
const idlFactory = ({ IDL }) =>
IDL.Service({
whoami: IDL.Func([], [IDL.Principal], ['query']),
});

const actor = Actor.createActor(idlFactory, {
agent,
canisterId: Principal.fromText('rrkah-fqaaa-aaaaa-aaaaq-cai'),
});

expect(actor.whoami).rejects.toThrowError(`Invalid certificate:`);
});
3 changes: 0 additions & 3 deletions e2e/node/basic/watermark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function indexOfQueryResponse(history: Response[]) {

test('basic', async () => {
const fetchProxy = new FetchProxy();
global.fetch;

const actor = await createActor({
fetch: fetchProxy.fetch.bind(fetchProxy),
Expand All @@ -60,7 +59,6 @@ test('basic', async () => {

test('replay queries only', async () => {
const fetchProxy = new FetchProxy();
global.fetch;

const actor = await createActor({
fetch: fetchProxy.fetch.bind(fetchProxy),
Expand All @@ -83,7 +81,6 @@ test('replay queries only', async () => {

test('replay attack', async () => {
const fetchProxy = new FetchProxy();
global.fetch;

const actor = await createActor({
verifyQuerySignatures: true,
Expand Down
5 changes: 2 additions & 3 deletions e2e/node/canisters/counter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Actor, ActorSubclass, HttpAgentOptions, Agent } from '@dfinity/agent';
import { IDL } from '@dfinity/candid';
import { Principal } from '@dfinity/principal';
import { readFileSync } from 'fs';
import path from 'path';
Expand All @@ -12,7 +11,7 @@ let cache: {
actor: any;
} | null = null;

const idl: IDL.InterfaceFactory = ({ IDL }) => {
const idl = ({ IDL }) => {
return IDL.Service({
inc: IDL.Func([], [], []),
inc_read: IDL.Func([], [IDL.Nat], []),
Expand Down Expand Up @@ -58,7 +57,7 @@ export const createActor = async (options?: HttpAgentOptions, agent?: Agent) =>
if (!options?.host?.includes('icp-api')) {
await effectiveAgent.fetchRootKey();
}
} catch (_) {
} catch {
//
}

Expand Down
14 changes: 9 additions & 5 deletions e2e/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
"devDependencies": {
"@peculiar/webcrypto": "^1.4.0",
"@trust/webcrypto": "^0.9.2",
"@tsconfig/node16": "^1.0.3",
"@tsconfig/node17": "^1.0.1",
"@types/base64-js": "^1.3.0",
Expand All @@ -34,16 +33,21 @@
"@typescript-eslint/parser": "^5.30.5",
"agent1": "npm:@dfinity/agent@^1.4.0",
"esbuild": "^0.15.16",
"eslint": "^8.19.0",
"eslint-plugin-jsdoc": "^39.3.3",
"isomorphic-fetch": "^3.0.0",
"locus": "^2.0.4",
"node-webcrypto-p11": "^2.5.0",
"size-limit": "^8.2.6",
"text-encoding": "^0.7.0",
"ts-node": "^10.8.2",
"typescript": "^5.2.2",
"vitest": "^0.34.6",
"webcrypto-core": "^1.7.5"
"vitest": "^0.34.6"
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "4.6.1"
},
"overrides": {
"vite": {
"rollup": "npm:@rollup/wasm-node"
}
}
}
2 changes: 1 addition & 1 deletion e2e/node/utils/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const makeAgent = async (options?: HttpAgentOptions) => {
});
try {
await agent.fetchRootKey();
} catch (_) {
} catch {
//
}
return agent;
Expand Down
Loading

0 comments on commit 3e68a89

Please sign in to comment.