@junobuild/ic-client 7.1.1 → 7.2.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/dev/_constants.d.ts +1 -0
- package/dev/errors.d.ts +9 -0
- package/dev/identity.d.ts +43 -0
- package/dev/types/identity.d.ts +48 -0
- package/dev.d.ts +3 -0
- package/dev.js +2 -0
- package/dev.js.map +7 -0
- package/dev.mjs +4 -0
- package/dev.mjs.map +7 -0
- package/package.json +8 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEFAULT_DEV_DELEGATION_IDENTITY_EXPIRATION_IN_MS: number;
|
package/dev/errors.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class UnsafeDevIdentityNotBrowserError extends Error {
|
|
2
|
+
constructor();
|
|
3
|
+
}
|
|
4
|
+
export declare class UnsafeDevIdentityNotLocalhostError extends Error {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export declare class UnsafeDevIdentityInvalidIdentifierError extends Error {
|
|
8
|
+
constructor(length: number);
|
|
9
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DevIdentifier, DevIdentifierData, GenerateUnsafeIdentityParams, GenerateUnsafeIdentityResult, LoadDevIdentifiersParams } from './types/identity';
|
|
2
|
+
/**
|
|
3
|
+
* Load all development identifiers that have been used for authentication.
|
|
4
|
+
*
|
|
5
|
+
* Returns an array of tuples containing the identifier string and metadata (created/updated timestamps),
|
|
6
|
+
* sorted by most recently used first.
|
|
7
|
+
*
|
|
8
|
+
* @param params - Load parameters
|
|
9
|
+
* @param params.limit - Optional maximum number of identifiers to return
|
|
10
|
+
* @returns Promise resolving to array of [identifier, metadata] tuples sorted by updatedAt descending
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const recent = await loadDevIdentifiers({ limit: 5 });
|
|
14
|
+
* // Returns only the 5 most recently used identifiers
|
|
15
|
+
*/
|
|
16
|
+
export declare const loadDevIdentifiers: ({ limit }?: LoadDevIdentifiersParams) => Promise<[DevIdentifier, DevIdentifierData][]>;
|
|
17
|
+
/**
|
|
18
|
+
* Clear all stored development identifiers from IndexedDB.
|
|
19
|
+
* This removes the history of used identifiers but does not affect AuthClient's stored credentials.
|
|
20
|
+
*
|
|
21
|
+
* @returns Promise that resolves when identifiers are cleared
|
|
22
|
+
*/
|
|
23
|
+
export declare const clearDevIdentifiers: () => Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Generate an identity for local development with the Internet Computer.
|
|
26
|
+
*
|
|
27
|
+
* ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
|
|
28
|
+
* ⚠️ UNSAFE - FOR LOCAL DEVELOPMENT ONLY ⚠️
|
|
29
|
+
* ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
|
|
30
|
+
*
|
|
31
|
+
* Returns the identity, session key, and delegation chain.
|
|
32
|
+
* Consumers must handle storage (e.g. for AuthClient compatibility).
|
|
33
|
+
*
|
|
34
|
+
* @param params - Generation parameters
|
|
35
|
+
* @param params.identifier - Unique identifier string for this dev identity (default: "dev")
|
|
36
|
+
* @param params.maxTimeToLiveInMilliseconds - Delegation expiration time in ms (default: 7 days)
|
|
37
|
+
*
|
|
38
|
+
* @returns Promise resolving to object containing identity, sessionKey, and delegationChain
|
|
39
|
+
*
|
|
40
|
+
* @throws {UnsafeDevIdentityNotBrowserError} If called outside browser environment
|
|
41
|
+
* @throws {UnsafeDevIdentityNotLocalhostError} If called outside localhost
|
|
42
|
+
**/
|
|
43
|
+
export declare const generateUnsafeDevIdentity: ({ identifier, maxTimeToLiveInMilliseconds }?: GenerateUnsafeIdentityParams) => Promise<GenerateUnsafeIdentityResult>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { DelegationChain, DelegationIdentity, ECDSAKeyIdentity } from '@icp-sdk/core/identity';
|
|
2
|
+
/**
|
|
3
|
+
* A unique string identifier for a development identity.
|
|
4
|
+
* e.g. "dev" or "david"
|
|
5
|
+
*/
|
|
6
|
+
export type DevIdentifier = string;
|
|
7
|
+
/**
|
|
8
|
+
* Timestamp in milliseconds since Unix epoch.
|
|
9
|
+
* Date objects cannot be persisted in IndexedDB, so we use numeric timestamps.
|
|
10
|
+
*/
|
|
11
|
+
export type DevIdentifierTimestamp = number;
|
|
12
|
+
/**
|
|
13
|
+
* Metadata about a development identifier's usage.
|
|
14
|
+
*/
|
|
15
|
+
export interface DevIdentifierData {
|
|
16
|
+
/** Timestamp when this identifier was first used */
|
|
17
|
+
createdAt: DevIdentifierTimestamp;
|
|
18
|
+
/** Timestamp when this identifier was last used */
|
|
19
|
+
updatedAt: DevIdentifierTimestamp;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parameters for generating an unsafe development identity.
|
|
23
|
+
*/
|
|
24
|
+
export interface GenerateUnsafeIdentityParams {
|
|
25
|
+
/** Unique identifier string for this dev identity (default: "dev") */
|
|
26
|
+
identifier?: DevIdentifier;
|
|
27
|
+
/** Delegation expiration time in milliseconds (default: 7 days) */
|
|
28
|
+
maxTimeToLiveInMilliseconds?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Result of generating an unsafe development identity.
|
|
32
|
+
* Contains all components needed for authentication and storage.
|
|
33
|
+
*/
|
|
34
|
+
export interface GenerateUnsafeIdentityResult {
|
|
35
|
+
/** The delegated identity for making IC calls */
|
|
36
|
+
identity: DelegationIdentity;
|
|
37
|
+
/** The session key (to be stored in IDB for AuthClient compatibility, key KEY_STORAGE_KEY) */
|
|
38
|
+
sessionKey: ECDSAKeyIdentity;
|
|
39
|
+
/** The delegation chain (to be store in IDB for AuthClient compatibility, key KEY_STORAGE_DELEGATION) */
|
|
40
|
+
delegationChain: DelegationChain;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parameters for loading development identifiers.
|
|
44
|
+
*/
|
|
45
|
+
export interface LoadDevIdentifiersParams {
|
|
46
|
+
/** Optional maximum number of identifiers to return */
|
|
47
|
+
limit?: number;
|
|
48
|
+
}
|
package/dev.d.ts
ADDED
package/dev.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=class extends Error{constructor(){super("A dev identity can only be used in browser environments")}},s=class extends Error{constructor(){super("A dev identity must only be used on localhost (127.0.0.1 or localhost)")}},i=class extends Error{constructor(t){super(`Identifier must be 32 characters or less, got ${t}`)}};import{DelegationChain as w,DelegationIdentity as v,ECDSAKeyIdentity as E,Ed25519KeyIdentity as g}from"@icp-sdk/core/identity";import{clear as x,createStore as A,entries as _,update as h}from"idb-keyval";var I=A("juno-dev-identifiers","juno-dev-identifiers-store"),S=async({limit:e}={})=>(await _(I)).sort(([y,{updatedAt:a}],[l,{updatedAt:d}])=>d-a).slice(0,e),R=()=>x(I),K=async({identifier:e="dev",maxTimeToLiveInMilliseconds:t}={})=>{if(!(typeof window<"u"))throw new o;let{location:{hostname:a}}=window;if(!["127.0.0.1","localhost"].includes(a))throw new s;let l=()=>{if(e.length>32)throw new i(e.length);return new TextEncoder().encode(e.padEnd(32,"0"))},d=async()=>{let n=l(),r=g.generate(n),c=await E.generate({extractable:!1}),p=t??6048e5,f=await w.create(r,c.getPublicKey(),new Date(Date.now()+p));return{identity:v.fromDelegation(c,f),sessionKey:c,delegationChain:f}},u=async()=>{await h(e,n=>{let r=Date.now();return{createdAt:n?.createdAt??r,updatedAt:r}},I)},D=await d();return await u(),D};export{i as UnsafeDevIdentityInvalidIdentifierError,o as UnsafeDevIdentityNotBrowserError,s as UnsafeDevIdentityNotLocalhostError,R as clearDevIdentifiers,K as generateUnsafeDevIdentity,S as loadDevIdentifiers};
|
|
2
|
+
//# sourceMappingURL=dev.js.map
|
package/dev.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/dev/errors.ts", "src/dev/identity.ts"],
|
|
4
|
+
"sourcesContent": ["export class UnsafeDevIdentityNotBrowserError extends Error {\n constructor() {\n super('A dev identity can only be used in browser environments');\n }\n}\n\nexport class UnsafeDevIdentityNotLocalhostError extends Error {\n constructor() {\n super('A dev identity must only be used on localhost (127.0.0.1 or localhost)');\n }\n}\n\nexport class UnsafeDevIdentityInvalidIdentifierError extends Error {\n constructor(length: number) {\n super(`Identifier must be 32 characters or less, got ${length}`);\n }\n}\n", "import {\n DelegationChain,\n DelegationIdentity,\n ECDSAKeyIdentity,\n Ed25519KeyIdentity\n} from '@icp-sdk/core/identity';\nimport {clear, createStore, entries, update} from 'idb-keyval';\nimport {DEFAULT_DEV_DELEGATION_IDENTITY_EXPIRATION_IN_MS} from './_constants';\nimport {\n UnsafeDevIdentityInvalidIdentifierError,\n UnsafeDevIdentityNotBrowserError,\n UnsafeDevIdentityNotLocalhostError\n} from './errors';\nimport type {\n DevIdentifier,\n DevIdentifierData,\n GenerateUnsafeIdentityParams,\n GenerateUnsafeIdentityResult,\n LoadDevIdentifiersParams\n} from './types/identity';\n\nconst identifiersIdbStore = createStore('juno-dev-identifiers', 'juno-dev-identifiers-store');\n\n/**\n * Load all development identifiers that have been used for authentication.\n *\n * Returns an array of tuples containing the identifier string and metadata (created/updated timestamps),\n * sorted by most recently used first.\n *\n * @param params - Load parameters\n * @param params.limit - Optional maximum number of identifiers to return\n * @returns Promise resolving to array of [identifier, metadata] tuples sorted by updatedAt descending\n *\n * @example\n * const recent = await loadDevIdentifiers({ limit: 5 });\n * // Returns only the 5 most recently used identifiers\n */\nexport const loadDevIdentifiers = async ({limit}: LoadDevIdentifiersParams = {}): Promise<\n [DevIdentifier, DevIdentifierData][]\n> => {\n const identifiers = await entries<DevIdentifier, DevIdentifierData>(identifiersIdbStore);\n\n return identifiers.sort(([_, {updatedAt: a}], [__, {updatedAt: b}]) => b - a).slice(0, limit);\n};\n\n/**\n * Clear all stored development identifiers from IndexedDB.\n * This removes the history of used identifiers but does not affect AuthClient's stored credentials.\n *\n * @returns Promise that resolves when identifiers are cleared\n */\nexport const clearDevIdentifiers = () => clear(identifiersIdbStore);\n\n/**\n * Generate an identity for local development with the Internet Computer.\n *\n * \u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\n * \u26A0\uFE0F UNSAFE - FOR LOCAL DEVELOPMENT ONLY \u26A0\uFE0F\n * \u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\n *\n * Returns the identity, session key, and delegation chain.\n * Consumers must handle storage (e.g. for AuthClient compatibility).\n *\n * @param params - Generation parameters\n * @param params.identifier - Unique identifier string for this dev identity (default: \"dev\")\n * @param params.maxTimeToLiveInMilliseconds - Delegation expiration time in ms (default: 7 days)\n *\n * @returns Promise resolving to object containing identity, sessionKey, and delegationChain\n *\n * @throws {UnsafeDevIdentityNotBrowserError} If called outside browser environment\n * @throws {UnsafeDevIdentityNotLocalhostError} If called outside localhost\n **/\nexport const generateUnsafeDevIdentity = async ({\n identifier = 'dev',\n maxTimeToLiveInMilliseconds\n}: GenerateUnsafeIdentityParams = {}): Promise<GenerateUnsafeIdentityResult> => {\n const isBrowser = (): boolean => typeof window !== `undefined`;\n\n if (!isBrowser()) {\n throw new UnsafeDevIdentityNotBrowserError();\n }\n\n const {\n location: {hostname}\n } = window;\n\n if (!['127.0.0.1', 'localhost'].includes(hostname)) {\n throw new UnsafeDevIdentityNotLocalhostError();\n }\n\n const generateSeed = (): Uint8Array => {\n if (identifier.length > 32) {\n throw new UnsafeDevIdentityInvalidIdentifierError(identifier.length);\n }\n\n const encoder = new TextEncoder();\n return encoder.encode(identifier.padEnd(32, '0'));\n };\n\n const generate = async (): Promise<GenerateUnsafeIdentityResult> => {\n const seedBytes = generateSeed();\n\n const rootIdentity = Ed25519KeyIdentity.generate(seedBytes);\n const sessionKey = await ECDSAKeyIdentity.generate({\n extractable: false\n });\n\n const sessionLengthInMilliseconds =\n maxTimeToLiveInMilliseconds ?? DEFAULT_DEV_DELEGATION_IDENTITY_EXPIRATION_IN_MS;\n\n const chain = await DelegationChain.create(\n rootIdentity,\n sessionKey.getPublicKey(),\n new Date(Date.now() + sessionLengthInMilliseconds)\n );\n\n const delegatedIdentity = DelegationIdentity.fromDelegation(sessionKey, chain);\n\n return {\n identity: delegatedIdentity,\n sessionKey,\n delegationChain: chain\n };\n };\n\n const saveIdentifierUsage = async () => {\n await update(\n identifier,\n (value) => {\n const now = Date.now();\n\n return {\n createdAt: value?.createdAt ?? now,\n updatedAt: now\n };\n },\n identifiersIdbStore\n );\n };\n\n const result = await generate();\n\n await saveIdentifierUsage();\n\n return result;\n};\n"],
|
|
5
|
+
"mappings": "AAAO,IAAMA,EAAN,cAA+C,KAAM,CAC1D,aAAc,CACZ,MAAM,yDAAyD,CACjE,CACF,EAEaC,EAAN,cAAiD,KAAM,CAC5D,aAAc,CACZ,MAAM,wEAAwE,CAChF,CACF,EAEaC,EAAN,cAAsD,KAAM,CACjE,YAAYC,EAAgB,CAC1B,MAAM,iDAAiDA,CAAM,EAAE,CACjE,CACF,EChBA,OACE,mBAAAC,EACA,sBAAAC,EACA,oBAAAC,EACA,sBAAAC,MACK,yBACP,OAAQ,SAAAC,EAAO,eAAAC,EAAa,WAAAC,EAAS,UAAAC,MAAa,aAelD,IAAMC,EAAsBC,EAAY,uBAAwB,4BAA4B,EAgB/EC,EAAqB,MAAO,CAAC,MAAAC,CAAK,EAA8B,CAAC,KAGxD,MAAMC,EAA0CJ,CAAmB,GAEpE,KAAK,CAAC,CAACK,EAAG,CAAC,UAAW,CAAC,CAAC,EAAG,CAACC,EAAI,CAAC,UAAWC,CAAC,CAAC,IAAMA,EAAI,CAAC,EAAE,MAAM,EAAGJ,CAAK,EASjFK,EAAsB,IAAMC,EAAMT,CAAmB,EAqBrDU,EAA4B,MAAO,CAC9C,WAAAC,EAAa,MACb,4BAAAC,CACF,EAAkC,CAAC,IAA6C,CAG9E,GAAI,EAF6B,OAAO,OAAW,KAGjD,MAAM,IAAIC,EAGZ,GAAM,CACJ,SAAU,CAAC,SAAAC,CAAQ,CACrB,EAAI,OAEJ,GAAI,CAAC,CAAC,YAAa,WAAW,EAAE,SAASA,CAAQ,EAC/C,MAAM,IAAIC,EAGZ,IAAMC,EAAe,IAAkB,CACrC,GAAIL,EAAW,OAAS,GACtB,MAAM,IAAIM,EAAwCN,EAAW,MAAM,EAIrE,OADgB,IAAI,YAAY,EACjB,OAAOA,EAAW,OAAO,GAAI,GAAG,CAAC,CAClD,EAEMO,EAAW,SAAmD,CAClE,IAAMC,EAAYH,EAAa,EAEzBI,EAAeC,EAAmB,SAASF,CAAS,EACpDG,EAAa,MAAMC,EAAiB,SAAS,CACjD,YAAa,EACf,CAAC,EAEKC,EACJZ,GAA+B,OAE3Ba,EAAQ,MAAMC,EAAgB,OAClCN,EACAE,EAAW,aAAa,EACxB,IAAI,KAAK,KAAK,IAAI,EAAIE,CAA2B,CACnD,EAIA,MAAO,CACL,SAHwBG,EAAmB,eAAeL,EAAYG,CAAK,EAI3E,WAAAH,EACA,gBAAiBG,CACnB,CACF,EAEMG,EAAsB,SAAY,CACtC,MAAMC,EACJlB,EACCmB,GAAU,CACT,IAAMC,EAAM,KAAK,IAAI,EAErB,MAAO,CACL,UAAWD,GAAO,WAAaC,EAC/B,UAAWA,CACb,CACF,EACA/B,CACF,CACF,EAEMgC,EAAS,MAAMd,EAAS,EAE9B,aAAMU,EAAoB,EAEnBI,CACT",
|
|
6
|
+
"names": ["UnsafeDevIdentityNotBrowserError", "UnsafeDevIdentityNotLocalhostError", "UnsafeDevIdentityInvalidIdentifierError", "length", "DelegationChain", "DelegationIdentity", "ECDSAKeyIdentity", "Ed25519KeyIdentity", "clear", "createStore", "entries", "update", "identifiersIdbStore", "createStore", "loadDevIdentifiers", "limit", "entries", "_", "__", "b", "clearDevIdentifiers", "clear", "generateUnsafeDevIdentity", "identifier", "maxTimeToLiveInMilliseconds", "UnsafeDevIdentityNotBrowserError", "hostname", "UnsafeDevIdentityNotLocalhostError", "generateSeed", "UnsafeDevIdentityInvalidIdentifierError", "generate", "seedBytes", "rootIdentity", "Ed25519KeyIdentity", "sessionKey", "ECDSAKeyIdentity", "sessionLengthInMilliseconds", "chain", "DelegationChain", "DelegationIdentity", "saveIdentifierUsage", "update", "value", "now", "result"]
|
|
7
|
+
}
|
package/dev.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createRequire as topLevelCreateRequire } from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var o=class extends Error{constructor(){super("A dev identity can only be used in browser environments")}},s=class extends Error{constructor(){super("A dev identity must only be used on localhost (127.0.0.1 or localhost)")}},i=class extends Error{constructor(t){super(`Identifier must be 32 characters or less, got ${t}`)}};import{DelegationChain as w,DelegationIdentity as v,ECDSAKeyIdentity as E,Ed25519KeyIdentity as g}from"@icp-sdk/core/identity";import{clear as x,createStore as A,entries as _,update as h}from"idb-keyval";var I=A("juno-dev-identifiers","juno-dev-identifiers-store"),S=async({limit:e}={})=>(await _(I)).sort(([y,{updatedAt:a}],[l,{updatedAt:d}])=>d-a).slice(0,e),R=()=>x(I),K=async({identifier:e="dev",maxTimeToLiveInMilliseconds:t}={})=>{if(!(typeof window<"u"))throw new o;let{location:{hostname:a}}=window;if(!["127.0.0.1","localhost"].includes(a))throw new s;let l=()=>{if(e.length>32)throw new i(e.length);return new TextEncoder().encode(e.padEnd(32,"0"))},d=async()=>{let n=l(),r=g.generate(n),c=await E.generate({extractable:!1}),p=t??6048e5,f=await w.create(r,c.getPublicKey(),new Date(Date.now()+p));return{identity:v.fromDelegation(c,f),sessionKey:c,delegationChain:f}},u=async()=>{await h(e,n=>{let r=Date.now();return{createdAt:n?.createdAt??r,updatedAt:r}},I)},D=await d();return await u(),D};export{i as UnsafeDevIdentityInvalidIdentifierError,o as UnsafeDevIdentityNotBrowserError,s as UnsafeDevIdentityNotLocalhostError,R as clearDevIdentifiers,K as generateUnsafeDevIdentity,S as loadDevIdentifiers};
|
|
4
|
+
//# sourceMappingURL=dev.mjs.map
|
package/dev.mjs.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/dev/errors.ts", "src/dev/identity.ts"],
|
|
4
|
+
"sourcesContent": ["export class UnsafeDevIdentityNotBrowserError extends Error {\n constructor() {\n super('A dev identity can only be used in browser environments');\n }\n}\n\nexport class UnsafeDevIdentityNotLocalhostError extends Error {\n constructor() {\n super('A dev identity must only be used on localhost (127.0.0.1 or localhost)');\n }\n}\n\nexport class UnsafeDevIdentityInvalidIdentifierError extends Error {\n constructor(length: number) {\n super(`Identifier must be 32 characters or less, got ${length}`);\n }\n}\n", "import {\n DelegationChain,\n DelegationIdentity,\n ECDSAKeyIdentity,\n Ed25519KeyIdentity\n} from '@icp-sdk/core/identity';\nimport {clear, createStore, entries, update} from 'idb-keyval';\nimport {DEFAULT_DEV_DELEGATION_IDENTITY_EXPIRATION_IN_MS} from './_constants';\nimport {\n UnsafeDevIdentityInvalidIdentifierError,\n UnsafeDevIdentityNotBrowserError,\n UnsafeDevIdentityNotLocalhostError\n} from './errors';\nimport type {\n DevIdentifier,\n DevIdentifierData,\n GenerateUnsafeIdentityParams,\n GenerateUnsafeIdentityResult,\n LoadDevIdentifiersParams\n} from './types/identity';\n\nconst identifiersIdbStore = createStore('juno-dev-identifiers', 'juno-dev-identifiers-store');\n\n/**\n * Load all development identifiers that have been used for authentication.\n *\n * Returns an array of tuples containing the identifier string and metadata (created/updated timestamps),\n * sorted by most recently used first.\n *\n * @param params - Load parameters\n * @param params.limit - Optional maximum number of identifiers to return\n * @returns Promise resolving to array of [identifier, metadata] tuples sorted by updatedAt descending\n *\n * @example\n * const recent = await loadDevIdentifiers({ limit: 5 });\n * // Returns only the 5 most recently used identifiers\n */\nexport const loadDevIdentifiers = async ({limit}: LoadDevIdentifiersParams = {}): Promise<\n [DevIdentifier, DevIdentifierData][]\n> => {\n const identifiers = await entries<DevIdentifier, DevIdentifierData>(identifiersIdbStore);\n\n return identifiers.sort(([_, {updatedAt: a}], [__, {updatedAt: b}]) => b - a).slice(0, limit);\n};\n\n/**\n * Clear all stored development identifiers from IndexedDB.\n * This removes the history of used identifiers but does not affect AuthClient's stored credentials.\n *\n * @returns Promise that resolves when identifiers are cleared\n */\nexport const clearDevIdentifiers = () => clear(identifiersIdbStore);\n\n/**\n * Generate an identity for local development with the Internet Computer.\n *\n * \u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\n * \u26A0\uFE0F UNSAFE - FOR LOCAL DEVELOPMENT ONLY \u26A0\uFE0F\n * \u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\n *\n * Returns the identity, session key, and delegation chain.\n * Consumers must handle storage (e.g. for AuthClient compatibility).\n *\n * @param params - Generation parameters\n * @param params.identifier - Unique identifier string for this dev identity (default: \"dev\")\n * @param params.maxTimeToLiveInMilliseconds - Delegation expiration time in ms (default: 7 days)\n *\n * @returns Promise resolving to object containing identity, sessionKey, and delegationChain\n *\n * @throws {UnsafeDevIdentityNotBrowserError} If called outside browser environment\n * @throws {UnsafeDevIdentityNotLocalhostError} If called outside localhost\n **/\nexport const generateUnsafeDevIdentity = async ({\n identifier = 'dev',\n maxTimeToLiveInMilliseconds\n}: GenerateUnsafeIdentityParams = {}): Promise<GenerateUnsafeIdentityResult> => {\n const isBrowser = (): boolean => typeof window !== `undefined`;\n\n if (!isBrowser()) {\n throw new UnsafeDevIdentityNotBrowserError();\n }\n\n const {\n location: {hostname}\n } = window;\n\n if (!['127.0.0.1', 'localhost'].includes(hostname)) {\n throw new UnsafeDevIdentityNotLocalhostError();\n }\n\n const generateSeed = (): Uint8Array => {\n if (identifier.length > 32) {\n throw new UnsafeDevIdentityInvalidIdentifierError(identifier.length);\n }\n\n const encoder = new TextEncoder();\n return encoder.encode(identifier.padEnd(32, '0'));\n };\n\n const generate = async (): Promise<GenerateUnsafeIdentityResult> => {\n const seedBytes = generateSeed();\n\n const rootIdentity = Ed25519KeyIdentity.generate(seedBytes);\n const sessionKey = await ECDSAKeyIdentity.generate({\n extractable: false\n });\n\n const sessionLengthInMilliseconds =\n maxTimeToLiveInMilliseconds ?? DEFAULT_DEV_DELEGATION_IDENTITY_EXPIRATION_IN_MS;\n\n const chain = await DelegationChain.create(\n rootIdentity,\n sessionKey.getPublicKey(),\n new Date(Date.now() + sessionLengthInMilliseconds)\n );\n\n const delegatedIdentity = DelegationIdentity.fromDelegation(sessionKey, chain);\n\n return {\n identity: delegatedIdentity,\n sessionKey,\n delegationChain: chain\n };\n };\n\n const saveIdentifierUsage = async () => {\n await update(\n identifier,\n (value) => {\n const now = Date.now();\n\n return {\n createdAt: value?.createdAt ?? now,\n updatedAt: now\n };\n },\n identifiersIdbStore\n );\n };\n\n const result = await generate();\n\n await saveIdentifierUsage();\n\n return result;\n};\n"],
|
|
5
|
+
"mappings": ";;AAAO,IAAMA,EAAN,cAA+C,KAAM,CAC1D,aAAc,CACZ,MAAM,yDAAyD,CACjE,CACF,EAEaC,EAAN,cAAiD,KAAM,CAC5D,aAAc,CACZ,MAAM,wEAAwE,CAChF,CACF,EAEaC,EAAN,cAAsD,KAAM,CACjE,YAAYC,EAAgB,CAC1B,MAAM,iDAAiDA,CAAM,EAAE,CACjE,CACF,EChBA,OACE,mBAAAC,EACA,sBAAAC,EACA,oBAAAC,EACA,sBAAAC,MACK,yBACP,OAAQ,SAAAC,EAAO,eAAAC,EAAa,WAAAC,EAAS,UAAAC,MAAa,aAelD,IAAMC,EAAsBC,EAAY,uBAAwB,4BAA4B,EAgB/EC,EAAqB,MAAO,CAAC,MAAAC,CAAK,EAA8B,CAAC,KAGxD,MAAMC,EAA0CJ,CAAmB,GAEpE,KAAK,CAAC,CAACK,EAAG,CAAC,UAAW,CAAC,CAAC,EAAG,CAACC,EAAI,CAAC,UAAWC,CAAC,CAAC,IAAMA,EAAI,CAAC,EAAE,MAAM,EAAGJ,CAAK,EASjFK,EAAsB,IAAMC,EAAMT,CAAmB,EAqBrDU,EAA4B,MAAO,CAC9C,WAAAC,EAAa,MACb,4BAAAC,CACF,EAAkC,CAAC,IAA6C,CAG9E,GAAI,EAF6B,OAAO,OAAW,KAGjD,MAAM,IAAIC,EAGZ,GAAM,CACJ,SAAU,CAAC,SAAAC,CAAQ,CACrB,EAAI,OAEJ,GAAI,CAAC,CAAC,YAAa,WAAW,EAAE,SAASA,CAAQ,EAC/C,MAAM,IAAIC,EAGZ,IAAMC,EAAe,IAAkB,CACrC,GAAIL,EAAW,OAAS,GACtB,MAAM,IAAIM,EAAwCN,EAAW,MAAM,EAIrE,OADgB,IAAI,YAAY,EACjB,OAAOA,EAAW,OAAO,GAAI,GAAG,CAAC,CAClD,EAEMO,EAAW,SAAmD,CAClE,IAAMC,EAAYH,EAAa,EAEzBI,EAAeC,EAAmB,SAASF,CAAS,EACpDG,EAAa,MAAMC,EAAiB,SAAS,CACjD,YAAa,EACf,CAAC,EAEKC,EACJZ,GAA+B,OAE3Ba,EAAQ,MAAMC,EAAgB,OAClCN,EACAE,EAAW,aAAa,EACxB,IAAI,KAAK,KAAK,IAAI,EAAIE,CAA2B,CACnD,EAIA,MAAO,CACL,SAHwBG,EAAmB,eAAeL,EAAYG,CAAK,EAI3E,WAAAH,EACA,gBAAiBG,CACnB,CACF,EAEMG,EAAsB,SAAY,CACtC,MAAMC,EACJlB,EACCmB,GAAU,CACT,IAAMC,EAAM,KAAK,IAAI,EAErB,MAAO,CACL,UAAWD,GAAO,WAAaC,EAC/B,UAAWA,CACb,CACF,EACA/B,CACF,CACF,EAEMgC,EAAS,MAAMd,EAAS,EAE9B,aAAMU,EAAoB,EAEnBI,CACT",
|
|
6
|
+
"names": ["UnsafeDevIdentityNotBrowserError", "UnsafeDevIdentityNotLocalhostError", "UnsafeDevIdentityInvalidIdentifierError", "length", "DelegationChain", "DelegationIdentity", "ECDSAKeyIdentity", "Ed25519KeyIdentity", "clear", "createStore", "entries", "update", "identifiersIdbStore", "createStore", "loadDevIdentifiers", "limit", "entries", "_", "__", "b", "clearDevIdentifiers", "clear", "generateUnsafeDevIdentity", "identifier", "maxTimeToLiveInMilliseconds", "UnsafeDevIdentityNotBrowserError", "hostname", "UnsafeDevIdentityNotLocalhostError", "generateSeed", "UnsafeDevIdentityInvalidIdentifierError", "generate", "seedBytes", "rootIdentity", "Ed25519KeyIdentity", "sessionKey", "ECDSAKeyIdentity", "sessionLengthInMilliseconds", "chain", "DelegationChain", "DelegationIdentity", "saveIdentifierUsage", "update", "value", "now", "result"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junobuild/ic-client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "Agent and actor with generated bindings for Juno on the Internet Computer",
|
|
5
5
|
"author": "David Dal Busco (https://daviddalbusco.com)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
"types": "./utils.d.ts",
|
|
29
29
|
"import": "./utils.js",
|
|
30
30
|
"require": "./utils.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./dev": {
|
|
33
|
+
"types": "./dev.d.ts",
|
|
34
|
+
"import": "./dev.js",
|
|
35
|
+
"require": "./dev.mjs"
|
|
31
36
|
}
|
|
32
37
|
},
|
|
33
38
|
"files": [
|
|
@@ -73,6 +78,7 @@
|
|
|
73
78
|
"homepage": "https://juno.build",
|
|
74
79
|
"peerDependencies": {
|
|
75
80
|
"@dfinity/utils": "^4.1",
|
|
76
|
-
"@icp-sdk/core": "^5"
|
|
81
|
+
"@icp-sdk/core": "^5",
|
|
82
|
+
"idb-keyval": "^6.2.2"
|
|
77
83
|
}
|
|
78
84
|
}
|