Skip to main content

SignPsbt

SignPsbt expects a partial transaction with all inputs and outputs fully declared and tries to sign all unsigned inputs that have all required fields (UTXO information, BIP32 derivation information, witness or sig scripts) set. If no error is returned, the PSBT is ready to be given to the next signer or to be finalized if lnd was the last signer.

NOTE: This RPC only signs inputs (and only those it can sign), it does not perform any other tasks (such as coin selection, UTXO locking or input/output/fee value validation, PSBT finalization). Any input that is incomplete will be skipped.

Source: walletrpc/walletkit.proto

gRPC

rpc SignPsbt (SignPsbtRequest) returns (SignPsbtResponse);

REST

HTTP MethodPath
POST /v2/wallet/psbt/sign

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 = {
funded_psbt: <bytes>,
};
client.signPsbt(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "signed_psbt": <bytes>,
// "signed_inputs": <uint32>,
// }

Messages

walletrpc.SignPsbtRequest

Source: walletrpc/walletkit.proto

FieldgRPC TypeREST TypeREST Placement
funded_psbt
bytesstringbody

walletrpc.SignPsbtResponse

Source: walletrpc/walletkit.proto

FieldgRPC TypeREST Type
signed_psbt
bytesstring
signed_inputs
uint32[]array