shogun-core 3.2.2 → 3.3.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.
Files changed (32) hide show
  1. package/README.md +12 -0
  2. package/dist/browser/shogun-core.js +108133 -43791
  3. package/dist/browser/shogun-core.js.map +1 -1
  4. package/dist/ship/examples/messenger-cli.js +173 -60
  5. package/dist/ship/examples/wallet-cli.js +767 -0
  6. package/dist/ship/implementation/SHIP_00.js +478 -0
  7. package/dist/ship/implementation/SHIP_01.js +300 -695
  8. package/dist/ship/implementation/SHIP_02.js +1366 -0
  9. package/dist/ship/implementation/SHIP_03.js +855 -0
  10. package/dist/ship/interfaces/ISHIP_00.js +135 -0
  11. package/dist/ship/interfaces/ISHIP_01.js +81 -24
  12. package/dist/ship/interfaces/ISHIP_02.js +57 -0
  13. package/dist/ship/interfaces/ISHIP_03.js +61 -0
  14. package/dist/src/gundb/db.js +55 -11
  15. package/dist/src/index.js +10 -2
  16. package/dist/src/managers/CoreInitializer.js +41 -13
  17. package/dist/src/storage/storage.js +22 -9
  18. package/dist/types/ship/examples/messenger-cli.d.ts +7 -1
  19. package/dist/types/ship/examples/wallet-cli.d.ts +131 -0
  20. package/dist/types/ship/implementation/SHIP_00.d.ts +113 -0
  21. package/dist/types/ship/implementation/SHIP_01.d.ts +47 -76
  22. package/dist/types/ship/implementation/SHIP_02.d.ts +297 -0
  23. package/dist/types/ship/implementation/SHIP_03.d.ts +127 -0
  24. package/dist/types/ship/interfaces/ISHIP_00.d.ts +410 -0
  25. package/dist/types/ship/interfaces/ISHIP_01.d.ts +157 -119
  26. package/dist/types/ship/interfaces/ISHIP_02.d.ts +470 -0
  27. package/dist/types/ship/interfaces/ISHIP_03.d.ts +295 -0
  28. package/dist/types/src/gundb/db.d.ts +10 -3
  29. package/dist/types/src/index.d.ts +7 -0
  30. package/dist/types/src/interfaces/shogun.d.ts +2 -0
  31. package/dist/types/src/storage/storage.d.ts +2 -1
  32. package/package.json +23 -9
