Skip to content

Commit

Permalink
Merge pull request #75 from MinterTeam/dev
Browse files Browse the repository at this point in the history
check deep link
  • Loading branch information
grkamil authored Dec 6, 2019
2 parents f2a923a + b5ed46a commit d2b7b5f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"ext-bcmath": "*",
"kornrunner/keccak": "1.0",
"guzzlehttp/guzzle": "^6.3",
"minter/minter-php-bip-44": "1.0.0",
"minter/minter-php-bip-44": "1.1.0",
"bitwasp/bitcoin-lib": "1.0.4",
"simplito/elliptic-php": "1.0.3",
"simplito/elliptic-php": "1.0.6",
"minter/php-rlp": "^0.2.4",
"ext-json": "*"
},
Expand Down
23 changes: 22 additions & 1 deletion src/Minter/SDK/MinterDeepLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class MinterDeepLink
/** @var RLP */
private $rlp;

/** @var string */
private $checkPassword;

/** @var string */
private const LINK_BASE_URL = 'https://bip.to/tx';

/**
* MinterDeepLink constructor.
* @param MinterTxInterface $txData
Expand Down Expand Up @@ -72,6 +78,14 @@ public function setGasPrice($gasPrice): void
$this->gasPrice = $gasPrice;
}

/**
* @param string $p
*/
public function setCheckPassword(string $p): void
{
$this->checkPassword = $p;
}

/**
* @return string
*/
Expand All @@ -91,6 +105,13 @@ public function encode(): string
'gasCoin' => $gasCoin
];

return $this->rlp->encode($deepLink)->toString('hex');
$params = ['d' => $this->rlp->encode($deepLink)->toString('hex')];
if($this->checkPassword) {
$checkPassword = str_split($this->checkPassword, 1);
$checkPassword = new Buffer($checkPassword);
$params['p'] = $this->rlp->encode($checkPassword)->toString('hex');
}

return self::LINK_BASE_URL . '?' . http_build_query($params);
}
}
8 changes: 5 additions & 3 deletions tests/MinterDeepLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class MinterDeepLinkTest extends TestCase
{
const HOST_BASE_URL = 'https://bip.to/tx';

public function testEncodeWithPayload()
{
$txData = new MinterSendCoinTx([
Expand All @@ -19,7 +21,7 @@ public function testEncodeWithPayload()
$link->setPayload('Hello World');

$this->assertSame(
'f83b01aae98a424950000000000000009418467bbb64a8edf890201d526c35957d82be3d9588112210f4768db4008b48656c6c6f20576f726c64808080',
self::HOST_BASE_URL . '?d=f83b01aae98a424950000000000000009418467bbb64a8edf890201d526c35957d82be3d9588112210f4768db4008b48656c6c6f20576f726c64808080',
$link->encode());
}

Expand All @@ -34,7 +36,7 @@ public function testEncodeWithoutPayload()
$link = new MinterDeepLink($txData);

$this->assertSame(
'f001aae98a424950000000000000009418467bbb64a8edf890201d526c35957d82be3d9588112210f4768db40080808080',
self::HOST_BASE_URL . '?d=f001aae98a424950000000000000009418467bbb64a8edf890201d526c35957d82be3d9588112210f4768db40080808080',
$link->encode());
}

Expand All @@ -54,7 +56,7 @@ public function testEncodeFullTx()
$link->setGasPrice('1');

$this->assertSame(
'f84701aae98a424950000000000000009418467bbb64a8edf890201d526c35957d82be3d9588112210f4768db4008d436865636b207061796c6f616401018a4d4e5400000000000000',
self::HOST_BASE_URL . '?d=f84701aae98a424950000000000000009418467bbb64a8edf890201d526c35957d82be3d9588112210f4768db4008d436865636b207061796c6f616401018a4d4e5400000000000000',
$link->encode()
);
}
Expand Down

0 comments on commit d2b7b5f

Please sign in to comment.