File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 20
20
"php" : " ^7.2" ,
21
21
"bitwasp/bitcoin" : " ^1.0" ,
22
22
"kodekeep/binary" : " ^1.0" ,
23
- "kodekeep/bytebuffer" : " ^1.0"
23
+ "kodekeep/bytebuffer" : " ^1.0" ,
24
+ "simplito/elliptic-php" : " ^1.0"
24
25
},
25
26
"require-dev" : {
26
27
"friendsofphp/php-cs-fixer" : " ^2.16" ,
Original file line number Diff line number Diff line change 17
17
use BitWasp \Bitcoin \Crypto \EcAdapter \EcAdapterFactory ;
18
18
use BitWasp \Bitcoin \Crypto \EcAdapter \Impl \PhpEcc \Key \PublicKey as EcPublicKey ;
19
19
use BitWasp \Bitcoin \Key \Factory \PublicKeyFactory ;
20
+ use Elliptic \EC ;
20
21
21
22
/**
22
23
* This is the public key class.
@@ -37,6 +38,29 @@ public static function fromPassphrase(string $passphrase): EcPublicKey
37
38
return PrivateKey::fromPassphrase ($ passphrase )->getPublicKey ();
38
39
}
39
40
41
+ /**
42
+ * Create a public key instance from a multi-signature asset.
43
+ *
44
+ * @param int $min
45
+ * @param array $publicKeys
46
+ *
47
+ * @return \BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Key\PublicKey
48
+ */
49
+ public static function fromMultiSignatureAsset (int $ min , array $ publicKeys ): EcPublicKey
50
+ {
51
+ $ minKey = static ::fromPassphrase ('0 ' .dechex ($ min ));
52
+ $ keys = [$ minKey ->getHex (), ...$ publicKeys ];
53
+
54
+ $ curve = (new EC ('secp256k1 ' ))->curve ;
55
+ $ P = $ curve ->jpoint (null , null , null );
56
+
57
+ foreach ($ keys as $ publicKey ) {
58
+ $ P = $ P ->add ($ curve ->decodePoint ($ publicKey , 'hex ' ));
59
+ }
60
+
61
+ return static ::fromHex (bin2hex (implode (array_map ('chr ' , $ P ->encodeCompressed (true )))));
62
+ }
63
+
40
64
/**
41
65
* Create a public key instance from a hex string.
42
66
*
Original file line number Diff line number Diff line change @@ -34,6 +34,21 @@ public function it_should_get_the_public_key_from_passphrase()
34
34
$ this ->assertSame ($ fixture ['data ' ]['publicKey ' ], $ actual ->getHex ());
35
35
}
36
36
37
+ /** @test */
38
+ public function it_should_get_the_public_key_from_a_multi_signature_asset ()
39
+ {
40
+ $ actual = TestClass::fromMultiSignatureAsset (3 , [
41
+ TestClass::fromPassphrase ('secret 1 ' )->getHex (),
42
+ TestClass::fromPassphrase ('secret 2 ' )->getHex (),
43
+ TestClass::fromPassphrase ('secret 3 ' )->getHex (),
44
+ ]);
45
+
46
+ $ this ->assertSame (
47
+ '0279f05076556da7173610a7676399c3620276ebbf8c67552ad3b1f26ec7627794 ' ,
48
+ $ actual ->getHex ()
49
+ );
50
+ }
51
+
37
52
/** @test */
38
53
public function it_should_get_the_public_key_from_hex ()
39
54
{
You can’t perform that action at this time.
0 commit comments