4.2.0 • Published 7 months ago

haven-wallet-core v4.2.0

Weekly downloads
33
License
MIT
Repository
github
Last release
7 months ago

Haven Web Core a Fork of Monero Javascript

A Node.js library for creating Haven Apps using RPC or WebAssembly

  • Supports browser and Node.js applications using WebAssembly.
  • Supports wallet and daemon RPC clients.
  • Supports multisig, view-only, and offline wallets.
  • Wallet types are interchangeable by conforming to a common interface.
  • Uses a clearly defined data model and API specification intended to be intuitive and robust.
  • Query wallet transactions, transfers, and outputs by their properties.
  • Fetch and process binary data from the daemon (e.g. raw blocks).
  • Receive notifications when blocks are added to the chain or when wallets sync, send, or receive.
  • Over 280 passing Mocha tests.

Table of contents

Architecture

Sample code

// import library
const monerojs = require("monero-javascript");

// connect to daemon
let daemon = await monerojs.connectToDaemonRpc("http://localhost:38081", "superuser", "abctesting123");
let height = await daemon.getHeight();            // 1523651
let txsInPool = await daemon.getTxPool();         // get transactions in the pool

// open wallet on monero-wallet-rpc
let walletRpc = await monerojs.connectToWalletRpc("http://localhost:38084", "rpc_user", "abc123");
await walletRpc.openWallet("sample_wallet_rpc", "supersecretpassword123");
let primaryAddress = await walletRpc.getPrimaryAddress(); // 555zgduFhmKd2o8rPUz...
let balance = await walletRpc.getBalance();               // 533648366742
let txs = await walletRpc.getTxs();                       // get transactions containing transfers to/from the wallet

// create wallet from mnemonic phrase using WebAssembly bindings to monero-project
let walletFull = await monerojs.createWalletFull({
  path: "sample_wallet_full",
  password: "supersecretpassword123",
  networkType: "stagenet",
  serverUri: "http://localhost:38081",
  serverUsername: "superuser",
  serverPassword: "abctesting123",
  mnemonic: "hefty value scenic...",
  restoreHeight: 573936,
});

// synchronize with progress notifications
await walletFull.sync(new class extends monerojs.MoneroWalletListener {
  onSyncProgress(height, startHeight, endHeight, percentDone, message) {
    // feed a progress bar?
  }
});

// synchronize in the background every 5 seconds
await walletFull.startSyncing(5000);

// receive notifications when funds are received, confirmed, and unlocked
let fundsReceived = false;
await walletFull.addListener(new class extends monerojs.MoneroWalletListener {
  onOutputReceived(output) {
    let amount = output.getAmount();
    let txHash = output.getTx().getHash();
    let isConfirmed = output.getTx().isConfirmed();
    let isLocked = output.getTx().isLocked();
    fundsReceived = true;
  }
});

// send funds from RPC wallet to WebAssembly wallet
let createdTx = await walletRpc.createTx({
  accountIndex: 0,
  address: await walletFull.getAddress(1, 0),
  amount: "250000000000", // send 0.25 XMR (denominated in atomic units)
  relay: false // create transaction and relay to the network if true
});
let fee = createdTx.getFee(); // "Are you sure you want to send... ?"
await walletRpc.relayTx(createdTx); // relay the transaction

// recipient receives unconfirmed funds within 5 seconds
await new Promise(function(resolve) { setTimeout(resolve, 5000); });
assert(fundsReceived);

// save and close WebAssembly wallet
await walletFull.close(true);

Using monero-javascript in your project

  1. cd your_project or mkdir your_project && cd your_project && npm init
  2. npm install monero-javascript
  3. Add require("monero-javascript") to your application code.

If using RPC servers:

  1. Download and install Monero CLI.
  2. Start monero-daemon-rpc, e.g.: ./monerod --stagenet (or use a remote daemon).
  3. Start monero-wallet-rpc, e.g.: ./monero-wallet-rpc --daemon-address http://localhost:38081 --stagenet --rpc-bind-port 38083 --rpc-login rpc_user:abc123 --wallet-dir ./

Building WebAssembly binaries from source

This project uses WebAssembly to package and execute Monero's source code for use in a browser or other WebAssembly-supported environments.

Compiled WebAssembly binaries are committed to ./dist for convenience, but these files can be built independently from source code:

  1. Install and activate emscripten
    1. Clone emscripten repository: git clone https://github.com/emscripten-core/emsdk.git
    2. cd emsdk
    3. git pull && ./emsdk install latest-upstream && ./emsdk activate latest-upstream && source ./emsdk_env.sh
    4. export EMSCRIPTEN=/absolute/path/to/emsdk/upstream/emscripten (change for your system)
  2. Clone monero-javascript repository: git clone https://github.com/monero-ecosystem/monero-javascript.git
  3. cd monero-javascript
  4. ./bin/build_all.sh

Developer guide

Using monero-javascript in your project

  1. cd your_project or mkdir your_project && cd your_project && npm init
  2. npm install monero-javascript@0.7.6
  3. Add require("monero-javascript") to your application code.
  4. If building a browser application, copy assets from ./dist to your web app's build directory as needed.

If using RPC servers:

  1. Download and install Monero CLI.
  2. Start monero-daemon-rpc, e.g.: ./monerod --stagenet (or use a remote daemon).
  3. Start monero-wallet-rpc, e.g.: ./monero-wallet-rpc --daemon-address http://localhost:38081 --stagenet --rpc-bind-port 38084 --rpc-login rpc_user:abc123 --wallet-dir ./

