odin-connect 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/demo/package-lock.json
CHANGED
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
"name": "demo",
|
|
9
9
|
"version": "0.0.0",
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"@dfinity/identity": "^3.3.0",
|
|
11
12
|
"odin-connect": "file:..",
|
|
12
13
|
"react": "^19.1.1",
|
|
13
14
|
"react-dom": "^19.1.1"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
17
|
+
"@apimatic/json-bigint": "^1.2.0",
|
|
16
18
|
"@eslint/js": "^9.33.0",
|
|
17
19
|
"@types/react": "^19.1.10",
|
|
18
20
|
"@types/react-dom": "^19.1.7",
|
|
@@ -27,10 +29,11 @@
|
|
|
27
29
|
}
|
|
28
30
|
},
|
|
29
31
|
"..": {
|
|
30
|
-
"version": "1.0.
|
|
32
|
+
"version": "1.0.3",
|
|
31
33
|
"license": "ISC",
|
|
32
34
|
"dependencies": {
|
|
33
35
|
"@apimatic/json-bigint": "^1.2.0",
|
|
36
|
+
"@dfinity/identity": "^3.3.0",
|
|
34
37
|
"axios": "^1.12.0"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
@@ -42,6 +45,13 @@
|
|
|
42
45
|
"vitest": "^3.2.4"
|
|
43
46
|
}
|
|
44
47
|
},
|
|
48
|
+
"node_modules/@apimatic/json-bigint": {
|
|
49
|
+
"version": "1.2.0",
|
|
50
|
+
"resolved": "https://registry.npmjs.org/@apimatic/json-bigint/-/json-bigint-1.2.0.tgz",
|
|
51
|
+
"integrity": "sha512-+bmVzYMdZu0Ya5L+my4FXFUih54OvQA/qlZsFOYdOoostyUuB27UDrVWQs/WVCmS0ADdo5vTU0eeTrrBkHoySw==",
|
|
52
|
+
"dev": true,
|
|
53
|
+
"license": "MIT"
|
|
54
|
+
},
|
|
45
55
|
"node_modules/@babel/code-frame": {
|
|
46
56
|
"version": "7.27.1",
|
|
47
57
|
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz",
|
|
@@ -324,6 +334,62 @@
|
|
|
324
334
|
"node": ">=6.9.0"
|
|
325
335
|
}
|
|
326
336
|
},
|
|
337
|
+
"node_modules/@dfinity/agent": {
|
|
338
|
+
"version": "3.3.0",
|
|
339
|
+
"resolved": "https://registry.npmjs.org/@dfinity/agent/-/agent-3.3.0.tgz",
|
|
340
|
+
"integrity": "sha512-CymEzXEfWpY+ecLlRhVa5occAQBIx5xVghZZ6EH1PSQVHm2bUXXPGmhC0SbEG+1qFgfiBSGCpJ2bMhrA1kBifw==",
|
|
341
|
+
"license": "Apache-2.0",
|
|
342
|
+
"peer": true,
|
|
343
|
+
"dependencies": {
|
|
344
|
+
"@dfinity/cbor": "^0.2.2",
|
|
345
|
+
"@noble/curves": "^1.9.2"
|
|
346
|
+
},
|
|
347
|
+
"peerDependencies": {
|
|
348
|
+
"@dfinity/candid": "3.3.0",
|
|
349
|
+
"@dfinity/principal": "3.3.0",
|
|
350
|
+
"@noble/hashes": "^1.8.0"
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
"node_modules/@dfinity/candid": {
|
|
354
|
+
"version": "3.3.0",
|
|
355
|
+
"resolved": "https://registry.npmjs.org/@dfinity/candid/-/candid-3.3.0.tgz",
|
|
356
|
+
"integrity": "sha512-cBK1B4EAr5FcwHjcXC5Hh9tFjWt8suFTggprhBJ0pJb7A7sztJJMxZrFbkfE8GdYoaIl3FUV0TatKT3C7FJ7ow==",
|
|
357
|
+
"license": "Apache-2.0",
|
|
358
|
+
"peer": true,
|
|
359
|
+
"peerDependencies": {
|
|
360
|
+
"@dfinity/principal": "3.3.0"
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
"node_modules/@dfinity/cbor": {
|
|
364
|
+
"version": "0.2.2",
|
|
365
|
+
"resolved": "https://registry.npmjs.org/@dfinity/cbor/-/cbor-0.2.2.tgz",
|
|
366
|
+
"integrity": "sha512-GPJpH73kDEKbUBdUjY80lz7cq9l0vm1h/7ppejPV6O0ZTqCLrYspssYvqjRmK4aNnJ/SKXsP0rg9LYX7zpegaA==",
|
|
367
|
+
"license": "Apache-2.0",
|
|
368
|
+
"peer": true
|
|
369
|
+
},
|
|
370
|
+
"node_modules/@dfinity/identity": {
|
|
371
|
+
"version": "3.3.0",
|
|
372
|
+
"resolved": "https://registry.npmjs.org/@dfinity/identity/-/identity-3.3.0.tgz",
|
|
373
|
+
"integrity": "sha512-991/j+PSgxSeaFLHBL6oD3whsjbpII+EtUsc8YfLi89mW9Prt8HAmxx39lLNQ2xykBitAopDcrAA7RJ6de/xiA==",
|
|
374
|
+
"license": "Apache-2.0",
|
|
375
|
+
"peerDependencies": {
|
|
376
|
+
"@dfinity/agent": "3.3.0",
|
|
377
|
+
"@dfinity/candid": "3.3.0",
|
|
378
|
+
"@dfinity/principal": "3.3.0",
|
|
379
|
+
"@noble/curves": "^1.9.2",
|
|
380
|
+
"@noble/hashes": "^1.8.0"
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
"node_modules/@dfinity/principal": {
|
|
384
|
+
"version": "3.3.0",
|
|
385
|
+
"resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-3.3.0.tgz",
|
|
386
|
+
"integrity": "sha512-0oisjzg6n7U7raayhcpmBLGxPQ4o/FbsMv0JN7OecVHaXo7+RfTrv+Dr5ty4JHTZJEw/4q+3sSPG9otRpbjaMA==",
|
|
387
|
+
"license": "Apache-2.0",
|
|
388
|
+
"peer": true,
|
|
389
|
+
"dependencies": {
|
|
390
|
+
"@noble/hashes": "^1.8.0"
|
|
391
|
+
}
|
|
392
|
+
},
|
|
327
393
|
"node_modules/@esbuild/aix-ppc64": {
|
|
328
394
|
"version": "0.25.9",
|
|
329
395
|
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.9.tgz",
|
|
@@ -1022,6 +1088,35 @@
|
|
|
1022
1088
|
"@jridgewell/sourcemap-codec": "^1.4.14"
|
|
1023
1089
|
}
|
|
1024
1090
|
},
|
|
1091
|
+
"node_modules/@noble/curves": {
|
|
1092
|
+
"version": "1.9.7",
|
|
1093
|
+
"resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.9.7.tgz",
|
|
1094
|
+
"integrity": "sha512-gbKGcRUYIjA3/zCCNaWDciTMFI0dCkvou3TL8Zmy5Nc7sJ47a0jtOeZoTaMxkuqRo9cRhjOdZJXegxYE5FN/xw==",
|
|
1095
|
+
"license": "MIT",
|
|
1096
|
+
"peer": true,
|
|
1097
|
+
"dependencies": {
|
|
1098
|
+
"@noble/hashes": "1.8.0"
|
|
1099
|
+
},
|
|
1100
|
+
"engines": {
|
|
1101
|
+
"node": "^14.21.3 || >=16"
|
|
1102
|
+
},
|
|
1103
|
+
"funding": {
|
|
1104
|
+
"url": "https://paulmillr.com/funding/"
|
|
1105
|
+
}
|
|
1106
|
+
},
|
|
1107
|
+
"node_modules/@noble/hashes": {
|
|
1108
|
+
"version": "1.8.0",
|
|
1109
|
+
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.8.0.tgz",
|
|
1110
|
+
"integrity": "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==",
|
|
1111
|
+
"license": "MIT",
|
|
1112
|
+
"peer": true,
|
|
1113
|
+
"engines": {
|
|
1114
|
+
"node": "^14.21.3 || >=16"
|
|
1115
|
+
},
|
|
1116
|
+
"funding": {
|
|
1117
|
+
"url": "https://paulmillr.com/funding/"
|
|
1118
|
+
}
|
|
1119
|
+
},
|
|
1025
1120
|
"node_modules/@nodelib/fs.scandir": {
|
|
1026
1121
|
"version": "2.1.5",
|
|
1027
1122
|
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
package/demo/package.json
CHANGED
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
"preview": "vite preview"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"@dfinity/identity": "^3.3.0",
|
|
13
14
|
"odin-connect": "file:..",
|
|
14
15
|
"react": "^19.1.1",
|
|
15
16
|
"react-dom": "^19.1.1"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
19
|
+
"@apimatic/json-bigint": "^1.2.0",
|
|
18
20
|
"@eslint/js": "^9.33.0",
|
|
19
21
|
"@types/react": "^19.1.10",
|
|
20
22
|
"@types/react-dom": "^19.1.7",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { User } from "../models/user";
|
|
2
2
|
import { OdinApi, Pagination, Sort } from "./api";
|
|
3
|
+
import { DelegationChain, Ed25519KeyIdentity } from "@dfinity/identity";
|
|
4
|
+
import type { DerEncodedPublicKey } from "@dfinity/agent";
|
|
3
5
|
declare const ORIGINS: {
|
|
4
6
|
local: string;
|
|
5
7
|
prod: string;
|
|
@@ -11,12 +13,28 @@ interface AppInitOptions {
|
|
|
11
13
|
icon?: string;
|
|
12
14
|
env?: keyof typeof ORIGINS;
|
|
13
15
|
}
|
|
14
|
-
interface
|
|
16
|
+
interface BaseConnectOptions {
|
|
15
17
|
open?: {
|
|
16
18
|
target: string;
|
|
17
19
|
settings: string;
|
|
18
20
|
};
|
|
19
|
-
requires_api
|
|
21
|
+
requires_api?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface ConnectOptionsWithDelegation extends BaseConnectOptions {
|
|
24
|
+
requires_delegation: true;
|
|
25
|
+
targets: string[];
|
|
26
|
+
session_key: Ed25519KeyIdentity;
|
|
27
|
+
public_key: DerEncodedPublicKey;
|
|
28
|
+
}
|
|
29
|
+
interface ConnectOptionsWithoutDelegation extends BaseConnectOptions {
|
|
30
|
+
requires_delegation?: false;
|
|
31
|
+
targets?: never;
|
|
32
|
+
session_key?: never;
|
|
33
|
+
}
|
|
34
|
+
type ConnectOptions = ConnectOptionsWithDelegation | ConnectOptionsWithoutDelegation;
|
|
35
|
+
interface ConnectResult {
|
|
36
|
+
user: User;
|
|
37
|
+
delegationChain?: DelegationChain | null;
|
|
20
38
|
}
|
|
21
39
|
interface BuyOptions {
|
|
22
40
|
principal: string;
|
|
@@ -84,7 +102,7 @@ export declare class Connect {
|
|
|
84
102
|
private createUrl;
|
|
85
103
|
private openWindow;
|
|
86
104
|
get origin(): string;
|
|
87
|
-
connect({ open, requires_api }:
|
|
105
|
+
connect({ open, requires_api, requires_delegation, session_key, targets, }: ConnectOptions): Promise<ConnectResult>;
|
|
88
106
|
getBalances({ principal, pagination }: GetBalanceOptions): Promise<readonly import("..").OdinBalance[]>;
|
|
89
107
|
getUser(principal: string): Promise<User>;
|
|
90
108
|
getToken(id: string): Promise<import("..").OdinToken>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/services/connect.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/services/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,EACL,eAAe,EACf,kBAAkB,EAEnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEzD,QAAA,MAAM,OAAO;;;;;CAMZ,CAAC;AAEF,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,OAAO,OAAO,CAAC;CAC5B;AACD,UAAU,kBAAkB;IAE1B,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,C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AAE,UAAU,EAAE,IAAI,EAAE,EAAE,mBAAmB;IAInD,eAAe,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,sBAAsB;IAKjE,IAAI,SAAS,YAEZ;IAED,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,WAAW;IAiBnD,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,UAAU;IAiB/C,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,eAAe;IAkBnE,YAAY,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,mBAAmB;IAiBjE,eAAe,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,sBAAsB;IAiBtE,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,WAAW;IAkBnE,WAAW,CAAC,EAAE,KAAK,EAAE,GAAG,MAAM,EAAE,EAAE,iBAAiB;IA0CzD,KAAK;IAIL,OAAO,CAAC,UAAU;CA4CnB"}
|
package/dist/services/connect.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OdinApi } from "./api";
|
|
2
2
|
import { createTokenValidators } from "../utils";
|
|
3
|
+
import { DelegationChain, } from "@dfinity/identity";
|
|
3
4
|
const ORIGINS = {
|
|
4
5
|
local: "http://localhost:5173",
|
|
5
6
|
prod: "https://odin.fun",
|
|
@@ -36,7 +37,7 @@ export class Connect {
|
|
|
36
37
|
get origin() {
|
|
37
38
|
return ORIGINS[this._appInfo?.env || "prod"];
|
|
38
39
|
}
|
|
39
|
-
connect({ open, requires_api }) {
|
|
40
|
+
connect({ open, requires_api, requires_delegation, session_key, targets, }) {
|
|
40
41
|
return new Promise((resolve, reject) => {
|
|
41
42
|
if (open) {
|
|
42
43
|
this._windowSettings = open;
|
|
@@ -48,15 +49,16 @@ export class Connect {
|
|
|
48
49
|
if (event.data.message != "rejected") {
|
|
49
50
|
// the user accepted the connection
|
|
50
51
|
try {
|
|
51
|
-
const
|
|
52
|
+
const eventData = event.data.message;
|
|
53
|
+
const { principal, jwt: jwtToken, delegationChain } = eventData;
|
|
52
54
|
if (requires_api) {
|
|
53
55
|
// issue a api key
|
|
54
56
|
// only using JWT for now, it will change in the real implementation
|
|
55
57
|
this._api.apiKey = jwtToken;
|
|
56
58
|
}
|
|
57
59
|
// we need to fetch user data from the api to get the full user object
|
|
58
|
-
const user = await this._api.getUser(
|
|
59
|
-
resolve(user);
|
|
60
|
+
const user = await this._api.getUser(principal);
|
|
61
|
+
resolve({ user, delegationChain: delegationChain ? DelegationChain.fromJSON(delegationChain) : null });
|
|
60
62
|
}
|
|
61
63
|
catch (error) {
|
|
62
64
|
reject(new Error("Failed to fetch user data"));
|
|
@@ -69,6 +71,12 @@ export class Connect {
|
|
|
69
71
|
};
|
|
70
72
|
const url = this.createUrl("authorize/connect");
|
|
71
73
|
url.searchParams.append("requires_api", requires_api ? "1" : "0");
|
|
74
|
+
if (requires_delegation) {
|
|
75
|
+
url.searchParams.append("requires_delegation", "1");
|
|
76
|
+
const sessionString = btoa(JSON.stringify(session_key.toJSON()));
|
|
77
|
+
url.searchParams.append("session_key", sessionString);
|
|
78
|
+
url.searchParams.append("targets", targets.join(","));
|
|
79
|
+
}
|
|
72
80
|
this.openWindow(url);
|
|
73
81
|
window.addEventListener("message", handleMessage);
|
|
74
82
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll, vi } from "vitest";
|
|
1
|
+
import { describe, it, expect, beforeAll, vi, afterEach } from "vitest";
|
|
2
2
|
import { Connect } from "./connect";
|
|
3
3
|
const mockTokens = [
|
|
4
4
|
{
|
|
@@ -15,6 +15,9 @@ describe("Connect", () => {
|
|
|
15
15
|
username: "username",
|
|
16
16
|
});
|
|
17
17
|
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.restoreAllMocks();
|
|
20
|
+
});
|
|
18
21
|
it("should initialize Connect instance", () => {
|
|
19
22
|
expect(connect).toBeDefined();
|
|
20
23
|
expect(connect).toBeInstanceOf(Connect);
|
|
@@ -36,12 +39,15 @@ describe("Connect", () => {
|
|
|
36
39
|
});
|
|
37
40
|
it("should open the connect window", () => {
|
|
38
41
|
const openSpy = vi.spyOn(window, "open").mockImplementation(() => null);
|
|
39
|
-
const getUserSpy = vi.spyOn(connect["_api"], "getUser")
|
|
42
|
+
const getUserSpy = vi.spyOn(connect["_api"], "getUser").mockResolvedValue({
|
|
43
|
+
principal: "user-principal",
|
|
44
|
+
username: "username",
|
|
45
|
+
});
|
|
40
46
|
const connectPromise = connect.connect({ requires_api: false });
|
|
41
47
|
connectPromise.then((res) => {
|
|
42
48
|
expect(res).toBeDefined();
|
|
43
|
-
expect(res.username).toBe("username");
|
|
44
|
-
expect(res.principal).toBe("user-principal");
|
|
49
|
+
expect(res.user.username).toBe("username");
|
|
50
|
+
expect(res.user.principal).toBe("user-principal");
|
|
45
51
|
expect(connect.apiClient.apiKey).toBeNull();
|
|
46
52
|
}, (e) => {
|
|
47
53
|
expect(true).toBe(false);
|
|
@@ -53,16 +59,24 @@ describe("Connect", () => {
|
|
|
53
59
|
expect(params.get("app_name")).toBe("TestApp");
|
|
54
60
|
expect(params.get("referrer")).toBeDefined();
|
|
55
61
|
expect(params.get("requires_api")).toBe("0");
|
|
56
|
-
simulateMessage("authorize/connect",
|
|
62
|
+
simulateMessage("authorize/connect", {
|
|
63
|
+
principal: "user-principal",
|
|
64
|
+
jwt: null,
|
|
65
|
+
});
|
|
57
66
|
expect(getUserSpy).toHaveBeenCalledWith("user-principal");
|
|
58
67
|
});
|
|
59
68
|
it("should open connect window with API requirement", () => {
|
|
69
|
+
vi.spyOn(connect["_api"], "getUser").mockResolvedValue({
|
|
70
|
+
principal: "user-principal",
|
|
71
|
+
username: "username",
|
|
72
|
+
});
|
|
60
73
|
const openSpy = vi.spyOn(window, "open").mockImplementation(() => null);
|
|
61
74
|
const connectPromise = connect.connect({ requires_api: true });
|
|
62
75
|
connectPromise.then((res) => {
|
|
76
|
+
console.log(res);
|
|
63
77
|
expect(res).toBeDefined();
|
|
64
|
-
expect(res.username).toBe("username");
|
|
65
|
-
expect(res.principal).toBe("user-principal");
|
|
78
|
+
expect(res.user.username).toBe("username");
|
|
79
|
+
expect(res.user.principal).toBe("user-principal");
|
|
66
80
|
expect(connect.apiClient.apiKey).toBe("test-jwt");
|
|
67
81
|
}, () => {
|
|
68
82
|
expect(true).toBe(false);
|
|
@@ -74,7 +88,10 @@ describe("Connect", () => {
|
|
|
74
88
|
expect(params.get("app_name")).toBe("TestApp");
|
|
75
89
|
expect(params.get("referrer")).toBeDefined();
|
|
76
90
|
expect(params.get("requires_api")).toBe("1");
|
|
77
|
-
simulateMessage("authorize/connect",
|
|
91
|
+
simulateMessage("authorize/connect", {
|
|
92
|
+
principal: "user-principal",
|
|
93
|
+
jwt: "test-jwt",
|
|
94
|
+
});
|
|
78
95
|
});
|
|
79
96
|
it("should handle rejected connection", () => {
|
|
80
97
|
const connectPromise = connect.connect({ requires_api: false });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "odin-connect",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"test": "vitest",
|
|
11
11
|
"demo:update": "npm run build && cd demo && npm install ../ && cd ..",
|
|
12
12
|
"demo:start": "cd demo && npm run dev",
|
|
13
|
+
"demo:build": "npm run demo:update && cd demo && npm run build",
|
|
13
14
|
"demo": "npm run demo:update && npm run demo:start",
|
|
14
15
|
"release": "release-it"
|
|
15
16
|
},
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"@apimatic/json-bigint": "^1.2.0",
|
|
39
|
+
"@dfinity/identity": "^3.3.0",
|
|
38
40
|
"axios": "^1.12.0"
|
|
39
41
|
},
|
|
40
42
|
"release-it": {
|