Skip to content

Commit

Permalink
Merge pull request #552 from xmtp/rygine/import-order
Browse files Browse the repository at this point in the history
Sort imports
  • Loading branch information
rygine authored Mar 13, 2024
2 parents 054a86e + e1e7dc9 commit adf2023
Show file tree
Hide file tree
Showing 90 changed files with 829 additions and 425 deletions.
14 changes: 13 additions & 1 deletion .prettierrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,17 @@ module.exports = {
trailingComma: 'es5',
arrowParens: 'always',
printWidth: 80,
plugins: ['prettier-plugin-packagejson'],
plugins: [
'prettier-plugin-packagejson',
'@ianvs/prettier-plugin-sort-imports',
],
importOrder: [
'<BUILTIN_MODULES>',
'<THIRD_PARTY_MODULES>',
'^@(/.*)$',
'^@test(/.*)$',
'^@bench(/.*)$',
'^[.]',
],
importOrderTypeScriptVersion: '5.4.2',
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.tabSize": 2,
"editor.detectIndentation": false,
"files.insertFinalNewline": true,
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ A client is created with `Client.create(wallet: Signer): Promise<Client>` that r
```ts
import { Client } from '@xmtp/xmtp-js'

// Create the client with a `Signer` from your application
const xmtp = await Client.create(wallet)
```
Expand Down Expand Up @@ -124,6 +125,7 @@ Most of the time, when interacting with the network, you'll want to do it throug

```ts
import { Client } from '@xmtp/xmtp-js'

// Create the client with a `Signer` from your application
const xmtp = await Client.create(wallet)
const conversations = xmtp.conversations
Expand Down Expand Up @@ -341,6 +343,7 @@ Additional codecs can be configured through the `ClientOptions` parameter of `Cl
```ts
// Adding support for `xmtp.org/composite` content type
import { CompositeCodec } from '@xmtp/xmtp-js'

const xmtp = Client.create(wallet, { codecs: [new CompositeCodec()] })
```

Expand Down Expand Up @@ -370,6 +373,7 @@ You can export the unencrypted key bundle using the static method `Client.getKey

```ts
import { Client } from '@xmtp/xmtp-js'

// Get the keys using a valid Signer. Save them somewhere secure.
const keys = await Client.getKeys(wallet)
// Create a client using keys returned from getKeys
Expand Down
8 changes: 4 additions & 4 deletions bench/decode.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { fetcher } from '@xmtp/proto'
import { add } from 'benny'
import { ConversationV1, ConversationV2 } from '@/conversations/Conversation'
import { SignedPublicKeyBundle } from '@/crypto/PublicKeyBundle'
import { MessageV1 } from '@/Message'
import { dateToNs } from '@/utils/date'
import { newLocalHostClient } from '@test/helpers'
import {
MESSAGE_SIZES,
newPrivateKeyBundle,
randomBytes,
wrapSuite,
} from './helpers'
import { add } from 'benny'
import { fetcher } from '@xmtp/proto'
import { dateToNs } from '@/utils/date'
import { SignedPublicKeyBundle } from '@/crypto/PublicKeyBundle'

const decodeV1 = () => {
return MESSAGE_SIZES.map((size) =>
Expand Down
10 changes: 5 additions & 5 deletions bench/encode.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { add } from 'benny'
import Client from '@/Client'
import { ConversationV2 } from '@/conversations/Conversation'
import { SignedPublicKeyBundle } from '@/crypto/PublicKeyBundle'
import { MessageV1 } from '@/Message'
import { add } from 'benny'
import { newWallet, newLocalHostClient } from '@test/helpers'
import { dateToNs } from '@/utils/date'
import { newLocalHostClient, newWallet } from '@test/helpers'
import {
MESSAGE_SIZES,
newPrivateKeyBundle,
randomBytes,
wrapSuite,
} from './helpers'
import Client from '@/Client'
import { dateToNs } from '@/utils/date'
import { SignedPublicKeyBundle } from '@/crypto/PublicKeyBundle'

const encodeV1 = () => {
return MESSAGE_SIZES.map((size) =>
Expand Down
2 changes: 1 addition & 1 deletion bench/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type Benchmark from 'benchmark'
import { suite, save, cycle } from 'benny'
import { cycle, save, suite } from 'benny'
import type { Config } from 'benny/lib/internal/common-types'
import crypto from '@/crypto/crypto'
import { PrivateKeyBundleV1 } from '@/crypto/PrivateKeyBundle'
Expand Down
2 changes: 1 addition & 1 deletion bench/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import encodeSuite from './encode'
import decodeSuite from './decode'
import encodeSuite from './encode'

const main = async () => {
await encodeSuite()
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"devDependencies": {
"@commitlint/cli": "19.0.3",
"@commitlint/config-conventional": "19.0.3",
"@ianvs/prettier-plugin-sort-imports": "^4.2.0",
"@metamask/providers": "^14.0.2",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-terser": "^0.4.4",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'rollup'
import typescript from '@rollup/plugin-typescript'
import json from '@rollup/plugin-json'
import typescript from '@rollup/plugin-typescript'
import { defineConfig } from 'rollup'
import tsConfigPaths from 'rollup-plugin-tsconfig-paths'

const external = [
Expand Down
8 changes: 4 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defineConfig } from 'rollup'
import typescript from '@rollup/plugin-typescript'
import { dts } from 'rollup-plugin-dts'
import filesize from 'rollup-plugin-filesize'
import json from '@rollup/plugin-json'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
import { resolveExtensions } from '@xmtp/rollup-plugin-resolve-extensions'
import { defineConfig } from 'rollup'
import { dts } from 'rollup-plugin-dts'
import filesize from 'rollup-plugin-filesize'
import tsConfigPaths from 'rollup-plugin-tsconfig-paths'

const external = [
Expand Down
9 changes: 5 additions & 4 deletions src/ApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { messageApi } from '@xmtp/proto'
import type { NotifyStreamEntityArrival } from '@xmtp/proto/ts/dist/types/fetch.pb'
import AuthCache from './authn/AuthCache'
import type { Authenticator } from '@/authn/interfaces'
import { retry, sleep } from '@/utils/async'
import { b64Decode } from '@/utils/bytes'
import { toNanoString } from '@/utils/date'
// eslint-disable-next-line no-restricted-syntax
import { version } from '../package.json'
import AuthCache from './authn/AuthCache'
import { XMTP_DEV_WARNING } from './constants'
import type { Flatten } from './utils/typedefs'
import { b64Decode } from '@/utils/bytes'
import { retry, sleep } from '@/utils/async'
import { toNanoString } from '@/utils/date'

export const { MessageApi, SortDirection } = messageApi

const RETRY_SLEEP_TIME = 100
Expand Down
78 changes: 43 additions & 35 deletions src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
import { PrivateKeyBundleV1 } from './crypto/PrivateKeyBundle'
import type { Signer } from './types/Signer'
import { messageApi, content as proto } from '@xmtp/proto'
import { getAddress, type WalletClient } from 'viem'
import KeystoreAuthenticator from '@/authn/KeystoreAuthenticator'
import Conversations from '@/conversations/Conversations'
import {
PublicKeyBundle,
SignedPublicKeyBundle,
} from '@/crypto/PublicKeyBundle'
import BrowserStoragePersistence from '@/keystore/persistence/BrowserStoragePersistence'
import InMemoryPersistence from '@/keystore/persistence/InMemoryPersistence'
import type { Persistence } from '@/keystore/persistence/interface'
import { KeystoreProviderUnavailableError } from '@/keystore/providers/errors'
import KeyGeneratorKeystoreProvider from '@/keystore/providers/KeyGeneratorKeystoreProvider'
import NetworkKeystoreProvider from '@/keystore/providers/NetworkKeystoreProvider'
import SnapProvider from '@/keystore/providers/SnapProvider'
import StaticKeystoreProvider from '@/keystore/providers/StaticKeystoreProvider'
import {
mapPaginatedStream,
type EnvelopeMapper,
type EnvelopeMapperWithMessage,
type EnvelopeWithMessage,
} from '@/utils/async'
import { isBrowser } from '@/utils/browser'
import { buildUserContactTopic, buildUserInviteTopic } from '@/utils/topic'
import { getSigner } from '@/utils/viem'
import HttpApiClient, {
ApiUrls,
SortDirection,
type ApiClient,
type PublishParams,
} from './ApiClient'
import { ContentTypeText, TextCodec } from './codecs/Text'
import type { ContentCodec, EncodedContent } from './MessageContent'
import { ContentTypeId } from './MessageContent'
import { compress, decompress } from './Compression'
import { content as proto, messageApi } from '@xmtp/proto'
import { decodeContactBundle, encodeContactBundle } from './ContactBundle'
import type { ApiClient, PublishParams } from './ApiClient'
import HttpApiClient, { ApiUrls, SortDirection } from './ApiClient'
import KeystoreAuthenticator from '@/authn/KeystoreAuthenticator'
import type { Flatten } from './utils/typedefs'
import { Contacts } from './Contacts'
import { PrivateKeyBundleV1 } from './crypto/PrivateKeyBundle'
import type { KeystoreProvider } from './keystore/providers/interfaces'
import type { KeystoreInterfaces } from './keystore/rpcDefinitions'
import { hasMetamaskWithSnaps } from './keystore/snapHelpers'
import type BackupClient from './message-backup/BackupClient'
import { BackupType } from './message-backup/BackupClient'
import { createBackupClient } from './message-backup/BackupClientFactory'
import type { KeystoreProvider } from './keystore/providers/interfaces'
import { hasMetamaskWithSnaps } from './keystore/snapHelpers'
import {
ContentTypeId,
type ContentCodec,
type EncodedContent,
} from './MessageContent'
import { packageName, version } from './snapInfo.json'
import type { ExtractDecodedType } from './types/client'
import { getAddress, type WalletClient } from 'viem'
import { Contacts } from './Contacts'
import type { KeystoreInterfaces } from './keystore/rpcDefinitions'
import { isBrowser } from '@/utils/browser'
import { getSigner } from '@/utils/viem'
import { buildUserContactTopic, buildUserInviteTopic } from '@/utils/topic'
import { mapPaginatedStream } from '@/utils/async'
import type {
EnvelopeMapperWithMessage,
EnvelopeMapper,
EnvelopeWithMessage,
} from '@/utils/async'
import type { Persistence } from '@/keystore/persistence/interface'
import BrowserStoragePersistence from '@/keystore/persistence/BrowserStoragePersistence'
import InMemoryPersistence from '@/keystore/persistence/InMemoryPersistence'
import SnapProvider from '@/keystore/providers/SnapProvider'
import StaticKeystoreProvider from '@/keystore/providers/StaticKeystoreProvider'
import NetworkKeystoreProvider from '@/keystore/providers/NetworkKeystoreProvider'
import KeyGeneratorKeystoreProvider from '@/keystore/providers/KeyGeneratorKeystoreProvider'
import { KeystoreProviderUnavailableError } from '@/keystore/providers/errors'
import {
PublicKeyBundle,
SignedPublicKeyBundle,
} from '@/crypto/PublicKeyBundle'
import type { Signer } from './types/Signer'
import type { Flatten } from './utils/typedefs'

const { Compression } = proto

// eslint-disable @typescript-eslint/explicit-module-boundary-types
Expand Down
2 changes: 1 addition & 1 deletion src/ContactBundle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { contact, publicKey } from '@xmtp/proto'
import {
PublicKeyBundle,
SignedPublicKeyBundle,
} from '@/crypto/PublicKeyBundle'
import { contact, publicKey } from '@xmtp/proto'

// Decodes contact bundles from the contact topic.
export function decodeContactBundle(
Expand Down
8 changes: 4 additions & 4 deletions src/Contacts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type Client from './Client'
import { privatePreferences } from '@xmtp/proto'
import Stream from './Stream'
import type { OnConnectionLostCallback } from './ApiClient'
import JobRunner from './conversations/JobRunner'
import type { EnvelopeWithMessage } from '@/utils/async'
import { fromNanoString } from '@/utils/date'
import { buildUserPrivatePreferencesTopic } from '@/utils/topic'
import type { OnConnectionLostCallback } from './ApiClient'
import type Client from './Client'
import JobRunner from './conversations/JobRunner'
import Stream from './Stream'

export type ConsentState = 'allowed' | 'denied' | 'unknown'

Expand Down
11 changes: 5 additions & 6 deletions src/Invitation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { invitation, type messageApi } from '@xmtp/proto'
import Long from 'long'
import { SignedPublicKeyBundle } from './crypto/PublicKeyBundle'
import type { messageApi } from '@xmtp/proto'
import { invitation } from '@xmtp/proto'
import crypto from './crypto/crypto'
import { dateToNs } from '@/utils/date'
import { buildDirectMessageTopicV2 } from '@/utils/topic'
import Ciphertext from './crypto/Ciphertext'
import crypto from './crypto/crypto'
import { decrypt, encrypt } from './crypto/encryption'
import type { PrivateKeyBundleV2 } from './crypto/PrivateKeyBundle'
import { buildDirectMessageTopicV2 } from '@/utils/topic'
import { dateToNs } from '@/utils/date'
import { SignedPublicKeyBundle } from './crypto/PublicKeyBundle'

export type InvitationContext = {
conversationId: string
Expand Down
20 changes: 11 additions & 9 deletions src/Message.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import type { Conversation } from './conversations/Conversation'
import { ConversationV1, ConversationV2 } from './conversations/Conversation'
import type Client from './Client'
import type { conversationReference } from '@xmtp/proto'
import { message as proto } from '@xmtp/proto'
import { message as proto, type conversationReference } from '@xmtp/proto'
import Long from 'long'
import { PublicKey } from '@/crypto/PublicKey'
import { PublicKeyBundle } from '@/crypto/PublicKeyBundle'
import type Client from './Client'
import {
ConversationV1,
ConversationV2,
type Conversation,
} from './conversations/Conversation'
import Ciphertext from './crypto/Ciphertext'
import { bytesToHex } from './crypto/utils'
import { sha256 } from './crypto/encryption'
import { bytesToHex } from './crypto/utils'
import type { KeystoreInterfaces } from './keystore/rpcDefinitions'
import type { ContentTypeId } from './MessageContent'
import { dateToNs, nsToDate } from './utils/date'
import { buildDecryptV1Request, getResultOrThrow } from './utils/keystore'
import type { KeystoreInterfaces } from './keystore/rpcDefinitions'
import { PublicKeyBundle } from '@/crypto/PublicKeyBundle'
import { PublicKey } from '@/crypto/PublicKey'

const headerBytesAndCiphertext = (
msg: proto.Message
Expand Down
2 changes: 1 addition & 1 deletion src/PreparedMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Envelope } from '@xmtp/proto/ts/dist/types/message_api/v1/message_api.pb'
import { bytesToHex } from './crypto/utils'
import { sha256 } from './crypto/encryption'
import { bytesToHex } from './crypto/utils'
import type { DecodedMessage } from './Message'

export class PreparedMessage {
Expand Down
2 changes: 1 addition & 1 deletion src/Stream.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { messageApi } from '@xmtp/proto'
import type { OnConnectionLostCallback, SubscriptionManager } from './ApiClient'
import type Client from './Client'
import type { messageApi } from '@xmtp/proto'

export type MessageDecoder<M> = (
env: messageApi.Envelope
Expand Down
4 changes: 2 additions & 2 deletions src/authn/KeystoreAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { authn } from '@xmtp/proto'
import { dateToNs } from '@/utils/date'
import Token from './Token'
import type {
KeystoreInterface,
KeystoreInterfaces,
} from '@/keystore/rpcDefinitions'
import { dateToNs } from '@/utils/date'
import Token from './Token'

const wrapToken = (token: authn.Token): Token => {
if (token instanceof Token) {
Expand Down
6 changes: 3 additions & 3 deletions src/authn/LocalAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { authn, signature, publicKey } from '@xmtp/proto'
import AuthData from './AuthData'
import Token from './Token'
import { authn, publicKey, signature } from '@xmtp/proto'
import { hexToBytes, keccak256 } from 'viem'
import type { PrivateKey } from '@/crypto/PrivateKey'
import AuthData from './AuthData'
import Token from './Token'

export default class LocalAuthenticator {
private identityKey: PrivateKey
Expand Down
3 changes: 1 addition & 2 deletions src/authn/Token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { signature, publicKey } from '@xmtp/proto'
import { authn } from '@xmtp/proto'
import { authn, type publicKey, type signature } from '@xmtp/proto'
import AuthData from './AuthData'

export default class Token implements authn.Token {
Expand Down
Loading

0 comments on commit adf2023

Please sign in to comment.