shogun-core 5.2.0 → 5.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -1143
- package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js +1220 -0
- package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js +844 -0
- package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js +2335 -0
- package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js +999 -0
- package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +1651 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js +825 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js +508 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +747 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +1608 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js +2117 -0
- package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js +86 -0
- package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js.map +1 -0
- package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js +539 -0
- package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/shogun-core.js +160386 -0
- package/dist/browser/shogun-core.js.map +1 -0
- package/dist/config/simplified-config.js +236 -0
- package/dist/core.js +329 -0
- package/dist/crypto/asymmetric.js +99 -0
- package/dist/crypto/double-ratchet.js +370 -0
- package/dist/crypto/file-encryption.js +213 -0
- package/dist/crypto/hashing.js +87 -0
- package/dist/crypto/index.js +34 -0
- package/dist/crypto/mls-codec.js +202 -0
- package/dist/crypto/mls.js +550 -0
- package/dist/crypto/pgp.js +390 -0
- package/dist/crypto/random-generation.js +341 -0
- package/dist/crypto/sframe.js +350 -0
- package/dist/crypto/signal-protocol.js +376 -0
- package/dist/crypto/symmetric.js +91 -0
- package/dist/crypto/types.js +2 -0
- package/dist/crypto/utils.js +140 -0
- package/dist/examples/auth-test.js +253 -0
- package/dist/examples/crypto-identity-example.js +151 -0
- package/dist/examples/crypto-working-test.js +83 -0
- package/dist/examples/double-ratchet-test.js +155 -0
- package/dist/examples/mls-advanced-example.js +294 -0
- package/dist/examples/mls-sframe-test.js +304 -0
- package/dist/examples/pgp-example.js +200 -0
- package/dist/examples/quick-auth-test.js +61 -0
- package/dist/examples/random-generation-test.js +151 -0
- package/dist/examples/signal-protocol-test.js +38 -0
- package/dist/examples/simple-api-test.js +114 -0
- package/dist/examples/simple-crypto-identity-example.js +84 -0
- package/dist/examples/timeout-test.js +227 -0
- package/dist/examples/zkproof-credentials-example.js +212 -0
- package/dist/examples/zkproof-example.js +201 -0
- package/dist/gundb/api.js +435 -0
- package/dist/gundb/crypto.js +283 -0
- package/dist/gundb/db.js +1946 -0
- package/dist/gundb/derive.js +232 -0
- package/dist/gundb/errors.js +76 -0
- package/dist/gundb/index.js +22 -0
- package/dist/gundb/rxjs.js +447 -0
- package/dist/gundb/types.js +5 -0
- package/dist/index.js +58 -0
- package/dist/interfaces/common.js +2 -0
- package/dist/interfaces/events.js +40 -0
- package/dist/interfaces/plugin.js +2 -0
- package/dist/interfaces/shogun.js +37 -0
- package/dist/managers/AuthManager.js +226 -0
- package/dist/managers/CoreInitializer.js +228 -0
- package/dist/managers/CryptoIdentityManager.js +366 -0
- package/dist/managers/EventManager.js +70 -0
- package/dist/managers/PluginManager.js +299 -0
- package/dist/plugins/base.js +50 -0
- package/dist/plugins/index.js +32 -0
- package/dist/plugins/nostr/index.js +20 -0
- package/dist/plugins/nostr/nostrConnector.js +419 -0
- package/dist/plugins/nostr/nostrConnectorPlugin.js +453 -0
- package/dist/plugins/nostr/nostrSigner.js +319 -0
- package/dist/plugins/nostr/types.js +2 -0
- package/dist/plugins/smartwallet/index.js +18 -0
- package/dist/plugins/smartwallet/smartWalletPlugin.js +511 -0
- package/dist/plugins/smartwallet/types.js +2 -0
- package/dist/plugins/web3/index.js +20 -0
- package/dist/plugins/web3/types.js +2 -0
- package/dist/plugins/web3/web3Connector.js +533 -0
- package/dist/plugins/web3/web3ConnectorPlugin.js +455 -0
- package/dist/plugins/web3/web3Signer.js +314 -0
- package/dist/plugins/webauthn/index.js +19 -0
- package/dist/plugins/webauthn/types.js +14 -0
- package/dist/plugins/webauthn/webauthn.js +496 -0
- package/dist/plugins/webauthn/webauthnPlugin.js +489 -0
- package/dist/plugins/webauthn/webauthnSigner.js +310 -0
- package/dist/plugins/zkproof/index.js +53 -0
- package/dist/plugins/zkproof/types.js +2 -0
- package/dist/plugins/zkproof/zkCredentials.js +213 -0
- package/dist/plugins/zkproof/zkProofConnector.js +198 -0
- package/dist/plugins/zkproof/zkProofPlugin.js +272 -0
- package/dist/storage/storage.js +145 -0
- package/dist/types/config/simplified-config.d.ts +114 -0
- package/dist/types/core.d.ts +305 -0
- package/dist/types/crypto/asymmetric.d.ts +6 -0
- package/dist/types/crypto/double-ratchet.d.ts +22 -0
- package/dist/types/crypto/file-encryption.d.ts +19 -0
- package/dist/types/crypto/hashing.d.ts +9 -0
- package/dist/types/crypto/index.d.ts +13 -0
- package/dist/types/crypto/mls-codec.d.ts +39 -0
- package/dist/types/crypto/mls.d.ts +130 -0
- package/dist/types/crypto/pgp.d.ts +95 -0
- package/dist/types/crypto/random-generation.d.ts +35 -0
- package/dist/types/crypto/sframe.d.ts +102 -0
- package/dist/types/crypto/signal-protocol.d.ts +26 -0
- package/dist/types/crypto/symmetric.d.ts +9 -0
- package/dist/types/crypto/types.d.ts +144 -0
- package/dist/types/crypto/utils.d.ts +22 -0
- package/dist/types/examples/auth-test.d.ts +8 -0
- package/dist/types/examples/crypto-identity-example.d.ts +5 -0
- package/dist/types/examples/crypto-working-test.d.ts +1 -0
- package/dist/types/examples/double-ratchet-test.d.ts +1 -0
- package/dist/types/examples/mls-advanced-example.d.ts +53 -0
- package/dist/types/examples/mls-sframe-test.d.ts +1 -0
- package/dist/types/examples/pgp-example.d.ts +75 -0
- package/dist/types/examples/quick-auth-test.d.ts +8 -0
- package/dist/types/examples/random-generation-test.d.ts +1 -0
- package/dist/types/examples/signal-protocol-test.d.ts +1 -0
- package/dist/types/examples/simple-api-test.d.ts +10 -0
- package/dist/types/examples/simple-crypto-identity-example.d.ts +6 -0
- package/dist/types/examples/timeout-test.d.ts +8 -0
- package/dist/types/examples/zkproof-credentials-example.d.ts +12 -0
- package/dist/types/examples/zkproof-example.d.ts +11 -0
- package/dist/types/gundb/api.d.ts +185 -0
- package/dist/types/gundb/crypto.d.ts +95 -0
- package/dist/types/gundb/db.d.ts +397 -0
- package/dist/types/gundb/derive.d.ts +21 -0
- package/dist/types/gundb/errors.d.ts +42 -0
- package/dist/types/gundb/index.d.ts +3 -0
- package/dist/types/gundb/rxjs.d.ts +110 -0
- package/dist/types/gundb/types.d.ts +255 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/interfaces/common.d.ts +85 -0
- package/dist/types/interfaces/events.d.ts +131 -0
- package/dist/types/interfaces/plugin.d.ts +162 -0
- package/dist/types/interfaces/shogun.d.ts +208 -0
- package/dist/types/managers/AuthManager.d.ts +72 -0
- package/dist/types/managers/CoreInitializer.d.ts +40 -0
- package/dist/types/managers/CryptoIdentityManager.d.ts +102 -0
- package/dist/types/managers/EventManager.d.ts +49 -0
- package/dist/types/managers/PluginManager.d.ts +145 -0
- package/dist/types/plugins/base.d.ts +35 -0
- package/dist/types/plugins/index.d.ts +18 -0
- package/dist/types/plugins/nostr/index.d.ts +4 -0
- package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
- package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
- package/dist/types/plugins/nostr/types.d.ts +122 -0
- package/dist/types/plugins/smartwallet/index.d.ts +2 -0
- package/dist/types/plugins/smartwallet/smartWalletPlugin.d.ts +67 -0
- package/dist/types/plugins/smartwallet/types.d.ts +80 -0
- package/dist/types/plugins/web3/index.d.ts +4 -0
- package/dist/types/plugins/web3/types.d.ts +107 -0
- package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
- package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
- package/dist/types/plugins/webauthn/index.d.ts +3 -0
- package/dist/types/plugins/webauthn/types.d.ts +183 -0
- package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +179 -0
- package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
- package/dist/types/plugins/zkproof/index.d.ts +48 -0
- package/dist/types/plugins/zkproof/types.d.ts +123 -0
- package/dist/types/plugins/zkproof/zkCredentials.d.ts +112 -0
- package/dist/types/plugins/zkproof/zkProofConnector.d.ts +46 -0
- package/dist/types/plugins/zkproof/zkProofPlugin.d.ts +76 -0
- package/dist/types/storage/storage.d.ts +51 -0
- package/dist/types/utils/errorHandler.d.ts +119 -0
- package/dist/types/utils/eventEmitter.d.ts +39 -0
- package/dist/types/utils/seedPhrase.d.ts +50 -0
- package/dist/types/utils/validation.d.ts +27 -0
- package/dist/utils/errorHandler.js +246 -0
- package/dist/utils/eventEmitter.js +79 -0
- package/dist/utils/seedPhrase.js +97 -0
- package/dist/utils/validation.js +81 -0
- package/package.json +10 -57
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SmartWalletPlugin = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
// Smart Wallet ABIs
|
|
7
|
+
const SMART_WALLET_FACTORY_ABI = [
|
|
8
|
+
"function createWallet(address owner, uint256 requiredSignatures, uint256 requiredGuardians) external returns (address wallet)",
|
|
9
|
+
"function createWalletWithGuardians(address owner, address[] memory guardians, uint256 requiredSignatures, uint256 requiredGuardians) external returns (address wallet)",
|
|
10
|
+
"function getOwnerWallets(address owner) external view returns (address[] memory)",
|
|
11
|
+
"event WalletCreated(address indexed wallet, address indexed owner, uint256 indexed walletIndex)",
|
|
12
|
+
];
|
|
13
|
+
const SMART_WALLET_ABI = [
|
|
14
|
+
// Signer management
|
|
15
|
+
"function addSigner(address signer) external",
|
|
16
|
+
"function removeSigner(address signer) external",
|
|
17
|
+
"function setRequiredSignatures(uint256 requiredSignatures) external",
|
|
18
|
+
"function signers(address) external view returns (bool)",
|
|
19
|
+
"function requiredSignatures() external view returns (uint256)",
|
|
20
|
+
"function owner() external view returns (address)",
|
|
21
|
+
// Guardian management
|
|
22
|
+
"function addGuardian(address guardian) external",
|
|
23
|
+
"function removeGuardian(address guardian) external",
|
|
24
|
+
"function setRequiredGuardians(uint256 requiredGuardians) external",
|
|
25
|
+
"function guardians(address) external view returns (bool)",
|
|
26
|
+
"function requiredGuardians() external view returns (uint256)",
|
|
27
|
+
// Execution
|
|
28
|
+
"function execute(address target, bytes calldata data, uint256 value) external returns (bool success, bytes memory returnData)",
|
|
29
|
+
"function executeBatch(address[] memory targets, bytes[] memory data, uint256[] memory values) external returns (bool[] memory results)",
|
|
30
|
+
// Multi-sig
|
|
31
|
+
"function proposeExecution(address target, bytes calldata data) external returns (uint256 proposalId)",
|
|
32
|
+
"function approveProposal(uint256 proposalId) external",
|
|
33
|
+
"function getProposal(uint256 proposalId) external view returns (address target, bytes memory data, address proposer, uint256 approvals, bool executed)",
|
|
34
|
+
"function hasApprovedProposal(uint256 proposalId, address signer) external view returns (bool)",
|
|
35
|
+
// Recovery
|
|
36
|
+
"function initiateRecovery(address newOwner) external",
|
|
37
|
+
"function approveRecovery() external",
|
|
38
|
+
"function executeRecovery() external",
|
|
39
|
+
"function getRecoveryRequest() external view returns (address newOwner, uint256 unlockTime, uint256 approvals)",
|
|
40
|
+
"function hasApprovedRecovery(address guardian) external view returns (bool)",
|
|
41
|
+
"event SignerAdded(address indexed signer)",
|
|
42
|
+
"event GuardianAdded(address indexed guardian)",
|
|
43
|
+
"event ExecutionExecuted(uint256 indexed proposalId, bool success)",
|
|
44
|
+
"event RecoveryExecuted(address indexed newOwner)",
|
|
45
|
+
];
|
|
46
|
+
/**
|
|
47
|
+
* Smart Wallet Plugin for Shogun Core
|
|
48
|
+
* Provides integration with Smart Wallet contracts for account abstraction
|
|
49
|
+
*/
|
|
50
|
+
class SmartWalletPlugin extends base_1.BasePlugin {
|
|
51
|
+
constructor(config = {}) {
|
|
52
|
+
super();
|
|
53
|
+
this.name = "smartwallet";
|
|
54
|
+
this.version = "1.0.0";
|
|
55
|
+
this.description = "Smart Wallet integration for Shogun Core with multi-sig and social recovery";
|
|
56
|
+
this.factoryContract = null;
|
|
57
|
+
this.signer = null;
|
|
58
|
+
this.config = {
|
|
59
|
+
enabled: true,
|
|
60
|
+
defaultRequiredSignatures: 1,
|
|
61
|
+
defaultRequiredGuardians: 2,
|
|
62
|
+
...config,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Initialize the plugin
|
|
67
|
+
*/
|
|
68
|
+
initialize(core) {
|
|
69
|
+
super.initialize(core);
|
|
70
|
+
if (!this.config.enabled) {
|
|
71
|
+
console.log("[SmartWallet] Plugin disabled");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
// Initialize provider and signer
|
|
76
|
+
this.initProvider();
|
|
77
|
+
// Initialize factory contract if address is provided
|
|
78
|
+
if (this.config.factoryAddress) {
|
|
79
|
+
this.initFactoryContract();
|
|
80
|
+
}
|
|
81
|
+
console.log("[SmartWallet] Plugin initialized successfully");
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error("[SmartWallet] Initialization failed:", error.message);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Destroy the plugin and cleanup resources
|
|
89
|
+
*/
|
|
90
|
+
destroy() {
|
|
91
|
+
this.factoryContract = null;
|
|
92
|
+
this.signer = null;
|
|
93
|
+
super.destroy();
|
|
94
|
+
console.log("[SmartWallet] Plugin destroyed");
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Initialize provider and signer
|
|
98
|
+
*/
|
|
99
|
+
initProvider() {
|
|
100
|
+
if (typeof window !== "undefined" && window.ethereum) {
|
|
101
|
+
const provider = new ethers_1.ethers.BrowserProvider(window.ethereum);
|
|
102
|
+
// Try to get signer from config, otherwise request from browser
|
|
103
|
+
if (this.config.privateKey) {
|
|
104
|
+
this.signer = new ethers_1.ethers.Wallet(this.config.privateKey, provider);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// Will be set when user connects wallet or provides private key
|
|
108
|
+
this.signer = null;
|
|
109
|
+
console.log("[SmartWallet] No private key provided. Use connectWallet() or setSigner() first.");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Set signer with private key or wallet instance
|
|
115
|
+
* This should be called after deriving the EOA from seed phrase
|
|
116
|
+
*/
|
|
117
|
+
async setSigner(privateKeyOrAddress) {
|
|
118
|
+
try {
|
|
119
|
+
if (!this.signer?.provider) {
|
|
120
|
+
const provider = new ethers_1.ethers.BrowserProvider(window.ethereum);
|
|
121
|
+
this.signer = new ethers_1.ethers.Wallet(privateKeyOrAddress, provider);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
this.signer = new ethers_1.ethers.Wallet(privateKeyOrAddress, this.signer.provider);
|
|
125
|
+
}
|
|
126
|
+
console.log("[SmartWallet] Signer updated");
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.error("[SmartWallet] Failed to set signer:", error.message);
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Connect to MetaMask or other injected provider
|
|
135
|
+
*/
|
|
136
|
+
async connectWallet() {
|
|
137
|
+
try {
|
|
138
|
+
if (typeof window !== "undefined" && window.ethereum) {
|
|
139
|
+
const provider = new ethers_1.ethers.BrowserProvider(window.ethereum);
|
|
140
|
+
await provider.send("eth_requestAccounts", []);
|
|
141
|
+
this.signer = await provider.getSigner();
|
|
142
|
+
console.log("[SmartWallet] Connected to wallet:", await this.signer.getAddress());
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
throw new Error("No Ethereum provider found");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error("[SmartWallet] Failed to connect wallet:", error.message);
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Initialize factory contract
|
|
155
|
+
*/
|
|
156
|
+
initFactoryContract() {
|
|
157
|
+
if (!this.config.factoryAddress || !this.signer) {
|
|
158
|
+
console.warn("[SmartWallet] Factory address or signer not available");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.factoryContract = new ethers_1.ethers.Contract(this.config.factoryAddress, SMART_WALLET_FACTORY_ABI, this.signer);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Ensure signer is available
|
|
165
|
+
*/
|
|
166
|
+
assertSigner() {
|
|
167
|
+
if (!this.signer) {
|
|
168
|
+
throw new Error("Signer not available. Please connect a wallet.");
|
|
169
|
+
}
|
|
170
|
+
return this.signer;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Ensure factory is initialized
|
|
174
|
+
*/
|
|
175
|
+
assertFactory() {
|
|
176
|
+
if (!this.factoryContract) {
|
|
177
|
+
throw new Error("SmartWallet factory not initialized. Please deploy factory first.");
|
|
178
|
+
}
|
|
179
|
+
return this.factoryContract;
|
|
180
|
+
}
|
|
181
|
+
// ============================================ Wallet Creation ============================================
|
|
182
|
+
async createWallet(owner, requiredSignatures, requiredGuardians) {
|
|
183
|
+
try {
|
|
184
|
+
const factory = this.assertFactory();
|
|
185
|
+
const sig = this.assertSigner();
|
|
186
|
+
const reqSig = requiredSignatures ?? this.config.defaultRequiredSignatures ?? 1;
|
|
187
|
+
const reqGuard = requiredGuardians ?? this.config.defaultRequiredGuardians ?? 2;
|
|
188
|
+
const tx = await factory.createWallet(owner, reqSig, reqGuard);
|
|
189
|
+
const receipt = await tx.wait();
|
|
190
|
+
// Extract wallet address from event
|
|
191
|
+
const event = receipt.logs.find((log) => log.topics[0] === ethers_1.ethers.id("WalletCreated(address,address,uint256)"));
|
|
192
|
+
const walletAddress = event
|
|
193
|
+
? ethers_1.ethers.getAddress("0x" + event.topics[1].slice(-40))
|
|
194
|
+
: null;
|
|
195
|
+
return {
|
|
196
|
+
success: true,
|
|
197
|
+
walletAddress: walletAddress || undefined,
|
|
198
|
+
transactionHash: receipt.hash,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
return {
|
|
203
|
+
success: false,
|
|
204
|
+
error: error.message,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async createWalletWithGuardians(owner, guardians, requiredSignatures, requiredGuardians) {
|
|
209
|
+
try {
|
|
210
|
+
const factory = this.assertFactory();
|
|
211
|
+
const reqSig = requiredSignatures ?? this.config.defaultRequiredSignatures ?? 1;
|
|
212
|
+
const reqGuard = requiredGuardians ?? this.config.defaultRequiredGuardians ?? 2;
|
|
213
|
+
const tx = await factory.createWalletWithGuardians(owner, guardians, reqSig, reqGuard);
|
|
214
|
+
const receipt = await tx.wait();
|
|
215
|
+
const event = receipt.logs.find((log) => log.topics[0] === ethers_1.ethers.id("WalletCreated(address,address,uint256)"));
|
|
216
|
+
const walletAddress = event
|
|
217
|
+
? ethers_1.ethers.getAddress("0x" + event.topics[1].slice(-40))
|
|
218
|
+
: null;
|
|
219
|
+
return {
|
|
220
|
+
success: true,
|
|
221
|
+
walletAddress: walletAddress || undefined,
|
|
222
|
+
transactionHash: receipt.hash,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
return {
|
|
227
|
+
success: false,
|
|
228
|
+
error: error.message,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// ============================================ Wallet Management ============================================
|
|
233
|
+
async getWalletInfo(walletAddress) {
|
|
234
|
+
try {
|
|
235
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
236
|
+
const [owner, requiredSig, requiredGuard, currentSigner] = await Promise.all([
|
|
237
|
+
walletContract.owner(),
|
|
238
|
+
walletContract.requiredSignatures(),
|
|
239
|
+
walletContract.requiredGuardians(),
|
|
240
|
+
this.assertSigner().getAddress(),
|
|
241
|
+
]);
|
|
242
|
+
const isSigner = await walletContract.signers(currentSigner);
|
|
243
|
+
return {
|
|
244
|
+
address: walletAddress,
|
|
245
|
+
owner,
|
|
246
|
+
isSigner,
|
|
247
|
+
requiredSignatures: Number(requiredSig),
|
|
248
|
+
requiredGuardians: Number(requiredGuard),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
console.error("[SmartWallet] Error getting wallet info:", error);
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async getOwnerWallets(ownerAddress) {
|
|
257
|
+
try {
|
|
258
|
+
const factory = this.assertFactory();
|
|
259
|
+
const wallets = await factory.getOwnerWallets(ownerAddress);
|
|
260
|
+
return wallets;
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
console.error("[SmartWallet] Error getting owner wallets:", error);
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// ============================================ Signer Management ============================================
|
|
268
|
+
async addSigner(walletAddress, signer) {
|
|
269
|
+
try {
|
|
270
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
271
|
+
const tx = await walletContract.addSigner(signer);
|
|
272
|
+
const receipt = await tx.wait();
|
|
273
|
+
return {
|
|
274
|
+
success: true,
|
|
275
|
+
transactionHash: receipt.hash,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
return {
|
|
280
|
+
success: false,
|
|
281
|
+
error: error.message,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
async removeSigner(walletAddress, signer) {
|
|
286
|
+
try {
|
|
287
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
288
|
+
const tx = await walletContract.removeSigner(signer);
|
|
289
|
+
const receipt = await tx.wait();
|
|
290
|
+
return {
|
|
291
|
+
success: true,
|
|
292
|
+
transactionHash: receipt.hash,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
return {
|
|
297
|
+
success: false,
|
|
298
|
+
error: error.message,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async setRequiredSignatures(walletAddress, required) {
|
|
303
|
+
try {
|
|
304
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
305
|
+
const tx = await walletContract.setRequiredSignatures(required);
|
|
306
|
+
const receipt = await tx.wait();
|
|
307
|
+
return {
|
|
308
|
+
success: true,
|
|
309
|
+
transactionHash: receipt.hash,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
return {
|
|
314
|
+
success: false,
|
|
315
|
+
error: error.message,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// ============================================ Guardian Management ============================================
|
|
320
|
+
async addGuardian(walletAddress, guardian) {
|
|
321
|
+
try {
|
|
322
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
323
|
+
const tx = await walletContract.addGuardian(guardian);
|
|
324
|
+
const receipt = await tx.wait();
|
|
325
|
+
return {
|
|
326
|
+
success: true,
|
|
327
|
+
transactionHash: receipt.hash,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
return {
|
|
332
|
+
success: false,
|
|
333
|
+
error: error.message,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
async removeGuardian(walletAddress, guardian) {
|
|
338
|
+
try {
|
|
339
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
340
|
+
const tx = await walletContract.removeGuardian(guardian);
|
|
341
|
+
const receipt = await tx.wait();
|
|
342
|
+
return {
|
|
343
|
+
success: true,
|
|
344
|
+
transactionHash: receipt.hash,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
return {
|
|
349
|
+
success: false,
|
|
350
|
+
error: error.message,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
// ============================================ Execution ============================================
|
|
355
|
+
async executeTransaction(walletAddress, target, data, value = "0") {
|
|
356
|
+
try {
|
|
357
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
358
|
+
const tx = await walletContract.execute(target, data, value);
|
|
359
|
+
const receipt = await tx.wait();
|
|
360
|
+
return {
|
|
361
|
+
success: true,
|
|
362
|
+
transactionHash: receipt.hash,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
return {
|
|
367
|
+
success: false,
|
|
368
|
+
error: error.message,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
async executeBatch(walletAddress, targets, dataArray, values) {
|
|
373
|
+
try {
|
|
374
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
375
|
+
const tx = await walletContract.executeBatch(targets, dataArray, values);
|
|
376
|
+
const receipt = await tx.wait();
|
|
377
|
+
return {
|
|
378
|
+
success: true,
|
|
379
|
+
transactionHash: receipt.hash,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
return {
|
|
384
|
+
success: false,
|
|
385
|
+
error: error.message,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
// ============================================ Multi-Sig ============================================
|
|
390
|
+
async proposeExecution(walletAddress, target, data) {
|
|
391
|
+
try {
|
|
392
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
393
|
+
const tx = await walletContract.proposeExecution(target, data);
|
|
394
|
+
const receipt = await tx.wait();
|
|
395
|
+
return {
|
|
396
|
+
success: true,
|
|
397
|
+
transactionHash: receipt.hash,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
return {
|
|
402
|
+
success: false,
|
|
403
|
+
error: error.message,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async approveProposal(walletAddress, proposalId) {
|
|
408
|
+
try {
|
|
409
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
410
|
+
const tx = await walletContract.approveProposal(proposalId);
|
|
411
|
+
const receipt = await tx.wait();
|
|
412
|
+
return {
|
|
413
|
+
success: true,
|
|
414
|
+
transactionHash: receipt.hash,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
return {
|
|
419
|
+
success: false,
|
|
420
|
+
error: error.message,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
async getProposalInfo(walletAddress, proposalId) {
|
|
425
|
+
try {
|
|
426
|
+
const provider = this.assertSigner().provider || ethers_1.ethers.getDefaultProvider();
|
|
427
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, provider);
|
|
428
|
+
const [target, data, proposer, approvals, executed] = await walletContract.getProposal(proposalId);
|
|
429
|
+
return {
|
|
430
|
+
proposalId,
|
|
431
|
+
target,
|
|
432
|
+
proposer,
|
|
433
|
+
approvals: Number(approvals),
|
|
434
|
+
executed,
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
catch (error) {
|
|
438
|
+
console.error("[SmartWallet] Error getting proposal info:", error);
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
// ============================================ Recovery ============================================
|
|
443
|
+
async initiateRecovery(walletAddress, newOwner) {
|
|
444
|
+
try {
|
|
445
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
446
|
+
const tx = await walletContract.initiateRecovery(newOwner);
|
|
447
|
+
const receipt = await tx.wait();
|
|
448
|
+
return {
|
|
449
|
+
success: true,
|
|
450
|
+
transactionHash: receipt.hash,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
return {
|
|
455
|
+
success: false,
|
|
456
|
+
error: error.message,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
async approveRecovery(walletAddress) {
|
|
461
|
+
try {
|
|
462
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
463
|
+
const tx = await walletContract.approveRecovery();
|
|
464
|
+
const receipt = await tx.wait();
|
|
465
|
+
return {
|
|
466
|
+
success: true,
|
|
467
|
+
transactionHash: receipt.hash,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
catch (error) {
|
|
471
|
+
return {
|
|
472
|
+
success: false,
|
|
473
|
+
error: error.message,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
async executeRecovery(walletAddress) {
|
|
478
|
+
try {
|
|
479
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, this.assertSigner());
|
|
480
|
+
const tx = await walletContract.executeRecovery();
|
|
481
|
+
const receipt = await tx.wait();
|
|
482
|
+
return {
|
|
483
|
+
success: true,
|
|
484
|
+
transactionHash: receipt.hash,
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
catch (error) {
|
|
488
|
+
return {
|
|
489
|
+
success: false,
|
|
490
|
+
error: error.message,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
async getRecoveryRequest(walletAddress) {
|
|
495
|
+
try {
|
|
496
|
+
const provider = this.assertSigner().provider || ethers_1.ethers.getDefaultProvider();
|
|
497
|
+
const walletContract = new ethers_1.ethers.Contract(walletAddress, SMART_WALLET_ABI, provider);
|
|
498
|
+
const [newOwner, unlockTime, approvals] = await walletContract.getRecoveryRequest();
|
|
499
|
+
return {
|
|
500
|
+
newOwner,
|
|
501
|
+
unlockTime: Number(unlockTime),
|
|
502
|
+
approvals: Number(approvals),
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
catch (error) {
|
|
506
|
+
console.error("[SmartWallet] Error getting recovery request:", error);
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
exports.SmartWalletPlugin = SmartWalletPlugin;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./web3ConnectorPlugin"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./web3Connector"), exports);
|
|
20
|
+
__exportStar(require("./web3Signer"), exports);
|