github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/subkey/README.md (about) 1 # go-subkey 2 [![Go Reference](https://pkg.go.dev/badge/github.com/vedhavyas/go-subkey.svg)](https://pkg.go.dev/github.com/vedhavyas/go-subkey) 3 4 Subkey port in Go 5 6 ## Usage 7 8 ### Generate Key pair 9 10 #### Sr25519 11 ```go 12 kr, err := sr25519.Scheme{}.Generate() 13 ``` 14 15 #### Ed25519 16 ```go 17 kr, err := ed25519.Scheme{}.Generate() 18 ``` 19 20 #### Ecdsa 21 ```go 22 kr, err := ecdsa.Scheme{}.Generate() 23 ``` 24 25 26 ### Deriving keypair from a mnemonic or seed 27 28 #### Mnemonic 29 ```go 30 uri := "crowd swamp sniff machine grid pretty client emotion banana cricket flush soap//foo//42///password" 31 scheme := sr25519.Scheme{} 32 kr, err := subkey.DeriveKeyPair(scheme, uri) 33 ``` 34 35 #### Hex encoded Seed 36 ```go 37 uri := "0x6ea8835d60351a39a1e2293b2902d7bd6e12e526e72c46f4fda4a233809c4379" 38 scheme := sr25519.Scheme{} 39 kr, err := subkey.DeriveKeyPair(scheme, uri) 40 ``` 41 42 #### Hex encoded Seed with derivation 43 ```go 44 uri := "0x6ea8835d60351a39a1e2293b2902d7bd6e12e526e72c46f4fda4a233809c4379//foo//42///password" 45 scheme := sr25519.Scheme{} 46 kr, err := subkey.DeriveKeyPair(scheme, uri) 47 ``` 48 49 50 ### Sign and verify using Keypair 51 ```go 52 kr, err := ed25519.Scheme{}.Generate() 53 msg := []byte("test message") 54 sig, err := kr.Sign(msg) 55 ok := kr.Verify(msg, sig) 56 ```