Skip to content

Commit c1c6dc3

Browse files
authored
Merge pull request #52 from BTS-CM/new_features
New features - Cloud wallet account creation & Same-T Fund Limit Order chaining!
2 parents 7669ea6 + 5942bb4 commit c1c6dc3

File tree

104 files changed

+4159
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+4159
-116
lines changed

src/background.js

+172
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import os from "os";
33
import url from "url";
44
import express from "express";
55

6+
import { key, PrivateKey } from "bitsharesjs";
67
import { Apis } from "bitsharesjs-ws";
78

89
import { app, BrowserWindow, Menu, Tray, ipcMain, screen, shell } from "electron";
@@ -194,6 +195,118 @@ const createWindow = async () => {
194195
isFetching = false;
195196
});
196197

198+
ipcMain.handle("genKey", async () => {
199+
return key.get_random_key().toWif();
200+
});
201+
202+
ipcMain.handle("genAccount", async (event, arg) => {
203+
const {
204+
userID,
205+
username,
206+
password,
207+
method,
208+
nodeURL
209+
} = arg;
210+
211+
let apiInstance;
212+
try {
213+
apiInstance = Apis.instance(nodeURL, true);
214+
} catch (error) {
215+
console.log({ error, location: "Apis.instance", nodeURL });
216+
return;
217+
}
218+
219+
try {
220+
await apiInstance.init_promise;
221+
console.log("connected to:", apiInstance.chain_id);
222+
} catch (err) {
223+
console.log({ err });
224+
return;
225+
}
226+
227+
apiInstance.close();
228+
apiInstance = null;
229+
230+
function _generateKeyFromPassword(accountName, role, password) {
231+
let seed = accountName + role + password;
232+
let privKey = PrivateKey.fromSeed(seed);
233+
let pubKey = privKey.toPublicKey().toPublicKeyString();
234+
return { privKey, pubKey };
235+
}
236+
237+
if (!userID || !username || !password || !method) {
238+
console.log(`Missing required parameters for account generation`);
239+
return { success: false };
240+
}
241+
242+
let {
243+
privKey: owner_private,
244+
pubKey: owner_public
245+
} = _generateKeyFromPassword(username, "owner", password);
246+
247+
let { privKey: active_private, pubKey: active_public } = _generateKeyFromPassword(
248+
username, "active", password
249+
);
250+
251+
let { privKey: memo_private, pubKey: memo_public } = _generateKeyFromPassword(
252+
username,
253+
"memo",
254+
password
255+
);
256+
257+
if (method === "ltm") {
258+
// BeetEOS broadcast by LTM account creating premium account names
259+
260+
if (!userID) {
261+
console.log(`User ID is required for this method`);
262+
return { success: false };
263+
}
264+
265+
return {
266+
fee: {
267+
amount: 0,
268+
asset_id: "1.3.0"
269+
},
270+
registrar: userID,
271+
referrer: userID,
272+
referrer_percent: 100,
273+
name: username,
274+
owner: {
275+
weight_threshold: 1,
276+
account_auths: [],
277+
key_auths: [[owner_public, 1]],
278+
address_auths: []
279+
},
280+
active: {
281+
weight_threshold: 1,
282+
account_auths: [],
283+
key_auths: [[active_public, 1]],
284+
address_auths: []
285+
},
286+
options: {
287+
memo_key: memo_public,
288+
voting_account: "1.2.5", // proxy-to-self
289+
votes: [],
290+
num_witness: 0,
291+
num_committee: 0,
292+
}
293+
};
294+
} else {
295+
// Creating user with the public account faucet
296+
return {
297+
account: {
298+
name: username,
299+
owner_key: owner_public,
300+
active_key: active_public,
301+
memo_key: memo_public,
302+
refcode: "1.2.1803677",
303+
referrer: "1.2.1803677"
304+
}
305+
};
306+
}
307+
});
308+
309+
197310
ipcMain.handle("fetchTopMarkets", async (event, arg) => {
198311
const { chain } = arg;
199312

@@ -258,6 +371,65 @@ const createWindow = async () => {
258371
return accountHistory ?? null;
259372
});
260373

374+
ipcMain.on("notify", (event, arg) => {
375+
const NOTIFICATION_TITLE = "Error!";
376+
const NOTIFICATION_BODY = arg;
377+
378+
if (os.platform === "win32") {
379+
app.setAppUserModelId(app.name);
380+
}
381+
382+
function showNotification() {
383+
new Notification({
384+
title: NOTIFICATION_TITLE,
385+
subtitle: "subtitle",
386+
body: NOTIFICATION_BODY,
387+
icon: __dirname + "/img/tray.png",
388+
}).show();
389+
}
390+
391+
showNotification();
392+
});
393+
394+
ipcMain.handle("faucetRegistration", async (event, arg) => {
395+
const { chain, bodyParameters } = arg;
396+
397+
function createAccountWithPassword(chain, bodyParameters) {
398+
return new Promise((resolve, reject) => {
399+
const faucetAddress = chain === "bitshares"
400+
? "https://faucet.bitshares.eu/onboarding"
401+
: "https://faucet.testnet.bitshares.eu";
402+
403+
fetch(faucetAddress + "/api/v1/accounts", {
404+
method: "post",
405+
mode: "cors",
406+
headers: {
407+
Accept: "application/json",
408+
"Content-type": "application/json"
409+
},
410+
body: bodyParameters
411+
})
412+
.then(response => response.json())
413+
.then(res => {
414+
if (!res || (res && res.error)) {
415+
reject(res.error);
416+
} else {
417+
resolve(res);
418+
}
419+
})
420+
.catch(reject);
421+
});
422+
}
423+
424+
try {
425+
const result = await createAccountWithPassword(chain, bodyParameters);
426+
return result;
427+
} catch (error) {
428+
console.error("Error during faucet registration:", error);
429+
return { error };
430+
}
431+
});
432+
261433
ipcMain.handle("generateDeepLink", async (event, arg) => {
262434
const { usrChain, nodeURL, operationNames, trxJSON } = arg;
263435

0 commit comments

Comments
 (0)