Skip to content

Commit

Permalink
[cgo] refs #7 Restoring functions defined in CGO, incorporating the…
Browse files Browse the repository at this point in the history
…m where they belong compared to `v0.25dev`.
  • Loading branch information
Maykel Arias Torres committed May 5, 2019
1 parent 6e36dc8 commit 06e7596
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 419 deletions.
31 changes: 0 additions & 31 deletions lib/cgo/api.client.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,34 +798,3 @@ func SKY_api_Client_DecryptWallet(_c C.Client__Handle, _id string, _password str
}
return
}

//export SKY_api_Client_RecoverWallet
func SKY_api_Client_RecoverWallet(_c C.Client__Handle, _id string, _seed string, _password string, _arg2 *C.WalletResponse__Handle) (____error_code uint32) {
c, okc := lookupClientHandle(_c)
if !okc {
____error_code = SKY_BAD_HANDLE
return
}
id := _id
password := _password
seed := _seed
__arg2, ____return_err := c.RecoverWallet(id, seed, password)
____error_code = libErrorCode(____return_err)
if ____return_err == nil {
*_arg2 = registerWalletResponseHandle(__arg2)
}
return
}

//export SKY_api_Client_Disconnect
func SKY_api_Client_Disconnect(_c C.Client__Handle, _id uint64) (____error_code uint32) {
c, okc := lookupClientHandle(_c)
if !okc {
____error_code = SKY_BAD_HANDLE
return
}
id := _id
____return_err := c.Disconnect(id)
____error_code = libErrorCode(____return_err)
return
}
27 changes: 19 additions & 8 deletions lib/cgo/cipher.bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ func SKY_cipher_DecodeBase58BitcoinAddress(_addr string, _arg1 *C.cipher__Bitcoi
return errcode
}

//export SKY_cipher_BitcoinAddressFromPubKey
func SKY_cipher_BitcoinAddressFromPubKey(_pubKey *C.cipher__PubKey, _arg1 *C.cipher__BitcoinAddress) {
pubKey := (*cipher.PubKey)(unsafe.Pointer(_pubKey))

addr := cipher.BitcoinAddressFromPubKey(*pubKey)
*_arg1 = *(*C.cipher__BitcoinAddress)(unsafe.Pointer(&addr))
}

//export SKY_cipher_BitcoinAddressFromSecKey
func SKY_cipher_BitcoinAddressFromSecKey(_secKey *C.cipher__SecKey, _arg1 *C.cipher__BitcoinAddress) uint32 {
secKey := (*cipher.SecKey)(unsafe.Pointer(_secKey))

addr, err := cipher.BitcoinAddressFromSecKey(*secKey)
if err == nil {
*_arg1 = *(*C.cipher__BitcoinAddress)(unsafe.Pointer(&addr))
}
return libErrorCode(err)
}

