@NathanosDev, how can I use PIC js to authenticate myself and transfer ICP from my account to another account?
I do a bunch of that here: icrc79.mo/pic/subs/subs.test.ts at main · PanIndustrial-Org/icrc79.mo · GitHub
See Award Tokens. If you want to use your actual plug wallet or some other kind of wallet you’ll need to pull out the PEM file and use it to initialize the identity.
I’m not sure the best way to do that with something like an II wallet.
It would be interesting to have a simple way to do a delegated identity in Pic.
In this ts file I see you create a “identity” object using a public and a private key both in base64 format. Then you call “actor.setidentity(identity)”, so you can perform authenticated update calls. I also extracted PEM file from the plug wallet but I cannot locate the keys. How can I get the public and private keys (in base64) from PEM file?
I don’t have the instructions right here with me, but if you search around I’m almost certain there is a way to do this(maybe quill?).
But I’ll also ask why you might need to do that with pocket ic? If it is for testing it is easier to just generate random ones and fund them like the alice and bob examples in the file. Or if you’re needing to fund one you can just send it tokens from the ICP ledger…that minterPublicKey is the one that the dfx nns install sets up and gives all the ICP to, so your test can just send your wallet a bunch of ICP as part of the test set up.
I would want to use my plug wallet first to call a test canister and later use the same code with the real canister. Do you know where I could find more info on how to extract the pub/pri keys from the pem file?
@rbole has a great article: Internet Computer Identity — a Journey of Discovery | by Bole Roland | Medium
I’m a bit confused about the use case here. In general the canister doesn’t know that it’s a Plug Wallet right? It only sees the principal that signed the transaction (although I haven’t worked with Plug Wallet so please correct me if I’m wrong).
But assuming that’s the case, in your test you don’t need to use a public/private key pair generated specifically by Plug, you can just use any randomly generated identifier and from your canister’s perspective it should be the same.
Am I missing something?
Thank you, I need some reading
I try to explain better below:
In @skilesare code, they use the following js snipped to create an Ed25519KeyIdentity
object:
const minterPublicKey = 'Uu8wv55BKmk9ZErr6OIt5XR1kpEGXcOSOC1OYzrAwuk=';
const minterPrivateKey =
'N3HB8Hh2PrWqhWH2Qqgr1vbU9T3gb1zgdBD8ZOdlQnVS7zC/nkEqaT1kSuvo4i3ldHWSkQZdw5I4LU5jOsDC6Q==';
const minterIdentity = Ed25519KeyIdentity.fromKeyPair(
base64ToUInt8Array(minterPublicKey),
base64ToUInt8Array(minterPrivateKey),
);
Then, they use this object to make calls to the NNS that require to authenticate. For instance::
await awardTokens(nnsledger, minterIdentity, nu...
In my case, I want to do something similar to interact with the real NNS and ICPSwap using my plug wallet, so I need a way to extract my public and private keys from my PEM file.
Question is how can I extract my public and private keys from my PEM file?
Maybe should I use agent-js for that?
Im case of JS you don’t need to extract a public and private key, you can just use the following package and code for a pem file:
import { Secp256k1KeyIdentity } from '@dfinity/identity-secp256k1';
const identity = Secp256k1KeyIdentity.fromPem(pemFileContentString);
Plug uses Secp256k1 as key algoritm since a while back.