Skip to content

Commit 77640ad

Browse files
committed
Merge branch 'main' into negotiated-topic-invitation-class
2 parents a0cb4e0 + 3659a35 commit 77640ad

8 files changed

+24
-19
lines changed

src/Client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from './MessageContent'
2525
import { decompress, compress } from './Compression'
2626
import { xmtpEnvelope, messageApi, fetcher } from '@xmtp/proto'
27-
import { DecodeContactBundle } from './ContactBundle'
27+
import { decodeContactBundle } from './ContactBundle'
2828
import ApiClient, { SortDirection } from './ApiClient'
2929
import { Authenticator } from './authn'
3030
const { Compression } = xmtpEnvelope
@@ -565,7 +565,7 @@ async function getUserContactFromNetwork(
565565

566566
for await (const env of stream) {
567567
if (!env.message) continue
568-
const bundle = DecodeContactBundle(b64Decode(env.message.toString()))
568+
const bundle = decodeContactBundle(b64Decode(env.message.toString()))
569569
const keyBundle = bundle.keyBundle
570570

571571
const address = keyBundle?.walletSignatureAddress()

src/ContactBundle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class ContactBundleV2 implements contact.ContactBundleV2 {
5555
export type ContactBundle = ContactBundleV1 | ContactBundleV2
5656

5757
// This is the primary function for reading contact bundles off the wire.
58-
export function DecodeContactBundle(bytes: Uint8Array): ContactBundle {
58+
export function decodeContactBundle(bytes: Uint8Array): ContactBundle {
5959
let cb: contact.ContactBundle
6060
try {
6161
cb = contact.ContactBundle.decode(bytes)

src/crypto/PrivateKeyBundle.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { NoMatchingPreKeyError } from './errors'
1212
export class PrivateKeyBundleV2 implements proto.PrivateKeyBundleV2 {
1313
identityKey: SignedPrivateKey
1414
preKeys: SignedPrivateKey[]
15+
version = 2
1516

1617
constructor(bundle: proto.PrivateKeyBundleV2) {
1718
if (!bundle.identityKey) {
@@ -132,6 +133,7 @@ export class PrivateKeyBundleV2 implements proto.PrivateKeyBundleV2 {
132133
export class PrivateKeyBundleV1 implements proto.PrivateKeyBundleV1 {
133134
identityKey: PrivateKey
134135
preKeys: PrivateKey[]
136+
version = 1
135137

136138
constructor(bundle: proto.PrivateKeyBundleV1) {
137139
if (!bundle.identityKey) {
@@ -229,7 +231,7 @@ export class PrivateKeyBundleV1 implements proto.PrivateKeyBundleV1 {
229231

230232
export type PrivateKeyBundle = PrivateKeyBundleV1 | PrivateKeyBundleV2
231233

232-
export function DecodePrivateKeyBundle(bytes: Uint8Array): PrivateKeyBundle {
234+
export function decodePrivateKeyBundle(bytes: Uint8Array): PrivateKeyBundle {
233235
const b = proto.PrivateKeyBundle.decode(bytes)
234236
if (b.v1) {
235237
return new PrivateKeyBundleV1(b.v1)

src/crypto/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
PrivateKeyBundleV1,
55
PrivateKeyBundleV2,
66
PrivateKeyBundle,
7-
DecodePrivateKeyBundle,
7+
decodePrivateKeyBundle,
88
} from './PrivateKeyBundle'
99
import { UnsignedPublicKey, SignedPublicKey, PublicKey } from './PublicKey'
1010
import Signature, { WalletSigner } from './Signature'
@@ -23,7 +23,7 @@ export {
2323
PrivateKey,
2424
SignedPrivateKey,
2525
PrivateKeyBundle,
26-
DecodePrivateKeyBundle,
26+
decodePrivateKeyBundle,
2727
PrivateKeyBundleV1,
2828
PrivateKeyBundleV2,
2929
Signature,

src/store/EncryptedStore.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Store } from './Store'
22
import { Signer } from 'ethers'
33
import {
44
PrivateKeyBundleV1,
5-
DecodePrivateKeyBundle,
5+
decodePrivateKeyBundle,
66
decrypt,
77
encrypt,
88
} from '../crypto'
@@ -129,7 +129,8 @@ function getEncryptedBundle(
129129
// to decode the bundle as a legacy bundle. Additionally return whether the bundle is in the expected format.
130130
function getPrivateBundle(bytes: Uint8Array): [PrivateKeyBundleV1, boolean] {
131131
try {
132-
const b = DecodePrivateKeyBundle(bytes) as PrivateKeyBundleV1
132+
// TODO: add support for V2
133+
const b = decodePrivateKeyBundle(bytes) as PrivateKeyBundleV1
133134
return [b, false]
134135
} catch (e) {
135136
// Adds a default fallback for older versions of the proto

src/store/StaticKeyStore.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
DecodePrivateKeyBundle,
2+
decodePrivateKeyBundle,
33
PrivateKeyBundleV1,
44
} from '../crypto/PrivateKeyBundle'
55
import { KeyStore } from './KeyStore'
@@ -11,7 +11,8 @@ export default class StaticKeyStore implements KeyStore {
1111
}
1212

1313
async loadPrivateKeyBundle(): Promise<PrivateKeyBundleV1> {
14-
return DecodePrivateKeyBundle(this.value) as PrivateKeyBundleV1
14+
// TODO: add support for V2
15+
return decodePrivateKeyBundle(this.value) as PrivateKeyBundleV1
1516
}
1617

1718
async storePrivateKeyBundle(): Promise<void> {

test/ContactBundle.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as assert from 'assert'
22
import {
33
ContactBundleV1,
44
ContactBundleV2,
5-
DecodeContactBundle,
5+
decodeContactBundle,
66
} from '../src/ContactBundle'
77
import {
88
PrivateKeyBundleV1,
@@ -18,13 +18,13 @@ describe('ContactBundles', function () {
1818
const priv = await PrivateKeyBundleV1.generate()
1919
const pub = priv.getPublicKeyBundle()
2020
let bytes = pub.toBytes()
21-
const cb = DecodeContactBundle(bytes)
21+
const cb = decodeContactBundle(bytes)
2222
expect(cb.keyBundle).toBeInstanceOf(PublicKeyBundle)
2323
assert.ok(pub.equals(cb.keyBundle as PublicKeyBundle))
2424

2525
const cb1 = new ContactBundleV1({ keyBundle: priv.getPublicKeyBundle() })
2626
bytes = cb1.toBytes()
27-
const cb2 = DecodeContactBundle(bytes)
27+
const cb2 = decodeContactBundle(bytes)
2828
expect(cb2.keyBundle).toBeInstanceOf(PublicKeyBundle)
2929
assert.ok(pub.equals(cb2.keyBundle as PublicKeyBundle))
3030

@@ -37,7 +37,7 @@ describe('ContactBundles', function () {
3737
const pub = priv.getPublicKeyBundle()
3838
const cb1 = new ContactBundleV2({ keyBundle: priv.getPublicKeyBundle() })
3939
let bytes = cb1.toBytes()
40-
const cb2 = DecodeContactBundle(bytes)
40+
const cb2 = decodeContactBundle(bytes)
4141
expect(cb2.keyBundle).toBeInstanceOf(SignedPublicKeyBundle)
4242
assert.ok(pub.equals(cb2.keyBundle as SignedPublicKeyBundle))
4343

test/crypto/PrivateKeyBundle.test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as assert from 'assert'
22
import {
3-
DecodePrivateKeyBundle,
3+
decodePrivateKeyBundle,
44
PrivateKey,
55
PrivateKeyBundleV1,
66
PrivateKeyBundleV2,
@@ -12,7 +12,7 @@ import {
1212
} from '../../src/store'
1313
import { hexToBytes } from '../../src/crypto/utils'
1414
import { newWallet } from '../helpers'
15-
import { DecodeContactBundle } from '../../src/ContactBundle'
15+
import { decodeContactBundle } from '../../src/ContactBundle'
1616

1717
describe('Crypto', function () {
1818
describe('PrivateKeyBundle', function () {
@@ -21,10 +21,11 @@ describe('Crypto', function () {
2121
// generate key bundle
2222
const bundle = await PrivateKeyBundleV2.generate(wallet)
2323
const bytes = bundle.encode()
24-
const bundle2 = DecodePrivateKeyBundle(bytes)
24+
const bundle2 = decodePrivateKeyBundle(bytes)
2525
expect(bundle2).toBeInstanceOf(PrivateKeyBundleV2)
26-
assert.ok(bundle.equals(bundle2 as PrivateKeyBundleV2))
27-
assert.ok(
26+
expect(bundle2.version).toBe(2)
27+
expect(bundle.equals(bundle2 as PrivateKeyBundleV2))
28+
expect(
2829
bundle
2930
.getPublicKeyBundle()
3031
.equals((bundle2 as PrivateKeyBundleV2).getPublicKeyBundle())

0 commit comments

Comments
 (0)