shogun-core 3.3.5 → 3.3.6
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/dist/browser/shogun-core.js +79919 -190726
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/{src/index.js → index.js} +0 -1
- package/dist/{src/managers → managers}/CoreInitializer.js +0 -6
- package/dist/{src/storage → storage}/storage.js +0 -16
- package/dist/types/{src/index.d.ts → index.d.ts} +0 -1
- package/package.json +10 -26
- package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_axios_index_js.shogun-core.js +0 -4078
- package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_axios_index_js.shogun-core.js.map +0 -1
- package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_is-ipfs_dist_src_index_js.shogun-core.js +0 -4908
- package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_is-ipfs_dist_src_index_js.shogun-core.js.map +0 -1
- package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_uint8-varint_dist_src_index_js-node_modu-0db5ba.shogun-core.js +0 -2109
- package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_uint8-varint_dist_src_index_js-node_modu-0db5ba.shogun-core.js.map +0 -1
- package/dist/ship/examples/identity-cli.js +0 -511
- package/dist/ship/examples/messenger-cli.js +0 -745
- package/dist/ship/examples/stealth-cli.js +0 -433
- package/dist/ship/examples/storage-cli.js +0 -615
- package/dist/ship/examples/vault-cli.js +0 -444
- package/dist/ship/examples/wallet-cli.js +0 -767
- package/dist/ship/implementation/SHIP_00.js +0 -478
- package/dist/ship/implementation/SHIP_01.js +0 -433
- package/dist/ship/implementation/SHIP_02.js +0 -1366
- package/dist/ship/implementation/SHIP_03.js +0 -855
- package/dist/ship/implementation/SHIP_04.js +0 -589
- package/dist/ship/implementation/SHIP_05.js +0 -1064
- package/dist/ship/implementation/SHIP_06.js +0 -635
- package/dist/ship/index.js +0 -17
- package/dist/ship/interfaces/ISHIP_00.js +0 -135
- package/dist/ship/interfaces/ISHIP_01.js +0 -128
- package/dist/ship/interfaces/ISHIP_02.js +0 -57
- package/dist/ship/interfaces/ISHIP_03.js +0 -61
- package/dist/ship/interfaces/ISHIP_04.js +0 -62
- package/dist/ship/interfaces/ISHIP_05.js +0 -59
- package/dist/ship/interfaces/ISHIP_06.js +0 -194
- package/dist/types/ship/examples/identity-cli.d.ts +0 -40
- package/dist/types/ship/examples/messenger-cli.d.ts +0 -37
- package/dist/types/ship/examples/stealth-cli.d.ts +0 -31
- package/dist/types/ship/examples/storage-cli.d.ts +0 -48
- package/dist/types/ship/examples/vault-cli.d.ts +0 -13
- package/dist/types/ship/examples/wallet-cli.d.ts +0 -131
- package/dist/types/ship/implementation/SHIP_00.d.ts +0 -113
- package/dist/types/ship/implementation/SHIP_01.d.ts +0 -80
- package/dist/types/ship/implementation/SHIP_02.d.ts +0 -297
- package/dist/types/ship/implementation/SHIP_03.d.ts +0 -127
- package/dist/types/ship/implementation/SHIP_04.d.ts +0 -76
- package/dist/types/ship/implementation/SHIP_05.d.ts +0 -70
- package/dist/types/ship/implementation/SHIP_06.d.ts +0 -101
- package/dist/types/ship/index.d.ts +0 -14
- package/dist/types/ship/interfaces/ISHIP_00.d.ts +0 -410
- package/dist/types/ship/interfaces/ISHIP_01.d.ts +0 -343
- package/dist/types/ship/interfaces/ISHIP_02.d.ts +0 -470
- package/dist/types/ship/interfaces/ISHIP_03.d.ts +0 -295
- package/dist/types/ship/interfaces/ISHIP_04.d.ts +0 -245
- package/dist/types/ship/interfaces/ISHIP_05.d.ts +0 -234
- package/dist/types/ship/interfaces/ISHIP_06.d.ts +0 -522
- /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}/db.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}/db.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/interfaces → interfaces}/shogun.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/storage → storage}/storage.d.ts +0 -0
- /package/dist/types/{src/types → types}/events.d.ts +0 -0
- /package/dist/types/{src/types → types}/shogun.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,615 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env tsx
|
|
2
|
-
"use strict";
|
|
3
|
-
/**
|
|
4
|
-
* SHIP-05 Storage CLI Example
|
|
5
|
-
*
|
|
6
|
-
* Interactive CLI demonstrating SHIP-05 encrypted file storage on IPFS
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* yarn storage <username> <password>
|
|
10
|
-
*
|
|
11
|
-
* Features:
|
|
12
|
-
* - Encrypted file upload to IPFS (uses SEA from SHIP-00)
|
|
13
|
-
* - Multiple IPFS services (Pinata, IPFS Client, Custom Gateway)
|
|
14
|
-
* - File download and decryption
|
|
15
|
-
* - File metadata management
|
|
16
|
-
* - Storage statistics
|
|
17
|
-
*/
|
|
18
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
19
|
-
if (k2 === undefined) k2 = k;
|
|
20
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
21
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
22
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
23
|
-
}
|
|
24
|
-
Object.defineProperty(o, k2, desc);
|
|
25
|
-
}) : (function(o, m, k, k2) {
|
|
26
|
-
if (k2 === undefined) k2 = k;
|
|
27
|
-
o[k2] = m[k];
|
|
28
|
-
}));
|
|
29
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
-
}) : function(o, v) {
|
|
32
|
-
o["default"] = v;
|
|
33
|
-
});
|
|
34
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
35
|
-
var ownKeys = function(o) {
|
|
36
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
37
|
-
var ar = [];
|
|
38
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
39
|
-
return ar;
|
|
40
|
-
};
|
|
41
|
-
return ownKeys(o);
|
|
42
|
-
};
|
|
43
|
-
return function (mod) {
|
|
44
|
-
if (mod && mod.__esModule) return mod;
|
|
45
|
-
var result = {};
|
|
46
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
47
|
-
__setModuleDefault(result, mod);
|
|
48
|
-
return result;
|
|
49
|
-
};
|
|
50
|
-
})();
|
|
51
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
-
exports.StorageCLI = void 0;
|
|
53
|
-
const SHIP_00_1 = require("../implementation/SHIP_00");
|
|
54
|
-
const SHIP_05_1 = require("../implementation/SHIP_05");
|
|
55
|
-
const readline = __importStar(require("readline"));
|
|
56
|
-
const fs = __importStar(require("fs"));
|
|
57
|
-
// ============================================================================
|
|
58
|
-
// CLI Interface
|
|
59
|
-
// ============================================================================
|
|
60
|
-
class StorageCLI {
|
|
61
|
-
constructor() {
|
|
62
|
-
this.username = "";
|
|
63
|
-
this.running = false;
|
|
64
|
-
// IPFS configuration
|
|
65
|
-
this.ipfsService = "CUSTOM";
|
|
66
|
-
this.ipfsConfig = {};
|
|
67
|
-
this.configFile = ".shogun-ipfs-config.json";
|
|
68
|
-
// Initialize SHIP-00 with peers
|
|
69
|
-
this.identity = new SHIP_00_1.SHIP_00({
|
|
70
|
-
gunOptions: {
|
|
71
|
-
peers: [
|
|
72
|
-
"https://peer.wallie.io/gun",
|
|
73
|
-
"https://v5g5jseqhgkp43lppgregcfbvi.srv.us/gun",
|
|
74
|
-
"https://relay.shogun-eco.xyz/gun",
|
|
75
|
-
],
|
|
76
|
-
radisk: true,
|
|
77
|
-
localStorage: false,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
// Will initialize SHIP-05 after login
|
|
81
|
-
this.storage = null;
|
|
82
|
-
this.rl = readline.createInterface({
|
|
83
|
-
input: process.stdin,
|
|
84
|
-
output: process.stdout,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
// ==========================================================================
|
|
88
|
-
// Authentication
|
|
89
|
-
// ==========================================================================
|
|
90
|
-
async login(username, password) {
|
|
91
|
-
console.log(`\n🔐 Logging in as ${username}...`);
|
|
92
|
-
try {
|
|
93
|
-
// Login with SHIP-00
|
|
94
|
-
let result = await this.identity.login(username, password);
|
|
95
|
-
if (!result.success) {
|
|
96
|
-
console.log("📝 User not found, creating new identity...");
|
|
97
|
-
const signupResult = await this.identity.signup(username, password);
|
|
98
|
-
if (!signupResult.success) {
|
|
99
|
-
console.error(`❌ Registration failed: ${signupResult.error}`);
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
103
|
-
result = await this.identity.login(username, password);
|
|
104
|
-
}
|
|
105
|
-
if (result.success) {
|
|
106
|
-
this.username = username;
|
|
107
|
-
console.log("\n✅ Authentication Successful!");
|
|
108
|
-
console.log("━".repeat(60));
|
|
109
|
-
console.log(` Username: ${username}`);
|
|
110
|
-
console.log(` Public Key: ${result.userPub?.substring(0, 40)}...`);
|
|
111
|
-
console.log(` Derived Address: ${result.derivedAddress}`);
|
|
112
|
-
console.log("━".repeat(60));
|
|
113
|
-
// Publish public key
|
|
114
|
-
await this.identity.publishPublicKey();
|
|
115
|
-
console.log("✅ Public key published!");
|
|
116
|
-
// Configure IPFS storage
|
|
117
|
-
await this.configureIPFS();
|
|
118
|
-
// Initialize SHIP-05
|
|
119
|
-
console.log("\n🔐 Initializing SHIP-05 (Storage)...");
|
|
120
|
-
console.log(` Service: ${this.ipfsService}`);
|
|
121
|
-
console.log(" Using SEA keypair from SHIP-00 for encryption");
|
|
122
|
-
this.storage = new SHIP_05_1.SHIP_05(this.identity, {
|
|
123
|
-
ipfsService: this.ipfsService,
|
|
124
|
-
ipfsConfig: this.ipfsConfig,
|
|
125
|
-
maxFileSizeMB: 100,
|
|
126
|
-
});
|
|
127
|
-
await this.storage.initialize();
|
|
128
|
-
console.log("✅ SHIP-05 initialized!");
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
console.error(`❌ Login failed: ${result.error}`);
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
console.error(`❌ Error: ${error.message}`);
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
// ==========================================================================
|
|
142
|
-
// IPFS Configuration
|
|
143
|
-
// ==========================================================================
|
|
144
|
-
async configureIPFS() {
|
|
145
|
-
// Try to load existing config
|
|
146
|
-
if (this.loadIPFSConfig()) {
|
|
147
|
-
console.log(`\n✅ Loaded IPFS config: ${this.ipfsService}`);
|
|
148
|
-
const reconfig = await this.prompt("Use saved config? (y/n, default: y): ");
|
|
149
|
-
if (reconfig.toLowerCase().trim() !== "n") {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
console.log("\n📦 Configure IPFS Storage");
|
|
154
|
-
console.log("━".repeat(60));
|
|
155
|
-
console.log("Available services:");
|
|
156
|
-
console.log("1. Pinata (recommended - managed IPFS)");
|
|
157
|
-
console.log("2. IPFS Client (local node)");
|
|
158
|
-
console.log("3. Custom Gateway");
|
|
159
|
-
console.log("━".repeat(60));
|
|
160
|
-
const choice = await this.prompt("Choose IPFS service (1-3, default: 3): ");
|
|
161
|
-
switch (choice.trim() || "3") {
|
|
162
|
-
case "1":
|
|
163
|
-
await this.configurePinata();
|
|
164
|
-
break;
|
|
165
|
-
case "2":
|
|
166
|
-
await this.configureIPFSClient();
|
|
167
|
-
break;
|
|
168
|
-
case "3":
|
|
169
|
-
default:
|
|
170
|
-
await this.configureCustomGateway();
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
// Save config
|
|
174
|
-
this.saveIPFSConfig();
|
|
175
|
-
}
|
|
176
|
-
async configurePinata() {
|
|
177
|
-
console.log("\n🔑 Pinata Configuration");
|
|
178
|
-
console.log("━".repeat(60));
|
|
179
|
-
console.log("Get your JWT from: https://app.pinata.cloud/");
|
|
180
|
-
const jwt = await this.prompt("Pinata JWT (or press Enter to skip): ");
|
|
181
|
-
if (jwt.trim()) {
|
|
182
|
-
this.ipfsService = "PINATA";
|
|
183
|
-
this.ipfsConfig = {
|
|
184
|
-
pinataJwt: jwt.trim(),
|
|
185
|
-
pinataGateway: "https://gateway.pinata.cloud",
|
|
186
|
-
};
|
|
187
|
-
console.log("✅ Pinata configured!");
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
console.log("⚠️ No JWT provided, using public IPFS gateway");
|
|
191
|
-
await this.configureCustomGateway();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
async configureIPFSClient() {
|
|
195
|
-
console.log("\n🖥️ IPFS Client Configuration");
|
|
196
|
-
console.log("━".repeat(60));
|
|
197
|
-
console.log("💡 For local IPFS node: http://localhost:5001");
|
|
198
|
-
console.log("⚠️ For Shogun Relay, use option 3 (Custom Gateway) instead!");
|
|
199
|
-
const url = await this.prompt("\nIPFS API URL (default: http://localhost:5001): ");
|
|
200
|
-
this.ipfsService = "IPFS-CLIENT";
|
|
201
|
-
this.ipfsConfig = {
|
|
202
|
-
url: url.trim() || "http://localhost:5001",
|
|
203
|
-
};
|
|
204
|
-
console.log(`✅ IPFS Client configured: ${this.ipfsConfig.url}`);
|
|
205
|
-
}
|
|
206
|
-
async configureCustomGateway() {
|
|
207
|
-
console.log("\n🌐 Custom Gateway/Relay Configuration");
|
|
208
|
-
console.log("━".repeat(60));
|
|
209
|
-
console.log("💡 Examples:");
|
|
210
|
-
console.log(" Shogun Relay (local): http://localhost:3000/api/v1/ipfs");
|
|
211
|
-
console.log(" Shogun Relay (remote): https://relay.shogun-eco.xyz/api/v1/ipfs");
|
|
212
|
-
console.log(" Public IPFS Gateway: https://ipfs.io");
|
|
213
|
-
console.log("━".repeat(60));
|
|
214
|
-
console.log("⚠️ BASE URL only - don't include /upload or /add!");
|
|
215
|
-
console.log(" The system will automatically try /upload then /add");
|
|
216
|
-
const url = await this.prompt("\nGateway/Relay URL: ");
|
|
217
|
-
const token = await this.prompt("Auth Token (REQUIRED for relay): ");
|
|
218
|
-
this.ipfsService = "CUSTOM";
|
|
219
|
-
this.ipfsConfig = {
|
|
220
|
-
customApiUrl: url.trim() || "https://ipfs.io",
|
|
221
|
-
};
|
|
222
|
-
if (token.trim()) {
|
|
223
|
-
this.ipfsConfig.customToken = token.trim();
|
|
224
|
-
console.log(`✅ Auth token configured: ${token.substring(0, 5)}...`);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
console.log("⚠️ WARNING: No auth token - relay uploads will fail!");
|
|
228
|
-
}
|
|
229
|
-
console.log(`✅ Custom gateway configured: ${this.ipfsConfig.customApiUrl}`);
|
|
230
|
-
}
|
|
231
|
-
saveIPFSConfig() {
|
|
232
|
-
try {
|
|
233
|
-
const config = {
|
|
234
|
-
service: this.ipfsService,
|
|
235
|
-
config: this.ipfsConfig,
|
|
236
|
-
};
|
|
237
|
-
fs.writeFileSync(this.configFile, JSON.stringify(config, null, 2));
|
|
238
|
-
console.log(`💾 IPFS config saved to ${this.configFile}`);
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
console.warn("⚠️ Could not save config:", error);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
loadIPFSConfig() {
|
|
245
|
-
try {
|
|
246
|
-
if (fs.existsSync(this.configFile)) {
|
|
247
|
-
const data = fs.readFileSync(this.configFile, 'utf-8');
|
|
248
|
-
const config = JSON.parse(data);
|
|
249
|
-
this.ipfsService = config.service;
|
|
250
|
-
this.ipfsConfig = config.config;
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
catch (error) {
|
|
255
|
-
console.warn("⚠️ Could not load config:", error);
|
|
256
|
-
}
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
// ==========================================================================
|
|
260
|
-
// File Operations
|
|
261
|
-
// ==========================================================================
|
|
262
|
-
async uploadFile() {
|
|
263
|
-
console.log("\n📤 Upload File to IPFS");
|
|
264
|
-
console.log("━".repeat(60));
|
|
265
|
-
const filepath = await this.prompt("Enter file path: ");
|
|
266
|
-
if (!filepath.trim()) {
|
|
267
|
-
console.log("❌ File path required");
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
// Check if file exists
|
|
271
|
-
if (!fs.existsSync(filepath.trim())) {
|
|
272
|
-
console.log(`❌ File not found: ${filepath}`);
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const encryptStr = await this.prompt("Encrypt file? (y/n, default: y): ");
|
|
276
|
-
const encrypt = encryptStr.toLowerCase().trim() !== "n";
|
|
277
|
-
try {
|
|
278
|
-
console.log("\n🔄 Reading file...");
|
|
279
|
-
const fileBuffer = fs.readFileSync(filepath.trim());
|
|
280
|
-
const filename = filepath.split("/").pop() || filepath.split("\\").pop() || "file";
|
|
281
|
-
console.log(`📁 File: ${filename}`);
|
|
282
|
-
console.log(`📊 Size: ${(fileBuffer.length / 1024 / 1024).toFixed(2)} MB`);
|
|
283
|
-
console.log(`🔐 Encrypt: ${encrypt ? "YES" : "NO"}`);
|
|
284
|
-
console.log("\n⏳ Uploading to IPFS...");
|
|
285
|
-
const result = await this.storage.uploadFile(fileBuffer, { encrypt });
|
|
286
|
-
if (result.success) {
|
|
287
|
-
console.log("\n✅ Upload Successful!");
|
|
288
|
-
console.log("━".repeat(60));
|
|
289
|
-
console.log(` IPFS Hash: ${result.hash}`);
|
|
290
|
-
console.log(` Size: ${((result.size || 0) / 1024 / 1024).toFixed(2)} MB`);
|
|
291
|
-
console.log(` Encrypted: ${result.encrypted ? "YES" : "NO"}`);
|
|
292
|
-
console.log("━".repeat(60));
|
|
293
|
-
// Save hash to file for easy retrieval
|
|
294
|
-
const hashFile = `ipfs-hash-${Date.now()}.txt`;
|
|
295
|
-
fs.writeFileSync(hashFile, result.hash || "");
|
|
296
|
-
console.log(`\n💾 Hash saved to: ${hashFile}`);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
console.error(`❌ Upload failed: ${result.error}`);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
catch (error) {
|
|
303
|
-
console.error(`❌ Error: ${error.message}`);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
async downloadFile() {
|
|
307
|
-
console.log("\n📥 Download File from IPFS");
|
|
308
|
-
console.log("━".repeat(60));
|
|
309
|
-
const hash = await this.prompt("Enter IPFS hash: ");
|
|
310
|
-
if (!hash.trim()) {
|
|
311
|
-
console.log("❌ IPFS hash required");
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
const decryptStr = await this.prompt("Decrypt file? (y/n, default: y): ");
|
|
315
|
-
const decrypt = decryptStr.toLowerCase().trim() !== "n";
|
|
316
|
-
try {
|
|
317
|
-
console.log("\n⏳ Downloading from IPFS...");
|
|
318
|
-
console.log(`📍 Hash: ${hash.trim()}`);
|
|
319
|
-
console.log(`🔓 Decrypt: ${decrypt ? "YES" : "NO"}`);
|
|
320
|
-
const data = await this.storage.downloadFile(hash.trim(), {
|
|
321
|
-
decrypt,
|
|
322
|
-
returnBlob: true,
|
|
323
|
-
});
|
|
324
|
-
if (data) {
|
|
325
|
-
// Save to file
|
|
326
|
-
const outputFile = `downloaded-${hash.substring(0, 10)}-${Date.now()}.bin`;
|
|
327
|
-
if (data instanceof Blob) {
|
|
328
|
-
const buffer = Buffer.from(await data.arrayBuffer());
|
|
329
|
-
fs.writeFileSync(outputFile, buffer);
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
fs.writeFileSync(outputFile, data);
|
|
333
|
-
}
|
|
334
|
-
console.log("\n✅ Download Successful!");
|
|
335
|
-
console.log("━".repeat(60));
|
|
336
|
-
console.log(` Saved to: ${outputFile}`);
|
|
337
|
-
console.log(` Size: ${fs.statSync(outputFile).size} bytes`);
|
|
338
|
-
console.log("━".repeat(60));
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
console.log("❌ Download failed - file not found");
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
catch (error) {
|
|
345
|
-
console.error(`❌ Error: ${error.message}`);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
async viewUserFiles() {
|
|
349
|
-
console.log("\n📂 Your Files");
|
|
350
|
-
console.log("━".repeat(60));
|
|
351
|
-
try {
|
|
352
|
-
const files = await this.storage.getUserFiles();
|
|
353
|
-
if (files.length === 0) {
|
|
354
|
-
console.log("No files uploaded yet");
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
console.log(`Found ${files.length} files:\n`);
|
|
358
|
-
files.forEach((file, i) => {
|
|
359
|
-
console.log(`${i + 1}. ${file.name}`);
|
|
360
|
-
console.log(` Hash: ${file.hash}`);
|
|
361
|
-
console.log(` Size: ${file.sizeMB} MB`);
|
|
362
|
-
console.log(` Encrypted: ${file.encrypted ? "YES 🔒" : "NO"}`);
|
|
363
|
-
console.log(` Uploaded: ${new Date(file.uploadedAt).toLocaleString()}`);
|
|
364
|
-
console.log("");
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
catch (error) {
|
|
368
|
-
console.error(`❌ Error: ${error.message}`);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
async deleteFile() {
|
|
372
|
-
console.log("\n🗑️ Delete File");
|
|
373
|
-
console.log("━".repeat(60));
|
|
374
|
-
const hash = await this.prompt("Enter IPFS hash to delete: ");
|
|
375
|
-
if (!hash.trim()) {
|
|
376
|
-
console.log("❌ IPFS hash required");
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
const confirm = await this.prompt("Are you sure? (yes/no): ");
|
|
380
|
-
if (confirm.toLowerCase() !== "yes") {
|
|
381
|
-
console.log("❌ Deletion cancelled");
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
try {
|
|
385
|
-
const result = await this.storage.deleteFile(hash.trim());
|
|
386
|
-
if (result.success) {
|
|
387
|
-
console.log("✅ File deleted successfully");
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
console.error(`❌ Deletion failed: ${result.error}`);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
catch (error) {
|
|
394
|
-
console.error(`❌ Error: ${error.message}`);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
async showStorageStats() {
|
|
398
|
-
console.log("\n📊 Storage Statistics");
|
|
399
|
-
console.log("━".repeat(60));
|
|
400
|
-
try {
|
|
401
|
-
const stats = await this.storage.getStorageStats();
|
|
402
|
-
console.log(` Total Files: ${stats.totalFiles}`);
|
|
403
|
-
console.log(` Total Size: ${stats.totalMB.toFixed(2)} MB`);
|
|
404
|
-
console.log(` Encrypted: ${stats.encryptedFiles} 🔒`);
|
|
405
|
-
console.log(` Plain: ${stats.plainFiles} 📄`);
|
|
406
|
-
console.log("━".repeat(60));
|
|
407
|
-
}
|
|
408
|
-
catch (error) {
|
|
409
|
-
console.error(`❌ Error: ${error.message}`);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
async testEncryption() {
|
|
413
|
-
console.log("\n🔐 Test SEA Encryption System");
|
|
414
|
-
console.log("━".repeat(60));
|
|
415
|
-
try {
|
|
416
|
-
// Test data
|
|
417
|
-
const testData = "Hello, SHIP-05! This is a secret message.";
|
|
418
|
-
console.log(`\n📝 Original data: "${testData}"`);
|
|
419
|
-
// Encrypt using SEA (from SHIP-00)
|
|
420
|
-
console.log("🔐 Encrypting with SEA keypair...");
|
|
421
|
-
const encrypted = await this.storage.encryptData(testData);
|
|
422
|
-
console.log(` Encrypted: ${encrypted.substring(0, 60)}...`);
|
|
423
|
-
// Decrypt using SEA
|
|
424
|
-
console.log("🔓 Decrypting with SEA keypair...");
|
|
425
|
-
const decrypted = await this.storage.decryptData(encrypted);
|
|
426
|
-
console.log(` Decrypted: "${decrypted}"`);
|
|
427
|
-
// Verify
|
|
428
|
-
if (testData === decrypted) {
|
|
429
|
-
console.log("\n✅ SEA Encryption test PASSED!");
|
|
430
|
-
console.log(" Using SHIP-00 keypair for encryption/decryption");
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
console.log("\n❌ Encryption test FAILED!");
|
|
434
|
-
}
|
|
435
|
-
console.log("━".repeat(60));
|
|
436
|
-
}
|
|
437
|
-
catch (error) {
|
|
438
|
-
console.error(`❌ Error: ${error.message}`);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
// ==========================================================================
|
|
442
|
-
// Menu
|
|
443
|
-
// ==========================================================================
|
|
444
|
-
async showMenu() {
|
|
445
|
-
while (this.running) {
|
|
446
|
-
console.log("\n🗡️ SHIP-05 Storage Manager");
|
|
447
|
-
console.log("━".repeat(60));
|
|
448
|
-
console.log("1. Upload File (Encrypted)");
|
|
449
|
-
console.log("2. Download File");
|
|
450
|
-
console.log("3. View Your Files");
|
|
451
|
-
console.log("4. Delete File");
|
|
452
|
-
console.log("5. Storage Statistics");
|
|
453
|
-
console.log("6. Test Encryption System");
|
|
454
|
-
console.log("7. Change IPFS Service");
|
|
455
|
-
console.log("8. Logout");
|
|
456
|
-
console.log("9. Exit");
|
|
457
|
-
console.log("━".repeat(60));
|
|
458
|
-
console.log("\n💡 For on-chain storage tracking, see SHIP-06 (coming soon)");
|
|
459
|
-
const choice = await this.prompt("\nChoose option: ");
|
|
460
|
-
switch (choice.trim()) {
|
|
461
|
-
case "1":
|
|
462
|
-
await this.uploadFile();
|
|
463
|
-
break;
|
|
464
|
-
case "2":
|
|
465
|
-
await this.downloadFile();
|
|
466
|
-
break;
|
|
467
|
-
case "3":
|
|
468
|
-
await this.viewUserFiles();
|
|
469
|
-
break;
|
|
470
|
-
case "4":
|
|
471
|
-
await this.deleteFile();
|
|
472
|
-
break;
|
|
473
|
-
case "5":
|
|
474
|
-
await this.showStorageStats();
|
|
475
|
-
break;
|
|
476
|
-
case "6":
|
|
477
|
-
await this.testEncryption();
|
|
478
|
-
break;
|
|
479
|
-
case "7":
|
|
480
|
-
await this.reconfigureIPFS();
|
|
481
|
-
break;
|
|
482
|
-
case "8":
|
|
483
|
-
await this.logout();
|
|
484
|
-
break;
|
|
485
|
-
case "9":
|
|
486
|
-
this.running = false;
|
|
487
|
-
console.log("\n👋 Goodbye!");
|
|
488
|
-
this.cleanup();
|
|
489
|
-
return;
|
|
490
|
-
default:
|
|
491
|
-
console.log("❌ Invalid choice");
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
async reconfigureIPFS() {
|
|
496
|
-
console.log("\n🔄 Reconfigure IPFS Service");
|
|
497
|
-
console.log(` Current: ${this.ipfsService}`);
|
|
498
|
-
// Force reconfiguration
|
|
499
|
-
console.log("\n📦 Configure IPFS Storage");
|
|
500
|
-
console.log("━".repeat(60));
|
|
501
|
-
console.log("Available services:");
|
|
502
|
-
console.log("1. Pinata (recommended - managed IPFS)");
|
|
503
|
-
console.log("2. IPFS Client (local node)");
|
|
504
|
-
console.log("3. Custom Gateway");
|
|
505
|
-
console.log("━".repeat(60));
|
|
506
|
-
const choice = await this.prompt("Choose IPFS service (1-3): ");
|
|
507
|
-
switch (choice.trim()) {
|
|
508
|
-
case "1":
|
|
509
|
-
await this.configurePinata();
|
|
510
|
-
break;
|
|
511
|
-
case "2":
|
|
512
|
-
await this.configureIPFSClient();
|
|
513
|
-
break;
|
|
514
|
-
case "3":
|
|
515
|
-
await this.configureCustomGateway();
|
|
516
|
-
break;
|
|
517
|
-
default:
|
|
518
|
-
console.log("❌ Invalid choice");
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
// Save new config
|
|
522
|
-
this.saveIPFSConfig();
|
|
523
|
-
// Re-initialize SHIP-05 with new config
|
|
524
|
-
this.storage = new SHIP_05_1.SHIP_05(this.identity, {
|
|
525
|
-
ipfsService: this.ipfsService,
|
|
526
|
-
ipfsConfig: this.ipfsConfig,
|
|
527
|
-
maxFileSizeMB: 100,
|
|
528
|
-
});
|
|
529
|
-
await this.storage.initialize();
|
|
530
|
-
console.log("✅ IPFS service updated!");
|
|
531
|
-
}
|
|
532
|
-
async logout() {
|
|
533
|
-
this.identity.logout();
|
|
534
|
-
this.username = "";
|
|
535
|
-
console.log("\n✅ Logged out successfully");
|
|
536
|
-
}
|
|
537
|
-
// ==========================================================================
|
|
538
|
-
// Utilities
|
|
539
|
-
// ==========================================================================
|
|
540
|
-
printHeader() {
|
|
541
|
-
console.log("\n╔" + "═".repeat(58) + "╗");
|
|
542
|
-
console.log("║" + " ".repeat(10) + "🗡️ SHOGUN STORAGE (SHIP-05) 🗡️" + " ".repeat(10) + "║");
|
|
543
|
-
console.log("║" + " ".repeat(8) + "Encrypted Decentralized File Storage" + " ".repeat(8) + "║");
|
|
544
|
-
console.log("╚" + "═".repeat(58) + "╝");
|
|
545
|
-
}
|
|
546
|
-
async prompt(question) {
|
|
547
|
-
return new Promise((resolve) => {
|
|
548
|
-
this.rl.question(question, (answer) => {
|
|
549
|
-
resolve(answer);
|
|
550
|
-
});
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
cleanup() {
|
|
554
|
-
this.rl.close();
|
|
555
|
-
process.exit(0);
|
|
556
|
-
}
|
|
557
|
-
async start(username, password) {
|
|
558
|
-
this.printHeader();
|
|
559
|
-
if (username && password) {
|
|
560
|
-
// Auto-login
|
|
561
|
-
const success = await this.login(username, password);
|
|
562
|
-
if (success) {
|
|
563
|
-
this.running = true;
|
|
564
|
-
await this.showMenu();
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
console.log("\n❌ Authentication failed");
|
|
568
|
-
this.cleanup();
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
else {
|
|
572
|
-
// Manual login
|
|
573
|
-
console.log("\n💡 Commands:");
|
|
574
|
-
console.log(" yarn storage <username> <password> - Auto-login");
|
|
575
|
-
console.log(" yarn storage - Manual login");
|
|
576
|
-
const user = await this.prompt("\nUsername: ");
|
|
577
|
-
const pass = await this.prompt("Password: ");
|
|
578
|
-
const success = await this.login(user, pass);
|
|
579
|
-
if (success) {
|
|
580
|
-
this.running = true;
|
|
581
|
-
await this.showMenu();
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
this.cleanup();
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
exports.StorageCLI = StorageCLI;
|
|
590
|
-
// ============================================================================
|
|
591
|
-
// Main Entry Point
|
|
592
|
-
// ============================================================================
|
|
593
|
-
async function main() {
|
|
594
|
-
const args = process.argv.slice(2);
|
|
595
|
-
const cli = new StorageCLI();
|
|
596
|
-
try {
|
|
597
|
-
if (args.length >= 2) {
|
|
598
|
-
// Auto-login mode
|
|
599
|
-
const [username, password] = args;
|
|
600
|
-
await cli.start(username, password);
|
|
601
|
-
}
|
|
602
|
-
else {
|
|
603
|
-
// Manual login mode
|
|
604
|
-
await cli.start();
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
catch (error) {
|
|
608
|
-
console.error("\n❌ Error:", error);
|
|
609
|
-
process.exit(1);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
// Run if called directly
|
|
613
|
-
if (require.main === module) {
|
|
614
|
-
main();
|
|
615
|
-
}
|