Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# BitGoSDK PHP

BitGoSDK written in PHP. This SDK contains methods for easily interacting with the BitGo API.
Expand All @@ -11,34 +10,32 @@ BitGoSDK written in PHP. This SDK contains methods for easily interacting with t

## Requirements

- PHP 7.4 or newer with the cURL extension
- PHP 7.4 or newer, with the cURL extension
- A BitGo account and an [access token](https://developers.bitgo.com/docs/get-started-access-tokens)
- A [BitGo Express](#bitgo-express) instance, for anything that needs your keys, such as creating wallets or sending

## Installation

To install the SDK, you will need to be using [Composer](http://getcomposer.org/) in your project. If you aren't using Composer yet, it's really simple! Here's how to install composer and the BitGoSDK PHP.
Install the SDK with [Composer](https://getcomposer.org/):

```sh
# Install Composer
curl -sS https://getcomposer.org/installer | php
composer require neto737/bitgosdk-php
```

Or add it to the `require` section of your `composer.json`:

# Add the BitGoSDK as a dependency
php composer.phar require neto737/bitgosdk-php
```json
"neto737/bitgosdk-php": "^2.3"
```

Next, require Composer's autoloader, in your application, to automatically load the BitGoSDK in your project:
Then load Composer's autoloader in your application:

```php
require 'vendor/autoload.php';

use neto737\BitGoSDK\BitGoSDK;
```

Or if put the following in your `composer.json`:

```json
"neto737/bitgosdk-php": "*"
```

## Example

```php
Expand All @@ -53,13 +50,25 @@ $bitgo->walletId = 'YOUR_WALLET_ID_HERE';
$createAddress = $bitgo->createWalletAddress();
```

More examples are in [`examples/`](examples/).

## BitGo Express

If you are going to use BitGo Express you have to run a BitGo Express node. You can find how to run your own BitGo Express node [here](https://github.com/BitGo/BitGoJS/blob/master/modules/express/README.md).
BitGo signs transactions on the client, so sending coins, creating wallets and other calls that use your keys go through `BitGoExpress`, which talks to your own BitGo Express instance. See [Install BitGo Express](https://developers.bitgo.com/docs/get-started-express-install) to run one, and the [Express API reference](https://developers.bitgo.com/reference/express-overview) for its endpoints.

## Documentation

- [BitGo developer portal](https://developers.bitgo.com/)
- [BitGo API reference](https://developers.bitgo.com/reference/overview)
- [Webhooks](https://developers.bitgo.com/docs/webhooks-overview) and [policies](https://developers.bitgo.com/docs/policies-overview)

## Attention

Keep your cacert.pem always up to date. You can find updates on the site [curl.haxx.se](https://curl.haxx.se/docs/caextract.html).
Keep your `cacert.pem` up to date. You can download the latest one from [curl.se](https://curl.se/docs/caextract.html).

## License

MIT. See [LICENSE](LICENSE). Versions 2.2.3 and earlier were released under GPL-3.0.

## Credits

Expand Down
54 changes: 0 additions & 54 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ parameters:
count: 1
path: src/BitGoExpress.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoExpress\:\:funoutWalletUnspents\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/BitGoExpress.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoExpress\:\:generateWallet\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down Expand Up @@ -174,12 +168,6 @@ parameters:
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:addBlockWebhook\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:addKeychain\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down Expand Up @@ -252,12 +240,6 @@ parameters:
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:getMaximumSpendable\(\) has invalid return type neto737\\BitGoSDK\\type\.$#'
identifier: class.notFound
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:getPendingApproval\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down Expand Up @@ -336,36 +318,12 @@ parameters:
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:getWebhookPayload\(\) has invalid return type neto737\\BitGoSDK\\type\.$#'
identifier: class.notFound
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:getWebhookPayload\(\) should return neto737\\BitGoSDK\\type but returns string\|false\.$#'
identifier: return.type
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:listBlockWebhooks\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:listKeychains\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:listPendingApprovals\(\) has invalid return type neto737\\BitGoSDK\\type\.$#'
identifier: class.notFound
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:listUserWebhooks\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down Expand Up @@ -414,12 +372,6 @@ parameters:
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:removeBlockWebhook\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:removePolicyRule\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down Expand Up @@ -450,12 +402,6 @@ parameters:
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:setRequestIP\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/BitGoSDK.php

-
message: '#^Method neto737\\BitGoSDK\\BitGoSDK\:\:setVelocityPolicyRule\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down
45 changes: 33 additions & 12 deletions src/BitGoExpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
*
* @package BitGoSDK PHP
* @author Neto Melo <neto737@live.com>
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3
* @version 2.2
* @license https://opensource.org/licenses/MIT MIT License
*/

namespace neto737\BitGoSDK;
Expand All @@ -24,10 +23,10 @@ class BitGoExpress
const DEFAULT_CONNECT_TIMEOUT = 10;

// Coin families for coin-specific params. Each lists mainnet and testnet codes, so testnet wallets get the same params.
private const UTXO_COINS = ['btc', 'tbtc', 'bch', 'tbch', 'btg', 'tbtg', 'dash', 'tdash', 'doge', 'tdoge', 'ltc', 'tltc', 'zec', 'tzec'];
private const BTC_COINS = ['btc', 'tbtc'];
private const SEGWIT_COINS = ['btc', 'tbtc', 'btg', 'tbtg', 'ltc', 'tltc'];
private const ETH_COINS = ['eth', 'teth', 'gteth', 'hteth'];
private const UTXO_COINS = ['btc', 'tbtc', 'tbtc4', 'tbtcsig', 'bch', 'tbch', 'btg', 'tbtg', 'dash', 'tdash', 'doge', 'tdoge', 'ltc', 'tltc', 'zec', 'tzec'];
private const BTC_COINS = ['btc', 'tbtc', 'tbtc4', 'tbtcsig'];
private const SEGWIT_COINS = ['btc', 'tbtc', 'tbtc4', 'tbtcsig', 'btg', 'tbtg', 'ltc', 'tltc'];
private const ETH_COINS = ['eth', 'teth', 'gteth', 'hteth', 'sepeth'];
private const XRP_COINS = ['xrp', 'txrp'];

private $APIEndpoint = null;
Expand All @@ -50,7 +49,7 @@ class BitGoExpress
*
* @param string $hostname Set the hostname of your BitGo Express instance. Prefix it with https:// if Express serves TLS.
* @param int $port Set the port of your BitGo Express instance
* @param string $coin Select the coin what you want to use with the BitGOSDK (use CurrencyCode class to select)
* @param string $coin Select the coin you want to use with the BitGoSDK (use CurrencyCode class to select)
* @throws \InvalidArgumentException if the hostname has a scheme other than http:// or https://
*/
public function __construct(string $hostname, int $port, string $coin = CurrencyCode::BITCOIN)
Expand Down Expand Up @@ -160,7 +159,8 @@ public function login(string $email, string $password, string $otp, ?bool $exten
}

/**
* Ping bitgo express to ensure that it is still running. Unlike /ping, this does not try connecting to bitgo.com.
* Ping BitGo through BitGo Express, to check that Express is running and can reach BitGo.
* Use pingExpress() to check Express alone.
*
* @return array
*/
Expand All @@ -170,6 +170,17 @@ public function ping()
return $this->__execute('GET');
}

/**
* Ping BitGo Express to ensure that it is still running. Unlike ping(), this does not try connecting to bitgo.com.
*
* @return array<string, mixed>
*/
public function pingExpress()
{
$this->url = $this->AuthAPIEndpoint . '/pingexpress';
return $this->__execute('GET');
}

/**
* This API call creates a new wallet.
*
Expand Down Expand Up @@ -384,9 +395,9 @@ public function consolidateWalletUnspents(string $walletPassphrase, ?int $numUns
* @param bool $enforceMinConfirmsForChange Apply the required confirmations set in minConfirms for change outputs
* @param int $feeRate The desired fee rate for the transaction in satoshis/kB
* @param int $feeTxConfirmTarget Fee rate is automatically chosen by targeting a transaction confirmation in this number of blocks (Only available on BTC, feeRate takes precedence if also set)
* @return array
* @return array<string, mixed>
*/
public function funoutWalletUnspents(string $walletPassphrase, ?string $xprv = null, ?int $maxNumInputsToUse = null, ?int $numUnspentsToMake = null, ?int $minValue = null, ?int $maxValue = null, ?int $minHeight = null, ?int $maxFeePercentage = null, ?int $minConfirms = null, ?bool $enforceMinConfirmsForChange = null, ?int $feeRate = null, ?int $feeTxConfirmTarget = null)
public function fanoutWalletUnspents(string $walletPassphrase, ?string $xprv = null, ?int $maxNumInputsToUse = null, ?int $numUnspentsToMake = null, ?int $minValue = null, ?int $maxValue = null, ?int $minHeight = null, ?int $maxFeePercentage = null, ?int $minConfirms = null, ?bool $enforceMinConfirmsForChange = null, ?int $feeRate = null, ?int $feeTxConfirmTarget = null)
{
$this->url = $this->APIEndpoint . '/wallet/' . $this->walletId . '/fanoutunspents';
$this->params = [
Expand All @@ -407,7 +418,17 @@ public function funoutWalletUnspents(string $walletPassphrase, ?string $xprv = n
}

/**
* his SDK call attempts to move all of the funds of the wallet into the address provided.
* @deprecated 2.3.0 Misspelled. Use fanoutWalletUnspents(), which takes the same arguments.
*
* @return array<string, mixed>
*/
public function funoutWalletUnspents(string $walletPassphrase, ?string $xprv = null, ?int $maxNumInputsToUse = null, ?int $numUnspentsToMake = null, ?int $minValue = null, ?int $maxValue = null, ?int $minHeight = null, ?int $maxFeePercentage = null, ?int $minConfirms = null, ?bool $enforceMinConfirmsForChange = null, ?int $feeRate = null, ?int $feeTxConfirmTarget = null)
{
return $this->fanoutWalletUnspents($walletPassphrase, $xprv, $maxNumInputsToUse, $numUnspentsToMake, $minValue, $maxValue, $minHeight, $maxFeePercentage, $minConfirms, $enforceMinConfirmsForChange, $feeRate, $feeTxConfirmTarget);
}

/**
* This SDK call attempts to move all of the funds of the wallet into the address provided.
*
* @param string $address The address to send all the funds in the wallet to.
* @param string $walletPassphrase Passphrase to decrypt the wallet’s private key.
Expand Down Expand Up @@ -508,7 +529,7 @@ public function signBuildTransaction($txPrebuild, ?string $prv = null, ?string $
* @param object $halfSigned The half-signed info returned from 'Sign Transaction’
* @param string $otp The current 2FA code
* @param string $txHex The half-signed, serialized transaction hex (alternative to halfSigned)
* @param string $comment Any additional comment to attach to the transaaction
* @param string $comment Any additional comment to attach to the transaction
* @return array
*/
public function sendBuildTransaction($halfSigned, string $otp, ?string $txHex = null, ?string $comment = null)
Expand Down
Loading
Loading