epistery 1.0.3 → 1.0.4
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/CLI.md +40 -64
- package/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/api.d.ts +0 -2
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js +0 -130
- package/dist/api.js.map +0 -1
- package/dist/controllers/baseController.d.ts +0 -8
- package/dist/controllers/baseController.d.ts.map +0 -1
- package/dist/controllers/baseController.js +0 -25
- package/dist/controllers/baseController.js.map +0 -1
- package/dist/controllers/create/CreateController.d.ts +0 -6
- package/dist/controllers/create/CreateController.d.ts.map +0 -1
- package/dist/controllers/create/CreateController.js +0 -17
- package/dist/controllers/create/CreateController.js.map +0 -1
- package/dist/controllers/ssl/SSLController.d.ts +0 -17
- package/dist/controllers/ssl/SSLController.d.ts.map +0 -1
- package/dist/controllers/ssl/SSLController.js +0 -129
- package/dist/controllers/ssl/SSLController.js.map +0 -1
- package/dist/controllers/status/StatusController.d.ts +0 -6
- package/dist/controllers/status/StatusController.d.ts.map +0 -1
- package/dist/controllers/status/StatusController.js +0 -29
- package/dist/controllers/status/StatusController.js.map +0 -1
- package/dist/controllers/write/WriteController.d.ts +0 -7
- package/dist/controllers/write/WriteController.d.ts.map +0 -1
- package/dist/controllers/write/WriteController.js +0 -50
- package/dist/controllers/write/WriteController.js.map +0 -1
package/CLI.md
CHANGED
|
@@ -11,7 +11,7 @@ epistery initialize localhost
|
|
|
11
11
|
# Set as default
|
|
12
12
|
epistery set-default localhost
|
|
13
13
|
|
|
14
|
-
# Make authenticated requests
|
|
14
|
+
# Make authenticated requests
|
|
15
15
|
epistery curl https://wiki.rootz.global/wiki/Home
|
|
16
16
|
```
|
|
17
17
|
|
|
@@ -30,14 +30,13 @@ epistery initialize wiki.rootz.global
|
|
|
30
30
|
|
|
31
31
|
### `epistery curl [options] <url>`
|
|
32
32
|
|
|
33
|
-
Make authenticated HTTP
|
|
33
|
+
Make authenticated HTTP requests using bot authentication (signs each request with wallet).
|
|
34
34
|
|
|
35
35
|
**Options:**
|
|
36
|
-
- `-w, --wallet <domain>` - Use specific domain (overrides default)
|
|
36
|
+
- `-w, --wallet <domain>` - Use specific domain wallet (overrides default)
|
|
37
37
|
- `-X, --request <method>` - HTTP method (default: GET)
|
|
38
|
-
- `-d, --data <data>` - Request body data
|
|
38
|
+
- `-d, --data <data>` - Request body data (must be quoted JSON string)
|
|
39
39
|
- `-H, --header <header>` - Additional headers
|
|
40
|
-
- `-b, --bot` - Use bot auth header (default: session cookie)
|
|
41
40
|
- `-v, --verbose` - Show detailed output
|
|
42
41
|
|
|
43
42
|
**Examples:**
|
|
@@ -45,16 +44,24 @@ Make authenticated HTTP request. Automatically performs key exchange on first us
|
|
|
45
44
|
# GET request (uses default domain)
|
|
46
45
|
epistery curl https://wiki.rootz.global/wiki/Home
|
|
47
46
|
|
|
48
|
-
# Use specific domain
|
|
49
|
-
epistery curl -w localhost https://localhost:4080/
|
|
47
|
+
# Use specific domain wallet
|
|
48
|
+
epistery curl -w localhost https://localhost:4080/wiki/Home
|
|
49
|
+
|
|
50
|
+
# PUT request with JSON data (note single quotes around JSON)
|
|
51
|
+
epistery curl -X PUT -d '{"title":"Test","body":"# Test"}' https://wiki.rootz.global/wiki/Test
|
|
50
52
|
|
|
51
53
|
# POST request
|
|
52
|
-
epistery curl -X POST -d '{"
|
|
54
|
+
epistery curl -X POST -d '{"name":"value"}' https://api.example.com/endpoint
|
|
53
55
|
|
|
54
|
-
#
|
|
55
|
-
epistery curl
|
|
56
|
+
# Verbose output for debugging
|
|
57
|
+
epistery curl -v https://wiki.rootz.global/wiki/Home
|
|
56
58
|
```
|
|
57
59
|
|
|
60
|
+
**Important Notes:**
|
|
61
|
+
- Always use **single quotes** around JSON data to prevent shell interpretation
|
|
62
|
+
- The CLI uses bot authentication mode (signs each request individually)
|
|
63
|
+
- No session management - each request is independently authenticated
|
|
64
|
+
|
|
58
65
|
### `epistery info [domain]`
|
|
59
66
|
|
|
60
67
|
Show domain information (wallet address, provider, session status).
|
|
@@ -84,35 +91,26 @@ Epistery CLI uses the same domain configuration system as the server:
|
|
|
84
91
|
│ └── [cli]
|
|
85
92
|
│ └── default_domain=localhost
|
|
86
93
|
├── localhost/
|
|
87
|
-
│
|
|
88
|
-
│ └── session.json # Session cookie (auto-created)
|
|
94
|
+
│ └── config.ini # Domain config with wallet & provider
|
|
89
95
|
└── wiki.rootz.global/
|
|
90
|
-
|
|
91
|
-
└── session.json
|
|
96
|
+
└── config.ini
|
|
92
97
|
```
|
|
93
98
|
|
|
94
|
-
### Authentication
|
|
95
|
-
|
|
96
|
-
**Session Cookie (Default):**
|
|
97
|
-
- Performs key exchange once, saves session cookie
|
|
98
|
-
- Subsequent requests use cookie
|
|
99
|
-
- Best for multiple requests to same server
|
|
100
|
-
|
|
101
|
-
**Bot Auth Header (`--bot`):**
|
|
102
|
-
- Signs each request individually
|
|
103
|
-
- No session management
|
|
104
|
-
- Best for distributed systems or one-off requests
|
|
99
|
+
### Authentication
|
|
105
100
|
|
|
106
|
-
|
|
101
|
+
The CLI uses **bot authentication mode**, which signs each request individually with the domain wallet's private key:
|
|
107
102
|
|
|
108
|
-
|
|
103
|
+
1. Load domain wallet from `~/.epistery/{domain}/config.ini`
|
|
104
|
+
2. Create authentication message with current timestamp
|
|
105
|
+
3. Sign message with wallet's private key
|
|
106
|
+
4. Send signature in `Authorization: Bot <base64-encoded-json>` header
|
|
107
|
+
5. Server verifies signature and authenticates request
|
|
109
108
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
No manual "connect" step required!
|
|
109
|
+
**Benefits:**
|
|
110
|
+
- Stateless - no session management needed
|
|
111
|
+
- Secure - private keys never leave your machine
|
|
112
|
+
- Simple - works immediately after initialization
|
|
113
|
+
- Reliable - each request is independently authenticated
|
|
116
114
|
|
|
117
115
|
## Usage Patterns
|
|
118
116
|
|
|
@@ -202,32 +200,19 @@ name=polkadot-hub-testnet
|
|
|
202
200
|
rpc=https://testnet-passet-hub-eth-rpc.polkadot.io
|
|
203
201
|
```
|
|
204
202
|
|
|
205
|
-
### Session File (`~/.epistery/{domain}/session.json`)
|
|
206
|
-
|
|
207
|
-
Auto-created by `epistery curl`:
|
|
208
|
-
|
|
209
|
-
```json
|
|
210
|
-
{
|
|
211
|
-
"domain": "https://wiki.rootz.global",
|
|
212
|
-
"cookie": "session_token_here",
|
|
213
|
-
"authenticated": true,
|
|
214
|
-
"timestamp": "2025-01-10T12:00:00.000Z"
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
203
|
## Security
|
|
219
204
|
|
|
220
205
|
- Domain configs stored with 0600 permissions (user only)
|
|
221
206
|
- Private keys never transmitted (only signatures)
|
|
222
207
|
- Each domain has its own isolated wallet
|
|
223
|
-
-
|
|
208
|
+
- Each request is signed with fresh timestamp to prevent replay attacks
|
|
224
209
|
|
|
225
210
|
## Design Philosophy
|
|
226
211
|
|
|
227
212
|
The Epistery CLI uses a unified command structure with subcommands:
|
|
228
213
|
- ✅ Uses existing Epistery domain config system
|
|
229
214
|
- ✅ Consistent with server-side architecture
|
|
230
|
-
- ✅
|
|
215
|
+
- ✅ Bot authentication (stateless, no session management)
|
|
231
216
|
- ✅ Default domain support (less typing)
|
|
232
217
|
- ✅ Simpler mental model (domain = wallet)
|
|
233
218
|
|
|
@@ -259,28 +244,19 @@ epistery curl -w staging.example.com https://staging.example.com/api/status
|
|
|
259
244
|
epistery curl -w prod.example.com https://prod.example.com/api/status
|
|
260
245
|
```
|
|
261
246
|
|
|
262
|
-
### Bot Mode
|
|
263
|
-
|
|
264
|
-
```bash
|
|
265
|
-
# Bot mode doesn't need session, signs each request
|
|
266
|
-
epistery curl --bot https://wiki.rootz.global/session/context
|
|
267
|
-
epistery curl --bot -X POST -d '{"title":"Log","body":"# Entry"}' https://wiki.rootz.global/wiki/Log
|
|
268
|
-
```
|
|
269
|
-
|
|
270
247
|
## Troubleshooting
|
|
271
248
|
|
|
272
249
|
**"Domain not found or has no wallet"**
|
|
273
250
|
- Run `epistery initialize <domain>` first
|
|
274
251
|
|
|
275
|
-
**
|
|
276
|
-
-
|
|
277
|
-
-
|
|
278
|
-
- Use `-v` flag for detailed output
|
|
252
|
+
**401 Unauthorized errors**
|
|
253
|
+
- Server may not recognize your wallet address
|
|
254
|
+
- Check that your address is authorized on the server
|
|
255
|
+
- Use `-v` flag for detailed debugging output
|
|
279
256
|
|
|
280
|
-
**
|
|
281
|
-
-
|
|
282
|
-
-
|
|
283
|
-
- Check server configuration
|
|
257
|
+
**JSON parsing errors**
|
|
258
|
+
- Ensure JSON data is wrapped in **single quotes**: `'{"key":"value"}'`
|
|
259
|
+
- Check that JSON is valid (use a JSON validator if needed)
|
|
284
260
|
|
|
285
261
|
## Integration
|
|
286
262
|
|
package/index.mjs
CHANGED
|
@@ -203,7 +203,7 @@ class EpisteryAttach {
|
|
|
203
203
|
return res.status(401).json({ error: 'Key exchange failed - invalid client credentials' });
|
|
204
204
|
}
|
|
205
205
|
const clientInfo = {
|
|
206
|
-
address: req.body.clientAddress
|
|
206
|
+
address: req.body.clientAddress,
|
|
207
207
|
publicKey:req.body.clientPublicKey
|
|
208
208
|
}
|
|
209
209
|
if (this.options.authentication) {
|
package/package.json
CHANGED
package/dist/api.d.ts
DELETED
package/dist/api.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":""}
|
package/dist/api.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const dotenv = __importStar(require("dotenv"));
|
|
40
|
-
const express_1 = __importDefault(require("express"));
|
|
41
|
-
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
42
|
-
const path_1 = __importDefault(require("path"));
|
|
43
|
-
const fs_1 = __importDefault(require("fs"));
|
|
44
|
-
const index_js_1 = require("./utils/index.js");
|
|
45
|
-
const CreateController_js_1 = require("./controllers/create/CreateController.js");
|
|
46
|
-
const StatusController_js_1 = require("./controllers/status/StatusController.js");
|
|
47
|
-
const WriteController_js_1 = require("./controllers/write/WriteController.js");
|
|
48
|
-
const epistery_1 = require("epistery");
|
|
49
|
-
dotenv.config();
|
|
50
|
-
epistery_1.Epistery.initialize();
|
|
51
|
-
const app = (0, express_1.default)();
|
|
52
|
-
const PORT = process.env.PORT || 3000;
|
|
53
|
-
app.use(express_1.default.json());
|
|
54
|
-
app.use((0, cookie_parser_1.default)());
|
|
55
|
-
// attach to the active domain. The domain is declared by context not by the environment
|
|
56
|
-
app.use(async (req, res, next) => {
|
|
57
|
-
if (req.app.locals.episteryConfig?.domain?.name !== req.hostname) {
|
|
58
|
-
req.app.locals.episteryConfig = index_js_1.Utils.GetConfig();
|
|
59
|
-
index_js_1.Utils.InitServerWallet(req.hostname);
|
|
60
|
-
await app.locals.episteryConfig.loadDomain(req.hostname);
|
|
61
|
-
}
|
|
62
|
-
next();
|
|
63
|
-
});
|
|
64
|
-
const createController = new CreateController_js_1.CreateController();
|
|
65
|
-
const statusController = new StatusController_js_1.StatusController();
|
|
66
|
-
const writeController = new WriteController_js_1.WriteController();
|
|
67
|
-
// Client library routes
|
|
68
|
-
const library = {
|
|
69
|
-
"client.js": "client/client.js",
|
|
70
|
-
"witness.js": "client/witness.js",
|
|
71
|
-
"ethers.js": "client/ethers.js",
|
|
72
|
-
"ethers.min.js": "client/ethers.min.js"
|
|
73
|
-
};
|
|
74
|
-
// Serve client library files
|
|
75
|
-
app.get('/.epistery/lib/:module', (req, res) => {
|
|
76
|
-
const modulePath = library[req.params.module];
|
|
77
|
-
if (!modulePath)
|
|
78
|
-
return res.status(404).send('Library not found');
|
|
79
|
-
const fullPath = path_1.default.resolve(modulePath);
|
|
80
|
-
if (!fs_1.default.existsSync(fullPath))
|
|
81
|
-
return res.status(404).send('File not found');
|
|
82
|
-
const ext = fullPath.slice(fullPath.lastIndexOf('.') + 1);
|
|
83
|
-
const contentTypes = {
|
|
84
|
-
'js': 'text/javascript',
|
|
85
|
-
'mjs': 'text/javascript',
|
|
86
|
-
'css': 'text/css',
|
|
87
|
-
'html': 'text/html',
|
|
88
|
-
'json': 'application/json'
|
|
89
|
-
};
|
|
90
|
-
if (contentTypes[ext]) {
|
|
91
|
-
res.set('Content-Type', contentTypes[ext]);
|
|
92
|
-
}
|
|
93
|
-
res.sendFile(fullPath);
|
|
94
|
-
});
|
|
95
|
-
// HTML status page
|
|
96
|
-
app.get('/.epistery/status.html', (req, res) => {
|
|
97
|
-
const config = index_js_1.Utils.GetConfig();
|
|
98
|
-
const domain = config.activeDomain.domain;
|
|
99
|
-
const serverDomain = index_js_1.Utils.GetDomainInfo(domain);
|
|
100
|
-
if (!serverDomain.wallet) {
|
|
101
|
-
return res.status(500).send('Server wallet not found');
|
|
102
|
-
}
|
|
103
|
-
const status = epistery_1.Epistery.getStatus({}, serverDomain);
|
|
104
|
-
const templatePath = path_1.default.resolve('client/status.html');
|
|
105
|
-
if (!fs_1.default.existsSync(templatePath)) {
|
|
106
|
-
return res.status(404).send('Status template not found');
|
|
107
|
-
}
|
|
108
|
-
let template = fs_1.default.readFileSync(templatePath, 'utf8');
|
|
109
|
-
// Simple template replacement
|
|
110
|
-
template = template.replace(/\{\{server\.domain\}\}/g, domain);
|
|
111
|
-
template = template.replace(/\{\{server\.walletAddress\}\}/g, status.server.walletAddress || '');
|
|
112
|
-
template = template.replace(/\{\{server\.provider\}\}/g, status.server.provider || '');
|
|
113
|
-
template = template.replace(/\{\{server\.chainId\}\}/g, status.server.chainId?.toString() || '');
|
|
114
|
-
template = template.replace(/\{\{timestamp\}\}/g, status.timestamp);
|
|
115
|
-
res.send(template);
|
|
116
|
-
});
|
|
117
|
-
// API routes
|
|
118
|
-
app.get('/.epistery/status', statusController.index.bind(statusController));
|
|
119
|
-
app.get('/.epistery/create', createController.index.bind(createController));
|
|
120
|
-
app.post('/.epistery/data/write', writeController.index.bind(writeController));
|
|
121
|
-
app.listen(PORT, () => {
|
|
122
|
-
console.log(`Server is running on http://localhost:${PORT}`);
|
|
123
|
-
console.log('Available routes:');
|
|
124
|
-
console.log(' GET /.epistery/status');
|
|
125
|
-
console.log(' GET /.epistery/status.html');
|
|
126
|
-
console.log(' GET /.epistery/create');
|
|
127
|
-
console.log(' GET /.epistery/lib/:module');
|
|
128
|
-
console.log(' POST /.epistery/data/write');
|
|
129
|
-
});
|
|
130
|
-
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,sDAAqD;AACrD,kEAAyC;AACzC,gDAAwB;AACxB,4CAAoB;AACpB,+CAAyC;AACzC,kFAA4E;AAC5E,kFAA4E;AAC5E,+EAAyE;AACzE,uCAAoC;AAEpC,MAAM,CAAC,MAAM,EAAE,CAAC;AAChB,mBAAQ,CAAC,UAAU,EAAE,CAAC;AAEtB,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AACtB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;AAEtC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACxB,GAAG,CAAC,GAAG,CAAC,IAAA,uBAAY,GAAE,CAAC,CAAC;AAExB,wFAAwF;AACxF,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAC/B,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,KAAK,GAAG,CAAC,QAAQ,EAAE,CAAC;QACjE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,GAAG,gBAAK,CAAC,SAAS,EAAE,CAA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,CAAC,8BAA8B,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Response, Request } from 'express';
|
|
2
|
-
export declare abstract class Controller {
|
|
3
|
-
protected sendResponse(res: Response, data: any, statusCode?: number): void;
|
|
4
|
-
protected setCookie(res: Response, name: string, data: any): void;
|
|
5
|
-
protected getCookie(req: Request, name: string): any;
|
|
6
|
-
protected sendError(res: Response, message: string, statusCode?: number): void;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=baseController.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"baseController.d.ts","sourceRoot":"","sources":["../../src/controllers/baseController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC5C,8BAAsB,UAAU;IAC9B,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAE,MAAY;IAIzE,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAI1D,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG;IAOpD,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,MAAY;CAM7E"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Controller = void 0;
|
|
4
|
-
class Controller {
|
|
5
|
-
sendResponse(res, data, statusCode = 200) {
|
|
6
|
-
res.status(statusCode).json(data);
|
|
7
|
-
}
|
|
8
|
-
setCookie(res, name, data) {
|
|
9
|
-
res.cookie(name, JSON.stringify(data));
|
|
10
|
-
}
|
|
11
|
-
getCookie(req, name) {
|
|
12
|
-
try {
|
|
13
|
-
return req.cookies[name];
|
|
14
|
-
}
|
|
15
|
-
catch (e) { }
|
|
16
|
-
}
|
|
17
|
-
sendError(res, message, statusCode = 500) {
|
|
18
|
-
res.status(statusCode).json({
|
|
19
|
-
error: message,
|
|
20
|
-
timestamp: new Date().toISOString()
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.Controller = Controller;
|
|
25
|
-
//# sourceMappingURL=baseController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"baseController.js","sourceRoot":"","sources":["../../src/controllers/baseController.ts"],"names":[],"mappings":";;;AACA,MAAsB,UAAU;IACpB,YAAY,CAAC,GAAa,EAAE,IAAS,EAAE,aAAqB,GAAG;QACvE,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAES,SAAS,CAAC,GAAa,EAAE,IAAY,EAAE,IAAS;QACxD,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACzC,CAAC;IAES,SAAS,CAAC,GAAY,EAAE,IAAY;QAC5C,IAAI,CAAC;YACH,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;QACD,OAAM,CAAC,EAAE,CAAC,CAAA,CAAC;IACb,CAAC;IAES,SAAS,CAAC,GAAa,EAAE,OAAe,EAAE,aAAqB,GAAG;QAC1E,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YAC1B,KAAK,EAAE,OAAO;YACd,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC,CAAC;IACL,CAAC;CACF;AAtBD,gCAsBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CreateController.d.ts","sourceRoot":"","sources":["../../../src/controllers/create/CreateController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,qBAAa,gBAAiB,SAAQ,UAAU;IACvC,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ;CASzC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CreateController = void 0;
|
|
4
|
-
const baseController_1 = require("../baseController");
|
|
5
|
-
const epistery_1 = require("epistery");
|
|
6
|
-
class CreateController extends baseController_1.Controller {
|
|
7
|
-
index(req, res) {
|
|
8
|
-
const walletInfo = epistery_1.Epistery.createWallet();
|
|
9
|
-
const clientCookie = {
|
|
10
|
-
wallet: walletInfo
|
|
11
|
-
};
|
|
12
|
-
this.setCookie(res, 'epistery-client', clientCookie);
|
|
13
|
-
this.sendResponse(res, clientCookie);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.CreateController = CreateController;
|
|
17
|
-
//# sourceMappingURL=CreateController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CreateController.js","sourceRoot":"","sources":["../../../src/controllers/create/CreateController.ts"],"names":[],"mappings":";;;AACA,sDAA+C;AAC/C,uCAAoC;AAGpC,MAAa,gBAAiB,SAAQ,2BAAU;IACvC,KAAK,CAAC,GAAY,EAAE,GAAa;QACtC,MAAM,UAAU,GAAoB,mBAAQ,CAAC,YAAY,EAAE,CAAC;QAC5D,MAAM,YAAY,GAAG;YACnB,MAAM,EAAE,UAAU;SACnB,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,iBAAiB,EAAE,YAAY,CAAC,CAAC;QACrD,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IACvC,CAAC;CACF;AAVD,4CAUC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from 'express';
|
|
2
|
-
import { Controller } from '../baseController';
|
|
3
|
-
import tls from 'tls';
|
|
4
|
-
export declare class SSLController extends Controller {
|
|
5
|
-
private pending;
|
|
6
|
-
private challenges;
|
|
7
|
-
private acme?;
|
|
8
|
-
private epistery;
|
|
9
|
-
constructor();
|
|
10
|
-
index(req: Request, res: Response): void;
|
|
11
|
-
initialize(): Promise<void>;
|
|
12
|
-
static get SNI(): {
|
|
13
|
-
SNICallback: (hostname: string, cb: (err: Error | null, ctx?: tls.SecureContext) => void) => void;
|
|
14
|
-
};
|
|
15
|
-
getCert(servername: string, attempt?: number): Promise<void>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=SSLController.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SSLController.d.ts","sourceRoot":"","sources":["../../../src/controllers/ssl/SSLController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,GAAG,MAAM,KAAK,CAAC;AActB,qBAAa,aAAc,SAAQ,UAAU;IACzC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,IAAI,CAAC,CAAc;IAC3B,OAAO,CAAC,QAAQ,CAAY;;IAOrB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI;IAUzC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQjC,MAAM,KAAK,GAAG,IAAI;QAAE,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,aAAa,KAAK,IAAI,KAAK,IAAI,CAAA;KAAE,CAWtH;IACK,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,MAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CA6CxE"}
|
|
@@ -1,129 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.SSLController = void 0;
|
|
40
|
-
const baseController_1 = require("../baseController");
|
|
41
|
-
const tls_1 = __importDefault(require("tls"));
|
|
42
|
-
const acme = __importStar(require("acme-client"));
|
|
43
|
-
const index_js_1 = require("../../utils/index.js");
|
|
44
|
-
class SSLController extends baseController_1.Controller {
|
|
45
|
-
constructor() {
|
|
46
|
-
super();
|
|
47
|
-
this.pending = {};
|
|
48
|
-
this.challenges = {};
|
|
49
|
-
}
|
|
50
|
-
index(req, res) {
|
|
51
|
-
const token = req.params.token;
|
|
52
|
-
if (token in this.challenges) {
|
|
53
|
-
res.writeHead(200);
|
|
54
|
-
res.end(this.challenges[token]);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
res.writeHead(302, { Location: `https://${req.headers.host}${req.url}` });
|
|
58
|
-
res.end();
|
|
59
|
-
}
|
|
60
|
-
async initialize() {
|
|
61
|
-
if (!this.acme) {
|
|
62
|
-
this.acme = new acme.Client({
|
|
63
|
-
directoryUrl: acme.directory.letsencrypt[process.env.PROFILE === 'DEV' ? 'staging' : 'production'],
|
|
64
|
-
accountKey: await acme.crypto.createPrivateKey(),
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
static get SNI() {
|
|
69
|
-
return {
|
|
70
|
-
SNICallback: async (hostname, cb) => {
|
|
71
|
-
const domain = index_js_1.Utils.GetDomainInfo(hostname);
|
|
72
|
-
if (domain.ssl) {
|
|
73
|
-
cb(null, tls_1.default.createSecureContext({ key: domain.ssl.key, cert: domain.ssl.cert }));
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
cb(new Error(`${hostname} is unknown`));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
async getCert(servername, attempt = 0) {
|
|
82
|
-
const domain = index_js_1.Utils.GetDomainInfo(servername);
|
|
83
|
-
if (domain.ssl) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
if (servername in this.pending) {
|
|
87
|
-
if (attempt >= 10) {
|
|
88
|
-
throw new Error(`Gave up waiting on certificate for ${servername}`);
|
|
89
|
-
}
|
|
90
|
-
await new Promise((resolve) => {
|
|
91
|
-
setTimeout(resolve, 1000);
|
|
92
|
-
});
|
|
93
|
-
await this.getCert(servername, (attempt + 1));
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
this.pending[servername] = true;
|
|
97
|
-
const config = index_js_1.Utils.GetConfig();
|
|
98
|
-
await this.initialize();
|
|
99
|
-
//TODO: We need to restore the concept of profile in .epistery/config.ini
|
|
100
|
-
if (!config.data.profile?.email)
|
|
101
|
-
throw new Error(`cannot request certificate without "email" set in epistery/config.ini`);
|
|
102
|
-
// create CSR
|
|
103
|
-
const [key, csr] = await acme.crypto.createCsr({
|
|
104
|
-
altNames: [servername],
|
|
105
|
-
});
|
|
106
|
-
// order certificate
|
|
107
|
-
if (!this.acme) {
|
|
108
|
-
throw new Error('ACME client not initialized');
|
|
109
|
-
}
|
|
110
|
-
const cert = await this.acme.auto({
|
|
111
|
-
csr,
|
|
112
|
-
email: config.data.profile?.email,
|
|
113
|
-
termsOfServiceAgreed: true,
|
|
114
|
-
challengePriority: ['http-01'],
|
|
115
|
-
challengeCreateFn: async (authz, challenge, keyAuthorization) => {
|
|
116
|
-
this.challenges[challenge.token] = keyAuthorization;
|
|
117
|
-
},
|
|
118
|
-
challengeRemoveFn: async (authz, challenge) => {
|
|
119
|
-
delete this.challenges[challenge.token];
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
// save certificate
|
|
123
|
-
domain.ssl = { cert: cert, key: key, modified: new Date() };
|
|
124
|
-
config.saveDomain(servername, domain);
|
|
125
|
-
delete this.pending[servername];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports.SSLController = SSLController;
|
|
129
|
-
//# sourceMappingURL=SSLController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SSLController.js","sourceRoot":"","sources":["../../../src/controllers/ssl/SSLController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAA+C;AAC/C,8CAAsB;AACtB,kDAAoC;AAEpC,mDAA6C;AAW7C,MAAa,aAAc,SAAQ,2BAAU;IAMzC;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACzB,CAAC;IACM,KAAK,CAAC,GAAY,EAAE,GAAa;QACpC,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;QAC/B,IAAI,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3B,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACnB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YAChC,OAAO;QACX,CAAC;QACD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAC,QAAQ,EAAE,WAAW,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,EAAE,EAAC,CAAC,CAAC;QACxE,GAAG,CAAC,GAAG,EAAE,CAAC;IACd,CAAC;IACD,KAAK,CAAC,UAAU;QACZ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACb,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC;gBACxB,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CA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AE,IAAI,IAAI,EAAE,EAAC,CAAC;QAC1D,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;CACJ;AAtFD,sCAsFC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StatusController.d.ts","sourceRoot":"","sources":["../../../src/controllers/status/StatusController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD,qBAAa,gBAAiB,SAAQ,UAAU;IACjC,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ;CAoB/C"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StatusController = void 0;
|
|
4
|
-
const baseController_js_1 = require("../baseController.js");
|
|
5
|
-
const index_js_1 = require("../../utils/index.js");
|
|
6
|
-
const epistery_1 = require("epistery");
|
|
7
|
-
class StatusController extends baseController_js_1.Controller {
|
|
8
|
-
async index(req, res) {
|
|
9
|
-
const config = index_js_1.Utils.GetConfig();
|
|
10
|
-
const domain = config.activeDomain.domain;
|
|
11
|
-
const rawClientCookie = this.getCookie(req, 'epistery-client');
|
|
12
|
-
const clientCookie = rawClientCookie ? JSON.parse(rawClientCookie) : null;
|
|
13
|
-
const clientWallet = {
|
|
14
|
-
address: clientCookie?.wallet?.address,
|
|
15
|
-
mnemonic: clientCookie?.wallet?.mnemonic,
|
|
16
|
-
publicKey: clientCookie?.wallet?.publicKey,
|
|
17
|
-
privateKey: clientCookie?.wallet?.privateKey,
|
|
18
|
-
};
|
|
19
|
-
const serverDomain = index_js_1.Utils.GetDomainInfo(domain);
|
|
20
|
-
if (!serverDomain.wallet) {
|
|
21
|
-
this.sendError(res, "Unable to load server wallet.", 400);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const status = epistery_1.Epistery.getStatus(clientWallet, serverDomain);
|
|
25
|
-
this.sendResponse(res, status);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.StatusController = StatusController;
|
|
29
|
-
//# sourceMappingURL=StatusController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StatusController.js","sourceRoot":"","sources":["../../../src/controllers/status/StatusController.ts"],"names":[],"mappings":";;;AACA,4DAAkD;AAClD,mDAAqF;AACrF,uCAAoC;AAEpC,MAAa,gBAAiB,SAAQ,8BAAU;IACvC,KAAK,CAAC,KAAK,CAAC,GAAY,EAAE,GAAa;QAC5C,MAAM,MAAM,GAAU,gBAAK,CAAC,SAAS,EAAE,CAAC;QACxC,MAAM,MAAM,GAAW,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC;QAClD,MAAM,eAAe,GAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;QACnE,MAAM,YAAY,GAAO,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC9E,MAAM,YAAY,GAAoB;YACpC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO;YACtC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ;YACxC,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS;YAC1C,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU;SAC7C,CAAA;QACD,MAAM,YAAY,GAAgB,gBAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC9D,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;YACzB,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,+BAA+B,EAAE,GAAG,CAAC,CAAC;YAC1D,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,mBAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAC9D,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACjC,CAAC;CACF;AArBD,4CAqBC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from 'express';
|
|
2
|
-
import { Controller } from '../baseController.js';
|
|
3
|
-
export declare class WriteController extends Controller {
|
|
4
|
-
constructor();
|
|
5
|
-
index(req: Request, res: Response): Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=WriteController.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WriteController.d.ts","sourceRoot":"","sources":["../../../src/controllers/write/WriteController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAOlD,qBAAa,eAAgB,SAAQ,UAAU;;IAKhC,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ;CA0C/C"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WriteController = void 0;
|
|
4
|
-
const baseController_js_1 = require("../baseController.js");
|
|
5
|
-
const ethers_1 = require("ethers");
|
|
6
|
-
const epistery_1 = require("epistery");
|
|
7
|
-
class WriteController extends baseController_js_1.Controller {
|
|
8
|
-
constructor() {
|
|
9
|
-
super();
|
|
10
|
-
}
|
|
11
|
-
async index(req, res) {
|
|
12
|
-
try {
|
|
13
|
-
const data = req.body;
|
|
14
|
-
if (!data || Object.keys(data).length === 0) {
|
|
15
|
-
return this.sendError(res, 'Request body is empty. Please provide data to sign and store.', 400);
|
|
16
|
-
}
|
|
17
|
-
// Use either user-given wallet or a generated data-wallet
|
|
18
|
-
let clientWallet;
|
|
19
|
-
let clientWalletInfo;
|
|
20
|
-
if (data.wallet && data.wallet.privateKey) {
|
|
21
|
-
clientWalletInfo = data.wallet;
|
|
22
|
-
clientWallet = new ethers_1.ethers.Wallet(clientWalletInfo.privateKey);
|
|
23
|
-
console.log('Using provided wallet:', clientWallet.address);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
clientWallet = ethers_1.ethers.Wallet.createRandom();
|
|
27
|
-
clientWalletInfo = {
|
|
28
|
-
address: clientWallet.address,
|
|
29
|
-
mnemonic: clientWallet.mnemonic?.phrase || '',
|
|
30
|
-
publicKey: clientWallet.publicKey,
|
|
31
|
-
privateKey: clientWallet.privateKey,
|
|
32
|
-
};
|
|
33
|
-
console.log('Generated new wallet:', clientWallet.address);
|
|
34
|
-
}
|
|
35
|
-
const episteryResponse = await epistery_1.Epistery.write(clientWalletInfo, data);
|
|
36
|
-
if (!episteryResponse)
|
|
37
|
-
this.sendError(res, `Unable to create IPFS hash. Result: ${JSON.stringify(episteryResponse)}`, 500);
|
|
38
|
-
this.sendResponse(res, episteryResponse);
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.error('Error in WriteController:', error);
|
|
42
|
-
if (error.message?.includes('ECONNREFUSED')) {
|
|
43
|
-
return this.sendError(res, 'IPFS node not running. Please start IPFS daemon.', 503);
|
|
44
|
-
}
|
|
45
|
-
this.sendError(res, `Failed to process and store data: ${error.message}`, 500);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.WriteController = WriteController;
|
|
50
|
-
//# sourceMappingURL=WriteController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WriteController.js","sourceRoot":"","sources":["../../../src/controllers/write/WriteController.ts"],"names":[],"mappings":";;;AACA,4DAAkD;AAClD,mCAAgC;AAIhC,uCAAoC;AAEpC,MAAa,eAAgB,SAAQ,8BAAU;IAC7C;Q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