Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
monero-nodejs-libwallet
Advanced tools
Wrapper for monero libwallet. All created wallet files are compatible with monero-wallet-cli
and monero-wallet-rpc
.
Check example/index.js
for usage examples of the library.
Configures log level and output (file or stdout
). Accepts integer log level (from 0
to 4
) and optional output filename (skip it if you want log to write in stdout
):
const monero = require('./build/Debug/monero');
monero.setupLog(4, 'wallet.log'); //maximum logs into `wallet.log` file
Create new wallet asynchronously:
const monero = require('./build/Debug/monero');
monero.createWallet({
'path': 'test-wallet',
'password': '123',
'network': 'mainnet',
'daemon_address': 'localhost:18081',
}).then((wallet) => console.log('New wallet succesfully created: ' + wallet.address()))
.catch((e) => console.log('Failed to create new wallet: ' + e));
Arguments object:
property | description | required |
---|---|---|
path | path to wallet file | yes |
password | password | yes |
network | one of mainnet (default) / stagenet / testnet | no |
daemon_address | remote node address | yes |
language | language to generate mnemonics for ('English' is default) | no |
Returns promise object. Throws in case of arguments error.
Opens existing wallet asynchronously:
const monero = require('./build/Debug/monero');
monero.openWallet({
'path': 'test-wallet',
'password': '123',
'network': 'mainnet',
'daemon_address': 'localhost:18081',
}).then((wallet) => console.log('New wallet succesfully created: ' + wallet.address()))
.catch((e) => console.log('Failed to create new wallet: ' + e));
Arguments object:
property | description | required |
---|---|---|
path | path to wallet file | yes |
password | password | yes |
network | one of mainnet (default) / stagenet / testnet | no |
daemon_address | remote node address | yes |
language | language to generate mnemonics for ('English' is default) | yes |
Returns promise object. Throws in case of arguments error.
Checks if wallet exists:
const monero = require('./build/Debug/monero');
if (monero.walletExists('test-wallet')) {
console.log('Wallet already exists');
} else {
console.log('Wallet does not exist');
}
Returns boolean.
Generates new payment id:
const monero = require('./build/Debug/monero');
console.log('New payment id: ' + monero.genPaymentId());
Checks if given payment id is valid:
const monero = require('./build/Debug/monero');
if (monero.paymentIdValid('180b67533011df75b74333e62599c160f5484bf8bb98779598520dfb90633198')) {
console.log('Payment id is valid');
} else {
console.log('Payment id is not valid');
}
Checks if given monero address valid in certain network type:
const monero = require('./build/Debug/monero');
if (monero.addressValid('44zrUGhyRHYbHYrfiGAtLdJMHfe5DtoFTBeVPCE6MGKzZA2bJ4tCJFuhYk3Wjp3YxEWoQU8So5xUiiArgnkBHZgX8Fyhv6e', 'mainnet')) {
console.log('Address is valid');
} else {
console.log('Address is not valid');
}
Returns an address of the wallet:
console.log('Wallet address: ' + wallet.address());
Returns mnemonic seed for the wallet:
console.log('Wallet seed: ' + wallet.seed());
Subscibes on wallet emitted events:
wallet.on('newBlock', function (height) {
console.log("blockchain updated, height: " + height);
});
wallet.on('refreshed', function () {
console.log("wallet is synchronized");
});
wallet.on('updated', function () {
console.log("updated");
});
wallet.on('unconfirmedMoneyReceived', function(tx, amount) {
console.log("unconfirmed money received. tx: " + tx + ", amount: " + amount);
});
wallet.on('moneyReceived', function(tx, amount) {
console.log("money received. tx: " + tx + ", amount: " + amount);
});
wallet.on('moneySpent', function(tx, amount) {
console.log("money spent. tx: " + tx + ", amount: " + amount);
});
Asynchronously saves wallet into the file:
wallet.store()
.then(() => {console.log("wallet stored")})
.catch((e) => {console.log("unable to store wallet: " + e)});
Creates pending transaction:
wallet.createTransaction({
'address': '44zrUGhyRHYbHYrfiGAtLdJMHfe5DtoFTBeVPCE6MGKzZA2bJ4tCJFuhYk3Wjp3YxEWoQU8So5xUiiArgnkBHZgX8Fyhv6e',
'amount': '2000000000', //monero atomic units as string
}).then((tx) => {
console.log("transaction created: " + tx.transactionsIds());
}).catch((e) => {
sent = false;
console.log("couldn't create transaction: " + e);
});
Accepts arguments object:
property | description | required |
---|---|---|
address | valid monero address | yes |
amount | monero atomic units as string | yes |
payment_id | valid payment id | no |
mixin | ring signature size (current minimum is 7 ) | no |
Throws in case of arguments error.
Returns promise. then
-callback accepts PendingTransaction
object, catch
-callback accepts error string.
Returns current wallet file path:
console.log("wallet located at : " + wallet.path());
Returns current network type (either mainnet
, stagenet
or testnet
):
console.log("network : " + wallet.network());
Returns corresponding hex-encoded wallet key:
console.log("secret view key : " + wallet.secretViewKey());
console.log("public view key : " + wallet.publicViewKey());
console.log("secret spend key : " + wallet.secretSpendKey());
console.log("public spend key : " + wallet.publicSpendKey());
console.log("public spend key : " + wallet.publicMultisigSignerKey());
Sets new password to the wallet:
wallet.setPassword('iamsherlocked');
Sets the blockchain height to start refresh from:
wallet.setRefreshFromBlockHeight(1555371);
console.log('refreshing from: ' + wallet.getRefreshFromBlockHeight());
Checks if wallet is connected to the daemon:
console.log('connected: ' + wallet.connected());
Sets trusted
flag to the daemon:
if (wallet.trustedDamon()) {
wallet.setTrustedDaemon(false); // trust no one
}
Returns wallet balance:
console.log('wallet: ' + wallet.address());
console.log('balance: ' + wallet.balance());
console.log('unlocked balance: ' + wallet.unlockedBalance());
Returns local blockchain height:
console.log('synced till: ' + wallet.blockchainHeight());
Returns remote node's blockhain height:
console.log('synchronized till: ' + wallet.daemonBlockchainHeight());
Checks if wallet is synchronized with a network:
console.log('wallet synchronized: ' + wallet.synchronized());
Stops synchronization.
Resumes synchronization.
Returns an object representing multisig wallet state:
var state = wallet.multisigState();
console.log('is multisig: ' + state.isMultisig);
console.log('is multisig ready: ' + state.isReady); //indicates multisig wallet creation process is finished
console.log('multisig threshold: ' + state.threshold); //number of required signatures
console.log('multisig total: ' + state.total); //number of participants
Returns serialized to string multisig info data necessary for multisig wallet creation (see example below).
Accepts multisig infos from all participants and the threshold to set wallet into multisig state (see example below). In case of N / N wallets it's the last step in wallet creation. In case of N - 1 / N wallets returns extra multisig info which must be passed to another participants.
Accepts extra multisig info (result of makeMultisig
invocation) from all participants and finalizes N - 1 / N multisig wallet creation.
3 / 3 multisig wallet creation example:
var msigInfo1 = wallet1.getMultisigInfo();
var msigInfo2 = wallet2.getMultisigInfo();
var msigInfo3 = wallet3.getMultisigInfo();
wallet1.makeMultisig([msigInfo2, msigInfo3], 3);
wallet2.makeMultisig([msigInfo1, msigInfo3], 3);
wallet3.makeMultisig([msigInfo1, msigInfo2], 3);
console.log('multisig wallet created');
console.log('wallet1 address: ' + wallet1.address());
console.log('wallet2 address: ' + wallet2.address());
console.log('wallet3 address: ' + wallet3.address());
2 / 3 multisig wallet creation example:
var msigInfo1 = wallet1.getMultisigInfo();
var msigInfo2 = wallet2.getMultisigInfo();
var msigInfo3 = wallet3.getMultisigInfo();
var emsigInfo1 = wallet1.makeMultisig([msigInfo2, msigInfo3], 2);
var emsigInfo2 = wallet2.makeMultisig([msigInfo1, msigInfo3], 2);
var emsigInfo3 = wallet3.makeMultisig([msigInfo1, msigInfo2], 2);
wallet1.finalizeMultisig([emsigInfo2, emsigInfo3]);
wallet2.finalizeMultisig([emsigInfo1, emsigInfo3]);
wallet3.finalizeMultisig([emsigInfo1, emsigInfo2]);
console.log('multisig wallet created');
console.log('wallet1 address: ' + wallet1.address());
console.log('wallet2 address: ' + wallet2.address());
console.log('wallet3 address: ' + wallet3.address());
Returns string of exported partial key images (see example below).
Imports exported partial key images from other participants:
var ki1 = msigWallet1.exportMultisigImages();
var ki2 = msigWallet2.exportMultisigImages();
var ki3 = msigWallet3.exportMultisigImages();
msigWallet1.importMultisigImages([ki2, ki3]);
msigWallet2.importMultisigImages([ki1, ki3]);
msigWallet3.importMultisigImages([ki1, ki2]);
Deserializes multisig transaction from other participant. Returns promise object.
Asynchronously sends transaction into the network:
tx.commit().then(() => {
console.log("transaction commited successfully");
}).catch((e) => {
console.log("error on commiting transaction: " + e);
});
Returns amount of the transaction:
console.log("transaction amount: " + tx.amount());
Returns transaction fee:
console.log("transaction fee: " + tx.fee());
If generated transaction is too big libwallet splits it into several transactions. This method returns number of generated low-level transactions:
console.log("generated " + tx.transactionsCount() + ' low level transactions');
Returns transactions ids of newly generated pending transaction:
if (tx.transactionsCount() > 1) {
for (i = 0; i < tx.transactionsCount(); i++) {
console.log('transaction #' + i + ': ' + tx.transactionsIds()[i]);
}
} else {
console.log('transaction id' + tx.transactionsIds());
}
Returns serialized multisig transaction which has to be passed to another participants for signature (see example below).
Signs multisig transaction:
wallet1.createTransaction({
'address': '44zrUGhyRHYbHYrfiGAtLdJMHfe5DtoFTBeVPCE6MGKzZA2bJ4tCJFuhYk3Wjp3YxEWoQU8So5xUiiArgnkBHZgX8Fyhv6e',
'amount': '2000000000',
}).then((tx) => {
var signData = tx.multisigSignData();
wallet2.restoreMultisigTransaction(signData).then((tx) => {
console.log('multisig transaction restored successfully. Signing...');
tx.signMultisigTransaction();
}).catch((e) => {
console.log("couldn't restore multisig transaction: " + e);
});
}).catch((e) => {
console.log("couldn't create transaction: " + e);
});
Returns an array of public signers key of participants who already signed this transaction:
console.log('participants already signed this transaction: ' + tx.signersKeys());
FAQs
Monero libwallet native addon. Under development at the moment
The npm package monero-nodejs-libwallet receives a total of 5 weekly downloads. As such, monero-nodejs-libwallet popularity was classified as not popular.
We found that monero-nodejs-libwallet demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.