@icp-sdk/auth 4.1.0 → 4.1.1
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.
|
@@ -48,7 +48,7 @@ class IdbStorage {
|
|
|
48
48
|
// Initializes a KeyVal on first request
|
|
49
49
|
initializedDb;
|
|
50
50
|
get _db() {
|
|
51
|
-
return new Promise((resolve) => {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
52
|
if (this.initializedDb) {
|
|
53
53
|
resolve(this.initializedDb);
|
|
54
54
|
return;
|
|
@@ -56,7 +56,7 @@ class IdbStorage {
|
|
|
56
56
|
IdbKeyVal.create(this.#options).then((db) => {
|
|
57
57
|
this.initializedDb = db;
|
|
58
58
|
resolve(db);
|
|
59
|
-
});
|
|
59
|
+
}).catch(reject);
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
async get(key) {
|
|
@@ -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) => {\n if (this.initializedDb) {\n resolve(this.initializedDb);\n return;\n }\n IdbKeyVal.create(this.#options).then((db) => {\n
|
|
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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A,EAEA,MAAa,IAAgB,KAAa,OAAyB;AACjE,UAAM,KAAK,MAAM,KAAK;AACtB,UAAM,GAAG,IAAI,KAAK,KAAK;AAAA,EACzB;AAAA,EAEA,MAAa,OAAO,KAA4B;AAC9C,UAAM,KAAK,MAAM,KAAK;AACtB,UAAM,GAAG,OAAO,GAAG;AAAA,EACrB;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icp-sdk/auth",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
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,23 +42,23 @@
|
|
|
42
42
|
"internet identity"
|
|
43
43
|
],
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@biomejs/biome": "^2.2.
|
|
46
|
-
"@icp-sdk/core": "^4.0
|
|
47
|
-
"@tanstack/config": "^0.
|
|
48
|
-
"fake-indexeddb": "^6.2.
|
|
49
|
-
"jsdom": "^27.0.
|
|
50
|
-
"publint": "^0.3.
|
|
51
|
-
"typescript": "^5.9.
|
|
52
|
-
"vite": "^7.1.
|
|
45
|
+
"@biomejs/biome": "^2.2.6",
|
|
46
|
+
"@icp-sdk/core": "^4.1.0",
|
|
47
|
+
"@tanstack/config": "^0.22.0",
|
|
48
|
+
"fake-indexeddb": "^6.2.4",
|
|
49
|
+
"jsdom": "^27.0.1",
|
|
50
|
+
"publint": "^0.3.15",
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"vite": "^7.1.11",
|
|
53
53
|
"vitest": "3.2.4"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@icp-sdk/core": "^4
|
|
56
|
+
"@icp-sdk/core": "^4"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"idb": "^7.1.1",
|
|
60
59
|
"@slide-computer/signer": "^4.0.0",
|
|
61
|
-
"@slide-computer/signer-web": "^4.0.0"
|
|
60
|
+
"@slide-computer/signer-web": "^4.0.0",
|
|
61
|
+
"idb": "^7.1.1"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "vite build && pnpm lint:package",
|
package/src/client/storage.ts
CHANGED
|
@@ -82,15 +82,17 @@ export class IdbStorage implements AuthClientStorage {
|
|
|
82
82
|
// Initializes a KeyVal on first request
|
|
83
83
|
private initializedDb: IdbKeyVal | undefined;
|
|
84
84
|
get _db(): Promise<IdbKeyVal> {
|
|
85
|
-
return new Promise((resolve) => {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
86
|
if (this.initializedDb) {
|
|
87
87
|
resolve(this.initializedDb);
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
|
-
IdbKeyVal.create(this.#options)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
IdbKeyVal.create(this.#options)
|
|
91
|
+
.then((db) => {
|
|
92
|
+
this.initializedDb = db;
|
|
93
|
+
resolve(db);
|
|
94
|
+
})
|
|
95
|
+
.catch(reject);
|
|
94
96
|
});
|
|
95
97
|
}
|
|
96
98
|
|