diff --git a/gatsby-config.js b/gatsby-config.js index 550942f0..31ad03e8 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -42,7 +42,7 @@ module.exports = { // gtmPreview: "YOUR_GOOGLE_TAGMANAGER_ENVIROMENT_PREVIEW_NAME", }, }, - 'gatsby-plugin-offline', + `gatsby-plugin-remove-serviceworker`, `gatsby-plugin-styled-components`, `gatsby-plugin-sharp`, diff --git a/gatsby-node.js b/gatsby-node.js index 8654802f..771fabc5 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -41,18 +41,33 @@ exports.onCreateNode = ({ node, getNode, actions }) => { if (isDoc) { let product = 'other' + // get sdk const isBitbox = filePath.includes('/bitbox/') const isSlp = filePath.includes('/slp/') const isGui = filePath.includes('/gui/') const isRest = filePath.includes('/rest/') const isBadger = filePath.includes('/badger/') + const isCashScript = filePath.includes('/cashscript/') + + // get platform + const isJs = filePath.includes('/js/') + const isAndroid = filePath.includes('/android/') + const isiOS = filePath.includes('/ios/') if (isBitbox) { slug = `/bitbox/docs/${filename}` product = 'bitbox' } if (isSlp) { - slug = `/slp/docs/${filename}` + if (isJs) { + slug = `/slp/docs/js/${filename}` + } else if (isAndroid) { + slug = `/slp/docs/android/${filename}` + } else if (isiOS) { + slug = `/slp/docs/ios/${filename}` + } else { + slug = `/slp/docs/${filename}` + } product = 'slp' } if (isGui) { @@ -67,6 +82,10 @@ exports.onCreateNode = ({ node, getNode, actions }) => { slug = `/badger/docs/${filename}` product = 'badger' } + if (isCashScript) { + slug = `/cashscript/docs/${filename}` + product = 'cashscript' + } createNodeField({ node, diff --git a/package.json b/package.json index bdac1850..89dd1003 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "developer.bitcoin.com", "description": "Bitcoin.com developer resources and documentation", - "version": "4.0.0", + "version": "8.5.2", "author": "Peter and Gabriel Cardona ", "dependencies": { "badger-components-react": "^0.3.0", @@ -10,8 +10,8 @@ "gatsby-plugin-flow": "^1.0.2", "gatsby-plugin-google-tagmanager": "^2.0.9", "gatsby-plugin-manifest": "^2.0.19", - "gatsby-plugin-offline": "^2.0.24", "gatsby-plugin-react-helmet": "^3.0.7", + "gatsby-plugin-remove-serviceworker": "^1.0.0", "gatsby-plugin-robots-txt": "^1.4.0", "gatsby-plugin-sharp": "^2.0.22", "gatsby-plugin-sitemap": "^2.0.6", @@ -43,7 +43,7 @@ ], "license": "MIT", "engines": { - "node": ">=10.15.1" + "node": ">=10.15.3" }, "scripts": { "start": "npm run develop", diff --git a/src/components/NavBar.js b/src/components/NavBar.js index 20e0de66..e1dcb805 100644 --- a/src/components/NavBar.js +++ b/src/components/NavBar.js @@ -46,6 +46,7 @@ const developBaseUrls = [ '/slp', '/faucets', '/badger', + '/cashscript', ] const learnBaseUrls = [ '/learn', diff --git a/src/components/ShareFooter.js b/src/components/ShareFooter.js index c7e71813..b245ef40 100644 --- a/src/components/ShareFooter.js +++ b/src/components/ShareFooter.js @@ -76,9 +76,11 @@ class ShareFooter extends React.Component { om.async = true document.body.appendChild(om) - if (window.omv8lwzo6nqacmgnulutqp) { - window.omv8lwzo6nqacmgnulutqp.reset() - } + setTimeout(() => { + if (window.omv8lwzo6nqacmgnulutqp) { + window.omv8lwzo6nqacmgnulutqp.reset() + } + }, 1000) // Keep track of the script tag this.scriptTag = om diff --git a/src/components/layouts/base.css b/src/components/layouts/base.css index 7aa857c6..eb12d5b8 100644 --- a/src/components/layouts/base.css +++ b/src/components/layouts/base.css @@ -38,3 +38,11 @@ button { font-size: 18px; } } + +table { + border-spacing: 0; +} + +tr:nth-child(even) { + background-color: #f2f2f2; +} diff --git a/src/data/docs/badger/badger-button.md b/src/data/docs/badger/badger-button.md index dd925967..807e7e80 100644 --- a/src/data/docs/badger/badger-button.md +++ b/src/data/docs/badger/badger-button.md @@ -10,9 +10,9 @@ Use any button on a page to send BCH by adding the "badger-button" class and inc #### Arguments -- data-to `String` cashaddr address of BCH destination -- data-satoshis `String` BCH amount to send in satoshis -- data-success-callback `String` (Optional) Name of global scoped function to call on success +- data-to `string` cashaddr address of BCH destination +- data-satoshis `string` BCH amount to send in satoshis +- data-success-callback `string` (Optional) Name of global scoped function to call on success #### Result @@ -50,11 +50,11 @@ Use any button on a page to send tokens by adding the "badger-button" class and #### Arguments -- data-to `String` cashaddr address of BCH destination -- data-token-protocol `String` The Token protocol -- data-token-id `String` The Token Id -- data-token-amount `String` (Required) The amount of tokens to send -- data-success-callback `String` (Optional) Name of global scoped function to call on success +- data-to `string` cashaddr address of BCH destination +- data-token-protocol `string` The Token protocol +- data-token-id `string` The Token Id +- data-token-amount `string` (Required) The amount of tokens to send +- data-success-callback `string` (Optional) Name of global scoped function to call on success #### Result diff --git a/src/data/docs/badger/badger-components-react.md b/src/data/docs/badger/badger-components-react.md index c3dc35c1..dc5ba4d9 100644 --- a/src/data/docs/badger/badger-components-react.md +++ b/src/data/docs/badger/badger-components-react.md @@ -226,7 +226,7 @@ Like other components, components enhanced with BadgerBase are free to add any o ```js import React from 'react' -import { BadgerBase, formatAmount } from 'badger-react-components' +import { BadgerBase, formatAmount } from 'badger-components-react' import styled from 'styled-components' @@ -236,10 +236,10 @@ const CoolButton = styled.button` border-radius: 24px; ` -const MyButton extends React.Component { +class MyButton extends React.Component { render() { // Props from higher order component - const {handleClick, to, price, currency, amount, coinDecimals step} = this.props; + const { handleClick, to, price, currency, amount, coinDecimals, step } = this.props; return (

Donate {price}{currency} to {to}

diff --git a/src/data/docs/badger/cash-id.md b/src/data/docs/badger/cash-id.md index 6c695d16..295d689c 100644 --- a/src/data/docs/badger/cash-id.md +++ b/src/data/docs/badger/cash-id.md @@ -9,8 +9,8 @@ The specification is available on [gitlab](https://gitlab.com/cashid/protocol-sp #### Arguments -- account `String` cashaddr address of user's address -- cashIdRequest `String` Cash ID request URI +- account `string` cashaddr address of user's address +- cashIdRequest `string` Cash ID request URI - `Callback` with error parameter #### Result diff --git a/src/data/docs/badger/send-bch.md b/src/data/docs/badger/send-bch.md index 9692c0f8..2413332e 100644 --- a/src/data/docs/badger/send-bch.md +++ b/src/data/docs/badger/send-bch.md @@ -9,9 +9,9 @@ Send a specified amount of BCH to a destination address #### Arguments - txParams `Object` containing to, from, and value properties - - to `String` optional: cashaddr address of BCH destination - - from `String` cashaddr address of user's address - - value `String` optional: BCH amount to send in satoshis + - to `string` optional: cashaddr address of BCH destination + - from `string` cashaddr address of user's address + - value `string` optional: BCH amount to send in satoshis - opReturn `Object` optional: - Properties - data `Array` data to be encoded in `nulldata` output diff --git a/src/data/docs/badger/send-slp-token.md b/src/data/docs/badger/send-slp-token.md index eeb7503f..65041fec 100644 --- a/src/data/docs/badger/send-slp-token.md +++ b/src/data/docs/badger/send-slp-token.md @@ -9,13 +9,13 @@ Send a specified amount of an SLP token to a destination address #### Arguments - txParams `Object` containing to, from, value and sendTokenData properties - - to `String` cashaddr address of token destination - - from `String` cashaddr address of user's address - - value `String` token amount to send + - to `string` cashaddr address of token destination + - from `string` cashaddr address of user's address + - value `string` token amount to send - sendTokenData `Object` containing tokenId and tokenProtocol properties - - tokenId `String` id of token + - tokenId `string` id of token - _Simple Ledger_: The txid of the geneis transaction - - tokenProtocol `String` protocol of the token + - tokenProtocol `string` protocol of the token - `slp` for Simple Ledger Protocol tokens - `Callback` with error and response parameters diff --git a/src/data/docs/bitbox/OpCodes.md b/src/data/docs/bitbox/OpCodes.md new file mode 100644 index 00000000..d0ed1e30 --- /dev/null +++ b/src/data/docs/bitbox/OpCodes.md @@ -0,0 +1,182 @@ +--- +title: OpCodes +icon: code +ordinal: 15 +--- + +Bitcoin Cash Script OP Codes are available on the `bitbox.Script` object. + +#### Examples + + // list all op codes + bitbox.Script.opcodes; + // { OP_FALSE: 0, + // OP_0: 0, + // OP_PUSHDATA1: 76, + // OP_PUSHDATA2: 77, + // OP_PUSHDATA4: 78, + // OP_1NEGATE: 79, + // OP_RESERVED: 80, + // OP_TRUE: 81, + // OP_1: 81, + // OP_2: 82, + // OP_3: 83, + // OP_4: 84, + // ... + // } + + // get the op code for a word + bitbox.Script.opcodes.OP_SPLIT + // 127 + bitbox.Script.opcodes.OP_NUM2BIN + // 128 + bitbox.Script.opcodes.OP_BIN2NUM + // 129 + +### Constants + +| Word | Opcode | Hex | Inputs | Outputs | Description | +| ------------ | ------ | --------- | --------- | ------------- | ------------------------------------------------------------------------------------------------------- | +| OP_0 | 0 | 0x00 | Nothing | (empty value) | An empty array of bytes is pushed onto the stack. (This is not a no-op: an item is added to the stack.) | +| OP_FALSE | 0 | 0x00 | Nothing | (empty value) | An empty array of bytes is pushed onto the stack. (This is not a no-op: an item is added to the stack.) | +| N/A | 1-75 | 0x01-0x4b | (special) | data | The next opcode bytes is data to be pushed onto the stack | +| OP_PUSHDATA1 | 76 | 0x4c | (special) | data | The next byte contains the number of bytes to be pushed onto the stack. | +| OP_PUSHDATA2 | 77 | 0x4d | (special) | data | The next two bytes contain the number of bytes to be pushed onto the stack in little endian order. | +| OP_PUSHDATA4 | 78 | 0x4e | (special) | data | The next four bytes contain the number of bytes to be pushed onto the stack in little endian order. | +| OP_1NEGATE | 79 | 0x4f | Nothing. | -1 | The number -1 is pushed onto the stack. | +| OP_TRUE | 81 | 0x51 | Nothing. | | The number 1 is pushed onto the stack. | +| OP_1 | 81 | 0x51 | Nothing. | | The number 1 is pushed onto the stack. | +| OP_2-OP_16 | 82-96 | 0x52-0x60 | Nothing. | 2-16 | The number in the word name (2-16) is pushed onto the stack. | + +### Flow control + +| Word | Opcode | Hex | Inputs | Outputs | Description | +| --------- | ------ | ---- | --------------------------------------------------------- | --------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| OP_NOP | 97 | 0x61 | Nothing | Nothing | Does nothing. | +| OP_IF | 99 | 0x63 | if [statements]else [statements]]\* endif | if [statements]else [statements]]\* endif | If the top stack value is not False, the statements are executed. The top stack value is removed. | +| OP_NOTIF | 100 | 0x64 | notif [statements]else [statements]]\* endif | notif [statements]else [statements]]\* endif | If the top stack value is False, the statements are executed. The top stack value is removed. | +| OP_ELSE | 103 | 0x67 | if [statements]else [statements]]\* endif | if [statements]else [statements]]\* endif | If the preceding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. | +| OP_ENDIF | 104 | 0x68 | if [statements]else [statements]]\* endif | if [statements]else [statements]]\* endif | Ends an if/else block. All blocks must end, or the transaction is invalid. An OP_ENDIF without OP_IF earlier is also invalid. | +| OP_VERIFY | 105 | 0x69 | True / false | Nothing / fail | Marks transaction as invalid if top stack value is not true. The top stack value is removed. | +| OP_RETURN | 106 | 0x6a | Nothing | fail | Marks transaction as invalid. | + +### Stack + +| Word | Opcode | Hex | Inputs | Outputs | Description | +| --------------- | ------ | ---- | ------------------- | ------------------ | -------------------------------------------------------------------------------------- | +| OP_TOALTSTACK | 107 | 0x6b | x1 | (alt)x1 | Puts the input onto the top of the alt stack. Removes it from the main stack. | +| OP_FROMALTSTACK | 108 | 0x6c | (alt)x1 | x1 | Puts the input onto the top of the main stack. Removes it from the alt stack. | +| OP_IFDUP | 115 | 0x73 | x | x / x x | If the top stack value is not 0, duplicate it. | +| OP_DEPTH | 116 | 0x74 | Nothing | | Puts the number of stack items onto the stack. | +| OP_DROP | 117 | 0x75 | x | Nothing | Removes the top stack item. | +| OP_DUP | 118 | 0x76 | x | x x | Duplicates the top stack item. | +| OP_NIP | 119 | 0x77 | x1 x2 | x2 | Removes the second-to-top stack item. | +| OP_OVER | 120 | 0x78 | x1 x2 | x1 x2 x1 | Copies the second-to-top stack item to the top. | +| OP_PICK | 121 | 0x79 | xn ... x2 x1 x0 | xn ... x2 x1 x0 xn | The item n back in the stack is copied to the top. | +| OP_ROLL | 122 | 0x7a | xn ... x2 x1 x0 | ... x2 x1 x0 xn | The item n back in the stack is moved to the top. | +| OP_ROT | 123 | 0x7b | x1 x2 x3 | x2 x3 x1 | The top three items on the stack are rotated to the left. | +| OP_SWAP | 124 | 0x7c | x1 x2 | x2 x1 | The top two items on the stack are swapped. | +| OP_TUCK | 125 | 0x7d | x1 x2 | x2 x1 x2 | The item at the top of the stack is copied and inserted before the second-to-top item. | +| OP_2DROP | 109 | 0x6d | x1 x2 | Nothing | Removes the top two stack items. | +| OP_2DUP | 110 | 0x6e | x1 x2 | x1 x2 x1 x2 | Duplicates the top two stack items. | +| OP_3DUP | 111 | 0x6f | x1 x2 x3 | x1 x2 x3 x1 x2 x3 | Duplicates the top three stack items. | +| OP_2OVER | 112 | 0x70 | x1 x2 x3 x4 | x1 x2 x3 x4 x1 x2 | Copies the pair of items two spaces back in the stack to the front. | +| OP_2ROT | 113 | 0x71 | x1 x2 x3 x4 x5 x6 | x3 x4 x5 x6 x1 x2 | The fifth and sixth items back are moved to the top of the stack. | +| OP_2SWAP | 114 | 0x72 | x1 x2 x3 x4 | x3 x4 x1 x2 | Swaps the top two pairs of items. | + +### Splice + +| Word | Opcode | Hex | Inputs | Outputs | Description | +| --------- | ------ | ---- | ------------- | ------- | ------------------------------------------------------------------------------ | +| OP_CAT | 126 | 0x7e | x1 x2 | out | Concatenates two strings | +| OP_SUBSTR | 127 | 0x7f | in begin size | out | Returns a section of a string | +| OP_LEFT | 128 | 0x80 | in size | out | Keeps only characters left of the specified point in a string. | +| OP_RIGHT | 129 | 0x81 | in size | out | Keeps only characters right of the specified point in a string. | +| OP_SIZE | 130 | 0x82 | in | in size | Pushes the string length of the top element of the stack (without popping it). | + +### Bitwise logic + +| Word | Opcode | Hex | Inputs | Outputs | Description | +| -------------- | ------ | ---- | ------ | -------------- | ------------------------------------------------------- | +| OP_INVERT | 131 | 0x83 | in | out | Flips all of the bits in the input. | +| OP_AND | 132 | 0x84 | x1 x2 | out | Boolean and between each bit in the inputs. | +| OP_OR | 133 | 0x85 | x1 x2 | out | Boolean or between each bit in the inputs. | +| OP_XOR | 134 | 0x86 | x1 x2 | out | Boolean exclusive or between each bit in the inputs. | +| OP_EQUAL | 135 | 0x87 | x1 x2 | True / false | Returns 1 if the inputs are exactly equal, 0 otherwise. | +| OP_EQUALVERIFY | 136 | 0x88 | x1 x2 | Nothing / fail | Same as OP_EQUAL, but runs OP_VERIFY afterward. | + +### Arithmetic + +| Word | Opcode | Hex | Inputs | Outputs | Description | +| --------------------- | ------ | ---- | --------- | -------------- | --------------------------------------------------------------------------- | +| OP_1ADD | 139 | 0x8b | in | out | 1 is added to the input. | +| OP_1SUB | 140 | 0x8c | in | out | 1 is subtracted from the input. | +| OP_2MUL | 141 | 0x8d | in | out | The input is multiplied by 2. | +| OP_2DIV | 142 | 0x8e | in | out | The input is divided by 2. | +| OP_NEGATE | 143 | 0x8f | in | out | The sign of the input is flipped. | +| OP_ABS | 144 | 0x90 | in | out | The input is made positive. | +| OP_NOT | 145 | 0x91 | in | out | If the input is 0 or 1, it is flipped. Otherwise the output will be 0. | +| OP_0NOTEQUAL | 146 | 0x92 | in | out | Returns 0 if the input is 0. 1 otherwise. | +| OP_ADD | 147 | 0x93 | a b | out | a is added to b. | +| OP_SUB | 148 | 0x94 | a b | out | b is subtracted from a. | +| OP_MUL | 149 | 0x95 | a b | out | a is multiplied by b. | +| OP_DIV | 150 | 0x96 | a b | out | a is divided by b. | +| OP_MOD | 151 | 0x97 | a b | out | Returns the remainder after dividing a by b. | +| OP_LSHIFT | 152 | 0x98 | a b | out | Shifts a left b bits, preserving sign. | +| OP_RSHIFT | 153 | 0x99 | a b | out | Shifts a right b bits, preserving sign. | +| OP_BOOLAND | 154 | 0x9a | a b | out | If both a and b are not "" (null string), the output is 1. Otherwise 0. | +| OP_BOOLOR | 155 | 0x9b | a b | out | If a or b is not "" (null string), the output is 1. Otherwise 0. | +| OP_NUMEQUAL | 156 | 0x9c | a b | out | Returns 1 if the numbers are equal, 0 otherwise. | +| OP_NUMEQUALVERIFY | 157 | 0x9d | a b | Nothing / fail | Same as OP_NUMEQUAL, but runs OP_VERIFY afterward. | +| OP_NUMNOTEQUAL | 158 | 0x9e | a b | out | Returns 1 if the numbers are not equal, 0 otherwise. | +| OP_LESSTHAN | 159 | 0x9f | a b | out | Returns 1 if a is less than b, 0 otherwise. | +| OP_GREATERTHAN | 160 | 0xa0 | a b | out | Returns 1 if a is greater than b, 0 otherwise. | +| OP_LESSTHANOREQUAL | 161 | 0xa1 | a b | out | Returns 1 if a is less than or equal to b, 0 otherwise. | +| OP_GREATERTHANOREQUAL | 162 | 0xa2 | a b | out | Returns 1 if a is greater than or equal to b, 0 otherwise. | +| OP_MIN | 163 | 0xa3 | a b | out | Returns the smaller of a and b. | +| OP_MAX | 164 | 0xa4 | a b | out | Returns the larger of a and b. | +| OP_WITHIN | 165 | 0xa5 | x min max | out | Returns 1 if x is within the specified range (left-inclusive), 0 otherwise. | + +### Crypto + +| Word | Opcode | Hex | Inputs | Outputs | Description | +| ---------------------- | ------ | ---- | ---------------------------------------------------------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| OP_RIPEMD160 | 166 | 0xa6 | in | hash | The input is hashed using RIPEMD-160. | +| OP_SHA1 | 167 | 0xa7 | in | hash | The input is hashed using SHA-1. | +| OP_SHA256 | 168 | 0xa8 | in | hash | The input is hashed using SHA-256. | +| OP_HASH160 | 169 | 0xa9 | in | hash | The input is hashed twice: first with SHA-256 and then with RIPEMD-160. | +| OP_HASH256 | 170 | 0xaa | in | hash | The input is hashed two times with SHA-256. | +| OP_CODESEPARATOR | 171 | 0xab | Nothing | Nothing | All of the signature checking words will only match signatures to the data after the most recently-executed OP_CODESEPARATOR. | +| OP_CHECKSIG | 172 | 0xac | sig pubkey | True / false | The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for this hash and public key. If it is, 1 is returned, 0 otherwise. | +| OP_CHECKSIGVERIFY | 173 | 0xad | sig pubkey | Nothing / fail | Same as OP_CHECKSIG, but OP_VERIFY is executed afterward. | +| OP_CHECKMULTISIG | 174 | 0xae | x sig1 sig2 ... pub1 pub2 | True / False | Compares the first signature against each public key until it finds an ECDSA match. Starting with the subsequent public key, it compares the second signature against each remaining public key until it finds an ECDSA match. The process is repeated until all signatures have been checked or not enough public keys remain to produce a successful result. All signatures need to match a public key. Because public keys are not checked again if they fail any signature comparison, signatures must be placed in the scriptSig using the same order as their corresponding public keys were placed in the scriptPubKey or redeemScript. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack. | +| OP_CHECKMULTISIGVERIFY | 175 | 0xaf | x sig1 sig2 ... pub1 pub2 ... | Nothing / fail | Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward. | + +### Locktime + +| Word | Opcode | Hex | Inputs | Outputs | Description | +| ---------------------- | ------ | ---- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| OP_CHECKLOCKTIMEVERIFY | 177 | 0xb1 | x | x / fail | Marks transaction as invalid if the top stack item is greater than the transaction's nLockTime field, otherwise script evaluation continues as though an OP_NOP was executed. Transaction is also invalid if 1. the stack is empty; or 2. the top stack item is negative; or 3. the top stack item is greater than or equal to 500000000 while the transaction's nLockTime field is less than 500000000, or vice versa; or 4. the input's nSequence field is equal to 0xffffffff. The precise semantics are described in BIP 0065. | +| OP_CHECKSEQUENCEVERIFY | 178 | 0xb2 | x | x / fail | Marks transaction as invalid if the relative lock time of the input (enforced by BIP 0068 with nSequence) is not equal to or longer than the value of the top stack item. The precise semantics are described in BIP 0112. | + +### Pseudo-words + +| Word | Opcode | Hex | Description | +| ---------------- | ------ | ---- | ---------------------------------------------------- | +| OP_PUBKEYHASH | 253 | 0xfd | Represents a public key hashed with OP_HASH160. | +| OP_PUBKEY | 254 | 0xfe | Represents a public key compatible with OP_CHECKSIG. | +| OP_INVALIDOPCODE | 255 | 0xff | Matches any opcode that is not yet assigned. | + +### Reserved words + +| Word | Opcode | Hex | When Used | +| ------------ | ------ | ---- | ----------------------------------------------------------------------- | +| OP_RESERVED | 80 | 0x50 | Transaction is invalid unless occuring in an unexecuted OP_IF branch | +| OP_VER | 98 | 0x62 | Transaction is invalid unless occuring in an unexecuted OP_IF branch | +| OP_VERIF | 101 | 0x65 | Transaction is invalid even when occuring in an unexecuted OP_IF branch | +| OP_VERNOTIF | 102 | 0x66 | Transaction is invalid even when occuring in an unexecuted OP_IF branch | +| OP_RESERVED1 | 137 | 0x89 | Transaction is invalid unless occuring in an unexecuted OP_IF branch | +| OP_RESERVED2 | 138 | 0x8a | Transaction is invalid unless occuring in an unexecuted OP_IF branch | +| OP_NOP1 | 176 | 0xb0 | The word is ignored. Does not mark transaction as invalid. | +| OP_NOP4 | 179 | 0xb3 | The word is ignored. Does not mark transaction as invalid. | +| OP_NOP10 | 185 | 0xb9 | The word is ignored. Does not mark transaction as invalid. | diff --git a/src/data/docs/bitbox/address.md b/src/data/docs/bitbox/address.md index 887130b2..7f1c485a 100644 --- a/src/data/docs/bitbox/address.md +++ b/src/data/docs/bitbox/address.md @@ -10,28 +10,28 @@ Converting cashaddr to legacy address format #### Arguments -1. address `String` cashaddr address to be converted +1. address `string` cashaddr address to be converted #### Result -legacyAddress `String` legacy base 58 check encoded address +legacyAddress `string` legacy base 58 check encoded address #### Examples // mainnet w/ prefix - BITBOX.Address.toLegacyAddress('bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') + bitbox.Address.toLegacyAddress('bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') // 1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN // mainnet w/ no prefix - BITBOX.Address.toLegacyAddress('qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') + bitbox.Address.toLegacyAddress('qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') // 1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN // testnet w/ prefix - BITBOX.Address.toLegacyAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.toLegacyAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // mqc1tmwY2368LLGktnePzEyPAsgADxbksi // testnet w/ no prefix - BITBOX.Address.toLegacyAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.toLegacyAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // mqc1tmwY2368LLGktnePzEyPAsgADxbksi ### `toCashAddress` @@ -40,30 +40,30 @@ Converting legacy to cashAddress format #### Arguments -1. address `String` required: legacy address to be converted -2. prefix `Boolean` optional: include prefix -3. regtest `Boolean` optional: return regtest address +1. address `string` required: legacy address to be converted +2. prefix `boolean` optional: include prefix +3. regtest `boolean` optional: return regtest address #### Result -cashAddress `String` cashAddr encoded address +cashAddress `string` cashAddr encoded address #### Examples // mainnet - BITBOX.Address.toCashAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN') + bitbox.Address.toCashAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN') // bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl // mainnet no prefix - BITBOX.Address.toCashAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN', false) + bitbox.Address.toCashAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN', false) // qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl // tesnet - BITBOX.Address.toCashAddress('msDbtTj7kWXPpYaR7PQmMK84i66fJqQMLx') + bitbox.Address.toCashAddress('msDbtTj7kWXPpYaR7PQmMK84i66fJqQMLx') // bchtest:qzq9je6pntpva3wf6scr7mlnycr54sjgeqxgrr9ku3 // testnet no prefix - BITBOX.Address.toCashAddress('msDbtTj7kWXPpYaR7PQmMK84i66fJqQMLx', false) + bitbox.Address.toCashAddress('msDbtTj7kWXPpYaR7PQmMK84i66fJqQMLx', false) // qzq9je6pntpva3wf6scr7mlnycr54sjgeqxgrr9ku3 ### `isLegacyAddress` @@ -72,36 +72,36 @@ Detect if legacy base58check encoded address #### Arguments -1. address `String`: address to determine +1. address `string`: address to determine #### Result -isLegacyAddress `Boolean`: true/false if legacy address +isLegacyAddress `boolean`: true/false if legacy address #### Examples // cashaddr - BITBOX.Address.isLegacyAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isLegacyAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // false // w/ no cashaddr prefix - BITBOX.Address.isLegacyAddress('qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') + bitbox.Address.isLegacyAddress('qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') // false // legacy - BITBOX.Address.isLegacyAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN') + bitbox.Address.isLegacyAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN') // true // testnet w/ cashaddr prefix - BITBOX.Address.isLegacyAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isLegacyAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // false // testnet w/ no cashaddr prefix - BITBOX.Address.isLegacyAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isLegacyAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // false // legacy testnet - BITBOX.Address.isLegacyAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') + bitbox.Address.isLegacyAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') // true ### `isCashAddress` @@ -110,36 +110,36 @@ Detect if cashAddr encoded address #### Arguments -1. address `String`: address to determine +1. address `string`: address to determine #### Result -isCashAddress `Boolean`: true/false if cashaddress +isCashAddress `boolean`: true/false if cashaddress #### Examples // mainnet cashaddr - BITBOX.Address.isCashAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isCashAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // true // mainnet w/ no cashaddr prefix - BITBOX.Address.isCashAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isCashAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // true // mainnet legacy - BITBOX.Address.isCashAddress('18HEMuar5ZhXDFep1gEiY1eoPPcBLxfDxj') + bitbox.Address.isCashAddress('18HEMuar5ZhXDFep1gEiY1eoPPcBLxfDxj') // false // testnet w/ cashaddr prefix - BITBOX.Address.isCashAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isCashAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // true // testnet w/ no cashaddr prefix - BITBOX.Address.isCashAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isCashAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // true // testnet legacy - BITBOX.Address.isCashAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') + bitbox.Address.isCashAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') // false ### `isMainnetAddress` @@ -148,36 +148,36 @@ Detect if mainnet address #### Arguments -1. address `String`: address to determine +1. address `string`: address to determine #### Result -isMainnetAddress `Boolean`: true/false if mainnet address +isMainnetAddress `boolean`: true/false if mainnet address #### Examples // mainnet cashaddr - BITBOX.Address.isMainnetAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isMainnetAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // true // mainnet cashaddr w/ no prefix - BITBOX.Address.isMainnetAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isMainnetAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // true // mainnet legacy - BITBOX.Address.isMainnetAddress('14krEkSaKoTkbFT9iUCfUYARo4EXA8co6M') + bitbox.Address.isMainnetAddress('14krEkSaKoTkbFT9iUCfUYARo4EXA8co6M') // true // testnet cashaddr - BITBOX.Address.isMainnetAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isMainnetAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // false // testnet w/ no cashaddr prefix - BITBOX.Address.isMainnetAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isMainnetAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // false // testnet legacy - BITBOX.Address.isMainnetAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') + bitbox.Address.isMainnetAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') // false ### `isTestnetAddress` @@ -186,74 +186,116 @@ Detect if testnet address #### Arguments -1. addresss `String`: address to determine +1. addresss `string`: address to determine #### Result -isTestnetAddresss `Boolean`: true/false if is testnet address +isTestnetAddresss `boolean`: true/false if is testnet address #### Examples // cashaddr mainnet - BITBOX.Address.isTestnetAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isTestnetAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') //false // w/ no cashaddr prefix - BITBOX.Address.isTestnetAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isTestnetAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // false // legacy mainnet - BITBOX.Address.isTestnetAddress('14krEkSaKoTkbFT9iUCfUYARo4EXA8co6M') + bitbox.Address.isTestnetAddress('14krEkSaKoTkbFT9iUCfUYARo4EXA8co6M') // false // cashaddr testnet - BITBOX.Address.isTestnetAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isTestnetAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // true // testnet w/ no cashaddr prefix - BITBOX.Address.isTestnetAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isTestnetAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // true // testnet legacy - BITBOX.Address.isTestnetAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') + bitbox.Address.isTestnetAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') // true +### `isRegTestAddress` + +Detect if regtest address + +#### Arguments + +1. addresss `string`: address to determine + +#### Result + +isRegtestAddresss `boolean`: true/false if is regtest address + +#### Examples + + // regtest + bitbox.Address.isRegTestAddress('bchreg:qzq9je6pntpva3wf6scr7mlnycr54sjgequ54zx9lh') + // true + + // regtest w/ no prefix + bitbox.Address.isRegTestAddress('qzq9je6pntpva3wf6scr7mlnycr54sjgequ54zx9lh') + // true + + // cashaddr mainnet + bitbox.Address.isRegTestAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + //false + + // w/ no cashaddr prefix + bitbox.Address.isRegTestAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + // false + + // legacy mainnet + bitbox.Address.isRegTestAddress('14krEkSaKoTkbFT9iUCfUYARo4EXA8co6M') + // false + + // cashaddr testnet + bitbox.Address.isRegTestAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + // false + + // testnet w/ no cashaddr prefix + bitbox.Address.isRegTestAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + // false + ### `isP2PKHAddress` Detect if p2pkh address #### Arguments -1. address `String` address to determine +1. address `string` address to determine #### Result -isP2PKHAddress `Boolean` true/false if is p2pkh address +isP2PKHAddress `boolean` true/false if is p2pkh address #### Examples // cashaddr - BITBOX.Address.isP2PKHAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isP2PKHAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // true // w/ no cashaddr prefix - BITBOX.Address.isP2PKHAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isP2PKHAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // true // legacy - BITBOX.Address.isP2PKHAddress('14krEkSaKoTkbFT9iUCfUYARo4EXA8co6M') + bitbox.Address.isP2PKHAddress('14krEkSaKoTkbFT9iUCfUYARo4EXA8co6M') // true // legacy testnet - BITBOX.Address.isP2PKHAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') + bitbox.Address.isP2PKHAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') // true // testnet w/ no cashaddr prefix - BITBOX.Address.isP2PKHAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isP2PKHAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // true // legacy testnet - BITBOX.Address.isP2PKHAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') + bitbox.Address.isP2PKHAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') // true ### `isP2SHAddress` @@ -262,36 +304,36 @@ Detect if p2sh address #### arguments -1. address `String` address to determine +1. address `string` address to determine #### Result -isP2SHAddress `Boolean` true/false if is p2sh address +isP2SHAddress `boolean` true/false if is p2sh address #### Examples // cashaddr - BITBOX.Address.isP2SHAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isP2SHAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // false // cashaddr w/ no prefix - BITBOX.Address.isP2SHAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.isP2SHAddress('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // false // legacy - BITBOX.Address.isP2SHAddress('1NoYQso5UF6XqC4NbjKAp2EnjJ59yLNn74') + bitbox.Address.isP2SHAddress('1NoYQso5UF6XqC4NbjKAp2EnjJ59yLNn74') // false // cashaddr testnet - BITBOX.Address.isP2SHAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isP2SHAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // false // cashaddr testnet w/ no prefix - BITBOX.Address.isP2SHAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.isP2SHAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // false // legacy testnet - BITBOX.Address.isP2SHAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') + bitbox.Address.isP2SHAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') // false ### `detectAddressFormat` @@ -300,36 +342,36 @@ Detect address format #### arguments -1. address `String` address to determine format +1. address `string` address to determine format #### Result -addressFormat `String` address format +addressFormat `string` address format #### Examples // cashaddr - BITBOX.Address.detectAddressFormat('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.detectAddressFormat('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // cashaddr // cashaddr w/ no prefix - BITBOX.Address.detectAddressFormat('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.detectAddressFormat('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // cashaddr // legacy - BITBOX.Address.detectAddressFormat('1NoYQso5UF6XqC4NbjKAp2EnjJ59yLNn74') + bitbox.Address.detectAddressFormat('1NoYQso5UF6XqC4NbjKAp2EnjJ59yLNn74') // legacy // cashaddr testnet - BITBOX.Address.detectAddressFormat('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.detectAddressFormat('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // cashaddr // cashaddr testnet w/ no prefix - BITBOX.Address.detectAddressFormat('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.detectAddressFormat('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // cashaddr // legacy testnet - BITBOX.Address.detectAddressFormat('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') + bitbox.Address.detectAddressFormat('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') // legacy ### `detectAddressNetwork` @@ -338,36 +380,36 @@ Detect address network #### arguments -1. address `String` address to determine network +1. address `string` address to determine network #### Result -addressNetwork `String` address network +addressNetwork `string` address network #### Examples // cashaddr - BITBOX.Address.detectAddressNetwork('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.detectAddressNetwork('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // mainnet // cashaddr w/ no prefix - BITBOX.Address.detectAddressNetwork('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') + bitbox.Address.detectAddressNetwork('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // mainnet // legacy - BITBOX.Address.detectAddressNetwork('1NoYQso5UF6XqC4NbjKAp2EnjJ59yLNn74') + bitbox.Address.detectAddressNetwork('1NoYQso5UF6XqC4NbjKAp2EnjJ59yLNn74') // mainnet // cashaddr testnet - BITBOX.Address.detectAddressNetwork('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.detectAddressNetwork('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // testnet // cashaddr testnet w/ no prefix - BITBOX.Address.detectAddressNetwork('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') + bitbox.Address.detectAddressNetwork('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // testnet // legacy testnet - BITBOX.Address.detectAddressNetwork('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') + bitbox.Address.detectAddressNetwork('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') // testnet ### `detectAddressType` @@ -376,36 +418,36 @@ Detect address network #### arguments -1. address `String` address to determine network +1. address `string` address to determine network #### Result -addressNetwork `String` address network +addressNetwork `string` address network #### Examples // cashaddr - BITBOX.Address.detectAddressType('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s'); + bitbox.Address.detectAddressType('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s'); // p2pkh // cashaddr w/ no prefix - BITBOX.Address.detectAddressType('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s'); + bitbox.Address.detectAddressType('qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s'); // p2pkh // legacy - BITBOX.Address.detectAddressType('1NoYQso5UF6XqC4NbjKAp2EnjJ59yLNn74'); + bitbox.Address.detectAddressType('1NoYQso5UF6XqC4NbjKAp2EnjJ59yLNn74'); // p2pkh // cashaddr testnet - BITBOX.Address.detectAddressType('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy'); + bitbox.Address.detectAddressType('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy'); // p2pkh // cashaddr testnet w/ no prefix - BITBOX.Address.detectAddressType('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy'); + bitbox.Address.detectAddressType('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy'); // p2pkh // legacy testnet - BITBOX.Address.detectAddressType('mqc1tmwY2368LLGktnePzEyPAsgADxbksi'); + bitbox.Address.detectAddressType('mqc1tmwY2368LLGktnePzEyPAsgADxbksi'); // p2pkh ### `fromXPub` @@ -414,19 +456,19 @@ Generates an address for an extended public key (xpub) #### Arguments -1. xpub `String`: extended public key to be used -2. path `String` `optional`: derivation path of external change address. Default is `0/0` +1. xpub `string`: extended public key to be used +2. path `string` **optional**: derivation path of external change address. Default is `0/0` #### Result -changeAddress `String`: cashaddr encoded change address +changeAddress `string`: cashaddr encoded change address #### Examples - // generate 5 external change addresses for xpub6DTNmB7gWa8RtQAfmy8wSDikM5mky4fhsnqQd9AqoCaLcekqNgRZW5JCSXwXkLDkABHTD1qx7kqrbGzT6xBGfAvCJSj2rwvKWP8eZBR2EVA + // generate 5 mainnet external change addresses for xpub6DTNmB7gWa8RtQAfmy8wSDikM5mky4fhsnqQd9AqoCaLcekqNgRZW5JCSXwXkLDkABHTD1qx7kqrbGzT6xBGfAvCJSj2rwvKWP8eZBR2EVA let xpub = 'xpub6DTNmB7gWa8RtQAfmy8wSDikM5mky4fhsnqQd9AqoCaLcekqNgRZW5JCSXwXkLDkABHTD1qx7kqrbGzT6xBGfAvCJSj2rwvKWP8eZBR2EVA'; for(let i = 0; i <= 4; i++) { - BITBOX.Address.fromXPub(xpub, "0/" + i) + console.log(bitbox.Address.fromXPub(xpub, "0/" + i)) } // bitcoincash:qptnmya5wkly7xf97wm5ak23yqdsz3l2cyj7k9vyyh // bitcoincash:qrr2suh9yjsrkl2qp3p967uhfg6u0r6xxsn9h5vuvr @@ -434,49 +476,53 @@ changeAddress `String`: cashaddr encoded change address // bitcoincash:qppgmuuwy07g0x39sx2z0x2u8e34tvfdxvy0c2jvx7 // bitcoincash:qryj8x4s7vfsc864jm0xaak9qfe8qgk245y9ska57l - // generate 5 external change addresses for xpub6DLXtM9JjvtUTm6TngeSXZdeKfFqA1sLYoFQMTTXYYbwDw55eTy7uhconrzw8mW1zzmpMBYpQLpBPzRdSn9Hxrse5TTnpdtcoeXahkC6bPd - let xpub = 'xpub6DLXtM9JjvtUTm6TngeSXZdeKfFqA1sLYoFQMTTXYYbwDw55eTy7uhconrzw8mW1zzmpMBYpQLpBPzRdSn9Hxrse5TTnpdtcoeXahkC6bPd'; - for(let i = 0; i <= 4; i++) { - BITBOX.Address.fromXPub(xpub, "0/" + i) - } - // bitcoincash:qpm05nr0fmxmyhlz0qermkad0zvsfsqu6ckv6e5tzr - // bitcoincash:qre28yd5msvsenn9qj5fwm3k3u00dty4ac739zhw2k - // bitcoincash:qp0utfskvcnsy2whkurk25x247jcdmexqyekzury66 - // bitcoincash:qqzjwx6zdvhkwalzvnaprwk73me9szqvgspgu6shst - // bitcoincash:qzpcg6atgg36vrkwvklw9325nqzdcxd8c5dl5l6k79 - - // generate 5 external change addresses for xpub6DLXtM9JjvtUV1i6tBdQ6RCwYHoUjzK2GL1BmXf4TW8QbFGWueMJrwRUsZntEUBfpqJACiid1PEPNbDVTRZxyGKp5k8KsHVg27nDR1Makdh - let xpub = 'xpub6DLXtM9JjvtUV1i6tBdQ6RCwYHoUjzK2GL1BmXf4TW8QbFGWueMJrwRUsZntEUBfpqJACiid1PEPNbDVTRZxyGKp5k8KsHVg27nDR1Makdh'; + // generate 5 testnet external change addresses for tpubDCrnMSKwDMAbxg82yqDt97peMvftCXk3EfBb9WgZh27mPbHGkysU3TW7qX5AwydmnVQfaGeNhUR6okQ3dS5AJTP9gEP7jk2Wcj6Xntc6gNh + let xpub = 'tpubDCrnMSKwDMAbxg82yqDt97peMvftCXk3EfBb9WgZh27mPbHGkysU3TW7qX5AwydmnVQfaGeNhUR6okQ3dS5AJTP9gEP7jk2Wcj6Xntc6gNh'; for(let i = 0; i <= 4; i++) { - BITBOX.Address.fromXPub(xpub, "0/" + i) + console.log(bitbox.Address.fromXPub(xpub, "0/" + i)) } - // bitcoincash:qrykz97x24tgz9nq29yyqcc98nqj8k2n45jg57manf - // bitcoincash:qp8e7rrajx3wscqr6zfu3mvnlkmt0s4dhqldpqscym - // bitcoincash:qrw6fhr6nl5lh9srh9a9sr890r3zzsgt7sqh7tkyve - // bitcoincash:qqj9ctz9sex3xjapgm8hv5dkpfmf7aalrs2z2jprm2 - // bitcoincash:qzytws9yvyqgsx3smfyy3yaq5xw9jt0xsy7kpnqpth - - // generate 5 external change addresses for xpub6DLXtM9JjvtUa9tPGP5kYXnGGeo3dnBuhUZP7QmE97hKxM1EizDgFZgVe8M5Nv49z5ytpAnwwNcc16wChnecpj3KyFPkufbi9uZaj5ALCGm - let xpub = 'xpub6DLXtM9JjvtUa9tPGP5kYXnGGeo3dnBuhUZP7QmE97hKxM1EizDgFZgVe8M5Nv49z5ytpAnwwNcc16wChnecpj3KyFPkufbi9uZaj5ALCGm'; + // bchtest:qrth8470sc9scek9u0jj2d0349t62gxzdstw2jukl8 + // bchtest:qpm56zc5re0nhms96r7p985aajthp0vxvg6e4ux3kc + // bchtest:qqtu3tf6yyd73ejhk3a2ylqynpl3mzzhwuzt299jfd + // bchtest:qzd7dvlnfukggjqsf5ju0qqwwltakfumjsck33js6m + // bchtest:qq322ataqeas4n0pdn4gz2sdereh5ae43ylk4qdvus + +### `fromXPriv` + +Generates an address for an extended private key (xpriv) + +#### Arguments + +1. xpriv `string`: extended private key to be used +2. path `string` **optional**: derivation path of change address. Default is `0'/0` + +#### Result + +changeAddress `string`: cashaddr encoded change address + +#### Examples + + // generate 5 mainnet addresses for xprvA2WwD9mk1Qd3rMjQ4ZRHvCWCj47jbXjY9Nf7npNRBmGUJngpRAvJzNpNgt7h2dDQ5huG7yFwYfz4PFJDPzkqfvBNPHnaio4yAbbUuv3EBnL + let xpriv = 'xprvA2WwD9mk1Qd3rMjQ4ZRHvCWCj47jbXjY9Nf7npNRBmGUJngpRAvJzNpNgt7h2dDQ5huG7yFwYfz4PFJDPzkqfvBNPHnaio4yAbbUuv3EBnL'; for(let i = 0; i <= 4; i++) { - BITBOX.Address.fromXPub(xpub, "0/" + i) + console.log(bitbox.Address.fromXPriv(xpriv, "0'/" + i)) } - // bitcoincash:qp9e7kd6pgy7pek2vemfspm6vc544xzm2yjfezst3q - // bitcoincash:qqt9g8ggmd5kxccvuye0nv7enj6syqqxyymnrhgkep - // bitcoincash:qqr8qf8qj7yxgtaydkt5xp0lw4fnu56jmy7q5k9sat - // bitcoincash:qzaf69rhsnzfjtg0ydw2qlqeyhpnsfzz4ghr5jkrzy - // bitcoincash:qrwjhc0dujvjtrl0e0zc8tkhwxfvljvamc6e0kcj3w - - // generate 5 external change addresses for xpub6DLXtM9JjvtUkiaWLnfiSHjW51vspUW7GDmkML17w2qoEeGztYYSmotgXJpwmoNCc6QbdCXWySEWki7jURV46hmN6MXwem1aNo3gxhkjJPj - let xpub = 'xpub6DLXtM9JjvtUkiaWLnfiSHjW51vspUW7GDmkML17w2qoEeGztYYSmotgXJpwmoNCc6QbdCXWySEWki7jURV46hmN6MXwem1aNo3gxhkjJPj'; + // bitcoincash:qpmcs78tpfvfphhedcczydaddu5wmcx0xvrwf3fjph + // bitcoincash:qppfr7fu4dzxguen85rjwa6ress3sl839qyudganxj + // bitcoincash:qpuaaaseccxyjj04d2l3qv4vd2wxj6gtwvnfe3ckh8 + // bitcoincash:qp46n7a53jvkarp9ps595fjv8czfd045v5zk4xhspm + // bitcoincash:qprjdqx7cnrac4uemp2fza08k875wsgzfcapk76n9n + + // generate 5 testnet addresses for tprv8jBszV65QgT8TAxvj8Go5r8C3BXwq3mYUvaEfEnsfjkx6PRuQYG4W8Bpc4HM2zbiT9S384shi2Zrr6qxXD6nUySxuvztP9o25hLuMcDvMYD + let xpriv = 'tprv8jBszV65QgT8TAxvj8Go5r8C3BXwq3mYUvaEfEnsfjkx6PRuQYG4W8Bpc4HM2zbiT9S384shi2Zrr6qxXD6nUySxuvztP9o25hLuMcDvMYD'; for(let i = 0; i <= 4; i++) { - BITBOX.Address.fromXPub(xpub, "0/" + i) + console.log(bitbox.Address.fromXPub(xpriv, "0'/" + i)) } - // bitcoincash:qzrfwca03gzgwgxsjcxfphuckztc9squ9vmws99sr7 - // bitcoincash:qrr0ykn2xwy80hl0p7vnm44l5sc43x5245nlrfc74c - // bitcoincash:qr3zlplv2w0t3s92twldjk432f45agls0qj35tyqtc - // bitcoincash:qqxf90phz7ysrj53tymq6qvmquk0kd04wvjf6s83nv - // bitcoincash:qrygumzwu7anzppyzcraa2tal3vlzc7p3smyh5cdth + // bchtest:qpmcs78tpfvfphhedcczydaddu5wmcx0xv8udkt9xt + // bchtest:qppfr7fu4dzxguen85rjwa6ress3sl839qqwf0lypw + // bchtest:qpuaaaseccxyjj04d2l3qv4vd2wxj6gtwvhmak6psm + // bchtest:qp46n7a53jvkarp9ps595fjv8czfd045v5xy3p48x8 + // bchtest:qprjdqx7cnrac4uemp2fza08k875wsgzfcenjecyz0 ### `fromOutputScript` @@ -485,29 +531,29 @@ Detect an addess from an OutputScript. #### Arguments 1. scriptPubKey `Buffer`: scriptPubKey -2. network `String` **optional**: defaults to "mainnet" +2. network `string` **optional**: defaults to "mainnet" #### Result -changeAddress `String`: cashaddr encoded change address +changeAddress `string`: cashaddr encoded change address #### Examples - const script = BITBOX.Script.encode([ + const script = bitbox.Script.encode([ Buffer.from("BOX", "ascii"), - BITBOX.Script.opcodes.OP_CAT, + bitbox.Script.opcodes.OP_CAT, Buffer.from("BITBOX", "ascii"), - BITBOX.Script.opcodes.OP_EQUAL + bitbox.Script.opcodes.OP_EQUAL ]); - const p2sh_hash160 = BITBOX.Crypto.hash160(script); - const scriptPubKey = BITBOX.Script.scriptHash.output.encode(p2sh_hash160); + const p2sh_hash160 = bitbox.Crypto.hash160(script); + const scriptPubKey = bitbox.Script.scriptHash.output.encode(p2sh_hash160); // mainnet address from output script - BITBOX.Address.fromOutputScript(scriptPubKey); + bitbox.Address.fromOutputScript(scriptPubKey); // bitcoincash:pz0qcslrqn7hr44hsszwl4lw5r6udkg6zqncnufkrl // testnet address from output script - BITBOX.Address.fromOutputScript(scriptPubKey, 'testnet'); + bitbox.Address.fromOutputScript(scriptPubKey, 'testnet'); // bchtest:pz0qcslrqn7hr44hsszwl4lw5r6udkg6zqh2hmtpyr ### `isHash160` @@ -516,22 +562,123 @@ Detect if an addess is a hash160. #### Arguments -1. address `String`: address +1. address `string`: address #### Result -isHash160 `Boolean`: true/false if address is hash160 +isHash160 `boolean`: true/false if address is hash160 #### Examples let hash160Address = '428df38e23fc879a25819427995c3e6355b12d33'; - BITBOX.Address.isHash160(hash160Address); + bitbox.Address.isHash160(hash160Address); // true let notHash160Address = 'bitcoincash:pz8a837lttkvjksg0jjmmulqvfkgpqrcdgufy8ns5s'; - BITBOX.Address.isHash160(notHash160Address); + bitbox.Address.isHash160(notHash160Address); // false +### `legacyToHash160` + +Convert legacy address to hash160. + +#### Arguments + +1. address `string`: legacy address + +#### Result + +hash160 `string`: hash160 + +#### Examples + + // legacy mainnet p2pkh + bitbox.Address.legacyToHash160("18xHZ8g2feo4ceejGpvzHkvXT79fi2ZdTG") + // 573d93b475be4f1925f3b74ed951201b0147eac1 + + // legacy mainnet p2sh + bitbox.Address.legacyToHash160("3DA6RBcFgLwLTpnF6BRAee8w6a9H6JQLCm") + // 7dc85da64d1d93ef01ef62e0221c02f512e3942f + + // legacy testnet p2pkh + bitbox.Address.legacyToHash160("mhTg9sgNgvAGfmJs192oUzQWqAXHH5nqLE") + // 155187a3283b08b30519db50bc23bbba9f4b6657 + +### `cashToHash160` + +Convert cash address to hash160. + +#### Arguments + +1. address `string`: cash address + +#### Result + +hash160 `string`: hash160 + +#### Examples + + // cash address mainnet p2pkh + bitbox.Address.cashToHash160("bitcoincash:qptnmya5wkly7xf97wm5ak23yqdsz3l2cyj7k9vyyh") + // 573d93b475be4f1925f3b74ed951201b0147eac1 + + // cash address mainnet p2sh + bitbox.Address.cashToHash160("bitcoincash:pp7ushdxf5we8mcpaa3wqgsuqt639cu59ur5xu5fug") + // 7dc85da64d1d93ef01ef62e0221c02f512e3942f + + // cash address testnet p2pkh + bitbox.Address.cashToHash160("bchtest:qq24rpar9qas3vc9r8d4p0prhwaf7jmx2u22nzt946") + // 155187a3283b08b30519db50bc23bbba9f4b6657 + +### `hash160ToLegacy` + +Convert hash160 to legacy address. + +#### Arguments + +1. hash160 `string`: hash160 +2. network `number` **optional** + +#### Result + +legacyAddress `string`: the address in legacy format + +#### Examples + + // legacy mainnet p2pkh + bitbox.Address.hash160ToLegacy("573d93b475be4f1925f3b74ed951201b0147eac1") + // 18xHZ8g2feo4ceejGpvzHkvXT79fi2ZdTG + + // legacy mainnet p2sh + bitbox.Address.hash160ToLegacy("7dc85da64d1d93ef01ef62e0221c02f512e3942f", 0x05) + // 3DA6RBcFgLwLTpnF6BRAee8w6a9H6JQLCm + + // legacy testnet p2pkh + bitbox.Address.hash160ToLegacy("155187a3283b08b30519db50bc23bbba9f4b6657", 0x6f) + // mhTg9sgNgvAGfmJs192oUzQWqAXHH5nqLE + +### `hash160ToCash` + +Convert hash160 to cash address. + +#### Arguments + +1. hash160 `string`: hash160 +2. network `number` **optional** + +#### Result + +cashAddress `string`: the address in cash format + +#### Examples + + bitbox.Address.hash160ToCash("573d93b475be4f1925f3b74ed951201b0147eac1") + 'bitcoincash:qptnmya5wkly7xf97wm5ak23yqdsz3l2cyj7k9vyyh' + bitbox.Address.hash160ToCash("7dc85da64d1d93ef01ef62e0221c02f512e3942f", 0x05) + 'bitcoincash:pp7ushdxf5we8mcpaa3wqgsuqt639cu59ur5xu5fug' + bitbox.Address.hash160ToCash("155187a3283b08b30519db50bc23bbba9f4b6657", 0x6f) + 'bchtest:qq24rpar9qas3vc9r8d4p0prhwaf7jmx2u22nzt946' + ### `details` Return details about an address including balance. @@ -539,20 +686,20 @@ Return details about an address including balance. #### Arguments - addresses (required): - - `String`: A single string containing a legacy or cash address. + - `string`: A single string containing a legacy or cash address. - `Array` of strings: Array with maximum of 20 legacy or cash addresses. #### Result - details: - - `Object`: containing details about the single address. - - `Array`: Array of Objects with details about addresses. + - `Promise`: containing details about the single address. + - `Promise`: Array of Objects with details about addresses. #### Examples (async () => { try { - let details = await BITBOX.Address.details(['1BFHGm4HzqgXXyNX8n7DsQno5DAC4iLMRA']); + let details = await bitbox.Address.details('1BFHGm4HzqgXXyNX8n7DsQno5DAC4iLMRA'); console.log(details) } catch(error) { console.error(error) @@ -584,7 +731,7 @@ Return details about an address including balance. (async () => { try { - let details = await BITBOX.Address.details(['1BFHGm4HzqgXXyNX8n7DsQno5DAC4iLMRA', "bitcoincash:qp7ekaepv3wf2nq035hevcma4x9sxmp3w56048g6ra"]); + let details = await bitbox.Address.details(['1BFHGm4HzqgXXyNX8n7DsQno5DAC4iLMRA', "bitcoincash:qp7ekaepv3wf2nq035hevcma4x9sxmp3w56048g6ra"]); console.log(details) } catch(error) { console.error(error) @@ -627,26 +774,25 @@ Return details about an address including balance. ### `utxo` -Return list of uxto for address +Return list of uxto for address. This includes confirmed and unconfirmed utxos. #### Arguments -- addresses (required): - - `String`: A single string containing a legacy or cash address. +- addresses (required) - 2 formats allowed: + - `string`: A single string containing a legacy or cash address. - `Array` of strings: Array with maximum of 20 legacy or cash addresses. #### Result -- utxo: - - utxo `Object`: containing `utxo` array of utxos, plus `legacyAddress`, - `cashAddress` and `scriptPubKey` properties. - - utxos `Array`: Array of utxo Objects. +- utxo (2 formats based on the argument format): + - utxo `Promise` + - utxos `Promise` #### Examples (async () => { try { - let utxo = await BITBOX.Address.utxo(['1BFHGm4HzqgXXyNX8n7DsQno5DAC4iLMRA']); + let utxo = await bitbox.Address.utxo('1M1FYu4zuVaxRPWLZG5CnP8qQrZaqu6c2L'); console.log(utxo); } catch(error) { console.error(error) @@ -679,7 +825,7 @@ Return list of uxto for address (async () => { try { - let utxo = await BITBOX.Address.utxo([ + let utxo = await bitbox.Address.utxo([ "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" ]); @@ -727,21 +873,21 @@ Return list of unconfirmed transactions for address #### Arguments - addresses (required): - - `String`: A single string containing a legacy or cash address. + - `string`: A single string containing a legacy or cash address. - `Array` of strings: Array with maximum of 20 legacy or cash addresses. #### Result - unconfirmed: - - utxo `Object`: containing `utxo` array of utxos, plus `legacyAddress` and + - utxo `Promise`: containing `utxo` array of utxos, plus `legacyAddress` and `cashAddress` properties. - - utxos `Array`: Array of utxo Objects. + - utxos `Promise`: Array of utxo Objects. #### Examples (async () => { try { - let unconfirmed = await BITBOX.Address.unconfirmed(['1JCwsMQtiV85fGjps4zXceaCCgxpQ1u84R']); + let unconfirmed = await bitbox.Address.unconfirmed('1JCwsMQtiV85fGjps4zXceaCCgxpQ1u84R'); console.log(unconfirmed); } catch(error) { console.error(error) @@ -767,7 +913,7 @@ Return list of unconfirmed transactions for address (async () => { try { - let unconfirmed = await BITBOX.Address.unconfirmed(['1JCwsMQtiV85fGjps4zXceaCCgxpQ1u84R', "bitcoincash:qqcp8fw06dmjd2gnfanpwytj7q93w408nv7usdqgsk"]) + let unconfirmed = await bitbox.Address.unconfirmed(['1JCwsMQtiV85fGjps4zXceaCCgxpQ1u84R', "bitcoincash:qqcp8fw06dmjd2gnfanpwytj7q93w408nv7usdqgsk"]) console.log(unconfirmed); } catch(error) { console.error(error) @@ -816,7 +962,7 @@ Returns decoded transactions for an address #### Arguments - addresses (required): - - `String`: A single string containing a legacy or cash address. + - `string`: A single string containing a legacy or cash address. - `Array` of strings: Array with maximum of 20 legacy or cash addresses. #### Result @@ -830,7 +976,7 @@ Returns decoded transactions for an address (async () => { try { - let transaction = await BITBOX.Address.transactions(['bitcoincash:qz7teqlcltdhqjn2an8nspu7g2x6g3d3rcq8nk4nzs']); + let transaction = await bitbox.Address.transactions('bitcoincash:qz7teqlcltdhqjn2an8nspu7g2x6g3d3rcq8nk4nzs'); console.log(transaction); } catch(error) { console.error(error) @@ -908,7 +1054,7 @@ Returns decoded transactions for an address (async () => { try { - let transaction = await BITBOX.Address.transactions([ + let transaction = await bitbox.Address.transactions([ "bitcoincash:qz7teqlcltdhqjn2an8nspu7g2x6g3d3rcq8nk4nzs", "bitcoincash:qqcp8fw06dmjd2gnfanpwytj7q93w408nv7usdqgsk" ]); @@ -1056,3 +1202,55 @@ Returns decoded transactions for an address // "currentPage": 0 // } // ] + +## Interfaces + +### AddressDetailsResult + + { + balance: number + balanceSat: number + totalReceived: number + totalReceivedSat: number + totalSent: number + totalSentSat: number + unconfirmedBalance: number + unconfirmedBalanceSat: number + unconfirmedTxApperances: number + txApperances: number + transactions: string[] + legacyAddress: string + cashAddress: string + } + +### AddressUtxoResult + + { + legacyAddress: string + cashAddress: string + scriptPubKey: string + utxos: [ + { + txid: string + vout: number + amount: number + satoshis: number + height: number + confirmations: number + } + ] + } + +### AddressUnconfirmedResult + + { + txid: string + vout: number + scriptPubKey: string + amount: number + satoshis: number + confirmations: number + ts: number + legacyAddress: string + cashAddress: string + } diff --git a/src/data/docs/bitbox/bitcoincash.md b/src/data/docs/bitbox/bitcoincash.md index bbec611b..07c8d04b 100644 --- a/src/data/docs/bitbox/bitcoincash.md +++ b/src/data/docs/bitbox/bitcoincash.md @@ -10,33 +10,33 @@ Converting Bitcoin Cash units to satoshi units #### Arguments -1. bitcoinCash `Number`: unit to be converted +1. bitcoinCash `number`: unit to be converted #### Result -satoshi `Number`: bitcoinCash unit converted to satoshis +satoshi `number`: bitcoinCash unit converted to satoshis #### Examples ```javascript // convert 9 $BCH to satoshis -BITBOX.BitcoinCash.toSatoshi(9) +bitbox.BitcoinCash.toSatoshi(9) // 900000000 // convert 1 $BCH to satoshis -BITBOX.BitcoinCash.toSatoshi(1) +bitbox.BitcoinCash.toSatoshi(1) // 100000000 // convert 100 $BCH to satoshis -BITBOX.BitcoinCash.toSatoshi(100) +bitbox.BitcoinCash.toSatoshi(100) // 10000000000 // convert 42 $BCH to satoshis -BITBOX.BitcoinCash.toSatoshi(42) +bitbox.BitcoinCash.toSatoshi(42) // 4200000000 // convert 507 $BCH to satoshis -BITBOX.BitcoinCash.toSatoshi(507) +bitbox.BitcoinCash.toSatoshi(507) // 50700000000 ``` @@ -46,33 +46,33 @@ Converting satoshi units to Bitcoin Cash units #### Arguments -1. satoshi `Number`: unit to be converted +1. satoshi `number`: unit to be converted #### Result -bitcoinCash `Number`: satoshi unit converted to Bitcoin Cash +bitcoinCash `number`: satoshi unit converted to Bitcoin Cash #### Examples ```javascript // convert 900000000 satoshis to $BCH -BITBOX.BitcoinCash.toBitcoinCash(900000000) +bitbox.BitcoinCash.toBitcoinCash(900000000) // 9 // convert 100000000 satoshis to $BCH -BITBOX.BitcoinCash.toBitcoinCash(100000000) +bitbox.BitcoinCash.toBitcoinCash(100000000) // 1 // convert 10000000000 satoshis to $BCH -BITBOX.BitcoinCash.toBitcoinCash(10000000000) +bitbox.BitcoinCash.toBitcoinCash(10000000000) // 100 // convert 4200000000 satoshis to $BCH -BITBOX.BitcoinCash.toBitcoinCash(4200000000) +bitbox.BitcoinCash.toBitcoinCash(4200000000) // 42 // convert 50700000000 satoshis to $BCH -BITBOX.BitcoinCash.toBitcoinCash(50700000000) +bitbox.BitcoinCash.toBitcoinCash(50700000000) // 507 ``` @@ -94,19 +94,15 @@ bits `Number`: satoshi unit converted to Bits // convert 4242323400 satoshis to 42423.234 bits BITBOX.BitcoinCash.toBits(4242323400) // 42423.234 - // convert 100000000 satoshis to 1000 bits BITBOX.BitcoinCash.toBits(100000000) // 1000 - // convert 314000000 satoshis to 3140 bits BITBOX.BitcoinCash.toBits(314000000) // 3140 - // convert 987600000000 satoshis to 9876000 bits BITBOX.BitcoinCash.toBits(987600000000) // 9876000 - // convert 12300 satoshis to 0.123 bits BITBOX.BitcoinCash.toBits(12300) // 0.123 @@ -130,19 +126,15 @@ satoshi `Number`: bits unit converted to satoshi // convert 42423.234 bits to 4242323400 satoshis BITBOX.BitcoinCash.fromBits(42423.234) // 4242323400 - // convert 1000 bits to 100000000 satoshis BITBOX.BitcoinCash.fromBits(1000) // 100000000 - // convert 3140 bits to 314000000 satoshis BITBOX.BitcoinCash.fromBits(3140) // 314000000 - // convert 9876000 bits to 987600000000 satoshis BITBOX.BitcoinCash.fromBits(9876000) // 987600000000 - // convert 0.123 bits to 12300 satoshis BITBOX.BitcoinCash.fromBits(0.123) // 12300 @@ -154,8 +146,8 @@ Sign message with private key #### Arguments -1. privateKeyWIF `String`: private key in wallet import format -2. message `String`: message to sign +1. privateKeyWIF `string`: private key in wallet import format +2. message `string`: message to sign #### Result @@ -164,7 +156,7 @@ signature `string`: cryptographic signature #### Examples ```javascript -BITBOX.BitcoinCash.signMessageWithPrivKey( +bitbox.BitcoinCash.signMessageWithPrivKey( 'KxtpRDUJDiutLaTV8Vuavhb6h7zq9YV9ZKA3dU79PCgYmNVmkkvS', 'EARTH' ) @@ -177,9 +169,9 @@ Verify message #### Arguments -1. address public cashaddr or legacy address which signed the message -2. signature cryptographic signature -3. message to verify +1. address `string`: public cashaddr or legacy address which signed the message +2. signature `string`: cryptographic signature +3. message `string`: to verify #### Result @@ -188,7 +180,7 @@ isVerified `boolean`: if message is verified or not #### Examples ```javascript -BITBOX.BitcoinCash.verifyMessage( +bitbox.BitcoinCash.verifyMessage( 'bitcoincash:qp2zvw3zpk5xx43w4tve7mtekd9kaxwj4uenq9eupv', 'IIYVhlo2Z6TWFjYX1+YM+7vQKz0m+zYdSe4eYpFLuAQDEZXqll7lZC8Au22VI2LLP5x+IerZckVk3QQPsA3e8/8=', 'EARTH' @@ -202,38 +194,38 @@ Encodes hex string as base58Check #### Arguments -1. hex `String`: hex encoded bytes to encode as base58check +1. hex `string`: hex encoded bytes to encode as base58check #### Result -base58check `String`: base58check encoded string +base58check `string`: base58check encoded string #### Examples ```javascript // encode 0079bd35d306f648350818470c9f18903df6e06902a026f2a7 as base58check let hex = '0079bd35d306f648350818470c9f18903df6e06902a026f2a7' -BITBOX.BitcoinCash.encodeBase58Check(hex) +bitbox.BitcoinCash.encodeBase58Check(hex) // 1C6hRmfzvWst5WA7bFRCVAqHt5gE2g7Qar // encode 006da742680accf2282df5fade8e9b7a01a517e779289b52cc as base58check let hex = '006da742680accf2282df5fade8e9b7a01a517e779289b52cc' -BITBOX.BitcoinCash.encodeBase58Check(hex) +bitbox.BitcoinCash.encodeBase58Check(hex) // 1Azo2JBz2JswboeY9xSMcp14BAfhjnD9SK // encode 00c68a6a07ccdaf1669cfd8d244d80ff36b713551c6208f672 as base58check let hex = '00c68a6a07ccdaf1669cfd8d244d80ff36b713551c6208f672' -BITBOX.BitcoinCash.encodeBase58Check(hex) +bitbox.BitcoinCash.encodeBase58Check(hex) // 1K6ncAmMEyQrKUYosZRD9swyZNXECu2aKs // encode 00d0a6b5e3dd43d0fb895b3b3df565bb8266c5ab00a25dbeb5 as base58check let hex = '00d0a6b5e3dd43d0fb895b3b3df565bb8266c5ab00a25dbeb5' -BITBOX.BitcoinCash.encodeBase58Check(hex) +bitbox.BitcoinCash.encodeBase58Check(hex) // 1L2FG9hH3bwchhxHaCs5cg1QNbhmbaeAs6 // encode 00db04c2e6f104997cb04c956bf25da6078e559d303127f08b as base58check let hex = '00db04c2e6f104997cb04c956bf25da6078e559d303127f08b' -BITBOX.BitcoinCash.encodeBase58Check(hex) +bitbox.BitcoinCash.encodeBase58Check(hex) // 1Ly4gqPddveYHMNkfjoXHanVszXpD3duKg ``` @@ -243,7 +235,7 @@ Decodes base58Check encoded string to hex #### Arguments -1. base58check `String`: base58check encoded string to decode to hex +1. base58check `string`: base58check encoded string to decode to hex #### Result @@ -254,27 +246,27 @@ hex `string`: hex encoded string ```javascript // decode 1C6hRmfzvWst5WA7bFRCVAqHt5gE2g7Qar to hex let base58check = '1C6hRmfzvWst5WA7bFRCVAqHt5gE2g7Qar' -BITBOX.BitcoinCash.decodeBase58Check(base58check) +bitbox.BitcoinCash.decodeBase58Check(base58check) // 0079bd35d306f648350818470c9f18903df6e06902a026f2a7 // decode 1Azo2JBz2JswboeY9xSMcp14BAfhjnD9SK to hex let base58check = '1Azo2JBz2JswboeY9xSMcp14BAfhjnD9SK' -BITBOX.BitcoinCash.decodeBase58Check(base58check) +bitbox.BitcoinCash.decodeBase58Check(base58check) // 006da742680accf2282df5fade8e9b7a01a517e779289b52cc // decode 1K6ncAmMEyQrKUYosZRD9swyZNXECu2aKs to hex let base58check = '1K6ncAmMEyQrKUYosZRD9swyZNXECu2aKs' -BITBOX.BitcoinCash.decodeBase58Check(base58check) +bitbox.BitcoinCash.decodeBase58Check(base58check) // 00c68a6a07ccdaf1669cfd8d244d80ff36b713551c6208f672 // decode 1L2FG9hH3bwchhxHaCs5cg1QNbhmbaeAs6 to hex let base58check = '1L2FG9hH3bwchhxHaCs5cg1QNbhmbaeAs6' -BITBOX.BitcoinCash.decodeBase58Check(base58check) +bitbox.BitcoinCash.decodeBase58Check(base58check) // 00d0a6b5e3dd43d0fb895b3b3df565bb8266c5ab00a25dbeb5 // decode 1Ly4gqPddveYHMNkfjoXHanVszXpD3duKg to hex let base58check = '1Ly4gqPddveYHMNkfjoXHanVszXpD3duKg' -BITBOX.BitcoinCash.decodeBase58Check(base58check) +bitbox.BitcoinCash.decodeBase58Check(base58check) // 00db04c2e6f104997cb04c956bf25da6078e559d303127f08b ``` @@ -284,8 +276,9 @@ Encodes address and options as BIP21 uri #### Arguments -1. address `String`: cashaddr (w/ or w/out prefix) or legacy base58check encoded address -2. options `Object`: options such as amount, label, message etc +1. address `string`: cashaddr (w/ or w/out prefix) or legacy base58check encoded address +2. options `EncodeBIP21Options`: options such as amount, label, message etc +3. regtest `boolean` **optional** #### Result @@ -299,7 +292,7 @@ let options = { amount: 1, label: '#BCHForEveryone', } -BITBOX.BitcoinCash.encodeBIP21(address, options) +bitbox.BitcoinCash.encodeBIP21(address, options) // bitcoincash:qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s?amount=1&label=%23BCHForEveryone let address = '1C6hRmfzvWst5WA7bFRCVAqHt5gE2g7Qar' @@ -308,7 +301,7 @@ let options = { label: 'coinbase donation', message: "and ya don't stop", } -BITBOX.BitcoinCash.encodeBIP21(address, options) +bitbox.BitcoinCash.encodeBIP21(address, options) // bitcoincash:qpum6dwnqmmysdggrprse8ccjq7ldcrfqgmmtgcmny?amount=12.5&label=coinbase%20donation&message=and%20ya%20don%27t%20stop let address = 'qzw6tfrh8p0jh834uf9rhg77pjg5rgnt3qw0e54u03' @@ -316,7 +309,7 @@ let options = { amount: 42, label: 'no prefix', } -BITBOX.BitcoinCash.encodeBIP21(address, options) +bitbox.BitcoinCash.encodeBIP21(address, options) // bitcoincash:qzw6tfrh8p0jh834uf9rhg77pjg5rgnt3qw0e54u03?amount=42&label=no%20prefix ``` @@ -326,23 +319,23 @@ Decodes BIP21 uri #### Arguments -1. bip21 `String`: bip21 encoded uri +1. bip21 `string`: bip21 encoded uri #### Result -results `Object`: decoded bip21 uri +results `BIP21Object`: decoded bip21 uri #### Examples ```javascript let bip21 = 'bitcoincash:qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s?amount=1&label=%23BCHForEveryone' -BITBOX.BitcoinCash.decodeBIP21(bip21) +bitbox.BitcoinCash.decodeBIP21(bip21) // { address: 'qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s', options: { amount: 1, label: '#BCHForEveryone' } } let bip21 = 'bitcoincash:qpum6dwnqmmysdggrprse8ccjq7ldcrfqgmmtgcmny?amount=12.5&label=coinbase%20donation&message=and%20ya%20don%27t%20stop' -BITBOX.BitcoinCash.decodeBIP21(bip21) +bitbox.BitcoinCash.decodeBIP21(bip21) // { address: 'qpum6dwnqmmysdggrprse8ccjq7ldcrfqgmmtgcmny', // options: // { amount: 12.5, @@ -353,7 +346,7 @@ BITBOX.BitcoinCash.decodeBIP21(bip21) let bip21 = 'bitcoincash:qzw6tfrh8p0jh834uf9rhg77pjg5rgnt3qw0e54u03?amount=42&label=no%20prefix' -BITBOX.BitcoinCash.decodeBIP21(bip21) +bitbox.BitcoinCash.decodeBIP21(bip21) // { address: 'qzw6tfrh8p0jh834uf9rhg77pjg5rgnt3qw0e54u03', options: { amount: 42, label: 'no prefix' } } ``` @@ -363,12 +356,12 @@ Get byte count of transaction #### Arguments -1. inputs `Object`: object w/ keys describing input types and counts. 'MULTISIG\-P2SH' and 'P2PKH'. "MULTISIG\-P2SH" also should include the required and total number of signatures. EX: "MULTISIG\-P2SH:2\-4" -2. outputs `Object`: object w/ keys describing output types and counts. 'P2SH' and 'P2PKH' +1. inputs `ByteCountInput`: object w/ keys describing input types and counts. 'MULTISIG\-P2SH' and 'P2PKH'. "MULTISIG\-P2SH" also should include the required and total number of signatures. EX: "MULTISIG\-P2SH:2\-4" +2. outputs `ByteCountOutput`: object w/ keys describing output types and counts. 'P2SH' and 'P2PKH' #### Result -byteCount `Number`: number of bytes +byteCount `number`: number of bytes #### Examples @@ -381,7 +374,7 @@ let inputs = { let outputs = { P2SH: 1, } -BITBOX.BitcoinCash.getByteCount(inputs, outputs) +bitbox.BitcoinCash.getByteCount(inputs, outputs) // 190 // 4 MULTISIG-P2SH 2-of-4 and 10 P2PKH inputs @@ -393,7 +386,7 @@ let inputs = { let outputs = { P2PKH: 23, } -BITBOX.BitcoinCash.getByteCount(inputs, outputs) +bitbox.BitcoinCash.getByteCount(inputs, outputs) // 2750 // 2 MULTISIG-P2SH 3-of-5 inputs @@ -404,7 +397,7 @@ let inputs = { let outputs = { P2PKH: 2, } -BITBOX.BitcoinCash.getByteCount(inputs, outputs) +bitbox.BitcoinCash.getByteCount(inputs, outputs) // 565 // 111 P2PKH inputs @@ -415,7 +408,7 @@ let inputs = { let outputs = { P2PKH: 2, } -BITBOX.BitcoinCash.getByteCount(inputs, outputs) +bitbox.BitcoinCash.getByteCount(inputs, outputs) // 16506 // 10 P2PKH and 1 MULTISIG-P2SH 1-of-2 input @@ -428,7 +421,7 @@ let outputs = { P2PKH: 2, P2SH: 1, } -BITBOX.BitcoinCash.getByteCount(inputs, outputs) +bitbox.BitcoinCash.getByteCount(inputs, outputs) // 1780 ``` @@ -438,25 +431,25 @@ BITBOX.BitcoinCash.getByteCount(inputs, outputs) #### Arguments -1. wif `String`: privkey WIF on mainnet or testnet -2. password `String`: password to encrypt wif with +1. wif `string`: privkey WIF on mainnet or testnet +2. password `string`: password to encrypt wif with #### Result -encryptedKey `String`: privkey WIF encrypted w/ password +encryptedKey `string`: privkey WIF encrypted w/ password #### Examples ```javascript // mainnet -BITBOX.BitcoinCash.encryptBIP38( +bitbox.BitcoinCash.encryptBIP38( 'L1phBREbhL4vb1uHHHCAse8bdGE5c7ic2PFjRxMawLzQCsiFVbvu', '9GKVkabAHBMyAf' ) // 6PYU2fDHRVF2194gKDGkbFbeu4mFgkWtVvg2RPd2Sp6KmZx3RCHFpgBB2G // testnet -BITBOX.BitcoinCash.encryptBIP38( +bitbox.BitcoinCash.encryptBIP38( 'cSx7KzdH9EcvDEireu2WYpGnXdFYpta7sJUNt5kVCJgA7kcAU8Gm', '1EBPIyj55eR8bVUov9' ) @@ -469,19 +462,19 @@ BITBOX.BitcoinCash.encryptBIP38( #### Arguments -1. encryptedKey `String`: encrypted privkey WIF -2. password `String`: password to decrypt wif with -3. network `String`: mainnet or testnet. Default: mainnet +1. encryptedKey `string`: encrypted privkey WIF +2. password `string`: password to decrypt wif with +3. network `string`: mainnet or testnet. Default: mainnet #### Result -wif `String`: decrypted privkey WIF on mainnet or testnet +wif `string`: decrypted privkey WIF on mainnet or testnet #### Examples ```javascript // mainnet -BITBOX.BitcoinCash.decryptBIP38( +bitbox.BitcoinCash.decryptBIP38( '6PYU2fDHRVF2194gKDGkbFbeu4mFgkWtVvg2RPd2Sp6KmZx3RCHFpgBB2G', '9GKVkabAHBMyAf', 'mainnet' @@ -489,10 +482,40 @@ BITBOX.BitcoinCash.decryptBIP38( // L1phBREbhL4vb1uHHHCAse8bdGE5c7ic2PFjRxMawLzQCsiFVbvu // testnet -BITBOX.BitcoinCash.decryptBIP38( +bitbox.BitcoinCash.decryptBIP38( '6PYUAPLwLSEjWSAfoe9NTSPkMZXnJA8j8EFJtKaeSnP18RCouutBrS2735', '1EBPIyj55eR8bVUov9', 'testnet' ) // cSx7KzdH9EcvDEireu2WYpGnXdFYpta7sJUNt5kVCJgA7kcAU8Gm ``` + +## Interfaces + +### EncodeBIP21Options + + { + amount?: number + label?: string + message?: string + } + +### BIP21Object + + { + address: string + options?: EncodeBIP21Options + } + +### ByteCountInput + + { + P2PKH?: number + } + +### ByteCountOutput + + { + P2PKH?: number + P2SH?: number + } diff --git a/src/data/docs/bitbox/bitdb.md b/src/data/docs/bitbox/bitdb.md new file mode 100644 index 00000000..dcffe516 --- /dev/null +++ b/src/data/docs/bitbox/bitdb.md @@ -0,0 +1,51 @@ +--- +title: BitDB +icon: coins +ordinal: 5 +--- + +### `get` + +Get BitDB data by `query` + +#### Arguments + +1. query `any`: BitDB Query + +#### Result + +result `any`: BitDB Result + +#### Examples + +```javascript +;(async () => { + let res = await bitbox.BitDB.get({ + v: 3, + q: { + db: ['c'], + find: {}, + limit: 10, + }, + }) + console.log(res) + + // returns + // { c: + // [ { _id: '5d40924a0f265a358b92401a', + // tx: [Object], + // in: [Array], + // out: [Array], + // blk: [Object] }, + // { _id: '5d40924a0f265a358b924019', + // tx: [Object], + // in: [Array], + // out: [Array], + // blk: [Object] }, + // { _id: '5d40924a0f265a358b924018', + // tx: [Object], + // in: [Array], + // out: [Array], + // blk: [Object] }, +})() +``` diff --git a/src/data/docs/bitbox/block.md b/src/data/docs/bitbox/block.md index 21da7289..e62cf768 100644 --- a/src/data/docs/bitbox/block.md +++ b/src/data/docs/bitbox/block.md @@ -1,7 +1,7 @@ --- title: Block icon: cube -ordinal: 5 +ordinal: 6 --- ### `detailsByHeight` @@ -11,20 +11,20 @@ Return details about a Block. Lookup the block with a block height. #### Arguments - blocks (required): - - `Number`: block height - - `Array` of Numbers: block heights + - `number`: block height + - `number[]` of Numbers: block heights #### Result - details - - `Object`: Details about Block - - `Array` of Objects: Details about Block + - `Promise` + - `Promise` #### Examples (async () => { try { - let details = await BITBOX.Block.detailsByHeight(500000); + let details = await bitbox.Block.detailsByHeight(500000); console.log(details); } catch(error) { console.error(error) @@ -59,7 +59,7 @@ Return details about a Block. Lookup the block with a block height. (async () => { try { - let details = await BITBOX.Block.detailsByHeight([500000, 500001]); + let details = await bitbox.Block.detailsByHeight([500000, 500001]); console.log(details); } catch(error) { console.error(error) @@ -119,20 +119,20 @@ Return details about a Block. Lookup the block with a block hash. #### Arguments - hashes (required): - - `String`: block hash - - `Array` of Strings: block hashes + - `string`: block hash + - `string[]` of Strings: block hashes #### Result - details - - `Object`: Details about Block - - `Array` of Objects: Details about Block + - `Promise` + - `Promise` #### Examples (async () => { try { - let details = await BITBOX.Block.hash("000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201"); + let details = await bitbox.Block.hash("000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201"); console.log(details); } catch(error) { console.error(error) @@ -166,7 +166,7 @@ Return details about a Block. Lookup the block with a block hash. (async () => { try { - let details = await BITBOX.Block.detailsByHeight([ + let details = await bitbox.Block.detailsByHeight([ "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201", "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201" ]); @@ -221,3 +221,28 @@ Return details about a Block. Lookup the block with a block hash. // "isMainChain": true, // "poolInfo": {} // }] + +## Interfaces + +### BlockDetails + + { + hash: string + size: number + height: number + version: number + merkleroot: string + tx: string[] + time: number + mediantime?: number + nonce: number + bits: string + difficulty: number + chainwork: string + confirmations: number + previousblockhash: string + nextblockhash: string + reward: number + isMainChain: boolean + poolInfo: object + } diff --git a/src/data/docs/bitbox/blockchain.md b/src/data/docs/bitbox/blockchain.md index 41e4596e..91689fff 100644 --- a/src/data/docs/bitbox/blockchain.md +++ b/src/data/docs/bitbox/blockchain.md @@ -1,7 +1,7 @@ --- title: Blockchain icon: cubes -ordinal: 6 +ordinal: 7 --- ### `getBestBlockHash` @@ -10,13 +10,13 @@ Returns the hash of the best (tip) block in the longest blockchain. #### Result -hex `String`: the block hash hex encoded +hex `Promise`: the block hash hex encoded #### Examples (async () => { try { - let getBestBlockHash = await BITBOX.Blockchain.getBestBlockHash(); + let getBestBlockHash = await bitbox.Blockchain.getBestBlockHash(); console.log(getBestBlockHash); } catch(error) { console.error(error) @@ -30,14 +30,18 @@ If verbose is false, returns a string that is serialized, hex-encoded data for b #### Arguments -1. blockhash `String` required: The block hash -2. verbose `Boolean` optional: true for a json object, false for the hex encoded data +1. blockhash `string`: The block hash +2. verbose `boolean` **optional**: true for a json object, false for the hex encoded data + +#### Result + +block `Promise` #### Examples (async () => { try { - let getBlock = await BITBOX.Blockchain.getBlock("00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"); + let getBlock = await bitbox.Blockchain.getBlock("00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"); console.log(getBlock); } catch(error) { console.error(error) @@ -66,11 +70,15 @@ If verbose is false, returns a string that is serialized, hex-encoded data for b Returns an object containing various state info regarding blockchain processing. +#### Result + +block `Promise` + #### Examples (async () => { try { - let getBlockchainInfo = await BITBOX.Blockchain.getBlockchainInfo(); + let getBlockchainInfo = await bitbox.Blockchain.getBlockchainInfo(); console.log(getBlockchainInfo); } catch(error) { console.error(error) @@ -103,13 +111,13 @@ Returns the number of blocks in the longest blockchain. #### Result -n (numeric) The current block count +n `Promise` #### Examples (async () => { try { - let getBlockCount = await BITBOX.Blockchain.getBlockCount(); + let getBlockCount = await bitbox.Blockchain.getBlockCount(); console.log(getBlockCount); } catch(error) { console.error(error) @@ -123,17 +131,17 @@ Returns hash of block in best-block-chain at height provided. #### Arguments -1. heights `Array` required: Array with maximum of 20 block heights. +1. height `number` **optional** #### Result -hash `string` The block hash +hash `Promise` The block hash #### Examples (async () => { try { - let getBlockHash = await BITBOX.Blockchain.getBlockHash([0]); + let getBlockHash = await bitbox.Blockchain.getBlockHash([0]); console.log(getBlockHash); } catch(error) { console.error(error) @@ -147,14 +155,18 @@ If verbose is false, returns a string that is serialized, hex-encoded data for b #### Arguments -1. hashes `Array` required: Array with maximum of 20 hashes. -2. verbose `Boolean` optional: true for a json object, false for the hex encoded data. default=true +1. hashes `string | string[]` +2. verbose `boolean` **optional**: true for a json object, false for the hex encoded data. + +#### Result + +blockHeader `Promise` The block header #### Examples (async () => { try { - let getBlockHeader = await BITBOX.Blockchain.getBlockHeader(["00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"]); + let getBlockHeader = await bitbox.Blockchain.getBlockHeader(["00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"]); console.log(getBlockHeader); } catch(error) { console.error(error) @@ -180,11 +192,15 @@ If verbose is false, returns a string that is serialized, hex-encoded data for b Return information about all known tips in the block tree, including the main chain as well as orphaned branches. +#### Result + +chainTips `Promise` + #### Examples (async () => { try { - let getChainTips = await BITBOX.Blockchain.getChainTips(); + let getChainTips = await bitbox.Blockchain.getChainTips(); console.log(getChainTips); } catch(error) { console.error(error) @@ -210,13 +226,13 @@ Returns the proof-of-work difficulty as a multiple of the minimum difficulty. #### Result -n.nnn (numeric): the proof-of-work difficulty as a multiple of the minimum difficulty. +n `Promise`: the proof-of-work difficulty as a multiple of the minimum difficulty. #### Examples (async () => { try { - let getDifficulty = await BITBOX.Blockchain.getDifficulty(); + let getDifficulty = await bitbox.Blockchain.getDifficulty(); console.log(getDifficulty); } catch(error) { console.error(error) @@ -225,22 +241,24 @@ n.nnn (numeric): the proof-of-work difficulty as a multiple of the minimum diffi // 702784497476.8376 -### `getMempoolAncestors` + ### `getMempoolEntry` @@ -274,20 +296,20 @@ Returns mempool data for given transaction #### Arguments - txids (required): - - `String`: TXID currently in mempool - - `Array` of strings: Array of TXIDs, with maximum of 20 entries. + - `string`: TXID currently in mempool + - `string[]`: Array of TXIDs #### Result - entry: - - `Object`: containing details about the single mempool entry. - - `Array`: Array of Objects with details about mempool entries. + - `Promise`: containing details about the single mempool entry. + - `Promise`: Array of Objects with details about mempool entries. #### Examples (async () => { try { - let getMempoolEntry = await BITBOX.Blockchain.getMempoolEntry(["fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33"]); + let getMempoolEntry = await bitbox.Blockchain.getMempoolEntry("fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33"); console.log(getMempoolEntry); } catch(error) { console.error(error) @@ -313,7 +335,7 @@ Returns mempool data for given transaction (async () => { try { - let getMempoolEntry = await BITBOX.Blockchain.getMempoolEntry([ + let getMempoolEntry = await bitbox.Blockchain.getMempoolEntry([ "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33", "defea04c38ee00cf73ad402984714ed22dc0dd99b2ae5cb50d791d94343ba79b" ]); @@ -362,11 +384,15 @@ Returns mempool data for given transaction Returns details on the active state of the TX memory pool. +#### Result + +entry `Promise` + #### Examples (async () => { try { - let getMempoolInfo = await BITBOX.Blockchain.getMempoolInfo(); + let getMempoolInfo = await bitbox.Blockchain.getMempoolInfo(); console.log(getMempoolInfo); } catch(error) { console.error(error) @@ -385,13 +411,17 @@ Returns all transaction ids in memory pool as a json array of string transaction #### Arguments -1. verbose (boolean, optional, default=false): True for a json object, false for array of transaction ids +1. verbose `boolean` **optional**: True for a json object, false for array of transaction ids + +#### Result + +rawMemPool `Promise` #### Examples (async () => { try { - let getRawMempool = await BITBOX.Blockchain.getRawMempool(true); + let getRawMempool = await bitbox.Blockchain.getRawMempool(true); console.log(getRawMempool); } catch(error) { console.error(error) @@ -421,15 +451,19 @@ Returns details about an unspent transaction output. #### Arguments -1. txid (string, required): The transaction id -2. n (numeric, required): vout number -3. include_mempool (boolean, optional): Whether to include the mempool +1. txid `string`: The transaction id +2. n `number`: vout number +3. include_mempool `boolean` **optional**: Whether to include the mempool + +#### Result + +txOut `Promise` #### Examples (async () => { try { - let getTxOut = await BITBOX.Blockchain.getTxOut("e25682caafc7000645d59f4c11d8d594b2943979b9d8fafb9f946e2b35c21b7e", 1); + let getTxOut = await bitbox.Blockchain.getTxOut("e25682caafc7000645d59f4c11d8d594b2943979b9d8fafb9f946e2b35c21b7e", 1); console.log(getTxOut); } catch(error) { console.error(error) @@ -444,23 +478,21 @@ Returns a hex-encoded proof that "txid" was included in a block. #### Arguments -- txids (required): - - `String`: A single string containing a txid. - - `Array` of strings: Array with maximum of 20 txids. +- txids: + - `string`: A single string containing a txid. + - `string[]` #### Result - proof: - - `String`: A string that is a serialized, hex-encoded data for the proof. - - `Array` of strings: Array of strings that are a serialized, hex-encoded data for the proof. - -legacyAddress `string` legacy base 58 check encoded address + - `Promise`: A string that is a serialized, hex-encoded data for the proof. + - `Promise`: Array of strings that are a serialized, hex-encoded data for the proof. #### Examples (async () => { try { - let getTxOutProof = await BITBOX.Blockchain.getTxOutProof("e25682caafc7000645d59f4c11d8d594b2943979b9d8fafb9f946e2b35c21b7e"); + let getTxOutProof = await bitbox.Blockchain.getTxOutProof("e25682caafc7000645d59f4c11d8d594b2943979b9d8fafb9f946e2b35c21b7e"); console.log(getTxOutProof); } catch(error) { console.error(error) @@ -471,7 +503,7 @@ legacyAddress `string` legacy base 58 check encoded address (async () => { try { - let getTxOutProof = await BITBOX.Blockchain.getTxOutProof([ + let getTxOutProof = await bitbox.Blockchain.getTxOutProof([ "e25682caafc7000645d59f4c11d8d594b2943979b9d8fafb9f946e2b35c21b7e", "d16662463fd98eb96c8f6898d58a4461ac3d0120f4d0aea601d72b37759f261c" ]); @@ -486,70 +518,74 @@ legacyAddress `string` legacy base 58 check encoded address // "010000007de867cc8adc5cc8fb6b898ca4462cf9fd667d7830a275277447e60800000000338f121232e169d3100edd82004dc2a1f0e1f030c6c488fa61eafa930b0528fe021f7449ffff001d36b4af9a0100000001338f121232e169d3100edd82004dc2a1f0e1f030c6c488fa61eafa930b0528fe0101" // ] -### `preciousBlock` + -### `pruneBlockchain` + -### `verifyChain` + ### `verifyTxOutProof` @@ -560,19 +596,19 @@ best chain #### Arguments - proof (required): - - `String`: The hex-encoded proof generated by gettxoutproof - - `Array` of strings: The hex-encoded proof generated by gettxoutproof + - `string`: The hex-encoded proof generated by gettxoutproof + - `string[]`: The hex-encoded proof generated by gettxoutproof #### Result -- txids `Array`: The txid(s) which the proof commits to, or empty array if the proof is invalid +- txids `Promise`: The txid(s) which the proof commits to, or empty array if the proof is invalid #### Examples (async () => { try { const proof = "0000002086a4a3161f9ba2174883ec0b93acceac3b2f37b36ed1f90000000000000000009cb02406d1094ecf3e0b4c0ca7c585125e721147c39daf6b48c90b512741e13a12333e5cb38705180f441d8c7100000008fee9b60f1edb57e5712839186277ed39e0a004a32be9096ee47472efde8eae62f789f9d7a9f59d0ea7093dea1e0c65ff0b953f1d8cf3d47f92e732ca0295f603c272d5f4a63509f7a887f2549d78af7444aa0ecbb4f66d9cbe13bc6a89f59e05a199df8325d490818ffefe6b6321d32d7496a68580459836c0183f89082fc1b491cc91b23ecdcaa4c347bf599a62904d61f1c15b400ebbd5c90149010c139d9c1e31b774b796977393a238080ab477e1d240d0c4f155d36f519668f49bae6bd8cd5b8e40522edf76faa09cca6188d83ff13af6967cc6a569d1a5e9aeb1fdb7f531ddd2d0cbb81879741d5f38166ac1932136264366a4065cc96a42e41f96294f02df01" - let verifyTxOutProof = await BITBOX.Blockchain.verifyTxOutProof(proof); + let verifyTxOutProof = await bitbox.Blockchain.verifyTxOutProof(proof); console.log(verifyTxOutProof); } catch(error) { console.error(error) @@ -586,7 +622,7 @@ best chain (async () => { try { const proof = "0000002086a4a3161f9ba2174883ec0b93acceac3b2f37b36ed1f90000000000000000009cb02406d1094ecf3e0b4c0ca7c585125e721147c39daf6b48c90b512741e13a12333e5cb38705180f441d8c7100000008fee9b60f1edb57e5712839186277ed39e0a004a32be9096ee47472efde8eae62f789f9d7a9f59d0ea7093dea1e0c65ff0b953f1d8cf3d47f92e732ca0295f603c272d5f4a63509f7a887f2549d78af7444aa0ecbb4f66d9cbe13bc6a89f59e05a199df8325d490818ffefe6b6321d32d7496a68580459836c0183f89082fc1b491cc91b23ecdcaa4c347bf599a62904d61f1c15b400ebbd5c90149010c139d9c1e31b774b796977393a238080ab477e1d240d0c4f155d36f519668f49bae6bd8cd5b8e40522edf76faa09cca6188d83ff13af6967cc6a569d1a5e9aeb1fdb7f531ddd2d0cbb81879741d5f38166ac1932136264366a4065cc96a42e41f96294f02df01" - let verifyTxOutProof = await BITBOX.Blockchain.verifyTxOutProof([proof, proof]); + let verifyTxOutProof = await bitbox.Blockchain.verifyTxOutProof([proof, proof]); console.log(verifyTxOutProof); } catch(error) { console.error(error) @@ -597,3 +633,76 @@ best chain // "03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7", // "03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7" // ] + +## Interfaces + +### MempoolInfo + + { + size: number + bytes: number + usage: number + maxmempool: number + mempoolminfee: number + } + +### BlockchainInfo + + { + chain: string + blocks: number + headers: number + bestblockhash: string + difficulty: number + mediantime: number + verificationprogress: number + chainwork: string + pruned: boolean + softforks: object[] + bip9_softforks: object + } + +### BlockHeader + + { + hash: string + confirmations: number + height: number + version: number + versionHex: string + merkleroot: string + time: number + mediantime: number + nonce: number + bits: string + difficulty: number + chainwork: string + previousblockhash: string + nextblockhash: string + } + +### ChainTip + + { + height: number + hash: string + branchlen: number + status: string + } + +### TxOut + + { + bestblock: string + confirmations: number + value: number + scriptPubKey: { + asm: string + hex: string + reqSigs: number + type: string + addresses: string[] + } + version: number + coinbase: boolean + } diff --git a/src/data/docs/bitbox/cashAccounts.md b/src/data/docs/bitbox/cashAccounts.md new file mode 100644 index 00000000..ef72f84a --- /dev/null +++ b/src/data/docs/bitbox/cashAccounts.md @@ -0,0 +1,195 @@ +--- +title: CashAccounts +icon: user-circle +ordinal: 8 +--- + +### `lookup` + +Returns an object containing account info + +#### Arguments + +1. account `string` **required** +2. number `number` **required** +3. collision `number` **optional** + +#### Result + +cashAccount `CashAccountInterface` + +#### Examples + + (async () => { + try { + let cashAccounts = await bitbox.CashAccounts.lookup("cgcardona", 122) + console.log(cashAccounts) + } catch (error) { + console.log(error) + } + })() + + // returns + { + identifier: "cgcardona#122;", + information: { + emoji: "🍞", + name: "cgcardona", + number: 122, + collision: { + hash: "6383276713", + count: 0, + length: 0 + }, + payment: [ + { + type: "Key Hash", + address: "bitcoincash:qrhncn6hgkhljqg4fuq4px5qg74sjz9fqqj64s9la9" + } + ] + } + } + +### `check` + +Returns an object containing block height and inclusion proof for independent verification + +#### Arguments + +1. account `string` **required** +2. number `number` **required** + +#### Result + +cashAccount `CashAccountCheckResult` + +#### Examples + + (async () => { + try { + let check = await bitbox.CashAccounts.check("cgcardona", 122) + console.log(check) + } catch (error) { + console.log(error) + } + })() + + // returns + { + "identifier": "cgcardona#122", + "block": 563742, + "results": [ + { + "transaction": "0100000001A8421264294082C08C0611E162BD49999443EF577C57923BD052F7202B09408E010000006A473044022039F4DD9AD6BC2C4E799D135BB68B5E05E71F83731EFC63260C7FB16F63BB842802203DEA9E82E97D28ADC9A9567E16762CF3663C24CE6A42AEDDC1E273E50B8CA9C941210202435C144A77C6ED76C3A74EE6006A9255B449F1B2F09FA2668027FEC106CFA1FFFFFFFF020000000000000000266A0401010101096367636172646F6E611501EF3C4F5745AFF901154F01509A8047AB0908A9008CD51100000000001976A914919908484336464C2A9938D24149A4177606340F88AC00000000", + "inclusionProof": "0000C020C98F109DA027EB72472AC903F6E2BFA993D88724734B2C01000000000000000019213AEE113214AF03EEEE303F733708AD79F259A148F4A17C496302E1D093DF7D9D2E5C4CE10418F2AE48C41F000000067AA86CA831AB260AF59E0ED93305939D9A300BD66076EB18D155143E992950C33A46C140D7202C577D6C25DCD8F315D304285D8BD890C41925F00CC256C22CC69E1410317FD69D5A58F762EE26B469DC1909F2D0DE5E471B0AC09C686C41664585DF32ABA0EEAF50B6AB66010206DE24A5C576CBC331EF153507E9E20D1C18506E24DBEDB0A0B66705E10376CD19ADB4A605098058ACB805D24456CC004CCA78ABA3969F47284773B7809C81B93E2CCCC280218272164AE5D90245A629F6801802EB00" + } + ] + } + +### `reverseLookup` + +Returns an object containing block height and inclusion proof for independent verification + +#### Arguments + +1. cashAddress `string` **required** + +#### Result + +reverseLookup `CashAccountReverseLookupResult` + +#### Examples + + (async () => { + try { + let reverseLookup = await bitbox.CashAccounts.reverseLookup("bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst") + console.log(check) + } catch (error) { + console.log(error) + } + })() + + // returns + { + "results": [ + { + "accountEmoji": "☯", + "nameText": "Jonathan", + "accountNumber": 100, + "accountHash": "5876958390", + "accountCollisionLength": 0, + "payloadType": 1, + "payloadAddress": "bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst" + }, + { + "accountEmoji": "🍭", + "nameText": "ConfirmationTest", + "accountNumber": 113, + "accountHash": "4640561912", + "accountCollisionLength": 0, + "payloadType": 1, + "payloadAddress": "bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst" + }, + { + "accountEmoji": "🌽", + "nameText": "Bob", + "accountNumber": 4035, + "accountHash": "7443382842", + "accountCollisionLength": 0, + "payloadType": 1, + "payloadAddress": "bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst" + }, + { + "accountEmoji": "🎀", + "nameText": "qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst", + "accountNumber": 7084, + "accountHash": "4319915751", + "accountCollisionLength": 0, + "payloadType": 1, + "payloadAddress": "bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst" + } + ] + } + +## Interfaces + +### CashAccountInterface + + { + identifier: string + information: { + emoji: string + name: string + number: number + collision: { + hash: string + } + payment: string[] + } + } + +### CashAccountCheckResult + + { + identifier: string + block: number + results: string[] + } + +### CashAccountReverseLookupResult + + { + results: SingleCashAccountReverseLookupResult[] + } + +### SingleCashAccountReverseLookupResult + + { + accountEmoji: any + nameText: string + accountNumber: number + accountHash: string + accountCollisionLength: number + payloadType: number + payloadAddress: string + } diff --git a/src/data/docs/bitbox/console.md b/src/data/docs/bitbox/console.md index 8676102a..15b4adf5 100644 --- a/src/data/docs/bitbox/console.md +++ b/src/data/docs/bitbox/console.md @@ -8,10 +8,10 @@ Launch a console w/ the entire Bitcoin Cash RPC available as well as dozens of h ```bash $ bitbox console --environment production -> BITBOX. -BITBOX.Address BITBOX.BitcoinCash BITBOX.Block BITBOX.Blockchain BITBOX.Control BITBOX.Crypto BITBOX.ECPair BITBOX.Generating BITBOX.restURL -BITBOX.HDNode BITBOX.Mining BITBOX.Mnemonic BITBOX.Network BITBOX.Price BITBOX.RawTransactions BITBOX.Script BITBOX.Socket -BITBOX.Transaction BITBOX.TransactionBuilder BITBOX.Util +> bitbox. +bitbox.Address bitbox.BitcoinCash bitbox.Block bitbox.Blockchain bitbox.Control bitbox.Crypto bitbox.ECPair bitbox.Generating bitbox.restURL +bitbox.HDNode bitbox.Mining bitbox.Mnemonic bitbox.Network bitbox.Price bitbox.RawTransactions bitbox.Script bitbox.Socket +bitbox.Transaction bitbox.TransactionBuilder bitbox.Util ``` ### Quickly test your ideas @@ -19,24 +19,24 @@ BITBOX.Transaction BITBOX.TransactionBuilder BITBOX.Util ```javascript bitbox console -> BITBOX.BitcoinCash.toSatoshi(9) +> bitbox.BitcoinCash.toSatoshi(9) // 900000000 -> BITBOX.Address.toLegacyAddress('bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') +> bitbox.Address.toLegacyAddress('bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') // 1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN // create mnemonic -> let mnemonic = BITBOX.Mnemonic.generate(128); +> let mnemonic = bitbox.Mnemonic.generate(128); // ancient slide suggest chaos vivid property trophy faith bamboo lunch save hint // create seed buffer from mnemonic -> let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); +> let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer -> let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); +> let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // derive hardened child HDNode -> let childNode = BITBOX.HDNode.derivePath(hdNode, "m/44'/145'/0'"); -> BITBOX.HDNode.toXPriv(childNode) +> let childNode = bitbox.HDNode.derivePath(hdNode, "m/44'/145'/0'"); +> bitbox.HDNode.toXPriv(childNode) // xprv9yHczLBaxwHo85o8mJVHSu1ghxEWM2QZcrvWFvHWXgkqfuqNz6EDNxv4wAPTBwX7nkrnBTPgdCZi7qyQAF72MF4KTq9UzzygDhvBajpwScs ``` diff --git a/src/data/docs/bitbox/control.md b/src/data/docs/bitbox/control.md index 6770e29e..aed5529c 100644 --- a/src/data/docs/bitbox/control.md +++ b/src/data/docs/bitbox/control.md @@ -1,18 +1,22 @@ --- title: Control icon: gamepad -ordinal: 7 +ordinal: 9 --- ### `getInfo` Returns an object containing various state info. +#### Result + +info `Promise` + #### Examples (async () => { try { - let getInfo = await BITBOX.Control.getInfo(); + let getInfo = await bitbox.Control.getInfo(); console.log(getInfo); } catch(error) { console.error(error) @@ -30,3 +34,106 @@ Returns an object containing various state info. // paytxfee: 0, // relayfee: 0.00001, // errors: '' } + +### `getNetworkInfo` + +Returns an object containing various network info. + +#### Result + +networkInfo `Promise` + +#### Examples + + (async () => { + try { + let getInfo = await bitbox.Control.getNetworkInfo(); + console.log(getInfo); + } catch(error) { + console.error(error) + } + })() + + // returns + { version: 190500, + subversion: '/Bitcoin ABC:0.19.5(EB32.0)/', + protocolversion: 70015, + localservices: '0000000000000425', + localrelay: true, + timeoffset: 0, + networkactive: true, + connections: 17, + networks: + [ { name: 'ipv4', + limited: false, + reachable: true, + proxy: '', + proxy_randomize_credentials: false }, + { name: 'ipv6', + limited: false, + reachable: true, + proxy: '', + proxy_randomize_credentials: false }, + { name: 'onion', + limited: true, + reachable: false, + proxy: '', + proxy_randomize_credentials: false } ], + relayfee: 0.00001, + excessutxocharge: 0, + warnings: + 'Warning: Unknown block versions being mined! It\'s possible unknown rules are in effect' }} + +## Interfaces + +### NodeInfo + + { + version: number + protocolversion: number + blocks: number + timeoffset: number + connections: number + proxy: string + difficulty: number + testnet: boolean + paytxfee: number + relayfee: number + errors: string + } + +### NetworkInfo + + { + version: number + subversion: string + protocolversion: number + localservices: string, + localrelay: boolean, + timeoffset: number, + networkactive: boolean, + connections: number, + networks: + [ { name: string, + limited: boolean, + reachable: boolean, + proxy: string, + proxy_randomize_credentials: boolean } + ], + relayfee: number, + excessutxocharge: number, + warnings: string + } + + diff --git a/src/data/docs/bitbox/crypto.md b/src/data/docs/bitbox/crypto.md index 54741ad3..d9c3b5c9 100644 --- a/src/data/docs/bitbox/crypto.md +++ b/src/data/docs/bitbox/crypto.md @@ -1,9 +1,38 @@ --- title: Crypto icon: link -ordinal: 8 +ordinal: 10 --- +### `sha1` + +Utility for creating sha1 hash digests of data + +#### Arguments + +1. buffer `Buffer`: data to be hashed + +#### Result + +buffer `Buffer`: sha1 hash of data + +#### Examples + + // buffer from hex + let buffer = Buffer.from('0101010101010101', 'hex') + bitbox.Crypto.sha1(buffer) + // + + // buffer from hex + let buffer = Buffer.from('031ad329b3117e1d1e2974406868e575d48cff88e8128ba0eedb10da053785033b', 'hex') + bitbox.Crypto.sha1(buffer) + // + + // buffer from hex + let buffer = Buffer.from('03123464075c7a5fa6b8680afa2c962a02e7bf071c6b2395b0ac711d462cac9354', 'hex') + bitbox.Crypto.sha1(buffer) + // + ### `sha256` Utility for creating sha256 hash digests of data @@ -14,24 +43,24 @@ Utility for creating sha256 hash digests of data #### Result -buffer `Buffer`: sha256 hash of data +buffer `Buffer`: sha1 hash of data #### Examples // buffer from hex let buffer = Buffer.from('0101010101010101', 'hex') - BITBOX.Crypto.sha256(buffer) - // + bitbox.Crypto.sha256(buffer) + // // buffer from hex let buffer = Buffer.from('031ad329b3117e1d1e2974406868e575d48cff88e8128ba0eedb10da053785033b', 'hex') - BITBOX.Crypto.sha256(buffer) - // + bitbox.Crypto.sha256(buffer) + // // buffer from hex let buffer = Buffer.from('03123464075c7a5fa6b8680afa2c962a02e7bf071c6b2395b0ac711d462cac9354', 'hex') - BITBOX.Crypto.sha256(buffer) - // + bitbox.Crypto.sha256(buffer) + // ### `ripemd160` @@ -49,18 +78,18 @@ buffer `Buffer`: ripemd160 hash of data // buffer from hex let buffer = Buffer.from('0101010101010101', 'hex') - BITBOX.Crypto.ripemd160(buffer) - // + bitbox.Crypto.ripemd160(buffer) + // // buffer from hex let buffer = Buffer.from('75618d82d1f6251f2ef1f42f5f0d5040330948a707ff6d69720dbdcb00b48aab', 'hex') - BITBOX.Crypto.ripemd160(buffer) - // + bitbox.Crypto.ripemd160(buffer) + // // buffer from hex let buffer = Buffer.from('978c09dd46091d1922fa01e9f4a975b91a371f26ba8399de27d53801152121de', 'hex') - BITBOX.Crypto.ripemd160(buffer) - // + bitbox.Crypto.ripemd160(buffer) + // ### `hash256` @@ -78,18 +107,18 @@ buffer `Buffer`: double sha256 hash of data // buffer from hex let buffer = Buffer.from('0101010101010101', 'hex') - BITBOX.Crypto.hash256(buffer) - // + bitbox.Crypto.hash256(buffer) + // // buffer from hex let buffer = Buffer.from('031ad329b3117e1d1e2974406868e575d48cff88e8128ba0eedb10da053785033b', 'hex') - BITBOX.Crypto.hash256(buffer) - // + bitbox.Crypto.hash256(buffer) + // // buffer from hex let buffer = Buffer.from('03123464075c7a5fa6b8680afa2c962a02e7bf071c6b2395b0ac711d462cac9354', 'hex') - BITBOX.Crypto.hash256(buffer) - // + bitbox.Crypto.hash256(buffer) + // ### `hash160` @@ -107,18 +136,18 @@ buffer `Buffer`: ripemd160(sha256()) hash of data // buffer from hex let buffer = Buffer.from('0101010101010101', 'hex') - BITBOX.Crypto.hash160(buffer) - // + bitbox.Crypto.hash160(buffer) + // // buffer from hex let buffer = Buffer.from('031ad329b3117e1d1e2974406868e575d48cff88e8128ba0eedb10da053785033b', 'hex') - BITBOX.Crypto.hash160(buffer) - // + bitbox.Crypto.hash160(buffer) + // // buffer from hex let buffer = Buffer.from('03123464075c7a5fa6b8680afa2c962a02e7bf071c6b2395b0ac711d462cac9354', 'hex') - BITBOX.Crypto.hash160(buffer) - // + bitbox.Crypto.hash160(buffer) + // ### `randomBytes` @@ -134,17 +163,17 @@ buffer `Buffer`: random bytes encoded as a buffer #### Examples - BITBOX.Crypto.randomBytes(16) - // + bitbox.Crypto.randomBytes(16) + // - BITBOX.Crypto.randomBytes(20) - // + bitbox.Crypto.randomBytes(20) + // - BITBOX.Crypto.randomBytes(24) - // + bitbox.Crypto.randomBytes(24) + // - BITBOX.Crypto.randomBytes(28) - // + bitbox.Crypto.randomBytes(28) + // - BITBOX.Crypto.randomBytes(32) - // + bitbox.Crypto.randomBytes(32) + // diff --git a/src/data/docs/bitbox/ecpair.md b/src/data/docs/bitbox/ecpair.md index a5bbd625..67b80459 100644 --- a/src/data/docs/bitbox/ecpair.md +++ b/src/data/docs/bitbox/ecpair.md @@ -1,30 +1,30 @@ --- title: ECPair icon: key -ordinal: 9 +ordinal: 11 --- ### `fromWIF` -Generates an ECPair from a private key in wallet import format. +Generates an ECPair from a private key in wallet import format ([WIF](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#private-key-formats)). Follow these [steps to go from a private key to a WIF](https://en.bitcoin.it/wiki/Wallet_import_format). This method only works with a [compressed private key](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#compressed-private-keys). #### Arguments -1. wif `string`: private key in wallet import format (WIF) +1. wif `string`: private key in wallet import format ([WIF](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#private-key-formats)) #### Result -ecpair `string`: ECPair +ecpair `ECPair` #### Examples // mainnet WIF let wif = 'L4vmKsStbQaCvaKPnCzdRArZgdAxTqVx8vjMGLW5nHtWdRguiRi1'; - BITBOX.ECPair.fromWIF(wif); + bitbox.ECPair.fromWIF(wif); // testnet WIF let wif = 'cSNLj6xeg3Yg2rfcgKoWNx4MiAgn9ugCUUro37UDEhn6CzeYqjWW' - BITBOX.ECPair.fromWIF(wif) + bitbox.ECPair.fromWIF(wif) ### `toWIF` @@ -43,17 +43,17 @@ wif `string`: private key in wallet import format // mainnet wif let wif = 'L4vmKsStbQaCvaKPnCzdRArZgdAxTqVx8vjMGLW5nHtWdRguiRi1'; // ecpair from wif - let ecpair = BITBOX.ECPair.fromWIF(wif); + let ecpair = bitbox.ECPair.fromWIF(wif); // wif from ecpair - BITBOX.ECPair.toWIF(ecpair); + bitbox.ECPair.toWIF(ecpair); // L4vmKsStbQaCvaKPnCzdRArZgdAxTqVx8vjMGLW5nHtWdRguiRi1 // testnet wif let wif = 'cT3tJP7BnjFJSAHbooMXrY8E9t2AFj37amSBAYFMeHfqPqPgD4ZA'; // ecpair from wif - let ecpair = BITBOX.ECPair.fromWIF(wif); + let ecpair = bitbox.ECPair.fromWIF(wif); // wif from ecpair - BITBOX.ECPair.toWIF(ecpair); + bitbox.ECPair.toWIF(ecpair); // cT3tJP7BnjFJSAHbooMXrY8E9t2AFj37amSBAYFMeHfqPqPgD4ZA ### `fromPublicKey` @@ -72,11 +72,11 @@ ecpair `ECPair` // create ECPair from mainnet pubkeyBuffer let pubkeyBuffer = Buffer.from("02fb721b92025e775b1b84774e65d568d24645cb633275f5c26f5c3101b214a8fb", 'hex'); - BITBOX.ECPair.fromPublicKey(pubkeyBuffer); + bitbox.ECPair.fromPublicKey(pubkeyBuffer); // create ECPair from testnet pubkeyBuffer let pubkeyBuffer = Buffer.from("024a6d0737a23c472d078d78c1cbc3c2bbf8767b48e72684ff03a911b463da7fa6", 'hex'); - BITBOX.ECPair.fromPublicKey(pubkeyBuffer); + bitbox.ECPair.fromPublicKey(pubkeyBuffer); ### `toPublicKey` @@ -93,15 +93,15 @@ buffer `Buffer`: public key of an ECPair as a buffer #### Examples // create ecpair from mainnet public key buffer - let ecpair = BITBOX.ECPair.fromPublicKey(Buffer.from('02d305772e0873fba6c1c7ff353ce374233316eb5820acd7ff3d7d9b82d514126b', 'hex')); + let ecpair = bitbox.ECPair.fromPublicKey(Buffer.from('02d305772e0873fba6c1c7ff353ce374233316eb5820acd7ff3d7d9b82d514126b', 'hex')); // create public key buffer - BITBOX.ECPair.toPublicKey(ecpair); + bitbox.ECPair.toPublicKey(ecpair); // // create ecpair from testnet public key buffer - let ecpair = BITBOX.ECPair.fromPublicKey(Buffer.from('024a6d0737a23c472d078d78c1cbc3c2bbf8767b48e72684ff03a911b463da7fa6', 'hex')); + let ecpair = bitbox.ECPair.fromPublicKey(Buffer.from('024a6d0737a23c472d078d78c1cbc3c2bbf8767b48e72684ff03a911b463da7fa6', 'hex')); // create public key buffer - BITBOX.ECPair.toPublicKey(ecpair); + bitbox.ECPair.toPublicKey(ecpair); // ### `toLegacyAddress` @@ -121,17 +121,17 @@ legacyAddress `string`: legacy base58check encoded address of an ECPair // mainnet wif let wif = 'L5GPEGxCmojgzFoBLUUqT2GegLGqobiYhTZzfLtpkLTfTb9E9NRn'; // ecpair from wif - let ecpair = BITBOX.ECPair.fromWIF(wif); + let ecpair = bitbox.ECPair.fromWIF(wif); // to legacy address - BITBOX.ECPair.toLegacyAddress(ecpair); + bitbox.ECPair.toLegacyAddress(ecpair); // 1DgxdA5bbMcCNWg3yB2MgKqFazV92BXgxK // testnet wif let wif = 'cSNLj6xeg3Yg2rfcgKoWNx4MiAgn9ugCUUro37UDEhn6CzeYqjWW'; // ecpair from wif - let ecpair = BITBOX.ECPair.fromWIF(wif); + let ecpair = bitbox.ECPair.fromWIF(wif); // to legacy address - BITBOX.ECPair.toLegacyAddress(ecpair); + bitbox.ECPair.toLegacyAddress(ecpair); // mg4PygFcXoyNJGJkM2Dcpe25av9wXzz1My ### `toCashAddress` @@ -141,7 +141,7 @@ Get cash address of ECPair #### Arguments 1. ecpair `ECPair` -2. regtest `Boolean` optional: return regtest address +2. regtest `boolean` **optional**: return regtest address #### Result @@ -152,17 +152,17 @@ cashAddress `string`: cashaddr encoded address of an ECPair // mainnet wif let wif = 'L5GPEGxCmojgzFoBLUUqT2GegLGqobiYhTZzfLtpkLTfTb9E9NRn'; // ecpair from wif - let ecpair = BITBOX.ECPair.fromWIF(wif); + let ecpair = bitbox.ECPair.fromWIF(wif); // to legacy address - BITBOX.ECPair.toCashAddress(ecpair); + bitbox.ECPair.toCashAddress(ecpair); // bitcoincash:qz9nq206kteyv2t7trhdr4vzzkej60kqtytn7sxkxm // testnet wif let wif = 'cSNLj6xeg3Yg2rfcgKoWNx4MiAgn9ugCUUro37UDEhn6CzeYqjWW'; // ecpair from wif - let ecpair = BITBOX.ECPair.fromWIF(wif); + let ecpair = bitbox.ECPair.fromWIF(wif); // to legacy address - BITBOX.ECPair.toCashAddress(ecpair); + bitbox.ECPair.toCashAddress(ecpair); // bchtest:qqzly4vrcxcjw62u4yq4nv86ltk2mc9v0yvq8mvj6m ### `sign` @@ -173,6 +173,7 @@ Sign 32 byte hash encoded as a buffer 1. ecpair `ECPair` 2. buffer `Buffer`: 32 byte Buffer +3. signatureAlgorithm: `number` **optional**. `0x00` for ECDSA and `0x01` for Schnorr. Defaults to `0x00` #### Result @@ -183,20 +184,20 @@ signature `Object` // mainnet wif let wif = 'Kxq2EzVbDwjquUt5zyCFED5FRt99RZKEKVDJWTQcpSDoLAWMqLer'; // ecpair from wif - let ecpair = BITBOX.ECPair.fromWIF(wif); + let ecpair = bitbox.ECPair.fromWIF(wif); // 32 byte buffer - let buf = Buffer.from(BITBOX.Crypto.sha256('EARTH'), 'hex'); + let buf = Buffer.from(bitbox.Crypto.sha256('EARTH'), 'hex'); // sign - BITBOX.ECPair.sign(ecpair, buf); + bitbox.ECPair.sign(ecpair, buf); // testnet wif let wif = 'cT3tJP7BnjFJSAHbooMXrY8E9t2AFj37amSBAYFMeHfqPqPgD4ZA'; // ecpair from wif - let ecpair = BITBOX.ECPair.fromWIF(wif); + let ecpair = bitbox.ECPair.fromWIF(wif); // 32 byte buffer - let buf = Buffer.from(BITBOX.Crypto.sha256('EARTH'), 'hex'); + let buf = Buffer.from(bitbox.Crypto.sha256('EARTH'), 'hex'); // sign - BITBOX.ECPair.sign(ecpair, buf); + bitbox.ECPair.sign(ecpair, buf); ### `verify` @@ -206,11 +207,11 @@ Verify signed 32 byte hash encoded as a buffer 1. ecpair `ECPair` 2. buffer `Buffer`: 32 byte Buffer -3. signature `Object` +3. signature `ECSignature` #### Result -verified `Boolean` +verified `boolean` #### Examples @@ -218,29 +219,29 @@ verified `Boolean` let wif1 = 'Kxq2EzVbDwjquUt5zyCFED5FRt99RZKEKVDJWTQcpSDoLAWMqLer'; let wif2 = 'L4BwXDmjzEyzKHbAfGruhieUDPs8KTx7DMgqPk4aF9GefzgqPENV'; // ecpairs from wifs - let ecpair1 = BITBOX.ECPair.fromWIF(wif1); - let ecpair2 = BITBOX.ECPair.fromWIF(wif2); + let ecpair1 = bitbox.ECPair.fromWIF(wif1); + let ecpair2 = bitbox.ECPair.fromWIF(wif2); // 32 byte buffer - let buf = Buffer.from(BITBOX.Crypto.sha256('EARTH'), 'hex'); + let buf = Buffer.from(bitbox.Crypto.sha256('EARTH'), 'hex'); // sign - let signature = BITBOX.ECPair.sign(ecpair1, buf); + let signature = bitbox.ECPair.sign(ecpair1, buf); // verify - BITBOX.ECPair.verify(ecpair1, buf, signature); + bitbox.ECPair.verify(ecpair1, buf, signature); // true - BITBOX.ECPair.verify(ecpair2, buf, signature); + bitbox.ECPair.verify(ecpair2, buf, signature); // false // testnet wifs let wif1 = 'cT3tJP7BnjFJSAHbooMXrY8E9t2AFj37amSBAYFMeHfqPqPgD4ZA'; let wif2 = 'cRaFawZ49jEV2X3byAV4iGBYCRBVU8PoBzUMVToeEbFeVzbH4Gi7'; // ecpairs from wifs - let ecpair1 = BITBOX.ECPair.fromWIF(wif1); - let ecpair2 = BITBOX.ECPair.fromWIF(wif2); + let ecpair1 = bitbox.ECPair.fromWIF(wif1); + let ecpair2 = bitbox.ECPair.fromWIF(wif2); // 32 byte buffer - let buf = Buffer.from(BITBOX.Crypto.sha256('EARTH'), 'hex'); + let buf = Buffer.from(bitbox.Crypto.sha256('EARTH'), 'hex'); // sign - let signature = BITBOX.ECPair.sign(ecpair1, buf); + let signature = bitbox.ECPair.sign(ecpair1, buf); // verify - BITBOX.ECPair.verify(ecpair1, buf, signature); + bitbox.ECPair.verify(ecpair1, buf, signature); // true - BITBOX.ECPair.verify(ecpair2, buf, signature); + bitbox.ECPair.verify(ecpair2, buf, signature); diff --git a/src/data/docs/bitbox/getting-started.md b/src/data/docs/bitbox/getting-started.md index ae9c0413..fa75c723 100644 --- a/src/data/docs/bitbox/getting-started.md +++ b/src/data/docs/bitbox/getting-started.md @@ -16,15 +16,118 @@ Use the official installer from [nodejs.org](https://nodejs.org/). Install the o To use commands like `new` and `console`: - npm install bitbox-sdk --global + npm install bitbox-cli --global + // installs a `bitbox` command -To use inside a command line script or client/server app: +To use inside a client/server app: npm install bitbox-sdk --save ### Usage -Use the [scaffold generator](./new), or manually import BITBOX into your code: +Import BITBOX into your code: - let BITBOXSDK = require('bitbox-sdk'); - let BITBOX = new BITBOXSDK(); + // require syntax + let BITBOX = require('bitbox-sdk').BITBOX; + let bitbox = new BITBOX(); + bitbox.Mnemonic.generate() + // couple sleep cruise hybrid physical nature spin hedgehog put paddle silver laundry + + // import syntax + import { BITBOX } from 'bitbox-sdk' + let bitbox = new BITBOX(); + bitbox.Mnemonic.generate() + // whip mind item rapid use cigar gap inherit shove weasel similar stick + +All classes are able to be included via both `require` and `import` + + // require syntax + const Address = require("bitbox-sdk").Address + let address = new Address() + const BitcoinCash = require("bitbox-sdk").BitcoinCash + let bitcoincash = new BitcoinCash() + const BitDB = require("bitbox-sdk").BitDB + let bitdb = new BitDB() + const Block = require("bitbox-sdk").Block + let block = new Block() + const Blockchain = require("bitbox-sdk").Blockchain + let blockchain = new Blockchain + const CashAccounts = require("bitbox-sdk").CashAccounts + let cashAccounts = new CashAccounts() + const Control = require("bitbox-sdk").Control + let control = new Control() + const Crypto = require("bitbox-sdk").Crypto + let crypto = new Crypto() + const ECPair = require("bitbox-sdk").ECPair + let ecpair = new ECPair() + const Generating = require("bitbox-sdk").Generating + let generating = new Generating() + const HDNode = require("bitbox-sdk").HDNode + let hdnode = new HDNode() + const Mining = require("bitbox-sdk").Mining + let mining = new Mining() + const Mnemonic = require("bitbox-sdk").Mnemonic + let mnemonic = new Mnemonic() + const Price = require("bitbox-sdk").Price + let price = new Price() + const RawTransactions = require("bitbox-sdk").RawTransactions + let rawtransactions = new RawTransactions() + const Schnorr = require("bitbox-sdk").Schnorr + let schnorr = new Schnorr + const Script = require("bitbox-sdk").Script + let script = new Script() + const Socket = require("bitbox-sdk").Socket + let socket = new Socket() + const Transaction = require("bitbox-sdk").Transaction + let transaction = new Transaction + const TransactionBuilder = require("bitbox-sdk").TransactionBuilder + let transactionbuilder = new TransactionBuilder() + const Util = require("bitbox-sdk").Util + let util = new Util() + + // import syntax + import { + Address, + BitcoinCash, + BitDB, + Block, + Blockchain, + CashAccounts, + Control, + Crypto, + ECPair, + Generating, + HDNode, + Mining, + Mnemonic, + Price, + RawTransactions, + Schnorr, + Script, + Socket, + Transaction, + TransactionBuilder, + Util + } from "bitbox-sdk" + + let address = new Address() + let bitcoincash = new BitcoinCash() + let bitdb = new BitDB() + let block = new Block() + let blockchain = new Blockchain + let cashAccounts = new CashAccounts() + let control = new Control() + let crypto = new Crypto() + let ecpair = new ECPair() + let generating = new Generating() + let hdnode = new HDNode() + let mining = new Mining() + let mnemonic = new Mnemonic() + let price = new Price() + let rawtransactions = new RawTransactions() + let schnorr = new Schnorr + let script = new Script() + let socket = new Socket() + let transaction = new Transaction + let transactionbuilder = new TransactionBuilder() + let util = new Util() diff --git a/src/data/docs/bitbox/hdnode.md b/src/data/docs/bitbox/hdnode.md index 1ba05f01..f6bab402 100644 --- a/src/data/docs/bitbox/hdnode.md +++ b/src/data/docs/bitbox/hdnode.md @@ -1,85 +1,89 @@ --- title: HDNode icon: code-branch -ordinal: 10 +ordinal: 12 --- +HDNode stands for Hierarchically Deterministic node which can be used to create a [HD wallet](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#hierarchical-deterministic-wallets-bip0032bip0044). + ### `fromSeed` -Create HDNode from Seed Buffer +Create HDNode from Seed Buffer. #### Arguments 1. rootSeed `Buffer`: root seed buffer -2. network `String` **optional**: network. default: 'mainnet' +2. network `string` **optional**: network. default: 'mainnet' #### Result -HDNode HDNode +HDNode `HDNode` #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - BITBOX.HDNode.fromSeed(seedBuffer); + bitbox.HDNode.fromSeed(seedBuffer); // generate entropy - let entropy = BITBOX.Crypto.randomBytes(32); + let entropy = bitbox.Crypto.randomBytes(32); // create mnemonic from entropy - let mnemonic = BITBOX.Mnemonic.fromEntropy(entropy); + let mnemonic = bitbox.Mnemonic.fromEntropy(entropy); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - BITBOX.HDNode.fromSeed(seedBuffer); + bitbox.HDNode.fromSeed(seedBuffer); ### `derive` -Derive non hardened child HDNode +Derive [non hardened](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#hardened-child-key-derivation) child HDNode #### Arguments -1. num `number`: number of child node. Ex: 0 +1. hdnode `HDNode` +2. num `number`: number of child node. Ex: 0 #### Result -HDNode HDNode +HDNode `HDNode` #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // derive unhardened child HDNode - BITBOX.HDNode.derive(hdNode, 0); + bitbox.HDNode.derive(hdNode, 0); ### `deriveHardened` -Derive hardened child HDNode +Derive [hardened](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#hardened-child-key-derivation) child HDNode #### Arguments -1. num `number`: number of child node. Ex: 0 +1. hdnode `HDNode` +2. num `number`: number of child node. Ex: 0 #### Result -HDNode HDNode +HDNode `HDNode` #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // derive hardened child HDNode - BITBOX.HDNode.deriveHardened(hdNode, 0); + bitbox.HDNode.deriveHardened(hdNode, 0); ### `derivePath` @@ -87,22 +91,23 @@ Derive child HDNode from path #### Arguments -1. path `string`: path of child hd node. Ex: "m/44'/145'/0'" +1. hdnode `HDNode` +2. path `string`: path of child hd node. Ex: "m/44'/145'/0'" #### Result -HDNode HDNode +HDNode `HDNode` #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // derive hardened child HDNode - BITBOX.HDNode.derivePath(hdNode, "m/44'/145'/0'"); + bitbox.HDNode.derivePath(hdNode, "m/44'/145'/0'"); ### `toLegacyAddress` @@ -110,7 +115,7 @@ Get legacy address of HDNode #### Arguments -1. hdNode: HDNode +1. hdnode `HDNode` #### Result @@ -119,25 +124,25 @@ legacyAddress `string`: legacy base58check encoded address of HDNode #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // to legacy address - BITBOX.HDNode.toLegacyAddress(hdNode); + bitbox.HDNode.toLegacyAddress(hdNode); // 14apxtw2LDQmXWsS5k4JEhG93Jzjswhvma // generate entropy - let entropy = BITBOX.Crypto.randomBytes(32); + let entropy = bitbox.Crypto.randomBytes(32); // create mnemonic from entropy - let mnemonic = BITBOX.Mnemonic.fromEntropy(entropy); + let mnemonic = bitbox.Mnemonic.fromEntropy(entropy); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // to cash address - BITBOX.HDNode.toLegacyAddress(hdNode); + bitbox.HDNode.toLegacyAddress(hdNode); // 14mVsq3H5Ep2Jb6AqoKsmY1BFHKCBGPDLi ### `toCashAddress` @@ -146,8 +151,8 @@ Get cash address of HDNode #### Arguments -1. hdNode: HDNode -2. regtest `Boolean` optional: return regtest address +1. hdnode `HDNode` +2. regtest `boolean` **optional**: return regtest address #### Result @@ -156,25 +161,25 @@ cashAddress `string`: cashaddr encoded address of HDNode #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // to cash address - BITBOX.HDNode.toCashAddress(hdNode); + bitbox.HDNode.toCashAddress(hdNode); // bitcoincash:qqrz6kqw6nvhwgwrt4g7fggepvewtkr7nukkeqf4rw // generate entropy - let entropy = BITBOX.Crypto.randomBytes(32); + let entropy = bitbox.Crypto.randomBytes(32); // create mnemonic from entropy - let mnemonic = BITBOX.Mnemonic.fromEntropy(entropy); + let mnemonic = bitbox.Mnemonic.fromEntropy(entropy); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // to cash address - BITBOX.HDNode.toCashAddress(hdNode); + bitbox.HDNode.toCashAddress(hdNode); // bitcoincash:qq549jxsjv66kw0smdju4es2axnk7hhe9cquhjg4gt ### `toWIF` @@ -183,7 +188,7 @@ Get private key in wallet import format (WIF) of HDNode #### Arguments -1. hdNode: HDNode +1. hdnode `HDNode` #### Result @@ -192,34 +197,34 @@ privateKeyWIF `string`: private key in wallet import format (WIF) of HDNode #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // to WIF - BITBOX.HDNode.toWIF(hdNode); + bitbox.HDNode.toWIF(hdNode); // L5E8QjFnLukp8BuF4uu9gmvvSrbafioURGdBve5tA3Eq5ptzbMCJ // generate entropy - let entropy = BITBOX.Crypto.randomBytes(32); + let entropy = bitbox.Crypto.randomBytes(32); // create mnemonic from entropy - let mnemonic = BITBOX.Mnemonic.fromEntropy(entropy); + let mnemonic = bitbox.Mnemonic.fromEntropy(entropy); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // to WIF - BITBOX.HDNode.toWIF(hdNode); + bitbox.HDNode.toWIF(hdNode); // KwobPFhv3AuXc3ps6YtWfMVRpLBDBA7jnJddurfELTyTNcFhZYpJ ### `toXPub` -Get extended public key of HDNode +Get [extended](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#extended-keys) [public key](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#public-key-cryptography-and-cryptocurrency) of HDNode #### Arguments -1. hdNode: HDNode +1. hdnode `HDNode` #### Result @@ -228,34 +233,34 @@ xpub `string`: extended public key of HDNode #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // to extended public key - BITBOX.HDNode.toXPub(hdNode); + bitbox.HDNode.toXPub(hdNode); // xpub661MyMwAqRbcG4CnhNYoK1r1TKLwQQ1UdC3LHoWFK61rsnzh7Hx35qQ9Z53ucYcE5WvA7GEDXhqqKjSY2e6Y8n7WNVLYHpXCuuX945VPuYn // generate entropy - let entropy = BITBOX.Crypto.randomBytes(32); + let entropy = bitbox.Crypto.randomBytes(32); // create mnemonic from entropy - let mnemonic = BITBOX.Mnemonic.fromEntropy(entropy); + let mnemonic = bitbox.Mnemonic.fromEntropy(entropy); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // to extended public key - BITBOX.HDNode.toXPub(hdNode); + bitbox.HDNode.toXPub(hdNode); // xpub661MyMwAqRbcFuMLeHkSbTNwNHG9MQyrAZqV1Q4MEAsmj9MYa5sxg8WC2LKqW6EHviHVucBjWi1n38juZpDDeX3U6YrsMeACdcNSTHkM8BQ ### `toXPriv` -Get extended private key of HDNode +Get [extended](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#extended-keys) [private key](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#private-keys) of HDNode #### Arguments -1. hdNode: HDNode +1. hdnode `HDNode` #### Result @@ -264,25 +269,25 @@ xpriv `string`: extended private key of HDNode #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // to extended private key - BITBOX.HDNode.toXPriv(hdNode); + bitbox.HDNode.toXPriv(hdNode); // xprv9s21ZrQH143K2eMCcbT4qwwRhw6qZaPaEDWB792bnrxQZPoP2JUk4kfEx9eeV1uGTAWAfCqYr4wDWo52qALiukizKwQzvEyNR1fWZJi97Kv // generate entropy - let entropy = BITBOX.Crypto.randomBytes(32); + let entropy = bitbox.Crypto.randomBytes(32); // create mnemonic from entropy - let mnemonic = BITBOX.Mnemonic.fromEntropy(entropy); + let mnemonic = bitbox.Mnemonic.fromEntropy(entropy); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // to extended private key - BITBOX.HDNode.toXPriv(hdNode); + bitbox.HDNode.toXPriv(hdNode); // xprv9s21ZrQH143K2b5GPP6zHz22E6LeCgQXJtwNbC3MA3Kz7Se7tveKo96EhqwFtSkYWkyenVcMqM7uq35PcUNG8cUdpsJEgwKG3dvfP7TmL3v ### `toKeyPair` @@ -291,7 +296,7 @@ Get the ECPair of an HDNode #### Arguments -1. hdNode: HDNode +1. hdnode `HDNode` #### Result @@ -300,25 +305,24 @@ keyPair `ECPair`: ECPair of an HDNode #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create root seed buffer from mnemonic - let rootSeed= BITBOX.Mnemonic.toSeed(mnemonic); + let rootSeed= bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from root seed - let hdNode = BITBOX.HDNode.fromSeed(rootSeed); + let hdNode = bitbox.HDNode.fromSeed(rootSeed); // create public key buffer from HDNode - BITBOX.HDNode.toKeyPair(hdNode); + bitbox.HDNode.toKeyPair(hdNode); // generate entropy - let entropy = BITBOX.Crypto.randomBytes(32); + let entropy = bitbox.Crypto.randomBytes(32); // create mnemonic from entropy - let mnemonic = BITBOX.Mnemonic.fromEntropy(entropy); + let mnemonic = bitbox.Mnemonic.fromEntropy(entropy); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // create public key buffer from HDNode - BITBOX.HDNode.toKeyPair(hdNode); - // + bitbox.HDNode.toKeyPair(hdNode); ### `toPublicKey` @@ -326,7 +330,7 @@ Get the public key of an HDNode as a buffer #### Arguments -1. hdNode: HDNode +1. hdnode `HDNode` #### Result @@ -335,26 +339,26 @@ publicKeyBuffer `Buffer`: public key of HDNode as a buffer #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create root seed buffer from mnemonic - let rootSeed= BITBOX.Mnemonic.toSeed(mnemonic); + let rootSeed= bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from root seed - let hdNode = BITBOX.HDNode.fromSeed(rootSeed); + let hdNode = bitbox.HDNode.fromSeed(rootSeed); // create public key buffer from HDNode - BITBOX.HDNode.toPublicKey(hdNode); - // + bitbox.HDNode.toPublicKey(hdNode); + // // generate entropy - let entropy = BITBOX.Crypto.randomBytes(32); + let entropy = bitbox.Crypto.randomBytes(32); // create mnemonic from entropy - let mnemonic = BITBOX.Mnemonic.fromEntropy(entropy); + let mnemonic = bitbox.Mnemonic.fromEntropy(entropy); // create seed buffer from mnemonic - let seedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let seedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create HDNode from seed buffer - let hdNode = BITBOX.HDNode.fromSeed(seedBuffer); + let hdNode = bitbox.HDNode.fromSeed(seedBuffer); // create public key buffer from HDNode - BITBOX.HDNode.toPublicKey(hdNode); - // + bitbox.HDNode.toPublicKey(hdNode); + // ### `toIdentifier` @@ -366,29 +370,29 @@ hash160 of Node’s public key. The same value you would see in a scriptPubKey. #### Result -identifier `string` +identifier `Buffer` #### Examples // mainnet let xpub = 'xpub6DWfGUo4cjC8oWmgZdpyFMH6v3oeyADfdUPhsehzn5jX44zpazivha3JxUtkcCvBEB1c6DGaiUmpyz2m1DRfGDEVZ5VxLLW2UNEbZ5iTRvi'; - let node = BITBOX.HDNode.fromXPub(xpub); - BITBOX.HDNode.toIdentifier(node); - // + let node = bitbox.HDNode.fromXPub(xpub); + bitbox.HDNode.toIdentifier(node); + // // the same as if we hash160ed it's publicKey - let publicKeyBuffer = BITBOX.HDNode.toPublicKey(node); - BITBOX.Crypto.hash160(publicKeyBuffer); - // + let publicKeyBuffer = bitbox.HDNode.toPublicKey(node); + bitbox.Crypto.hash160(publicKeyBuffer); + // // testnet let xpub = 'tpubDCxmZ3qLVVphg6NpsnAjQFqDPwr9HYqSgoAcUYAfqSgo32dL6NA8QXqWsS6XTjoGggohZKvujsAv2F2ugej9qfUYau2jSUB4JaYnfMsx3MJ'; - let node = BITBOX.HDNode.fromXPub(xpub); - BITBOX.HDNode.toIdentifier(node); - // + let node = bitbox.HDNode.fromXPub(xpub); + bitbox.HDNode.toIdentifier(node); + // // the same as if we hash160ed it's publicKey - let publicKeyBuffer = BITBOX.HDNode.toPublicKey(node); - BITBOX.Crypto.hash160(publicKeyBuffer); - // + let publicKeyBuffer = bitbox.HDNode.toPublicKey(node); + bitbox.Crypto.hash160(publicKeyBuffer); + // ### `fromXPriv` @@ -396,7 +400,7 @@ Generate HDNode from extended private key #### Arguments -1. xpriv: extended private key +1. xpriv `string`: extended private key #### Result @@ -405,10 +409,10 @@ hdNode `HDNode` #### Examples // mainnet xpriv - BITBOX.HDNode.fromXPriv('xprv9s21ZrQH143K2b5GPP6zHz22E6LeCgQXJtwNbC3MA3Kz7Se7tveKo96EhqwFtSkYWkyenVcMqM7uq35PcUNG8cUdpsJEgwKG3dvfP7TmL3v'); + bitbox.HDNode.fromXPriv('xprv9s21ZrQH143K2b5GPP6zHz22E6LeCgQXJtwNbC3MA3Kz7Se7tveKo96EhqwFtSkYWkyenVcMqM7uq35PcUNG8cUdpsJEgwKG3dvfP7TmL3v'); // testnet xpriv - BITBOX.HDNode.fromXPriv('tprv8gQ3zr1F5pRHMebqqhorrorYNvUG3XkcZjSWVs2cEtRwwJy1TRhgRx4XcF8dYHM2eyTbTCcdKYNhqgyBQphxwRoVyVKr9zuyoA8WxNDRvom'); + bitbox.HDNode.fromXPriv('tprv8gQ3zr1F5pRHMebqqhorrorYNvUG3XkcZjSWVs2cEtRwwJy1TRhgRx4XcF8dYHM2eyTbTCcdKYNhqgyBQphxwRoVyVKr9zuyoA8WxNDRvom'); ### `fromXPub` @@ -416,7 +420,7 @@ Generate HDNode from extended public key #### Arguments -1. xpub: extended public key +1. xpub `string`: extended public key #### Result @@ -425,10 +429,10 @@ hdNode `HDNode` #### Examples // mainnet xpub - BITBOX.HDNode.fromXPub('xpub661MyMwAqRbcFuMLeHkSbTNwNHG9MQyrAZqV1Q4MEAsmj9MYa5sxg8WC2LKqW6EHviHVucBjWi1n38juZpDDeX3U6YrsMeACdcNSTHkM8BQ'); + bitbox.HDNode.fromXPub('xpub661MyMwAqRbcFuMLeHkSbTNwNHG9MQyrAZqV1Q4MEAsmj9MYa5sxg8WC2LKqW6EHviHVucBjWi1n38juZpDDeX3U6YrsMeACdcNSTHkM8BQ'); // testnet xpub - BITBOX.HDNode.fromXPub('tpubDD669G3VEC6xF7ddjMUTGDWewwzCCrwX933HnP4ufAELmoDn5pXGcSgPnLodjFvWQwRXkG94f77BatEDA8dfQ99yy97kRYynUpNLENEqTBo'); + bitbox.HDNode.fromXPub('tpubDD669G3VEC6xF7ddjMUTGDWewwzCCrwX933HnP4ufAELmoDn5pXGcSgPnLodjFvWQwRXkG94f77BatEDA8dfQ99yy97kRYynUpNLENEqTBo'); ### `isPublic` @@ -440,32 +444,32 @@ Check if an HDNode can only derive public keys and children #### Result -isPublic `Boolean` +isPublic `boolean` #### Examples // mainnet xpub let xpub = 'xpub6DWfGUo4cjC8oWmgZdpyFMH6v3oeyADfdUPhsehzn5jX44zpazivha3JxUtkcCvBEB1c6DGaiUmpyz2m1DRfGDEVZ5VxLLW2UNEbZ5iTRvi'; - let node = BITBOX.HDNode.fromXPub(xpub); - BITBOX.HDNode.isPublic(node); + let node = bitbox.HDNode.fromXPub(xpub); + bitbox.HDNode.isPublic(node); // true // mainnet xpriv let xpriv = 'xprv9ys4cvcoU8RoxqkZ7Fgt33te4LPHgcsKwyoZYVorkzp9uonWxWgP9wiSQhPeBUqVHbdAyov4Yi55RywBkDfZKdJFRqA51Anz6v72zGaMGZp'; - let node = BITBOX.HDNode.fromXPriv(xpriv); - BITBOX.HDNode.isPublic(node); + let node = bitbox.HDNode.fromXPriv(xpriv); + bitbox.HDNode.isPublic(node); // false // testnet xpub let xpub = 'tpubDCxmZ3qLVVphg6NpsnAjQFqDPwr9HYqSgoAcUYAfqSgo32dL6NA8QXqWsS6XTjoGggohZKvujsAv2F2ugej9qfUYau2jSUB4JaYnfMsx3MJ'; - let node = BITBOX.HDNode.fromXPub(xpub); - BITBOX.HDNode.isPublic(node); + let node = bitbox.HDNode.fromXPub(xpub); + bitbox.HDNode.isPublic(node); // true // testnet xpriv let xpriv = 'tprv8ggxJ8SG5EdqakzVUeLa9Gr7sqCdEcJPUNDmtdJscNxfmxoXvU36ZguiUWukJVEWEixAUr8pJabJkCt33wzxFQA587gqN51Lxdxx97zAzuG'; - let node = BITBOX.HDNode.fromXPriv(xpriv); - BITBOX.HDNode.isPublic(node); + let node = bitbox.HDNode.fromXPriv(xpriv); + bitbox.HDNode.isPublic(node); // false ### `isPrivate` @@ -478,32 +482,32 @@ Check if an HDNode can derive both public and private keys and children #### Result -isPrivate `Boolean` +isPrivate `boolean` #### Examples // mainnet xpub let xpub = 'xpub6DWfGUo4cjC8oWmgZdpyFMH6v3oeyADfdUPhsehzn5jX44zpazivha3JxUtkcCvBEB1c6DGaiUmpyz2m1DRfGDEVZ5VxLLW2UNEbZ5iTRvi'; - let node = BITBOX.HDNode.fromXPub(xpub); - BITBOX.HDNode.isPrivate(node); + let node = bitbox.HDNode.fromXPub(xpub); + bitbox.HDNode.isPrivate(node); // false // mainnet xpriv let xpriv = 'xprv9ys4cvcoU8RoxqkZ7Fgt33te4LPHgcsKwyoZYVorkzp9uonWxWgP9wiSQhPeBUqVHbdAyov4Yi55RywBkDfZKdJFRqA51Anz6v72zGaMGZp'; - let node = BITBOX.HDNode.fromXPriv(xpriv); - BITBOX.HDNode.isPrivate(node); + let node = bitbox.HDNode.fromXPriv(xpriv); + bitbox.HDNode.isPrivate(node); // true // testnet xpub let xpub = 'tpubDCxmZ3qLVVphg6NpsnAjQFqDPwr9HYqSgoAcUYAfqSgo32dL6NA8QXqWsS6XTjoGggohZKvujsAv2F2ugej9qfUYau2jSUB4JaYnfMsx3MJ'; - let node = BITBOX.HDNode.fromXPub(xpub); - BITBOX.HDNode.isPrivate(node); + let node = bitbox.HDNode.fromXPub(xpub); + bitbox.HDNode.isPrivate(node); // false // testnet xpriv let xpriv = 'tprv8ggxJ8SG5EdqakzVUeLa9Gr7sqCdEcJPUNDmtdJscNxfmxoXvU36ZguiUWukJVEWEixAUr8pJabJkCt33wzxFQA587gqN51Lxdxx97zAzuG'; - let node = BITBOX.HDNode.fromXPriv(xpriv); - BITBOX.HDNode.isPrivate(node); + let node = bitbox.HDNode.fromXPriv(xpriv); + bitbox.HDNode.isPrivate(node); // true ### `sign` @@ -517,27 +521,27 @@ Sign 32 byte hash encoded as a buffer #### Result -signature `Object` +signature `ECSignature` #### Examples // mainnet xpriv let xpriv = 'xprv9z2uWrGjbYPxc728rvtMi4jt4SudRiSfYn6Tdif5XN17pJ1NTbHoHK6JePkPLY1NHXLaQcA6sWudpZDm7DwKhbsGQieAp9wx46Wbio4iXg9'; // hdnode from xpriv - let hdnode = BITBOX.HDNode.fromXPriv(xpriv); + let hdnode = bitbox.HDNode.fromXPriv(xpriv); // 32 byte buffer - let buf = Buffer.from(BITBOX.Crypto.sha256('EARTH'), 'hex'); + let buf = Buffer.from(bitbox.Crypto.sha256('EARTH'), 'hex'); // sign - BITBOX.HDNode.sign(hdnode, buf); + bitbox.HDNode.sign(hdnode, buf); // testnet xpriv let xpriv = 'tprv8ggxJ8SG5EdqakzVUeLa9Gr7sqCdEcJPUNDmtdJscNxfmxoXvU36ZguiUWukJVEWEixAUr8pJabJkCt33wzxFQA587gqN51Lxdxx97zAzuG'; // hdnode from xpriv - let hdnode = BITBOX.HDNode.fromXPriv(xpriv); + let hdnode = bitbox.HDNode.fromXPriv(xpriv); // 32 byte buffer - let buf = Buffer.from(BITBOX.Crypto.sha256('EARTH'), 'hex'); + let buf = Buffer.from(bitbox.Crypto.sha256('EARTH'), 'hex'); // sign - BITBOX.HDNode.sign(hdnode, buf); + bitbox.HDNode.sign(hdnode, buf); ### `verify` @@ -547,11 +551,11 @@ Verify signed 32 byte hash encoded as a buffer 1. hdnode `HDNode` 2. buffer `Buffer` -3. signature `Object` +3. signature `ECSignature` #### Result -verified `Boolean` +verified `boolean` #### Examples @@ -559,32 +563,32 @@ verified `Boolean` let xpriv1 = 'xprv9ys4cvcoU8RoqvzxGj886r4Ey3w1WfVNYH8sMnVPVzyQtaPPM6Q8pHm3D9WPWvEupGEgcJ1xLaGaZDcvKfoAurE2AzHRRRup5FuHzDr8n15'; let xpriv2 = 'xprv9ys4cvcoU8RoxqkZ7Fgt33te4LPHgcsKwyoZYVorkzp9uonWxWgP9wiSQhPeBUqVHbdAyov4Yi55RywBkDfZKdJFRqA51Anz6v72zGaMGZp'; // hdnodes from xprivs - let hdnode1 = BITBOX.HDNode.fromXPriv(xpriv1); - let hdnode2 = BITBOX.HDNode.fromXPriv(xpriv2); + let hdnode1 = bitbox.HDNode.fromXPriv(xpriv1); + let hdnode2 = bitbox.HDNode.fromXPriv(xpriv2); // 32 byte buffer - let buf = Buffer.from(BITBOX.Crypto.sha256('EARTH'), 'hex'); + let buf = Buffer.from(bitbox.Crypto.sha256('EARTH'), 'hex'); // sign - let signature = BITBOX.HDNode.sign(hdnode1, buf); + let signature = bitbox.HDNode.sign(hdnode1, buf); // verify - BITBOX.HDNode.verify(hdnode1, buf, signature); + bitbox.HDNode.verify(hdnode1, buf, signature); // true - BITBOX.HDNode.verify(hdnode2, buf, signature); + bitbox.HDNode.verify(hdnode2, buf, signature); // false // testnet xprivs let xpriv1 = 'tprv8ggxJ8SG5EdqakzVUeLa9Gr7sqCdEcJPUNDmtdJscNxfmxoXvU36ZguiUWukJVEWEixAUr8pJabJkCt33wzxFQA587gqN51Lxdxx97zAzuG'; let xpriv2 = 'tprv8ggxJ8SG5EdqiM6Dn63QwHScQ7HS5hXqUMxSD1NEbDyPw6VtoUMFZBAohpTMsPz9cYbpHELmA4Zm79NKRvEvFdhWRX2bSmu7V7PiNb364nv'; // hdnodes from xprivs - let hdnode1 = BITBOX.HDNode.fromXPriv(xpriv1); - let hdnode2 = BITBOX.HDNode.fromXPriv(xpriv2); + let hdnode1 = bitbox.HDNode.fromXPriv(xpriv1); + let hdnode2 = bitbox.HDNode.fromXPriv(xpriv2); // 32 byte buffer - let buf = Buffer.from(BITBOX.Crypto.sha256('EARTH'), 'hex'); + let buf = Buffer.from(bitbox.Crypto.sha256('EARTH'), 'hex'); // sign - let signature = BITBOX.ECPair.sign(hdnode1, buf); + let signature = bitbox.ECPair.sign(hdnode1, buf); // verify - BITBOX.HDNode.verify(hdnode1, buf, signature); + bitbox.HDNode.verify(hdnode1, buf, signature); // true - BITBOX.HDNode.verify(hdnode2, buf, signature); + bitbox.HDNode.verify(hdnode2, buf, signature); // false ### `createAccount` @@ -593,7 +597,7 @@ Create [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#th #### Arguments -1. hdNodes: Array of HDNodes +1. hdNodes `HDNode[]` #### Result @@ -602,15 +606,15 @@ account: `Object` #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create root seed buffer - let rootSeedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let rootSeedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create master hd node - let masterHDNode = BITBOX.HDNode.fromSeed(rootSeedBuffer); + let masterHDNode = bitbox.HDNode.fromSeed(rootSeedBuffer); // derive child node let childNode = masterHDNode.derivePath("m/44'/145'/0'/0"); // create account - let account = BITBOX.HDNode.createAccount([childNode]); + let account = bitbox.HDNode.createAccount([childNode]); ### `getChainAddress` @@ -618,24 +622,24 @@ Returns the latest address from account #### Arguments -1. account: `Number` +1. account: `number` #### Result -address: `String` +address: `string` #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create root seed buffer - let rootSeedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let rootSeedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create master hd node - let masterHDNode = BITBOX.HDNode.fromSeed(rootSeedBuffer); + let masterHDNode = bitbox.HDNode.fromSeed(rootSeedBuffer); // derive child node let childNode = masterHDNode.derivePath("m/44'/145'/0'/0"); // create account - let account = BITBOX.HDNode.createAccount([childNode]); + let account = bitbox.HDNode.createAccount([childNode]); account.getChainAddress(0) // 1EsibxXqzxzcor7eS34dSGrZp1kb3nQFFr @@ -645,24 +649,24 @@ Moves the most recent address forward for account #### Arguments -1. account: `Number` +1. account: `number` #### Result -address: `String` +address: `string` #### Examples // create mnemonic - let mnemonic = BITBOX.Mnemonic.generate(128); + let mnemonic = bitbox.Mnemonic.generate(128); // create root seed buffer - let rootSeedBuffer = BITBOX.Mnemonic.toSeed(mnemonic); + let rootSeedBuffer = bitbox.Mnemonic.toSeed(mnemonic); // create master hd node - let masterHDNode = BITBOX.HDNode.fromSeed(rootSeedBuffer); + let masterHDNode = bitbox.HDNode.fromSeed(rootSeedBuffer); // derive child node let childNode = masterHDNode.derivePath("m/44'/145'/0'/0"); // create account - let account = BITBOX.HDNode.createAccount([childNode]); + let account = bitbox.HDNode.createAccount([childNode]); account.getChainAddress(0) // 1EsibxXqzxzcor7eS34dSGrZp1kb3nQFFr account.nextChainAddress(0) diff --git a/src/data/docs/bitbox/mining.md b/src/data/docs/bitbox/mining.md index 5d21ea43..072a9fc5 100644 --- a/src/data/docs/bitbox/mining.md +++ b/src/data/docs/bitbox/mining.md @@ -1,7 +1,7 @@ --- title: Mining icon: hdd -ordinal: 11 +ordinal: 13 --- ### `getMiningInfo` @@ -10,24 +10,13 @@ Returns a json object containing mining-related information. #### Result -``` -{ - "blocks": nnn, (numeric) The current block - "currentblocksize": nnn, (numeric) The last block size - "currentblocktx": nnn, (numeric) The last block transaction - "difficulty": xxx.xxxxx (numeric) The current difficulty - "errors": "..." (string) Current errors - "networkhashps": nnn, (numeric) The network hashes per second - "pooledtx": n (numeric) The size of the mempool - "chain": "xxxx", (string) current network name as defined in BIP70 (main, test, regtest) -} -``` +miningInfo: `Promise` #### Examples (async () => { try { - let getMiningInfo = await BITBOX.Mining.getMiningInfo(); + let getMiningInfo = await bitbox.Mining.getMiningInfo(); console.log(getMiningInfo); } catch(error) { console.error(error) @@ -40,18 +29,18 @@ Returns the estimated network hashes per second based on the last n blocks. Pass #### Arguments -1. nblocks (numeric, optional, default=120): The number of blocks, or -1 for blocks since last difficulty change. -2. height (numeric, optional, default=-1): To estimate at the time of the given height. +1. nblocks `number` **optional**: The number of blocks, or -1 for blocks since last difficulty change. +2. height `number`, **optional**: To estimate at the time of the given height. #### Result -x (numeric): Hashes per second estimated +x `Promise`: Hashes per second estimated #### Examples (async () => { try { - let getNetworkHashps = await BITBOX.Mining.getNetworkHashps(); + let getNetworkHashps = await bitbox.Mining.getNetworkHashps(); console.log(getNetworkHashps); } catch(error) { console.error(error) diff --git a/src/data/docs/bitbox/mnemonic.md b/src/data/docs/bitbox/mnemonic.md index ba266a74..03f029e3 100644 --- a/src/data/docs/bitbox/mnemonic.md +++ b/src/data/docs/bitbox/mnemonic.md @@ -1,7 +1,7 @@ --- title: Mnemonic icon: elipses -ordinal: 12 +ordinal: 14 --- ### `generate` @@ -10,8 +10,8 @@ Generate [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) #### Arguments -1. randomBits `number`: number of random bits of entropy to use. The more bits the longer the mnemonic. -2. mnemonic word list `array` `optional`: list of words to generate the mnemonic from +1. randomBits `number` **optional**: number of random bits of entropy to use. The more bits the longer the mnemonic. +2. mnemonic word list `string[]` **optional**: list of words to generate the mnemonic from #### Result @@ -20,37 +20,41 @@ mnemonic `string` a random mnemonic #### Examples // generate 12 word mnemonic - BITBOX.Mnemonic.generate(128); + bitbox.Mnemonic.generate(128); // boil lonely casino manage habit where total glory muffin name limit mansion // generate 15 word mnemonic - BITBOX.Mnemonic.generate(160); + bitbox.Mnemonic.generate(160); // steak prevent estate save dance design close noise cheap season among train sleep ketchup gas // generate 18 word mnemonic - BITBOX.Mnemonic.generate(192); + bitbox.Mnemonic.generate(192); // fever endorse purpose normal fashion desert blood robust prevent clean guard display raise virtual again unit banana rich // generate 21 word mnemonic - BITBOX.Mnemonic.generate(224); + bitbox.Mnemonic.generate(224); // scan pink shock describe chicken edit budget exit camera morning awesome silk inner pair sea few flock walnut write mountain surface // generate 24 word mnemonic - BITBOX.Mnemonic.generate(256); + bitbox.Mnemonic.generate(256); // disagree tide elbow citizen jazz cinnamon bridge certain april settle pact film always inmate border inform solution that submit produce cloth balcony upper maid // generate 12 french word mnemonic - BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().french); + bitbox.Mnemonic.generate(128, bitbox.Mnemonic.wordLists().french); // annonce ampleur sanglier peser acheter cultiver abroger embellir résoudre dialogue grappin lanterne + // generate 256 bit korean word mnemonic + bitbox.Mnemonic.generate(256, bitbox.Mnemonic.wordLists().korean) + // 기능 단추 교육 비난 시집 근육 운동 코미디 숟가락 과목 한동안 유적 시리즈 삼월 앞날 유난히 흰색 사실 논문 장사 어른 논문 의논 장차 + ### `fromEntropy` Create mnemonic from entropy #### Arguments -1. randomBytes `Buffer`: buffer of random entropy. This entropy can be generated w/ BITBOX.Crypto.randomBytes. -2. mnemonic word list `array` `optional`: list of words to generate the mnemonic from +1. randomBytes `Buffer`: buffer of random entropy. This entropy can be generated w/ `bitbox.Crypto.randomBytes`. +2. mnemonic word list `string[]` **optional**: list of words to generate the mnemonic from #### Result @@ -59,45 +63,45 @@ mnemonic `string` a random mnemonic #### Examples // generate 16 bytes of entropy - let entropy = BITBOX.Crypto.randomBytes(16); + let entropy = bitbox.Crypto.randomBytes(16); // // turn entropy to 12 word mnemonic - BITBOX.Mnemonic.fromEntropy(entropy) + bitbox.Mnemonic.fromEntropy(entropy) // security question relief cruel nephew jump chest copper axis assist gift correct // generate 20 bytes of entropy - let entropy = BITBOX.Crypto.randomBytes(20); + let entropy = bitbox.Crypto.randomBytes(20); // // turn entropy to 15 word mnemonic - BITBOX.Mnemonic.fromEntropy(entropy) + bitbox.Mnemonic.fromEntropy(entropy) // impact hub pattern turkey cruel adult short moment make toe one actress roast yellow hurt // generate 24 bytes of entropy - let entropy = BITBOX.Crypto.randomBytes(24); + let entropy = bitbox.Crypto.randomBytes(24); // // turn entropy to 18 word mnemonic - BITBOX.Mnemonic.fromEntropy(entropy) + bitbox.Mnemonic.fromEntropy(entropy) // bid quantum chronic marriage swing affair record amateur enhance heart object mind spoon speak toast piece chef real // generate 28 bytes of entropy - let entropy = BITBOX.Crypto.randomBytes(28); + let entropy = bitbox.Crypto.randomBytes(28); // // turn entropy to 21 word mnemonic - BITBOX.Mnemonic.fromEntropy(entropy) + bitbox.Mnemonic.fromEntropy(entropy) // orchard rural giant okay tape pipe luggage clap bring wear ticket slot fiscal seminar crazy robot distance current dizzy swarm barrel // generate 32 bytes of entropy - let entropy = BITBOX.Crypto.randomBytes(32); + let entropy = bitbox.Crypto.randomBytes(32); // // turn entropy to 24 word mnemonic - BITBOX.Mnemonic.fromEntropy(entropy) + bitbox.Mnemonic.fromEntropy(entropy) // vibrant solution level obtain cheap damage october giant chalk cushion assist fossil spawn artist rice edit proof hotel process survey gas sausage mouse property // generate 16 bytes of entropy - let entropy = BITBOX.Crypto.randomBytes(16); + let entropy = bitbox.Crypto.randomBytes(16); // // turn entropy to 12 japanese word mnemonic - BITBOX.Mnemonic.fromEntropy(entropy.toString('hex'), BITBOX.Mnemonic.wordLists().japanese) + bitbox.Mnemonic.fromEntropy(entropy.toString('hex'), bitbox.Mnemonic.wordLists().japanese) // ぱそこん にあう にんめい きどく ちそう せんきょ かいが きおく いれる いねむり しいく きかんしゃ ### `toEntropy` @@ -107,7 +111,7 @@ Turn mnemonic to entropy #### Arguments 1. mnemonic `string`: a mnemonic to turn to entropy. -2. mnemonic word list `array` `optional`: list of words the mnemonic was generated from +2. mnemonic word list `string[]` **optional**: list of words the mnemonic was generated from #### Result @@ -117,28 +121,28 @@ entropy `Buffer` entropy encoded as buffer // turn 12 word mnemonic to entropy let mnemonic = 'security question relief cruel nephew jump chest copper axis assist gift correct'; - BITBOX.Mnemonic.toEntropy(mnemonic) - // + bitbox.Mnemonic.toEntropy(mnemonic) + // // turn 15 word mnemonic to entropy let mnemonic = 'impact hub pattern turkey cruel adult short moment make toe one actress roast yellow hurt'; - BITBOX.Mnemonic.toEntropy(mnemonic) - // + bitbox.Mnemonic.toEntropy(mnemonic) + // // turn 18 word mnemonic to entropy let mnemonic = 'bid quantum chronic marriage swing affair record amateur enhance heart object mind spoon speak toast piece chef real'; - BITBOX.Mnemonic.toEntropy(mnemonic) - // + bitbox.Mnemonic.toEntropy(mnemonic) + // // turn 21 word mnemonic to entropy let mnemonic = 'orchard rural giant okay tape pipe luggage clap bring wear ticket slot fiscal seminar crazy robot distance current dizzy swarm barrel'; - BITBOX.Mnemonic.toEntropy(mnemonic) - // + bitbox.Mnemonic.toEntropy(mnemonic) + // // turn 24 word mnemonic to entropy let mnemonic = 'vibrant solution level obtain cheap damage october giant chalk cushion assist fossil spawn artist rice edit proof hotel process survey gas sausage mouse property'; - BITBOX.Mnemonic.toEntropy(mnemonic) - // + bitbox.Mnemonic.toEntropy(mnemonic) + // ### `validate` @@ -147,21 +151,21 @@ Validate mnemonic #### Arguments 1. mnemonic `string` mnemonic phrase -2. mnemonic word list `array`: list of words the mnemonic was generated from +2. mnemonic word list `string[]`: list of words the mnemonic was generated from #### Result -valid `String` +valid `string` #### Examples - BITBOX.Mnemonic.validate('ca', BITBOX.Mnemonic.wordLists().english) + bitbox.Mnemonic.validate('ca', bitbox.Mnemonic.wordLists().english) // ca is not in wordlist, did you mean cabbage? - BITBOX.Mnemonic.validate('boil lonely casino manage habit where total glory muffin name limit mansion', BITBOX.Mnemonic.wordLists().english) + bitbox.Mnemonic.validate('boil lonely casino manage habit where total glory muffin name limit mansion', bitbox.Mnemonic.wordLists().english) // Valid mnemonic - BITBOX.Mnemonic.validate('boil lonely casino manage habit where total glory muffin name limit mansion boil lonely casino manage habit where total glory muffin name limit mansion', BITBOX.Mnemonic.wordLists().english) + bitbox.Mnemonic.validate('boil lonely casino manage habit where total glory muffin name limit mansion boil lonely casino manage habit where total glory muffin name limit mansion', bitbox.Mnemonic.wordLists().english) // Invalid mnemonic ### `toSeed` @@ -170,8 +174,8 @@ Create root seed from mnemonic #### Arguments -1. mnemonic `String` mnemonic phrase -2. passphrase `String` `optional`: passphrase. Defaults to "" +1. mnemonic `string` mnemonic phrase +2. passphrase `string` **optional**: passphrase. Defaults to "" #### Result @@ -179,20 +183,20 @@ rootSeed `Buffer` #### Examples - BITBOX.Mnemonic.toSeed('enable stem left method one submit coach bid inspire cluster armed bracket') - // + bitbox.Mnemonic.toSeed('enable stem left method one submit coach bid inspire cluster armed bracket') + // - BITBOX.Mnemonic.toSeed('vendor talk alone sick balance tissue number armor frequent plug transfer chest', 'password'); - // + bitbox.Mnemonic.toSeed('vendor talk alone sick balance tissue number armor frequent plug transfer chest', 'password'); + // - BITBOX.Mnemonic.toSeed('idea relax weird defense body bronze champion ancient vocal peanut similar dose grit company peasant gate sunset deal library act include penalty annual main', ''); - // + bitbox.Mnemonic.toSeed('idea relax weird defense body bronze champion ancient vocal peanut similar dose grit company peasant gate sunset deal library act include penalty annual main', ''); + // - BITBOX.Mnemonic.toSeed('bus aware census desk orphan zebra fashion host try muscle pig close jealous slice elegant prison reject ship great program trumpet syrup tray remove', ''); - // + bitbox.Mnemonic.toSeed('bus aware census desk orphan zebra fashion host try muscle pig close jealous slice elegant prison reject ship great program trumpet syrup tray remove', ''); + // - BITBOX.Mnemonic.toSeed('frost deliver coin clutch upon round scene wonder various wise luggage country', 'yayayayay'); - // + bitbox.Mnemonic.toSeed('frost deliver coin clutch upon round scene wonder various wise luggage country', 'yayayayay'); + // ### `wordLists` @@ -204,7 +208,7 @@ wordlists `object` an object with wordlists in the following languages english ( #### Examples - BITBOX.Mnemonic.wordLists(); + bitbox.Mnemonic.wordLists(); // { // EN: [], // JA: [], @@ -224,34 +228,34 @@ Returns an array of privateKeyWIF/publicAddress pairs. It generates the addresse #### Arguments -1. mnemonic `String`: mnemonic to use -2. numberOfKeypairs `Number` `optional`: number of keypairs to return. Default is 1 -3. regtest `Boolean` optional: return regtest key pairs +1. mnemonic `string`: mnemonic to use +2. numberOfKeypairs `number` **optional**: number of keypairs to return. Default is 1 +3. regtest `boolean` **optional**: return regtest key pairs #### Result -keypairs `Array` array of privateKeyWIF/publicAddress pairs +keypairs `any[]` array of privateKeyWIF/publicAddress pairs #### Examples // First create a mnemonic from 32 bytes of random entropy - let entropy = BITBOX.Crypto.randomBytes(32); - // - let mnemonic = BITBOX.Mnemonic.fromEntropy(entropy); - // symptom owner ridge follow buffalo choose stem depend million jar lemon claw color credit remove model pudding slot fiber west heavy ranch bird wet + let entropy = bitbox.Crypto.randomBytes(32); + // + let mnemonic = bitbox.Mnemonic.fromEntropy(entropy); + // rural pistol giant label nominee curtain egg crystal famous only drill van place unit attitude oven memory fade mix sun shrug soon steak easily // Then call toKeypairs and pass in your mnemonic and how many keypairs you'd like - BITBOX.Mnemonic.toKeypairs(mnemonic, 5) - // [ { privateKeyWIF: 'Kz6b1TszeUGaypUpRCnfD2L17bQSW93o4j3VMpvT5e5BqaF9XkyP', - // address: 'bitcoincash:qp8a4vzfk9kstwsl4ud4ym3z2tckdf7a4gfwkxvtfq' }, - // { privateKeyWIF: 'L5ZHQ2BdTQaTq2A8HNsdkHYKPLsfrHgvJyrVxHFFZyN9K3fmeoiG', - // address: 'bitcoincash:qq5nxh27up6hcm0nn36lxtu7n8a7l6jsj52s8dvtex' }, - // { privateKeyWIF: 'KwyY3Z7STwbxnmQXe1vVmXhT8Y3W1BJQpRgteRhTWCyvvdro2j33', - // address: 'bitcoincash:qzj9n9jmnmyeqfdc5k65kxta3c7ch0g3wudeyjeg3y' }, - // { privateKeyWIF: 'KxMG2mjL8DZQCaoXz8aFw5XYqguKiDHBb16JwDQMGa7ga7kfy9cE', - // address: 'bitcoincash:qrhj0lesz6sn7l4hc5arh5tt8k583ahdaun6mcdjx8' }, - // { privateKeyWIF: 'Kz3qqJ8GFSSbDrBqtV7mfhBoDPkSmMKtp7Yk62psDgmRjyU8id8J', - // address: 'bitcoincash:qp8xjllc75c2hgrpjy3f6kegtfqgmn72dqs0y20anv' } ] + bitbox.Mnemonic.toKeypairs(mnemonic, 5) + // [ { privateKeyWIF: 'KwuSgSuV6m3U1oahRQEhSQ6e4gRE6LZXNGDTETGPGotKQJdH7ADd', + // address: 'bitcoincash:qqvk7aculs8r6t29pj23de35t43tupks2ua6wmc2hy' }, + // { privateKeyWIF: 'L34pfoBm2swLBX5vAx1ReeYbSnpsvu7DRVaiLW8e9wNEJw5p3mV5', + // address: 'bitcoincash:qzt8ju6au2075cpzrhzwe5n96ycqnurarur5k92nd5' }, + // { privateKeyWIF: 'L2nCRgDzmTRrQzSssFvVA7xiYHBJyfj62jdDwu1bTjHKVoLGxsqs', + // address: 'bitcoincash:qpdjwtyvqqaapykxr3pr6cty4gpww30aucam9l0qzn' }, + // { privateKeyWIF: 'KyDLLa4RZKhnBP78Ue6557B55Jmffu1y8mH8p8WKA12knJUjiq4u', + // address: 'bitcoincash:qq8kee4k4h9fn22xya9p5u203vg69aat3usqdvkdkn' }, + // { privateKeyWIF: 'L5gB66JqhfouEtZG5aRMQ9JaVS2ggkK3YozGfzZegBupaPXqdfaz', + // address: 'bitcoincash:qphwlpu2wzjxrjts94pn4wh778fwsu2afg2aj5her9' } ] ### `findNearestWord` @@ -259,35 +263,35 @@ Returns nearest matching word from provided word list #### Arguments -1. word `String`: mnemonic to use -2. wordlist `Array`: wordlist to search +1. word `string`: mnemonic to use +2. wordlist `string[]`: wordlist to search #### Result -word `String` nearest matching word from provided wordlist +word `string` nearest matching word from provided wordlist #### Examples // english let word = 'ab'; - let wordlist = BITBOX.Mnemonic.wordLists().english; - BITBOX.Mnemonic.findNearestWord(word, wordlist); + let wordlist = bitbox.Mnemonic.wordLists().english; + bitbox.Mnemonic.findNearestWord(word, wordlist); // abandon // french let word = 'octu'; - let wordlist = BITBOX.Mnemonic.wordLists().french; - BITBOX.Mnemonic.findNearestWord(word, wordlist); + let wordlist = bitbox.Mnemonic.wordLists().french; + bitbox.Mnemonic.findNearestWord(word, wordlist); // octupler // spanish let word = 'foobaro'; - let wordlist = BITBOX.Mnemonic.wordLists().spanish; - BITBOX.Mnemonic.findNearestWord(word, wordlist); + let wordlist = bitbox.Mnemonic.wordLists().spanish; + bitbox.Mnemonic.findNearestWord(word, wordlist); // forro // italian let word = 'nv'; - let wordlist = BITBOX.Mnemonic.wordLists().italian; - BITBOX.Mnemonic.findNearestWord(word, wordlist); + let wordlist = bitbox.Mnemonic.wordLists().italian; + bitbox.Mnemonic.findNearestWord(word, wordlist); // neve diff --git a/src/data/docs/bitbox/price.md b/src/data/docs/bitbox/price.md index 89e3dac9..4bc60cce 100644 --- a/src/data/docs/bitbox/price.md +++ b/src/data/docs/bitbox/price.md @@ -1,7 +1,7 @@ --- title: Price icon: dollar-sign -ordinal: 13 +ordinal: 16 --- ### `current` @@ -10,57 +10,25 @@ Return current price of BCH in multiple currencies #### Arguments -1. currency `String` optional: Defaults to all listed currencies +1. currency `string` **optional**: Defaults to usd + +Valid currencies + +aed, afn, all, amd, ang, aoa, ars, aud, awg, azn, bam, bbd, bdt, bgn, bhd, bif, bmd, bnd, bob, brl, bsd, btn, bwp, byn, bzd, cad, cdf, chf, clf, clp, cnh, cny, cop, crc, cuc, cup, cve, czk, djf, dkk, dop, dzd, egp, ern, etb, eur, fjd, fkp, gbp, gel, ggp, ghs, gip, gmd, gnf, gtq, gyd, hkd, hnl, hrk, htg, huf, idr, ils, imp, inr, iqd, irr, isk, jep, jmd, jod, jpy, kes, kgs, khr, kmf, kpw, krw, kwd, kyd, kzt, lak, lbp, lkr, lrd, lsl, lyd, mad, mdl, mga, mkd, mmk, mnt, mop, mro, mur, mvr, mwk, mxn, myr, mzn, nad, ngn, nio, nok, npr, nzd, omr, pab, pen, pgk, php, pkr, pln, pyg, qar, ron, rsd, rub, rwf, sar, sbd, scr, sdg, sek, sgd, shp, sll, sos, srd, ssp, std, svc, syp, szl, thb, tjs, tmt, tnd, top, try, ttd, twd, tzs, uah, ugx, usd, uyu, uzs, vef, vnd, vuv, wst, xaf, xag, xau, xcd, xdr, xof, xpd, xpf, xpt, yer, zar, zmw, zwl #### Result -price `Object | number`: Price of all listed currencies or price of single requested currencies +price `Promise`: Price of single requested currency #### Examples (async () => { try { - let current = await BITBOX.Price.current(); + let current = await bitbox.Price.current('usd'); console.log(current); } catch(error) { console.error(error) } })() - // { - // USD: 867.86, - // GBP: 661.97, - // EUR: 744.83, - // CNY: 5818.31, - // PAB: 867.86, - // ARS: 23881.77, - // BOB: 6029.19, - // CLP: 567233.3, - // PEN: 2836.77, - // PYG: 4961524.18, - // UYU: 27161.48, - // VEF: 69342014, - // CRC: 491742.86, - // MXN: 16399.26, - // NGN: 313297.46, - // INR: 59392.82, - // RUB: 54372.12, - // AUD: 1175.32, - // BRL: 3330.68, - // CAD: 1146.01, - // ZAR: 11520, - // GHS: 4155.94, - // JPY: 98025.65, - // ILS: 3155.57, - // SAR: 3254.39, - // KRW: 979163.05, - // COP: 2509470.44, - // PHP: 46374.53, - // PLN: 3199.97 - // } - - (async () => { - let current = await BITBOX.Price.current('usd'); - console.log(current); - })() - // 868.57 + // 26681 diff --git a/src/data/docs/bitbox/rawtransactions.md b/src/data/docs/bitbox/rawtransactions.md index 55c3c849..c7076ed7 100644 --- a/src/data/docs/bitbox/rawtransactions.md +++ b/src/data/docs/bitbox/rawtransactions.md @@ -1,7 +1,7 @@ --- title: RawTransactions icon: exchange -ordinal: 14 +ordinal: 17 --- ### `decodeRawTransaction` @@ -10,42 +10,40 @@ Return an Array of JSON objects representing the serialized, hex-encoded transac #### Arguments -- hex (required): - - `String`: A hex encoded transaction - - `Array` of strings: Array with maximum of 20 transaction hex strings. +- hex `string | string[]` #### Result -- txs: - - `Object`: An object containing decoded transaction details. - - `Array`: An array of objects containing decoded transaction details. +- txs `Promise` #### Examples (async () => { try { - let decodeRawTransaction = await BITBOX.RawTransactions.decodeRawTransaction('01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'); + let decodeRawTransaction = await bitbox.RawTransactions.decodeRawTransaction('01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'); console.log(decodeRawTransaction); } catch(error) { console.error(error) } })() - // [{ txid: 'd86c34adaeae19171fd98fe0ffd89bfb92a1e6f0339f5e4f18d837715fd25758', - // hash: 'd86c34adaeae19171fd98fe0ffd89bfb92a1e6f0339f5e4f18d837715fd25758', - // size: 191, - // version: 1, - // locktime: 0, - // vin: - // [ { txid: '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b', - // vout: 0, - // scriptSig: [Object], - // sequence: 4294967295 } ], - // vout: [ { value: 12.5, n: 0, scriptPubKey: [Object] } ] }] + // { txid: 'd86c34adaeae19171fd98fe0ffd89bfb92a1e6f0339f5e4f18d837715fd25758', + // hash: + // 'd86c34adaeae19171fd98fe0ffd89bfb92a1e6f0339f5e4f18d837715fd25758', + // size: 191, + // version: 1, + // locktime: 0, + // vin: + // [ { txid: + // '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b', + // vout: 0, + // scriptSig: [Object], + // sequence: 4294967295 } ], + // vout: [ { value: 12.5, n: 0, scriptPubKey: [Object] } ] } (async () => { try { - let decodeRawTransaction = await BITBOX.RawTransactions.decodeRawTransaction([ + let decodeRawTransaction = await bitbox.RawTransactions.decodeRawTransaction([ '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000', '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' ]); @@ -55,23 +53,54 @@ Return an Array of JSON objects representing the serialized, hex-encoded transac } })() + // [ { txid: + // 'd86c34adaeae19171fd98fe0ffd89bfb92a1e6f0339f5e4f18d837715fd25758', + // hash: + // 'd86c34adaeae19171fd98fe0ffd89bfb92a1e6f0339f5e4f18d837715fd25758', + // size: 191, + // version: 1, + // locktime: 0, + // vin: [ [Object] ], + // vout: [ [Object] ] }, + // { txid: + // 'd86c34adaeae19171fd98fe0ffd89bfb92a1e6f0339f5e4f18d837715fd25758', + // hash: + // 'd86c34adaeae19171fd98fe0ffd89bfb92a1e6f0339f5e4f18d837715fd25758', + // size: 191, + // version: 1, + // locktime: 0, + // vin: [ [Object] ], + // vout: [ [Object] ] } ] + ### `decodeScript` -Decode an Array of hex-encoded scripts. +Decode hex-encoded scripts #### Arguments -1. hexstrings `Array` required: Array with maximum of 20 hex encoded scripts. +1. hex `string | string[]` #### Result -decodedScripts `Array` +decodedScripts `Promise` #### Examples (async () => { try { - let decodeScript = await BITBOX.RawTransactions.decodeScript(['4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16']); + let decodeScript = await bitbox.RawTransactions.decodeScript('4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16'); + console.log(decodeScript); + } catch(error) { + console.error(error) + } + })() + + // { asm: '30450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed59201 02e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16', type: 'nonstandard', p2sh: 'bitcoincash:pqwndulzwft8dlmqrteqyc9hf823xr3lcc7ypt74ts' } + + + (async () => { + try { + let decodeScript = await bitbox.RawTransactions.decodeScript(['4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16']); console.log(decodeScript); } catch(error) { console.error(error) @@ -90,30 +119,30 @@ that is serialized, hex-encoded data for 'txid'. #### Arguments -- txids (required): +- txids `string | string[]` +- verbose `boolean` **optiona**: If false, return a string, + otherwise return a json object - - `String`: transaction ID - - `Array`: Array of strings of transaction IDs, with maximum of 20. +#### Result -- verbose `Boolean` (optional, default=false): If false, return a string, - otherwise return a json object +- rawTx `Promise` #### Examples (async () => { try { - let getRawTransaction = await BITBOX.RawTransactions.getRawTransaction("0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"); + let getRawTransaction = await bitbox.RawTransactions.getRawTransaction("0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"); console.log(getRawTransaction); } catch(error) { console.error(error) } })() - // [ '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000' ] + // 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000 (async () => { try { - let getRawTransaction = await BITBOX.RawTransactions.getRawTransaction([ + let getRawTransaction = await bitbox.RawTransactions.getRawTransaction([ "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098", "b25d24fbb42d84812ed2cb55797f10fdec41afc7906ab563d1ec8c8676a2037f" ], true); @@ -123,6 +152,39 @@ that is serialized, hex-encoded data for 'txid'. } })() + // [ { hex: + // '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000', + // txid: + // '0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098', + // hash: + // '0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098', + // size: 134, + // version: 1, + // locktime: 0, + // vin: [ [Object] ], + // vout: [ [Object] ], + // blockhash: + // '00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048', + // confirmations: 581882, + // time: 1231469665, + // blocktime: 1231469665 }, + // { hex: + // '01000000010f3cb469bc82f931ee77d80b3dd495d02f9ed7cdc455cea3e7baa4bdeea6a78d000000006a47304402205ce3e1dfe4b5207818ce27035bc7cc03a5631f806d351535b32ce77c8d136aed02204e66e1fa4c2e12feab0d41a5593aff9629cdbc6ccb6126bc3d1a20404be7760c412103d44946d17e00179bbfc3b723aedc1831d8604e6a04bbd91170f1d894d04657bbffffffff02e6ec8500000000001976a914b5befddad83d9180fd4082c5528cf5a779b0fa6688acdf220000000000001976a9142c21a1be4239eeed678a456627a08d5f813d5c9288ac00000000', + // txid: + // 'b25d24fbb42d84812ed2cb55797f10fdec41afc7906ab563d1ec8c8676a2037f', + // hash: + // 'b25d24fbb42d84812ed2cb55797f10fdec41afc7906ab563d1ec8c8676a2037f', + // size: 225, + // version: 1, + // locktime: 0, + // vin: [ [Object] ], + // vout: [ [Object], [Object] ], + // blockhash: + // '000000000000000003a09a7d68a0d62fd0ab51c368372e46bac84277e2df47e2', + // confirmations: 16151, + // time: 1547752564, + // blocktime: 1547752564 } ] + ### `sendRawTransaction` Submits raw transaction (serialized, hex-encoded) to local node and network. Also see createrawtransaction and signrawtransaction calls. @@ -131,23 +193,62 @@ For bulk uploads, transactions must use different UTXOs. #### Arguments -- hex (required): - - `String`: hex encoded string of the transaction to be broadcast - - `Array` of strings: each element is a hex encoded string +- hex `string | string[]` #### Result -hex `Array` Array of txids +txid `Promise` #### Examples // single tx (async () => { try { - let sendRawTransaction = await BITBOX.RawTransactions.sendRawTransaction("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000"); + let sendRawTransaction = await bitbox.RawTransactions.sendRawTransaction("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000"); + console.log(sendRawTransaction); + } catch(error) { + console.error(error) + } + })() + // 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098 + + // single tx as array + (async () => { + try { + let sendRawTransaction = await bitbox.RawTransactions.sendRawTransaction(["01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000"]); console.log(sendRawTransaction); } catch(error) { console.error(error) } })() // ['0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098'] + +## Interfaces + +### VerboseRawTransaction + + { + hex: string + txid: string + size: number + version: number + locktime: number + vin: [{ coinbase: string; sequence: number }] + vout: [ + { + value: number + n: number + scriptPubKey: { + asm: string + hex: string + reqSigs: number + type: string + addresses: string[] + } + } + ] + blockhash: string + confirmations: number + time: number + blocktime: number + } diff --git a/src/data/docs/bitbox/schnorr.md b/src/data/docs/bitbox/schnorr.md new file mode 100644 index 00000000..95c8d6d7 --- /dev/null +++ b/src/data/docs/bitbox/schnorr.md @@ -0,0 +1,476 @@ +--- +title: Schnorr +icon: code +ordinal: 18 +--- + +### `sign` + +Sign a 32-byte message with the private key, returning a 64-byte signature. + +#### Arguments + +1. privateKey `BigInteger` +2. message `Buffer` + +#### Result + +signature `Buffer` + +#### Examples + + const Buffer = require("safe-buffer").Buffer + const BigInteger = require("bigi") + + // signing + const privateKey = BigInteger.fromHex( + "B7E151628AED2A6ABF7158809CF4F3C762E7160F38B4DA56A784D9045190CFEF" + ) + const message = Buffer.from( + "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89", + "hex" + ) + const createdSignature = bitbox.Schnorr.sign(privateKey, message) + console.log("The signature is: " + createdSignature.toString("hex")) + // The signature is: 2a298dacae57395a15d0795ddbfd1dcb564da82b0f269bc70a74f8220429ba1d1e51a22ccec35599b8f266912281f8365ffc2d035a230434a1a64dc59f7013fd + +### `verify` + +Verify a 64-byte signature of a 32-byte message against the public key. Throws an `Error` if verification fails. + +#### Arguments + +1. publicKey. `Buffer` +2. message. `Buffer` +3. signature. `Buffer` + +#### Examples + + const Buffer = require("safe-buffer").Buffer + const publicKey = Buffer.from( + "02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659", + "hex" + ) + const message = Buffer.from( + "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89", + "hex" + ) + const signatureToVerify = Buffer.from( + "2A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D1E51A22CCEC35599B8F266912281F8365FFC2D035A230434A1A64DC59F7013FD", + "hex" + ) + try { + bitbox.Schnorr.verify(publicKey, message, signatureToVerify) + console.log("The signature is valid.") + } catch (e) { + console.error("The signature verification failed: " + e) + } + +### `batchVerify` + +Verify a list of 64-byte signatures as a batch operation. Throws an `Error` if verification fails. + +#### Arguments + +1. publicKeys. `Buffer[]` +2. messages. `Buffer[]` +3. signatures. `Buffer[]` + +#### Examples + + const Buffer = require("safe-buffer").Buffer + const publicKeys = [ + Buffer.from( + "02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659", + "hex" + ), + Buffer.from( + "03FAC2114C2FBB091527EB7C64ECB11F8021CB45E8E7809D3C0938E4B8C0E5F84B", + "hex" + ), + Buffer.from( + "026D7F1D87AB3BBC8BC01F95D9AECE1E659D6E33C880F8EFA65FACF83E698BBBF7", + "hex" + ) + ] + const messages = [ + Buffer.from( + "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89", + "hex" + ), + Buffer.from( + "5E2D58D8B3BCDF1ABADEC7829054F90DDA9805AAB56C77333024B9D0A508B75C", + "hex" + ), + Buffer.from( + "B2F0CD8ECB23C1710903F872C31B0FD37E15224AF457722A87C5E0C7F50FFFB3", + "hex" + ) + ] + const signatures = [ + Buffer.from( + "2A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D1E51A22CCEC35599B8F266912281F8365FFC2D035A230434A1A64DC59F7013FD", + "hex" + ), + Buffer.from( + "00DA9B08172A9B6F0466A2DEFD817F2D7AB437E0D253CB5395A963866B3574BE00880371D01766935B92D2AB4CD5C8A2A5837EC57FED7660773A05F0DE142380", + "hex" + ), + Buffer.from( + "68CA1CC46F291A385E7C255562068357F964532300BEADFFB72DD93668C0C1CAC8D26132EB3200B86D66DE9C661A464C6B2293BB9A9F5B966E53CA736C7E504F", + "hex" + ) + ] + try { + bitbox.Schnorr.batchVerify(publicKeys, messages, signatures) + console.log("The signatures are valid.") + } catch (e) { + console.error("The signature verification failed: " + e) + } + +### `nonInteractive` + +Aggregates multiple signatures of different private keys over the same message into a single 64-byte signature using a scheme that is safe from rogue-key attacks. + +This non-interactive scheme requires the knowledge of all private keys that are participating in the multi-signature creation. + +#### Arguments + +1. privateKeys. `BigInteger[]` +2. message `Buffer` + +#### Result + +aggregatedSignature `Buffer` + +#### Examples + + const Buffer = require("safe-buffer").Buffer + const BigInteger = require("bigi") + + const privateKey1 = BigInteger.fromHex( + "B7E151628AED2A6ABF7158809CF4F3C762E7160F38B4DA56A784D9045190CFEF" + ) + const privateKey2 = BigInteger.fromHex( + "C90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B14E5C7" + ) + const message = Buffer.from( + "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89", + "hex" + ) + const aggregatedSignature = bitbox.Schnorr.nonInteractive( + [privateKey1, privateKey2], + message + ) + + // verifying an aggregated signature + const publicKey1 = Buffer.from( + "02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659", + "hex" + ) + const publicKey2 = Buffer.from( + "03FAC2114C2FBB091527EB7C64ECB11F8021CB45E8E7809D3C0938E4B8C0E5F84B", + "hex" + ) + const X = bitbox.Schnorr.publicKeyCombine([publicKey1, publicKey2]) + try { + bitbox.Schnorr.verify(X, message, aggregatedSignature) + console.log("The signature is valid.") + } catch (e) { + console.error("The signature verification failed: " + e) + } + +### `computeEll` + +Generate `ell` which is the hash over all public keys participating in a session. + +#### Arguments + +1. publicKeys. `BigInteger[]` + +#### Result + +publicKeyHash `Buffer` + +#### Examples + + const Buffer = require("safe-buffer").Buffer + const BigInteger = require("bigi") + + const publicData = { + pubKeys: [ + Buffer.from( + "03846f34fdb2345f4bf932cb4b7d278fb3af24f44224fb52ae551781c3a3cad68a", + "hex" + ), + Buffer.from( + "02cd836b1d42c51d80cef695a14502c21d2c3c644bc82f6a7052eb29247cf61f4f", + "hex" + ), + Buffer.from( + "03b8c1765111002f09ba35c468fab273798a9058d1f8a4e276f45a1f1481dd0bdb", + "hex" + ) + ], + message: bitbox.Schnorr.hash(Buffer.from("muSig is awesome!", "utf8")), + pubKeyHash: null, + pubKeyCombined: null, + commitments: [], + nonces: [], + nonceCombined: null, + partialSignatures: [], + signature: null + } + + // data only known by the individual party, these values are never shared + // between the signers! + const signerPrivateData = [ + // signer 1 + { + privateKey: BigInteger.fromHex( + "add2b25e2d356bec3770305391cbc80cab3a40057ad836bcb49ef3eed74a3fee" + ), + session: null + }, + // signer 2 + { + privateKey: BigInteger.fromHex( + "0a1645eef5a10e1f5011269abba9fd85c4f0cc70820d6f102fb7137f2988ad78" + ), + session: null + }, + // signer 3 + { + privateKey: BigInteger.fromHex( + "2031e7fed15c770519707bb092a6337215530e921ccea42030c15d86e8eaf0b8" + ), + session: null + } + ] + + // ----------------------------------------------------------------------- + // Step 1: Combine the public keys + // The public keys P_i are combined into the combined public key P. + // This can be done by every signer individually or by the initializing + // party and then be distributed to every participant. + // ----------------------------------------------------------------------- + publicData.pubKeyHash = bitbox.Schnorr.computeEll(publicData.pubKeys) + +### `publicKeyCombine` + +Creates the special rogue-key-resistant combined public key `P` by applying the MuSig coefficient to each public key `P_i` before adding them together. + +#### Arguments + +1. publicKeys. `Buffer[]` +2. publicKeyHash. `Buffer` + +#### Result + +X `Buffer` + +#### Examples + + // continued from above + publicData.pubKeyCombined = bitbox.Schnorr.publicKeyCombine( + publicData.pubKeys, + publicData.pubKeyHash + ) + +### `sessionInitialize` + +Creates a signing session. Each participant must create a session and must not share the content of the session apart from the commitment and later the nonce. + +#### Arguments + +1. sessionId. `Buffer` +2. privateKey. `BigInteger` +3. message. `Buffer` +4. pubKeyCombined. `Buffer` +5. ell. `Buffer` +6. idx. `number` + +#### Result + +session `Session` + +#### Examples + + // continued from above + // ----------------------------------------------------------------------- + // Step 2: Create the private signing session + // Each signing party does this in private. The session ID *must* be + // unique for every call to sessionInitialize, otherwise it's trivial for + // an attacker to extract the secret key! + // ----------------------------------------------------------------------- + signerPrivateData.forEach((data, idx) => { + const sessionId = bitbox.Crypto.randomBytes(32) // must never be reused between sessions! + data.session = bitbox.Schnorr.sessionInitialize( + sessionId, + data.privateKey, + publicData.message, + publicData.pubKeyCombined, + publicData.pubKeyHash, + idx + ) + }) + const signerSession = signerPrivateData[0].session + +### `sessionNonceCombine` + +Combines multiple nonces `R_i` into the combined nonce `R`. + +#### Arguments + +1. session. `Session` +2. nonces. `Buffer[]` + +#### Result + +nonceCombined `Buffer` + +#### Examples + + // continued from above + // ----------------------------------------------------------------------- + // Step 3: Exchange commitments (communication round 1) + // The signers now exchange the commitments H(R_i). This is simulated here + // by copying the values from the private data to public data array. + // ----------------------------------------------------------------------- + for (let i = 0; i < publicData.pubKeys.length; i++) { + publicData.commitments[i] = signerPrivateData[i].session.commitment + } + + // ----------------------------------------------------------------------- + // Step 4: Get nonces (communication round 2) + // Now that everybody has commited to the session, the nonces (R_i) can be + // exchanged. Again, this is simulated by copying. + // ----------------------------------------------------------------------- + for (let i = 0; i < publicData.pubKeys.length; i++) { + publicData.nonces[i] = signerPrivateData[i].session.nonce + } + + // ----------------------------------------------------------------------- + // Step 5: Combine nonces + // The nonces can now be combined into R. Each participant should do this + // and keep track of whether the nonce was negated or not. This is needed + // for the later steps. + // ----------------------------------------------------------------------- + publicData.nonceCombined = bitbox.Schnorr.sessionNonceCombine( + signerSession, + publicData.nonces + ) + signerPrivateData.forEach( + data => (data.session.nonceIsNegated = signerSession.nonceIsNegated) + ) + +### `partialSign` + +Creates a partial signature `s_i` for a participant. + +#### Arguments + +1. session. `Session` +2. message. `Buffer` +3. nonceCombined. `Buffer` +4. publicKeyCombined. `Buffer` + +#### Result + +partialSignature `BigInteger` + +#### Examples + + // continued from above + // ----------------------------------------------------------------------- + // Step 6: Generate partial signatures + // Every participant can now create their partial signature s_i over the + // given message. + // ----------------------------------------------------------------------- + signerPrivateData.forEach(data => { + data.session.partialSignature = bitbox.Schnorr.partialSign( + data.session, + publicData.message, + publicData.nonceCombined, + publicData.pubKeyCombined + ) + }) + +### `partialSignatureVerify` + +Verifies a partial signature `s_i` against the participant's public key `P_i`. Throws an `Error` if verification fails. + +#### Arguments + +1. session. `Session` +2. partialSig. `BigInteger` +3. nonceCombined. `Buffer` +4. idx. `number` +5. publicKey. `Buffer` +6. nonce. `Buffer` + +#### Examples + + // continued from above + // ----------------------------------------------------------------------- + // Step 7: Exchange partial signatures (communication round 3) + // The partial signature of each signer is exchanged with the other + // participants. Simulated here by copying. + // ----------------------------------------------------------------------- + for (let i = 0; i < publicData.pubKeys.length; i++) { + publicData.partialSignatures[i] = + signerPrivateData[i].session.partialSignature + } + + // ----------------------------------------------------------------------- + // Step 8: Verify individual partial signatures + // Every participant should verify the partial signatures received by the + // other participants. + // ----------------------------------------------------------------------- + for (let i = 0; i < publicData.pubKeys.length; i++) { + bitbox.Schnorr.partialSignatureVerify( + signerSession, + publicData.partialSignatures[i], + publicData.nonceCombined, + i, + publicData.pubKeys[i], + publicData.nonces[i] + ) + } + +### `partialSignaturesCombine` + +Combines multiple partial signatures into a Schnorr signature `(s, R)` that can be verified against the combined public key `P`. + +#### Arguments + +1. nonceCombined. `Buffer` +2. partialSignatures. `BigInteger[]` + +#### Result + +signature `Buffer` + +#### Examples + + // continued from above + // ----------------------------------------------------------------------- + // Step 9: Combine partial signatures + // Finally, the partial signatures can be combined into the full signature + // (s, R) that can be verified against combined public key P. + // ----------------------------------------------------------------------- + publicData.signature = bitbox.Schnorr.partialSignaturesCombine( + publicData.nonceCombined, + publicData.partialSignatures + ) + + // ----------------------------------------------------------------------- + // Step 10: Verify signature + // The resulting signature can now be verified as a normal Schnorr + // signature (s, R) over the message m and public key P. + // ----------------------------------------------------------------------- + bitbox.Schnorr.verify( + publicData.pubKeyCombined, + publicData.message, + publicData.signature + ) diff --git a/src/data/docs/bitbox/script.md b/src/data/docs/bitbox/script.md index 49849759..89472e12 100644 --- a/src/data/docs/bitbox/script.md +++ b/src/data/docs/bitbox/script.md @@ -1,7 +1,7 @@ --- title: Script icon: code -ordinal: 15 +ordinal: 19 --- ### `opcodes` @@ -15,7 +15,7 @@ opcodes `Object` #### Examples // list all op codes - BITBOX.Script.opcodes; + bitbox.Script.opcodes; // { OP_FALSE: 0, // OP_0: 0, // OP_PUSHDATA1: 76, @@ -32,11 +32,11 @@ opcodes `Object` // } // get the op code for a word - BITBOX.Script.opcodes.OP_SPLIT + bitbox.Script.opcodes.OP_SPLIT // 127 - BITBOX.Script.opcodes.OP_NUM2BIN + bitbox.Script.opcodes.OP_NUM2BIN // 128 - BITBOX.Script.opcodes.OP_BIN2NUM + bitbox.Script.opcodes.OP_BIN2NUM // 129 ### `encode` @@ -45,7 +45,7 @@ Encode a Script buffer #### Arguments -1. scriptChunks `Array` +1. scriptChunks `Array` #### Result @@ -58,8 +58,8 @@ buffer `Buffer` Buffer.from('3045022100877e2f9c28421f0a850cc8ff66ba1d0f6c8dbe9e63e199c2c2600c9c15bf9d4402204d35b13d3cc202aa25722b2b1791442ebc5c39d898b609515260ad08f0e766a601', 'hex'), Buffer.from('02fb721b92025e775b1b84774e65d568d24645cb633275f5c26f5c3101b214a8fb', 'hex') ] - BITBOX.Script.encode(scriptSig); - // + bitbox.Script.encode(scriptSig); + // // encode P2PKH scriptPubKey to buffer let scriptPubKey = [ @@ -69,8 +69,8 @@ buffer `Buffer` 136, 172 ]; - BITBOX.Script.encode(scriptPubKey); - // + bitbox.Script.encode(scriptPubKey); + // ### `decode` @@ -82,24 +82,21 @@ Decode a Script buffer. #### Result -decodedScript `Array` +decodedScript `Array` #### Examples // decode P2PKH scriptSig buffer let scriptSigBuffer = Buffer.from("483045022100877e2f9c28421f0a850cc8ff66ba1d0f6c8dbe9e63e199c2c2600c9c15bf9d4402204d35b13d3cc202aa25722b2b1791442ebc5c39d898b609515260ad08f0e766a6012102fb721b92025e775b1b84774e65d568d24645cb633275f5c26f5c3101b214a8fb", 'hex'); - BITBOX.Script.decode(scriptSigBuffer); - // [ - // , - // - // ] + bitbox.Script.decode(scriptSigBuffer); + // [ , ] // decode P2PKH scriptPubKey buffer let scriptPubKeyBuffer = Buffer.from("76a91424e9c07804d0ee7e5bda934e0a3ae8710fc007dd88ac", 'hex'); - BITBOX.Script.decode(scriptPubKeyBuffer); + bitbox.Script.decode(scriptPubKeyBuffer); // [ 118, // 169, - // , + // , // 136, // 172 ] @@ -113,18 +110,18 @@ Script buffer to ASM. #### Result -asm `String` +asm `string` #### Examples // P2PKH scriptSig let scriptSigBuffer = Buffer.from('483045022100877e2f9c28421f0a850cc8ff66ba1d0f6c8dbe9e63e199c2c2600c9c15bf9d4402204d35b13d3cc202aa25722b2b1791442ebc5c39d898b609515260ad08f0e766a6012102fb721b92025e775b1b84774e65d568d24645cb633275f5c26f5c3101b214a8fb', 'hex'); - BITBOX.Script.toASM(scriptSigBuffer); + bitbox.Script.toASM(scriptSigBuffer); // 3045022100877e2f9c28421f0a850cc8ff66ba1d0f6c8dbe9e63e199c2c2600c9c15bf9d4402204d35b13d3cc202aa25722b2b1791442ebc5c39d898b609515260ad08f0e766a601 02fb721b92025e775b1b84774e65d568d24645cb633275f5c26f5c3101b214a8fb // P2PKH scriptPubKey let scriptBuffer = Buffer.from("76a914bee4182d9fbc8931a728410a0cd3e0f340f2995a88ac", 'hex'); - BITBOX.Script.toASM(scriptBuffer); + bitbox.Script.toASM(scriptBuffer); // OP_DUP OP_HASH160 bee4182d9fbc8931a728410a0cd3e0f340f2995a OP_EQUALVERIFY OP_CHECKSIG ### `fromASM` @@ -133,7 +130,7 @@ Script ASM to buffer #### Arguments -1. asm `String` +1. asm `string` #### Result @@ -143,12 +140,12 @@ buffer `Buffer` // P2PKH scriptSig let scriptSigASM = "3045022100877e2f9c28421f0a850cc8ff66ba1d0f6c8dbe9e63e199c2c2600c9c15bf9d4402204d35b13d3cc202aa25722b2b1791442ebc5c39d898b609515260ad08f0e766a601 02fb721b92025e775b1b84774e65d568d24645cb633275f5c26f5c3101b214a8fb"; - BITBOX.Script.fromASM(scriptSigASM); + bitbox.Script.fromASM(scriptSigASM); // // P2PKH scriptPubKey let scriptPubKeyASM = "OP_DUP OP_HASH160 bee4182d9fbc8931a728410a0cd3e0f340f2995a OP_EQUALVERIFY OP_CHECKSIG"; - BITBOX.Script.fromASM(scriptPubKeyASM); + bitbox.Script.fromASM(scriptPubKeyASM); // ### `encodeNullDataOutput` @@ -157,7 +154,7 @@ nulldata output template: `` OP_RETURN `data` `` #### Arguments -1. data `Buffer` +1. data `Buffer` #### Result @@ -166,15 +163,15 @@ buffer `Buffer` #### Examples let data = "BCHForEveryone"; - let buf = BITBOX.Script.nullData.output.encode(Buffer.from(data, 'ascii')); - // - BITBOX.Script.toASM(buf); + let buf = Buffer.from(data, 'ascii') + let encoded = bitbox.Script.encodeNullDataOutput(buf); + bitbox.Script.toASM(encoded); // OP_RETURN 424348466f7245766572796f6e65 let data = "Satoshi Nakamoto"; - let buf = BITBOX.Script.nullData.output.encode(Buffer.from(data, 'ascii')); - // - BITBOX.Script.toASM(buf); + let buf = Buffer.from(data, 'ascii') + let encoded = bitbox.Script.encodeNullDataOutput(buf); + bitbox.Script.toASM(encoded); // OP_RETURN 5361746f736869204e616b616d6f746 ### `decodeNullDataOutput` @@ -183,7 +180,7 @@ decode nulldata output #### Arguments -1. output `Buffer` +1. output `Buffer` #### Result @@ -192,11 +189,15 @@ buffer `Buffer` #### Examples let hex = '6a0e424348466f7245766572796f6e65'; - BITBOX.Script.nullData.output.decode(Buffer.from(hex, 'hex')).toString('ascii'); + let buf = Buffer.from(hex, 'hex') + let decoded = bitbox.Script.decodeNullDataOutput(buf); + decoded.toString('ascii') // BCHForEveryone let hex = '6a105361746f736869204e616b616d6f746f'; - BITBOX.Script.nullData.output.decode(Buffer.from(hex, 'hex')).toString('ascii'); + let buf = Buffer.from(hex, 'hex') + let decoded = bitbox.Script.decodeNullDataOutput(buf); + decoded.toString('ascii') // Satoshi Nakamoto ### `checkNullDataOutput` @@ -209,19 +210,23 @@ check nulldata output format #### Result -valid `Boolean` +valid `boolean` #### Examples - let data = "BCHForEveryone"; - let buf = BITBOX.Script.nullData.output.encode(Buffer.from(data, 'ascii')); - BITBOX.Script.nullData.output.check(buf); + // check null data output + let data = "BCHForEveryone" + let buf = Buffer.from(data, 'ascii') + let encoded = bitbox.Script.encodeNullDataOutput(buf) + bitbox.Script.checkNullDataOutput(encoded) // true - let data = "Satoshi Nakamoto"; - let buf = BITBOX.Script.nullData.output.encode(Buffer.from(data, 'ascii')); - BITBOX.Script.nullData.output.check(buf); - // true + // check p2pk input + let signature = '304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801'; + let buf = Buffer.from(signature, 'hex') + let encoded = bitbox.Script.encodeP2PKInput(buf) + bitbox.Script.checkNullDataOutput(encoded); + // false ### `encodeP2PKInput` @@ -229,18 +234,18 @@ p2pk input template: `` `signature` `` #### Arguments -1. signature `Buffer` +1. signature `Buffer` #### Result -buffer `Buffer` +encoded `Buffer` #### Examples let signature = '304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801'; - let buf = BITBOX.Script.pubKey.input.encode(Buffer.from(signature, 'hex')); - // - BITBOX.Script.toASM(buf); + let buf = Buffer.from(signature, 'hex') + let encoded = bitbox.Script.encodeP2PKInput(buf) + bitbox.Script.toASM(encoded); // 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 ### `decodeP2PKInput` @@ -253,13 +258,14 @@ decode p2pk input #### Result -buffer `Buffer` +decoded `Buffer` #### Examples - let hex = '47304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801'; - BITBOX.Script.pubKey.input.decode(Buffer.from(hex, 'hex')); - // + let input = '47304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801'; + let buf = Buffer.from(input, 'hex') + bitbox.Script.decodeP2PKInput(buf) + // ### `checkP2PKInput` @@ -271,15 +277,24 @@ check p2pk input format #### Result -valid `Boolean` +valid `boolean` #### Examples - let signature = '304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801'; - let input = BITBOX.Script.pubKey.input.encode(Buffer.from(signature, 'hex')); - BITBOX.Script.pubKey.input.check(input); + // check p2pk input + let input = '304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801'; + let buf = Buffer.from(input, 'hex') + let encoded = bitbox.Script.encodeP2PKInput(buf) + bitbox.Script.checkP2PKInput(encoded) // true + // check null data output + let data = "BCHForEveryone"; + let buf = Buffer.from(data, 'ascii') + let encoded = bitbox.Script.encodeNullDataOutput(buf); + bitbox.Script.checkP2PKInput(encoded) + // false + ### `encodeP2PKOutput` p2pk output template: `` `pubKey` OP_CHECKSIG `` @@ -290,14 +305,14 @@ p2pk output template: `` `pubKey` OP_CHECKSIG `` #### Result -buffer `Buffer` +output `Buffer` #### Examples - let pubKey = '02d305772e0873fba6c1c7ff353ce374233316eb5820acd7ff3d7d9b82d514126b'; - let buf = BITBOX.Script.pubKey.output.encode(Buffer.from(pubKey, 'hex')); - // - BITBOX.Script.toASM(buf) + let pubKey = '02d305772e0873fba6c1c7ff353ce374233316eb5820acd7ff3d7d9b82d514126b' + let buf = Buffer.from(pubKey, 'hex') + let encoded = bitbox.Script.encodeP2PKOutput(buf) + bitbox.Script.toASM(encoded) // 02d305772e0873fba6c1c7ff353ce374233316eb5820acd7ff3d7d9b82d514126b OP_CHECKSIG ### `decodeP2PKOutput` @@ -306,17 +321,18 @@ decode p2pk output #### Arguments -1. pubKey `Buffer` +1. output `Buffer` #### Result -buffer `Buffer` +decoded `Buffer` #### Examples - let hex = '2102d305772e0873fba6c1c7ff353ce374233316eb5820acd7ff3d7d9b82d514126bac'; - BITBOX.Script.pubKey.output.decode(Buffer.from(hex, 'hex')); - // + let output = '2102d305772e0873fba6c1c7ff353ce374233316eb5820acd7ff3d7d9b82d514126bac'; + let buf = Buffer.from(output, 'hex') + bitbox.Script.decodeP2PKOutput(buf) + // ### `checkP2PKOutput` @@ -328,16 +344,24 @@ check P2PK output format #### Result -valid `Boolean` +valid `boolean` #### Examples // check p2pk output - let pubKey = '02d305772e0873fba6c1c7ff353ce374233316eb5820acd7ff3d7d9b82d514126b'; - let buf = BITBOX.Script.pubKey.output.encode(Buffer.from(pubKey, 'hex')); - BITBOX.Script.pubKey.output.check(buf); + let output = '02d305772e0873fba6c1c7ff353ce374233316eb5820acd7ff3d7d9b82d514126b'; + let buf = Buffer.from(output, 'hex') + let encoded = bitbox.Script.encodeP2PKOutput(buf) + bitbox.Script.checkP2PKOutput(encoded) // true + // null data output + let data = "BCHForEveryone"; + let buf = Buffer.from(data, 'ascii') + let encoded = bitbox.Script.encodeNullDataOutput(buf); + bitbox.Script.checkP2PKOutput(encoded) + // false + ### `encodeP2PKHInput` p2pkh input template: `` `signature` `pubKey` `` @@ -349,15 +373,16 @@ p2pkh input template: `` `signature` `pubKey` `` #### Result -buffer `Buffer` +encoded `Buffer` #### Examples let signature = '304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801'; let pubKey = '02d9bb8da1de26d390b6f3dcb4e589857730536b646995fa948a8319ede2ca1c15'; - let buf = BITBOX.Script.pubKeyHash.input.encode(Buffer.from(signature, 'hex'), Buffer.from(pubKey, 'hex')); - // - BITBOX.Script.toASM(buf); + let sigBuf = Buffer.from(signature, 'hex') + let pubKeyBuf = Buffer.from(pubKey, 'hex') + let encoded = bitbox.Script.encodeP2PKHInput(sigBuf, pubKeyBuf); + bitbox.Script.toASM(encoded); // 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 02d9bb8da1de26d390b6f3dcb4e589857730536b646995fa948a8319ede2ca1c15 ### `decodeP2PKHInput` @@ -366,18 +391,20 @@ decode p2pkh input #### Arguments -1. signature `Buffer` +1. input `Buffer` #### Result -buffer `Buffer` +decoded `Buffer` #### Examples - let hex = '47304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca28012102d9bb8da1de26d390b6f3dcb4e589857730536b646995fa948a8319ede2ca1c15'; - BITBOX.Script.pubKeyHash.input.decode(Buffer.from(hex, 'hex')); - // { signature: , - // pubKey: } + let input = '47304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca28012102d9bb8da1de26d390b6f3dcb4e589857730536b646995fa948a8319ede2ca1c15' + let buf = Buffer.from(input, 'hex') + bitbox.Script.decodeP2PKHInput(buf) + // { signature: + // , + // pubKey: } ### `checkP2PKHInput` @@ -389,37 +416,44 @@ check P2PKH input format #### Result -valid `Boolean` +valid `boolean` #### Examples // check p2pkh input let signature = '304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801'; let pubKey = '02d9bb8da1de26d390b6f3dcb4e589857730536b646995fa948a8319ede2ca1c15'; - let buf = BITBOX.Script.pubKeyHash.input.encode(Buffer.from(signature, 'hex'), Buffer.from(pubKey, 'hex')); - BITBOX.Script.pubKeyHash.input.check(buf); + let sigBuf = Buffer.from(signature, 'hex') + let pubKeyBuf = Buffer.from(pubKey, 'hex') + let encoded = bitbox.Script.encodeP2PKHInput(sigBuf, pubKeyBuf); + bitbox.Script.checkP2PKHInput(encoded); // true + // check p2pk input + let input = '304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801'; + let buf = Buffer.from(input, 'hex') + let encoded = bitbox.Script.encodeP2PKInput(buf) + bitbox.Script.checkP2PKHInput(encoded); + // false + ### `encodeP2PKHOutput` p2pkh output template: `` OP_DUP OP_HASH160 `pubKeyHash` OP_EQUALVERIFY OP_CHECKSIG `` #### Arguments -1. signature `Buffer` -2. pubKey `Buffer` +1. identifier `Buffer` #### Result -buffer `Buffer` +output `Buffer` #### Examples - let node = BITBOX.HDNode.fromXPriv('xprv9xoxVbZ7L8jmvKx7e1hgd7muo8H35ysTx1LCKFey5nVHUkHSPBxpzBzt2HVK16hu4m6oN5vfaCWSZQvqtDhfJTCY3t9ocp7H7zcTZ2fVRwL'); - let identifier = BITBOX.HDNode.toIdentifier(node); - let buf = BITBOX.Script.pubKeyHash.output.encode(identifier); - // - BITBOX.Script.toASM(buf) + let node = bitbox.HDNode.fromXPriv('xprv9xoxVbZ7L8jmvKx7e1hgd7muo8H35ysTx1LCKFey5nVHUkHSPBxpzBzt2HVK16hu4m6oN5vfaCWSZQvqtDhfJTCY3t9ocp7H7zcTZ2fVRwL'); + let identifier = bitbox.HDNode.toIdentifier(node); + let output = bitbox.Script.encodeP2PKHOutput(identifier); + bitbox.Script.toASM(output) // OP_DUP OP_HASH160 6ee7ded4f9d0deb6f4a63d68df5ccc4e41ad8967 OP_EQUALVERIFY OP_CHECKSIG ### `decodeP2PKHOutput` @@ -432,13 +466,14 @@ decode p2pkh output #### Result -buffer `Buffer` +decoded `Buffer` #### Examples - let hex = '76a9146ee7ded4f9d0deb6f4a63d68df5ccc4e41ad896788ac'; - BITBOX.Script.pubKeyHash.output.decode(Buffer.from(hex, 'hex')); - // + let output = '76a9146ee7ded4f9d0deb6f4a63d68df5ccc4e41ad896788ac'; + let buf = Buffer.from(output, 'hex') + bitbox.Script.pubKeyHash.output.decode(buf); + // ### `checkP2PKHOutput` @@ -450,41 +485,45 @@ check P2PKH output format #### Result -valid `Boolean` +valid `boolean` #### Examples // check p2pkh output - let node = BITBOX.HDNode.fromXPriv('xprv9xoxVbZ7L8jmvKx7e1hgd7muo8H35ysTx1LCKFey5nVHUkHSPBxpzBzt2HVK16hu4m6oN5vfaCWSZQvqtDhfJTCY3t9ocp7H7zcTZ2fVRwL'); - let identifier = BITBOX.HDNode.toIdentifier(node); - let buf = BITBOX.Script.pubKeyHash.output.encode(identifier); - BITBOX.Script.pubKeyHash.output.check(buf); + let node = bitbox.HDNode.fromXPriv('xprv9xoxVbZ7L8jmvKx7e1hgd7muo8H35ysTx1LCKFey5nVHUkHSPBxpzBzt2HVK16hu4m6oN5vfaCWSZQvqtDhfJTCY3t9ocp7H7zcTZ2fVRwL'); + let identifier = bitbox.HDNode.toIdentifier(node); + let output = bitbox.Script.encodeP2PKHOutput(identifier); + bitbox.Script.checkP2PKHOutput(output); // true + + // check p2pk output + let output = '02d305772e0873fba6c1c7ff353ce374233316eb5820acd7ff3d7d9b82d514126b'; + let buf = Buffer.from(output, 'hex') + let encoded = bitbox.Script.encodeP2PKOutput(buf) + bitbox.Script.checkP2PKHOutput(encoded); + // false + ### `encodeP2MSInput` p2ms Input template: `OP_0 [signatures ...]` #### Arguments -1. signatures `Array` +1. signatures `Buffer[]` #### Result -buffer `Buffer` +encoded `Buffer` #### Examples let signatures = [ - "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801", - "3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501" + Buffer.from("304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801", "hex"), + Buffer.from("3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501", "hex") ]; - let sigs = signatures.map((signature) => { - return signature ? Buffer.from(signature, 'hex') : BITBOX.Script.opcodes.OP_0 - }) - let buf = BITBOX.Script.multisig.input.encode(sigs); - // - BITBOX.Script.toASM(buf); + let encoded = bitbox.Script.encodeP2MSInput(signatures); + bitbox.Script.toASM(encoded); // OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d14050 ### `decodeP2MSInput` @@ -497,14 +536,15 @@ decode p2ms input #### Result -buffer `Buffer` +decoded `Buffer[]` #### Examples let hex = '0047304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801483045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501'; - BITBOX.Script.multisig.input.decode(Buffer.from(hex, 'hex')); - // [ , - // ] + let input = Buffer.from(hex, 'hex') + bitbox.Script.multisig.input.decode(input); + // [ , + // ] ### `checkP2MSInput` @@ -516,45 +556,50 @@ check P2MS input format #### Result -valid `Boolean` +valid `boolean` #### Examples + // check p2ms input let signatures = [ - "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801", - "3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501" + Buffer.from("304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801", "hex"), + Buffer.from("3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501", "hex") ]; - let sigs = signatures.map((signature) => { - return signature ? Buffer.from(signature, 'hex') : BITBOX.Script.opcodes.OP_0 - }) - let buf = BITBOX.Script.multisig.input.encode(sigs); - BITBOX.Script.multisig.input.check(buf); + let encoded = bitbox.Script.encodeP2MSInput(signatures); + bitbox.Script.checkP2MSInput(encoded); // true + // check p2pkh input + let signature = '304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801'; + let pubKey = '02d9bb8da1de26d390b6f3dcb4e589857730536b646995fa948a8319ede2ca1c15'; + let sigBuf = Buffer.from(signature, 'hex') + let pubKeyBuf = Buffer.from(pubKey, 'hex') + let encoded = bitbox.Script.encodeP2PKHInput(sigBuf, pubKeyBuf); + bitbox.Script.checkP2MSInput(encoded); + // false + ### `encodeP2MSOutput` p2ms Output template: `m [pubKeys ...] n OP_CHECKMULTISIG` #### Arguments -1. m `Number` -2. pubKeys `Array` +1. m `number` +2. pubKeys `Buffer[]` #### Result -buffer `Buffer` +output `Buffer` #### Examples - let arr = [ - "02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1", - "0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a" + let pubKeys = [ + Buffer.from("02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1", "hex"), + Buffer.from("0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a", "hex") ]; - let pubKeys = arr.map((p) => { return Buffer.from(p, 'hex') }) let m = pubKeys.length - let buf = BITBOX.Script.multisig.output.encode(m, pubKeys); - // - BITBOX.Script.toASM(buf); + let buf = bitbox.Script.encodeP2MSOutput(m, pubKeys); + bitbox.Script.toASM(buf); // OP_2 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a OP_2 OP_CHECKMULTISIG ### `decodeP2MSOutput` @@ -572,11 +617,11 @@ buffer `Buffer` #### Examples let hex = '522102359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1210395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a52ae'; - BITBOX.Script.multisig.output.decode(Buffer.from(hex, 'hex')); + let output = Buffer.from(hex, 'hex') + bitbox.Script.decodeP2MSOutput(output); // { m: 2, - // pubKeys: - // [ , - // ] } + // pubKeys: [ , + // ] } ### `checkP2MSOutput` @@ -584,24 +629,30 @@ check P2MS output format #### Arguments -1. input `Buffer` +1. output `Buffer` #### Result -valid `Boolean` +valid `boolean` #### Examples - let arr = [ - "02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1", - "0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a" + // check p2ms output + let pubKeys = [ + Buffer.from("02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1", "hex"), + Buffer.from("0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a", "hex") ]; - let pubKeys = arr.map((p) => { return Buffer.from(p, 'hex') }) let m = pubKeys.length - let buf = BITBOX.Script.multisig.output.encode(m, pubKeys); - BITBOX.Script.multisig.output.check(buf); + let output = bitbox.Script.encodeP2MSOutput(m, pubKeys); + bitbox.Script.checkP2MSOutput(output); // true + let node = bitbox.HDNode.fromXPriv('xprv9xoxVbZ7L8jmvKx7e1hgd7muo8H35ysTx1LCKFey5nVHUkHSPBxpzBzt2HVK16hu4m6oN5vfaCWSZQvqtDhfJTCY3t9ocp7H7zcTZ2fVRwL'); + let identifier = bitbox.HDNode.toIdentifier(node); + let output = bitbox.Script.encodeP2PKHOutput(identifier); + bitbox.Script.checkP2MSOutput(output); + // false + ### `encodeP2SHInput` p2sh Input template: `` `scriptSig` `serialized scriptPubKey script` `` @@ -613,15 +664,14 @@ p2sh Input template: `` `scriptSig` `serialized scriptPubKey script` `` #### Result -buffer `Buffer` +input`Buffer` #### Examples - let redeemScriptSig = BITBOX.Script.fromASM("OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501"); - let redeemScript = BITBOX.Script.fromASM("OP_2 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a OP_2 OP_CHECKMULTISIG"); - let buf = BITBOX.Script.scriptHash.input.encode(redeemScriptSig, redeemScript); - // - BITBOX.Script.toASM(buf) + let redeemScriptSig = bitbox.Script.fromASM("OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501"); + let redeemScript = bitbox.Script.fromASM("OP_2 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a OP_2 OP_CHECKMULTISIG"); + let input = bitbox.Script.encodeP2SHInput(redeemScriptSig, redeemScript); + bitbox.Script.toASM(input) // OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501 522102359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1210395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a52ae ### `decodeP2SHInput` @@ -634,14 +684,15 @@ decode p2sh input #### Result -buffer `Buffer` +decoded `Buffer` #### Examples - let hex = '0047304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801483045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d14050147522102359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1210395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a52ae'; - BITBOX.Script.scriptHash.input.decode(Buffer.from(hex, 'hex')); - // { redeemScript: , - // redeemScriptSig: } + let hex = '0047304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801483045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d14050147522102359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1210395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a52ae' + let input = Buffer.from(hex, 'hex') + bitbox.Script.decodeP2SHInput(input) + // { redeemScript: , + // redeemScriptSig: }} ### `checkP2SHInput` @@ -653,16 +704,26 @@ check P2SH input format #### Result -valid `Boolean` +valid `boolean` #### Examples - let redeemScriptSig = BITBOX.Script.fromASM("OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501"); - let redeemScript = BITBOX.Script.fromASM("OP_2 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a OP_2 OP_CHECKMULTISIG"); - let buf = BITBOX.Script.scriptHash.input.encode(redeemScriptSig, redeemScript); - BITBOX.Script.scriptHash.input.check(buf); + // check p2sh input + let redeemScriptSig = bitbox.Script.fromASM("OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501") + let redeemScript = bitbox.Script.fromASM("OP_2 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a OP_2 OP_CHECKMULTISIG") + let input = bitbox.Script.encodeP2SHInput(redeemScriptSig, redeemScript) + bitbox.Script.checkP2SHInput(input) // true + // check p2ms input + let signatures = [ + Buffer.from("304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801", "hex"), + Buffer.from("3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501", "hex") + ]; + let input = bitbox.Script.encodeP2MSInput(signatures); + bitbox.Script.checkP2SHInput(input) + // false + ### `encodeP2SHOutput` p2sh Output template: `` OP_HASH160 `scriptHash` OP_EQUAL `` @@ -673,15 +734,14 @@ p2sh Output template: `` OP_HASH160 `scriptHash` OP_EQUAL `` #### Result -buffer `Buffer` +output `Buffer` #### Examples - let redeemScript = BITBOX.Script.fromASM("OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG"); - let scriptHash = BITBOX.Crypto.hash160(redeemScript); - let buf = BITBOX.Script.scriptHash.output.encode(scriptHash); - // - BITBOX.Script.toASM(buf) + let redeemScript = bitbox.Script.fromASM("OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG"); + let scriptHash = bitbox.Crypto.hash160(redeemScript); + let output = bitbox.Script.encodeP2SHOutput(scriptHash); + bitbox.Script.toASM(output) // OP_HASH160 1b61ebed0c2a16c699a99c3d5ef4d08de7fb1cb8 OP_EQUAL ### `decodeP2SHOutput` @@ -694,13 +754,14 @@ decode p2sh output #### Result -buffer `Buffer` +decoded `Buffer` #### Examples - let hex = 'a9141b61ebed0c2a16c699a99c3d5ef4d08de7fb1cb887'; - BITBOX.Script.scriptHash.output.decode(Buffer.from(hex, 'hex')); - // + let hex = 'a9141b61ebed0c2a16c699a99c3d5ef4d08de7fb1cb887' + let output = Buffer.from(hex, 'hex') + bitbox.Script.decodeP2SHOutput(output) + // ### `checkP2SHOutput` @@ -712,16 +773,27 @@ check P2SH output format #### Result -valid `Boolean` +valid `boolean` #### Examples - let redeemScript = BITBOX.Script.fromASM("OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG"); - let scriptHash = BITBOX.Crypto.hash160(redeemScript); - let buf = BITBOX.Script.scriptHash.output.encode(scriptHash); - BITBOX.Script.scriptHash.output.check(buf); + // check p2sh output + let redeemScript = bitbox.Script.fromASM("OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG") + let scriptHash = bitbox.Crypto.hash160(redeemScript) + let output = bitbox.Script.encodeP2SHOutput(scriptHash) + bitbox.Script.checkP2SHOutput(output); // true + // check p2ms output + let pubKeys = [ + Buffer.from("02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1", "hex"), + Buffer.from("0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a", "hex") + ]; + let m = pubKeys.length + let output = bitbox.Script.encodeP2MSOutput(m, pubKeys); + bitbox.Script.checkP2SHOutput(output); + // false + ### `classifyInput` Classify transaction input @@ -732,24 +804,24 @@ Classify transaction input #### Result -type `String` +type `string` #### Examples let pubkeyInput = "3045022100ba2c3b717e023966cb16df65ca83f77029e2a5b80c47c47b6956474ac9ff281302201d48ee3292439e284a6654a0e79ac2b8f7fff5c6b0d715260aa296501a239c6441"; - BITBOX.Script.classifyInput(BITBOX.Script.fromASM(pubkeyInput)); + bitbox.Script.classifyInput(bitbox.Script.fromASM(pubkeyInput)); // pubkey let pubkeyhashInput = "30440220280d4a9954c5afe24089bdd545466bd7a8caad8b295e30de9d3cb5e56fccf64e022036663b2c53b5fac674b4b935b53e2a4ea88dfc71c9b879870976d82887542ab441 02969479fa9bea3082697dce683ac05b13ae63016b41d5ca1a450ad40f6c543751"; - BITBOX.Script.classifyInput(BITBOX.Script.fromASM(pubkeyhashInput)); + bitbox.Script.classifyInput(bitbox.Script.fromASM(pubkeyhashInput)); // pubkeyhash let multisigInput = "OP_0 3045022100fe324541215798b2df68cbd44039615e23c506d4ec1a05572064392a98196b82022068c849fa6699206da2fc6d7848efc1d3804a5816d6293615fe34c1a7f34e1c2f01 3044022001ab168e80b863fdec694350b587339bb72a37108ac3c989849251444d13ebba02201811272023e3c1038478eb972a82d3ad431bfc2408e88e4da990f1a7ecbb263901 3045022100aaeb7204c17eee2f2c4ff1c9f8b39b79e75e7fbf33e92cc67ac51be8f15b75f90220659eee314a4943a6384d2b154fa5821ef7a084814d7ee2c6f9f7f0ffb53be34b01"; - BITBOX.Script.classifyInput(BITBOX.Script.fromASM(multisigInput)); + bitbox.Script.classifyInput(bitbox.Script.fromASM(multisigInput)); // multisig let scripthashInput = "OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501 522102359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1210395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a52ae"; - BITBOX.Script.classifyInput(BITBOX.Script.fromASM(scripthashInput)); + bitbox.Script.classifyInput(bitbox.Script.fromASM(scripthashInput)); // scripthash ### `classifyOutput` @@ -762,26 +834,306 @@ Classify transaction output #### Result -type `String` +type `string` #### Examples let nullDataOutput = "OP_RETURN 424348466f7245766572796f6e65"; - BITBOX.Script.classifyOutput(BITBOX.Script.fromASM(nullDataOutput)); + bitbox.Script.classifyOutput(bitbox.Script.fromASM(nullDataOutput)); // nulldata let pubkeyOutput = "02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 OP_CHECKSIG"; - BITBOX.Script.classifyOutput(BITBOX.Script.fromASM(pubkeyOutput)); + bitbox.Script.classifyOutput(bitbox.Script.fromASM(pubkeyOutput)); // pubkey let pubkeyhashOutput = "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG"; - BITBOX.Script.classifyOutput(BITBOX.Script.fromASM(pubkeyhashOutput)); + bitbox.Script.classifyOutput(bitbox.Script.fromASM(pubkeyhashOutput)); // pubkeyhash let multisigOutput = "OP_2 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a OP_2 OP_CHECKMULTISIG"; - BITBOX.Script.classifyOutput(BITBOX.Script.fromASM(multisigOutput)); + bitbox.Script.classifyOutput(bitbox.Script.fromASM(multisigOutput)); // multisig let scripthashOutput = "OP_HASH160 722ff0bc2c3f47b35c20df646c395594da24e90e OP_EQUAL"; - BITBOX.Script.classifyOutput(BITBOX.Script.fromASM(scripthashOutput)); + bitbox.Script.classifyOutput(bitbox.Script.fromASM(scripthashOutput)); // scripthash + +### `encodeNumber` + +Classify transaction output + +#### Arguments + +1. number: `number` + +#### Result + +hex `string` + +#### Examples + + bitbox.Script.encodeNumber(1) + // "01" + + bitbox.Script.encodeNumber(1000) + // "e803" + +### `decodeNumber` + +Classify transaction output + +#### Arguments + +1. buffer: `Buffer` +2. maxLength: `number` **optional** +3. minimal: `boolean` **optional** + +#### Result + +hex `string` + +#### Examples + + bitbox.Script.number.decode(Buffer.from("01", 'hex')) + // 1 + + bitbox.Script.number.decode(Buffer.from("e803", 'hex')) + // 1000 + +## Interfaces + +### opcodes + + { + OP_FALSE: 0 + OP_0: 0 + OP_PUSHDATA1: 76 + OP_PUSHDATA2: 77 + OP_PUSHDATA4: 78 + OP_1NEGATE: 79 + OP_RESERVED: 80 + OP_TRUE: 81 + OP_1: 81 + OP_2: 82 + OP_3: 83 + OP_4: 84 + OP_5: 85 + OP_6: 86 + OP_7: 87 + OP_8: 88 + OP_9: 89 + OP_10: 90 + OP_11: 91 + OP_12: 92 + OP_13: 93 + OP_14: 94 + OP_15: 95 + OP_16: 96 + OP_NOP: 97 + OP_VER: 98 + OP_IF: 99 + OP_NOTIF: 100 + OP_VERIF: 101 + OP_VERNOTIF: 102 + OP_ELSE: 103 + OP_ENDIF: 104 + OP_VERIFY: 105 + OP_RETURN: 106 + OP_TOALTSTACK: 107 + OP_FROMALTSTACK: 108 + OP_2DROP: 109 + OP_2DUP: 110 + OP_3DUP: 111 + OP_2OVER: 112 + OP_2ROT: 113 + OP_2SWAP: 114 + OP_IFDUP: 115 + OP_DEPTH: 116 + OP_DROP: 117 + OP_DUP: 118 + OP_NIP: 119 + OP_OVER: 120 + OP_PICK: 121 + OP_ROLL: 122 + OP_ROT: 123 + OP_SWAP: 124 + OP_TUCK: 125 + OP_CAT: 126 + OP_SPLIT: 127 + OP_NUM2BIN: 128 + OP_BIN2NUM: 129 + OP_SIZE: 130 + OP_INVERT: 131 + OP_AND: 132 // May 2018 reenabled + OP_OR: 133 // May 2018 reenabled + OP_XOR: 134 // May 2018 reenabled + OP_EQUAL: 135 + OP_EQUALVERIFY: 136 + OP_RESERVED1: 137 + OP_RESERVED2: 138 + OP_1ADD: 139 + OP_1SUB: 140 + OP_2MUL: 141 + OP_2DIV: 142 + OP_NEGATE: 143 + OP_ABS: 144 + OP_NOT: 145 + OP_0NOTEQUAL: 146 + OP_ADD: 147 + OP_SUB: 148 + OP_MUL: 149 + OP_DIV: 150 // May 2018 reenabled + OP_MOD: 151 // May 2018 reenabled + OP_LSHIFT: 152 + OP_RSHIFT: 153 + OP_BOOLAND: 154 + OP_BOOLOR: 155 + OP_NUMEQUAL: 156 + OP_NUMEQUALVERIFY: 157 + OP_NUMNOTEQUAL: 158 + OP_LESSTHAN: 159 + OP_GREATERTHAN: 160 + OP_LESSTHANOREQUAL: 161 + OP_GREATERTHANOREQUAL: 162 + OP_MIN: 163 + OP_MAX: 164 + OP_WITHIN: 165 + OP_RIPEMD160: 166 + OP_SHA1: 167 + OP_SHA256: 168 + OP_HASH160: 169 + OP_HASH256: 170 + OP_CODESEPARATOR: 171 + OP_CHECKSIG: 172 + OP_CHECKSIGVERIFY: 173 + OP_CHECKMULTISIG: 174 + OP_CHECKMULTISIGVERIFY: 175 + OP_NOP1: 176 + OP_NOP2: 177 + OP_CHECKLOCKTIMEVERIFY: 177 + OP_NOP3: 178 + OP_CHECKSEQUENCEVERIFY: 178 + OP_NOP4: 179 + OP_NOP5: 180 + OP_NOP6: 181 + OP_NOP7: 182 + OP_NOP8: 183 + OP_NOP9: 184 + OP_NOP10: 185 + OP_CHECKDATASIG: 186 + OP_CHECKDATASIGVERIFY: 187 + OP_PUBKEYHASH: 253 + OP_PUBKEY: 254 + OP_INVALIDOPCODE: 255 + } + +### DecodedP2PKHInput + + { + signature: Buffer + pubKey: Buffer + } + +### DecodedP2MSOutput + + { + m: number + pubKeys: Buffer[] + } + +### DecodedP2SHInput + + { + redeemScript: Buffer + redeemScriptSig: Buffer + } + +### nullData + + { + output: { + encode(data: Buffer): Buffer + decode(output: Buffer): Buffer + check(output: Buffer): boolean + } + } + +#### pubKey + + { + input: + { + encode(signature: Buffer): Buffer + decode(input: Buffer): Buffer + check(input: Buffer): boolean + decodeStack(data: Buffer): Buffer + encodeStack(data: Buffer): Buffer + }, + output: { + encode(pubKey: Buffer): Buffer + decode(output: Buffer): Buffer + check(output: Buffer): boolean + } + } + +### pubKeyHash + + { + input: + { + encode(signature: Buffer, pubKey: Buffer): Buffer + decode(data: Buffer): DecodedP2PKHInput + check(data: Buffer): boolean + decodeStack(data: Buffer): Buffer + encodeStack(data: Buffer): Buffer + }, + output: + { + encode(identifier: Buffer): Buffer + decode(output: Buffer): Buffer + check(output: Buffer): boolean + } + } + +### multisig + + { + input: + { + encode(signatures: Buffer[]): Buffer + decode(input: Buffer): Buffer[] + check(input: Buffer): boolean + }, + output: + { + encode(m: number, pubKeys: Buffer[]): Buffer + decode(output: Buffer): DecodedP2MSOutput + check(output: Buffer): boolean + } + } + +### scriptHash + + { + input: + { + encode(redeemScriptSig: Buffer, redeemScript: Buffer): Buffer + decode(input: Buffer): DecodedP2SHInput + check(data: Buffer): boolean + decodeStack(data: Buffer): Buffer + encodeStack(data: Buffer): Buffer + }, + output: + { + encode(scriptHash: Buffer): Buffer + decode(output: Buffer): Buffer + check(output: Buffer): boolean + } + } + +### scriptNumber + + { + encode(number: number): Buffer + decode(buffer: Buffer, maxLength?: number, minimal?: boolean): number + } diff --git a/src/data/docs/bitbox/socket.md b/src/data/docs/bitbox/socket.md index 207068b9..679bc08b 100644 --- a/src/data/docs/bitbox/socket.md +++ b/src/data/docs/bitbox/socket.md @@ -1,7 +1,7 @@ --- title: Socket icon: plug -ordinal: 16 +ordinal: 20 --- ### `constructor` @@ -11,8 +11,10 @@ Create new Socket. #### Arguments 1. config `Object`: with properties: - 1. restURL `String`: optional, Defaults to `https://rest.bitcoin.com` - 2. callback `Function`: optional + 1. wsURL `string`: optional, Defaults to `wss://ws.bitcoin.com` + 2. bitsocketURL `string`: optional + 3. restURL `string`: optional + 4. callback `Function`: optional #### Result @@ -21,7 +23,7 @@ Socket `Socket` #### Examples // instance of Socket - let socket = new BITBOX.Socket({callback: () => {console.log('connected')}, restURL: 'https://rest.bitcoin.com'}) + let socket = new bitbox.Socket({callback: () => {console.log('connected')}, wsURL: 'wss://ws.bitcoin.com'}) ### `listen` @@ -29,7 +31,8 @@ Listen on a websocket to get real\-time data. #### Arguments -1. dataType `String`: type of data to return in real time. Currently only `transactions` +1. query `string | object`: type of data to return in real time. `transactions` or `blocks` are valid `string`s. Any BitSocket `query` object is also valid +2. callback `function`: function to be called which gets passed back `message` in real time. #### Result @@ -37,52 +40,116 @@ data `Object`: data returned in real\-time over a websocket #### Examples - let socket = new BITBOX.Socket({callback: () => {console.log('connected')}, restURL: 'https://rest.bitcoin.com'}) + // raw websocket data example + + let socket = new bitbox.Socket({callback: () => {console.log('connected')}, wsURL: 'wss://ws.bitcoin.com'}) socket.listen('transactions', (message) => { console.log(message) - - // returns the following - { - "format": { - "txid": "edbfdc5a149741009df15f8b518bdebc54261854fcdfefd7d8aa8a78b5e14250", - "version": 2, - "locktime": 0, - "size": 225, - "vsize": 225 - }, - "inputs": [ - { - "txid": "92923f5048703bbf4cb78344d200935b37b88cfaa767635cf0c4275942c9b382", - "n": 3, - "script": "304502210099b59aaf9238612ad9ab706cb469dbd13662177e44cfdc5f29101e9e142ceb10022018061daf1127544f1b97817f2430b9f9c78efe54b51303c91c723807834e4ece41 025cc1f660956d4b924a0792b222ddd9b1742280c5e283281364a9b63123fe23e2", - "sequence": 4294967295 + }) + // returns the following + { + "format": { + "txid": "edbfdc5a149741009df15f8b518bdebc54261854fcdfefd7d8aa8a78b5e14250", + "version": 2, + "locktime": 0, + "size": 225, + "vsize": 225 + }, + "inputs": [ + { + "txid": "92923f5048703bbf4cb78344d200935b37b88cfaa767635cf0c4275942c9b382", + "n": 3, + "script": "304502210099b59aaf9238612ad9ab706cb469dbd13662177e44cfdc5f29101e9e142ceb10022018061daf1127544f1b97817f2430b9f9c78efe54b51303c91c723807834e4ece41 025cc1f660956d4b924a0792b222ddd9b1742280c5e283281364a9b63123fe23e2", + "sequence": 4294967295 + } + ], + "outputs": [ + { + "satoshi": 6526, + "value": "0.00006526", + "n": 0, + "scriptPubKey": { + "asm": "OP_DUP OP_HASH160 670180972852c974359232baa64f4019f205bfbc OP_EQUALVERIFY OP_CHECKSIG", + "hex": "76a914670180972852c974359232baa64f4019f205bfbc88ac", + "type": "pubkeyhash", + "addresses": [ + "1APeQ9A39esuwsPDogNZYpGS5CxC54m5CL" + ] } - ], - "outputs": [ - { - "satoshi": 6526, - "value": "0.00006526", - "n": 0, - "scriptPubKey": { - "asm": "OP_DUP OP_HASH160 670180972852c974359232baa64f4019f205bfbc OP_EQUALVERIFY OP_CHECKSIG", - "hex": "76a914670180972852c974359232baa64f4019f205bfbc88ac", - "type": "pubkeyhash", - "addresses": [ - "1APeQ9A39esuwsPDogNZYpGS5CxC54m5CL" - ] - } - }, - { - "satoshi": 0, - "value": "0.00000000", - "n": 1, - "scriptPubKey": { - "asm": "OP_RETURN 73747265737374657374626974636f696e2e63617368", - "hex": "6a1673747265737374657374626974636f696e2e63617368", - "type": "nulldata", - "addresses": [] - } + }, + { + "satoshi": 0, + "value": "0.00000000", + "n": 1, + "scriptPubKey": { + "asm": "OP_RETURN 73747265737374657374626974636f696e2e63617368", + "hex": "6a1673747265737374657374626974636f696e2e63617368", + "type": "nulldata", + "addresses": [] } - ] + } + ] + } + + + let socket = new bitbox.Socket({callback: () => {console.log('connected')}, wsURL: 'https://ws.bitcoin.com'}) + socket.listen('blocks', (message) => { + console.log(message) + }) + // returns the following + { + "transactions": 183, + "totalBCHSent": 1057662477171, + "reward": 1250000000, + "prevHash": "cfac607ebae85629ede7d34f36064d24974f95c90b89c5000000000000000000", + "id": "0d2d939b3793ff8b2e130fe1f5257abd7784bfe147009f000000000000000000", + "hash": "0000000000000000009f0047e1bf8477bd7a25f5e10f132e8bff93379b932d0d", + "merkleRoot": "ac040e9130a71647f29dc55355fbe8db8bb1a5f1ac86b7ee1be0ae8488dc407e", + "version": 549453824, + "time": 1558667998, + "bits": 402882446, + "nonce": 2478895818 + } + + // BitSocket query example + let socket = new bitbox.Socket({ + callback: () => { + console.log("connected") + }, + wsURL: "wss://ws.bitcoin.com" + }) + socket.listen( + { + v: 3, + q: { find: {} } + }, + msg => { + setTimeout(function() { + socket.close(() => { + console.log("closed") + }) + }, 5000) } + ) + // returns + // {"type":"mempool","data":[{"tx":{"h":"09ff3049857875089519407e6d00634c901ca3e42b79c2357f07ca0806255abd"},"in":[{"i":0,"b0":"MEUCIQD1aIxxL/QsWBU+yaRTWi8CPtF22Lgj9FyFgs/Tk0MzTAIgTrw3P06CszZYN3hE6AzRSntvutzpgb5YM5ydgQJrWhJB","b1":"BGf/LfIPKLxirRiFJYaPQdRh99qzweUAMUzbUhjlY3v9D5wC61s/OD9pjSj/E1R+rwXdkhYTCGHdAhaCTp1zN+M=","str":"3045022100f5688c712ff42c58153ec9a4535a2f023ed176d8b823f45c8582cfd39343334c02204ebc373f4e82b33658377844e80cd14a7b6fbadce981be58339c9d81026b5a1241 0467ff2df20f28bc62ad188525868f41d461f7dab3c1e500314cdb5218e5637bfd0f9c02eb5b3f383f698d28ff13547eaf05dd9216130861dd0216824e9d7337e3","e":{"h":"6749fdb788c89abcbd28008470b7823e6658ce82b6939135ea52dd6df3d529bd","i":1,"a":"qqrxa0h9jqnc7v4wmj9ysetsp3y7w9l36u8gnnjulq"},"h0":"3045022100f5688c712ff42c58153ec9a4535a2f023ed176d8b823f45c8582cfd39343334c02204ebc373f4e82b33658377844e80cd14a7b6fbadce981be58339c9d81026b5a1241","h1":"0467ff2df20f28bc62ad188525868f41d461f7dab3c1e500314cdb5218e5637bfd0f9c02eb5b3f383f698d28ff13547eaf05dd9216130861dd0216824e9d7337e3"}],"out":[{"i":0,"b0":{"op":106},"b1":"XUh5xw==","s1":"]Hy�","b2":"Rjj8ADakaq4888s+Ock4xDyiM5w8CFCcNgQ0WDfncRM=","s2":"F8�\u00006�j�<��>9�8�<�3�<\bP�6\u00044X7�q\u0013","str":"OP_RETURN 5d4879c7 4638fc0036a46aae3cf3cb3e39c938c43ca2339c3c08509c3604345837e77113","e":{"v":0,"i":0},"h1":"5d4879c7","h2":"4638fc0036a46aae3cf3cb3e39c938c43ca2339c3c08509c3604345837e77113"},{"i":1,"b0":{"op":118},"b1":{"op":169},"b2":"Bm6+5ZAnjzKu3IpIZXAMSecX8dc=","s2":"\u0006n��'�2�܊Hep\fI�\u0017��","b3":{"op":136},"b4":{"op":172},"str":"OP_DUP OP_HASH160 066ebee590278f32aedc8a4865700c49e717f1d7 OP_EQUALVERIFY OP_CHECKSIG","e":{"v":2020,"i":1,"a":"qqrxa0h9jqnc7v4wmj9ysetsp3y7w9l36u8gnnjulq"},"h2":"066ebee590278f32aedc8a4865700c49e717f1d7"}],"_id":"5d4879c8a236c608b89c551e"}]} + // closed + +### `close` + +Close websocket connection + +#### Arguments + +1. callback `function` (optional): function to be called. + +#### Examples + + let socket = new bitbox.Socket({callback: () => {console.log('connected')}, wsURL: 'wss://ws.bitcoin.com'}) + socket.listen('transactions', (message) => { + socket.close(() => { + console.log("closed") + }) }) + // returns the following + // closed diff --git a/src/data/docs/bitbox/transaction.md b/src/data/docs/bitbox/transaction.md index 23462883..652394ac 100644 --- a/src/data/docs/bitbox/transaction.md +++ b/src/data/docs/bitbox/transaction.md @@ -1,7 +1,7 @@ --- title: Transaction icon: exchange -ordinal: 17 +ordinal: 21 --- ## Transaction @@ -12,20 +12,18 @@ Return details about a Transaction. #### Arguments -- txids (required): - - `String`: transaction ID - - `Array` of strings: collection of transaction IDs +- txids `string | string[]`: transaction ID #### Result -details `Array`: Array of Objects with details about transactions +details `Promise` #### Examples // single txid (async () => { try { - let details = await BITBOX.Transaction.details('a85fa3d831ab6b0305e7ff88d2d4941e25a810d4461635df51490653822071a8'); + let details = await bitbox.Transaction.details('a85fa3d831ab6b0305e7ff88d2d4941e25a810d4461635df51490653822071a8'); console.log(details); } catch(error) { console.error(error) @@ -73,7 +71,7 @@ details `Array`: Array of Objects with details about transactions // array of txids (async () => { try { - let details = await BITBOX.Transaction.details(["a85fa3d831ab6b0305e7ff88d2d4941e25a810d4461635df51490653822071a8", "113f1fe1c454a56436d4f93c7c6e315d1ed985d111299e9c2a3e2d3d1e9f177f"]); + let details = await bitbox.Transaction.details(["a85fa3d831ab6b0305e7ff88d2d4941e25a810d4461635df51490653822071a8", "113f1fe1c454a56436d4f93c7c6e315d1ed985d111299e9c2a3e2d3d1e9f177f"]); console.log(details); } catch(error) { console.error(error) @@ -107,3 +105,23 @@ details `Array`: Array of Objects with details about transactions // size: 372, // valueIn: 2.0997689, // fees: 0.00011201 } ] + +## Interfaces + +### TxnDetails + + { + txid: string + version: number + locktime: number + vin: object[] + vout: object[] + blockhash: string + blockheight: number + confirmations: number + time: number + blocktime: number + isCoinBase: boolean + valueOut: number + size: number + } diff --git a/src/data/docs/bitbox/transactionBuilder.md b/src/data/docs/bitbox/transactionBuilder.md index ffcebe5d..bceda8b3 100644 --- a/src/data/docs/bitbox/transactionBuilder.md +++ b/src/data/docs/bitbox/transactionBuilder.md @@ -1,16 +1,17 @@ --- title: TransactionBuilder icon: arrows-vertical -ordinal: 18 +ordinal: 22 --- ### `constructor` Create new Transaction Builder. +The Transaction Builder object represents a transaction internally and is used to build a transaction step-by-step. It can then be expressed as a hexadecimal `string` ready to be sent to the \$BCH network. The necessary steps to create a transaction are: [`addInput`](#addinput), [`addOutput`](#addoutput), [`setLockTime`](#setlocktime), [`sign`](#sign) and [`build`](#build). #### Arguments -1. network `String`: Defaults to "mainnet" +1. network `string`: Defaults to "mainnet" #### Result @@ -19,7 +20,7 @@ TransactionBuilder `TransactionBuilder` #### Examples // instance of transaction builder - let transactionBuilder = new BITBOX.TransactionBuilder('mainnet'); + let transactionBuilder = new bitbox.TransactionBuilder('mainnet'); ### `hashTypes` @@ -41,16 +42,26 @@ BITBOX supports the `SIGHASH_ALL`, `SIGHASH_NONE` and `SIGHASH_SINGLE` hash type transactionBuilder.DEFAULT_SEQUENCE // 4294967295 +### `signatureAlgorithms` + +BITBOX supports the `ECDSA` and `SCHNORR` signature algorithms. + +#### Examples + + transactionBuilder.signatureAlgorithms + // { ECDSA: 0, + // SCHNORR: 1 } + ### `addInput` Add input to transaction #### Arguments -1. txid `String` (required): txid of vout -2. index `Number` (required): index of vout -3. sequence `Number` (optional): relative lock time. Default `0xffffffff` -4. prevOutScript `String` (optional): previous output script +1. txid `string`: txid of vout +2. index `number`: index of vout +3. sequence `number` **optional**: relative lock time. Default `0xffffffff` +4. prevOutScript `string` **optional**: previous output script #### Examples @@ -65,13 +76,13 @@ Add output to transaction #### Arguments -1. scriptPubKey `String`: legacy/cashaddr address or script -2. sendAmount `Number`: amount to send in satoshis +1. scriptPubKey `string`: legacy/cashaddr address or script +2. sendAmount `number`: amount to send in satoshis #### Examples let originalAmount = 100000; - let byteCount = BITBOX.BitcoinCash.getByteCount({ P2PKH: 1 }, { P2PKH: 1 }); + let byteCount = bitbox.BitcoinCash.getByteCount({ P2PKH: 1 }, { P2PKH: 1 }); // amount to send to receiver. It's the original amount - 1 sat/byte for tx size let sendAmount = originalAmount - byteCount; // add output w/ address and amount to send @@ -79,16 +90,16 @@ Add output to transaction ### `setLockTime` -Set locktime +Set [locktime](https://developer.bitcoin.com/mastering-bitcoin-cash/4-transactions/#transaction-locktime) #### Arguments -1. locktime `Number` +1. locktime `number` #### Examples let originalAmount = 100000; - let byteCount = BITBOX.BitcoinCash.getByteCount({ P2PKH: 1 }, { P2PKH: 1 }); + let byteCount = bitbox.BitcoinCash.getByteCount({ P2PKH: 1 }, { P2PKH: 1 }); // amount to send to receiver. It's the original amount - 1 sat/byte for tx size let sendAmount = originalAmount - byteCount; // add output w/ address and amount to send @@ -97,27 +108,28 @@ Set locktime ### `sign` -Sign transaction +Sign transaction. It creates the unlocking script needed to spend an input. Each input has its own script and thus 'sign' must be called for each input even if the keyPair is the same. #### Arguments -1. vin `Number`: vin to sign +1. vin `number`: vin to sign 2. keyPair `ECPair`: ECPair of HDNode 3. redeemScript `Buffer` -4. hashType `Number` -5. originalAmount `Number`: satoshis in vin +4. hashType `number` +5. originalAmount `number`: satoshis in vin +6. signatureAlgorithm **optional** `number`: Signature Algorithm (ECDSA/Schnorr) #### Examples let originalAmount = 100000; // node of address which is going to spend utxo - let hdnode = BITBOX.HDNode.fromXPriv("xprvA3eaDg64MwDr72PVGJ7CkvshNAzCDRz7rn98sYrZVAtDSWCAmNGQhEQeCLDcnmcpSkfjhHevXmu4ZL8ZcT9D4vEbG8LpiToZETrHZttw9Yw"); + let hdnode = bitbox.HDNode.fromXPriv("xprvA3eaDg64MwDr72PVGJ7CkvshNAzCDRz7rn98sYrZVAtDSWCAmNGQhEQeCLDcnmcpSkfjhHevXmu4ZL8ZcT9D4vEbG8LpiToZETrHZttw9Yw"); // keypair - let keyPair = BITBOX.HDNode.toKeyPair(hdnode); + let keyPair = bitbox.HDNode.toKeyPair(hdnode); // empty redeemScript variable let redeemScript; // sign w/ keyPair - transactionBuilder.sign(0, keyPair, redeemScript, transactionBuilder.hashTypes.SIGHASH_ALL, originalAmount); + transactionBuilder.sign(0, keyPair, redeemScript, transactionBuilder.hashTypes.SIGHASH_ALL, originalAmount, transactionBuilder.signatureAlgorithms.SCHNORR); ### `build` @@ -146,7 +158,7 @@ rawHex `string`: hex encoded raw transaction ready to be sent to the \$BCH netwo let hex = tx.toHex(); // 02000000010e7f337fbaeee563d73e1dccd09be89a90c0bad28126df200958befe150989f7000000006b48304502210085b8eb33f3981315bbe39c6810d0311c6cb39504914300ecd952cab8353222e202200ec95797c06ba8c9b15d59ab80e63300cb2371f67b3969d0b502d0fed733fbed4121025c85a571619e60fed412de0356b4e28f4f3670ab0c2b899dfe60e69aaa6cd4c0ffffffff01a6370000000000001976a91479d3297d1823149f4ec61df31d19f2fad5390c0288ac00000000 // sendRawTransaction to running BCH node - BITBOX.RawTransactions.sendRawTransaction(hex).then((result) => { console.log(result); }, (err) => { console.log(err); }); + bitbox.RawTransactions.sendRawTransaction(hex).then((result) => { console.log(result); }, (err) => { console.log(err); }); // dfe54ec45c6fa2fa85b76d113de85b169d36902eaf6700f1cca21eed1392814b ### `OP_RETURN` @@ -162,8 +174,8 @@ rawHex `string`: hex encoded raw transaction ready to be sent to the \$BCH netwo // encode some text as a buffer let buf = new Buffer('#BCHForEveryone'); // create array w/ OP_RETURN code and text buffer and encode - let data = BITBOX.Script.encode([ - BITBOX.Script.opcodes.OP_RETURN, + let data = bitbox.Script.encode([ + bitbox.Script.opcodes.OP_RETURN, buf ]) // add encoded data as output and send 0 satoshis @@ -173,8 +185,8 @@ rawHex `string`: hex encoded raw transaction ready to be sent to the \$BCH netwo "OP_RETURN 23424348466f7245766572796f6e65" // you can use BITBOX to decode it to the original text - let fromAsm = BITBOX.Script.fromASM("OP_RETURN 23424348466f7245766572796f6e65") - let decoded = BITBOX.Script.decode(fromAsm) + let fromAsm = bitbox.Script.fromASM("OP_RETURN 23424348466f7245766572796f6e65") + let decoded = bitbox.Script.decode(fromAsm) decoded[1].toString('ascii') // #BCHForEveryone @@ -193,7 +205,7 @@ encoded `Buffer` #### Examples - let transactionBuilder = new BITBOX.TransactionBuilder(); + let transactionBuilder = new bitbox.TransactionBuilder(); let r = Buffer.from('1ea1fdff81b3a271659df4aad19bc4ef83def389131a36358fe64b245632e777', 'hex'); let s = Buffer.from('29e164658be9ce810921bf81d6b86694785a79ea1e52dbfa5105148d1f0bc1', 'hex'); transactionBuilder.bip66.encode(r, s); @@ -213,7 +225,7 @@ decoded `Object` #### Examples - let transactionBuilder = new BITBOX.TransactionBuilder(); + let transactionBuilder = new bitbox.TransactionBuilder(); let signature = new Buffer.from('304302201ea1fdff81b3a271659df4aad19bc4ef83def389131a36358fe64b245632e777021f29e164658be9ce810921bf81d6b86694785a79ea1e52dbfa5105148d1f0bc1', 'hex'); transactionBuilder.bip66.decode(signature); // { r: @@ -231,11 +243,11 @@ Check format of [bip66](https://github.com/bitcoin/bips/blob/master/bip-0066.med #### Result -value `Boolean` +value `boolean` #### Examples - let transactionBuilder = new BITBOX.TransactionBuilder(); + let transactionBuilder = new bitbox.TransactionBuilder(); let DER = '3044022029db2d5f4e1dcc04e19266cce3cb135865784c62ab653b307f0e0bb744f5c2aa022000a97f5826912cac8b44d9f577a26f169a2f8db781f2ddb7de2bc886e93b6844'; let buffer = Buffer.from(DER, 'hex') transactionBuilder.bip66.check(buffer); @@ -251,11 +263,11 @@ Encoded [bip68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki) #### Result -hex `String`: hex encoded relative timelock +hex `string`: hex encoded relative timelock #### Examples - let transactionBuilder = new BITBOX.TransactionBuilder(); + let transactionBuilder = new bitbox.TransactionBuilder(); transactionBuilder.bip68.encode({ seconds: 2048 }) // 4194308 transactionBuilder.bip68.encode({ blocks: 52 }) @@ -267,7 +279,7 @@ Decoded [bip68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki) #### Arguments -1. hex `String`: hex encoded relative lock time +1. hex `string`: hex encoded relative lock time #### Result @@ -275,7 +287,7 @@ details `Object`: details about the relative lock time #### Examples - let transactionBuilder = new BITBOX.TransactionBuilder(); + let transactionBuilder = new bitbox.TransactionBuilder(); transactionBuilder.bip68.decode(0x03ffffff) // { seconds: 33553920 } transactionBuilder.bip68.decode(0x0100fffe) diff --git a/src/data/docs/bitbox/util.md b/src/data/docs/bitbox/util.md index c869f2e8..4efafa5c 100644 --- a/src/data/docs/bitbox/util.md +++ b/src/data/docs/bitbox/util.md @@ -1,7 +1,7 @@ --- title: Util icon: cogs -ordinal: 19 +ordinal: 23 --- ### `validateAddress` @@ -10,20 +10,17 @@ Return information about the given bitcoin address. #### Arguments -- address (required): - - `String`: legacy or cash address - - `Array`: array of strings containing legacy or cash addresses. +- address `string | string[]` #### Result -- `Object`: An object with an `isvalid` Boolean property will be returned. If - true, additional properties will exist. +- addressDetails `Promise` #### Examples (async () => { try { - let validateAddress = await BITBOX.Util.validateAddress("bitcoincash:qzc86hrdufhcwlyzk7k82x77kfs2myekn57nv9cw5f"); + let validateAddress = await bitbox.Util.validateAddress("bitcoincash:qzc86hrdufhcwlyzk7k82x77kfs2myekn57nv9cw5f"); console.log(validateAddress); } catch(error) { console.error(error) @@ -39,3 +36,87 @@ Return information about the given bitcoin address. // pubkey: '0312eeb9ae5f14c3cf43cece11134af860c2ef7d775060e3a578ceec888acada31', // iscompressed: true, // account: 'Test' } + + (async () => { + try { + let validateAddress = await bitbox.Util.validateAddress(["bitcoincash:qzc86hrdufhcwlyzk7k82x77kfs2myekn57nv9cw5f"]); + console.log(validateAddress); + } catch(error) { + console.error(error) + } + })() + + // [{ isvalid: true, + // address: '17fshh33qUze2yifiJ2sXgijSMzJ2KNEwu', + // scriptPubKey: '76a914492ae280d70af33acf0ae7cd329b961e65e9cbd888ac', + // ismine: true, + // iswatchonly: false, + // isscript: false, + // pubkey: '0312eeb9ae5f14c3cf43cece11134af860c2ef7d775060e3a578ceec888acada31', + // iscompressed: true, + // account: 'Test' }] + +### `sweep` + +Sweep utxo for `wif` to cashAddress + +#### Arguments + +- wif `string` +- toAddr `string` +- balanceOnly `boolean` **optional**. Defaults to `false` + +#### Result + +- result `string | number` + +#### Examples + + // balance only + (async () => { + try { + const wif = "cP8LcsoMneSyjdtyFTmnASsmAuyd2SfZjG4drp5twAJoSpRa2RCx" + const toAddr = "bchtest:qqmd9unmhkpx4pkmr6fkrr8rm6y77vckjvqe8aey35" + const result = await bitbox.Util.sweep( + wif, + toAddr, + true + ) + console.log(result); + } catch(error) { + console.error(error) + } + })() + // 0.1 + + // sweep utxo + (async () => { + try { + const wif = "cP8LcsoMneSyjdtyFTmnASsmAuyd2SfZjG4drp5twAJoSpRa2RCx" + const toAddr = "bchtest:qqmd9unmhkpx4pkmr6fkrr8rm6y77vckjvqe8aey35" + const result = await bitbox.Util.sweep( + wif, + toAddr + ) + console.log(result); + } catch(error) { + console.error(error) + } + })() + // 6b647ddfbb6b0edfaf61d2952b9f8e195d2dfede0e63fe12e1beab16e5bcfe5c + +## Interfaces + +### AddressDetails + + { + isvalid: boolean + address: string + scriptPubKey: string + ismine: boolean + iswatchonly: boolean + isscript: boolean + pubkey: string + iscompressed: boolean + account: string + } diff --git a/src/data/docs/bitcoincom-link/create-token.md b/src/data/docs/bitcoincom-link/create-token.md new file mode 100644 index 00000000..903b027d --- /dev/null +++ b/src/data/docs/bitcoincom-link/create-token.md @@ -0,0 +1,115 @@ +--- +title: Create Token +icon: coins +ordinal: 4 +--- + +# createToken + +Creates a new SLP token, and mints the initial supply to specified wallet address. + +## Method Interface + +``` +function createToken(CreateTokenInput): Promise +``` + +## Input arguments + +``` +interface CreateTokenInput { + name: string; // token name + symbol: string; // token symbol + decimals: number; // number of decimals + initialSupply: number; // initial supply to send to receive address + tokenReceiverAddress: string; // SLP formatted address to receive the initial token supply + batonReceiverAddress?: string; // optional SLP formatted address which will have minting privledges for additional tokens + documentUri?: string; // URI of document related to token + documentHash?: string; // hash of document related to token +} +``` + +## Success return value + +``` +interface CreateTokenOutput { + tokenId: string; // unique id for new token (also txid of token genesis tx) +} +``` + +## Error return value + +``` +interface Error { + type: string; // `NO_PROVIDER`|`PROTOCOL_ERROR``|`MALFORMED_INPUT`|`CANCELED` + description: string; + data: string; +} +``` + +## Example + +``` +import bitcoincomLink from 'bitcoincom-link'; + +bitcoincomLink.createToken({ + name: 'World Hunger Token', + symbol: 'WHT', + decimals: 8, + initialSupply: '1000000000', + tokenReceiverAddress: 'simpleledger:qrw3pqgyjffxsv5qdj9n6zdpe70zqsegxcjyff6q8m', +}) +.then((data: CreateTokenOutput) => { + const { + tokenId, + } = data; + + console.log('Token id: ' + tokenId); +}) +.catch(({type: string, description: string, data: any}) => { + switch(type) { + case NO_PROVIDER: + console.log('No provider available.'); + break; + case PROTOCOL_ERROR: + console.log('The provided protocol is not supported by this wallet.'); + break; + case MALFORMED_INPUT: + console.log('The input provided is not valid.'); + break; + case CANCELED: + console.log('The user has canceled this transaction request.'); + break; + } +}); +``` + +## Demo - Create new token + + + +## Provider Request Handling + +- Validate the input parameters to make sure that the SLP addresses provided are valid and match the SLP address scheme +- Present the request to the user, and allow them to pick from which of their accounts the BCH to mint the tokens will be sourced (for some wallets they may only have a single account) +- If the user accepts the transaction, sign & broadcast the transaction, then return the transaction id to the app. + - SLP transactions should conform with the [protocol spec](https://github.com/simpleledger/slp-specifications/blob/master/slp-token-type-1.md#mint---extended-minting-transaction) +- If the user rejects the transaction, communicate back to the app that the user canceled the request. + +Example + +``` +{ + tokenId: '31065a7ab53d5fa8e66ef1680e51c8485953c77e069293889b06d2b0b4934205', +} +``` + +## Wallet Provider Support + +| Provider | Supported | Comments | +| ----------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Badger Chrome Extension | ⚠️ | When specifying a batonReceiverAddress, it currently acts as a boolean. If true, it will be issued on vout1 on the change address. Any BCH change will be placed on the mint baton UTXO | +| Badger Mobile | ⛔️ | | +| Bitcoin.com iOS | ⛔️ | | +| Bitcoin.com Android | ⛔️ | | diff --git a/src/data/docs/bitcoincom-link/get-address.md b/src/data/docs/bitcoincom-link/get-address.md new file mode 100644 index 00000000..6c0467d2 --- /dev/null +++ b/src/data/docs/bitcoincom-link/get-address.md @@ -0,0 +1,103 @@ +--- +title: Get Address +icon: bitcoin +ordinal: 1 +--- + +# getAddress + +Can be called to retreive a users BCH/SLP/BTC address. + +The address returned by this method may not repreent all the funds in the users control, and calling the method multiple times could return different addresses, depending on the wallet provider. + +## Method Interface + +``` +function getAddress(GetAccountInput): Promise +``` + +## Input arguments + +``` +interface GetAccountInput { + protocol: string; // BCH/SLP/BTC or any future protocol +} +``` + +## Success return value + +``` +interface GetAccountOutput { + address: string; // Address for the given protocol + label?: string; // A label the users has set to identify their wallet +} +``` + +## Error return value + +``` +interface Error { + type: string; // `NO_PROVIDER`|`CONNECTION_DENIED` + description: string; + data: string; +} +``` + +## Client Call Example + +``` +import bitcoincomLink from 'bitcoincom-link'; + +bitcoincomLink.getAddress({ + protocol: 'BCH', +}) +.then((data: GetAccountOutput) => { + const { + address, + label, + } = data; + + console.log('User address: ' + address); + console.log('User address label (Optional): ' + label); +}) +.catch(({type: string, description: string, data: any}) => { + switch(type) { + case NO_PROVIDER: + console.log('No provider available.'); + break; + case CANCELED: + console.log('The user has canceled this request.'); + break; + case PROTOCOL_ERROR: + console.log('The provided protocol is not supported by this wallet.'); + break; + } +}); +``` + +## Demo + + + +## Provider Request Handling + +Depending on the account structure of the wallet, user handling may be different. In all cases, the wallet MUST return an address & protocol, or an error message. Each wallet may choose to provide back a default address in all cases, while others with multiple accounts and HD keys, may prompt a user to select an account from which to provide a new address. + +Example + +``` +{ + address: 'bitcoincash:qrd9khmeg4nqag3h5gzu8vjt537pm7le85lcauzezc', + label: 'My Spending Wallet' +} +``` + +## Wallet Provider Support + +| Provider | Supported | Comments | +| ----------------------- | --------- | -------- | +| Badger Chrome Extension | ✅ | | +| Badger Mobile | ⛔️ | | +| Bitcoin.com iOS | ⛔️ | | +| Bitcoin.com Android | ⛔️ | | diff --git a/src/data/docs/bitcoincom-link/get-wallet-provider-status.md b/src/data/docs/bitcoincom-link/get-wallet-provider-status.md new file mode 100644 index 00000000..811b9ab3 --- /dev/null +++ b/src/data/docs/bitcoincom-link/get-wallet-provider-status.md @@ -0,0 +1,55 @@ +--- +title: Get Wallet Status +icon: wallet +ordinal: 5 +--- + +# getWalletProviderStatus + +Provides information about the availability of any wallet provider in the current browser environment. When called, the package will check of any of the following wallet providers are currently connected: Badger, Android, iOS. + +All providers will provided a status of either `AVAILABLE` or `NOT_AVAILABLE`, with the exception of Badger, which has a 3rd status `LOGGED_IN`. + +In the case of a `LOGGED_IN` for Badger, this means that your app is in an evironment where the Badger wallet is present, and it is ready for your app to interact with it. If Badger has a status of `AVAILABLE`, your app can not yet interact with it, so please inform the user to log into their Badger wallet if this status is received. + +Unlike other methods on the Wallet API, this is a synchronous method; directly returning the result. + +## Method Interface + +``` +function getWalletProviderStatus(): GetWalletProviderStatusOutput +``` + +## Input arguments + +N/A + +## Return value + +``` +interface GetWalletProviderStatusOutput { + badger: WalletProviderStatus; + android: WalletProviderStatus; + ios: WalletProviderStatus; +} + +enum WalletProviderStatus { + NOT_AVAILABLE, + AVAILABLE, + LOGGED_IN, +} +``` + +## Client Call Example + +``` +import bitcoincomLink from 'bitcoincom-link'; + +const providerStatuses = bitcoincomLink.getWalletProviderStatus(); +console.log('Provider statuses: ' + JSON.stringify(providerStatuses)); +``` + +## Demo + + diff --git a/src/data/docs/bitcoincom-link/getting-started.md b/src/data/docs/bitcoincom-link/getting-started.md new file mode 100644 index 00000000..4ec3fafa --- /dev/null +++ b/src/data/docs/bitcoincom-link/getting-started.md @@ -0,0 +1,30 @@ +--- +title: Getting Started +icon: home +ordinal: 0 +--- + +### Bitcoin.com Link + +A standard interface for blockchain connected applications to interact with 3rd party user wallets. + +### Overview + +The package will serve as a multi-provider interface for applications, with the first wallet provider being the Badger Chrome extension. In the near future, support will be added for Bitcoin.com mobile and desktop wallets as well. + +The method interface will allow any web based application to interact with the Bitcoin Cash blockchain without requiring the users private keys. All methods high level operations which will request a specific transaction, such as sending BCH, and the wallet will take care of creating the transaction, getting the users signature, and broadcasting the transaction to the network. This way there is no need for the application developer to worry about how to safely manage a users keys or even about the complexities of blockchain transactions. + +### Installation + +In a browser - cdn [![](https://data.jsdelivr.com/v1/package/npm/bitcoincom-link/badge)](https://www.jsdelivr.com/package/npm/bitcoincom-link) + +Install via npm [![npm version](https://badge.fury.io/js/bitcoincom-link.svg)](https://badge.fury.io/js/bitcoincom-link) + +### Testbed + +[Demo site](https://bitcoincom-link-testbed.netlify.com/) + +The document for each method on this page, has a live demo of the wallet api embeded for you to try out the code. For example, here is a interactive example of how to get the user's address. Simply click on the button at the top of the render section on the right hand side. In this case the button is labeled as `getAddress`. Please ensure you have the [Badger browser extension wallet](https://badger.bitcoin.com/) installed in order to use this interactive demo on your desktop computer. + + diff --git a/src/data/docs/bitcoincom-link/pay-invoice.md b/src/data/docs/bitcoincom-link/pay-invoice.md new file mode 100644 index 00000000..fd9c626a --- /dev/null +++ b/src/data/docs/bitcoincom-link/pay-invoice.md @@ -0,0 +1,112 @@ +--- +title: Pay Invoice +icon: invoice +ordinal: 3 +--- + +# payInvoice + +Provides an interface for an application to request payment of a BIP70 invoice to a users wallet. + +## Method Interface + +``` +function payInvoice(PayInvoiceInput): Promise +``` + +## Input arguments + +``` +interface PayInvoiceInput { + url: string; // Url to retrieve the BIP70 payment request from the merchant server +} +``` + +## Success return value + +``` +interface PayInvoiceOutput { + memo: string; // Message from merchant server upon receiving payment +} +``` + +## Error return value + +``` +interface Error { + type: string; // `NO_PROVIDER`|`PROTOCOL_ERROR`|`MERCHANT_ERROR`|`MALFORMED_INPUT`|`CANCELED` + description: string; + data: string; +} +``` + +## Example + +``` +import bitcoincomLink from 'bitcoincom-link'; + +bitcoincomLink.payInvoice({ + url: 'bitcoincash:?r=https://bitpay.com/i/LHQmUTjzAcqX1NU47Nk1mJ', +}) +.then((data: PayInvoiceOutput) => { + const { + memo, + } = data; + + console.log('Payment processed memo from merchant server: ' + memo); +}) +.catch(({type: string, description: string, data: any}) => { + switch(type) { + case NO_PROVIDER: + console.log('No provider available.'); + break; + case PROTOCOL_ERROR: + console.log('The provided protocol is not supported by this wallet.'); + break; + case MERCHANT_ERROR: + console.log('There was an error when sending this transaction to the merchant.'); + break; + case MALFORMED_INPUT: + console.log('The input provided is not valid.'); + break; + case CANCELED: + console.log('The user has canceled this transaction request.'); + break; + } +}); +``` + +## Demo - Send BCH Invoice + + + +## Demo - Send SLP Invoice + + + +## Provider Request Handling + +- Fetch payment request from merchant server +- Present payment request information to user for approval +- Upon approval, submit transaction and send confirmation to merchant server +- Return payment confirmation memo from merchant server to connected application +- In the case there is an error in the + +Example + +``` +{ + memo: 'Payment of 1 BTC for eleven tribbles accepted for processing.', +} +``` + +## Wallet Provider Support + +| Provider | Supported | Comments | +| ----------------------- | --------- | -------- | +| Badger Chrome Extension | ✅ | | +| Badger Mobile | ⛔️ | | +| Bitcoin.com iOS | ⛔️ | | +| Bitcoin.com Android | ⛔️ | | diff --git a/src/data/docs/bitcoincom-link/send-assets.md b/src/data/docs/bitcoincom-link/send-assets.md new file mode 100644 index 00000000..c8143903 --- /dev/null +++ b/src/data/docs/bitcoincom-link/send-assets.md @@ -0,0 +1,119 @@ +--- +title: Send Assets +icon: exchange +ordinal: 2 +--- + +# sendAssets + +Allows for a simple send of assets from user to specified address. The use case is where another application would like to request payment from the user wallet directly, without alerting any 3rd party server (merchant server). + +## Method Interface + +``` +function sendAssets(SendAssetsInput): Promise +``` + +## Input arguments + +``` +interface SendAssetsInput { + to: string; // Address of the receiver of the assets to be sent + protocol: string; // BCH/SLP/BTC or any future protocol + assetId?: string; // Optional in the case of BCH or BTC. Required in the case of SLP, and will be token id + value: string; // The amount of coins or assets to be sent, in user readable decimal format (eg. "0.000123") +} +``` + +## Success return value + +``` +interface SendAssetsOutput { + txid: string; // Transaction id of the sent assets +} +``` + +## Error return value + +``` +interface Error { + type: string; // `NO_PROVIDER`|`PROTOCOL_ERROR`|`SEND_ERROR`|`MALFORMED_INPUT`|`CANCELED` + description: string; + data: string; +} +``` + +## Example + +``` +import bitcoincomLink from 'bitcoincom-link'; + +bitcoincomLink.sendAssets({ + to: 'bitcoincash:qrd9khmeg4nqag3h5gzu8vjt537pm7le85lcauzezc', + protocol: 'BCH', + value: '0.000123', +}) +.then((data: SendAssetsOutput) => { + const { + txid, + } = data; + + console.log('Completed transaction id: ' + txid); +}) +.catch(({type: string, description: string, data: any}) => { + switch(type) { + case NO_PROVIDER: + console.log('No provider available.'); + break; + case PROTOCOL_ERROR: + console.log('The provided protocol is not supported by this wallet.'); + break; + case SEND_ERROR: + console.log('There was an error when broadcasting this transaction to the network.'); + break; + case MALFORMED_INPUT: + console.log('The input provided is not valid.'); + break; + case CANCELED: + console.log('The user has canceled this transaction request.'); + break; + } +}); +``` + +## Demo - Send BCH + + + +## Demo - Send SLP Tokens + + + +## Provider Request Handling + +- Validate the input parameters to make sure that the address provided is valid, and that it matches the provided protocol. +- Present the request to the user, and allow them to pick from which of their accounts they would like to send the funds (for some wallets they may only have a single account) +- If the user accepts the transaction, sign & broadcast the transaction, then return the transaction id to the app. + - The transaction does not have any input UTXO requirements, other than having enough funds to sucessfully match it's outputs + - BCH/BTC transactions should have at least 1 UTXO output, for the specified input amount and specified address. Any additionaly UTXO outputs for the remaining input amounts are to be determined by the wallet provider, including the fee. + - SLP transactions should conform with the [protocol spec](https://github.com/simpleledger/slp-specifications/blob/master/slp-token-type-1.md#send---spend-transaction) +- If the user rejects the transaction, communicate back to the app that the user canceled the request. + +Example + +``` +{ + txid: '31065a7ab53d5fa8e66ef1680e51c8485953c77e069293889b06d2b0b4934205', +} +``` + +## Wallet Provider Support + +| Provider | Supported | Comments | +| ----------------------- | --------- | -------- | +| Badger Chrome Extension | ✅ | | +| Badger Mobile | ⛔️ | | +| Bitcoin.com iOS | ⛔️ | | +| Bitcoin.com Android | ⛔️ | | diff --git a/src/data/docs/cashscript/cashc.md b/src/data/docs/cashscript/cashc.md new file mode 100644 index 00000000..b4402994 --- /dev/null +++ b/src/data/docs/cashscript/cashc.md @@ -0,0 +1,36 @@ +--- +title: Cashc CLI +icon: terminal +ordinal: 1 +--- + +`cashc` can be used to compile CashScript `.cash` files into `.json` artifact files. These artifacts can be imported and used by any of the CashScript SDKs, or other libraries / applications that use CashScript. Check out the [Language Documentation](/cashscript/docs/language) for a full overview of this Artifact format. + +### Installation +You can use `npm` to install the `cashc` command line tool gloablly. + +```bash +npm install -g cashc +``` + +### Usage +The `cashc` CLI tool can be used to compile `.cash` files to JSON artifact files. + +```bash +Usage: cashc [options] [source_file] + +Options: + --output, -o Specify a file to output the generated artifact. [string] + --hex, -h Compile the contract to hex format rather than a full artifact + [boolean] + --asm, -A Compile the contract to ASM format rather than a full artifact + [boolean] + --args, -a List of constructor arguments to pass into the contract. Can + only be used in combination with either the --hex or --asm + flags. When compiling to a JSON artifact, contract instantiation + should be done through the CashScript SDK. Note that NO type + checking is performed by the cashc CLI, so it is safer to use + the CashScript SDK. [array] + --help Show help [boolean] + --version Show version number [boolean] +``` diff --git a/src/data/docs/cashscript/getting-started.md b/src/data/docs/cashscript/getting-started.md new file mode 100644 index 00000000..eba5a666 --- /dev/null +++ b/src/data/docs/cashscript/getting-started.md @@ -0,0 +1,109 @@ +--- +title: Getting Started +icon: home +ordinal: 0 +--- + +CashScript is a high-level language that allows you to write Bitcoin Cash contracts in a straightforward and familiar way. It is inspired by Ethereum's Solidity, but it is not the same, and cash contracts work very differently from Ethereum's smart contracts. See the [Language Documentation](/cashscript/docs/language) for a full reference of the language. + +--- + +**Attention:** CashScript is in active development so its APIs are subject to change. The library can still contain bugs, so it is recommended to only use the CashScript SDK on the `testnet` network. + +### The CashScript Compiler +CashScript features a compiler as a standalone command line tool, called `cashc`. It can be installed through npm and used to compile `.cash` files into `.json` artifact files. These artifact files can be imported into the CashScript JavaScript SDK (or other SDKs in the future). Note that the CashScript SDK also has a function to import and compile `.cash` files directly, so it is not required to use the `cashc` command line tool. + +See the [cashc documentation](/cashscript/docs/cashc) for more information on the `cashc` command line tool. + +#### Installation +```bash +npm install -g cashc +``` + +#### Usage +```bash +Usage: cashc [options] [source_file] + +Options: + --output, -o Specify a file to output the generated artifact. [string] + --hex, -h Compile the contract to hex format rather than a full artifact + [boolean] + --asm, -A Compile the contract to ASM format rather than a full artifact + [boolean] + --args, -a List of constructor arguments to pass into the contract. Can + only be used in combination with either the --hex or --asm + flags. When compiling to a JSON artifact, contract instantiation + should be done through the CashScript SDK. Note that NO type + checking is performed by the cashc CLI, so it is safer to use + the CashScript SDK. [array] + --help Show help [boolean] + --version Show version number [boolean] +``` + +### The CashScript SDK +The main way to interact with cash contracts and integrate them into applications is the CashScript SDK. This SDK allows you to compile `.cash` files or import `.json` artifact files, and convert them to `Contract` objects. These objects are used to create new contract instances. These instances are used to interact with the contracts using the functions that were implemented in the `.cash` file. For more information on the CashScript SDK, refer to the [full SDK documentation](/cashscript/docs/sdk). + +#### Installation +```bash +npm install cashscript +``` + +#### Usage +```ts +import { Contract, ... } from 'cashscript'; +``` + +```js +const { Contract, ... } = require('cashscript'); +``` + +Using the CashScript SDK, you can import / compile existing cash contract files, create new instances of these contracts, and interact with these instances: + +```ts +... + // Compile the P2PKH Cash Contract + const P2PKH: Contract = Contract.compile(path.join(__dirname, 'p2pkh.cash'), 'testnet'); + + // Instantiate a new P2PKH contract with constructor arguments: { pkh: pkh } + const instance: Instance = P2PKH.new(pkh); + + // Get contract balance & output address + balance + const contractBalance: number = await instance.getBalance(); + console.log('contract address:', instance.address); + console.log('contract balance:', contractBalance); + + // Call the spend function with the owner's signature + // And use it to send 0. 000 100 00 BCH back to the contract's address + const tx: TxnDetailsResult = await instance.functions + .spend(pk, new Sig(keypair)) + .send(instance.address, 10000); + console.log('transaction details:', tx); +... +``` + +### Examples +If you want to see CashScript in action and check out its usage, there are several example contracts in the [CashScript repository](https://github.com/Bitcoin-com/cashscript/tree/master/examples). The `.cash` files contain example contracts, and the `.ts` files contain example usage of the CashScript SDK to interact with these contracts. + +The "Hello World" of cash contracts is defining the P2PKH pattern inside a cash contract, which can be found under [`examples/p2pkh.cash`](https://github.com/Bitcoin-com/cashscript/tree/master/examples/p2pkh.cash). Its usage can be found under [`examples/p2pkh.ts`](https://github.com/Bitcoin-com/cashscript/tree/master/examples/p2pkh.ts). + +#### Running the examples +To run the examples, clone the [CashScript repository](https://github.com/Bitcoin-com/cashscript) and navigate to the `examples/` directory. Since the examples depend on the SDK, be sure to run `yarn` inside the `examples/` directory, which installs all required packages. + +```bash +git clone git@github.com:Bitcoin-com/cashscript.git +cd cashscript/examples +yarn +``` + +All `.ts` files in the examples directory can then be executed with `ts-node`. + +```bash +npm install -g ts-node +ts-node p2pkh.ts +``` + +All `.js` files can be executed with `node`. + +```bash +node p2pkh.js +``` diff --git a/src/data/docs/cashscript/language.md b/src/data/docs/cashscript/language.md new file mode 100644 index 00000000..e9642817 --- /dev/null +++ b/src/data/docs/cashscript/language.md @@ -0,0 +1,400 @@ +--- +title: CashScript Language +icon: coins +ordinal: 3 +--- + +### Introduction +The CashScript language allows you to write Bitcoin Cash contracts in a straightforward, readable, and maintainable way. It has a syntax similar to Ethereum's [Solidity language](https://solidity.readthedocs.io/), which is the most widespread smart contract language in the greater blockchain ecosystem. + +### Structure of a contract file +Take the following example contract: + +```solidity +pragma cashscript ^0.3.0; + +contract TransferWithTimeout( + pubkey sender, + pubkey recipient, + int timeout +) { + function transfer(sig recipientSig) { + require(checkSig(recipientSig, recipient)); + } + + function timeout(sig senderSig) { + require(checkSig(senderSig, sender)); + require(tx.time >= timeout); + } +} +``` + +A contract file may start with a pragma directive to indicate the language version the contract was written for. This ensures that a contract is not compiled using the wrong compiler version, which can cause unintended effects. The pragma directive follows regular [semantic versioning rules](https://semver.npmjs.com/). + +A contract in CashScript is a collection of functions that can be used to spend the funds that are locked in this contract. These contracts can be instantiated using the contract's parameters, and their functions can be called by specifying the correct function parameters. The example used above is a simple value transfer that can be claimed by the recipient before a certain timeout, after which it can be reclaimed by the original sender. To instantiate this contract, the public keys of the sender and recipient should be passed as well as a timeout in the form of a block number. + +For the recipient to spend from this contract, they need to use the transfer function and provide a valid transaction signature using their keypair. For the sender to reclaim from this contract, they also need to provide a valid transaction signature using their keychain, but to the timeout function. In addition, the timeout function also checks that the block number in which this transaction is included is greater than or equal to the timeout value. + +### Control structures +The only control structures are `if` and `else`, with loops and return statements left out due to their incompatibility with the underlying Bitcoin Script. If-else statements follow the usual semantics known from C or JavaScript. + +Parentheses can not be omitted for conditionals, but curly braces can be omitted around single-statement bodies. + +Note that there is no type conversion from non-boolean to boolean types as there is in C and JavaScript, so `if (1) { ... }` is not valid CashScript and should instead be written as `if (bool(1)) { ... }`. + +### Comments +Comments can be added anywhere in the contract file. Comment semantics are similar to languages like JavaScript or C. This means that single-line comments can be added with `// ...`, while multiline comments can be added with `/* ... */`. + +### Types +CashScript is a statically typed language, which means that the type of each variable needs to be specified. Types can interact with each other in expressions containing operators. For a quick reference of the various operators, see [Operators](/cashscript/docs/language#operators). Types can also be implicitly or explicitly casted to other types. For a quick reference of the various casting possibilities, see [Casting](/cashscript/docs/language#casting). + +#### Boolean +`bool`: The possible values are constants true and false. + +Operators: + +- `!` (logical negation) +- `&&` (logical conjunction, “and”) +- `||` (logical disjunction, “or”) +- `==` (equality) +- `!=` (inequality) + +The operators `||` and `&&` don't apply common short-circuiting rules. This means that in the expression `f(x) || g(y)`, even if `f(x)` evaluates to true, `g(y)` will still be executed. + +#### Integer +`int`: Signed integer of 32 bit size. + +Operators: + +- Comparisons: `<=`, `<`, `==`, `!=`, `>=`, `>` (all evaluate to `bool`) +- Arithmetic operators: `+`, `-`, unary `-`, `/`, `%` (modulo). + +Note the clear lack of the `*` and `**` (exponentation) operators as well as any bitwise operators. + +While integer sizes are limited to 32 bits, the output of arithmetic operations can exceed this size. This will not result in an overflow, but instead the script will fail when using this value in another integer operation. Division and modulo operations will fail if the right hand side of the expression is zero. + +#### String +`string`: ASCII-encoded byte sequence. + +Operators: + +- `+` (concatenation) +- `==` (equality) +- `!=` (inequality) + +Members: + +- `length`: Number of characters that represent the string. +- `split(int)`: Splits the string at the specified index and returns a tuple with the two resulting strings. + +#### Bytes +`bytes`: Byte sequence. Can optionally be bound to a certain byte length by specifying e.g. `bytes5`, `bytes32`, etc. + +Operators: + +- `+` (concatenation) +- `==` (equality) +- `!=` (inequality) + +Members: + +- `length`: Number of bytes in the sequence. +- `split(int)`: Splits the byte sequence at the specified index and returns a tuple with the two resulting byte sequences. + +#### Pubkey +`pubkey`: Byte sequence representing a public key. + +Operators: + +- `==` (equality) +- `!=` (inequality) + +#### Sig +`sig`: Byte sequence representing a transaction signature. + +Operators: + +- `==` (equality) +- `!=` (inequality) + +#### Datasig +`datasig`: Byte sequence representing a data signature. + +Operators: + +- `==` (equality) +- `!=` (inequality) + +#### Array & Tuple +These types are not assignable, and only have very specific uses within CashScript. + +Arrays are only able to be passed into `checkMultisig` functions using the following syntax: + +``` +checkMultisig([sig1, sig2], [pk1, pk2, pk3]); +``` + +Tuples can only arise by using the `split` member function on a `string` or a `bytes` type. Their first or second element can be accessed through a familiar array indexing syntax: + +``` +string question = "What is Bitcoin Cash?"; +string answer = question.split(15)[0].split(8)[1]; +``` + +### Variables +Variables can be declared by specifying their type and their name. All variables need to be initialised at their time of declaration, but they can be reassigned later on, so it is possible to specifically initialise variables to zero. Since CashScript is strongly typed and has no type inference, it is not possible to use keywords such as `var` or `let` to declare variables, as might be possible in different languages such as JavaScript. + +``` +int myNumber = 3000; +string myString = 'Bitcoin Cash'; +``` + +### Functions & Globals +#### Arithmetic functions +**`int abs(int a)`** + +Returns the absolute value of argument `a`. + +**`int min(int a, int b)`** + +Returns the minimum value of arguments `a` and `b`. + +**`int max(int a, int b)`** + +Retuns the maximum value of arguments `a` and `b`. + +**`bool within(int x, int lower, int upper)`** + +Returns `true` if and only if `x >= lower && x < upper`. + +#### Hashing functions +**`bytes20 ripemd160(any x)`** + +Returns the RIPEMD-160 hash of argument `x`. + +**`bytes32 sha1(any x)`** + +Returns the SHA-1 hash of argument `x`. + +**`bytes32 sha256(any x)`** + +Returns the SHA-256 hash of argument `x`. + +**`bytes20 hash160(any x)`** + +Returns the RIPEMD-160 hash of the SHA-256 hash of argument `x`. + +**`bytes32 hash256(any x)`** + +Returns the double SHA-256 hash of argument `x`. + +#### Signature checking functions +**Note:** All signature checking functions must comply with the [NULLFAIL](https://github.com/bitcoin/bips/blob/master/bip-0146.mediawiki) rule. This rule implies that if you want to use the output of a signature check inside the condition of an if-statement, the input signature needs to either be correct, or an empty byte array. When you use a valid but incorrect signature as in input, the script will fail immediately. + +**`bool checksig(sig s, pubkey pk)`** + +Checks that transaction signature `s` is valid for the current transaction and matches with public key `pk`. + +**`bool checkMultiSig(sig[] sigs, pubkey[] pks)`** + +Performs a multi-signature check using a list of transaction signatures and public keys. + +**Note**: While this function is compiled correctly and can be used, it is not supported by the JavaScript SDK, so it is recommended not to use `checkMultiSig` at the moment. + +**`bool checkDataSig(datasig s, bytes msg, pubkey pk)`** + +Checks that sig `s` is a valid signature for message `msg` and matches with public key `pk`. + +#### Error handling +**`void require(bool condition)`** + +Asserts that boolean expression `condition` evaluates to `true`. If it evaluates to `false`, the script fails. As this function has a `void` return type, it can only be used as a standalone statement. + +#### Units +An integer literal can take a suffix of either monetary or temporary units to add smeantic value to these integers and to simplify arithmetic. When these units are used, the underlying integer is automatically multiplied by the value of the unit. The units `sats`, `finney`, `bits` and `bitcoin` are used to denote monetary value, while the units `seconds`, `minutes`, `hours`, `days` and `weeks` are used to denote time. + +``` +require(1 sats == 1); +require(1 finney == 10); +require(1 bit == 100); +require(1 bitcoin == 1e8); + +require(1 seconds == 1); +require(1 minutes == 60 seconds); +require(1 hours == 60 minutes); +require(1 days == 24 hours); +require(1 weeks == 7 days); +``` + +Be careful when using these units in precise calendar calculations though, because not every year equals 365 days and not even every minute has 60 seconds because of [leap seconds](https://en.wikipedia.org/wiki/Leap_second). + +#### Global time variables +**`tx.time`** + +Represents the block number that the transaction is included in. It can also represent the timestamp of the transaction when so configured in the transaction. The JavaScript SDK only has support for block number right now though, so it is recommended to only use it as the block number. + +Due to limitations in the underlying Bitcoin Script, `tx.time` can only be used in the following way: + +```solidity +require(tx.time >= ); +``` + +**`tx.age`** + +Represents the block depth of the utxo that is being spent by the current transaction. It can also represent the utxo's age in seconds when so configured in the transaction. The JavaScript SDK only has support for block depth right now though so it is recommended to only use it as the block depth. + +Due to limitations in the underlying Bitcoin Script, `tx.age` can only be used in the following way: + +```solidity +require(tx.age >= ); +``` + +#### Global covenant variables +Covenant variables are used to put constraints on the money inside the smart contract. This can be used to limit the addresses where money can be sent for example. + +This technique works by passing the sighash preimage into the smart contract and extracting the individual fields. Because this sighash preimage needs to be verified, **it is mandatory** to include a `require(checkSig(sig, pubkey));` statement anywhere in the code when using these covenant variables. This statement will be used by the compiler to verify the validity of the passed preimage. Using the CashScript SDK, this preimage is passed in automatically by the SDK, but when constructing transactions manually, be sure to include the preimage as a parameter. + +See [BIP143](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#specification) and [Bitcoin Cash replay protected sighash](https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/replay-protected-sighash.md#digest-algorithm) for more technical documentation of the contents of all covenant variables. Note that the explanation of the variables below are using the default `hashtype` of `0x41`. Other hashtypes might assign different meaning to these variables. If it is important to use a specific hashtype, this can be enforced with `require(tx.hashtype == 0x41);`. + +**`tx.version (bytes4)`** + +Represents the version of the current transaction. Different transaction versions can have differences in functionality. Currently only version 1 and 2 exist, where only version 2 has support for [BIP68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki). Note that `tx.version` is of type `bytes4` so to use it as an integer it needs to be cast to `int`: `int(tx.version)`. + +**`tx.hashPrevouts (bytes32)`** + +Represents the double sha256 of the serialisation of all input outpoints. + +**`tx.hashSequence (bytes32)`** + +Represents the double sha256 of the serialisation of `nSequence` of all inputs. + +**`tx.outpoint (bytes36)`** + +Represents the outpoint of the current input (`bytes32` txid concatenated with `bytes4` vout). + +**`tx.bytecode (bytes)`** + +Represents the Bitcoin Script bytecode of the current contract. This can be used to enforce sending money back to the contract in combination with `tx.hashOutputs`. + +```solidity +bytes32 output = new OutputP2SH(bytes8(10000), hash160(tx.bytecode)); +require(hash256(output) == tx.hashOutputs); +``` + +**`tx.value (bytes8)`** + +Represents the value of current input being spent. This can be used to enforce the full balance or a specific part of the contract's balance to be spent. Note that `tx.value` is of type `bytes8`, which is over the size limit for casting to integer, so to cast it to an integer it needs to be cast through a regular `bytes` type: `int(bytes(tx.value))`. Due to technical limitations, this can only work if `tx.value` fits within a 32-bit signed integer (max ~21 BCH). + +**`tx.sequence (bytes4)`** + +Represents the `nSequence` field of the current input. + +**`tx.hashOutputs (bytes32)`** + +Represents the double sha256 of the serialisation of all outputs (`bytes8` amount + `bytes` locking script). Can be used to enforce sending specific amounts to specific addresses. + +```solidity +bytes34 out1 = new OutputP2PKH(bytes8(10000), pkh); +bytes32 out2 = new OutputP2SH(bytes8(10000), hash160(tx.bytecode)); +require(hash256(out1 + out2) == tx.hashOutputs); +``` + +**`tx.locktime (bytes4)`** + +Represents the `nLocktime` field of the current input. + +**`tx.hashtype (bytes4)`** + +Represents the hashtype used for the generation of the sighash and signature. Can be used to enforce that the spender uses a specific hashtype. See [replay protected sighash](https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/replay-protected-sighash.md#digest-algorithm) for the implications of different hashtypes. + +### Object instantiation +To assist with enforcing outputs, there are output variables that can be instantiated. These outputs can then be used together with `tx.hashOutputs` to enforce sending to these outputs. See the documentation for `tx.hashOutputs` in the section above. + +**`new OutputP2PKH(bytes8 amount, bytes20 pkh): bytes34`** + +Creates new P2PKH output serialisation for an output sending `amount` to `pkh`. + +**`new OutputP2SH(bytes8 amount, bytes20 scriptHash): bytes32`** + +Creates new P2SH output serialisation for an output sending `amount` to `scriptHash`. + +**`new OutputNullData(bytes[] chunks): bytes`** + +Creates new OP_RETURN output serialisation for an output containing an OP_RETURN script with `chunks`. + +### Operators +| Precedence | Description | Operator | +| ---------- | ------------------------------- | ------------------------ | +| 1 | Parentheses | `()` | +| 2 | Type cast | `()` | +| 3 | Object instantiation | `new ()` | +| 4 | Function call | `()` | +| 5 | Tuple index | `[]` | +| 6 | Member access | `.` | +| 7 | Postfix increment and decrement | `++`, `--` | +| 8 | Unary minus | `-` | +| 8 | Logical NOT | `!` | +| 9 | Division and modulo | `/`, `%` | +| 10 | Addition and subtraction | `+`, `-` | +| 10 | String / bytes concatenation | `+` | +| 11 | Numeric comparison | `<`, `>`, `<=`, `>=` | +| 12 | Equality and inequality | `==`, `!=` | +| 13 | Logical AND | `&&` | +| 14 | Logical OR | `||` | +| 15 | Assignment | `=` | + +### Casting +Type casting is done using a syntax similar to function calls, but using a type name instead of a function name. + +```solidity +pubkey pk = pubkey(0x0000); +``` + +See the following table for information on which types can be cast to other which other types. + +| Type | Implicitly castable to | Explicitly castable to | +| ------- | ---------------------- | ---------------------------------- | +| int | | bytes, bool | +| bool | | int | +| string | | bytes | +| bytes | | sig, pubkey, int | +| pubkey | bytes | bytes | +| sig | bytes | bytes, datasig | +| datasig | bytes | bytes | + +### Artifacts +Compiled cash contracts can be represented by so-called artifacts. These artifacts are stored in `.json` files so they can be shared and stored for later usage without recompilation. These artifacts allow any third-party SDKs to be developed, as they only need to be able to import and use an artifact file, while leaving the compilation to the `cashc` command line tool. + +#### Artifact specification +```ts +interface Artifact { + contractName: string // Contract name + constructorInputs: AbiInput[] // Arguments required to instantiate a contract + abi: AbiFunction[] // functions that can be called + bytecode: string // Compiled Script without constructor parameters added (in ASM format) + source: string // Source code of the CashScript contract + networks: { + // Dictionary per network (testnet / mainnet) + [network: string]: { + // Dictionary of contract addresses with the corresponding compiled script (in ASM format) + [address: string]: string + } + } + compiler: { + name: string // Compiler used to compile this contract + version: string // Compiler version used to compile this contract + } + updatedAt: string // Last datetime this artifact was updated (in ISO format) +} + +interface AbiInput { + name: string // Input name + type: string // Input type (see language documentation) +} + +interface AbiFunction { + name: string // Function name + covenant: boolean // Does this function use covenant variables + inputs: AbiInput[] // Function inputs / parameters +} +``` diff --git a/src/data/docs/cashscript/sdk.md b/src/data/docs/cashscript/sdk.md new file mode 100644 index 00000000..bc46fd36 --- /dev/null +++ b/src/data/docs/cashscript/sdk.md @@ -0,0 +1,261 @@ +--- +title: CashScript SDK +icon: code +ordinal: 2 +--- + +### Contract +The `Contract` class allows you to compile CashScript files into `Contract` objects, from which these contracts can be instantiated and interacted with. These `Contract` objects can also be imported from a JSON Artifact file, and exported to one, which allows you to store and transfer the contract definition in JSON format, so you don't need to recompile the contract every time you use it. For more information on Artifacts, see the [Language Documentation](/cashscript/docs/language). + +#### Creating a Contract object +Before instantiating a contract, first you need to create a new `Contract` object. This can be done by compiling a CashScript file, or by importing an Artifact file that was exported previously. + +**`Contract.compile(fnOrString: string, network?: string): Contract`** + +If `fnOrString` is a file, compiles the CashScript file. If it is a source code string, it compiles the contract specified by the string. Optionally specify a network string (`'testnet'` or `'mainnet'`) to connect with. Returns a `Contract` object that can be further used to instantiate new instances of this contract. + +**Note: If you're using CashScript in a browser-based environment, you can only use the string-based compilation**, so you have to read the file in a different way, such as the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), and pass the string into the `compile` function. + +```ts +const P2PKH: Contract = Contract.compile( + path.join(__dirname, 'p2pkh.cash'), + 'testnet' +) +``` + +**`Contract.import(fnOrArtifact: string | Artifact, network?: string): Contract`** + +Imports an Artifact file in `.json` format that was compiled previously. This file is found at the path specified by argument `fn`. Optionally specify a network string (`'testnet'` or `'mainnet'`) to connect with. Returns a `Contract` object that can be further used to instantiate new instances of this contract. + +**Note: If you're using CashScript in a browser-based environment, you cannot use the file import**, so you will have to import the artifact JSON file in a different way, such as a require statement or the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), and pass this object into the `import` function. + +```ts +const P2PKH: Contract = Contract.import( + path.join(__dirname, 'p2pkh.json'), + 'testnet' +) +``` + +#### Exporting a contract +A `Contract` object can be exported to an Artifact file to be imported at a later moment, so it can be stored or transfered more easily, and can be used without recompilation. If the object is exported after one or more new contracts have been instantiated, their details will be stored in the file as well so they can be easily accessed later on. + +**`contract.export(fn?: string): Artifact`** + +Writes the contract's details to an Artifact file found at the location specified by argument `fn` and returns the object, so it can be retrieved later. If the file does not exist yet, it is created. If the file already exists, **it is overwritten**. If no `fn` arguhment is passed, just the artifact object is returned. + +**Note: If you're using CashScript in a browser-based environment, you cannot export to a file**. + +```ts +P2PKH.export(path.join(__dirname, 'p2pkh.json')) +``` + +#### Instantiating a contract +After creating a `Contract` object through compilation or import, this contract can be instantiated. If any contracts were instantiated before and this information was stored, these instances can also be accessed. + +**`contract.new(...parameters: Parameter[]): Instance`** + +This function is derived by looking at the contract parameters specified inside the contract's CashScript file, and to call it the parameters need to match those specified in contract code. + +```ts +const instance: Instance = P2PKH.new(pkh) +``` + +**`contract.deployed(at?: string): Instance`** + +Looks up the address specified by argument `at` and returns the instance that belongs to the address if it exists. If `at` is omitted it returns the first instance that it finds. + +```ts +const instance: Instance = P2PKH.deployed() +const instance: Instance = P2PKH.deployed( + 'bchtest:ppzllwzk775qk86zfskzyzae7pa9h4dvzcfezpsdkl' +) +``` + +### Instance +After instantiating a new contract or retrieving a previously deployed one, this instance can be interacted with using the functions implemented in the `.cash` file. + +**`instance.address`** + +An instance's address can be retrieved through the `address` member field. + +```ts +console.log(instance.address) +``` + +**`async instance.getBalance(): Promise`** + +Returns the total balance of the contract in satoshis. This incudes confirmed and unconfirmed balance. + +```ts +const contractBalance: number = await instance.getBalance() +``` + +**`instance.functions.(...parameters: Parameter[]): Transaction`** + +All contract functions defined in your CashScript file can be found by their name under the `functions` member field of an instance. To call them, the parameters need to match the ones defined in your CashScript file. + +```ts +const tx = await instance.functions + .spend(pk, new Sig(keypair)) + .send(instance.address, 10000) +``` + +**A note on transaction signatures:** + +Some cash contract functions require a signature parameter, which needs to be a valid transaction signature for the current transaction. The current transaction details are unknown at the time of calling a contract function. This is why we have a separate `Sig` class made up of a keypair and an optional hashtype, that represents a placeholder for these signatures. These placeholders are automatically replaced by the correct signature during the transaction building phase. + +**`new Sig(keypair: ECPair, hashtype?: HashType)`** + +Creates a placeholder for a transaction signature of the current transaction. During the transaction building phase this placeholder is replaced by the actual signature. **Important**: When calling a function that uses covenant variables, the first `Sig` parameter will be used to generate and pass in the sighash preimage as parameter. + +```ts +new Sig(keypair, HashType.SIGHASH_ALL) +``` + +### Transaction +Calling any of the contract functions on a contract instance results in a `Transaction` object, which can be sent by specifying a recipient and amount to send, or a list of these pairs. The `send` functiion calls can also be replaced by `meep` function calls to output the debug command to debug the transaction using [meep](https://github.com/gcash/meep). + +The CashScript SDK supports transactions to regular addresses, as well as OP_RETURN outputs. To do so we define two different kind of outputs: + +```ts +interface Recipient { + to: string + amount: number +} +interface OpReturn { + opReturn: string[] +} +type Output = Recipient | OpReturn +``` + +**Transaction options** + +Optionally, options can be passed into all `send` function documented below, which can influence the transaction. + +```ts +interface TxOptions { + time?: number + age?: number + fee?: number + minChange?: number +} +``` + +`time` sets the transaction `locktime` field in blocks, which corresponds with the `tx.time` global CashScript variable. `age` sets the transaction `sequence` field in blocks, which corresponds with the `tx.age` global CashScript variable. `fee` sets a hardcoded transaction fee, which can be used when the smart contract depends on the transaction having a specific fee. `minChange` sets the minimal value of change that can be sent back to the contract. + +**`async transaction.send(to: string, amount: number, options?: TxOptions): Promise`** + +Sends a transaction for an amount denoted in satoshis by argument `amount` to an address specified by argument `to`. This sends the transaction to the `rest.bitcoin.com` servers to be included in the Bitcoin Cash blockchain. Returns the raw `TxnDetailsResult` object as returned by `rest.bitcoin.com`. + +```ts +const tx = await instance.functions + .spend(pk, new Sig(keypair)) + .send(instance.address, 10000) +``` + +**`async transaction.send(Output[], options?: TxOptions): Promise`** + +Sends a transaction with multiple outputs to multiple address-amount pairs specified by the list of `{ to: string, amount: number }` objects. This sends the transaction to the `rest.bitcoin.com` servers to be included in the Bitcoin Cash blockchain. Returns the raw `TxnDetailsResult` object as returned by `rest.bitcoin.com`. + +```ts +const tx = await instance.functions + .spend(pk, new Sig(keypair)) + .send([ + { to: instance.address, amount: 10000 }, + { to: instance.address, amount: 20000 }, + ]) +``` + +These transactions can include outputs to other addresses as well as OP_RETURN outputs: + +```ts +const tx = await instance.functions + .spend(pk, new Sig(keypair)) + .send([ + { opReturn: ['0x6d02', 'Hello World!'] }, + { to: instance.address, amount: 10000 }, + ]) +``` + +**`async transaction.meep(to: string, amount: number, options?: TxOptions): Promise`** + +Prints the `meep` command that can be used to debug the transaction resulting from using the `send` function. + +```ts +await instance.functions + .spend(pk, new Sig(keypair)) + .meep(instance.address, 10000) +``` + +**`async transaction.meep(Output[], options?: TxOptions): Promise`** + +Prints the `meep` command that can be used to debug the transaction resulting from using the `send` function. + +```ts +await instance.functions + .spend(pk, new Sig(keypair)) + .meep([ + { to: instance.address, amount: 10000 }, + { to: instance.address, amount: 20000 }, + ]) +``` + +#### Transaction errors +Transactions can fail for a number of reasons. Most of these are related to the execution of the smart contract (e.g. wrong parameters or a bug in the contract code). But errors can also occur because of other reasons (e.g. a fee that's too low or a mempool conflict). To facilitate error handling in your applications, the CashScript SDK provides an enum of different "reasons" for a failure. This `Reason` enum only includes errors that are related to smart contract execution, so other reasons have to be caught separately. + +Besides this `Reason` enum, there are also several error classes that can be caught and acted on: + +* **`FailedRequireError`**, signifies a failed require statement. This includes any of the following reasons: `Reason.EVAL_FALSE`, `Reason.VERIFY`, `Reason.EQUALVERIFY`, `Reason.CHECKMULTISIGVERIFY`, `Reason.CHECKSIGVERIFY`, `Reason.CHECKDATASIGVERIFY`, `Reason.NUMEQUALVERIFY`. +* **`FailedTimeCheckError`**, signifies a failed timecheck using `tx.time` or `tx.age`. This includes any of the following reasons: `Reason.NEGATIVE_LOCKTIME`, `Reason.UNSATISFIED_LOCKTIME`. +* **`FailedSigCHeckError`**, signifies a failed signature check. This includes any of the following reasons: `Reason.SIG_COUNT`, `Reason.PUBKEY_COUNT`, `Reason.SIG_HASHTYPE`, `Reason.SIG_DER`, `Reason.SIG_HIGH_S`, `Reason.SIG_NULLFAIL`, `Reason.SIG_BADLENGTH`, `Reason.SIG_NONSCHNORR`. +* **`FailedTransactionError`**, signifies a general fallback error. This includes all remaining reasons listed in the `Reason` enum as well as any other reasons unrelated to the smart contract execution. + +```ts +enum Reason { + EVAL_FALSE = 'Script evaluated without error but finished with a false/empty top stack element', + VERIFY = 'Script failed an OP_VERIFY operation', + EQUALVERIFY = 'Script failed an OP_EQUALVERIFY operation', + CHECKMULTISIGVERIFY = 'Script failed an OP_CHECKMULTISIGVERIFY operation', + CHECKSIGVERIFY = 'Script failed an OP_CHECKSIGVERIFY operation', + CHECKDATASIGVERIFY = 'Script failed an OP_CHECKDATASIGVERIFY operation', + NUMEQUALVERIFY = 'Script failed an OP_NUMEQUALVERIFY operation', + SCRIPT_SIZE = 'Script is too big', + PUSH_SIZE = 'Push value size limit exceeded', + OP_COUNT = 'Operation limit exceeded', + STACK_SIZE = 'Stack size limit exceeded', + SIG_COUNT = 'Signature count negative or greater than pubkey count', + PUBKEY_COUNT = 'Pubkey count negative or limit exceeded', + INVALID_OPERAND_SIZE = 'Invalid operand size', + INVALID_NUMBER_RANGE = 'Given operand is not a number within the valid range [-2^31...2^31]', + IMPOSSIBLE_ENCODING = 'The requested encoding is impossible to satisfy', + INVALID_SPLIT_RANGE = 'Invalid OP_SPLIT range', + INVALID_BIT_COUNT = 'Invalid number of bit set in OP_CHECKMULTISIG', + BAD_OPCODE = 'Opcode missing or not understood', + DISABLED_OPCODE = 'Attempted to use a disabled opcode', + INVALID_STACK_OPERATION = 'Operation not valid with the current stack size', + INVALID_ALTSTACK_OPERATION = 'Operation not valid with the current altstack size', + OP_RETURN = 'OP_RETURN was encountered', + UNBALANCED_CONDITIONAL = 'Invalid OP_IF construction', + DIV_BY_ZERO = 'Division by zero error', + MOD_BY_ZERO = 'Modulo by zero error', + INVALID_BITFIELD_SIZE = 'Bitfield of unexpected size error', + INVALID_BIT_RANGE = 'Bitfield\'s bit out of the expected range', + NEGATIVE_LOCKTIME = 'Negative locktime', + UNSATISFIED_LOCKTIME = 'Locktime requirement not satisfied', + SIG_HASHTYPE = 'Signature hash type missing or not understood', + SIG_DER = 'Non-canonical DER signature', + MINIMALDATA = 'Data push larger than necessary', + SIG_PUSHONLY = 'Only push operators allowed in signature scripts', + SIG_HIGH_S = 'Non-canonical signature: S value is unnecessarily high', + MINIMALIF = 'OP_IF/NOTIF argument must be minimal', + SIG_NULLFAIL = 'Signature must be zero for failed CHECK(MULTI)SIG operation', + SIG_BADLENGTH = 'Signature cannot be 65 bytes in CHECKMULTISIG', + SIG_NONSCHNORR = 'Only Schnorr signatures allowed in this operation', + DISCOURAGE_UPGRADABLE_NOPS = 'NOPx reserved for soft-fork upgrades', + PUBKEYTYPE = 'Public key is neither compressed or uncompressed', + CLEANSTACK = 'Script did not clean its stack', + NONCOMPRESSED_PUBKEY = 'Using non-compressed public key', + ILLEGAL_FORKID = 'Illegal use of SIGHASH_FORKID', + MUST_USE_FORKID = 'Signature must use SIGHASH_FORKID', +} +``` diff --git a/src/data/docs/rest/address.md b/src/data/docs/rest/address.md index 0f22e4c6..a2a533d0 100644 --- a/src/data/docs/rest/address.md +++ b/src/data/docs/rest/address.md @@ -16,7 +16,7 @@ Returns the details of an address including balance #### URL Parameters -1. address `String` required +1. address `string` required #### Result @@ -46,6 +46,7 @@ array `Array` of JSON Objects ], "legacyAddress": "1Fg4r9iDrEkCcDmHTy2T79EusNfhyQpu7W", "cashAddress": "bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c", + "slpAddress":"simpleledger:qzs02v05l7qs5s24srqju498qu55dwuj0c20jv8m5x", "currentPage": 0, "pagesTotal": 1 } @@ -72,6 +73,69 @@ array `Array` of JSON Objects curl -X POST "https://rest.bitcoin.com/v2/address/details" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"addresses\":[\"bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c\",\"bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0\"]}" + [ + { + "balance": 0.05, + "balanceSat": 5000000, + "totalReceived": 0.09185868, + "totalReceivedSat": 9185868, + "totalSent": 0.04185868, + "totalSentSat": 4185868, + "unconfirmedBalance": 0, + "unconfirmedBalanceSat": 0, + "unconfirmedTxApperances": 0, + "txApperances": 40, + "transactions": [ + "41e9a118765ecf7a1ba4487c0863e23dba343cc5880381a72f0365ac2546c5fa", + "2f902dec880568511cefa87b9dd761563edeba9c8ba784dc9fca2f7c8c4e6f97", + "eea57285462dd70dadcd431fc814857b3f81fe4d0a059a8c02c12fd7d33c02d1", + "282b3b296b6aed7122586ed69f7a57d35584eaf94a4d1b1ad7d1b05d36cb79d1", + "ac444896b3e32d17824fa6573eed3b89768c5c9085b7a71f3ba88e9d5ba67355", + "a5f972572ee1753e2fd2457dd61ce5f40fa2f8a30173d417e49feef7542c96a1", + "5165dc531aad05d1149bb0f0d9b7bda99c73e2f05e314bcfb5b4bb9ca5e1af5e", + "54edaa42ff3d6559884a84ebb9bf5ef255635902f5f23b4854245d6b093d41d4", + "2b0825188e909410a20a6fbdc58ff5ccf368844273f93f551222c91e6d0fa888", + "7a12ea2c83d0c8a5d0f643974b0f04bc19be185c9011ed8fc33255a61d3198bb" + ], + "legacyAddress": "1Fg4r9iDrEkCcDmHTy2T79EusNfhyQpu7W", + "cashAddress": "bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c", + "slpAddress": "simpleledger:qzs02v05l7qs5s24srqju498qu55dwuj0c20jv8m5x", + "currentPage": 0, + "pagesTotal": 1 + }, + { + "balance": 0.00582434, + "balanceSat": 582434, + "totalReceived": 2.1308325, + "totalReceivedSat": 213083250, + "totalSent": 2.12500816, + "totalSentSat": 212500816, + "unconfirmedBalance": 0, + "unconfirmedBalanceSat": 0, + "unconfirmedTxApperances": 0, + "txApperances": 12, + "transactions": [ + "c42f8f16d3baa2ee343ea89ef110dfe094992379d08edd30887b8ca7ee671c9a", + "1afcc63b244182647909539ebe3f4a44b8ea4120a95edb8d9eebe5347b9491bb", + "e4a0ac48ff3f42fc342717a2a3d34248e5e85bae79d59bd20e1b60e61b1c500f", + "0f9b49cafeb9ae1d741cdb12137c92816aa8470944c270a78ba2e610bd59190d", + "ceb0cab0e37b59caf3ca29e1a698d19ff47f2827dd09cb2f3b91b9100b1dad1c", + "8bc2134c7e48e56e1769b3d7c4c1e3a0acc68e1e58160eee6fa67f3208c07262", + "b3792d28377b975560e1b6f09e48aeff8438d4c6969ca578bd406393bd50bd7d", + "ecc1b51bac767880382bf3190ff17abf78d0936843a022a943d871116ed50368", + "9ea667bcfc9cd337bd6c5583d8094c1b1942bd2015d95b54189deac5070eeff0", + "6960255abe64893073921e96bf3c053c82686e0fc22a565494fbe2a31e766975", + "7e9aa7a74de2b30200a2d6fc748ff35a0c753221444194f720bb7f61ef1d9153", + "eff00a9538487ff44243c75fb13de19b5783454c42c81b9aff9afbfd09cbaec3" + ], + "legacyAddress": "1PCBukyYULnmraUpMy2hW1Y1ngEQTN8DtF", + "cashAddress": "bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0", + "slpAddress": "simpleledger:qrehqueqhw629p6e57994436w730t4rzasly056h43", + "currentPage": 0, + "pagesTotal": 1 + } + ] + ## Address utxos single Returns the list of utxo for an address @@ -84,7 +148,7 @@ Returns the list of utxo for an address #### URL Parameters -1. address `String` required +1. address `string` required #### Result @@ -124,7 +188,9 @@ utxo `Object` ], "legacyAddress": "1Fg4r9iDrEkCcDmHTy2T79EusNfhyQpu7W", "cashAddress": "bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c", - "scriptPubKey": "76a914a0f531f4ff810a415580c12e54a7072946bb927e88ac" + "slpAddress":"simpleledger:qzs02v05l7qs5s24srqju498qu55dwuj0c20jv8m5x", + "scriptPubKey": "76a914a0f531f4ff810a415580c12e54a7072946bb927e88ac", + "asm": "OP_DUP OP_HASH160 a0f531f4ff810a415580c12e54a7072946bb927e OP_EQUALVERIFY OP_CHECKSIG" } ## Address utxos bulk @@ -180,7 +246,9 @@ array `Array` of JSON Objects ], "legacyAddress": "1Fg4r9iDrEkCcDmHTy2T79EusNfhyQpu7W", "cashAddress": "bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c", - "scriptPubKey": "76a914a0f531f4ff810a415580c12e54a7072946bb927e88ac" + "slpAddress": "simpleledger:qzs02v05l7qs5s24srqju498qu55dwuj0c20jv8m5x", + "scriptPubKey": "76a914a0f531f4ff810a415580c12e54a7072946bb927e88ac", + "asm": "OP_DUP OP_HASH160 a0f531f4ff810a415580c12e54a7072946bb927e OP_EQUALVERIFY OP_CHECKSIG" }, { "utxos": [ @@ -203,7 +271,9 @@ array `Array` of JSON Objects ], "legacyAddress": "1PCBukyYULnmraUpMy2hW1Y1ngEQTN8DtF", "cashAddress": "bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0", - "scriptPubKey": "76a914f3707320bbb4a28759a78a5ad63a77a2f5d462ec88ac" + "slpAddress": "simpleledger:qrehqueqhw629p6e57994436w730t4rzasly056h43", + "scriptPubKey": "76a914f3707320bbb4a28759a78a5ad63a77a2f5d462ec88ac", + "asm": "OP_DUP OP_HASH160 f3707320bbb4a28759a78a5ad63a77a2f5d462ec OP_EQUALVERIFY OP_CHECKSIG" } ] @@ -219,7 +289,7 @@ Returns the list of unconfirmed transactions for an address #### URL Parameters -1. address `String` required +1. address `string` required #### Result @@ -229,6 +299,25 @@ array `Array` of JSON Objects curl -X GET "https://rest.bitcoin.com/v2/address/unconfirmed/bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c" -H "accept: application/json" + + { + "utxos": [ + { + "txid": "b3792d28377b975560e1b6f09e48aeff8438d4c6969ca578bd406393bd50bd7d", + "vout": 0, + "amount": 0.00051061, + "satoshis": 51061, + "height": 560615, + "confirmations": 7045 + } + ], + "legacyAddress": "1Fg4r9iDrEkCcDmHTy2T79EusNfhyQpu7W", + "cashAddress": "bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c", + "slpAddress": "simpleledger:qzs02v05l7qs5s24srqju498qu55dwuj0c20jv8m5x", + "scriptPubKey": "76a914a0f531f4ff810a415580c12e54a7072946bb927e88ac", + "asm": "OP_DUP OP_HASH160 a0f531f4ff810a415580c12e54a7072946bb927e OP_EQUALVERIFY OP_CHECKSIG" + } + ## Unconfirmed transactions bulk Returns the list of unconfirmed transactions for an array of addresses @@ -251,6 +340,43 @@ array `Array` of JSON Objects curl -X POST "https://rest.bitcoin.com/v2/address/unconfirmed" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"addresses\":[\"bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c\",\"bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0\"]}" + [ + { + "utxos": [ + { + "txid": "b3792d28377b975560e1b6f09e48aeff8438d4c6969ca578bd406393bd50bd7d", + "vout": 0, + "amount": 0.00051061, + "satoshis": 51061, + "height": 560615, + "confirmations": 7045 + } + ], + "legacyAddress": "1Fg4r9iDrEkCcDmHTy2T79EusNfhyQpu7W", + "cashAddress": "bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c", + "slpAddress": "simpleledger:qzs02v05l7qs5s24srqju498qu55dwuj0c20jv8m5x", + "scriptPubKey": "76a914a0f531f4ff810a415580c12e54a7072946bb927e88ac", + "asm": "OP_DUP OP_HASH160 a0f531f4ff810a415580c12e54a7072946bb927e OP_EQUALVERIFY OP_CHECKSIG" + }, + { + "utxos": [ + { + "txid": "ac444896b3e32d17824fa6573eed3b89768c5c9085b7a71f3ba88e9d5ba67355", + "vout": 13, + "amount": 0.01, + "satoshis": 1000000, + "height": 558992, + "confirmations": 24514 + } + ], + "legacyAddress": "1PCBukyYULnmraUpMy2hW1Y1ngEQTN8DtF", + "cashAddress": "bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0", + "slpAddress": "simpleledger:qrehqueqhw629p6e57994436w730t4rzasly056h43", + "scriptPubKey": "76a914f3707320bbb4a28759a78a5ad63a77a2f5d462ec88ac", + "asm": "OP_DUP OP_HASH160 f3707320bbb4a28759a78a5ad63a77a2f5d462ec OP_EQUALVERIFY OP_CHECKSIG" + } + ] + ## Transactions single Returns the list of transactions for an address @@ -263,7 +389,7 @@ Returns the list of transactions for an address #### URL Parameters -1. address `String` required +1. address `string` required #### Result @@ -321,5 +447,6 @@ addresses `Object` // returns { "cashAddress": "bitcoincash:qquzx5j5d6u9pge0u7tcurhnk8te3xt0rqlessqhpw", - "legacyAddress": "167q9vxiL43xkn3gHCMfg7UbriX1VfdfG5" + "legacyAddress": "167q9vxiL43xkn3gHCMfg7UbriX1VfdfG5", + "slpAddress": "simpleledger:qquzx5j5d6u9pge0u7tcurhnk8te3xt0rqnzmt4hls" } diff --git a/src/data/docs/rest/block.md b/src/data/docs/rest/block.md index 47266644..8fc3020d 100644 --- a/src/data/docs/rest/block.md +++ b/src/data/docs/rest/block.md @@ -16,7 +16,7 @@ Details about a single block by hash #### URL Parameters -1. hash `String` required +1. hash `string` required #### Result @@ -80,7 +80,7 @@ blocksDetails `Array` of Objects #### Examples - curl -X POST "https://bitcoin.com/v2/v2/block/detailsByHash" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"hashes\":[\"0000000000000000040e83398a79a16390897f0d18c92bada6350a19a32ec984\",\"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201\"]}" + curl -X POST "https://rest.bitcoin.com/v2/v2/block/detailsByHash" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"hashes\":[\"0000000000000000040e83398a79a16390897f0d18c92bada6350a19a32ec984\",\"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201\"]}" // returns [ @@ -164,7 +164,7 @@ Details about a block by height #### URL Parameters -1. height `String` required +1. height `string` required #### Result @@ -229,7 +229,7 @@ blocksDetails `Array` of Objects #### Examples - curl -X POST "https://bitcoin.com/v2/v2/block/detailsByHeight" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"heights\":[499000,500000]}" + curl -X POST "https://rest.bitcoin.com/v2/v2/block/detailsByHeight" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"heights\":[499000,500000]}" // returns [ diff --git a/src/data/docs/rest/blockchain.md b/src/data/docs/rest/blockchain.md index 126e7c36..805ac94f 100644 --- a/src/data/docs/rest/blockchain.md +++ b/src/data/docs/rest/blockchain.md @@ -16,7 +16,7 @@ Returns the hash of the best (tip) block in the longest blockchain. #### Result -bestBlockHash `String` +bestBlockHash `string` #### Examples @@ -98,7 +98,7 @@ Returns the number of blocks in the longest blockchain. #### Result -blockCount `String` +blockCount `string` #### Examples @@ -119,8 +119,8 @@ If verbose is false, returns a string that is serialized, hex-encoded data for b #### URL Parameters -1. hash `String` required -2. verbose `Boolean` optional +1. hash `string` required +2. verbose `boolean` optional #### Result @@ -161,7 +161,7 @@ Returns an Array of Objects w/ block header info. This is a bulk request. #### URL Parameters 1. hashes `Array` of Strings. Required -2. verbose `Boolean` optional +2. verbose `boolean` optional #### Result @@ -169,7 +169,7 @@ blockHeaders `Array` of Objects #### Examples - curl -X POST "https://bitcoin.com/v2/blockchain/getBlockHeader" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"hashes\":[\"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201\",\"00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3\"],\"verbose\":true}" + curl -X POST "https://rest.bitcoin.com/v2/blockchain/getBlockHeader" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"hashes\":[\"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201\",\"00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3\"],\"verbose\":true}" // returns [ @@ -253,7 +253,7 @@ Returns the proof-of-work difficulty as a multiple of the minimum difficulty. #### Result -difficulty `Number` +difficulty `number` #### Examples @@ -274,7 +274,7 @@ Returns mempool data for single transaction #### URL Parameters -1. txid `String` required +1. txid `string` required #### Result @@ -309,7 +309,7 @@ mempoolEntries `Array` of Objects #### Examples - curl -X POST "https://bitcoin.com/v2/blockchain/getMempoolEntry" -H "accept: */*" -H "Content-Type: application/json" -d "{\"txids\":[\"a5f972572ee1753e2fd2457dd61ce5f40fa2f8a30173d417e49feef7542c96a1\",\"5165dc531aad05d1149bb0f0d9b7bda99c73e2f05e314bcfb5b4bb9ca5e1af5e\"]}" + curl -X POST "https://rest.bitcoin.com/v2/blockchain/getMempoolEntry" -H "accept: */*" -H "Content-Type: application/json" -d "{\"txids\":[\"a5f972572ee1753e2fd2457dd61ce5f40fa2f8a30173d417e49feef7542c96a1\",\"5165dc531aad05d1149bb0f0d9b7bda99c73e2f05e314bcfb5b4bb9ca5e1af5e\"]}" // returns { @@ -355,7 +355,7 @@ Returns all transaction ids in memory pool as a json array of string transaction #### URL Parameters -1. verbose `Boolean` optional +1. verbose `boolean` optional #### Result @@ -391,9 +391,9 @@ Returns details about an unspent transaction output. #### URL Parameters -1. txid `String` required -2. n `Number` required -3. mempool `Boolean` optional +1. txid `string` required +2. n `number` required +3. mempool `boolean` optional #### Result @@ -432,11 +432,11 @@ Returns a hex-encoded proof that a single txid was included in a block. #### URL Parameters -1. txid `String` required +1. txid `string` required #### Result -txOutProof `String` +txOutProof `string` #### Examples @@ -465,7 +465,7 @@ txOutProofs `Array` of Objects #### Examples - curl -X POST "https://bitcoin.com/v2/blockchain/getTxOutProof" -H "accept: */*" -H "Content-Type: application/json" -d "{\"txids\":[\"a5f972572ee1753e2fd2457dd61ce5f40fa2f8a30173d417e49feef7542c96a1\",\"5165dc531aad05d1149bb0f0d9b7bda99c73e2f05e314bcfb5b4bb9ca5e1af5e\"]}" + curl -X POST "https://rest.bitcoin.com/v2/blockchain/getTxOutProof" -H "accept: */*" -H "Content-Type: application/json" -d "{\"txids\":[\"a5f972572ee1753e2fd2457dd61ce5f40fa2f8a30173d417e49feef7542c96a1\",\"5165dc531aad05d1149bb0f0d9b7bda99c73e2f05e314bcfb5b4bb9ca5e1af5e\"]}" // returns [ @@ -489,7 +489,7 @@ Verifies that a single proof points to a transaction in a block, returning the t #### URL Parameters -1. proof `String` required +1. proof `string` required #### Result @@ -524,7 +524,7 @@ txOutProofs `Array` of Objects #### Examples - curl -X POST "https://bitcoin.com/v2/blockchain/verifyTxOutProof" -H "accept: */*" -H "Content-Type: application/json" -d "{\"proofs\":[\"010000007de867cc8adc5cc8fb6b898ca4462cf9fd667d7830a275277447e60800000000338f121232e169d3100edd82004dc2a1f0e1f030c6c488fa61eafa930b0528fe021f7449ffff001d36b4af9a0100000001338f121232e169d3100edd82004dc2a1f0e1f030c6c488fa61eafa930b0528fe0101\",\"000000202cbe31a32f4ad5b42877a9ccf9ff6edb3f5ab29ff73ec9000000000000000000069061a8809fed6557fa87eeb5aa7ac9e6720dcb2e2f401b40b7d83be5b4cb4f20a1e95b8c8d01188ca7c098e20100000a3705adb29177f22766afb07d46eb1d3f16a68fdd01c1ede671fcb954899ffed4c161c0a33aa8f6e562e40b1e0124818663e063004720d8d7e9074808a1f16ca56ba218571cb8069bc45bc8c6496ad9611b35d412e2545211ba85438be487d6dc39cd0ae63a41be9a89c4ed823fa6eceb0ceffe13638defa01109a514e639b89e5eafe1a59cbbb4b5cf4b315ef0e2739ca9bdb7d9f0b09b14d105ad1a53dc655176895cacc3f897d5088b004113f886df266edd1ff797f4550885f32380c8fb575be00072239baa70ccf354882e8c50a1d01e81ab2c85146d9e8c3c75140eca2d9d5640af739a86047493e24b1393745914a75fdfe19f081626a5846353c67b45ccf2dd6a753ba118e89239b7916be2ee06e34dc85257228edeaaca06efa0a565580872eff1787360bdf7ff274bb49437bef6a368ab578e34b739ddcc16088a8603ad3700\"]}" + curl -X POST "https://rest.bitcoin.com/v2/blockchain/verifyTxOutProof" -H "accept: */*" -H "Content-Type: application/json" -d "{\"proofs\":[\"010000007de867cc8adc5cc8fb6b898ca4462cf9fd667d7830a275277447e60800000000338f121232e169d3100edd82004dc2a1f0e1f030c6c488fa61eafa930b0528fe021f7449ffff001d36b4af9a0100000001338f121232e169d3100edd82004dc2a1f0e1f030c6c488fa61eafa930b0528fe0101\",\"000000202cbe31a32f4ad5b42877a9ccf9ff6edb3f5ab29ff73ec9000000000000000000069061a8809fed6557fa87eeb5aa7ac9e6720dcb2e2f401b40b7d83be5b4cb4f20a1e95b8c8d01188ca7c098e20100000a3705adb29177f22766afb07d46eb1d3f16a68fdd01c1ede671fcb954899ffed4c161c0a33aa8f6e562e40b1e0124818663e063004720d8d7e9074808a1f16ca56ba218571cb8069bc45bc8c6496ad9611b35d412e2545211ba85438be487d6dc39cd0ae63a41be9a89c4ed823fa6eceb0ceffe13638defa01109a514e639b89e5eafe1a59cbbb4b5cf4b315ef0e2739ca9bdb7d9f0b09b14d105ad1a53dc655176895cacc3f897d5088b004113f886df266edd1ff797f4550885f32380c8fb575be00072239baa70ccf354882e8c50a1d01e81ab2c85146d9e8c3c75140eca2d9d5640af739a86047493e24b1393745914a75fdfe19f081626a5846353c67b45ccf2dd6a753ba118e89239b7916be2ee06e34dc85257228edeaaca06efa0a565580872eff1787360bdf7ff274bb49437bef6a368ab578e34b739ddcc16088a8603ad3700\"]}" // returns [ diff --git a/src/data/docs/rest/cashAccounts.md b/src/data/docs/rest/cashAccounts.md new file mode 100644 index 00000000..4884d165 --- /dev/null +++ b/src/data/docs/rest/cashAccounts.md @@ -0,0 +1,192 @@ +--- +title: CashAccounts +icon: user-circle +ordinal: 4 +--- + +## Account Lookup + +Returns an object containing account info + +**URL** : `v2/cashAccounts/lookup/{account}/{number}/{collision}` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. account `string` **required** +2. number `string` **required** +3. collision `string` **optional** + +#### Result + +accountInfo `CashAccountInterface` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/cashAccounts/lookup/cgcardona/122/6383276713" -H "accept: */*" + + // returns + { + "identifier": "cgcardona#122;", + "information": { + "emoji": "🍞", + "name": "cgcardona", + "number": 122, + "collision": { + "hash": "6383276713", + "count": 0, + "length": 0 + }, + "payment": [ + { + "type": "Key Hash", + "address": "bitcoincash:qrhncn6hgkhljqg4fuq4px5qg74sjz9fqqj64s9la9" + } + ] + } + } + +## Account Check + +Get multiple Cash Accounts block height and inclusion proof for independent verification + +**URL** : `v2/cashAccounts/check/{account}/{number}` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. account `string` **required** +2. number `string` **required** + +#### Result + +accountLookup `CashAccountBatchResults` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/cashAccounts/check/cgcardona/122" -H "accept: */*" + + // returns + { + "identifier": "cgcardona#122", + "block": 563742, + "results": [ + { + "transaction": "0100000001A8421264294082C08C0611E162BD49999443EF577C57923BD052F7202B09408E010000006A473044022039F4DD9AD6BC2C4E799D135BB68B5E05E71F83731EFC63260C7FB16F63BB842802203DEA9E82E97D28ADC9A9567E16762CF3663C24CE6A42AEDDC1E273E50B8CA9C941210202435C144A77C6ED76C3A74EE6006A9255B449F1B2F09FA2668027FEC106CFA1FFFFFFFF020000000000000000266A0401010101096367636172646F6E611501EF3C4F5745AFF901154F01509A8047AB0908A9008CD51100000000001976A914919908484336464C2A9938D24149A4177606340F88AC00000000", + "inclusionProof": "0000C020C98F109DA027EB72472AC903F6E2BFA993D88724734B2C01000000000000000019213AEE113214AF03EEEE303F733708AD79F259A148F4A17C496302E1D093DF7D9D2E5C4CE10418F2AE48C41F000000067AA86CA831AB260AF59E0ED93305939D9A300BD66076EB18D155143E992950C33A46C140D7202C577D6C25DCD8F315D304285D8BD890C41925F00CC256C22CC69E1410317FD69D5A58F762EE26B469DC1909F2D0DE5E471B0AC09C686C41664585DF32ABA0EEAF50B6AB66010206DE24A5C576CBC331EF153507E9E20D1C18506E24DBEDB0A0B66705E10376CD19ADB4A605098058ACB805D24456CC004CCA78ABA3969F47284773B7809C81B93E2CCCC280218272164AE5D90245A629F6801802EB00" + } + ] + } + +## Reverse Lookup + +Get Cash Accounts associated with the address provided. + +**URL** : `v2/cashAccounts/reverseLookup/{account}` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. account `string` **required** + +#### Result + +accountLookup `CashAccountReverseLookupResults` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/cashAccounts/reverselookup/bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst" -H "accept: */*" + + // returns + { + "results": [ + { + "accountEmoji": "☯", + "nameText": "Jonathan", + "accountNumber": 100, + "accountHash": "5876958390", + "accountCollisionLength": 0, + "payloadType": 1, + "payloadAddress": "bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst" + }, + { + "accountEmoji": "🍭", + "nameText": "ConfirmationTest", + "accountNumber": 113, + "accountHash": "4640561912", + "accountCollisionLength": 0, + "payloadType": 1, + "payloadAddress": "bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst" + }, + { + "accountEmoji": "🌽", + "nameText": "Bob", + "accountNumber": 4035, + "accountHash": "7443382842", + "accountCollisionLength": 0, + "payloadType": 1, + "payloadAddress": "bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst" + }, + { + "accountEmoji": "🎀", + "nameText": "qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst", + "accountNumber": 7084, + "accountHash": "4319915751", + "accountCollisionLength": 0, + "payloadType": 1, + "payloadAddress": "bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst" + } + ] + } + +## Interfaces + +### CashAccountInterface + + { + identifier: string + information: { + emoji: string + name: string + number: number + collision: { + hash: string + } + payment: string[] + } + } + +### CashAccountBatchResults + + { + identifier: string + block: number + results: string[] + } + +### CashAccountReverseLookupResults + + { + results: SingleCashAccountReverseLookupResult[] + } + +### SingleCashAccountReverseLookupResult + + { + accountEmoji: any + nameText: string + accountNumber: number + accountHash: string + accountCollisionLength: number + payloadType: number + payloadAddress: string + } diff --git a/src/data/docs/rest/control.md b/src/data/docs/rest/control.md index 3d0a7d6b..02c3b1d0 100644 --- a/src/data/docs/rest/control.md +++ b/src/data/docs/rest/control.md @@ -1,7 +1,7 @@ --- title: Control icon: gamepad -ordinal: 4 +ordinal: 5 --- ## Get Info @@ -36,3 +36,59 @@ info `Object` "relayfee": 0.00001, "errors": "" } + +## Get Network Info + +Returns an object containing various network info. + +**URL** : `v2/control/getNetworkInfo` + +**Method** : `GET` + +**Auth required** : NO + +#### Result + +networkInfo `Object` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/control/getNetworkInfo" -H "accept: application/json" + + // returns + { + "version": 190500, + "subversion": "/Bitcoin ABC:0.19.5(EB32.0)/", + "protocolversion": 70015, + "localservices": "0000000000000425", + "localrelay": true, + "timeoffset": 0, + "networkactive": true, + "connections": 15, + "networks": [ + { + "name": "ipv4", + "limited": false, + "reachable": true, + "proxy": "", + "proxy_randomize_credentials": false + }, + { + "name": "ipv6", + "limited": false, + "reachable": true, + "proxy": "", + "proxy_randomize_credentials": false + }, + { + "name": "onion", + "limited": true, + "reachable": false, + "proxy": "", + "proxy_randomize_credentials": false + } + ], + "relayfee": 0.00001, + "excessutxocharge": 0, + "warnings": "Warning: Unknown block versions being mined! It's possible unknown rules are in effect" + } diff --git a/src/data/docs/rest/mining.md b/src/data/docs/rest/mining.md index 5c7f5764..b68ebe08 100644 --- a/src/data/docs/rest/mining.md +++ b/src/data/docs/rest/mining.md @@ -29,7 +29,7 @@ array `Array` of JSON Objects "currentblocktx": 0, "difficulty": 243738776600.1426, "blockprioritypercentage": 5, - "errors": "", + "warnings": "", "networkhashps": 1587730664538483000, "pooledtx": 112, "chain": "main" @@ -47,12 +47,12 @@ Returns the estimated network hashes per second based on the last n blocks. Pass #### Body Parameters -1. nblocks `String` optional -2. height `String` optional +1. nblocks `string` optional +2. height `string` optional #### Result -getworkHashps `Number` +getworkHashps `number` #### Examples diff --git a/src/data/docs/rest/rawtransactions.md b/src/data/docs/rest/rawtransactions.md index 2f7acf11..cf4b2767 100644 --- a/src/data/docs/rest/rawtransactions.md +++ b/src/data/docs/rest/rawtransactions.md @@ -1,7 +1,7 @@ --- title: Raw Transactions icon: exchange -ordinal: 8 +ordinal: 7 --- ## Decode Single Raw Transaction @@ -16,7 +16,7 @@ Return a JSON object representing the serialized, hex-encoded transaction. #### URL Parameters -1. hex encoded `String` (required) +1. hex encoded `string` (required) #### Result @@ -24,7 +24,7 @@ Return a JSON object representing the serialized, hex-encoded transaction. #### Examples - curl -X GET "https://bitcoin.com/v2/rawtransactions/decodeRawTransaction/02000000010e991f7ccec410f27d333f737f149b5d3be6728687da81072e638aed0063a176010000006b483045022100cd20443b0af090053450bc4ab00d563d4ac5955bb36e0135b00b8a96a19f233302205047f2c70a08c6ef4b76f2d198b33a31d17edfaa7e1e9e865894da0d396009354121024d4e7f522f67105b7bf5f9dbe557e7b2244613fdfcd6fe09304f93877328f6beffffffff02a0860100000000001976a9140ee020c07f39526ac5505c54fa1ab98490979b8388acb5f0f70b000000001976a9143a9b2b0c12fe722fcf653b6ef5dcc38732d6ff5188ac00000000" -H "accept: application/json" + curl -X GET "https://rest.bitcoin.com/v2/rawtransactions/decodeRawTransaction/02000000010e991f7ccec410f27d333f737f149b5d3be6728687da81072e638aed0063a176010000006b483045022100cd20443b0af090053450bc4ab00d563d4ac5955bb36e0135b00b8a96a19f233302205047f2c70a08c6ef4b76f2d198b33a31d17edfaa7e1e9e865894da0d396009354121024d4e7f522f67105b7bf5f9dbe557e7b2244613fdfcd6fe09304f93877328f6beffffffff02a0860100000000001976a9140ee020c07f39526ac5505c54fa1ab98490979b8388acb5f0f70b000000001976a9143a9b2b0c12fe722fcf653b6ef5dcc38732d6ff5188ac00000000" -H "accept: application/json" // returns { @@ -178,7 +178,7 @@ Decode a single hex-encoded script. #### URL Parameters -1. hex encoded `String` (required) +1. hex encoded `string` (required) #### Result @@ -243,19 +243,19 @@ return the raw transaction data. If verbose is 'true', returns an Object with in #### URL Parameters -1. hex encoded txid `String` (required) +1. hex encoded txid `string` (required) #### Query Parameters -1. verbose `String` of value "true" optional. Default is false. +1. verbose `string` of value "true" optional. Default is false. #### Result -`String` containing hex encoded transaction if _verbose_ is false. `Object` containing the decoded transaction data if _verbose_ is true. +`string` containing hex encoded transaction if _verbose_ is false. `Object` containing the decoded transaction data if _verbose_ is true. #### Examples - curl -X GET "https://bitcoin.com/v2/rawtransactions/getRawTransaction/40112ab9d2b5f98427839272d7a1e23dd2afc6c8355626f373e076c2ab5c2f72?verbose=true" -H "accept: application/json" + curl -X GET "https://rest.bitcoin.com/v2/rawtransactions/getRawTransaction/40112ab9d2b5f98427839272d7a1e23dd2afc6c8355626f373e076c2ab5c2f72?verbose=true" -H "accept: application/json" // returns { @@ -322,11 +322,11 @@ Send single raw transactions to network. #### URL Parameters -1. hex `String`. (required) +1. hex `string`. (required) #### Result -txids `String` containing the txid of the transaction +txids `string` containing the txid of the transaction #### Examples diff --git a/src/data/docs/rest/slp.md b/src/data/docs/rest/slp.md index 2f03844d..a79027f5 100644 --- a/src/data/docs/rest/slp.md +++ b/src/data/docs/rest/slp.md @@ -1,7 +1,7 @@ --- title: SLP icon: coins -ordinal: 9 +ordinal: 8 --- ## List @@ -16,7 +16,7 @@ List all SLP tokens #### Result -`Array` containing all SLP tokens +tokens `TokenInterface[]` containing all SLP tokens #### Examples @@ -24,25 +24,49 @@ List all SLP tokens // returns [ - { - "id": "24686f336975796253be67ab3d6b1b304905f0f5d81fa934c581aba4da606f38", - "timestamp": "2019-02-05 10:17", - "symbol": "TESTNET1", - "name": "SLP SDK Testnet Token 1", - "documentUri": "badger@bitcoin.com", - "documentHash": "", + { "decimals": 8, - "initialTokenQty": 1000 + "timestamp": "2019-05-24 17:13:21", + "timestampUnix": 1558718001, + "versionType": 1, + "documentUri": "", + "symbol": "CAR-CH", + "name": "CaracasCash", + "containsBaton": false, + "id": "7380843cd1089a1a01783f86af37734dc99667a1cdc577391b5f6ea42fc1bfb4", + "documentHash": null, + "initialTokenQty": 21000000, + "blockCreated": 583989, + "blockLastActiveSend": 584020, + "blockLastActiveMint": null, + "txnsSinceGenesis": 2, + "validAddresses": 2, + "totalMinted": 21000000, + "totalBurned": 0, + "circulatingSupply": 21000000, + "mintingBatonStatus": "NEVER_CREATED" }, { - "id": "78d57a82a0dd9930cc17843d9d06677f267777dd6b25055bad0ae43f1b884091", - "timestamp": "2019-02-04 12:43", - "symbol": "SLPSDK", - "name": "Awesome SLP SDK Token", - "documentUri": "badger@bitcoin.com", - "documentHash": "", - "decimals": 2, - "initialTokenQty": 1000000 + "decimals": 0, + "timestamp": "2019-05-21 11:33:07", + "timestampUnix": 1558438387, + "versionType": 1, + "documentUri": "developer.bitcoin.com", + "symbol": "GABRIEL", + "name": "SLP SDK Example", + "containsBaton": true, + "id": "9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0", + "documentHash": "1010101010101010101010101010101010101010101010101010101010101010", + "initialTokenQty": 100000000, + "blockCreated": 583529, + "blockLastActiveSend": 583529, + "blockLastActiveMint": 583536, + "txnsSinceGenesis": 6, + "validAddresses": 2, + "totalMinted": 100000256, + "totalBurned": 10, + "circulatingSupply": 100000246, + "mintingBatonStatus": "ALIVE" } ] @@ -58,26 +82,38 @@ List details about single SLP token by tokenId #### URL Parameters -1. tokenId `String` (required) +1. tokenId `string` **required** #### Result -token `Object` +token `TokenInterface` #### Examples - curl -X GET "https://rest.bitcoin.com/v2/slp/list/259908ae44f46ef585edef4bcc1e50dc06e4c391ac4be929fae27235b8158cf1" -H "accept: */*" + curl -X GET "https://rest.bitcoin.com/v2/slp/list/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0" -H "accept: */*" // returns { - "id": "259908ae44f46ef585edef4bcc1e50dc06e4c391ac4be929fae27235b8158cf1", - "timestamp": "2018-10-11 02:39", - "symbol": "BROC", - "name": "Broccoli", - "documentUri": "broccoli.cash", - "documentHash": "", - "decimals": 2, - "initialTokenQty": 1000 + "decimals": 0, + "timestamp": "2019-05-21 11:33:07", + "timestampUnix": 1558438387, + "versionType": 1, + "documentUri": "developer.bitcoin.com", + "symbol": "GABRIEL", + "name": "SLP SDK Example", + "containsBaton": true, + "id": "9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0", + "documentHash": "1010101010101010101010101010101010101010101010101010101010101010", + "initialTokenQty": 100000000, + "blockCreated": 583529, + "blockLastActiveSend": 583529, + "blockLastActiveMint": 583536, + "txnsSinceGenesis": 6, + "validAddresses": 2, + "totalMinted": 100000256, + "totalBurned": 10, + "circulatingSupply": 100000246, + "mintingBatonStatus": "ALIVE" } ## List bulk @@ -92,45 +128,69 @@ List details about several SLP tokens,e by tokenId #### BODY Parameters -1. tokenIds `Array` of token ID strings (required) +1. tokenIds `string[]` of token ID strings **required** #### Result -`Array` of token objects. +`TokenInterface[]` of token objects. #### Examples - curl -X POST "https://rest.bitcoin.com/v2/slp/list" -H "accept: */*" -H "Content-Type: application/json" -d "{\"tokenIds\":[\"259908ae44f46ef585edef4bcc1e50dc06e4c391ac4be929fae27235b8158cf1\",\"7dd083dbec32133c78afd17f2a7550516202c7e9bf98e570edd91d06aebb54ad\"]}" + curl -X POST "https://rest.bitcoin.com/v2/slp/list" -H "accept: */*" -H "Content-Type: application/json" -d "{\"tokenIds\":[\"7380843cd1089a1a01783f86af37734dc99667a1cdc577391b5f6ea42fc1bfb4\",\"9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0\"]}" // returns [ { - "id": "259908ae44f46ef585edef4bcc1e50dc06e4c391ac4be929fae27235b8158cf1", - "timestamp": "2018-10-11 02:39", - "symbol": "BROC", - "name": "Broccoli", - "documentUri": "broccoli.cash", - "documentHash": "", - "decimals": 2, - "initialTokenQty": 1000 + "decimals": 8, + "timestamp": "2019-05-24 17:13:21", + "timestampUnix": 1558718001, + "versionType": 1, + "documentUri": "", + "symbol": "CAR-CH", + "name": "CaracasCash", + "containsBaton": false, + "id": "7380843cd1089a1a01783f86af37734dc99667a1cdc577391b5f6ea42fc1bfb4", + "documentHash": null, + "initialTokenQty": 21000000, + "blockCreated": 583989, + "blockLastActiveSend": 584020, + "blockLastActiveMint": null, + "txnsSinceGenesis": 2, + "validAddresses": 2, + "totalMinted": 21000000, + "totalBurned": 0, + "circulatingSupply": 21000000, + "mintingBatonStatus": "NEVER_CREATED" }, { - "id": "7dd083dbec32133c78afd17f2a7550516202c7e9bf98e570edd91d06aebb54ad", - "timestamp": "2019-02-25 17:04", - "symbol": "HN", - "name": "Rambo Test Token", - "documentUri": "test", - "documentHash": "", - "decimals": 2, - "initialTokenQty": 8888 + "decimals": 0, + "timestamp": "2019-05-21 11:33:07", + "timestampUnix": 1558438387, + "versionType": 1, + "documentUri": "developer.bitcoin.com", + "symbol": "GABRIEL", + "name": "SLP SDK Example", + "containsBaton": true, + "id": "9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0", + "documentHash": "1010101010101010101010101010101010101010101010101010101010101010", + "initialTokenQty": 100000000, + "blockCreated": 583529, + "blockLastActiveSend": 583529, + "blockLastActiveMint": 583536, + "txnsSinceGenesis": 6, + "validAddresses": 2, + "totalMinted": 100000256, + "totalBurned": 10, + "circulatingSupply": 100000246, + "mintingBatonStatus": "ALIVE" } ] - + } + +## Convert address bulk + +Convert multiple addresses to cash, legacy and simpleledger format + +**URL** : `v2/slp/convert` + +**Method** : `POST` + +**Auth required** : NO + +#### Body Parameters + +1. addresses `string[]` **required**. Can be in cash, legacy or simpleledger format + +#### Result + +conversion `ConvertResult[]` + +#### Examples + + curl -X POST "https://rest.bitcoin.com/v2/slp/convert" -H "accept: */*" -H "Content-Type: application/json" -d "{\"addresses\":[\"simpleledger:qrxa0unrn67rtn85v7asfddhhth43ecnxua0antk2l\"]}" + + // returns + [ + { + "slpAddress": "simpleledger:qrxa0unrn67rtn85v7asfddhhth43ecnxua0antk2l", + "cashAddress": "bitcoincash:qrxa0unrn67rtn85v7asfddhhth43ecnxu35kg7k5p", + "legacyAddress": "1KmQDaJdUDwwEFRwVwGwTqJ9gqBzyGYzjY" + } + ] + +## Validate Single + +Validate single SLP transaction by txid. + +**URL** : `v2/slp/validate/{txid}` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. txid `string` **required** + +#### Result + +valid `ValidateTxidResult` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/slp/validateTxid/f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" -H "accept: */*" + + // returns + { + "txid": "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + "valid": false, + "invalidReason": "SLP OP_RETURN parsing error (Bad OP_RETURN)." + } ## Validate Bulk @@ -167,21 +287,22 @@ Validate multiple SLP transactions by txid. #### Body Parameters -1. txids `Array` (required) +1. txids `string[]` **required** #### Result -valid `Array` of txid strings +valid `ValidateTxidResult[]` #### Examples - curl -X POST "https://rest.bitcoin.com/v2/slp/validateTxid" -H "accept: */*" -H "Content-Type: application/json" -d "{\"txids\":[\"88b121101d71b73599dfc7d79eead599031912b2c48298bf5c1f37f4dd743ffa\",\"fb0eeaa501a6e1acb721669c62a3f70741f48ae0fd7f4b8e1d72088785c51952\"]}"" + curl -X POST "https://rest.bitcoin.com/v2/slp/validateTxid" -H "accept: */*" -H "Content-Type: application/json" -d "{\"txids\":[\"f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a\",\"fb0eeaa501a6e1acb721669c62a3f70741f48ae0fd7f4b8e1d72088785c51952\"]}" // returns [ { - "txid": "88b121101d71b73599dfc7d79eead599031912b2c48298bf5c1f37f4dd743ffa", - "valid": true + "txid": "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + "valid": false, + "invalidReason":"SLP OP_RETURN parsing error (Bad OP_RETURN)." }, { "txid": "fb0eeaa501a6e1acb721669c62a3f70741f48ae0fd7f4b8e1d72088785c51952", @@ -189,6 +310,433 @@ valid `Array` of txid strings } ] +## Balances by address + +List all balances for address + +**URL** : `v2/slp/balancesForAddress/:address` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. address `string` **required** + +#### Result + +balances `BalancesForAddress[]` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/slp/balancesForAddress/simpleledger:qz9tzs6d5097ejpg279rg0rnlhz546q4fsnck9wh5m" -H "accept: */*" + + // returns + [ + { + "tokenId": "7f8889682d57369ed0e32336f8b7e0ffec625a35cca183f4e81fde4e71a538a1", + "balance": 433962, + "balanceString": "433962", + "slpAddress": "simpleledger:qz9tzs6d5097ejpg279rg0rnlhz546q4fsnck9wh5m", + "decimalCount": 0 + } + ] + +## Balances by tokenId + +List all balances for tokenId + +**URL** : `v2/slp/balancesForToken/:tokenId` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. tokenId `string` **required** + +#### Result + +balances `BalancesForToken[]` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/slp/balancesForToken/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0" -H "accept: */*" + + // returns + [ + { + "tokenId": "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + "tokenBalance": 20, + "tokenBalanceString": "20", + "slpAddress": 'simpleledger:qp4g0q97tq53pasnxk2rs570c6573qvylunsf5gy9e' + }, + { + "tokenId": "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + "tokenBalance": 335.55, + "tokenBalanceString": "335.55", + "slpAddress": 'simpleledger:qqcraw7q0ys3kg4z6f2zd267fhg2093c5c0spfk03f' + } + ] + +## Balances for address by tokenId + +List balance for address by tokenId + +**URL** : `v2/slp/balance/:address/:tokenId` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. address `string` **required** +1. tokenId `string` **required** + +#### Result + +balance `BalanceForAddressByTokenId` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/slp/balance/simpleledger:qrxa0unrn67rtn85v7asfddhhth43ecnxua0antk2l/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0" -H "accept: */*" + + // returns + { + "tokenId": "9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0", + "balance": 100000245 + "balanceString": "100000245" + } + +## Token Stats + +Stats for token by tokenId + +**URL** : `v2/slp/tokenStats/:tokenId` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. tokenId `string` **required** + +#### Result + +stats `TokenInterface` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/slp/tokenStats/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0" -H "accept: */*" + + // returns + { + "decimals": 0, + "timestamp": "2019-05-21 11:33:07", + "timestampUnix": 1558438387, + "versionType": 1, + "documentUri": "developer.bitcoin.com", + "symbol": "GABRIEL", + "name": "SLP SDK Example", + "containsBaton": true, + "id": "9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0", + "documentHash": "1010101010101010101010101010101010101010101010101010101010101010", + "initialTokenQty": 100000000, + "blockCreated": 583529, + "blockLastActiveSend": 583529, + "blockLastActiveMint": 583536, + "txnsSinceGenesis": 6, + "validAddresses": 2, + "totalMinted": 100000256, + "totalBurned": 10, + "circulatingSupply": 100000246, + "mintingBatonStatus": "ALIVE" + } + +## Transaction Details + +SLP Transaction details by transaction Id + +**URL** : `v2/slp/txDetails/:txid` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. txidd `string` **required** + +#### Result + +txDetails `Object` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/slp/txDetails/8ab4ac5dea3f9024e3954ee5b61452955d659a34561f79ef62ac44e133d0980e" -H "accept: */*" + + // returns + { + "txid": "8ab4ac5dea3f9024e3954ee5b61452955d659a34561f79ef62ac44e133d0980e", + "version": 2, + "locktime": 0, + "vin": [ + { + "txid": "99721a9da3f8bffd6465707cf956d6280a7d139242edb74c0158e0d66097568b", + "vout": 0, + "sequence": 4294967295, + "n": 0, + "scriptSig": { + "hex": "483045022100f59ab062beb612c49631bf5e214abe9a839637106a48d13b7cc5878b9dffd15e022011a872d53b1f7881464c39a27b9ad75dd2c348f1e5b726ece164d816a64370a541210242faa7cc02f9e6c3a0aec97a946b9d3793fa6ab76362e02dd239bc56393671cd", + "asm": "3045022100f59ab062beb612c49631bf5e214abe9a839637106a48d13b7cc5878b9dffd15e022011a872d53b1f7881464c39a27b9ad75dd2c348f1e5b726ece164d816a64370a5[ALL|FORKID] 0242faa7cc02f9e6c3a0aec97a946b9d3793fa6ab76362e02dd239bc56393671cd" + }, + "value": 12300, + "legacyAddress": "1GQTe9EdBaF4fCTC2esvPNXewkUZoytADL", + "cashAddress": "bitcoincash:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fgmc5skpja", + "slpAddress": "simpleledger:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fghrltrpvr" + }, + { + "txid": "23cbcbbe3b38418e0ae2135c2dce05d0ec07ee24f1e4c4b73a45af72d3e25bb4", + "vout": 3, + "sequence": 4294967295, + "n": 1, + "scriptSig": { + "hex": "47304402200233d4f348ae1629d868fae2047c77c5da8e52d42291b660fcd813012f76e627022027376e08e38bfbe0746c152fe9caf3a42579838953e166ad238363e594960ccd41210242faa7cc02f9e6c3a0aec97a946b9d3793fa6ab76362e02dd239bc56393671cd", + "asm": "304402200233d4f348ae1629d868fae2047c77c5da8e52d42291b660fcd813012f76e627022027376e08e38bfbe0746c152fe9caf3a42579838953e166ad238363e594960ccd[ALL|FORKID] 0242faa7cc02f9e6c3a0aec97a946b9d3793fa6ab76362e02dd239bc56393671cd" + }, + "value": 15986676, + "legacyAddress": "1GQTe9EdBaF4fCTC2esvPNXewkUZoytADL", + "cashAddress": "bitcoincash:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fgmc5skpja", + "slpAddress": "simpleledger:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fghrltrpvr" + }, + { + "txid": "91bafd1d8ff36748804e98a17a9777017e0251fb77fcb0a29b3c6c20764bd674", + "vout": 0, + "sequence": 4294967295, + "n": 2, + "scriptSig": { + "hex": "483045022100b907aca9e4be21bef149baa715e6826420f8886b00bca9a5d380a8243549d8cf02205938d363f581d4a20a5eeb2b7002c5aa118fceea58d4de58907ea21c1e6a088141210242faa7cc02f9e6c3a0aec97a946b9d3793fa6ab76362e02dd239bc56393671cd", + "asm": "3045022100b907aca9e4be21bef149baa715e6826420f8886b00bca9a5d380a8243549d8cf02205938d363f581d4a20a5eeb2b7002c5aa118fceea58d4de58907ea21c1e6a0881[ALL|FORKID] 0242faa7cc02f9e6c3a0aec97a946b9d3793fa6ab76362e02dd239bc56393671cd" + }, + "value": 10000, + "legacyAddress": "1GQTe9EdBaF4fCTC2esvPNXewkUZoytADL", + "cashAddress": "bitcoincash:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fgmc5skpja", + "slpAddress": "simpleledger:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fghrltrpvr" + }, + { + "txid": "ccb182f945a2b3555d88c6ff0edaeaf4ef3ae6c5aa8650e7688f9b2ff376274a", + "vout": 0, + "sequence": 4294967295, + "n": 3, + "scriptSig": { + "hex": "483045022100eac5b06854ccfe84f8e8155f23d64ce68f95c5f99fdc1ee058a5abd9edfeca2502200e42583ce43458ebccbca8cff772443116c1e2ac8912fc90abcc6efdcf24550241210242faa7cc02f9e6c3a0aec97a946b9d3793fa6ab76362e02dd239bc56393671cd", + "asm": "3045022100eac5b06854ccfe84f8e8155f23d64ce68f95c5f99fdc1ee058a5abd9edfeca2502200e42583ce43458ebccbca8cff772443116c1e2ac8912fc90abcc6efdcf245502[ALL|FORKID] 0242faa7cc02f9e6c3a0aec97a946b9d3793fa6ab76362e02dd239bc56393671cd" + }, + "value": 3210, + "legacyAddress": "1GQTe9EdBaF4fCTC2esvPNXewkUZoytADL", + "cashAddress": "bitcoincash:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fgmc5skpja", + "slpAddress": "simpleledger:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fghrltrpvr" + }, + { + "txid": "23cbcbbe3b38418e0ae2135c2dce05d0ec07ee24f1e4c4b73a45af72d3e25bb4", + "vout": 2, + "sequence": 4294967295, + "n": 4, + "scriptSig": { + "hex": "483045022100ef64c1ff60dda8ff30c5f5a760100fa1327e938a98970289fe91ada41bc10dc70220060204aa6391151bcc451901dc2c174ea07031071673279097f28ef4f19bef9d41210242faa7cc02f9e6c3a0aec97a946b9d3793fa6ab76362e02dd239bc56393671cd", + "asm": "3045022100ef64c1ff60dda8ff30c5f5a760100fa1327e938a98970289fe91ada41bc10dc70220060204aa6391151bcc451901dc2c174ea07031071673279097f28ef4f19bef9d[ALL|FORKID] 0242faa7cc02f9e6c3a0aec97a946b9d3793fa6ab76362e02dd239bc56393671cd" + }, + "value": 546, + "legacyAddress": "1GQTe9EdBaF4fCTC2esvPNXewkUZoytADL", + "cashAddress": "bitcoincash:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fgmc5skpja", + "slpAddress": "simpleledger:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fghrltrpvr" + } + ], + "vout": [ + { + "value": "0.00000000", + "n": 0, + "scriptPubKey": { + "hex": "6a04534c500001010453454e4420df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb080000000005f5e10008000001638de34bc0", + "asm": "OP_RETURN 5262419 1 1145980243 df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb 0000000005f5e100 000001638de34bc0" + }, + "spentTxId": null, + "spentIndex": null, + "spentHeight": null + }, + { + "value": "0.00000546", + "n": 1, + "scriptPubKey": { + "hex": "76a914a8f9b1307fa412da6a909f08930e5a502d27a74a88ac", + "asm": "OP_DUP OP_HASH160 a8f9b1307fa412da6a909f08930e5a502d27a74a OP_EQUALVERIFY OP_CHECKSIG", + "addresses": [ + "1GQTe9EdBaF4fCTC2esvPNXewkUZoytADL" + ], + "type": "pubkeyhash", + "cashAddrs": [ + "bitcoincash:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fgmc5skpja" + ], + "slpAddrs": [ + "simpleledger:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fghrltrpvr" + ] + }, + "spentTxId": "0a730a25a758af6a28605bf6e7f8e697739bbf442826082e3d348817691e406e", + "spentIndex": 2, + "spentHeight": 572220 + }, + { + "value": "0.00000546", + "n": 2, + "scriptPubKey": { + "hex": "76a914a8f9b1307fa412da6a909f08930e5a502d27a74a88ac", + "asm": "OP_DUP OP_HASH160 a8f9b1307fa412da6a909f08930e5a502d27a74a OP_EQUALVERIFY OP_CHECKSIG", + "addresses": [ + "1GQTe9EdBaF4fCTC2esvPNXewkUZoytADL" + ], + "type": "pubkeyhash", + "cashAddrs": [ + "bitcoincash:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fgmc5skpja" + ], + "slpAddrs": [ + "simpleledger:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fghrltrpvr" + ] + }, + "spentTxId": "0a730a25a758af6a28605bf6e7f8e697739bbf442826082e3d348817691e406e", + "spentIndex": 1, + "spentHeight": 572220 + }, + { + "value": "0.16010680", + "n": 3, + "scriptPubKey": { + "hex": "76a914a8f9b1307fa412da6a909f08930e5a502d27a74a88ac", + "asm": "OP_DUP OP_HASH160 a8f9b1307fa412da6a909f08930e5a502d27a74a OP_EQUALVERIFY OP_CHECKSIG", + "addresses": [ + "1GQTe9EdBaF4fCTC2esvPNXewkUZoytADL" + ], + "type": "pubkeyhash", + "cashAddrs": [ + "bitcoincash:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fgmc5skpja" + ], + "slpAddrs": [ + "simpleledger:qz50nvfs07jp9kn2jz0s3ycwtfgz6fa8fghrltrpvr" + ] + }, + "spentTxId": "0a730a25a758af6a28605bf6e7f8e697739bbf442826082e3d348817691e406e", + "spentIndex": 0, + "spentHeight": 572220 + } + ], + "blockhash": "000000000000000003600e20592475b15fafcfe1971859217fa67c6331af1144", + "blockheight": 571897, + "confirmations": 12176, + "time": 1551459665, + "blocktime": 1551459665, + "valueOut": 0.16011772, + "size": 924, + "valueIn": 0.16012732, + "fees": 0.0000096, + "tokenInfo": { + "versionType": 1, + "transactionType": "SEND", + "tokenIdHex": "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + "sendOutputs": [ + "0", + "100000000", + "1527093873600" + ] + }, + "tokenIsValid": true + } + +## Transactions + +SLP Transactions by tokenId and address + +**URL** : `v2/slp/transactions/:tokenId/:address` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. tokenId `string` **required** +2. address `string` **required** + +#### Result + +transactions `Array` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/slp/transactions/9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0/simpleledger:qrxa0unrn67rtn85v7asfddhhth43ecnxua0antk2l" -H "accept: */*" + + // returns + [ + { + "txid": "6f69a127738eab861b56e39137124ebcda84c82083879aea82dcd897643b8ee3", + "tokenDetails": { + "valid": true, + "detail": { + "decimals": 0, + "tokenIdHex": "9ba379fe8171176d4e7e6771d9a24cd0e044c7b788d5f86a3fdf80904832b2c0", + "transactionType": "MINT", + "versionType": 1, + "documentUri": "developer.bitcoin.com", + "documentSha256Hex": "1010101010101010101010101010101010101010101010101010101010101010", + "symbol": "GABRIEL", + "name": "SLP SDK Example", + "txnBatonVout": 2, + "txnContainsBaton": true, + "outputs": [ + { + "address": "simpleledger:qrxa0unrn67rtn85v7asfddhhth43ecnxua0antk2l", + "amount": "10" + } + ] + }, + "invalidReason": null, + "schema_version": 70 + } + } + ] + +## Burn Total + +input, output and burn total for slp transaction + +**URL** : `v2/slp/burnTotal/:transactionId` + +**Method** : `GET` + +**Auth required** : NO + +#### URL Parameters + +1. transactionId `string` **required** + +#### Result + +totals `BurnTotalResult` + +#### Examples + + curl -X GET "https://rest.bitcoin.com/v2/slp/burnTotal/c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de" -H "accept: */*" + + // returns + { + "transactionId": "c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de", + "inputTotal": 100000100, + "outputTotal": 100000000, + "burnTotal": 100 + } + ## Create TokenType1 Create an SLP token class of TokenType1. @@ -203,28 +751,28 @@ Note this endpoint is only live w/ a `NON_JS_FRAMEWORK` environment variable #### URL Parameters -1. fundingAddress `String` (required) -2. fundingWif `String` (required) -3. tokenReceiverAddress `String` (required) -4. batonReceiverAddress `String` (required) -5. bchChangeReceiverAddress `String` (required) -6. decimals `String` (required) -7. name `String` (required). This cannot have any spaces. It must be URL encoded -8. symbol `String` (required) -9. documentUri `String` (required) -10. documentHash `String` (required) -11. initialTokenQty `String` (required) +1. `fundingAddress`: `string`. **required** slp address format +2. `fundingWif`: `string`. **required** compressed WIF format. Available via `SLP.HDNode.toWIF` +3. `tokenReceiverAddress` : `string`. **required** slp address format +4. `batonReceiverAddress`: `string`. **required** slp address format. The address which has the baton has the ability to mint more tokens. +5. `bchChangeReceiverAddress` : `string.` **required** cash address format +6. `decimals`: `number`. **required** Number of decimal points for your token +7. `name` : `string`. **required** Name of token. This cannot have any spaces. It must be URL encoded +8. `symbol` : `string`. **required** Token symbol +9. `documentUri` : `string`. **required** URI of token document +10. `documentHash` : `string`. **required** Hash of token document +11. `initialTokenQty` : `number`. **required** Initial token quantity #### Result -txid `String` +txid `string` #### Examples - curl -X GET "http://localhost:3000/v2/slp/createTokenType1/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/cMsGTGBgS4qsbPNVbp8fwgTCN6YAgjxY6VQrixDxPRZ5x92F5oc4/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/0/Burner%20Coins%20Rule/BURN/documentUri/1010101010101010101010101010101010101010101010101010101010101010/100000000" -H "accept: */*" + curl -X GET "http://localhost:3000/v2/slp/createTokenType1/slptest:qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq03en9tn6/cUbRd4Ubjej127coVq73jJaAn395xLS3buxfQZWqCzt5zDX5ko6a/slptest:qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq03en9tn6/slptest:qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq03en9tn6/bchtest:qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq597glup8/0/Burner%20Coins%20Rule/BURN/documentUri/1010101010101010101010101010101010101010101010101010101010101010/100000000" -H "accept: */*" // returns - 946e43c71ff8917687793897d3c4e8b96a12a4f83575dfb45cedd870a0a90c69 + 46572fd617d7f73985061f40539d2852a7cf71f0ee720d194f6a9e838cf39dd4 ## Mint TokenType1 @@ -240,24 +788,24 @@ Note this endpoint is only live w/ a `NON_JS_FRAMEWORK` environment variable #### URL Parameters -1. fundingAddress `String` (required) -2. fundingWif `String` (required) -3. tokenReceiverAddress `String` (required) -4. batonReceiverAddress `String` (required) -5. bchChangeReceiverAddress `String` (required) -6. tokenId `String` (required) -7. additionalTokenQty `String` (required) +1. `fundingAddress`: `string`. **required** slp address format +2. `fundingWif`: `string`. **required** compressed WIF format. Available via `SLP.HDNode.toWIF` +3. `tokenReceiverAddress` : `string`. **required** slp address format +4. `batonReceiverAddress`: `string`. **required** slp address format. The address which has the baton has the ability to mint more tokens. +5. `bchChangeReceiverAddress` : `String.` **required** cash address format +6. `tokenId`: `string`. **required** tokenId of token to mint more of +7. `additionalTokenQty`: `number`. **required** Number of additional tokens to mint #### Result -txid `String` +txid `string` #### Examples - curl -X GET "http://localhost:3000/v2/slp/mintTokenType1/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/cMsGTGBgS4qsbPNVbp8fwgTCN6YAgjxY6VQrixDxPRZ5x92F5oc4/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/946e43c71ff8917687793897d3c4e8b96a12a4f83575dfb45cedd870a0a90c69/123" -H "accept: */*" + curl -X GET "http://localhost:3000/v2/slp/mintTokenType1/qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq03en9tn6/cUbRd4Ubjej127coVq73jJaAn395xLS3buxfQZWqCzt5zDX5ko6a/qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq03en9tn6/qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq03en9tn6/bchtest:qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq597glup8/46572fd617d7f73985061f40539d2852a7cf71f0ee720d194f6a9e838cf39dd4/123" -H "accept: */*" // returns - 5dc4ca831acd571963d767e296d84b92effd57c757aab8e39ed3bb59cb2b2e94 + cc32021e0d5124ee57f409fb4d6e982d37d1bb25ab1a5a9c3901dce403f9eb7f ## Send TokenType1 @@ -273,23 +821,23 @@ Note this endpoint is only live w/ a `NON_JS_FRAMEWORK` environment variable #### URL Parameters -1. fundingAddress `String` (required) -2. fundingWif `String` (required) -3. tokenReceiverAddress `String` (required) -4. bchChangeReceiverAddress `String` (required) -5. tokenId `String` (required) -6. amount`String` (required) +1. `fundingAddress`: `string`. **required** slp address format +2. `fundingWif`: `string`. **required** compressed WIF format. Available via `SLP.HDNode.toWIF` +3. `tokenReceiverAddress` : `string` . **required** slp address format +4. `bchChangeReceiverAddress`: `string` **required** cash address format +5. `tokenId`: `string`. **required** tokenId of token to send +6. `amount`: `number`. **required** Number of tokens to send #### Result -txid `String` +txid `string` #### Examples - curl -X GET "http://localhost:3000/v2/slp/sendTokenType1/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/cMsGTGBgS4qsbPNVbp8fwgTCN6YAgjxY6VQrixDxPRZ5x92F5oc4/bchtest:qza06mmt6zxfgq2yv6jxaq3juffhzvmv9cxayyqlfp/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/946e43c71ff8917687793897d3c4e8b96a12a4f83575dfb45cedd870a0a90c69/123" -H "accept: */*" + curl -X GET "http://localhost:3000/v2/slp/sendTokenType1/qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq03en9tn6/cUbRd4Ubjej127coVq73jJaAn395xLS3buxfQZWqCzt5zDX5ko6a/slptest:qry4ku0t2u7xypl9fqh3f2javgh5797lc5d9ftlw7h/bchtest:qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq597glup8/46572fd617d7f73985061f40539d2852a7cf71f0ee720d194f6a9e838cf39dd4/1" -H "accept: */*" // returns - b76daf1f2627f253aecc09a19eafe8422d79e6b59b2536493e1025e92a4d75dd + b428b862615b99b7529c90d4f53417a74a523288ed3015cc5251bac3818de358 ## Burn TokenType1 @@ -305,49 +853,98 @@ Note this endpoint is only live w/ a `NON_JS_FRAMEWORK` environment variable #### URL Parameters -1. fundingAddress `String` (required) -2. fundingWif `String` (required) -3. bchChangeReceiverAddress `String` (required) -4. tokenId `String` (required) -5. amount`String` (required) +1. `fundingAddress`: `string`. **required** slp address format +2. `fundingWif`: `string`. **required** compressed WIF format. Available via `SLP.HDNode.toWIF` +3. `bchChangeReceiverAddress` : `String.` **required** cash address format +4. `tokenId`: `string`. **required** tokenId of token to burn all of +5. `amount`: `number`. **required** Amount of tokens to burn #### Result -txid `String` +txid `string` #### Examples - curl -X GET "http://localhost:3000/v2/slp/burnTokenType1/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/cMsGTGBgS4qsbPNVbp8fwgTCN6YAgjxY6VQrixDxPRZ5x92F5oc4/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/946e43c71ff8917687793897d3c4e8b96a12a4f83575dfb45cedd870a0a90c69/123" -H "accept: */*" + curl -X GET "http://localhost:3000/v2/slp/burnTokenType1/qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq03en9tn6/cUbRd4Ubjej127coVq73jJaAn395xLS3buxfQZWqCzt5zDX5ko6a/bchtest:qq5a73af60j6u6nhfwnyyq8ejc2cf3g2uq597glup8/46572fd617d7f73985061f40539d2852a7cf71f0ee720d194f6a9e838cf39dd4/10" -H "accept: */*" // returns - 902b139b201940a5b726d4ef636a3b2225a64220fb150a6f5bde697180b6c758 + 78098f87a37bd783577e703a7885d409a2600573435e8157d7887bf608c96a1c -## Burn All TokenType1 +## Interfaces -Burn all tokens by tokenId. +### ValidateTxidResult -**URL** : `v2/slp/burnAllTokenType1/:fundingAddress/:fundingWif/:bchChangeReceiverAddress/:tokenId",` + { + txid: string + valid: boolean + invalidReason?: string + } -**Method** : `GET` +### TokenInterface -**Auth required** : NO + { + decimals: number + timestamp: string + timestampUnix: number + versionType: number + documentUri: string + symbol: string + name: string + containsBaton: boolean + id: string + documentHash: null | string + initialTokenQty: number + blockCreated: number + blockLastActiveSend: number + blockLastActiveMint: null | number + txnsSinceGenesis: number + validAddresses: number + totalMinted: number + totalBurned: number + circulatingSupply: number + mintingBatonStatus: string + } -Note this endpoint is only live w/ a `NON_JS_FRAMEWORK` environment variable +### BalancesForAddress -#### URL Parameters + { + tokenId: string + balance: number + balanceString: string + slpAddress: string + decimalCount: number + } -1. fundingAddress `String` (required) -2. fundingWif `String` (required) -3. bchChangeReceiverAddress `String` (required) -4. tokenId `String` (required) +### BalancesForToken -#### Result + { + tokenBalance: number + tokenBalanceString: string + slpAddress: string + tokenId: string + } -txid `String` +### BalanceForAddressByTokenId -#### Examples + { + tokenId: string + balance: number + balanceString: string + } - curl -X GET "http://localhost:3000/v2/slp/burnAllTokenType1/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/cMsGTGBgS4qsbPNVbp8fwgTCN6YAgjxY6VQrixDxPRZ5x92F5oc4/bchtest:qqm2nq9cv9gw66zn5xa0udpxnysknm2x4c95yw59pd/946e43c71ff8917687793897d3c4e8b96a12a4f83575dfb45cedd870a0a90c69" -H "accept: */*" +### ConvertResult - // returns - 7e9ff2924355f890ac45151dbb9aca0802d2b84fd478cc35ad62474d12a93b6b + { + slpAddress: string + cashAddress: string + legacyAddress: string + } + +### BurnTotalResult + + { + transactionId: string + inputTotal: number + outputTotal: number + burnTotal: number + } diff --git a/src/data/docs/rest/transaction.md b/src/data/docs/rest/transaction.md index 02e62445..6442c0f4 100644 --- a/src/data/docs/rest/transaction.md +++ b/src/data/docs/rest/transaction.md @@ -1,7 +1,7 @@ --- title: Transaction icon: exchange -ordinal: 10 +ordinal: 9 --- ## Transaction details single @@ -16,7 +16,7 @@ Details about a transaction #### URL Parameters -1. txid `String` required +1. txid `string` required #### Result diff --git a/src/data/docs/rest/util.md b/src/data/docs/rest/util.md index a11d1da4..55d6e4d9 100644 --- a/src/data/docs/rest/util.md +++ b/src/data/docs/rest/util.md @@ -1,7 +1,7 @@ --- title: Util icon: cogs -ordinal: 11 +ordinal: 10 --- ## Validate Address Single @@ -16,7 +16,7 @@ Return information about single bitcoin cash address. #### URL Parameters -1. address `String` required +1. address `string` required #### Result diff --git a/src/data/docs/slp/android/getting-started.md b/src/data/docs/slp/android/getting-started.md new file mode 100644 index 00000000..36b21bf2 --- /dev/null +++ b/src/data/docs/slp/android/getting-started.md @@ -0,0 +1,220 @@ +--- +title: Android +icon: android +ordinal: 7 +--- + +### Github repo + +[slp-wallet-sdk-android](https://github.com/Bitcoin-com/slp-wallet-sdk-android) + +### Supported Android Versions + +5.0+ + +#### Warning + +On Android versions prior to Android 6.0 Marshmallow, disabling the secure lock screen (reconfiguring it to None, Swipe, or another mode which does not authenicate the user) will have the following conquences: + +- Loss of the BCH and tokens held at the wallet address. +- Loss of access to the private key that controls the BCH and tokens held at the wallet address. + +Tokens and any extra BCH at the wallet address can only be recovered if the mnemonic has been previously backed up. + +### Installation + +#### Gradle + +Add JitPack to the list of repositories in your top level `build.gradle` file for the project: + +```groovy +allprojects { + repositories { + google() + jcenter() + maven { url 'https://jitpack.io' } // Add this repository + } +} +``` + +In the module 'build.gradle' file, add the dependency: + +```groovy +dependencies { + // ... + + implementation 'com.github.Bitcoin-com:slp-wallet-sdk-android:0.4' + implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' + +} +``` + +Excluding guava is required to avoid conflicts. + +##### Binary compatibility + +In the current version of the SDK, some items need to be removed for binary compatibility. + +Add these packaging options to your module `build.gradle`. + +```groovy +android { + // ... + + packagingOptions { + exclude 'lib/x86_64/darwin/libscrypt.dylib' + exclude 'lib/x86_64/freebsd/libscrypt.so' + exclude 'lib/x86_64/linux/libscrypt.so' + } +} +``` + +### Get Started + +```kotlin +import com.bitcoin.slpwallet.SLPWallet + +// Create a new wallet on mainnet, or load one previously created. +val slpWallet: SLPWallet = SLPWallet.loadOrCreate(context, Network.MAIN) + +val slpWalletFromPhrase: SLPWallet = SLPWallet.fromMnemonic( + context, + Network.MAIN + "rare genre crumble sport burger laugh lecture reject exhaust hello express pass" + ) + +// A wallet is created on mainnet if one does not exist already. +val slpWallet: SLPWallet = SLPWallet.getInstance(context) +``` + +### Addresses + Mnemonic + +The wallet resuses two addresses that shares mnemonic. + +- The SLP address on m/44'/245'/0'/0/0. +- The BCH address on m/44'/145'/0'/0/0. + +All BCH change will be sent to the BCH address while all token change is sent to the SLP address, separating the two if they were not already. This helps protect against accidental spending of BCH that contains SLP, by wallets are not aware of SLP, which would result in loss of coins. + +```kotlin +slpWallet.mnemonic // "rare", "genre", "crumble", "sport", "burger", "laugh", "lecture", "reject", "exhaust", "hello", "express", "pass" +slpWallet.slpAddress // simpleledger:qr6wa5eemn0fl3vghvk5cr480s3fqtgnevkaxny9x7 +slpWallet.bchAddress // bitcoincash:qr6wa5eemn0fl3vghvk5cr480s3fqtgnev6xdg39cq + +``` + +#### Token and BCH Balances + +The balances, including both tokens and BCH, are available as LiveData. + +```kotlin +slpWallet.balance.observe(this, Observer { balanceList: List -> + var balances = "" + for (balance in balanceList) { + val nf = getTokenNumberFormat(balance.decimals, balance.ticker) + balances += "${nf.format(balance.amount)}\n" + } + balancesText.text = balances +}) +``` + +The BCH balance item has an emtpy `tokenId` of `""`. + +```kotlin +interface BalanceInfo { + var tokenId: String + var amount: BigDecimal + var ticker: String? + var name: String? + var decimals: Int? +} +``` + +To refresh the current balance: + +```kotlin +slpWallet.refreshBalance() +``` + +### Send Token + +```kotlin +private val compositeDisposable = CompositeDisposable() + +// ... + +val tokenId = "73bf34eb6cd6879fc75b0e91ad82ef61a6bf2f10adb38a067a25b30f9a644cea" +val amount = BigDecimal(1) +val toAddress = "simpleledger:qpfp0tfafxfq52mdpperlyschmmh6scfgse80v7a4p" + +slpWallet.sendToken(tokenId, amount, toAddress) + .subscribeOn(Schedulers.io()) + .subscribe( + { txid: String -> + Timber.d("sendToken() was successful, with txid: $txid") + }, + { e: Throwable -> + Timber.e("Error when sending. $e") + } + ).addTo(compositeDisposable) +``` + +The example above uses Rx, but the status of the send task is also available as LiveData: + +```kotlin +slpWallet.sendStatus.observe(this, Observer { task: ProgressTask -> + var sendStatus = "" + when (task.status) { + TaskStatus.IDLE -> { + sendStatus = "" + } + TaskStatus.UNDERWAY -> { + sendStatus = "Sending..." + } + TaskStatus.SUCCESS -> { + sendStatus = "Sent tx ${task.result}" + } + TaskStatus.ERROR -> { + sendStatus = "Error. ${task.message}" + } + } + sendStatusText.text = sendStatus +}) +``` + +Once a send has been completed, you can reset the status to `IDLE`: + +```kotlin +slpWallet.clearSendStatus() +``` + +### UI + +Some convenience methods are included to make it easier to display tokens in your UI. + +#### Formatting Amounts + +This will display the amount to the full number of decimal places permitted by the coin, preceded by the ticker. + +```kotlin +import com.bitcoin.slpwallet.getTokenNumberFormat + +val nf: NumberFormat = getTokenNumberFormat(decimals, ticker) +val text: String = nf.format(amount) // "AAR 123.45" +``` + +### Logging + +This library uses [Timber](https://github.com/JakeWharton/timber) for logging, but does not plant it's own tree. Plant a tree like this when your application starts to see the logs: + +```kotlin +override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + if (BuildConfig.DEBUG) { + Timber.plant(Timber.DebugTree()) + } + + // ... +} +``` diff --git a/src/data/docs/slp/ios/getting-started.md b/src/data/docs/slp/ios/getting-started.md new file mode 100644 index 00000000..03ba0e7d --- /dev/null +++ b/src/data/docs/slp/ios/getting-started.md @@ -0,0 +1,196 @@ +--- +title: iOS +icon: ios +ordinal: 8 +--- + +### Github repo + +[slp-wallet-sdk-ios](https://github.com/Bitcoin-com/slp-wallet-sdk-ios) + +### Installation + +#### CocoaPods + +##### Podfile + +```ruby +# Add our BitcoinKit fork that handles SLP address +source 'https://github.com/Bitcoin-com/CocoaPods.git' +source 'https://github.com/CocoaPods/Specs.git' + +platform :ios, '10.0' + +target 'SLPWalletTestApp' do +use_frameworks! + +# Pods for SLPWalletTestApp +pod 'SLPWallet' + +end +``` + +##### Commands + +```bash +$ brew install autoconf automake // Required with BitcoinKit +$ brew install libtool // Required with BitcoinKit +$ pod install +``` + +##### Pod install issue + +```bash +sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/ +``` + +#### Configuration + +SLPWallet uses the Keychain to safely store the mnemonic seed phrase on your device. However, you need to create an entitlement file to allow the access to the Keychain. You can have a look at the sample project anytime you need to check the configuration [here.](./Sample/SLPWalletDemo/) + +Under the hood, the SDK is using [KeychainAccess](https://github.com/kishikawakatsumi/KeychainAccess). + +```xml + + + + + keychain-access-groups + + $(AppIdentifierPrefix)your.bundle.id + + + +``` + +### Get Started + +#### Setup URL + API Key (Not required :warning:, nice to have :dash:) + +The SDK uses https://rest.bitcoin.com which by default is limited to up to 60 calls per minute per IP address. If you would like to increase your REST calls limit rate, please contact [Bitcoin.com's team](https://developer.bitcoin.com/rest/) to obtain an API key. You may configure the SDK to work with an API key or with your own REST API, as shown below: + +Add your setup to your `AppDelegate.swift` as follows: + +1. Add the following import statement: + +```Swift +Import SLPWallet +``` + +2. Setup in the `application(_:didFinishLaunchingWithOptions:)` + +```Swift +// Optional setup +SLPWalletConfig.setRestAPIKey("MY_API_KEY") // Optional +SLPWalletConfig.setRestURL("https://rest.bitcoin.com") // By default => https://rest.bitcoin.com +``` + +#### Creating new wallet with/without mnemonic + +The wallet works with only 2 addresses, using: + +- the SLP recommended path 44'/245'/0' + m/0/0 (handling tokens - bch with token + token change address) +- the BCH recommended path 44'/145'/0' + m/0/0 (handling gas - bch without token + bch change address) + +However, both paths are scanned to get any bch or tokens available. + +```swift +// Init 1 +// Generate/Restore a wallet + Save/Get in Keychain +// If mnemonic in Keychain +// Restore wallet +// else +// Generate mnemonic +let wallet = try SLPWallet(.testnet) // .mainnet or .testnet + +// Init 2 +// Restore a wallet from Mnemonic + Save in Keychain +let wallet = try SLPWallet("My Mnemonic", network: .testnet) // .mainnet or .testnet + +// Init 3 +// Generate a wallet +// If force == true +// Generate everytime a new wallet +// else +// => Init 1 +let wallet = try SLPWallet(.testnet, force: Bool) // .mainnet or .testnet +``` + +#### Addresses + tokens + +```swift +wallet.mnemonic // [String] +wallet.slpAddress // String +wallet.cashAddress // String +wallet.tokens // [String:SLPToken] Tokens are accessible after an initial fetch or if you have started the scheduler +``` + +#### Fetch my tokens + +```swift +wallet + .fetchTokens() // RxSwift => Single<[String:Token]> + .subscribe(onSuccess: { tokens in + // My tokens + tokens.forEach({ tokenId, token in + token.tokenId + token.tokenName + token.tokenTicker + token.decimal + token.getBalance() + token.getGas() + }) + }, onError: { error in + // ... + }) +``` + +#### Send token + +```swift +wallet + .sendToken(tokenId, amount: amount, toAddress: toAddress) // toAddress can be a slp / cash address or legacy + .subscribe(onSuccess: { txid in // RxSwift => Single + // ... + }, onError: { error in + // ... + }) +``` + +#### Auto update wallet/tokens (balances + gas) + +```swift +// Start & Stop +wallet.scheduler.resume() +wallet.scheduler.suspend() + +// Change the interval +wallet.schedulerInterval = 10 // in seconds (30 by default) +``` + +#### WalletDelegate called when : + +- scheduler is started + token balance changed + +```swift +class MyViewController: SLPWalletDelegate { + + + override func viewDidLoad() { + super.viewDidLoad() + + let wallet = ... // Setup a wallet + wallet.delegate = self + } + + func onUpdatedToken(_ token: SLPToken) { + // My updated token + token.tokenId + token.tokenName + token.tokenTicker + token.decimal + token.getBalance() + token.getGas() + } +} +``` diff --git a/src/data/docs/slp/address.md b/src/data/docs/slp/js/address.md similarity index 93% rename from src/data/docs/slp/address.md rename to src/data/docs/slp/js/address.md index 66cc5644..86b44038 100644 --- a/src/data/docs/slp/address.md +++ b/src/data/docs/slp/js/address.md @@ -10,11 +10,11 @@ Converting cashaddr or slpaddr to legacy address format #### Arguments -1. address `String` cashaddr or slpaddr address to be converted +1. address `string` cashaddr or slpaddr address to be converted #### Result -legacyAddress `String` legacy base 58 check encoded address +legacyAddress `string` legacy base 58 check encoded address #### Examples @@ -56,13 +56,13 @@ Converting legacy or slpaddr to cashAddress format #### Arguments -1. address `String` required: legacy or cashaddr address to be converted -2. prefix `Boolean` optional: include prefix -3. regtest `Boolean` optional: return regtest address +1. address `string` required: legacy or cashaddr address to be converted +2. prefix `boolean` optional: include prefix +3. regtest `boolean` optional: return regtest address #### Result -cashAddress `String` cashAddr encoded address +cashAddress `string` cashAddr encoded address #### Examples @@ -104,13 +104,13 @@ Converting legacy or cashaddr to slpAddress format #### Arguments -1. address `String` required: legacy or cashaddr address to be converted -2. prefix `Boolean` optional: include prefix -3. regtest `Boolean` optional: return regtest address +1. address `string` required: legacy or cashaddr address to be converted +2. prefix `boolean` optional: include prefix +3. regtest `boolean` optional: return regtest address #### Result -slpAddress `String` slpAddr encoded address +slpAddress `string` slpAddr encoded address #### Examples @@ -152,11 +152,11 @@ Detect if slpAddr encoded address #### Arguments -1. address `String`: address to determine +1. address `string`: address to determine #### Result -isSLPAddress `Boolean`: true/false if slpaddress +isSLPAddress `boolean`: true/false if slpaddress #### Examples @@ -190,11 +190,11 @@ Detect if mainnet address #### Arguments -1. address `String`: address to determine +1. address `string`: address to determine #### Result -isMainnetAddress `Boolean`: true/false if mainnet address +isMainnetAddress `boolean`: true/false if mainnet address #### Examples @@ -244,11 +244,11 @@ Detect if testnet address #### Arguments -1. addresss `String`: address to determine +1. addresss `string`: address to determine #### Result -isTestnetAddresss `Boolean`: true/false if is testnet address +isTestnetAddresss `boolean`: true/false if is testnet address #### Examples @@ -298,11 +298,11 @@ Detect if p2pkh address #### Arguments -1. address `String` address to determine +1. address `string` address to determine #### Result -isP2PKHAddress `Boolean` true/false if is p2pkh address +isP2PKHAddress `boolean` true/false if is p2pkh address #### Examples @@ -352,11 +352,11 @@ Detect if p2sh address #### arguments -1. address `String` address to determine +1. address `string` address to determine #### Result -isP2SHAddress `Boolean` true/false if is p2sh address +isP2SHAddress `boolean` true/false if is p2sh address #### Examples @@ -406,11 +406,11 @@ Detect address format #### arguments -1. address `String` address to determine format +1. address `string` address to determine format #### Result -addressFormat `String` address format +addressFormat `string` address format #### Examples @@ -460,11 +460,11 @@ Detect address network #### arguments -1. address `String` address to determine network +1. address `string` address to determine network #### Result -addressNetwork `String` address network +addressNetwork `string` address network #### Examples @@ -514,11 +514,11 @@ Detect address network #### arguments -1. address `String` address to determine network +1. address `string` address to determine network #### Result -addressNetwork `String` address network +addressNetwork `string` address network #### Examples @@ -569,7 +569,7 @@ Return details about an address including balance. #### Arguments - addresses (required): - - `String`: A single string containing a legacy, cash or slp address. + - `string`: A single string containing a legacy, cash or slp address. - `Array` of strings: Array with maximum of 20 legacy, cash or slp addresses. #### Result @@ -623,7 +623,7 @@ Return list of uxto for address #### Arguments - addresses (required): - - `String`: A single string containing a legacy, cash or slp address. + - `string`: A single string containing a legacy, cash or slp address. - `Array` of strings: Array with maximum of 20 legacy, cash or slp addresses. #### Result @@ -675,7 +675,7 @@ Return list of unconfirmed transactions for address #### Arguments - addresses (required): - - `String`: A single string containing a legacy, cash or slp address. + - `string`: A single string containing a legacy, cash or slp address. - `Array` of strings: Array with maximum of 20 legacy, cash or slp addresses. #### Result @@ -720,7 +720,7 @@ Returns decoded transactions for an address #### Arguments - addresses (required): - - `String`: A single string containing a legacy, cash or slp address. + - `string`: A single string containing a legacy, cash or slp address. - `Array` of strings: Array with maximum of 20 legacy, cash or slp addresses. #### Result diff --git a/src/data/docs/slp/console.md b/src/data/docs/slp/js/console.md similarity index 100% rename from src/data/docs/slp/console.md rename to src/data/docs/slp/js/console.md diff --git a/src/data/docs/slp/js/ecpair.md b/src/data/docs/slp/js/ecpair.md new file mode 100644 index 00000000..9b8f404f --- /dev/null +++ b/src/data/docs/slp/js/ecpair.md @@ -0,0 +1,25 @@ +--- +title: ECPair +icon: key +ordinal: 4 +--- + +### `toSLPAddress` + +Get slp address of ECPair + +#### Arguments + +1. ecpair: `ECPair` + +#### Result + +slpAddress `string`: slpaddr encoded address of ECPair + +#### Examples + + // create ecpair from wif + let ecpair = SLP.ECPair.fromWIF('cUCSrdhu7mCzx4sWqL6irqzprkofxPmLHYgkSnG2WaWVqJDXtWRS') + // to slp address + SLP.ECPair.toSLPAddress(ecpair); + // slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03 diff --git a/src/data/docs/slp/getting-started.md b/src/data/docs/slp/js/getting-started.md similarity index 90% rename from src/data/docs/slp/getting-started.md rename to src/data/docs/slp/js/getting-started.md index 6989a80d..252fc0a8 100644 --- a/src/data/docs/slp/getting-started.md +++ b/src/data/docs/slp/js/getting-started.md @@ -16,11 +16,11 @@ Use the official installer from [nodejs.org](https://nodejs.org/). Install the o To use commands like `new` and `console`: - npm install sdk-sdk --global + npm install slp-sdk --global To use inside a command line script or client/server app: - npm install sdk-sdk --save + npm install slp-sdk --save ### Usage diff --git a/src/data/docs/slp/js/hdnode.md b/src/data/docs/slp/js/hdnode.md new file mode 100644 index 00000000..8e83bd18 --- /dev/null +++ b/src/data/docs/slp/js/hdnode.md @@ -0,0 +1,626 @@ +--- +title: HDNode +icon: code-branch +ordinal: 5 +--- + +HDNode stands for Hierarchically Deterministic node which can be used to create a [HD wallet](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#hierarchical-deterministic-wallets-bip0032bip0044). + +### `fromSeed` + +Create HDNode from Seed Buffer. + +#### Arguments + +1. rootSeed `Buffer`: root seed buffer +2. network `string` **optional**: network. default: 'mainnet' + +#### Result + +HDNode HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + SLP.HDNode.fromSeed(seedBuffer); + + // generate entropy + let entropy = SLP.Crypto.randomBytes(32); + // create mnemonic from entropy + let mnemonic = SLP.Mnemonic.fromEntropy(entropy); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + SLP.HDNode.fromSeed(seedBuffer); + +### `derive` + +Derive [non hardened](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#hardened-child-key-derivation) child HDNode + +#### Arguments + +1. num `number`: number of child node. Ex: 0 + +#### Result + +HDNode HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // derive unhardened child HDNode + SLP.HDNode.derive(hdNode, 0); + +### `deriveHardened` + +Derive [hardened](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#hardened-child-key-derivation) child HDNode + +#### Arguments + +1. num `number`: number of child node. Ex: 0 + +#### Result + +HDNode HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // derive hardened child HDNode + SLP.HDNode.deriveHardened(hdNode, 0); + +### `derivePath` + +Derive child HDNode from path + +#### Arguments + +1. path `string`: path of child hd node. Ex: "m/44'/145'/0'" + +#### Result + +HDNode HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // derive hardened child HDNode + SLP.HDNode.derivePath(hdNode, "m/44'/145'/0'"); + +### `toLegacyAddress` + +Get legacy address of HDNode + +#### Arguments + +1. hdNode: HDNode + +#### Result + +legacyAddress `string`: legacy base58check encoded address of HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to legacy address + SLP.HDNode.toLegacyAddress(hdNode); + // 14apxtw2LDQmXWsS5k4JEhG93Jzjswhvma + + // generate entropy + let entropy = SLP.Crypto.randomBytes(32); + // create mnemonic from entropy + let mnemonic = SLP.Mnemonic.fromEntropy(entropy); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to cash address + SLP.HDNode.toLegacyAddress(hdNode); + // 14mVsq3H5Ep2Jb6AqoKsmY1BFHKCBGPDLi + +### `toCashAddress` + +Get cash address of HDNode + +#### Arguments + +1. hdNode: HDNode +2. regtest `boolean` optional: return regtest address + +#### Result + +cashAddress `string`: cashaddr encoded address of HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to cash address + SLP.HDNode.toCashAddress(hdNode); + // bitcoincash:qqrz6kqw6nvhwgwrt4g7fggepvewtkr7nukkeqf4rw + + // generate entropy + let entropy = SLP.Crypto.randomBytes(32); + // create mnemonic from entropy + let mnemonic = SLP.Mnemonic.fromEntropy(entropy); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to cash address + SLP.HDNode.toCashAddress(hdNode); + // bitcoincash:qq549jxsjv66kw0smdju4es2axnk7hhe9cquhjg4gt + +### `toSLPAddress` + +Get slp address of HDNode + +#### Arguments + +1. hdNode: HDNode + +#### Result + +slpAddress `string`: slpaddr encoded address of HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to cash address + SLP.HDNode.toSLPAddress(hdNode); + // simpleledger:qpst7ganm0ucmj3yl7jxvdqrm7tg3zhveg89xjh25d + + // generate entropy + let entropy = SLP.Crypto.randomBytes(32); + // create mnemonic from entropy + let mnemonic = SLP.Mnemonic.fromEntropy(entropy); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to cash address + SLP.HDNode.toSLPAddress(hdNode); + // simpleledger:qqxh2z2z397m4c6u9s5x6wjtku742q8rpvm6al2nrf + +### `toWIF` + +Get private key in wallet import format (WIF) of HDNode + +#### Arguments + +1. hdNode: HDNode + +#### Result + +privateKeyWIF `string`: private key in wallet import format (WIF) of HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to WIF + SLP.HDNode.toWIF(hdNode); + // L5E8QjFnLukp8BuF4uu9gmvvSrbafioURGdBve5tA3Eq5ptzbMCJ + + // generate entropy + let entropy = SLP.Crypto.randomBytes(32); + // create mnemonic from entropy + let mnemonic = SLP.Mnemonic.fromEntropy(entropy); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to WIF + SLP.HDNode.toWIF(hdNode); + // KwobPFhv3AuXc3ps6YtWfMVRpLBDBA7jnJddurfELTyTNcFhZYpJ + +### `toXPub` + +Get [extended](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#extended-keys) [public key](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#public-key-cryptography-and-cryptocurrency) of HDNode + +#### Arguments + +1. hdNode: HDNode + +#### Result + +xpub `string`: extended public key of HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to extended public key + SLP.HDNode.toXPub(hdNode); + // xpub661MyMwAqRbcG4CnhNYoK1r1TKLwQQ1UdC3LHoWFK61rsnzh7Hx35qQ9Z53ucYcE5WvA7GEDXhqqKjSY2e6Y8n7WNVLYHpXCuuX945VPuYn + + // generate entropy + let entropy = SLP.Crypto.randomBytes(32); + // create mnemonic from entropy + let mnemonic = SLP.Mnemonic.fromEntropy(entropy); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to extended public key + SLP.HDNode.toXPub(hdNode); + // xpub661MyMwAqRbcFuMLeHkSbTNwNHG9MQyrAZqV1Q4MEAsmj9MYa5sxg8WC2LKqW6EHviHVucBjWi1n38juZpDDeX3U6YrsMeACdcNSTHkM8BQ + +### `toXPriv` + +Get [extended](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#extended-keys) [private key](https://developer.bitcoin.com/mastering-bitcoin-cash/3-keys-addresses-wallets/#private-keys) of HDNode + +#### Arguments + +1. hdNode: HDNode + +#### Result + +xpriv `string`: extended private key of HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to extended private key + SLP.HDNode.toXPriv(hdNode); + // xprv9s21ZrQH143K2eMCcbT4qwwRhw6qZaPaEDWB792bnrxQZPoP2JUk4kfEx9eeV1uGTAWAfCqYr4wDWo52qALiukizKwQzvEyNR1fWZJi97Kv + + // generate entropy + let entropy = SLP.Crypto.randomBytes(32); + // create mnemonic from entropy + let mnemonic = SLP.Mnemonic.fromEntropy(entropy); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // to extended private key + SLP.HDNode.toXPriv(hdNode); + // xprv9s21ZrQH143K2b5GPP6zHz22E6LeCgQXJtwNbC3MA3Kz7Se7tveKo96EhqwFtSkYWkyenVcMqM7uq35PcUNG8cUdpsJEgwKG3dvfP7TmL3v + +### `toKeyPair` + +Get the ECPair of an HDNode + +#### Arguments + +1. hdNode: HDNode + +#### Result + +keyPair `ECPair`: ECPair of an HDNode + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create root seed buffer from mnemonic + let rootSeed= SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from root seed + let hdNode = SLP.HDNode.fromSeed(rootSeed); + // create public key buffer from HDNode + SLP.HDNode.toKeyPair(hdNode); + + // generate entropy + let entropy = SLP.Crypto.randomBytes(32); + // create mnemonic from entropy + let mnemonic = SLP.Mnemonic.fromEntropy(entropy); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // create public key buffer from HDNode + SLP.HDNode.toKeyPair(hdNode); + // + +### `toPublicKey` + +Get the public key of an HDNode as a buffer + +#### Arguments + +1. hdNode: HDNode + +#### Result + +publicKeyBuffer `Buffer`: public key of HDNode as a buffer + +#### Examples + + // create mnemonic + let mnemonic = SLP.Mnemonic.generate(128); + // create root seed buffer from mnemonic + let rootSeed= SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from root seed + let hdNode = SLP.HDNode.fromSeed(rootSeed); + // create public key buffer from HDNode + SLP.HDNode.toPublicKey(hdNode); + // + + // generate entropy + let entropy = SLP.Crypto.randomBytes(32); + // create mnemonic from entropy + let mnemonic = SLP.Mnemonic.fromEntropy(entropy); + // create seed buffer from mnemonic + let seedBuffer = SLP.Mnemonic.toSeed(mnemonic); + // create HDNode from seed buffer + let hdNode = SLP.HDNode.fromSeed(seedBuffer); + // create public key buffer from HDNode + SLP.HDNode.toPublicKey(hdNode); + // + +### `toIdentifier` + +hash160 of Node’s public key. The same value you would see in a scriptPubKey. + +#### Arguments + +1. hdnode `HDNode` + +#### Result + +identifier `string` + +#### Examples + + // mainnet + let xpub = 'xpub6DWfGUo4cjC8oWmgZdpyFMH6v3oeyADfdUPhsehzn5jX44zpazivha3JxUtkcCvBEB1c6DGaiUmpyz2m1DRfGDEVZ5VxLLW2UNEbZ5iTRvi'; + let node = SLP.HDNode.fromXPub(xpub); + SLP.HDNode.toIdentifier(node); + // + // the same as if we hash160ed it's publicKey + let publicKeyBuffer = SLP.HDNode.toPublicKey(node); + SLP.Crypto.hash160(publicKeyBuffer); + // + + // testnet + let xpub = 'tpubDCxmZ3qLVVphg6NpsnAjQFqDPwr9HYqSgoAcUYAfqSgo32dL6NA8QXqWsS6XTjoGggohZKvujsAv2F2ugej9qfUYau2jSUB4JaYnfMsx3MJ'; + let node = SLP.HDNode.fromXPub(xpub); + SLP.HDNode.toIdentifier(node); + // + // the same as if we hash160ed it's publicKey + let publicKeyBuffer = SLP.HDNode.toPublicKey(node); + SLP.Crypto.hash160(publicKeyBuffer); + // + +### `fromXPriv` + +Generate HDNode from extended private key + +#### Arguments + +1. xpriv: extended private key + +#### Result + +hdNode `HDNode` + +#### Examples + + // mainnet xpriv + SLP.HDNode.fromXPriv('xprv9s21ZrQH143K2b5GPP6zHz22E6LeCgQXJtwNbC3MA3Kz7Se7tveKo96EhqwFtSkYWkyenVcMqM7uq35PcUNG8cUdpsJEgwKG3dvfP7TmL3v'); + + // testnet xpriv + SLP.HDNode.fromXPriv('tprv8gQ3zr1F5pRHMebqqhorrorYNvUG3XkcZjSWVs2cEtRwwJy1TRhgRx4XcF8dYHM2eyTbTCcdKYNhqgyBQphxwRoVyVKr9zuyoA8WxNDRvom'); + +### `fromXPub` + +Generate HDNode from extended public key + +#### Arguments + +1. xpub: extended public key + +#### Result + +hdNode `HDNode` + +#### Examples + + // mainnet xpub + SLP.HDNode.fromXPub('xpub661MyMwAqRbcFuMLeHkSbTNwNHG9MQyrAZqV1Q4MEAsmj9MYa5sxg8WC2LKqW6EHviHVucBjWi1n38juZpDDeX3U6YrsMeACdcNSTHkM8BQ'); + + // testnet xpub + SLP.HDNode.fromXPub('tpubDD669G3VEC6xF7ddjMUTGDWewwzCCrwX933HnP4ufAELmoDn5pXGcSgPnLodjFvWQwRXkG94f77BatEDA8dfQ99yy97kRYynUpNLENEqTBo'); + +### `isPublic` + +Check if an HDNode can only derive public keys and children + +#### Arguments + +1. hdnode `HDNode` + +#### Result + +isPublic `boolean` + +#### Examples + + // mainnet xpub + let xpub = 'xpub6DWfGUo4cjC8oWmgZdpyFMH6v3oeyADfdUPhsehzn5jX44zpazivha3JxUtkcCvBEB1c6DGaiUmpyz2m1DRfGDEVZ5VxLLW2UNEbZ5iTRvi'; + let node = SLP.HDNode.fromXPub(xpub); + SLP.HDNode.isPublic(node); + // true + + // mainnet xpriv + let xpriv = 'xprv9ys4cvcoU8RoxqkZ7Fgt33te4LPHgcsKwyoZYVorkzp9uonWxWgP9wiSQhPeBUqVHbdAyov4Yi55RywBkDfZKdJFRqA51Anz6v72zGaMGZp'; + let node = SLP.HDNode.fromXPriv(xpriv); + SLP.HDNode.isPublic(node); + // false + + // testnet xpub + let xpub = 'tpubDCxmZ3qLVVphg6NpsnAjQFqDPwr9HYqSgoAcUYAfqSgo32dL6NA8QXqWsS6XTjoGggohZKvujsAv2F2ugej9qfUYau2jSUB4JaYnfMsx3MJ'; + let node = SLP.HDNode.fromXPub(xpub); + SLP.HDNode.isPublic(node); + // true + + // testnet xpriv + let xpriv = 'tprv8ggxJ8SG5EdqakzVUeLa9Gr7sqCdEcJPUNDmtdJscNxfmxoXvU36ZguiUWukJVEWEixAUr8pJabJkCt33wzxFQA587gqN51Lxdxx97zAzuG'; + let node = SLP.HDNode.fromXPriv(xpriv); + SLP.HDNode.isPublic(node); + // false + +### `isPrivate` + +Check if an HDNode can derive both public and private keys and children + +#### Arguments + +1. hdnode `HDNode` + +#### Result + +isPrivate `boolean` + +#### Examples + + // mainnet xpub + let xpub = 'xpub6DWfGUo4cjC8oWmgZdpyFMH6v3oeyADfdUPhsehzn5jX44zpazivha3JxUtkcCvBEB1c6DGaiUmpyz2m1DRfGDEVZ5VxLLW2UNEbZ5iTRvi'; + let node = SLP.HDNode.fromXPub(xpub); + SLP.HDNode.isPrivate(node); + // false + + // mainnet xpriv + let xpriv = 'xprv9ys4cvcoU8RoxqkZ7Fgt33te4LPHgcsKwyoZYVorkzp9uonWxWgP9wiSQhPeBUqVHbdAyov4Yi55RywBkDfZKdJFRqA51Anz6v72zGaMGZp'; + let node = SLP.HDNode.fromXPriv(xpriv); + SLP.HDNode.isPrivate(node); + // true + + // testnet xpub + let xpub = 'tpubDCxmZ3qLVVphg6NpsnAjQFqDPwr9HYqSgoAcUYAfqSgo32dL6NA8QXqWsS6XTjoGggohZKvujsAv2F2ugej9qfUYau2jSUB4JaYnfMsx3MJ'; + let node = SLP.HDNode.fromXPub(xpub); + SLP.HDNode.isPrivate(node); + // false + + // testnet xpriv + let xpriv = 'tprv8ggxJ8SG5EdqakzVUeLa9Gr7sqCdEcJPUNDmtdJscNxfmxoXvU36ZguiUWukJVEWEixAUr8pJabJkCt33wzxFQA587gqN51Lxdxx97zAzuG'; + let node = SLP.HDNode.fromXPriv(xpriv); + SLP.HDNode.isPrivate(node); + // true + +### `sign` + +Sign 32 byte hash encoded as a buffer + +#### Arguments + +1. hdnode `HDNode` +2. buffer `Buffer` + +#### Result + +signature `Object` + +#### Examples + + // mainnet xpriv + let xpriv = 'xprv9z2uWrGjbYPxc728rvtMi4jt4SudRiSfYn6Tdif5XN17pJ1NTbHoHK6JePkPLY1NHXLaQcA6sWudpZDm7DwKhbsGQieAp9wx46Wbio4iXg9'; + // hdnode from xpriv + let hdnode = SLP.HDNode.fromXPriv(xpriv); + // 32 byte buffer + let buf = Buffer.from(SLP.Crypto.sha256('EARTH'), 'hex'); + // sign + SLP.HDNode.sign(hdnode, buf); + + // testnet xpriv + let xpriv = 'tprv8ggxJ8SG5EdqakzVUeLa9Gr7sqCdEcJPUNDmtdJscNxfmxoXvU36ZguiUWukJVEWEixAUr8pJabJkCt33wzxFQA587gqN51Lxdxx97zAzuG'; + // hdnode from xpriv + let hdnode = SLP.HDNode.fromXPriv(xpriv); + // 32 byte buffer + let buf = Buffer.from(SLP.Crypto.sha256('EARTH'), 'hex'); + // sign + SLP.HDNode.sign(hdnode, buf); + +### `verify` + +Verify signed 32 byte hash encoded as a buffer + +#### Arguments + +1. hdnode `HDNode` +2. buffer `Buffer` +3. signature `Object` + +#### Result + +verified `boolean` + +#### Examples + + // mainnet xprivs + let xpriv1 = 'xprv9ys4cvcoU8RoqvzxGj886r4Ey3w1WfVNYH8sMnVPVzyQtaPPM6Q8pHm3D9WPWvEupGEgcJ1xLaGaZDcvKfoAurE2AzHRRRup5FuHzDr8n15'; + let xpriv2 = 'xprv9ys4cvcoU8RoxqkZ7Fgt33te4LPHgcsKwyoZYVorkzp9uonWxWgP9wiSQhPeBUqVHbdAyov4Yi55RywBkDfZKdJFRqA51Anz6v72zGaMGZp'; + // hdnodes from xprivs + let hdnode1 = SLP.HDNode.fromXPriv(xpriv1); + let hdnode2 = SLP.HDNode.fromXPriv(xpriv2); + // 32 byte buffer + let buf = Buffer.from(SLP.Crypto.sha256('EARTH'), 'hex'); + // sign + let signature = SLP.HDNode.sign(hdnode1, buf); + // verify + SLP.HDNode.verify(hdnode1, buf, signature); + // true + SLP.HDNode.verify(hdnode2, buf, signature); + // false + + // testnet xprivs + let xpriv1 = 'tprv8ggxJ8SG5EdqakzVUeLa9Gr7sqCdEcJPUNDmtdJscNxfmxoXvU36ZguiUWukJVEWEixAUr8pJabJkCt33wzxFQA587gqN51Lxdxx97zAzuG'; + let xpriv2 = 'tprv8ggxJ8SG5EdqiM6Dn63QwHScQ7HS5hXqUMxSD1NEbDyPw6VtoUMFZBAohpTMsPz9cYbpHELmA4Zm79NKRvEvFdhWRX2bSmu7V7PiNb364nv'; + // hdnodes from xprivs + let hdnode1 = SLP.HDNode.fromXPriv(xpriv1); + let hdnode2 = SLP.HDNode.fromXPriv(xpriv2); + // 32 byte buffer + let buf = Buffer.from(SLP.Crypto.sha256('EARTH'), 'hex'); + // sign + let signature = SLP.ECPair.sign(hdnode1, buf); + // verify + SLP.HDNode.verify(hdnode1, buf, signature); + // true + SLP.HDNode.verify(hdnode2, buf, signature); + // false diff --git a/src/data/docs/slp/new.md b/src/data/docs/slp/js/new.md similarity index 100% rename from src/data/docs/slp/new.md rename to src/data/docs/slp/js/new.md diff --git a/src/data/docs/slp/slp.md b/src/data/docs/slp/js/slp.md similarity index 84% rename from src/data/docs/slp/slp.md rename to src/data/docs/slp/js/slp.md index bb04b5d2..06e5cc3b 100644 --- a/src/data/docs/slp/slp.md +++ b/src/data/docs/slp/js/slp.md @@ -1,7 +1,7 @@ --- title: SLP icon: elipses -ordinal: 4 +ordinal: 6 --- ### `Constructor` @@ -14,7 +14,7 @@ Create an instance of SLP SDK ##### Valid config properties -- `restURL`: `String`. By default SLP SDK will connect to https://rest.bitcoin.com/v2/ +- `restURL`: `string`. By default SLP SDK will connect to https://rest.bitcoin.com/v2/ #### Result diff --git a/src/data/docs/slp/js/slpdb.md b/src/data/docs/slp/js/slpdb.md new file mode 100644 index 00000000..0d2dc4fa --- /dev/null +++ b/src/data/docs/slp/js/slpdb.md @@ -0,0 +1,85 @@ +--- +title: SLPDB +icon: coins +ordinal: 7 +--- + +### `get` + +Get SLPDB data by `query` + +#### Arguments + +1. query `any`: SLPDB Query + +#### Result + +result `any`: SLPDB Result + +#### Examples + +```javascript +;(async () => { + let SLPSDK = require('slp-sdk') + let SLP = new SLPSDK() + let res = await SLP.SLPDB.get({ + v: 3, + q: { + db: ['t'], + find: {}, + limit: 10, + }, + }) + console.log(res) + + // returns + // { t: + // [ [Object], + // [Object], + // [Object], + // [Object], + // [Object], + // [Object], + // [Object], + // [Object], + // [Object], + // [Object] ] } + + console.log(res.t[0]) + + // returns + // + // { _id: '5d43635f4760895f2a312f71', + // schema_version: 71, + // lastUpdatedBlock: 593917, + // tokenDetails: + // { decimals: 0, + // tokenIdHex: + // 'c586b4339dfe5f4c3b508a0c6db2531c64ff091065dc47c885291cad6aefbd45', + // timestamp: '2019-08-01 21:23:58', + // timestamp_unix: 1564694638, + // transactionType: 'GENESIS', + // versionType: 129, + // documentUri: '', + // documentSha256Hex: null, + // symbol: '', + // name: '', + // batonVout: null, + // containsBaton: false, + // genesisOrMintQuantity: '1', + // sendOutputs: null }, + // mintBatonUtxo: '', + // tokenStats: + // { block_created: 593918, + // block_last_active_send: null, + // block_last_active_mint: null, + // qty_valid_txns_since_genesis: 1, + // qty_valid_token_utxos: 0, + // qty_valid_token_addresses: 0, + // qty_token_minted: '1', + // qty_token_burned: '1', + // qty_token_circulating_supply: '0', + // qty_satoshis_locked_up: 0, + // minting_baton_status: 'NEVER_CREATED' } } +})() +``` diff --git a/src/data/docs/slp/js/socket.md b/src/data/docs/slp/js/socket.md new file mode 100644 index 00000000..eea5dddf --- /dev/null +++ b/src/data/docs/slp/js/socket.md @@ -0,0 +1,83 @@ +--- +title: Socket +icon: plug +ordinal: 8 +--- + +### `constructor` + +Create new Socket. + +#### Arguments + +1. config `Object`: with properties: + 1. wsURL `string`: optional, Defaults to `wss://ws.bitcoin.com` + 2. slpsocketURL `string`: optional + 3. restURL `string`: optional + 4. callback `Function`: optional + +#### Result + +Socket `Socket` + +#### Examples + + // instance of Socket + let socket = new SLP.Socket({callback: () => {console.log('connected')}, wsURL: 'wss://ws.bitcoin.com'}) + +### `listen` + +Listen on a websocket to get real\-time data. + +#### Arguments + +1. query `string | object`: type of data to return in real time. `transactions` or `blocks` are valid `string`s. Any SLPSocket `query` object is also valid +2. callback `function`: function to be called which gets passed back `message` in real time. + +#### Result + +data `Object`: data returned in real\-time over a websocket + +#### Examples + + let socket = new SLP.Socket({ + callback: () => { + console.log("connected") + }, + wsURL: "wss://ws.bitcoin.com" + }) + socket.listen( + { + v: 3, + q: { find: {} } + }, + msg => { + setTimeout(function() { + socket.close(() => { + console.log("closed") + }) + }, 5000) + } + ) + // returns + // {"type":"mempool","data":[{"_id":"5d49a5d1a5f7f174062c77d4","tx":{"h":"65c7fdb83416f7e5265a7c8f7bc91c4ff61846500f93eb6de4826f4383a32fea"},"in":[{"i":0,"b0":"MEQCIEd1aDojWA4Mn0+Ohe8u/xAIZLI3YSoCftPiL6nAYqvbAiAgJr0E1SDirrv1x3WVPfhxHES2pmw7BUv2Ce3Tt3mnKEE=","b1":"A4B14wuKtzl6/4UZZBlcV9JqpfAn2WTRXJj24FMdK0se","str":"304402204775683a23580e0c9f4f8e85ef2eff100864b237612a027ed3e22fa9c062abdb02202026bd04d520e2aebbf5c775953df8711c44b6a66c3b054bf609edd3b779a72841 038075e30b8ab7397aff851964195c57d26aa5f027d964d15c98f6e0531d2b4b1e","e":{"h":"2e18c90a40f82dc415f87709a8bfed549b068dfab0deec4d032d3d1b7d9178a8","i":2,"s":"RzBEAiBHdWg6I1gODJ9PjoXvLv8QCGSyN2EqAn7T4i+pwGKr2wIgICa9BNUg4q679cd1lT34cRxEtqZsOwVL9gnt07d5pyhBIQOAdeMLirc5ev+FGWQZXFfSaqXwJ9lk0VyY9uBTHStLHg==","a":"simpleledger:qzht6wanjrxqjp6qyla6t856mfhgktg3wcphvqpm6m"},"h0":"304402204775683a23580e0c9f4f8e85ef2eff100864b237612a027ed3e22fa9c062abdb02202026bd04d520e2aebbf5c775953df8711c44b6a66c3b054bf609edd3b779a72841","h1":"038075e30b8ab7397aff851964195c57d26aa5f027d964d15c98f6e0531d2b4b1e"},{"i":1,"b0":"MEQCIEI6fm5yuoLxhO8jSfHO4o3bsIDxA57hxnM47glyM7MCAiAod189/A11KbYunWRI60tSsdsrWRVgtD0zBFOsnk6GjEE=","b1":"ArKlVkqejzomjw/dFV0xhhbKwZkw2tEemC8+zbT+MZrt","str":"30440220423a7e6e72ba82f184ef2349f1cee28ddbb080f1039ee1c67338ee097233b302022028775f3dfc0d7529b62e9d6448eb4b52b1db2b591560b43d330453ac9e4e868c41 02b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed","e":{"h":"2e18c90a40f82dc415f87709a8bfed549b068dfab0deec4d032d3d1b7d9178a8","i":3,"s":"RzBEAiBCOn5ucrqC8YTvI0nxzuKN27CA8QOe4cZzOO4JcjOzAgIgKHdfPfwNdSm2Lp1kSOtLUrHbK1kVYLQ9MwRTrJ5OhoxBIQKypVZKno86Jo8P3RVdMYYWysGZMNrRHpgvPs20/jGa7Q==","a":"simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk"},"h0":"30440220423a7e6e72ba82f184ef2349f1cee28ddbb080f1039ee1c67338ee097233b302022028775f3dfc0d7529b62e9d6448eb4b52b1db2b591560b43d330453ac9e4e868c41","h1":"02b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed"}],"out":[{"i":0,"b0":{"op":106},"b1":"U0xQAA==","s1":"SLP\u0000","b2":"AQ==","s2":"\u0001","b3":"U0VORA==","s3":"SEND","b4":"A6rK4niocisDz7t1z4yivBgQ8J0X6Oa0hNpRNgpiA+Y=","s4":"\u0003���x�r+\u0003ϻuό��\u0018\u0010�\u0017�洄�Q6\nb\u0003�","b5":"AAAAAAAAA+g=","s5":"\u0000\u0000\u0000\u0000\u0000\u0000\u0003�","b6":"AAAAAAAPLrg=","s6":"\u0000\u0000\u0000\u0000\u0000\u000f.�","str":"OP_RETURN 534c5000 01 53454e44 03aacae278a8722b03cfbb75cf8ca2bc1810f09d17e8e6b484da51360a6203e6 00000000000003e8 00000000000f2eb8","e":{"v":0,"i":0,"s":"agRTTFAAAQEEU0VORCADqsrieKhyKwPPu3XPjKK8GBDwnRfo5rSE2lE2CmID5ggAAAAAAAAD6AgAAAAAAA8uuA=="},"h1":"534c5000","h2":"01","h3":"53454e44","h4":"03aacae278a8722b03cfbb75cf8ca2bc1810f09d17e8e6b484da51360a6203e6","h5":"00000000000003e8","h6":"00000000000f2eb8"},{"i":1,"b0":{"op":118},"b1":{"op":169},"b2":"BggP97JkHTbRBHn6zPUTLGcF5+w=","s2":"\u0006\b\u000f��d\u001d6�\u0004y���\u0013,g\u0005��","b3":{"op":136},"b4":{"op":172},"str":"OP_DUP OP_HASH160 06080ff7b2641d36d10479faccf5132c6705e7ec OP_EQUALVERIFY OP_CHECKSIG","e":{"v":546,"i":1,"s":"dqkUBggP97JkHTbRBHn6zPUTLGcF5+yIrA==","a":"simpleledger:qqrqsrlhkfjp6dk3q3ul4n84zvkxwp08as29vh52n0"},"h2":"06080ff7b2641d36d10479faccf5132c6705e7ec"},{"i":2,"b0":{"op":118},"b1":{"op":169},"b2":"rr07s5DMCQdAJ/ulnprabostEXY=","s2":"��;���\t\u0007@'�����n�-\u0011v","b3":{"op":136},"b4":{"op":172},"str":"OP_DUP OP_HASH160 aebd3bb390cc09074027fba59e9ada6e8b2d1176 OP_EQUALVERIFY OP_CHECKSIG","e":{"v":546,"i":2,"s":"dqkUrr07s5DMCQdAJ/ulnprabostEXaIrA==","a":"simpleledger:qzht6wanjrxqjp6qyla6t856mfhgktg3wcphvqpm6m"},"h2":"aebd3bb390cc09074027fba59e9ada6e8b2d1176"},{"i":3,"b0":{"op":118},"b1":{"op":169},"b2":"6dQvuLkMwbjc9pgoC7OgZs4Ih28=","s2":"��/��\f�����(\u000b��f�\b�o","b3":{"op":136},"b4":{"op":172},"str":"OP_DUP OP_HASH160 e9d42fb8b90cc1b8dcf698280bb3a066ce08876f OP_EQUALVERIFY OP_CHECKSIG","e":{"v":3995752,"i":3,"s":"dqkU6dQvuLkMwbjc9pgoC7OgZs4Ih2+IrA==","a":"simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk"},"h2":"e9d42fb8b90cc1b8dcf698280bb3a066ce08876f"}],"slp":{"valid":true,"detail":{"decimals":3,"tokenIdHex":"03aacae278a8722b03cfbb75cf8ca2bc1810f09d17e8e6b484da51360a6203e6","transactionType":"SEND","versionType":1,"documentUri":"gemstone.cash","documentSha256Hex":null,"symbol":"GEM","name":"gemstone","txnBatonVout":null,"txnContainsBaton":false,"outputs":[{"address":"simpleledger:qqrqsrlhkfjp6dk3q3ul4n84zvkxwp08as29vh52n0","amount":"1"},{"address":"simpleledger:qzht6wanjrxqjp6qyla6t856mfhgktg3wcphvqpm6m","amount":"995"}]},"invalidReason":null,"schema_version":71}}]} + // closed + +### `close` + +Close websocket connection + +#### Arguments + +1. callback `function` (optional): function to be called. + +#### Examples + + let socket = new bitbox.Socket({callback: () => {console.log('connected')}, wsURL: 'wss://ws.bitcoin.com'}) + socket.listen('transactions', (message) => { + socket.close(() => { + console.log("closed") + }) + }) + // returns the following + // closed diff --git a/src/data/docs/slp/js/tokentype1.md b/src/data/docs/slp/js/tokentype1.md new file mode 100644 index 00000000..c35342d6 --- /dev/null +++ b/src/data/docs/slp/js/tokentype1.md @@ -0,0 +1,311 @@ +--- +title: TokenType1 +icon: circle +ordinal: 9 +--- + +### `create` + +Create a new SLP Token of Type 1 + +#### Arguments + +1. createConfig `Object` required + +##### Valid config properties + +- `fundingAddress`: `string`. **required** slp address format +- `fundingWif`: `string`. **required** compressed WIF format. Available via `SLP.HDNode.toWIF` +- `tokenReceiverAddress` : `string`. **required** slp address format +- `bchChangeReceiverAddress` : `String.` **required** cash address format +- `batonReceiverAddress`: `string`. **optional** slp address format. The address which has the baton has the ability to mint more tokens. +- `decimals`: `number`. **required** Number of decimal points for your token +- `name` : `string`. **required** Name of token +- `symbol` : `string`. **required** Token symbol +- `documentUri` : `string`. **required** URI of token document +- `documentHash` : `string`. **required** Hash of token document +- `initialTokenQty` : `number`. **required** Initial token quantity + +#### Result + +tokenId `string`. The tokenId of your newly created token. This tokenId is the txid of the genesis tx. You will use this tokenId as your token's unique identifier and to mint future tokens + +#### Examples + + (async function() { + try { + let token = await SLP.TokenType1.create({ + fundingAddress: "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + fundingWif: "cUCSrdhu7mCzx4sWqL6irqzprkofxPmLHYgkSnG2WaWVqJDXtWRS", + tokenReceiverAddress: + "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + bchChangeReceiverAddress: + "bchtest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcmf0pnpav", + batonReceiverAddress: + "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + decimals: 2, + name: "Test SLP SDK Token", + symbol: "GABRIEL", + documentUri: "badger@bitcoin.com", + documentHash: null, + initialTokenQty: 1000 + }); + console.log(token); + } catch (err) { + console.log("ERROR: ", err); + } + })(); + + // returns + // a3787d6b170707c59920486e9e03ea99f589fe4939454d36053d84dfc7388384 + +### `mint` + +Mint additional tokens of Type 1 + +#### Arguments + +1. mintConfig `Object` required + +##### Valid config properties + +- `fundingAddress`: `string`. **required** slp address format +- `fundingWif`: `string`. **required** compressed WIF format. Available via `SLP.HDNode.toWIF` +- `tokenReceiverAddress` : `string`. **required** slp address format +- `bchChangeReceiverAddress` : `String.` **required** cash address format +- `batonReceiverAddress`: `string`. **optional** slp address format. The address which has the baton has the ability to mint more tokens. +- `tokenId`: `string`. **required** tokenId of token to mint more of +- `additionalTokenQty`: `number`. **required** Number of additional tokens to mint + +#### Result + +mintId `string`. The txid of the newly minted tokens + +#### Examples + + (async function() { + try { + let mint = await SLP.TokenType1.mint({ + fundingAddress: "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + fundingWif: "cUCSrdhu7mCzx4sWqL6irqzprkofxPmLHYgkSnG2WaWVqJDXtWRS", + tokenReceiverAddress: + "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + batonReceiverAddress: + "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + bchChangeReceiverAddress: + "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + tokenId: + "a3787d6b170707c59920486e9e03ea99f589fe4939454d36053d84dfc7388384", + additionalTokenQty: 507 + }); + console.log(mint); + } catch (err) { + console.log("ERROR: ", err); + } + })(); + + // returns + 9d1595b34c488df7f26d39b5081e97c9939f4d8698ddbd86e5bbd3a54f95e96e + +### `send` + +Send tokens of Type 1. one-to-one, one-to-many, many-to-many and many-to-one token transactions supported + +#### Arguments + +1. sendConfig `Object` required + +##### Valid config properties + +- `fundingAddress`: `string`. **required** slp address format +- `fundingWif`: `string`. **required** compressed WIF format. Available via `SLP.HDNode.toWIF` +- `tokenReceiverAddress` : `string` or `Array`. **required** slp address format +- `bchChangeReceiverAddress` : `string` or `Array`. **required** cash address format +- `tokenId`: `string`. **required** tokenId of token to send +- `amount`: `number`. **required** Number of tokens to send + +#### Result + +sendId `string`. The txid of your sent tokens + +#### Examples + + // one-to-one + (async function() { + try { + let send = await SLP.TokenType1.send({ + fundingAddress: "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + fundingWif: "cUCSrdhu7mCzx4sWqL6irqzprkofxPmLHYgkSnG2WaWVqJDXtWRS", + tokenReceiverAddress: + "slptest:qrj9k49drcsk4al8wxn53hnkfvts6ew5jvv32952nh", + bchChangeReceiverAddress: + "bchtest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcmf0pnpav", + tokenId: + "a3787d6b170707c59920486e9e03ea99f589fe4939454d36053d84dfc7388384", + amount: 1.01 + }); + console.log(send); + } catch (err) { + console.log("ERROR: ", err); + } + })(); + // returns + 251eb8a71184251453eb373c8912c8afd67e6820de5679de91b930689e776be1 + + // one-to-many + (async function() { + try { + let send = await SLP.TokenType1.send({ + fundingAddress: "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + fundingWif: "cUCSrdhu7mCzx4sWqL6irqzprkofxPmLHYgkSnG2WaWVqJDXtWRS", + tokenReceiverAddress: [ + "slptest:qrj9k49drcsk4al8wxn53hnkfvts6ew5jvv32952nh", + "slptest:qz7wjkg7s8e5khq2c6xeu6pcw28q4c0egglpawvw89", + "slptest:qqwcgz4gl0sddcau57lygvycx7hgf2fjaylpalknp4", + "slptest:qqvpqwvr9jpnhu0zq79th0fhtws9nhp5pyxnjjj2zx", + "slptest:qrgcu3c2aqzp535s7cek5tdjgkpvh38dmg5h75q2c9", + "slptest:qr0jjjjfatzg46adpa325grwdx39zfhdpgkxq2ejq9", + "slptest:qppcj6hynmzx8nu0ewh7an454d3wt3ama5k7vua2nk", + "slptest:qza6x2fef3jaxrr6vtkjkjsd8xcmwzaufqq66eur44", + "slptest:qz9x0t4s5gzwtlgyx3avkq33ec2ph3g5tg0zws77qm", + "slptest:qz4yf0k0z76wlmm4glvzrph2kld4h8y40ymn3wpaza", + "slptest:qzxs4uqmjfrygkv0499ej0rvnqd6cj7y9yfsdwnnpk", + "slptest:qqj98r7t8jalmepfc27776zvzdfwvxwhu58fsvqa7r", + "slptest:qqrca59a98nxvq6zlqmzquerj5n68ntd3s5ac0elqg", + "slptest:qpstysh49m30f2skd6hhjpr8wgp7jtxvqg27ww56up", + "slptest:qqlesvq4ntx5day4fpunqewvlf7pdr9k2g424uvxj8", + "slptest:qqez4680qx4rnpwm0xddwmd6v8dsr4x4rs9f2qmf8t", + "slptest:qrfgwsahle0dfn7pd78rc6x496zgv96525nkr3agyg" + ], + bchChangeReceiverAddress: + "bchtest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcmf0pnpav", + tokenId: + "a3787d6b170707c59920486e9e03ea99f589fe4939454d36053d84dfc7388384", + amount: [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ] + }); + console.log(send); + } catch (err) { + console.log("ERROR: ", err); + } + })(); + // returns + // 84a4b2a1ec002a769e5cf055a56f485a4652442b0bb8cae06f3ac4ee1ac6b49b + + // many-to-many + (async function() { + try { + let send = await SLP.TokenType1.send({ + fundingAddress: [ + "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + "slptest:qrj9k49drcsk4al8wxn53hnkfvts6ew5jvv32952nh" + ], + fundingWif: [ + "cUCSrdhu7mCzx4sWqL6irqzprkofxPmLHYgkSnG2WaWVqJDXtWRS", + "cNVP2nTzUMFerfpjrTuDgoFGnKAfjZznKomknUVKQSdFHqK5cRc5" + ], + tokenReceiverAddress: [ + "qp8u8lsax86msxmvy236az4q2aq26pe2ng5dfkjsx2", + "qqjdcjmqlenuas2qyj57n564s9rzushamcn9rg5ccl" + ], + bchChangeReceiverAddress: + "bchtest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcmf0pnpav", + tokenId: + "47f4a3ecf16001d062852ecffac8d23cc2fce6816ea856b2ddc3638bae85cf98", + amount: [1, 1] + }); + console.log(send); + } catch (err) { + console.log("ERROR: ", err); + } + })(); + // returns + // c4b5b4c3536121f01705010ec7e4112ba05a45e151cc98a3e0378cd921a9f85f + + // many-to-one + (async function() { + try { + let send = await SLP.TokenType1.send({ + fundingAddress: [ + "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + "slptest:qrj9k49drcsk4al8wxn53hnkfvts6ew5jvv32952nh" + ], + fundingWif: [ + "cUCSrdhu7mCzx4sWqL6irqzprkofxPmLHYgkSnG2WaWVqJDXtWRS", + "cNVP2nTzUMFerfpjrTuDgoFGnKAfjZznKomknUVKQSdFHqK5cRc5" + ], + tokenReceiverAddress: "qrrw0wkvyn4yrssprcqjrwthfz0e0edlmyj7gms7kj", + bchChangeReceiverAddress: + "bchtest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcmf0pnpav", + tokenId: + "47f4a3ecf16001d062852ecffac8d23cc2fce6816ea856b2ddc3638bae85cf98", + amount: 12 + }); + console.log(send); + } catch (err) { + console.log("ERROR: ", err); + } + })(); + // returns + // d42b5e375025e4eece6437a060b7cc274bdc8143ccca51c290f2e76758c47a53 + +### `burn` + +Burn an amount of tokens for an address by tokenId + +**CAUTION: THIS WILL BURN AN AMOUNT OF YOUR TOKENS FOR A TOKENID. PLEASE USE WITH CARE** + +#### Arguments + +1. burnConfig `Object` required + +##### Valid config properties + +- `fundingAddress`: `string`. **required** slp address format +- `fundingWif`: `string`. **required** compressed WIF format. Available via `SLP.HDNode.toWIF` +- `bchChangeReceiverAddress` : `String.` **required** cash address format +- `tokenId`: `string`. **required** tokenId of token to burn all of +- `amount`: `number`. **required** Amount of tokens to burn + +#### Result + +txid `string`. The txid of your burned tokens + +#### Examples + + (async function() { + try { + let burn = await SLP.TokenType1.burn({ + fundingAddress: "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03", + fundingWif: "cUCSrdhu7mCzx4sWqL6irqzprkofxPmLHYgkSnG2WaWVqJDXtWRS", + tokenId: + "a3787d6b170707c59920486e9e03ea99f589fe4939454d36053d84dfc7388384", + amount: 5.99, + bchChangeReceiverAddress: + "slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03" + }); + console.log(burn); + } catch (err) { + console.log("ERROR: ", err); + } + })(); + + // returns + 2c90f44dbb0a3257ded2c30d46d387490aee61eecd168534c8b645ffe21cbc50 diff --git a/src/data/docs/slp/js/util.md b/src/data/docs/slp/js/util.md new file mode 100644 index 00000000..0bdf006d --- /dev/null +++ b/src/data/docs/slp/js/util.md @@ -0,0 +1,841 @@ +--- +title: Util +icon: exchange +ordinal: 10 +--- + +### `list` + +List all tokens or list single token by id + +#### Arguments + +1. id : `string` or `string[]` **optional**. The token id(s) + +#### Result + +tokens : `Array` or `Object`. tokens or single token + +#### Examples + +##### List all tokens + + (async () => { + try { + let list = await SLP.Utils.list(); + console.log(list); + } catch (error) { + console.error(error); + } + })(); + + // returns + [ { decimals: 5, + timestamp: '2019-04-20 05:03', + versionType: 1, + documentUri: 'developer.bitcoin.com', + symbol: 'MYSTERY', + name: 'Mystery', + containsBaton: true, + id: + '10528f22fc20422f7c1075a87ed7270c0a17bc17ea79c6e2f426c6cc14bb25f2', + documentHash: + '1010101010101010101010101010101010101010101010101010101010101010', + initialTokenQty: 500, + blockCreated: 579041, + blockLastActiveSend: null, + blockLastActiveMint: null, + txnsSinceGenesis: 1, + validAddresses: 1, + totalMinted: 500, + totalBurned: 0, + circulatingSupply: 500, + mintingBatonStatus: 'ALIVE' }, + { decimals: 8, + timestamp: '2019-04-20 04:54', + versionType: 1, + documentUri: 'developer.bitcoin.com', + symbol: 'ENIGMA', + name: 'Enigma', + containsBaton: true, + id: + '113c55921fe29919ff84e53a6d5af39ed9d983a1c3b3000f27125688489935fa', + documentHash: + '1010101010101010101010101010101010101010101010101010101010101010', + initialTokenQty: 1234, + blockCreated: 579040, + blockLastActiveSend: null, + blockLastActiveMint: 579040, + txnsSinceGenesis: 2, + validAddresses: 2, + totalMinted: 1334, + totalBurned: 0, + circulatingSupply: 1334, + mintingBatonStatus: 'ALIVE' } + ] + +##### List single token + + (async () => { + try { + let list = await SLP.Utils.list( + "b3f4f132dc3b9c8c96316346993a8d54d729715147b7b11aa6c8cd909e955313" + ); + console.log(list); + } catch (error) { + console.error(error); + } + })(); + + // returns + { decimals: 8, + timestamp: '2019-04-20 04:54', + versionType: 1, + documentUri: 'developer.bitcoin.com', + symbol: 'ENIGMA', + name: 'Enigma', + containsBaton: true, + id: + '113c55921fe29919ff84e53a6d5af39ed9d983a1c3b3000f27125688489935fa', + documentHash: + '1010101010101010101010101010101010101010101010101010101010101010', + initialTokenQty: 1234, + blockCreated: 579040, + blockLastActiveSend: null, + blockLastActiveMint: 579040, + txnsSinceGenesis: 2, + validAddresses: 2, + totalMinted: 1334, + totalBurned: 0, + circulatingSupply: 1334, + mintingBatonStatus: 'ALIVE' } + +##### List multiple tokens by tokenIds + + (async () => { + try { + let list = await SLP.Utils.list([ + "fa6c74c52450fc164e17402a46645ce494a8a8e93b1383fa27460086931ef59f", + "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0" + ]); + console.log(list); + } catch (error) { + console.error(error); + } + })(); + + // returns + [ { decimals: 0, + timestamp: '2019-02-18 14:47', + versionType: 1, + documentUri: 'https://simpleledger.cash', + symbol: 'SLP', + name: 'Official SLP Token', + containsBaton: true, + id: + 'fa6c74c52450fc164e17402a46645ce494a8a8e93b1383fa27460086931ef59f', + documentHash: null, + initialTokenQty: 18446744073709552000, + blockCreated: 570305, + blockLastActiveSend: 580275, + blockLastActiveMint: 575914, + txnsSinceGenesis: 4537, + validAddresses: 164, + totalMinted: 19414628793626410000, + totalBurned: 18446568350267302000, + circulatingSupply: 968060443359109600, + mintingBatonStatus: 'ALIVE' }, + { decimals: 8, + timestamp: '2019-02-14 03:11', + versionType: 1, + documentUri: 'psfoundation.cash', + symbol: 'PSF', + name: 'Permissionless Software Foundation', + containsBaton: true, + id: + '38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0', + documentHash: null, + initialTokenQty: 19882.09163133, + blockCreated: 569658, + blockLastActiveSend: 580153, + blockLastActiveMint: null, + txnsSinceGenesis: 51, + validAddresses: 9, + totalMinted: 19882.09163133, + totalBurned: 0.0534241, + circulatingSupply: 19882.03820723, + mintingBatonStatus: 'ALIVE' } ] + +### `balancesForAddress` + +Return all balances for an address + +#### Arguments + +- address (required): + - `string`: A single string containing an slp address. + - `Array` of strings: Array with maximum of 20 slp addresses. + +#### Result + +- `Array`: containing balances Objects. +- `Array`: Array of arrays. + +#### Examples + + (async () => { + try { + let balances = await SLP.Utils.balancesForAddress('simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk'); + console.log(balances); + } catch (error) { + console.error(error); + } + })(); + + // returns + // [ { tokenId: + // '968ff0cc4c93864001e03e9524e351250b94ec56150fa4897f65b0b6477d44d4', + // balance: '9980', + // slpAddress: 'simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk', + // decimalCount: 9 }, + // { tokenId: + // 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', + // balance: '617', + // slpAddress: 'simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk', + // decimalCount: 8 }, + // { tokenId: + // 'b96304d12f1bbc2196df582516410e55a9b34e13c7b4585bf5c1770af30d034f', + // balance: '1', + // slpAddress: 'simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk', + // decimalCount: 0 }, + // { tokenId: + // 'a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37', + // balance: '776', + // slpAddress: 'simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk', + // decimalCount: 7 } ] + + // balances for Cash Address + (async () => { + try { + let balances = await SLP.Utils.balancesForAddress('bitcoincash:qr4zg7xth86yzq94gl8jvnf5z4wuupzt3g4hl47n9y'); + console.log(balances); + } catch (error) { + console.error(error); + } + })(); + + // returns + // [ { tokenId: + // '467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5', + // balance: '507', + // decimalCount: 2 } ] + + // balances for Legacy Address + (async () => { + try { + let balances = await SLP.Utils.balancesForAddress('1NM2ozrXVSnMRm66ua6aGeXgMsU7yqwqLS'); + console.log(balances); + } catch (error) { + console.error(error); + } + })(); + + // returns + // [ { tokenId: + // '467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5', + // balance: '507', + // decimalCount: 2 } ] + + + // multiple addresses + const addresses = [ + "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9", + "simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57" + ] + await SLP.Utils.balancesForAddress(addresses) + // returns + // [ + // [ + // { + // tokenId: + // "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + // balance: 1, + // balanceString: "1", + // slpAddress: "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9", + // decimalCount: 8 + // }, + // { + // tokenId: + // "a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37", + // balance: 1, + // balanceString: "1", + // slpAddress: "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9", + // decimalCount: 7 + // } + // ], + // [ + // { + // tokenId: + // "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", + // balance: 10, + // balanceString: "10", + // slpAddress: "simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57", + // decimalCount: 8 + // } + // ] + // ] + +### `balance` + +Return single balance for an address by token id + +#### Arguments + +1. address : `string` **required**. The address in legacy, cash or slp address format +2. id : `string` **required**. The token id + +#### Result + +balance : `Object`. the address's balance for single token + +#### Examples + + // single balance for SLP Address + (async () => { + try { + let balance = await SLP.Utils.balance( + "simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk", + "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" + ); + console.log(balance); + } catch (error) { + console.error(error); + } + })(); + + // returns + // { tokenId: + // 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', + // balance: '617', + // decimalCount: 8 } + + // single balance for Cash Address + (async () => { + try { + let balance = await SLP.Utils.balance( + "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg", + "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" + ); + console.log(balance); + } catch (error) { + console.error(error); + } + })(); + + // returns + // { tokenId: + // 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', + // balance: '617', + // decimalCount: 8 } + + // single balance for Legacy Address + (async () => { + try { + let balance = await SLP.Utils.balance( + "1DwQqpWc8pzaRydCmiJsPdoqCzmjSQQbp8", + "467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5" + ); + console.log(balance); + } catch (error) { + console.error(error); + } + })(); + + // returns + // { tokenId: + // '467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5', + // balance: '1234', + // decimalCount: 2 } + +### `validateTxid` + +Validate that txid is an SLP transaction + +#### Arguments + +1. txid : `string` or `Array` **required**. The transaction id(s) to validate + +#### Result + +validated : `Array` + +#### Examples + + // validate single SLP txid + (async () => { + try { + let validated = await SLP.Utils.validateTxid( + "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" + ); + console.log(validated); + } catch (error) { + console.error(error); + } + })(); + + // returns + [ { txid: + 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', + valid: true } ] + + // validate multiple SLP txids + (async () => { + try { + let validated = await SLP.Utils.validateTxid([ + "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + "00ea27261196a411776f81029c0ebe34362936b4a9847deb1f7a40a02b3a1476" + ]); + console.log(validated); + } catch (error) { + console.error(error); + } + })(); + + // returns + [ { txid: + 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', + valid: true }, + { txid: + '00ea27261196a411776f81029c0ebe34362936b4a9847deb1f7a40a02b3a1476', + valid: true } ] + +### `balancesForToken` + +List all balances for tokenId + +#### Arguments + +1. tokenId: `string` **required**. The tokenId + +#### Result + +balances: `Array` + +#### Examples + + (async () => { + try { + let balances = await SLP.Utils.balancesForToken( + "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" + ) + console.log(balances) + } catch (error) { + console.error(error) + } + })() + + // returns + [ + { + tokenId: "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + tokenBalance: 20, + slpAddress: 'simpleledger:qp4g0q97tq53pasnxk2rs570c6573qvylunsf5gy9e' + }, + { + tokenId: "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + tokenBalance: 335.55, + slpAddress: 'simpleledger:qqcraw7q0ys3kg4z6f2zd267fhg2093c5c0spfk03f' + } + ] + +### `tokenStats` + +Stats for token by tokenId + +#### Arguments + +1. tokenId: `string` **required**. The tokenId + +#### Result + +stats: `Object` + +#### Examples + + (async () => { + try { + let stats = await SLP.Utils.tokenStats( + "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" + ) + console.log(stats) + } catch (error) { + console.error(error) + } + })() + + // returns + { tokenId: + 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', + documentUri: '', + symbol: 'NAKAMOTO', + name: 'NAKAMOTO', + decimals: 8, + txnsSinceGenesis: 367, + validUtxos: 248, + validAddresses: 195, + circulatingSupply: 20995990, + totalBurned: 4010, + totalMinted: 21000000, + satoshisLockedUp: 135408 + } + +### `transactions` + +SLP Transactions by tokenId and address + +#### Arguments + +1. tokenId: `string` **required**. The tokenId +2. address: `string` **required**. The address + +#### Result + +transactions: `Array` + +#### Examples + + (async () => { + try { + let transactions = await SLP.Utils.transactions( + "495322b37d6b2eae81f045eda612b95870a0c2b6069c58f70cf8ef4e6a9fd43a", + "qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqlsy4gusz" + ) + console.log(transactions) + } catch (error) { + console.error(error) + } + })() + + // returns + [ + { + "txid": "27e27170b546f05b2af69d6eddff8834038facf5d81302e9e562df09a5c4445f", + "tokenDetails": { + "valid": true, + "detail": { + "decimals": null, + "tokenIdHex": "495322b37d6b2eae81f045eda612b95870a0c2b6069c58f70cf8ef4e6a9fd43a", + "timestamp": null, + "transactionType": "SEND", + "versionType": 1, + "documentUri": null, + "documentSha256Hex": null, + "symbol": null, + "name": null, + "batonVout": null, + "containsBaton": null, + "genesisOrMintQuantity": null, + "sendOutputs": [ + { + "$numberDecimal": "0" + }, + { + "$numberDecimal": "25" + }, + { + "$numberDecimal": "77" + } + ] + }, + "invalidReason": null, + "schema_version": 30 + } + } + ] + +### `decodeOpReturn` + +Get high-level SLP data on a transaction by decoding the OP_RETURN data. +Throws an error if the txid is not an SLP transaction. + +Note: It is convention in the SLP protocol to use the lowest denomination +of decimal in the calculations. e.g. Using integer `satoshis` for calculations +instead of floating point `bitcoins`. For this reason, the decimal information +for the token only exists in the Genesis transaction, and other transactions +display all token quantities as large integers. + +#### Arguments + +1. txid: `string` **required**. The txid of an SLP transaction + +#### Result + +slpData: `Object` + +#### Examples + + // A Genesis SLP transaction. + (async () => { + try { + const txid = + "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90" + + const slpData = await SLP.Utils.decodeOpReturn(txid) + console.log(slpData) + } catch (error) { + console.error(error) + } + })() + + // returns + { + "tokenType": 1, + "transactionType": "genesis", + "ticker": "SLPSDK", + "name": "SLP SDK example using BITBOX", + "documentUrl": "developer.bitcoin.com", + "documentHash": "", + "decimals": 8, + "mintBatonVout": 2, + "initialQty": 507, + "tokensSentTo": "bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05", + "batonHolder": "bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05" + } + + // A Mint SLP transaction. + (async () => { + try { + const txid = + "65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4" + + const slpData = await SLP.Utils.decodeOpReturn(txid) + console.log(slpData) + } catch (error) { + console.error(error) + } + })() + + // returns + { + "tokenType": 1, + "transactionType": "mint", + "tokenId": "023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4", + "mintBatonVout": 2, + "batonStillExists": true, + "quantity": "10000000000", + "tokensSentTo": "bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q", + "batonHolder": "bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q" + } + + // A Send SLP transaction. + (async () => { + try { + const txid = + "4f922565af664b6fdf0a1ba3924487344be721b3d8815c62cafc8a51e04a8afa" + + const slpData = await SLP.Utils.decodeOpReturn(txid) + console.log(slpData) + } catch (error) { + console.error(error) + } + })() + + // returns + { + "tokenType": 1, + "transactionType": "send", + "tokenId": "023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4", + "spendData": [ + { + "quantity": "300000000", + "sentTo": "bitcoincash:qzv7t2pzn2d0pklnetdjt65crh6fe8vnhuwvhsk2nn", + "vout": 1 + }, + { + "quantity": "60400000000", + "sentTo": "bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q", + "vout": 2 + } + ] + } + +### `isTokenUtxo` + +Given an array of UTXOs, this function returns an array of Boolean values +indicating if each UTXO belongs to an SLP transaction (true) or not (false). +If false, the UTXO is safe for a wallet to spend in a normal BCH transaction. + +#### Arguments + +1. utxos: `Array` of utxo objects **required**. + +#### Result + +- `Array` of Boolean values. + - `true`: The UTXO belongs to an SLP token. + - `false`: The UTXO does not belong to an SLP token. + +#### Examples + + (async () => { + try { + const u = await SLP.Address.utxo("bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05") + const utxos = u.utxos + + console.log(`utxos: ${JSON.stringify(utxos,null,2)}`) + + const isSLPUtxo: await SLP.Utils.isTokenUtxo(utxos) + console.log(`isSLPUtxo: ${JSON.stringify(canSpend,null,2}`) + } catch (error) { + console.error(error) + } + })() + + // returns + utxos: [ + { + txid: + "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + vout: 3, + amount: 0.00002015, + satoshis: 2015, + height: 594892, + confirmations: 5 + }, + { + txid: + "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + vout: 2, + amount: 0.00000546, + satoshis: 546, + height: 594892, + confirmations: 5 + } + ] + + isSLPUtxo: + [ + false, + true + ] + +### `tokenUtxoDetails` + +Hydrate a UTXO with SLP token metadata. + +Expects an array of UTXO objects as input. Returns an array of equal size. +If the UTXO does not belong to a SLP transaction, it will return false. +If the UTXO is part of an SLP transaction, it will return the UTXO object +with additional SLP information attached. + +#### Arguments + +1. utxos: `Array` of utxo objects **required**. + +#### Result + +- `Array` + - `false`: The UTXO does not belong to an SLP token and is safe to spend. + - `Object`: The same UTXO object hydrated with SLP token metadata. + +#### Examples + + (async () => { + try { + const u = await SLP.Address.utxo("bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05") + const utxos = u.utxos + + console.log(`utxos: ${JSON.stringify(utxos,null,2)}`) + + const isSLPUtxo: await SLP.Utils.tokenUtxoDetails(utxos) + console.log(`isSLPUtxo: ${JSON.stringify(canSpend,null,2}`) + } catch (error) { + console.error(error) + } + })() + + // returns + utxos: [ + { + txid: + "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + vout: 3, + amount: 0.00002015, + satoshis: 2015, + height: 594892, + confirmations: 5 + }, + { + txid: + "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + vout: 2, + amount: 0.00000546, + satoshis: 546, + height: 594892, + confirmations: 5 + } + ] + + isSLPUtxo: + [ + false, + { + "txid": "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + "vout": 2, + "amount": 0.00000546, + "satoshis": 546, + "height": 594892, + "confirmations": 5, + "tokenType": "minting-baton", + "tokenId": "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + "tokenTicker": "SLPSDK", + "tokenName": "SLP SDK example using BITBOX", + "tokenDocumentUrl": "developer.bitcoin.com", + "tokenDocumentHash": "", + "decimals": 8 + } + ] + +### `burnTotal` + +List input, output and burn total for slp transaction + +#### Arguments + +1. transactionId: `string` **required** + +#### Result + +burnTotal `BurnTotalResult` + +#### Examples + + (async () => { + try { + const burnTotal = await SLP.Utils.burnTotal( + "c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de" + ) + console.log(burnTotal) + } catch (error) { + console.error(error) + } + })() + + // returns + { + transactionId: 'c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de', + inputTotal: 100000100, + outputTotal: 100000000, + burnTotal: 100 + } + +## Interfaces + +### BurnTotalResult + + { + transactionId: string + inputTotal: number + outputTota": number + burnTotal: number + } diff --git a/src/data/docs/slp/tokentype1.md b/src/data/docs/slp/tokentype1.md deleted file mode 100644 index 3bcb6de2..00000000 --- a/src/data/docs/slp/tokentype1.md +++ /dev/null @@ -1,223 +0,0 @@ ---- -title: TokenType1 -icon: circle -ordinal: 5 ---- - -### `create` - -Create a new SLP Token of Type 1 - -#### Arguments - -1. createConfig `Object` required - -##### Valid config properties - -- `fundingAddress`: `String`. legacy, cash or slp address format -- `fundingWif`: `String`. : compressed WIF format. Available via `SLP.HDNode.toWIF` -- `tokenReceiverAddress` : `String`. legacy, cash or slp address format -- `batonReceiverAddress`: `String`. legacy, cash or slp address format. The address which has the baton has the ability to mint more tokens. -- `bchChangeReceiverAddress` : `String.` legacy, cash or slp address format -- `decimals`: `Number`. Number of decimal points for your token -- `name` : `String`. Name of token -- `symbol` : `String`. Token symbol -- `documentUri` : `String`. URI of token document -- `documentHash` : `String`. Hash of token document -- `initialTokenQty` : `Number`. Initial token quantity - -#### Result - -tokenId `String`. The tokenId of your newly created token. This tokenId is the txid of the genesis tx. You will use this tokenId as your token's unique identifier and to mint future tokens - -#### Examples - - (async function() { - let token = await SLP.TokenType1.create({ - fundingAddress: 'bitcoincash:qpdg4wtc96zucm6qzvnwwskfu7h4l9wapgmz3jwdm7', - fundingWif: 'KxW2CYJ78Tf1fJNYZcoKhGuKD4Gf5qsBEFgLpVFMtZJLSDCRkpXD', - tokenReceiverAddress: '19Fk11eyDcou66eTQ1ovTXJj7BsJTgsfo1', - batonReceiverAddress: - 'simpleledger:qpdg4wtc96zucm6qzvnwwskfu7h4l9wapghe6fmd9q', - bchChangeReceiverAddress: - '19Fk11eyDcou66eTQ1ovTXJj7BsJTgsfo1', - decimals: 2, - name: 'Test SLP SDK Token 3', - symbol: 'TEST3', - documentUri: 'badger@bitcoin.com', - documentHash: null, - initialTokenQty: 1234, - }) - console.log(token) - })() - - // returns - 703920f578d36d975ffdee428df822557c6e9313ceda0d28ad837ebbf2007327 - -### `mint` - -Mint additional tokens of Type 1 - -#### Arguments - -1. mintConfig `Object` required - -##### Valid config properties - -- `fundingAddress`: `String`. legacy, cash or slp address format -- `fundingWif`: `String`. : compressed WIF format. Available via `SLP.HDNode.toWIF` -- `tokenReceiverAddress` : `String`. legacy, cash or slp address format -- `batonReceiverAddress`: `String`. legacy, cash or slp address format -- `bchChangeReceiverAddress` : `String.` legacy, cash or slp address format -- `tokenId`: `String`. tokenId of token to mint more of -- `additionalTokenQty`: `Number`. Number of additional tokens to mint - -#### Result - -mintId `String`. The txid of the newly minted tokens - -#### Examples - - (async function() { - let mint = await SLP.TokenType1.mint({ - fundingAddress: '19Fk11eyDcou66eTQ1ovTXJj7BsJTgsfo1', - fundingWif: 'KxW2CYJ78Tf1fJNYZcoKhGuKD4Gf5qsBEFgLpVFMtZJLSDCRkpXD', - tokenReceiverAddress: '1G84HH1zJLQq6akzzHYJVnTEYhiqkHpNtZ', - batonReceiverAddress: - 'bitcoincash:qzjalztem05hahspdkrqr529me4f7h27zyqu20smfq', - bchChangeReceiverAddress: - 'simpleledger:qzjalztem05hahspdkrqr529me4f7h27zyv8p59mh7', - tokenId: '703920f578d36d975ffdee428df822557c6e9313ceda0d28ad837ebbf2007327', - additionalTokenQty: 100, - }) - console.log(mint) - })() - - // returns - 26a3eb17e11a732bbfd2fdf45bd1f21e9ffebe79b2fe6d2ad229481be38f1f85 - -### `send` - -Send tokens of Type 1 - -#### Arguments - -1. sendConfig `Object` required - -##### Valid config properties - -- `fundingAddress`: `String`. legacy, cash or slp address format -- `fundingWif`: `String`. : compressed WIF format. Available via `SLP.HDNode.toWIF` -- `tokenReceiverAddress` : `String`. legacy, cash or slp address format -- `bchChangeReceiverAddress` : `String.` legacy, cash or slp address format -- `tokenId`: `String`. tokenId of token to send -- `amount`: `Number`. Number of tokens to send - -#### Result - -sendId `String`. The txid of your sent tokens - -#### Examples - - (async function() { - let send = await SLP.TokenType1.send({ - fundingAddress: '1G84HH1zJLQq6akzzHYJVnTEYhiqkHpNtZ', - fundingWif: 'KyuyWyx7gJC6SMsRTkMgJcRCXhoQ7gqxJdGUEybWx7Uu8197ToqE', - tokenReceiverAddress: 'simpleledger:qzczwp9wnej8mhel4me5v2rv20x95d6yyglncxdgtr', - bchChangeReceiverAddress: - 'simpleledger:qzczwp9wnej8mhel4me5v2rv20x95d6yyglncxdgtr', - tokenId: '703920f578d36d975ffdee428df822557c6e9313ceda0d28ad837ebbf2007327', - amount: 10, - }) - console.log(send) - })() - - // returns - 76fb0f1d3d8a010720f8f24c19476e16fa96735e5c215b12773a65608017bd25 - -### `burn` - -Burn an amount of tokens for an address by tokenId - -**CAUTION: THIS WILL BURN AN AMOUNT OF YOUR TOKENS FOR A TOKENID. PLEASE USE WITH CARE** - -#### Arguments - -1. burnConfig `Object` required - -##### Valid config properties - -- `fundingAddress`: `String`. legacy, cash or slp address format -- `fundingWif`: `String`. : compressed WIF format. Available via `SLP.HDNode.toWIF` -- `tokenId`: `String`. tokenId of token to burn all of -- `bchChangeReceiverAddress` : `String`. legacy, cash or slp address format -- `amount`: `Number`. Amount of tokens to burn - -#### Result - -txid `String`. The txid of your burned tokens - -#### Examples - - (async () => { - try { - let iBurnConfig = { - fundingAddress: "bchtest:qp5e2laasex4m2qkrtel3skamsftvu0gaswsmdxcd2", - fundingWif: "cQS4N8Jbw9bmoWiVmprVEs5dEeJ6oUE2FxUo5VSvsDQSBfXakrVc", - tokenId: - "4c7d9c4f50f99ec0d21213d51b09e2c5199e18d88bf2f4a809f164601eda0e1b", - amount: 500, - bchChangeReceiverAddress: - "bchtest:qp5e2laasex4m2qkrtel3skamsftvu0gaswsmdxcd2" - }; - let burn = await SLP.TokenType1.burn(iBurnConfig); - console.log(burn); - } catch (error) { - console.error(error); - } - })(); - - // returns - 30785e55da16be11ce849805abb6d058cfc2f76057627a36a34d3855e678489c - -### `burnAll` - -Burn all tokens for an address by tokenId - -**CAUTION: THIS WILL BURN ALL OF YOUR TOKENS FOR A TOKENID. PLEASE USE WITH CARE** - -#### Arguments - -1. burnAllConfig `Object` required - -##### Valid config properties - -- `fundingAddress`: `String`. legacy, cash or slp address format -- `fundingWif`: `String`. : compressed WIF format. Available via `SLP.HDNode.toWIF` -- `tokenId`: `String`. tokenId of token to burn all of -- `bchChangeReceiverAddress` : `String.` legacy, cash or slp address format - -#### Result - -txid `String`. The txid of your burned tokens - -#### Examples - - (async () => { - try { - let iBurnAllConfig = { - fundingAddress: "bchtest:qqjfqa7qsmydeuctqvddppjnkr53vchseuv49mhsxa", - fundingWif: "cNbbGFfSG8xvrH4HXJLcoENEmtkDAvPoC21qVhjntUc18XBzhGGe", - tokenId: - "3125ee6e4b051a19996a58cd876dade21a0a891d16845ada7d441573805c08db", - bchChangeReceiverAddress: "bchtest:qp5e2laasex4m2qkrtel3skamsftvu0gaswsmdxcd2" - }; - let burnAll = await SLP.TokenType1.burnAll(iBurnAllConfig); - console.log(burnAll); - } catch (error) { - console.error(error); - } - })(); - - // returns - 8d2a6aad3de38e79718c043c6f83a960807787efec92d6a1d9940e2ed04d2169 diff --git a/src/data/docs/slp/utils.md b/src/data/docs/slp/utils.md deleted file mode 100644 index 53c64100..00000000 --- a/src/data/docs/slp/utils.md +++ /dev/null @@ -1,305 +0,0 @@ ---- -title: Utils -icon: exchange -ordinal: 6 ---- - -### `list` - -List all tokens or list single token by id - -#### Arguments - -1. id : `String` or `Array` optional. The token id(s) - -#### Result - -tokens : `Array` or `Object`. tokens or single token - -#### Examples - -##### List all tokens - - (async () => { - try { - let list = await SLP.Utils.list(); - console.log(list); - } catch (error) { - console.error(error); - } - })(); - - // returns - [ { id: 'a72788409fa0ff38556e0d26d17edcc8e6ac04dcdc4904eeb5297c6096dc6e75', - timestamp: '2019-02-10 03:24', - symbol: 'C', - name: 'Contract Name', - documentUri: 'documentUri', - documentHash: - '1000000000000000000000000000000000000000000000000000000000000001', - decimals: 1, - initialTokenQty: 10 }, - { id: 'e6fe00fc1f53320b72bd5cbed76c0c82e5edfea1b6f9cb0f71bfb28c3b6211a8', - timestamp: '2019-02-05 04:01', - symbol: 'TESTNET3', - name: 'SLP SDK Testnet Token 3', - documentUri: 'badger@bitcoin.com', - documentHash: '', - decimals: 8, - initialTokenQty: 100 }] - -##### List single token - - (async () => { - try { - let list = await SLP.Utils.list( - "b3f4f132dc3b9c8c96316346993a8d54d729715147b7b11aa6c8cd909e955313" - ); - console.log(list); - } catch (error) { - console.error(error); - } - })(); - - // returns - { id: 'b3f4f132dc3b9c8c96316346993a8d54d729715147b7b11aa6c8cd909e955313', - timestamp: '2019-01-30 21:56', - symbol: 'SLPJS', - name: 'Awesome SLPJS README Token', - documentUri: 'info@simpleledger.io', - documentHash: '', - decimals: 2, - initialTokenQty: 1000000 } - -##### List multiple tokens by tokenIds - - (async () => { - try { - let list = await SLP.Utils.list([ - "fa6c74c52450fc164e17402a46645ce494a8a8e93b1383fa27460086931ef59f", - "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0" - ]); - console.log(list); - } catch (error) { - console.error(error); - } - })(); - - // returns - [{ - "id": "fa6c74c52450fc164e17402a46645ce494a8a8e93b1383fa27460086931ef59f", - "timestamp": "2019-02-18 15:47", - "symbol": "SLP", - "name": "Official SLP Token", - "documentUri": "https://simpleledger.cash", - "documentHash": "", - "decimals": 0, - "initialTokenQty": 18446744073709552000 - }, - { - "id": "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0", - "timestamp": "2019-02-14 04:11", - "symbol": "PSF", - "name": "Permissionless Software Foundation", - "documentUri": "psfoundation.cash", - "documentHash": "", - "decimals": 8, - "initialTokenQty": 19882.09163133 - }] - -### `balancesForAddress` - -Return all balances for an address - -#### Arguments - -1. address : `String` required. The address in legacy, cash or slp address format - -#### Result - -balances : `Object`. The address's balances - -#### Examples - - (async () => { - try { - let balances = await SLP.Utils.balancesForAddress('simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk'); - console.log(balances); - } catch (error) { - console.error(error); - } - })(); - - // returns - // [ { tokenId: - // '968ff0cc4c93864001e03e9524e351250b94ec56150fa4897f65b0b6477d44d4', - // balance: '9980', - // decimalCount: 9 }, - // { tokenId: - // 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', - // balance: '617', - // decimalCount: 8 }, - // { tokenId: - // 'b96304d12f1bbc2196df582516410e55a9b34e13c7b4585bf5c1770af30d034f', - // balance: '1', - // decimalCount: 0 }, - // { tokenId: - // 'a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37', - // balance: '776', - // decimalCount: 7 } ] - - // balances for Cash Address - (async () => { - try { - let balances = await SLP.Utils.balancesForAddress('bitcoincash:qr4zg7xth86yzq94gl8jvnf5z4wuupzt3g4hl47n9y'); - console.log(balances); - } catch (error) { - console.error(error); - } - })(); - - // returns - // [ { tokenId: - // '467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5', - // balance: '507', - // decimalCount: 2 } ] - - // balances for Legacy Address - (async () => { - try { - let balances = await SLP.Utils.balancesForAddress('1NM2ozrXVSnMRm66ua6aGeXgMsU7yqwqLS'); - console.log(balances); - } catch (error) { - console.error(error); - } - })(); - - // returns - // [ { tokenId: - // '467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5', - // balance: '507', - // decimalCount: 2 } ] - -### `balance` - -Return single balance for an address by token id - -#### Arguments - -1. address : `String` required. The address in legacy, cash or slp address format -2. id : `String` required. The token id - -#### Result - -balance : `Object`. the address's balance for single token - -#### Examples - - // single balance for SLP Address - (async () => { - try { - let balance = await SLP.Utils.balance( - "simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk", - "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" - ); - console.log(balance); - } catch (error) { - console.error(error); - } - })(); - - // returns - // { tokenId: - // 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', - // balance: '617', - // decimalCount: 8 } - - // single balance for Cash Address - (async () => { - try { - let balance = await SLP.Utils.balance( - "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg", - "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" - ); - console.log(balance); - } catch (error) { - console.error(error); - } - })(); - - // returns - // { tokenId: - // 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', - // balance: '617', - // decimalCount: 8 } - - // single balance for Legacy Address - (async () => { - try { - let balance = await SLP.Utils.balance( - "1DwQqpWc8pzaRydCmiJsPdoqCzmjSQQbp8", - "467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5" - ); - console.log(balance); - } catch (error) { - console.error(error); - } - })(); - - // returns - // { tokenId: - // '467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5', - // balance: '1234', - // decimalCount: 2 } - -### `validateTxid` - -Validate that txid is an SLP transaction - -#### Arguments - -1. txid : `String` or `Array` required. The transaction id(s) to validate - -#### Result - -validated : `Array` - -#### Examples - - // validate single SLP txid - (async () => { - try { - let validated = await SLP.Utils.validateTxid( - "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" - ); - console.log(validated); - } catch (error) { - console.error(error); - } - })(); - - // returns - [ { txid: - 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', - valid: true } ] - - // validate multiple SLP txids - (async () => { - try { - let validated = await SLP.Utils.validateTxid([ - "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", - "00ea27261196a411776f81029c0ebe34362936b4a9847deb1f7a40a02b3a1476" - ]); - console.log(validated); - } catch (error) { - console.error(error); - } - })(); - - // returns - [ { txid: - 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', - valid: true }, - { txid: - '00ea27261196a411776f81029c0ebe34362936b4a9847deb1f7a40a02b3a1476', - valid: true } ] diff --git a/src/data/insights/scale.cash.md b/src/data/insights/scale.cash.md index 9366fd93..2e52d70b 100644 --- a/src/data/insights/scale.cash.md +++ b/src/data/insights/scale.cash.md @@ -40,7 +40,7 @@ Your wallet is only ever accessed locally and all transactions are signed by you Download a [Bitcoin Cash Wallet](https://wallet.bitcoin.com/) and scan the QR code at scale.cash. Send the address between 15,000–1,300,000 satoshis—or at the time of this writing, between $0.08–$7. -In this example we're using the bitcoin.com mobile iOS wallet. We sent $1 and it created txid [1467afce1d35fa4ada2feaeb1beba0573971783e2d1af271e3d6e9a4c660afa1](https://explorer.bitcoin.com/bch/tx/1467afce1d35fa4ada2feaeb1beba0573971783e2d1af271e3d6e9a4c660afa1). +In this example we're using the bitcoin.com mobile iOS wallet. We sent \$1 and it created txid [1467afce1d35fa4ada2feaeb1beba0573971783e2d1af271e3d6e9a4c660afa1](https://explorer.bitcoin.com/bch/tx/1467afce1d35fa4ada2feaeb1beba0573971783e2d1af271e3d6e9a4c660afa1). ![bitcoin.com ios wallet shot 1](/images/scale-5.png) @@ -95,7 +95,7 @@ bitbox new scale.cash --scaffold react This creates a basic BIP44 wallet in a react app with BITBOX already bundled. The scale.cash codebase also shows how to [create a mnemonic](https://github.com/SpendBCH/bch-stresstest-web/blob/7e7300f192701bf256252c118fe8dd3d4d6d475b/src/stresstest-lib/wallet.js#L20). ``` -this.mnemonic = BITBOX.Mnemonic.generate(256) +this.mnemonic = bitbox.Mnemonic.generate(256) ``` Which can then be [stored and reloaded](https://github.com/SpendBCH/bch-stresstest-web/blob/a4b0f3493f467efc32ff9a3f03ca0ad96a6f87f8/src/App.js#L17) when your component mounts. @@ -120,19 +120,19 @@ componentDidMount() { It also shows how to create a root seed, BIP44 master HDNode, first external change node, privkeyWIF, ECPair, PubKey and [address in legacy and cash format](https://github.com/SpendBCH/bch-stresstest-web/blob/7e7300f192701bf256252c118fe8dd3d4d6d475b/src/stresstest-lib/wallet.js#L25-L34). ```javascript -let rootSeed = BITBOX.Mnemonic.toSeed(this.mnemonic) -let masterHDNode = BITBOX.HDNode.fromSeed( +let rootSeed = bitbox.Mnemonic.toSeed(this.mnemonic) +let masterHDNode = bitbox.HDNode.fromSeed( rootSeed, window.scaleCashSettings.networkString ) -this.hdNode = BITBOX.HDNode.derivePath(masterHDNode, "m/44'/145'/0'") -this.node0 = BITBOX.HDNode.derivePath(this.hdNode, '0/0') -this.node0WIF = BITBOX.ECPair.toWIF(BITBOX.HDNode.toKeyPair(this.node0)) - -let ecpair = BITBOX.ECPair.fromWIF(this.node0WIF) -this.node0LegacyAddress = BITBOX.ECPair.toLegacyAddress(ecpair) -this.node0CashAddress = BITBOX.ECPair.toCashAddress(ecpair) -this.pubKey = Buffer(BITBOX.ECPair.toPublicKey(ecpair), 'hex') +this.hdNode = bitbox.HDNode.derivePath(masterHDNode, "m/44'/145'/0'") +this.node0 = bitbox.HDNode.derivePath(this.hdNode, '0/0') +this.node0WIF = bitbox.ECPair.toWIF(bitbox.HDNode.toKeyPair(this.node0)) + +let ecpair = bitbox.ECPair.fromWIF(this.node0WIF) +this.node0LegacyAddress = bitbox.ECPair.toLegacyAddress(ecpair) +this.node0CashAddress = bitbox.ECPair.toCashAddress(ecpair) +this.pubKey = Buffer(bitbox.ECPair.toPublicKey(ecpair), 'hex') ``` #### REST @@ -157,7 +157,7 @@ Every newly created address in scale.cash signs the message `stresstestbitcoin.c ```javascript this.messageToSign = 'stresstestbitcoin.cash' -this.signature = BITBOX.BitcoinCash.signMessageWithPrivKey( +this.signature = bitbox.BitcoinCash.signMessageWithPrivKey( this.node0WIF, this.messageToSign ) @@ -170,7 +170,7 @@ This is useful if you want to prove ownership of this address. You can share the Or you can verify ownership with `bitbox-sdk`. ```javascript -BITBOX.BitcoinCash.verifyMessage( +bitbox.BitcoinCash.verifyMessage( 'bitcoincash:qrxju3vcdctp8s9zx7224s2extas8gc2juyk5ayhyv', 'IEqQIvP0x1RP0GIFlWZonP7ObQQ2nWu8oATX5pq31ryTToDtrTgKb3JNZnAePcyZui7jgZt7oEzA7/q4FSlfL94=', 'stresstestbitcoin.cash' @@ -184,7 +184,7 @@ Scale.cash also [shows how](https://github.com/SpendBCH/bch-stresstest-web/blob/ ```javascript const opReturnTagText = 'stresstestbitcoin.cash' -const opReturnTagBuffer = BITBOX.Script.nullData.output.encode( +const opReturnTagBuffer = bitbox.Script.nullData.output.encode( Buffer.from(opReturnTagText, 'ascii') ) ``` @@ -194,7 +194,7 @@ const opReturnTagBuffer = BITBOX.Script.nullData.output.encode( Finally scale.cash [shows how](https://github.com/SpendBCH/bch-stresstest-web/blob/master/src/stresstest-lib/utils.js#L183) to create transactions with P2PKH inputs/outputs and an `OP_RETURN` output. ```javascript -let transactionBuilder = new BITBOX.TransactionBuilder( +let transactionBuilder = new bitbox.TransactionBuilder( window.scaleCashSettings.networkString ) transactionBuilder.addInput(wallet.txid, wallet.vout) diff --git a/src/data/mastering-bitcoin-cash/3-keys-addresses-wallets.md b/src/data/mastering-bitcoin-cash/3-keys-addresses-wallets.md index 8dd0ffb3..eff098da 100644 --- a/src/data/mastering-bitcoin-cash/3-keys-addresses-wallets.md +++ b/src/data/mastering-bitcoin-cash/3-keys-addresses-wallets.md @@ -915,23 +915,23 @@ On the fourth level, "change," an HD wallet has two subtrees, one for creating r Using [BITBOX](/bitbox) you can experiment with generating BIP0044 HDNodes, as well as displaying them in different formats: ```javascript -let mnemonic = BITBOX.Mnemonic.generate(256) +let mnemonic = bitbox.Mnemonic.generate(256) // section urge actress improve hill elephant mirror twice movie route garden true blast gauge dilemma protect hello copper cactus south bonus license merry shine -let seed = BITBOX.Mnemonic.toSeed(mnemonic) -let hdNode = BITBOX.HDNode.fromSeed(seed) +let seed = bitbox.Mnemonic.toSeed(mnemonic) +let hdNode = bitbox.HDNode.fromSeed(seed) // BIP44 Account 0 -let bchAccount0 = BITBOX.HDNode.derivePath(hdNode, "m/44'/145'/0'") +let bchAccount0 = bitbox.HDNode.derivePath(hdNode, "m/44'/145'/0'") -BITBOX.HDNode.toCashAddress(bchAccount0) +bitbox.HDNode.toCashAddress(bchAccount0) // bitcoincash:qr8xeztlnt0axpxnsf8s9hlwmvnd0krf4vfy3v9un9 -BITBOX.HDNode.toLegacyAddress(bchAccount0) +bitbox.HDNode.toLegacyAddress(bchAccount0) // 1KpUDopUHBBASLJM3Lx39dpLRPf3PEMnEy -BITBOX.HDNode.toWIF(bchAccount0) +bitbox.HDNode.toWIF(bchAccount0) // Kwf7ujr3ZgyY8Uv3pT7kuyyf3paYdtdQecsiomJe6f9TBkR1Ad2 ``` @@ -949,12 +949,12 @@ A BIP0038 encryption scheme takes as input a Bitcoin Cash private key, encoded i ```javascript // mainnet -BITBOX.BitcoinCash.encryptBIP38( +bitbox.BitcoinCash.encryptBIP38( 'L1phBREbhL4vb1uHHHCAse8bdGE5c7ic2PFjRxMawLzQCsiFVbvu', '9GKVkabAHBMyAf' ) // 6PYU2fDHRVF2194gKDGkbFbeu4mFgkWtVvg2RPd2Sp6KmZx3RCHFpgBB2G -BITBOX.BitcoinCash.decryptBIP38( +bitbox.BitcoinCash.decryptBIP38( '6PYU2fDHRVF2194gKDGkbFbeu4mFgkWtVvg2RPd2Sp6KmZx3RCHFpgBB2G', '9GKVkabAHBMyAf', 'mainnet' @@ -962,12 +962,12 @@ BITBOX.BitcoinCash.decryptBIP38( // L1phBREbhL4vb1uHHHCAse8bdGE5c7ic2PFjRxMawLzQCsiFVbvu // testnet -BITBOX.BitcoinCash.encryptBIP38( +bitbox.BitcoinCash.encryptBIP38( 'cSx7KzdH9EcvDEireu2WYpGnXdFYpta7sJUNt5kVCJgA7kcAU8Gm', '1EBPIyj55eR8bVUov9' ) // 6PYUAPLwLSEjWSAfoe9NTSPkMZXnJA8j8EFJtKaeSnP18RCouutBrS2735 -BITBOX.BitcoinCash.decryptBIP38( +bitbox.BitcoinCash.decryptBIP38( '6PYUAPLwLSEjWSAfoe9NTSPkMZXnJA8j8EFJtKaeSnP18RCouutBrS2735', '1EBPIyj55eR8bVUov9', 'testnet' diff --git a/src/data/mastering-bitcoin-cash/4-transactions.md b/src/data/mastering-bitcoin-cash/4-transactions.md index 1996d6b3..36cbf7d4 100644 --- a/src/data/mastering-bitcoin-cash/4-transactions.md +++ b/src/data/mastering-bitcoin-cash/4-transactions.md @@ -115,13 +115,13 @@ The transaction scripting language, used in the locking script mentioned previou Table 2. The structure of a transaction output -In [A script that calls `BITBOX.Address.utxo` to find the UTXO related to an address](#get_utxo), we use the `BITBOX.Address` class to find the unspent outputs (UTXO) of a specific address. +In [A script that calls `bitbox.Address.utxo` to find the UTXO related to an address](#get_utxo), we use the `bitbox.Address` class to find the unspent outputs (UTXO) of a specific address. -Example 1. A script that calls `BITBOX.Address.utxo` to find the UTXO related to an address +Example 1. A script that calls `bitbox.Address.utxo` to find the UTXO related to an address ```javascript -BITBOX.Address.utxo('bitcoincash:qpcxf2sv9hjw08nvpgffpamfus9nmksm3chv5zqtnz').then((result) => { +bitbox.Address.utxo('bitcoincash:qpcxf2sv9hjw08nvpgffpamfus9nmksm3chv5zqtnz').then((result) => { console.log(result); }, (err) => { console.log(err); diff --git a/src/data/mastering-bitcoin-cash/5-the-bitcoin-cash-network.md b/src/data/mastering-bitcoin-cash/5-the-bitcoin-cash-network.md index 4040084f..eb83274d 100644 --- a/src/data/mastering-bitcoin-cash/5-the-bitcoin-cash-network.md +++ b/src/data/mastering-bitcoin-cash/5-the-bitcoin-cash-network.md @@ -104,7 +104,7 @@ A node must connect to a few different peers in order to establish diverse paths With BITBOX you can list the peer connections with the command getpeerinfo: ```javascript -BITBOX.Network.getPeerInfo().then( +bitbox.Network.getPeerInfo().then( result => { console.log(result) }, diff --git a/src/data/mastering-bitcoin-cash/6-the-blockchain.md b/src/data/mastering-bitcoin-cash/6-the-blockchain.md index cc105efb..dcf37197 100644 --- a/src/data/mastering-bitcoin-cash/6-the-blockchain.md +++ b/src/data/mastering-bitcoin-cash/6-the-blockchain.md @@ -91,7 +91,7 @@ You can search for that block hash in any block explorer website, such as blockc #### Using BITBOX ```javascript -BITBOX.Block.details( +bitbox.Block.details( '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' ).then( result => { diff --git a/src/data/tutorials/account-creation.md b/src/data/tutorials/account-creation.md index 74f991e3..a6edf391 100644 --- a/src/data/tutorials/account-creation.md +++ b/src/data/tutorials/account-creation.md @@ -26,8 +26,8 @@ You can configure how much entropy BITBOX uses to create your mnemonic in the co To do this we’re using NodeJS’s [`crypto.randomBytes`](https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback) and the wonderful [BIP39.js](https://github.com/bitcoinjs/bip39). ```javascript -let randomBytes = BITBOX.Crypto.randomBytes(32) -let mnemonic = BITBOX.Mnemonic.fromEntropy(randomBytes) +let randomBytes = bitbox.Crypto.randomBytes(32) +let mnemonic = bitbox.Mnemonic.fromEntropy(randomBytes) ``` ![Mnemonic](https://bigearth.github.io/bitblog/assets/mnemonic.png) @@ -40,7 +40,7 @@ Next we take an optional password and combined w/ the mnemonic create a root see ```javascvript let password = 'l337'; -let rootSeed = BITBOX.Mnemonic.toSeed(mnemonic, password); +let rootSeed = bitbox.Mnemonic.toSeed(mnemonic, password); ``` ### Master key @@ -48,7 +48,7 @@ let rootSeed = BITBOX.Mnemonic.toSeed(mnemonic, password); Finally we’re using [bitcoinlib-js](https://github.com/bitcoinjs/bitcoinjs-lib) to create a masterkey from the rootSeed. ```javascript -let masterkey = BITBOX.HDNode.fromSeed(rootSeed) +let masterkey = bitbox.HDNode.fromSeed(rootSeed) ``` This masterkey can be used to create 4 billion child keys. Each of those child keys can produce 4 billion child keys recursively in a derivation path. @@ -63,7 +63,7 @@ Due to the huge number of potential derivation paths BIPs 43 and 44 introduced c m / purpose' / coin_type' / account' / change / address_index ``` -`purpose'` is always set to 44 to signify that the wallet is BIP 44 compliant. `coin_type'` is set to 145 for $BCH. Then we create 10 accounts which are siblings and get the first private key in Wallet Import Format. +`purpose'` is always set to 44 to signify that the wallet is BIP 44 compliant. `coin_type'` is set to 145 for \$BCH. Then we create 10 accounts which are siblings and get the first private key in Wallet Import Format. ```javascript let purpose = "44'" @@ -71,8 +71,8 @@ let coin = "145'" let addresses = [] for (let i = 0; i < 10; i++) { let path = `m/${purpose}/${coin}/${i}` - let account = BITBOX.HDNode.derivePath(masterkey, path) - addresses.push(BITBOX.HDNode.toWIF(BITBOX.HDNode.derive(account, 0))) + let account = bitbox.HDNode.derivePath(masterkey, path) + addresses.push(bitbox.HDNode.toWIF(bitbox.HDNode.derive(account, 0))) } ``` @@ -87,7 +87,7 @@ We don’t want to display the private key WIF by default to the user because it ![Private WIF](https://bigearth.github.io/bitblog/assets/private-wif.png) ```javascript -let publicKey = BITBOX.ECPair.toLegacyAddress(BITBOX.ECPair.fromWIF(privKeyWIF)) +let publicKey = bitbox.ECPair.toLegacyAddress(bitbox.ECPair.fromWIF(privKeyWIF)) ``` ![Base58Check](https://bigearth.github.io/bitblog/assets/base58check.png) @@ -97,14 +97,14 @@ let publicKey = BITBOX.ECPair.toLegacyAddress(BITBOX.ECPair.fromWIF(privKeyWIF)) `publicKey` from the previous step is Base58Check encoded. You can toggle displaying the address in [CashAddr](https://www.bitcoinabc.org/cashaddr) via [bchaddr.js](https://github.com/bitcoincashjs/bchaddrjs). ```javascript -BITBOX.Address.toCashAddress(publicKey) +bitbox.Address.toCashAddress(publicKey) ``` ![CashAddr](https://bigearth.github.io/bitblog/assets/cashaddr-public.png) ### Testnet -You can also toggle generating keys on the $BCH testnet. +You can also toggle generating keys on the \$BCH testnet. ![Testnet private](https://bigearth.github.io/bitblog/assets/testnet-wif.png) diff --git a/src/data/tutorials/address-conversion.md b/src/data/tutorials/address-conversion.md index 70930dd9..e2c13393 100644 --- a/src/data/tutorials/address-conversion.md +++ b/src/data/tutorials/address-conversion.md @@ -5,7 +5,7 @@ publishedAt: 2018-07-06 updatedAt: 2018-07-06 --- -When Bitcoin Cash began as a fork of $BTC on Aug 1st 2017 it kept the legacy address format. This ended up causing quite a bit of confusion and resulted in lost funds as users accidentally sent $BCH to $BTC addresses and vice versa. +When Bitcoin Cash began as a fork of $BTC on Aug 1st 2017 it kept the legacy address format. This ended up causing quite a bit of confusion and resulted in lost funds as users accidentally sent $BCH to \$BTC addresses and vice versa. To fix this [cashaddr](https://github.com/bitcoincashorg/spec/blob/master/cashaddr.md) was introduced. It’s a base32 encoding based on Bech32. @@ -23,9 +23,9 @@ We’re using [bchaddr.js](https://github.com/bitcoincashjs/bchaddrjs) along w/ ```javascript let wif = 'L3npdkC5BkLZP2d6orb5ZefXYZFzkiteDB5okSgyuYJeGXLH3QNA' -let ecpair = BITBOX.ECPair.fromWIF(wif) -let cashaddr = BITBOX.ECPair.toCashAddress(ecpair) -let base58Check = BITBOX.ECPair.toLegacyAddress(ecpair) +let ecpair = bitbox.ECPair.fromWIF(wif) +let cashaddr = bitbox.ECPair.toCashAddress(ecpair) +let base58Check = bitbox.ECPair.toLegacyAddress(ecpair) let cashaddrQR = let base58CheckQR = let wifQR = @@ -37,4 +37,4 @@ All the addresses in BITBOX are 100% legit on the $BCH network. However BITBOX d You can safely sweep any funds sent to a BITBOX generated address into a wallet via the private key WIF. But we strongly advice against sending any actual funds to a BITBOX address. This is a development tool and not meant to handle actual funds. -If you want to send real coins to a BITBOX address and then sweep them back into a live wallet we suggest using the $BCH testnet. +If you want to send real coins to a BITBOX address and then sweep them back into a live wallet we suggest using the \$BCH testnet. diff --git a/src/data/tutorials/address-utxo.md b/src/data/tutorials/address-utxo.md index c4f070cc..78176acf 100644 --- a/src/data/tutorials/address-utxo.md +++ b/src/data/tutorials/address-utxo.md @@ -16,7 +16,7 @@ Before we get started let’s create an HDNode and send it some satohis. First we generate a random 256 bit mnemonic. ```javascript -let mnemonic = BITBOX.Mnemonic.generate(256) +let mnemonic = bitbox.Mnemonic.generate(256) // slam tag city glass asthma mention rich leader snake prevent fatal trick typical gallery scare sort clip wolf strike float dwarf just clip mail ``` @@ -26,7 +26,7 @@ From that mnemonic we create a root seed buffer. ```javascript // root seed buffer -let rootSeed = BITBOX.Mnemonic.toSeed(mnemonic) +let rootSeed = bitbox.Mnemonic.toSeed(mnemonic) ``` ### Master HD Node @@ -35,7 +35,7 @@ With our root seed we can create a [BIP32](https://github.com/bitcoin/bips/blob/ ```javascript // master HDNode -let masterHDNode = BITBOX.HDNode.fromSeed(rootSeed, 'bitcoincash') +let masterHDNode = bitbox.HDNode.fromSeed(rootSeed, 'bitcoincash') ``` ### Account @@ -44,7 +44,7 @@ Next create a [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.media ```javascript // HDNode of BIP44 account -let account = BITBOX.HDNode.derivePath(masterHDNode, "m/44'/145'/0'") +let account = bitbox.HDNode.derivePath(masterHDNode, "m/44'/145'/0'") ``` ### Change @@ -53,14 +53,14 @@ Create the first external change address per BIP44. ```javascript // derive the first external change address HDNode which is going to spend utxo -let change = BITBOX.HDNode.derivePath(account, '0/0') +let change = bitbox.HDNode.derivePath(account, '0/0') ``` ### Cash Address ```javascript // get the cash address -let cashAddress = BITBOX.HDNode.toCashAddress(change) +let cashAddress = bitbox.HDNode.toCashAddress(change) // bitcoincash:qqn2yf5jzrhwr3magjps5muz30akqqgsm5q7wcgkga ``` @@ -77,7 +77,7 @@ BITBOX Cloud is your Blockchain as a Service.’ We recently started integrating You can use [Address.utxo](../bitbox/docs/address/#utxo) to get back a list of utxo for an address ```javascript -BITBOX.Address.utxo( +bitbox.Address.utxo( 'bitcoincash:qqn2yf5jzrhwr3magjps5muz30akqqgsm5q7wcgkga' ).then( result => { @@ -106,12 +106,12 @@ First create an instance of `TransactionBuilder`. Note the `'bitcoincash'` argum ```javascript // instance of transaction builder -let transactionBuilder = new BITBOX.TransactionBuilder('bitcoincash') +let transactionBuilder = new bitbox.TransactionBuilder('bitcoincash') ``` ### Original amount -Now get the original amount of satoshis from the utxo. This is returned from the call to `BITBOX.Address.utxo`. +Now get the original amount of satoshis from the utxo. This is returned from the call to `bitbox.Address.utxo`. ```javascript // original amount of satoshis in vin @@ -151,7 +151,7 @@ Next use [BitcoinCash.getByteCount](../bitbox/docs/bitcoincash#getByteCount) to ```javascript // get byte count to calculate fee. paying 1 sat/byte -let byteCount = BITBOX.BitcoinCash.getByteCount({ P2PKH: 1 }, { P2PKH: 1 }) +let byteCount = bitbox.BitcoinCash.getByteCount({ P2PKH: 1 }, { P2PKH: 1 }) // 192 ``` @@ -182,7 +182,7 @@ Now get the change node’s keypair to sign the transaction. ```javascript // keypair -let keyPair = BITBOX.HDNode.toKeyPair(change) +let keyPair = bitbox.HDNode.toKeyPair(change) ``` ### Sign input @@ -218,7 +218,7 @@ Finally we’re ready to send our transaction to the BCH network. ```javascript // sendRawTransaction to running BCH node -BITBOX.RawTransactions.sendRawTransaction(hex).then( +bitbox.RawTransactions.sendRawTransaction(hex).then( result => { console.log(result) }, @@ -242,22 +242,22 @@ let mnemonic = 'slam tag city glass asthma mention rich leader snake prevent fatal trick typical gallery scare sort clip wolf strike float dwarf just clip mail' // root seed buffer -let rootSeed = BITBOX.Mnemonic.toSeed(mnemonic) +let rootSeed = bitbox.Mnemonic.toSeed(mnemonic) // master HDNode -let masterHDNode = BITBOX.HDNode.fromSeed(rootSeed, 'bitcoincash') +let masterHDNode = bitbox.HDNode.fromSeed(rootSeed, 'bitcoincash') // HDNode of BIP44 account -let account = BITBOX.HDNode.derivePath(masterHDNode, "m/44'/145'/0'") +let account = bitbox.HDNode.derivePath(masterHDNode, "m/44'/145'/0'") // derive the first external change address HDNode which is going to spend utxo -let change = BITBOX.HDNode.derivePath(account, '0/0') +let change = bitbox.HDNode.derivePath(account, '0/0') // get the cash address -let cashAddress = BITBOX.HDNode.toCashAddress(change) +let cashAddress = bitbox.HDNode.toCashAddress(change) // bitcoincash:qqn2yf5jzrhwr3magjps5muz30akqqgsm5q7wcgkga -BITBOX.Address.utxo( +bitbox.Address.utxo( 'bitcoincash:qqn2yf5jzrhwr3magjps5muz30akqqgsm5q7wcgkga' ).then( result => { @@ -273,7 +273,7 @@ BITBOX.Address.utxo( // cashAddress: 'bitcoincash:qqn2yf5jzrhwr3magjps5muz30akqqgsm5q7wcgkga' } ] // instance of transaction builder - let transactionBuilder = new BITBOX.TransactionBuilder('bitcoincash') + let transactionBuilder = new bitbox.TransactionBuilder('bitcoincash') // original amount of satoshis in vin let originalAmount = result[0].satoshis @@ -288,7 +288,7 @@ BITBOX.Address.utxo( transactionBuilder.addInput(txid, vout) // get byte count to calculate fee. paying 1 sat/byte - let byteCount = BITBOX.BitcoinCash.getByteCount({ P2PKH: 1 }, { P2PKH: 1 }) + let byteCount = bitbox.BitcoinCash.getByteCount({ P2PKH: 1 }, { P2PKH: 1 }) // 192 // amount to send to receiver. It's the original amount - 1 sat/byte for tx size @@ -301,7 +301,7 @@ BITBOX.Address.utxo( ) // keypair - let keyPair = BITBOX.HDNode.toKeyPair(change) + let keyPair = bitbox.HDNode.toKeyPair(change) // sign w/ HDNode let redeemScript @@ -319,7 +319,7 @@ BITBOX.Address.utxo( let hex = tx.toHex() // sendRawTransaction to running BCH node - BITBOX.RawTransactions.sendRawTransaction(hex).then( + bitbox.RawTransactions.sendRawTransaction(hex).then( result => { console.log(result) }, @@ -342,7 +342,7 @@ If we did that correct we should get back a txid [1549abf70bf1f59618d650d72bb717 This was to show step by step how to create a mnemonic, root seed, master node, bip44 account and bip44 change node. It showed how to create a cash address. -Once you have utxo which are spendable it showed how to call BITBOX Cloud via `BITBOX.Address.utxo` to get back a list of spendable utxo. +Once you have utxo which are spendable it showed how to call BITBOX Cloud via `bitbox.Address.utxo` to get back a list of spendable utxo. It next showed how to build a transaction, sign it and `POST` it to the BCH network. diff --git a/src/data/tutorials/bip21.md b/src/data/tutorials/bip21.md index 99dc732a..4b74b9ec 100644 --- a/src/data/tutorials/bip21.md +++ b/src/data/tutorials/bip21.md @@ -5,7 +5,7 @@ publishedAt: 2018-07-06 updatedAt: 2018-07-06 --- -Bitcoin Cash is all about sending and receiving payments. [BIP21](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki) describes a way to encode payment request information such as address, amount, message etc as a URI. These URIs are a very popular way to share payment requests and you’ll often see them as links in a website or as QR codes. Today we’re releasing `encodeBIP21` and `decodeBIP21` to make it easy for your app to encode/decode BIP21 $BCH URIs. +Bitcoin Cash is all about sending and receiving payments. [BIP21](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki) describes a way to encode payment request information such as address, amount, message etc as a URI. These URIs are a very popular way to share payment requests and you’ll often see them as links in a website or as QR codes. Today we’re releasing `encodeBIP21` and `decodeBIP21` to make it easy for your app to encode/decode BIP21 \$BCH URIs. ## encodeBIP21 @@ -18,7 +18,7 @@ let options = { amount: 1, label: '#BCHForEveryone', } -BITBOX.BitcoinCash.encodeBIP21(address, options) +bitbox.BitcoinCash.encodeBIP21(address, options) // bitcoincash:qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s?amount=1&label=%23BCHForEveryone // cashaddr w/out prefix @@ -27,7 +27,7 @@ let options = { amount: 1, label: '#BCHForEveryone', } -BITBOX.BitcoinCash.encodeBIP21(address, options) +bitbox.BitcoinCash.encodeBIP21(address, options) // bitcoincash:qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s?amount=1&label=%23BCHForEveryone // works w/ legacy addresses too @@ -36,7 +36,7 @@ let options = { amount: 1, label: '#BCHForEveryone', } -BITBOX.BitcoinCash.encodeBIP21(address, options) +bitbox.BitcoinCash.encodeBIP21(address, options) // bitcoincash:qr2tcpvsnca0gaw7jxngtmsvd4ffqdpkxqtfzcd8w3?amount=1&label=%23BCHForEveryone ``` @@ -51,7 +51,7 @@ let options = { amount: 'one', label: '#BCHForEveryone', } -BITBOX.BitcoinCash.encodeBIP21(address, options) +bitbox.BitcoinCash.encodeBIP21(address, options) // TypeError: Invalid amount // won't accept a negative value as an amount @@ -60,7 +60,7 @@ let options = { amount: -1, label: '#BCHForEveryone', } -BITBOX.BitcoinCash.encodeBIP21(address, options) +bitbox.BitcoinCash.encodeBIP21(address, options) // TypeError: Invalid amount ``` @@ -71,7 +71,7 @@ To decode a BIP21 URI pass in a valid URI. ```javascript let bip21 = 'bitcoincash:qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s?amount=1&label=%23BCHForEveryone' -BITBOX.BitcoinCash.decodeBIP21(bip21) +bitbox.BitcoinCash.decodeBIP21(bip21) // { address: 'qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s', options: { amount: 1, label: '#BCHForEveryone' } } ``` @@ -82,7 +82,7 @@ BITBOX.BitcoinCash.decodeBIP21(bip21) ```javascript let bip21 = 'qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s?amount=1&label=%23BCHForEveryone' -BITBOX.BitcoinCash.decodeBIP21(bip21) +bitbox.BitcoinCash.decodeBIP21(bip21) // Error: Invalid BIP21 URI: qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s?amount=1&label=%23BCHForEveryone ``` diff --git a/src/data/tutorials/bitbox-cli.md b/src/data/tutorials/bitbox-cli.md index 0a213f58..c8eb643e 100644 --- a/src/data/tutorials/bitbox-cli.md +++ b/src/data/tutorials/bitbox-cli.md @@ -48,7 +48,7 @@ bitbox console This will load the console and create a `BITBOX` object w/ the entire \$BCH JSON RPC available. That `BITBOX` object can send commands to the running Bitcoin ABC node that you configured in the previous step. ```bash -> BITBOX.Network.getNetworkInfo().then((result) => { console.log(result); }, (err) => { console.log(err); }); +> bitbox.Network.getNetworkInfo().then((result) => { console.log(result); }, (err) => { console.log(err); }); { version: 160200, subversion: '/Bitcoin ABC:0.16.2(EB8.0)/', @@ -104,7 +104,7 @@ Next you need to `require` or `import` `BITBOXSDK` into your app depending on if let BITBOXSDK = require('bitbox-sdk').default let BITBOX = new BITBOXSDK() -BITBOX.getnetworkinfo().then( +bitbox.getnetworkinfo().then( result => { console.log(result) }, diff --git a/src/data/tutorials/bitbox-typescript-support.md b/src/data/tutorials/bitbox-typescript-support.md index 369a6525..68e91ab9 100644 --- a/src/data/tutorials/bitbox-typescript-support.md +++ b/src/data/tutorials/bitbox-typescript-support.md @@ -15,7 +15,7 @@ Unit testing and statically typed programming languages can help reduce the numb ### Goal -The goal for this article will be to show how to enable TypeScript types for BITBOX. We will utilize the existing BITBOX scaffolding system to create a new project and then show how to make the required updates so that the types can be accessed during development. +The goal for this article will be to show how to enable TypeScript types for bitbox. We will utilize the existing BITBOX scaffolding system to create a new project and then show how to make the required updates so that the types can be accessed during development. ### Prerequisites diff --git a/src/data/tutorials/extended-public-keys.md b/src/data/tutorials/extended-public-keys.md index c2253bf2..7c5addf8 100644 --- a/src/data/tutorials/extended-public-keys.md +++ b/src/data/tutorials/extended-public-keys.md @@ -14,7 +14,7 @@ Bitcoin Cash offers an unimaginably large number of addresses. This allows you t ```javascript for (let i = 0; i < 5; i++) { console.log( - BITBOX.Address.fromXPub( + bitbox.Address.fromXPub( 'xpub6Bs8HUjmkWC8F6yN6AB4t4npFg7R3EAnzY8yZKRMEiLdTr1PNFwhVSWSaUSkNs43pehV4dNvaQqUAUmAWQXATDQNb1S9EhH515BjyRz5ZNE', `${i}` ) @@ -35,10 +35,10 @@ Write a script to generate the addresses 1 at a time and check the blockchain to ## Privacy -**Be aware** that if you use `BITBOX.Address.fromXPub` in the browser or share your `xpub` w/ anyone else they will be able to generate all your public keys and know exactly how much money has in total been sent to that `xpub`. They **cannot** spend any funds unless they also have the private keys. +**Be aware** that if you use `bitbox.Address.fromXPub` in the browser or share your `xpub` w/ anyone else they will be able to generate all your public keys and know exactly how much money has in total been sent to that `xpub`. They **cannot** spend any funds unless they also have the private keys. As a matter of good practice you should keep your private keys in a hardware wallet or as a mnemonic on a paper wallet. You should be aware that using `xpub` comes w/ lessened privacy if you make your `xpub` known to anyone. ## Summary -Extended public keys make generating a new address for every transaction possible. `BITBOX.Address.fromXPub` makes it quick and easy for devs to have their apps create an infinite number of addresses for their users w/out needing to expose their users to loss via holding their private keys. +Extended public keys make generating a new address for every transaction possible. `bitbox.Address.fromXPub` makes it quick and easy for devs to have their apps create an infinite number of addresses for their users w/out needing to expose their users to loss via holding their private keys. diff --git a/src/data/tutorials/mnemonic-word-lists.md b/src/data/tutorials/mnemonic-word-lists.md index 5f78f65e..c2eca5ee 100644 --- a/src/data/tutorials/mnemonic-word-lists.md +++ b/src/data/tutorials/mnemonic-word-lists.md @@ -5,11 +5,11 @@ publishedAt: 2018-07-06 updatedAt: 2018-07-06 --- -Bitcoin Cash is meant for people all over EARTH. Most of those people don’t speak english. That’s why today we’re releasing `wordLists` so you can generate mnemonics in 8 different languages to help spread $BCH to people all over the planet. +Bitcoin Cash is meant for people all over EARTH. Most of those people don’t speak english. That’s why today we’re releasing `wordLists` so you can generate mnemonics in 8 different languages to help spread \$BCH to people all over the planet. ## wordLists -[BITBOX.Mnemonic](/bitbox/docs/mnemonic/#validate) now has a [wordLists](/bitbox/docs/mnemonic/#wordlists) method which returns an object w/ the following keys: +[bitbox.Mnemonic](/bitbox/docs/mnemonic/#validate) now has a [wordLists](/bitbox/docs/mnemonic/#wordlists) method which returns an object w/ the following keys: ```javascript { @@ -24,7 +24,7 @@ Bitcoin Cash is meant for people all over EARTH. Most of those people don’t sp } ``` -Each of these keys contains an array w/ 2048 words in that language. 4 `BITBOX.Mnemonic` methods now accept that wordlist as their 2nd argument and will create and validate mnemonics in those languages. +Each of these keys contains an array w/ 2048 words in that language. 4 `bitbox.Mnemonic` methods now accept that wordlist as their 2nd argument and will create and validate mnemonics in those languages. The methods which now accepts a `wordslist` argument are @@ -38,55 +38,55 @@ The methods which now accepts a `wordslist` argument are #### Chinese simplified ```javascript -BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().chinese_simplified) +bitbox.Mnemonic.generate(128, bitbox.Mnemonic.wordLists().chinese_simplified) // 南 英 钉 油 冷 馏 扶 搬 特 规 波 顺 ``` #### Chinese traditional ```javascript -BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().chinese_traditional) +bitbox.Mnemonic.generate(128, bitbox.Mnemonic.wordLists().chinese_traditional) // 蒸 融 陣 默 甲 蓋 躺 靈 原 富 恆 份 ``` #### French ```javascript -BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().french) +bitbox.Mnemonic.generate(128, bitbox.Mnemonic.wordLists().french) // annonce ampleur sanglier peser acheter cultiver abroger embellir résoudre dialogue grappin lanterne ``` #### Italian ```javascript -BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().italian) +bitbox.Mnemonic.generate(128, bitbox.Mnemonic.wordLists().italian) // raschiato comodo petalo lira ipotesi mondina scettro ritmico bacino abrasivo attrito eletto ``` #### Japanese ```javascript -BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().japanese) +bitbox.Mnemonic.generate(128, bitbox.Mnemonic.wordLists().japanese) // かいが こける つねづね けおりもの けむり せんろ しゃくほう けんみん あわせる ひつぎ みてい たいない ``` #### Korean ```javascript -BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().korean) +bitbox.Mnemonic.generate(128, bitbox.Mnemonic.wordLists().korean) // 회색 제공 적성 만일 당장 확인 사람 화장 숫자 여군 대도시 하순 ``` #### Spanish ```javascript -BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().spanish) +bitbox.Mnemonic.generate(128, bitbox.Mnemonic.wordLists().spanish) // combate hundir trauma edad élite medio grave pie aduana donar pimienta bodega ``` ## BITBOX GUI -BITBOX GUI has also been updated to generate mnemonics in all of the above languages. There is now a language selector on the configuration screen. Select the language that you’d like to use and restart your BITBOX. +BITBOX GUI has also been updated to generate mnemonics in all of the above languages. There is now a language selector on the configuration screen. Select the language that you’d like to use and restart your bitbox. ![](https://bigearth.github.io/bitblog/assets/language-select.png) @@ -120,4 +120,4 @@ BITBOX GUI has also been updated to generate mnemonics in all of the above langu ## Summary -With `wordLists` it’s now easier than ever to generate mnemonics in languages other than english to help spread $BCH all over the EARTH. +With `wordLists` it’s now easier than ever to generate mnemonics in languages other than english to help spread \$BCH all over the EARTH. diff --git a/src/data/tutorials/multiple-environments.md b/src/data/tutorials/multiple-environments.md index b2d603b6..7b4249ba 100644 --- a/src/data/tutorials/multiple-environments.md +++ b/src/data/tutorials/multiple-environments.md @@ -12,7 +12,7 @@ Imagine you have a $BCH app which you’d like to deploy. However before doing t Let’s say our newly created $BCH app is just a simple call to `getnetworkinfo` but of course it could be much more complex as `BITBOX` supports the entire $BCH RPC. ```javascript -BITBOX.Network.getnetworkinfo().then( +bitbox.Network.getnetworkinfo().then( result => { console.log(result) }, @@ -28,7 +28,7 @@ To test our code first stub out an app w/ production credentials bitbox new myApp --environment production --restURL example.com ``` -Next open up the newly created `bitbox.js` file and add config for your local BITBOX. +Next open up the newly created `bitbox.js` file and add config for your local bitbox. ```javascript networks: { @@ -48,7 +48,7 @@ Now when you fire up your BITBOX console you can tell it which environment to co ```bash bitbox console --environment development -> BITBOX.Network.getNetworkInfo().then((result) => { console.log(result); }, (err) => { console.log(err); }); +> bitbox.Network.getNetworkInfo().then((result) => { console.log(result); }, (err) => { console.log(err); }); { version: 130100, subversion: '/Bitcoin ABC:0.16.2(EB8.0)/', @@ -83,4 +83,4 @@ warnings: '' } ### Summary -This is just a small example to show how BITBOX can accelerate your $BCH workflow. You can stub out an app scaffold w/ configuration for `development` and `production` environments. You have the full $BCH RPC available on the `BITBOX` object and you can quickly switch between sending commands to different environments. +This is just a small example to show how BITBOX can accelerate your \$BCH workflow. You can stub out an app scaffold w/ configuration for `development` and `production` environments. You have the full \$BCH RPC available on the `BITBOX` object and you can quickly switch between sending commands to different environments. diff --git a/src/data/tutorials/sign-and-verify.md b/src/data/tutorials/sign-and-verify.md index 629198ef..f5f0afb8 100644 --- a/src/data/tutorials/sign-and-verify.md +++ b/src/data/tutorials/sign-and-verify.md @@ -13,7 +13,7 @@ Or someone could potentially give you a loan or credit using a signature from a ### Sign a message -You can sign a message w/ any address in your BITBOX. It doesn’t matter if it’s in cashaddr or legacy encoding. Just paste the address into the address field and type the message that you want to sign. Then click the ‘Sign’ button and if you have entered a valid address that has keys in your BITBOX you’ll see a signature appear. +You can sign a message w/ any address in your bitbox. It doesn’t matter if it’s in cashaddr or legacy encoding. Just paste the address into the address field and type the message that you want to sign. Then click the ‘Sign’ button and if you have entered a valid address that has keys in your BITBOX you’ll see a signature appear. ![Converter](https://bigearth.github.io/bitblog/assets/verify-cashaddr.png) @@ -36,7 +36,7 @@ BITBOX supports the entire Bitcoin Cash RPC. [`bitbox-sdk`](https://www.npmjs.co #### Sign ```javascript -BITBOX.BitcoinCash.signMessageWithPrivKey( +bitbox.BitcoinCash.signMessageWithPrivKey( 'KxtpRDUJDiutLaTV8Vuavhb6h7zq9YV9ZKA3dU79PCgYmNVmkkvS', 'EARTH' ) @@ -46,7 +46,7 @@ BITBOX.BitcoinCash.signMessageWithPrivKey( #### Verify ```javascript -BITBOX.BitcoinCash.verifyMessage( +bitbox.BitcoinCash.verifyMessage( 'bitcoincash:qp2zvw3zpk5xx43w4tve7mtekd9kaxwj4uenq9eupv', 'IIYVhlo2Z6TWFjYX1+YM+7vQKz0m+zYdSe4eYpFLuAQDEZXqll7lZC8Au22VI2LLP5x+IerZckVk3QQPsA3e8/8=', 'EARTH' diff --git a/src/data/tutorials/utilities-part-1.md b/src/data/tutorials/utilities-part-1.md index e2b4fe67..51a4db75 100644 --- a/src/data/tutorials/utilities-part-1.md +++ b/src/data/tutorials/utilities-part-1.md @@ -5,19 +5,19 @@ publishedAt: 2018-07-06 updatedAt: 2018-07-06 --- -`bitbox-sdk` recently added 3 new Objects full of utility methods to help you accelerate your $BCH workflow. The `BitcoinCash` methods convert between satoshis and whole units. +`bitbox-sdk` recently added 3 new Objects full of utility methods to help you accelerate your \$BCH workflow. The `BitcoinCash` methods convert between satoshis and whole units. The `Address` methods let you convert legacy addresses to cashaddr and reverse as well as detecting address formats, types and networks. -The `Crypto` methods let you create sha256 and ripemd160 hashes as well as generate random bytes. Together the `BitcoinCash` and `Crypto` utilities let you quickly build out a great $BCH application. +The `Crypto` methods let you create sha256 and ripemd160 hashes as well as generate random bytes. Together the `BitcoinCash` and `Crypto` utilities let you quickly build out a great \$BCH application. ## BitcoinCash ```javascript -BITBOX.BitcoinCash.toSatoshi(9) +bitbox.BitcoinCash.toSatoshi(9) // 900000000 -BITBOX.BitcoinCash.toBitcoinCash(900000000) +bitbox.BitcoinCash.toBitcoinCash(900000000) // 9 ``` @@ -26,55 +26,55 @@ BITBOX.BitcoinCash.toBitcoinCash(900000000) ## Address ```javascript -BITBOX.Address.toLegacyAddress( +bitbox.Address.toLegacyAddress( 'bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl' ) // 1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN -BITBOX.Address.toCashAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN') +bitbox.Address.toCashAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN') // bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl -BITBOX.Address.isLegacyAddress( +bitbox.Address.isLegacyAddress( 'bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s' ) // false -BITBOX.Address.isCashAddress( +bitbox.Address.isCashAddress( 'bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s' ) // true -BITBOX.Address.isMainnetAddress( +bitbox.Address.isMainnetAddress( 'bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s' ) // true -BITBOX.Address.isTestnetAddress( +bitbox.Address.isTestnetAddress( 'bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s' ) //false -BITBOX.Address.isP2PKHAddress( +bitbox.Address.isP2PKHAddress( 'bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s' ) // true -BITBOX.Address.isP2SHAddress( +bitbox.Address.isP2SHAddress( 'bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s' ) // false -BITBOX.Address.detectAddressFormat( +bitbox.Address.detectAddressFormat( 'bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s' ) // cashaddr -BITBOX.Address.detectAddressNetwork( +bitbox.Address.detectAddressNetwork( 'bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s' ) // mainnet -BITBOX.Address.detectAddressType( +bitbox.Address.detectAddressType( 'bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s' ) // p2pkh @@ -86,22 +86,22 @@ BITBOX.Address.detectAddressType( ```javascript let buffer = Buffer.from('0101010101010101', 'hex') -BITBOX.Crypto.sha256(buffer) +bitbox.Crypto.sha256(buffer) // let buffer = Buffer.from('0101010101010101', 'hex') -BITBOX.Crypto.ripemd160(buffer) +bitbox.Crypto.ripemd160(buffer) // let buffer = Buffer.from('0101010101010101', 'hex') -BITBOX.Crypto.hash256(buffer) +bitbox.Crypto.hash256(buffer) // let buffer = Buffer.from('0101010101010101', 'hex') -BITBOX.Crypto.hash160(buffer) +bitbox.Crypto.hash160(buffer) // -BITBOX.Crypto.randomBytes(16) +bitbox.Crypto.randomBytes(16) // ``` diff --git a/src/data/tutorials/utilities-part-2.md b/src/data/tutorials/utilities-part-2.md index 758586e7..19575723 100644 --- a/src/data/tutorials/utilities-part-2.md +++ b/src/data/tutorials/utilities-part-2.md @@ -5,18 +5,18 @@ publishedAt: 2018-07-06 updatedAt: 2018-07-06 --- -[HD Wallets](https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch05.asciidoc) are at the heart of most Bitcoin Cash apps. Being able to quickly create them can let developers create more exciting $BCH apps quicker than ever. Today we’re releasing 7 new utility methods to let you quickly generate mnemonics, root seeds, master private keys, HD wallets and then to sign and verify messages w/ keys from that wallet. +[HD Wallets](https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch05.asciidoc) are at the heart of most Bitcoin Cash apps. Being able to quickly create them can let developers create more exciting \$BCH apps quicker than ever. Today we’re releasing 7 new utility methods to let you quickly generate mnemonics, root seeds, master private keys, HD wallets and then to sign and verify messages w/ keys from that wallet. ## Mnemonic ```javascript // Turn random bytes to mnemonic -let entropy = BITBOX.Crypto.randomBytes(16) -BITBOX.Mnemonic.fromEntropy(entropy) +let entropy = bitbox.Crypto.randomBytes(16) +bitbox.Mnemonic.fromEntropy(entropy) // talk able guilt away taxi opinion club pact together ribbon middle patch // Turn mnemonic to root seed -BITBOX.Mnemonic.toSeed( +bitbox.Mnemonic.toSeed( 'enable stem left method one submit coach bid inspire cluster armed bracket' ) // @@ -27,8 +27,8 @@ BITBOX.Mnemonic.toSeed( ## HDNode ```javascript -// Create Master Private Key w/ rootSeed returned from BITBOX.Mnemonic.toSeed -BITBOX.HDNode.fromSeed(rootSeed) +// Create Master Private Key w/ rootSeed returned from bitbox.Mnemonic.toSeed +bitbox.HDNode.fromSeed(rootSeed) // HDNode { // keyPair: // ECPair { @@ -67,7 +67,7 @@ BITBOX.HDNode.fromSeed(rootSeed) ```javascript // Create keypair from private key in wallet import format -BITBOX.ECPair.fromWIF('KxYoF3rr34fxUtGwfeASBrz6AWLjJCMG5wniooriX8NvHucsTDFz') +bitbox.ECPair.fromWIF('KxYoF3rr34fxUtGwfeASBrz6AWLjJCMG5wniooriX8NvHucsTDFz') // ECPair { // d: // BigInteger { @@ -98,13 +98,13 @@ BITBOX.ECPair.fromWIF('KxYoF3rr34fxUtGwfeASBrz6AWLjJCMG5wniooriX8NvHucsTDFz') ## BitcoinCash ```javascript -BITBOX.BitcoinCash.signMessageWithPrivKey( +bitbox.BitcoinCash.signMessageWithPrivKey( 'KxtpRDUJDiutLaTV8Vuavhb6h7zq9YV9ZKA3dU79PCgYmNVmkkvS', 'EARTH' ) // IIYVhlo2Z6TWFjYX1+YM+7vQKz0m+zYdSe4eYpFLuAQDEZXqll7lZC8Au22VI2LLP5x+IerZckVk3QQPsA3e8/8= -BITBOX.BitcoinCash.verifyMessage( +bitbox.BitcoinCash.verifyMessage( 'bitcoincash:qp2zvw3zpk5xx43w4tve7mtekd9kaxwj4uenq9eupv', 'IIYVhlo2Z6TWFjYX1+YM+7vQKz0m+zYdSe4eYpFLuAQDEZXqll7lZC8Au22VI2LLP5x+IerZckVk3QQPsA3e8/8=', 'EARTH' diff --git a/src/data/tutorials/websocket-scaffold.md b/src/data/tutorials/websocket-scaffold.md index 0048940b..8f253a23 100644 --- a/src/data/tutorials/websocket-scaffold.md +++ b/src/data/tutorials/websocket-scaffold.md @@ -56,7 +56,7 @@ Donate BCH shows very practical ways to leverage BITBOX when creating an app. It BITBOX can convert whole BCH units [to satoshis](/bitbox/docs/bitcoincash/#tosatoshi) as well as converting satoshis to [bits](/bitbox/docs/bitcoincash/#tobits) and back to [whole units](/bitbox/docs/bitcoincash/#tobitcoincash). The scaffold [converts satoshis](https://github.com/Bitcoin-com/bitbox-scaffold-websockets/blob/master/src/App.js#L50) to whole BCH. ```javascript -const value = BITBOX.BitcoinCash.toBitcoinCash(curr.satoshi) +const value = bitbox.BitcoinCash.toBitcoinCash(curr.satoshi) ``` #### Address Conversion @@ -64,7 +64,7 @@ const value = BITBOX.BitcoinCash.toBitcoinCash(curr.satoshi) BITBOX has methods for converting [cash address to legacy](/bitbox/docs/address/#tolegacyaddress) and [legacy to cash](/bitbox/docs/address/#tocashaddress). The scaffold [converts cash address to legacy address](https://github.com/Bitcoin-com/bitbox-scaffold-websockets/blob/master/src/App.js#L97). ```javascript -const cashaddr = BITBOX.Address.toCashAddress(address) +const cashaddr = bitbox.Address.toCashAddress(address) ``` #### REST @@ -72,7 +72,7 @@ const cashaddr = BITBOX.Address.toCashAddress(address) BITBOX SDK has [REST](https://rest.bitcoin.com) integration bundled. The scaffold calls [Address.details](https://github.com/Bitcoin-com/bitbox-scaffold-websockets/blob/master/src/App.js#L121) to get back utxo for an address. ```javascript -BITBOX.Address.details(addr).then( +bitbox.Address.details(addr).then( result => { result.forEach(r => { Object.keys(donations).forEach(p => { @@ -95,7 +95,7 @@ BITBOX.Address.details(addr).then( The `Socket` class lets you quickly get real-time blockchain data. First [create an instance](/bitbox/docs/socket/#constructor) and then [call listen](/bitbox/docs/socket/#listen). Here's how the scaffold [updates the UI](https://github.com/Bitcoin-com/bitbox-scaffold-websockets/blob/master/src/App.js#L81) after new tx data comes in. ```javascript -const socket = new BITBOX.Socket() +const socket = new bitbox.Socket() socket.listen('transactions', this.handleNewTx) ``` diff --git a/src/pages/bitbox.js b/src/pages/bitbox.js index a0ab22c5..866c47e0 100644 --- a/src/pages/bitbox.js +++ b/src/pages/bitbox.js @@ -128,11 +128,11 @@ const BitboxPage = ({ location, data }: Props) => ( {`// generate 24 word mnemonic -BITBOX.Mnemonic.generate(256); +bitbox.Mnemonic.generate(256); // disagree tide elbow citizen jazz cinnamon bridge certain april settle pact film always inmate border inform solution that submit produce cloth balcony upper maid // generate 12 french word mnemonic -BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().french); +bitbox.Mnemonic.generate(128, bitbox.Mnemonic.wordLists().french); // annonce ampleur sanglier peser acheter cultiver abroger embellir résoudre dialogue grappin lanterne`} @@ -146,7 +146,7 @@ BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().french); {`// decode raw transaction hex (async () => { try { - let decodeRawTransaction = await BITBOX.RawTransactions.decodeRawTransaction('01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'); + let decodeRawTransaction = await bitbox.RawTransactions.decodeRawTransaction('01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'); console.log(decodeRawTransaction); } catch(error) { console.error(error) @@ -156,7 +156,7 @@ BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().french); // send raw transactions to the network (async () => { try { - let sendRawTransaction = await BITBOX.RawTransactions.sendRawTransaction("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000"); + let sendRawTransaction = await bitbox.RawTransactions.sendRawTransaction("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000"); console.log(sendRawTransaction); } catch(error) { console.error(error) @@ -166,7 +166,7 @@ BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().french); // get transaction details by txid (async () => { try { - let details = await BITBOX.Transaction.details('a85fa3d831ab6b0305e7ff88d2d4941e25a810d4461635df51490653822071a8'); + let details = await bitbox.Transaction.details('a85fa3d831ab6b0305e7ff88d2d4941e25a810d4461635df51490653822071a8'); console.log(details); } catch(error) { console.error(error) @@ -182,27 +182,27 @@ BITBOX.Mnemonic.generate(128, BITBOX.Mnemonic.wordLists().french); {`// cashaddr to legacy -BITBOX.Address.toLegacyAddress('bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') +bitbox.Address.toLegacyAddress('bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') // 1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN // legacy to cashaddr -BITBOX.Address.toCashAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN') +bitbox.Address.toCashAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN') // bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl // detect legacy address -BITBOX.Address.isLegacyAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') +bitbox.Address.isLegacyAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // false // detect cashaddr address -BITBOX.Address.isCashAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') +bitbox.Address.isCashAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // true // detect mainnet address -BITBOX.Address.isMainnetAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') +bitbox.Address.isMainnetAddress('bitcoincash:qqfx3wcg8ts09mt5l3zey06wenapyfqq2qrcyj5x0s') // true // detect testnet address -BITBOX.Address.isTestnetAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') +bitbox.Address.isTestnetAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') // true`} @@ -211,15 +211,15 @@ BITBOX.Address.isTestnetAddress('bchtest:qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a Convert between satoshis and whole units or bits. {`// convert 9 $BCH to satoshis -BITBOX.BitcoinCash.toSatoshi(9) +bitbox.BitcoinCash.toSatoshi(9) // 900000000 // convert 900000000 satoshis to $BCH -BITBOX.BitcoinCash.toBitcoinCash(900000000) +bitbox.BitcoinCash.toBitcoinCash(900000000) // 9 // convert 4242323400 satoshis to 42423234 bits -BITBOX.BitcoinCash.satsToBits(4242323400) +bitbox.BitcoinCash.satsToBits(4242323400) // 42423234`} @@ -231,7 +231,7 @@ BITBOX.BitcoinCash.satsToBits(4242323400) {` // list all op codes -BITBOX.Script.opcodes; +bitbox.Script.opcodes; // { OP_FALSE: 0, // OP_0: 0, // OP_PUSHDATA1: 76, @@ -248,11 +248,11 @@ BITBOX.Script.opcodes; // } // get the op code for a word -BITBOX.Script.opcodes.OP_SPLIT +bitbox.Script.opcodes.OP_SPLIT // 127 -BITBOX.Script.opcodes.OP_NUM2BIN +bitbox.Script.opcodes.OP_NUM2BIN // 128 -BITBOX.Script.opcodes.OP_BIN2NUM +bitbox.Script.opcodes.OP_BIN2NUM // 129`} diff --git a/src/pages/develop.js b/src/pages/develop.js index cc8a148d..6ab17254 100644 --- a/src/pages/develop.js +++ b/src/pages/develop.js @@ -84,6 +84,12 @@ const DevelopPage = ({ location, data }: Props) => ( text="Tokenize anything. Everything you need to easily issue, spend or trade your own token." cta="View" /> + ( + + + + + diff --git a/src/pages/slp.js b/src/pages/slp.js index 19ea14bc..37b32d3e 100644 --- a/src/pages/slp.js +++ b/src/pages/slp.js @@ -8,6 +8,8 @@ import DefaultLayout from 'components/layouts/DefaultLayout' import Hero from 'components/Hero' import Container from 'components/Container' import HelmetPlus from 'components/HelmetPlus' +import { FaAndroid, FaApple, FaJs } from 'react-icons/fa' +import InfoCard from 'components/InfoCard' import Text from 'atoms/Text' import H3 from 'atoms/H3' @@ -15,21 +17,35 @@ import H1 from 'atoms/H1' import Button from 'atoms/Button' import Code from 'atoms/Code' import StyledLink from 'atoms/StyledLink' +import { SmartLink } from 'atoms/StyledLink' import media from 'styles/media' import spacing from 'styles/spacing' +const CardLayout = styled.div` + display: grid; + padding-top: ${spacing.large}; + grid-gap: ${spacing.medium}; + grid-template-columns: 1fr; + ${media.medium` + grid-template-columns: repeat(auto-fit, minmax(400px, .5fr)); + `}; +` + const HeroLayout = styled.div` display: grid; grid-gap: ${spacing.tiny}; ` -const InstallCTA = styled.div` - margin-top: ${spacing.medium}; - display: grid; - grid-auto-flow: dense; - grid-template-columns: max-content; - grid-gap: ${spacing.small}; +const HeroButtonLayout = styled.div` + display: flex; + flex-direction: row; + flex-wrap: wrap; +` + +const HeroButtonItem = styled.div` + margin-right: ${spacing.small}; + margin-bottom: ${spacing.small}; ` const PreviewLayout = styled.div` @@ -98,13 +114,23 @@ const SLPPage = ({ location, data }: Props) => (

Secure Tokens on Bitcoin Cash

- - INSTALL VIA NPM - {`npm install slp-sdk --global`} - - - - + + + + Javascript + + + + + Android + + + + + iOS + + + @@ -112,112 +138,51 @@ const SLPPage = ({ location, data }: Props) => (

Simple Ledger Protocol

- SLP SDK is a fully featured javascript framework powered by{' '} - BITBOX. Everything you need to - easily issue, spend or trade your own token. + + Simple Ledger Protocol + {' '} + is simple, robust and extensible. All transactions are 100% on the + blockchain for full auditability by any party. The first and + currently only BCH token system to support light wallets. You can + use multi signature addresses and other advanced Bitcoin script + features with SLP tokens. +
+ +
+ + + +

+ Javascript +

- Simple Ledger Protocol is simple, robust and extensible. All - transactions are 100% on the blockchain for full auditability by any - party. The first and currently only BCH token system to support - light wallets. You can use multi signature addresses and other - Bitcoin script features with SLP tokens. + SLP SDK is a fully featured javascript framework powered by{' '} + BITBOX. Everything you need to + easily issue, spend or trade your own token. Install via NPM and + talk to Bitcoin.com's cloud with no further setup.{' '}
- -

List

- List all tokens - - {`(async () => { - try { - let list = await SLP.Utils.list(); - console.log(list); - } catch (error) { - console.error(error); - } -})(); - -// returns -[ { id: 'a72788409fa0ff38556e0d26d17edcc8e6ac04dcdc4904eeb5297c6096dc6e75', - timestamp: '2019-02-10 03:24', - symbol: 'C', - name: 'Contract Name', - documentUri: 'documentUri', - documentHash: - '1000000000000000000000000000000000000000000000000000000000000001', - decimals: 1, - initialTokenQty: 10 }, - { id: 'e6fe00fc1f53320b72bd5cbed76c0c82e5edfea1b6f9cb0f71bfb28c3b6211a8', - timestamp: '2019-02-05 04:01', - symbol: 'TESTNET3', - name: 'SLP SDK Testnet Token 3', - documentUri: 'badger@bitcoin.com', - documentHash: '', - decimals: 8, - initialTokenQty: 100 }] -`} - - List single token by id - - {`(async () => { - try { - let list = await SLP.Utils.list( - "b3f4f132dc3b9c8c96316346993a8d54d729715147b7b11aa6c8cd909e955313" - ); - console.log(list); - } catch (error) { - console.error(error); - } -})(); - -// returns -{ id: 'b3f4f132dc3b9c8c96316346993a8d54d729715147b7b11aa6c8cd909e955313', - timestamp: '2019-01-30 21:56', - symbol: 'SLPJS', - name: 'Awesome SLPJS README Token', - documentUri: 'info@simpleledger.io', - documentHash: '', - decimals: 2, - initialTokenQty: 1000000 } -`} - -
- -

Conversion

- Convert between slp, cashAddr and legacyAddr addresses - - {`// cash address to slp address - SLP.Address.toSLPAddress('bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl') - // simpleledger:qzm47qz5ue99y9yl4aca7jnz7dwgdenl857dzayzdp - - // legacy address to cash address - SLP.Address.toCashAddress('1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN') - // bitcoincash:qzm47qz5ue99y9yl4aca7jnz7dwgdenl85jkfx3znl - - // slp address to legacy address - SLP.Address.toLegacyAddress('simpleledger:qzm47qz5ue99y9yl4aca7jnz7dwgdenl857dzayzdp') - // 1HiaTupadqQN66Tvgt7QSE5Wg13BUy25eN -`} - -
- -

Built-in console

+ +

+ Android +

- Custom REPL with the full BITBOX and Bitcoin Cash JSON RPC API built - in. Test your ideas quickly with no overhead. + Install via Gradle. Convert between cash and slp address formats. + Send tokens w/ balances, including both tokens and BCH, available as + LiveData. Convenience methods to make it easier to display tokens. + Timber for logging.
- -

100% Documented

+ +

+ iOS +

- Every method, argument, data type and return value is documented in - great detail. + Install via CocoaPods. Generate mnemonics. Convert between cash and + slp address formats. Send tokens and fetch token balances.
- -

REST integration

- SLP SDK is coupled to REST with no further setup. -
diff --git a/src/templates/docPage.js b/src/templates/docPage.js index 9e4a0c0b..5174441d 100644 --- a/src/templates/docPage.js +++ b/src/templates/docPage.js @@ -131,7 +131,8 @@ class DocTemplate extends React.PureComponent { badger: '/badger/docs/getting-started', gui: '/gui/docs/getting-started', rest: '/rest/docs/getting-started', - slp: '/slp/docs/getting-started', + slp: '/slp/docs/js/getting-started', + cashscript: '/cashscript/docs/getting-started', }[event.target.value] pageTarget && push(pageTarget) @@ -181,6 +182,9 @@ class DocTemplate extends React.PureComponent { + diff --git a/src/utils/formatting.js b/src/utils/formatting.js index 07512105..09f16edb 100644 --- a/src/utils/formatting.js +++ b/src/utils/formatting.js @@ -6,6 +6,7 @@ const titleMap = { gui: 'GUI', slp: 'SLP', badger: 'Badger', + cashscript: 'CashScript', other: 'Other', } export const getTitleDisplay = (product: string) => { diff --git a/src/utils/icon-helpers.js b/src/utils/icon-helpers.js index cf1c2929..e45c6a0a 100644 --- a/src/utils/icon-helpers.js +++ b/src/utils/icon-helpers.js @@ -4,7 +4,9 @@ import * as React from 'react' // https://react-icons.netlify.com/#/ import { + FaAndroid, FaAngleRight, + FaApple, FaArrowsAltV, FaBtc, FaBuromobelexperte, @@ -23,6 +25,7 @@ import { FaGamepad, FaHdd, FaHome, + FaJs, FaKey, FaLink, FaPlug, @@ -37,12 +40,18 @@ import { // Whitelist of valid icons export const getIcon = (icon: string): React.Node => { switch (icon) { + case 'android': + return + case 'ios': + return case 'elipses': return case 'plus': return case 'home': return + case 'js': + return case 'terminal': return case 'file': diff --git a/yarn.lock b/yarn.lock index f664975c..f015e1ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1475,13 +1475,6 @@ babel-eslint@^9.0.0: eslint-scope "3.7.1" eslint-visitor-keys "^1.0.0" -babel-extract-comments@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/babel-extract-comments/-/babel-extract-comments-1.0.0.tgz#0a2aedf81417ed391b85e18b4614e693a0351a21" - integrity sha512-qWWzi4TlddohA91bFwgt6zO/J0X+io7Qp184Fw0m2JYRSTZnJbFR8+07KmzudHCZgOiKRCrjhylwv9Xd8gfhVQ== - dependencies: - babylon "^6.18.0" - babel-loader@^8.0.0: version "8.0.5" resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.0.5.tgz#225322d7509c2157655840bba52e46b6c2f2fe33" @@ -1537,24 +1530,11 @@ babel-plugin-syntax-jsx@^6.18.0: resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946" integrity sha1-CvMqmm4Tyno/1QaeYtew9Y0NiUY= -babel-plugin-syntax-object-rest-spread@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5" - integrity sha1-/WU28rzhODb/o6VFjEkDpZe7O/U= - babel-plugin-syntax-trailing-function-commas@^7.0.0-beta.0: version "7.0.0-beta.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-7.0.0-beta.0.tgz#aa213c1435e2bffeb6fca842287ef534ad05d5cf" integrity sha512-Xj9XuRuz3nTSbaTXWv3itLOcxyF4oPD8douBBmj7U9BBC6nEBYfyOJYQMf/8PJAFotC62UY5dFfIGEPr7WswzQ== -babel-plugin-transform-object-rest-spread@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz#0f36692d50fef6b7e2d4b3ac1478137a963b7b06" - integrity sha1-DzZpLVD+9rfi1LOsFHgTepY7ewY= - dependencies: - babel-plugin-syntax-object-rest-spread "^6.8.0" - babel-runtime "^6.26.0" - babel-preset-fbjs@^3.1.2: version "3.2.0" resolved "https://registry.yarnpkg.com/babel-preset-fbjs/-/babel-preset-fbjs-3.2.0.tgz#c0e6347d3e0379ed84b3c2434d3467567aa05297" @@ -1608,11 +1588,6 @@ babel-runtime@^6.26.0: core-js "^2.4.0" regenerator-runtime "^0.11.0" -babylon@^6.18.0: - version "6.18.0" - resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" - integrity sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ== - backo2@1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" @@ -4745,17 +4720,6 @@ gatsby-plugin-manifest@^2.0.19: bluebird "^3.5.0" sharp "^0.21.3" -gatsby-plugin-offline@^2.0.24: - version "2.0.24" - resolved "https://registry.yarnpkg.com/gatsby-plugin-offline/-/gatsby-plugin-offline-2.0.24.tgz#75034a9c658fbd55391e077fa8f40de4cb5e0ba9" - integrity sha512-TNXEstqpHttlFPQiEvsVTlqm+O4KMhuPoG//blr5z75Y1c8RCNmjJqZHsxCvEhjp/tS3C2LcWb93pUIKNV5jNg== - dependencies: - "@babel/runtime" "^7.0.0" - cheerio "^1.0.0-rc.2" - idb-keyval "^3.1.0" - lodash "^4.17.10" - workbox-build "^3.6.3" - gatsby-plugin-page-creator@^2.0.8: version "2.0.8" resolved "https://registry.yarnpkg.com/gatsby-plugin-page-creator/-/gatsby-plugin-page-creator-2.0.8.tgz#9dfe7df93bca06a898ce29d5701aedf85d1f23f2" @@ -4778,6 +4742,11 @@ gatsby-plugin-react-helmet@^3.0.7: dependencies: "@babel/runtime" "^7.0.0" +gatsby-plugin-remove-serviceworker@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/gatsby-plugin-remove-serviceworker/-/gatsby-plugin-remove-serviceworker-1.0.0.tgz#9fb433bc8bd766e14e1d3711c4ac6f051e1dff7c" + integrity sha1-n7QzvIvXZuFOHTcRxKxvBR4d/3w= + gatsby-plugin-robots-txt@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/gatsby-plugin-robots-txt/-/gatsby-plugin-robots-txt-1.4.0.tgz#2da3fb60a307f83b34a9fbdd85fdb4e6a53e431a" @@ -5096,11 +5065,6 @@ get-caller-file@^1.0.1: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w== -get-own-enumerable-property-symbols@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.0.tgz#b877b49a5c16aefac3655f2ed2ea5b684df8d203" - integrity sha512-CIJYJC4GGF06TakLg8z4GQKvDsx9EMspVxOYih7LerEL/WosUnFIww45CGfxfeKHqlg3twgUrYRT1O3WQqjGCg== - get-port@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc" @@ -5851,11 +5815,6 @@ icss-utils@^2.1.0: dependencies: postcss "^6.0.1" -idb-keyval@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-3.1.0.tgz#cce9ed320734446784d52ed398c4b075a4273f51" - integrity sha512-iFwFN5n00KNNnVxlOOK280SJJfXWY7pbMUOQXdIXehvvc/mGCV/6T2Ae+Pk2KwAkkATDTwfMavOiDH5lrJKWXQ== - ieee754@^1.1.4: version "1.1.12" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.12.tgz#50bf24e5b9c8bb98af4964c941cdb0918da7b60b" @@ -6390,7 +6349,7 @@ is-number@^3.0.0: dependencies: kind-of "^3.0.2" -is-obj@^1.0.0, is-obj@^1.0.1: +is-obj@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f" integrity sha1-PkcprB9f3gJc19g6iW2rn09n2w8= @@ -6453,11 +6412,6 @@ is-regex@^1.0.4: dependencies: has "^1.0.1" -is-regexp@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/is-regexp/-/is-regexp-1.0.0.tgz#fd2d883545c46bac5a633e7b9a09e87fa2cb5069" - integrity sha1-/S2INUXEa6xaYz57mgnof6LLUGk= - is-relative-url@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-relative-url/-/is-relative-url-2.0.0.tgz#72902d7fe04b3d4792e7db15f9db84b7204c9cef" @@ -6646,15 +6600,6 @@ joi@12.x.x: isemail "3.x.x" topo "2.x.x" -joi@^11.1.1: - version "11.4.0" - resolved "https://registry.yarnpkg.com/joi/-/joi-11.4.0.tgz#f674897537b625e9ac3d0b7e1604c828ad913ccb" - integrity sha512-O7Uw+w/zEWgbL6OcHbyACKSj0PkQeUgmehdoXVSxt92QFCq4+1390Rwh5moI2K/OgC7D8RHRZqHZxT2husMJHA== - dependencies: - hoek "4.x.x" - isemail "3.x.x" - topo "2.x.x" - jpeg-js@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.2.0.tgz#53e448ec9d263e683266467e9442d2c5a2ef5482" @@ -6969,11 +6914,6 @@ lockfile@^1.0.4: dependencies: signal-exit "^3.0.2" -lodash._reinterpolate@~3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" - integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0= - lodash.clonedeep@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" @@ -7064,21 +7004,6 @@ lodash.repeat@^4.1.0: resolved "https://registry.yarnpkg.com/lodash.repeat/-/lodash.repeat-4.1.0.tgz#fc7de8131d8c8ac07e4b49f74ffe829d1f2bec44" integrity sha1-/H3oEx2MisB+S0n3T/6CnR8r7EQ= -lodash.template@^4.4.0: - version "4.4.0" - resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0" - integrity sha1-5zoDhcg1VZF0bgILmWecaQ5o+6A= - dependencies: - lodash._reinterpolate "~3.0.0" - lodash.templatesettings "^4.0.0" - -lodash.templatesettings@^4.0.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/lodash.templatesettings/-/lodash.templatesettings-4.1.0.tgz#2b4d4e95ba440d915ff08bc899e4553666713316" - integrity sha1-K01OlbpEDZFf8IvImeRVNmZxMxY= - dependencies: - lodash._reinterpolate "~3.0.0" - lodash.toarray@^4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/lodash.toarray/-/lodash.toarray-4.4.0.tgz#24c4bfcd6b2fba38bfd0594db1179d8e9b656561" @@ -10835,15 +10760,6 @@ stringify-entities@^1.0.1: is-alphanumerical "^1.0.0" is-hexadecimal "^1.0.0" -stringify-object@^3.2.2: - version "3.3.0" - resolved "https://registry.yarnpkg.com/stringify-object/-/stringify-object-3.3.0.tgz#703065aefca19300d3ce88af4f5b3956d7556629" - integrity sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw== - dependencies: - get-own-enumerable-property-symbols "^3.0.0" - is-obj "^1.0.1" - is-regexp "^1.0.0" - strip-ansi@3.0.1, strip-ansi@^3.0.0, strip-ansi@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" @@ -10882,14 +10798,6 @@ strip-bom@^3.0.0: resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" integrity sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM= -strip-comments@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/strip-comments/-/strip-comments-1.0.2.tgz#82b9c45e7f05873bee53f37168af930aa368679d" - integrity sha512-kL97alc47hoyIQSV165tTt9rG5dn4w1dNnBhOQ3bOU1Nc1hel09jnXANaHJ7vzHLd4Ju8kseDGzlev96pghLFw== - dependencies: - babel-extract-comments "^1.0.0" - babel-plugin-transform-object-rest-spread "^6.26.0" - strip-dirs@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/strip-dirs/-/strip-dirs-2.1.0.tgz#4987736264fc344cf20f6c34aca9d13d1d4ed6c5" @@ -11982,124 +11890,6 @@ wordwrap@~1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus= -workbox-background-sync@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-background-sync/-/workbox-background-sync-3.6.3.tgz#6609a0fac9eda336a7c52e6aa227ba2ae532ad94" - integrity sha512-ypLo0B6dces4gSpaslmDg5wuoUWrHHVJfFWwl1udvSylLdXvnrfhFfriCS42SNEe5lsZtcNZF27W/SMzBlva7Q== - dependencies: - workbox-core "^3.6.3" - -workbox-broadcast-cache-update@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-broadcast-cache-update/-/workbox-broadcast-cache-update-3.6.3.tgz#3f5dff22ada8c93e397fb38c1dc100606a7b92da" - integrity sha512-pJl4lbClQcvp0SyTiEw0zLSsVYE1RDlCPtpKnpMjxFtu8lCFTAEuVyzxp9w7GF4/b3P4h5nyQ+q7V9mIR7YzGg== - dependencies: - workbox-core "^3.6.3" - -workbox-build@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-build/-/workbox-build-3.6.3.tgz#77110f9f52dc5d82fa6c1c384c6f5e2225adcbd8" - integrity sha512-w0clZ/pVjL8VXy6GfthefxpEXs0T8uiRuopZSFVQ8ovfbH6c6kUpEh6DcYwm/Y6dyWPiCucdyAZotgjz+nRz8g== - dependencies: - babel-runtime "^6.26.0" - common-tags "^1.4.0" - fs-extra "^4.0.2" - glob "^7.1.2" - joi "^11.1.1" - lodash.template "^4.4.0" - pretty-bytes "^4.0.2" - stringify-object "^3.2.2" - strip-comments "^1.0.2" - workbox-background-sync "^3.6.3" - workbox-broadcast-cache-update "^3.6.3" - workbox-cache-expiration "^3.6.3" - workbox-cacheable-response "^3.6.3" - workbox-core "^3.6.3" - workbox-google-analytics "^3.6.3" - workbox-navigation-preload "^3.6.3" - workbox-precaching "^3.6.3" - workbox-range-requests "^3.6.3" - workbox-routing "^3.6.3" - workbox-strategies "^3.6.3" - workbox-streams "^3.6.3" - workbox-sw "^3.6.3" - -workbox-cache-expiration@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-cache-expiration/-/workbox-cache-expiration-3.6.3.tgz#4819697254a72098a13f94b594325a28a1e90372" - integrity sha512-+ECNph/6doYx89oopO/UolYdDmQtGUgo8KCgluwBF/RieyA1ZOFKfrSiNjztxOrGJoyBB7raTIOlEEwZ1LaHoA== - dependencies: - workbox-core "^3.6.3" - -workbox-cacheable-response@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-cacheable-response/-/workbox-cacheable-response-3.6.3.tgz#869f1a68fce9063f6869ddbf7fa0a2e0a868b3aa" - integrity sha512-QpmbGA9SLcA7fklBLm06C4zFg577Dt8u3QgLM0eMnnbaVv3rhm4vbmDpBkyTqvgK/Ly8MBDQzlXDtUCswQwqqg== - dependencies: - workbox-core "^3.6.3" - -workbox-core@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-core/-/workbox-core-3.6.3.tgz#69abba70a4f3f2a5c059295a6f3b7c62bd00e15c" - integrity sha512-cx9cx0nscPkIWs8Pt98HGrS9/aORuUcSkWjG25GqNWdvD/pSe7/5Oh3BKs0fC+rUshCiyLbxW54q0hA+GqZeSQ== - -workbox-google-analytics@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-google-analytics/-/workbox-google-analytics-3.6.3.tgz#99df2a3d70d6e91961e18a6752bac12e91fbf727" - integrity sha512-RQBUo/6SXtIaQTRFj4RQZ9e1gAl7D8oS5S+Hi173Kk70/BgJjzPwXpC5A249Jv5YfkCOLMQCeF9A27BiD0b0ig== - dependencies: - workbox-background-sync "^3.6.3" - workbox-core "^3.6.3" - workbox-routing "^3.6.3" - workbox-strategies "^3.6.3" - -workbox-navigation-preload@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-navigation-preload/-/workbox-navigation-preload-3.6.3.tgz#a2c34eb7c17e7485b795125091215f757b3c4964" - integrity sha512-dd26xTX16DUu0i+MhqZK/jQXgfIitu0yATM4jhRXEmpMqQ4MxEeNvl2CgjDMOHBnCVMax+CFZQWwxMx/X/PqCw== - dependencies: - workbox-core "^3.6.3" - -workbox-precaching@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-precaching/-/workbox-precaching-3.6.3.tgz#5341515e9d5872c58ede026a31e19bafafa4e1c1" - integrity sha512-aBqT66BuMFviPTW6IpccZZHzpA8xzvZU2OM1AdhmSlYDXOJyb1+Z6blVD7z2Q8VNtV1UVwQIdImIX+hH3C3PIw== - dependencies: - workbox-core "^3.6.3" - -workbox-range-requests@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-range-requests/-/workbox-range-requests-3.6.3.tgz#3cc21cba31f2dd8c43c52a196bcc8f6cdbcde803" - integrity sha512-R+yLWQy7D9aRF9yJ3QzwYnGFnGDhMUij4jVBUVtkl67oaVoP1ymZ81AfCmfZro2kpPRI+vmNMfxxW531cqdx8A== - dependencies: - workbox-core "^3.6.3" - -workbox-routing@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-routing/-/workbox-routing-3.6.3.tgz#659cd8f9274986cfa98fda0d050de6422075acf7" - integrity sha512-bX20i95OKXXQovXhFOViOK63HYmXvsIwZXKWbSpVeKToxMrp0G/6LZXnhg82ijj/S5yhKNRf9LeGDzaqxzAwMQ== - dependencies: - workbox-core "^3.6.3" - -workbox-strategies@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-strategies/-/workbox-strategies-3.6.3.tgz#11a0dc249a7bc23d3465ec1322d28fa6643d64a0" - integrity sha512-Pg5eulqeKet2y8j73Yw6xTgLdElktcWExGkzDVCGqfV9JCvnGuEpz5eVsCIK70+k4oJcBCin9qEg3g3CwEIH3g== - dependencies: - workbox-core "^3.6.3" - -workbox-streams@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-streams/-/workbox-streams-3.6.3.tgz#beaea5d5b230239836cc327b07d471aa6101955a" - integrity sha512-rqDuS4duj+3aZUYI1LsrD2t9hHOjwPqnUIfrXSOxSVjVn83W2MisDF2Bj+dFUZv4GalL9xqErcFW++9gH+Z27w== - dependencies: - workbox-core "^3.6.3" - -workbox-sw@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/workbox-sw/-/workbox-sw-3.6.3.tgz#278ea4c1831b92bbe2d420da8399176c4b2789ff" - integrity sha512-IQOUi+RLhvYCiv80RP23KBW/NTtIvzvjex28B8NW1jOm+iV4VIu3VXKXTA6er5/wjjuhmtB28qEAUqADLAyOSg== - worker-farm@^1.5.2: version "1.6.0" resolved "https://registry.yarnpkg.com/worker-farm/-/worker-farm-1.6.0.tgz#aecc405976fab5a95526180846f0dba288f3a4a0"