Skip to content

Commit b9c9418

Browse files
marc0oloclaude
andcommitted
feat(frontend): migrate @dfinity/vetkeys library from @dfinity/* to @icp-sdk/core
- Replace @dfinity/agent, @dfinity/candid, @dfinity/principal, @dfinity/identity with @icp-sdk/core - DefaultEncryptedMapsClient and DefaultKeyManagerClient constructors now accept HttpAgent directly instead of HttpAgentOptions (BREAKING — see CHANGELOG.md) - Remove generated index.js/index.d.ts wrappers, import idlFactory directly - Update test helpers to use HttpAgent.create() from @icp-sdk/core/agent - Update local dev network port from 4943 to 8000 - Test scripts migrated from dfx CLI to icp CLI Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d5b39d4 commit b9c9418

16 files changed

Lines changed: 762 additions & 48 deletions

frontend/ic_vetkeys/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@
1212

1313
### Changed
1414

15+
- **BREAKING** `DefaultEncryptedMapsClient` and `DefaultKeyManagerClient`
16+
constructors now accept an `HttpAgent` (from `@icp-sdk/core/agent`) instead of
17+
`HttpAgentOptions`. Since `HttpAgent.create()` is async, the agent must be
18+
created by the caller before being passed in — this avoids relying on the
19+
deprecated `HttpAgent.createSync()` and allows full configuration upfront,
20+
including providing the network's root key for local development:
21+
```ts
22+
const agent = await HttpAgent.create({
23+
host,
24+
identity,
25+
...(rootKey ? { rootKey } : {}), // rootKey from ic_env cookie in local dev
26+
});
27+
new DefaultEncryptedMapsClient(agent, canisterId);
28+
```
1529

1630
- Make `DerivedKeyMaterial.deriveAesGcmCryptoKey` `@internal`.
1731

frontend/ic_vetkeys/make_did_bindings.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ set -ex
33
function make_and_copy_declarations () {
44
DIR=$1
55
NAME=$2
6+
DID_FILE=$3
67

78
pushd "$DIR""$NAME"
89
make extract-candid
9-
dfx generate $NAME
1010
popd
1111

12-
rm -r "src/declarations/$NAME"
13-
mv "$DIR/""$NAME""/src/declarations/""$NAME" "src/declarations/"
12+
rm -rf "src/declarations/$NAME"
13+
mkdir -p "src/declarations/$NAME"
14+
npx @icp-sdk/bindgen --did-file "$DIR$NAME/$DID_FILE" --out-dir "src/declarations/$NAME" --declarations-flat --force
1415
}
1516

16-
make_and_copy_declarations "../../backend/rs/canisters/" "ic_vetkeys_manager_canister"
17-
make_and_copy_declarations "../../backend/rs/canisters/" "ic_vetkeys_encrypted_maps_canister"
17+
make_and_copy_declarations "../../backend/rs/canisters/" "ic_vetkeys_manager_canister" "ic_vetkeys_manager_canister.did"
18+
make_and_copy_declarations "../../backend/rs/canisters/" "ic_vetkeys_encrypted_maps_canister" "ic_vetkeys_encrypted_maps_canister.did"

frontend/ic_vetkeys/package.json

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@
5757
"module": "dist/lib/index.es.js",
5858
"typings": "dist/types/index.d.ts",
5959
"dependencies": {
60-
"@dfinity/agent": "^3.4.0",
61-
"@dfinity/candid": "^3.4.0",
62-
"@dfinity/principal": "^3.4.0",
60+
"@icp-sdk/core": "^5.2.1",
6361
"idb-keyval": "^6.2.1"
6462
},
6563
"devDependencies": {
66-
"@dfinity/identity": "^3.4.0",
6764
"@eslint/js": "^9.22.0",
6865
"@types/node": "^24.0.4",
6966
"@vitest/coverage-v8": "^3.0.5",
@@ -84,15 +81,15 @@
8481
"scripts": {
8582
"build": "tsc && vite build",
8683
"prepare": "npm run build",
87-
"coverage": "npm run test:deploy_all && export $(cat .test1.env .test2.env | xargs) && vitest run --coverage",
84+
"coverage": "npm run test:deploy_all && CANISTER_ID_IC_VETKEYS_MANAGER_CANISTER=$(cd $(git rev-parse --show-toplevel)/backend/rs/canisters && icp canister status ic_vetkeys_manager_canister -e local --id-only) CANISTER_ID_IC_VETKEYS_ENCRYPTED_MAPS_CANISTER=$(cd $(git rev-parse --show-toplevel)/backend/rs/canisters && icp canister status ic_vetkeys_encrypted_maps_canister -e local --id-only) vitest run --coverage",
8885
"lint": "eslint",
8986
"make:docs": "mkdir -p $(git rev-parse --show-toplevel)/docs/key_manager && mkdir -p $(git rev-parse --show-toplevel)/docs/encrypted_maps && typedoc --out $(git rev-parse --show-toplevel)/docs",
9087
"prettier": "prettier --write .",
9188
"prettier-check": "prettier --check .",
9289
"test_utils": "vitest utils",
93-
"test": "npm run test:deploy_all && export $(cat .test1.env .test2.env | xargs) && vitest --sequence.concurrent",
94-
"test:deploy_all": "npm run test:deploy_key_manager_canister && npm run test:deploy_encrypted_maps_canister",
95-
"test:deploy_key_manager_canister": "cd $(git rev-parse --show-toplevel)/backend/rs/canisters/ic_vetkeys_manager_canister && dfx start --clean --background; dfx deploy --argument '(\"dfx_test_key\")' ic_vetkeys_manager_canister && grep CANISTER_ID .env > $(git rev-parse --show-toplevel)/frontend/ic_vetkeys/.test1.env",
96-
"test:deploy_encrypted_maps_canister": "cd $(git rev-parse --show-toplevel)/backend/rs/canisters/ic_vetkeys_encrypted_maps_canister && dfx start --clean --background; dfx deploy --argument '(\"dfx_test_key\")' ic_vetkeys_encrypted_maps_canister && grep CANISTER_ID .env > $(git rev-parse --show-toplevel)/frontend/ic_vetkeys/.test2.env"
90+
"test": "npm run test:deploy_all && CANISTER_ID_IC_VETKEYS_MANAGER_CANISTER=$(cd $(git rev-parse --show-toplevel)/backend/rs/canisters && icp canister status ic_vetkeys_manager_canister -e local --id-only) CANISTER_ID_IC_VETKEYS_ENCRYPTED_MAPS_CANISTER=$(cd $(git rev-parse --show-toplevel)/backend/rs/canisters && icp canister status ic_vetkeys_encrypted_maps_canister -e local --id-only) vitest run --sequence.concurrent",
91+
"test:deploy_all": "cd $(git rev-parse --show-toplevel)/backend/rs/canisters && (icp network stop || true) && icp network start -d && icp deploy ic_vetkeys_manager_canister -e local && icp deploy ic_vetkeys_encrypted_maps_canister -e local",
92+
"test:deploy_key_manager_canister": "cd $(git rev-parse --show-toplevel)/backend/rs/canisters && (icp network stop || true) && icp network start -d && icp deploy ic_vetkeys_manager_canister -e local",
93+
"test:deploy_encrypted_maps_canister": "cd $(git rev-parse --show-toplevel)/backend/rs/canisters && (icp network stop || true) && icp network start -d && icp deploy ic_vetkeys_encrypted_maps_canister -e local"
9794
}
9895
}

frontend/ic_vetkeys/src/declarations/ic_vetkeys_encrypted_maps_canister/ic_vetkeys_encrypted_maps_canister.did.d.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
import type { Principal } from '@dfinity/principal';
2-
import type { ActorMethod } from '@dfinity/agent';
3-
import type { IDL } from '@dfinity/candid';
1+
/* eslint-disable */
2+
3+
// @ts-nocheck
4+
5+
// This file was automatically generated by @icp-sdk/bindgen@0.3.0.
6+
// You should NOT make any changes in this file as it will be overwritten.
7+
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
8+
9+
import type { ActorMethod } from '@icp-sdk/core/agent';
10+
import type { IDL } from '@icp-sdk/core/candid';
11+
import type { Principal } from '@icp-sdk/core/principal';
412