Building WebAssembly binaries from source

This project uses WebAssembly to package and execute Monero's source code for use in a browser or other WebAssembly-supported environment.

Compiled WebAssembly binaries are committed to ./dist for convenience, but these files can be built independently from source code:

  1. Install and activate emscripten.
    1. Clone emscripten repository: git clone https://github.com/emscripten-core/emsdk.git
    2. cd emsdk
    3. git pull && ./emsdk install 3.1.10 && ./emsdk activate 3.1.10 && source ./emsdk_env.sh
    4. export EMSCRIPTEN=path/to/emsdk/upstream/emscripten (change for your system)
  2. Clone monero-javascript repository: git clone --recursive https://github.com/monero-ecosystem/monero-javascript.git
  3. cd monero-javascript
  4. ./bin/update_submodules.sh
  5. Modify ./external/monero-cpp/external/monero-project/src/crypto/wallet/CMakeLists.txt from set(MONERO_WALLET_CRYPTO_LIBRARY "auto" ... to set(MONERO_WALLET_CRYPTO_LIBRARY "cn" ....
  6. Download and install unbound 1.17.0 to your home directory (~).
  7. ./bin/build_all.sh (install monero-project dependencies as needed for your system)

Running tests

  1. Clone the project repository: git clone https://github.com/monero-ecosystem/monero-javascript.git
  2. cd monero-javascript
  3. Start RPC servers:
    1. Download and install Monero CLI.
    2. Start monero-daemon-rpc, e.g.: ./monerod --testnet (or use a remote daemon).
    3. Start monero-wallet-rpc, e.g.: ./monero-wallet-rpc --daemon-address http://localhost:38081 --testnet --rpc-bind-port 28084 --rpc-login rpc_user:abc123 --wallet-dir ./
  4. Configure the appropriate RPC endpoints, authentication, and other settings in TestUtils.js (e.g. WALLET_RPC_CONFIG and DAEMON_RPC_CONFIG).

Running tests in Node.js

  • Run all tests: npm test
  • Run tests by their description, e.g.: npm run test -- --grep "Can get transactions"

Running tests in a browser

  1. Start monero-wallet-rpc servers used by tests: ./bin/start_wallet_rpc_test_servers.sh
  2. In another terminal, build browser tests: ./bin/build_browser_tests.sh
  3. Access http://localhost:8080/tests.html in a browser to run all tests

Related projects

License

This project is licensed under MIT.

Donations

If this library brings you value, please consider donating.

4.2.0

7 months ago

4.1.0

8 months ago

4.1.1

8 months ago

3.3.2

1 year ago

3.3.1

2 years ago

3.3.0

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.0.21

2 years ago

3.0.20

2 years ago

3.0.19

2 years ago

3.0.12

2 years ago

3.0.13

2 years ago

3.0.10

2 years ago

3.0.11

2 years ago

3.0.16

2 years ago

3.0.17

2 years ago

3.0.14

2 years ago

3.0.15

2 years ago

3.0.18

2 years ago

3.0.9

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.8

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

2.3.0

3 years ago

2.3.1

3 years ago

2.3.4

3 years ago

2.3.3

3 years ago

2.3.5

3 years ago

3.0.0

2 years ago

2.2.3

3 years ago

2.1.13

3 years ago

2.1.9

3 years ago

2.1.12

3 years ago

2.1.10

3 years ago

2.1.11

3 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.4.112

4 years ago

1.4.111

4 years ago

2.1.0

4 years ago

1.4.109

4 years ago

1.4.100

4 years ago

1.4.84

4 years ago

1.4.85

4 years ago

1.4.99

4 years ago

1.4.74

4 years ago

1.4.77

4 years ago

1.4.69

4 years ago

1.4.71

4 years ago

1.4.70

4 years ago

1.4.73

4 years ago

1.4.68

4 years ago

1.4.67

4 years ago

1.4.59

4 years ago

1.4.57

4 years ago

1.4.55

4 years ago

1.4.56

4 years ago

1.4.51

4 years ago

1.4.50

4 years ago

1.4.35

4 years ago

1.4.34

4 years ago

1.4.37

4 years ago

1.4.36

4 years ago

1.4.39

4 years ago

1.4.38

4 years ago

1.4.40

4 years ago

1.4.41

4 years ago

1.4.44

4 years ago

1.4.43

4 years ago

1.4.46

4 years ago

1.4.45

4 years ago

1.4.48

4 years ago

1.4.49

4 years ago

1.4.32

4 years ago

1.4.30

4 years ago

1.4.26

4 years ago

1.4.28

4 years ago

1.4.27

4 years ago

1.4.24

4 years ago

1.4.23

4 years ago

1.4.22

4 years ago

1.4.21

4 years ago

1.4.20

4 years ago

1.4.18

4 years ago

1.4.17

4 years ago

1.4.16

4 years ago

1.4.13

4 years ago

1.4.14

4 years ago

1.4.6

4 years ago

1.4.7

4 years ago

1.4.12

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.3.2

4 years ago

1.2.45

4 years ago

1.2.44

4 years ago

1.2.43

4 years ago

1.2.38

4 years ago

1.2.39

4 years ago

1.2.36

4 years ago

1.2.37

4 years ago

1.2.34

4 years ago

1.2.35

4 years ago

1.2.20

4 years ago

1.2.10

4 years ago

1.2.11

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago