Skip to content

Commit 84e9099

Browse files
committed
btcjson: add optional address field to signmessagewithprivkey
1 parent e7ed630 commit 84e9099

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

btcjson/chainsvrcmds.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,19 +929,23 @@ func NewSetGenerateCmd(generate bool, genProcLimit *int) *SetGenerateCmd {
929929

930930
// SignMessageWithPrivKeyCmd defines the signmessagewithprivkey JSON-RPC command.
931931
type SignMessageWithPrivKeyCmd struct {
932-
PrivKey string // base 58 Wallet Import format private key
933-
Message string // Message to sign
932+
PrivKey string // base 58 Wallet Import format private key
933+
Message string // Message to sign
934+
Address *string // optional address for BIP-322 signing
934935
}
935936

936937
// NewSignMessageWithPrivKey returns a new instance which can be used to issue a
937938
// signmessagewithprivkey JSON-RPC command.
938939
//
939940
// The first parameter is a private key in base 58 Wallet Import format.
940941
// The second parameter is the message to sign.
941-
func NewSignMessageWithPrivKey(privKey, message string) *SignMessageWithPrivKeyCmd {
942+
// The optional third parameter is an address for BIP-322 signing. Passing nil
943+
// will use the default legacy signing method.
944+
func NewSignMessageWithPrivKey(privKey, message string, address *string) *SignMessageWithPrivKeyCmd {
942945
return &SignMessageWithPrivKeyCmd{
943946
PrivKey: privKey,
944947
Message: message,
948+
Address: address,
945949
}
946950
}
947951

btcjson/chainsvrcmds_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,14 +1304,29 @@ func TestChainSvrCmds(t *testing.T) {
13041304
return btcjson.NewCmd("signmessagewithprivkey", "5Hue", "Hey")
13051305
},
13061306
staticCmd: func() interface{} {
1307-
return btcjson.NewSignMessageWithPrivKey("5Hue", "Hey")
1307+
return btcjson.NewSignMessageWithPrivKey("5Hue", "Hey", nil)
13081308
},
13091309
marshalled: `{"jsonrpc":"1.0","method":"signmessagewithprivkey","params":["5Hue","Hey"],"id":1}`,
13101310
unmarshalled: &btcjson.SignMessageWithPrivKeyCmd{
13111311
PrivKey: "5Hue",
13121312
Message: "Hey",
13131313
},
13141314
},
1315+
{
1316+
name: "signmessagewithprivkey - with address",
1317+
newCmd: func() (interface{}, error) {
1318+
return btcjson.NewCmd("signmessagewithprivkey", "5Hue", "Hey", "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa")
1319+
},
1320+
staticCmd: func() interface{} {
1321+
return btcjson.NewSignMessageWithPrivKey("5Hue", "Hey", btcjson.String("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"))
1322+
},
1323+
marshalled: `{"jsonrpc":"1.0","method":"signmessagewithprivkey","params":["5Hue","Hey","1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"],"id":1}`,
1324+
unmarshalled: &btcjson.SignMessageWithPrivKeyCmd{
1325+
PrivKey: "5Hue",
1326+
Message: "Hey",
1327+
Address: btcjson.String("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"),
1328+
},
1329+
},
13151330
{
13161331
name: "stop",
13171332
newCmd: func() (interface{}, error) {

0 commit comments

Comments
 (0)