Skip to content

Commit 6dc3c56

Browse files
committed
new version
1 parent 864ad62 commit 6dc3c56

4 files changed

Lines changed: 69 additions & 51 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@relaycc/xmtp-js",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "The XMTP client SDK for interacting with XMTP networks, with minor additions and modifications from the Relay team.",
55
"main": "dist/cjs/src/index.js",
66
"module": "dist/esm/src/index.js",

src/crypto/PrivateKeyBundle.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ export class PrivateKeyBundleV1 implements proto.PrivateKeyBundleV1 {
176176
const fixPrivateKey = (privateKey: proto.PrivateKey) => {
177177
if (privateKey.secp256k1) {
178178
if (
179-
!((privateKey.timestamp as any) instanceof Long) &&
179+
!((privateKey.timestamp as unknown) instanceof Long) &&
180180
privateKey.timestamp !== undefined
181181
) {
182+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
182183
privateKey.timestamp = Long.fromValue(privateKey.timestamp as any)
183184
}
184185
if (typeof privateKey.secp256k1.bytes === 'object') {
@@ -197,10 +198,11 @@ export class PrivateKeyBundleV1 implements proto.PrivateKeyBundleV1 {
197198
)
198199
}
199200
if (
200-
!((privateKey.publicKey.timestamp as any) instanceof Long) &&
201+
!((privateKey.publicKey.timestamp as unknown) instanceof Long) &&
201202
privateKey.publicKey.timestamp !== undefined
202203
) {
203204
privateKey.publicKey.timestamp = Long.fromValue(
205+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
204206
privateKey.publicKey.timestamp as any
205207
)
206208
}

test/Performance.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Performance', () => {
3131
'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
3232
)
3333
})
34-
34+
/*
3535
it('Fetch one conversation', async () => {
3636
const wallet = new Wallet(process.env.RELAYCC_TEST_PK as string)
3737
const client = await Client.create(wallet)
@@ -45,13 +45,13 @@ describe('Performance', () => {
4545
limit: 1,
4646
})
4747
})
48-
48+
*/
4949
it('List conversations', async () => {
5050
const wallet = new Wallet(process.env.RELAYCC_TEST_PK as string)
5151
const client = await Client.create(wallet)
5252
await client.conversations.list()
5353
})
54-
54+
/*
5555
it('Sends a message to itself', async () => {
5656
const wallet = new Wallet(process.env.RELAYCC_TEST_PK as string)
5757
const client = await Client.create(wallet)
@@ -104,6 +104,8 @@ describe('Performance', () => {
104104
const result = await Promise.all(requests)
105105
console.log(result)
106106
})
107+
108+
*/
107109
})
108110

109111
function getAddress() {

test/conversations/Conversation.test.ts

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,36 @@ import {
22
ConversationV1,
33
decodeMessageV1,
44
decodeMessageV2,
5-
encodeMessageV1, encodeMessageV2
6-
} from "./../../src/conversations/Conversation";
7-
import { DecodedMessage, DecodedMessageExport, MessageV1 } from "./../../src/Message";
8-
import { buildDirectMessageTopic, buildUserIntroTopic } from "../../src/utils";
5+
encodeMessageV1,
6+
encodeMessageV2,
7+
} from './../../src/conversations/Conversation'
8+
import {
9+
DecodedMessage,
10+
DecodedMessageExport,
11+
MessageV1,
12+
} from './../../src/Message'
13+
import { buildDirectMessageTopic, buildUserIntroTopic } from '../../src/utils'
914
import {
1015
Client,
1116
Compression,
1217
ContentTypeFallback,
1318
ContentTypeId,
14-
ContentTypeText, PublicKeyBundle, TextCodec
15-
} from "../../src";
16-
import { SortDirection } from "../../src"
19+
ContentTypeText,
20+
PublicKeyBundle,
21+
TextCodec,
22+
} from '../../src'
23+
import { SortDirection } from '../../src'
1724
import { sleep } from '../../src/utils'
1825
import { newLocalHostClient, newWallet, waitForUserContact } from '../helpers'
1926
import {
2027
PrivateKey,
2128
PrivateKeyBundleV1,
2229
SignedPublicKeyBundle,
2330
} from '../../src/crypto'
24-
import { ConversationV2 } from "../../src/conversations"
31+
import { ConversationV2 } from '../../src/conversations'
2532
import { ContentTypeTestKey, TestKeyCodec } from '../ContentTypeTestKey'
2633
import { content as proto, fetcher } from '@xmtp/proto'
27-
import Stream from "../../src/Stream";
34+
import Stream from '../../src/Stream'
2835

