Skip to content
Snippets Groups Projects
Commit d47f7fb5 authored by Jonah Husson's avatar Jonah Husson
Browse files

Fixes, renames

parent 8a1f1623
Branches
Tags
3 merge requests!128Project/base32768,!124Update for single DB cipher object,!109Project/haven beta
......@@ -9,8 +9,8 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/jwalterweatherman v1.1.0
github.com/stretchr/testify v1.8.2
gitlab.com/elixxir/client/v4 v4.6.4-0.20230530222715-a0c0ea0de57f
gitlab.com/elixxir/crypto v0.0.7-0.20230522162218-45433d877235
gitlab.com/elixxir/client/v4 v4.6.4-0.20230530215702-1eaf1ba5d94c
gitlab.com/elixxir/crypto v0.0.7-0.20230525135047-4e3664debc50
gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c
gitlab.com/elixxir/wasm-utils v0.0.0-20230522231408-a43b2c1481b2
gitlab.com/xx_network/crypto v0.0.5-0.20230214003943-8a09396e95dd
......@@ -28,12 +28,10 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/elliotchance/orderedmap v1.4.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gobwas/ws v1.1.0 // indirect
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
......@@ -42,27 +40,18 @@ require (
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.1.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20221003100820-41fad3beba17 // indirect
github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pkg/profile v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/sethvargo/go-diceware v0.3.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
github.com/ttacon/libphonenumber v1.2.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
......@@ -83,8 +72,6 @@ require (
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/sqlite v1.4.4 // indirect
gorm.io/gorm v1.24.3 // indirect
......
This diff is collapsed.
......@@ -11,6 +11,7 @@ package main
import (
"encoding/json"
"gitlab.com/elixxir/crypto/database"
"time"
"github.com/pkg/errors"
......@@ -18,7 +19,6 @@ import (
"gitlab.com/elixxir/client/v4/channels"
"gitlab.com/elixxir/client/v4/cmix/rounds"
cryptoBroadcast "gitlab.com/elixxir/crypto/broadcast"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/elixxir/crypto/message"
wChannels "gitlab.com/elixxir/xxdk-wasm/indexedDb/worker/channels"
......@@ -64,7 +64,7 @@ func (m *manager) newWASMEventModelCB(data []byte) ([]byte, error) {
// Create new encryption cipher
rng := fastRNG.NewStreamGenerator(12, 1024, csprng.NewSystemRNG)
encryption, err := cryptoChannel.NewCipherFromJSON(
encryption, err := database.NewCipherFromJSON(
[]byte(msg.EncryptionJSON), rng.GetStream())
if err != nil {
return []byte{}, errors.Errorf(
......
......@@ -12,6 +12,7 @@ package main
import (
"crypto/ed25519"
"encoding/json"
"gitlab.com/elixxir/crypto/database"
"strconv"
"strings"
"syscall/js"
......@@ -25,7 +26,6 @@ import (
"gitlab.com/elixxir/client/v4/channels"
"gitlab.com/elixxir/client/v4/cmix/rounds"
cryptoBroadcast "gitlab.com/elixxir/crypto/broadcast"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/message"
"gitlab.com/elixxir/wasm-utils/utils"
"gitlab.com/elixxir/xxdk-wasm/indexedDb/impl"
......@@ -37,7 +37,7 @@ import (
// caller to ensure that its methods are called sequentially.
type wasmModel struct {
db *idb.Database
cipher cryptoChannel.Cipher
cipher database.Cipher
eventUpdate func(eventType int64, jsonMarshallable any)
}
......
......@@ -14,6 +14,7 @@ import (
"encoding/json"
"errors"
"fmt"
"gitlab.com/elixxir/crypto/database"
"os"
"strconv"
"testing"
......@@ -27,7 +28,6 @@ import (
cft "gitlab.com/elixxir/client/v4/channelsFileTransfer"
"gitlab.com/elixxir/client/v4/cmix/rounds"
cryptoBroadcast "gitlab.com/elixxir/crypto/broadcast"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/fileTransfer"
"gitlab.com/elixxir/crypto/message"
"gitlab.com/elixxir/wasm-utils/storage"
......@@ -120,12 +120,12 @@ func TestWasmModel_ReceiveFile(t *testing.T) {
// Happy path, insert message and look it up
func TestWasmModel_GetMessage(t *testing.T) {
cipher, err := cryptoChannel.NewCipher(
cipher, err := database.NewCipher(
[]byte("testPass"), []byte("testSalt"), 128, csprng.NewSystemRNG())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for _, c := range []cryptoChannel.Cipher{nil, cipher} {
for _, c := range []database.Cipher{nil, cipher} {
cs := ""
if c != nil {
cs = "_withCipher"
......@@ -207,12 +207,12 @@ func TestWasmModel_DeleteMessage(t *testing.T) {
// Test wasmModel.UpdateSentStatus happy path and ensure fields don't change.
func Test_wasmModel_UpdateSentStatus(t *testing.T) {
cipher, err := cryptoChannel.NewCipher(
cipher, err := database.NewCipher(
[]byte("testPass"), []byte("testSalt"), 128, csprng.NewSystemRNG())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for _, c := range []cryptoChannel.Cipher{nil, cipher} {
for _, c := range []database.Cipher{nil, cipher} {
cs := ""
if c != nil {
cs = "_withCipher"
......@@ -282,12 +282,12 @@ func Test_wasmModel_UpdateSentStatus(t *testing.T) {
// Smoke test wasmModel.JoinChannel/wasmModel.LeaveChannel happy paths.
func Test_wasmModel_JoinChannel_LeaveChannel(t *testing.T) {
cipher, err := cryptoChannel.NewCipher(
cipher, err := database.NewCipher(
[]byte("testPass"), []byte("testSalt"), 128, csprng.NewSystemRNG())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for _, c := range []cryptoChannel.Cipher{nil, cipher} {
for _, c := range []database.Cipher{nil, cipher} {
cs := ""
if c != nil {
cs = "_withCipher"
......@@ -334,12 +334,12 @@ func Test_wasmModel_JoinChannel_LeaveChannel(t *testing.T) {
// Test UUID gets returned when different messages are added.
func Test_wasmModel_UUIDTest(t *testing.T) {
cipher, err := cryptoChannel.NewCipher(
cipher, err := database.NewCipher(
[]byte("testPass"), []byte("testSalt"), 128, csprng.NewSystemRNG())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for _, c := range []cryptoChannel.Cipher{nil, cipher} {
for _, c := range []database.Cipher{nil, cipher} {
cs := ""
if c != nil {
cs = "_withCipher"
......@@ -381,12 +381,12 @@ func Test_wasmModel_UUIDTest(t *testing.T) {
// Tests if the same message ID being sent always returns the same UUID.
func Test_wasmModel_DuplicateReceives(t *testing.T) {
cipher, err := cryptoChannel.NewCipher(
cipher, err := database.NewCipher(
[]byte("testPass"), []byte("testSalt"), 128, csprng.NewSystemRNG())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for _, c := range []cryptoChannel.Cipher{nil, cipher} {
for _, c := range []database.Cipher{nil, cipher} {
cs := ""
if c != nil {
cs = "_withCipher"
......@@ -428,12 +428,12 @@ func Test_wasmModel_DuplicateReceives(t *testing.T) {
// Happy path: Inserts many messages, deletes some, and checks that the final
// result is as expected.
func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
cipher, err := cryptoChannel.NewCipher(
cipher, err := database.NewCipher(
[]byte("testPass"), []byte("testSalt"), 128, csprng.NewSystemRNG())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for _, c := range []cryptoChannel.Cipher{nil, cipher} {
for _, c := range []database.Cipher{nil, cipher} {
cs := ""
if c != nil {
cs = "_withCipher"
......@@ -501,12 +501,12 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
// This test is designed to prove the behavior of unique indexes.
// Inserts will not fail, they simply will not happen.
func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
cipher, err := cryptoChannel.NewCipher(
cipher, err := database.NewCipher(
[]byte("testPass"), []byte("testSalt"), 128, csprng.NewSystemRNG())
if err != nil {
t.Fatalf("Failed to create cipher")
}
for i, c := range []cryptoChannel.Cipher{nil, cipher} {
for i, c := range []database.Cipher{nil, cipher} {
cs := ""
if c != nil {
cs = "_withCipher"
......
......@@ -11,6 +11,7 @@ package main
import (
"encoding/json"
"gitlab.com/elixxir/crypto/database"
"syscall/js"
"github.com/hack-pad/go-indexeddb/idb"
......@@ -18,7 +19,6 @@ import (
"gitlab.com/elixxir/client/v4/bindings"
"gitlab.com/elixxir/client/v4/channels"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/xxdk-wasm/indexedDb/impl"
)
......@@ -29,13 +29,13 @@ const currentVersion uint = 1
// NewWASMEventModel returns a [channels.EventModel] backed by a wasmModel.
// The name should be a base64 encoding of the users public key. Returns the
// EventModel based on IndexedDb and the database name as reported by IndexedDb.
func NewWASMEventModel(databaseName string, encryption cryptoChannel.Cipher,
func NewWASMEventModel(databaseName string, encryption database.Cipher,
uiCallbacks bindings.ChannelUICallbacks) (channels.EventModel, error) {
return newWASMModel(databaseName, encryption, uiCallbacks)
}
// newWASMModel creates the given [idb.Database] and returns a wasmModel.
func newWASMModel(databaseName string, encryption cryptoChannel.Cipher,
func newWASMModel(databaseName string, encryption database.Cipher,
uiCallbacks bindings.ChannelUICallbacks) (*wasmModel, error) {
// Attempt to open database object
ctx, cancel := impl.NewContext()
......
......@@ -12,12 +12,12 @@ package main
import (
"crypto/ed25519"
"encoding/json"
"gitlab.com/elixxir/crypto/database"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/dm"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/fastRNG"
wDm "gitlab.com/elixxir/xxdk-wasm/indexedDb/worker/dm"
"gitlab.com/elixxir/xxdk-wasm/worker"
......@@ -61,7 +61,7 @@ func (m *manager) newWASMEventModelCB(data []byte) ([]byte, error) {
// Create new encryption cipher
rng := fastRNG.NewStreamGenerator(12, 1024, csprng.NewSystemRNG)
encryption, err := cryptoChannel.NewCipherFromJSON(
encryption, err := database.NewCipherFromJSON(
[]byte(msg.EncryptionJSON), rng.GetStream())
if err != nil {
return []byte{}, errors.Errorf("failed to JSON unmarshal channel "+
......
......@@ -13,6 +13,7 @@ import (
"bytes"
"crypto/ed25519"
"encoding/json"
"gitlab.com/elixxir/crypto/database"
"gitlab.com/xx_network/primitives/netTime"
"strings"
"syscall/js"
......@@ -24,7 +25,6 @@ import (
"gitlab.com/elixxir/client/v4/cmix/rounds"
"gitlab.com/elixxir/client/v4/dm"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/message"
"gitlab.com/elixxir/wasm-utils/utils"
"gitlab.com/elixxir/xxdk-wasm/indexedDb/impl"
......@@ -36,7 +36,7 @@ import (
// caller to ensure that its methods are called sequentially.
type wasmModel struct {
db *idb.Database
cipher cryptoChannel.Cipher
cipher database.Cipher
receivedMessageCB MessageReceivedCallback
}
......
......@@ -11,13 +11,13 @@ package main
import (
"crypto/ed25519"
"gitlab.com/elixxir/crypto/database"
"syscall/js"
"github.com/hack-pad/go-indexeddb/idb"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/dm"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/xxdk-wasm/indexedDb/impl"
)
......@@ -35,13 +35,13 @@ type MessageReceivedCallback func(
// NewWASMEventModel returns a [channels.EventModel] backed by a wasmModel.
// The name should be a base64 encoding of the users public key. Returns the
// EventModel based on IndexedDb and the database name as reported by IndexedDb.
func NewWASMEventModel(databaseName string, encryption cryptoChannel.Cipher,
func NewWASMEventModel(databaseName string, encryption database.Cipher,
cb MessageReceivedCallback) (dm.EventModel, error) {
return newWASMModel(databaseName, encryption, cb)
}
// newWASMModel creates the given [idb.Database] and returns a wasmModel.
func newWASMModel(databaseName string, encryption cryptoChannel.Cipher,
func newWASMModel(databaseName string, encryption database.Cipher,
cb MessageReceivedCallback) (*wasmModel, error) {
// Attempt to open database object
ctx, cancel := impl.NewContext()
......
......@@ -11,6 +11,7 @@ package channels
import (
"encoding/json"
"gitlab.com/elixxir/crypto/database"
"time"
"github.com/pkg/errors"
......@@ -19,7 +20,6 @@ import (
"gitlab.com/elixxir/client/v4/bindings"
"gitlab.com/elixxir/client/v4/channels"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/elixxir/xxdk-wasm/worker"
)
......@@ -36,7 +36,7 @@ type eventUpdateCallback func(eventType int64, jsonData []byte)
// the channel manager to define the path but the callback is the same
// across the board.
func NewWASMEventModelBuilder(wasmJsPath string,
encryption cryptoChannel.Cipher,
encryption database.Cipher,
channelCbs bindings.ChannelUICallbacks) channels.EventModelBuilder {
fn := func(path string) (channels.EventModel, error) {
return NewWASMEventModel(path, wasmJsPath, encryption,
......@@ -54,7 +54,7 @@ type NewWASMEventModelMessage struct {
// NewWASMEventModel returns a [channels.EventModel] backed by a wasmModel.
// The name should be a base64 encoding of the users public key.
func NewWASMEventModel(path, wasmJsPath string, encryption cryptoChannel.Cipher,
func NewWASMEventModel(path, wasmJsPath string, encryption database.Cipher,
channelCbs bindings.ChannelUICallbacks) (
channels.EventModel, error) {
databaseName := path + databaseSuffix
......
......@@ -12,13 +12,13 @@ package dm
import (
"crypto/ed25519"
"encoding/json"
"gitlab.com/elixxir/crypto/database"
"time"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/dm"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/elixxir/xxdk-wasm/worker"
)
......@@ -42,7 +42,7 @@ type NewWASMEventModelMessage struct {
// NewWASMEventModel returns a [channels.EventModel] backed by a wasmModel.
// The name should be a base64 encoding of the users public key.
func NewWASMEventModel(path, wasmJsPath string, encryption cryptoChannel.Cipher,
func NewWASMEventModel(path, wasmJsPath string, encryption database.Cipher,
cb MessageReceivedCallback) (dm.EventModel, error) {
databaseName := path + databaseSuffix
......
......@@ -63,9 +63,9 @@ func Test_ChannelsManagerMethods(t *testing.T) {
// Tests that the map representing ChannelDbCipher returned by
// newChannelDbCipherJS contains all of the methods on ChannelDbCipher.
func Test_newChannelDbCipherJS(t *testing.T) {
cipherType := reflect.TypeOf(&ChannelDbCipher{})
cipherType := reflect.TypeOf(&DbCipher{})
cipher := newChannelDbCipherJS(&bindings.ChannelDbCipher{})
cipher := newDbCipherJS(&bindings.DbCipher{})
if len(cipher) != cipherType.NumMethod() {
t.Errorf("ChannelDbCipher JS object does not have all methods."+
"\nexpected: %d\nreceived: %d", cipherType.NumMethod(), len(cipher))
......@@ -83,8 +83,8 @@ func Test_newChannelDbCipherJS(t *testing.T) {
// Tests that ChannelDbCipher has all the methods that
// [bindings.ChannelDbCipher] has.
func Test_ChannelDbCipherMethods(t *testing.T) {
cipherType := reflect.TypeOf(&ChannelDbCipher{})
binCipherType := reflect.TypeOf(&bindings.ChannelDbCipher{})
cipherType := reflect.TypeOf(&DbCipher{})
binCipherType := reflect.TypeOf(&bindings.DbCipher{})
if binCipherType.NumMethod() != cipherType.NumMethod() {
t.Errorf("WASM ChannelDbCipher object does not have all methods from "+
......
......@@ -68,7 +68,7 @@ func Test_DMClientMethods(t *testing.T) {
func Test_newDMDbCipherJS(t *testing.T) {
cipherType := reflect.TypeOf(&DMDbCipher{})
cipher := newDMDbCipherJS(&bindings.DMDbCipher{})
cipher := newDMDbCipherJS(&bindings.DbCipher{})
if len(cipher) != cipherType.NumMethod() {
t.Errorf("DMDbCipher JS object does not have all methods."+
"\nexpected: %d\nreceived: %d", cipherType.NumMethod(), len(cipher))
......@@ -86,7 +86,7 @@ func Test_newDMDbCipherJS(t *testing.T) {
// Tests that DMDbCipher has all the methods that [bindings.DMDbCipher] has.
func Test_DMDbCipherMethods(t *testing.T) {
cipherType := reflect.TypeOf(&DMDbCipher{})
binCipherType := reflect.TypeOf(&bindings.DMDbCipher{})
binCipherType := reflect.TypeOf(&bindings.DbCipher{})
if binCipherType.NumMethod() != cipherType.NumMethod() {
t.Errorf("WASM DMDbCipher object does not have all methods from "+
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment