/
wallet.js
83 lines (65 loc) · 2.35 KB
/
wallet.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var https = require('https');
const fs = require('fs');
const ChainUtil = require("./chain-util");
const path = 'wallet.dat'
const outputtext = 'Wallet already exists!';
try {
if (!fs.existsSync(path)) {
var keyPair = ChainUtil.genKeyPair(Date.now().toString());
var publicKey = "";
var privateKey = "";
publicKey = keyPair.getPublic("hex");
privateKey = keyPair.getSecret("hex");
console.log(publicKey + " - privatekey: " + privateKey);
var jsonObject = JSON.stringify({
"PrivateKey": privateKey,
"PublicKey": "HeroooesCoin" + publicKey.substring(1),
"CryptoAsset": "HeroooesCoin",
"Identifier": ""
});
fs.writeFile("wallet.dat", jsonObject, function (err) {
if (err) {
return console.log(err);
}
console.log("Wallet file was created!");
});
var cryptoAssetInput = { PrivateKey: privateKey, PublicKey: "HeroooesCoin" + publicKey.substring(1), CryptoAsset: "HeroooesCoin", Identifier: "" };
jsonObject = JSON.stringify({
"SignMessage": cryptoAssetInput,
"CryptoAsset": "HeroooesCoin",
});
var postheaders = {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(jsonObject, 'utf8')
};
var optionspost = {
host: 'www.heroooescoin.com',
path: '/api/cryptoasset22',
method: 'POST',
headers: postheaders
};
console.info('Options prepared:');
console.info(optionspost);
console.info('Do the POST call');
// do the POST call
var reqPost = https.request(optionspost, function (res) {
console.log("statusCode: ", res.statusCode);
res.on('data', function (d) {
console.info('POST result:\n');
process.stdout.write(d);
console.info('\n\nPOST completed');
});
});
// write the json data
reqPost.write(jsonObject);
reqPost.end();
reqPost.on('error', function (e) {
console.error(e);
});
}
else {
console.log(outputtext);
}
} catch (err) {
console.log(err);
}