Open amgando opened 3 years ago
Hi, I'm going to walk you through the near log-in command. So just to get an idea here running on a macro S with node version 1219 it's Thursday, May 20th, and I am using NPM to manage my node environment.
So that's where near as installed and I'm running near version two. So when I take near login what you're going to see is some texts to appear on the screen.
And then my browser is gonna pop up in a new window. And on the bottom of the screen here, I'm refreshing every one second.
My home account there's this hidden folder here called near credentials with the default folder in there that represents the Testnet on the new year network.
And so what I'm looking at here is the list of private keys that I have four accounts that I control, and these are full access keys on your protocol.
And so that's what we're about to do here from the console. We're about to log in with near CLI. This is different from logging into a website like Paras, for example, if you're going to go there and log in and log in with near this is using a browser log in and it's actually using local storage in your browser.
So this is different from what we're doing here, which is logging in with near CLI and storing our private keys in the file system.
So just be aware of of that when we're doing this. And then on the left-hand side here, let's start Google and let's start with you.
And that's where we'll do our search for near cl. So okay. So let's go ahead and do it over here on the right hand side near login we'll just type that you see immediately the browser opens up to this URL and it's telling us basically if the browser doesn't open up automatically, you can just open up this link.
And what we can see in this link is that we're going to whatever the network is that we're working on in this case is Testnet by default, we can change an environment variable to make it mean that and then this logging URL, there's a bit of some URL query string variables here including this public key and a a redirect URL on success.
That's our local hosts. So there's, there's actually a local server running, waiting to catch this redirect in just a few seconds.
And so there's nothing we need to do over here. Just giving you a sense of what's going on in the console on the left-hand side.
This unknown app will appear whenever you're asking for a full access to the, and basically you take any one of your accounts in here.
So I have an avid account called this is Testnet and this is a Testnet. So does it really matter? I'll pick, this is Testnet keep your eye down here where you'll see this refresh as soon as I'm done.
So I'm just going to click allow here. I'm going to be asked to confirm this is Testnet and as soon as this happens, the right-hand side, it's going to change both top and bottom.
So looks like the bottom didn't refresh and it's possible this actually showed up in here in Testnet. So my bad for watching the wrong location.
Let's run this again and see how this this works up here. Let's start with near login. We get this to authorize.
This is that's that. And then again, on the top right-hand side, we see a confirmation of the login. This is test net with public key has been added.
We get this page showing us we can close the window. This is actually the local host server. That's running just for the purpose of catching this redirect, and then down here.
Oh gosh we use the same account. So this didn't refresh. Let's try it one more time. That's near log in here.
And then let's remove this, that should go away. I can see it appear log in. All right. So third time's a charm near login pops up in the window.
This is Testnet pick that, confirm it here. This is that's not. And then we'll see the top half confirm and the bottom, right?
We'll see this key up here as a new entry in our credentials folder before it was just replacing, but it wasn't flashing.
So anyway what has happened here, let's actually take a look at this key and see what we can do with it.
So, first of all, I can search for this is Tufts net to see the state of this account. And I can look for the keys on this account and I'll see here, three full access keys, and here's another full access key.
And so, so these jeez, so these these keys here that have been added and this full access key and this full access key, and then these three down here they all have a matching public key.
So we can actually check to see if you know, which, which one this is right here. So let's cancel best we can.
And of course, I need to delete this private key now that it's visible on the video, but here, I'm just going to match this DV C P, which one of these sorts of DPCP it's this one, in fact these are, these are two matches here, but just kind of searching the terminal.
You'll see. So this is the key that I've added and it's a full access key, and here's the private key that's associated with it.
And it's being kept in mind, your credentials folder under either default or Testnet. And so in that in that sense I've got full control of this account and I can basically do anything else I want with this, including delete all of these other keys or delete the entire account if I want to it's a full access key.
Now I've logged in and I don't need to do this more than once with your login because this key is kept here.
As long as this key file that's here in my local folder, isn't deleted. And as long as the key remains attached to the account, I will continue to have full access.
And to this account, be able to sign messages as if I am the owner or that I control this account.
So it's really just a one-time thing. And then your keys are there, if you delete the account or this key is removed from the account, or you delete this file, for some reason, you don't need to log in again and you need to do this for every single account that you want to control on every single network.
So it's Testnet or main net. These are even if it's the same name, account, you'll have to log in again cause it's different now.
So hopefully that makes near logging clear from a usage perspective, let's take a look at the command a little bit closer.
So just starting here with Google, near taillight login right into the documentation we can see in your log in, I've actually got this page open already right here.
There are no arguments. The the command basically does what you saw it do here, where it opens up this screen on your wallet and then asks you to go in and confirm this once completed, you have your access to these stored locally in this folder.
And depending on the operating system, you know, macro Linux, it'll be in your root folder in a windows, it will be in this other folder.
And then the the folders that you saw us working with default, and Testnet there's also been a net main net, so on.
And then these are Jason objects that have these three values, and then here's the same example on the right-hand side.
And so that's basically the near login command from, from a user's perspective. Let's dig in a little bit deeper to these accounts.
So there are two kinds of keys, full access, keys, and call access and full access keys, give you access to the eight primitive actions, the eight primitive things that you can do with near like creating new sub accounts on this account, deleting this account entirely adding a key or deleting keys from this account, maybe deploying a contract, his account, calling the function on it as a contract deployed, transferring tokens from this account somewhere else in staking tokens that this account controls.
So you can do all of these things with a full access, key function, call access keys. On the other hand, they look like this in terms of the the JSON representation of them.
When you call near keys
on an account, this is what a FunctionalCall
access key looks like. It was a telltale sign right there.
Plus it's a bigger object compared with function. The full access keys are, are much smaller, public key knots and permission.
So function clocks is keys, have a few more details in them. And and so these have some other some other restrictions here in terms of in terms of what you can do with it.
So so that's just a little bit more about keys. And then in terms of the functionality of this command, let's take a look at near CLI.
So your a is the command in your stale line? Very simple just the command, a little bit of help. And you can optionally specify a different wallet URL but but this log-in functions is where the real work happens.
It's a pretty, pretty big command here. But we can just take a look at the code and see that we do some optional event tracking if you're interested in opting into that.
If you provide the wallet URL then you'll get this you'll get this kind of note here. So, you know apparently that's that's something that's surprising for me.
We set up a new URL the title of the window, some search brands generate a new key pair and then set the public key pair of the URLs query string to the public key.
And recall you saw that when we were actually looking at the printout and then this you know bold yellow messages, this printed out at the URL.
And then depending on whether or not we're using windows, we do something a little bit differently here. And assuming that we were able to kind of you know, capture that's this callback that's that's the local server that we're starting then then we go ahead and and set this up where where we try and get this success URL redirected, you know, depending on whether or not we're in a get pod, a workspace and whether or not we're in windows, we'll use a slightly different command to handle that.
And then this is the warning, you know, if the browser doesn't automatically open, please visit the URL. Here we have that's function that helps us you know, get the account from from the page.
And and then we create this interface to capture standard in and standard out so that we can capture some of the the messages that we get in response here.
And and at this point we grabbed the account from the console writing out you know, whatever it is that we've that we found.
So this, this function here we'll we'll actually capture some of the results and print that out. And then we we just close this out.
So, so this section here is really all about managing the redirect, capturing the value from that redirect and printing out the appropriate message to be able to compensate for you know, how, how we want to read this, this data out.
And then a little bit of event tracking maybe at some error that gets printed here. But that that's about the end of it.
So that's the, the log-in flow. Most of it, as you can see is in this open URL asking you to log in.
And then once that once that comes back in the the, the account is the key is added and there, there is the place where this key pair gets added.
I'm curious about that. So whereas verify coming from, you know, it looks like it's a verify account in utils, let's take a look at that.
Okay. And here we can see we verify, and if the key is found, then we put it in storage. So this is the utility that will will actually end up writing the key to the local storage.
Assuming that it's found on the on the then we can be sure that the queue is properly added as part of the login process.
And and then and then we can do that logged in with public key. So this is that message that we see logged in as with public key and in that the short public feeds.
So these are the two sort of main files that are involved in this transaction this verify account utility. And then the the code that we saw just a minute ago when we were looking at the implementation of its function this one right here.
Right? So, so this is this is the place right here assuming that that we're done with this, we can try and verify the account, but it's actually been created that onto put that into the file system.
All right. Well, that's near login from usage to implementation.
Submission
I've created this video covering NEAR CLI
near login
command requested by #1Video
[ 16:04 ]
https://www.loom.com/share/054b4ef450a342b297e252a98c2bcda8Related Links
near login
is herenear login
is hereUnencryptedFileSystemKeyStore
is hereCommunity Votes ❤️ I love it! 🚀 I can help you!