diff --git a/README.md b/README.md index a239a04..71422c6 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ --- -A [battle-tested](__tests__) toolkit for the Nano cryptocurrency, allowing you to derive keys, generate seeds, hashes, signatures, proofs of work and state blocks. +A [battle-tested](__tests__) toolkit for the Nano cryptocurrency. If you are looking for legacy blocks, you will want the `^1.0.0` versions. @@ -17,13 +17,43 @@ The documentation is available locally in [docs/](docs/) or online at [https://m --- +## Features + +- Generate seeds +- Derive secret keys, public keys and addresses +- Hash blocks +- Sign and verify blocks +- Compute and test proofs of work +- Check the format of seeds, secret keys, public keys, addresses, amounts, etc. +- Convert Nano units +- **CLI doing all of the above** + +--- + ## Usage +To install the library: + ``` npm install nanocurrency # or yarn add nanocurrency ``` +```js +import * as nanocurrency from 'nanocurrency'; +``` + +To install the CLI: + +``` +npm install -g nanocurrency +# or yarn global add nanocurrency +``` + +```bash +nanocurrency --help +``` + --- ## Performance @@ -39,21 +69,15 @@ Considering you can pre-compute and cache the work prior to an actual transactio Contributions are very welcome. To develop, make use of the following commands (using [Yarn](https://yarnpkg.com)): -* `yarn build:dev`: build the C++ code to WebAssembly and bundle the files into the `dist` directory, without optimization so that it is fast while developing. Note that you'll need to have Docker installed +- `yarn build:dev`: build the C++ code to WebAssembly and bundle the files into the `dist` directory, without optimization so that it is fast while developing. Note that you'll need to have Docker installed -* `yarn test`: test the code +- `yarn test`: test the code -* `yarn lint`: lint the code against [JavaScript Standard Style](https://standardjs.com) +- `yarn lint`: lint the code against [JavaScript Standard Style](https://standardjs.com) -* `yarn format`: format the code with [Prettier](https://prettier.io) +- `yarn format`: format the code with [Prettier](https://prettier.io) -* `yarn generate-docs`: generate the `DOCUMENTATION.md` file from the [JSDoc](http://usejsdoc.org) annotations - ---- - -## Helpful materials - -* Article about seed / secret key / public key / address generation: https://medium.com/@benkray/raiblocks-deterministic-keys-8cb869cc6046 +- `yarn generate-docs`: generate the `DOCUMENTATION.md` file from the [JSDoc](http://usejsdoc.org) annotations --- diff --git a/docs/enums/unit.html b/docs/enums/unit.html index ecdc9d0..b992d47 100644 --- a/docs/enums/unit.html +++ b/docs/enums/unit.html @@ -1055,7 +1055,7 @@ img { max-width: 100%; }
KNano: = "KNano"
@@ -1070,7 +1070,7 @@ img { max-width: 100%; }
MNano: = "MNano"
@@ -1085,7 +1085,7 @@ img { max-width: 100%; }
NANO: = "NANO"
@@ -1100,7 +1100,7 @@ img { max-width: 100%; }
Nano: = "Nano"
@@ -1115,7 +1115,7 @@ img { max-width: 100%; }
hex: = "hex"
@@ -1130,7 +1130,7 @@ img { max-width: 100%; }
knano: = "knano"
@@ -1145,7 +1145,7 @@ img { max-width: 100%; }
nano: = "nano"
@@ -1160,7 +1160,7 @@ img { max-width: 100%; }
raw: = "raw"
diff --git a/docs/index.html b/docs/index.html index 9258d38..1082fdc 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1049,13 +1049,13 @@ img { max-width: 100%; }

checkAddress

    -
  • checkAddress(address: any): boolean
  • +
  • checkAddress(address: string): boolean
  • @@ -1066,7 +1066,7 @@ img { max-width: 100%; }

    Parameters

    • -
      address: any
      +
      address: string

      The address to check

      @@ -1081,13 +1081,13 @@ img { max-width: 100%; }

      checkAmount

        -
      • checkAmount(amount: any): boolean
      • +
      • checkAmount(amount: string): boolean
      • @@ -1098,7 +1098,7 @@ img { max-width: 100%; }

        Parameters

        • -
          amount: any
          +
          amount: string

          The amount to check

          @@ -1113,13 +1113,13 @@ img { max-width: 100%; }

          checkHash

            -
          • checkHash(hash: any): boolean
          • +
          • checkHash(hash: string): boolean
          • @@ -1130,7 +1130,7 @@ img { max-width: 100%; }

            Parameters

            • -
              hash: any
              +
              hash: string

              The hash to check

              @@ -1145,13 +1145,13 @@ img { max-width: 100%; }

              checkKey

                -
              • checkKey(key: any): boolean
              • +
              • checkKey(key: string): boolean
              • @@ -1162,7 +1162,7 @@ img { max-width: 100%; }

                Parameters

                • -
                  key: any
                  +
                  key: string

                  The key to check

                  @@ -1177,13 +1177,13 @@ img { max-width: 100%; }

                  checkSeed

                    -
                  • checkSeed(seed: any): boolean
                  • +
                  • checkSeed(seed: string): boolean
                  • @@ -1194,7 +1194,7 @@ img { max-width: 100%; }

                    Parameters

                    • -
                      seed: any
                      +
                      seed: string

                      The seed to check

                      @@ -1209,13 +1209,13 @@ img { max-width: 100%; }

                      checkSignature

                        -
                      • checkSignature(signature: any): boolean
                      • +
                      • checkSignature(signature: string): boolean
                      • @@ -1226,7 +1226,7 @@ img { max-width: 100%; }

                        Parameters

                        • -
                          signature: any
                          +
                          signature: string

                          The signature to check

                          @@ -1241,13 +1241,13 @@ img { max-width: 100%; }

                          checkWork

                            -
                          • checkWork(work: any): boolean
                          • +
                          • checkWork(work: string): boolean
                          • @@ -1258,7 +1258,7 @@ img { max-width: 100%; }

                            Parameters

                            • -
                              work: any
                              +
                              work: string

                              The work to check

                              @@ -1279,7 +1279,7 @@ img { max-width: 100%; }
                            • @@ -1318,7 +1318,7 @@ img { max-width: 100%; }
                            • @@ -1356,7 +1356,7 @@ img { max-width: 100%; }
                            • @@ -1396,7 +1396,7 @@ img { max-width: 100%; }
                            • @@ -1434,7 +1434,7 @@ img { max-width: 100%; }
                            • @@ -1466,7 +1466,7 @@ img { max-width: 100%; }
                            • @@ -1504,7 +1504,7 @@ img { max-width: 100%; }
                            • @@ -1527,7 +1527,7 @@ img { max-width: 100%; }
                            • @@ -1559,7 +1559,7 @@ img { max-width: 100%; }
                            • @@ -1591,7 +1591,7 @@ img { max-width: 100%; }
                            • @@ -1623,7 +1623,7 @@ img { max-width: 100%; }
                            • diff --git a/docs/interfaces/blockdata.html b/docs/interfaces/blockdata.html index 2c3e0d4..d604d36 100644 --- a/docs/interfaces/blockdata.html +++ b/docs/interfaces/blockdata.html @@ -1051,7 +1051,7 @@ img { max-width: 100%; }
                              balance: string
                              @@ -1066,7 +1066,7 @@ img { max-width: 100%; }
                              link: string
                              @@ -1081,7 +1081,7 @@ img { max-width: 100%; }
                              previous: string
                              @@ -1096,7 +1096,7 @@ img { max-width: 100%; }
                              representative: string
                              @@ -1111,7 +1111,7 @@ img { max-width: 100%; }
                              work: string | null
                              diff --git a/docs/interfaces/computeworkparams.html b/docs/interfaces/computeworkparams.html index 45024ce..098abc8 100644 --- a/docs/interfaces/computeworkparams.html +++ b/docs/interfaces/computeworkparams.html @@ -1039,7 +1039,7 @@ img { max-width: 100%; }
                              workerCount: number
                              @@ -1054,7 +1054,7 @@ img { max-width: 100%; }
                              workerIndex: number
                              diff --git a/docs/interfaces/convertparams.html b/docs/interfaces/convertparams.html index bc2efab..9530e41 100644 --- a/docs/interfaces/convertparams.html +++ b/docs/interfaces/convertparams.html @@ -1039,7 +1039,7 @@ img { max-width: 100%; }
                              from: Unit
                              @@ -1054,7 +1054,7 @@ img { max-width: 100%; }
                              to: Unit
                              diff --git a/docs/interfaces/deriveaddressparams.html b/docs/interfaces/deriveaddressparams.html index c1d61b9..c575d8b 100644 --- a/docs/interfaces/deriveaddressparams.html +++ b/docs/interfaces/deriveaddressparams.html @@ -1035,7 +1035,7 @@ img { max-width: 100%; }
                              useNanoPrefix: undefined | true | false
                              diff --git a/docs/interfaces/hashblockparams.html b/docs/interfaces/hashblockparams.html index fb1aac0..7a56ccb 100644 --- a/docs/interfaces/hashblockparams.html +++ b/docs/interfaces/hashblockparams.html @@ -1051,7 +1051,7 @@ img { max-width: 100%; }
                              account: string
                              @@ -1066,7 +1066,7 @@ img { max-width: 100%; }
                              balance: string
                              @@ -1081,7 +1081,7 @@ img { max-width: 100%; }
                              link: string
                              @@ -1096,7 +1096,7 @@ img { max-width: 100%; }
                              previous: string
                              @@ -1111,7 +1111,7 @@ img { max-width: 100%; }
                              representative: string
                              diff --git a/docs/interfaces/signblockparams.html b/docs/interfaces/signblockparams.html index 951eb6f..7f7b2cd 100644 --- a/docs/interfaces/signblockparams.html +++ b/docs/interfaces/signblockparams.html @@ -1039,7 +1039,7 @@ img { max-width: 100%; }
                              hash: string
                              @@ -1054,7 +1054,7 @@ img { max-width: 100%; }
                              secretKey: string
                              diff --git a/docs/interfaces/validateworkparams.html b/docs/interfaces/validateworkparams.html index 4e54345..ae80475 100644 --- a/docs/interfaces/validateworkparams.html +++ b/docs/interfaces/validateworkparams.html @@ -1039,7 +1039,7 @@ img { max-width: 100%; }
                              blockHash: string
                              @@ -1054,7 +1054,7 @@ img { max-width: 100%; }
                              work: string
                              diff --git a/docs/interfaces/verifyblockparams.html b/docs/interfaces/verifyblockparams.html index dc1c136..c3486a4 100644 --- a/docs/interfaces/verifyblockparams.html +++ b/docs/interfaces/verifyblockparams.html @@ -1043,7 +1043,7 @@ img { max-width: 100%; }
                              hash: string
                              @@ -1058,7 +1058,7 @@ img { max-width: 100%; }
                              publicKey: string
                              @@ -1073,7 +1073,7 @@ img { max-width: 100%; }
                              signature: string
                              diff --git a/src/check.ts b/src/check.ts index 8a60126..3ce33b0 100644 --- a/src/check.ts +++ b/src/check.ts @@ -35,7 +35,7 @@ export function checkNumber(candidate: any) { * @param amount - The amount to check * @returns Valid */ -export function checkAmount(amount: any) { +export function checkAmount(amount: string) { if (!checkString(amount) || !/^[1-9]{1}[0-9]{0,38}$/.test(amount)) return false; const candidate = new BigNumber(amount); @@ -49,7 +49,7 @@ export function checkAmount(amount: any) { * @param seed - The seed to check * @returns Valid */ -export function checkSeed(seed: any) { +export function checkSeed(seed: string) { return checkString(seed) && /^[0-9a-fA-F]{64}$/.test(seed); } @@ -59,7 +59,7 @@ export function checkSeed(seed: any) { * @param hash - The hash to check * @returns Valid */ -export function checkHash(hash: any) { +export function checkHash(hash: string) { return checkSeed(hash); } @@ -69,7 +69,7 @@ export function checkHash(hash: any) { * @param key - The key to check * @returns Valid */ -export function checkKey(key: any) { +export function checkKey(key: string) { return checkSeed(key); } @@ -79,7 +79,7 @@ export function checkKey(key: any) { * @param address - The address to check * @returns Valid */ -export function checkAddress(address: any) { +export function checkAddress(address: string) { const parseResult = parseAddress(address); return parseResult.valid; @@ -91,7 +91,7 @@ export function checkAddress(address: any) { * @param work - The work to check * @returns Valid */ -export function checkWork(work: any) { +export function checkWork(work: string) { return checkString(work) && /^[0-9a-fA-F]{16}$/.test(work); } @@ -101,6 +101,6 @@ export function checkWork(work: any) { * @param signature - The signature to check * @returns Valid */ -export function checkSignature(signature: any) { +export function checkSignature(signature: string) { return checkString(signature) && /^[0-9a-fA-F]{128}$/.test(signature); }