Skip to main content

VerifyMessageWithAddr

VerifyMessageWithAddr returns the validity and the recovered public key of the provided compact signature (base64 encoded). The verification is twofold. First the validity of the signature itself is checked and then it is verified that the recovered public key of the signature equals the public key of the provided address. There is no dependence on the private key of the address therefore also external addresses are allowed to verify signatures. Supported address types are P2PKH, P2WKH, NP2WKH, P2TR.

This method is the counterpart of the related signing method (SignMessageWithAddr) and aims to provide full compatibility to bitcoin-core's implementation. Although bitcoin-core/btcd only provide this functionality for legacy addresses this function enhances it to the address types: P2PKH, P2WKH, NP2WKH, P2TR.

The verification for P2TR addresses is a special case and requires the ECDSA compact signature to compare the reovered public key to the internal taproot key. The compact ECDSA signature format was used because there are still no known compact signature schemes for schnorr signatures.

Source: walletrpc/walletkit.proto

gRPC

rpc VerifyMessageWithAddr (VerifyMessageWithAddrRequest) returns (VerifyMessageWithAddrResponse);

REST

HTTP MethodPath
POST /v2/wallet/address/verifymessage

Code Samples

const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const GRPC_HOST = 'localhost:10009'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
const TLS_PATH = 'LND_DIR/tls.cert'

const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'walletrpc/walletkit.proto'], loaderOptions);
const walletrpc = grpc.loadPackageDefinition(packageDefinition).walletrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new walletrpc.WalletKit(GRPC_HOST, creds);
let request = {
msg: <bytes>,
signature: <string>,
addr: <string>,
};
client.verifyMessageWithAddr(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "valid": <bool>,
// "pubkey": <bytes>,
// }

Messages

walletrpc.VerifyMessageWithAddrRequest

Source: walletrpc/walletkit.proto

FieldgRPC TypeREST TypeREST Placement
msg
bytesstringbody
signature
stringstringbody
addr
stringstringbody

walletrpc.VerifyMessageWithAddrResponse

Source: walletrpc/walletkit.proto

FieldgRPC TypeREST Type
valid
boolboolean
pubkey
bytesstring