cardano-launcher icon indicating copy to clipboard operation
cardano-launcher copied to clipboard

Make this standalone

Open philkunz opened this issue 4 years ago • 7 comments

I'm currently in the process of developing a MIT licensed TypeScript client library that replicates the functionality of daedalus.

For now I'm going the docker route to get things running out of the box and as self contained as possible. That inherently requires the user to either manually start the docker containers or to install the module with a user that has permissions to connect to the docker.sock on the system. I also developed a docker remote api module for that https://gitlab.com/mojoio/docker

I'm now looking at this repository. While I get the purpose, I feel there needs to be a even more hands-off solution to start node and wallet on any system. I want a package that downloads the system dependent compiled binaries for me, and starts node and wallet. All that should be part of a cardano-launcher like package. Projects that handle it that way are for example https://github.com/nodegit/nodegit or even the vastly popular puppeteer from Google.

Before you brush this off as out of scope: Please either consider a separate package for this and point me in a direction where best to find stable binaries for all platforms, so I can implement it in my package (https://gitlab.com/mojoio/cardano) or consider including it here.

The nodejs developer ecosystem is huge. The simpler we make it to consume cardano in simple website projects for payments without having to go through a third party payment gateway, the more adoption we will see. Making things easy even for non experienced devs is key here.

philkunz avatar Aug 17 '20 12:08 philkunz

@philkunz both project (cardano-node and cardano-wallet) exports pre-compiled binary artefacts on each release on the 3 major platforms: Windows, MacOS and GNU/Linux. You can find them on the following links:

cardano-node

  • https://hydra.iohk.io/job/Cardano/cardano-node/cardano-node-win64/latest/download/1
  • https://hydra.iohk.io/job/Cardano/cardano-node/cardano-node-macos/latest/download/1
  • https://hydra.iohk.io/job/Cardano/cardano-node/cardano-node-linux/latest/download/1

cardano-wallet

  • https://hydra.iohk.io/job/Cardano/cardano-wallet/cardano-wallet-win64/latest/download/1
  • https://hydra.iohk.io/job/Cardano/cardano-wallet/cardano-wallet-macos64/latest/download/1
  • https://hydra.iohk.io/job/Cardano/cardano-wallet/cardano-wallet-linux64/latest/download/1

Note that the bundles of cardano-wallet do contain additional pre-compiled binaries that are part of the toolchain, like cardano-address, bech32 or cardano-transaction.

KtorZ avatar Aug 17 '20 13:08 KtorZ

@KtorZ Thank you. Whats the best way to ask for help should I run into issues?

Btw. here is what the API is gonna look like:

import * as cardano from '@mojoio/cardano';

const run = async () => {
  await cardano.install(/* optional pathArg here, defaults to packageDir/.nogit/ */) // installs the needed binaries for the regarding system
  const cardanoClient = cardano.CardanoClient.createForNetwork('mainnet'); // static function that creates an instance of CardanoClient
  await cardanoClient.syncedPromise; // a promise that resolves once the running cardano-node has synced with the blockchain
  const cardanoWallet = await cardanoClient.restoreWalletFromSeed(['my', 'awesome', 'seed']) // creates a wallet from seed. Alternatively takes a space separated string.
  const expectedPayment = cardanoWallet.createExpectedPayment(100.546, 'some optional address to forward to upon completion'); // creates an expectedPayment of 100.546, takes a address to forward payments to upon completion
  // use expectedPayment.amount and expectedPayment.address to display transaction information to your customer
  const receipt = await expectedPayment.paymentReceivedPromise; // a promise that resolves with a receipt once payment is received.

  // trigger some action here, e.g. delivery of an ebook by email or posting items for shipment in the physical world.
}

run();

philkunz avatar Aug 17 '20 13:08 philkunz

Yes, when the cardano-launcher npm module is installed, it should also download and install the correct binaries.

A while back I looked at how PhantomJS did it: https://github.com/Medium/phantomjs/blob/master/install.js . The script looks quite horrible - even finding the install path for the binaries is not easy.

rvl avatar Aug 17 '20 22:08 rvl

@rvl I've done it previously and it is actually pretty straight forward with node.js (at least for MAC and Linux). The only thing that is important here is to have a very lean dependency tree as we don't want to open up an attack vector by being reliant on too many third party packages and their maintainers (the incentive with billions at stake is quite high here and there have been attacks on popular packages like eslint before -> https://eslint.org/blog/2018/07/postmortem-for-malicious-package-publishes). NodeJS has most things built in that we need for that. As of now cardano-launcher looks pretty much perfect dependency-tree-wise: http://npm.broofa.com/?q=cardano-launcher.

Still, dependencies right now look like this:

"dependencies": {
    "get-port": "^5.1.1",
    "lodash": "^4.17.19",
    "mkdirp": "^1.0.3",
    "tsee": "^1.3.0"
  }

Those should be pinned, as package-lock won't be respected when cardano-launcher is used as dependency and only a single maintainer having his/her rsa keys stolen can jeopardise this package otherwise.

philkunz avatar Aug 17 '20 22:08 philkunz

That's a good point about dependency ranges. I have fixed it in #87.

We have a script to download builds from our Hydra CI server. It's used when we test for windows. I have made the script into a nodejs module, and added linux and macos support in #88. But I don't think I will be able to do a good job of writing the npm install script.

It would be really cool to be able to npm install cardano-launcher and automatically get the correct cardano-wallet and cardano-node installed in node_modules.

rvl avatar Aug 18 '20 02:08 rvl

I still have a few questions before tackling the install script:

  1. Is the version of the downloaded cardano-node and cardano-wallet pinned or are we always going for latest?
  2. In the event that we go for latest -> how do we ensure to catch breaking changes?
  3. In the event that we go for a pinned version ->
    • Do we keep the version updated in the install script itself
    • or are we using a custom section in package.json
    • or are we using a separate .json file to keep that info?

@rvl EDIT: https://github.com/input-output-hk/cardano-launcher/blob/master/nix/sources.json Is this what I'm looking for? and the function getNiv in your script?

philkunz avatar Aug 18 '20 02:08 philkunz

Yes it's pinned, for the reason that you state. cardano-wallet usually requires a specific version of cardano-node, and because the cardano-wallet CLI might change and break cardano-launcher.

And you're correct - the versions are kept in nix/sources.json.

rvl avatar Aug 18 '20 02:08 rvl