@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

next
ts 65 lines 2.37 KB
Raw
1 /**
2 * @fileoverview The `composio.keyring` namespace: the public transfer keys of
3 * the organization's customer-managed keyring.
4 *
5 * @module Keyring
6 */
7 import ComposioClient from '@composio/client';
8 import { KeyringTransferKeysResponse } from '../types/keyring.types';
9 import { ComposioRequestOptions } from '../types/requestOptions.types';
10 import { telemetry } from '../telemetry/Telemetry';
11 import { withCancellation } from '../utils/cancellation';
12 import { transformKeyringTransferKeysResponse } from '../utils/transformers/keyring';
13
14 /**
15 * `composio.keyring` — the organization's customer-managed keyring.
16 *
17 * @example
18 * ```typescript
19 * const { activeKid, keys } = await composio.keyring.listTransferKeys();
20 * const sealingKey = keys.find(key => key.kid === activeKid);
21 * ```
22 */
23 export class Keyring {
24 private client: ComposioClient;
25
26 constructor(client: ComposioClient) {
27 this.client = client;
28 telemetry.instrument(this, 'Keyring');
29 }
30
31 /**
32 * Lists the public transfer keys of the organization's active customer
33 * keyring, the keys a secret is sealed to before it is sent to Composio.
34 *
35 * Always seal new secrets to the key whose `kid` is `activeKid`: a JWE with
36 * `RSA-OAEP-256` key management, `A256GCM` content encryption, and the
37 * `kid` in the protected header. Older keys stay listed so values sealed to
38 * them remain openable.
39 *
40 * The organization behind the API key must have an ACTIVE customer keyring
41 * instance; otherwise the API answers 404.
42 *
43 * @returns {Promise<KeyringTransferKeysResponse>} The active key ID and every accepted public JWK, newest first
44 *
45 * @example
46 * ```typescript
47 * import { CompactEncrypt, importJWK } from 'jose';
48 *
49 * const { activeKid, keys } = await composio.keyring.listTransferKeys();
50 * const jwk = keys.find(key => key.kid === activeKid)!;
51 * const sealed = await new CompactEncrypt(new TextEncoder().encode(secret))
52 * .setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM', kid: activeKid })
53 * .encrypt(await importJWK(jwk, 'RSA-OAEP-256'));
54 * ```
55 */
56 async listTransferKeys(
57 requestOptions?: ComposioRequestOptions
58 ): Promise<KeyringTransferKeysResponse> {
59 const result = await withCancellation(
60 () => this.client.keyring.listTransferKeys(requestOptions),
61 requestOptions?.signal
62 );
63 return transformKeyringTransferKeysResponse(result);
64 }
65 }