github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/gomobile/walletutil/ecdsa_test.go (about) 1 2 package walletutil 3 4 import ( 5 "bytes" 6 "crypto/ecdsa" 7 "fmt" 8 "github.com/ethereum/go-ethereum/common/math" 9 "github.com/ethereum/go-ethereum/crypto" 10 "github.com/tyler-smith/go-bip39" 11 "github.com/sixexorg/magnetic-ring/common" 12 "github.com/sixexorg/magnetic-ring/crypto/secp256k1/bitelliptic" 13 "github.com/sixexorg/magnetic-ring/radar/orgchain" 14 "testing" 15 ) 16 17 func TestGenerateAppEcdsaKey(t *testing.T) { 18 19 seed := GenerateSeed("abcdefg",128) 20 21 22 fmt.Printf("seed=%s\n",seed) 23 24 prvBytestr := GenerateRandomPrvKey(seed) 25 26 pubBytes := GetPubKey(prvBytestr) 27 28 addr := ToAddress(pubBytes) 29 fmt.Printf("address-->%s\n",addr) 30 31 fmt.Printf("pubBytes: %s\n", pubBytes) 32 33 msg := "hello world!" 34 35 sigbuf := Sign(prvBytestr,msg) 36 37 fmt.Printf("src: %s\n", msg) 38 39 40 fmt.Printf("sigbuf:%s\n",sigbuf) 41 42 result := Verify(pubBytes,msg,sigbuf) 43 44 t.Logf("verify result-->%v\n",result) 45 46 47 } 48 49 50 51 52 func TestVerify(t *testing.T) { 53 54 pubkbytes := "049c42b72d86685a2c2069933d5e7996e52cfe7215f3d7af1b4c48ba93bd53a7f38e23f8a97d71af07c0a8733016baa8a1e3122f5e7c0da740d0d2710db0d8dd36" 55 sigstr := "db784b8b6521f0916494a3aad84ef4e03de5b45400bb776712b912ca0ca6b36c3c3cf00ce9ba473c526e675c1b18346fabf6bcaa0653fc9440ce534a3ac1a06f" 56 pubbuf,err := common.Hex2Bytes(pubkbytes) 57 if err != nil { 58 t.Errorf("error=%v\n",err) 59 return 60 } 61 62 63 fmt.Printf("pubBytes: %v\n", pubbuf) 64 fmt.Printf("pubBytes: %X\n", pubbuf) 65 fmt.Printf("pubBytes len: %d\n", len(pubbuf)) 66 67 msg := "hello world!" 68 69 70 //sigbuf,err := Sign(prvBytes,msg) 71 //if err != nil { 72 // t.Error("err-->%v\n",err) 73 // return 74 //} 75 76 sigbuf,err := common.Hex2Bytes(sigstr) 77 if err != nil { 78 t.Errorf("error=%v\n",err) 79 return 80 } 81 82 t.Logf("sigbuf-->%x\n",sigbuf) 83 84 85 result := Verify(pubkbytes,msg,sigstr) 86 87 t.Logf("verify result-->%v\n",result) 88 89 90 } 91 92 func TestNewMnemonic(t *testing.T) { 93 //nem:=NewMnemonic(128) 94 //fmt.Printf("nem:%s\n",nem) 95 96 nem := "session bike timber matter scare region cloud small since turtle wasp winner" 97 98 seed := bip39.NewSeed(nem, "") 99 100 101 buffer := new(bytes.Buffer) 102 103 //seedbuf := common.Hex2Bytes(seed) 104 105 buffer.Write(seed) 106 107 key, err := ecdsa.GenerateKey(bitelliptic.S256(), buffer) 108 if err != nil { 109 return 110 } 111 prvBytes := math.PaddedBigBytes(key.D, 32) 112 113 hexstr := common.Bytes2Hex(prvBytes) 114 115 fmt.Printf("prvkstr:%x\n",prvBytes) 116 //hex := fmt.Sprintf("%x") 117 k,err := crypto.HexToECDSA(hexstr) 118 if err != nil { 119 t.Errorf("error=%v\n",err) 120 return 121 } 122 123 addr := crypto.PubkeyToAddress(k.PublicKey) 124 fmt.Printf("final addr:%s\n",addr.String()) 125 126 } 127 128 func TestGetaccountnonce(t *testing.T) { 129 str := GetAccountBalance("http://127.0.0.1:10086","ct1J8X6KQMKs2j6mCg99uC6M463m8ug6ze4","orgid") 130 fmt.Printf("str=%s\n",str) 131 } 132 133 func TestCreateLeague(t *testing.T) { 134 str := GetOrgInfo("http://192.168.10.153:20086","ct27hJxDpRvW63TCN2MF6PyT2D1ayqjv24x") 135 136 fmt.Printf("str=%s\n",str) 137 } 138 139 func TestCap(t *testing.T) { 140 fmt.Printf("begin\n") 141 re := &orgchain.ResultOp{} 142 fmt.Printf("☂️ ☂️ ☂️ ☂️ ☂️ ☂️ ☂️ ☂️ re--->%+v\n",re) 143 select { 144 case orgTx := <-re.ORGTX: 145 fmt.Println("☃️ digestMainTx ORGTX--->", orgTx) 146 147 case mcc := <-re.MCC: 148 fmt.Println("☃️ digestMainTx MCC--->", mcc) 149 } 150 151 }