@capsara/sdk 1.0.5 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +110 -28
  2. package/dist/builder/capsa-builder.d.ts +19 -11
  3. package/dist/builder/capsa-builder.d.ts.map +1 -1
  4. package/dist/builder/capsa-builder.js +149 -70
  5. package/dist/builder/capsa-builder.js.map +1 -1
  6. package/dist/client/capsara-client.d.ts +21 -26
  7. package/dist/client/capsara-client.d.ts.map +1 -1
  8. package/dist/client/capsara-client.js +86 -55
  9. package/dist/client/capsara-client.js.map +1 -1
  10. package/dist/errors/account-error.d.ts +5 -70
  11. package/dist/errors/account-error.d.ts.map +1 -1
  12. package/dist/errors/account-error.js +8 -146
  13. package/dist/errors/account-error.js.map +1 -1
  14. package/dist/errors/audit-error.d.ts +4 -28
  15. package/dist/errors/audit-error.d.ts.map +1 -1
  16. package/dist/errors/audit-error.js +9 -82
  17. package/dist/errors/audit-error.js.map +1 -1
  18. package/dist/errors/auth-error.d.ts +4 -35
  19. package/dist/errors/auth-error.d.ts.map +1 -1
  20. package/dist/errors/auth-error.js +6 -77
  21. package/dist/errors/auth-error.js.map +1 -1
  22. package/dist/errors/capsa-error.d.ts +5 -59
  23. package/dist/errors/capsa-error.d.ts.map +1 -1
  24. package/dist/errors/capsa-error.js +9 -156
  25. package/dist/errors/capsa-error.js.map +1 -1
  26. package/dist/errors/capsara-error.d.ts +24 -24
  27. package/dist/errors/capsara-error.d.ts.map +1 -1
  28. package/dist/errors/capsara-error.js +141 -34
  29. package/dist/errors/capsara-error.js.map +1 -1
  30. package/dist/errors/index.d.ts +1 -1
  31. package/dist/errors/index.d.ts.map +1 -1
  32. package/dist/index.d.ts +8 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +1 -0
  35. package/dist/index.js.map +1 -1
  36. package/dist/internal/capsa-cache.d.ts +0 -1
  37. package/dist/internal/capsa-cache.d.ts.map +1 -1
  38. package/dist/internal/capsa-cache.js +7 -5
  39. package/dist/internal/capsa-cache.js.map +1 -1
  40. package/dist/internal/config/http-client.d.ts.map +1 -1
  41. package/dist/internal/config/http-client.js +48 -21
  42. package/dist/internal/config/http-client.js.map +1 -1
  43. package/dist/internal/config/retry-interceptor.d.ts +18 -1
  44. package/dist/internal/config/retry-interceptor.d.ts.map +1 -1
  45. package/dist/internal/config/retry-interceptor.js +104 -79
  46. package/dist/internal/config/retry-interceptor.js.map +1 -1
  47. package/dist/internal/config/token-refresh.d.ts +12 -0
  48. package/dist/internal/config/token-refresh.d.ts.map +1 -0
  49. package/dist/internal/config/token-refresh.js +43 -0
  50. package/dist/internal/config/token-refresh.js.map +1 -0
  51. package/dist/internal/crypto/compression.js +1 -1
  52. package/dist/internal/crypto/compression.js.map +1 -1
  53. package/dist/internal/crypto/key-generator.d.ts +3 -6
  54. package/dist/internal/crypto/key-generator.d.ts.map +1 -1
  55. package/dist/internal/crypto/key-generator.js +26 -27
  56. package/dist/internal/crypto/key-generator.js.map +1 -1
  57. package/dist/internal/crypto/primitives.d.ts +1 -2
  58. package/dist/internal/crypto/primitives.d.ts.map +1 -1
  59. package/dist/internal/crypto/primitives.js +7 -9
  60. package/dist/internal/crypto/primitives.js.map +1 -1
  61. package/dist/internal/crypto/signatures.d.ts +3 -1
  62. package/dist/internal/crypto/signatures.d.ts.map +1 -1
  63. package/dist/internal/crypto/signatures.js +14 -6
  64. package/dist/internal/crypto/signatures.js.map +1 -1
  65. package/dist/internal/decryptor/capsa-decryptor.d.ts +8 -54
  66. package/dist/internal/decryptor/capsa-decryptor.d.ts.map +1 -1
  67. package/dist/internal/decryptor/capsa-decryptor.js +125 -150
  68. package/dist/internal/decryptor/capsa-decryptor.js.map +1 -1
  69. package/dist/internal/http-factory.d.ts +3 -19
  70. package/dist/internal/http-factory.d.ts.map +1 -1
  71. package/dist/internal/http-factory.js +3 -140
  72. package/dist/internal/http-factory.js.map +1 -1
  73. package/dist/internal/services/account-service.d.ts +11 -33
  74. package/dist/internal/services/account-service.d.ts.map +1 -1
  75. package/dist/internal/services/account-service.js +38 -53
  76. package/dist/internal/services/account-service.js.map +1 -1
  77. package/dist/internal/services/audit-service.d.ts.map +1 -1
  78. package/dist/internal/services/audit-service.js +17 -1
  79. package/dist/internal/services/audit-service.js.map +1 -1
  80. package/dist/internal/services/auth-service.d.ts +3 -0
  81. package/dist/internal/services/auth-service.d.ts.map +1 -1
  82. package/dist/internal/services/auth-service.js +68 -17
  83. package/dist/internal/services/auth-service.js.map +1 -1
  84. package/dist/internal/services/capsa-service.d.ts +2 -26
  85. package/dist/internal/services/capsa-service.d.ts.map +1 -1
  86. package/dist/internal/services/capsa-service.js +8 -34
  87. package/dist/internal/services/capsa-service.js.map +1 -1
  88. package/dist/internal/services/download-service.d.ts +13 -27
  89. package/dist/internal/services/download-service.d.ts.map +1 -1
  90. package/dist/internal/services/download-service.js +23 -57
  91. package/dist/internal/services/download-service.js.map +1 -1
  92. package/dist/internal/services/key-service.d.ts +4 -14
  93. package/dist/internal/services/key-service.d.ts.map +1 -1
  94. package/dist/internal/services/key-service.js +35 -21
  95. package/dist/internal/services/key-service.js.map +1 -1
  96. package/dist/internal/services/limits-service.d.ts +2 -16
  97. package/dist/internal/services/limits-service.d.ts.map +1 -1
  98. package/dist/internal/services/limits-service.js +18 -28
  99. package/dist/internal/services/limits-service.js.map +1 -1
  100. package/dist/internal/services/upload-service.d.ts +33 -26
  101. package/dist/internal/services/upload-service.d.ts.map +1 -1
  102. package/dist/internal/services/upload-service.js +309 -133
  103. package/dist/internal/services/upload-service.js.map +1 -1
  104. package/dist/internal/types.d.ts +0 -1
  105. package/dist/internal/types.d.ts.map +1 -1
  106. package/dist/internal/utils/filename-check.d.ts +11 -0
  107. package/dist/internal/utils/filename-check.d.ts.map +1 -0
  108. package/dist/internal/utils/filename-check.js +28 -0
  109. package/dist/internal/utils/filename-check.js.map +1 -0
  110. package/dist/internal/utils/safe-filename.d.ts +31 -0
  111. package/dist/internal/utils/safe-filename.d.ts.map +1 -0
  112. package/dist/internal/utils/safe-filename.js +126 -0
  113. package/dist/internal/utils/safe-filename.js.map +1 -0
  114. package/dist/internal/version.d.ts +2 -16
  115. package/dist/internal/version.d.ts.map +1 -1
  116. package/dist/internal/version.js +4 -16
  117. package/dist/internal/version.js.map +1 -1
  118. package/dist/types/index.d.ts +26 -10
  119. package/dist/types/index.d.ts.map +1 -1
  120. package/dist/types/index.js.map +1 -1
  121. package/package.json +13 -11
  122. package/dist/internal/index.d.ts +0 -5
  123. package/dist/internal/index.d.ts.map +0 -1
  124. package/dist/internal/index.js +0 -5
  125. package/dist/internal/index.js.map +0 -1
  126. package/dist/internal/retry-executor.d.ts +0 -74
  127. package/dist/internal/retry-executor.d.ts.map +0 -1
  128. package/dist/internal/retry-executor.js +0 -204
  129. package/dist/internal/retry-executor.js.map +0 -1
