-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
chore(bitgo): add .prettierrc.yml
- Loading branch information
Showing
87 changed files
with
7,642 additions
and
5,280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.json | ||
*.yml | ||
CHANGELOG.md | ||
CHANGELOG.md | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
printWidth: 120 | ||
singleQuote: true | ||
trailingComma: 'es5' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ Please email us at [email protected] if you have questions or comments about thi | |
|
||
[![Known Vulnerabilities](https://snyk.io/test/github/BitGo/BitGoJS/badge.svg)](https://snyk.io/test/github/BitGo/BitGoJS) | ||
[![BitGo SDK](https://github.com/BitGo/BitGoJS/actions/workflows/ci.yml/badge.svg)](https://github.com/BitGo/BitGoJS/actions/workflows/ci.yml) | ||
|
||
# Installation | ||
|
||
Please make sure you are running at least Node version 8 (the latest LTS release is recommended) and NPM version 6. | ||
|
@@ -29,7 +30,9 @@ You can find the complete release notes (since version 4.44.0) [here](https://gi | |
# Example Usage | ||
|
||
## Initialize SDK | ||
|
||
Create an access token by logging into your bitgo account, going to the API access tab [in the settings area](https://www.bitgo.com/settings) and making a developer token. | ||
|
||
```js | ||
const BitGo = require('bitgo'); | ||
const bitgo = new BitGo.BitGo({ accessToken: ACCESS_TOKEN }); // defaults to testnet. add env: 'prod' if you want to go against mainnet | ||
|
@@ -38,37 +41,42 @@ console.dir(result); | |
``` | ||
|
||
## Create Wallet | ||
|
||
```js | ||
const params = { | ||
"passphrase": "replaceme", | ||
"label": "firstwallet" | ||
passphrase: 'replaceme', | ||
label: 'firstwallet', | ||
}; | ||
const { wallet } = await bitgo.coin('tbtc').wallets().generateWallet(params); | ||
console.dir(wallet); | ||
``` | ||
|
||
## Create new address | ||
|
||
```js | ||
const address = await wallet.createAddress(); | ||
console.dir(address); | ||
``` | ||
|
||
## View wallet transfers | ||
|
||
```js | ||
const transfers = await wallet.transfers(); | ||
``` | ||
|
||
## Send coins | ||
|
||
```js | ||
const result = await wallet.sendCoins({ | ||
address: "2NEe9QhKPB2gnQLB3hffMuDcoFKZFjHYJYx", | ||
address: '2NEe9QhKPB2gnQLB3hffMuDcoFKZFjHYJYx', | ||
amount: 0.01 * 1e8, | ||
walletPassphrase: "replaceme" | ||
walletPassphrase: 'replaceme', | ||
}); | ||
console.dir(result); | ||
``` | ||
|
||
## More examples | ||
|
||
Further demos and examples in both JavaScript and TypeScript can be found in the [example](example) directory. | ||
|
||
# Enabling additional debugging output | ||
|
@@ -78,21 +86,23 @@ Further demos and examples in both JavaScript and TypeScript can be found in the | |
When using the `bitgo` npm package, the easiest way to enable debug output is by setting the `DEBUG` environment variable to one or more of the debug namespaces in the table below. Multiple debug namespaces can be enabled by giving a comma-separated list or by using `*` as a wildcard. See the [debug package documentation](https://github.com/visionmedia/debug#readme) for more details. | ||
|
||
## Available Debug Namespaces | ||
| Namespace | Description | | ||
| --- | --- | | ||
| `bitgo:index` | Core BitGo object. Currently only constant fetch failures and HMAC response failures will emit debug information for this namespace. | | ||
| `bitgo:v1:txb` | Version 1 (legacy) transaction builder | | ||
| `bitgo:v2:pendingapprovals` | Pending approval operations. Currently only wallet fetch errors will emit debug information for this namespace. | | ||
| `bitgo:v2:wallet` | Wallet operations including transaction prebuild, sendMany calls and consolidation transactions | | ||
| `bitgo:v2:utxo` | Low level operations for UTXO coins, including transaction parsing, verification, signing and explanations | | ||
| `bitgo:v2:eth` | Ethereum specific output. Currently only failures to require the optional Ethereum libraries are reported | | ||
| `bitgo:v2:util` | SDK utilities specific output. Currently only failures to require the optional Ethereum libraries are reported | | ||
|
||
| Namespace | Description | | ||
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | | ||
| `bitgo:index` | Core BitGo object. Currently only constant fetch failures and HMAC response failures will emit debug information for this namespace. | | ||
| `bitgo:v1:txb` | Version 1 (legacy) transaction builder | | ||
| `bitgo:v2:pendingapprovals` | Pending approval operations. Currently only wallet fetch errors will emit debug information for this namespace. | | ||
| `bitgo:v2:wallet` | Wallet operations including transaction prebuild, sendMany calls and consolidation transactions | | ||
| `bitgo:v2:utxo` | Low level operations for UTXO coins, including transaction parsing, verification, signing and explanations | | ||
| `bitgo:v2:eth` | Ethereum specific output. Currently only failures to require the optional Ethereum libraries are reported | | ||
| `bitgo:v2:util` | SDK utilities specific output. Currently only failures to require the optional Ethereum libraries are reported | | ||
|
||
Another debug namespace which is not provided by BitGoJS but is helpful nonetheless is the `superagent` namespace, which will output all HTTP requests and responses (only the URL, not bodies). | ||
|
||
## Example | ||
|
||
To run an SDK script with debug output enabled, export the DEBUG environment variable before running. | ||
|
||
```shell script | ||
export DEBUG='bitgo:*' # enable all bitgo debug namespaces | ||
node myScript.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import { ethGasConfigs, mainnetTokens, testnetTokens, Tokens, tokens } from '@bitgo/statics'; | ||
import { Config, defaults, defaultConstants } from '@bitgo/sdk-core'; | ||
export { Config, defaultConstants, defaults, ethGasConfigs, mainnetTokens, testnetTokens, tokens, Tokens }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,51 @@ | ||
describe('BitGoJS in the browser', () => { | ||
it('Should work', () => { | ||
const BitGoJS = window['BitGoJS']; | ||
expect(BitGoJS).toBeTruthy(); | ||
}); | ||
it('Should work', () => { | ||
const BitGoJS = window['BitGoJS']; | ||
expect(BitGoJS).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('Coins', () => { | ||
it('Should work for all coins', () => { | ||
const BitGoJS = window['BitGoJS']; | ||
const bitgo = new BitGoJS.BitGo({ env: 'test' }); | ||
// these objects are defined in BitGoJS.Coin, but are not coins in the traditional sense | ||
const excludedKeys = { | ||
'AbstractUtxoCoin': 1, | ||
'Erc20Token': 1, | ||
'OfcToken': 1, | ||
'StellarToken': 1, | ||
'CeloToken': 1, | ||
'EosToken': 1, | ||
'AlgoToken': 1, | ||
'AvaxCToken': 1, | ||
'PolygonToken': 1, | ||
'BscToken': 1, | ||
}; | ||
Object.keys(BitGoJS.Coin) | ||
.filter((coinName) => !excludedKeys[coinName]) | ||
.forEach((coinName) => { | ||
const coinIdentifier = coinName.toLowerCase(); | ||
const coin = bitgo.coin(coinIdentifier); | ||
expect(coin).toBeTruthy(); | ||
expect(coin.type).toEqual(coinIdentifier); | ||
}) | ||
}) | ||
it('Should work for all coins', () => { | ||
const BitGoJS = window['BitGoJS']; | ||
const bitgo = new BitGoJS.BitGo({ env: 'test' }); | ||
// these objects are defined in BitGoJS.Coin, but are not coins in the traditional sense | ||
const excludedKeys = { | ||
AbstractUtxoCoin: 1, | ||
Erc20Token: 1, | ||
OfcToken: 1, | ||
StellarToken: 1, | ||
CeloToken: 1, | ||
EosToken: 1, | ||
AlgoToken: 1, | ||
AvaxCToken: 1, | ||
PolygonToken: 1, | ||
BscToken: 1, | ||
}; | ||
Object.keys(BitGoJS.Coin) | ||
.filter((coinName) => !excludedKeys[coinName]) | ||
.forEach((coinName) => { | ||
const coinIdentifier = coinName.toLowerCase(); | ||
const coin = bitgo.coin(coinIdentifier); | ||
expect(coin).toBeTruthy(); | ||
expect(coin.type).toEqual(coinIdentifier); | ||
}); | ||
}); | ||
|
||
it('UTXO bufferutils should work', () => { | ||
const BitGoJS = window['BitGoJS']; | ||
const bitgo = new BitGoJS.BitGo({ env: 'test' }); | ||
it('UTXO bufferutils should work', () => { | ||
const BitGoJS = window['BitGoJS']; | ||
const bitgo = new BitGoJS.BitGo({ env: 'test' }); | ||
|
||
const txHex = '0100000002008287fa5a4e9d393134b525ae038cbcb4c757eadaa378c33caeed294c63137f000000006b48304502204dc8131adb9420729ff1580bbbcf01f5ef879defee5225a8261b5681075b8a120221009dc3386f5301ab4a88dfd89d8927a7807242a30ee252fa864d61d0b079aaa2c20121038c4b3c81572d84ce32a2a41c5bb54d4c408b5ce3df9be451f4f57ba8bd8ebf59ffffffff17ed0cc32384bf9c410d023d4ab25f4499992824308e89c448fd570e1060fc0e000000006b48304502202c0ff069c0783c11259936307ef906b211542a01ca33cf6993ddb7b8d55b42ac02210095c4bceb1886f5bcc6ca2dbb909259c0509e768693a93fe2d01d511a57356f25012102e99ed9483d91f1fa67abd838f21afd80bf6a3732128ab5aad0ee5b975679c13dffffffff02bca2b100000000001976a914cc3aa0deca267914cbcf96f79ccd1b679d85e20188ac08c2eb0b000000001976a914380c5a7247e945a5aa242056f9b046a9366fe21788ac00000000'; | ||
const btc = bitgo.coin('btc'); | ||
const tx = btc.createTransactionFromHex(txHex); | ||
expect(tx.getId()).toEqual('4f666850ac8a54c834a90e62fc9dc50b3c99275dd1f91960e1ea89813970e444'); | ||
const txHex = | ||
'0100000002008287fa5a4e9d393134b525ae038cbcb4c757eadaa378c33caeed294c63137f000000006b48304502204dc8131adb9420729ff1580bbbcf01f5ef879defee5225a8261b5681075b8a120221009dc3386f5301ab4a88dfd89d8927a7807242a30ee252fa864d61d0b079aaa2c20121038c4b3c81572d84ce32a2a41c5bb54d4c408b5ce3df9be451f4f57ba8bd8ebf59ffffffff17ed0cc32384bf9c410d023d4ab25f4499992824308e89c448fd570e1060fc0e000000006b48304502202c0ff069c0783c11259936307ef906b211542a01ca33cf6993ddb7b8d55b42ac02210095c4bceb1886f5bcc6ca2dbb909259c0509e768693a93fe2d01d511a57356f25012102e99ed9483d91f1fa67abd838f21afd80bf6a3732128ab5aad0ee5b975679c13dffffffff02bca2b100000000001976a914cc3aa0deca267914cbcf96f79ccd1b679d85e20188ac08c2eb0b000000001976a914380c5a7247e945a5aa242056f9b046a9366fe21788ac00000000'; | ||
const btc = bitgo.coin('btc'); | ||
const tx = btc.createTransactionFromHex(txHex); | ||
expect(tx.getId()).toEqual('4f666850ac8a54c834a90e62fc9dc50b3c99275dd1f91960e1ea89813970e444'); | ||
|
||
const txHexBig = '0100000002008287fa5a4e9d393134b525ae038cbcb4c757eadaa378c33caeed294c63137f000000006b48304502204dc8131adb9420729ff1580bbbcf01f5ef879defee5225a8261b5681075b8a120221009dc3386f5301ab4a88dfd89d8927a7807242a30ee252fa864d61d0b079aaa2c20121038c4b3c81572d84ce32a2a41c5bb54d4c408b5ce3df9be451f4f57ba8bd8ebf59ffffffff17ed0cc32384bf9c410d023d4ab25f4499992824308e89c448fd570e1060fc0e000000006b48304502202c0ff069c0783c11259936307ef906b211542a01ca33cf6993ddb7b8d55b42ac02210095c4bceb1886f5bcc6ca2dbb909259c0509e768693a93fe2d01d511a57356f25012102e99ed9483d91f1fa67abd838f21afd80bf6a3732128ab5aad0ee5b975679c13dffffffff02f8ffc42ebca2b1001976a914cc3aa0deca267914cbcf96f79ccd1b679d85e20188ac08c2eb0b000000001976a914380c5a7247e945a5aa242056f9b046a9366fe21788ac00000000'; | ||
const doge = bitgo.coin('doge'); | ||
const txBig = doge.createTransactionFromHex(txHexBig); | ||
expect(txBig.outs[0].value.toString()).toEqual('49999999999999992'); | ||
}) | ||
const txHexBig = | ||
'0100000002008287fa5a4e9d393134b525ae038cbcb4c757eadaa378c33caeed294c63137f000000006b48304502204dc8131adb9420729ff1580bbbcf01f5ef879defee5225a8261b5681075b8a120221009dc3386f5301ab4a88dfd89d8927a7807242a30ee252fa864d61d0b079aaa2c20121038c4b3c81572d84ce32a2a41c5bb54d4c408b5ce3df9be451f4f57ba8bd8ebf59ffffffff17ed0cc32384bf9c410d023d4ab25f4499992824308e89c448fd570e1060fc0e000000006b48304502202c0ff069c0783c11259936307ef906b211542a01ca33cf6993ddb7b8d55b42ac02210095c4bceb1886f5bcc6ca2dbb909259c0509e768693a93fe2d01d511a57356f25012102e99ed9483d91f1fa67abd838f21afd80bf6a3732128ab5aad0ee5b975679c13dffffffff02f8ffc42ebca2b1001976a914cc3aa0deca267914cbcf96f79ccd1b679d85e20188ac08c2eb0b000000001976a914380c5a7247e945a5aa242056f9b046a9366fe21788ac00000000'; | ||
const doge = bitgo.coin('doge'); | ||
const txBig = doge.createTransactionFromHex(txHexBig); | ||
expect(txBig.outs[0].value.toString()).toEqual('49999999999999992'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// intercept & mock all the redudant calls to fetch constants by the browser | ||
(function(global) { | ||
const constants = {}; | ||
BitGoJS.BitGo.prototype.getConstants = (params) => constants; | ||
BitGoJS.BitGo.prototype.fetchConstants = (params, callback) => | ||
(function (global) { | ||
const constants = {}; | ||
BitGoJS.BitGo.prototype.getConstants = (params) => constants; | ||
BitGoJS.BitGo.prototype.fetchConstants = (params, callback) => | ||
new Promise((resolve) => { | ||
resolve({ | ||
...constants, | ||
}); | ||
}); | ||
})(window) | ||
})(window); |
Oops, something went wrong.