Skip to content

Commit

Permalink
Merge pull request #124 from xmtp/jazzz/revert-bundle-versioning
Browse files Browse the repository at this point in the history
Revert "Merge pull request #121 from xmtp/jazzz/bundle-versioning"
  • Loading branch information
jazzz authored Jun 30, 2022
2 parents 3ad719a + cc2df01 commit 959e288
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 400 deletions.
9 changes: 3 additions & 6 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import { decompress, compress } from './Compression'
import { Compression } from './proto/messaging'
import * as proto from './proto/messaging'
import ContactBundle from './ContactBundle'

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down Expand Up @@ -196,12 +195,10 @@ export default class Client {
callback: (msgs: WakuMessage[]) => {
for (const msg of msgs) {
if (!msg.payload) continue
const bundle = ContactBundle.fromBytes(msg.payload as Uint8Array)
const keyBundle = bundle.keyBundle

const address = keyBundle?.walletSignatureAddress()
const bundle = PublicKeyBundle.fromBytes(msg.payload as Uint8Array)
const address = bundle.walletSignatureAddress()
if (address === peerAddress) {
recipientKey = keyBundle
recipientKey = bundle
break
}
}
Expand Down
39 changes: 0 additions & 39 deletions src/ContactBundle.ts

This file was deleted.

30 changes: 13 additions & 17 deletions src/crypto/PrivateKeyBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { NoMatchingPreKeyError } from './errors'
// PrivateKeyBundle bundles the private keys corresponding to a PublicKeyBundle for convenience.
// This bundle must not be shared with anyone, although will have to be persisted
// somehow so that older messages can be decrypted again.
export default class PrivateKeyBundle implements proto.PrivateKeyBundleV1 {
export default class PrivateKeyBundle implements proto.PrivateKeyBundle {
identityKey: PrivateKey
preKeys: PrivateKey[]

Expand Down Expand Up @@ -121,21 +121,17 @@ export default class PrivateKeyBundle implements proto.PrivateKeyBundleV1 {
throw new Error('missing identity key')
}
const bytes = proto.PrivateKeyBundle.encode({
v1: {
identityKey: this.identityKey,
preKeys: this.preKeys,
},
identityKey: this.identityKey,
preKeys: this.preKeys,
}).finish()
const wPreKey = getRandomValues(new Uint8Array(32))
const secret = hexToBytes(
await wallet.signMessage(PrivateKeyBundle.storageSigRequestText(wPreKey))
)
const ciphertext = await encrypt(bytes, secret)
return proto.EncryptedPrivateKeyBundle.encode({
v1: {
walletPreKey: wPreKey,
ciphertext,
},
walletPreKey: wPreKey,
ciphertext,
}).finish()
}

Expand All @@ -145,29 +141,29 @@ export default class PrivateKeyBundle implements proto.PrivateKeyBundleV1 {
bytes: Uint8Array
): Promise<PrivateKeyBundle> {
const encrypted = proto.EncryptedPrivateKeyBundle.decode(bytes)
if (!encrypted.v1?.walletPreKey) {
if (!encrypted.walletPreKey) {
throw new Error('missing wallet pre-key')
}
const secret = hexToBytes(
await wallet.signMessage(
PrivateKeyBundle.storageSigRequestText(encrypted.v1.walletPreKey)
PrivateKeyBundle.storageSigRequestText(encrypted.walletPreKey)
)
)
if (!encrypted.v1?.ciphertext?.aes256GcmHkdfSha256) {
if (!encrypted.ciphertext?.aes256GcmHkdfSha256) {
throw new Error('missing bundle ciphertext')
}
const ciphertext = new Ciphertext(encrypted.v1.ciphertext)
const ciphertext = new Ciphertext(encrypted.ciphertext)
const decrypted = await decrypt(ciphertext, secret)
const bundle = proto.PrivateKeyBundle.decode(decrypted)
if (!bundle.v1?.identityKey) {
if (!bundle.identityKey) {
throw new Error('missing identity key')
}
if (bundle.v1?.preKeys.length === 0) {
if (bundle.preKeys.length === 0) {
throw new Error('missing pre-keys')
}
return new PrivateKeyBundle(
new PrivateKey(bundle.v1.identityKey),
bundle.v1.preKeys.map((protoKey) => new PrivateKey(protoKey))
new PrivateKey(bundle.identityKey),
bundle.preKeys.map((protoKey) => new PrivateKey(protoKey))
)
}
}
10 changes: 0 additions & 10 deletions src/proto/messaging.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ message PublicKeyBundle {
PublicKey preKey = 2;
}

message ContactBundleV1 {
PublicKeyBundle keyBundle = 1;
}

message ContactBundle {
oneof version {
ContactBundleV1 v1 = 1;
}
}

// ContentTypeId is used to identify the type of content stored in a Message.
message ContentTypeId {
string authorityId = 1; // authority governing this content type
Expand Down
131 changes: 0 additions & 131 deletions src/proto/messaging.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 2 additions & 14 deletions src/proto/private_key.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,12 @@ message PrivateKey {
PublicKey publicKey = 3;
}

message PrivateKeyBundleV1 {
message PrivateKeyBundle {
PrivateKey identityKey = 1;
repeated PrivateKey preKeys = 2;
}

message PrivateKeyBundle {
oneof version {
PrivateKeyBundleV1 v1 = 1;
}
}

message EncryptedPrivateKeyBundleV1 {
message EncryptedPrivateKeyBundle {
bytes walletPreKey = 1;
Ciphertext ciphertext = 2;
}

message EncryptedPrivateKeyBundle {
oneof version {
EncryptedPrivateKeyBundleV1 v1 = 1;
}
}
Loading

0 comments on commit 959e288

Please sign in to comment.