Skip to content

Commit 0d26070

Browse files
author
Brian Faust
committed
feat: implement Address#fromMultiSignatureAsset
1 parent 8fe4b62 commit 0d26070

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/Identities/Address.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ public static function fromPassphrase(string $passphrase, AbstractNetwork $netwo
4444
return static::fromPrivateKey(PrivateKey::fromPassphrase($passphrase), $network);
4545
}
4646

47+
/**
48+
* Derive the address from the given multi-signature asset.
49+
*
50+
* @param int $min
51+
* @param array $publicKeys
52+
*
53+
* @return string
54+
*/
55+
public static function fromMultiSignatureAsset(int $min, array $publicKeys): string
56+
{
57+
return static::fromPublicKey(PublicKey::fromMultiSignatureAsset($min, $publicKeys)->getHex());
58+
}
59+
4760
/**
4861
* Derive the address from the given public key.
4962
*

tests/Unit/Identities/AddressTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ public function it_should_get_the_address_from_passphrase()
4444
$this->assertSame($fixture['data']['address'], $actual);
4545
}
4646

47+
/** @test */
48+
public function it_should_get_the_address_from_a_multi_signature_asset()
49+
{
50+
$actual = TestClass::fromMultiSignatureAsset(3, [
51+
'02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56',
52+
'02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b',
53+
'03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0',
54+
'020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3',
55+
'03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219',
56+
]);
57+
58+
$this->assertSame('DMNBBtYt1teAKxA2BpiTW9PA3gX3Ad5dyk', $actual);
59+
}
60+
4761
/** @test */
4862
public function it_should_get_the_address_from_public_key()
4963
{

tests/Unit/Identities/PublicKeyTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ public function it_should_get_the_public_key_from_passphrase()
3838
public function it_should_get_the_public_key_from_a_multi_signature_asset()
3939
{
4040
$actual = TestClass::fromMultiSignatureAsset(3, [
41-
TestClass::fromPassphrase('secret 1')->getHex(),
42-
TestClass::fromPassphrase('secret 2')->getHex(),
43-
TestClass::fromPassphrase('secret 3')->getHex(),
41+
'02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56',
42+
'02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b',
43+
'03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0',
44+
'020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3',
45+
'03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219',
4446
]);
4547

4648
$this->assertSame(
47-
'0279f05076556da7173610a7676399c3620276ebbf8c67552ad3b1f26ec7627794',
49+
'03da05c1c1d4f9c6bda13695b2f29fbc65d9589edc070fc61fe97974be3e59c14e',
4850
$actual->getHex()
4951
);
5052
}

0 commit comments

Comments
 (0)