lnrpc/signrpc: add ComputeInputScript to the Signer sub-server

In this commit, we add the ComputeInputScript which will allow callers
to obtain witnesses for all outputs under control of the wallet. This
allows external scripting of things like coin join, etc.
This commit is contained in:
Olaoluwa Osuntokun 2018-11-28 20:08:00 -08:00
parent a8ac3cfe7d
commit 6c201e435a
No known key found for this signature in database
GPG Key ID: CE58F7F8E20FD9A2
2 changed files with 171 additions and 34 deletions

@ -14,6 +14,8 @@ It has these top-level messages:
SignDescriptor
SignReq
SignResp
InputScript
InputScriptResp
*/
package signrpc
@ -345,6 +347,50 @@ func (m *SignResp) GetRawSigs() [][]byte {
return nil
}
type InputScript struct {
// / The serializes witness stack for the specified input.
Witness [][]byte `protobuf:"bytes,1,rep,name=witness,proto3" json:"witness,omitempty"`
// **
// The optional sig script for the specified witness that will only be set if
// the input specified is a nested p2sh witness program.
SigScript []byte `protobuf:"bytes,2,opt,name=sig_script,json=sigScript,proto3" json:"sig_script,omitempty"`
}
func (m *InputScript) Reset() { *m = InputScript{} }
func (m *InputScript) String() string { return proto.CompactTextString(m) }
func (*InputScript) ProtoMessage() {}
func (*InputScript) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
func (m *InputScript) GetWitness() [][]byte {
if m != nil {
return m.Witness
}
return nil
}
func (m *InputScript) GetSigScript() []byte {
if m != nil {
return m.SigScript
}
return nil
}
type InputScriptResp struct {
InputScripts []*InputScript `protobuf:"bytes,1,rep,name=input_scripts,json=inputScripts" json:"input_scripts,omitempty"`
}
func (m *InputScriptResp) Reset() { *m = InputScriptResp{} }
func (m *InputScriptResp) String() string { return proto.CompactTextString(m) }
func (*InputScriptResp) ProtoMessage() {}
func (*InputScriptResp) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
func (m *InputScriptResp) GetInputScripts() []*InputScript {
if m != nil {
return m.InputScripts
}
return nil
}
func init() {
proto.RegisterType((*KeyLocator)(nil), "signrpc.KeyLocator")
proto.RegisterType((*KeyDescriptor)(nil), "signrpc.KeyDescriptor")
@ -352,6 +398,8 @@ func init() {
proto.RegisterType((*SignDescriptor)(nil), "signrpc.SignDescriptor")
proto.RegisterType((*SignReq)(nil), "signrpc.SignReq")
proto.RegisterType((*SignResp)(nil), "signrpc.SignResp")
proto.RegisterType((*InputScript)(nil), "signrpc.InputScript")
proto.RegisterType((*InputScriptResp)(nil), "signrpc.InputScriptResp")
}
// Reference imports to suppress errors if they are not otherwise used.
@ -372,9 +420,21 @@ type SignerClient interface {
// signed with, and also any optional tweaks. The return value is a fixed
// 64-byte signature (the same format as we use on the wire in Lightning).
//
// If we're unable to sign using the specified keys, then an error will be
// If we are unable to sign using the specified keys, then an error will be
// returned.
SignOutputRaw(ctx context.Context, in *SignReq, opts ...grpc.CallOption) (*SignResp, error)
// *
// 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 output 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.
ComputeInputScript(ctx context.Context, in *SignReq, opts ...grpc.CallOption) (*InputScriptResp, error)
}
type signerClient struct {
@ -394,6 +454,15 @@ func (c *signerClient) SignOutputRaw(ctx context.Context, in *SignReq, opts ...g
return out, nil
}
func (c *signerClient) ComputeInputScript(ctx context.Context, in *SignReq, opts ...grpc.CallOption) (*InputScriptResp, error) {
out := new(InputScriptResp)
err := grpc.Invoke(ctx, "/signrpc.Signer/ComputeInputScript", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Signer service
type SignerServer interface {
@ -404,9 +473,21 @@ type SignerServer interface {
// signed with, and also any optional tweaks. The return value is a fixed
// 64-byte signature (the same format as we use on the wire in Lightning).
//
// If we're unable to sign using the specified keys, then an error will be
// If we are unable to sign using the specified keys, then an error will be
// returned.
SignOutputRaw(context.Context, *SignReq) (*SignResp, error)
// *
// 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 output 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.
ComputeInputScript(context.Context, *SignReq) (*InputScriptResp, error)
}
func RegisterSignerServer(s *grpc.Server, srv SignerServer) {
@ -431,6 +512,24 @@ func _Signer_SignOutputRaw_Handler(srv interface{}, ctx context.Context, dec fun
return interceptor(ctx, in, info, handler)
}
func _Signer_ComputeInputScript_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SignReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SignerServer).ComputeInputScript(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/signrpc.Signer/ComputeInputScript",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SignerServer).ComputeInputScript(ctx, req.(*SignReq))
}
return interceptor(ctx, in, info, handler)
}
var _Signer_serviceDesc = grpc.ServiceDesc{
ServiceName: "signrpc.Signer",
HandlerType: (*SignerServer)(nil),
@ -439,6 +538,10 @@ var _Signer_serviceDesc = grpc.ServiceDesc{
MethodName: "SignOutputRaw",
Handler: _Signer_SignOutputRaw_Handler,
},
{
MethodName: "ComputeInputScript",
Handler: _Signer_ComputeInputScript_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "signrpc/signer.proto",
@ -447,35 +550,39 @@ var _Signer_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("signrpc/signer.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 465 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x92, 0x41, 0x8f, 0xd3, 0x3e,
0x10, 0xc5,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0x32, 0x3d, 0x5c, 0x2e, 0x3d, 0x97, 0x83, 0x96, 0xc9, 0x25, 0xf8, 0x76, 0x88,
0x6c, 0xc8, 0x33, 0xf0, 0x71, 0x8a, 0x14, 0x39, 0x4e, 0x70, 0xe6, 0x21, 0xf5, 0x5a, 0xd6, 0x6f,
0x44, 0x2e, 0x97, 0x5f, 0x60, 0xb2, 0x31, 0xcf, 0x95, 0x7c, 0x84, 0x08, 0xff, 0x5d, 0x9b, 0xeb,
0x51, 0xd6, 0x93, 0xff, 0x1f, 0x4c, 0xa1, 0xfc, 0xf6, 0xf9, 0xa3, 0x7f, 0x1c, 0xd9, 0xec, 0x26,
0xe6, 0x95, 0x7f, 0xf8, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xd0, 0x6b, 0x86, 0xc5, 0xfd, 0x02, 0x00,
0x00,
// 536 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x93, 0xd1, 0x8f, 0xd2, 0x40,
0x10, 0xc6, 0x0f, 0x10, 0xca, 0x4d, 0x5b, 0xd4, 0x95, 0x68, 0xd5, 0x18, 0xb1, 0xf1, 0x0c, 0x4f,
0x18, 0xd1, 0x98, 0xe8, 0x93, 0x39, 0xcd, 0x85, 0x0b, 0x97, 0x5c, 0xb2, 0xf0, 0xde, 0x94, 0xb2,
0xf6, 0x36, 0xe5, 0xda, 0x5e, 0x77, 0x6b, 0xe9, 0x9b, 0xff, 0x83, 0xff, 0xb0, 0x99, 0xdd, 0x05,
0x8a, 0xde, 0x13, 0x7c, 0x5f, 0x67, 0x67, 0x7e, 0x3b, 0x5f, 0x0b, 0x43, 0xc1, 0xe3, 0xb4, 0xc8,
0xa3, 0xf7, 0xf8, 0xcb, 0x8a, 0x49, 0x5e, 0x64, 0x32, 0x23, 0x96, 0x71, 0xfd, 0x19, 0xc0, 0x9c,
0xd5, 0x57, 0x59, 0x14, 0xca, 0xac, 0x20, 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 0xb7, 0xa0, 0xb7, 0x50, 0x5f, 0x11, 0xf9, 0x04, 0x2e,
0xfe, 0xbb, 0x56, 0x5b, 0xa7, 0x61, 0x45, 0x1e, 0x1d, 0x5d, 0x9e, 0xb2, 0xbb, 0x17, 0x8f, 0xff,
0x71, 0x44, 0x4e, 0xbe, 0x01, 0xf9, 0x9e, 0xdd, 0xe6, 0xa5, 0x64, 0xcd, 0xdb, 0xfd, 0x7f, 0xd4,
0xbb, 0x17, 0x86, 0x89, 0x7c, 0xd5, 0x53, 0x9f, 0xef, 0xc7, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff,
0x7b, 0x48, 0x93, 0x2a, 0xd6, 0x03, 0x00, 0x00,
}

@ -103,6 +103,22 @@ message SignResp {
repeated bytes raw_sigs = 1;
}
message InputScript {
/// The serializes witness stack for the specified input.
repeated bytes witness = 1;
/***
The optional sig script for the specified witness that will only be set if
the input specified is a nested p2sh witness program.
*/
bytes sig_script = 2;
}
message InputScriptResp {
/// The set of fully valid input scripts requested.
repeated InputScript input_scripts = 1;
}
service Signer {
/**
SignOutputRaw is a method that can be used to generated a signature for a
@ -111,8 +127,22 @@ service Signer {
signed with, and also any optional tweaks. The return value is a fixed
64-byte signature (the same format as we use on the wire in Lightning).
If we're unable to sign using the specified keys, then an error will be
If we are unable to sign using the specified keys, then an error will be
returned.
*/
rpc SignOutputRaw(SignReq) returns (SignResp);
/**
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 output 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.
*/
rpc ComputeInputScript(SignReq) returns (InputScriptResp);
}