Skip to content

Commit

Permalink
cgo: Add verify message.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed Oct 14, 2024
1 parent dbc5f93 commit c1f2aa6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
27 changes: 27 additions & 0 deletions cgo/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import "C"
import (
"encoding/base64"
"encoding/json"
"fmt"

dcrwallet "decred.org/dcrwallet/v4/wallet"
"decred.org/dcrwallet/v4/wallet/udb"
"github.com/decred/dcrd/txscript/v4/stdaddr"
)
Expand Down Expand Up @@ -84,6 +86,31 @@ func signMessage(cName, cMessage, cAddress, cPassword *C.char) *C.char {
return successCResponse(sEnc)
}

//export verifyMessage
func verifyMessage(cName, cMessage, cAddress, cSig *C.char) *C.char {
w, ok := loadedWallet(cName)
if !ok {
return errCResponse("wallet with name %q is not loaded", goString(cName))
}

addr, err := stdaddr.DecodeAddress(goString(cAddress), w.MainWallet().ChainParams())
if err != nil {
return errCResponse("unable to decode address: %v", err)
}

sig, err := base64.StdEncoding.DecodeString(goString(cSig))
if err != nil {
return errCResponse("unable to decode signature: %v", err)
}

ok, err = dcrwallet.VerifyMessage(goString(cMessage), addr, sig, w.MainWallet().ChainParams())
if err != nil {
return errCResponse("unable to sign message: %v", err)
}

return successCResponse(fmt.Sprintf("%v", ok))
}

//export addresses
func addresses(cName *C.char) *C.char {
w, ok := loadedWallet(cName)
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/decred/libwallet

require (
decred.org/dcrdex v0.0.0-20240415203145-79c4689fd164
decred.org/dcrwallet/v4 v4.1.2
decred.org/dcrwallet/v4 v4.1.3
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/decred/dcrd/addrmgr/v2 v2.0.4
github.com/decred/dcrd/chaincfg/chainhash v1.0.4
Expand All @@ -15,7 +15,7 @@ require (
github.com/decred/slog v1.2.0
github.com/jrick/logrotate v1.0.0
github.com/kevinburke/nacl v0.0.0-20210405173606-cd9060f5f776
golang.org/x/crypto v0.24.0
golang.org/x/crypto v0.26.0
)

require (
Expand All @@ -36,18 +36,18 @@ require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/decred/dcrd/dcrjson/v4 v4.1.0 // indirect
github.com/decred/dcrd/gcs/v4 v4.1.0 // indirect
github.com/decred/dcrd/mixing v0.4.0 // indirect
github.com/decred/dcrd/mixing v0.4.1 // indirect
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.3.0 // indirect
github.com/decred/go-socks v1.1.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/jrick/bitset v1.0.0 // indirect
github.com/jrick/wsrpc/v2 v2.3.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/stretchr/testify v1.8.2 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
)

Expand Down
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ decred.org/cspp/v2 v2.2.0 h1:VSOUC1w0Wo+QOGS0r1XO6TLnO16X67KuvpDmRRYyr08=
decred.org/cspp/v2 v2.2.0/go.mod h1:9nO3bfvCheOPIFZw5f6sRQ42CjBFB5RKSaJ9Iq6G4MA=
decred.org/dcrdex v0.0.0-20240415203145-79c4689fd164 h1:ImD+Zui9lnZhVYacX0x9ki1M95hTYxwASl2PvVoAc2M=
decred.org/dcrdex v0.0.0-20240415203145-79c4689fd164/go.mod h1:rvIXDCS3B3gbu8b0tKDvNU664nC+/zVl3ivs6AeA2V8=
decred.org/dcrwallet/v4 v4.1.2 h1:NESPkLLpLXwrsWRmeDSLM/O5NaSMFSyjQrG+9m0iuzk=
decred.org/dcrwallet/v4 v4.1.2/go.mod h1:Ivu6THxbdMLGxKTa/eJT7vDr2awmKok7gEh82oCxs/s=
decred.org/dcrwallet/v4 v4.1.3 h1:XKxDbvPAHXfLunYNbCIEh2TYCwZ039hvUJCcTpfBAMg=
decred.org/dcrwallet/v4 v4.1.3/go.mod h1:hqAijllSbuhT4dZofpufi/08kGDXVUJUnPNtmqnJq4A=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
Expand Down Expand Up @@ -54,8 +54,8 @@ github.com/decred/dcrd/gcs/v4 v4.1.0 h1:tpW7JW53yJZlgNwl/n2NL1b8NxHaIPRUyNuLMkB/
github.com/decred/dcrd/gcs/v4 v4.1.0/go.mod h1:nPTbGM/I3Ihe5KFvUmxZEqQP/jDZQjQ63+WEi/f4lqU=
github.com/decred/dcrd/hdkeychain/v3 v3.1.2 h1:x25WuuE7zM/20EynuVMyOhL0K8BwGBBsexGq8xTiHFA=
github.com/decred/dcrd/hdkeychain/v3 v3.1.2/go.mod h1:FnNJmZ7jqUDeAo6/c/xkQi5cuxh3EWtJeMmW6/Z8lcc=
github.com/decred/dcrd/mixing v0.4.0 h1:XblHAND4Vt5owVUvjPorDg30eWT53DpCZs6VF7U1t6U=
github.com/decred/dcrd/mixing v0.4.0/go.mod h1:ySvVwTZyVz5YvevA6YjPrB6pJEwTm7IkHohTfaiHh2c=
github.com/decred/dcrd/mixing v0.4.1 h1:W8ZCzhmNyzG1xjJMA3L6FOElmp98Ttnk3dDUxD6irAE=
github.com/decred/dcrd/mixing v0.4.1/go.mod h1:ySvVwTZyVz5YvevA6YjPrB6pJEwTm7IkHohTfaiHh2c=
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.3.0 h1:l0DnCcILTNrpy8APF3FLN312ChpkQaAuW30aC/RgBaw=
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.3.0/go.mod h1:j+kkRPXPJB5S9VFOsx8SQLcU7PTFkPKRc1aCHN4ENzA=
github.com/decred/dcrd/txscript/v4 v4.1.1 h1:R4M2+jMujgQA91899SkL0cW66d6DC76Gx+1W1oEHjc0=
Expand All @@ -77,8 +77,8 @@ github.com/jrick/wsrpc/v2 v2.3.5 h1:CwdycaR/df09iGkPMXs1FxqAHMCQbdAiTGoHfOrtuds=
github.com/jrick/wsrpc/v2 v2.3.5/go.mod h1:7oBeDM/xMF6Yqy4GDAjpppuOf1hm6lWsaG3EaMrm+aA=
github.com/kevinburke/nacl v0.0.0-20210405173606-cd9060f5f776 h1:W8T7zJRO9imecUZySwPkuXHosjp2MloqAY1eSAEEOIo=
github.com/kevinburke/nacl v0.0.0-20210405173606-cd9060f5f776/go.mod h1:VUp2yfq+wAk8hMl3NNN34fXjzUD9xMpGvUL8eSJz9Ns=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -91,15 +91,15 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA=
go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down

0 comments on commit c1f2aa6

Please sign in to comment.