package/README.md CHANGED
@@ -11,6 +11,11 @@ A **capsa** is a zero-knowledge encrypted envelope for securely exchanging files
11
11
  - **Encrypted subject, body, and structured data**
12
12
  - **Batch sending** with automatic chunking
13
13
 
14
+ ## Requirements
15
+
16
+ - Node.js 20 or later
17
+ - The package is published as an ES module
18
+
14
19
  ## Installation
15
20
 
16
21
  ```bash
@@ -33,14 +38,14 @@ Authentication requires two steps: login with your credentials, then set your pr
33
38
 
34
39
  ```typescript
35
40
  await client.login({
36
- email: 'you@example.com',
41
+ partyId: 'party_...',
37
42
  password: '...'
38
43
  });
39
44
  ```
40
45
 
41
46
  ### Set Private Key
42
47
 
43
- After logging in, set your private key for signing and decryption. Generate and register your keypair using `generateKeyPair()` and `addPublicKey()`, then store the private key securely.
48
+ After logging in, set your private key for signing and decryption. Generate and register your keypair using `CapsaraClient.generateKeyPair()` and `addPublicKey()`, then store the private key securely.
44
49
 
45
50
  ```typescript
46
51
  // Your code to load the private key from secure storage (key vault, HSM, etc.)
@@ -51,7 +56,7 @@ client.setPrivateKey(privateKey);
51
56
 
52
57
  ## Sending Capsas
53
58
 
54
- Use the `CapsaBuilder` to create capsas with recipients and files. Always use `sendCapsas()` even for a single capsa since it handles encryption and batching efficiently.
59
+ Use a capsa builder to create capsas with recipients and files. Always use `sendCapsas()` even for a single capsa since it handles encryption and batching efficiently.
55
60
 
56
61
  ```typescript
57
62
  import { CapsaraClient, CapsaraError, FileInput } from '@capsara/sdk';
@@ -60,9 +65,8 @@ try {
60
65
  // Create a builder for each capsa you want to send
61
66
  const builder = await client.createCapsaBuilder();
62
67
 
63
- // Add recipients (can add multiple)
68
+ // Add the recipient (one per capsa; their delegates are added automatically)
64
69
  builder.addRecipient('party_recipient1');
65
- builder.addRecipient('party_recipient2');
66
70
 
67
71
  // Add files from path or buffer
68
72
  builder.addFile(FileInput.fromPath('./documents/policy.pdf'));
@@ -91,7 +95,9 @@ try {
91
95
  }
92
96
  } catch (error) {
93
97
  if (error instanceof CapsaraError) {
94
- console.error('Failed to send:', error.message);
98
+ console.error(`Failed to send: ${error.code} ${error.message}`);
99
+ } else {
100
+ throw error;
95
101
  }
96
102
  }
97
103
  ```
@@ -114,7 +120,30 @@ matter2
114
120
  await client.sendCapsas([matter1, matter2]);
115
121
  ```
116
122
 
117
- The SDK automatically splits large batches to stay within server limits.
123
+ Each capsa goes to exactly one recipient, its principal. Multi-party access comes through that recipient's delegates, which the SDK adds automatically, each with its own encrypted key and acting for the recipient. A second `addRecipient()` on the same builder throws, and a builder with no recipient is rejected before anything is sent. To send to yourself, pass your own party ID; your delegates are then included. To reach several recipients, create one builder per recipient and send them together in one batch:
124
+
125
+ ```typescript
126
+ const recipients = ['party_recipient1', 'party_recipient2'];
127
+
128
+ const builders = await Promise.all(recipients.map(async (recipient) => {
129
+ const builder = await client.createCapsaBuilder();
130
+ return builder
131
+ .addRecipient(recipient)
132
+ .withSubject('Policy Documents - Q1 2025')
133
+ .addFile(FileInput.fromPath('./documents/policy.pdf'))
134
+ .withExpiration(new Date(Date.now() + 90 * 24 * 60 * 60 * 1000));
135
+ }));
136
+
137
+ const result = await client.sendCapsas(builders);
138
+ for (const error of result.errors ?? []) {
139
+ // code is the reason the capsa was rejected, e.g. DELEGATE_PRINCIPAL_MISMATCH
140
+ console.error(`Capsa ${error.index} failed: ${error.error} (${error.code})`);
141
+ }
142
+ ```
143
+
144
+ The builder class is not exported by name. Let TypeScript infer it from `createCapsaBuilder()`, or name it as `Awaited<ReturnType<CapsaraClient['createCapsaBuilder']>>`.
145
+
146
+ The SDK automatically splits large batches to stay within server limits. Call `getLimits()` to read the current limits.
118
147
 
119
148
  ## Receiving Capsas
120
149
 
@@ -129,9 +158,9 @@ const response = await client.listCapsas({
129
158
  console.log(`Found ${response.capsas.length} capsas`);
130
159
 
131
160
  for (const capsa of response.capsas) {
132
- console.log(`- ${capsa.id}: ${capsa.fileCount} files`);
161
+ console.log(`- ${capsa.id} (${capsa.status ?? 'unknown'})`);
133
162
  console.log(` Created: ${capsa.createdAt}`);
134
- console.log(` From: ${capsa.creatorId}`);
163
+ console.log(` From: ${capsa.creator}`);
135
164
  }
136
165
 
137
166
  // Pagination
@@ -144,8 +173,13 @@ if (response.pagination.hasMore) {
144
173
 
145
174
  ### Get Capsa and Download Files
146
175
 
176
+ A file's `filename` comes from the sender and is untrusted, so write each file under a directory you choose using `safeFilename`, which is always a single, safe path segment (see `sanitizeFilename` for the rules):
177
+
147
178
  ```typescript
148
179
  import fs from 'node:fs';
180
+ import path from 'node:path';
181
+
182
+ const downloadDir = './downloads';
149
183
 
150
184
  const capsa = await client.getCapsa('capsa_abc-123');
151
185
 
@@ -155,8 +189,8 @@ console.log('Structured data:', capsa.structured);
155
189
 
156
190
  // Download each file
157
191
  for (const file of capsa.files) {
158
- const { data, filename } = await client.downloadFile(capsa.packageId, file.id);
159
- fs.writeFileSync(`./downloads/${filename}`, data);
192
+ const { data, safeFilename } = await client.downloadFile(capsa.id, file.fileId);
193
+ fs.writeFileSync(path.join(downloadDir, safeFilename), data);
160
194
  }
161
195
  ```
162
196
 
@@ -164,13 +198,14 @@ for (const file of capsa.files) {
164
198
 
165
199
  Capsara supports delegation for scenarios where a system acts on behalf of a party. For example, an agency management system (AMS) might process capsas on behalf of the agencies it serves. When a capsa is sent to a delegated recipient, the delegate receives its own RSA-encrypted copy of the master key. If the recipient also has a public key registered in the system, they receive their own encrypted copy as well. Otherwise, only the delegate can decrypt on their behalf.
166
200
 
167
- If you're a delegate, the flow is identical to receiving. List your capsas and check the `actingFor` field on each one to see which party it belongs to. This lets you route the data to the correct recipient in your system.
201
+ If you're a delegate, the flow is identical to receiving. To see which party a capsa belongs to, find your own entry in the capsa's keychain: its `actingFor` field lists the party IDs you act for on that capsa. This lets you route the data to the correct recipient in your system.
168
202
 
169
203
  ```typescript
170
204
  // Authenticate as the delegate (e.g., an AMS)
171
205
  const client = new CapsaraClient('https://capsara-env-api-url.com');
172
- await client.login({ email: 'ams@example.com', password: '...' });
206
+ const auth = await client.login({ partyId: 'party_...', password: '...' });
173
207
  client.setPrivateKey(loadPrivateKeyFromSecureStorage());
208
+ const myPartyId = auth.party.id;
174
209
 
175
210
  // List capsas (includes capsas for all parties you represent)
176
211
  const response = await client.listCapsas();
@@ -179,22 +214,56 @@ for (const summary of response.capsas) {
179
214
  const capsa = await client.getCapsa(summary.id);
180
215
 
181
216
  // Check who this capsa is for
182
- if (capsa.actingFor) {
183
- console.log(`Capsa ${summary.id} is for agency ${capsa.actingFor}`);
184
- routeToAgency(capsa.actingFor, capsa);
217
+ const myEntry = capsa.keychain.keys.find((entry) => entry.party === myPartyId);
218
+ const agencyId = myEntry?.actingFor?.[0];
219
+ if (agencyId) {
220
+ console.log(`Capsa ${summary.id} is for agency ${agencyId}`);
221
+ routeToAgency(agencyId, capsa);
185
222
  }
186
223
 
187
224
  // Download and process files
188
225
  for (const file of capsa.files) {
189
- const { data, filename } = await client.downloadFile(summary.id, file.id);
190
- processFile(capsa.actingFor, filename, data);
226
+ const { data, safeFilename } = await client.downloadFile(summary.id, file.fileId);
227
+ processFile(agencyId, safeFilename, data);
191
228
  }
192
229
  }
193
230
  ```
194
231
 
232
+ ## Error Handling
233
+
234
+ Every SDK error is a `CapsaraError`. The subclasses `CapsaraAuthError`, `CapsaraCapsaError`, `CapsaraAuditError` and `CapsaraAccountError` tell you which area failed.
235
+
236
+ ```typescript
237
+ import { CapsaraAuthError, CapsaraCapsaError, CapsaraError } from '@capsara/sdk';
238
+
239
+ try {
240
+ const capsa = await client.getCapsa('capsa_abc-123');
241
+ } catch (error) {
242
+ if (error instanceof CapsaraAuthError) {
243
+ console.error(`Auth error: ${error.message} (${error.code})`);
244
+ } else if (error instanceof CapsaraCapsaError) {
245
+ console.error(`Capsa error: ${error.message} (${error.code})`);
246
+ } else if (error instanceof CapsaraError) {
247
+ console.error(`Error: ${error.message} (${error.code})`);
248
+ } else {
249
+ throw error;
250
+ }
251
+ }
252
+ ```
253
+
254
+ Every `CapsaraError` exposes:
255
+
256
+ - `code`: the API error code exactly as the server sent it (e.g. `ENVELOPE_NOT_FOUND`, `RATE_LIMIT_EXCEEDED`), or an SDK code for client-side failures. A response without a usable error body gets `HTTP_<status>`.
257
+ - `statusCode`: the HTTP status (0 for client-side failures).
258
+ - `details`: the server's details as sent, when provided.
259
+ - `retryAfter`: seconds to wait on 429/503, when provided.
260
+ - `requestId`: the server request ID, when provided.
261
+
262
+ Expired and deleted capsas fail with `CapsaraCapsaError` status 410 and code `ENVELOPE_EXPIRED` or `ENVELOPE_DELETED`. Signature problems fail before decryption with `SIGNATURE_KEY_MISSING`, `SIGNATURE_KEY_MISMATCH` or `SIGNATURE_VERIFICATION_FAILED`. A capsa encrypted to a key you have not configured fails with `PRIVATE_KEY_NOT_AVAILABLE`.
263
+
195
264
  ## Encryption
196
265
 
197
- Every capsa is protected by a unique AES-256-GCM symmetric key (the "master key") generated at send time. Files and metadata (subject, body, and structured data) are each encrypted with this master key using a fresh random IV, producing authenticated ciphertext that guarantees both confidentiality and tamper detection. The master key itself is then encrypted once per authorized party and any authorized delegates using their RSA-4096 public key with OAEP-SHA256 padding, so only the holder of the corresponding private key can recover it. Each file is independently hashed with SHA-256 before encryption, and these hashes along with all IVs are bound into a canonical string that the sender signs using RS256 (RSA-SHA256 in JWS format). Recipients and the server validate this signature against the sender's public key before trusting any content, ensuring both authenticity and integrity of the entire capsa. Key fingerprints are SHA-256 hashes of the public key PEM, providing a compact identifier for key verification. Files are gzip-compressed before encryption by default to reduce storage and transfer costs. All encryption, decryption, signing, and verification happen locally in the SDK. Capsara's servers only ever store ciphertext and cannot read your files, your metadata, or your keys.
266
+ Every capsa is protected by its own AES-256-GCM key (the "master key"), generated in the SDK at send time. Files, filenames, and the subject, body and structured data are each encrypted with the master key under a fresh random IV, so any change to the ciphertext is detected on decryption. Files are gzip-compressed before encryption by default. The master key is then encrypted for the sender, the recipient and each of the recipient's delegates with their RSA-4096 public key using OAEP with SHA-256, so only the holder of a matching private key can recover it. The sender signs the capsa with RS256 (RSA-SHA256 in JWS format) over a canonical string that binds the capsa ID, its total size, the key-encryption algorithm, the sender's party ID, the fingerprint of the sender's public key, the SHA-256 hash of each encrypted file, every file and filename IV, and the IVs of the subject, body and structured data. The server checks this signature at upload. On receive, the SDK checks the sender's public key against the sender's keychain fingerprint, rebuilds the canonical string from the capsa it received, and verifies the signature before decrypting anything, so a signature cannot be moved to another capsa or key. Key fingerprints are lowercase hex SHA-256 hashes of the DER-encoded SubjectPublicKeyInfo, so PEM formatting does not change them. All encryption, decryption, signing, and verification happen locally in the SDK. Capsara's servers only ever store ciphertext and cannot read your files, your metadata, or your keys.
198
267
 
199
268
  ## Private Key Security
200
269
 
@@ -204,27 +273,40 @@ You are fully responsible for your private key's lifecycle: generation, secure s
204
273
 
205
274
  The SDK provides a `rotateKey()` method that generates a new RSA-4096 key pair and registers the new public key with Capsara. New capsas sent to you will be encrypted with your new key. However, capsas are immutable once created and their keychain and encrypted contents never change. Existing capsas remain accessible only with the private key that was active when they were created. Keep prior private keys available for as long as you need access to capsas encrypted under them.
206
275
 
276
+ Pass `onKeyPairGenerated` to `rotateKey()` to store the new key pair before it is registered, so a lost response cannot lose the key; if the callback throws, nothing is registered. After a successful rotation the client uses the new private key and keeps the previous one for decrypting older capsas. After a restart, give the client your older keys with `addPreviousPrivateKey()` or the `previousPrivateKeys` client option. The SDK picks the key whose fingerprint matches your keychain entry; if none matches it throws `PRIVATE_KEY_NOT_AVAILABLE`.
277
+
207
278
  ## API Reference
208
279
 
209
280
  | Method | Description |
210
281
  |--------|-------------|
211
- | `CapsaraClient.generateKeyPair()` | Generate an RSA-4096 key pair (static) |
212
- | `login(credentials)` | Authenticate with email and password |
213
- | `logout()` | Log out and clear cached data |
282
+ | `CapsaraClient.generateKeyPair()` | Generate an RSA-4096 key pair (static, async) |
283
+ | `login(credentials)` | Authenticate with party ID and password |
284
+ | `logout()` | Clear local tokens and cached data, then revoke the session (throws `CapsaraAuthError` if the server does not confirm) |
285
+ | `isAuthenticated()` | Check whether the client has an access token |
214
286
  | `setPrivateKey(privateKey)` | Set the private key for signing and decryption |
215
- | `createCapsaBuilder()` | Create a `CapsaBuilder` pre-loaded with server limits |
287
+ | `addPreviousPrivateKey(privateKey)` | Keep a rotated-out private key for older capsas |
288
+ | `createCapsaBuilder()` | Create a capsa builder pre-loaded with server limits |
216
289
  | `sendCapsas(builders)` | Encrypt and send one or more capsas |
217
- | `getCapsa(capsaId)` | Fetch and decrypt a capsa |
290
+ | `getCapsa(capsaId)` | Fetch, verify and decrypt a capsa |
218
291
  | `listCapsas(filters?)` | List capsas with optional filters |
219
292
  | `deleteCapsa(capsaId)` | Soft-delete a capsa |
220
293
  | `downloadFile(capsaId, fileId)` | Download and decrypt a file |
221
- | `getAuditEntries(capsaId)` | Get audit trail entries |
222
- | `addPublicKey(key, fingerprint)` | Register a new public key |
223
- | `rotateKey()` | Generate and register a new key pair |
224
- | `getKeyHistory()` | Get previous public keys |
294
+ | `getAuditEntries(capsaId, filters?)` | Get audit trail entries |
295
+ | `createAuditEntry(capsaId, entry)` | Add an audit entry (`log` or `processed`) |
296
+ | `getCurrentPublicKey()` | Get your current registered public key |
297
+ | `addPublicKey(key, fingerprint, reason?)` | Register a new public key |
298
+ | `rotateKey(options?)` | Generate and register a new key pair, then switch to it |
299
+ | `getKeyHistory()` | Get the fingerprints and rotation dates of previous keys |
225
300
  | `getLimits()` | Get server-enforced limits |
301
+ | `clearCache()` | Clear cached master keys |
226
302
  | `destroy()` | Release resources and clear keys |
227
303
 
304
+ ## Support
305
+
306
+ Email support@tessarai.com.
307
+
228
308
  ## License
229
309
 
230
310
  Capsara SDK License. See [LICENSE](./LICENSE) for details.
311
+
312
+ Copyright (c) 2024-2026 Tessarai, LLC and Laird Rixford. All rights reserved.
@@ -40,7 +40,7 @@ export interface BuiltCapsa {
40
40
  }
41
41
  /** Server-aligned validation constants. */
42
42
  export declare const SERVER_LIMITS: {
43
- /** Maximum keychain entries (recipients + creator + delegates) */
43
+ /** Maximum keychain entries (creator + recipient + delegates) */
44
44
  readonly MAX_KEYCHAIN_KEYS: 100;
45
45
  /** Maximum base64url-encoded encrypted subject length */
46
46
  readonly MAX_ENCRYPTED_SUBJECT: 65536;
@@ -64,8 +64,8 @@ export declare const SERVER_LIMITS: {
64
64
  readonly MAX_ENCRYPTED_FILENAME: 2048;
65
65
  /** Maximum base64url-encoded signature payload length */
66
66
  readonly MAX_SIGNATURE_PAYLOAD: 65536;
67
- /** Maximum parties a delegate can act for */
68
- readonly MAX_ACTING_FOR: 10;
67
+ /** Maximum UTF-8 bytes of one JSON part in the upload request (the serialized capsa) */
68
+ readonly MAX_JSON_FIELD: 1048576;
69
69
  };
70
70
  export declare class CapsaBuilder {
71
71
  #private;
@@ -79,19 +79,26 @@ export declare class CapsaBuilder {
79
79
  set expiresAt(value: Date | string | undefined);
80
80
  constructor(creatorId: string, creatorPrivateKey: string, limits: SystemLimits);
81
81
  /**
82
- * Add a recipient to the capsa
82
+ * Set the capsa's recipient (its principal).
83
+ *
84
+ * A capsa goes to exactly one recipient. The recipient's registered delegates
85
+ * are added automatically at send time, each acting for this recipient, so
86
+ * several parties can still access the capsa through their own keys. To send
87
+ * to several recipients, use one builder per recipient and send them together
88
+ * in one batch with sendCapsas().
89
+ *
90
+ * The recipient may be the creator itself (a self-send); the creator's own
91
+ * delegates are then added, acting for the creator.
83
92
  * @param partyId - Party ID
93
+ * @throws Error if a recipient has already been added
84
94
  */
85
95
  addRecipient(partyId: string): this;
86
- /**
87
- * Add multiple recipients to the capsa
88
- * @param partyIds - Party IDs
89
- */
90
- addRecipients(...partyIds: string[]): this;
91
96
  /**
92
97
  * Add a file to the capsa
93
98
  * @param input - File input (path or buffer with filename)
94
- * @throws Error if file exceeds size limit or too many files
99
+ * @throws CapsaraError (VALIDATION_ERROR) if the file name contains "/", "\" or
100
+ * control characters, is empty or only spaces, or is "." or ".."; if the file
101
+ * exceeds the size limit; or if the capsa already has the maximum number of files
95
102
  */
96
103
  addFile(input: FileInput): this;
97
104
  /**
@@ -160,7 +167,8 @@ export declare class CapsaBuilder {
160
167
  getFileCount(): number;
161
168
  /**
162
169
  * Build the capsa with encryption and signature.
163
- * @param partyKeys - Public keys for all recipients
170
+ * @param partyKeys - Public keys for the creator, the recipient and its delegates
171
+ * (other parties in the list are ignored)
164
172
  */
165
173
  build(partyKeys: PartyKey[]): Promise<BuiltCapsa>;
166
174
  }
@@ -1 +1 @@
1
- {"version":3,"file":"capsa-builder.d.ts","sourceRoot":"","sources":["../../src/builder/capsa-builder.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAsB1D,OAAO,KAAK,EACV,SAAS,EAET,QAAQ,EAER,YAAY,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,aAAa,EAEd,MAAM,sBAAsB,CAAC;AAE9B,gCAAgC;AAChC,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;IACvD,SAAS,EAAE;Q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