Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protocol and snapshot changes for public chunked media #468

Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0f89629
move media defintiion from payloads.proto to protocol.proto. Also add…
tak-hntlabs Jul 24, 2024
21552e1
apply the snapshot in the sdk
tak-hntlabs Jul 24, 2024
e730ef4
space snapshot on the go side
tak-hntlabs Jul 24, 2024
965a0b4
crypto-utils
tak-hntlabs Jul 24, 2024
2f3fb42
Uint8Array
tak-hntlabs Jul 24, 2024
b8fc967
decryptAesGcm return value as Uint8Array
tak-hntlabs Jul 24, 2024
579aa55
extend key material
tak-hntlabs Jul 25, 2024
bd68b1b
test cases to download encrypted media
tak-hntlabs Jul 25, 2024
52c0332
merge latest main
tak-hntlabs Jul 25, 2024
1f1feff
test case for go-seide snapshot
tak-hntlabs Jul 25, 2024
848d9dc
can add event if entitled
tak-hntlabs Jul 26, 2024
50c3cf0
make spaceImage helper
tak-hntlabs Jul 26, 2024
24ac0c4
client.setImage
tak-hntlabs Jul 26, 2024
fe2ddaa
spaceImage snapshot test
tak-hntlabs Jul 26, 2024
33a6158
remove unused imports
tak-hntlabs Jul 26, 2024
bde94b9
add deriveKeyAndIV test
tak-hntlabs Jul 26, 2024
56f624c
delete unwanted file
tak-hntlabs Jul 26, 2024
3e96c56
remove whitespace
tak-hntlabs Jul 26, 2024
18240ae
fix test name
tak-hntlabs Jul 26, 2024
6b52fd3
add seedphrase to the DerivedAESGCM struct
tak-hntlabs Jul 26, 2024
cbcfa1f
make this as similar as possible with the browser implementation
tak-hntlabs Jul 27, 2024
6a33fc3
change seedPhrase to string
tak-hntlabs Jul 28, 2024
1e541cd
handle seedPhrase as contract Id string
tak-hntlabs Jul 28, 2024
ccd9144
fix crypto_utils to be as similar as possible with browser implementa…
tak-hntlabs Jul 28, 2024
569f9c3
Merge branch 'main' into tak/hnt-10653-protocolproto-and-sdk-changes-…
tak-hntlabs Jul 29, 2024
3edc33e
Merge branch 'main' into tak/hnt-10653-protocolproto-and-sdk-changes-…
tak-hntlabs Jul 29, 2024
967019a
remove seedPhrase from DerivedAESGCM
tak-hntlabs Jul 29, 2024
d081e60
remove unused arg
tak-hntlabs Jul 29, 2024
56826ad
redfine SpaceImage type from ChunkedMedia to EncryptedData
tak-hntlabs Jul 30, 2024
355c876
Merge branch 'main' into tak/hnt-10653-protocolproto-and-sdk-changes-…
tak-hntlabs Jul 30, 2024
2ff4f6a
move ChunkedMedia/MediaInfo/EmbeddedMedia back to payload. Add Derive…
tak-hntlabs Jul 30, 2024
b93c4e1
Merge branch 'main' into tak/hnt-10653-protocolproto-and-sdk-changes-…
tak-hntlabs Jul 30, 2024
f9475a8
add only changed parts to payload.proto. Revert the res
tak-hntlabs Jul 30, 2024
673a554
fix comment
tak-hntlabs Jul 30, 2024
edf2c15
remove unused argument
tak-hntlabs Jul 30, 2024
0245026
remove unused function
tak-hntlabs Jul 30, 2024
3d1cd69
delete unused makeMediaStreamIdFromSpaceId
tak-hntlabs Jul 30, 2024
bcc39a3
move isEncryptedData to util.test
tak-hntlabs Jul 30, 2024
ac1491d
Merge branch 'main' into tak/hnt-10653-protocolproto-and-sdk-changes-…
tak-hntlabs Jul 30, 2024
a5062a5
prettier
tak-hntlabs Jul 31, 2024
aad008b
Merge branch 'main' into tak/hnt-10653-protocolproto-and-sdk-changes-…
tak-hntlabs Jul 31, 2024
e0020f3
renamed fieldname from 'space_image' to 'data'
tak-hntlabs Jul 31, 2024
cfc50a1
rename space image names
tak-hntlabs Jul 31, 2024
52fd989
Merge branch 'main' into tak/hnt-10653-protocolproto-and-sdk-changes-…
tak-hntlabs Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/node/crypto/encrypt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package crypto

const (
AES_GCM_DERIVED_ALGORITHM = "r.aes-256-gcm.derived"
)
tak-hntlabs marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions core/node/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ func Make_SpacePayload_Membership(op MembershipOp, userId string, initiatorId st
return Make_MemberPayload_Membership(op, userAddress, initiatorAddress, nil)
}

