fix: send to public channel

This commit is contained in:
Richard Ramos 2022-09-23 16:08:36 -04:00
parent cf0e677d2c
commit ed29fe845e
No known key found for this signature in database
GPG Key ID: BD36D48BC9FFC88C
3 changed files with 2690 additions and 38 deletions

112
go.mod
View File

@ -2,34 +2,142 @@ module waku/client
go 1.19
replace github.com/flynn/noise v1.0.0 => github.com/status-im/noise v1.0.1-handshakeMessages
require (
github.com/ethereum/go-ethereum v1.10.21
github.com/golang/protobuf v1.5.2
github.com/status-im/go-waku v0.2.3-0.20220915230805-448f5a2e0ef6
github.com/status-im/status-go v0.110.1
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
)
require (
github.com/BurntSushi/toml v1.2.0 // indirect
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cheekybits/genny v1.0.0 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cruxic/go-hmac-drbg v0.0.0-20170206035330-84c46983886d // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ethereum/go-ethereum v1.10.21 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/flynn/noise v1.0.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-migrate/migrate/v4 v4.15.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/ipfs/go-cid v0.2.0 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
github.com/klauspost/compress v1.15.1 // indirect
github.com/klauspost/cpuid/v2 v2.0.14 // indirect
github.com/koron/go-ssdp v0.0.3 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-eventbus v0.2.1 // indirect
github.com/libp2p/go-flow-metrics v0.0.3 // indirect
github.com/libp2p/go-libp2p v0.21.0 // indirect
github.com/libp2p/go-libp2p-asn-util v0.2.0 // indirect
github.com/libp2p/go-libp2p-core v0.19.1 // indirect
github.com/libp2p/go-libp2p-peerstore v0.7.1 // indirect
github.com/libp2p/go-libp2p-pubsub v0.7.1-0.20220701163738-60cf38003244 // indirect
github.com/libp2p/go-libp2p-resource-manager v0.5.1 // indirect
github.com/libp2p/go-mplex v0.7.0 // indirect
github.com/libp2p/go-msgio v0.2.0 // indirect
github.com/libp2p/go-nat v0.1.0 // indirect
github.com/libp2p/go-netroute v0.2.0 // indirect
github.com/libp2p/go-openssl v0.0.7 // indirect
github.com/libp2p/go-reuseport v0.2.0 // indirect
github.com/libp2p/go-yamux/v3 v3.1.2 // indirect
github.com/lucas-clemente/quic-go v0.28.0 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
github.com/marten-seemann/qtls-go1-17 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.0-beta.1 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v2.0.2+incompatible // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.0.4 // indirect
github.com/multiformats/go-base36 v0.1.0 // indirect
github.com/multiformats/go-multiaddr v0.6.0 // indirect
github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
github.com/multiformats/go-multibase v0.1.1 // indirect
github.com/multiformats/go-multicodec v0.5.0 // indirect
github.com/multiformats/go-multihash v0.2.0 // indirect
github.com/multiformats/go-multistream v0.3.3 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pborman/uuid v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.35.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/rjeczalik/notify v0.9.2 // indirect
github.com/russolsen/transit v0.0.0-20180705123435-0794b4c4505a // indirect
github.com/shirou/gopsutil v3.21.5+incompatible // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/status-im/doubleratchet v3.0.0+incompatible // indirect
github.com/status-im/go-discover v0.0.0-20220406135310-85a2ce36f63e // indirect
github.com/status-im/go-rln v0.1.1 // indirect
github.com/status-im/go-waku-rendezvous v0.0.0-20220817210730-9b9b02b1e880 // indirect
github.com/status-im/status-go/extkeys v1.1.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
github.com/tklauser/go-sysconf v0.3.6 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee // indirect
go.opencensus.io v0.23.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.22.0 // indirect
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220630215102-69896b714898 // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.11 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
)

2492
go.sum

File diff suppressed because it is too large Load Diff

124
run.go
View File

