diff --git a/docs/dapi-client-js/usage/core/broadcasttransaction.md b/docs/dapi-client-js/usage/core/broadcasttransaction.md index 49cabc979..2dd20c4c0 100644 --- a/docs/dapi-client-js/usage/core/broadcasttransaction.md +++ b/docs/dapi-client-js/usage/core/broadcasttransaction.md @@ -14,4 +14,4 @@ Parameters: Returns : transactionId (string). -N.B : The TransactionID provided is subject to [transaction malleability](https://dashcore.readme.io/docs/core-guide-transactions-transaction-malleability), and is not a source of truth (the transaction might be included in a block with a different txid). \ No newline at end of file +N.B : The TransactionID provided is subject to [transaction malleability](https://docs.dash.org/projects/core/en/stable/docs/guide/transactions-transaction-malleability.html), and is not a source of truth (the transaction might be included in a block with a different txid). \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 4245443be..8e6aef021 100644 --- a/docs/index.md +++ b/docs/index.md @@ -90,6 +90,20 @@ resources/source-code Previous Version of Docs ``` +```{toctree} +:maxdepth: 2 +:titlesonly: +:caption: Dash SDK +:hidden: + +sdk-js/overview +sdk-js/examples/examples +sdk-js/getting-started/getting-started +sdk-js/platform/platform +sdk-js/usage/usage +sdk-js/wallet/wallet +``` + ```{toctree} :maxdepth: 2 :titlesonly: diff --git a/docs/intro/what-is-dash.md b/docs/intro/what-is-dash.md index 5f9c76a89..7cc511fa5 100644 --- a/docs/intro/what-is-dash.md +++ b/docs/intro/what-is-dash.md @@ -52,7 +52,7 @@ However, the Dash network has a second layer of network participants that provid ### Long-Living Masternode Quorums -Dash's [long-living masternode quorums](https://dashcore.readme.io/docs/core-guide-dash-features-masternode-quorums) (LLMQs) are used to facilitate the operation of masternode-provided features in a decentralized, deterministic way. These LLMQs are deterministic subsets of the overall masternode list that are formed via a [distributed key generation](../reference/glossary.md#distributed-key-generation-dkg) protocol and remain active for long periods of time (e.g. hours to days). The main task of LLMQs is to perform threshold signing of consensus-related messages for features like InstantSend and ChainLocks. +Dash's [long-living masternode quorums](https://docs.dash.org/projects/core/en/stable/docs/guide/dash-features-masternode-quorums.html) (LLMQs) are used to facilitate the operation of masternode-provided features in a decentralized, deterministic way. These LLMQs are deterministic subsets of the overall masternode list that are formed via a [distributed key generation](../reference/glossary.md#distributed-key-generation-dkg) protocol and remain active for long periods of time (e.g. hours to days). The main task of LLMQs is to perform threshold signing of consensus-related messages for features like InstantSend and ChainLocks. ### InstantSend diff --git a/docs/reference/dapi-endpoints-core-grpc-endpoints.md b/docs/reference/dapi-endpoints-core-grpc-endpoints.md index 6c9ce89e0..6e9628530 100644 --- a/docs/reference/dapi-endpoints-core-grpc-endpoints.md +++ b/docs/reference/dapi-endpoints-core-grpc-endpoints.md @@ -395,7 +395,7 @@ GetTransactionResponse { ### subscribeToBlockHeadersWithChainLocks -This endpoint helps support simplified payment verification ([SPV](https://dashcore.readme.io/docs/core-guide-operating-modes-simplified-payment-verification-spv)) via DAPI by providing access to block headers which can then be used to verify transactions and simplified masternode lists. +This endpoint helps support simplified payment verification ([SPV](https://docs.dash.org/projects/core/en/stable/docs/guide/operating-modes-simplified-payment-verification-spv.html)) via DAPI by providing access to block headers which can then be used to verify transactions and simplified masternode lists. **Returns**: streams the requested block header information **Parameters**: diff --git a/docs/reference/dapi-endpoints.md b/docs/reference/dapi-endpoints.md index 9548e6175..66f20fbc4 100644 --- a/docs/reference/dapi-endpoints.md +++ b/docs/reference/dapi-endpoints.md @@ -21,7 +21,7 @@ | 1 | [`getStatus`](../reference/dapi-endpoints-core-grpc-endpoints.md#getstatus) | Returns blockchain status information | | 1 | [`getTransaction`](../reference/dapi-endpoints-core-grpc-endpoints.md#gettransaction) | Returns details for the requested transaction | | 1 | [`subscribeTo` `BlockHeadersWithChainLocks`](../reference/dapi-endpoints-core-grpc-endpoints.md#subscribetoblockheaderswithchainlocks) | Returns the requested block headers along with the associated ChainLocks.
_Added in Dash Platform v0.22_ | -| 1 | [`subscribeTo` `TransactionsWithProofs`](../reference/dapi-endpoints-core-grpc-endpoints.md#subscribetotransactionswithproofs) | Returns transactions matching the provided bloom filter along with the associated [`islock` message](https://dashcore.readme.io/docs/core-ref-p2p-network-instantsend-messages#islock) and [merkle block](https://dashcore.readme.io/docs/core-ref-p2p-network-data-messages#merkleblock) | +| 1 | [`subscribeTo` `TransactionsWithProofs`](../reference/dapi-endpoints-core-grpc-endpoints.md#subscribetotransactionswithproofs) | Returns transactions matching the provided bloom filter along with the associated [`islock` message](https://docs.dash.org/projects/core/en/stable/docs/reference/p2p-network-instantsend-messages.html#islock) and [merkle block](https://docs.dash.org/projects/core/en/stable/docs/reference/p2p-network-data-messages.html#merkleblock) | ### Platform gRPC Service diff --git a/docs/reference/glossary.md b/docs/reference/glossary.md index 3e2071724..27baa8fae 100644 --- a/docs/reference/glossary.md +++ b/docs/reference/glossary.md @@ -66,7 +66,7 @@ An organization where decision making is governed according to a set of rules th ## Devnet -A development environment in which developers can obtain and spend Dash that has no real-world value on a network that is very similar to the Dash [mainnet](#mainnet). Multiple independent devnets can coexist without interference. Devnets can be either public or private networks. See the Testing Applications page for a more detailed description of network types. +A development environment in which developers can obtain and spend Dash that has no real-world value on a network that is very similar to the Dash [mainnet](#mainnet). Multiple independent devnets can coexist without interference. Devnets can be either public or private networks. See the Testing Applications page for a more detailed description of network types. ## Direct Settlement Payment Channel (DSPC) @@ -123,7 +123,7 @@ BLS signature resulting from some agreement within a masternode quorum ## Regtest -A local regression testing environment in which developers can almost instantly generate blocks on demand for testing events, and can create private Dash with no real-world value. See the Testing Applications page for a more detailed description of network types. +A local regression testing environment in which developers can almost instantly generate blocks on demand for testing events, and can create private Dash with no real-world value. See the Testing Applications page for a more detailed description of network types. ## Simple Payment Verification A method for verifying if transactions are part of a block without downloading the whole block. This is useful for lightweight clients which don't run continuously and which don't have the storage space or bandwidth for a full copy of the blockchain. @@ -142,7 +142,7 @@ Dash fork of [Tendermint](https://tendermint.com/core) modified for use in Dash ## Testnet -A global testing environment in which developers can obtain and spend Dash that has no real-world value on a network that is very similar to the Dash [mainnet](#mainnet). See the Testing Applications page for a more detailed description of network types. +A global testing environment in which developers can obtain and spend Dash that has no real-world value on a network that is very similar to the Dash [mainnet](#mainnet). See the Testing Applications page for a more detailed description of network types. See: [Intro to Testnet](../intro/to-testnet.md) for more information diff --git a/docs/sdk-js/examples/examples.md b/docs/sdk-js/examples/examples.md new file mode 100644 index 000000000..e3aac57c3 --- /dev/null +++ b/docs/sdk-js/examples/examples.md @@ -0,0 +1,13 @@ +# Examples + +```{toctree} +:maxdepth: 2 +:titlesonly: + +fetch-an-identity-from-its-name +generate-a-new-mnemonic +paying-to-another-address +receive-money-and-check-balance +sign-and-verify-messages +use-different-account +``` diff --git a/docs/sdk-js/examples/fetch-an-identity-from-its-name.md b/docs/sdk-js/examples/fetch-an-identity-from-its-name.md new file mode 100644 index 000000000..c32c8ff34 --- /dev/null +++ b/docs/sdk-js/examples/fetch-an-identity-from-its-name.md @@ -0,0 +1,17 @@ +# Fetching an identity from its name + +Assuming you have created an identity and attached a name to it (see how to [register an identity](../../tutorials/identities-and-names/register-an-identity.md) and how to [attach it to a name](../../tutorials/identities-and-names/register-a-name-for-an-identity.md)), you will then be able to directly recover an identity from its names. See below: + +```js +const client = new Dash.Client({ + wallet: { + mnemonic: '', // Your app mnemonic, which holds the identity + }, +}); + +// This is the name previously registered in DPNS. +const identityName = 'alice'; + +const nameDocument = await client.platform.names.resolve(`${identityName}.dash`); +const identity = await client.platform.identities.get(nameDocument.ownerId); +``` \ No newline at end of file diff --git a/docs/sdk-js/examples/generate-a-new-mnemonic.md b/docs/sdk-js/examples/generate-a-new-mnemonic.md new file mode 100644 index 000000000..9fb6bfcd6 --- /dev/null +++ b/docs/sdk-js/examples/generate-a-new-mnemonic.md @@ -0,0 +1,48 @@ +# Generate a new mnemonic + +In order to be able to keep your private keys private, we encourage to create your own mnemonic instead of using those from the examples (that might be empty). +Below, you will be proposed two options allowing you to create a new mnemonic, depending on the level of customisation you need. + +## Dash.Client + +By passing `null` to the mnemonic value of the wallet options, you can get Wallet-lib to generate a new mnemonic for you. + +```js +const Dash = require("dash"); +const client = new Dash.Client({ + network: "testnet", + wallet: { + mnemonic: null, + }, +}); +const mnemonic = client.wallet.exportWallet(); +console.log({mnemonic}); +``` + +## Dash.Mnemonic + +```js +const Dash = require("dash"); +const {Mnemonic} = Dash.Core; + +const mnemnonic = new Mnemonic().toString() +``` + +### Language selection + +```js +const {Mnemonic} = Dash.Core; +const {CHINESE, ENGLISH, FRENCH, ITALIAN, JAPANESE, SPANISH} = Mnemonic.Words; +console.log(new Mnemonic(Mnemonic.Words.FRENCH).toString()) +``` + +### Entropy size + +By default, the value for mnemonic is `128` (12 words), but you can generate a 24 words (or other) : + +```js +const {Mnemonic} = Dash.Core; +console.log(new Mnemonic(256).toString()) +``` + +You can even replace the word list by your own, providing a list of 2048 unique words. \ No newline at end of file diff --git a/docs/sdk-js/examples/paying-to-another-address.md b/docs/sdk-js/examples/paying-to-another-address.md new file mode 100644 index 000000000..1eba64a9b --- /dev/null +++ b/docs/sdk-js/examples/paying-to-another-address.md @@ -0,0 +1,28 @@ +# Paying to another address + +In order to pay, you need to have an [existing balance](../examples/receive-money-and-check-balance.md). +The below code will allow you to pay to a single address a specific amount of satoshis. + +```js +const Dash = require('dash'); + +const mnemonic = ''; // your mnemonic here. +const client = new Dash.Client({ + wallet: { + mnemonic, + }, +}); + +async function payToRecipient(account) { + const transaction = account.createTransaction({ + recipient: 'yNPbcFfabtNmmxKdGwhHomdYfVs6gikbPf', + satoshis: 10000, + }); + const transactionId = await account.broadcastTransaction(transaction); +} + +client.wallet.getAccount().then(payToRecipient); + +``` + +See more on create [transaction options here](https://dashpay.github.io/platform/Wallet-library/account/createTransaction/). \ No newline at end of file diff --git a/docs/sdk-js/examples/receive-money-and-check-balance.md b/docs/sdk-js/examples/receive-money-and-check-balance.md new file mode 100644 index 000000000..b0bd85aa2 --- /dev/null +++ b/docs/sdk-js/examples/receive-money-and-check-balance.md @@ -0,0 +1,92 @@ +# Receive money and display balance + +## Initialize client + +Initialize the SDK Client with your [generated mnemonic](../examples/generate-a-new-mnemonic.md) passed as an option. + +```js +const Dash = require("dash"); +const mnemonic = ''// your mnemonic here. +const client = new Dash.Client({ + wallet: { + mnemonic, + } +}); + +async function showBalance() { + const account = await client.wallet.getAccount(); + const totalBalance = account.getTotalBalance(); + console.log(`Account's total balance: ${totalBalance} duffs`); +} +``` + +Having your `client` instance set up, you will be able to access the `account` and `wallet` instance generated from your mnemonic. + +By default `getAccount()` returns the first BIP44 account. +You can read more on [how to use a different account](../examples/use-different-account.md). + +## Generate a receiving address + +Dash wallet supports two different types of addresses: + +- `external` addresses used for receiving funds from other addresses +- `internal` addresses used for change outputs of outgoing transactions +- For your privacy, you might want to generate a new address for each payment: + +```js +async function generateUnusedAddress() { + const account = await client.wallet.getAccount(); + const { address } = account.getUnusedAddress(); + console.log(`Unused external address: ${address}`); +} +``` + +This above code will generate a new unique (never used) address. + +## Displaying your balance + +_Dash Wallet returns the balance in duffs (1 Dash is equal to 100.000.000 duffs)_ + +`getTotalBalance()` function takes into account `confirmed` and `unconfirmed` transactions (not included in a block). +It is recommended to check the confirmed balance before making a payment: + +```js +async function showBalance() { + const account = await client.wallet.getAccount(); + const totalBalance = account.getTotalBalance(); + const confirmedBalance = account.getConfirmedBalance(); + const unconfirmedBalance = account.getUnconfirmedBalance(); + console.log(`Account balance: + Confirmed: ${confirmedBalance} + Unconfirmed: ${unconfirmedBalance} + Total: ${totalBalance} + `); +} +``` + +## Listen for event on received transaction + +When a new unconfirmed transaction is received, you can receive an event, and then validate the address or perform an action if needed. + +```js +// FETCHED/UNCONFIRMED_TRANSACTION event is currently disabled + +async function listenUnconfirmedTransaction() { + const account = await client.wallet.getAccount(); + account.on('FETCHED/UNCONFIRMED_TRANSACTION', (data) => { + console.dir(data); + }); +} +``` + +## Get address at specific index + +In case you want to retrieve an address at specific index: + +```js +async function getAddressAtIndex() { + const account = await client.wallet.getAccount(); + const { address: externalAddress } = account.getAddress(2); + const { address: internalAddress } = account.getAddress(2, 'internal'); +} +``` \ No newline at end of file diff --git a/docs/sdk-js/examples/sign-and-verify-messages.md b/docs/sdk-js/examples/sign-and-verify-messages.md new file mode 100644 index 000000000..5faa38d48 --- /dev/null +++ b/docs/sdk-js/examples/sign-and-verify-messages.md @@ -0,0 +1,24 @@ +# Sign and verify messages + +Dash SDK exports the Message constructor inside the Core namespace `new Dash.Core.Message` + +```js +const Dash = require('dash'); + +const mnemonic = ''; + +const client = new Dash.Client({ + wallet: { + mnemonic, + }, +}); + +async function signAndVerify() { + const account = await client.wallet.getAccount(); + + const pk = new Dash.Core.PrivateKey(); + const message = new Dash.Core.Message('hello, world'); + const signed = account.sign(message, pk); + const verified = message.verify(pk.toAddress().toString(), signed.toString()); +} +``` \ No newline at end of file diff --git a/docs/sdk-js/examples/use-different-account.md b/docs/sdk-js/examples/use-different-account.md new file mode 100644 index 000000000..e316a0e98 --- /dev/null +++ b/docs/sdk-js/examples/use-different-account.md @@ -0,0 +1,11 @@ +# Using a different account + +Clients initialized with a mnemonic support multiple accounts as defined in [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki). + +By default `client.wallet.getAccount()` returns the account at index `0`. + +To access other accounts, pass the `index` option: + +``` +const secondAccount = await client.wallet.getAccount({ index: 1 }) +``` \ No newline at end of file diff --git a/docs/sdk-js/getting-started/about-schemas.md b/docs/sdk-js/getting-started/about-schemas.md new file mode 100644 index 000000000..edc7dbf46 --- /dev/null +++ b/docs/sdk-js/getting-started/about-schemas.md @@ -0,0 +1,5 @@ +# About Schemas + +Schemas represents the application data structure, a JSON Schema language based set of rules that allows the creation of a Data Contract. + +You can read more in the [Dash Platform Documentation - Data contract section](../../explanations/platform-protocol-data-contract.md). \ No newline at end of file diff --git a/docs/sdk-js/getting-started/core-concepts.md b/docs/sdk-js/getting-started/core-concepts.md new file mode 100644 index 000000000..dc2ca8f96 --- /dev/null +++ b/docs/sdk-js/getting-started/core-concepts.md @@ -0,0 +1,30 @@ +# Core concepts + +The [Dash Core Developer Guide](https://docs.dash.org/projects/core/en/stable/docs/guide/introduction.html) will answer most of questions about the fundamentals of Dash. However, some elements provided by the SDK need to be grasped, so we will quickly cover some of those. + +## Wallet + +At the core of Dash is the Payment Chain. In order to be able to transact on it, one needs to have a set of [UTXOs](https://docs.dash.org/projects/core/en/stable/docs/guide/block-chain-transaction-data.html) that are controlled by a Wallet instance. + +In order to access your UTXO, you will have to provide a valid mnemonic that will unlock the Wallet and automatically fetch the associated UTXOs. + +When an SDK instance is created, you can access your wallet via the `client.wallet` variable. (Check [wallet-lib documentation](https://dashpay.github.io/platform/Wallet-library/) for more details) + +## Account + +Since the introduction of deterministic wallets ([BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)), a wallet is represented by multiple accounts. + +It is the instance you will use most of the time for receiving or broadcasting payments. + +You can access your account with `client.getWalletAccount()`. See [how to use a different account](../examples/use-different-account.md) if you need to get an account at a specific index. + +## App Schema and Contracts + +The Dash Platform Chain provides developers with the ability to create applications. +Each application requires a set of rules and conditions described as a portable document in the form of a JSON Schema. + +When registered, those applications schemas are called contracts and contains a contractId (namespace : `client.platform.contracts`). + +By default, this library supports Dash Platform Name Service (DPNS) (to attach a name to an identity), under the namespace `client.platform.names` for testnet. + +See: [how to use multiple apps](../getting-started/working-with-multiple-apps.md) \ No newline at end of file diff --git a/docs/sdk-js/getting-started/dash-platform-applications.md b/docs/sdk-js/getting-started/dash-platform-applications.md new file mode 100644 index 000000000..f07a91ed8 --- /dev/null +++ b/docs/sdk-js/getting-started/dash-platform-applications.md @@ -0,0 +1,9 @@ +# Dash Platform applications + +## DPNS + +DPNS is handled in the Dash SDK Client under the namespace `client.platform.names.*'`. [Read more here](../platform/names/names.md) + +## DashPay + +The DashPay contract is registered on testnet under contract id `Bwr4WHCPz5rFVAD87RqTs3izo4zpzwsEdKPWUT1NS1C7`. Its functionality is not incorporated with the Dash SDK at this time. \ No newline at end of file diff --git a/docs/sdk-js/getting-started/getting-started.md b/docs/sdk-js/getting-started/getting-started.md new file mode 100644 index 000000000..d77eb3fcf --- /dev/null +++ b/docs/sdk-js/getting-started/getting-started.md @@ -0,0 +1,12 @@ +# Getting started + +```{toctree} +:maxdepth: 2 + +about-schemas +core-concepts +dash-platform-applications +working-with-multiple-apps +quick-start +with-typescript +``` diff --git a/docs/sdk-js/getting-started/quick-start.md b/docs/sdk-js/getting-started/quick-start.md new file mode 100644 index 000000000..ae84f7bdc --- /dev/null +++ b/docs/sdk-js/getting-started/quick-start.md @@ -0,0 +1,46 @@ +# Quick start + +In order to use this library, you will need to add our [NPM package](https://www.npmjs.com/dash) to your project. + +Having [NodeJS](https://nodejs.org/) installed, just type : + +```bash +npm install dash +``` + +## Initialization + +Let's create a Dash SDK client instance specifying both our mnemonic and the schema we wish to work with. + +```js +const Dash = require('dash'); +const opts = { + wallet: { + mnemonic: "arena light cheap control apple buffalo indicate rare motor valid accident isolate", + }, +}; +const client = new Dash.Client(opts); +client.wallet.getAccount().then(async (account) => { + // Do something +}) +``` + +Quick note: +If no `mnemonic` is provided or `mnemonic: null` is passed inside the `wallet` option, a new mnemonic will be generated. + + +## Make a payment + +```js +client.wallet.getAccount().then(async (account) => { + const transaction = account.createTransaction({ + recipient: 'yixnmigzC236WmTXp9SBZ42csyp9By6Hw8', + amount: 0.12, + }); + await account.broadcastTransaction(transaction); +}); +``` + +## Interact with Dash Platform + +See the [Tutorial section](../../tutorials/introduction.md) of the Dash Platform documentation for examples. \ No newline at end of file diff --git a/docs/sdk-js/getting-started/with-typescript.md b/docs/sdk-js/getting-started/with-typescript.md new file mode 100644 index 000000000..635e19157 --- /dev/null +++ b/docs/sdk-js/getting-started/with-typescript.md @@ -0,0 +1,36 @@ +# TypeScript + +In order to use Dash SDK with TypeScript. + +Create an index.ts file + +```js +import Dash from 'dash'; +const clientOpts = { + wallet: { + mnemonic: null, // Will generate a new address, you should keep it. + }, +}; +const client = new Dash.Client(clientOpts); + +const initializeAccount = async () => { + const account = await client.wallet.getAccount(); + const balance = account.getTotalBalance(); + console.log(`Account balance: ${balance}`) +} +``` + +Have a following `tsconfig.json` file + +```json +{ + "compilerOptions": { + "module": "commonjs", + "moduleResolution": "node", + "esModuleInterop": true + } +} +``` + +**Compile:** `tsc -p tsconfig.json` +**Run:** `node index.js` \ No newline at end of file diff --git a/docs/sdk-js/getting-started/working-with-multiple-apps.md b/docs/sdk-js/getting-started/working-with-multiple-apps.md new file mode 100644 index 000000000..60466b892 --- /dev/null +++ b/docs/sdk-js/getting-started/working-with-multiple-apps.md @@ -0,0 +1,23 @@ +# Working with multiple apps + +When working with other registered contracts, you will need to know their `contractId` and reference it in the SDK constructor. + +Assuming a contract DashPay has the following `contractId: "77w8Xqn25HwJhjodrHW133aXhjuTsTv9ozQaYpSHACE3"`. +You can then pass it as an option. + +```js +const client = new Dash.Client({ + apps: { + dashpay: { + contractId: '77w8Xqn25HwJhjodrHW133aXhjuTsTv9ozQaYpSHACE3' + } + } +}); +``` + +This allow the method `client.platform.documents.get` to provide you field selection. +Therefore, if the contract has a `profile` field that you wish to access, the SDK will allow you to use dot-syntax for access : + +```js +const bobProfile = await client.platform.documents.get('dashpay.profile', { name: 'bob' }); +``` \ No newline at end of file diff --git a/docs/sdk-js/overview.md b/docs/sdk-js/overview.md new file mode 100644 index 000000000..8ecc33dd6 --- /dev/null +++ b/docs/sdk-js/overview.md @@ -0,0 +1,43 @@ +# Overview + +[![NPM Version](https://img.shields.io/npm/v/dash)](https://www.npmjs.org/package/dash) +[![Release Packages](https://github.com/dashpay/platform/actions/workflows/release.yml/badge.svg)](https://github.com/dashpay/platform/actions/workflows/release.yml) +[![Release Date](https://img.shields.io/github/release-date/dashpay/platform)](https://github.com/dashpay/platform/releases/latest) +[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen)](https://github.com/RichardLitt/standard-readme) + +Dash library for JavaScript/TypeScript ecosystem (Wallet, DAPI, Primitives, BLS, ...) + +Dash library provides access via [DAPI](../explanations/dapi.md) to use both the Dash Core network and Dash Platform on [supported networks](https://github.com/dashpay/platform/#supported-networks). The Dash Core network can be used to broadcast and receive payments. Dash Platform can be used to manage identities, register data contracts for applications, and submit or retrieve application data via documents. + +## Install + +### From NPM + +In order to use this library, you will need to add our [NPM package](https://www.npmjs.com/dash) to your project. + +Having [NodeJS](https://nodejs.org/) installed, just type: + +```bash +npm install dash +``` + +### From unpkg + +```html + +``` + +### Usage examples + +- [Generate a mnemonic](./examples/generate-a-new-mnemonic.md) +- [Receive money and display balance](./examples/receive-money-and-check-balance.md) +- [Pay to another address](./examples/paying-to-another-address.md) +- [Use another BIP44 account](./examples/use-different-account.md) + +### Dash Platform Tutorials + +See the [Tutorial section](../tutorials/introduction.md) of the Dash Platform documentation for examples. + +## Licence + +[MIT](https://github.com/dashevo/dashjs/blob/master/LICENCE.md) © Dash Core Group, Inc. \ No newline at end of file diff --git a/docs/sdk-js/platform/contracts/contracts.md b/docs/sdk-js/platform/contracts/contracts.md new file mode 100644 index 000000000..a1b4f52e9 --- /dev/null +++ b/docs/sdk-js/platform/contracts/contracts.md @@ -0,0 +1,16 @@ +# Contracts + +## What is a contract + +Contracts are registered sets of rules defined in a [JSON Application Schema](../../getting-started/core-concepts.md). + +See the Dash Platform documentation for more information about [Data Contracts](../../../explanations/platform-protocol-data-contract.md). + +```{toctree} +:maxdepth: 2 + +create +get +publish +update +``` diff --git a/docs/sdk-js/platform/contracts/create.md b/docs/sdk-js/platform/contracts/create.md new file mode 100644 index 000000000..b6e1bed22 --- /dev/null +++ b/docs/sdk-js/platform/contracts/create.md @@ -0,0 +1,38 @@ +# Create + +**Usage**: `client.platform.contracts.create(contractDefinitions, identity)` +**Description**: This method will return a Contract object initialized with the parameters defined and apply to the used identity. + +Parameters: + +| parameters | type | required | Description | +| ----------------------- | ---------------- | -------- | ---------------------------------------------------------------------------------------------------------------------- | +| **contractDefinitions** | JSONDataContract | yes | The defined [JSON Application Schema](../../../explanations/platform-protocol-data-contract.md) | +| **identity** | Identity | yes | A valid [registered `application` identity](../identities/register.md) | + +**Example**: + +```js + const identityId = '';// Your identity identifier. + + // Your valid json contract definitions + const contractDefinitions = { + note: { + properties: { + message: { + type: "string" + } + }, + additionalProperties: false + } + }; + const identity = await client.platform.identities.get(identityId); + const contract = client.platform.contracts.create(contractDefinitions, identity); + + // You can use the validate method from DPP to validate the created contract + const validationResult = client.platform.dpp.dataContract.validate(contract); +``` + +**Note**: When your contract is created, it will only exist locally. Use the [publish](../contracts/publish.md) method to register it. + +Returns: Contract. \ No newline at end of file diff --git a/docs/sdk-js/platform/contracts/get.md b/docs/sdk-js/platform/contracts/get.md new file mode 100644 index 000000000..7cf5587b0 --- /dev/null +++ b/docs/sdk-js/platform/contracts/get.md @@ -0,0 +1,14 @@ +# Get + +**Usage**: `client.platform.contracts.get(contractId)` +**Description**: This method will allow you to fetch back a contract from its id. + +Parameters: + +| parameters | type | required | Description | +| -------------- | ------ | -------- | ---------------------------------------------------- | +| **identifier** | string | yes | Will fetch back the contract matching the identifier | + +**Example**: `await client.platform.contracts.get('77w8Xqn25HwJhjodrHW133aXhjuTsTv9ozQaYpSHACE3')` + +Returns: Contract (or `null` if it's not a registered contract). \ No newline at end of file diff --git a/docs/sdk-js/platform/contracts/publish.md b/docs/sdk-js/platform/contracts/publish.md new file mode 100644 index 000000000..9eb493f14 --- /dev/null +++ b/docs/sdk-js/platform/contracts/publish.md @@ -0,0 +1,23 @@ +# Publish + +**Usage**: `client.platform.contracts.publish(contract, identity)` +**Description**: This method will sign and broadcast any valid contract. + +Parameters: + +| parameters | type | required | Description | +| ------------ | -------- | -------- | -------------------------------------------------------------------------------------------------------- | +| **contract** | Contract | yes | A valid [created contract](../contracts/create.md) | +| **identity** | Identity | yes | A valid [registered `application` identity](../identities/register.md) | + +**Example**: + +```js +const identityId = '';// Your identity identifier. +const identity = await client.platform.identities.get(identityId); +// See the contract.create documentation for more on how to create a dataContract +const contract = await client.platform.contracts.create(contractDefinitions, identity); +await client.platform.contracts.publish(contract, identity); +``` + +Returns : DataContractCreateTransition. \ No newline at end of file diff --git a/docs/sdk-js/platform/contracts/update.md b/docs/sdk-js/platform/contracts/update.md new file mode 100644 index 000000000..e6ac2b0bf --- /dev/null +++ b/docs/sdk-js/platform/contracts/update.md @@ -0,0 +1,13 @@ +# Update + +**Usage**: `client.platform.contracts.update(contract, identity)` +**Description**: This method will sign and broadcast an updated valid contract. + +Parameters: + +| parameters | type | required | Description | +| ------------ | -------- | -------- | ------------------------------------------------------------------------------------------------------------- | +| **contract** | Contract | yes | A valid [created contract](../contracts/create.md) | +| **identity** | Identity | yes | A valid [registered `application` identity](../identities/register.md) | + +Returns: DataContractUpdateTransition. \ No newline at end of file diff --git a/docs/sdk-js/platform/documents/broadcast.md b/docs/sdk-js/platform/documents/broadcast.md new file mode 100644 index 000000000..da9d88c42 --- /dev/null +++ b/docs/sdk-js/platform/documents/broadcast.md @@ -0,0 +1,32 @@ +# Broadcast + +**Usage**: `client.platform.document.broadcast(documents, identity)` +**Description**: This method will broadcast the document on the Application Chain + +Parameters: + +| parameters | type | required | Description | +| --------------------- | ------------------- | -------- | ----------------------------------------------------------------------------------------------------------- | +| **documents** | Object | yes | | +| **documents.create** | ExtendedDocument\[] | no | array of valid [created document](../documents/create.md) to create | +| **documents.replace** | ExtendedDocument\[] | no | array of valid [created document](../documents/create.md) to replace | +| **documents.delete** | ExtendedDocument\[] | no | array of valid [created document](../documents/create.md) to delete | +| **identity** | Identity | yes | A valid [registered identity](../identities/register.md) | + +**Example**: + +```js +const identityId = '';// Your identity identifier +const identity = await client.platform.identities.get(identityId); + +const helloWorldDocument = await client.platform.documents.create( + // Assuming a contract tutorialContract is registered with a field note + 'tutorialContract.note', + identity, + { message: 'Hello World'}, +); + +await client.platform.documents.broadcast({ create: [helloWorldDocument] }, identity); +``` + +Returns: documents. \ No newline at end of file diff --git a/docs/sdk-js/platform/documents/create.md b/docs/sdk-js/platform/documents/create.md new file mode 100644 index 000000000..f261034d7 --- /dev/null +++ b/docs/sdk-js/platform/documents/create.md @@ -0,0 +1,30 @@ +# Create + +**Usage**: `client.platform.documents.create(typeLocator, identity, documentOpts)` +**Description**: This method will return a ExtendedDocument object initialized with the parameters defined and apply to the used identity. + +Parameters: + +| parameters | type | required | Description | +| -------------- | -------- | -------- | ----------------------------------------------------------------------------------------------- | +| **dotLocator** | string | yes | Field of a specific application, under the form `appName.fieldName` | +| **identity** | Identity | yes | A valid [registered identity](../identities/register.md) | +| **docOpts** | Object | yes | A valid data that match the data contract structure | + +**Example**: + +```js +const identityId = '';// Your identity identifier +const identity = await client.platform.identities.get(identityId); + +const helloWorldDocument = await client.platform.documents.create( + // Assume a contract helloWorldContract is registered with a field note + 'helloWorldContract.note', + identity, + { message: 'Hello World'}, + ); +``` + +**Note**: When your document is created, it will only exist locally, use the [broadcast](../documents/broadcast.md) method to register it. + +Returns: ExtendedDocument \ No newline at end of file diff --git a/docs/sdk-js/platform/documents/documents.md b/docs/sdk-js/platform/documents/documents.md new file mode 100644 index 000000000..f44b9180f --- /dev/null +++ b/docs/sdk-js/platform/documents/documents.md @@ -0,0 +1,16 @@ +# Documents + +## What is a document + +Documents in Dash Platform are similar to those in standard document-oriented databases (MongoDB,...). +They represent a record consisting of one, or multiples field-value pairs and should respect the structure of the dataContract on which they are submitted in. + +See more on the Dash Platform documentation about [Data Contract](../../../explanations/platform-protocol-data-contract.md). + +```{toctree} +:maxdepth: 2 + +broadcast +create +get +``` diff --git a/docs/sdk-js/platform/documents/get.md b/docs/sdk-js/platform/documents/get.md new file mode 100644 index 000000000..4772a6e12 --- /dev/null +++ b/docs/sdk-js/platform/documents/get.md @@ -0,0 +1,35 @@ +# Get + +**Usage**: `client.platform.documents.get(typeLocator, opts)` +**Description**: This method will allow you to fetch back documents matching the provided parameters. + +Parameters: + +| parameters | type | required | Description | +| --------------- | ------ | ---------------- | ------------------------------------------------------------------- | +| **typeLocator** | string | yes | Field of a specific application, under the form `appName.fieldName` | +| **opts** | object | no (default: {}) | Query options of the request | + +**Queries options**: + +| parameters | type | required | Description | +| -------------- | ------- | -------- | ------------------------- | +| **where** | array | no | Mongo-like where query | +| **orderBy** | array | no | Mongo-like orderBy query | +| **limit** | integer | no | how many objects to fetch | +| **startAt** | integer | no | number of objects to skip | +| **startAfter** | integer | no | exclusive skip | + +[Learn more about query syntax](../../../reference/query-syntax.md). + +**Example**: + +```js + const queryOpts = { + where: [ + ['normalizedLabel', '==', 'alice'], + ['normalizedParentDomainName', '==', 'dash'], + ], + }; + await client.platform.documents.get('dpns.domain', queryOpts); +``` \ No newline at end of file diff --git a/docs/sdk-js/platform/identities/get.md b/docs/sdk-js/platform/identities/get.md new file mode 100644 index 000000000..b9ba54088 --- /dev/null +++ b/docs/sdk-js/platform/identities/get.md @@ -0,0 +1,14 @@ +# Get + +**Usage**: `client.platform.identities.get(identityId)` +**Description**: This method will allow you to fetch back an identity from its id. + +Parameters: + +| parameters | type | required | Description | +| -------------- | ------ | -------- | ---------------------------------------------------- | +| **identifier** | string | yes | Will fetch back the identity matching the identifier | + +**Example**: `await client.platform.identities.get('3GegupTgRfdN9JMS8R6QXF3B2VbZtiw63eyudh1oMJAk')` + +Returns: Identity (or `null` if it does not exist). \ No newline at end of file diff --git a/docs/sdk-js/platform/identities/identities.md b/docs/sdk-js/platform/identities/identities.md new file mode 100644 index 000000000..467ceeafc --- /dev/null +++ b/docs/sdk-js/platform/identities/identities.md @@ -0,0 +1,21 @@ +# Identities + +## What is an identity + +An Identity is a blockchain-based identifier for individuals (users) and applications. +Identities are the atomic element that, when linked with additional applications, can be extended to provide new functionality. + +Read more on the Dash Platform documentation about [Identity](../../../explanations/identity.md). +You might also want to consult the usage for the [DPNS Name Service](../names/names.md) in order to attach a name to your created identity. + +## Credits + +Each identity contains a credit balance. The ratio is 1 duff = 1000 credits. + +```{toctree} +:maxdepth: 2 + +get +register +topup +``` diff --git a/docs/sdk-js/platform/identities/register.md b/docs/sdk-js/platform/identities/register.md new file mode 100644 index 000000000..cfd037c78 --- /dev/null +++ b/docs/sdk-js/platform/identities/register.md @@ -0,0 +1,16 @@ +# Register + +**Usage**: `client.platform.identities.register()` +**Description**: This method will register a new identity for you. + +Parameters: + +| parameters | type | required | Description | +| ------------- | ------ | -------- | ------------------------------------------------------------------- | +| fundingAmount | number | no | Defaults: 10000. Allow to set a funding amount in duffs (satoshis). | + +**Example**: `await client.platform.identities.register()` + +**Note**: The created identity will be associated to the active account. You might want to know more about how to [change your active account](../../examples/use-different-account.md). + +Returns: Identity. \ No newline at end of file diff --git a/docs/sdk-js/platform/identities/topup.md b/docs/sdk-js/platform/identities/topup.md new file mode 100644 index 000000000..bca04e36f --- /dev/null +++ b/docs/sdk-js/platform/identities/topup.md @@ -0,0 +1,25 @@ +# Topup + +**Usage**: `client.platform.identities.topUp(identity, amount)` +**Description**: This method will topup the provided identity's balance. + +_The identity balance might slightly vary from the topped up amount because of the transaction fee estimation._ + +Parameters: + +| parameters | type | required | Description | +| ------------ | -------- | -------- | ----------------------------------------------------------------------------------------------- | +| **identity** | Identity | yes | A valid [registered identity](../identities/register.md) | +| **amount** | number | yes | A duffs (satoshis) value corresponding to the amount you want to top up to the identity. | + +**Example**: + +```js +const identityId = '';// Your identity identifier +const identity = await client.platform.identities.get(identityId); +await client.platform.identities.topUp(identity.getId(), 10000); + +console.log(`New identity balance: ${identity.balance}`) +``` + +Returns: Boolean. \ No newline at end of file diff --git a/docs/sdk-js/platform/names/names.md b/docs/sdk-js/platform/names/names.md new file mode 100644 index 000000000..59400072b --- /dev/null +++ b/docs/sdk-js/platform/names/names.md @@ -0,0 +1,20 @@ +# Names + +## What is DPNS + +DPNS is a special Dash Platform Application that is intended to provide a naming service for the Application Chain. + +Decoupling name from the blockchain identity enables a unique user experience coupled with the highest security while remaining compatible with [Decentralized Identifiers](https://www.w3.org/TR/did-core/). + +Limitation: max length of 63 characters on charset `0-9`,`A-Z`(case insensitive), `-`. + +Domain names are linked to an Identity. + +```{toctree} +:maxdepth: 2 + +register +resolve +resolvebyrecord +search +``` diff --git a/docs/sdk-js/platform/names/register.md b/docs/sdk-js/platform/names/register.md new file mode 100644 index 000000000..59482fc80 --- /dev/null +++ b/docs/sdk-js/platform/names/register.md @@ -0,0 +1,18 @@ +# Register + +**Usage**: `client.platform.names.register(name, records, identity)` +**Description**: This method will create a DPNS record matching your identity to the user or appname defined. + +Parameters: + +| parameters | type | required | Description | +| -------------------------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **name** | String | yes | An alphanumeric (1-63 character) value used for human-identification (can contain `-` but not as the first or last character). If a name with no parent domain is entered, '.dash' is used. | +| **records** | Object | yes | records object having only one of the following items | +| **records.dashUniqueIdentityId** | String | no | Unique Identity ID for this name record | +| **records.dashAliasIdentityId** | String | no | Used to signify that this name is the alias for another id | +| **identity** | Identity | yes | A valid [registered identity](../identities/register.md) | + +**Example**: `await client.platform.names.register('alice', { dashUniqueIdentityId: identity.getId() }, identity)` + +Returns: the created domain document \ No newline at end of file diff --git a/docs/sdk-js/platform/names/resolve.md b/docs/sdk-js/platform/names/resolve.md new file mode 100644 index 000000000..ecd4a082c --- /dev/null +++ b/docs/sdk-js/platform/names/resolve.md @@ -0,0 +1,14 @@ +# Resovle + +**Usage**: `client.platform.names.resolve('.dash')` +**Description**: This method will allow you to resolve a DPNS record from its humanized name. + +Parameters: + +| parameters | type | required | Description | +| ---------- | ------ | -------- | ----------------------------------------------------------------------------- | +| **name** | String | yes | An alphanumeric (2-63) value used for human-identification (can contains `-`) | + +**Example**: `await client.platform.names.resolve('alice.dash')` + +Returns : ExtendedDocument (or `null` if do not exist). \ No newline at end of file diff --git a/docs/sdk-js/platform/names/resolvebyrecord.md b/docs/sdk-js/platform/names/resolvebyrecord.md new file mode 100644 index 000000000..63b272456 --- /dev/null +++ b/docs/sdk-js/platform/names/resolvebyrecord.md @@ -0,0 +1,22 @@ +# ResolveByRecord + +**Usage**: `client.platform.names.resolveByRecord(record, value)` +**Description**: This method will allow you to resolve a DPNS record by identity ID. + +Parameters: + +| parameters | type | required | Description | +| ---------- | ------ | -------- | -------------------------------------------------------------------- | +| **record** | String | yes | Type of the record (`dashUniqueIdentityId` or `dashAliasIdentityId`) | +| **value** | String | yes | Identifier value for the record | + +**Example**: + +This example will describe how to resolve names by the dash unique identity id. + +```js +const identityId = '3ge4yjGinQDhxh2aVpyLTQaoka45BkijkoybfAkDepoN'; +const document = await client.platform.names.resolveByRecord('dashUniqueIdentityId', identityId); +``` + +Returns: array of ExtendedDocument. \ No newline at end of file diff --git a/docs/sdk-js/platform/names/search.md b/docs/sdk-js/platform/names/search.md new file mode 100644 index 000000000..0a3bc0141 --- /dev/null +++ b/docs/sdk-js/platform/names/search.md @@ -0,0 +1,24 @@ +# Search + +**Usage**: `client.platform.names.search(labelPrefix, parentDomain)` +**Description**: This method will allow you to search all records matching the label prefix on the specified parent domain. + +Parameters: + +| parameters | type | required | Description | +| ---------------- | ------ | -------- | ------------------------------------------------- | +| **labelPrefix** | String | yes | label prefix to search for | +| **parentDomain** | String | yes | parent domain name on which to perform the search | + +**Example**: + +This example will describe how to search all names on the parent domain `dash` that starts with the label prefix `al`. +It will resolves names documents such as `alice`, `alex` etc... + +```js +const labelPrefix = 'al'; +const parentDomain = 'dash'; +const document = await client.platform.names.search(labelPrefix, parentDomain); +``` + +Returns: Documents matching the label prefix on the parent domain. \ No newline at end of file diff --git a/docs/sdk-js/platform/platform.md b/docs/sdk-js/platform/platform.md new file mode 100644 index 000000000..11f4f1d4b --- /dev/null +++ b/docs/sdk-js/platform/platform.md @@ -0,0 +1,20 @@ +# Platform + +The Dash Platform provides a technology stack on the top of Dash Network that allows creation of feature-rich decentralized applications. + +You can learn more from the [Dash Platform Documentation - What is Dash Platform?](../../intro/what-is-dash-platform.md) + +## Platform components + +- DAPI: A decentralized API that runs on all Masternodes and offers gRPC endpoints for retrieving payment chain metadata (blocks, transactions), as well as application data (documents, contracts, identities). +- Drive: Application chain storage layer where the data defined by Data Contracts is stored and managed. +- DPNS: Naming service provided by a Dash Platform App + +```{toctree} +:maxdepth: 3 + +contracts/contracts +documents/documents +identities/identities +names/names +``` diff --git a/docs/sdk-js/usage/dapi.md b/docs/sdk-js/usage/dapi.md new file mode 100644 index 000000000..83ade98b8 --- /dev/null +++ b/docs/sdk-js/usage/dapi.md @@ -0,0 +1,13 @@ +# DAPI + +## About DAPI + +DAPI (Decentralized API) is a distributed and decentralized endpoints provided by the Masternode Network. + +## Get the DAPI-Client instance + +```js + const dapiClient = client.getDAPIClient(); +``` + +The usage is then [described here](../../explanations/dapi.md). \ No newline at end of file diff --git a/docs/sdk-js/usage/dashcore-lib-primitives.md b/docs/sdk-js/usage/dashcore-lib-primitives.md new file mode 100644 index 000000000..269da2340 --- /dev/null +++ b/docs/sdk-js/usage/dashcore-lib-primitives.md @@ -0,0 +1,122 @@ +# Dashcore Lib primitives + +All Dashcore lib primitives are exposed via the `Core` namespace. + +```js +const Dash = require('dash'); +const { + Core: { + Block, + Transaction, + Address, + // ... + } +} = Dash; +``` + +## Transaction + +The Transaction primitive allows creating and manipulating transactions. It also allows signing transactions with a private key. +Supports fee control and input/output access (which allows passing a specific script). + +```js +const { Transaction } = Dash.Core; +const tx = new Transaction(txProps) +``` + +Access the [Transaction documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/transaction.md) + +## Address + +Standardized representation of a Dash Address. Address can be instantiated from a String, PrivateKey, PublicKey, HDPrivateKey or HdPublicKey. +Pay-to-script-hash (P2SH) multi-signature addresses from an array of PublicKeys are also supported. + +```js +const { Address } = Dash.Core; +``` + +Access the [Address documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/address.md) + +## Block + +Given a binary representation of the block as input, the Block class allows you to have a deserialized representation of a Block or its header. It also allows validating the transactions in the block against the header merkle root. + +The block's transactions can also be explored by iterating over elements in array (`block.transactions`). + +`const { Block } = Dash.Core;` + +Access the [Block documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/block.md) + +## UnspentOutput + +Representation of an UnspentOutput (also called UTXO as in Unspent Transaction Output). +Mostly useful in association with a Transaction and for Scripts. + +`const { UnspentOutput } = Dash.Core.Transaction;` + +Access the [UnspentOutput documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/unspentoutput.md) + +## HDPublicKey + +Hierarchical Deterministic (HD) version of the PublicKey. +Used internally by Wallet-lib and for exchange between peers (DashPay) + +const { HDPublicKey } = Dash.Core;\` + +Access the [HDKeys documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/hierarchical.md#hdpublickey) + +## HDPrivateKey + +Hierarchical Deterministic (HD) version of the PrivateKey. +Used internally by Wallet-lib. + +`const { HDPrivateKey } = Dash.Core;` + +Access the [HDKeys documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/hierarchical.md#hdprivatekey) + +## PublicKey + +`const { PublicKey } = Dash.Core;` + +Access the [PublicKey documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/publickey.md) + +## PrivateKey + +`const { PrivateKey } = Dash.Core;` + +Access the [PrivateKey documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/privatekey.md) + +## Mnemonic + +Implementation of [BIP39 Mnemonic code for generative deterministic keys](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki). +Generates a random mnemonic with the chosen language, validates a mnemonic or returns the associated HDPrivateKey. + +`const { Mnemonic } = Dash.Core;` + +Access the [Mnemonic documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/mnemonic.md) + +## Network + +A representation of the internal parameters relative to the selected network. By default, all primitives works with 'livenet'. + +`const { Network } = Dash.Core;` + +Access the [Network documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/networks.md) + +## Script + +`const { Script } = Dash.Core.Transaction;` + +Access the [Script documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/script.md) + +## Input + +`const { Input } = Dash.Core.Transaction;` + +Access the [Transaction documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/transaction.md#adding-inputs) + +## Output + +`const { Output } = Dash.Core.Transaction;` + +Access the [Transaction documentation on dashpay/dashcore-lib](https://github.com/dashpay/dashcore-lib/blob/master/docs/core-concepts/transaction.md#handling-outputs) \ No newline at end of file diff --git a/docs/sdk-js/usage/usage.md b/docs/sdk-js/usage/usage.md new file mode 100644 index 000000000..dd2c4456a --- /dev/null +++ b/docs/sdk-js/usage/usage.md @@ -0,0 +1,9 @@ +# Usage + +```{toctree} +:maxdepth: 2 +:titlesonly: + +dapi +dashcore-lib-primitives +``` diff --git a/docs/sdk-js/wallet/accounts.md b/docs/sdk-js/wallet/accounts.md new file mode 100644 index 000000000..fdacb8ff4 --- /dev/null +++ b/docs/sdk-js/wallet/accounts.md @@ -0,0 +1,27 @@ +# Accounts + +## Getting an account + +When Wallet is initialized with `mnemonic`, it holds multiple Accounts according to BIP44. +Each Account holds the keys needed to make a payments from it. + +Wallet's `getAccount` method used to access an account: + +```js +const client = new Dash.Client({ + wallet: { + mnemonic: "maximum blast eight orchard waste wood gospel siren parent deer athlete impact", + }, +}); + +const account = await client.wallet.getAccount() +// Do something with account +``` + +As optional parameter, an integer representing the account `index` can be passed as parameter. By default, index account on call is 0. + +``` +client.wallet.getAccount({ index: 1 }) +``` + +Awaiting for the `getAccount()` promise is necessary to ensure the wallet is synced-up with the network and make sure that the UTXO set is ready to be used for payment/signing. \ No newline at end of file diff --git a/docs/sdk-js/wallet/signing-encrypt.md b/docs/sdk-js/wallet/signing-encrypt.md new file mode 100644 index 000000000..b6d78ec8b --- /dev/null +++ b/docs/sdk-js/wallet/signing-encrypt.md @@ -0,0 +1,30 @@ +# Signing and encryption + +## Obtain account + +```js +const account = await client.wallet.getAccount(); +``` + +## Sign a Transaction + +```js +const tx = new Dash.Core.Transaction({ + // ...txOpts +}); +const signedTx = account.sign(tx); +``` + +## Encrypt a message + +```js + const message = 'Something'; + const signedMessage = account.encrypt('AES', message, 'secret'); +``` + +## Decrypt a message + +```js +const encrypted = 'U2FsdGVkX19JLa+1UpbMcut1/QFWLMlKUS+iqz+7Wl4='; +const message = account.decrypt('AES', encrypted, 'secret'); +``` \ No newline at end of file diff --git a/docs/sdk-js/wallet/wallet.md b/docs/sdk-js/wallet/wallet.md new file mode 100644 index 000000000..f0f9513b6 --- /dev/null +++ b/docs/sdk-js/wallet/wallet.md @@ -0,0 +1,17 @@ +# Wallet + +## About Wallet-lib + +When Dash.Client is initiated with a `mnemonic` property, a wallet instance becomes accessible via `client.wallet` property. + +To initialize the wallet account and synchronize with the network, use `client.wallet.getAccount()`. + +Find out more about the Wallet in its [complete documentation](https://dashpay.github.io/platform/Wallet-library/) + +```{toctree} +:maxdepth: 2 +:titlesonly: + +accounts +signing-encrypt +``` diff --git a/scripts/1-readme-rename.sh b/scripts/1-readme-rename.sh index 2d0697590..15900b4b9 100755 --- a/scripts/1-readme-rename.sh +++ b/scripts/1-readme-rename.sh @@ -10,5 +10,14 @@ find docs/intro -iname "*.md" -type f -name 'intro-*' -print0 | xargs -0 rename find docs/protocol-ref -iname "*.md" -type f -name 'platform-protocol-reference-*' -print0 | xargs -0 rename $RENAME_ARGS 's/platform-protocol-reference-//' find docs/reference -iname "*.md" -type f -name 'reference-*' -print0 | xargs -0 rename $RENAME_ARGS 's/reference-//' find docs/resources -iname "*.md" -type f -name 'resources-*' -print0 | xargs -0 rename $RENAME_ARGS 's/resources-//' +find docs/sdk-js -iname "*.md" -type f -name 'dash-sdk-overview*' -print0 | xargs -0 rename $RENAME_ARGS 's/dash-sdk-//' +find docs/sdk-js/examples -iname "*.md" -type f -name 'dash-sdk-examples-*' -print0 | xargs -0 rename $RENAME_ARGS 's/dash-sdk-examples-//' +find docs/sdk-js/getting-started -iname "*.md" -type f -name 'dash-sdk-getting-started-*' -print0 | xargs -0 rename $RENAME_ARGS 's/dash-sdk-getting-started-//' +find docs/sdk-js/platform -iname "*.md" -type f -name 'dash-sdk-contracts-*' -print0 | xargs -0 rename $RENAME_ARGS 's/dash-sdk-contracts-//' +find docs/sdk-js/platform -iname "*.md" -type f -name 'dash-sdk-documents-*' -print0 | xargs -0 rename $RENAME_ARGS 's/dash-sdk-documents-//' +find docs/sdk-js/platform -iname "*.md" -type f -name 'dash-sdk-identities-*' -print0 | xargs -0 rename $RENAME_ARGS 's/dash-sdk-identities-//' +find docs/sdk-js/platform -iname "*.md" -type f -name 'dash-sdk-names-*' -print0 | xargs -0 rename $RENAME_ARGS 's/dash-sdk-names-//' +find docs/sdk-js/usage -iname "*.md" -type f -name 'dash-sdk-usage-*' -print0 | xargs -0 rename $RENAME_ARGS 's/dash-sdk-usage-//' +find docs/sdk-js/wallet -iname "*.md" -type f -name 'dash-sdk-wallet-*' -print0 | xargs -0 rename $RENAME_ARGS 's/dash-sdk-wallet-//' find docs/tutorials -iname "*.md" -type f -name 'tutorials-*' -print0 | xargs -0 rename $RENAME_ARGS 's/tutorials-//' find docs/tutorials -iname "*.md" -type f -name 'tutorial-*' -print0 | xargs -0 rename $RENAME_ARGS 's/tutorial-//'