513
export type AccessRights = { 'Read' : null } |
614
{ 'ReadWrite' : null } |
715
{ 'ReadWriteManage' : null };
8-
export interface ByteBuf { 'inner' : Uint8Array | number[] }
16+
export interface ByteBuf { 'inner' : Uint8Array }
917
export interface EncryptedMapData {
1018
'access_control' : Array<[Principal, AccessRights]>,
1119
'keyvals' : Array<[ByteBuf, ByteBuf]>,
@@ -60,4 +68,4 @@ export interface _SERVICE {
6068
>,
6169
}
6270
export declare const idlFactory: IDL.InterfaceFactory;
63-
export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];
71+
export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];

frontend/ic_vetkeys/src/declarations/ic_vetkeys_encrypted_maps_canister/ic_vetkeys_encrypted_maps_canister.did.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* eslint-disable */
2+
3+
// @ts-nocheck
4+
5+
// This file was automatically generated by @icp-sdk/bindgen@0.3.0.
6+
// You should NOT make any changes in this file as it will be overwritten.
7+
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
8+
9+
import { IDL } from '@icp-sdk/core/candid';
10+
111
export const idlFactory = ({ IDL }) => {
212
const ByteBuf = IDL.Record({ 'inner' : IDL.Vec(IDL.Nat8) });
313
const AccessRights = IDL.Variant({
@@ -26,6 +36,7 @@ export const idlFactory = ({ IDL }) => {
2636
'Err' : IDL.Text,
2737
});
2838
const Result_5 = IDL.Variant({ 'Ok' : IDL.Vec(ByteBuf), 'Err' : IDL.Text });
39+
2940
return IDL.Service({
3041
'get_accessible_shared_map_names' : IDL.Func(
3142
[],
@@ -103,4 +114,5 @@ export const idlFactory = ({ IDL }) => {
103114
),
104115
});
105116
};
106-
export const init = ({ IDL }) => { return []; };
117+
118+
export const init = ({ IDL }) => { return [IDL.Text]; };

0 commit comments

Comments
 (0)