shogun-core 5.2.0 → 5.2.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.
Files changed (185) hide show
  1. package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js +1220 -0
  2. package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js.map +1 -0
  3. package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js +844 -0
  4. package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js.map +1 -0
  5. package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js +2335 -0
  6. package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js.map +1 -0
  7. package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js +999 -0
  8. package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js.map +1 -0
  9. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +1651 -0
  10. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +1 -0
  11. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js +825 -0
  12. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js.map +1 -0
  13. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js +508 -0
  14. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js.map +1 -0
  15. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +747 -0
  16. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -0
  17. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +1608 -0
  18. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +1 -0
  19. package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js +2117 -0
  20. package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js.map +1 -0
  21. package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js +86 -0
  22. package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js.map +1 -0
  23. package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js +539 -0
  24. package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js.map +1 -0
  25. package/dist/browser/shogun-core.js +160386 -0
  26. package/dist/browser/shogun-core.js.map +1 -0
  27. package/dist/config/simplified-config.js +236 -0
  28. package/dist/core.js +329 -0
  29. package/dist/crypto/asymmetric.js +99 -0
  30. package/dist/crypto/double-ratchet.js +370 -0
  31. package/dist/crypto/file-encryption.js +213 -0
  32. package/dist/crypto/hashing.js +87 -0
  33. package/dist/crypto/index.js +34 -0
  34. package/dist/crypto/mls-codec.js +202 -0
  35. package/dist/crypto/mls.js +550 -0
  36. package/dist/crypto/pgp.js +390 -0
  37. package/dist/crypto/random-generation.js +341 -0
  38. package/dist/crypto/sframe.js +350 -0
  39. package/dist/crypto/signal-protocol.js +376 -0
  40. package/dist/crypto/symmetric.js +91 -0
  41. package/dist/crypto/types.js +2 -0
  42. package/dist/crypto/utils.js +140 -0
  43. package/dist/examples/auth-test.js +253 -0
  44. package/dist/examples/crypto-identity-example.js +151 -0
  45. package/dist/examples/crypto-working-test.js +83 -0
  46. package/dist/examples/double-ratchet-test.js +155 -0
  47. package/dist/examples/mls-advanced-example.js +294 -0
  48. package/dist/examples/mls-sframe-test.js +304 -0
  49. package/dist/examples/pgp-example.js +200 -0
  50. package/dist/examples/quick-auth-test.js +61 -0
  51. package/dist/examples/random-generation-test.js +151 -0
  52. package/dist/examples/signal-protocol-test.js +38 -0
  53. package/dist/examples/simple-api-test.js +114 -0
  54. package/dist/examples/simple-crypto-identity-example.js +84 -0
  55. package/dist/examples/timeout-test.js +227 -0
  56. package/dist/examples/zkproof-credentials-example.js +212 -0
  57. package/dist/examples/zkproof-example.js +201 -0
  58. package/dist/gundb/api.js +435 -0
  59. package/dist/gundb/crypto.js +283 -0
  60. package/dist/gundb/db.js +1946 -0
  61. package/dist/gundb/derive.js +232 -0
  62. package/dist/gundb/errors.js +76 -0
  63. package/dist/gundb/index.js +22 -0
  64. package/dist/gundb/rxjs.js +447 -0
  65. package/dist/gundb/types.js +5 -0
  66. package/dist/index.js +58 -0
  67. package/dist/interfaces/common.js +2 -0
  68. package/dist/interfaces/events.js +40 -0
  69. package/dist/interfaces/plugin.js +2 -0
  70. package/dist/interfaces/shogun.js +37 -0
  71. package/dist/managers/AuthManager.js +226 -0
  72. package/dist/managers/CoreInitializer.js +228 -0
  73. package/dist/managers/CryptoIdentityManager.js +366 -0
  74. package/dist/managers/EventManager.js +70 -0
  75. package/dist/managers/PluginManager.js +299 -0
  76. package/dist/plugins/base.js +50 -0
  77. package/dist/plugins/index.js +32 -0
  78. package/dist/plugins/nostr/index.js +20 -0
  79. package/dist/plugins/nostr/nostrConnector.js +419 -0
  80. package/dist/plugins/nostr/nostrConnectorPlugin.js +453 -0
  81. package/dist/plugins/nostr/nostrSigner.js +319 -0
  82. package/dist/plugins/nostr/types.js +2 -0
  83. package/dist/plugins/smartwallet/index.js +18 -0
  84. package/dist/plugins/smartwallet/smartWalletPlugin.js +511 -0
  85. package/dist/plugins/smartwallet/types.js +2 -0
  86. package/dist/plugins/web3/index.js +20 -0
  87. package/dist/plugins/web3/types.js +2 -0
  88. package/dist/plugins/web3/web3Connector.js +533 -0
  89. package/dist/plugins/web3/web3ConnectorPlugin.js +455 -0
  90. package/dist/plugins/web3/web3Signer.js +314 -0
  91. package/dist/plugins/webauthn/index.js +19 -0
  92. package/dist/plugins/webauthn/types.js +14 -0
  93. package/dist/plugins/webauthn/webauthn.js +496 -0
  94. package/dist/plugins/webauthn/webauthnPlugin.js +489 -0
  95. package/dist/plugins/webauthn/webauthnSigner.js +310 -0
  96. package/dist/plugins/zkproof/index.js +53 -0
  97. package/dist/plugins/zkproof/types.js +2 -0
  98. package/dist/plugins/zkproof/zkCredentials.js +213 -0
  99. package/dist/plugins/zkproof/zkProofConnector.js +198 -0
  100. package/dist/plugins/zkproof/zkProofPlugin.js +272 -0
  101. package/dist/storage/storage.js +145 -0
  102. package/dist/types/config/simplified-config.d.ts +114 -0
  103. package/dist/types/core.d.ts +305 -0
  104. package/dist/types/crypto/asymmetric.d.ts +6 -0
  105. package/dist/types/crypto/double-ratchet.d.ts +22 -0
  106. package/dist/types/crypto/file-encryption.d.ts +19 -0
  107. package/dist/types/crypto/hashing.d.ts +9 -0
  108. package/dist/types/crypto/index.d.ts +13 -0
  109. package/dist/types/crypto/mls-codec.d.ts +39 -0
  110. package/dist/types/crypto/mls.d.ts +130 -0
  111. package/dist/types/crypto/pgp.d.ts +95 -0
  112. package/dist/types/crypto/random-generation.d.ts +35 -0
  113. package/dist/types/crypto/sframe.d.ts +102 -0
  114. package/dist/types/crypto/signal-protocol.d.ts +26 -0
  115. package/dist/types/crypto/symmetric.d.ts +9 -0
  116. package/dist/types/crypto/types.d.ts +144 -0
  117. package/dist/types/crypto/utils.d.ts +22 -0
  118. package/dist/types/examples/auth-test.d.ts +8 -0
  119. package/dist/types/examples/crypto-identity-example.d.ts +5 -0
  120. package/dist/types/examples/crypto-working-test.d.ts +1 -0
  121. package/dist/types/examples/double-ratchet-test.d.ts +1 -0
  122. package/dist/types/examples/mls-advanced-example.d.ts +53 -0
  123. package/dist/types/examples/mls-sframe-test.d.ts +1 -0
  124. package/dist/types/examples/pgp-example.d.ts +75 -0
  125. package/dist/types/examples/quick-auth-test.d.ts +8 -0
  126. package/dist/types/examples/random-generation-test.d.ts +1 -0
  127. package/dist/types/examples/signal-protocol-test.d.ts +1 -0
  128. package/dist/types/examples/simple-api-test.d.ts +10 -0
  129. package/dist/types/examples/simple-crypto-identity-example.d.ts +6 -0
  130. package/dist/types/examples/timeout-test.d.ts +8 -0
  131. package/dist/types/examples/zkproof-credentials-example.d.ts +12 -0
  132. package/dist/types/examples/zkproof-example.d.ts +11 -0
  133. package/dist/types/gundb/api.d.ts +185 -0
  134. package/dist/types/gundb/crypto.d.ts +95 -0
  135. package/dist/types/gundb/db.d.ts +397 -0
  136. package/dist/types/gundb/derive.d.ts +21 -0
  137. package/dist/types/gundb/errors.d.ts +42 -0
  138. package/dist/types/gundb/index.d.ts +3 -0
  139. package/dist/types/gundb/rxjs.d.ts +110 -0
  140. package/dist/types/gundb/types.d.ts +255 -0
  141. package/dist/types/index.d.ts +16 -0
  142. package/dist/types/interfaces/common.d.ts +85 -0
  143. package/dist/types/interfaces/events.d.ts +131 -0
  144. package/dist/types/interfaces/plugin.d.ts +162 -0
  145. package/dist/types/interfaces/shogun.d.ts +208 -0
  146. package/dist/types/managers/AuthManager.d.ts +72 -0
  147. package/dist/types/managers/CoreInitializer.d.ts +40 -0
  148. package/dist/types/managers/CryptoIdentityManager.d.ts +102 -0
  149. package/dist/types/managers/EventManager.d.ts +49 -0
  150. package/dist/types/managers/PluginManager.d.ts +145 -0
  151. package/dist/types/plugins/base.d.ts +35 -0
  152. package/dist/types/plugins/index.d.ts +18 -0
  153. package/dist/types/plugins/nostr/index.d.ts +4 -0
  154. package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
  155. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
  156. package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
  157. package/dist/types/plugins/nostr/types.d.ts +122 -0
  158. package/dist/types/plugins/smartwallet/index.d.ts +2 -0
  159. package/dist/types/plugins/smartwallet/smartWalletPlugin.d.ts +67 -0
  160. package/dist/types/plugins/smartwallet/types.d.ts +80 -0
  161. package/dist/types/plugins/web3/index.d.ts +4 -0
  162. package/dist/types/plugins/web3/types.d.ts +107 -0
  163. package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
  164. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
  165. package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
  166. package/dist/types/plugins/webauthn/index.d.ts +3 -0
  167. package/dist/types/plugins/webauthn/types.d.ts +183 -0
  168. package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
  169. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +179 -0
  170. package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
  171. package/dist/types/plugins/zkproof/index.d.ts +48 -0
  172. package/dist/types/plugins/zkproof/types.d.ts +123 -0
  173. package/dist/types/plugins/zkproof/zkCredentials.d.ts +112 -0
  174. package/dist/types/plugins/zkproof/zkProofConnector.d.ts +46 -0
  175. package/dist/types/plugins/zkproof/zkProofPlugin.d.ts +76 -0
  176. package/dist/types/storage/storage.d.ts +51 -0
  177. package/dist/types/utils/errorHandler.d.ts +119 -0
  178. package/dist/types/utils/eventEmitter.d.ts +39 -0
  179. package/dist/types/utils/seedPhrase.d.ts +50 -0
  180. package/dist/types/utils/validation.d.ts +27 -0
  181. package/dist/utils/errorHandler.js +246 -0
  182. package/dist/utils/eventEmitter.js +79 -0
  183. package/dist/utils/seedPhrase.js +97 -0
  184. package/dist/utils/validation.js +81 -0
  185. package/package.json +10 -1
