@p47h/vault-js 0.9.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/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # P47H Vault JS
2
+
3
+ Secure, local-first cryptographic storage for browser environments.
4
+ Backed by Argon2id, XChaCha20Poly1305, and Ed25519 via WebAssembly.
5
+
6
+ [![License: AGPL v3](https://img.shields.io/badge/License-AGPL_v3-blue.svg)](./LICENSE)
7
+ [![Commercial License Available](https://img.shields.io/badge/Commercial-Available-green.svg)](https://p47h.com/licensing)
8
+
9
+ ## Overview
10
+
11
+ P47H Vault JS addresses the insecurity of storing sensitive user secrets (API keys, private keys, PII) in browser storage mechanisms like `localStorage` or cookies.
12
+
13
+ It provides an encrypted enclave within the client application, leveraging the P47H Core Rust implementation compiled to WebAssembly. This ensures that cryptographic operations are consistent across platforms and resistant to common JavaScript-based attack vectors.
14
+
15
+ ## Key Features
16
+
17
+ * **WASM-Backed Cryptography:** Core logic resides in a compiled Rust binary, not interpreted JavaScript.
18
+ * **Memory Isolation:** Private keys are generated within the WASM linear memory and are not exposed to the JavaScript heap as plain text during rest.
19
+ * **Authenticated Encryption:** Data is persisted using XChaCha20Poly1305.
20
+ * **Key Derivation:** Master keys are derived using Argon2id (OWASP recommendation) to resist brute-force attacks.
21
+ * **Framework Agnostic:** Pure TypeScript implementation suitable for React, Vue, Angular, or vanilla JS.
22
+ * **Dual Licensing:** AGPLv3 for open source, commercial licenses available for proprietary use.
23
+
24
+ ## Architecture
25
+
26
+ This library adheres to Clean Architecture principles. It exposes a strict interface (`IVault`) and allows for dependency injection of storage adapters, ensuring testability and modularity.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install @p47h/vault-js
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ### Initialization (Open Source Mode)
37
+
38
+ The library loads the WASM module asynchronously. By default, it runs in AGPLv3 mode:
39
+
40
+ ```typescript
41
+ import { P47hVault } from '@p47h/vault-js';
42
+
43
+ const vault = new P47hVault();
44
+ await vault.init({ wasmPath: '/wasm/p47h_wasm_core_bg.wasm' });
45
+
46
+ // Console will show: "🔓 P47H Vault: Running in AGPLv3 Mode..."
47
+ ```
48
+
49
+ ### Initialization (Commercial License)
50
+
51
+ To activate a commercial license and remove the AGPLv3 nagware:
52
+
53
+ ```typescript
54
+ import { P47hVault } from '@p47h/vault-js';
55
+
56
+ const vault = new P47hVault();
57
+ await vault.init({
58
+ wasmPath: '/wasm/p47h_wasm_core_bg.wasm',
59
+ licenseKey: 'YOUR_LICENSE_TOKEN_HERE' // Format: PAYLOAD.SIGNATURE
60
+ });
61
+
62
+ // Check license status
63
+ if (vault.isCommercialLicense()) {
64
+ console.log(`Licensed to: ${vault.getLicensee()}`);
65
+ }
66
+ ```
67
+
68
+ ### Identity Creation
69
+
70
+ Generates a new Ed25519 identity. The private key is encrypted immediately upon generation using a session key derived from the provided password.
71
+
72
+ ```typescript
73
+ try {
74
+ const did = await vault.register("strong-user-password");
75
+ console.log("Identity created:", did); // e.g., did:p47h:123...
76
+ } catch (error) {
77
+ console.error("Registration failed:", error);
78
+ }
79
+ ```
80
+
81
+ ### Secure Storage
82
+
83
+ Store arbitrary secrets. The payload is encrypted before touching the persistent storage layer.
84
+
85
+ ```typescript
86
+ await vault.saveSecret("stripe_api_key", "sk_live_...");
87
+ ```
88
+
89
+ ### Zero-Exposure Usage
90
+
91
+ Use stored secrets without extracting them to the application layer. The vault handles decryption and usage internally.
92
+
93
+ ```typescript
94
+ // Example: Signing a payload with the identity's private key
95
+ const signature = await vault.sign(new TextEncoder().encode("transaction_payload"));
96
+ ```
97
+
98
+ ## Licensing
99
+
100
+ This project uses a **Dual Licensing** model with built-in IP protection ("Crypto-Nagware").
101
+
102
+ ### How It Works
103
+
104
+ 1. **Without License Key:** The SDK operates in AGPLv3 mode with visible console warnings reminding users of their obligation to release source code.
105
+
106
+ 2. **With Valid License Key:** The SDK verifies the Ed25519-signed license token embedded in the WASM binary. If valid, no warnings are shown.
107
+
108
+ 3. **Tamper Resistance:** The verification logic is compiled into Rust/WASM. Removing the nagware requires modifying and recompiling the source code, not just editing JavaScript.
109
+
110
+ ### Open Source License (AGPLv3)
111
+
112
+ Free for use in open-source projects. If you integrate this library into an application, that application must also be released under the AGPLv3 license AND make source code available to network users.
113
+
114
+ ### Commercial License
115
+
116
+ For proprietary, closed-source, or commercial applications, a commercial license is required. This license releases you from the copyleft requirements of the AGPLv3 and includes:
117
+
118
+ * ✅ IP Indemnification
119
+ * ✅ No AGPLv3 source disclosure requirements
120
+ * ✅ No console nagware messages
121
+ * ✅ Direct Support & Priority Updates
122
+ * ✅ LTS Security Patches
123
+
124
+ **[Get Your License](https://p47h.com/licensing)** | **[Contact Sales](mailto:support@p47h.com)**
125
+
126
+ ## API Reference
127
+
128
+ ### VaultConfig
129
+
130
+ ```typescript
131
+ interface VaultConfig {
132
+ wasmPath?: string; // Path to WASM binary (default: auto-detect)
133
+ storage?: IStorage; // Custom storage adapter (default: IndexedDB)
134
+ licenseKey?: string; // Commercial license token
135
+ }
136
+ ```
137
+
138
+ ### License Methods
139
+
140
+ ```typescript
141
+ // Check if commercial license is active
142
+ vault.isCommercialLicense(): boolean;
143
+
144
+ // Get licensee name (null if AGPLv3 mode)
145
+ vault.getLicensee(): string | null;
146
+ ```
147
+
148
+ ---
149
+
150
+ Copyright © 2026 P47H Team. All rights reserved.