UNPKG

radix-account-tools-js

Version:

Javascript/Typescript account creation tools for Radix DLT

45 lines (44 loc) 2.74 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.create_random_accounts = create_random_accounts; exports.load_account_from_pkBytes = load_account_from_pkBytes; const account_utils_1 = require("./account-utils"); let defaultNetworkId = 0; // 0 for stokenet, 1 for mainnet function create_random_accounts() { return __awaiter(this, arguments, void 0, function* (networkId = defaultNetworkId) { console.log("DEMO: Creating accounts from a mnemonic phrase."); // mnemonic phrase must be words separated by spaces let mnemonic = ""; // manually add mnemonic phrase here if (mnemonic == "") { mnemonic = (0, account_utils_1.generate24WordMnemonic)(); // generate new random mnemonic phrase if none specified } console.log("Phrase: ", mnemonic); let multiAccounts = (0, account_utils_1.generateAccountsFromMnemonic)(mnemonic, [0, 1, 2, 100], networkId); (yield multiAccounts).forEach((accountData) => { console.log("Index: " + accountData.index + " Address : " + accountData.address); console.log("Private Key Bytes: [" + accountData.privateKey.bytes.join() + "]"); }); }); } function load_account_from_pkBytes() { return __awaiter(this, arguments, void 0, function* (networkId = defaultNetworkId) { console.log("DEMO: Create an account from an array of bytes."); let pkBytes = Uint8Array.from([ 59, 221, 206, 186, 244, 250, 32, 61, 48, 35, 211, 187, 215, 144, 255, 221, 195, 4, 159, 158, 149, 222, 251, 113, 141, 82, 164, 202, 44, 150, 174, 79, ]); // you can load this array from a .env file or get it from any other source console.log("Bytes array: [" + pkBytes.join() + "]"); let privateKey = yield (0, account_utils_1.generateEd25519PrivateKey)(pkBytes); let account = yield (0, account_utils_1.generateNewVirtualAccount)(privateKey, networkId); console.log("New account created from bytes: " + account.address); }); }