@deadvault/sdk 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 DEADBOX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,197 @@
1
+ # @deadvault/sdk
2
+
3
+ Decentralized credential store SDK for AI agents, servers & scripts. Read, write, and manage encrypted secrets stored on-chain via the [DeadVault](https://vault.dead.box) smart contract.
4
+
5
+ Part of the [DEADBOX](https://dead.box) ecosystem.
6
+
7
+ ## Features
8
+
9
+ - **Read & write** encrypted vaults on-chain (Base, Ethereum, Arbitrum, Optimism)
10
+ - **AES-256-GCM** encryption with PBKDF2 key derivation (600k iterations)
11
+ - **TOTP generation** — RFC 6238 codes from vault entries
12
+ - **Zero dependencies** beyond `viem` as a peer dependency
13
+ - **Isomorphic** — works in Node.js 18+, Deno, Bun, Cloudflare Workers
14
+ - **ESM + CJS** dual output with full TypeScript types
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install @deadvault/sdk viem
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ```ts
25
+ import { DeadVault } from "@deadvault/sdk";
26
+
27
+ const vault = new DeadVault({ chain: "base" });
28
+
29
+ // Read & decrypt
30
+ const data = await vault.read({
31
+ address: "0xYourAddress",
32
+ password: "master-password",
33
+ });
34
+
35
+ // Find a specific entry
36
+ const key = vault.findEntry(data, { label: "OpenAI" });
37
+ console.log(key?.secret); // sk-...
38
+ ```
39
+
40
+ ## Constructor
41
+
42
+ ```ts
43
+ const vault = new DeadVault(config);
44
+ ```
45
+
46
+ | Option | Type | Default | Description |
47
+ |-----------|----------|----------|------------------------------------------------------|
48
+ | `chain` | `string` | `"base"` | Chain name: `base`, `ethereum`, `arbitrum`, `optimism` |
49
+ | `chainId` | `number` | `8453` | Chain ID (overrides `chain`) |
50
+ | `rpcUrl` | `string` | — | Custom RPC URL |
51
+
52
+ ## Reading Secrets
53
+
54
+ ```ts
55
+ const data = await vault.read({
56
+ address: "0x...",
57
+ password: "secret",
58
+ walletSignature: "0x...", // required for v2 vaults
59
+ });
60
+ ```
61
+
62
+ Returns `VaultData` with an `entries` array of `VaultEntry` objects.
63
+
64
+ ## Finding Entries
65
+
66
+ ```ts
67
+ // By label (case-insensitive substring)
68
+ vault.findEntry(data, { label: "OpenAI" });
69
+
70
+ // By category
71
+ vault.findEntry(data, { category: "API Keys" });
72
+
73
+ // By URL
74
+ vault.findEntry(data, { url: "github.com" });
75
+
76
+ // Custom predicate
77
+ vault.findEntry(data, (e) => e.secret.startsWith("sk-"));
78
+
79
+ // Find all matching
80
+ vault.findEntries(data, { type: "totp" });
81
+ ```
82
+
83
+ ## Writing Secrets
84
+
85
+ ```ts
86
+ // Sign the KDF message (needed for v2 encryption)
87
+ const sig = await vault.signKdfMessage("0xPrivateKey");
88
+
89
+ // Read existing vault
90
+ const data = await vault.read({
91
+ address: "0xYourAddress",
92
+ password: "secret",
93
+ walletSignature: sig,
94
+ });
95
+
96
+ // Add an entry
97
+ data.entries.push({
98
+ id: crypto.randomUUID(),
99
+ label: "New API Key",
100
+ secret: "sk-abc123...",
101
+ category: "API Keys",
102
+ createdAt: Date.now(),
103
+ updatedAt: Date.now(),
104
+ });
105
+
106
+ // Write back on-chain
107
+ const result = await vault.write({
108
+ data,
109
+ password: "secret",
110
+ privateKey: "0xPrivateKey",
111
+ walletSignature: sig,
112
+ });
113
+
114
+ console.log("TX:", result.hash);
115
+ console.log("Block:", result.blockNumber);
116
+ ```
117
+
118
+ ## TOTP Generation
119
+
120
+ ```ts
121
+ const totpEntries = vault.findEntries(data, { type: "totp" });
122
+
123
+ for (const entry of totpEntries) {
124
+ const code = await vault.generateTOTP(entry);
125
+ const remaining = vault.getTOTPTimeRemaining();
126
+ console.log(`${entry.label}: ${code} (${remaining}s remaining)`);
127
+ }
128
+ ```
129
+
130
+ ## Utilities
131
+
132
+ ```ts
133
+ // Check write fee
134
+ const fee = await vault.getWriteFee();
135
+ console.log(fee.wei); // 23255813953488n
136
+ console.log(fee.eth); // "0.00002326"
137
+
138
+ // Check unlimited pass
139
+ const hasPass = await vault.hasPass("0x...");
140
+
141
+ // Check if vault exists
142
+ const exists = await vault.hasVault("0x...");
143
+ ```
144
+
145
+ ## Supported Chains
146
+
147
+ | Chain | ID | Contract |
148
+ |--------------|---------|-------------------------------------------------|
149
+ | Base | `8453` | `0xF74C1131E11aF8dc10F25bAa977dD0B86d4A5C37` |
150
+ | Ethereum | `1` | `0xF74C1131E11aF8dc10F25bAa977dD0B86d4A5C37` |
151
+ | Arbitrum One | `42161` | `0x33939ede1A19A64EE755F1B5B3284A8E71F68484` |
152
+ | Optimism | `10` | `0x33939ede1A19A64EE755F1B5B3284A8E71F68484` |
153
+
154
+ ## Encryption
155
+
156
+ All vault data is encrypted client-side before being stored on-chain.
157
+
158
+ - **v1**: `PBKDF2(password, salt, 600k, SHA-256)` → AES-256-GCM
159
+ - **v2**: `PBKDF2(password + walletSignature, salt, 600k, SHA-256)` → AES-256-GCM
160
+
161
+ The SDK always writes v2 and can read both formats.
162
+
163
+ ## Low-Level Exports
164
+
165
+ For advanced use cases, the SDK also exports crypto and chain primitives:
166
+
167
+ ```ts
168
+ import {
169
+ encrypt,
170
+ encryptV2,
171
+ decrypt,
172
+ detectVersionFromHex,
173
+ KDF_SIGN_MESSAGE,
174
+ generateTOTP,
175
+ getTOTPTimeRemaining,
176
+ isValidTOTPSecret,
177
+ base32Decode,
178
+ VAULT_ADDRESSES,
179
+ CHAIN_NAME_TO_ID,
180
+ } from "@deadvault/sdk";
181
+ ```
182
+
183
+ ## Security
184
+
185
+ - Encryption keys are derived locally — private keys and passwords never leave the client
186
+ - All on-chain data is encrypted ciphertext — the contract stores opaque blobs
187
+ - PBKDF2 with 600,000 iterations for brute-force resistance
188
+ - v2 encryption binds the key to the wallet via a signature, preventing password-only attacks
189
+
190
+ ## Requirements
191
+
192
+ - Node.js ≥ 18 (Web Crypto API)
193
+ - `viem` ≥ 2.0.0 as peer dependency
194
+
195
+ ## License
196
+
197
+ MIT — see [LICENSE](./LICENSE)