index.js
 1  import { Actor, HttpAgent } from "@dfinity/agent";
 2  
 3  // Imports and re-exports candid interface
 4  import { idlFactory } from "./internet-identity.did.js";
 5  export { idlFactory } from "./internet-identity.did.js";
 6  
 7  /* CANISTER_ID is replaced by webpack based on node environment
 8   * Note: canister environment variable will be standardized as
 9   * process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
10   * beginning in dfx 0.15.0
11   */
12  export const canisterId =
13    process.env.CANISTER_ID_INTERNET-IDENTITY ||
14    process.env.INTERNET-IDENTITY_CANISTER_ID;
15  
16  export const createActor = (canisterId, options = {}) => {
17    const agent = options.agent || new HttpAgent({ ...options.agentOptions });
18  
19    if (options.agent && options.agentOptions) {
20      console.warn(
21        "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent."
22      );
23    }
24  
25    // Fetch root key for certificate validation during development
26    if (process.env.DFX_NETWORK !== "ic") {
27      agent.fetchRootKey().catch((err) => {
28        console.warn(
29          "Unable to fetch root key. Check to ensure that your local replica is running"
30        );
31        console.error(err);
32      });
33    }
34  
35    // Creates an actor with using the candid interface and the HttpAgent
36    return Actor.createActor(idlFactory, {
37      agent,
38      canisterId,
39      ...options.actorOptions,
40    });
41  };
42  
43  export const internet-identity = createActor(canisterId);