diff --git a/keyserver/flow-typed/npm/@matrix-org/olm_vx.x.x.js b/keyserver/flow-typed/npm/@matrix-org/olm_vx.x.x.js new file mode 100644 --- /dev/null +++ b/keyserver/flow-typed/npm/@matrix-org/olm_vx.x.x.js @@ -0,0 +1,125 @@ +// flow-typed signature: 085f002da86534cfd8cee47ffa99dd67 +// flow-typed version: <>/@matrix-org/olm_v3.2.4/flow_v0.182.0 + +declare module '@matrix-org/olm' { + + declare export class Account { + constructor(): this; + free(): void; + create(): void; + identity_keys(): string; + sign(message: string | Uint8Array): string; + one_time_keys(): string; + mark_keys_as_published(): void; + max_number_of_one_time_keys(): number; + generate_one_time_keys(number_of_keys: number): void; + remove_one_time_keys(session: Session): void; + generate_fallback_key(): void; + fallback_key(): string; + pickle(key: string | Uint8Array): string; + unpickle(key: string | Uint8Array, pickle: string): void; + } + + declare export class Session { + constructor(): this; + free(): void; + pickle(key: string | Uint8Array): string; + unpickle(key: string | Uint8Array, pickle: string): void; + create_outbound( + account: Account, their_identity_key: string, their_one_time_key: string, + ): void; + create_inbound(account: Account, one_time_key_message: string): void; + create_inbound_from( + account: Account, identity_key: string, one_time_key_message: string, + ): void; + session_id(): string; + has_received_message(): boolean; + matches_inbound(one_time_key_message: string): boolean; + matches_inbound_from(identity_key: string, one_time_key_message: string): boolean; + encrypt(plaintext: string): Object; + decrypt(message_type: number, message: string): string; + describe(): string; + } + + declare export class Utility { + constructor(): this; + free(): void; + sha256(input: string | Uint8Array): string; + ed25519_verify(key: string, message: string | Uint8Array, signature: string): void; + } + + declare class InboundGroupSession { + constructor(): this; + free(): void; + pickle(key: string | Uint8Array): string; + unpickle(key: string | Uint8Array, pickle: string): void; + create(session_key: string): string; + import_session(session_key: string): string; + decrypt(message: string): Object; + session_id(): string; + first_known_index(): number; + export_session(message_index: number): string; + } + + declare class OutboundGroupSession { + constructor(): this; + free(): void; + pickle(key: string | Uint8Array): string; + unpickle(key: string | Uint8Array, pickle: string): void; + create(): void; + encrypt(plaintext: string): string; + session_id(): string; + session_key(): string; + message_index(): number; + } + + declare class PkEncryption { + constructor(): this; + free(): void; + set_recipient_key(key: string): void; + encrypt(plaintext: string): Object; + } + + declare class PkDecryption { + constructor(): this; + free(): void; + init_with_private_key(key: Uint8Array): string; + generate_key(): string; + get_private_key(): Uint8Array; + pickle(key: string | Uint8Array): string; + unpickle(key: string | Uint8Array, pickle: string): string; + decrypt(ephemeral_key: string, mac: string, ciphertext: string): string; + } + + declare class PkSigning { + constructor(): this; + free(): void; + init_with_seed(seed: Uint8Array): string; + generate_seed(): Uint8Array; + sign(message: string): string; + } + + declare class SAS { + constructor(): this; + free(): void; + get_pubkey(): string; + set_their_key(their_key: string): void; + generate_bytes(info: string, length: number): Uint8Array; + calculate_mac(input: string, info: string): string; + calculate_mac_long_kdf(input: string, info: string): string; + } + + declare export function init(opts?: Object): Promise; + + declare export function get_library_version(): [number, number, number]; + + declare export var PRIVATE_KEY_LENGTH: number; + + declare export default { + init: typeof init, + get_library_version: typeof get_library_version, + PRIVATE_KEY_LENGTH: typeof PRIVATE_KEY_LENGTH, + Account: typeof Account, + Utility: typeof Utility, + }; +} diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js --- a/keyserver/src/responders/user-responders.js +++ b/keyserver/src/responders/user-responders.js @@ -1,5 +1,6 @@ // @flow +import type { Utility as OlmUtility } from '@matrix-org/olm'; import invariant from 'invariant'; import { getRustAPI } from 'rust-node-addon'; import { ErrorTypes, SiweMessage } from 'siwe'; @@ -102,8 +103,7 @@ } from '../updaters/account-updaters.js'; import { userSubscriptionUpdater } from '../updaters/user-subscription-updaters.js'; import { viewerAcknowledgmentUpdater } from '../updaters/viewer-acknowledgment-updater.js'; -import { getOLMUtility } from '../utils/olm-utils.js'; -import type { OLMUtility } from '../utils/olm-utils.js'; +import { getOlmUtility } from '../utils/olm-utils.js'; import { validateInput } from '../utils/validation-utils.js'; const subscriptionUpdateRequestInputValidator = tShape({ @@ -227,7 +227,7 @@ throw new ServerError('invalid_identity_keys_blob'); } - const olmUtil: OLMUtility = getOLMUtility(); + const olmUtil: OlmUtility = getOlmUtility(); try { olmUtil.ed25519_verify( identityKeys.primaryIdentityPublicKeys.ed25519, @@ -371,7 +371,7 @@ if (signedIdentityKeysBlob) { identityKeys = JSON.parse(signedIdentityKeysBlob.payload); - const olmUtil: OLMUtility = getOLMUtility(); + const olmUtil: OlmUtility = getOlmUtility(); try { olmUtil.ed25519_verify( identityKeys.primaryIdentityPublicKeys.ed25519, @@ -540,7 +540,7 @@ throw new ServerError('invalid_identity_keys_blob'); } - const olmUtil: OLMUtility = getOLMUtility(); + const olmUtil: OlmUtility = getOlmUtility(); try { olmUtil.ed25519_verify( identityKeys.primaryIdentityPublicKeys.ed25519, diff --git a/keyserver/src/utils/olm-utils.js b/keyserver/src/utils/olm-utils.js --- a/keyserver/src/utils/olm-utils.js +++ b/keyserver/src/utils/olm-utils.js @@ -1,6 +1,7 @@ // @flow import olm from '@matrix-org/olm'; +import type { Utility as OlmUtility } from '@matrix-org/olm'; import invariant from 'invariant'; import { importJSON } from './import-json.js'; @@ -16,18 +17,8 @@ return olmConfig; } -export type OLMUtility = { - +free: () => void, - +sha256: (input: string | Uint8Array) => string, - +ed25519_verify: ( - key: string, - message: string | Uint8Array, - signature: string, - ) => void, -}; - -let cachedOLMUtility: OLMUtility; -function getOLMUtility(): OLMUtility { +let cachedOLMUtility: OlmUtility; +function getOlmUtility(): OlmUtility { if (cachedOLMUtility) { return cachedOLMUtility; } @@ -35,4 +26,4 @@ return cachedOLMUtility; } -export { getOlmConfig, getOLMUtility }; +export { getOlmConfig, getOlmUtility }; diff --git a/web/flow-typed/npm/@matrix-org/olm_vx.x.x.js b/web/flow-typed/npm/@matrix-org/olm_vx.x.x.js new file mode 100644 --- /dev/null +++ b/web/flow-typed/npm/@matrix-org/olm_vx.x.x.js @@ -0,0 +1,125 @@ +// flow-typed signature: 085f002da86534cfd8cee47ffa99dd67 +// flow-typed version: <>/@matrix-org/olm_v3.2.4/flow_v0.182.0 + +declare module '@matrix-org/olm' { + + declare export class Account { + constructor(): this; + free(): void; + create(): void; + identity_keys(): string; + sign(message: string | Uint8Array): string; + one_time_keys(): string; + mark_keys_as_published(): void; + max_number_of_one_time_keys(): number; + generate_one_time_keys(number_of_keys: number): void; + remove_one_time_keys(session: Session): void; + generate_fallback_key(): void; + fallback_key(): string; + pickle(key: string | Uint8Array): string; + unpickle(key: string | Uint8Array, pickle: string): void; + } + + declare export class Session { + constructor(): this; + free(): void; + pickle(key: string | Uint8Array): string; + unpickle(key: string | Uint8Array, pickle: string): void; + create_outbound( + account: Account, their_identity_key: string, their_one_time_key: string, + ): void; + create_inbound(account: Account, one_time_key_message: string): void; + create_inbound_from( + account: Account, identity_key: string, one_time_key_message: string, + ): void; + session_id(): string; + has_received_message(): boolean; + matches_inbound(one_time_key_message: string): boolean; + matches_inbound_from(identity_key: string, one_time_key_message: string): boolean; + encrypt(plaintext: string): Object; + decrypt(message_type: number, message: string): string; + describe(): string; + } + + declare export class Utility { + constructor(): this; + free(): void; + sha256(input: string | Uint8Array): string; + ed25519_verify(key: string, message: string | Uint8Array, signature: string): void; + } + + declare class InboundGroupSession { + constructor(): this; + free(): void; + pickle(key: string | Uint8Array): string; + unpickle(key: string | Uint8Array, pickle: string): void; + create(session_key: string): string; + import_session(session_key: string): string; + decrypt(message: string): Object; + session_id(): string; + first_known_index(): number; + export_session(message_index: number): string; + } + + declare class OutboundGroupSession { + constructor(): this; + free(): void; + pickle(key: string | Uint8Array): string; + unpickle(key: string | Uint8Array, pickle: string): void; + create(): void; + encrypt(plaintext: string): string; + session_id(): string; + session_key(): string; + message_index(): number; + } + + declare class PkEncryption { + constructor(): this; + free(): void; + set_recipient_key(key: string): void; + encrypt(plaintext: string): Object; + } + + declare class PkDecryption { + constructor(): this; + free(): void; + init_with_private_key(key: Uint8Array): string; + generate_key(): string; + get_private_key(): Uint8Array; + pickle(key: string | Uint8Array): string; + unpickle(key: string | Uint8Array, pickle: string): string; + decrypt(ephemeral_key: string, mac: string, ciphertext: string): string; + } + + declare class PkSigning { + constructor(): this; + free(): void; + init_with_seed(seed: Uint8Array): string; + generate_seed(): Uint8Array; + sign(message: string): string; + } + + declare class SAS { + constructor(): this; + free(): void; + get_pubkey(): string; + set_their_key(their_key: string): void; + generate_bytes(info: string, length: number): Uint8Array; + calculate_mac(input: string, info: string): string; + calculate_mac_long_kdf(input: string, info: string): string; + } + + declare export function init(opts?: Object): Promise; + + declare export function get_library_version(): [number, number, number]; + + declare export var PRIVATE_KEY_LENGTH: number; + + declare export default { + init: typeof init, + get_library_version: typeof get_library_version, + PRIVATE_KEY_LENGTH: typeof PRIVATE_KEY_LENGTH, + Account: typeof Account, + Utility: typeof Utility, + }; +}