shogun-core 3.1.0 → 3.2.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 (109) hide show
  1. package/dist/browser/_e6ae.shogun-core.js +14 -0
  2. package/dist/browser/_e6ae.shogun-core.js.map +1 -0
  3. package/dist/browser/shogun-core.js +1685 -6
  4. package/dist/browser/shogun-core.js.map +1 -1
  5. package/dist/ship/examples/messenger-cli.js +632 -0
  6. package/dist/ship/implementation/SHIP_01.js +803 -0
  7. package/dist/ship/interfaces/ISHIP_01.js +71 -0
  8. package/dist/{gundb → src/gundb}/db.js +2 -2
  9. package/dist/{index.js → src/index.js} +7 -2
  10. package/dist/types/ship/examples/messenger-cli.d.ts +31 -0
  11. package/dist/types/ship/implementation/SHIP_01.d.ts +108 -0
  12. package/dist/types/ship/interfaces/ISHIP_01.d.ts +305 -0
  13. package/dist/types/{index.d.ts → src/index.d.ts} +4 -1
  14. package/package.json +2 -1
  15. /package/dist/{config → src/config}/simplified-config.js +0 -0
  16. /package/dist/{core.js → src/core.js} +0 -0
  17. /package/dist/{examples → src/examples}/api-test.js +0 -0
  18. /package/dist/{examples → src/examples}/simple-api-test.js +0 -0
  19. /package/dist/{gundb → src/gundb}/api.js +0 -0
  20. /package/dist/{gundb → src/gundb}/crypto.js +0 -0
  21. /package/dist/{gundb → src/gundb}/derive.js +0 -0
  22. /package/dist/{gundb → src/gundb}/errors.js +0 -0
  23. /package/dist/{gundb → src/gundb}/index.js +0 -0
  24. /package/dist/{gundb → src/gundb}/rxjs.js +0 -0
  25. /package/dist/{gundb → src/gundb}/types.js +0 -0
  26. /package/dist/{interfaces → src/interfaces}/common.js +0 -0
  27. /package/dist/{interfaces → src/interfaces}/events.js +0 -0
  28. /package/dist/{interfaces → src/interfaces}/plugin.js +0 -0
  29. /package/dist/{interfaces → src/interfaces}/shogun.js +0 -0
  30. /package/dist/{managers → src/managers}/AuthManager.js +0 -0
  31. /package/dist/{managers → src/managers}/CoreInitializer.js +0 -0
  32. /package/dist/{managers → src/managers}/EventManager.js +0 -0
  33. /package/dist/{managers → src/managers}/PluginManager.js +0 -0
  34. /package/dist/{migration-test.js → src/migration-test.js} +0 -0
  35. /package/dist/{plugins → src/plugins}/base.js +0 -0
  36. /package/dist/{plugins → src/plugins}/index.js +0 -0
  37. /package/dist/{plugins → src/plugins}/nostr/index.js +0 -0
  38. /package/dist/{plugins → src/plugins}/nostr/nostrConnector.js +0 -0
  39. /package/dist/{plugins → src/plugins}/nostr/nostrConnectorPlugin.js +0 -0
  40. /package/dist/{plugins → src/plugins}/nostr/nostrSigner.js +0 -0
  41. /package/dist/{plugins → src/plugins}/nostr/types.js +0 -0
  42. /package/dist/{plugins → src/plugins}/oauth/index.js +0 -0
  43. /package/dist/{plugins → src/plugins}/oauth/oauthConnector.js +0 -0
  44. /package/dist/{plugins → src/plugins}/oauth/oauthPlugin.js +0 -0
  45. /package/dist/{plugins → src/plugins}/oauth/types.js +0 -0
  46. /package/dist/{plugins → src/plugins}/web3/index.js +0 -0
  47. /package/dist/{plugins → src/plugins}/web3/types.js +0 -0
  48. /package/dist/{plugins → src/plugins}/web3/web3Connector.js +0 -0
  49. /package/dist/{plugins → src/plugins}/web3/web3ConnectorPlugin.js +0 -0
  50. /package/dist/{plugins → src/plugins}/web3/web3Signer.js +0 -0
  51. /package/dist/{plugins → src/plugins}/webauthn/index.js +0 -0
  52. /package/dist/{plugins → src/plugins}/webauthn/types.js +0 -0
  53. /package/dist/{plugins → src/plugins}/webauthn/webauthn.js +0 -0
  54. /package/dist/{plugins → src/plugins}/webauthn/webauthnPlugin.js +0 -0
  55. /package/dist/{plugins → src/plugins}/webauthn/webauthnSigner.js +0 -0
  56. /package/dist/{storage → src/storage}/storage.js +0 -0
  57. /package/dist/{types → src/types}/events.js +0 -0
  58. /package/dist/{types → src/types}/shogun.js +0 -0
  59. /package/dist/{utils → src/utils}/errorHandler.js +0 -0
  60. /package/dist/{utils → src/utils}/eventEmitter.js +0 -0
  61. /package/dist/{utils → src/utils}/validation.js +0 -0
  62. /package/dist/types/{config → src/config}/simplified-config.d.ts +0 -0
  63. /package/dist/types/{core.d.ts → src/core.d.ts} +0 -0
  64. /package/dist/types/{examples → src/examples}/api-test.d.ts +0 -0
  65. /package/dist/types/{examples → src/examples}/simple-api-test.d.ts +0 -0
  66. /package/dist/types/{gundb → src/gundb}/api.d.ts +0 -0
  67. /package/dist/types/{gundb → src/gundb}/crypto.d.ts +0 -0
  68. /package/dist/types/{gundb → src/gundb}/db.d.ts +0 -0
  69. /package/dist/types/{gundb → src/gundb}/derive.d.ts +0 -0
  70. /package/dist/types/{gundb → src/gundb}/errors.d.ts +0 -0
  71. /package/dist/types/{gundb → src/gundb}/index.d.ts +0 -0
  72. /package/dist/types/{gundb → src/gundb}/rxjs.d.ts +0 -0
  73. /package/dist/types/{gundb → src/gundb}/types.d.ts +0 -0
  74. /package/dist/types/{interfaces → src/interfaces}/common.d.ts +0 -0
  75. /package/dist/types/{interfaces → src/interfaces}/events.d.ts +0 -0
  76. /package/dist/types/{interfaces → src/interfaces}/plugin.d.ts +0 -0
  77. /package/dist/types/{interfaces → src/interfaces}/shogun.d.ts +0 -0
  78. /package/dist/types/{managers → src/managers}/AuthManager.d.ts +0 -0
  79. /package/dist/types/{managers → src/managers}/CoreInitializer.d.ts +0 -0
  80. /package/dist/types/{managers → src/managers}/EventManager.d.ts +0 -0
  81. /package/dist/types/{managers → src/managers}/PluginManager.d.ts +0 -0
  82. /package/dist/types/{migration-test.d.ts → src/migration-test.d.ts} +0 -0
  83. /package/dist/types/{plugins → src/plugins}/base.d.ts +0 -0
  84. /package/dist/types/{plugins → src/plugins}/index.d.ts +0 -0
  85. /package/dist/types/{plugins → src/plugins}/nostr/index.d.ts +0 -0
  86. /package/dist/types/{plugins → src/plugins}/nostr/nostrConnector.d.ts +0 -0
  87. /package/dist/types/{plugins → src/plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
  88. /package/dist/types/{plugins → src/plugins}/nostr/nostrSigner.d.ts +0 -0
  89. /package/dist/types/{plugins → src/plugins}/nostr/types.d.ts +0 -0
  90. /package/dist/types/{plugins → src/plugins}/oauth/index.d.ts +0 -0
  91. /package/dist/types/{plugins → src/plugins}/oauth/oauthConnector.d.ts +0 -0
  92. /package/dist/types/{plugins → src/plugins}/oauth/oauthPlugin.d.ts +0 -0
  93. /package/dist/types/{plugins → src/plugins}/oauth/types.d.ts +0 -0
  94. /package/dist/types/{plugins → src/plugins}/web3/index.d.ts +0 -0
  95. /package/dist/types/{plugins → src/plugins}/web3/types.d.ts +0 -0
  96. /package/dist/types/{plugins → src/plugins}/web3/web3Connector.d.ts +0 -0
  97. /package/dist/types/{plugins → src/plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
  98. /package/dist/types/{plugins → src/plugins}/web3/web3Signer.d.ts +0 -0
  99. /package/dist/types/{plugins → src/plugins}/webauthn/index.d.ts +0 -0
  100. /package/dist/types/{plugins → src/plugins}/webauthn/types.d.ts +0 -0
  101. /package/dist/types/{plugins → src/plugins}/webauthn/webauthn.d.ts +0 -0
  102. /package/dist/types/{plugins → src/plugins}/webauthn/webauthnPlugin.d.ts +0 -0
  103. /package/dist/types/{plugins → src/plugins}/webauthn/webauthnSigner.d.ts +0 -0
  104. /package/dist/types/{storage → src/storage}/storage.d.ts +0 -0
  105. /package/dist/types/{types → src/types}/events.d.ts +0 -0
  106. /package/dist/types/{types → src/types}/shogun.d.ts +0 -0
  107. /package/dist/types/{utils → src/utils}/errorHandler.d.ts +0 -0
  108. /package/dist/types/{utils → src/utils}/eventEmitter.d.ts +0 -0
  109. /package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * Shogun Messaging Protocol Interface
4
+ *
5
+ * @title ISHIP_01 - Decentralized Encrypted Messaging
6
+ * @notice Interface for decentralized encrypted messaging on GunDB
7
+ *
8
+ * ## Abstract
9
+ *
10
+ * This standard defines an interface for decentralized messaging that allows:
11
+ * - Username/password authentication
12
+ * - Public key publication on GunDB
13
+ * - End-to-end encrypted message sending (ECDH)
14
+ * - Real-time message reception
15
+ * - Decentralized message history
16
+ *
17
+ * ## Specification
18
+ *
19
+ * Based on:
20
+ * - GunDB for P2P storage
21
+ * - SEA (Security, Encryption, Authorization) for cryptography
22
+ * - ECDH (Elliptic Curve Diffie-Hellman) for key agreement
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ // ============================================================================
26
+ // IMPLEMENTATION EXAMPLE
27
+ // ============================================================================
28
+ /**
29
+ * Example of how to implement ISHIP_01
30
+ *
31
+ * ```typescript
32
+ * class SecureMessagingApp implements ISHIP_01 {
33
+ * private shogun: ShogunCore;
34
+ *
35
+ * constructor(config: MessagingConfig) {
36
+ * this.shogun = new ShogunCore(config);
37
+ * }
38
+ *
39
+ * async signup(username: string, password: string): Promise<SignupResult> {
40
+ * const result = await this.shogun.signUp(username, password);
41
+ * return {
42
+ * success: result.success,
43
+ * userPub: result.pub,
44
+ * derivedAddress: this.pubKeyToAddress(result.pub || "")
45
+ * };
46
+ * }
47
+ *
48
+ * async sendMessage(recipientUsername: string, message: string): Promise<SendMessageResult> {
49
+ * // 1. Get recipient's epub
50
+ * const recipientKey = await this.getRecipientPublicKey(recipientUsername);
51
+ *
52
+ * // 2. Encrypt with ECDH
53
+ * const encrypted = await this.shogun.db.crypto.encFor(
54
+ * message,
55
+ * this.shogun.db.user.is, // sender
56
+ * { epub: recipientKey.epub } // receiver
57
+ * );
58
+ *
59
+ * // 3. Save to GunDB
60
+ * await this.shogun.db.user.get('messages/...').put({
61
+ * content: encrypted,
62
+ * from: this.shogun.db.user.is.pub,
63
+ * to: recipientUsername,
64
+ * timestamp: Date.now().toString()
65
+ * });
66
+ *
67
+ * return { success: true, messageId: '...' };
68
+ * }
69
+ * }
70
+ * ```
71
+ */
@@ -1085,8 +1085,8 @@ class DataBase {
1085
1085
  username: username,
1086
1086
  userPub: userPub,
1087
1087
  epub: epub,
1088
- registeredAt: Date.now(),
1089
- lastSeen: Date.now(),
1088
+ registeredAt: Date.now().toString(),
1089
+ lastSeen: Date.now().toString(),
1090
1090
  };
1091
1091
  const ack = await this.node
1092
1092
  .get("users")
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.autoQuickStart = exports.AutoQuickStart = exports.createSimpleAPI = exports.quickStart = exports.QuickStart = exports.SimpleGunAPI = exports.DataBase = exports.GunErrors = exports.derive = exports.crypto = exports.RxJS = exports.SEA = exports.ShogunCore = exports.Gun = void 0;
20
+ exports.autoQuickStart = exports.AutoQuickStart = exports.createSimpleAPI = exports.quickStart = exports.QuickStart = exports.SimpleGunAPI = exports.DataBase = exports.GunErrors = exports.derive = exports.crypto = exports.RxJS = exports.SEA = exports.ShogunCore = exports.Gun = exports.MessengerCLI = exports.SHIP_01 = void 0;
21
21
  const core_1 = require("./core");
22
22
  Object.defineProperty(exports, "ShogunCore", { enumerable: true, get: function () { return core_1.ShogunCore; } });
23
23
  const db_1 = require("./gundb/db");
@@ -41,5 +41,10 @@ exports.Gun = db_3.default;
41
41
  __exportStar(require("./utils/errorHandler"), exports);
42
42
  __exportStar(require("./plugins"), exports);
43
43
  __exportStar(require("./interfaces/shogun"), exports);
44
- // Export simplified configuration
45
44
  __exportStar(require("./config/simplified-config"), exports);
45
+ var SHIP_01_1 = require("../ship/implementation/SHIP_01");
46
+ Object.defineProperty(exports, "SHIP_01", { enumerable: true, get: function () { return SHIP_01_1.SHIP_01; } });
47
+ // Export MessengerCLI only in Node.js environment (not browser)
48
+ // This prevents "readline is not a function" errors in browser builds
49
+ var messenger_cli_1 = require("../ship/examples/messenger-cli");
50
+ Object.defineProperty(exports, "MessengerCLI", { enumerable: true, get: function () { return messenger_cli_1.MessengerCLI; } });
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Shogun Chat - CLI Interface
4
+ *
5
+ * End-to-end encrypted decentralized chat
6
+ * Simple and functional CLI interface
7
+ */
8
+ export declare class MessengerCLI {
9
+ private app;
10
+ private rl;
11
+ private currentUser;
12
+ private recipient;
13
+ private derivedAddress;
14
+ private isAuthenticated;
15
+ constructor();
16
+ private setupHandlers;
17
+ private withTimeout;
18
+ login(username: string, password: string): Promise<boolean>;
19
+ private sendMessage;
20
+ private onMessageReceived;
21
+ private exportKeyPair;
22
+ private importKeyPair;
23
+ private loginWithPair;
24
+ private wipeAllMessages;
25
+ private handleCommand;
26
+ private showHelp;
27
+ private showStatus;
28
+ private showHeader;
29
+ private updatePrompt;
30
+ start(): Promise<void>;
31
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Esempio Pratico: Messaggistica Decentralizzata con Shogun Core
3
+ *
4
+ * Questo esempio mostra come creare un sistema di messaggistica sicuro usando:
5
+ * - Shogun Core per autenticazione (username/password)
6
+ * - GunDB per storage decentralizzato P2P
7
+ * - SEA (Security, Encryption, Authorization) per crittografia
8
+ *
9
+ * Vantaggi:
10
+ * ✅ Completamente decentralizzato (no server centrale)
11
+ * ✅ Zero costi (no blockchain, no gas fees)
12
+ * ✅ Real-time messaging
13
+ * ✅ Offline-first
14
+ * ✅ End-to-end encryption
15
+ *
16
+ * Note sull'ERC7627:
17
+ * L'EIP era un template concettuale. Questo esempio implementa
18
+ * solo la parte GunDB/Shogun Core senza interazione blockchain.
19
+ * La funzione deriveEthereumAddress() rimane come utility per derivare
20
+ * un address Ethereum dalla chiave GunDB se necessario in futuro.
21
+ */
22
+ import type { ISHIP_01, SignupResult, AuthResult, SendMessageResult, DecryptedMessage, OperationResult } from "../interfaces/ISHIP_01";
23
+ import { ShogunCoreConfig } from "../../src/interfaces/shogun";
24
+ import { ISEAPair } from "../../src/types/shogun";
25
+ /**
26
+ * Classe per messaggistica sicura con Shogun Core
27
+ * Implementa l'interfaccia ISHIP_01
28
+ * Usa solo GunDB per storage decentralizzato (no blockchain)
29
+ */
30
+ declare class SHIP_01 implements ISHIP_01 {
31
+ private shogun;
32
+ constructor(shogunConfig: ShogunCoreConfig);
33
+ /**
34
+ * Registra un nuovo utente
35
+ */
36
+ signup(username: string, password: string): Promise<SignupResult>;
37
+ /**
38
+ * Login con username e password
39
+ */
40
+ login(username: string, password: string): Promise<AuthResult>;
41
+ /**
42
+ * Login con SEA Key Pair
43
+ *
44
+ * Autenticazione diretta usando un key pair esportato.
45
+ * Utile per:
46
+ * - Recupero account senza password
47
+ * - Portabilità tra dispositivi
48
+ * - Backup dell'identità
49
+ */
50
+ loginWithPair(seaPair: ISEAPair): Promise<AuthResult>;
51
+ /**
52
+ * Logout
53
+ */
54
+ logout(): void;
55
+ /**
56
+ * Verifica se l'utente è autenticato
57
+ */
58
+ isLoggedIn(): boolean;
59
+ /**
60
+ * Salva la chiave pubblica dell'utente su GunDB
61
+ * Questo permette ad altri di trovare la tua chiave per criptare messaggi
62
+ */
63
+ publishPublicKey(): Promise<OperationResult>;
64
+ /**
65
+ * Invia un messaggio crittografato a un altro utente
66
+ */
67
+ sendMessage(recipientUsername: string, message: string): Promise<SendMessageResult>;
68
+ /**
69
+ * Ottiene la chiave pubblica di un utente da GunDB
70
+ */
71
+ private getRecipientPublicKey;
72
+ /**
73
+ * Ascolta messaggi crittografati in arrivo su GunDB
74
+ */
75
+ listenForMessages(onMessage: (message: DecryptedMessage) => void): Promise<void>;
76
+ /**
77
+ * Decripta un messaggio usando SEA.secret + SEA.decrypt (ECDH)
78
+ */
79
+ private decryptMessage;
80
+ /**
81
+ * Ottiene la chiave pubblica di un utente dalla sua pub key
82
+ */
83
+ private getPublicKeyByPub;
84
+ /**
85
+ * Recupera lo storico dei messaggi crittografati con un utente
86
+ */
87
+ getMessageHistory(withUsername: string): Promise<Array<{
88
+ from: string;
89
+ to: string;
90
+ content: string;
91
+ timestamp: number;
92
+ }>>;
93
+ /**
94
+ * Converte la chiave pubblica di GunDB in address Ethereum
95
+ * Usa la chiave privata SEA come seed per derivazione deterministica
96
+ *
97
+ * Questo garantisce che:
98
+ * - Stesso SEA pair → stesso address Ethereum
99
+ * - Derivazione cryptografica sicura
100
+ * - Identità unificata tra GunDB e blockchain
101
+ */
102
+ deriveEthereumAddress(publicKey?: string): Promise<string>;
103
+ /**
104
+ * Genera ID messaggio univoco
105
+ */
106
+ private generateMessageId;
107
+ }
108
+ export { SHIP_01 };
@@ -0,0 +1,305 @@
1
+ /**
2
+ * Shogun Messaging Protocol Interface
3
+ *
4
+ * @title ISHIP_01 - Decentralized Encrypted Messaging
5
+ * @notice Interface for decentralized encrypted messaging on GunDB
6
+ *
7
+ * ## Abstract
8
+ *
9
+ * This standard defines an interface for decentralized messaging that allows:
10
+ * - Username/password authentication
11
+ * - Public key publication on GunDB
12
+ * - End-to-end encrypted message sending (ECDH)
13
+ * - Real-time message reception
14
+ * - Decentralized message history
15
+ *
16
+ * ## Specification
17
+ *
18
+ * Based on:
19
+ * - GunDB for P2P storage
20
+ * - SEA (Security, Encryption, Authorization) for cryptography
21
+ * - ECDH (Elliptic Curve Diffie-Hellman) for key agreement
22
+ */
23
+ /**
24
+ * @notice Authentication result
25
+ */
26
+ export interface AuthResult {
27
+ success: boolean;
28
+ userPub?: string;
29
+ derivedAddress?: string;
30
+ error?: string;
31
+ }
32
+ /**
33
+ * @notice Signup result
34
+ */
35
+ export interface SignupResult {
36
+ success: boolean;
37
+ userPub?: string;
38
+ derivedAddress?: string;
39
+ error?: string;
40
+ }
41
+ /**
42
+ * @notice Message structure
43
+ */
44
+ export interface Message {
45
+ from: string;
46
+ to: string;
47
+ content: string;
48
+ timestamp: string;
49
+ messageId: string;
50
+ }
51
+ /**
52
+ * @notice Decrypted message structure (for UI)
53
+ */
54
+ export interface DecryptedMessage {
55
+ from: string;
56
+ content: string;
57
+ timestamp: number;
58
+ }
59
+ /**
60
+ * @notice User public key
61
+ */
62
+ export interface UserPublicKey {
63
+ pub: string;
64
+ epub: string;
65
+ algorithm: string;
66
+ timestamp: string;
67
+ }
68
+ /**
69
+ * @notice Operation result
70
+ */
71
+ export interface OperationResult {
72
+ success: boolean;
73
+ error?: string;
74
+ }
75
+ /**
76
+ * @notice Send message result
77
+ */
78
+ export interface SendMessageResult extends OperationResult {
79
+ messageId?: string;
80
+ }
81
+ /**
82
+ * @title ISHIP_01 - Decentralized Messaging
83
+ * @notice Main interface for the messaging system
84
+ */
85
+ export interface ISHIP_01 {
86
+ /**
87
+ * @notice Register a new user
88
+ * @param username Desired username
89
+ * @param password Password
90
+ * @return Result with userPub and derivedAddress
91
+ */
92
+ signup(username: string, password: string): Promise<SignupResult>;
93
+ /**
94
+ * @notice Login with username and password
95
+ * @param username Username
96
+ * @param password Password
97
+ * @return Result with userPub and derivedAddress
98
+ */
99
+ login(username: string, password: string): Promise<AuthResult>;
100
+ /**
101
+ * @notice Logout current user
102
+ */
103
+ logout(): void;
104
+ /**
105
+ * @notice Check if user is authenticated
106
+ * @return True if authenticated
107
+ */
108
+ isLoggedIn(): boolean;
109
+ /**
110
+ * @notice Publish public key on GunDB
111
+ * @dev Allows others to find your key to encrypt messages
112
+ * @return Operation result
113
+ */
114
+ publishPublicKey(): Promise<OperationResult>;
115
+ /**
116
+ * @notice Send encrypted message
117
+ * @dev Uses ECDH to derive shared secret, then AES-GCM for encryption
118
+ * @param recipientUsername Recipient's username
119
+ * @param message Plain text message content
120
+ * @return Result with messageId
121
+ *
122
+ * Flow:
123
+ * 1. Retrieve recipient's epub from GunDB
124
+ * 2. SEA.secret(recipient.epub, sender.pair) → shared_secret
125
+ * 3. SEA.encrypt(message, shared_secret) → encrypted
126
+ * 4. Save encrypted on GunDB
127
+ */
128
+ sendMessage(recipientUsername: string, message: string): Promise<SendMessageResult>;
129
+ /**
130
+ * @notice Listen for incoming messages in real-time
131
+ * @dev Automatically decrypts received messages
132
+ * @param onMessage Callback called for each message
133
+ *
134
+ * Decryption flow:
135
+ * 1. Receive encrypted message from GunDB
136
+ * 2. Retrieve sender's epub
137
+ * 3. SEA.secret(sender.epub, receiver.pair) → shared_secret
138
+ * 4. SEA.decrypt(encrypted, shared_secret) → message
139
+ * 5. Call callback with decrypted message
140
+ */
141
+ listenForMessages(onMessage: (message: DecryptedMessage) => void): Promise<void>;
142
+ /**
143
+ * @notice Retrieve message history with a user
144
+ * @dev Decrypts all messages in history
145
+ * @param withUsername Username of the other user
146
+ * @return Array of decrypted messages sorted by timestamp
147
+ */
148
+ getMessageHistory(withUsername: string): Promise<Array<{
149
+ from: string;
150
+ to: string;
151
+ content: string;
152
+ timestamp: number;
153
+ }>>;
154
+ }
155
+ /**
156
+ * @notice Interface for GunDB → Ethereum identity conversion
157
+ */
158
+ export interface IAddressDerivation {
159
+ /**
160
+ * @notice Convert GunDB public key to Ethereum address
161
+ * @param publicKey Public key in base64 format (GunDB)
162
+ * @return Ethereum address with checksum
163
+ *
164
+ * Process:
165
+ * 1. Decode from base64 (GunDB format)
166
+ * 2. Convert to bytes
167
+ * 3. keccak256(bytes)
168
+ * 4. Take last 20 bytes
169
+ * 5. Apply EIP-55 checksum
170
+ */
171
+ pubKeyToAddress(publicKey: string): string;
172
+ }
173
+ /**
174
+ * @notice Messaging system configuration
175
+ */
176
+ export interface MessagingConfig {
177
+ /**
178
+ * @notice GunDB peers
179
+ */
180
+ peers: string[];
181
+ /**
182
+ * @notice Application scope
183
+ */
184
+ scope: string;
185
+ /**
186
+ * @notice Operation timeout (ms)
187
+ */
188
+ timeout?: number;
189
+ /**
190
+ * @notice Enable debug logging
191
+ */
192
+ debug?: boolean;
193
+ }
194
+ /**
195
+ * @notice Cryptographic functions provided by Shogun Core
196
+ * @dev Wrapper for GunDB SEA
197
+ */
198
+ export interface ISEACrypto {
199
+ /**
200
+ * @notice Encrypt data for a recipient (ECDH)
201
+ * @param data Data to encrypt
202
+ * @param senderPair Sender's key pair
203
+ * @param receiverEpub Recipient's encryption public key
204
+ * @return Encrypted data
205
+ */
206
+ encFor(data: any, senderPair: {
207
+ pub: string;
208
+ priv: string;
209
+ epub: string;
210
+ epriv: string;
211
+ }, receiverEpub: {
212
+ epub: string;
213
+ }): Promise<string>;
214
+ /**
215
+ * @notice Decrypt data from a sender (ECDH)
216
+ * @param encryptedData Encrypted data
217
+ * @param senderEpub Sender's encryption public key
218
+ * @param receiverPair Recipient's key pair
219
+ * @return Decrypted data
220
+ */
221
+ decFrom(encryptedData: string, senderEpub: {
222
+ epub: string;
223
+ }, receiverPair: {
224
+ pub: string;
225
+ priv: string;
226
+ epub: string;
227
+ epriv: string;
228
+ }): Promise<any>;
229
+ /**
230
+ * @notice Derive shared secret between two parties (ECDH)
231
+ * @param epub Other party's encryption public key
232
+ * @param pair Own key pair
233
+ * @return Shared secret
234
+ */
235
+ secret(epub: string, pair: {
236
+ pub: string;
237
+ priv: string;
238
+ epub: string;
239
+ epriv: string;
240
+ }): Promise<string>;
241
+ /**
242
+ * @notice Encrypt with symmetric key
243
+ * @param data Data to encrypt
244
+ * @param key Symmetric key
245
+ * @return Encrypted data
246
+ */
247
+ encrypt(data: any, key: string): Promise<string>;
248
+ /**
249
+ * @notice Decrypt with symmetric key
250
+ * @param encryptedData Encrypted data
251
+ * @param key Symmetric key
252
+ * @return Decrypted data
253
+ */
254
+ decrypt(encryptedData: string, key: string): Promise<any>;
255
+ /**
256
+ * @notice Hash text with SHA-256
257
+ * @param text Text to hash
258
+ * @return Hash
259
+ */
260
+ hashText(text: string): Promise<string>;
261
+ }
262
+ /**
263
+ * Example of how to implement ISHIP_01
264
+ *
265
+ * ```typescript
266
+ * class SecureMessagingApp implements ISHIP_01 {
267
+ * private shogun: ShogunCore;
268
+ *
269
+ * constructor(config: MessagingConfig) {
270
+ * this.shogun = new ShogunCore(config);
271
+ * }
272
+ *
273
+ * async signup(username: string, password: string): Promise<SignupResult> {
274
+ * const result = await this.shogun.signUp(username, password);
275
+ * return {
276
+ * success: result.success,
277
+ * userPub: result.pub,
278
+ * derivedAddress: this.pubKeyToAddress(result.pub || "")
279
+ * };
280
+ * }
281
+ *
282
+ * async sendMessage(recipientUsername: string, message: string): Promise<SendMessageResult> {
283
+ * // 1. Get recipient's epub
284
+ * const recipientKey = await this.getRecipientPublicKey(recipientUsername);
285
+ *
286
+ * // 2. Encrypt with ECDH
287
+ * const encrypted = await this.shogun.db.crypto.encFor(
288
+ * message,
289
+ * this.shogun.db.user.is, // sender
290
+ * { epub: recipientKey.epub } // receiver
291
+ * );
292
+ *
293
+ * // 3. Save to GunDB
294
+ * await this.shogun.db.user.get('messages/...').put({
295
+ * content: encrypted,
296
+ * from: this.shogun.db.user.is.pub,
297
+ * to: recipientUsername,
298
+ * timestamp: Date.now().toString()
299
+ * });
300
+ *
301
+ * return { success: true, messageId: '...' };
302
+ * }
303
+ * }
304
+ * ```
305
+ */
@@ -7,7 +7,10 @@ import Gun from "./gundb/db";
7
7
  export * from "./utils/errorHandler";
8
8
  export * from "./plugins";
9
9
  export * from "./interfaces/shogun";
10
- export type * from "./interfaces/plugin";
11
10
  export * from "./config/simplified-config";
11
+ export type * from "./interfaces/plugin";
12
+ export { SHIP_01 } from "../ship/implementation/SHIP_01";
13
+ export type { ISHIP_01 } from "../ship/interfaces/ISHIP_01";
14
+ export { MessengerCLI } from "../ship/examples/messenger-cli";
12
15
  export type { IGunUserInstance, IGunInstance, GunDataEventData, GunPeerEventData, DeriveOptions, TypedGunOperationResult, TypedAuthResult, };
13
16
  export { Gun, ShogunCore, SEA, RxJS, crypto, derive, GunErrors, DataBase, SimpleGunAPI, QuickStart, quickStart, createSimpleAPI, AutoQuickStart, autoQuickStart, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shogun-core",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "SHOGUN CORE - Core library for Shogun Ecosystem",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -82,6 +82,7 @@
82
82
  "stream-browserify": "^3.0.0",
83
83
  "ts-jest": "^29.3.2",
84
84
  "ts-loader": "^9.5.1",
85
+ "tsx": "^4.20.6",
85
86
  "typedoc": "^0.27.9",
86
87
  "typescript": "^5.3.3",
87
88
  "util": "^0.12.5",
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