-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Private Key for Generated Account #123
Comments
I've been using the following which I lifted from
|
Would love to make a new function for this, what would you like to see? Atm, it can fairly complicated, but you can do some crafty stuff here: acc1, _ := aptos.NewEd25519Account()
pk, ok := acc1.Signer.(*crypto.Ed25519PrivateKey) Thinking something like: // ExtractMessageSigner extracts the message signer from the account for
func (account *Account) ExtractMessageSigner() (crypto.MessageSigner, bool) {
ed25519PrivKey, ok := account.Signer.(*crypto.Ed25519PrivateKey)
if ok {
return ed25519PrivKey, ok
}
singleSigner, ok := account.Signer.(*crypto.SingleSigner)
if ok {
return singleSigner.Signer, ok
}
return nil, false
} Or alternatively can just make an "ExtractPrivateKeyString" / ExtractPrivateKeyString extracts the private key string
func (account *Account) ExtractPrivateKeyString() (string, error) {
// Handle the key by itself
ed25519PrivateKey, ok := account.Signer.(*crypto.Ed25519PrivateKey)
if ok {
return ed25519PrivateKey.ToAIP80()
}
// Handle key in single signer
singleSigner, ok := account.Signer.(*crypto.SingleSigner)
if !ok {
innerSigner := singleSigner.Signer
switch innerSigner.(type) {
case *crypto.Ed25519PrivateKey:
return innerSigner.(*crypto.Ed25519PrivateKey).ToAIP80()
case *crypto.Secp256k1PrivateKey:
return innerSigner.(*crypto.Secp256k1PrivateKey).ToAIP80()
}
}
return "", errors.New("signer is not a private key")
} |
Here's an attempt at it with some other fixes #125 |
@gregnazario 👋 I was away for a few weeks 👶 Thanks for putting up the PR. I left some comments. |
I've committed with that feedback! Please reopen if it's not enough |
Hey there all!!!
I have generated an account using aptos-labs/aptos-go-sdk as such
acc1, _ := aptos.NewEd25519Account()
I want to ask how to get access of the Private Key for this generated Account.
The text was updated successfully, but these errors were encountered: