@capsara/sdk 1.0.5 → 2.0.1
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.
- package/README.md +110 -28
- package/dist/builder/capsa-builder.d.ts +29 -13
- package/dist/builder/capsa-builder.d.ts.map +1 -1
- package/dist/builder/capsa-builder.js +302 -84
- package/dist/builder/capsa-builder.js.map +1 -1
- package/dist/client/capsara-client.d.ts +30 -26
- package/dist/client/capsara-client.d.ts.map +1 -1
- package/dist/client/capsara-client.js +102 -60
- package/dist/client/capsara-client.js.map +1 -1
- package/dist/errors/account-error.d.ts +5 -70
- package/dist/errors/account-error.d.ts.map +1 -1
- package/dist/errors/account-error.js +8 -146
- package/dist/errors/account-error.js.map +1 -1
- package/dist/errors/audit-error.d.ts +4 -28
- package/dist/errors/audit-error.d.ts.map +1 -1
- package/dist/errors/audit-error.js +9 -82
- package/dist/errors/audit-error.js.map +1 -1
- package/dist/errors/auth-error.d.ts +4 -35
- package/dist/errors/auth-error.d.ts.map +1 -1
- package/dist/errors/auth-error.js +6 -77
- package/dist/errors/auth-error.js.map +1 -1
- package/dist/errors/capsa-error.d.ts +5 -59
- package/dist/errors/capsa-error.d.ts.map +1 -1
- package/dist/errors/capsa-error.js +9 -156
- package/dist/errors/capsa-error.js.map +1 -1
- package/dist/errors/capsara-error.d.ts +24 -24
- package/dist/errors/capsara-error.d.ts.map +1 -1
- package/dist/errors/capsara-error.js +141 -34
- package/dist/errors/capsara-error.js.map +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/capsa-cache.d.ts +0 -3
- package/dist/internal/capsa-cache.d.ts.map +1 -1
- package/dist/internal/capsa-cache.js +7 -23
- package/dist/internal/capsa-cache.js.map +1 -1
- package/dist/internal/config/http-client.d.ts.map +1 -1
- package/dist/internal/config/http-client.js +48 -21
- package/dist/internal/config/http-client.js.map +1 -1
- package/dist/internal/config/retry-interceptor.d.ts +26 -3
- package/dist/internal/config/retry-interceptor.d.ts.map +1 -1
- package/dist/internal/config/retry-interceptor.js +111 -83
- package/dist/internal/config/retry-interceptor.js.map +1 -1
- package/dist/internal/config/token-refresh.d.ts +12 -0
- package/dist/internal/config/token-refresh.d.ts.map +1 -0
- package/dist/internal/config/token-refresh.js +43 -0
- package/dist/internal/config/token-refresh.js.map +1 -0
- package/dist/internal/crypto/compression.d.ts +12 -0
- package/dist/internal/crypto/compression.d.ts.map +1 -1
- package/dist/internal/crypto/compression.js +14 -1
- package/dist/internal/crypto/compression.js.map +1 -1
- package/dist/internal/crypto/key-generator.d.ts +39 -4
- package/dist/internal/crypto/key-generator.d.ts.map +1 -1
- package/dist/internal/crypto/key-generator.js +93 -24
- package/dist/internal/crypto/key-generator.js.map +1 -1
- package/dist/internal/crypto/primitives.d.ts +1 -2
- package/dist/internal/crypto/primitives.d.ts.map +1 -1
- package/dist/internal/crypto/primitives.js +15 -14
- package/dist/internal/crypto/primitives.js.map +1 -1
- package/dist/internal/crypto/signatures.d.ts +3 -1
- package/dist/internal/crypto/signatures.d.ts.map +1 -1
- package/dist/internal/crypto/signatures.js +14 -6
- package/dist/internal/crypto/signatures.js.map +1 -1
- package/dist/internal/decryptor/capsa-decryptor.d.ts +11 -54
- package/dist/internal/decryptor/capsa-decryptor.d.ts.map +1 -1
- package/dist/internal/decryptor/capsa-decryptor.js +167 -160
- package/dist/internal/decryptor/capsa-decryptor.js.map +1 -1
- package/dist/internal/http-factory.d.ts +3 -47
- package/dist/internal/http-factory.d.ts.map +1 -1
- package/dist/internal/http-factory.js +2 -157
- package/dist/internal/http-factory.js.map +1 -1
- package/dist/internal/logging.d.ts +13 -0
- package/dist/internal/logging.d.ts.map +1 -0
- package/dist/internal/logging.js +22 -0
- package/dist/internal/logging.js.map +1 -0
- package/dist/internal/services/account-service.d.ts +11 -33
- package/dist/internal/services/account-service.d.ts.map +1 -1
- package/dist/internal/services/account-service.js +38 -53
- package/dist/internal/services/account-service.js.map +1 -1
- package/dist/internal/services/audit-service.d.ts.map +1 -1
- package/dist/internal/services/audit-service.js +17 -1
- package/dist/internal/services/audit-service.js.map +1 -1
- package/dist/internal/services/auth-service.d.ts +17 -1
- package/dist/internal/services/auth-service.d.ts.map +1 -1
- package/dist/internal/services/auth-service.js +188 -51
- package/dist/internal/services/auth-service.js.map +1 -1
- package/dist/internal/services/capsa-service.d.ts +8 -26
- package/dist/internal/services/capsa-service.d.ts.map +1 -1
- package/dist/internal/services/capsa-service.js +91 -44
- package/dist/internal/services/capsa-service.js.map +1 -1
- package/dist/internal/services/download-service.d.ts +17 -25
- package/dist/internal/services/download-service.d.ts.map +1 -1
- package/dist/internal/services/download-service.js +30 -56
- package/dist/internal/services/download-service.js.map +1 -1
- package/dist/internal/services/key-service.d.ts +6 -14
- package/dist/internal/services/key-service.d.ts.map +1 -1
- package/dist/internal/services/key-service.js +63 -21
- package/dist/internal/services/key-service.js.map +1 -1
- package/dist/internal/services/limits-service.d.ts +14 -16
- package/dist/internal/services/limits-service.d.ts.map +1 -1
- package/dist/internal/services/limits-service.js +60 -28
- package/dist/internal/services/limits-service.js.map +1 -1
- package/dist/internal/services/upload-service.d.ts +33 -27
- package/dist/internal/services/upload-service.d.ts.map +1 -1
- package/dist/internal/services/upload-service.js +307 -133
- package/dist/internal/services/upload-service.js.map +1 -1
- package/dist/internal/types.d.ts +0 -7
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/internal/upload/multipart-builder.d.ts +0 -15
- package/dist/internal/upload/multipart-builder.d.ts.map +1 -1
- package/dist/internal/upload/multipart-builder.js +0 -26
- package/dist/internal/upload/multipart-builder.js.map +1 -1
- package/dist/internal/utils/filename-check.d.ts +11 -0
- package/dist/internal/utils/filename-check.d.ts.map +1 -0
- package/dist/internal/utils/filename-check.js +28 -0
- package/dist/internal/utils/filename-check.js.map +1 -0
- package/dist/internal/utils/rfc3339.d.ts +15 -0
- package/dist/internal/utils/rfc3339.d.ts.map +1 -0
- package/dist/internal/utils/rfc3339.js +53 -0
- package/dist/internal/utils/rfc3339.js.map +1 -0
- package/dist/internal/utils/safe-filename.d.ts +31 -0
- package/dist/internal/utils/safe-filename.d.ts.map +1 -0
- package/dist/internal/utils/safe-filename.js +126 -0
- package/dist/internal/utils/safe-filename.js.map +1 -0
- package/dist/internal/version.d.ts +18 -14
- package/dist/internal/version.d.ts.map +1 -1
- package/dist/internal/version.js +47 -14
- package/dist/internal/version.js.map +1 -1
- package/dist/types/index.d.ts +26 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +13 -11
- package/dist/internal/index.d.ts +0 -5
- package/dist/internal/index.d.ts.map +0 -1
- package/dist/internal/index.js +0 -5
- package/dist/internal/index.js.map +0 -1
- package/dist/internal/retry-executor.d.ts +0 -74
- package/dist/internal/retry-executor.d.ts.map +0 -1
- package/dist/internal/retry-executor.js +0 -204
- 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
|
-
|
|
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
|
|
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
|
|
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(
|
|
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
|
-
|
|
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}
|
|
161
|
+
console.log(`- ${capsa.id} (${capsa.status ?? 'unknown'})`);
|
|
133
162
|
console.log(` Created: ${capsa.createdAt}`);
|
|
134
|
-
console.log(` From: ${capsa.
|
|
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,
|
|
159
|
-
fs.writeFileSync(
|
|
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.
|
|
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({
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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,
|
|
190
|
-
processFile(
|
|
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`, `FINGERPRINT_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
|
|
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
|
|
213
|
-
| `logout()` |
|
|
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
|
-
| `
|
|
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
|
-
| `
|
|
223
|
-
| `
|
|
224
|
-
| `
|
|
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.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/** Fluent capsa builder for creating encrypted capsas. */
|
|
2
2
|
import type { FileInput, PartyKey, SystemLimits } from '../types/index.js';
|
|
3
3
|
import type { CapsaMetadata, KeychainEntry, EncryptedFile } from '../internal/types.js';
|
|
4
|
+
/** Refusal for structured data that is not a JSON object; the same text in every sender SDK. */
|
|
5
|
+
export declare const STRUCTURED_NOT_OBJECT_MESSAGE = "Structured data must be a JSON object (not an array, string, number or null).";
|
|
4
6
|
/** Capsa metadata for upload */
|
|
5
7
|
export interface CapsaUploadData {
|
|
6
8
|
packageId: string;
|
|
@@ -40,7 +42,7 @@ export interface BuiltCapsa {
|
|
|
40
42
|
}
|
|
41
43
|
/** Server-aligned validation constants. */
|
|
42
44
|
export declare const SERVER_LIMITS: {
|
|
43
|
-
/** Maximum keychain entries (
|
|
45
|
+
/** Maximum keychain entries (creator + recipient + delegates) */
|
|
44
46
|
readonly MAX_KEYCHAIN_KEYS: 100;
|
|
45
47
|
/** Maximum base64url-encoded encrypted subject length */
|
|
46
48
|
readonly MAX_ENCRYPTED_SUBJECT: 65536;
|
|
@@ -60,12 +62,18 @@ export declare const SERVER_LIMITS: {
|
|
|
60
62
|
readonly MAX_RELATED_PACKAGES: 50;
|
|
61
63
|
/** Maximum party ID length */
|
|
62
64
|
readonly MAX_PARTY_ID_LENGTH: 100;
|
|
65
|
+
/** Maximum characters per related package reference */
|
|
66
|
+
readonly MAX_RELATED_PACKAGE_LENGTH: 100;
|
|
67
|
+
/** Maximum MIME type length */
|
|
68
|
+
readonly MAX_MIMETYPE_LENGTH: 255;
|
|
69
|
+
/** Maximum transform reference length */
|
|
70
|
+
readonly MAX_TRANSFORM_LENGTH: 2048;
|
|
63
71
|
/** Maximum base64url-encoded encrypted filename length */
|
|
64
72
|
readonly MAX_ENCRYPTED_FILENAME: 2048;
|
|
65
|
-
/** Maximum base64url-encoded signature payload length */
|
|
66
|
-
readonly MAX_SIGNATURE_PAYLOAD:
|
|
67
|
-
/** Maximum
|
|
68
|
-
readonly
|
|
73
|
+
/** Maximum base64url-encoded signature payload length (128 KiB; a 500-file capsa signs about 66,200 chars) */
|
|
74
|
+
readonly MAX_SIGNATURE_PAYLOAD: 131072;
|
|
75
|
+
/** Maximum UTF-8 bytes of one JSON part in the upload request (the serialized capsa) */
|
|
76
|
+
readonly MAX_JSON_FIELD: 1048576;
|
|
69
77
|
};
|
|
70
78
|
export declare class CapsaBuilder {
|
|
71
79
|
#private;
|
|
@@ -79,19 +87,26 @@ export declare class CapsaBuilder {
|
|
|
79
87
|
set expiresAt(value: Date | string | undefined);
|
|
80
88
|
constructor(creatorId: string, creatorPrivateKey: string, limits: SystemLimits);
|
|
81
89
|
/**
|
|
82
|
-
*
|
|
90
|
+
* Set the capsa's recipient (its principal).
|
|
91
|
+
*
|
|
92
|
+
* A capsa goes to exactly one recipient. The recipient's registered delegates
|
|
93
|
+
* are added automatically at send time, each acting for this recipient, so
|
|
94
|
+
* several parties can still access the capsa through their own keys. To send
|
|
95
|
+
* to several recipients, use one builder per recipient and send them together
|
|
96
|
+
* in one batch with sendCapsas().
|
|
97
|
+
*
|
|
98
|
+
* The recipient may be the creator itself (a self-send); the creator's own
|
|
99
|
+
* delegates are then added, acting for the creator.
|
|
83
100
|
* @param partyId - Party ID
|
|
101
|
+
* @throws Error if a recipient has already been added
|
|
84
102
|
*/
|
|
85
103
|
addRecipient(partyId: string): this;
|
|
86
|
-
/**
|
|
87
|
-
* Add multiple recipients to the capsa
|
|
88
|
-
* @param partyIds - Party IDs
|
|
89
|
-
*/
|
|
90
|
-
addRecipients(...partyIds: string[]): this;
|
|
91
104
|
/**
|
|
92
105
|
* Add a file to the capsa
|
|
93
106
|
* @param input - File input (path or buffer with filename)
|
|
94
|
-
* @throws
|
|
107
|
+
* @throws CapsaraError (VALIDATION_ERROR) if the file name contains "/", "\" or
|
|
108
|
+
* control characters, is empty or only spaces, or is "." or ".."; if the file
|
|
109
|
+
* exceeds the size limit; or if the capsa already has the maximum number of files
|
|
95
110
|
*/
|
|
96
111
|
addFile(input: FileInput): this;
|
|
97
112
|
/**
|
|
@@ -160,7 +175,8 @@ export declare class CapsaBuilder {
|
|
|
160
175
|
getFileCount(): number;
|
|
161
176
|
/**
|
|
162
177
|
* Build the capsa with encryption and signature.
|
|
163
|
-
* @param partyKeys - Public keys for
|
|
178
|
+
* @param partyKeys - Public keys for the creator, the recipient and its delegates
|
|
179
|
+
* (other parties in the list are ignored)
|
|
164
180
|
*/
|
|
165
181
|
build(partyKeys: PartyKey[]): Promise<BuiltCapsa>;
|
|
166
182
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capsa-builder.d.ts","sourceRoot":"","sources":["../../src/builder/capsa-builder.ts"],"names":[],"mappings":"AAAA,0DAA0D;
|
|
1
|
+
{"version":3,"file":"capsa-builder.d.ts","sourceRoot":"","sources":["../../src/builder/capsa-builder.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAiC1D,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,gGAAgG;AAChG,eAAO,MAAM,6BAA6B,kFACuC,CAAC;AAElF,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;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACxF,aAAa,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,QAAQ,CAAC,EAAE,aAA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