Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
3fbb5c16
Commit
3fbb5c16
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
added optional db encryption
parent
dfdaa0f4
No related branches found
No related tags found
3 merge requests
!60
Revert "Fail a test to be sure it works"
,
!21
added optional db encryption
,
!20
Create JS bindings for ChannelDbCipher
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
indexedDb/implementation.go
+11
-0
11 additions, 0 deletions
indexedDb/implementation.go
indexedDb/init.go
+12
-8
12 additions, 8 deletions
indexedDb/init.go
with
23 additions
and
8 deletions
indexedDb/implementation.go
+
11
−
0
View file @
3fbb5c16
...
...
@@ -39,6 +39,7 @@ const dbTimeout = time.Second
// channel.
type
wasmModel
struct
{
db
*
idb
.
Database
cipher
cryptoChannel
.
Cipher
receivedMessageCB
MessageReceivedCallback
updateMux
sync
.
Mutex
}
...
...
@@ -206,6 +207,16 @@ func (w *wasmModel) ReceiveMessage(channelID *id.ID,
timestamp
time
.
Time
,
lease
time
.
Duration
,
round
rounds
.
Round
,
mType
channels
.
MessageType
,
status
channels
.
SentStatus
)
uint64
{
// Handle encryption, if it is present
if
w
.
cipher
!=
nil
{
cipherText
,
err
:=
w
.
cipher
.
Encrypt
([]
byte
(
text
))
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to encrypt Message: %+v"
,
err
)
return
0
}
text
=
string
(
cipherText
)
}
msgToInsert
:=
buildMessage
(
channelID
.
Marshal
(),
messageID
.
Bytes
(),
nil
,
nickname
,
text
,
pubKey
,
codeset
,
timestamp
,
lease
,
round
.
ID
,
mType
,
status
)
...
...
This diff is collapsed.
Click to expand it.
indexedDb/init.go
+
12
−
8
View file @
3fbb5c16
...
...
@@ -10,6 +10,7 @@
package
indexedDb
import
(
cryptoChannel
"gitlab.com/elixxir/crypto/channel"
"syscall/js"
"github.com/hack-pad/go-indexeddb/idb"
...
...
@@ -37,25 +38,25 @@ type MessageReceivedCallback func(uuid uint64, channelID *id.ID, update bool)
// NewWASMEventModelBuilder returns an EventModelBuilder which allows
// the channel manager to define the path but the callback is the same
// across the board.
func
NewWASMEventModelBuilder
(
func
NewWASMEventModelBuilder
(
encryption
cryptoChannel
.
Cipher
,
cb
MessageReceivedCallback
)
channels
.
EventModelBuilder
{
fn
:=
func
(
path
string
)
(
channels
.
EventModel
,
error
)
{
return
NewWASMEventModel
(
path
,
cb
)
return
NewWASMEventModel
(
path
,
encryption
,
cb
)
}
return
fn
}
// NewWASMEventModel returns a [channels.EventModel] backed by a wasmModel.
// The name should be a base64 encoding of the users public key.
func
NewWASMEventModel
(
path
string
,
cb
MessageReceivedCallback
)
(
channels
.
EventModel
,
error
)
{
func
NewWASMEventModel
(
path
string
,
encryption
cryptoChannel
.
Cipher
,
cb
MessageReceivedCallback
)
(
channels
.
EventModel
,
error
)
{
databaseName
:=
path
+
databaseSuffix
return
newWASMModel
(
databaseName
,
cb
)
return
newWASMModel
(
databaseName
,
encryption
,
cb
)
}
// newWASMModel creates the given [idb.Database] and returns a wasmModel.
func
newWASMModel
(
databaseName
string
,
cb
MessageReceivedCallback
)
(
*
wasmModel
,
error
)
{
func
newWASMModel
(
databaseName
string
,
encryption
cryptoChannel
.
Cipher
,
cb
MessageReceivedCallback
)
(
*
wasmModel
,
error
)
{
// Attempt to open database object
ctx
,
cancel
:=
newContext
()
defer
cancel
()
...
...
@@ -88,7 +89,10 @@ func newWASMModel(databaseName string, cb MessageReceivedCallback) (
// Wait for database open to finish
db
,
err
:=
openRequest
.
Await
(
ctx
)
return
&
wasmModel
{
db
:
db
,
receivedMessageCB
:
cb
},
err
if
encryption
==
nil
{
jww
.
WARN
.
Printf
(
"IndexedDb encryption disabled!"
)
}
return
&
wasmModel
{
db
:
db
,
receivedMessageCB
:
cb
,
cipher
:
encryption
},
err
}
// v1Upgrade performs the v0 -> v1 database upgrade.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment