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

Add MLS Queue service #2031

Merged
merged 20 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 4 additions & 6 deletions packages/sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ import { SignerContext } from './signerContext'
import { decryptAESGCM, deriveKeyAndIV, encryptAESGCM, uint8ArrayToBase64 } from './crypto_utils'
import { makeTags, makeTipTags } from './tags'
import { TipEventObject } from '@river-build/generated/dev/typings/ITipping'
import { extractMlsExternalGroup } from './mls/utils/mlsutils'
import { extractMlsExternalGroup, ExtractMlsExternalGroupResult } from './mls/utils/mlsutils'

export type ClientEvents = StreamEvents & DecryptionEvents

Expand Down Expand Up @@ -2527,11 +2527,9 @@ export class Client
})
}

public async getMlsExternalGroupInfo(streamId: string): Promise<{
externalGroupSnapshot: Uint8Array
groupInfoMessage: Uint8Array
commits: { commit: Uint8Array; groupInfoMessage: Uint8Array }[]
}> {
public async getMlsExternalGroupInfo(
streamId: string,
): Promise<ExtractMlsExternalGroupResult | undefined> {
let streamView = this.stream(streamId)?.view
if (!streamView || !streamView.isInitialized) {
streamView = await this.getStream(streamId)
Expand Down
45 changes: 45 additions & 0 deletions packages/sdk/src/mls/coordinator/awaiter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export interface IAwaiter {
promise: Promise<void>
resolve: () => void
}

export class NoopAwaiter implements IAwaiter {
public promise = Promise.resolve()
public resolve = () => {}
}

export class IndefiniteAwaiter implements IAwaiter {
public promise: Promise<void>
public resolve!: () => void

public constructor() {
this.promise = new Promise((resolve) => {
this.resolve = resolve
})
}
}

export class TimeoutAwaiter implements IAwaiter {
// top level promise
public promise: Promise<void>
// resolve handler to the inner promise
public resolve!: () => void
public constructor(timeoutMS: number, msg: string = 'Awaiter timed out') {
let timeout: NodeJS.Timeout
const timeoutPromise = new Promise<never>((_resolve, reject) => {
timeout = setTimeout(() => {
reject(new Error(msg))
}, timeoutMS)
})
const internalPromise: Promise<void> = new Promise(
(resolve: (value: void) => void, _reject) => {
this.resolve = () => {
resolve()
}
},
).finally(() => {
clearTimeout(timeout)
})
this.promise = Promise.race([internalPromise, timeoutPromise])
}
}
Loading
Loading