Skip to content

Commit

Permalink
Merge pull request #546 from xmtp/rygine/update-imports-exports
Browse files Browse the repository at this point in the history
Enforce `type` specifier on imports and exports
  • Loading branch information
rygine authored Mar 12, 2024
2 parents 612c6ff + e621cee commit 687cd8a
Show file tree
Hide file tree
Showing 66 changed files with 231 additions and 233 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ module.exports = {
parserOptions: {
sourceType: 'module',
warnOnUnsupportedTypeScriptVersion: false,
project: 'tsconfig.json',
},
rules: {
'@typescript-eslint/consistent-type-exports': [
'error',
{
fixMixedExportsWithInlineTypeSpecifier: false,
},
],
'@typescript-eslint/consistent-type-imports': 'error',
'prettier/prettier': 'error',
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-description': 'off',
Expand Down
2 changes: 1 addition & 1 deletion bench/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Benchmark from 'benchmark'
import { suite, save, cycle } from 'benny'
import { Config } from 'benny/lib/internal/common-types'
import type { Config } from 'benny/lib/internal/common-types'
import crypto from '../src/crypto/crypto'
import { PrivateKeyBundleV1 } from '../src/crypto/PrivateKeyBundle'
import { newWallet } from '../test/helpers'
Expand Down
6 changes: 3 additions & 3 deletions src/ApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { messageApi } from '@xmtp/proto'
import { NotifyStreamEntityArrival } from '@xmtp/proto/ts/dist/types/fetch.pb'
import type { NotifyStreamEntityArrival } from '@xmtp/proto/ts/dist/types/fetch.pb'
import { b64Decode, retry, sleep, toNanoString } from './utils'
import AuthCache from './authn/AuthCache'
import { Authenticator } from './authn'
import type { Authenticator } from './authn'
import { version } from '../package.json'
import { XMTP_DEV_WARNING } from './constants'
import { Flatten } from './utils/typedefs'
import type { Flatten } from './utils/typedefs'
export const { MessageApi, SortDirection } = messageApi

const RETRY_SLEEP_TIME = 100
Expand Down
34 changes: 17 additions & 17 deletions src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
import { PrivateKeyBundleV1 } from './crypto/PrivateKeyBundle'
import { PublicKeyBundle, SignedPublicKeyBundle } from './crypto'
import type {
EnvelopeMapper,
EnvelopeMapperWithMessage,
EnvelopeWithMessage,
} from './utils'
import {
buildUserContactTopic,
mapPaginatedStream,
EnvelopeMapper,
buildUserInviteTopic,
isBrowser,
getSigner,
EnvelopeMapperWithMessage,
EnvelopeWithMessage,
} from './utils'
import { Signer } from './types/Signer'
import type { Signer } from './types/Signer'
import { Conversations } from './conversations'
import { ContentTypeText, TextCodec } from './codecs/Text'
import { ContentTypeId, ContentCodec, EncodedContent } from './MessageContent'
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 HttpApiClient, {
ApiUrls,
ApiClient,
PublishParams,
SortDirection,
} from './ApiClient'
import type { ApiClient, PublishParams } from './ApiClient'
import HttpApiClient, { ApiUrls, SortDirection } from './ApiClient'
import { KeystoreAuthenticator } from './authn'
import { Flatten } from './utils/typedefs'
import BackupClient, { BackupType } from './message-backup/BackupClient'
import type { Flatten } from './utils/typedefs'
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'
import {
KeyGeneratorKeystoreProvider,
KeystoreProvider,
KeystoreProviderUnavailableError,
NetworkKeystoreProvider,
SnapProvider,
StaticKeystoreProvider,
} from './keystore/providers'
import type { Persistence } from './keystore/persistence'
import {
BrowserStoragePersistence,
InMemoryPersistence,
Persistence,
} from './keystore/persistence'
import { hasMetamaskWithSnaps } from './keystore/snapHelpers'
import { packageName, version } from './snapInfo.json'
import { ExtractDecodedType } from './types/client'
import type { ExtractDecodedType } from './types/client'
import { getAddress, type WalletClient } from 'viem'
import { Contacts } from './Contacts'
import { KeystoreInterfaces } from './keystore/rpcDefinitions'
import type { KeystoreInterfaces } from './keystore/rpcDefinitions'
const { Compression } = proto

// eslint-disable @typescript-eslint/explicit-module-boundary-types
Expand Down
11 changes: 4 additions & 7 deletions src/Contacts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import Client from './Client'
import type Client from './Client'
import { privatePreferences } from '@xmtp/proto'
import {
EnvelopeWithMessage,
buildUserPrivatePreferencesTopic,
fromNanoString,
} from './utils'
import type { EnvelopeWithMessage } from './utils'
import { buildUserPrivatePreferencesTopic, fromNanoString } from './utils'
import Stream from './Stream'
import { OnConnectionLostCallback } from './ApiClient'
import type { OnConnectionLostCallback } from './ApiClient'
import JobRunner from './conversations/JobRunner'

export type ConsentState = 'allowed' | 'denied' | 'unknown'
Expand Down
5 changes: 3 additions & 2 deletions src/Invitation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Long from 'long'
import { SignedPublicKeyBundle } from './crypto/PublicKeyBundle'
import { messageApi, invitation } from '@xmtp/proto'
import type { messageApi } from '@xmtp/proto'
import { invitation } from '@xmtp/proto'
import crypto from './crypto/crypto'
import Ciphertext from './crypto/Ciphertext'
import { decrypt, encrypt } from './crypto'
import { PrivateKeyBundleV2 } from './crypto/PrivateKeyBundle'
import type { PrivateKeyBundleV2 } from './crypto/PrivateKeyBundle'
import { dateToNs, buildDirectMessageTopicV2 } from './utils'

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

const headerBytesAndCiphertext = (
msg: proto.Message
Expand Down
2 changes: 1 addition & 1 deletion src/MessageContent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { content as proto } from '@xmtp/proto'
import type { content as proto } from '@xmtp/proto'

// Represents proto.ContentTypeId
export class ContentTypeId {
Expand Down
4 changes: 2 additions & 2 deletions src/PreparedMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Envelope } from '@xmtp/proto/ts/dist/types/message_api/v1/message_api.pb'
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 { DecodedMessage } from './Message'
import type { DecodedMessage } from './Message'

export class PreparedMessage {
messageEnvelope: Envelope
Expand Down
6 changes: 3 additions & 3 deletions src/Stream.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OnConnectionLostCallback, SubscriptionManager } from './ApiClient'
import Client from './Client'
import { 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/AuthCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Authenticator } from './interfaces'
import Token from './Token'
import type { Authenticator } from './interfaces'
import type Token from './Token'

// Default to 10 seconds less than expected expiry to give some wiggle room near the end
// https://github.com/xmtp/xmtp-node-go/blob/main/pkg/api/authentication.go#L18
Expand Down
2 changes: 1 addition & 1 deletion src/authn/AuthData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { authn as authnProto } from '@xmtp/proto'
import Long from 'long'
import type Long from 'long'
import { dateToNs } from '../utils/date'

export default class AuthData implements authnProto.AuthData {
Expand Down
4 changes: 2 additions & 2 deletions src/authn/KeystoreAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { authn } from '@xmtp/proto'
import type { authn } from '@xmtp/proto'
import { dateToNs } from '../utils'
import Token from './Token'
import {
import type {
KeystoreInterface,
KeystoreInterfaces,
} from '../keystore/rpcDefinitions'
Expand Down
2 changes: 1 addition & 1 deletion src/authn/LocalAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authn, signature, publicKey } from '@xmtp/proto'
import AuthData from './AuthData'
import { PrivateKey } from '../crypto'
import type { PrivateKey } from '../crypto'
import Token from './Token'
import { hexToBytes, keccak256 } from 'viem'

Expand Down
3 changes: 2 additions & 1 deletion src/authn/Token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { authn, signature, publicKey } from '@xmtp/proto'
import type { signature, publicKey } from '@xmtp/proto'
import { authn } from '@xmtp/proto'
import AuthData from './AuthData'

export default class Token implements authn.Token {
Expand Down
2 changes: 1 addition & 1 deletion src/authn/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Token from './Token'
import type Token from './Token'

export interface Authenticator {
createToken(timestamp?: Date): Promise<Token>
Expand Down
5 changes: 2 additions & 3 deletions src/codecs/Composite.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable camelcase */
import {
ContentTypeId,
import type {
ContentCodec,
EncodedContent,
CodecRegistry,
} from '../MessageContent'
import { ContentTypeId } from '../MessageContent'
import { composite as proto } from '@xmtp/proto'

// xmtp.org/composite
Expand Down
3 changes: 2 additions & 1 deletion src/codecs/Text.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContentTypeId, ContentCodec, EncodedContent } from '../MessageContent'
import type { ContentCodec, EncodedContent } from '../MessageContent'
import { ContentTypeId } from '../MessageContent'

// xmtp.org/text
//
Expand Down
18 changes: 7 additions & 11 deletions src/conversations/Conversation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OnConnectionLostCallback } from './../ApiClient'
import type { OnConnectionLostCallback } from './../ApiClient'
import {
buildUserIntroTopic,
buildDirectMessageTopic,
Expand All @@ -7,20 +7,16 @@ import {
toNanoString,
} from '../utils'
import Stream from '../Stream'
import Client, {
import type {
ListMessagesOptions,
ListMessagesPaginatedOptions,
SendOptions,
} from '../Client'
import { InvitationContext } from '../Invitation'
import type Client from '../Client'
import type { InvitationContext } from '../Invitation'
import { DecodedMessage, MessageV1, MessageV2 } from '../Message'
import {
messageApi,
message,
content as proto,
keystore,
ciphertext,
} from '@xmtp/proto'
import type { messageApi, keystore, ciphertext } from '@xmtp/proto'
import { message, content as proto } from '@xmtp/proto'
import {
SignedPublicKey,
Signature,
Expand All @@ -31,7 +27,7 @@ import { PreparedMessage } from '../PreparedMessage'
import { sha256 } from '../crypto/encryption'
import { buildDecryptV1Request, getResultOrThrow } from '../utils/keystore'
import { ContentTypeText } from '../codecs/Text'
import { ConsentState } from '../Contacts'
import type { ConsentState } from '../Contacts'
import { getAddress } from 'viem'

/**
Expand Down
13 changes: 7 additions & 6 deletions src/conversations/Conversations.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { OnConnectionLostCallback } from './../ApiClient'
import { messageApi, keystore, conversationReference } from '@xmtp/proto'
import type { OnConnectionLostCallback } from './../ApiClient'
import type { messageApi, keystore, conversationReference } from '@xmtp/proto'
import { SignedPublicKeyBundle } from './../crypto/PublicKeyBundle'
import { ListMessagesOptions } from './../Client'
import { InvitationContext } from './../Invitation'
import { Conversation, ConversationV1, ConversationV2 } from './Conversation'
import type { ListMessagesOptions } from './../Client'
import type { InvitationContext } from './../Invitation'
import type { Conversation } from './Conversation'
import { ConversationV1, ConversationV2 } from './Conversation'
import { MessageV1, DecodedMessage } from '../Message'
import Stream from '../Stream'
import Client from '../Client'
import type Client from '../Client'
import {
buildDirectMessageTopic,
buildUserIntroTopic,
Expand Down
2 changes: 1 addition & 1 deletion src/conversations/JobRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { keystore } from '@xmtp/proto'
import { Mutex } from 'async-mutex'
import Long from 'long'
import { dateToNs, nsToDate } from '../utils'
import { KeystoreInterfaces } from '../keystore/rpcDefinitions'
import type { KeystoreInterfaces } from '../keystore/rpcDefinitions'

const CLOCK_SKEW_OFFSET_MS = 10000

Expand Down
3 changes: 2 additions & 1 deletion src/conversations/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as Conversations } from './Conversations'
export { Conversation, ConversationV1, ConversationV2 } from './Conversation'
export type { Conversation } from './Conversation'
export { ConversationV1, ConversationV2 } from './Conversation'
9 changes: 3 additions & 6 deletions src/crypto/PrivateKey.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { privateKey } from '@xmtp/proto'
import * as secp from '@noble/secp256k1'
import Long from 'long'
import Signature, {
ECDSACompactWithRecovery,
ecdsaSignerKey,
KeySigner,
} from './Signature'
import type { ECDSACompactWithRecovery, KeySigner } from './Signature'
import Signature, { ecdsaSignerKey } from './Signature'
import { PublicKey, SignedPublicKey, UnsignedPublicKey } from './PublicKey'
import Ciphertext from './Ciphertext'
import type Ciphertext from './Ciphertext'
import { decrypt, encrypt, sha256 } from './encryption'
import { equalBytes } from './utils'

Expand Down
4 changes: 2 additions & 2 deletions src/crypto/PrivateKeyBundle.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { privateKey as proto } from '@xmtp/proto'
import { PrivateKey, SignedPrivateKey } from './PrivateKey'
import { WalletSigner } from './Signature'
import { PublicKey, SignedPublicKey } from './PublicKey'
import type { PublicKey, SignedPublicKey } from './PublicKey'
import { PublicKeyBundle, SignedPublicKeyBundle } from './PublicKeyBundle'
import { Signer } from '../types/Signer'
import type { Signer } from '../types/Signer'
import { NoMatchingPreKeyError } from './errors'

// PrivateKeyBundle bundles the private keys corresponding to a PublicKeyBundle for convenience.
Expand Down
5 changes: 3 additions & 2 deletions src/crypto/PublicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import * as secp from '@noble/secp256k1'
import Long from 'long'
import Signature, { WalletSigner } from './Signature'
import { computeAddress, equalBytes, splitSignature } from './utils'
import { Signer } from '../types/Signer'
import type { Signer } from '../types/Signer'
import { sha256 } from './encryption'
import { hashMessage, Hex, hexToBytes } from 'viem'
import type { Hex } from 'viem'
import { hashMessage, hexToBytes } from 'viem'

// SECP256k1 public key in uncompressed format with prefix
type secp256k1Uncompressed = {
Expand Down
5 changes: 3 additions & 2 deletions src/crypto/Signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import Long from 'long'
import * as secp from '@noble/secp256k1'
import { PublicKey, UnsignedPublicKey, SignedPublicKey } from './PublicKey'
import { SignedPrivateKey } from './PrivateKey'
import { Signer } from '../types/Signer'
import type { Signer } from '../types/Signer'
import { bytesToHex, equalBytes, splitSignature } from './utils'
import { Hex, hashMessage, hexToBytes } from 'viem'
import type { Hex } from 'viem'
import { hashMessage, hexToBytes } from 'viem'

// ECDSA signature with recovery bit.
export type ECDSACompactWithRecovery = {
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/SignedEciesCiphertext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ciphertext } from '@xmtp/proto'
import { sha256 } from './encryption'
import { PrivateKey, SignedPrivateKey } from './PrivateKey'
import { PublicKey, SignedPublicKey } from './PublicKey'
import type { PrivateKey, SignedPrivateKey } from './PrivateKey'
import type { PublicKey, SignedPublicKey } from './PublicKey'
import Signature from './Signature'

const IV_LENGTH = 16
Expand Down
Loading

0 comments on commit 687cd8a

Please sign in to comment.