Skip to main content

ComputeInputScript

ComputeInputScript generates a complete InputIndex for the passed transaction with the signature as defined within the passed SignDescriptor. This method should be capable of generating the proper input script for both regular p2wkh/p2tr outputs and p2wkh outputs nested within a regular p2sh output.

Note that when using this method to sign inputs belonging to the wallet, the only items of the SignDescriptor that need to be populated are pkScript in the TxOut field, the value in that same field, and finally the input index.

Source: signrpc/signer.proto

gRPC

rpc ComputeInputScript (SignReq) returns (InputScriptResp);

REST

HTTP MethodPath
POST /v2/signer/inputscript

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', 'signrpc/signer.proto'], loaderOptions);
const signrpc = grpc.loadPackageDefinition(packageDefinition).signrpc;
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 signrpc.Signer(GRPC_HOST, creds);
let request = {
raw_tx_bytes: <bytes>,
sign_descs: <SignDescriptor>,
prev_outputs: <TxOut>,
};
client.computeInputScript(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "input_scripts": <InputScript>,
// }

Messages

signrpc.SignReq

Source: signrpc/signer.proto

FieldgRPC TypeREST TypeREST Placement
raw_tx_bytes
bytesstringbody
sign_descs
SignDescriptor[]arraybody
prev_outputs
TxOut[]arraybody

signrpc.InputScriptResp

Source: signrpc/signer.proto

FieldgRPC TypeREST Type
input_scripts
InputScript[]array

Nested Messages

signrpc.SignDescriptor

FieldgRPC TypeREST Type
key_desc
KeyDescriptorobject
single_tweak
bytesstring
double_tweak
bytesstring
tap_tweak
bytesstring
witness_script
bytesstring
output
TxOutobject
sighash
uint32integer
input_index
int32integer
sign_method
SignMethodstring

signrpc.KeyDescriptor

FieldgRPC TypeREST Type
raw_key_bytes
bytesstring
key_loc
KeyLocatorobject

signrpc.KeyLocator

FieldgRPC TypeREST Type
key_family
int32integer
key_index
int32integer

signrpc.TxOut

FieldgRPC TypeREST Type
value
int64string
pk_script
bytesstring

signrpc.InputScript

FieldgRPC TypeREST Type
witness
bytes[]array
sig_script
bytesstring

Enums

signrpc.SignMethod

NameNumber
SIGN_METHOD_WITNESS_V0
0
SIGN_METHOD_TAPROOT_KEY_SPEND_BIP0086
1
SIGN_METHOD_TAPROOT_KEY_SPEND
2
SIGN_METHOD_TAPROOT_SCRIPT_SPEND
3