Esempio n. 1
0
func TestMustDecodeBase58Address(t *testing.T) {
	p, _ := GenerateKeyPair()
	a := AddressFromPubKey(p)
	assert.Nil(t, a.Verify(p))

	assert.Panics(t, func() { MustDecodeBase58Address("") })
	assert.Panics(t, func() { MustDecodeBase58Address("cascs") })
	b := a.Bytes()
	h := string(base58.Hex2Base58(b[:len(b)/2]))
	assert.Panics(t, func() { MustDecodeBase58Address(h) })
	h = string(base58.Hex2Base58(b))
	assert.NotPanics(t, func() { MustDecodeBase58Address(h) })
	a2 := MustDecodeBase58Address(h)
	assert.Equal(t, a, a2)
}
//exports seckey in wallet import format
//key must be compressed
func BitcoinWalletImportFormatFromSeckey(seckey []byte) string {
	b1 := append([]byte{byte(0x80)}, seckey[:]...)
	b2 := append(b1[:], []byte{0x01}...)
	b3 := _DoubleSHA256(b2) //checksum
	b4 := append(b2, b3[0:4]...)
	return string(base58.Hex2Base58(b4))
}
//prints the bitcoin address for a seckey
func BitcoinAddressFromPubkey(pubkey []byte) string {
	b1 := SumSHA256(pubkey[:])
	b2 := _HashRipemd160(b1[:])
	b3 := append([]byte{byte(0)}, b2[:]...)
	b4 := _DoubleSHA256(b3)
	b5 := append(b3, b4[0:4]...)
	return string(base58.Hex2Base58(b5))
}
Esempio n. 4
0
// Address as Base58 encoded string
// Returns address as printable
// version is first byte in binary format
// in printed address its key, version, checksum
func (self *Address) String() string {
	b := make([]byte, 20+1+4)
	copy(b[0:20], self.Key[0:20])
	b[20] = self.Version
	chksum := self.Checksum()
	copy(b[21:25], chksum[0:4])
	return string(base58.Hex2Base58(b))
}
Esempio n. 5
0
func TestDecodeBase58Address(t *testing.T) {
	p, _ := GenerateKeyPair()
	a := AddressFromPubKey(p)
	assert.Nil(t, a.Verify(p))

	a2, err := DecodeBase58Address("")
	assert.NotNil(t, err)
	a2, err = DecodeBase58Address("cascs")
	assert.NotNil(t, err)
	b := a.Bytes()
	h := string(base58.Hex2Base58(b[:len(b)/2]))
	a2, err = DecodeBase58Address(h)
	assert.NotNil(t, err)
	h = string(base58.Hex2Base58(b))
	a2, err = DecodeBase58Address(h)
	assert.Nil(t, err)
	assert.Equal(t, a, a2)
}
Esempio n. 6
0
//prints the bitcoin address for a seckey
func BitcoinAddressFromPubkey(pubkey PubKey) string {
	b1 := SumSHA256(pubkey[:])
	b2 := HashRipemd160(b1[:])
	b3 := append([]byte{byte(0)}, b2[:]...)
	b4 := DoubleSHA256(b3)
	b5 := append(b3, b4[0:4]...)
	return string(base58.Hex2Base58(b5))
	// return Address{
	// 	Version: 0,
	// 	Key:     b2,
	// }
}
Esempio n. 7
0
func (self Address) BitcoinString() string {
	return string(base58.Hex2Base58(self.BitcoinBytes()))
}
Esempio n. 8
0
// Address as Base58 encoded string
// Returns address as printable
// version is first byte in binary format
// in printed address its key, version, checksum
func (self Address) String() string {
	return string(base58.Hex2Base58(self.Bytes()))
}