@icp-sdk/auth 5.0.0-beta.2 → 6.0.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.
@@ -1,83 +1,90 @@
1
- import { IdbKeyVal } from "./db.js";
2
- const KEY_STORAGE_KEY = "identity";
3
- const KEY_STORAGE_DELEGATION = "delegation";
4
- const KEY_VECTOR = "iv";
5
- const DB_VERSION = 1;
6
- class LocalStorage {
7
- constructor(prefix = "ic-", _localStorage) {
8
- this.prefix = prefix;
9
- this._localStorage = _localStorage;
10
- }
11
- get(key) {
12
- return Promise.resolve(this._getLocalStorage().getItem(this.prefix + key));
13
- }
14
- set(key, value) {
15
- this._getLocalStorage().setItem(this.prefix + key, value);
16
- return Promise.resolve();
17
- }
18
- remove(key) {
19
- this._getLocalStorage().removeItem(this.prefix + key);
20
- return Promise.resolve();
21
- }
22
- _getLocalStorage() {
23
- if (this._localStorage) {
24
- return this._localStorage;
1
+ import { IdbKeyVal } from './db.js';
2
+ export const KEY_STORAGE_KEY = 'identity';
3
+ export const KEY_STORAGE_DELEGATION = 'delegation';
4
+ export const KEY_VECTOR = 'iv';
5
+ // Increment if any fields are modified
6
+ export const DB_VERSION = 1;
7
+ /**
8
+ * Legacy implementation of AuthClientStorage, for use where IndexedDb is not available
9
+ */
10
+ export class LocalStorage {
11
+ prefix;
12
+ _localStorage;
13
+ constructor(prefix = 'ic-', _localStorage) {
14
+ this.prefix = prefix;
15
+ this._localStorage = _localStorage;
25
16
  }
26
- const ls = globalThis.localStorage;
27
- if (!ls) {
28
- throw new Error("Could not find local storage.");
17
+ get(key) {
18
+ return Promise.resolve(this._getLocalStorage().getItem(this.prefix + key));
19
+ }
20
+ set(key, value) {
21
+ this._getLocalStorage().setItem(this.prefix + key, value);
22
+ return Promise.resolve();
23
+ }
24
+ remove(key) {
25
+ this._getLocalStorage().removeItem(this.prefix + key);
26
+ return Promise.resolve();
27
+ }
28
+ _getLocalStorage() {
29
+ if (this._localStorage) {
30
+ return this._localStorage;
31
+ }
32
+ const ls = globalThis.localStorage;
33
+ if (!ls) {
34
+ throw new Error('Could not find local storage.');
35
+ }
36
+ return ls;
29
37
  }
30
- return ls;
31
- }
32
38
  }
33
- class IdbStorage {
34
- #options;
35
- /**
36
- * @param options - DBCreateOptions
37
- * @param options.dbName - name for the indexeddb database
38
- * @param options.storeName - name for the indexeddb Data Store
39
- * @param options.version - version of the database. Increment to safely upgrade
40
- * @example
41
- * ```ts
42
- * const storage = new IdbStorage({ dbName: 'my-db', storeName: 'my-store', version: 2 });
43
- * ```
44
- */
45
- constructor(options) {
46
- this.#options = options ?? {};
47
- }
48
- // Initializes a KeyVal on first request
49
- initializedDb;
50
- get _db() {
51
- return new Promise((resolve, reject) => {
52
- if (this.initializedDb) {
53
- resolve(this.initializedDb);
54
- return;
55
- }
56
- IdbKeyVal.create(this.#options).then((db) => {
57
- this.initializedDb = db;
58
- resolve(db);
59
- }).catch(reject);
60
- });
61
- }
62
- async get(key) {
63
- const db = await this._db;
64
- return await db.get(key);
65
- }
66
- async set(key, value) {
67
- const db = await this._db;
68
- await db.set(key, value);
69
- }
70
- async remove(key) {
71
- const db = await this._db;
72
- await db.remove(key);
73
- }
39
+ /**
40
+ * IdbStorage is an interface for simple storage of string key-value pairs built on {@link IdbKeyVal}
41
+ *
42
+ * It replaces {@link LocalStorage}
43
+ * @see implements {@link AuthClientStorage}
44
+ */
45
+ export class IdbStorage {
46
+ #options;
47
+ /**
48
+ * @param options - DBCreateOptions
49
+ * @param options.dbName - name for the indexeddb database
50
+ * @param options.storeName - name for the indexeddb Data Store
51
+ * @param options.version - version of the database. Increment to safely upgrade
52
+ * @example
53
+ * ```ts
54
+ * const storage = new IdbStorage({ dbName: 'my-db', storeName: 'my-store', version: 2 });
55
+ * ```
56
+ */
57
+ constructor(options) {
58
+ this.#options = options ?? {};
59
+ }
60
+ // Initializes a KeyVal on first request
61
+ initializedDb;
62
+ get _db() {
63
+ return new Promise((resolve, reject) => {
64
+ if (this.initializedDb) {
65
+ resolve(this.initializedDb);
66
+ return;
67
+ }
68
+ IdbKeyVal.create(this.#options)
69
+ .then((db) => {
70
+ this.initializedDb = db;
71
+ resolve(db);
72
+ })
73
+ .catch(reject);
74
+ });
75
+ }
76
+ async get(key) {
77
+ const db = await this._db;
78
+ return await db.get(key);
79
+ // return (await db.get<string>(key)) ?? null;
80
+ }
81
+ async set(key, value) {
82
+ const db = await this._db;
83
+ await db.set(key, value);
84
+ }
85
+ async remove(key) {
86
+ const db = await this._db;
87
+ await db.remove(key);
88
+ }
74
89
  }
75
- export {
76
- DB_VERSION,
77
- IdbStorage,
78
- KEY_STORAGE_DELEGATION,
79
- KEY_STORAGE_KEY,
80
- KEY_VECTOR,
81
- LocalStorage
82
- };
83
- //# sourceMappingURL=storage.js.map
90
+ //# sourceMappingURL=storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage.js","sources":["../../../src/client/storage.ts"],"sourcesContent":["import { type DBCreateOptions, IdbKeyVal } from './db.ts';\n\nexport const KEY_STORAGE_KEY = 'identity';\nexport const KEY_STORAGE_DELEGATION = 'delegation';\nexport const KEY_VECTOR = 'iv';\n// Increment if any fields are modified\nexport const DB_VERSION = 1;\n\nexport type StoredKey = string | CryptoKeyPair;\n\n/**\n * Interface for persisting user authentication data\n */\nexport interface AuthClientStorage {\n get(key: string): Promise<StoredKey | null>;\n\n set(key: string, value: StoredKey): Promise<void>;\n\n remove(key: string): Promise<void>;\n}\n\n/**\n * Legacy implementation of AuthClientStorage, for use where IndexedDb is not available\n */\nexport class LocalStorage implements AuthClientStorage {\n constructor(\n public readonly prefix = 'ic-',\n private readonly _localStorage?: Storage,\n ) {}\n\n public get(key: string): Promise<string | null> {\n return Promise.resolve(this._getLocalStorage().getItem(this.prefix + key));\n }\n\n public set(key: string, value: string): Promise<void> {\n this._getLocalStorage().setItem(this.prefix + key, value);\n return Promise.resolve();\n }\n\n public remove(key: string): Promise<void> {\n this._getLocalStorage().removeItem(this.prefix + key);\n return Promise.resolve();\n }\n\n private _getLocalStorage() {\n if (this._localStorage) {\n return this._localStorage;\n }\n\n const ls = globalThis.localStorage;\n if (!ls) {\n throw new Error('Could not find local storage.');\n }\n\n return ls;\n }\n}\n\n/**\n * IdbStorage is an interface for simple storage of string key-value pairs built on {@link IdbKeyVal}\n *\n * It replaces {@link LocalStorage}\n * @see implements {@link AuthClientStorage}\n */\nexport class IdbStorage implements AuthClientStorage {\n #options: DBCreateOptions;\n\n /**\n * @param options - DBCreateOptions\n * @param options.dbName - name for the indexeddb database\n * @param options.storeName - name for the indexeddb Data Store\n * @param options.version - version of the database. Increment to safely upgrade\n * @example\n * ```ts\n * const storage = new IdbStorage({ dbName: 'my-db', storeName: 'my-store', version: 2 });\n * ```\n */\n constructor(options?: DBCreateOptions) {\n this.#options = options ?? {};\n }\n\n // Initializes a KeyVal on first request\n private initializedDb: IdbKeyVal | undefined;\n get _db(): Promise<IdbKeyVal> {\n return new Promise((resolve, reject) => {\n if (this.initializedDb) {\n resolve(this.initializedDb);\n return;\n }\n IdbKeyVal.create(this.#options)\n .then((db) => {\n this.initializedDb = db;\n resolve(db);\n })\n .catch(reject);\n });\n }\n\n public async get<T = string>(key: string): Promise<T | null> {\n const db = await this._db;\n return await db.get<T>(key);\n // return (await db.get<string>(key)) ?? null;\n }\n\n public async set<T = string>(key: string, value: T): Promise<void> {\n const db = await this._db;\n await db.set(key, value);\n }\n\n public async remove(key: string): Promise<void> {\n const db = await this._db;\n await db.remove(key);\n }\n}\n"],"names":[],"mappings":";AAEO,MAAM,kBAAkB;AACxB,MAAM,yBAAyB;AAC/B,MAAM,aAAa;AAEnB,MAAM,aAAa;AAkBnB,MAAM,aAA0C;AAAA,EACrD,YACkB,SAAS,OACR,eACjB;AAFgB,SAAA,SAAA;AACC,SAAA,gBAAA;AAAA,EAChB;AAAA,EAEI,IAAI,KAAqC;AAC9C,WAAO,QAAQ,QAAQ,KAAK,iBAAA,EAAmB,QAAQ,KAAK,SAAS,GAAG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,CAAC;QAC1B,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;CACF"}
package/dist/esm/index.js CHANGED
@@ -1,4 +1,3 @@
1
- throw new Error(
2
- "There are no exports in the root module of this package. Import from submodules instead. Use intellisense or the docs to find the available submodules."
3
- );
4
- //# sourceMappingURL=index.js.map
1
+ throw new Error('There are no exports in the root module of this package. Import from submodules instead. Use intellisense or the docs to find the available submodules.');
2
+ export {};
3
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["throw new Error(\n 'There are no exports in the root module of this package. Import from submodules instead. Use intellisense or the docs to find the available submodules.',\n);\n"],"names":[],"mappings":"AAAA,MAAM,IAAI;AAAA,EACR;AACF;"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,IAAI,KAAK,CACb,yJAAyJ,CAC1J,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icp-sdk/auth",
3
- "version": "5.0.0-beta.2",
3
+ "version": "6.0.0",
4
4
  "author": "DFINITY Stiftung <sdk@dfinity.org>",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Authentication library for Internet Computer web apps",
@@ -42,24 +42,23 @@
42
42
  "internet identity"
43
43
  ],
44
44
  "devDependencies": {
45
- "@biomejs/biome": "^2.3.7",
46
- "@icp-sdk/core": "5.0.0-beta.2",
47
- "@tanstack/config": "^0.22.1",
45
+ "@biomejs/biome": "^2.4.10",
46
+ "@icp-sdk/core": "^5.2.1",
47
+ "@icp-sdk/signer": "^5.2.0",
48
48
  "fake-indexeddb": "^6.2.5",
49
- "jsdom": "^27.2.0",
50
- "publint": "^0.3.15",
49
+ "jsdom": "^27.4.0",
50
+ "publint": "^0.3.18",
51
51
  "typescript": "^5.9.3",
52
- "vite": "^7.2.4",
53
52
  "vitest": "4.0.14"
54
53
  },
55
54
  "peerDependencies": {
56
- "@icp-sdk/core": "5.0.0-beta.2"
55
+ "@icp-sdk/core": "^5"
57
56
  },
58
57
  "dependencies": {
59
58
  "idb": "^7.1.1"
60
59
  },
61
60
  "scripts": {
62
- "build": "vite build && pnpm lint:package",
61
+ "build": "tsc -p tsconfig.build.json && pnpm lint:package",
63
62
  "test": "vitest",
64
63
  "codestyle:check": "biome check",
65
64
  "codestyle:fix": "biome check --write",