forked from ensdomains/offchain-resolver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
30 lines (29 loc) · 1.12 KB
/
index.ts
File metadata and controls
30 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { makeApp } from './server';
import { Command } from 'commander';
import { readFileSync } from 'fs';
import { ethers } from 'ethers';
import { JSONDatabase } from './json';
const program = new Command();
program
.requiredOption(
'-k --private-key <key>',
'Private key to sign responses with. Prefix with @ to read from a file'
)
.requiredOption('-d --data <file>', 'JSON file to read data from')
.option('-t --ttl <number>', 'TTL for signatures', '300')
.option('-p --port <number>', 'Port number to serve on', '8080');
program.parse(process.argv);
const options = program.opts();
let privateKey = options.privateKey;
if (privateKey.startsWith('@')) {
privateKey = ethers.utils.arrayify(
readFileSync(privateKey.slice(1), { encoding: 'utf-8' })
);
}
const address = ethers.utils.computeAddress(privateKey);
const signer = new ethers.utils.SigningKey(privateKey);
const db = JSONDatabase.fromFilename(options.data, parseInt(options.ttl));
const app = makeApp(signer, '/', db);
console.log(`Serving on port ${options.port} with signing address ${address}`);
app.listen(parseInt(options.port));
module.exports = app;