shogun-core 3.2.3 → 3.3.1
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 +12 -0
- package/dist/browser/shogun-core.js +909 -1804
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/{src/gundb → gundb}/db.js +55 -11
- package/dist/{src/index.js → index.js} +1 -7
- package/dist/{src/managers → managers}/CoreInitializer.js +41 -13
- package/dist/{src/storage → storage}/storage.js +22 -9
- package/dist/types/{src/gundb → gundb}/db.d.ts +10 -3
- package/dist/types/{src/index.d.ts → index.d.ts} +0 -3
- package/dist/types/{src/interfaces → interfaces}/shogun.d.ts +2 -0
- package/dist/types/{src/storage → storage}/storage.d.ts +2 -1
- package/dist/types/{src/types → types}/shogun.d.ts +2 -0
- package/package.json +22 -9
- package/dist/browser/_e6ae.shogun-core.js +0 -14
- package/dist/browser/_e6ae.shogun-core.js.map +0 -1
- package/dist/ship/examples/messenger-cli.js +0 -629
- package/dist/ship/implementation/SHIP_01.js +0 -650
- package/dist/ship/interfaces/ISHIP_01.js +0 -71
- package/dist/types/ship/examples/messenger-cli.d.ts +0 -31
- package/dist/types/ship/implementation/SHIP_01.d.ts +0 -113
- package/dist/types/ship/interfaces/ISHIP_01.d.ts +0 -305
- /package/dist/{src/config → config}/simplified-config.js +0 -0
- /package/dist/{src/core.js → core.js} +0 -0
- /package/dist/{src/examples → examples}/api-test.js +0 -0
- /package/dist/{src/examples → examples}/simple-api-test.js +0 -0
- /package/dist/{src/gundb → gundb}/api.js +0 -0
- /package/dist/{src/gundb → gundb}/crypto.js +0 -0
- /package/dist/{src/gundb → gundb}/derive.js +0 -0
- /package/dist/{src/gundb → gundb}/errors.js +0 -0
- /package/dist/{src/gundb → gundb}/index.js +0 -0
- /package/dist/{src/gundb → gundb}/rxjs.js +0 -0
- /package/dist/{src/gundb → gundb}/types.js +0 -0
- /package/dist/{src/interfaces → interfaces}/common.js +0 -0
- /package/dist/{src/interfaces → interfaces}/events.js +0 -0
- /package/dist/{src/interfaces → interfaces}/plugin.js +0 -0
- /package/dist/{src/interfaces → interfaces}/shogun.js +0 -0
- /package/dist/{src/managers → managers}/AuthManager.js +0 -0
- /package/dist/{src/managers → managers}/EventManager.js +0 -0
- /package/dist/{src/managers → managers}/PluginManager.js +0 -0
- /package/dist/{src/migration-test.js → migration-test.js} +0 -0
- /package/dist/{src/plugins → plugins}/base.js +0 -0
- /package/dist/{src/plugins → plugins}/index.js +0 -0
- /package/dist/{src/plugins → plugins}/nostr/index.js +0 -0
- /package/dist/{src/plugins → plugins}/nostr/nostrConnector.js +0 -0
- /package/dist/{src/plugins → plugins}/nostr/nostrConnectorPlugin.js +0 -0
- /package/dist/{src/plugins → plugins}/nostr/nostrSigner.js +0 -0
- /package/dist/{src/plugins → plugins}/nostr/types.js +0 -0
- /package/dist/{src/plugins → plugins}/oauth/index.js +0 -0
- /package/dist/{src/plugins → plugins}/oauth/oauthConnector.js +0 -0
- /package/dist/{src/plugins → plugins}/oauth/oauthPlugin.js +0 -0
- /package/dist/{src/plugins → plugins}/oauth/types.js +0 -0
- /package/dist/{src/plugins → plugins}/web3/index.js +0 -0
- /package/dist/{src/plugins → plugins}/web3/types.js +0 -0
- /package/dist/{src/plugins → plugins}/web3/web3Connector.js +0 -0
- /package/dist/{src/plugins → plugins}/web3/web3ConnectorPlugin.js +0 -0
- /package/dist/{src/plugins → plugins}/web3/web3Signer.js +0 -0
- /package/dist/{src/plugins → plugins}/webauthn/index.js +0 -0
- /package/dist/{src/plugins → plugins}/webauthn/types.js +0 -0
- /package/dist/{src/plugins → plugins}/webauthn/webauthn.js +0 -0
- /package/dist/{src/plugins → plugins}/webauthn/webauthnPlugin.js +0 -0
- /package/dist/{src/plugins → plugins}/webauthn/webauthnSigner.js +0 -0
- /package/dist/types/{src/config → config}/simplified-config.d.ts +0 -0
- /package/dist/types/{src/core.d.ts → core.d.ts} +0 -0
- /package/dist/{src/types → types}/events.js +0 -0
- /package/dist/types/{src/examples → examples}/api-test.d.ts +0 -0
- /package/dist/types/{src/examples → examples}/simple-api-test.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/api.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/crypto.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/derive.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/errors.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/index.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/rxjs.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/types.d.ts +0 -0
- /package/dist/types/{src/interfaces → interfaces}/common.d.ts +0 -0
- /package/dist/types/{src/interfaces → interfaces}/events.d.ts +0 -0
- /package/dist/types/{src/interfaces → interfaces}/plugin.d.ts +0 -0
- /package/dist/types/{src/managers → managers}/AuthManager.d.ts +0 -0
- /package/dist/types/{src/managers → managers}/CoreInitializer.d.ts +0 -0
- /package/dist/types/{src/managers → managers}/EventManager.d.ts +0 -0
- /package/dist/types/{src/managers → managers}/PluginManager.d.ts +0 -0
- /package/dist/types/{src/migration-test.d.ts → migration-test.d.ts} +0 -0
- /package/dist/types/{src/plugins → plugins}/base.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/index.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/nostr/index.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/nostr/nostrConnector.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/nostr/nostrSigner.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/nostr/types.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/oauth/index.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/oauth/oauthConnector.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/oauth/oauthPlugin.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/oauth/types.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/web3/index.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/web3/types.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/web3/web3Connector.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/web3/web3Signer.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/webauthn/index.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/webauthn/types.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/webauthn/webauthn.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/webauthn/webauthnPlugin.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/webauthn/webauthnSigner.d.ts +0 -0
- /package/dist/{src/types → types}/shogun.js +0 -0
- /package/dist/types/{src/types → types}/events.d.ts +0 -0
- /package/dist/types/{src/utils → utils}/errorHandler.d.ts +0 -0
- /package/dist/types/{src/utils → utils}/eventEmitter.d.ts +0 -0
- /package/dist/types/{src/utils → utils}/validation.d.ts +0 -0
- /package/dist/{src/utils → utils}/errorHandler.js +0 -0
- /package/dist/{src/utils → utils}/eventEmitter.js +0 -0
- /package/dist/{src/utils → utils}/validation.js +0 -0
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
*/
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
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
|
-
static readonly NODES: {
|
|
33
|
-
readonly MESSAGES: "messages";
|
|
34
|
-
readonly USERS: "users";
|
|
35
|
-
readonly PUBLIC_KEYS: "publicKeys";
|
|
36
|
-
};
|
|
37
|
-
constructor(shogunConfig: ShogunCoreConfig);
|
|
38
|
-
/**
|
|
39
|
-
* Registra un nuovo utente
|
|
40
|
-
*/
|
|
41
|
-
signup(username: string, password: string): Promise<SignupResult>;
|
|
42
|
-
/**
|
|
43
|
-
* Login con username e password
|
|
44
|
-
*/
|
|
45
|
-
login(username: string, password: string): Promise<AuthResult>;
|
|
46
|
-
/**
|
|
47
|
-
* Login con SEA Key Pair
|
|
48
|
-
*
|
|
49
|
-
* Autenticazione diretta usando un key pair esportato.
|
|
50
|
-
* Utile per:
|
|
51
|
-
* - Recupero account senza password
|
|
52
|
-
* - Portabilità tra dispositivi
|
|
53
|
-
* - Backup dell'identità
|
|
54
|
-
*/
|
|
55
|
-
loginWithPair(seaPair: ISEAPair): Promise<AuthResult>;
|
|
56
|
-
/**
|
|
57
|
-
* Logout
|
|
58
|
-
*/
|
|
59
|
-
logout(): void;
|
|
60
|
-
/**
|
|
61
|
-
* Verifica se l'utente è autenticato
|
|
62
|
-
*/
|
|
63
|
-
isLoggedIn(): boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Salva la chiave pubblica dell'utente su GunDB
|
|
66
|
-
* Questo permette ad altri di trovare la tua chiave per criptare messaggi
|
|
67
|
-
*/
|
|
68
|
-
publishPublicKey(): Promise<OperationResult>;
|
|
69
|
-
/**
|
|
70
|
-
* Invia un messaggio crittografato a un altro utente
|
|
71
|
-
*/
|
|
72
|
-
sendMessage(recipientUsername: string, message: string): Promise<SendMessageResult>;
|
|
73
|
-
/**
|
|
74
|
-
* Ottiene la chiave pubblica di un utente da GunDB
|
|
75
|
-
*/
|
|
76
|
-
private getRecipientPublicKey;
|
|
77
|
-
/**
|
|
78
|
-
* Ascolta messaggi crittografati in arrivo su GunDB
|
|
79
|
-
*/
|
|
80
|
-
listenForMessages(onMessage: (message: DecryptedMessage) => void): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Decripta un messaggio usando SEA.secret + SEA.decrypt (ECDH)
|
|
83
|
-
*/
|
|
84
|
-
private decryptMessage;
|
|
85
|
-
/**
|
|
86
|
-
* Ottiene la chiave pubblica di un utente dalla sua pub key
|
|
87
|
-
*/
|
|
88
|
-
private getPublicKeyByPub;
|
|
89
|
-
/**
|
|
90
|
-
* Recupera lo storico dei messaggi crittografati con un utente
|
|
91
|
-
*/
|
|
92
|
-
getMessageHistory(withUsername: string): Promise<Array<{
|
|
93
|
-
from: string;
|
|
94
|
-
to: string;
|
|
95
|
-
content: string;
|
|
96
|
-
timestamp: number;
|
|
97
|
-
}>>;
|
|
98
|
-
/**
|
|
99
|
-
* Converte la chiave pubblica di GunDB in address Ethereum
|
|
100
|
-
* Usa la chiave privata SEA come seed per derivazione deterministica
|
|
101
|
-
*
|
|
102
|
-
* Questo garantisce che:
|
|
103
|
-
* - Stesso SEA pair → stesso address Ethereum
|
|
104
|
-
* - Derivazione cryptografica sicura
|
|
105
|
-
* - Identità unificata tra GunDB e blockchain
|
|
106
|
-
*/
|
|
107
|
-
deriveEthereumAddress(publicKey?: string): Promise<string>;
|
|
108
|
-
/**
|
|
109
|
-
* Genera ID messaggio univoco
|
|
110
|
-
*/
|
|
111
|
-
private generateMessageId;
|
|
112
|
-
}
|
|
113
|
-
export { SHIP_01 };
|
|
@@ -1,305 +0,0 @@
|
|
|
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
|
-
*/
|
|
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
|