Thanks to everyone above for the great commentary, really was nice to follow as I started troubleshooting not being able to load in my existing dfx principal via agent-js (I received the same different dfx and node principals as everyone else).
Since it did take me a bit of time to get through it all, hopefully these steps make it easier for those of you running into a similar issue (as of the time of this post).
Navigate to my .dfx identities → ~/.config/.dfx/identity
Create a new identity → mkdir local-testing; cd local-testing
Look up how to generate a key → quill generate --help
Generate a key and seed file → quill generate --pem-file identity.pem --seed-file seed.txt
Now implement Kyle’s code snippet below (copied from comment this post is replying to)
If you run this an have NodeJS version 17+, you will receive the following error coming from the hdkey library import → Error: error:0308010C:digital envelope routines::unsupported. The possible solutions for getting around this are here, the easiest of which is downgrading to node 16. (@kpeacock/sdk team can you provide a node 17+ solution? )
Now running the above node script and dfx identity get-principal should return the same identity! Yay!
So there’s no way to just pass in a path to a PEM file and get an identity that can be used in @dfinity/agent? It used to be the case that I could just pass in JSON object and all of this worked, that was last Summer. What happened?
For all those who are interested on this thread, I have created a dfinity module in BlueprintJS called blueprint-dfinity. The goal of this module is to make it easier to write NodeJS clients for the Internet Computer.
Some of the key features of this BlueprintJS module are:
Declarative approach for defining actors
Ability to bind actors and their source canisters to properties
Codifies bootstrapping code
The current version of trunk uses the original property definition approach to defining actors, and binding them to object properties. The newest version of the blueprint-dfinity, which is to be released with v5, uses decorators to define the actors and bindings to properties on ES6 classes.
For example, if I go back to DFX < 0.12.0, generate an identity with dfx identity new <alias>, this solution will work, but if one uses any newer versions of dfx that uses different key generation, it will break.
@AdamS@kpeacock Are there any node based solutions in agent-js or elsewhere for pulling in the new Secp256k1 identities from a dfx >=0.12.0 generated pem file?
Also I tried playing with the blueprint solution provided by the post directly above this one , but upon testing it with identities generated by dfx >= 0.12.0 I’ve found @hilljh82’s solution now produces a different identity (maybe it worked previously but there were a few changes made?).
Is there an issue with the Ed25519 and/or Secp256k1 solutions provided by ZenVoich?
Several developers I’ve spoken with prefer for the solution that imports the dfx generated pem file instead of the quill generated seed.txt (which they’ve professed the seed.txt derived identity import feels like a “hacky”, “roundabout”, or “unstable” solution).
It’s also about consistency, mostly because then developers are using two different tools to manage identity/canisters.
there’s nothing wrong with using the PEM files - we just haven’t added official support or documentation for it yet.
instead of the quill generated seed.txt (which they’ve professed the seed.txt derived identity import feels like a “hacky”, “roundabout”, or “unstable” solution).
Quill is unnecessary, unless you’re trying to use an existing PEM file in a seed phrase context. I simply suggest using a freshly generated seed phrase from your tool of choice, which will work nicely in CI contexts
@peterparker do you mean how to decrypt the dfx-encrypted PEM? You can see the process here. You will also need the nonce from your identity’s config, which is located at .config/dfx/identity/<identity name>/identity.json