Signing and verifying messages
Through signing and verifying messages we can provide proof that a digital signature was created by a private key.
Signing a message API docs
By signing a message using the SDK we can provide a digital signature. Anyone with the message
, pubkey
and signature
can verify the signature was created by the private key of this pubkey.
Rust
let sign_message_request = SignMessageRequest {
message: "<message to sign>".to_string(),
};
let sign_message_response = sdk
.sign_message(&sign_message_request)?;
// Get the node info for your pubkey
let info = sdk.node_info().await?;
let signature = sign_message_response.signature;
let pubkey = info.id;
info!("Pubkey: {}", pubkey);
info!("Signature: {}", signature);
Swift
let signMessageRequest = SignMessageRequest(
message: "<message to sign>"
)
let signMessageResponse = try? sdk
.signMessage(req: signMessageRequest)
// Get the node info for your pubkey
let info = try? sdk.nodeInfo()
let signature = signMessageResponse!.signature
let pubkey = info!.id
print("Pubkey: {}", pubkey);
print("Signature: {}", signature);
Kotlin
val message = "<message to sign>"
try {
val signMessageRequest = SignMessageRequest(message)
val signMessageResponse = sdk.signMessage(signMessageRequest)
// Get the node info for your pubkey
val info = sdk.nodeInfo()
val signature = signMessageResponse?.signature
val pubkey = info?.id
// Log.v("Breez", "Pubkey: ${pubkey}")
// Log.v("Breez", "Signature: ${signature}")
} catch (e: Exception) {
// handle error
}
React Native
const signMessageResponse = await signMessage({
message: '<message to sign>'
})
// Get the node info for your pubkey
const info = await nodeInfo()
const signature = signMessageResponse.signature
const pubkey = info.id
console.log(`Pubkey: ${pubkey}`)
console.log(`Signature: ${signature}`)
Dart
SignMessageRequest signMessageRequest = SignMessageRequest(
message: "<message to sign>",
);
SignMessageResponse signMessageResponse = await breezSDK.signMessage(
req: signMessageRequest,
);
// Get the node info for your pubkey
NodeState? info = await breezSDK.nodeInfo();
String signature = signMessageResponse.signature;
String? pubkey = info?.id;
print("Pubkey: $pubkey");
print("Signature: $signature");
Python
message = "<message to sign>"
try:
sign_message_request = breez_sdk.SignMessageRequest(message)
sign_message_response = sdk_services.sign_message(sign_message_request)
# Get the node info for your pubkey
info = sdk_services.node_info()
signature = sign_message_response.signature
pubkey = info.id
logging.debug(f"Pubkey: {pubkey}")
logging.debug(f"Signature: {signature}")
except Exception as error:
logging.error(error)
raise
Go
message := "<message to sign>"
signMessageRequest := breez_sdk.SignMessageRequest{
Message: message,
}
signMessageResponse, err := sdk.SignMessage(signMessageRequest)
if err != nil {
log.Printf("Error: %#v", err)
return
}
// Get the node info for your pubkey
info, err := sdk.NodeInfo()
if err != nil {
log.Printf("Error: %#v", err)
return
}
signature := signMessageResponse.Signature
pubkey := info.Id
log.Printf("Pubkey: %v", pubkey)
log.Printf("Signature: %v", signature)
C#
var message = "<message to sign>";
try
{
var signMessageRequest = new SignMessageRequest(message);
var signMessageResponse = sdk.SignMessage(signMessageRequest);
// Get the node info for your pubkey
var info = sdk.NodeInfo();
var signature = signMessageResponse?.signature;
var pubkey = info?.id;
Console.WriteLine($"Pubkey: {pubkey}");
Console.WriteLine($"Signature: {signature}");
}
catch (Exception)
{
// Handle error
}
Verifying a message API docs
You can prove control of a private key by verifying a message
with it's signature
and pubkey
.
Rust
let check_message_request = CheckMessageRequest {
message: "<message>".to_string(),
pubkey: "<pubkey of signer>".to_string(),
signature: "<message signature>".to_string(),
};
let check_message_response = sdk
.check_message(&check_message_request)?;
let is_valid = check_message_response.is_valid;
info!("Signature valid: {}", is_valid);
Swift
let checkMessageRequest = CheckMessageRequest(
message: "<message>",
pubkey: "<pubkey of signer>",
signature: "<message signature>"
)
let checkMessageResponse = try? sdk
.checkMessage(req: checkMessageRequest)
let isValid = checkMessageResponse!.isValid
print("Signature valid: {}", isValid);
Kotlin
val message = "<message>"
val pubkey = "<pubkey of signer>"
val signature = "<message signature>"
try {
val checkMessageRequest = CheckMessageRequest(message, pubkey, signature)
val checkMessageResponse = sdk.checkMessage(checkMessageRequest)
val isValid = checkMessageResponse?.isValid
// Log.v("Breez", "Signature valid: ${isValid}")
} catch (e: Exception) {
// handle error
}
React Native
const checkMessageResponse = await checkMessage({
message: '<message>',
pubkey: '<pubkey of signer>',
signature: '<message signature>'
})
const isValid = checkMessageResponse.isValid
console.log(`Signature valid: ${isValid}`)
Dart
CheckMessageRequest checkMessageRequest = CheckMessageRequest(
message: "<message>",
pubkey: "<pubkey of signer>",
signature: "<message signature>",
);
CheckMessageResponse checkMessageResponse = await breezSDK.checkMessage(
req: checkMessageRequest,
);
bool isValid = checkMessageResponse.isValid;
print("Signature valid: $isValid");
Python
message = "<message>"
pubkey = "<pubkey of signer>"
signature = "<message signature>"
try:
check_message_request = breez_sdk.CheckMessageRequest(message, pubkey, signature)
check_message_response = sdk_services.check_message(check_message_request)
is_valid = check_message_response.is_valid
logging.debug(f"Signature valid: {is_valid}")
except Exception as error:
logging.error(error)
raise
Go
message := "<message>"
pubkey := "<pubkey of signer>"
signature := "<message signature>"
checkMessageRequest := breez_sdk.CheckMessageRequest{
Message: message,
Pubkey: pubkey,
Signature: signature,
}
checkMessageResponse, err := sdk.CheckMessage(checkMessageRequest)
if err != nil {
log.Printf("Error: %#v", err)
return
}
isValid := checkMessageResponse.IsValid
log.Printf("Signature valid: %v", isValid)
C#
var message = "<message>";
var pubkey = "<pubkey of signer>";
var signature = "<message signature>";
try
{
var checkMessageRequest = new CheckMessageRequest(message, pubkey, signature);
var checkMessageResponse = sdk.CheckMessage(checkMessageRequest);
var isValid = checkMessageResponse?.isValid;
Console.WriteLine($"Signature valid: {isValid}");
}
catch (Exception)
{
// Handle error
}