@@ -0,0 +1,295 @@
1
+ /**
2
+ * SHIP-03: Dual-Key Stealth Address Interface
3
+ *
4
+ * @title ISHIP_03 - Privacy-Preserving Stealth Addresses
5
+ * @notice Interface for ERC-5564 compatible stealth addresses
6
+ *
7
+ * ## Abstract
8
+ *
9
+ * This standard extends SHIP-00 and SHIP-02 to enable:
10
+ * - Dual-key stealth addresses (viewing + spending keys)
11
+ * - ERC-5564 / Fluidkey compatibility
12
+ * - Enhanced transaction privacy
13
+ * - Stealth address scanning and opening
14
+ * - Deterministic key derivation from SHIP-00 identity
15
+ *
16
+ * ## Specification
17
+ *
18
+ * Based on:
19
+ * - SHIP-00 for identity foundation
20
+ * - SHIP-02 for Ethereum address derivation
21
+ * - ERC-5564 for stealth address standard
22
+ * - Fluidkey Stealth Account Kit
23
+ * - ECDH for shared secret derivation
24
+ *
25
+ * ## Key Concepts
26
+ *
27
+ * **Viewing Key**: Used to scan blockchain for incoming stealth payments
28
+ * **Spending Key**: Used to spend funds received at stealth addresses
29
+ * **Ephemeral Key**: One-time key used by sender to generate stealth address
30
+ *
31
+ * ## Dependencies
32
+ *
33
+ * - SHIP-00: Identity and authentication foundation
34
+ * - SHIP-02: Ethereum wallet operations
35
+ * - @fluidkey/stealth-account-kit: ERC-5564 implementation
36
+ * - ethers: Ethereum operations
37
+ *
38
+ * ## Usage
39
+ *
40
+ * ```typescript
41
+ * const identity = new SHIP_00({ gunOptions: { peers: ['...'] } });
42
+ * await identity.login('alice', 'password123');
43
+ *
44
+ * const eth = new SHIP_02(identity);
45
+ * await eth.initialize();
46
+ *
47
+ * const stealth = new SHIP_03(identity, eth);
48
+ * await stealth.initialize();
49
+ *
50
+ * // Get stealth keys (derived from SHIP-00 identity)
51
+ * const keys = await stealth.getStealthKeys();
52
+ *
53
+ * // Generate stealth address for recipient
54
+ * const stealthAddr = await stealth.generateStealthAddress(
55
+ * recipientViewingKey,
56
+ * recipientSpendingKey
57
+ * );
58
+ * ```
59
+ */
60
+ /**
61
+ * @notice Dual stealth keys (viewing + spending)
62
+ */
63
+ export interface StealthKeys {
64
+ viewingKey: {
65
+ publicKey: string;
66
+ privateKey: string;
67
+ };
68
+ spendingKey: {
69
+ publicKey: string;
70
+ privateKey: string;
71
+ };
72
+ }
73
+ /**
74
+ * @notice Ephemeral key pair for stealth generation
75
+ */
76
+ export interface EphemeralKeyPair {
77
+ publicKey: string;
78
+ privateKey: string;
79
+ }
80
+ /**
81
+ * @notice Stealth address generation result
82
+ */
83
+ export interface StealthAddressResult {
84
+ success: boolean;
85
+ stealthAddress?: string;
86
+ ephemeralPublicKey?: string;
87
+ viewTag?: string;
88
+ error?: string;
89
+ }
90
+ /**
91
+ * @notice Stealth metadata for announcements (ERC-5564)
92
+ */
93
+ export interface StealthMetadata {
94
+ ephemeralPublicKey: string;
95
+ viewTag: string;
96
+ stealthAddress: string;
97
+ createdAt: number;
98
+ }
99
+ /**
100
+ * @notice Announced stealth payment data
101
+ */
102
+ export interface AnnouncedStealth {
103
+ stealthAddress: string;
104
+ ephemeralPublicKey: string;
105
+ viewTag: string;
106
+ schemeId: number;
107
+ announcer: string;
108
+ txHash?: string;
109
+ }
110
+ /**
111
+ * @notice Scanned stealth address that belongs to user
112
+ */
113
+ export interface OwnedStealthAddress {
114
+ stealthAddress: string;
115
+ ephemeralPublicKey: string;
116
+ privateKey: string;
117
+ wallet: any;
118
+ metadata: StealthMetadata;
119
+ }
120
+ /**
121
+ * @notice Configuration for SHIP-03
122
+ */
123
+ export interface SHIP_03_Config {
124
+ /** Enable ERC-5564 compatibility mode */
125
+ erc5564Compatible?: boolean;
126
+ /** Default scheme ID for ERC-5564 */
127
+ defaultSchemeId?: number;
128
+ /** Enable view tag optimization */
129
+ enableViewTag?: boolean;
130
+ /** Auto-scan for stealth addresses */
131
+ autoScan?: boolean;
132
+ }
133
+ /**
134
+ * @title ISHIP_03 - Dual-Key Stealth Addresses
135
+ * @notice Main interface for privacy-preserving stealth addresses
136
+ */
137
+ export interface ISHIP_03 {
138
+ /**
139
+ * @notice Initialize the stealth address system
140
+ * @dev Must be called after SHIP-02 initialization
141
+ * @returns Promise that resolves when initialization is complete
142
+ */
143
+ initialize(): Promise<void>;
144
+ /**
145
+ * @notice Check if system is initialized
146
+ * @returns True if initialized, false otherwise
147
+ */
148
+ isInitialized(): boolean;
149
+ /**
150
+ * @notice Get or generate user's stealth keys (viewing + spending)
151
+ * @dev Keys are deterministically derived from SHIP-00 identity
152
+ * @returns Promise resolving to StealthKeys
153
+ */
154
+ getStealthKeys(): Promise<StealthKeys>;
155
+ /**
156
+ * @notice Get public stealth keys by username (alias)
157
+ * @param username User's alias/username
158
+ * @returns Promise resolving to public keys or null
159
+ */
160
+ getPublicStealthKeysByUsername(username: string): Promise<{
161
+ viewingPublicKey: string;
162
+ spendingPublicKey: string;
163
+ } | null>;
164
+ /**
165
+ * @notice Get public stealth keys for another user by Gun public key
166
+ * @param userPub User's SHIP-00 public key
167
+ * @returns Promise resolving to public keys or null
168
+ */
169
+ getPublicStealthKeys(userPub: string): Promise<{
170
+ viewingPublicKey: string;
171
+ spendingPublicKey: string;
172
+ } | null>;
173
+ /**
174
+ * @notice Search directory for users with published stealth keys
175
+ * @returns Promise resolving to array of users with stealth keys
176
+ */
177
+ searchStealthDirectory(): Promise<Array<{
178
+ username?: string;
179
+ gunPub: string;
180
+ viewingPublicKey: string;
181
+ spendingPublicKey: string;
182
+ timestamp?: number;
183
+ }>>;
184
+ /**
185
+ * @notice Export stealth keys (encrypted)
186
+ * @returns Promise resolving to encrypted keys JSON
187
+ */
188
+ exportStealthKeys(): Promise<string>;
189
+ /**
190
+ * @notice Import stealth keys (encrypted)
191
+ * @param encryptedKeys Encrypted keys JSON
192
+ * @returns Promise that resolves when import is complete
193
+ */
194
+ importStealthKeys(encryptedKeys: string): Promise<void>;
195
+ /**
196
+ * @notice Publish public stealth keys to Gun network
197
+ * @dev Makes your stealth keys discoverable by others
198
+ * @returns Promise that resolves when keys are published
199
+ */
200
+ publishStealthKeys(): Promise<void>;
201
+ /**
202
+ * @notice Generate ephemeral key pair for stealth address creation
203
+ * @returns Promise resolving to EphemeralKeyPair
204
+ */
205
+ generateEphemeralKeyPair(): Promise<EphemeralKeyPair>;
206
+ /**
207
+ * @notice Generate stealth address for a recipient
208
+ * @param recipientViewingKey Recipient's viewing public key
209
+ * @param recipientSpendingKey Recipient's spending public key
210
+ * @param ephemeralPrivateKey Optional ephemeral key (auto-generated if not provided)
211
+ * @returns Promise resolving to StealthAddressResult
212
+ */
213
+ generateStealthAddress(recipientViewingKey: string, recipientSpendingKey: string, ephemeralPrivateKey?: string): Promise<StealthAddressResult>;
214
+ /**
215
+ * @notice Generate multiple stealth addresses (batch)
216
+ * @param recipients Array of recipient key pairs
217
+ * @param ephemeralPrivateKey Optional shared ephemeral key
218
+ * @returns Promise resolving to array of results
219
+ */
220
+ generateMultipleStealthAddresses(recipients: Array<{
221
+ viewingKey: string;
222
+ spendingKey: string;
223
+ }>, ephemeralPrivateKey?: string): Promise<StealthAddressResult[]>;
224
+ /**
225
+ * @notice Open/unlock a stealth address to derive private key
226
+ * @param stealthAddress The stealth address to open
227
+ * @param ephemeralPublicKey Ephemeral public key from announcement
228
+ * @returns Promise resolving to wallet with stealth private key
229
+ */
230
+ openStealthAddress(stealthAddress: string, ephemeralPublicKey: string): Promise<any>;
231
+ /**
232
+ * @notice Check if a stealth address belongs to user
233
+ * @param stealthAddress Address to check
234
+ * @param ephemeralPublicKey Ephemeral public key from announcement
235
+ * @returns Promise resolving to boolean
236
+ */
237
+ isStealthAddressMine(stealthAddress: string, ephemeralPublicKey: string): Promise<boolean>;
238
+ /**
239
+ * @notice Get private key for owned stealth address
240
+ * @param stealthAddress The stealth address
241
+ * @param ephemeralPublicKey Ephemeral public key from announcement
242
+ * @returns Promise resolving to private key hex string
243
+ */
244
+ getStealthPrivateKey(stealthAddress: string, ephemeralPublicKey: string): Promise<string>;
245
+ /**
246
+ * @notice Scan announced stealth addresses for ownership
247
+ * @param announcements Array of announced stealth data
248
+ * @returns Promise resolving to owned stealth addresses
249
+ */
250
+ scanStealthAddresses(announcements: AnnouncedStealth[]): Promise<OwnedStealthAddress[]>;
251
+ /**
252
+ * @notice Quick scan using view tags (optimization)
253
+ * @param announcements Array with view tags
254
+ * @returns Promise resolving to potentially owned addresses (need full verification)
255
+ */
256
+ quickScanWithViewTags(announcements: AnnouncedStealth[]): Promise<AnnouncedStealth[]>;
257
+ /**
258
+ * @notice Create ERC-5564 announcement metadata
259
+ * @param stealthAddress Generated stealth address
260
+ * @param ephemeralPublicKey Ephemeral public key
261
+ * @returns StealthMetadata object
262
+ */
263
+ createAnnouncementMetadata(stealthAddress: string, ephemeralPublicKey: string): StealthMetadata;
264
+ /**
265
+ * @notice Parse announcement from transaction data
266
+ * @param txData Transaction data or logs
267
+ * @returns Promise resolving to AnnouncedStealth or null
268
+ */
269
+ parseAnnouncement(txData: any): Promise<AnnouncedStealth | null>;
270
+ /**
271
+ * @notice Get all owned stealth addresses
272
+ * @returns Promise resolving to array of owned stealth addresses
273
+ */
274
+ getAllOwnedStealthAddresses(): Promise<OwnedStealthAddress[]>;
275
+ /**
276
+ * @notice Clear cache and reset state
277
+ * @returns Promise that resolves when cleared
278
+ */
279
+ clearCache(): Promise<void>;
280
+ /**
281
+ * @notice Verify stealth address was correctly generated
282
+ * @param stealthAddress Address to verify
283
+ * @param ephemeralPublicKey Ephemeral key used
284
+ * @param spendingPublicKey Spending public key
285
+ * @returns Promise resolving to boolean
286
+ */
287
+ verifyStealthAddress(stealthAddress: string, ephemeralPublicKey: string, spendingPublicKey: string): Promise<boolean>;
288
+ }
289
+ export type SHIP_03_Events = {
290
+ stealthKeysGenerated: (keys: StealthKeys) => void;
291
+ stealthAddressGenerated: (result: StealthAddressResult) => void;
292
+ stealthAddressOpened: (wallet: any) => void;
293
+ stealthAddressScanned: (owned: OwnedStealthAddress[]) => void;
294
+ error: (error: Error) => void;
295
+ };
@@ -29,7 +29,12 @@ declare class DataBase {
29
29
  private readonly onAuthCallbacks;
30
30
  private readonly eventEmitter;
31
31
  private _rxjs?;
32
- constructor(gun: IGunInstance, appScope?: string);
32
+ private disableAutoRecall;
33
+ private silent;
34
+ constructor(gun: IGunInstance, appScope?: string, options?: {
35
+ disableAutoRecall?: boolean;
36
+ silent?: boolean;
37
+ });
33
38
  /**
34
39
  * Initialize the GunInstance asynchronously
35
40
  * This method should be called after construction to perform async operations
@@ -329,7 +334,9 @@ declare class DataBase {
329
334
  /**
330
335
  * Recall user session
331
336
  */
332
- recall(): void;
337
+ recall(options?: {
338
+ sessionStorage?: boolean;
339
+ }): void;
333
340
  /**
334
341
  * Leave user session
335
342
  */
@@ -371,7 +378,7 @@ declare class DataBase {
371
378
  */
372
379
  isAuthenticated(): boolean;
373
380
  }
374
- declare const createGun: (config: any) => IGunInstance<any>;
381
+ declare const createGun: (config: any, silent?: boolean) => IGunInstance<any>;
375
382
  export { Gun, DataBase, SEA, RxJS, crypto, GunErrors, derive, createGun };
376
383
  export default Gun;
377
384
  export type { IGunUserInstance, IGunInstance, IGunChain } from "gun/types";
@@ -9,8 +9,15 @@ export * from "./plugins";
9
9
  export * from "./interfaces/shogun";
10
10
  export * from "./config/simplified-config";
11
11
  export type * from "./interfaces/plugin";
12
+ export { SHIP_00 } from "../ship/implementation/SHIP_00";
13
+ export type { ISHIP_00 } from "../ship/interfaces/ISHIP_00";
12
14
  export { SHIP_01 } from "../ship/implementation/SHIP_01";
13
15
  export type { ISHIP_01 } from "../ship/interfaces/ISHIP_01";
16
+ export { SHIP_02 } from "../ship/implementation/SHIP_02";
17
+ export type { ISHIP_02 } from "../ship/interfaces/ISHIP_02";
18
+ export { SHIP_03 } from "../ship/implementation/SHIP_03";
19
+ export type { ISHIP_03 } from "../ship/interfaces/ISHIP_03";
14
20
  export { MessengerCLI } from "../ship/examples/messenger-cli";
21
+ export { WalletCLI } from "../ship/examples/wallet-cli";
15
22
  export type { IGunUserInstance, IGunInstance, GunDataEventData, GunPeerEventData, DeriveOptions, TypedGunOperationResult, TypedAuthResult, };
16
23
  export { Gun, ShogunCore, SEA, RxJS, crypto, derive, GunErrors, DataBase, SimpleGunAPI, QuickStart, quickStart, createSimpleAPI, AutoQuickStart, autoQuickStart, };
@@ -185,6 +185,8 @@ export interface ShogunCoreConfig {
185
185
  plugins?: {
186
186
  autoRegister?: ShogunPlugin[];
187
187
  };
188
+ disableAutoRecall?: boolean;
189
+ silent?: boolean;
188
190
  }
189
191
  export interface ShogunEvents {
190
192
  error: (data: {
@@ -7,10 +7,11 @@ export declare class ShogunStorage {
7
7
  private store;
8
8
  private isTestMode;
9
9
  private useLocalStorage;
10
+ private silent;
10
11
  /**
11
12
  * Initializes storage and loads any existing keypair from localStorage if available
12
13
  */
13
- constructor();
14
+ constructor(silent?: boolean);
14
15
  /**
15
16
  * Gets the stored keypair asynchronously
16
17
  * @returns Promise resolving to the keypair or null if not found
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "shogun-core",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "description": "SHOGUN CORE - Core library for Shogun Ecosystem",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.js",
7
- "types": "./dist/types/index.d.ts",
5
+ "main": "./dist/src/index.js",
6
+ "module": "./dist/src/index.js",
7
+ "types": "./dist/types/src/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/types/index.d.ts",
11
- "import": "./dist/index.js",
12
- "require": "./dist/index.js",
10
+ "types": "./dist/types/src/index.d.ts",
11
+ "import": "./dist/src/index.js",
12
+ "require": "./dist/src/index.js",
13
13
  "browser": "./dist/browser/shogun-core.js",
14
- "default": "./dist/index.js",
15
- "node": "./dist/index.js"
14
+ "default": "./dist/src/index.js",
15
+ "node": "./dist/src/index.js"
16
16
  }
17
17
  },
18
18
  "files": [
@@ -23,6 +23,13 @@
23
23
  "build:cjs": "tsc",
24
24
  "build:browser": "webpack --config webpack.config.cjs",
25
25
  "dev": "tsc --watch",
26
+ "identity": "tsx ship/examples/identity-cli.ts",
27
+ "messenger": "tsx ship/examples/messenger-cli.ts",
28
+ "wallet": "tsx ship/examples/wallet-cli.ts",
29
+ "stealth": "tsx ship/examples/stealth-cli.ts",
30
+ "storage": "tsx ship/examples/storage-cli.ts",
31
+ "ephemeral": "tsx ship/examples/ephemeral-cli.ts",
32
+ "vault": "tsx ship/examples/vault-cli.ts",
26
33
  "format": "prettier --write \"src/**/*.ts\"",
27
34
  "docs": "yarn typedoc --options typedoc.json",
28
35
  "prebuild": "rimraf dist",
@@ -44,22 +51,29 @@
44
51
  "author": "Scobru",
45
52
  "license": "MIT",
46
53
  "dependencies": {
54
+ "@fluidkey/stealth-account-kit": "^1.1.0",
47
55
  "@noble/curves": "^1.9.1",
56
+ "@scure/bip32": "^2.0.1",
48
57
  "assert": "^2.1.0",
49
58
  "base64url": "^3.0.1",
50
59
  "buffer": "^6.0.3",
60
+ "bugoff": "^0.0.9",
51
61
  "constants-browserify": "^1.0.0",
52
62
  "crypto-browserify": "^3.12.0",
53
63
  "ethers": "^6.13.5",
64
+ "form-data": "^4.0.4",
54
65
  "gun": "git+https://github.com/amark/gun.git",
55
66
  "keccak256": "^1.0.6",
56
67
  "nostr-tools": "^2.15.0",
57
68
  "qs": "^6.14.0",
58
69
  "rxjs": "^7.8.2",
70
+ "shogun-ipfs": "file:../shogun-ipfs",
59
71
  "ts-node": "^10.9.2",
60
72
  "url": "^0.11.4",
61
73
  "uuid": "^11.1.0",
62
74
  "vm-browserify": "^1.1.2",
75
+ "webtorrent": "^1.9.7",
76
+ "wrtc": "^0.4.7",
63
77
  "ws": "^8.18.3"
64
78
  },
65
79
  "devDependencies": {