diff --git a/.gitignore b/.gitignore
index 6fe20f0..b548e42 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,2 @@
node_modules
-.env
-package-lock.json
\ No newline at end of file
+priv
diff --git a/API.md b/API.md
deleted file mode 100644
index cde8695..0000000
--- a/API.md
+++ /dev/null
@@ -1,583 +0,0 @@
-## Classes
-
-
-- CardanocliJs
-
-
-
-## Typedefs
-
-
-- lovelace
-
-- path
-
-- paymentAddr
-
-- stakeAddr
-
-- TxIn :
Object
-
-- TxOut :
Object
-
-- MintAction :
Object
-
-- Mint :
Object
-
-- Certificate :
Object
-
-- Withdrawal :
Object
-
-
-
-
-
-## CardanocliJs
-**Kind**: global class
-
-* [CardanocliJs](#CardanocliJs)
- * [new CardanocliJs(options)](#new_CardanocliJs_new)
- * [.queryProtocolParameters()](#CardanocliJs+queryProtocolParameters) ⇒ object
- * [.queryTip()](#CardanocliJs+queryTip) ⇒ object
- * [.queryStakeAddressInfo(address)](#CardanocliJs+queryStakeAddressInfo) ⇒ object
- * [.queryUtxo(address)](#CardanocliJs+queryUtxo) ⇒ object
- * [.addressKeyGen(account)](#CardanocliJs+addressKeyGen)
- * [.stakeAddressKeyGen(account)](#CardanocliJs+stakeAddressKeyGen)
- * [.stakeAddressBuild(account)](#CardanocliJs+stakeAddressBuild) ⇒ [path
](#path)
- * [.addressBuild(account, options)](#CardanocliJs+addressBuild)
- * [.addressKeyHash(account)](#CardanocliJs+addressKeyHash)
- * [.addressInfo(address)](#CardanocliJs+addressInfo) ⇒ object
- * [.addressBuildScript(script)](#CardanocliJs+addressBuildScript) ⇒ [paymentAddr
](#paymentAddr)
- * [.wallet(account)](#CardanocliJs+wallet)
- * [.pool(poolName)](#CardanocliJs+pool)
- * [.stakeAddressRegistrationCertificate(account)](#CardanocliJs+stakeAddressRegistrationCertificate) ⇒ [path
](#path)
- * [.stakeAddressDeregistrationCertificate(account)](#CardanocliJs+stakeAddressDeregistrationCertificate) ⇒ [path
](#path)
- * [.stakeAddressDelegationCertificate(account, poolId)](#CardanocliJs+stakeAddressDelegationCertificate) ⇒ [path
](#path)
- * [.stakeAddressKeyHash(account)](#CardanocliJs+stakeAddressKeyHash) ⇒ string
- * [.nodeKeyGenKES(poolName)](#CardanocliJs+nodeKeyGenKES)
- * [.nodeKeyGen(poolName)](#CardanocliJs+nodeKeyGen)
- * [.nodeIssueOpCert(poolName, [kesPeriod])](#CardanocliJs+nodeIssueOpCert) ⇒ [path
](#path)
- * [.nodeKeyGenVRF(poolName)](#CardanocliJs+nodeKeyGenVRF)
- * [.stakePoolId(poolName)](#CardanocliJs+stakePoolId) ⇒ string
- * [.stakePoolMetadataHash(metadata)](#CardanocliJs+stakePoolMetadataHash) ⇒ string
- * [.stakePoolRegistrationCertificate(poolName, options)](#CardanocliJs+stakePoolRegistrationCertificate) ⇒ [path
](#path)
- * [.stakePoolDeregistrationCertificate(poolName, epoch)](#CardanocliJs+stakePoolDeregistrationCertificate) ⇒ [path
](#path)
- * [.transactionBuildRaw(options)](#CardanocliJs+transactionBuildRaw) ⇒ [path
](#path)
- * [.transactionCalculateMinFee(options)](#CardanocliJs+transactionCalculateMinFee) ⇒ [lovelace
](#lovelace)
- * [.transactionPolicyid(script)](#CardanocliJs+transactionPolicyid) ⇒ string
- * [.transactionSign(options)](#CardanocliJs+transactionSign) ⇒ [path
](#path)
- * [.transactionWitness(options)](#CardanocliJs+transactionWitness) ⇒ [path
](#path)
- * [.transactionAssemble(options)](#CardanocliJs+transactionAssemble) ⇒ [path
](#path)
- * [.transactionCalculateMinValue(value)](#CardanocliJs+transactionCalculateMinValue) ⇒ [lovelace
](#lovelace)
- * [.transactionSubmit(tx)](#CardanocliJs+transactionSubmit) ⇒ string
- * [.transactionTxid(options)](#CardanocliJs+transactionTxid) ⇒ [path
](#path)
- * [.transactionView(options)](#CardanocliJs+transactionView) ⇒ [path
](#path)
- * [.KESPeriod()](#CardanocliJs+KESPeriod) ⇒ number
- * [.getDownloadUrl(filePath)](#CardanocliJs+getDownloadUrl) ⇒ [path
](#path)
- * [.toLovelace(ada)](#CardanocliJs+toLovelace) ⇒ [lovelace
](#lovelace)
- * [.toAda(lovelace)](#CardanocliJs+toAda) ⇒ number
-
-
-
-### new CardanocliJs(options)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| options | Object
| |
-| [options.shelleyGenesisPath] | [path
](#path) | |
-| [options.socketPath] | [path
](#path) | Default: Env Variable |
-| [options.cliPath] | [path
](#path) | Default: Env Variable |
-| [options.dir] | [path
](#path) | Default: Working Dir |
-| [options.era] | string
| |
-| [options.network] | string
| Default: mainnet |
-| [options.httpProvider] | string
| Optional - Useful when using cli at different location than node or in browser |
-
-
-
-### cardanocliJs.queryProtocolParameters() ⇒ object
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-
-### cardanocliJs.queryTip() ⇒ object
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-
-### cardanocliJs.queryStakeAddressInfo(address) ⇒ object
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| address | [stakeAddr
](#stakeAddr) |
-
-
-
-### cardanocliJs.queryUtxo(address) ⇒ object
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| address | [paymentAddr
](#paymentAddr) |
-
-
-
-### cardanocliJs.addressKeyGen(account)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| account | string
| Name of account |
-
-
-
-### cardanocliJs.stakeAddressKeyGen(account)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| account | string
| Name of account |
-
-
-
-### cardanocliJs.stakeAddressBuild(account) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| account | string
| Name of account |
-
-
-
-### cardanocliJs.addressBuild(account, options)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| account | string
| Name of account |
-| options | Object
| |
-| [options.paymentVkey] | [path
](#path) | |
-| [options.stakeVkey] | [path
](#path) | |
-| [options.paymentScript] | object
| |
-| [options.stakeScript] | object
| |
-
-
-
-### cardanocliJs.addressKeyHash(account)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| account | string
| Name of account |
-
-
-
-### cardanocliJs.addressInfo(address) ⇒ object
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| address | [paymentAddr
](#paymentAddr) |
-
-
-
-### cardanocliJs.addressBuildScript(script) ⇒ [paymentAddr
](#paymentAddr)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| script | object
|
-
-
-
-### cardanocliJs.wallet(account)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| account | string
| Name of the account |
-
-
-
-### cardanocliJs.pool(poolName)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| poolName | string
| Name of the pool |
-
-
-
-### cardanocliJs.stakeAddressRegistrationCertificate(account) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| account | string
| Name of the account |
-
-
-
-### cardanocliJs.stakeAddressDeregistrationCertificate(account) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| account | string
| Name of the account |
-
-
-
-### cardanocliJs.stakeAddressDelegationCertificate(account, poolId) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| account | string
| Name of the account |
-| poolId | string
| Stake pool verification key (Bech32 or hex-encoded) |
-
-
-
-### cardanocliJs.stakeAddressKeyHash(account) ⇒ string
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| account | string
| Name of the account |
-
-
-
-### cardanocliJs.nodeKeyGenKES(poolName)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| poolName | string
| Name of the pool |
-
-
-
-### cardanocliJs.nodeKeyGen(poolName)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| poolName | string
| Name of the pool |
-
-
-
-### cardanocliJs.nodeIssueOpCert(poolName, [kesPeriod]) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| poolName | string
| Name of the pool |
-| [kesPeriod] | number
| Optional (Offline mode) |
-
-
-
-### cardanocliJs.nodeKeyGenVRF(poolName)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| poolName | string
| Name of the pool |
-
-
-
-### cardanocliJs.stakePoolId(poolName) ⇒ string
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| poolName | string
| Name of the pool |
-
-
-
-### cardanocliJs.stakePoolMetadataHash(metadata) ⇒ string
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| metadata | string
| Raw File |
-
-
-
-### cardanocliJs.stakePoolRegistrationCertificate(poolName, options) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| poolName | string
| Name of the pool |
-| options | Object
| |
-| options.pledge | [lovelace
](#lovelace) | |
-| options.margin | number
| |
-| options.cost | [lovelace
](#lovelace) | |
-| options.url | string
| |
-| options.metaHash | string
| |
-| options.rewardAccount | [path
](#path) | |
-| options.owners | [Array.<path>
](#path) | |
-| options.relays | Array.<Object>
| |
-
-
-
-### cardanocliJs.stakePoolDeregistrationCertificate(poolName, epoch) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| poolName | string
| Name of the pool |
-| epoch | number
| Retirement Epoch |
-
-
-
-### cardanocliJs.transactionBuildRaw(options) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| options | Object
| |
-| options.txIn | [Array.<TxIn>
](#TxIn) | |
-| options.txOut | [Array.<TxOut>
](#TxOut) | |
-| [options.withdrawals] | [Array.<Withdrawal>
](#Withdrawal) | |
-| [options.certs] | [Array.<Certificate>
](#Certificate) | |
-| [options.fee] | [lovelace
](#lovelace) | |
-| [options.mint] | [Mint
](#Mint) | |
-| [options.auxScript] | Array.<object>
| |
-| [options.metadata] | object
| |
-| [options.invalidBefore] | number
| Default: 0 |
-| [options.invalidAfter] | number
| Default: current+10000 |
-
-
-
-### cardanocliJs.transactionCalculateMinFee(options) ⇒ [lovelace
](#lovelace)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| options | Object
|
-| options.txBody | [path
](#path) |
-| options.txIn | Array.<object>
|
-| options.txOut | Array.<object>
|
-| options.witnessCount | number
|
-
-
-
-### cardanocliJs.transactionPolicyid(script) ⇒ string
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-**Returns**: string
- - Policy Id
-
-| Param | Type |
-| --- | --- |
-| script | object
|
-
-
-
-### cardanocliJs.transactionSign(options) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| options | Object
| |
-| options.signingKeys | [Array.<path>
](#path) | One ore more signing keys |
-| options.txBody | [path
](#path) | |
-
-
-
-### cardanocliJs.transactionWitness(options) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| options | Object
|
-| options.txBody | [path
](#path) |
-| options.signingKey | [path
](#path) |
-
-
-
-### cardanocliJs.transactionAssemble(options) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| options | Object
|
-| options.txBody | [path
](#path) |
-| options.witnessFiles | [Array.<path>
](#path) |
-
-
-
-### cardanocliJs.transactionCalculateMinValue(value) ⇒ [lovelace
](#lovelace)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| value | object
|
-
-
-
-### cardanocliJs.transactionSubmit(tx) ⇒ string
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-**Returns**: string
- - Transaction Hash
-
-| Param | Type | Description |
-| --- | --- | --- |
-| tx | [path
](#path) \| string
| Path or Signed Tx File |
-
-
-
-### cardanocliJs.transactionTxid(options) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| options | Object
|
-| [options.txBody] | [path
](#path) |
-| [options.txFile] | [path
](#path) |
-
-
-
-### cardanocliJs.transactionView(options) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| options | Object
|
-| [options.txBody] | [path
](#path) |
-| [options.txFile] | [path
](#path) |
-
-
-
-### cardanocliJs.KESPeriod() ⇒ number
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-
-### cardanocliJs.getDownloadUrl(filePath) ⇒ [path
](#path)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-**Returns**: [path
](#path) - - Download link for the file
-
-| Param | Type |
-| --- | --- |
-| filePath | [path
](#path) |
-
-
-
-### cardanocliJs.toLovelace(ada) ⇒ [lovelace
](#lovelace)
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| ada | number
|
-
-
-
-### cardanocliJs.toAda(lovelace) ⇒ number
-**Kind**: instance method of [CardanocliJs
](#CardanocliJs)
-
-| Param | Type |
-| --- | --- |
-| lovelace | [lovelace
](#lovelace) |
-
-
-
-## lovelace
-**Kind**: global typedef
-**Properties**
-
-| Type |
-| --- |
-| number
|
-
-
-
-## path
-**Kind**: global typedef
-**Properties**
-
-| Type |
-| --- |
-| string
|
-
-
-
-## paymentAddr
-**Kind**: global typedef
-**Properties**
-
-| Type |
-| --- |
-| string
|
-
-
-
-## stakeAddr
-**Kind**: global typedef
-**Properties**
-
-| Type |
-| --- |
-| string
|
-
-
-
-## TxIn : Object
-**Kind**: global typedef
-**Properties**
-
-| Name | Type |
-| --- | --- |
-| txHash | string
|
-| txId | string
|
-| [script] | object
|
-
-
-
-## TxOut : Object
-**Kind**: global typedef
-**Properties**
-
-| Name | Type |
-| --- | --- |
-| address | string
|
-| value | object
|
-
-
-
-## MintAction : Object
-**Kind**: global typedef
-**Properties**
-
-| Name | Type |
-| --- | --- |
-| action | string
|
-| quantity | number
|
-| asset | string
|
-
-
-
-## Mint : Object
-**Kind**: global typedef
-**Properties**
-
-| Name | Type |
-| --- | --- |
-| mintAction | [Array.<MintAction>
](#MintAction) |
-| script | Array.<object>
|
-
-
-
-## Certificate : Object
-**Kind**: global typedef
-**Properties**
-
-| Name | Type |
-| --- | --- |
-| cert | [path
](#path) |
-| [script] | object
|
-
-
-
-## Withdrawal : Object
-**Kind**: global typedef
-**Properties**
-
-| Name | Type |
-| --- | --- |
-| stakingAddress | string
|
-| reward | [lovelace
](#lovelace) |
-| [script] | object
|
-
diff --git a/README.md b/README.md
index 3d3e1c0..74b3414 100644
--- a/README.md
+++ b/README.md
@@ -2,27 +2,16 @@
## Overview
-This is a library, which wraps the cardano-cli with JavaScript and makes it possible to interact with the cli-commands much faster and more efficient.
+This is a library wrapping the cardano-cli with TypeScript (can also be used in Javascript projects) which makes it possible to interact with the cardano CLI much faster and more efficient.
-#### This library was initially brought by [BerryPool](http://pipool.online/) and currently maintained by [Shareslake](https://www.shareslake.com). You can support the work by delegating to the Berry pool.
+## Prerequisites
-#### Donations (ADA):
+You need access to a Cardano Node socket. If you have a remote node you can create a ssh tunnel with the socket file as follows:
-- Shareslake:
-```
-addr1q9rsrh7kjhct7llm88dug6l5mh047gq6yq3wt3gjfd6uk3ldch4wp7w7v3ac4wp6q33gz2kemwn8ap6zch0u3za6pypshaa6ry
-```
-- Berry:
```
-addr1q97x8rfnkw4pmdgnwjzavl8jvg77tuy6wn3wm90x9emwgj8nhh356yzp7k3qwmhe4fk0g5u6kx5ka4rz5qcq4j7mvh2sg67tj5
+ssh -nNT -L /tmp/forwarded.socket:/path/to/remote/node.socket remote-machine-user@remote-machine-ip
```
-
-## Prerequisites
-
-- `cardano-node >= 1.29.0`
-- `node.js >= 12.19.0`
-
## Install
#### NPM
@@ -34,7 +23,7 @@ npm install cardanocli-js
#### From source
```bash
-git clone https://github.com/shareslake/cardanocli-js.git
+git clone https://github.com/miguelaeh/cardanocli-js.git
cd cardanocli-js
npm install
```
@@ -48,75 +37,41 @@ const shelleyGenesisPath = "/home/ada/mainnet-shelley-genesis.json";
const cardanocliJs = new CardanocliJs({ shelleyGenesisPath });
const createWallet = (account) => {
- const payment = cardanocliJs.addressKeyGen(account);
- const stake = cardanocliJs.stakeAddressKeyGen(account);
- cardanocliJs.stakeAddressBuild(account);
- cardanocliJs.addressBuild(account, {
+ const payment = cardanocliJs.address.keyGen(account);
+ const stake = cardanocliJs.stake_address.keyGen(account);
+ cardanocliJs.stake_address.build(account);
+ const addr = cardanocliJs.address.build(account, {
paymentVkey: payment.vkey,
stakeVkey: stake.vkey,
});
- return cardanocliJs.wallet(account);
+ return addr;
};
-const createPool = (name) => {
- cardanocliJs.nodeKeyGenKES(name);
- cardanocliJs.nodeKeyGen(name);
- cardanocliJs.nodeIssueOpCert(name);
- cardanocliJs.nodeKeyGenVRF(name);
- return cardanocliJs.pool(name);
-};
+const walletAddr = createWallet("my-wallet-name");
-const wallet = createWallet("Ada");
-const pool = createPool("Berry");
-
-console.log(wallet.paymentAddr);
-console.log(pool.vrf.vkey);
+console.log("My wallet address:", walletAddr);
```
-Check /examples for more use cases.
-
-## API
+Check `/examples` for more use cases. If you have doubts on how to use a specific command you can also check the `tests` folder, where all the commands are tested.
-- API Documentation
-
-## Structure
-
-All files will be stored and used in the directory you choose when instantiating CardanocliJs (`dir`).
-The directory is split in two subfolders `tmp` and `priv`.
-In the `tmp` folder are stored protocol paramters, raw transactions, signed transactions and witnesses with unique identifiers.
-The `priv` folder is again divided into two subolders holding on one site the pools `pool` and on the other side the wallets `wallet` (like [CNTools](https://cardano-community.github.io/guild-operators/#/) structure).
+## Tests
-Example structure:
+Install npm dev dependencies using `npm install --also=dev`.
-```
-dir
- tmp
-
- ...
- priv
- pool
- Berry
-
-
-
- ...
- wallet
- Lovelace
-
-
- ...
-```
+Tests are using Jest framework and can be run by using `npm run-script test` command.
-## Tests
+Tests are configured to run with the Sancho network. You may need to update your `cardano-cli` binary to the sancho one in order to run the tests.
-Install npm dev dependencies using `npm install --also=dev`.
+## Major changes
-Tests are using Jest framework and can be run by using `npm -s run test` command.
+### 5.0.0
-To configure the test suite, make a copy of `.env.dist` and rename it `.env`. Then change all parameters values to fit your environment.
+Starting on version `4.0.0` the HTTP provider has been removed. There are better options for that as of today. For example, the blockfrost API.
+This means than to use this library you need a fully synced node. And it is, as its name states, a wrapper over the CLI to make your life easier when creating scripts.
+If you need to connect to your own remote cardano nodes you can forward the socket via an SSH tunnel:
-**Caution**: The `TEST_WORKSPACE_DIR` will be deleted at the end of the test suite. **NEVER USE AN EXISTING DIRECTORY !!!** You may disable this behavior by commenting the cleanup function in `test/index.test.js`:
+```
+ssh -nNT -L /tmp/forwarded.socket:/path/to/remote/node.socket remote-machine-user@remote-machine-ip
+```
- afterAll(() => {
- // cleanUpTestDirectory();
- });
+For better maintencane, the library has been moved to TypesScript and its internal structure changed.
diff --git a/examples/deregisterWallet.js b/examples/deregisterWallet.js
deleted file mode 100644
index c77b7bf..0000000
--- a/examples/deregisterWallet.js
+++ /dev/null
@@ -1,58 +0,0 @@
-const CardanocliJs = require("../index.js");
-const os = require("os");
-const path = require("path");
-
-const dir = path.join(os.homedir(), "testnet");
-const shelleyPath = path.join(
- os.homedir(),
- "testnet",
- "testnet-shelley-genesis.json"
-);
-
-const cardanocliJs = new CardanocliJs({
- network: "testnet-magic 1097911063",
- dir: dir,
- shelleyGenesisPath: shelleyPath,
-});
-
-const deregisterWallet = (wallet) => {
- let account = wallet.name;
- let stakeAddressDeposit = cardanocliJs.queryProtocolParameters().stakeAddressDeposit;
- let stakeCert = cardanocliJs.stakeAddressDeregistrationCertificate(account);
- let paymentAddress = cardanocliJs.wallet(account).paymentAddr;
- let balance = cardanocliJs.wallet(account).balance().value.lovelace;
- let tx = {
- txIn: cardanocliJs.queryUtxo(paymentAddress),
- txOut: [
- { address: paymentAddress, value: { lovelace: balance + stakeAddressDeposit } },
- ],
- certs: [{ cert: stakeCert }],
- witnessCount: 2,
- };
- let txBodyRaw = cardanocliJs.transactionBuildRaw(tx);
- let fee = cardanocliJs.transactionCalculateMinFee({
- ...tx,
- txBody: txBodyRaw,
- });
- tx.txOut[0].value.lovelace -= fee;
- let txBody = cardanocliJs.transactionBuildRaw({ ...tx, fee });
- let txSigned = cardanocliJs.transactionSign({
- txBody,
- signingKeys: [
- cardanocliJs.wallet(account).payment.skey,
- cardanocliJs.wallet(account).stake.skey,
- ],
- });
-
- return txSigned;
-};
-
-let wallet = cardanocliJs.wallet("Test");
-
-console.log(wallet);
-
-let tx = deregisterWallet(wallet);
-
-let txHash = cardanocliJs.transactionSubmit(tx);
-
-console.log("TxHash: " + txHash);
diff --git a/examples/mintMA.js b/examples/mintMA.js
index 21cd4cd..a5c94fb 100644
--- a/examples/mintMA.js
+++ b/examples/mintMA.js
@@ -1,63 +1,71 @@
-const CardanocliJs = require("../index.js");
-const os = require("os");
-const path = require("path");
-
-const dir = path.join(os.homedir(), "testnet");
-const shelleyPath = path.join(
- os.homedir(),
- "testnet",
- "testnet-shelley-genesis.json"
-);
-
-const cardanocliJs = new CardanocliJs({
- network: "testnet-magic 1097911063",
- dir: dir,
- shelleyGenesisPath: shelleyPath,
-});
+import CardanoCliJs from "../index";
+import { CardanoCliJsOptions } from "../lib/cardanoclijs";
+import fs from 'fs';
-const createTransaction = (tx) => {
- let raw = cardanocliJs.transactionBuildRaw(tx);
- let fee = cardanocliJs.transactionCalculateMinFee({
- ...tx,
- txBody: raw,
- });
- tx.txOut[0].value.lovelace -= fee;
- return cardanocliJs.transactionBuildRaw({ ...tx, fee });
-};
+const options = new CardanoCliJsOptions({ shelleyGenesisPath: `${__dirname}/../tests/assets/shelley-genesis.json` });
+const cli = new CardanoCliJs(options);
-const signTransaction = (wallet, tx, script) => {
- return cardanocliJs.transactionSign({
- signingKeys: [wallet.payment.skey, wallet.payment.skey],
- txBody: tx,
+const createWallet = (account) => {
+ const payment = cardanocliJs.address.keyGen(account);
+ const stake = cardanocliJs.stake_address.keyGen(account);
+ cardanocliJs.stake_address.build(account);
+ const addr = cardanocliJs.address.build(account, {
+ paymentVkey: payment.vkey,
+ stakeVkey: stake.vkey,
});
+ return addr;
};
-const wallet = cardanocliJs.wallet("Berry");
+const walletName = "test-wallet";
+const wallet = createWallet(walletName);
const mintScript = {
- keyHash: cardanocliJs.addressKeyHash(wallet.name),
+ keyHash: cli.address.keyHash(walletName),
type: "sig",
};
-const policy = cardanocliJs.transactionPolicyid(mintScript);
+const scriptFile = fs.writeFileSync("/tmp/script.json", JSON.stringify(mintScript));
+const policyId = cli.transaction.transactionPolicyId(scriptFile);
const realAssetName = "Berrycoin"
const assetName = Buffer.from(realAssetName).toString('hex')
-const BERRYCOIN = policy + "." + assetName;
-
-const tx = {
- txIn: wallet.balance().utxo,
- txOut: [
- {
- address: wallet.paymentAddr,
- value: { ...wallet.balance().value, [BERRYCOIN]: 100 },
- },
- ],
- mint: [
- { action: "mint", quantity: 100, asset: BERRYCOIN, script: mintScript },
- ],
- witnessCount: 2,
-};
+const BERRYCOIN = policyId + "." + assetName;
+
+const addr = fs.readFileSync(`${cli.options.dir}/priv/wallet/${walletName}/${walletName}.payment.addr`, 'utf8');
+const utxos = cli.query.utxo(addr);
+const balance = utxos.forEach((utxo) => {
+ Object.keys(utxo.value).forEach((asset) => {
+ if (!value[asset]) value[asset] = 0;
+ value[asset] += utxo.value[asset];
+ });
+});
+
+// Create raw tx
+const raw_opts = [];
+for (let utxo of Object.keys(utxos)) {
+ raw_opts.push({ name: 'tx-in', value: utxo});
+}
+raw_opts.push({ name: 'tx-out', value: `${addr} ${balance}`});
+// Mint 100 tokens
+raw_opts.push({ name: 'mint', value: `100 ${BERRYCOIN}`});
+raw_opts.push({ name: 'minting-script-file', value: scriptFile });
+const draftTxFile = cli.transaction.buildRaw(raw_opts);
+const fee = cli.transaction.calculateMinFee(draftTxFile, utxos.length, 1, 1);
+
+// Create the options again with the correct amount (removing the fee)
+const opts = [];
+for (let utxo of Object.keys(utxos)) {
+ opts.push({ name: 'tx-in', value: utxo});
+}
+opts.push({ name: 'tx-out', value: `${addr} ${balance - fee}`});
+// Mint 100 tokens
+opts.push({ name: 'mint', value: `100 ${BERRYCOIN}`});
+opts.push({ name: 'minting-script-file', value: scriptFile });
+opts.push({ name: 'fee', value: fee });
+const rawTxFile = cli.transaction.buildRaw(opts);
+
+const signedTxFile = cli.transaction.sign(rawTxFile, [
+ `${cli.options.dir}/priv/wallet/${walletName}/${walletName}.payment.skey`
+]);
+
+console.log(cli.transaction.view({ txFile: signedTxFile }));
-const raw = createTransaction(tx);
-const signed = signTransaction(wallet, raw);
-console.log(cardanocliJs.transactionView({ txFile: signed }));
-const txHash = cardanocliJs.transactionSubmit(signed);
-console.log(txHash);
+// Submit the transaction to actually mint the asset
+cli.transaction.submit(signedTxFile);
diff --git a/examples/queryTip.js b/examples/queryTip.js
index 3e81435..e528055 100644
--- a/examples/queryTip.js
+++ b/examples/queryTip.js
@@ -1,20 +1,7 @@
-const CardanocliJs = require("../index.js");
-const os = require("os");
-const path = require("path");
+import CardanoCliJs from "../index";
+import { CardanoCliJsOptions } from "../lib/cardanoclijs";
-const dir = path.join(os.homedir(), "testnet");
-const shelleyPath = path.join(
- os.homedir(),
- "testnet",
- "testnet-shelley-genesis.json"
-);
+const options = new CardanoCliJsOptions({ shelleyGenesisPath: `${__dirname}/../tests/assets/shelley-genesis.json` });
+const cli = new CardanoCliJs(options);
-const cardanocliJs = new CardanocliJs({
- network: "testnet-magic 1097911063",
- era: "alonzo",
- dir: dir,
- shelleyGenesisPath: shelleyPath,
- socketPath: path.join(os.homedir(), "testnet", "db", "socket"),
-});
-
-console.log(cardanocliJs.queryTip());
+console.log(cli.query.tip());
diff --git a/examples/registerPool.js b/examples/registerPool.js
index cdc050c..085074c 100644
--- a/examples/registerPool.js
+++ b/examples/registerPool.js
@@ -1,86 +1,53 @@
-const CardanocliJs = require("../index.js");
-const os = require("os");
-const path = require("path");
-const fetch = require("sync-fetch");
-
-const dir = path.join(os.homedir(), "testnet");
-const shelleyPath = path.join(
- os.homedir(),
- "testnet",
- "testnet-shelley-genesis.json"
-);
-
-const cardanocliJs = new CardanocliJs({
- network: "testnet-magic 1097911063",
- dir: dir,
- shelleyGenesisPath: shelleyPath,
-});
-
-const createPool = (name) => {
- cardanocliJs.nodeKeyGenKES(name);
- cardanocliJs.nodeKeyGen(name);
- cardanocliJs.nodeIssueOpCert(name);
- cardanocliJs.nodeKeyGenVRF(name);
- return cardanocliJs.pool(name);
-};
-
-const registerPool = (pool, wallet, data) => {
- let name = pool.name;
- let poolId = cardanocliJs.stakePoolId(name);
- let poolCert = cardanocliJs.stakePoolRegistrationCertificate(name, data);
- let delegCert = cardanocliJs.stakeAddressDelegationCertificate(
- wallet.name,
- poolId
- );
- let poolDeposit = cardanocliJs.queryProtocolParameters().poolDeposit;
- let tx = {
- txIn: wallet.balance().utxo,
- txOut: [
- {
- address: wallet.paymentAddr,
- value: { lovelace: wallet.balance().value.lovelace - poolDeposit },
- },
- ],
- witnessCount: 3,
- certs: [{ cert: poolCert }, { cert: delegCert }],
- };
- let txBodyRaw = cardanocliJs.transactionBuildRaw(tx);
- let fee = cardanocliJs.transactionCalculateMinFee({
- ...tx,
- txBody: txBodyRaw,
- });
- tx.txOut[0].value.lovelace -= fee;
- let txBody = cardanocliJs.transactionBuildRaw({ ...tx, fee });
- let txSigned = cardanocliJs.transactionSign({
- txBody,
- signingKeys: [wallet.payment.skey, wallet.stake.skey, pool.node.skey],
+import CardanoCliJs from "../index";
+import { CardanoCliJsOptions } from "../lib/cardanoclijs";
+
+const options = new CardanoCliJsOptions({ shelleyGenesisPath: `${__dirname}/../tests/assets/shelley-genesis.json` });
+const cli = new CardanoCliJs(options);
+
+const createWallet = (account) => {
+ const payment = cardanocliJs.address.keyGen(account);
+ const stake = cardanocliJs.stake_address.keyGen(account);
+ cardanocliJs.stake_address.build(account);
+ const addr = cardanocliJs.address.build(account, {
+ paymentVkey: payment.vkey,
+ stakeVkey: stake.vkey,
});
- return txSigned;
+ return addr;
};
-let pool = createPool("BerryJs");
-
-const wallet = cardanocliJs.wallet("Ada");
-console.log(wallet);
-
-const poolData = {
- pledge: cardanocliJs.toLovelace(100),
- margin: 0.015,
- cost: cardanocliJs.toLovelace(340),
- owners: [wallet.stake.vkey],
- rewardAccount: wallet.stake.vkey,
+const walletName = "test-wallet";
+const wallet = createWallet(walletName);
+
+const poolName = "test-pool";
+const poolKesKeys = cli.node.keyGenKES(poolName);
+const poolKeys = cli.node.keyGen(poolName);
+const poolOpCert = cli.node.issueOpCert(poolName, {});
+const poolVrfKeys = cli.node.keyGenVRF(poolName);
+
+const poolId = cli.stake_pool.id(poolName);
+const poolCert = cli.stake_pool.registrationCertificate(poolName, {
+ pledge: 100000000,
+ margin: 0.0015,
+ cost: 340000000,
+ url: "https://test-url.com",
+ metaHash: cli.stake_pool.metadataHash({
+ name: "YourPoolName",
+ description: "Your pool description",
+ ticker: "TEST",
+ homepage: "https://yourpoollink.com"
+ }),
+ rewardAccountFile: `${cli.options.dir}/priv/wallet/${walletName}/${walletName}.stake.vkey`,
+ ownersStakeVKeyFiles: [ `${cli.options.dir}/priv/wallet/${walletName}/${walletName}.stake.vkey` ],
relays: [
{ host: "relay.one.io", port: 3001 },
{ host: "relay.two.io", port: 3001 },
],
- url: "",
- metaHash: cardanocliJs.stakePoolMetadataHash(fetch("").text()),
-};
-
-console.log(poolData);
-
-let tx = registerPool(pool, wallet, poolData);
+});
-let txHash = cardanocliJs.transactionSubmit(tx);
+const stakeAddrDelegCert = cli.stake_address.delegationCertificate(walletName, { stakePoolId: poolId });
+const poolDeposit = cli.query.protocolParameters().poolDeposit;
-console.log("TxHash: " + txHash);
+// Just create the transaction as always and sign with 3 witness count:
+// `${cli.options.dir}/priv/wallet/${walletName}/${walletName}.payment.skey`
+// `${cli.options.dir}/priv/wallet/${walletName}/${walletName}.stake.vkey`
+// `${cli.options.dir}/priv/wallet/${poolName}/${poolName}.node.skey`
diff --git a/examples/registerWallet.js b/examples/registerWallet.js
deleted file mode 100644
index 6b651e6..0000000
--- a/examples/registerWallet.js
+++ /dev/null
@@ -1,72 +0,0 @@
-const CardanocliJs = require("../index.js");
-const os = require("os");
-const path = require("path");
-
-const dir = path.join(os.homedir(), "testnet");
-const shelleyPath = path.join(
- os.homedir(),
- "testnet",
- "testnet-shelley-genesis.json"
-);
-
-const cardanocliJs = new CardanocliJs({
- network: "testnet-magic 1097911063",
- dir: dir,
- shelleyGenesisPath: shelleyPath,
-});
-
-const createWallet = (account) => {
- const payment = cardanocliJs.addressKeyGen(account);
- const stake = cardanocliJs.stakeAddressKeyGen(account);
- cardanocliJs.stakeAddressBuild(account);
- cardanocliJs.addressBuild(account, {
- paymentVkey: payment.vkey,
- stakeVkey: stake.vkey,
- });
- return cardanocliJs.wallet(account);
-};
-
-const registerWallet = (wallet) => {
- let account = wallet.name;
- let stakeAddressDeposit = cardanocliJs.queryProtocolParameters().stakeAddressDeposit;
- let stakeCert = cardanocliJs.stakeAddressRegistrationCertificate(account);
- let paymentAddress = cardanocliJs.wallet(account).paymentAddr;
- let balance = cardanocliJs.wallet(account).balance().value.lovelace;
- if (balance < stakeAddressDeposit) {
- throw new Error("The wallet balance needs to be higher than stakeAddressDeposit");
- }
- let tx = {
- txIn: cardanocliJs.queryUtxo(paymentAddress),
- txOut: [
- { address: paymentAddress, value: { lovelace: balance - stakeAddressDeposit } },
- ],
- certs: [{ cert: stakeCert }],
- witnessCount: 2,
- };
- let txBodyRaw = cardanocliJs.transactionBuildRaw(tx);
- let fee = cardanocliJs.transactionCalculateMinFee({
- ...tx,
- txBody: txBodyRaw,
- });
- tx.txOut[0].value.lovelace -= fee;
- let txBody = cardanocliJs.transactionBuildRaw({ ...tx, fee });
- let txSigned = cardanocliJs.transactionSign({
- txBody,
- signingKeys: [
- cardanocliJs.wallet(account).payment.skey,
- cardanocliJs.wallet(account).stake.skey,
- ],
- });
-
- return txSigned;
-};
-
-let wallet = createWallet("Test");
-
-console.log(wallet);
-
-let tx = registerWallet(wallet);
-
-let txHash = cardanocliJs.transactionSubmit(tx);
-
-console.log("TxHash: " + txHash);
diff --git a/examples/simpleTransaction.js b/examples/simpleTransaction.js
index 6704c71..7329c8b 100644
--- a/examples/simpleTransaction.js
+++ b/examples/simpleTransaction.js
@@ -1,68 +1,33 @@
-const CardanocliJs = require("../index.js");
-const os = require("os");
-const path = require("path");
+import CardanoCliJs from "../index";
+import { CardanoCliJsOptions } from "../lib/cardanoclijs";
-const dir = path.join(os.homedir(), "testnet");
-const shelleyPath = path.join(
- os.homedir(),
- "testnet",
- "testnet-shelley-genesis.json"
-);
-
-const cardanocliJs = new CardanocliJs({
- network: "testnet-magic 1097911063",
- dir: dir,
- shelleyGenesisPath: shelleyPath,
- socketPath: path.join(os.homedir(), "testnet", "db", "socket"),
-});
+const options = new CardanoCliJsOptions({ shelleyGenesisPath: `${__dirname}/../tests/assets/shelley-genesis.json` });
+const cli = new CardanoCliJs(options);
//funded wallet
-const sender = cardanocliJs.wallet("Ales");
-console.log(
- "Balance of Sender wallet: " +
- cardanocliJs.toAda(sender.balance().value.lovelace) +
- " ADA"
-);
+const sender = "addr_test1qzjlc05tyyw264wy7m4u7np5yqdwglks0xhu6765cl4qex9r9kvav4hmznru9px9n7cpa2hmmv4593eegve3t834xppqwdsllm3km";
+const utxos = cli.query.utxo(addr);
+const utxoIds = Object.keys(utxos);
+const balance = utxos.forEach((utxo) => {
+ Object.keys(utxo.value).forEach((asset) => {
+ if (!value[asset]) value[asset] = 0;
+ value[asset] += utxo.value[asset];
+ });
+});
//receiver address
const receiver =
"addr_test1qzjlc05tyyw264wy7m4u7np5yqdwglks0xhu6765cl4qex9r9kvav4hmznru9px9n7cpa2hmmv4593eegve3t834xppqwskp4t";
-// create raw transaction
-let txInfo = {
- txIn: cardanocliJs.queryUtxo(sender.paymentAddr),
- txOut: [
- {
- address: sender.paymentAddr,
- value: {
- lovelace: sender.balance().value.lovelace - cardanocliJs.toLovelace(5),
- },
- }, //value going back to sender
- { address: receiver, value: { lovelace: cardanocliJs.toLovelace(5) } }, //value going to receiver
- ],
- metadata: { 1: { cardanocliJs: "First Metadata from cardanocli-js" } },
-};
-let raw = cardanocliJs.transactionBuildRaw(txInfo);
-
-//calculate fee
-let fee = cardanocliJs.transactionCalculateMinFee({
- ...txInfo,
- txBody: raw,
- witnessCount: 1,
-});
-
-//pay the fee by subtracting it from the sender utxo
-txInfo.txOut[0].value.lovelace -= fee;
+const amountToSend = 5000000; // 5 ADA
+const rawTxFile = cli.transaction.build([
+ ...utxoIds.map((u) => ({ name: "tx-in", value: u })),
+ { name: 'tx-out', value: `${receiver} ${amountToSend}`},
+ { name: "change-address", value: sender },
+]);
-//create final transaction
-let tx = cardanocliJs.transactionBuildRaw({ ...txInfo, fee });
-
-//sign the transaction
-let txSigned = cardanocliJs.transactionSign({
- txBody: tx,
- signingKeys: [sender.payment.skey],
-});
+const signedTxFile = cli.transaction.sign(rawTxFile, [
+ `path/to/payment.skey`
+]);
-//broadcast transaction
-let txHash = cardanocliJs.transactionSubmit(txSigned);
-console.log("TxHash: " + txHash);
+cli.transaction.submit(signedTxFile);
diff --git a/helper.js b/helper.js
deleted file mode 100644
index bcdb2de..0000000
--- a/helper.js
+++ /dev/null
@@ -1,254 +0,0 @@
-const fs = require("fs");
-
-exports.ownerToString = (ownerList) => {
- let result = "";
- ownerList.forEach(
- (owner) => (result += `--pool-owner-stake-verification-key-file ${owner} `)
- );
- return result;
-};
-
-exports.relayToString = (relayList) => {
- let result = "";
- relayList.forEach((relay) => {
- if (!((relay.host || relay.ip) && relay.port) && !relay.multiHost)
- throw new Error("Relay is missing arguments");
- if (relay.host) {
- result += `--single-host-pool-relay ${relay.host} --pool-relay-port ${relay.port} `;
- } else if (relay.ip) {
- result += `--pool-relay-ipv4 ${relay.ip} --pool-relay-port ${relay.port} `;
- } else if (relay.multiHost) {
- result += `--multi-host-pool-relay ${relay.multiHost} `;
- }
- });
- return result;
-};
-
-exports.certToString = (dir, certList) => {
- let result = "";
- certList.forEach(
- (cert) =>
- (result += `--certificate ${cert.cert} ${
- cert.script
- ? `--certificate-script-file ${this.jsonToPath(dir, cert.script)} `
- : ""
- } ${
- cert.datum
- ? `--certificate-script-datum-value '${JSON.stringify(cert.datum)}' `
- : ""
- } ${
- cert.redeemer
- ? `--certificate-script-redeemer-value '${JSON.stringify(
- cert.redeemer
- )}' `
- : ""
- } ${
- cert.executionUnits
- ? `--certificate-execution-units "(${
- cert.executionUnits[0] + "," + cert.executionUnits[1]
- })" `
- : ""
- }`)
- );
- return result;
-};
-
-exports.withdrawalToString = (dir, withdrawalList) => {
- let result = "";
- withdrawalList.forEach(
- (withdrawal) =>
- (result += `--withdrawal ${withdrawal.stakingAddress}+${
- withdrawal.reward
- } ${
- withdrawal.script
- ? `--withdrawal-script-file ${this.jsonToPath(
- dir,
- withdrawal.script
- )} `
- : ""
- } ${
- withdrawal.datum
- ? `--withdrawal-script-datum-value '${JSON.stringify(
- withdrawal.datum
- )}' `
- : ""
- } ${
- withdrawal.redeemer
- ? `--withdrawal-script-redeemer-value '${JSON.stringify(
- withdrawal.redeemer
- )}' `
- : ""
- } ${
- withdrawal.executionUnits
- ? `--withdrawal-execution-units "(${
- withdrawal.executionUnits[0] + "," + withdrawal.executionUnits[1]
- })" `
- : ""
- }`)
- );
- return result;
-};
-
-exports.auxScriptToString = (dir, scriptList) => {
- return scriptList
- .map((script) => `--auxiliary-script-file ${this.jsonToPath(dir, script)}`)
- .join(" ");
-};
-
-exports.jsonToPath = (dir, json, type = "script") => {
- let scriptUID = Math.random().toString(36).substr(2, 9);
- fs.writeFileSync(
- `${dir}/tmp/${type}_${scriptUID}.json`,
- JSON.stringify(json)
- );
- return `${dir}/tmp/${type}_${scriptUID}.json`;
-};
-
-exports.txInToString = (dir, txInList, isCollateral) => {
- let result = "";
- txInList.forEach(
- (txIn) =>
- (result += `--tx-in${isCollateral ? "-collateral" : ""} ${txIn.txHash}#${
- txIn.txId
- } ${
- txIn.script
- ? `--tx-in-script-file ${this.jsonToPath(dir, txIn.script)} `
- : ""
- } ${
- txIn.datum
- ? `--tx-in-datum-value '${JSON.stringify(txIn.datum)}' `
- : ""
- } ${
- txIn.redeemer
- ? `--tx-in-redeemer-value '${JSON.stringify(txIn.redeemer)}' `
- : ""
- } ${
- txIn.executionUnits
- ? `--tx-in-execution-units "(${
- txIn.executionUnits[0] + "," + txIn.executionUnits[1]
- })" `
- : ""
- }`)
- );
- return result;
-};
-
-exports.txOutToString = (txOutList) => {
- let result = "";
- let assetOutStr;
- txOutList.forEach((txOut) => {
- assetOutStr = "";
- result += `--tx-out ${txOut.address}+${txOut.value.lovelace}`;
- Object.keys(txOut.value).forEach((asset) => {
- if (asset == "lovelace") return;
- assetOutStr += `+${txOut.value[asset]} ${asset}`;
- });
- if (assetOutStr)
- result += `+"${assetOutStr.slice(1)}"`;
- txOut.datumHash && (result += ` --tx-out-datum-hash ${txOut.datumHash}`);
- result += " ";
- });
- return result;
-};
-
-exports.signingKeysToString = (signingKeys) => {
- let result = "";
- signingKeys.forEach(
- (signingKey) => (result += `--signing-key-file ${signingKey} `)
- );
- return result;
-};
-
-exports.witnessFilesToString = (witnessFiles) => {
- let result = "";
- witnessFiles.forEach(
- (witnessFile) => (result += `--witness-file ${witnessFile} `)
- );
- return result;
-};
-
-exports.fileException = (callback) => {
- try {
- callback();
- } catch {}
-};
-
-exports.setKeys = (obj, path, value) => {
- var pList = path.split(".");
- var len = pList.length;
- for (var i = 0; i < len - 1; i++) {
- var elem = pList[i];
- if (!obj[elem]) obj[elem] = {};
- obj = obj[elem];
- }
-
- obj[pList[len - 1]] = value;
-};
-
-exports.fileExists = (files) => {
- for (file of files) {
- let exists;
- this.fileException(() => {
- exists = fs.readFileSync(file);
- });
- if (exists)
- throw new Error(
- `File ${file} already exists. Remove it manually if you want to create a new file.`
- );
- }
-};
-
-exports.mintToString = (dir, minting) => {
- let result = `--mint="`;
- minting.forEach((mint, index, arr) => {
- if (
- !(
- (mint.quantity || mint.asset) &&
- (mint.action == "mint" || mint.action == "burn")
- )
- )
- throw new Error("action, asset and quantity property required");
- if (Object.is(arr.length - 1, index)) {
- result += `${mint.action == "mint" ? "" : "-"}${mint.quantity} ${
- mint.asset
- }`;
- } else {
- result += `${mint.action == "mint" ? "" : "-"}${mint.quantity} ${
- mint.asset
- }+`;
- }
- });
- result = result.trim();
- result += `" `;
- const usedScripts = [];
- result += minting
- .map((mint) => {
- const script = this.jsonToPath(dir, mint.script);
- if (usedScripts.includes(script)) return "";
- usedScripts.push(script);
- return `--mint-script-file ${script} ${
- mint.redeemer
- ? `--mint-redeemer-value '${JSON.stringify(mint.redeemer)}' `
- : ""
- } ${
- mint.executionUnits
- ? `--mint-execution-units "(${
- mint.executionUnits[0] + "," + mint.executionUnits[1]
- })" `
- : ""
- }`;
- })
- .join(" ");
- return result;
-};
-
-exports.multiAssetToString = (options) => {
- let result = `"${options.address} + `;
- result += `${options.value.lovelace}`;
- Object.keys(options.value).forEach((asset) => {
- if (asset == "lovelace") return;
- result += `+${options.value[asset]} ${asset}`;
- });
- result += `"`;
- return result;
-};
diff --git a/index.d.ts b/index.d.ts
deleted file mode 100644
index 42fe762..0000000
--- a/index.d.ts
+++ /dev/null
@@ -1,231 +0,0 @@
-// Typescript type definitions for cardanocli-js
-
-export class CardanocliJs {
- constructor(options: CardanocliJs.ConstructorOptions);
-
- queryProtocolParameters(): any;
- queryTip(): CardanocliJs.QueryTip;
- queryStakeAddressInfo(address: string): CardanocliJs.StakeAddressInfo[];
- queryUtxo(address: string): CardanocliJs.Utxo[];
-
- addressKeyGen(account: string): CardanocliJs.Account;
-
- stakeAddressKeyGen(account: string): CardanocliJs.Account;
- stakeAddressBuild(account: string): string;
-
- addressBuild(account: string, options: CardanocliJs.AddressBuildOptions): string;
- addressKeyHash(account: string): string;
- addressInfo(address: string): CardanocliJs.AddressInfo;
- addressBuildScript(script: any): string;
-
- wallet(account: string): CardanocliJs.Wallet;
-
- pool(poolName: string): CardanocliJs.Pool;
-
- stakeAddressRegistrationCertificate(account: string): string;
- stakeAddressDeregistrationCertificate(accout: string): string;
- stakeAddressDelegationCertificate(account: string, poolId: string): string;
- stakeAddressKeyHash(account: string): string;
-
- nodeKeyGenKES(poolName: string): CardanocliJs.Account;
- nodeKeyGen(poolName: string): CardanocliJs.Account;
- nodeIssueOpCert(poolName: string, kesPeriod: number): string;
- nodeKeyGenVRF(poolName: string): CardanocliJs.Account;
- nodeNewCounter(poolName: string, counter: string): string;
-
- stakePoolId(poolName: string): string;
- stakePoolMetadataHash(metadata: string): string;
- stakePoolRegistrationCertificate(poolName: string, options: CardanocliJs.StakePoolRegistrationOptions): string;
- stakePoolDeregistrationCertificate(poolName: string, epoch: number): string;
-
- transactionBuildRaw(options: CardanocliJs.Transaction): string;
- transactionBuild(options: CardanocliJs.Transaction): string;
- transactionCalculateMinFee(options: CardanocliJs.CalculateMinFeeOptions): number;
- transactionPolicyid(script: any): string;
- transactionHashScriptData(script: any): string;
- transactionSign(options: CardanocliJs.TransationSignOptions): string;
- transactionWitness(options:CardanocliJs.TransactionWitnessOptions): string;
- transactionAssemble(options: CardanocliJs.TransactionAssembleOptions): string;
- transactionCalculateMinValue(value: number): number;
- transactionCalculateMinRequiredUtxo(address: string, value: any): number;
- transactionSubmit(tx: string): string;
- transactionTxid(options: CardanocliJs.TransactionViewOptions): string;
- transactionView(options: CardanocliJs.TransactionViewOptions): string;
-
- KESPeriod(): number;
- getDownloadUrl(filePath: string): string;
-
- toLovelace(ada: number): number;
- toAda(lovelace: number): number;
-}
-
-declare namespace CardanocliJs {
-
- export interface ConstructorOptions {
- shelleyGenesisPath: string,
- socketPath?: string,
- cliPath?: string,
- dir?: string,
- era?: string,
- network?: string,
- httpProvider?: string,
- }
-
- export interface AddressBuildOptions {
- paymentVkey?: string,
- stakeVkey?: string,
- paymentScript?: string,
- stakeScript?: string,
- }
-
- export interface StakePoolRegistrationOptions {
- pledge: number,
- margin: number,
- cost: number,
- url: string,
- metaHash: string,
- rewardAccount: string,
- owners: string[],
- relays: any[]
- }
-
- export interface CalculateMinFeeOptions {
- txBody: string,
- txIn: TxIn[],
- txOut: TxOut[],
- witnessCount: number,
- }
-
- export interface TransationSignOptions {
- signingKeys: string[],
- txBody: string,
- }
-
- export interface TransactionWitnessOptions {
- txBody: string,
- signingKey: string,
- }
-
- export interface TransactionAssembleOptions {
- txBody: string,
- witnessFiles: string[],
- }
-
- export interface TransactionViewOptions {
- txBody?: string,
- txFile?: string,
- }
-
- export interface Transaction {
- txIn: TxIn[],
- txOut: TxOut[],
- txInCollateral?: TxInCollateral[],
- withdrawals?: Withdrawal[],
- certs?: Certificate[],
- fee?: number,
- mint?: Mint[],
- auxScript?: any,
- metadata?: any,
- invalidBefore?: number,
- invalidAfter?: number,
- scriptInvalid?: boolean,
- }
-
- export interface QueryTip {
- epoch: number,
- hash: string,
- slot: number,
- block: number,
- era: string,
- syncProgress: string,
- }
-
- export interface Wallet {
- name: string,
- paymentAddr: string,
- stakingAddr: string,
- balance: () => {
- utxo: Utxo[],
- value: any
- },
- reward: () => StakeAddressInfo | string,
- }
-
- export interface Pool {
- name: string,
- id: string,
- }
-
- export interface StakeAddressInfo {
- address: string,
- rewardAccountBalance: number,
- delegation: string,
- }
-
- export interface AddressInfo {
- address: string,
- era: string,
- encoding: string,
- type: string,
- base16: string,
- }
-
- export interface TxIn {
- txHash: string,
- txId: string,
- script?: any,
- datum?: any,
- redeemer?: any,
- executionUnits: any,
- }
-
- export interface TxOut {
- address: string,
- value: any,
- datumHash: string,
- }
-
- export interface TxInCollateral {
- txHash: string,
- txId: string,
- }
-
- export interface Withdrawal {
- stakingAddress: string,
- reward: number,
- script: any,
- datum: any,
- redeemer: any,
- executionUnits: any,
- }
-
- export interface Certificate {
- cert: string,
- script: any,
- datum: any,
- redeemer: any,
- executionUnits: any,
- }
-
- export interface Mint {
- action: string,
- quantity: string,
- asset: string,
- script: any,
- datum: any,
- redeemer: any,
- executionUnits: any,
- }
-
- export interface Utxo {
- txHash: string,
- txId: number,
- value: any
- }
-
- export interface Account {
- vkey: string,
- skey: string,
- counter?: string,
- }
-}
diff --git a/index.js b/index.js
deleted file mode 100644
index e2f0968..0000000
--- a/index.js
+++ /dev/null
@@ -1,1369 +0,0 @@
-const execSync =
- typeof window !== "undefined" || require("child_process").execSync;
-const fs = typeof window !== "undefined" || require("fs");
-const {
- ownerToString,
- relayToString,
- certToString,
- txInToString,
- txOutToString,
- signingKeysToString,
- witnessFilesToString,
- fileException,
- setKeys,
- fileExists,
- mintToString,
- jsonToPath,
- auxScriptToString,
- withdrawalToString,
- multiAssetToString,
-} = require("./helper");
-const fetch =
- typeof window !== "undefined" ? window.fetch : require("sync-fetch");
-
-/**
- * @typedef lovelace
- * @property {number}
- */
-
-/**
- * @typedef asset
- * @property {string}
- */
-
-/**
- * @typedef quantity
- * @property {string}
- */
-
-/**
- * @typedef path
- * @property {string}
- */
-
-/**
- * @typedef paymentAddr
- * @property {string}
- */
-
-/**
- * @typedef stakeAddr
- * @property {string}
- */
-
-/**
- * @typedef {Object} TxIn
- * @property {string} txHash
- * @property {string} txId
- * @property {object=} script
- * @property {object=} datum
- * @property {object=} redeemer
- * @property {[number, number]} executionUnits
- */
-/**
- * @typedef {Object} TxOut
- * @property {string} address
- * @property {object} value
- * @property {string} datumHash
- */
-/**
- * @typedef {Object} TxInCollateral
- * @property {string} txHash
- * @property {string} txId
- */
-/**
- * @typedef {Object} Mint
- * @property {string} action
- * @property {string} quantity
- * @property {string} asset
- * @property {object} script
- * @property {object=} datum
- * @property {object=} redeemer
- * @property {[number, number]} executionUnits
- */
-/**
- * @typedef {Object} Certificate
- * @property {path} cert
- * @property {object=} script
- * @property {object=} datum
- * @property {object=} redeemer
- * @property {[number, number]} executionUnits
- */
-/**
- * @typedef {Object} Withdrawal
- * @property {string} stakingAddress
- * @property {lovelace} reward
- * @property {object=} script
- * @property {object=} datum
- * @property {object=} redeemer
- * @property {[number, number]} executionUnits
- */
-/**
- * @typedef {Object.} Value
- */
-
-class CardanocliJs {
- /**
- *
- * @param {Object} options
- * @param {path=} options.shelleyGenesisPath
- * @param {path=} options.socketPath - Default: Env Variable
- * @param {path=} options.cliPath - Default: Env Variable
- * @param {path=} options.dir - Default: Working Dir
- * @param {string=} options.era
- * @param {string=} options.network - Default: mainnet
- * @param {string=} options.httpProvider - Optional - Useful when using cli at different location than node or in browser
- */
-
- constructor(options) {
- this.network = "mainnet";
- this.era = "";
- this.dir = ".";
- this.cliPath = "cardano-cli";
-
- if (options) {
- options.shelleyGenesisPath &&
- (this.shelleyGenesis = JSON.parse(
- execSync(`cat ${options.shelleyGenesisPath}`).toString()
- ));
-
- options.socketPath &&
- (process.env["CARDANO_NODE_SOCKET_PATH"] = options.socketPath);
- options.era && (this.era = "--" + options.era + "-era");
- options.network && (this.network = options.network);
- options.dir && (this.dir = options.dir);
- options.cliPath && (this.cliPath = options.cliPath);
- options.httpProvider && (this.httpProvider = options.httpProvider);
- if (!this.httpProvider && typeof window !== "undefined")
- throw new Error("httpProvider required");
- if (this.httpProvider) {
- if (typeof window === "undefined") {
- this.shelleyGenesis = fetch(
- `${this.httpProvider}/shelleyGenesis`
- ).json();
- } else {
- (() => async () => {
- this.shelleyGenesis = await fetch(
- `${this.httpProvider}/shelleyGenesis`
- ).then((res) => res.json());
- })();
- }
- }
- }
-
- typeof window !== "undefined" || execSync(`mkdir -p ${this.dir}/tmp`);
- }
-
- /**
- * @returns {object}
- */
- queryProtocolParameters() {
- if (this.httpProvider) {
- let response = fetch(`${this.httpProvider}/queryProtocolParameters`);
- if (typeof window === "undefined") {
- response = response.json();
- fs.writeFileSync(
- `${this.dir}/tmp/protocolParams.json`,
- JSON.stringify(response)
- );
- this.protocolParametersPath = `${this.dir}/tmp/protocolParams.json`;
- return response;
- }
- return response.then((res) => res.json());
- }
- execSync(`${this.cliPath} query protocol-parameters \
- --${this.network} \
- --cardano-mode \
- --out-file ${this.dir}/tmp/protocolParams.json
- `);
- this.protocolParametersPath = `${this.dir}/tmp/protocolParams.json`;
- return JSON.parse(execSync(`cat ${this.dir}/tmp/protocolParams.json`));
- }
-
- /**
- * @returns {object}
- */
- queryTip() {
- if (this.httpProvider) {
- let response = fetch(`${this.httpProvider}/queryTip`);
- return typeof window !== "undefined"
- ? response.then((res) => res.json())
- : response.json();
- }
- return JSON.parse(
- execSync(`${this.cliPath} query tip \
- --${this.network} \
- --cardano-mode
- `).toString()
- );
- }
-
- /**
- * @param {stakeAddr} address
- * @returns {object}
- */
- queryStakeAddressInfo(address) {
- if (this.httpProvider) {
- let response = fetch(
- `${this.httpProvider}/queryStakeAddressInfo/${address}`
- );
- return typeof window !== "undefined"
- ? response.then((res) => res.json())
- : response.json();
- }
- return JSON.parse(
- execSync(`${this.cliPath} query stake-address-info \
- --${this.network} \
- --address ${address}
- `).toString()
- );
- }
-
- /**
- * @param {paymentAddr} address
- * @returns {object}
- */
- queryUtxo(address) {
- if (this.httpProvider) {
- let response = fetch(`${this.httpProvider}/queryUtxo/${address}`);
- return typeof window !== "undefined"
- ? response.then((res) => res.json())
- : response.json();
- }
- const utxosRaw = execSync(`${this.cliPath} query utxo \
- --${this.network} \
- --address ${address} \
- --cardano-mode
- `).toString();
-
- const utxos = utxosRaw.split("\n");
- utxos.splice(0, 1);
- utxos.splice(0, 1);
- utxos.splice(utxos.length - 1, 1);
- const result = utxos.map((raw, index) => {
- const utxo = raw.replace(/\s+/g, " ").split(" ");
- const txHash = utxo[0];
- const txId = parseInt(utxo[1]);
- const valueList = utxo.slice(2, utxo.length).join(" ").split("+");
- const value = {};
- let datumHash;
- valueList.forEach((v) => {
- if (v.includes("TxOutDatumHash") || v.includes("TxOutDatumNone") ) {
- if (!v.includes("None"))
- datumHash = JSON.parse(v.trim().split(" ")[2]);
- return;
- }
- let [quantity, asset] = v.trim().split(" ");
- quantity = parseInt(quantity);
- value[asset] = quantity;
- });
- const result = { txHash, txId, value };
- if (datumHash) result.datumHash = datumHash;
-
- return result;
- });
-
- return result;
- }
-
- /**
- *
- * @param {string} account - Name of account
- */
- addressKeyGen(account) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/${account}/addressKeyGen`);
- return response.then((res) => res.json());
- }
- let vkey = `${this.dir}/priv/wallet/${account}/${account}.payment.vkey`;
- let skey = `${this.dir}/priv/wallet/${account}/${account}.payment.skey`;
- fileExists([vkey, skey]);
- execSync(`mkdir -p ${this.dir}/priv/wallet/${account}`);
- execSync(`${this.cliPath} address key-gen \
- --verification-key-file ${vkey} \
- --signing-key-file ${skey}
- `);
- return {
- vkey,
- skey,
- };
- }
-
- /**
- *
- * @param {string} account - Name of account
- */
- stakeAddressKeyGen(account) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(
- `${this.httpProvider}/${account}/stakeAddressKeyGen`
- );
- return response.then((res) => res.json());
- }
- let vkey = `${this.dir}/priv/wallet/${account}/${account}.stake.vkey`;
- let skey = `${this.dir}/priv/wallet/${account}/${account}.stake.skey`;
- fileExists([vkey, skey]);
- execSync(`mkdir -p ${this.dir}/priv/wallet/${account}`);
- execSync(`${this.cliPath} stake-address key-gen \
- --verification-key-file ${vkey} \
- --signing-key-file ${skey}
- `);
- return {
- vkey,
- skey,
- };
- }
-
- /**
- *
- * @param {string} account - Name of account
- * @returns {path}
- */
- stakeAddressBuild(account) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/${account}/stakeAddressBuild`);
- return response.then((res) => res.text());
- }
- execSync(`${this.cliPath} stake-address build \
- --staking-verification-key-file ${this.dir}/priv/wallet/${account}/${account}.stake.vkey \
- --out-file ${this.dir}/priv/wallet/${account}/${account}.stake.addr \
- --${this.network}
- `);
- return `${this.dir}/priv/wallet/${account}/${account}.stake.addr`;
- }
-
- /**
- *
- * @param {string} account - Name of account
- * @param {Object} options
- * @param {path} [options.paymentVkey]
- * @param {path} [options.stakeVkey]
- * @param {object} [options.paymentScript]
- * @param {object} [options.stakeScript]
- */
- addressBuild(account, options) {
- const paymentVkey = options.paymentVkey
- ? `--payment-verification-key-file ${options.paymentVkey}`
- : "";
- const stakeVkey = options.stakeVkey
- ? `--staking-verification-key-file ${options.stakeVkey}`
- : "";
- const paymentScript = options.paymentScript
- ? `--payment-script-file ${jsonToPath(this.dir, options.paymentScript)}`
- : "";
- const stakeScript = options.stakeScript
- ? `--stake-script-file ${jsonToPath(this.dir, options.stakeScript)}`
- : "";
-
- execSync(`${this.cliPath} address build \
- ${paymentVkey} \
- ${stakeVkey} \
- ${paymentScript} \
- ${stakeScript} \
- --out-file ${this.dir}/priv/wallet/${account}/${account}.payment.addr \
- --${this.network}
- `);
- return `${this.dir}/priv/wallet/${account}/${account}.payment.addr`;
- }
-
- /**
- *
- * @param {string} account - Name of account
- */
- addressKeyHash(account) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/${account}/addressKeyHash`);
- return response.then((res) => res.text());
- }
- return execSync(`${this.cliPath} address key-hash \
- --payment-verification-key-file ${this.dir}/priv/wallet/${account}/${account}.payment.vkey \
- `)
- .toString()
- .trim();
- }
-
- /**
- *
- * @param {paymentAddr} address
- * @returns {object}
- */
- addressInfo(address) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/addressInfo/${address}`);
- return response.then((res) => res.json());
- }
- return JSON.parse(
- execSync(`${this.cliPath} address info \
- --address ${address} \
- `)
- .toString()
- .replace(/\s+/g, " ")
- );
- }
-
- /**
- *
- * @param {object} script
- * @returns {paymentAddr}
- */
- addressBuildScript(script) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/addressBuildScript`, {
- headers: {
- "Content-Type": "application/json",
- },
- method: "POST",
- body: JSON.stringify(script),
- });
- return response.then((res) => res.text());
- }
- let UID = Math.random().toString(36).substr(2, 9);
- fs.writeFileSync(
- `${this.dir}/tmp/script_${UID}.json`,
- JSON.stringify(script)
- );
- let scriptAddr = execSync(
- `${this.cliPath} address build-script --script-file ${this.dir}/tmp/script_${UID}.json --${this.network}`
- )
- .toString()
- .replace(/\s+/g, " ");
- return scriptAddr;
- }
-
- /**
- *
- * @param {string} account - Name of the account
- */
- wallet(account) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}${account}/wallet`);
- return response.then((res) => res.json());
- }
- let paymentAddr = "No payment keys generated";
- let stakingAddr = "No staking keys generated";
-
- fileException(() => {
- paymentAddr = fs
- .readFileSync(
- `${this.dir}/priv/wallet/${account}/${account}.payment.addr`
- )
- .toString();
- });
- fileException(() => {
- stakingAddr = fs
- .readFileSync(
- `${this.dir}/priv/wallet/${account}/${account}.stake.addr`
- )
- .toString();
- });
-
- let files = fs.readdirSync(`${this.dir}/priv/wallet/${account}`);
- let keysPath = {};
- files.forEach((file) => {
- let name = file.split(".")[1] + "." + file.split(".")[2];
- setKeys(keysPath, name, `${this.dir}/priv/wallet/${account}/${file}`);
- });
-
- const balance = () => {
- const utxos = this.queryUtxo(paymentAddr);
- const value = {};
- utxos.forEach((utxo) => {
- Object.keys(utxo.value).forEach((asset) => {
- if (!value[asset]) value[asset] = 0;
- value[asset] += utxo.value[asset];
- });
- });
-
- return { utxo: utxos, value };
- };
- let reward = () => {
- let r;
- try {
- r = this.queryStakeAddressInfo(stakingAddr);
- r = r.find(
- (delegation) => delegation.address == stakingAddr
- ).rewardAccountBalance;
- } catch {
- r = "Staking key is not registered";
- }
- return r;
- };
-
- return {
- name: account,
- paymentAddr,
- stakingAddr,
- balance,
- reward,
- ...keysPath,
- };
- }
-
- /**
- *
- * @param {string} poolName - Name of the pool
- */
- pool(poolName) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}${poolName}/pool`);
- return response.then((res) => res.json());
- }
- let id;
- fileException(() => {
- fs.readFileSync(
- `${this.dir}/priv/pool/${poolName}/${poolName}.node.vkey`
- );
- id = this.stakePoolId(poolName);
- });
- let files = fs.readdirSync(`${this.dir}/priv/pool/${poolName}`);
- let keysPath = {};
- files.forEach((file) => {
- let name = file.split(".")[1] + "." + file.split(".")[2];
- setKeys(keysPath, name, `${this.dir}/priv/pool/${poolName}/${file}`);
- });
- return {
- name: poolName,
- id,
- ...keysPath,
- };
- }
-
- /**
- *
- * @param {string} account - Name of the account
- * @returns {path}
- */
- stakeAddressRegistrationCertificate(account) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(
- `${this.httpProvider}${account}/stakeAddressRegistrationCertificate`
- );
- return response.then((res) => res.text());
- }
- execSync(`${this.cliPath} stake-address registration-certificate \
- --staking-verification-key-file ${this.dir}/priv/wallet/${account}/${account}.stake.vkey \
- --out-file ${this.dir}/priv/wallet/${account}/${account}.stake.cert
- `);
- return `${this.dir}/priv/wallet/${account}/${account}.stake.cert`;
- }
-
- /**
- *
- * @param {string} account - Name of the account
- * @returns {path}
- */
- stakeAddressDeregistrationCertificate(account) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(
- `${this.httpProvider}${account}/stakeAddressDeregistrationCertificate`
- );
- return response.then((res) => res.text());
- }
- execSync(`${this.cliPath} stake-address deregistration-certificate \
- --staking-verification-key-file ${this.dir}/priv/wallet/${account}/${account}.stake.vkey \
- --out-file ${this.dir}/priv/wallet/${account}/${account}.stake.cert
- `);
- return `${this.dir}/priv/wallet/${account}/${account}.stake.cert`;
- }
-
- /**
- *
- * @param {string} account - Name of the account
- * @param {string} poolId - Stake pool verification key (Bech32 or hex-encoded)
- * @returns {path}
- */
- stakeAddressDelegationCertificate(account, poolId) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(
- `${this.httpProvider}${account}/stakeAddressDelegationCertificate?poolId=${poolId}`
- );
- return response.then((res) => res.text());
- }
- execSync(`${this.cliPath} stake-address delegation-certificate \
- --staking-verification-key-file ${this.dir}/priv/wallet/${account}/${account}.stake.vkey \
- --stake-pool-id ${poolId} \
- --out-file ${this.dir}/priv/wallet/${account}/${account}.deleg.cert
- `);
- return `${this.dir}/priv/wallet/${account}/${account}.deleg.cert`;
- }
-
- /**
- *
- * @param {string} account - Name of the account
- * @returns {string}
- */
- stakeAddressKeyHash(account) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(
- `${this.httpProvider}/${account}/stakeAddressKeyHash`
- );
- return response.then((res) => res.text());
- }
- return execSync(`${this.cliPath} stake-address key-hash \
- --staking-verification-key-file ${this.dir}/priv/wallet/${account}/${account}.stake.vkey \
- `)
- .toString()
- .trim();
- }
-
- /**
- *
- * @param {string} poolName - Name of the pool
- */
- nodeKeyGenKES(poolName) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/${poolName}/nodeKeyGenKES`);
- return response.then((res) => res.json());
- }
- let vkey = `${this.dir}/priv/pool/${poolName}/${poolName}.kes.vkey`;
- let skey = `${this.dir}/priv/pool/${poolName}/${poolName}.kes.skey`;
- fileExists([vkey, skey]);
- execSync(`mkdir -p ${this.dir}/priv/pool/${poolName}`);
- execSync(`${this.cliPath} node key-gen-KES \
- --verification-key-file ${vkey} \
- --signing-key-file ${skey}
- `);
- return {
- vkey,
- skey,
- };
- }
-
- /**
- *
- * @param {string} poolName - Name of the pool
- */
- nodeKeyGen(poolName) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/${poolName}/nodeKeyGen`);
- return response.then((res) => res.json());
- }
- let vkey = `${this.dir}/priv/pool/${poolName}/${poolName}.node.vkey`;
- let skey = `${this.dir}/priv/pool/${poolName}/${poolName}.node.skey`;
- let counter = `${this.dir}/priv/pool/${poolName}/${poolName}.node.counter`;
- fileExists([vkey, skey, counter]);
- execSync(`mkdir -p ${this.dir}/priv/pool/${poolName}`);
- execSync(`${this.cliPath} node key-gen \
- --cold-verification-key-file ${vkey} \
- --cold-signing-key-file ${skey} \
- --operational-certificate-issue-counter ${counter}
- `);
- return {
- vkey,
- skey,
- counter,
- };
- }
-
- /**
- *
- * @param {string} poolName - Name of the pool
- * @param {number=} kesPeriod - Optional (Offline mode)
- * @returns {path}
- */
- nodeIssueOpCert(poolName, kesPeriod) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/${poolName}/nodeIssueOpCert`);
- return response.then((res) => res.text());
- }
- execSync(`${this.cliPath} node issue-op-cert \
- --kes-verification-key-file ${
- this.dir
- }/priv/pool/${poolName}/${poolName}.kes.vkey \
- --cold-signing-key-file ${
- this.dir
- }/priv/pool/${poolName}/${poolName}.node.skey \
- --operational-certificate-issue-counter ${
- this.dir
- }/priv/pool/${poolName}/${poolName}.node.counter \
- --kes-period ${
- kesPeriod ? kesPeriod : this.KESPeriod()
- } \
- --out-file ${
- this.dir
- }/priv/pool/${poolName}/${poolName}.node.cert
- `);
- return `${this.dir}/priv/pool/${poolName}/${poolName}.node.cert`;
- }
-
- /**
- *
- * @param {string} poolName - Name of the pool
- */
- nodeKeyGenVRF(poolName) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/${poolName}/nodeKeyGenVRF`);
- return response.then((res) => res.json());
- }
- let vkey = `${this.dir}/priv/pool/${poolName}/${poolName}.vrf.vkey`;
- let skey = `${this.dir}/priv/pool/${poolName}/${poolName}.vrf.skey`;
- fileExists([vkey, skey]);
- execSync(`mkdir -p ${this.dir}/priv/pool/${poolName}`);
- execSync(`${this.cliPath} node key-gen-VRF \
- --verification-key-file ${vkey} \
- --signing-key-file ${skey}
- `);
- return {
- vkey,
- skey,
- };
- }
-
- nodeNewCounter(poolName, counter) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(
- `${this.httpProvider}/${poolName}/nodeNewCounter?counter=${counter}`
- );
- return response.then((res) => res.text());
- }
-
- execSync(`mkdir -p ${this.dir}/priv/pool/${poolName}`);
- execSync(`${this.cliPath} node new-counter \
- --cold-verification-key-file ${this.dir}/priv/pool/${poolName}/${poolName}.node.vkey \
- --counter-value ${counter} \
- --operational-certificate-issue-counter-file ${this.dir}/priv/pool/${poolName}/${poolName}.node.counter
- `);
- return `${this.dir}/priv/pool/${poolName}/${poolName}.node.counter`;
- }
-
- /**
- *
- * @param {string} poolName - Name of the pool
- * @returns {string}
- */
- stakePoolId(poolName) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/${poolName}/stakePoolId`);
- return response.then((res) => res.text());
- }
- return execSync(
- `${this.cliPath} stake-pool id --cold-verification-key-file ${this.dir}/priv/pool/${poolName}/${poolName}.node.vkey`
- )
- .toString()
- .replace(/\s+/g, " ");
- }
-
- /**
- *
- * @param {string} metadata - Raw File
- * @returns {string}
- */
- stakePoolMetadataHash(metadata) {
- if (this.httpProvider && typeof window !== "undefined") {
- let response = fetch(`${this.httpProvider}/stakePoolMetadataHash`, {
- method: "POST",
- body: metadata,
- });
- return response.then((res) => res.text());
- }
- fs.writeFileSync(`${this.dir}/tmp/poolmeta.json`, metadata);
- let metaHash = execSync(
- `${this.cliPath} stake-pool metadata-hash --pool-metadata-file ${this.dir}/tmp/poolmeta.json`
- )
- .toString()
- .replace(/\s+/g, " ");
- execSync(`rm ${this.dir}/tmp/poolmeta.json`);
- return metaHash;
- }
-
- /**
- * @param {string} poolName - Name of the pool
- * @param {Object} options
- * @param {lovelace} options.pledge
- * @param {number} options.margin
- * @param {lovelace} options.cost
- * @param {string} options.url
- * @param {string} options.metaHash
- * @param {path} options.rewardAccount
- * @param {Array} options.owners
- * @param {Array