@ -1,26 +1,29 @@
package main
// we have a waku node running via this command and listening for RPC requests on port 8545:
// ./build/waku \
// --dns-discovery=true \
// --dns-discovery-url=enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@test.nodes.status.im \
// --discv5-discovery=true \
// --rpc \
// --rpc-admin
/*
./build/waku \
--dns-discovery=true \
--dns-discovery-url=enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@prod.nodes.status.im \
--discv5-discovery=true \
--rpc \
--rpc-admin
*/
// the goal is to send a request like the following to send a message to a user on the status mobile app:
// curl -v -f -s -X POST -H Content-type:application/json --data '{
// "id": 1,
// "jsonrpc": "2.0",
// "method": "post_waku_v2_relay_v1_message",
// "params": ["", {
// "payload": "abcdef112233",
// "contentTopic": "contentTopicGoesHere",
// "timestamp": 1257894000000000000,
// "version": 1
// }]
// }' http://localhost:8545
/*
curl -v -f -s -X POST -H Content-type:application/json --data '{
"id": 1,
"jsonrpc": "2.0",
"method": "post_waku_v2_relay_v1_message",
"params": ["", {
"payload": "abcdef112233",
"contentTopic": "contentTopicGoesHere",
"timestamp": 1257894000000000000,
"version": 1
}]
}' http://localhost:8545
*/
// the following script generates an appropriate contentTopic for a known user's public key.
// We know we need to generate a protobuf ChatMessage and wrap it in a protobuf ApplicationMetadataMessage.
@ -82,20 +85,22 @@ package main
import (
"crypto/ecdsa"
"crypto/sha256"
"encoding/hex"
"fmt"
"math/big"
"strconv"
"time"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/protobuf"
"golang.org/x/crypto/pbkdf2"
// "google.golang.org/protobuf/proto"
"github.com/golang/protobuf/proto"
// "github.com/status-im/status-go/protocol/encryption"
// "github.com/status-im/status-go/protocol/protobuf"
// "github.com/status-im/status-go/protocol/sqlite"
v1protocol "github.com/status-im/status-go/protocol/v1"
)
@ -107,27 +112,30 @@ var (
)
func main() {
jasonKey := "04aa379d2661d6358f41b47a866f2674ca987e3398e93318ec08ea58b9f7035df491131a62ad3a469af609df9af58bcad698dac7f01e160130b7e187c60b824973"
rramosKey := "04ca2cf0599ace5def8543cb53e7fbd1d54ba65ab89f8794a08f9bf0406a7895c8074f380adf47a6692df0217cc81d2c680c6f50ef4149c84901f95c22a76bfa96"
// jasonKey := "04aa379d2661d6358f41b47a866f2674ca987e3398e93318ec08ea58b9f7035df491131a62ad3a469af609df9af58bcad698dac7f01e160130b7e187c60b824973"
// kbKey := "04e3ec4eb8a7c6b78f30b25ee2b2c34040ede4b9e51627ac82051bb37c4c3de21da0709bced20619566c545ff7b69fd58b8840cd48a686fffe68608f879bf9155b"
// mikeKey := "04622248490465b1d0cd5ec48375484682bec9a16f550ffd461cb803d4a8970a88cf8f99390a8e2216012602a9f8a0882ae86d773667d2802939150f3a14f1963a"
publicKeyString := jasonKey
publicKeyString := rramosKey
publicKey, err := StrToPublicKey(publicKeyString)
if err != nil {
panic(err)
}
// fmt.Printf("PUKEY: '%v'\n", publicKey.X)
partitionTopic := PartitionedTopic(publicKey)
// fmt.Printf("PAR TOPIC: '%v'\n", partitionTopic)
_ = publicKey
topic := "testrramos" // PartitionedTopic(publicKey)
topicBytes := ToTopic(topic)
contentTopic := ContentTopic(topicBytes)
testMessage := protobuf.ChatMessage{
Text: "abc123",
ChatId: fmt.Sprintf("0x%v", publicKeyString),
ChatId: topic,
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
MessageType: protobuf.MessageType_ONE_TO_ONE,
Clock: 154593077368201,
Timestamp: 1545930773682,
MessageType: protobuf.MessageType_PUBLIC_GROUP,
Clock: uint64(time.Now().Unix()),
Timestamp: uint64(time.Now().Unix()),
}
// fmt.Printf("testMessage: '%v'\n", testMessage)
encodedPayload, err := proto.Marshal(&testMessage)
if err != nil {
@ -143,11 +151,49 @@ func main() {
if err != nil {
panic(err)
}
// fmt.Printf("wrappedPayload: '%v'\n", wrappedPayload)
hexEncoded := hex.EncodeToString(wrappedPayload)
// fmt.Printf("hexEncoded: '%v'\n", hexEncoded)
fmt.Printf("%v:%v", partitionTopic, hexEncoded)
// The messages need to be encrypted before they're broadcasted
payload := node.Payload{}
payload.Data = wrappedPayload
payload.Key = &node.KeyInfo{
PrivKey: authorKey, // Key used to sign the message
// For sending to a public channel
Kind: node.Symmetric,
SymKey: generateSymKey(topic),
// For 1:1
// Kind: node.Asymmetric,
// PubKey: publicKey
}
payloadBytes, err := payload.Encode(1)
if err != nil {
panic(err)
}
hexEncoded := hex.EncodeToString(payloadBytes)
fmt.Printf(`
curl -v --fail-with-body -s -X POST -H Content-type:application/json --data '{
"id": 1,
"jsonrpc": "2.0",
"method": "post_waku_v2_relay_v1_message",
"params": ["", {
"payload": "%s",
"contentTopic": "%s",
"version": 1,
"timestamp": %d
}]
}' http://localhost:8545
`, hexEncoded, contentTopic, time.Now().UnixNano())
}
func ContentTopic(t []byte) string {
enc := hexutil.Encode(t)
return "/waku/1/" + enc + "/rfc26"
}
// ToTopic converts a string to a whisper topic.
@ -190,3 +236,9 @@ func NegotiatedTopic(publicKey *ecdsa.PublicKey) string {
func DiscoveryTopic() string {
return discoveryTopic
}
func generateSymKey(password string) []byte {
// AesKeyLength represents the length (in bytes) of an private key
AESKeyLength := 256 / 8
return pbkdf2.Key([]byte(password), nil, 65356, AESKeyLength, sha256.New)
}