#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./check-address-tca.php <address> <rules>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// get vars
$address = $argv[1];
$rules = json_decode($argv[2], true);
// check
echo "Checking address {$address} with rules: " . json_encode($rules) . "\n";
$result = $api->checkAddressTokenAccess($address, $rules);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
}
// show the results
echo "\$result: " . json_encode($result, 192) . "\n";
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./provisional-delete-tx.php <promise_id>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// get vars
$promise_id = $argv[1];
// check
echo "deleting provisional tx for promise_id {$promise_id}\n";
$result = $api->deletePromisedTransaction($promise_id);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
}
// show the results
echo "\$result: " . json_encode($result, 192) . "\n";
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./address-register.php <oauth_token> <address> <label>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
$oauth_token = $argv[1];
$address = $argv[2];
$label = $argv[3];
if (!$oauth_token) {
    throw new Exception("oauth_token is required", 1);
}
if (!$address) {
    throw new Exception("address is required", 1);
}
if (!$label) {
    throw new Exception("label is required", 1);
}
// check
echo "registering address for token " . substr($oauth_token, 0, 4) . "...\n";
$result = $api->registerAddress($address, $oauth_token, $label, $public = true, $active = true);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./provisional-submit-tx.php <source> <destination> <token> <amount>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// get vars
$source = $argv[1];
$destination = $argv[2];
$token = $argv[3];
$amount = $argv[4];
if (!$source) {
    throw new Exception("source is required", 1);
}
if (!$destination) {
    throw new Exception("destination is required", 1);
}
if (!$token) {
    throw new Exception("token is required", 1);
}
if (!$amount) {
    throw new Exception("amount is required", 1);
}
// check
echo "promising {$source}, {$destination}, {$token}, {$amount}\n";
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./provisional-delete-source-address.php <address>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// get vars
$address = $argv[1];
if (!$address) {
    throw new Exception("Address is required", 1);
}
// check
echo "delete {$address}\n";
$result = $api->deleteProvisionalSource($address);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
}
// show the results
echo "\$result: " . json_encode($result, 192) . "\n";
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./generate-oauth-token.php <step> <code>
*/
require __DIR__ . '/init/bootstrap.php';
$step = $argv[1];
if (!$step) {
    throw new Exception("Step is required", 1);
}
if ($step == 1) {
    $get_vars = ['client_id' => env('TOKENPASS_CLIENT_ID'), 'redirect_uri' => 'http://localhost:8000/oauth_callback', 'scope' => 'tca,private-address,manage-address,private-balances', 'response_type' => 'code', 'state' => 'foo_' . date("Ymd_His")];
    $url = env('TOKENPASS_PROVIDER_HOST') . '/oauth/authorize?' . http_build_query($get_vars);
    echo "{$url}\n";
    exit(0);
}
if ($step == 2) {
    $code = $argv[2];
    if (!$code) {
        throw new Exception("Code is required", 1);
    }
    $api = new TokenpassAPI();
    $access_token = $api->getOAuthAccessToken($code);
    echo "\$access_token:\n{$access_token}\n";
    exit(0);
}
exit(1);
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
lookup-addresses-list.php <username> <refresh>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
$username = $argv[1];
if (!$username) {
    throw new Exception("username is required", 1);
}
$refresh = !!(isset($argv[2]) ? $argv[2] : false);
// check
echo "get addresses list\n";
$result = $api->getPublicAddresses($username, $refresh);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
}
// show the results
echo "\$result: " . json_encode($result, 192) . "\n";
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./check-username-tca.php <oauth_token> <username> <rules>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// get vars
$oauth_token = $argv[1];
$username = $argv[2];
$rules = json_decode($argv[3], true);
// check
echo "Checking user {$username} with rules: " . json_encode($rules) . "\n";
$result = $api->checkTokenAccess($username, $rules, $oauth_token);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
}
// show the results
echo "\$result: " . json_encode($result, 192) . "\n";
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./address-verify.php <oauth_token> <address> <signature>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// get vars
$oauth_token = $argv[1];
$address = $argv[2];
$signature = $argv[3];
if (!$oauth_token) {
    throw new Exception("oauth_token is required", 1);
}
if (!$address) {
    throw new Exception("Address is required", 1);
}
if (!$signature) {
    throw new Exception("signature is required", 1);
}
// check
echo "verifying address {$address} with signature {$signature}\n";
$result = $api->verifyAddress($address, $oauth_token, $signature);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./provisional-update-tx.php <promise_id> <amount>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// get vars
$promise_id = $argv[1];
$amount = $argv[2];
if (!$promise_id) {
    throw new Exception("promise_id is required", 1);
}
if (!$amount) {
    throw new Exception("amount is required", 1);
}
// check
echo "updating {$amount}\n";
$result = $api->updatePromisedTransaction($promise_id, ['quantity' => $amount, 'expiration' => time() + 3600]);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./private-balances.php <username> <address>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
$oauth_token = $argv[1];
if (!$oauth_token) {
    throw new Exception("oauth_token is required", 1);
}
// check
echo "get private balances for token " . substr($oauth_token, 0, 4) . "...\n";
$result = $api->getCombinedProtectedBalances($oauth_token);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
}
// show the results
echo "\$result: " . json_encode($result, 192) . "\n";
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./provisional-list-source-addresses.php
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
echo "getting addresses\n";
$result = $api->getProvisionalSourceList();
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
}
// show the results
echo "\$result: " . json_encode($result, 192) . "\n";
if ($result) {
    foreach ($result as $source_address) {
        $address = $source_address['address'];
        $restricted_assets = $source_address['assets'];
    }
}
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./provisional-list-tx.php
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// check
echo "listing promises\n";
$result = $api->getPromisedTransactionList();
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
}
// show the results
echo "\$result: " . json_encode($result, 192) . "\n";
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./public-address-details <username> <address>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
$username = $argv[1];
$address = $argv[2];
if (!$username) {
    throw new Exception("username is required", 1);
}
if (!$address) {
    throw new Exception("address is required", 1);
}
// check
echo "fetching public address details for {$username} {$address}\n";
$result = $api->getPublicAddressDetails($username, $address);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
}
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./provisional-register-source-address.php <address> <proof>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// get vars
$address = $argv[1];
if (!$address) {
    throw new Exception("Address is required", 1);
}
$proof = $argv[2];
if (!$proof) {
    $message = $address . '_' . hash('sha256', env('TOKENPASS_CLIENT_ID'));
    echo "Please sign this message with the private key of address {$address}:\n{$message}\n";
    exit(0);
}
// check
echo "registering {$address} with proof {$proof}\n";
$result = $api->registerProvisionalSource($address, $proof);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./address-details.php <oauth_token> <address>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
$oauth_token = $argv[1];
$address = $argv[2];
if (!$oauth_token) {
    throw new Exception("oauth_token is required", 1);
}
if (!$address) {
    throw new Exception("address is required", 1);
}
// check
echo "fetching address details for {$address} with token " . substr($oauth_token, 0, 4) . "...\n";
$result = $api->getAddressDetailsForAuthenticatedUser($address, $oauth_token);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }
}
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./address-update.php <oauth_token> <address> <label>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// get vars
$oauth_token = $argv[1];
$address = $argv[2];
$label = $argv[3];
if (!$oauth_token) {
    throw new Exception("oauth_token is required", 1);
}
if (!$address) {
    throw new Exception("Address is required", 1);
}
if (!$label) {
    throw new Exception("label is required", 1);
}
// check
echo "updating address {$address} with label {$label}\n";
$result = $api->updateAddressDetails($address, $oauth_token, $label);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
#!/usr/bin/env php
<?php 
use Tokenly\TokenpassClient\TokenpassAPI;
/*
# Usage:
export TOKENPASS_PROVIDER_HOST=https://tokenpass-stage.tokenly.com
export TOKENPASS_CLIENT_ID=xxxxx
export TOKENPASS_CLIENT_SECRET=xxxxx
./address-delete.php <oauth_token> <address>
*/
require __DIR__ . '/init/bootstrap.php';
$api = new TokenpassAPI();
// get vars
$oauth_token = $argv[1];
$address = $argv[2];
if (!$oauth_token) {
    throw new Exception("oauth_token is required", 1);
}
if (!$address) {
    throw new Exception("Address is required", 1);
}
// check
echo "DELETING address {$address}\n";
$result = $api->deleteAddress($address, $oauth_token);
// handle error
if ($result === false) {
    $error_string = $api->getErrorsAsString();
    if ($error_string) {
        echo "ERROR: {$error_string}\n";
        exit(1);
    }