> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aeon.so/llms.txt
> Use this file to discover all available pages before exploring further.

# acceptWorkspaceInvite()

> Accept an invitation to join an Aeon workspace using AeonClient, authorized by a pre-generated signature.

# `acceptWorkspaceInvite(workspaceId: string, signature: string): Promise<void>`

Allows an `AeonClient` instance to accept an invitation to join a specific Aeon workspace. This operation requires cryptographic authorization in the form of a signature.

The signature must be generated beforehand by calling [`AeonSigner.signAcceptWorkspaceMessage(workspaceId)`](../../aeon-signer/sign-accept-workspace-message) with the same `workspaceId`.

## Parameters

* `workspaceId`: `string` - The unique identifier of the workspace for which the invitation is being accepted.
* `signature`: `string` - The hexadecimal string representation of the signature obtained by calling `AeonSigner.signAcceptWorkspaceMessage(workspaceId)`.

## Returns

* `Promise<void>`: A promise that resolves when the invitation has been successfully processed and the client is recognized as a member of the workspace. It rejects if there's an error, such as an invalid `workspaceId`, an expired invitation, or network issues.

## Example

```typescript theme={null}
import { AeonClient, AeonSigner } from "@aeon-protocol/aeon-sdk"; // Assuming AeonClient is available from the SDK
import { Wallet } from "ethers"; // Example: if AeonSigner is created from an ethers Wallet

// Assume 'aeonSigner' is an initialized AeonSigner instance
// const privateKeyHex = "your-private-key-hex-without-0x";
// const aeonSigner = new AeonSigner({ privateKey: Buffer.from(privateKeyHex, "hex") });

// Assume 'client' is an initialized AeonClient instance
// const client = new AeonClient({ /* ... AeonClient config ... */ });

async function joinWorkspaceWithClient(
  client: AeonClient,
  aeonSigner: AeonSigner, // AeonSigner needed to generate the signature
  workspaceId: string
) {
  try {
    console.log(
      `Generating signature to accept invitation for workspace: ${workspaceId}...`
    );
    // 1. Generate the signature using AeonSigner
    const signature = await aeonSigner.signAcceptWorkspaceMessage(workspaceId);
    console.log(`Signature obtained: ${signature}`);

    console.log(
      `Attempting to join workspace via AeonClient: ${workspaceId} with signature...`
    );
    // 2. Call acceptWorkspaceInvite on AeonClient with the workspaceId and signature
    await client.acceptWorkspaceInvite(workspaceId, signature);
    console.log(`Successfully joined workspace: ${workspaceId}`);
    // Additional logic here, e.g., fetching workspace details or roles
  } catch (error) {
    console.error(
      `Failed to join workspace ${workspaceId} via AeonClient:`,
      error
    );
    // Handle specific errors if needed
  }
}

// Example usage:
// const privateKey = Wallet.createRandom().privateKey.slice(2); // Example private key
// const signerInstance = new AeonSigner({ privateKey: Buffer.from(privateKey, "hex") });
// const clientInstance = new AeonClient({ /* ... appropriate AeonClient configuration ... */ });
// const workspaceToJoin = "some-unique-workspace-id"; // Replace with actual workspace ID
// joinWorkspaceWithClient(clientInstance, signerInstance, workspaceToJoin);
```