2936
describe('conversation', () => {
3037
let alice: Client
@@ -668,8 +675,8 @@ describe('conversation', () => {
668675

669676
describe('encode/decode is classless on V1', () => {
670677
beforeEach(async () => {
671-
alice = await newLocalHostClient({publishLegacyContact: true})
672-
bob = await newLocalHostClient({publishLegacyContact: true})
678+
alice = await newLocalHostClient({ publishLegacyContact: true })
679+
bob = await newLocalHostClient({ publishLegacyContact: true })
673680
await waitForUserContact(alice, alice)
674681
await waitForUserContact(bob, bob)
675682
})
@@ -682,22 +689,26 @@ describe('conversation', () => {
682689
alice.address
683690
)
684691
const baseCodecs = {
685-
[`${ContentTypeText.authorityId}/${ContentTypeText.typeId}`]: new TextCodec(),
692+
[`${ContentTypeText.authorityId}/${ContentTypeText.typeId}`]:
693+
new TextCodec(),
686694
}
687695

688696
const stream = await Stream.create<DecodedMessageExport>(
689697
aliceConversation.getClient(),
690698
[aliceConversation.topic],
691699
async (e) => {
692700
const convo = deepcopy(aliceConversation.export())
693-
if(convo.version !== 'v1') {
701+
if (convo.version !== 'v1') {
694702
throw new Error('unexpected convo version')
695703
}
696704
const keys = deepcopy(aliceConversation.getClient().legacyKeys)
697705
return await decodeMessageV1(
698706
e,
699707
convo,
700-
{codecFor: (c: ContentTypeId) => baseCodecs[`${c.authorityId}/${c.typeId}`]},
708+
{
709+
codecFor: (c: ContentTypeId) =>
710+
baseCodecs[`${c.authorityId}/${c.typeId}`],
711+
},
701712
keys
702713
)
703714
}
@@ -724,21 +735,28 @@ describe('conversation', () => {
724735
alice.address
725736
)
726737
const baseCodecs = {
727-
[`${ContentTypeText.authorityId}/${ContentTypeText.typeId}`]: new TextCodec(),
738+
[`${ContentTypeText.authorityId}/${ContentTypeText.typeId}`]:
739+
new TextCodec(),
728740
}
729741

730742
await sleep(100)
731743

732744
let topics: string[]
733-
let recipient = await bobConversation.getClient().getUserContact(bobConversation.peerAddress)
745+
let recipient = await bobConversation
746+
.getClient()
747+
.getUserContact(bobConversation.peerAddress)
734748
if (!recipient) {
735-
throw new Error(`recipient ${bobConversation.peerAddress} is not registered`)
749+
throw new Error(
750+
`recipient ${bobConversation.peerAddress} is not registered`
751+
)
736752
}
737753
if (!(recipient instanceof PublicKeyBundle)) {
738754
recipient = recipient.toLegacyBundle()
739755
}
740756

741-
if (!bobConversation.getClient().contacts.has(bobConversation.peerAddress)) {
757+
if (
758+
!bobConversation.getClient().contacts.has(bobConversation.peerAddress)
759+
) {
742760
topics = [
743761
buildUserIntroTopic(bobConversation.peerAddress),
744762
buildUserIntroTopic(bobConversation.getClient().address),
@@ -751,12 +769,10 @@ describe('conversation', () => {
751769

752770
const keys = deepcopy(bobConversation.getClient().legacyKeys)
753771

754-
const msg = await encodeMessageV1(
755-
"Hi Alice!",
756-
keys,
757-
recipient,
758-
{codecFor: (c: ContentTypeId) => baseCodecs[`${c.authorityId}/${c.typeId}`]},
759-
)
772+
const msg = await encodeMessageV1('Hi Alice!', keys, recipient, {
773+
codecFor: (c: ContentTypeId) =>
774+
baseCodecs[`${c.authorityId}/${c.typeId}`],
775+
})
760776

761777
await bobConversation.getClient().publishEnvelopes(
762778
topics.map((topic) => ({
@@ -768,9 +784,7 @@ describe('conversation', () => {
768784

769785
await sleep(100)
770786

771-
const [aliceMessages] = await Promise.all([
772-
aliceConversation.messages(),
773-
])
787+
const [aliceMessages] = await Promise.all([aliceConversation.messages()])
774788

775789
expect(aliceMessages).toHaveLength(1)
776790
expect(aliceMessages[0].messageVersion).toBe('v1')
@@ -795,22 +809,22 @@ describe('conversation', () => {
795809
alice.address
796810
)
797811
const baseCodecs = {
798-
[`${ContentTypeText.authorityId}/${ContentTypeText.typeId}`]: new TextCodec(),
812+
[`${ContentTypeText.authorityId}/${ContentTypeText.typeId}`]:
813+
new TextCodec(),
799814
}
800815

801816
const stream = await Stream.create<DecodedMessageExport>(
802817
aliceConversation.getClient(),
803818
[aliceConversation.topic],
804819
async (e) => {
805820
const convo = deepcopy(aliceConversation.export())
806-
if(convo.version !== 'v2') {
821+
if (convo.version !== 'v2') {
807822
throw new Error('unexpected convo version')
808823
}
809-
return await decodeMessageV2(
810-
e,
811-
convo,
812-
{codecFor: (c: ContentTypeId) => baseCodecs[`${c.authorityId}/${c.typeId}`]}
813-
)
824+
return await decodeMessageV2(e, convo, {
825+
codecFor: (c: ContentTypeId) =>
826+
baseCodecs[`${c.authorityId}/${c.typeId}`],
827+
})
814828
}
815829
)
816830

@@ -835,42 +849,42 @@ describe('conversation', () => {
835849
alice.address
836850
)
837851
const baseCodecs = {
838-
[`${ContentTypeText.authorityId}/${ContentTypeText.typeId}`]: new TextCodec(),
852+
[`${ContentTypeText.authorityId}/${ContentTypeText.typeId}`]:
853+
new TextCodec(),
839854
}
840855

841856
const convo = bobConversation.export()
842-
if(convo.version !== 'v2') {
857+
if (convo.version !== 'v2') {
843858
throw new Error('unexpected convo version')
844859
}
845860

846861
const msg = await encodeMessageV2(
847-
"Hi Alice!",
862+
'Hi Alice!',
848863
deepcopy(convo),
849864
deepcopy(bobConversation.getClient().keys),
850-
{codecFor: (c: ContentTypeId) => baseCodecs[`${c.authorityId}/${c.typeId}`]},
865+
{
866+
codecFor: (c: ContentTypeId) =>
867+
baseCodecs[`${c.authorityId}/${c.typeId}`],
868+
},
851869
undefined
852870
)
853871
await bobConversation.getClient().publishEnvelopes([
854872
{
855873
contentTopic: bobConversation.topic,
856874
message: msg.toBytes(),
857875
timestamp: msg.sent,
858-
}]
859-
)
876+
},
877+
])
860878

861879
await sleep(100)
862880

863-
const [aliceMessages] = await Promise.all([
864-
aliceConversation.messages(),
865-
])
881+
const [aliceMessages] = await Promise.all([aliceConversation.messages()])
866882

867883
expect(aliceMessages).toHaveLength(1)
868884
expect(aliceMessages[0].messageVersion).toBe('v2')
869885
expect(aliceMessages[0].error).toBeUndefined()
870886
expect(aliceMessages[0].senderAddress).toBe(bob.address)
871887
expect(aliceMessages[0].conversation.topic).toBe(aliceConversation.topic)
872888
})
873-
874889
})
875-
876890
})

0 commit comments

Comments
 (0)