baking-bad / netezos

Netezos is a cross-platform Tezos SDK for .NET developers, simplifying the access and interaction with the Tezos blockchain
https://netezos.dev
MIT License
40 stars 21 forks source link

Can i do authentication related thing for temple account using netezos sdk? #49

Closed KamranShahid closed 2 years ago

KamranShahid commented 2 years ago

my scenario is like i will provide the word from secret phrase and in return i will got password. or things like password is correct for account e.t.c. https://tezos.stackexchange.com/questions/29/what-are-my-remedies-if-i-forgot-the-password-i-created-during-the-fundraiser

KamranShahid commented 2 years ago

Following are possible kind command/operations i have extracted from the code

"activate_account" "ballot" "delegation" "double_baking_evidence" "double_endorsement_evidence" "double_preendorsement_evidence" "endorsement" "origination" "preendorsement" "proposals" "register_global_constant" "reveal" "seed_nonce_revelation" "set_deposits_limit" "transaction"

Don't know if any one of above is usable for my scenario

@Groxan it could be great if you can give your expert opinion in this as well

Groxan commented 2 years ago

Sorry, I didn't get what exactly you want to achieve. What authentication do you mean? If you want to check the password correctness, you need to restore the account and check its balance. If the balance != 0, then the password is likely correct. Also, I don't think it's possible to get a password from a given word from mnemonic.

KamranShahid commented 2 years ago

Suppose an account have forgot his password. so i am thinking of writing some .net code to restore it. Or if he remember i wanted to confirm his password. is it possible via netezos

Groxan commented 2 years ago

Got it. Yes, you can use var key = Key.FromMnemonic(...) to restore the account from mnemonic+password or from mnemonic+email+password in case of fundrizer accounts. So, if key.Address is correct, then the password is correct.

KamranShahid commented 2 years ago

Can you share any example please. just like to do first if the given things is correct. also i was thinking of providing specific phrase like if wallet at time of creation is provided 10 words. i wanted to input email, 9th word to retrieve the password. or i wanted to give email, account address, password to verify if the wallet details are correct

Groxan commented 2 years ago

i wanted to input email, 9th word to retrieve the password

It's not possible to retrieve a password from seed phrase and email.

i wanted to give email, account address, password to verify if the wallet details are correct

That's not possible without seed phrase.

KamranShahid commented 2 years ago

ok. you mean't all seed phrase words needed to be provided :( Can you share any example. i have tried with var key = Key.FromMnemonic(new Mnemonic (new List<string> { "xfdfd", "dfdf", "dfdf",...})); but don't know where too password email or account address for verification after above line

Groxan commented 2 years ago

Even if you have full seed phrase, you can't retreive the password from it, except for brute-forcing. It's math :)

var expectedAddress = "tz1...";

var email = "...";
var mnemonic = new("...");
var password = "...";

var key = Key.FromMnemonic(mnemonic, email, password);

if (key.Address == expectedAddress)
    return true;
KamranShahid commented 2 years ago

Thanks Groxan. will try this

KamranShahid commented 2 years ago

I have tried but don't know why getting different address. any other thing i have to take care

var expectedAddress = "tz1NpRgSe3RUWjJD1mYhHbzVNxhPaqK6XemJ";
var email = "myemail@gmail.com";
Mnemonic mnemonic = new Mnemonic(new List<string> { "****", ""****",", ""****",", ""****",", ""****",", ""****",", ""****",", ""****",", ""****",", ""****",", ""****",", ""****"," }) ;
var password = "mypassword";
var key = Key.FromMnemonic(mnemonic, email, password);

if (key.Address == expectedAddress)
{

}
else
{

} 
KamranShahid commented 2 years ago

I have created a new wallet in firefox extension. i didn't find any place for email. Is email a mandatory or optional? With new account even if i am sending email as empty or with var key = Key.FromMnemonic(mnemonic, password); i am still not able to get matched address

Groxan commented 2 years ago

I have tried but don't know why getting different address.

That means that you use wrong password, seed, or email.

i am still not able to get matched address

Can you show an example?

KamranShahid commented 2 years ago
var expectedAddress = "tz1ZLGJkLMdEDmfR5wCgTCRDUhBFujFDMN1b";
            Mnemonic mnemonic = new Mnemonic("aaaa bbbbb cdcdfd dfdf dfdf dfdf dfd dfd dfdf dfdfdf dfdfdf jealous");
            var password = "********";         
            var key = Key.FromMnemonic(mnemonic,  password);
            if (key.Address == expectedAddress)
            {

            }
            else
            {

            } 

you can try it with your own wallet password, phrase and address as well. I have not found email option when creating wallet. same behavior when tried another wallet creation in firefox extension

KamranShahid commented 2 years ago

or should i share full real phrase, password and address?

Groxan commented 2 years ago

Yes, I meant the original mnemonic and password, but not from a real account, but a test one, in order to reproduce your issue. Never mind. I think you just confuse simple keys with HD keys (which are usually used by wallets). Try to use HDKey.FromMnemonic(), then derive the key with the same path as in your wallet, and then compare the address.

KamranShahid commented 2 years ago

var expectedAddress = "tz1ZLGJkLMdEDmfR5wCgTCRDUhBFujFDMN1b";
Mnemonic mnemonic = new Mnemonic("funny before illness obvious mail shoe honey cycle sponsor hill mirror jealous"); var password = "Kamran13"; var key = HDKey.FromMnemonic(mnemonic, password);

        if (key.Address == expectedAddress)
        {

        }
        else
        {

        }

Please use above one. this is the second wallet i have created in firefox extension

Groxan commented 2 years ago

I tried to import your mnemonic and passphrase into Kukai wallet and got different address as well (by the way, the address in Kukai was the same as returned by Netezos). So, I recommend you asking the one, who created the extension you use, because it seems generating addresses at some uncommon HD path, or else.

I'm closing this issue, because the original question was already answered. Feel free to join our Discord, which is a better place for random discussions.

KamranShahid commented 2 years ago

Thanks Groxan. I have by the way created the wallet using Temple in chrome and firefox extension. will check how wallet is created in Kukai as well for my own learning

Groxan commented 2 years ago

FYI: Temple doesn't use password for seed generation, just mnemonic.

KamranShahid commented 2 years ago

Oops. mean this is different in wallet to wallet implementation. i have tried with seed phrase only. but still address doesn't match

 var expectedAddress = "tz1ZLGJkLMdEDmfR5wCgTCRDUhBFujFDMN1b";          
            Mnemonic mnemonic = new Mnemonic("funny before illness obvious mail shoe honey cycle sponsor hill mirror jealous");
            var key = HDKey.FromMnemonic(mnemonic);

            if (key.Address == expectedAddress)
            {

            }
            else
            {

            } 
KamranShahid commented 2 years ago

Even Kukai didn't work with above code :(