Skip to content

a Go library that implements ED25519-based BIP32, BIP39, and BIP44 for HD wallet management and secure ECDH key exchange using Curve25519.(key25519 是一个基于 ED25519 的 Go 语言库,实现了 BIP32、BIP39 和 BIP44,用于管理分层确定性(HD)钱包,并基于 Curve25519 实现了安全的椭圆曲线密钥交换)

License

Notifications You must be signed in to change notification settings

lyonnee/key25519

Repository files navigation


key25519

English 中文

key25519 is a cryptographic library written in Go that implements a variety of cryptographic functions based on Ed25519, including BIP32 hierarchical deterministic wallets, BIP39 mnemonic generation, BIP44 multi-account wallet structures, and ECDH key exchange protocols based on Curve25519.

Features

  • BIP32, BIP39, BIP44: Supports hierarchical deterministic wallets and mnemonic generation.
  • ECDH Key Exchange: Secure key exchange implemented using Curve25519.
  • Keystore Management: Provides functionalities to securely export and import Keystores.

Installation

Install using the go get command:

go get github.com/lyonnee/key25519

Usage Examples

ECDH Key Exchange

kp1 := key25519.NewKeyPair()
kp2 := key25519.NewKeyPair()

kp1EcdhPubKey, _ := kp1.ExportEcdhPubKey()
kp2EcdhPubKey, _ := kp2.ExportEcdhPubKey()

sk1, _ := kp1.Ecdh(kp2EcdhPubKey)
sk2, _ := kp2.Ecdh(kp1EcdhPubKey)

// The shared secret should be the same for both parties
fmt.Println(format.EncodeBase58(sk1))
fmt.Println(format.EncodeBase58(sk2))

HD Wallet

mnemonic, _ := bip39.GenerateMnemonic(bip39.LEN_12, bip39.ENGLISH)
seed := bip39.NewSeed(mnemonic, "")

masterKey := bip32.NewMasterKey(seed)
path := "m/44'/501'/0'/0'"
indexs, _ := bip44.ParsePath(path)

var newKey = masterKey
for _, v := range indexs {
    newKey = bip32.CKDPriv(newKey, v)
}

edPrivKey := ed25519.NewKeyFromSeed(newKey.PrivKey)
pubk, _ := key25519.NewPubKeyFromEd25519PubKey(edPrivKey.Public().(ed25519.PublicKey))

fmt.Println(format.EncodeBase58(edPrivKey)) // Private key
fmt.Println(format.EncodeBase58(pubk.Bytes())) // Public key

Keystore Example

kp := key25519.NewKeyPair()
originMsg := []byte("i am lyon")
signedMsg := kp.PrivateKey().SignMsg(originMsg)

filename := "./" + format.EncodeBase58(kp.PublicKey().Bytes()) + ".keystore"
password := "kaixin"

err := kp.ExportKeystore(filename, password)
// ...
kp2, _ := key25519.NewKeyPairFromKeystore(filename, password)

res := key25519.VerifyMsg(kp2.PublicKey(), originMsg, signedMsg)
// Verification of the signature
fmt.Println(res)

Contribution

We welcome issues and pull requests to improve key25519.

License

key25519 is released under the MIT License. See the LICENSE file for more information.

About

a Go library that implements ED25519-based BIP32, BIP39, and BIP44 for HD wallet management and secure ECDH key exchange using Curve25519.(key25519 是一个基于 ED25519 的 Go 语言库,实现了 BIP32、BIP39 和 BIP44,用于管理分层确定性(HD)钱包,并基于 Curve25519 实现了安全的椭圆曲线密钥交换)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages