Skip to content

Commit

Permalink
feat: implement Address#fromMultiSignatureAsset
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian committed Nov 19, 2020
1 parent 8fe4b62 commit 0d26070
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/Identities/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ public static function fromPassphrase(string $passphrase, AbstractNetwork $netwo
return static::fromPrivateKey(PrivateKey::fromPassphrase($passphrase), $network);
}

/**
* Derive the address from the given multi-signature asset.
*
* @param int $min
* @param array $publicKeys
*
* @return string
*/
public static function fromMultiSignatureAsset(int $min, array $publicKeys): string
{
return static::fromPublicKey(PublicKey::fromMultiSignatureAsset($min, $publicKeys)->getHex());
}

/**
* Derive the address from the given public key.
*
Expand Down
14 changes: 14 additions & 0 deletions tests/Unit/Identities/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ public function it_should_get_the_address_from_passphrase()
$this->assertSame($fixture['data']['address'], $actual);
}

/** @test */
public function it_should_get_the_address_from_a_multi_signature_asset()
{
$actual = TestClass::fromMultiSignatureAsset(3, [
'02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56',
'02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b',
'03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0',
'020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3',
'03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219',
]);

$this->assertSame('DMNBBtYt1teAKxA2BpiTW9PA3gX3Ad5dyk', $actual);
}

/** @test */
public function it_should_get_the_address_from_public_key()
{
Expand Down
10 changes: 6 additions & 4 deletions tests/Unit/Identities/PublicKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ public function it_should_get_the_public_key_from_passphrase()
public function it_should_get_the_public_key_from_a_multi_signature_asset()
{
$actual = TestClass::fromMultiSignatureAsset(3, [
TestClass::fromPassphrase('secret 1')->getHex(),
TestClass::fromPassphrase('secret 2')->getHex(),
TestClass::fromPassphrase('secret 3')->getHex(),
'02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56',
'02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b',
'03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0',
'020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3',
'03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219',
]);

$this->assertSame(
'0279f05076556da7173610a7676399c3620276ebbf8c67552ad3b1f26ec7627794',
'03da05c1c1d4f9c6bda13695b2f29fbc65d9589edc070fc61fe97974be3e59c14e',
$actual->getHex()
);
}
Expand Down

0 comments on commit 0d26070

Please sign in to comment.