-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-n-reg.ts
33 lines (26 loc) · 1.11 KB
/
gen-n-reg.ts
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
31
32
33
import { SDKFactory, Config } from "dav-js";
const eth = require('ethereumjs-wallet');
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs';
const wallet = JSON.parse(fs.readFileSync(path.join(os.homedir(), '.dav', 'wallet')).toString());
async function main() {
await generateDrone('');
await generateDrone('1');
await generateDrone('2');
await generateDrone('3');
}
async function generateDrone(droneName: string) {
const generatedKey = eth.generate();
const identity = {
private: generatedKey.getPrivateKeyString(),
public: generatedKey.getPublicKeyString(),
address: generatedKey.getChecksumAddressString(),
};
const keyFile = path.join(os.homedir(), '.dav', `drone${droneName}`);
fs.writeFileSync(keyFile, JSON.stringify(identity));
const DAV = SDKFactory({ ethNodeUrl: wallet.nodeUrl });
const res = await DAV.registerIdentity(identity.address, wallet.address, wallet.private, identity.private);
console.log(`New DAV identity: ${identity.address}`);
}
main().then(() => { console.log('Done') }, (err) => { console.error(err) });