-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic wireing of the remote signer
- Loading branch information
1 parent
433d1a2
commit 84035c7
Showing
6 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package config | ||
|
||
import "time" | ||
|
||
const ( | ||
defaultUrl = "http://127.0.0.1:9791" | ||
defaultTimeout = 2 * time.Second | ||
) | ||
|
||
type RemoteSignerCfg struct { | ||
URL string `long:"url" description:"URL of the remote signer"` | ||
Timeout time.Duration `long:"timeout" description:"client when making requests to the remote signer"` | ||
} | ||
|
||
func DefaultRemoteSignerConfig() RemoteSignerCfg { | ||
return RemoteSignerCfg{ | ||
URL: defaultUrl, | ||
Timeout: defaultTimeout, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package remotesigner | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/babylonlabs-io/covenant-emulator/config" | ||
"github.com/babylonlabs-io/covenant-emulator/covenant" | ||
"github.com/babylonlabs-io/covenant-emulator/covenant-signer/signerapp" | ||
"github.com/babylonlabs-io/covenant-emulator/covenant-signer/signerservice" | ||
"github.com/btcsuite/btcd/btcec/v2" | ||
) | ||
|
||
var _ covenant.Signer = RemoteSigner{} | ||
|
||
func covenantRequestToSignerRequest(req covenant.SigningRequest) *signerapp.ParsedSigningRequest { | ||
return &signerapp.ParsedSigningRequest{ | ||
StakingTx: req.StakingTx, | ||
SlashingTx: req.SlashingTx, | ||
UnbondingTx: req.UnbondingTx, | ||
SlashUnbondingTx: req.SlashUnbondingTx, | ||
StakingOutputIdx: req.StakingOutputIdx, | ||
SlashingScript: req.SlashingPkScriptPath, | ||
UnbondingScript: req.StakingTxUnbondingPkScriptPath, | ||
UnbondingSlashingScript: req.UnbondingTxSlashingPkScriptPath, | ||
FpEncKeys: req.FpEncKeys, | ||
} | ||
} | ||
|
||
func signerResponseToCovenantResponse(resp *signerapp.ParsedSigningResponse) *covenant.SignaturesResponse { | ||
return &covenant.SignaturesResponse{ | ||
SlashSigs: resp.SlashAdaptorSigs, | ||
UnbondingSig: resp.UnbondingSig, | ||
SlashUnbondingSigs: resp.SlashUnbondingAdaptorSigs, | ||
} | ||
} | ||
|
||
type RemoteSigner struct { | ||
cfg *config.RemoteSignerCfg | ||
} | ||
|
||
func NewRemoteSigner(cfg *config.RemoteSignerCfg) RemoteSigner { | ||
return RemoteSigner{ | ||
cfg: cfg, | ||
} | ||
} | ||
|
||
func (rs RemoteSigner) PubKey() (*btcec.PublicKey, error) { | ||
return signerservice.GetPublicKey(context.Background(), rs.cfg.URL, rs.cfg.Timeout) | ||
} | ||
|
||
func (rs RemoteSigner) SignTransactions(req covenant.SigningRequest) (*covenant.SignaturesResponse, error) { | ||
resp, err := signerservice.RequestCovenantSignaure( | ||
context.Background(), | ||
rs.cfg.URL, | ||
rs.cfg.Timeout, | ||
covenantRequestToSignerRequest(req), | ||
) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return signerResponseToCovenantResponse(resp), nil | ||
} |