shogun-core 3.3.1 → 3.3.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/dist/ship/examples/ephemeral-cli.js +234 -0
- package/dist/ship/examples/identity-cli.js +503 -0
- package/dist/ship/examples/messenger-cli.js +745 -0
- package/dist/ship/examples/stealth-cli.js +433 -0
- package/dist/ship/examples/storage-cli.js +615 -0
- package/dist/ship/examples/vault-cli.js +444 -0
- package/dist/ship/examples/wallet-cli.js +767 -0
- package/dist/ship/implementation/SHIP_00.js +478 -0
- package/dist/ship/implementation/SHIP_01.js +433 -0
- package/dist/ship/implementation/SHIP_02.js +1366 -0
- package/dist/ship/implementation/SHIP_03.js +855 -0
- package/dist/ship/implementation/SHIP_04.js +589 -0
- package/dist/ship/implementation/SHIP_05.js +1064 -0
- package/dist/ship/implementation/SHIP_06.js +350 -0
- package/dist/ship/implementation/SHIP_07.js +635 -0
- package/dist/ship/index.js +17 -0
- package/dist/ship/interfaces/ISHIP_00.js +135 -0
- package/dist/ship/interfaces/ISHIP_01.js +128 -0
- package/dist/ship/interfaces/ISHIP_02.js +57 -0
- package/dist/ship/interfaces/ISHIP_03.js +61 -0
- package/dist/ship/interfaces/ISHIP_04.js +62 -0
- package/dist/ship/interfaces/ISHIP_05.js +59 -0
- package/dist/ship/interfaces/ISHIP_06.js +144 -0
- package/dist/ship/interfaces/ISHIP_07.js +194 -0
- package/dist/types/ship/examples/ephemeral-cli.d.ts +13 -0
- package/dist/types/ship/examples/identity-cli.d.ts +40 -0
- package/dist/types/ship/examples/messenger-cli.d.ts +37 -0
- package/dist/types/ship/examples/stealth-cli.d.ts +31 -0
- package/dist/types/ship/examples/storage-cli.d.ts +48 -0
- package/dist/types/ship/examples/vault-cli.d.ts +13 -0
- package/dist/types/ship/examples/wallet-cli.d.ts +131 -0
- package/dist/types/ship/implementation/SHIP_00.d.ts +113 -0
- package/dist/types/ship/implementation/SHIP_01.d.ts +80 -0
- package/dist/types/ship/implementation/SHIP_02.d.ts +297 -0
- package/dist/types/ship/implementation/SHIP_03.d.ts +127 -0
- package/dist/types/ship/implementation/SHIP_04.d.ts +76 -0
- package/dist/types/ship/implementation/SHIP_05.d.ts +70 -0
- package/dist/types/ship/implementation/SHIP_06.d.ts +66 -0
- package/dist/types/ship/implementation/SHIP_07.d.ts +101 -0
- package/dist/types/ship/index.d.ts +14 -0
- package/dist/types/ship/interfaces/ISHIP_00.d.ts +410 -0
- package/dist/types/ship/interfaces/ISHIP_01.d.ts +343 -0
- package/dist/types/ship/interfaces/ISHIP_02.d.ts +470 -0
- package/dist/types/ship/interfaces/ISHIP_03.d.ts +295 -0
- package/dist/types/ship/interfaces/ISHIP_04.d.ts +245 -0
- package/dist/types/ship/interfaces/ISHIP_05.d.ts +234 -0
- package/dist/types/ship/interfaces/ISHIP_06.d.ts +370 -0
- package/dist/types/ship/interfaces/ISHIP_07.d.ts +522 -0
- package/package.json +1 -1
- /package/dist/{config → src/config}/simplified-config.js +0 -0
- /package/dist/{core.js → src/core.js} +0 -0
- /package/dist/{examples → src/examples}/api-test.js +0 -0
- /package/dist/{examples → src/examples}/simple-api-test.js +0 -0
- /package/dist/{gundb → src/gundb}/api.js +0 -0
- /package/dist/{gundb → src/gundb}/crypto.js +0 -0
- /package/dist/{gundb → src/gundb}/db.js +0 -0
- /package/dist/{gundb → src/gundb}/derive.js +0 -0
- /package/dist/{gundb → src/gundb}/errors.js +0 -0
- /package/dist/{gundb → src/gundb}/index.js +0 -0
- /package/dist/{gundb → src/gundb}/rxjs.js +0 -0
- /package/dist/{gundb → src/gundb}/types.js +0 -0
- /package/dist/{index.js → src/index.js} +0 -0
- /package/dist/{interfaces → src/interfaces}/common.js +0 -0
- /package/dist/{interfaces → src/interfaces}/events.js +0 -0
- /package/dist/{interfaces → src/interfaces}/plugin.js +0 -0
- /package/dist/{interfaces → src/interfaces}/shogun.js +0 -0
- /package/dist/{managers → src/managers}/AuthManager.js +0 -0
- /package/dist/{managers → src/managers}/CoreInitializer.js +0 -0
- /package/dist/{managers → src/managers}/EventManager.js +0 -0
- /package/dist/{managers → src/managers}/PluginManager.js +0 -0
- /package/dist/{migration-test.js → src/migration-test.js} +0 -0
- /package/dist/{plugins → src/plugins}/base.js +0 -0
- /package/dist/{plugins → src/plugins}/index.js +0 -0
- /package/dist/{plugins → src/plugins}/nostr/index.js +0 -0
- /package/dist/{plugins → src/plugins}/nostr/nostrConnector.js +0 -0
- /package/dist/{plugins → src/plugins}/nostr/nostrConnectorPlugin.js +0 -0
- /package/dist/{plugins → src/plugins}/nostr/nostrSigner.js +0 -0
- /package/dist/{plugins → src/plugins}/nostr/types.js +0 -0
- /package/dist/{plugins → src/plugins}/oauth/index.js +0 -0
- /package/dist/{plugins → src/plugins}/oauth/oauthConnector.js +0 -0
- /package/dist/{plugins → src/plugins}/oauth/oauthPlugin.js +0 -0
- /package/dist/{plugins → src/plugins}/oauth/types.js +0 -0
- /package/dist/{plugins → src/plugins}/web3/index.js +0 -0
- /package/dist/{plugins → src/plugins}/web3/types.js +0 -0
- /package/dist/{plugins → src/plugins}/web3/web3Connector.js +0 -0
- /package/dist/{plugins → src/plugins}/web3/web3ConnectorPlugin.js +0 -0
- /package/dist/{plugins → src/plugins}/web3/web3Signer.js +0 -0
- /package/dist/{plugins → src/plugins}/webauthn/index.js +0 -0
- /package/dist/{plugins → src/plugins}/webauthn/types.js +0 -0
- /package/dist/{plugins → src/plugins}/webauthn/webauthn.js +0 -0
- /package/dist/{plugins → src/plugins}/webauthn/webauthnPlugin.js +0 -0
- /package/dist/{plugins → src/plugins}/webauthn/webauthnSigner.js +0 -0
- /package/dist/{storage → src/storage}/storage.js +0 -0
- /package/dist/{types → src/types}/events.js +0 -0
- /package/dist/{types → src/types}/shogun.js +0 -0
- /package/dist/{utils → src/utils}/errorHandler.js +0 -0
- /package/dist/{utils → src/utils}/eventEmitter.js +0 -0
- /package/dist/{utils → src/utils}/validation.js +0 -0
- /package/dist/types/{config → src/config}/simplified-config.d.ts +0 -0
- /package/dist/types/{core.d.ts → src/core.d.ts} +0 -0
- /package/dist/types/{examples → src/examples}/api-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/simple-api-test.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/api.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/crypto.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/db.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/derive.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/errors.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/index.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/rxjs.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/types.d.ts +0 -0
- /package/dist/types/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/types/{interfaces → src/interfaces}/common.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/events.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/plugin.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/shogun.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/AuthManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/CoreInitializer.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/EventManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/PluginManager.d.ts +0 -0
- /package/dist/types/{migration-test.d.ts → src/migration-test.d.ts} +0 -0
- /package/dist/types/{plugins → src/plugins}/base.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrConnector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrSigner.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/oauth/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/oauth/oauthConnector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/oauth/oauthPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/oauth/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3Connector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3Signer.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthn.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthnPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthnSigner.d.ts +0 -0
- /package/dist/types/{storage → src/storage}/storage.d.ts +0 -0
- /package/dist/types/{types → src/types}/events.d.ts +0 -0
- /package/dist/types/{types → src/types}/shogun.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/errorHandler.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/eventEmitter.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHIP-07: Secure Vault Interface
|
|
3
|
+
*
|
|
4
|
+
* @title ISHIP_07 - Secure Encrypted Vault
|
|
5
|
+
* @notice Interface for secure encrypted key-value storage on GunDB
|
|
6
|
+
* @dev This interface depends on ISHIP_00 for identity and encryption
|
|
7
|
+
*
|
|
8
|
+
* ## Abstract
|
|
9
|
+
*
|
|
10
|
+
* This standard defines an interface for secure vault storage that allows:
|
|
11
|
+
* - End-to-end encrypted key-value storage
|
|
12
|
+
* - Soft delete with recovery
|
|
13
|
+
* - Export/import for backup
|
|
14
|
+
* - Rich metadata support
|
|
15
|
+
* - Simple, secure, focused on storage only
|
|
16
|
+
*
|
|
17
|
+
* ## Dependencies
|
|
18
|
+
*
|
|
19
|
+
* - ISHIP_00: Identity and authentication layer
|
|
20
|
+
* - GunDB: P2P storage
|
|
21
|
+
* - SEA: Cryptography (AES-256-GCM)
|
|
22
|
+
*
|
|
23
|
+
* ## Inspiration
|
|
24
|
+
*
|
|
25
|
+
* Based on Gunsafe (https://github.com/draeder/gunsafe)
|
|
26
|
+
* Adapted for Shogun ecosystem with SHIP-00 integration
|
|
27
|
+
*/
|
|
28
|
+
import type { ISHIP_00 } from "./ISHIP_00";
|
|
29
|
+
/**
|
|
30
|
+
* @notice Vault record structure
|
|
31
|
+
*/
|
|
32
|
+
export interface VaultRecord {
|
|
33
|
+
name: string;
|
|
34
|
+
data: any;
|
|
35
|
+
created: number;
|
|
36
|
+
updated: number;
|
|
37
|
+
deleted: boolean;
|
|
38
|
+
metadata?: RecordMetadata;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @notice Encrypted record (stored in GunDB)
|
|
42
|
+
*/
|
|
43
|
+
export interface EncryptedRecord {
|
|
44
|
+
data: string;
|
|
45
|
+
created: string;
|
|
46
|
+
updated: string;
|
|
47
|
+
deleted: boolean;
|
|
48
|
+
metadata?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @notice Record metadata
|
|
52
|
+
*/
|
|
53
|
+
export interface RecordMetadata {
|
|
54
|
+
type?: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
tags?: string[];
|
|
57
|
+
expiresAt?: number;
|
|
58
|
+
[key: string]: any;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @notice Vault operation result
|
|
62
|
+
*/
|
|
63
|
+
export interface VaultResult {
|
|
64
|
+
success: boolean;
|
|
65
|
+
error?: string;
|
|
66
|
+
recordName?: string;
|
|
67
|
+
recordCount?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @notice Vault statistics
|
|
71
|
+
*/
|
|
72
|
+
export interface VaultStats {
|
|
73
|
+
totalRecords: number;
|
|
74
|
+
activeRecords: number;
|
|
75
|
+
deletedRecords: number;
|
|
76
|
+
totalSize: number;
|
|
77
|
+
created: number;
|
|
78
|
+
lastModified: number;
|
|
79
|
+
recordsByType?: Record<string, number>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @notice Options for retrieving records
|
|
83
|
+
*/
|
|
84
|
+
export interface GetOptions {
|
|
85
|
+
includeDeleted?: boolean;
|
|
86
|
+
decrypt?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @notice Options for listing records
|
|
90
|
+
*/
|
|
91
|
+
export interface ListOptions {
|
|
92
|
+
includeDeleted?: boolean;
|
|
93
|
+
filterByTag?: string;
|
|
94
|
+
filterByType?: string;
|
|
95
|
+
sortBy?: "name" | "created" | "updated";
|
|
96
|
+
sortDesc?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @notice Options for importing vault
|
|
100
|
+
*/
|
|
101
|
+
export interface ImportOptions {
|
|
102
|
+
merge?: boolean;
|
|
103
|
+
overwrite?: boolean;
|
|
104
|
+
skipDeleted?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @notice Options for exporting vault
|
|
108
|
+
*/
|
|
109
|
+
export interface ExportOptions {
|
|
110
|
+
includeDeleted?: boolean;
|
|
111
|
+
pretty?: boolean;
|
|
112
|
+
filterByTag?: string;
|
|
113
|
+
filterByType?: string;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @title ISHIP_07 - Secure Vault
|
|
117
|
+
* @notice Main interface for secure encrypted vault
|
|
118
|
+
* @dev Depends on ISHIP_00 for all identity and encryption operations
|
|
119
|
+
*
|
|
120
|
+
* Constructor pattern:
|
|
121
|
+
* ```typescript
|
|
122
|
+
* class SecureVault implements ISHIP_07 {
|
|
123
|
+
* constructor(private identity: ISHIP_00) {}
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export interface ISHIP_07 {
|
|
128
|
+
/**
|
|
129
|
+
* @notice Get the identity provider
|
|
130
|
+
* @dev Returns the ISHIP_00 instance used for identity operations
|
|
131
|
+
* @return Identity provider instance
|
|
132
|
+
*/
|
|
133
|
+
getIdentity(): ISHIP_00;
|
|
134
|
+
/**
|
|
135
|
+
* @notice Initialize vault
|
|
136
|
+
* @dev Sets up vault node structure in user's Gun space
|
|
137
|
+
*
|
|
138
|
+
* Prerequisites:
|
|
139
|
+
* - User must be authenticated (via ISHIP_00)
|
|
140
|
+
*
|
|
141
|
+
* Flow:
|
|
142
|
+
* 1. Verify user authentication
|
|
143
|
+
* 2. Create vault node structure
|
|
144
|
+
* 3. Initialize metadata
|
|
145
|
+
*/
|
|
146
|
+
initialize(): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* @notice Check if vault is initialized
|
|
149
|
+
* @return True if vault is initialized
|
|
150
|
+
*/
|
|
151
|
+
isInitialized(): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* @notice Store encrypted record in vault
|
|
154
|
+
* @dev Encrypts data with SEA and stores in user's vault node
|
|
155
|
+
* @param name Record name/key (must be unique)
|
|
156
|
+
* @param data Data to encrypt and store (any type)
|
|
157
|
+
* @param metadata Optional metadata
|
|
158
|
+
* @return Operation result
|
|
159
|
+
*
|
|
160
|
+
* Prerequisites:
|
|
161
|
+
* - Vault must be initialized
|
|
162
|
+
* - User must be authenticated
|
|
163
|
+
*
|
|
164
|
+
* Flow:
|
|
165
|
+
* 1. Validate record name
|
|
166
|
+
* 2. Encrypt data with SEA
|
|
167
|
+
* 3. Encrypt metadata if provided
|
|
168
|
+
* 4. Store in gun.user().get('vault').get('records').get(name)
|
|
169
|
+
* 5. Update vault metadata
|
|
170
|
+
*/
|
|
171
|
+
put(name: string, data: any, metadata?: RecordMetadata): Promise<VaultResult>;
|
|
172
|
+
/**
|
|
173
|
+
* @notice Retrieve and decrypt record from vault
|
|
174
|
+
* @dev Retrieves and decrypts record from user's vault node
|
|
175
|
+
* @param name Record name/key
|
|
176
|
+
* @param options Retrieval options
|
|
177
|
+
* @return Decrypted record or null if not found
|
|
178
|
+
*
|
|
179
|
+
* Prerequisites:
|
|
180
|
+
* - Vault must be initialized
|
|
181
|
+
* - User must be authenticated
|
|
182
|
+
*
|
|
183
|
+
* Flow:
|
|
184
|
+
* 1. Retrieve encrypted record from Gun
|
|
185
|
+
* 2. Decrypt data with SEA
|
|
186
|
+
* 3. Decrypt metadata if present
|
|
187
|
+
* 4. Return decrypted record
|
|
188
|
+
*/
|
|
189
|
+
get(name: string, options?: GetOptions): Promise<VaultRecord | null>;
|
|
190
|
+
/**
|
|
191
|
+
* @notice Delete record from vault (soft delete)
|
|
192
|
+
* @dev Marks record as deleted without removing data
|
|
193
|
+
* @param name Record name/key (optional - deletes all if omitted)
|
|
194
|
+
* @return Operation result
|
|
195
|
+
*
|
|
196
|
+
* Soft Delete:
|
|
197
|
+
* - Record data remains encrypted in Gun
|
|
198
|
+
* - Marked as deleted (deleted: true)
|
|
199
|
+
* - Can be recovered before compaction
|
|
200
|
+
* - Not returned by default in list/get
|
|
201
|
+
*/
|
|
202
|
+
delete(name?: string): Promise<VaultResult>;
|
|
203
|
+
/**
|
|
204
|
+
* @notice List all record names in vault
|
|
205
|
+
* @dev Returns array of record names matching criteria
|
|
206
|
+
* @param options List options
|
|
207
|
+
* @return Array of record names
|
|
208
|
+
*
|
|
209
|
+
* Flow:
|
|
210
|
+
* 1. Retrieve all records from vault node
|
|
211
|
+
* 2. Apply filters (deleted, tags, type)
|
|
212
|
+
* 3. Sort if requested
|
|
213
|
+
* 4. Return record names
|
|
214
|
+
*/
|
|
215
|
+
list(options?: ListOptions): Promise<string[]>;
|
|
216
|
+
/**
|
|
217
|
+
* @notice Check if record exists
|
|
218
|
+
* @param name Record name/key
|
|
219
|
+
* @return True if record exists (and not deleted)
|
|
220
|
+
*/
|
|
221
|
+
exists(name: string): Promise<boolean>;
|
|
222
|
+
/**
|
|
223
|
+
* @notice Update existing record
|
|
224
|
+
* @dev Updates record data and timestamp
|
|
225
|
+
* @param name Record name/key
|
|
226
|
+
* @param data New data
|
|
227
|
+
* @return Operation result
|
|
228
|
+
*
|
|
229
|
+
* Flow:
|
|
230
|
+
* 1. Check if record exists
|
|
231
|
+
* 2. Encrypt new data
|
|
232
|
+
* 3. Update record with new data
|
|
233
|
+
* 4. Update timestamp
|
|
234
|
+
*/
|
|
235
|
+
update(name: string, data: any): Promise<VaultResult>;
|
|
236
|
+
/**
|
|
237
|
+
* @notice Export entire vault (encrypted)
|
|
238
|
+
* @dev Exports all vault records as encrypted JSON string
|
|
239
|
+
* @param password Optional additional encryption password
|
|
240
|
+
* @param options Export options
|
|
241
|
+
* @return Encrypted vault backup as string
|
|
242
|
+
*
|
|
243
|
+
* Flow:
|
|
244
|
+
* 1. Retrieve all records
|
|
245
|
+
* 2. Optionally filter records
|
|
246
|
+
* 3. Serialize to JSON
|
|
247
|
+
* 4. Optionally encrypt with additional password
|
|
248
|
+
* 5. Return as base64 string
|
|
249
|
+
*/
|
|
250
|
+
export(password?: string, options?: ExportOptions): Promise<string>;
|
|
251
|
+
/**
|
|
252
|
+
* @notice Import vault from backup
|
|
253
|
+
* @dev Imports and decrypts vault backup
|
|
254
|
+
* @param backupData Exported vault data
|
|
255
|
+
* @param password Optional decryption password
|
|
256
|
+
* @param options Import options
|
|
257
|
+
* @return Operation result
|
|
258
|
+
*
|
|
259
|
+
* Flow:
|
|
260
|
+
* 1. Decode base64 backup
|
|
261
|
+
* 2. Decrypt with password if provided
|
|
262
|
+
* 3. Parse JSON
|
|
263
|
+
* 4. For each record:
|
|
264
|
+
* - Check if exists (if merge mode)
|
|
265
|
+
* - Import or skip based on options
|
|
266
|
+
* 5. Update vault metadata
|
|
267
|
+
*/
|
|
268
|
+
import(backupData: string, password?: string, options?: ImportOptions): Promise<VaultResult>;
|
|
269
|
+
/**
|
|
270
|
+
* @notice Get vault statistics
|
|
271
|
+
* @dev Returns statistics about vault contents
|
|
272
|
+
* @return Vault statistics
|
|
273
|
+
*/
|
|
274
|
+
getStats(): Promise<VaultStats>;
|
|
275
|
+
/**
|
|
276
|
+
* @notice Clear all records (soft delete all)
|
|
277
|
+
* @dev Marks all records as deleted
|
|
278
|
+
* @return Operation result
|
|
279
|
+
*/
|
|
280
|
+
clear(): Promise<VaultResult>;
|
|
281
|
+
/**
|
|
282
|
+
* @notice Compact vault (remove deleted records permanently)
|
|
283
|
+
* @dev Permanently removes soft-deleted records
|
|
284
|
+
* @return Operation result
|
|
285
|
+
*
|
|
286
|
+
* ⚠️ WARNING:
|
|
287
|
+
* - This operation is irreversible
|
|
288
|
+
* - Deleted records cannot be recovered after compaction
|
|
289
|
+
*/
|
|
290
|
+
compact(): Promise<VaultResult>;
|
|
291
|
+
/**
|
|
292
|
+
* @notice Search records by content
|
|
293
|
+
* @dev Searches decrypted content (expensive operation)
|
|
294
|
+
* @param query Search query
|
|
295
|
+
* @return Array of matching record names
|
|
296
|
+
*/
|
|
297
|
+
search(query: string): Promise<string[]>;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* @notice Vault configuration
|
|
301
|
+
*/
|
|
302
|
+
export interface VaultConfig {
|
|
303
|
+
/**
|
|
304
|
+
* @notice Identity provider (SHIP-00 instance)
|
|
305
|
+
*/
|
|
306
|
+
identity: ISHIP_00;
|
|
307
|
+
/**
|
|
308
|
+
* @notice Vault node name in Gun (default: "vault")
|
|
309
|
+
*/
|
|
310
|
+
vaultNodeName?: string;
|
|
311
|
+
/**
|
|
312
|
+
* @notice Enable debug logging
|
|
313
|
+
*/
|
|
314
|
+
debug?: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* @notice Operation timeout (ms)
|
|
317
|
+
*/
|
|
318
|
+
timeout?: number;
|
|
319
|
+
/**
|
|
320
|
+
* @notice Enable automatic backup
|
|
321
|
+
*/
|
|
322
|
+
autoBackup?: boolean;
|
|
323
|
+
/**
|
|
324
|
+
* @notice Backup interval (ms)
|
|
325
|
+
*/
|
|
326
|
+
backupInterval?: number;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* @notice Event emitter interface for SHIP-07
|
|
330
|
+
*/
|
|
331
|
+
export interface ISHIP_07Events {
|
|
332
|
+
/**
|
|
333
|
+
* Emitted when vault is initialized
|
|
334
|
+
*/
|
|
335
|
+
initialized: () => void;
|
|
336
|
+
/**
|
|
337
|
+
* Emitted when record is added
|
|
338
|
+
*/
|
|
339
|
+
recordAdded: (name: string) => void;
|
|
340
|
+
/**
|
|
341
|
+
* Emitted when record is updated
|
|
342
|
+
*/
|
|
343
|
+
recordUpdated: (name: string) => void;
|
|
344
|
+
/**
|
|
345
|
+
* Emitted when record is deleted
|
|
346
|
+
*/
|
|
347
|
+
recordDeleted: (name: string) => void;
|
|
348
|
+
/**
|
|
349
|
+
* Emitted when vault is exported
|
|
350
|
+
*/
|
|
351
|
+
exported: (size: number) => void;
|
|
352
|
+
/**
|
|
353
|
+
* Emitted when vault is imported
|
|
354
|
+
*/
|
|
355
|
+
imported: (recordCount: number) => void;
|
|
356
|
+
/**
|
|
357
|
+
* Emitted on error
|
|
358
|
+
*/
|
|
359
|
+
error: (error: Error) => void;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Example of how to implement ISHIP_07 with ISHIP_00 dependency
|
|
363
|
+
*
|
|
364
|
+
* ```typescript
|
|
365
|
+
* import { ISHIP_00 } from './ISHIP_00';
|
|
366
|
+
* import { ISHIP_07, VaultRecord, VaultResult } from './ISHIP_07';
|
|
367
|
+
*
|
|
368
|
+
* class SecureVault implements ISHIP_07 {
|
|
369
|
+
* private vaultNode: any;
|
|
370
|
+
* private initialized: boolean = false;
|
|
371
|
+
*
|
|
372
|
+
* constructor(private identity: ISHIP_00) {
|
|
373
|
+
* if (!identity.isLoggedIn()) {
|
|
374
|
+
* throw new Error('User must be authenticated via SHIP-00');
|
|
375
|
+
* }
|
|
376
|
+
* }
|
|
377
|
+
*
|
|
378
|
+
* getIdentity(): ISHIP_00 {
|
|
379
|
+
* return this.identity;
|
|
380
|
+
* }
|
|
381
|
+
*
|
|
382
|
+
* async initialize(): Promise<void> {
|
|
383
|
+
* // Get Gun user node
|
|
384
|
+
* const gun = this.identity.shogun.db.gun;
|
|
385
|
+
* this.vaultNode = gun.user().get('vault').get('records');
|
|
386
|
+
*
|
|
387
|
+
* // Initialize vault metadata
|
|
388
|
+
* await gun.user().get('vault').get('metadata').put({
|
|
389
|
+
* version: '1.0.0',
|
|
390
|
+
* created: Date.now().toString()
|
|
391
|
+
* });
|
|
392
|
+
*
|
|
393
|
+
* this.initialized = true;
|
|
394
|
+
* }
|
|
395
|
+
*
|
|
396
|
+
* isInitialized(): boolean {
|
|
397
|
+
* return this.initialized;
|
|
398
|
+
* }
|
|
399
|
+
*
|
|
400
|
+
* async put(name: string, data: any, metadata?: RecordMetadata): Promise<VaultResult> {
|
|
401
|
+
* if (!this.initialized) {
|
|
402
|
+
* return { success: false, error: 'Vault not initialized' };
|
|
403
|
+
* }
|
|
404
|
+
*
|
|
405
|
+
* try {
|
|
406
|
+
* // Get SEA crypto
|
|
407
|
+
* const crypto = this.identity.shogun.db.crypto;
|
|
408
|
+
* const pair = this.identity.getKeyPair();
|
|
409
|
+
*
|
|
410
|
+
* if (!pair) {
|
|
411
|
+
* return { success: false, error: 'Cannot access key pair' };
|
|
412
|
+
* }
|
|
413
|
+
*
|
|
414
|
+
* // Encrypt data
|
|
415
|
+
* const encryptedData = await crypto.encrypt(
|
|
416
|
+
* JSON.stringify(data),
|
|
417
|
+
* pair.epriv
|
|
418
|
+
* );
|
|
419
|
+
*
|
|
420
|
+
* // Encrypt metadata if provided
|
|
421
|
+
* const encryptedMetadata = metadata
|
|
422
|
+
* ? await crypto.encrypt(JSON.stringify(metadata), pair.epriv)
|
|
423
|
+
* : undefined;
|
|
424
|
+
*
|
|
425
|
+
* // Store in vault
|
|
426
|
+
* const record = {
|
|
427
|
+
* data: encryptedData,
|
|
428
|
+
* created: Date.now().toString(),
|
|
429
|
+
* updated: Date.now().toString(),
|
|
430
|
+
* deleted: false,
|
|
431
|
+
* metadata: encryptedMetadata
|
|
432
|
+
* };
|
|
433
|
+
*
|
|
434
|
+
* await this.vaultNode.get(name).put(record);
|
|
435
|
+
*
|
|
436
|
+
* return { success: true, recordName: name };
|
|
437
|
+
* } catch (error: any) {
|
|
438
|
+
* return { success: false, error: error.message };
|
|
439
|
+
* }
|
|
440
|
+
* }
|
|
441
|
+
*
|
|
442
|
+
* async get(name: string, options?: GetOptions): Promise<VaultRecord | null> {
|
|
443
|
+
* if (!this.initialized) {
|
|
444
|
+
* return null;
|
|
445
|
+
* }
|
|
446
|
+
*
|
|
447
|
+
* try {
|
|
448
|
+
* // Retrieve from vault
|
|
449
|
+
* const encryptedRecord = await this.vaultNode.get(name).then();
|
|
450
|
+
*
|
|
451
|
+
* if (!encryptedRecord || !encryptedRecord.data) {
|
|
452
|
+
* return null;
|
|
453
|
+
* }
|
|
454
|
+
*
|
|
455
|
+
* // Skip if deleted (unless includeDeleted)
|
|
456
|
+
* if (encryptedRecord.deleted && !options?.includeDeleted) {
|
|
457
|
+
* return null;
|
|
458
|
+
* }
|
|
459
|
+
*
|
|
460
|
+
* // Decrypt data
|
|
461
|
+
* const crypto = this.identity.shogun.db.crypto;
|
|
462
|
+
* const pair = this.identity.getKeyPair();
|
|
463
|
+
*
|
|
464
|
+
* if (!pair) {
|
|
465
|
+
* return null;
|
|
466
|
+
* }
|
|
467
|
+
*
|
|
468
|
+
* const decryptedData = await crypto.decrypt(
|
|
469
|
+
* encryptedRecord.data,
|
|
470
|
+
* pair.epriv
|
|
471
|
+
* );
|
|
472
|
+
*
|
|
473
|
+
* // Decrypt metadata if present
|
|
474
|
+
* const decryptedMetadata = encryptedRecord.metadata
|
|
475
|
+
* ? JSON.parse(await crypto.decrypt(encryptedRecord.metadata, pair.epriv))
|
|
476
|
+
* : undefined;
|
|
477
|
+
*
|
|
478
|
+
* return {
|
|
479
|
+
* name,
|
|
480
|
+
* data: JSON.parse(decryptedData),
|
|
481
|
+
* created: parseInt(encryptedRecord.created),
|
|
482
|
+
* updated: parseInt(encryptedRecord.updated),
|
|
483
|
+
* deleted: encryptedRecord.deleted,
|
|
484
|
+
* metadata: decryptedMetadata
|
|
485
|
+
* };
|
|
486
|
+
* } catch (error) {
|
|
487
|
+
* console.error('Error retrieving record:', error);
|
|
488
|
+
* return null;
|
|
489
|
+
* }
|
|
490
|
+
* }
|
|
491
|
+
*
|
|
492
|
+
* async delete(name?: string): Promise<VaultResult> {
|
|
493
|
+
* // Implementation here
|
|
494
|
+
* return { success: true };
|
|
495
|
+
* }
|
|
496
|
+
*
|
|
497
|
+
* async list(options?: ListOptions): Promise<string[]> {
|
|
498
|
+
* // Implementation here
|
|
499
|
+
* return [];
|
|
500
|
+
* }
|
|
501
|
+
*
|
|
502
|
+
* // ... implement other methods
|
|
503
|
+
* }
|
|
504
|
+
*
|
|
505
|
+
* // Usage
|
|
506
|
+
* const identity = new SHIP_00(config);
|
|
507
|
+
* await identity.login('alice', 'password123');
|
|
508
|
+
*
|
|
509
|
+
* const vault = new SecureVault(identity);
|
|
510
|
+
* await vault.initialize();
|
|
511
|
+
*
|
|
512
|
+
* // Store encrypted data
|
|
513
|
+
* await vault.put('my-password', 'super_secret', {
|
|
514
|
+
* type: 'password',
|
|
515
|
+
* description: 'GitHub password'
|
|
516
|
+
* });
|
|
517
|
+
*
|
|
518
|
+
* // Retrieve decrypted data
|
|
519
|
+
* const record = await vault.get('my-password');
|
|
520
|
+
* console.log('Password:', record?.data);
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|