//export SKY_cipher_BitcoinWalletImportFormatFromSeckey
func SKY_cipher_BitcoinWalletImportFormatFromSeckey(_seckey *C.cipher__SecKey, _arg1 *C.GoString_) {
seckey := (*cipher.SecKey)(unsafe.Pointer(_seckey))
Expand Down Expand Up @@ -91,11 +110,3 @@ func SKY_cipher_BitcoinAddress_Checksum(_addr *C.cipher__BitcoinAddress, _arg0 *
cs := addr.Checksum()
C.memcpy(unsafe.Pointer(_arg0), unsafe.Pointer(&cs[0]), C.size_t(len(cs)))
}

//export SKY_cipher_BitcoinPubKeyRipemd160
func SKY_cipher_BitcoinPubKeyRipemd160(_pubKey *C.cipher__PubKey, _arg0 *C.cipher__Ripemd160) {
pubkey := *(*cipher.PubKey)(unsafe.Pointer(_pubKey))
r160 := cipher.BitcoinPubKeyRipemd160(pubkey)
C.memcpy(unsafe.Pointer(_arg0), unsafe.Pointer(&r160[0]), C.size_t(len(r160)))

}
65 changes: 65 additions & 0 deletions lib/cgo/cipher.crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,36 @@ func SKY_cipher_PubKeyFromHex(_s string, _arg1 *C.cipher__PubKey) (____error_cod
return
}

//export SKY_cipher_PubKeyFromSecKey
func SKY_cipher_PubKeyFromSecKey(_seckey *C.cipher__SecKey, _arg1 *C.cipher__PubKey) (____error_code uint32) {
seckey := (*cipher.SecKey)(unsafe.Pointer(_seckey))

pubkey, err := cipher.PubKeyFromSecKey(*seckey)
____error_code = libErrorCode(err)

if err == nil {
copyToBuffer(reflect.ValueOf(pubkey[:]), unsafe.Pointer(_arg1), uint(SizeofPubKey))
}

return
}

//export SKY_cipher_PubKeyFromSig
func SKY_cipher_PubKeyFromSig(_sig *C.cipher__Sig, _hash *C.cipher__SHA256, _arg2 *C.cipher__PubKey) (____error_code uint32) {
sig := (*cipher.Sig)(unsafe.Pointer(_sig))
hash := (*cipher.SHA256)(unsafe.Pointer(_hash))

pubkey, err := cipher.PubKeyFromSig(*sig, *hash)

errcode := libErrorCode(err)
if err == nil {
copyToBuffer(reflect.ValueOf(pubkey[:]), unsafe.Pointer(_arg2), uint(SizeofPubKey))

}
____error_code = errcode
return
}

//export SKY_cipher_PubKey_Verify
func SKY_cipher_PubKey_Verify(_pk *C.cipher__PubKey) (____error_code uint32) {
pk := (*cipher.PubKey)(unsafe.Pointer(_pk))
Expand Down Expand Up @@ -80,6 +110,17 @@ func SKY_cipher_NewSecKey(_b []byte, _arg1 *C.cipher__SecKey) (____error_code ui
return
}

//export SKY_cipher_SecKeyFromHex
func SKY_cipher_SecKeyFromHex(_s string, _arg1 *C.cipher__SecKey) (____error_code uint32) {
sk, err := cipher.SecKeyFromHex(_s)
errcode := libErrorCode(err)
if err == nil {
copyToBuffer(reflect.ValueOf(sk[:]), unsafe.Pointer(_arg1), uint(SizeofSecKey))
}
____error_code = errcode
return
}

//export SKY_cipher_SecKey_Verify
func SKY_cipher_SecKey_Verify(_sk *C.cipher__SecKey) (____error_code uint32) {
sk := (*cipher.SecKey)(unsafe.Pointer(_sk))
Expand All @@ -96,6 +137,18 @@ func SKY_cipher_SecKey_Hex(_sk *C.cipher__SecKey, _arg1 *C.GoString_) (____error
return
}

//export SKY_cipher_ECDH
func SKY_cipher_ECDH(_pub *C.cipher__PubKey, _sec *C.cipher__SecKey, _arg2 *C.GoSlice_) (____error_code uint32) {
pub := (*cipher.PubKey)(unsafe.Pointer(_pub))
sec := (*cipher.SecKey)(unsafe.Pointer(_sec))
b, err := cipher.ECDH(*pub, *sec)
____error_code = libErrorCode(err)
if err == nil {
copyToGoSlice(reflect.ValueOf(b), _arg2)
}
return
}

//export SKY_cipher_NewSig
func SKY_cipher_NewSig(_b []byte, _arg1 *C.cipher__Sig) (____error_code uint32) {
s, err := cipher.NewSig(_b)
Expand Down Expand Up @@ -176,6 +229,18 @@ func SKY_cipher_GenerateKeyPair(_arg0 *C.cipher__PubKey, _arg1 *C.cipher__SecKey
return
}

//export SKY_cipher_GenerateDeterministicKeyPair
func SKY_cipher_GenerateDeterministicKeyPair(_seed []byte, _arg1 *C.cipher__PubKey, _arg2 *C.cipher__SecKey) (____error_code uint32) {
p, s, err := cipher.GenerateDeterministicKeyPair(_seed)
if err == nil {
copyToBuffer(reflect.ValueOf(p[:]), unsafe.Pointer(_arg1), uint(SizeofPubKey))
copyToBuffer(reflect.ValueOf(s[:]), unsafe.Pointer(_arg2), uint(SizeofSecKey))
}

____error_code = libErrorCode(err)
return
}

//export SKY_cipher_DeterministicKeyPairIterator
func SKY_cipher_DeterministicKeyPairIterator(_seed []byte, _arg1 *C.GoSlice_, _arg2 *C.cipher__PubKey, _arg3 *C.cipher__SecKey) (____error_code uint32) {
h, p, s, err := cipher.DeterministicKeyPairIterator(_seed)
Expand Down
150 changes: 0 additions & 150 deletions lib/cgo/cipher.crypto.hw.go

This file was deleted.

38 changes: 17 additions & 21 deletions lib/cgo/cipher.hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ func SKY_cipher_Ripemd160_Set(_rd *C.cipher__Ripemd160, _b []byte) (____error_co
return
}

//export SKY_cipher_Ripemd160FromBytes
func SKY_cipher_Ripemd160FromBytes(_data []byte, _arg1 *C.cipher__Ripemd160) (____error_code uint32) {
rd, __return_err := cipher.Ripemd160FromBytes(_data)

if __return_err != nil {
copyToBuffer(reflect.ValueOf(rd[:]), unsafe.Pointer(_arg1), uint(SizeofRipemd160))
}
____error_code = libErrorCode(__return_err)
return
}

//export SKY_cipher_HashRipemd160
func SKY_cipher_HashRipemd160(_data []byte, _arg1 *C.cipher__Ripemd160) (____error_code uint32) {
rd := cipher.HashRipemd160(_data)
Expand All @@ -44,6 +33,15 @@ func SKY_cipher_HashRipemd160(_data []byte, _arg1 *C.cipher__Ripemd160) (____err
return
}

//export SKY_cipher_SHA256_Set
func SKY_cipher_SHA256_Set(_g *C.cipher__SHA256, _b []byte) (____error_code uint32) {
g := (*cipher.SHA256)(unsafe.Pointer(_g))

err := g.Set(_b)
____error_code = libErrorCode(err)
return
}

//export SKY_cipher_SHA256_Hex
func SKY_cipher_SHA256_Hex(_g *C.cipher__SHA256, _arg1 *C.GoString_) (____error_code uint32) {
g := (*cipher.SHA256)(unsafe.Pointer(_g))
Expand All @@ -61,6 +59,14 @@ func SKY_cipher_SHA256_Xor(_g *C.cipher__SHA256, _b *C.cipher__SHA256, _arg1 *C.
return
}

//export SKY_cipher_SumSHA256
func SKY_cipher_SumSHA256(_b []byte, _arg1 *C.cipher__SHA256) (____error_code uint32) {
h := cipher.SumSHA256(_b)

copyToBuffer(reflect.ValueOf(h[:]), unsafe.Pointer(_arg1), uint(SizeofSHA256))
return
}

//export SKY_cipher_SHA256FromHex
func SKY_cipher_SHA256FromHex(_hs string, _arg1 *C.cipher__SHA256) (____error_code uint32) {
h, err := cipher.SHA256FromHex(_hs)
Expand All @@ -71,16 +77,6 @@ func SKY_cipher_SHA256FromHex(_hs string, _arg1 *C.cipher__SHA256) (____error_co
return
}

//export SKY_cipher_SHA256FromBytes
func SKY_cipher_SHA256FromBytes(_data []byte, _arg1 *C.cipher__SHA256) (____error_code uint32) {
sha, err := cipher.SHA256FromBytes(_data)
____error_code = libErrorCode(err)
if err != nil {
copyToBuffer(reflect.ValueOf(sha[:]), unsafe.Pointer(_arg1), uint(SizeofSHA256))
}
return
}

//export SKY_cipher_DoubleSHA256
func SKY_cipher_DoubleSHA256(_b []byte, _arg1 *C.cipher__SHA256) (____error_code uint32) {
h := cipher.DoubleSHA256(_b)
Expand Down
Loading

0 comments on commit 06e7596

Please sign in to comment.