func Make_SpacePayload_SpaceImage(
ciphertext string,
) *StreamEvent_SpacePayload {
encryptedData := &EncryptedData{
Ciphertext: ciphertext,
Algorithm: crypto.AES_GCM_DERIVED_ALGORITHM,
}
return &StreamEvent_SpacePayload{
SpacePayload: &SpacePayload{
Content: &SpacePayload_SpaceImage{
SpaceImage: encryptedData,
},
},
}
}

func Make_SpacePayload_ChannelUpdate(
op ChannelOp,
channelId StreamId,
Expand Down
16 changes: 13 additions & 3 deletions core/node/events/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func Update_Snapshot(iSnapshot *Snapshot, event *ParsedEvent, miniblockNum int64
iSnapshot = migrations.MigrateSnapshot(iSnapshot)
switch payload := event.Event.Payload.(type) {
case *StreamEvent_SpacePayload:
return update_Snapshot_Space(iSnapshot, payload.SpacePayload, eventNum)
return update_Snapshot_Space(iSnapshot, payload.SpacePayload, event.Event.CreatorAddress, eventNum)
case *StreamEvent_ChannelPayload:
return update_Snapshot_Channel(iSnapshot, payload.ChannelPayload)
case *StreamEvent_DmChannelPayload:
Expand All @@ -182,7 +182,12 @@ func Update_Snapshot(iSnapshot *Snapshot, event *ParsedEvent, miniblockNum int64
}
}

func update_Snapshot_Space(iSnapshot *Snapshot, spacePayload *SpacePayload, eventNum int64) error {
func update_Snapshot_Space(
iSnapshot *Snapshot,
spacePayload *SpacePayload,
creatorAddress []byte,
eventNum int64,
) error {
snapshot := iSnapshot.Content.(*Snapshot_SpaceContent)
if snapshot == nil {
return RiverError(Err_INVALID_ARGUMENT, "blockheader snapshot is not a space snapshot")
Expand All @@ -199,6 +204,12 @@ func update_Snapshot_Space(iSnapshot *Snapshot, spacePayload *SpacePayload, even
}
snapshot.SpaceContent.Channels = insertChannel(snapshot.SpaceContent.Channels, channel)
return nil
case *SpacePayload_SpaceImage:
snapshot.SpaceContent.SpaceMedia = &SpacePayload_SnappedSpaceMedia{
Data: content.SpaceImage,
CreatorAddress: creatorAddress,
}
return nil
default:
return RiverError(Err_INVALID_ARGUMENT, "unknown space payload type %T", spacePayload.Content)
}
Expand Down Expand Up @@ -487,7 +498,6 @@ func update_Snapshot_Member(
}
snapshot.Pins = snapPins
return nil

default:
return RiverError(Err_INVALID_ARGUMENT, "unknown membership payload type %T", memberPayload.Content)
}
Expand Down
34 changes: 33 additions & 1 deletion core/node/events/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ func make_Space_Membership(
return parsed
}

func make_Space_Image(
wallet *crypto.Wallet,
ciphertext string,
prevMiniblockHash []byte,
t *testing.T,
) *ParsedEvent {
envelope, err := MakeEnvelopeWithPayload(
wallet,
Make_SpacePayload_SpaceImage(
ciphertext,
),
prevMiniblockHash,
)
assert.NoError(t, err)
parsed, err := ParseEvent(envelope)
assert.NoError(t, err)
return parsed
}

func make_Space_Username(wallet *crypto.Wallet, username string, prevHash []byte, t *testing.T) *ParsedEvent {
envelope, err := MakeEnvelopeWithPayload(
wallet,
Expand Down Expand Up @@ -197,7 +216,9 @@ func TestCloneAndUpdateSpaceSnapshot(t *testing.T) {
membership := make_Space_Membership(wallet, MembershipOp_SO_JOIN, userId, nil, t)
username := make_Space_Username(wallet, "bob", nil, t)
displayName := make_Space_DisplayName(wallet, "bobIsTheGreatest", nil, t)
events := []*ParsedEvent{membership, username, displayName}
imageCipertext := "space_image_ciphertext"
image := make_Space_Image(wallet, imageCipertext, nil, t)
events := []*ParsedEvent{membership, username, displayName, image}
for i, event := range events[:] {
err = Update_Snapshot(snapshot, event, 1, int64(3+i))
assert.NoError(t, err)
Expand Down Expand Up @@ -231,6 +252,17 @@ func TestCloneAndUpdateSpaceSnapshot(t *testing.T) {
int64(5),
member.DisplayName.EventNum,
)

assert.Equal(
t,
imageCipertext,
snapshot.Content.(*Snapshot_SpaceContent).SpaceContent.SpaceMedia.Data.Ciphertext,
)
assert.Equal(
t,
crypto.AES_GCM_DERIVED_ALGORITHM,
snapshot.Content.(*Snapshot_SpaceContent).SpaceContent.SpaceMedia.Data.Algorithm,
)
}

func TestUpdateSnapshotFailsIfInception(t *testing.T) {
Expand Down
Loading
Loading