Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hs/update express #354

Closed
wants to merge 133 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
f10d39f
Update ownership metadata
AndrewFerr Dec 8, 2022
5d62511
Query & claim needed keys before encrypting (#270)
AndrewFerr Dec 8, 2022
6e9c700
Handle pre-shared invite keys (#271)
AndrewFerr Dec 8, 2022
367cdb9
Merge branch 'main' into element-main
AndrewFerr Dec 19, 2022
b505f75
Allow zero values for LRU config options
Half-Shot Jan 18, 2023
68c4733
Allow zero values for LRU config options (#6)
Half-Shot Jan 19, 2023
591b66e
Merge branch 'main' into travis/update
turt2live Mar 24, 2023
cbcc8ef
Update main branch to current v0.6.5 pre-release state (#7)
turt2live Mar 27, 2023
3900fe2
v0.6.4-element.0
Half-Shot Mar 28, 2023
9c2036c
Use the new members array?
turt2live Mar 28, 2023
2485ea1
Use the new members array? (#8)
Half-Shot Mar 28, 2023
b19bd4c
Fix key query and claim APIs to support async functionality (#314)
turt2live Apr 5, 2023
33c7242
Better interface
turt2live Apr 6, 2023
db33128
Fix key query and claim APIs to support async functionality (#9)
Half-Shot Apr 6, 2023
aa7394c
0.6.5
Half-Shot Apr 6, 2023
3bd23c4
Allow usage of the SQLite-based crypto store
AndrewFerr Apr 14, 2023
c73cacf
Add types for lowdb
AndrewFerr Apr 14, 2023
bce5d60
Update tests
AndrewFerr Apr 14, 2023
00a0b27
Update examples
AndrewFerr Apr 17, 2023
dc8202a
Fix lint rules for new the imports in examples
AndrewFerr Apr 17, 2023
4c07639
Test the SQLite crypto store
AndrewFerr Apr 20, 2023
3f24fb5
Fix lint rules
AndrewFerr Apr 20, 2023
a983376
Add missing semicolon
AndrewFerr Apr 20, 2023
50460ae
Merge branch 'sql-crypto-store'
AndrewFerr Apr 21, 2023
d4c8886
Reset version back to "develop" for jsdoc, for now
AndrewFerr Apr 21, 2023
5b75a2f
Support node 20, drop node 16
AndrewFerr Apr 25, 2023
82c0f14
Update deps
AndrewFerr Apr 25, 2023
18875a2
Update eslint
AndrewFerr Apr 25, 2023
563d129
Remove superfluous comment
AndrewFerr Apr 26, 2023
5f527b7
Support node 20, drop node 16 (#12)
AndrewFerr Apr 26, 2023
795323d
Update Jest
AndrewFerr Apr 26, 2023
11f3962
Update rust-sdk crypto dependency (#14)
AndrewFerr Apr 26, 2023
f62a508
Sync with upstream
AndrewFerr May 18, 2023
888c97d
Shortcircuit sync loop if we've requested to stop syncing
Half-Shot Jun 5, 2023
9df413e
Reduce our reliance on an up-to-date joined rooms cache (#16)
tadzik Jun 5, 2023
7902671
Update src/MatrixClient.ts
Half-Shot Jun 29, 2023
5617a1f
Refactor transaction handler.
Half-Shot Jun 29, 2023
fbec61f
Add scripts to aid PRs & releases (#18)
AndrewFerr Jun 29, 2023
6b37f16
Shortcircuit sync loop if we've requested to stop syncing (#19)
AndrewFerr Jun 29, 2023
813cc80
Correct the output folder for the Docs workflow (#21)
AndrewFerr Jun 29, 2023
f985cd4
Use remote default branches in helper scripts
AndrewFerr Jun 29, 2023
a0c209e
Fix races
Half-Shot Jul 3, 2023
cfae65f
Refactor transaction handler. (#20)
Half-Shot Jul 3, 2023
6cfd717
Upstream intake: dependency updates
AndrewFerr Jul 19, 2023
8c7c2ae
Remove Sled crypto store, use SQLite by default
AndrewFerr Jul 13, 2023
8e306a8
Remove Sled crypto store from examples & tests
AndrewFerr Jul 17, 2023
6eb9572
Fix operator precedence & typings
AndrewFerr Jul 18, 2023
73a38c1
Update rust-sdk bindings
AndrewFerr Aug 1, 2023
fef0d54
Pull to-device event list out of returned tuple
AndrewFerr Jul 19, 2023
974771b
Log when OlmMachine returns unexpected value
AndrewFerr Jul 19, 2023
d87f7d8
Add crypto test for to-device messages
AndrewFerr Aug 2, 2023
ceae460
Add support for key backups
AndrewFerr Jul 7, 2023
bfe6c37
Back up keys when receiving/creating them
AndrewFerr Jul 19, 2023
64463f4
Handle immediate outgoing backup requests
AndrewFerr Jul 25, 2023
e735cb5
Queue async key backup operations
AndrewFerr Aug 3, 2023
7449440
Fix/document awaits
AndrewFerr Aug 4, 2023
cc221fb
Apply review recommendations
AndrewFerr Aug 4, 2023
ae61b8f
Put auth_data signature in correct place
AndrewFerr Aug 4, 2023
bcee62b
Add key backup test
AndrewFerr Aug 4, 2023
1af9ee9
Satisfy linter
AndrewFerr Aug 4, 2023
f96ac19
Add tests and fixes
AndrewFerr Aug 10, 2023
746e4a7
Error when enabling backups with unknown algorithm
AndrewFerr Aug 10, 2023
a1d7a72
Merge branch 'af/no-sled'
AndrewFerr Aug 10, 2023
d6a8ff6
Merge branch 'af/to-device-msgs-fix'
AndrewFerr Aug 10, 2023
9a3dfae
Merge branch 'af/key-backups'
AndrewFerr Aug 10, 2023
c249cf5
Tweak key backup auth data type to fix docs
AndrewFerr Aug 11, 2023
401ad7a
Merge branch 'af/key-backups'
AndrewFerr Aug 11, 2023
ac1fe44
Get type checking from OlmMachine.shareRoomKey
AndrewFerr Aug 10, 2023
b3475a1
Merge branch 'main'
AndrewFerr Aug 11, 2023
2e00af9
Merge branch 'af/to-device-request-use-object'
AndrewFerr Aug 11, 2023
de0872d
Add support for exportRoomKeysForSession
Half-Shot Sep 4, 2023
187363e
Update dependency
Half-Shot Sep 6, 2023
3988fd3
Nitpick: fix inconsistent indent in package.json
AndrewFerr Sep 6, 2023
7fdb6e2
Rename & refactor session data export type
AndrewFerr Sep 6, 2023
b945461
Satisfy linter with trailing newline
AndrewFerr Sep 6, 2023
4b59dc0
Catch when CryptoClient can't find room members
AndrewFerr Sep 6, 2023
b5fbd7f
Put exportRoomKeysForSession on MatrixClient
AndrewFerr Sep 6, 2023
bd9fa96
Test room key exports
AndrewFerr Sep 6, 2023
ee77957
Emit an event when an Intent is created
AndrewFerr Sep 6, 2023
dab204a
Warn instead of error
AndrewFerr Sep 6, 2023
8fbe5e0
Don't print error object in warning
AndrewFerr Sep 6, 2023
8dab018
Prevent setting multiple room key backup listeners
AndrewFerr Sep 6, 2023
356954e
Merge branch 'af/catch-crypto-room-event-member-lookup'
AndrewFerr Sep 7, 2023
e57073c
Merge branch 'af/listen-for-intent-setup'
AndrewFerr Sep 7, 2023
f03e778
Emit "intent.new" after caching the new Intent
AndrewFerr Sep 27, 2023
a5dcf62
Add test
AndrewFerr Sep 27, 2023
0c074f2
Merge branch 'af/listen-for-intent-setup'
AndrewFerr Sep 27, 2023
fb00ab4
Merge upstream dependency upgrades
AndrewFerr Oct 31, 2023
ea8c166
Merge upstream release
AndrewFerr Nov 17, 2023
686a499
Add getEventNearestToTimestamp
Half-Shot Nov 22, 2023
9c6835e
Add tests for getEventNearestToTimestamp
Half-Shot Nov 22, 2023
06e66df
v1
Half-Shot Nov 22, 2023
cf05059
Fix test
Half-Shot Nov 23, 2023
703e625
Fix tests
Half-Shot Nov 23, 2023
669408d
Add getEventNearestToTimestamp (#38)
AndrewFerr Nov 24, 2023
471842d
Batch tracked users setup
Half-Shot Nov 24, 2023
a8a9242
Ensure we cache a room when it's not encrypted.
Half-Shot Nov 24, 2023
2fdc594
Cache rooms that are not encrypted.
Half-Shot Nov 24, 2023
0ee885e
Recheck encrypted status on each m.room.encryption
Half-Shot Nov 24, 2023
b924ef0
Don't check all joined rooms on startup
Half-Shot Nov 24, 2023
5c059a1
Fix test
Half-Shot Nov 24, 2023
bf1159e
Fix tests
Half-Shot Nov 27, 2023
be459b0
Comma
Half-Shot Nov 27, 2023
e84fee9
Rewrite logic to determine correct client to decrypt event/.
Half-Shot Nov 28, 2023
42fc7e8
Use ES2022 for Error causes
Half-Shot Nov 28, 2023
ed4ba92
Fix release version
Half-Shot Nov 28, 2023
15643f8
And examples too
Half-Shot Nov 28, 2023
81e6824
Fix obvious bs
Half-Shot Nov 29, 2023
7e050c7
Fix branch
Half-Shot Nov 29, 2023
da2792e
Cache non-encrypted rooms and skip fetching encrypted rooms on startu…
Half-Shot Dec 4, 2023
f656aba
Save an iteration
Half-Shot Dec 4, 2023
e95019d
Add new
Half-Shot Dec 4, 2023
5a0dd1e
Ensure we check if the room is encrypted first.
Half-Shot Dec 4, 2023
c852f25
Tidy up
Half-Shot Dec 4, 2023
a806668
Batch tracked users setup (#40)
Half-Shot Dec 4, 2023
9344147
Lint
Half-Shot Dec 4, 2023
545eb16
Use a more structured algorithm for determining decryption client for…
Half-Shot Dec 4, 2023
db39b0a
0.7.0
Half-Shot Dec 4, 2023
124a70c
Allow specifing a specific device ID for impersonation.
Half-Shot Dec 19, 2023
6ab2f49
Warn if the device changes./
Half-Shot Dec 19, 2023
9014b6b
Clear storage if the device changes.
Half-Shot Dec 19, 2023
277d3d8
Cleanup
Half-Shot Dec 19, 2023
78d48dc
Lint
Half-Shot Dec 19, 2023
e25be55
Warn properly
Half-Shot Dec 19, 2023
e5dcc5a
Make tests happy
Half-Shot Dec 19, 2023
34f8695
Tidy more
Half-Shot Dec 19, 2023
959e603
Fix another test
Half-Shot Dec 19, 2023
3d82d83
Refactor to instead create a new storage per device, rather than dele…
Half-Shot Dec 20, 2023
5672a5a
Log the migration
Half-Shot Dec 20, 2023
1c031ef
Move all files but allow it to fail
Half-Shot Dec 20, 2023
583b1cd
trailing commas
Half-Shot Dec 20, 2023
cbf2d45
Allow setting a specific impersonation device for appservices (#43)
Half-Shot Dec 20, 2023
98a2e0c
Update express types
Half-Shot Jan 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* turt2live
* @vector-im/bridges
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
node-version-file: .node-version
- run: yarn install
- run: yarn docs
- name: Build and deploy docs
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: .jsdoc/matrix-bot-sdk/develop
folder: .jsdoc/@vector-im/matrix-bot-sdk/develop
2 changes: 1 addition & 1 deletion .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18' # Target desired node version
node-version-file: .node-version
- run: yarn install
- run: yarn lint

Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MIT License

Copyright (c) 2022 - 2023 New Vector Ltd
Copyright (c) 2018 - 2023 Travis Ralston

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# matrix-bot-sdk

[![npm version](https://badge.fury.io/js/matrix-bot-sdk.svg)](https://www.npmjs.com/package/matrix-bot-sdk)
[![npm version](https://badge.fury.io/js/@vector-im%2Fmatrix-bot-sdk.svg)](https://www.npmjs.com/package/@vector-im/matrix-bot-sdk)

TypeScript/JavaScript SDK for Matrix bots. For help and support, visit [#matrix-bot-sdk:t2bot.io](https://matrix.to/#/#matrix-bot-sdk:t2bot.io)

Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![npm version](https://badge.fury.io/js/matrix-bot-sdk.svg)](https://www.npmjs.com/package/matrix-bot-sdk)
[![npm version](https://badge.fury.io/js/@vector-im%2Fmatrix-bot-sdk.svg)](https://www.npmjs.com/package/@vector-im/matrix-bot-sdk)

TypeScript/JavaScript SDK for Matrix bots. For help and support, visit [#matrix-bot-sdk:t2bot.io](https://matrix.to/#/#matrix-bot-sdk:t2bot.io)

Expand All @@ -11,7 +11,7 @@ TypeScript/JavaScript SDK for Matrix bots. For help and support, visit [#matrix-

## Installing

This package can be found on [npm](https://www.npmjs.com/package/matrix-bot-sdk):
This package can be found on [npm](https://www.npmjs.com/package/@vector-im/matrix-bot-sdk):
```
npm install matrix-bot-sdk
npm install @vector-im/matrix-bot-sdk
```
2 changes: 1 addition & 1 deletion examples/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const dmTarget = creds?.['dmTarget'] ?? "@admin:localhost";
const homeserverUrl = creds?.['homeserverUrl'] ?? "http://localhost:8008";
const accessToken = creds?.['accessToken'] ?? 'YOUR_TOKEN';
const storage = new SimpleFsStorageProvider("./examples/storage/bot.json");
const crypto = new RustSdkCryptoStorageProvider("./examples/storage/bot_sled", StoreType.Sled);
const crypto = new RustSdkCryptoStorageProvider("./examples/storage/bot_sqlite", StoreType.Sqlite);

const client = new MatrixClient(homeserverUrl, accessToken, storage, crypto);
AutojoinRoomsMixin.setupOnClient(client);
Expand Down
2 changes: 1 addition & 1 deletion examples/encryption_appservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ try {
const dmTarget = creds?.['dmTarget'] ?? "@admin:localhost";
const homeserverUrl = creds?.['homeserverUrl'] ?? "http://localhost:8008";
const storage = new SimpleFsStorageProvider("./examples/storage/encryption_appservice.json");
const crypto = new RustSdkAppserviceCryptoStorageProvider("./examples/storage/encryption_appservice_sled", StoreType.Sled);
const crypto = new RustSdkAppserviceCryptoStorageProvider("./examples/storage/encryption_appservice_sqlite", StoreType.Sqlite);
const worksImage = fs.readFileSync("./examples/static/it-works.png");

const registration: IAppserviceRegistration = {
Expand Down
6 changes: 3 additions & 3 deletions examples/encryption_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ const dmTarget = creds?.['dmTarget'] ?? "@admin:localhost";
const homeserverUrl = creds?.['homeserverUrl'] ?? "http://localhost:8008";
const accessToken = creds?.['accessToken'] ?? 'YOUR_TOKEN';
const storage = new SimpleFsStorageProvider("./examples/storage/encryption_bot.json");
const crypto = new RustSdkCryptoStorageProvider("./examples/storage/encryption_bot_sled", StoreType.Sled);
const crypto = new RustSdkCryptoStorageProvider("./examples/storage/encryption_bot_sqlite", StoreType.Sqlite);
const worksImage = fs.readFileSync("./examples/static/it-works.png");

const client = new MatrixClient(homeserverUrl, accessToken, storage, crypto);

(async function() {
let encryptedRoomId: string;
let encryptedRoomId: string|undefined = undefined;
const joinedRooms = await client.getJoinedRooms();
await client.crypto.prepare(joinedRooms); // init crypto because we're doing things before the client is started
await client.crypto.prepare(); // init crypto because we're doing things before the client is started
for (const roomId of joinedRooms) {
if (await client.crypto.isRoomEncrypted(roomId)) {
encryptedRoomId = roomId;
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"name": "matrix-bot-sdk",
"version": "develop",
"name": "@vector-im/matrix-bot-sdk",
"version": "0.7.0",
"description": "TypeScript/JavaScript SDK for Matrix bots and appservices",
"repository": {
"type": "git",
"url": "git+https://github.com/turt2live/matrix-bot-sdk.git"
"url": "git+https://github.com/vector-im/matrix-bot-sdk.git"
},
"author": "turt2live",
"author": "Element",
"license": "MIT",
"bugs": {
"url": "https://github.com/turt2live/matrix-bot-sdk/issues"
"url": "https://github.com/vector-im/matrix-bot-sdk/issues"
},
"homepage": "https://github.com/vector-im/matrix-bot-sdk#readme",
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/turt2live/matrix-bot-sdk#readme",
"scripts": {
"prepublishOnly": "yarn build",
"docs": "jsdoc -c jsdoc.json -P package.json -u docs/tutorials",
Expand Down Expand Up @@ -52,8 +55,8 @@
"tsconfig.json"
],
"dependencies": {
"@matrix-org/matrix-sdk-crypto-nodejs": "0.1.0-beta.6",
"@types/express": "^4.17.20",
"@matrix-org/matrix-sdk-crypto-nodejs": "0.1.0-beta.11",
"@types/express": "^4.17.21",
"another-json": "^0.2.0",
"async-lock": "^1.4.0",
"chalk": "4",
Expand Down
33 changes: 33 additions & 0 deletions scripts/fetch-remotes
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
set -e

for REMOTE in $(git remote); do
URL=$(git remote get-url $REMOTE)
if [[ $URL =~ "turt2live" ]]; then
UPSTREAM_REPO=$REMOTE
elif [[ $URL =~ "vector-im" ]]; then
FORK_REPO=$REMOTE
fi
done

function echoAndDo {
echo "$*"
$*
}

if [[ -z $UPSTREAM_REPO ]]; then
echo -n 'Adding remote for upstream repo: '
UPSTREAM_REPO=turt2live
echoAndDo git remote add $UPSTREAM_REPO [email protected]:turt2live/matrix-bot-sdk.git
fi

if [[ -z $FORK_REPO ]]; then
echo -n 'Adding remote for fork repo: '
FORK_REPO=vector-im
echoAndDo git remote add $FORK_REPO [email protected]:vector-im/matrix-bot-sdk.git
fi

for REPO in $UPSTREAM_REPO $FORK_REPO; do
git fetch $REPO >/dev/null
git remote set-head $REPO -a >/dev/null
done
14 changes: 14 additions & 0 deletions scripts/prepare-patch-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

if [[ $# -lt 1 ]]; then
echo 'Please provide a title for your patch branch' >&2
exit 1
fi
PATCH_TITLE=$1

. $(dirname $0)/fetch-remotes

git checkout -b $PATCH_TITLE $(git merge-base $UPSTREAM_REPO $FORK_REPO)

echo "Branch '$PATCH_TITLE' is now ready. Push changes to this branch when preparing a PR, and aim to merge it to both upstream and the fork."
50 changes: 50 additions & 0 deletions scripts/tag-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -e

if [[ -n $(git status --porcelain) ]]; then
echo 'Working dir is dirty, aborting' >&2
exit 1
fi

. $(dirname $0)/fetch-remotes

git checkout element-release
git reset --hard $FORK_REPO

PREID=element

# The latest upstream release tag reachable from the current commit
PREV_UPST_TAG=$(git log --decorate=short --decorate-refs=refs/tags/ --simplify-by-decoration --oneline | awk '/ \(tag: / && !/beta|element/ {sub(/)$/, "", $3); print $3; exit}')

# The commit hash of the retrieved tag (not of the tag itself)
PREV_UPST_TAG_HASH=$(git rev-parse ${PREV_UPST_TAG}~0)

# The immediate child commit of the release commit,
# to consider the 'Revert version back to "develop"' commits
PREV_UPST_NXT_HASH=$(git rev-list ${PREV_UPST_TAG}..${UPSTREAM_REPO} | tail -n 1)

# Check if the current branch is a direct merge of the previous upstream release
for MERGE_PARENT in $(git show -s | awk '/^Merge: / {print $2; print $3; exit}'); do
if [[ $PREV_UPST_TAG_HASH =~ ^$MERGE_PARENT || $PREV_UPST_NXT_HASH =~ ^$MERGE_PARENT ]]; then
RELEASE_MERGE=1
break
fi
done

if [[ $RELEASE_MERGE -eq 1 ]]; then
THIS_TAG="${PREV_UPST_TAG}-${PREID}"
THIS_VER=${THIS_TAG#v}
else
THIS_VER=$(npx semver --preid ${PREID} -i prerelease ${PREV_UPST_TAG#v})
while [[ -n $(git tag -l "v${THIS_VER}") ]]; do
THIS_VER=$(npx semver --preid ${PREID} -i prerelease $THIS_VER)
done
THIS_TAG="v${THIS_VER}"
fi

sed -i 's/\("version": "\).*\("\)/\1'$THIS_VER'\2/' package.json
git add package.json
git commit -m $THIS_TAG
git tag -sm $THIS_TAG{,}

echo "Tag '$THIS_TAG' is now ready and may be pushed"
95 changes: 94 additions & 1 deletion src/MatrixClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import { DMs } from "./DMs";
import { ServerVersions } from "./models/ServerVersions";
import { RoomCreateOptions } from "./models/CreateRoom";
import { PresenceState } from './models/events/PresenceEvent';
import { IKeyBackupInfo, IKeyBackupInfoRetrieved, IKeyBackupInfoUnsigned, IKeyBackupInfoUpdate, IKeyBackupVersion, KeyBackupVersion } from "./models/KeyBackup";
import { MatrixError } from "./models/MatrixError";

const SYNC_BACKOFF_MIN_MS = 5000;
const SYNC_BACKOFF_MAX_MS = 15000;
Expand Down Expand Up @@ -654,7 +656,7 @@ export class MatrixClient extends EventEmitter {

if (this.crypto) {
LogService.debug("MatrixClientLite", "Preparing end-to-end encryption");
await this.crypto.prepare(this.lastJoinedRoomIds);
await this.crypto.prepare();
LogService.info("MatrixClientLite", "End-to-end encryption enabled");
}

Expand Down Expand Up @@ -996,6 +998,18 @@ export class MatrixClient extends EventEmitter {
};
}

/**
* Get the nearest event to a given timestamp, either forwards or backwards.
* @param roomId The room ID to get the context in.
* @param ts The event ID to get the context of.
* @param dir The maximum number of events to return on either side of the event.
* @returns The ID and origin server timestamp of the event.
*/
@timedMatrixClientFunctionCall()
public async getEventNearestToTimestamp(roomId: string, ts: number, dir: "f"|"b"): Promise<{event_id: string, origin_server_ts: number}> {
return await this.doRequest("GET", "/_matrix/client/v1/rooms/" + encodeURIComponent(roomId) + "/timestamp_to_event", { ts, dir });
}

/**
* Gets the profile for a given user
* @param {string} userId the user ID to lookup
Expand Down Expand Up @@ -1968,6 +1982,85 @@ export class MatrixClient extends EventEmitter {
});
}

/**
* Get information about the latest room key backup version.
* @returns {Promise<IKeyBackupInfoRetrieved|null>} Resolves to the retrieved key backup info,
* or null if there is no existing backup.
*/
public async getKeyBackupVersion(): Promise<IKeyBackupInfoRetrieved|null> {
try {
return await this.doRequest("GET", "/_matrix/client/v3/room_keys/version");
} catch (e) {
if (e instanceof MatrixError && e.errcode === "M_NOT_FOUND") {
return null;
} else {
throw e;
}
}
}

/**
* Create a new room key backup.
* @param {IKeyBackupInfoUnsigned} info The properties of the key backup to create,
* with its auth_data left unsigned.
* @returns {Promise<IKeyBackupVersion>} Resolves to the version id of the new backup.
*/
@requiresCrypto()
public async signAndCreateKeyBackupVersion(info: IKeyBackupInfoUnsigned): Promise<IKeyBackupVersion> {
const data: IKeyBackupInfo = {
...info,
auth_data: {
...info.auth_data,
signatures: await this.crypto.sign(info),
},
};
return this.doRequest("POST", "/_matrix/client/v3/room_keys/version", null, data);
}

/**
* Update an existing room key backup.
* @param {KeyBackupVersion} version The key backup version to update.
* @param {IKeyBackupInfoUpdate} info The properties of the key backup to be applied.
* @returns {Promise<void>} Resolves when complete.
*/
@requiresCrypto()
public updateKeyBackupVersion(version: KeyBackupVersion, info: IKeyBackupInfoUpdate): Promise<void> {
const data = {
...info,
signatures: this.crypto.sign(info),
};
return this.doRequest("PUT", `/_matrix/client/v3/room_keys/version/${version}`, null, data);
}

/**
* Enable backing up of room keys.
* @param {IKeyBackupInfoRetrieved} info The configuration for key backup behaviour,
* as returned by {@link getKeyBackupVersion}.
* @returns {Promise<void>} Resolves when complete.
*/
@requiresCrypto()
public enableKeyBackup(info: IKeyBackupInfoRetrieved): Promise<void> {
return this.crypto.enableKeyBackup(info);
}

/**
* Disable backing up of room keys.
*/
public disableKeyBackup(): Promise<void> {
return this.crypto?.disableKeyBackup() ?? Promise.resolve();
}

/**
* Exports a set of keys for a given session.
* @param roomId The room ID for the session.
* @param sessionId The session ID.
* @returns An array of session keys.
*/
@requiresCrypto()
public exportRoomKeysForSession(roomId: string, sessionId: string) {
return this.crypto.exportRoomKeysForSession(roomId, sessionId);
}

/**
* Get relations for a given event.
* @param {string} roomId The room ID to for the given event.
Expand Down
12 changes: 12 additions & 0 deletions src/SynapseAdminApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,16 @@ export class SynapseAdminApis {
public async makeRoomAdmin(roomId: string, userId?: string): Promise<void> {
return this.client.doRequest("POST", `/_synapse/admin/v1/rooms/${encodeURIComponent(roomId)}/make_room_admin`, {}, { user_id: userId });
}

/**
* Get the nearest event to a given timestamp, either forwards or backwards. You do not
* need to be joined to the room to retrieve this information.
* @param roomId The room ID to get the context in.
* @param ts The event ID to get the context of.
* @param dir The maximum number of events to return on either side of the event.
* @returns The ID and origin server timestamp of the event.
*/
public async getEventNearestToTimestamp(roomId: string, ts: number, dir: "f"|"b"): Promise<{event_id: string, origin_server_ts: number}> {
return await this.client.doRequest("GET", "/_synapse/admin/v1/rooms/" + encodeURIComponent(roomId) + "/timestamp_to_event", { ts, dir });
}
}
Loading
Loading