Solnet icon indicating copy to clipboard operation
Solnet copied to clipboard

How to create an Account based on the private key of Base58?

Open JavinYang opened this issue 3 years ago • 0 comments

I can use github.com/gagliardetto/solan-go to create an Account (Wallet) through private key (base58)

// Wallet is a wrapper around a PrivateKey
type Wallet struct {
	PrivateKey PrivateKey
}

func NewWallet() *Wallet {
	privateKey, err := NewRandomPrivateKey()
	if err != nil {
		panic(fmt.Sprintf("failed to generate private key: %s", err))
	}
	return &Wallet{
		PrivateKey: privateKey,
	}
}

func WalletFromPrivateKeyBase58(privateKey string) (*Wallet, error) {
	k, err := PrivateKeyFromBase58(privateKey)
	if err != nil {
		return nil, fmt.Errorf("account from private key: private key from b58: %w", err)
	}
	return &Wallet{
		PrivateKey: k,
	}, nil
}

func (a *Wallet) PublicKey() PublicKey {
	return a.PrivateKey.PublicKey()
}

...

But SolNet needs PrivateKey and PublicKey to create an account

/// <summary>
        /// Initialize an account with the passed private and public keys.
        /// </summary>
        /// <param name="privateKey">The private key.</param>
        /// <param name="publicKey">The public key.</param>
        public Account(string privateKey, string publicKey)
        {
            PrivateKey = new PrivateKey(privateKey);
            PublicKey = new PublicKey(publicKey);
        }

How can I create an account using only PrivateKey?

JavinYang avatar Nov 21 '22 04:11 JavinYang