Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine authored Nov 28, 2023
2 parents 361b0ae + 59d5c5b commit 270bad5
Show file tree
Hide file tree
Showing 142 changed files with 20,018 additions and 20,428 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ module.exports = {
'jsdoc/require-param': 'off',
'jsdoc/require-param-type': 'off',
'jsdoc/require-returns': 'off',
// this is necessary to ensure that the crypto library is available
// in node and the browser
'no-restricted-syntax': [
'error',
{
selector: 'ImportDeclaration[source.value=/^(node:)?crypto$/]',
message:
'Do not import directly from `crypto`, use `src/crypto/crypto` instead.',
},
],
},
plugins: ['@typescript-eslint', 'prettier', 'jsdoc'],
ignorePatterns: [
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ on:
branches:
- main
- beta

permissions:
contents: read

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -19,6 +28,8 @@ jobs:
node-version-file: '.nvmrc'
- name: Install dependencies
run: npm ci
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
run: npm audit signatures
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.16.0
18.14.0
File renamed without changes.
6 changes: 5 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest Tests",
"name": "Debug Jest Test: Current File",
// If you use nvm and VSCode can't find node,
// move your nvm init script to your .zprofile
// instead of your .zshrc
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"${fileBasenameNoExtension}",
"--no-cache",
"--runInBand",
"--env=node",
Expand Down
301 changes: 161 additions & 140 deletions README.md

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions bench/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from './../src/conversations/Conversation'
import { MessageV1 } from '../src/Message'
import { newLocalHostClient } from '../test/helpers'
import { utils } from '../src/crypto'
import { SignedPublicKeyBundle } from '../src/crypto'
import {
MESSAGE_SIZES,
newPrivateKeyBundle,
Expand All @@ -13,6 +13,7 @@ import {
} from './helpers'
import { add } from 'benny'
import { fetcher } from '@xmtp/proto'
import { dateToNs } from '../src/utils'

const decodeV1 = () => {
return MESSAGE_SIZES.map((size) =>
Expand All @@ -22,11 +23,13 @@ const decodeV1 = () => {

const message = randomBytes(size)
const encodedMessage = await MessageV1.encode(
alice.legacyKeys,
bob.getPublicKeyBundle(),
alice.keystore,
await alice.encodeContent(message),
alice.publicKeyBundle,
bob.getPublicKeyBundle(),
new Date()
)

const messageBytes = encodedMessage.toBytes()

const convo = new ConversationV1(
Expand Down Expand Up @@ -58,15 +61,22 @@ const decodeV2 = () => {
const bob = await newPrivateKeyBundle()

const message = randomBytes(size)
const invite = await alice.keystore.createInvite({
recipient: SignedPublicKeyBundle.fromLegacyBundle(
bob.getPublicKeyBundle()
),
createdNs: dateToNs(new Date()),
context: undefined,
})
const convo = new ConversationV2(
alice,
'xmtp/0/foo',
utils.getRandomValues(new Uint8Array(32)),
invite.conversation?.topic ?? '',
bob.identityKey.publicKey.walletSignatureAddress(),
new Date(),
undefined
)
const encodedMessage = await convo.encodeMessage(message)
const payload = await alice.encodeContent(message)
const encodedMessage = await convo.createMessage(payload)
const messageBytes = encodedMessage.toBytes()

const envelope = {
Expand Down
29 changes: 19 additions & 10 deletions bench/encode.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ConversationV2 } from './../src/conversations/Conversation'
import { MessageV1 } from '../src/Message'
import { add } from 'benny'
import { Client } from '../src'
import { Client, dateToNs } from '../src'
import { newWallet, newLocalHostClient } from '../test/helpers'
import { utils } from '../src/crypto'
import { SignedPublicKeyBundle } from '../src/crypto'
import {
MESSAGE_SIZES,
newPrivateKeyBundle,
Expand All @@ -17,16 +17,17 @@ const encodeV1 = () => {
const alice = await Client.create(newWallet(), { env: 'local' })
const bobKeys = (await newPrivateKeyBundle()).getPublicKeyBundle()

const message = randomBytes(size)
const message = randomBytes(size).toString()
const timestamp = new Date()

// The returned function is the actual benchmark. Everything above is setup
return async () => {
const encodedMessage = await alice.encodeContent(message)
await MessageV1.encode(
alice.legacyKeys,
bobKeys,
alice.keystore,
encodedMessage,
alice.publicKeyBundle,
bobKeys,
timestamp
)
}
Expand All @@ -39,20 +40,28 @@ const encodeV2 = () => {
return MESSAGE_SIZES.map((size) =>
add(`encode and encrypt a ${size} byte v2 message`, async () => {
const alice = await newLocalHostClient()
const topicKey = utils.getRandomValues(new Uint8Array(32))
const bob = await newPrivateKeyBundle()

const invite = await alice.keystore.createInvite({
recipient: SignedPublicKeyBundle.fromLegacyBundle(
bob.getPublicKeyBundle()
),
createdNs: dateToNs(new Date()),
context: undefined,
})
const convo = new ConversationV2(
alice,
'xmtp/0/foo',
topicKey,
'0xf00',
invite.conversation?.topic ?? '',
bob.identityKey.publicKey.walletSignatureAddress(),
new Date(),
undefined
)
const message = randomBytes(size)
const payload = await alice.encodeContent(message)

// The returned function is the actual benchmark. Everything above is setup
return async () => {
await convo.encodeMessage(message)
await convo.createMessage(payload)
}
})
)
Expand Down
2 changes: 1 addition & 1 deletion bench/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type Benchmark from 'benchmark'
import { suite, save, cycle } from 'benny'
import { Config } from 'benny/lib/internal/common-types'
import { crypto } from '../src/crypto/encryption'
import crypto from '../src/crypto/crypto'
import { PrivateKeyBundleV1 } from '../src/crypto/PrivateKeyBundle'
import { newWallet } from '../test/helpers'

Expand Down
File renamed without changes.
10 changes: 0 additions & 10 deletions config/fileTransformer.js

This file was deleted.

7 changes: 0 additions & 7 deletions config/tsconfig.cjs.json

This file was deleted.

7 changes: 0 additions & 7 deletions config/tsconfig.esm.json

This file was deleted.

8 changes: 0 additions & 8 deletions config/tsconfig.types.json

This file was deleted.

7 changes: 0 additions & 7 deletions config/tsconfig.umd.json

This file was deleted.

40 changes: 0 additions & 40 deletions config/webpack.config.js

This file was deleted.

10 changes: 3 additions & 7 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ services:
environment:
- GOWAKU-NODEKEY=8a30dcb604b0b53627a5adc054dbf434b446628d4bd1eccc681d223f0550ce67
command:
- --ws
- --store
- --message-db-connection-string=postgres://postgres:xmtp@db:5432/postgres?sslmode=disable
- --message-db-reader-connection-string=postgres://postgres:xmtp@db:5432/postgres?sslmode=disable
- --lightpush
- --filter
- --ws-port=9001
- --store.enable
- --store.db-connection-string=postgres://postgres:xmtp@db:5432/postgres?sslmode=disable
- --store.reader-db-connection-string=postgres://postgres:xmtp@db:5432/postgres?sslmode=disable
- --wait-for-db=30s
- --api.authn.enable
ports:
Expand Down
15 changes: 15 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
roots: ['<rootDir>/test'],
testMatch: [
'**/__tests__/**/*.+(ts|tsx|js)',
'**/?(*.)+(spec|test).+(ts|tsx|js)',
],
transform: {
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
},
],
},
}
17 changes: 0 additions & 17 deletions jest.config.js

This file was deleted.

18 changes: 17 additions & 1 deletion jest.jsdom.env.js → jest.jsdom.env.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const Environment = require('jest-environment-jsdom')
const Environment = require('jest-environment-jsdom').default

module.exports = class JsdomTestEnvironment extends Environment {
async setup() {
await super.setup()

if (typeof this.global.TextEncoder === 'undefined') {
const { TextEncoder } = require('util')
this.global.TextEncoder = TextEncoder
Expand All @@ -20,6 +21,21 @@ module.exports = class JsdomTestEnvironment extends Environment {
this.global.crypto = require('crypto').webcrypto
}

if (typeof this.global.CompressionStream === 'undefined') {
// eslint-disable-next-line no-undef
this.global.CompressionStream = CompressionStream
}

if (typeof this.global.DecompressionStream === 'undefined') {
// eslint-disable-next-line no-undef
this.global.DecompressionStream = DecompressionStream
}

if (typeof this.global.performance.markResourceTiming === 'undefined') {
// eslint-disable-next-line @typescript-eslint/no-empty-function
this.global.performance.markResourceTiming = () => {}
}

// https://github.com/facebook/jest/issues/9983
this.global.Uint8Array = Uint8Array
}
Expand Down
Loading

0 comments on commit 270bad5

Please sign in to comment.