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 wallet info for your pubkey
let info = sdk.get_info().await?;

let signature = sign_message_response.signature;
let pubkey = info.wallet_info.pubkey;

info!("Pubkey: {}", pubkey);
info!("Signature: {}", signature);
Swift
let signMessageRequest = SignMessageRequest(
    message: "<message to sign>"
)
let signMessageResponse = try? sdk
    .signMessage(req: signMessageRequest)

// Get the wallet info for your pubkey
let info = try? sdk.getInfo()

let signature = signMessageResponse!.signature
let pubkey = info!.walletInfo.pubkey

print("Pubkey: {}", pubkey);
print("Signature: {}", signature);
Kotlin
val message = "<message to sign>"
try {
    val signMessageRequest = SignMessageRequest(message)
    val signMessageResponse = sdk.signMessage(signMessageRequest)

    // Get the wallet info for your pubkey
    val info = sdk.getInfo()

    val signature = signMessageResponse?.signature
    val pubkey = info?.walletInfo?.pubkey

    // 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 wallet info for your pubkey
const info = await getInfo()

const signature = signMessageResponse.signature
const pubkey = info.walletInfo.pubkey

console.log(`Pubkey: ${pubkey}`)
console.log(`Signature: ${signature}`)
Dart
SignMessageRequest signMessageRequest = SignMessageRequest(
  message: "<message to sign>",
);
SignMessageResponse signMessageResponse = breezSDKLiquid.instance!.signMessage(
  req: signMessageRequest,
);

// Get the wallet info for your pubkey
GetInfoResponse? info = await breezSDKLiquid.instance!.getInfo();

String signature = signMessageResponse.signature;
String pubkey = info.walletInfo.pubkey;

print("Pubkey: $pubkey");
print("Signature: $signature");
Python
message = "<message to sign>"
try:
    sign_message_request = SignMessageRequest(message)
    sign_message_response = sdk.sign_message(sign_message_request)

    # Get the wallet info for your pubkey
    info = sdk.get_info()

    signature = sign_message_response.signature
    pubkey = info.wallet_info.pubkey

    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_liquid.SignMessageRequest{
    Message: message,
}
signMessageResponse, err := sdk.SignMessage(signMessageRequest)
if err != nil {
    log.Printf("Error: %#v", err)
    return
}

// Get the wallet info for your pubkey
info, err := sdk.GetInfo()
if err != nil {
    log.Printf("Error: %#v", err)
    return
}

signature := signMessageResponse.Signature
pubkey := info.WalletInfo.Pubkey

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 wallet info for your pubkey
    var info = sdk.GetInfo();

    var signature = signMessageResponse?.signature;
    var pubkey = info?.walletInfo?.pubkey;

    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 = breezSDKLiquid.instance!.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 = CheckMessageRequest(message, pubkey, signature)
    check_message_response = sdk.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_liquid.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
}