Skip to content

Commit

Permalink
chore: expose e2ei_rotate in the wasm wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
typfel committed Oct 9, 2024
1 parent 2612a59 commit ef3c383
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
41 changes: 41 additions & 0 deletions crypto-ffi/bindings/js/CoreCrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,47 @@ export class CoreCrypto {
}
}

/**
* Creates an update commit which replaces your leaf containing basic credentials with a leaf node containing x509 credentials in the conversation.
*
* NOTE: you can only call this after you've completed the enrollment for an end-to-end identity, calling this without
* a valid end-to-end identity will result in an error.
*
* **CAUTION**: {@link CoreCrypto.commitAccepted} **HAS TO** be called afterward **ONLY IF** the Delivery Service responds
* '200 OK' to the {@link CommitBundle} upload. It will "merge" the commit locally i.e. increment the local group
* epoch, use new encryption secrets etc...
*
* @param conversationId - The ID of the conversation
*
* @returns A {@link CommitBundle}
*/
async e2eiRotate(
conversationId: ConversationId
): Promise<CommitBundle> {
try {
const ffiRet: CoreCryptoFfiTypes.CommitBundle =
await CoreCryptoError.asyncMapErr(
this.#cc.e2ei_rotate(conversationId)
);

const gi = ffiRet.group_info;

const ret: CommitBundle = {
welcome: ffiRet.welcome,
commit: ffiRet.commit,
groupInfo: {
encryptionType: gi.encryption_type,
ratchetTreeType: gi.ratchet_tree_type,
payload: gi.payload,
},
};

return ret;
} catch (e) {
throw CoreCryptoError.fromStdError(e as Error);
}
}

/**
* Commits the local pending proposals and returns the {@link CommitBundle} object containing what can result from this operation.
*
Expand Down
20 changes: 20 additions & 0 deletions crypto-ffi/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,26 @@ impl CoreCrypto {
.err_into(),
)
}
/// Returns: [`WasmCryptoResult<CommitBundle>`]
///
/// see [core_crypto::mls::MlsCentral::e2ei_rotate_all]
pub fn e2ei_rotate(&self, conversation_id: ConversationId) -> Promise {
let this = self.inner.clone();
future_to_promise(
async move {
let mut central = this.write().await;
let commit = central
.e2ei_rotate(&conversation_id, None)
.await
.map_err(CoreCryptoError::from)?;

let commit: CommitBundle = commit.try_into()?;

WasmCryptoResult::Ok(serde_wasm_bindgen::to_value(&commit)?)
}
.err_into(),
)
}

/// see [core_crypto::mls::MlsCentral::e2ei_enrollment_stash]
pub fn e2ei_enrollment_stash(&self, enrollment: E2eiEnrollment) -> Promise {
Expand Down

0 comments on commit ef3c383

Please sign in to comment.