Skip to content

Commit b80bc94

Browse files
authored
fix: handle signed messages that were created through Desktop Wallet 2.0 (#31)
1 parent 88ef990 commit b80bc94

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## Unreleased
99

10+
## 0.2.5 - 2018-12-07
11+
12+
### Fixed
13+
- Handle signed messages that were created through Desktop Wallet 2.0
14+
1015
## 0.2.4 - 2018-11-08
1116

1217
### Fixed

src/Utils/Message.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ class Message
5555
*/
5656
public function __construct(object $message)
5757
{
58-
$this->publicKey = $message->publickey;
58+
if (property_exists($message, 'publickey')) {
59+
$this->publicKey = $message->publickey;
60+
} elseif (property_exists($message, 'publicKey')) {
61+
$this->publicKey = $message->publicKey;
62+
} else {
63+
throw new InvalidArgumentException('The given message did not contain a valid public key.');
64+
}
65+
5966
$this->signature = $message->signature;
6067
$this->message = $message->message;
6168
}

tests/Utils/MessageTest.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MessageTest extends TestCase
2727
/** @test */
2828
public function it_should_sign_a_valid_message()
2929
{
30-
$fixture = $this->getFixture('message');
30+
$fixture = $this->getFixture('message-v1');
3131

3232
$message = Message::sign($fixture['data']['message'], $fixture['passphrase']);
3333

@@ -39,7 +39,7 @@ public function it_should_sign_a_valid_message()
3939
/** @test */
4040
public function it_should_create_a_message_from_an_object()
4141
{
42-
$fixture = json_decode(json_encode($this->getFixture('message')['data']));
42+
$fixture = json_decode(json_encode($this->getFixture('message-v1')['data']));
4343

4444
$message = Message::new($fixture);
4545

@@ -51,7 +51,7 @@ public function it_should_create_a_message_from_an_object()
5151
/** @test */
5252
public function it_should_create_a_message_from_an_array()
5353
{
54-
$fixture = $this->getFixture('message')['data'];
54+
$fixture = $this->getFixture('message-v1')['data'];
5555

5656
$message = Message::new($fixture);
5757

@@ -63,7 +63,7 @@ public function it_should_create_a_message_from_an_array()
6363
/** @test */
6464
public function it_should_create_a_message_from_a_string()
6565
{
66-
$fixture = $this->getFixture('message')['data'];
66+
$fixture = $this->getFixture('message-v1')['data'];
6767

6868
$message = Message::new(json_encode($fixture));
6969

@@ -89,33 +89,41 @@ public function it_should_sign_a_message()
8989
}
9090

9191
/** @test */
92-
public function it_should_verify_a_message()
92+
public function it_should_verify_a_message_from_v1()
9393
{
94-
$message = Message::new($this->getFixture('message')['data']);
94+
$message = Message::new($this->getFixture('message-v1')['data']);
95+
96+
$this->assertTrue($message->verify());
97+
}
98+
99+
/** @test */
100+
public function it_should_verify_a_message_from_v2()
101+
{
102+
$message = Message::new($this->getFixture('message-v2')['data']);
95103

96104
$this->assertTrue($message->verify());
97105
}
98106

99107
/** @test */
100108
public function it_should_turn_a_message_into_an_array()
101109
{
102-
$message = Message::new($this->getFixture('message')['data']);
110+
$message = Message::new($this->getFixture('message-v1')['data']);
103111

104112
$this->assertInternalType('array', $message->toArray());
105113
}
106114

107115
/** @test */
108116
public function it_should_turn_a_message_into_json()
109117
{
110-
$message = Message::new($this->getFixture('message')['data']);
118+
$message = Message::new($this->getFixture('message-v1')['data']);
111119

112120
$this->assertInternalType('string', $message->toJSON());
113121
}
114122

115123
/** @test */
116124
public function it_should_turn_a_message_into_a_string()
117125
{
118-
$message = Message::new($this->getFixture('message')['data']);
126+
$message = Message::new($this->getFixture('message-v1')['data']);
119127

120128
$this->assertInternalType('string', $message->__toString());
121129
}
File renamed without changes.

tests/fixtures/message-v2.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"data": {
3+
"publicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192",
4+
"signature": "304402200fb4adddd1f1d652b544ea6ab62828a0a65b712ed447e2538db0caebfa68929e02205ecb2e1c63b29879c2ecf1255db506d671c8b3fa6017f67cfd1bf07e6edd1cc8",
5+
"message": "Hello World"
6+
},
7+
"passphrase": "this is a top secret passphrase"
8+
}

0 commit comments

Comments
 (0)