Skip to content

Commit

Permalink
sdk: allow empty bio in UserBio by adding updatedAt field (#956)
Browse files Browse the repository at this point in the history
Without the `updated_at` field, protobuf with empty bio field was
failing to encrypt.
  • Loading branch information
miguel-nascimento authored Sep 4, 2024
1 parent 9133f8d commit bc3901d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/sdk/src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,4 +1066,24 @@ describe('clientTest', () => {
const decrypted = await bobsClient.getUserBio(bobsClient.userId)
expect(decrypted).toStrictEqual(bio)
})

test('setUserBio empty', async () => {
await expect(await bobsClient.initializeUser()).toResolve()
bobsClient.startSync()
const streamId = bobsClient.userMetadataStreamId!
const userMetadataStream = await bobsClient.waitForStream(streamId)

expect(userMetadataStream).toBeDefined()
expect(
userMetadataStream.view.snapshot?.content.case === 'userMetadataContent' &&
userMetadataStream.view.snapshot?.content.value.profileImage === undefined,
).toBe(true)

const bio = new UserBio({ bio: '' })
const { eventId } = await bobsClient.setUserBio(bio)
expect(await waitFor(() => userMetadataStream.view.events.has(eventId))).toBe(true)

const decrypted = await bobsClient.getUserBio(bobsClient.userId)
expect(decrypted).toStrictEqual(bio)
})
})
1 change: 1 addition & 0 deletions packages/sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ export class Client
// encrypt the chunked media
// use the lowercased userId as the key phrase
const { key, iv } = await deriveKeyAndIV(context)
bio.updatedAtEpochMs = BigInt(Date.now())
const bioBinary = bio.toBinary()
const { ciphertext } = await encryptAESGCM(bioBinary, key, iv)
const encryptedData = new EncryptedData({
Expand Down
1 change: 1 addition & 0 deletions protocol/payloads.proto
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ message ChunkedMedia {

message UserBio {
string bio = 1;
optional uint64 updated_at_epoch_ms = 2;
}

// a client created with an bearer token cannot make blockchain transactions, but can add events to the river nodes
Expand Down

0 comments on commit bc3901d

Please sign in to comment.