Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Generate ADA wallet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel committed Aug 19, 2021
1 parent c40f617 commit c64270d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 47 deletions.
1 change: 1 addition & 0 deletions src/Utils/Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Constant
'LYRA' => "44'/497'/0'/0",
'TESTNET' => "44'/1'/0'/0",
'DOGE' => "44'/3'/0'/0",
'ADA' => "1852'/1815'/0'",
];

public const CONTRACT_ADDRESSES = array(
Expand Down
1 change: 1 addition & 0 deletions src/Utils/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ class Currency extends Enum
public const ETH = 'ETH';
public const LTC = 'LTC';
public const DOGE = 'DOGE';
public const ADA = 'ADA';
}
29 changes: 29 additions & 0 deletions src/Wallet/Ada.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Tatum\Wallet;

use BitWasp\Bitcoin\Key\Factory\HierarchicalKeyFactory;
use BitWasp\Bitcoin\Mnemonic\MnemonicFactory;

class Ada
{
/**
* @param $mnemonic
*/
private static function generateEntropyFromMnemonic($mnemonic): \BitWasp\Buffertools\BufferInterface
{
$bip39 = MnemonicFactory::bip39();
return $bip39->mnemonicToEntropy($mnemonic);
}

public function generateAdaWallet(string $mnemonic) : array
{
$entropy = self::generateEntropyFromMnemonic($mnemonic);
$xprv = hash_pbkdf2('sha512', '', $entropy->getHex(), 4096, 96);

$xprv[0] &= 248;
$xprv[31] &= 31;
$xprv[31] |= 64;

}
}
47 changes: 0 additions & 47 deletions src/Wallet/Address.php

This file was deleted.

10 changes: 10 additions & 0 deletions src/Wallet/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ private function generateMnemonic(): string
return $bip39->entropyToMnemonic($entropy);
}

/**
* @param $mnemonic
*/
private function generateEntropyFromMnemonic($mnemonic): \BitWasp\Buffertools\BufferInterface
{
$bip39 = MnemonicFactory::bip39();
return $bip39->mnemonicToEntropy($mnemonic);
}

/**
* @param string $mnemonic
* @return \BitWasp\Bitcoin\Key\Deterministic\HierarchicalKey
Expand Down Expand Up @@ -256,6 +265,7 @@ public function generateWallet(
case Currency::DOGE:
return $this->generateBtcBasedWallet($mnemonic);
case Currency::ETH:
case Currency::ADA:
return $this->generateEthWallet($mnemonic);
default:
throw new UnexpectedValueException('Unsupported Blockchain' . $this->currency . '.');
Expand Down
2 changes: 2 additions & 0 deletions tests/WalletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public function testGenerateWallets()
foreach ($currencies as $currency) {
$wallet = new Wallet($currency);
$generatedWallet = $wallet->generateWallet();
print_r($generatedWallet);
print_r($currency);
self::assertWallet($generatedWallet);
}
}
Expand Down

0 comments on commit c64270d

Please sign in to comment.