@@ -0,0 +1,122 @@
1
+ import { BaseConfig, BaseResult, BaseCacheEntry } from "../../interfaces/common";
2
+ import { AuthResult, SignUpResult } from "../../interfaces/shogun";
3
+ /**
4
+ * Result of connection attempt
5
+ */
6
+ export interface ConnectionResult extends BaseResult {
7
+ address?: string;
8
+ username?: string;
9
+ randomPassword?: string;
10
+ extensionType?: "alby" | "nostr" | "manual";
11
+ }
12
+ /**
13
+ * Structure for credentials generated via Bitcoin wallet
14
+ */
15
+ export interface NostrConnectorCredentials {
16
+ /** Generated username based on the address */
17
+ username: string;
18
+ /** Chiave GunDB derivata dalla signature */
19
+ key: any;
20
+ /** Original message signed by the user */
21
+ message: string;
22
+ /** Signature provided by the wallet */
23
+ signature: string;
24
+ }
25
+ /**
26
+ * Alby extension interface
27
+ */
28
+ export interface AlbyProvider {
29
+ isAlby?: boolean;
30
+ enable: () => Promise<any>;
31
+ signMessage?: (message: string, address?: string) => Promise<string>;
32
+ getPublicKey?: () => Promise<string>;
33
+ getInfo?: () => Promise<any>;
34
+ }
35
+ /**
36
+ * Nostr extension interface
37
+ */
38
+ export interface NostrProvider {
39
+ getPublicKey: () => Promise<string>;
40
+ signEvent: (event: any) => Promise<any>;
41
+ nip04: {
42
+ encrypt: (pubkey: string, plaintext: string) => Promise<string>;
43
+ decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
44
+ };
45
+ }
46
+ /**
47
+ * Cache entry for signatures
48
+ */
49
+ export interface SignatureCache extends BaseCacheEntry<string> {
50
+ signature: string;
51
+ address: string;
52
+ }
53
+ /**
54
+ * Bitcoin wallet configuration options
55
+ */
56
+ export interface NostrConnectorConfig extends BaseConfig {
57
+ cacheDuration?: number;
58
+ network?: "mainnet" | "testnet";
59
+ useApi?: boolean;
60
+ apiUrl?: string;
61
+ }
62
+ /**
63
+ * Bitcoin Key pair interface
64
+ */
65
+ export interface NostrConnectorKeyPair {
66
+ privateKey: string;
67
+ publicKey: string;
68
+ address: string;
69
+ type: "legacy" | "segwit" | "taproot" | "nostr";
70
+ }
71
+ /**
72
+ * Interface for the Bitcoin wallet plugin
73
+ */
74
+ export interface NostrConnectorPluginInterface {
75
+ /**
76
+ * Check if any Bitcoin wallet is available in the browser
77
+ * @returns true if a wallet is available, false otherwise
78
+ */
79
+ isAvailable(): boolean;
80
+ /**
81
+ * Connect to a Bitcoin wallet
82
+ * @param type Type of wallet to connect to
83
+ * @returns Promise with the connection result
84
+ */
85
+ connectBitcoinWallet(type?: "alby" | "nostr" | "manual"): Promise<ConnectionResult>;
86
+ /**
87
+ * Generate credentials using a Bitcoin wallet
88
+ * @param address Bitcoin address
89
+ * @returns Promise with the generated credentials
90
+ */
91
+ generateCredentials(address: string, signature: string, message: string): Promise<NostrConnectorCredentials>;
92
+ /**
93
+ * Release resources and clean up event listeners
94
+ */
95
+ cleanup(): void;
96
+ /**
97
+ * Generate a password based on a signature
98
+ * @param signature Signature
99
+ * @returns Promise with the generated password
100
+ */
101
+ generatePassword(signature: string): Promise<string>;
102
+ /**
103
+ * Verify a signature
104
+ * @param message Signed message
105
+ * @param signature Signature to verify
106
+ * @param address The Bitcoin address that supposedly created the signature
107
+ * @returns Promise that resolves to true if the signature is valid
108
+ */
109
+ verifySignature(message: string, signature: string, address: string): Promise<boolean>;
110
+ /**
111
+ * Login with Bitcoin wallet
112
+ * @param address Bitcoin address
113
+ * @returns Promise with the operation result
114
+ */
115
+ login(address: string): Promise<AuthResult>;
116
+ /**
117
+ * Sign up with Nostr wallet
118
+ * @param address Nostr address
119
+ * @returns Promise with authentication result
120
+ */
121
+ signUp(address: string): Promise<SignUpResult>;
122
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./smartWalletPlugin";
2
+ export * from "./types";
@@ -0,0 +1,67 @@
1
+ import { BasePlugin } from "../base";
2
+ import { ShogunCore } from "../../core";
3
+ import { SmartWalletPluginInterface, SmartWalletConfig, WalletCreateResult, WalletInfo, ExecutionResult, ProposalInfo, RecoveryRequest } from "./types";
4
+ /**
5
+ * Smart Wallet Plugin for Shogun Core
6
+ * Provides integration with Smart Wallet contracts for account abstraction
7
+ */
8
+ export declare class SmartWalletPlugin extends BasePlugin implements SmartWalletPluginInterface {
9
+ name: string;
10
+ version: string;
11
+ description: string;
12
+ private config;
13
+ private factoryContract;
14
+ private signer;
15
+ constructor(config?: SmartWalletConfig);
16
+ /**
17
+ * Initialize the plugin
18
+ */
19
+ initialize(core: ShogunCore): void;
20
+ /**
21
+ * Destroy the plugin and cleanup resources
22
+ */
23
+ destroy(): void;
24
+ /**
25
+ * Initialize provider and signer
26
+ */
27
+ private initProvider;
28
+ /**
29
+ * Set signer with private key or wallet instance
30
+ * This should be called after deriving the EOA from seed phrase
31
+ */
32
+ setSigner(privateKeyOrAddress: string): Promise<void>;
33
+ /**
34
+ * Connect to MetaMask or other injected provider
35
+ */
36
+ connectWallet(): Promise<void>;
37
+ /**
38
+ * Initialize factory contract
39
+ */
40
+ private initFactoryContract;
41
+ /**
42
+ * Ensure signer is available
43
+ */
44
+ private assertSigner;
45
+ /**
46
+ * Ensure factory is initialized
47
+ */
48
+ private assertFactory;
49
+ createWallet(owner: string, requiredSignatures?: number, requiredGuardians?: number): Promise<WalletCreateResult>;
50
+ createWalletWithGuardians(owner: string, guardians: string[], requiredSignatures?: number, requiredGuardians?: number): Promise<WalletCreateResult>;
51
+ getWalletInfo(walletAddress: string): Promise<WalletInfo | null>;
52
+ getOwnerWallets(ownerAddress: string): Promise<string[]>;
53
+ addSigner(walletAddress: string, signer: string): Promise<ExecutionResult>;
54
+ removeSigner(walletAddress: string, signer: string): Promise<ExecutionResult>;
55
+ setRequiredSignatures(walletAddress: string, required: number): Promise<ExecutionResult>;
56
+ addGuardian(walletAddress: string, guardian: string): Promise<ExecutionResult>;
57
+ removeGuardian(walletAddress: string, guardian: string): Promise<ExecutionResult>;
58
+ executeTransaction(walletAddress: string, target: string, data: string, value?: string): Promise<ExecutionResult>;
59
+ executeBatch(walletAddress: string, targets: string[], dataArray: string[], values: string[]): Promise<ExecutionResult>;
60
+ proposeExecution(walletAddress: string, target: string, data: string): Promise<ExecutionResult>;
61
+ approveProposal(walletAddress: string, proposalId: number): Promise<ExecutionResult>;
62
+ getProposalInfo(walletAddress: string, proposalId: number): Promise<ProposalInfo | null>;
63
+ initiateRecovery(walletAddress: string, newOwner: string): Promise<ExecutionResult>;
64
+ approveRecovery(walletAddress: string): Promise<ExecutionResult>;
65
+ executeRecovery(walletAddress: string): Promise<ExecutionResult>;
66
+ getRecoveryRequest(walletAddress: string): Promise<RecoveryRequest | null>;
67
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Configuration options for SmartWallet plugin
3
+ */
4
+ export interface SmartWalletConfig {
5
+ enabled?: boolean;
6
+ factoryAddress?: string;
7
+ defaultRequiredSignatures?: number;
8
+ defaultRequiredGuardians?: number;
9
+ privateKey?: string;
10
+ }
11
+ /**
12
+ * Result of wallet creation
13
+ */
14
+ export interface WalletCreateResult {
15
+ success: boolean;
16
+ walletAddress?: string;
17
+ transactionHash?: string;
18
+ error?: string;
19
+ }
20
+ /**
21
+ * Wallet information
22
+ */
23
+ export interface WalletInfo {
24
+ address: string;
25
+ owner: string;
26
+ isSigner: boolean;
27
+ requiredSignatures: number;
28
+ requiredGuardians: number;
29
+ }
30
+ /**
31
+ * Proposal information
32
+ */
33
+ export interface ProposalInfo {
34
+ proposalId: number;
35
+ target: string;
36
+ proposer: string;
37
+ approvals: number;
38
+ executed: boolean;
39
+ }
40
+ /**
41
+ * Recovery request information
42
+ */
43
+ export interface RecoveryRequest {
44
+ newOwner: string;
45
+ unlockTime: number;
46
+ approvals: number;
47
+ }
48
+ /**
49
+ * Transaction execution result
50
+ */
51
+ export interface ExecutionResult {
52
+ success: boolean;
53
+ transactionHash?: string;
54
+ error?: string;
55
+ }
56
+ /**
57
+ * Interface for SmartWallet plugin
58
+ */
59
+ export interface SmartWalletPluginInterface {
60
+ setSigner(privateKey: string): Promise<void>;
61
+ connectWallet(): Promise<void>;
62
+ createWallet(owner: string, requiredSignatures?: number, requiredGuardians?: number): Promise<WalletCreateResult>;
63
+ createWalletWithGuardians(owner: string, guardians: string[], requiredSignatures?: number, requiredGuardians?: number): Promise<WalletCreateResult>;
64
+ getWalletInfo(walletAddress: string): Promise<WalletInfo | null>;
65
+ getOwnerWallets(ownerAddress: string): Promise<string[]>;
66
+ addSigner(walletAddress: string, signer: string): Promise<ExecutionResult>;
67
+ removeSigner(walletAddress: string, signer: string): Promise<ExecutionResult>;
68
+ setRequiredSignatures(walletAddress: string, required: number): Promise<ExecutionResult>;
69
+ addGuardian(walletAddress: string, guardian: string): Promise<ExecutionResult>;
70
+ removeGuardian(walletAddress: string, guardian: string): Promise<ExecutionResult>;
71
+ executeTransaction(walletAddress: string, target: string, data: string, value?: string): Promise<ExecutionResult>;
72
+ executeBatch(walletAddress: string, targets: string[], dataArray: string[], values: string[]): Promise<ExecutionResult>;
73
+ proposeExecution(walletAddress: string, target: string, data: string): Promise<ExecutionResult>;
74
+ approveProposal(walletAddress: string, proposalId: number): Promise<ExecutionResult>;
75
+ getProposalInfo(walletAddress: string, proposalId: number): Promise<ProposalInfo | null>;
76
+ initiateRecovery(walletAddress: string, newOwner: string): Promise<ExecutionResult>;
77
+ approveRecovery(walletAddress: string): Promise<ExecutionResult>;
78
+ executeRecovery(walletAddress: string): Promise<ExecutionResult>;
79
+ getRecoveryRequest(walletAddress: string): Promise<RecoveryRequest | null>;
80
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./web3ConnectorPlugin";
2
+ export * from "./types";
3
+ export * from "./web3Connector";
4
+ export * from "./web3Signer";
@@ -0,0 +1,107 @@
1
+ import { ISEAPair } from "gun";
2
+ import { BaseConfig, BaseResult, BaseCacheEntry } from "../../interfaces/common";
3
+ import { AuthResult, SignUpResult } from "../../interfaces/shogun";
4
+ /**
5
+ * Result of connection attempt
6
+ */
7
+ export interface ConnectionResult extends BaseResult {
8
+ address?: string;
9
+ username?: string;
10
+ randomPassword?: string;
11
+ }
12
+ /**
13
+ * Structure for credentials generated via MetaMask
14
+ */
15
+ export interface Web3ConnectorCredentials {
16
+ /** Generated username based on the address */
17
+ username: string;
18
+ /** Generated password based on the signature */
19
+ password: string;
20
+ /** Original message signed by the user */
21
+ message: string;
22
+ /** Signature provided by MetaMask */
23
+ signature: string;
24
+ }
25
+ /**
26
+ * Ethereum provider interface
27
+ */
28
+ export interface EthereumProvider {
29
+ request: (args: any) => Promise<any>;
30
+ isMetaMask?: boolean;
31
+ on?: (event: string, handler: (params: any) => void) => void;
32
+ removeListener?: (event: string, handler: (params: any) => void) => void;
33
+ }
34
+ /**
35
+ * Cache entry for signatures
36
+ */
37
+ export interface SignatureCache extends BaseCacheEntry<string> {
38
+ signature: string;
39
+ address: string;
40
+ }
41
+ /**
42
+ * MetaMask configuration options
43
+ */
44
+ export interface Web3Config extends BaseConfig {
45
+ cacheDuration?: number;
46
+ }
47
+ /**
48
+ * Interfaccia per il plugin MetaMask
49
+ */
50
+ export interface Web3ConnectorPluginInterface {
51
+ /**
52
+ * Verifica se MetaMask è disponibile nel browser
53
+ * @returns true se MetaMask è disponibile, false altrimenti
54
+ */
55
+ isAvailable(): boolean;
56
+ /**
57
+ * Connette a MetaMask
58
+ * @returns Promise con il risultato della connessione
59
+ */
60
+ connectMetaMask(): Promise<ConnectionResult>;
61
+ /**
62
+ * Genera credenziali utilizzando MetaMask
63
+ * @param address Indirizzo Ethereum
64
+ * @returns Promise con le credenziali generate
65
+ */
66
+ generateCredentials(address: string): Promise<ISEAPair>;
67
+ /**
68
+ * Rilascia le risorse e pulisce gli event listener
69
+ */
70
+ cleanup(): void;
71
+ /**
72
+ * Imposta un provider personalizzato
73
+ * @param rpcUrl URL del provider RPC
74
+ * @param privateKey Chiave privata
75
+ */
76
+ setCustomProvider(rpcUrl: string, privateKey: string): void;
77
+ /**
78
+ * Ottiene il signer Ethereum
79
+ * @returns Promise con il signer
80
+ */
81
+ getSigner(): Promise<any>;
82
+ /**
83
+ * Genera una password basata su una firma
84
+ * @param signature Firma
85
+ * @returns Promise con la password generata
86
+ */
87
+ generatePassword(signature: string): Promise<string>;
88
+ /**
89
+ * Verifica una firma
90
+ * @param message Messaggio firmato
91
+ * @param signature Firma da verificare
92
+ * @returns Promise con l'indirizzo che ha generato la firma
93
+ */
94
+ verifySignature(message: string, signature: string): Promise<string>;
95
+ /**
96
+ * Login con MetaMask
97
+ * @param address Indirizzo Ethereum
98
+ * @returns Promise con il risultato dell'operazione
99
+ */
100
+ login(address: string): Promise<AuthResult>;
101
+ /**
102
+ * Sign up with Web3 wallet
103
+ * @param address Ethereum address
104
+ * @returns Promise with authentication result
105
+ */
106
+ signUp(address: string): Promise<SignUpResult>;
107
+ }
@@ -0,0 +1,129 @@
1
+ /**
2
+ * The MetaMaskAuth class provides functionality for connecting, signing up, and logging in using MetaMask.
3
+ */
4
+ import { ethers } from "ethers";
5
+ import { EventEmitter } from "../../utils/eventEmitter";
6
+ import { ConnectionResult, EthereumProvider, Web3Config } from "./types";
7
+ import { ISEAPair } from "gun";
8
+ declare global {
9
+ interface Window {
10
+ ethereum?: EthereumProvider;
11
+ Web3Connector?: typeof Web3Connector;
12
+ _ethereumProviders?: EthereumProvider[];
13
+ }
14
+ }
15
+ declare global {
16
+ namespace NodeJS {
17
+ interface Global {
18
+ web3Connector?: typeof Web3Connector;
19
+ }
20
+ }
21
+ }
22
+ /**
23
+ * Class for MetaMask connection
24
+ */
25
+ declare class Web3Connector extends EventEmitter {
26
+ private readonly MESSAGE_TO_SIGN;
27
+ private readonly DEFAULT_CONFIG;
28
+ private readonly config;
29
+ private readonly signatureCache;
30
+ private provider;
31
+ private customProvider;
32
+ private customWallet;
33
+ constructor(config?: Partial<Web3Config>);
34
+ /**
35
+ * Initialize the provider synchronously with fallback mechanisms
36
+ * to handle conflicts between multiple wallet providers
37
+ */
38
+ private initProvider;
39
+ /**
40
+ * Get available Ethereum provider from multiple possible sources
41
+ */
42
+ private getAvailableEthereumProvider;
43
+ /**
44
+ * Initialize the BrowserProvider (async method for explicit calls)
45
+ */
46
+ setupProvider(): Promise<void>;
47
+ /**
48
+ * Setup MetaMask event listeners using BrowserProvider
49
+ */
50
+ private setupEventListeners;
51
+ /**
52
+ * Cleanup event listeners
53
+ */
54
+ cleanup(): void;
55
+ /**
56
+ * Get cached signature if valid
57
+ */
58
+ private getCachedSignature;
59
+ /**
60
+ * Cache signature
61
+ */
62
+ private cacheSignature;
63
+ /**
64
+ * Validates that the address is valid
65
+ */
66
+ private validateAddress;
67
+ /**
68
+ * Connects to MetaMask with retry logic using BrowserProvider
69
+ */
70
+ connectMetaMask(): Promise<ConnectionResult>;
71
+ /**
72
+ * Generates credentials for the given address
73
+ */
74
+ generateCredentials(address: string): Promise<ISEAPair>;
75
+ /**
76
+ * Generates credentials from a signature
77
+ */
78
+ private generateCredentialsFromSignature;
79
+ /**
80
+ * Generates fallback credentials (for testing/development)
81
+ */
82
+ private generateFallbackCredentials;
83
+ /**
84
+ * Checks if MetaMask is available
85
+ */
86
+ static isMetaMaskAvailable(): boolean;
87
+ /**
88
+ * Requests signature with timeout
89
+ */
90
+ private requestSignatureWithTimeout;
91
+ /**
92
+ * Checks if the connector is available
93
+ */
94
+ isAvailable(): boolean;
95
+ /**
96
+ * Sets a custom provider for testing/development
97
+ */
98
+ setCustomProvider(rpcUrl: string, privateKey: string): void;
99
+ /**
100
+ * Get active signer instance using BrowserProvider
101
+ */
102
+ getSigner(): Promise<ethers.Signer>;
103
+ /**
104
+ * Get active provider instance using BrowserProvider
105
+ */
106
+ getProvider(): Promise<ethers.JsonRpcProvider | ethers.BrowserProvider>;
107
+ /**
108
+ * Generate deterministic password from signature
109
+ * @param signature - Cryptographic signature
110
+ * @returns 64-character hex string
111
+ * @throws {Error} For invalid signature
112
+ */
113
+ generatePassword(signature: string): Promise<string>;
114
+ /**
115
+ * Verify message signature
116
+ * @param message - Original signed message
117
+ * @param signature - Cryptographic signature
118
+ * @returns Recovered Ethereum address
119
+ * @throws {Error} For invalid inputs
120
+ */
121
+ verifySignature(message: string, signature: string): Promise<string>;
122
+ /**
123
+ * Get browser-based Ethereum signer
124
+ * @returns Browser provider signer
125
+ * @throws {Error} If MetaMask not detected
126
+ */
127
+ getEthereumSigner(): Promise<ethers.Signer>;
128
+ }
129
+ export { Web3Connector };
@@ -0,0 +1,160 @@
1
+ import { BasePlugin } from "../base";
2
+ import { ShogunCore } from "../../core";
3
+ import { Web3SigningCredential } from "./web3Signer";
4
+ import { ConnectionResult, Web3ConnectorPluginInterface } from "./types";
5
+ import { ethers } from "ethers";
6
+ import { AuthResult, SignUpResult } from "../../interfaces/shogun";
7
+ import { ISEAPair } from "gun";
8
+ /**
9
+ * Plugin per la gestione delle funzionalità Web3 in ShogunCore
10
+ */
11
+ export declare class Web3ConnectorPlugin extends BasePlugin implements Web3ConnectorPluginInterface {
12
+ name: string;
13
+ version: string;
14
+ description: string;
15
+ private Web3;
16
+ private signer;
17
+ /**
18
+ * @inheritdoc
19
+ */
20
+ initialize(core: ShogunCore): void;
21
+ /**
22
+ * @inheritdoc
23
+ */
24
+ destroy(): void;
25
+ /**
26
+ * Assicura che il modulo Web3 sia inizializzato
27
+ * @private
28
+ */
29
+ private assertMetaMask;
30
+ /**
31
+ * Assicura che il signer sia inizializzato
32
+ * @private
33
+ */
34
+ private assertSigner;
35
+ /**
36
+ * @inheritdoc
37
+ */
38
+ isAvailable(): boolean;
39
+ /**
40
+ * @inheritdoc
41
+ */
42
+ connectMetaMask(): Promise<ConnectionResult>;
43
+ /**
44
+ * @inheritdoc
45
+ */
46
+ generateCredentials(address: string): Promise<ISEAPair>;
47
+ /**
48
+ * @inheritdoc
49
+ */
50
+ cleanup(): void;
51
+ /**
52
+ * @inheritdoc
53
+ */
54
+ setCustomProvider(rpcUrl: string, privateKey: string): void;
55
+ /**
56
+ * @inheritdoc
57
+ */
58
+ getSigner(): Promise<ethers.Signer>;
59
+ /**
60
+ * @inheritdoc
61
+ */
62
+ getProvider(): Promise<ethers.JsonRpcProvider | ethers.BrowserProvider>;
63
+ /**
64
+ * @inheritdoc
65
+ */
66
+ generatePassword(signature: string): Promise<string>;
67
+ /**
68
+ * @inheritdoc
69
+ */
70
+ verifySignature(message: string, signature: string): Promise<string>;
71
+ /**
72
+ * Creates a new Web3 signing credential
73
+ * CONSISTENT with normal Web3 approach
74
+ */
75
+ createSigningCredential(address: string): Promise<Web3SigningCredential>;
76
+ /**
77
+ * Creates an authenticator function for Web3 signing
78
+ */
79
+ createAuthenticator(address: string): (data: any) => Promise<string>;
80
+ /**
81
+ * Creates a derived key pair from Web3 credential
82
+ */
83
+ createDerivedKeyPair(address: string, extra?: string[]): Promise<{
84
+ pub: string;
85
+ priv: string;
86
+ epub: string;
87
+ epriv: string;
88
+ }>;
89
+ /**
90
+ * Signs data with derived keys after Web3 verification
91
+ */
92
+ signWithDerivedKeys(data: any, address: string, extra?: string[]): Promise<string>;
93
+ /**
94
+ * Get signing credential by address
95
+ */
96
+ getSigningCredential(address: string): Web3SigningCredential | undefined;
97
+ /**
98
+ * List all signing credentials
99
+ */
100
+ listSigningCredentials(): Web3SigningCredential[];
101
+ /**
102
+ * Remove a signing credential
103
+ */
104
+ removeSigningCredential(address: string): boolean;
105
+ /**
106
+ * Creates a Gun user from Web3 signing credential
107
+ * This ensures the SAME user is created as with normal approach
108
+ */
109
+ createGunUserFromSigningCredential(address: string): Promise<{
110
+ success: boolean;
111
+ userPub?: string;
112
+ error?: string;
113
+ }>;
114
+ /**
115
+ * Get the Gun user public key for a signing credential
116
+ */
117
+ getGunUserPubFromSigningCredential(address: string): Promise<string | undefined>;
118
+ /**
119
+ * Get the password (for consistency checking)
120
+ */
121
+ getPassword(address: string): string | undefined;
122
+ /**
123
+ * Verify consistency between oneshot and normal approaches
124
+ * This ensures both approaches create the same Gun user
125
+ */
126
+ verifyConsistency(address: string, expectedUserPub?: string): Promise<{
127
+ consistent: boolean;
128
+ actualUserPub?: string;
129
+ expectedUserPub?: string;
130
+ }>;
131
+ /**
132
+ * Complete oneshot workflow that creates the SAME Gun user as normal approach
133
+ * This is the recommended method for oneshot signing with full consistency
134
+ */
135
+ setupConsistentOneshotSigning(address: string): Promise<{
136
+ credential: Web3SigningCredential;
137
+ authenticator: (data: any) => Promise<string>;
138
+ gunUser: {
139
+ success: boolean;
140
+ userPub?: string;
141
+ error?: string;
142
+ };
143
+ username: string;
144
+ password: string;
145
+ }>;
146
+ /**
147
+ * Login con Web3
148
+ * @param address - Indirizzo Ethereum
149
+ * @returns {Promise<AuthResult>} Risultato dell'autenticazione
150
+ * @description Autentica l'utente usando le credenziali del wallet Web3 dopo la verifica della firma
151
+ */
152
+ login(address: string): Promise<AuthResult>;
153
+ /**
154
+ * Register new user with Web3 wallet
155
+ * @param address - Ethereum address
156
+ * @returns {Promise<SignUpResult>} Registration result
157
+ */
158
+ signUp(address: string): Promise<SignUpResult>;
159
+ }
160
+ export type { Web3ConnectorPluginInterface } from "./types";