Skip to content

Commit

Permalink
Merge pull request #526 from xmtp/main
Browse files Browse the repository at this point in the history
`main` => `beta`
  • Loading branch information
rygine authored Jan 24, 2024
2 parents 03ce704 + 1f10148 commit fb4e15f
Show file tree
Hide file tree
Showing 27 changed files with 343 additions and 223 deletions.
43 changes: 0 additions & 43 deletions build/rollup-plugin-resolve-extensions/index.ts

This file was deleted.

48 changes: 0 additions & 48 deletions build/utils.ts

This file was deleted.

31 changes: 31 additions & 0 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@
"scripts": {
"prebench": "npm run build:bench",
"bench": "node dist/bench/index.cjs",
"build": "npm run clean:dist && npm run build:plugin && npm run build:rollup",
"build": "npm run clean:dist && rollup -c",
"build:bench": "rollup -c rollup.config.bench.js",
"build:docs": "rimraf docs && mkdir -p tmp && cp README.md tmp/ && sed -i.bak '/badge.svg/d' tmp/README.md && typedoc --excludePrivate --readme tmp/README.md src/index.ts",
"build:rollup": "rollup -c",
"build:plugin": "rollup -c rollup.config.build.js",
"clean": "npm run clean:dist",
"clean:dist": "rimraf dist",
"package": "npm pack",
Expand Down Expand Up @@ -129,6 +127,7 @@
"@types/node": "^18.14.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"@xmtp/rollup-plugin-resolve-extensions": "^1.0.0",
"benny": "^3.7.1",
"dd-trace": "^2.12.2",
"eslint": "^8.50.0",
Expand Down
23 changes: 0 additions & 23 deletions rollup.config.build.js

This file was deleted.

10 changes: 7 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 { resolveExtensions } from './build/rollup-plugin-resolve-extensions/index.js'
import { resolveExtensions } from '@xmtp/rollup-plugin-resolve-extensions'

const external = [
'@noble/secp256k1',
Expand Down Expand Up @@ -69,7 +69,11 @@ export default defineConfig([
format: 'es',
sourcemap: true,
},
plugins: [resolveExtensions(['.browser']), terser(), ...plugins],
plugins: [
resolveExtensions({ extensions: ['.browser'] }),
terser(),
...plugins,
],
external,
},
{
Expand All @@ -80,7 +84,7 @@ export default defineConfig([
sourcemap: true,
},
plugins: [
resolveExtensions(['.bundler', '.browser']),
resolveExtensions({ extensions: ['.bundler', '.browser'] }),
terser(),
...plugins,
],
Expand Down
10 changes: 5 additions & 5 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { KeystoreAuthenticator } from './authn'
import { Flatten } from './utils/typedefs'
import BackupClient, { BackupType } from './message-backup/BackupClient'
import { createBackupClient } from './message-backup/BackupClientFactory'
import { Keystore } from './keystore'
import {
KeyGeneratorKeystoreProvider,
KeystoreProvider,
Expand All @@ -47,6 +46,7 @@ import { packageName, version } from './snapInfo.json'
import { ExtractDecodedType } from './types/client'
import type { WalletClient } from 'viem'
import { Contacts } from './Contacts'
import { KeystoreInterfaces } from './keystore/rpcDefinitions'
const { Compression } = proto

// eslint-disable @typescript-eslint/explicit-module-boundary-types
Expand Down Expand Up @@ -147,7 +147,7 @@ export type KeyStoreOptions = {
* The client will attempt to use each one in sequence until one successfully
* returns a Keystore instance
*/
keystoreProviders: KeystoreProvider[]
keystoreProviders: KeystoreProvider<KeystoreInterfaces>[]
/**
* Enable the Keystore to persist conversations in the provided storage interface
*/
Expand Down Expand Up @@ -252,7 +252,7 @@ export function defaultOptions(opts?: Partial<ClientOptions>): ClientOptions {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default class Client<ContentTypes = any> {
address: string
keystore: Keystore
keystore: KeystoreInterfaces
apiClient: ApiClient
contacts: Contacts
publicKeyBundle: PublicKeyBundle
Expand All @@ -271,7 +271,7 @@ export default class Client<ContentTypes = any> {
publicKeyBundle: PublicKeyBundle,
apiClient: ApiClient,
backupClient: BackupClient,
keystore: Keystore
keystore: KeystoreInterfaces
) {
this.knownPublicKeyBundles = new Map<
string,
Expand Down Expand Up @@ -857,7 +857,7 @@ async function bootstrapKeystore(
opts: ClientOptions,
apiClient: ApiClient,
wallet: Signer | null
): Promise<Keystore> {
) {
for (const provider of opts.keystoreProviders) {
try {
return await provider.newKeystore(opts, apiClient, wallet ?? undefined)
Expand Down
6 changes: 3 additions & 3 deletions src/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { bytesToHex } from './crypto/utils'
import { sha256 } from './crypto/encryption'
import { ContentTypeId } from './MessageContent'
import { dateToNs, nsToDate } from './utils'
import { Keystore } from './keystore'
import { buildDecryptV1Request, getResultOrThrow } from './utils/keystore'
import { KeystoreInterfaces } from './keystore/rpcDefinitions'

const headerBytesAndCiphertext = (
msg: proto.Message
Expand Down Expand Up @@ -105,7 +105,7 @@ export class MessageV1 extends MessageBase implements proto.MessageV1 {
}

async decrypt(
keystore: Keystore,
keystore: KeystoreInterfaces,
myPublicKeyBundle: PublicKeyBundle
): Promise<Uint8Array> {
const responses = (
Expand Down Expand Up @@ -151,7 +151,7 @@ export class MessageV1 extends MessageBase implements proto.MessageV1 {
}

static async encode(
keystore: Keystore,
keystore: KeystoreInterfaces,
payload: Uint8Array,
sender: PublicKeyBundle,
recipient: PublicKeyBundle,
Expand Down
13 changes: 9 additions & 4 deletions src/authn/KeystoreAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { authn } from '@xmtp/proto'
import { Keystore } from '../keystore'
import { dateToNs } from '../utils'
import Token from './Token'
import {
KeystoreInterface,
KeystoreInterfaces,
} from '../keystore/rpcDefinitions'

const wrapToken = (token: authn.Token): Token => {
if (token instanceof Token) {
Expand All @@ -10,10 +13,12 @@ const wrapToken = (token: authn.Token): Token => {
return new Token(token)
}

export default class KeystoreAuthenticator {
private keystore: Keystore
export default class KeystoreAuthenticator<
T extends KeystoreInterfaces = KeystoreInterface,
> {
private keystore: T

constructor(keystore: Keystore) {
constructor(keystore: T) {
this.keystore = keystore
}

Expand Down
4 changes: 3 additions & 1 deletion src/authn/LocalAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { keccak256 } from 'js-sha3'
import sha3 from 'js-sha3'
import { authn, signature, publicKey } from '@xmtp/proto'
import AuthData from './AuthData'
import { PrivateKey } from '../crypto'
import { hexToBytes } from '../crypto/utils'
import Token from './Token'

const { keccak256 } = sha3

export default class LocalAuthenticator {
private identityKey: PrivateKey

Expand Down
6 changes: 3 additions & 3 deletions src/conversations/JobRunner.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { keystore } from '@xmtp/proto'
import { Mutex } from 'async-mutex'
import { Keystore } from '../keystore'
import Long from 'long'
import { dateToNs, nsToDate } from '../utils'
import { KeystoreInterfaces } from '../keystore/rpcDefinitions'

const CLOCK_SKEW_OFFSET_MS = 10000

Expand All @@ -13,10 +13,10 @@ type UpdateJob<T> = (lastRun: Date | undefined) => Promise<T>
export default class JobRunner {
readonly jobType: JobType
readonly mutex: Mutex
readonly keystore: Keystore
readonly keystore: KeystoreInterfaces
disableOffset: boolean = false

constructor(jobType: JobType, keystore: Keystore) {
constructor(jobType: JobType, keystore: KeystoreInterfaces) {
this.jobType = jobType
this.mutex = new Mutex()
this.keystore = keystore
Expand Down
28 changes: 23 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,30 @@ export {
buildUserInviteTopic,
buildUserPrivateStoreTopic,
} from './utils'
export { Keystore, InMemoryKeystore, TopicData } from './keystore'
export {
Keystore,
InMemoryKeystore,
TopicData,
keystoreApiDefs,
} from './keystore'
apiDefs as keystoreApiDefs,
snapApiDefs as snapKeystoreApiDefs,
KeystoreApiDefs,
KeystoreApiEntries,
KeystoreApiMethods,
KeystoreApiRequestEncoders,
KeystoreApiRequestValues,
KeystoreApiResponseDecoders,
KeystoreInterface,
KeystoreInterfaceRequestValues,
KeystoreInterfaces,
KeystoreRPC,
KeystoreRPCCodec,
SnapKeystoreApiDefs,
SnapKeystoreApiEntries,
SnapKeystoreApiMethods,
SnapKeystoreApiRequestEncoders,
SnapKeystoreApiRequestValues,
SnapKeystoreApiResponseDecoders,
SnapKeystoreInterface,
SnapKeystoreInterfaceRequestValues,
} from './keystore/rpcDefinitions'
export {
KeystoreProvider,
KeyGeneratorKeystoreProvider,
Expand Down
Loading

0 comments on commit fb4e15f

Please sign in to comment.