@capsara/sdk 1.0.1 → 1.0.2
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/LICENSE +74 -74
- package/README.md +230 -230
- package/package.json +61 -61
package/LICENSE
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
Capsara SDK License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024-2026 Tessarai, LLC and Laird Rixford (the "License Holders"). All rights reserved.
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS
|
|
6
|
-
|
|
7
|
-
1. GRANT OF LICENSE
|
|
8
|
-
|
|
9
|
-
Subject to the terms and conditions of this License, Tessarai, LLC
|
|
10
|
-
("Licensor") grants you a limited, non-exclusive, non-transferable,
|
|
11
|
-
non-sublicensable, revocable license to use the Capsara SDK ("Software")
|
|
12
|
-
solely in connection with the Capsara platform and services provided by
|
|
13
|
-
Licensor.
|
|
14
|
-
|
|
15
|
-
2. RESTRICTIONS
|
|
16
|
-
|
|
17
|
-
You may NOT:
|
|
18
|
-
|
|
19
|
-
a. Redistribute, sublicense, sell, lease, or otherwise transfer the
|
|
20
|
-
Software or any portion thereof to any third party;
|
|
21
|
-
b. Modify, adapt, translate, reverse engineer, decompile, disassemble,
|
|
22
|
-
or create derivative works based on the Software;
|
|
23
|
-
c. Use the Software to build, support, or operate any product or service
|
|
24
|
-
that competes with the Capsara platform;
|
|
25
|
-
d. Use the Software independently of or outside the Capsara platform;
|
|
26
|
-
e. Remove, alter, or obscure any copyright, trademark, or other
|
|
27
|
-
proprietary notices in the Software.
|
|
28
|
-
|
|
29
|
-
3. PLATFORM BINDING
|
|
30
|
-
|
|
31
|
-
This license is valid only for use with the Capsara platform. Any use of
|
|
32
|
-
the Software outside the Capsara platform, including but not limited to
|
|
33
|
-
integration with competing or unrelated services, is strictly prohibited.
|
|
34
|
-
|
|
35
|
-
4. INTELLECTUAL PROPERTY
|
|
36
|
-
|
|
37
|
-
The Software and all copies thereof are proprietary to and the property
|
|
38
|
-
of the License Holders. All right, title, and interest in and to the
|
|
39
|
-
Software, including all intellectual property rights therein, remain
|
|
40
|
-
exclusively with the License Holders. No rights are
|
|
41
|
-
granted to you other than as expressly set forth in this License.
|
|
42
|
-
|
|
43
|
-
5. TERMINATION
|
|
44
|
-
|
|
45
|
-
This License is effective until terminated. Licensor may terminate this
|
|
46
|
-
License at any time, with or without cause, upon written notice. This
|
|
47
|
-
License will terminate automatically if you fail to comply with any term
|
|
48
|
-
or condition of this License. Upon termination, you must cease all use
|
|
49
|
-
of the Software and destroy all copies in your possession or control.
|
|
50
|
-
|
|
51
|
-
6. GOVERNING TERMS
|
|
52
|
-
|
|
53
|
-
Use of the Software is governed by the Capsara Terms of Service, which
|
|
54
|
-
are incorporated herein by reference. In the event of any conflict
|
|
55
|
-
between this License and the Terms of Service, the Terms of Service
|
|
56
|
-
shall prevail.
|
|
57
|
-
|
|
58
|
-
7. DISCLAIMER OF WARRANTIES
|
|
59
|
-
|
|
60
|
-
THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
61
|
-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
62
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
|
|
63
|
-
IN NO EVENT SHALL THE LICENSE HOLDERS OR ANY CONTRIBUTORS BE
|
|
64
|
-
LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
65
|
-
OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
|
|
66
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
67
|
-
|
|
68
|
-
8. LIMITATION OF LIABILITY
|
|
69
|
-
|
|
70
|
-
IN NO EVENT SHALL LICENSOR BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
|
|
71
|
-
SPECIAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES, OR ANY LOSS OF PROFITS OR
|
|
72
|
-
REVENUE, WHETHER INCURRED DIRECTLY OR INDIRECTLY, OR ANY LOSS OF DATA,
|
|
73
|
-
USE, GOODWILL, OR OTHER INTANGIBLE LOSSES, RESULTING FROM YOUR USE OF
|
|
74
|
-
OR INABILITY TO USE THE SOFTWARE.
|
|
1
|
+
Capsara SDK License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Tessarai, LLC and Laird Rixford (the "License Holders"). All rights reserved.
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS
|
|
6
|
+
|
|
7
|
+
1. GRANT OF LICENSE
|
|
8
|
+
|
|
9
|
+
Subject to the terms and conditions of this License, Tessarai, LLC
|
|
10
|
+
("Licensor") grants you a limited, non-exclusive, non-transferable,
|
|
11
|
+
non-sublicensable, revocable license to use the Capsara SDK ("Software")
|
|
12
|
+
solely in connection with the Capsara platform and services provided by
|
|
13
|
+
Licensor.
|
|
14
|
+
|
|
15
|
+
2. RESTRICTIONS
|
|
16
|
+
|
|
17
|
+
You may NOT:
|
|
18
|
+
|
|
19
|
+
a. Redistribute, sublicense, sell, lease, or otherwise transfer the
|
|
20
|
+
Software or any portion thereof to any third party;
|
|
21
|
+
b. Modify, adapt, translate, reverse engineer, decompile, disassemble,
|
|
22
|
+
or create derivative works based on the Software;
|
|
23
|
+
c. Use the Software to build, support, or operate any product or service
|
|
24
|
+
that competes with the Capsara platform;
|
|
25
|
+
d. Use the Software independently of or outside the Capsara platform;
|
|
26
|
+
e. Remove, alter, or obscure any copyright, trademark, or other
|
|
27
|
+
proprietary notices in the Software.
|
|
28
|
+
|
|
29
|
+
3. PLATFORM BINDING
|
|
30
|
+
|
|
31
|
+
This license is valid only for use with the Capsara platform. Any use of
|
|
32
|
+
the Software outside the Capsara platform, including but not limited to
|
|
33
|
+
integration with competing or unrelated services, is strictly prohibited.
|
|
34
|
+
|
|
35
|
+
4. INTELLECTUAL PROPERTY
|
|
36
|
+
|
|
37
|
+
The Software and all copies thereof are proprietary to and the property
|
|
38
|
+
of the License Holders. All right, title, and interest in and to the
|
|
39
|
+
Software, including all intellectual property rights therein, remain
|
|
40
|
+
exclusively with the License Holders. No rights are
|
|
41
|
+
granted to you other than as expressly set forth in this License.
|
|
42
|
+
|
|
43
|
+
5. TERMINATION
|
|
44
|
+
|
|
45
|
+
This License is effective until terminated. Licensor may terminate this
|
|
46
|
+
License at any time, with or without cause, upon written notice. This
|
|
47
|
+
License will terminate automatically if you fail to comply with any term
|
|
48
|
+
or condition of this License. Upon termination, you must cease all use
|
|
49
|
+
of the Software and destroy all copies in your possession or control.
|
|
50
|
+
|
|
51
|
+
6. GOVERNING TERMS
|
|
52
|
+
|
|
53
|
+
Use of the Software is governed by the Capsara Terms of Service, which
|
|
54
|
+
are incorporated herein by reference. In the event of any conflict
|
|
55
|
+
between this License and the Terms of Service, the Terms of Service
|
|
56
|
+
shall prevail.
|
|
57
|
+
|
|
58
|
+
7. DISCLAIMER OF WARRANTIES
|
|
59
|
+
|
|
60
|
+
THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
61
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
62
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
|
|
63
|
+
IN NO EVENT SHALL THE LICENSE HOLDERS OR ANY CONTRIBUTORS BE
|
|
64
|
+
LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
65
|
+
OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
|
|
66
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
67
|
+
|
|
68
|
+
8. LIMITATION OF LIABILITY
|
|
69
|
+
|
|
70
|
+
IN NO EVENT SHALL LICENSOR BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
|
|
71
|
+
SPECIAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES, OR ANY LOSS OF PROFITS OR
|
|
72
|
+
REVENUE, WHETHER INCURRED DIRECTLY OR INDIRECTLY, OR ANY LOSS OF DATA,
|
|
73
|
+
USE, GOODWILL, OR OTHER INTANGIBLE LOSSES, RESULTING FROM YOUR USE OF
|
|
74
|
+
OR INABILITY TO USE THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,230 +1,230 @@
|
|
|
1
|
-
# Capsara SDK — TypeScript
|
|
2
|
-
|
|
3
|
-
Zero-knowledge encrypted messaging and file sharing for multi-party collaboration.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **AES-256-GCM** encryption with unique keys per capsa
|
|
8
|
-
- **RSA-4096-OAEP** key encryption for multi-party access
|
|
9
|
-
- **Compression** — gzip before encryption
|
|
10
|
-
- **Digital signatures** — RSA-SHA256 sender authenticity
|
|
11
|
-
- **Encrypted subject, body, and structured data**
|
|
12
|
-
- **Batch sending** with automatic chunking
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npm install @capsara/sdk
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Initialize the Client
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import { CapsaraClient } from '@capsara/sdk';
|
|
24
|
-
|
|
25
|
-
const client = new CapsaraClient('https://api.capsara.com');
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Authentication
|
|
29
|
-
|
|
30
|
-
Authentication requires two steps: login with your credentials, then set your private key for cryptographic operations.
|
|
31
|
-
|
|
32
|
-
### Login
|
|
33
|
-
|
|
34
|
-
```typescript
|
|
35
|
-
await client.login({
|
|
36
|
-
email: 'you@example.com',
|
|
37
|
-
password: '...'
|
|
38
|
-
});
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Set Private Key
|
|
42
|
-
|
|
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.
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
// Load your private key from secure storage (key vault, HSM, etc.)
|
|
47
|
-
const privateKey = loadPrivateKeyFromSecureStorage();
|
|
48
|
-
|
|
49
|
-
client.setPrivateKey(privateKey);
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Sending Capsas
|
|
53
|
-
|
|
54
|
-
Use the `CapsaBuilder` to create capsas with recipients and files. Always use `sendCapsas()` even for a single capsa — it handles encryption and batching efficiently.
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { CapsaraClient, CapsaraError, FileInput } from '@capsara/sdk';
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
// Create a builder for each capsa you want to send
|
|
61
|
-
const builder = await client.createCapsaBuilder();
|
|
62
|
-
|
|
63
|
-
// Add recipients — can add multiple
|
|
64
|
-
builder.addRecipient('party_recipient1');
|
|
65
|
-
builder.addRecipient('party_recipient2');
|
|
66
|
-
|
|
67
|
-
// Add files from path or buffer
|
|
68
|
-
builder.addFile(FileInput.fromPath('./documents/policy.pdf'));
|
|
69
|
-
builder.addFile(FileInput.fromBuffer(
|
|
70
|
-
Buffer.from('Policy data here'),
|
|
71
|
-
'policy-data.txt'
|
|
72
|
-
));
|
|
73
|
-
|
|
74
|
-
// Add optional metadata
|
|
75
|
-
builder.withSubject('Policy Documents — Q1 2025');
|
|
76
|
-
builder.withBody('Please review the attached policy documents.');
|
|
77
|
-
builder.withStructured({
|
|
78
|
-
policyNumber: 'POL-12345',
|
|
79
|
-
effectiveDate: '2025-01-01'
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Set expiration
|
|
83
|
-
builder.withExpiration(new Date(Date.now() + 90 * 24 * 60 * 60 * 1000));
|
|
84
|
-
|
|
85
|
-
// Send
|
|
86
|
-
const result = await client.sendCapsas([builder]);
|
|
87
|
-
console.log(`Sent ${result.successful} capsa(s)`);
|
|
88
|
-
|
|
89
|
-
if (result.failed > 0) {
|
|
90
|
-
console.error(`${result.failed} capsas failed to send`);
|
|
91
|
-
}
|
|
92
|
-
} catch (error) {
|
|
93
|
-
if (error instanceof CapsaraError) {
|
|
94
|
-
console.error('Failed to send:', error.message);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
A **capsa** maps one-to-one with a *matter* — a unique combination of sender, recipient, client, and action. Send multiple capsas in one call:
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
const matter1 = await client.createCapsaBuilder();
|
|
103
|
-
matter1
|
|
104
|
-
.addRecipient('party_org_b')
|
|
105
|
-
.withSubject('Client 1 — New Home Policy')
|
|
106
|
-
.addFile(FileInput.fromPath('./policy.pdf'));
|
|
107
|
-
|
|
108
|
-
const matter2 = await client.createCapsaBuilder();
|
|
109
|
-
matter2
|
|
110
|
-
.addRecipient('party_org_b')
|
|
111
|
-
.withSubject('Client 1 — Auto Endorsement')
|
|
112
|
-
.withBody('Endorsement effective 3/1. No documents required.');
|
|
113
|
-
|
|
114
|
-
await client.sendCapsas([matter1, matter2]);
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
The SDK automatically splits large batches to stay within server limits.
|
|
118
|
-
|
|
119
|
-
## Receiving Capsas
|
|
120
|
-
|
|
121
|
-
### List Capsas
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
const response = await client.listCapsas({
|
|
125
|
-
status: 'active',
|
|
126
|
-
limit: 50
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
console.log(`Found ${response.capsas.length} capsas`);
|
|
130
|
-
|
|
131
|
-
for (const capsa of response.capsas) {
|
|
132
|
-
console.log(`- ${capsa.id}: ${capsa.fileCount} files`);
|
|
133
|
-
console.log(` Created: ${capsa.createdAt}`);
|
|
134
|
-
console.log(` From: ${capsa.creatorId}`);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Pagination
|
|
138
|
-
if (response.pagination.hasMore) {
|
|
139
|
-
const nextPage = await client.listCapsas({
|
|
140
|
-
after: response.pagination.nextCursor
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### Get Capsa and Download Files
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
import fs from 'node:fs';
|
|
149
|
-
|
|
150
|
-
const capsa = await client.getCapsa('cap_abc123');
|
|
151
|
-
|
|
152
|
-
console.log('Subject:', capsa.subject);
|
|
153
|
-
console.log('Body:', capsa.body);
|
|
154
|
-
console.log('Structured data:', capsa.structured);
|
|
155
|
-
|
|
156
|
-
// Download each file
|
|
157
|
-
for (const file of capsa.files) {
|
|
158
|
-
const { data, filename } = await client.downloadFile(capsa.packageId, file.id);
|
|
159
|
-
fs.writeFileSync(`./downloads/${filename}`, data);
|
|
160
|
-
}
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
## Delegation
|
|
164
|
-
|
|
165
|
-
Capsara supports delegation for scenarios where a system acts on behalf of a party — for example, an agency management system (AMS) processing 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
|
-
|
|
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.
|
|
168
|
-
|
|
169
|
-
```typescript
|
|
170
|
-
// Authenticate as the delegate (e.g., an AMS)
|
|
171
|
-
const client = new CapsaraClient('https://api.capsara.com');
|
|
172
|
-
await client.login({ email: 'ams@example.com', password: '...' });
|
|
173
|
-
client.setPrivateKey(loadPrivateKeyFromSecureStorage());
|
|
174
|
-
|
|
175
|
-
// List capsas — includes capsas for all parties you represent
|
|
176
|
-
const response = await client.listCapsas();
|
|
177
|
-
|
|
178
|
-
for (const summary of response.capsas) {
|
|
179
|
-
const capsa = await client.getCapsa(summary.id);
|
|
180
|
-
|
|
181
|
-
// 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);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Download and process files
|
|
188
|
-
for (const file of capsa.files) {
|
|
189
|
-
const { data, filename } = await client.downloadFile(summary.id, file.id);
|
|
190
|
-
processFile(capsa.actingFor, filename, data);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
## Encryption
|
|
196
|
-
|
|
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.
|
|
198
|
-
|
|
199
|
-
## Private Key Security
|
|
200
|
-
|
|
201
|
-
Your private key is the sole point of access to every capsa encrypted for you. Capsara uses zero-knowledge encryption — your private key never leaves your environment, is never transmitted to Capsara's servers, and is never stored by Capsara. There is no recovery mechanism, no master backdoor, and no support override. If your private key is lost, every capsa encrypted for your party becomes permanently inaccessible. No one — not Capsara, not the sender, not an administrator — can recover your data without your private key.
|
|
202
|
-
|
|
203
|
-
You are fully responsible for your private key's lifecycle: generation, secure storage, and backup. Store it in a cloud key vault (Azure Key Vault, AWS Secrets Manager, HashiCorp Vault), a hardware security module, or at minimum an encrypted secrets manager — never in source code, configuration files, or logs. Back it up to a secondary secure location so that a single infrastructure failure does not result in permanent data loss.
|
|
204
|
-
|
|
205
|
-
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 — 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
|
-
|
|
207
|
-
## API Reference
|
|
208
|
-
|
|
209
|
-
| Method | Description |
|
|
210
|
-
|--------|-------------|
|
|
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 |
|
|
214
|
-
| `setPrivateKey(privateKey)` | Set the private key for signing and decryption |
|
|
215
|
-
| `createCapsaBuilder()` | Create a `CapsaBuilder` pre-loaded with server limits |
|
|
216
|
-
| `sendCapsas(builders)` | Encrypt and send one or more capsas |
|
|
217
|
-
| `getCapsa(capsaId)` | Fetch and decrypt a capsa |
|
|
218
|
-
| `listCapsas(filters?)` | List capsas with optional filters |
|
|
219
|
-
| `deleteCapsa(capsaId)` | Soft-delete a capsa |
|
|
220
|
-
| `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 |
|
|
225
|
-
| `getLimits()` | Get server-enforced limits |
|
|
226
|
-
| `destroy()` | Release resources and clear keys |
|
|
227
|
-
|
|
228
|
-
## License
|
|
229
|
-
|
|
230
|
-
Capsara SDK License — see [LICENSE](./LICENSE) for details.
|
|
1
|
+
# Capsara SDK — TypeScript
|
|
2
|
+
|
|
3
|
+
Zero-knowledge encrypted messaging and file sharing for multi-party collaboration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **AES-256-GCM** encryption with unique keys per capsa
|
|
8
|
+
- **RSA-4096-OAEP** key encryption for multi-party access
|
|
9
|
+
- **Compression** — gzip before encryption
|
|
10
|
+
- **Digital signatures** — RSA-SHA256 sender authenticity
|
|
11
|
+
- **Encrypted subject, body, and structured data**
|
|
12
|
+
- **Batch sending** with automatic chunking
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @capsara/sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Initialize the Client
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { CapsaraClient } from '@capsara/sdk';
|
|
24
|
+
|
|
25
|
+
const client = new CapsaraClient('https://api.capsara.com');
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Authentication
|
|
29
|
+
|
|
30
|
+
Authentication requires two steps: login with your credentials, then set your private key for cryptographic operations.
|
|
31
|
+
|
|
32
|
+
### Login
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
await client.login({
|
|
36
|
+
email: 'you@example.com',
|
|
37
|
+
password: '...'
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Set Private Key
|
|
42
|
+
|
|
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.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// Load your private key from secure storage (key vault, HSM, etc.)
|
|
47
|
+
const privateKey = loadPrivateKeyFromSecureStorage();
|
|
48
|
+
|
|
49
|
+
client.setPrivateKey(privateKey);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Sending Capsas
|
|
53
|
+
|
|
54
|
+
Use the `CapsaBuilder` to create capsas with recipients and files. Always use `sendCapsas()` even for a single capsa — it handles encryption and batching efficiently.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { CapsaraClient, CapsaraError, FileInput } from '@capsara/sdk';
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
// Create a builder for each capsa you want to send
|
|
61
|
+
const builder = await client.createCapsaBuilder();
|
|
62
|
+
|
|
63
|
+
// Add recipients — can add multiple
|
|
64
|
+
builder.addRecipient('party_recipient1');
|
|
65
|
+
builder.addRecipient('party_recipient2');
|
|
66
|
+
|
|
67
|
+
// Add files from path or buffer
|
|
68
|
+
builder.addFile(FileInput.fromPath('./documents/policy.pdf'));
|
|
69
|
+
builder.addFile(FileInput.fromBuffer(
|
|
70
|
+
Buffer.from('Policy data here'),
|
|
71
|
+
'policy-data.txt'
|
|
72
|
+
));
|
|
73
|
+
|
|
74
|
+
// Add optional metadata
|
|
75
|
+
builder.withSubject('Policy Documents — Q1 2025');
|
|
76
|
+
builder.withBody('Please review the attached policy documents.');
|
|
77
|
+
builder.withStructured({
|
|
78
|
+
policyNumber: 'POL-12345',
|
|
79
|
+
effectiveDate: '2025-01-01'
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Set expiration
|
|
83
|
+
builder.withExpiration(new Date(Date.now() + 90 * 24 * 60 * 60 * 1000));
|
|
84
|
+
|
|
85
|
+
// Send
|
|
86
|
+
const result = await client.sendCapsas([builder]);
|
|
87
|
+
console.log(`Sent ${result.successful} capsa(s)`);
|
|
88
|
+
|
|
89
|
+
if (result.failed > 0) {
|
|
90
|
+
console.error(`${result.failed} capsas failed to send`);
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (error instanceof CapsaraError) {
|
|
94
|
+
console.error('Failed to send:', error.message);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
A **capsa** maps one-to-one with a *matter* — a unique combination of sender, recipient, client, and action. Send multiple capsas in one call:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
const matter1 = await client.createCapsaBuilder();
|
|
103
|
+
matter1
|
|
104
|
+
.addRecipient('party_org_b')
|
|
105
|
+
.withSubject('Client 1 — New Home Policy')
|
|
106
|
+
.addFile(FileInput.fromPath('./policy.pdf'));
|
|
107
|
+
|
|
108
|
+
const matter2 = await client.createCapsaBuilder();
|
|
109
|
+
matter2
|
|
110
|
+
.addRecipient('party_org_b')
|
|
111
|
+
.withSubject('Client 1 — Auto Endorsement')
|
|
112
|
+
.withBody('Endorsement effective 3/1. No documents required.');
|
|
113
|
+
|
|
114
|
+
await client.sendCapsas([matter1, matter2]);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The SDK automatically splits large batches to stay within server limits.
|
|
118
|
+
|
|
119
|
+
## Receiving Capsas
|
|
120
|
+
|
|
121
|
+
### List Capsas
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const response = await client.listCapsas({
|
|
125
|
+
status: 'active',
|
|
126
|
+
limit: 50
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
console.log(`Found ${response.capsas.length} capsas`);
|
|
130
|
+
|
|
131
|
+
for (const capsa of response.capsas) {
|
|
132
|
+
console.log(`- ${capsa.id}: ${capsa.fileCount} files`);
|
|
133
|
+
console.log(` Created: ${capsa.createdAt}`);
|
|
134
|
+
console.log(` From: ${capsa.creatorId}`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Pagination
|
|
138
|
+
if (response.pagination.hasMore) {
|
|
139
|
+
const nextPage = await client.listCapsas({
|
|
140
|
+
after: response.pagination.nextCursor
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Get Capsa and Download Files
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import fs from 'node:fs';
|
|
149
|
+
|
|
150
|
+
const capsa = await client.getCapsa('cap_abc123');
|
|
151
|
+
|
|
152
|
+
console.log('Subject:', capsa.subject);
|
|
153
|
+
console.log('Body:', capsa.body);
|
|
154
|
+
console.log('Structured data:', capsa.structured);
|
|
155
|
+
|
|
156
|
+
// Download each file
|
|
157
|
+
for (const file of capsa.files) {
|
|
158
|
+
const { data, filename } = await client.downloadFile(capsa.packageId, file.id);
|
|
159
|
+
fs.writeFileSync(`./downloads/${filename}`, data);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Delegation
|
|
164
|
+
|
|
165
|
+
Capsara supports delegation for scenarios where a system acts on behalf of a party — for example, an agency management system (AMS) processing 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
|
+
|
|
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.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
// Authenticate as the delegate (e.g., an AMS)
|
|
171
|
+
const client = new CapsaraClient('https://api.capsara.com');
|
|
172
|
+
await client.login({ email: 'ams@example.com', password: '...' });
|
|
173
|
+
client.setPrivateKey(loadPrivateKeyFromSecureStorage());
|
|
174
|
+
|
|
175
|
+
// List capsas — includes capsas for all parties you represent
|
|
176
|
+
const response = await client.listCapsas();
|
|
177
|
+
|
|
178
|
+
for (const summary of response.capsas) {
|
|
179
|
+
const capsa = await client.getCapsa(summary.id);
|
|
180
|
+
|
|
181
|
+
// 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);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Download and process files
|
|
188
|
+
for (const file of capsa.files) {
|
|
189
|
+
const { data, filename } = await client.downloadFile(summary.id, file.id);
|
|
190
|
+
processFile(capsa.actingFor, filename, data);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Encryption
|
|
196
|
+
|
|
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.
|
|
198
|
+
|
|
199
|
+
## Private Key Security
|
|
200
|
+
|
|
201
|
+
Your private key is the sole point of access to every capsa encrypted for you. Capsara uses zero-knowledge encryption — your private key never leaves your environment, is never transmitted to Capsara's servers, and is never stored by Capsara. There is no recovery mechanism, no master backdoor, and no support override. If your private key is lost, every capsa encrypted for your party becomes permanently inaccessible. No one — not Capsara, not the sender, not an administrator — can recover your data without your private key.
|
|
202
|
+
|
|
203
|
+
You are fully responsible for your private key's lifecycle: generation, secure storage, and backup. Store it in a cloud key vault (Azure Key Vault, AWS Secrets Manager, HashiCorp Vault), a hardware security module, or at minimum an encrypted secrets manager — never in source code, configuration files, or logs. Back it up to a secondary secure location so that a single infrastructure failure does not result in permanent data loss.
|
|
204
|
+
|
|
205
|
+
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 — 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
|
+
|
|
207
|
+
## API Reference
|
|
208
|
+
|
|
209
|
+
| Method | Description |
|
|
210
|
+
|--------|-------------|
|
|
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 |
|
|
214
|
+
| `setPrivateKey(privateKey)` | Set the private key for signing and decryption |
|
|
215
|
+
| `createCapsaBuilder()` | Create a `CapsaBuilder` pre-loaded with server limits |
|
|
216
|
+
| `sendCapsas(builders)` | Encrypt and send one or more capsas |
|
|
217
|
+
| `getCapsa(capsaId)` | Fetch and decrypt a capsa |
|
|
218
|
+
| `listCapsas(filters?)` | List capsas with optional filters |
|
|
219
|
+
| `deleteCapsa(capsaId)` | Soft-delete a capsa |
|
|
220
|
+
| `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 |
|
|
225
|
+
| `getLimits()` | Get server-enforced limits |
|
|
226
|
+
| `destroy()` | Release resources and clear keys |
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
Capsara SDK License — see [LICENSE](./LICENSE) for details.
|
package/package.json
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@capsara/sdk",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Capsara SDK for TypeScript",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"clean": "rm -rf dist",
|
|
10
|
-
"build": "npm run clean && tsc",
|
|
11
|
-
"dev": "tsc --watch",
|
|
12
|
-
"test": "vitest",
|
|
13
|
-
"test:coverage": "vitest --coverage",
|
|
14
|
-
"lint": "eslint src/**/*.ts",
|
|
15
|
-
"prepublishOnly": "npm run build"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"encryption",
|
|
19
|
-
"zero-knowledge",
|
|
20
|
-
"secure-sharing",
|
|
21
|
-
"pgp",
|
|
22
|
-
"rsa",
|
|
23
|
-
"aes",
|
|
24
|
-
"file-sharing",
|
|
25
|
-
"multi-party",
|
|
26
|
-
"insurance",
|
|
27
|
-
"compliance",
|
|
28
|
-
"hipaa"
|
|
29
|
-
],
|
|
30
|
-
"author": "Tessarai, LLC",
|
|
31
|
-
"license": "
|
|
32
|
-
"repository": {
|
|
33
|
-
"type": "git",
|
|
34
|
-
"url": "https://github.com/tessarai-corpus/capsara-typescript.git"
|
|
35
|
-
},
|
|
36
|
-
"bugs": {
|
|
37
|
-
"url": "https://github.com/tessarai-corpus/capsara-typescript/issues"
|
|
38
|
-
},
|
|
39
|
-
"homepage": "https://github.com/tessarai-corpus/capsara-typescript#readme",
|
|
40
|
-
"engines": {
|
|
41
|
-
"node": ">=20.0.0"
|
|
42
|
-
},
|
|
43
|
-
"dependencies": {
|
|
44
|
-
"axios": "^1.7.9"
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@eslint/js": "^9.39.1",
|
|
48
|
-
"@types/node": "^20.17.10",
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^8.18.2",
|
|
50
|
-
"@typescript-eslint/parser": "^8.18.2",
|
|
51
|
-
"@vitest/coverage-v8": "^2.1.8",
|
|
52
|
-
"eslint": "^9.18.0",
|
|
53
|
-
"typescript": "^5.9.0",
|
|
54
|
-
"vitest": "^2.1.8"
|
|
55
|
-
},
|
|
56
|
-
"files": [
|
|
57
|
-
"dist",
|
|
58
|
-
"README.md",
|
|
59
|
-
"LICENSE"
|
|
60
|
-
]
|
|
61
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@capsara/sdk",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Capsara SDK for TypeScript",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"clean": "rm -rf dist",
|
|
10
|
+
"build": "npm run clean && tsc",
|
|
11
|
+
"dev": "tsc --watch",
|
|
12
|
+
"test": "vitest",
|
|
13
|
+
"test:coverage": "vitest --coverage",
|
|
14
|
+
"lint": "eslint src/**/*.ts",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"encryption",
|
|
19
|
+
"zero-knowledge",
|
|
20
|
+
"secure-sharing",
|
|
21
|
+
"pgp",
|
|
22
|
+
"rsa",
|
|
23
|
+
"aes",
|
|
24
|
+
"file-sharing",
|
|
25
|
+
"multi-party",
|
|
26
|
+
"insurance",
|
|
27
|
+
"compliance",
|
|
28
|
+
"hipaa"
|
|
29
|
+
],
|
|
30
|
+
"author": "Tessarai, LLC",
|
|
31
|
+
"license": "Capsara SDK License",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/tessarai-corpus/capsara-typescript.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/tessarai-corpus/capsara-typescript/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/tessarai-corpus/capsara-typescript#readme",
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=20.0.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"axios": "^1.7.9"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@eslint/js": "^9.39.1",
|
|
48
|
+
"@types/node": "^20.17.10",
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^8.18.2",
|
|
50
|
+
"@typescript-eslint/parser": "^8.18.2",
|
|
51
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
52
|
+
"eslint": "^9.18.0",
|
|
53
|
+
"typescript": "^5.9.0",
|
|
54
|
+
"vitest": "^2.1.8"
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"README.md",
|
|
59
|
+
"LICENSE"
|
|
60
|
+
]
|
|
61
|
+
}
|