Skip to content

Commit 1da38f9

Browse files
committed
Add MessagingCommand (signmessage + verifymessage); Add createfrom
1 parent 69ed608 commit 1da38f9

File tree

6 files changed

+1045
-814
lines changed

6 files changed

+1045
-814
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package multichain.command;
2+
3+
import multichain.command.builders.QueryBuilderMessaging;
4+
import multichain.object.Address;
5+
6+
public class MessagingCommand extends QueryBuilderMessaging {
7+
8+
public MessagingCommand(String ip, String port, String login, String password) {
9+
initialize(ip, port, login, password);
10+
}
11+
12+
/**
13+
* Verifies that message was approved by the owner of address by checking the
14+
* base64-encoded digital signature provided.
15+
*
16+
* @param address
17+
* (Address, required) The owner address
18+
* @param signature
19+
* (String, required) The base64-encoded digital signature to check
20+
* @param message
21+
* (String, required) The message
22+
* @return (Boolean) True if the message is approved, else false
23+
* @throws MultichainException
24+
*/
25+
public final boolean verifyMessage(Address address, String signature, String message) throws MultichainException {
26+
return verifyMessage(address.getAddress(), signature, message);
27+
}
28+
29+
/**
30+
* {@link #verifyMessage(Address, String, String)} with address in format string
31+
*
32+
* @param address
33+
* (String, required) The owner address
34+
* @param signature
35+
* (String, required) The base64-encoded digital signature to check
36+
* @param message
37+
* (String, required) The message
38+
* @return (Boolean) True if the message is approved, else false
39+
* @throws MultichainException
40+
*/
41+
public final boolean verifyMessage(String address, String signature, String message) throws MultichainException {
42+
Object objectBool = executeVerifyMessage(address, signature, message);
43+
return (boolean) objectBool;
44+
}
45+
46+
/**
47+
* Returns a base64-encoded digital signature which proves that message was
48+
* approved by the owner of the address or any other private key given in
49+
* addressORPrivateKey.
50+
*
51+
* @param addressORPrivateKey
52+
* (Address, required) The address or the private key (which must
53+
* belong to this wallet)
54+
* @param message
55+
* (String, required) The message to approved
56+
* @return (String) The base64-encoded digital signature
57+
* @throws MultichainException
58+
*/
59+
60+
public final String signMessage(Address addressORPrivateKey, String message) throws MultichainException {
61+
return signMessage(addressORPrivateKey.getAddress(), message);
62+
}
63+
64+
/**
65+
* {@link #signMessage(Address, String)} with addressORPrivateKey in format
66+
* string
67+
*
68+
* @param addressORPrivateKey
69+
* (String, required) The address or the private key (which must
70+
* belong to this wallet)
71+
* @param message
72+
* (String, required) The message to approved
73+
* @return (String) The base64-encoded digital signature
74+
* @throws MultichainException
75+
*/
76+
public final String signMessage(String addressORPrivateKey, String message) throws MultichainException {
77+
Object objectSign = executeSignMessage(addressORPrivateKey, message);
78+
return (String) objectSign;
79+
}
80+
}

src/multichain/command/MultiChainCommand.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class MultiChainCommand {
1818
private ChainCommand chainCommand;
1919
private GrantCommand grantCommand;
2020
private IssueCommand issueCommand;
21+
private MessagingCommand messagingCommand;
2122
private RAWTransactionCommand rawTransactionCommand;
2223
private StreamCommand streamCommand;
2324
private WalletTransactionCommand walletTransactionCommand;
@@ -33,6 +34,7 @@ public MultiChainCommand(String ip, String port, String login, String password)
3334
chainCommand = new ChainCommand(ip, port, login, password);
3435
grantCommand = new GrantCommand(ip, port, login, password);
3536
issueCommand = new IssueCommand(ip, port, login, password);
37+
messagingCommand = new MessagingCommand(ip, port, login, password);
3638
rawTransactionCommand = new RAWTransactionCommand(ip, port, login, password);
3739
streamCommand = new StreamCommand(ip, port, login, password);
3840
walletTransactionCommand = new WalletTransactionCommand(ip, port, login, password);
@@ -53,6 +55,21 @@ public void setIssueCommand(IssueCommand issueCommand) {
5355
this.issueCommand = issueCommand;
5456
}
5557

58+
/**
59+
* @return the messagingCommand
60+
*/
61+
public MessagingCommand getMessagingCommand() {
62+
return messagingCommand;
63+
}
64+
65+
/**
66+
* @param messagingCommand
67+
* the messagingCommand to set
68+
*/
69+
public void setMessagingCommand(MessagingCommand messagingCommand) {
70+
this.messagingCommand = messagingCommand;
71+
}
72+
5673
/**
5774
* @return the streamCommand
5875
*/

0 commit comments

Comments
 (0)