mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-10-14 00:59:21 +00:00
Introduce Liquid network parameters (#64)
Up to know we just use the Bitcoin mainnet parameters `chaincfg.MainNetParams` for Liquid. That's okay, because we use them for creating and verifying extended private and public keys. Those only depend on `HDPrivateKeyID` and `HDPublicKeyID`, which are the same for Bitcoin and Liquid networks. The only real difference is the `HDCoinType` used for key derivation, which we want to use in the future. So it is a good idea to introduce this value now. Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
parent
1383d0aaa6
commit
3fe9c018cd
@ -4,6 +4,9 @@ import (
|
|||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LiquidNetParams defines the network parameters for the Liquid network.
|
||||||
|
var LiquidNetParams chaincfg.Params
|
||||||
|
|
||||||
// PlmntNetParams defines the network parameters for the Planetmint network.
|
// PlmntNetParams defines the network parameters for the Planetmint network.
|
||||||
var PlmntNetParams = chaincfg.Params{
|
var PlmntNetParams = chaincfg.Params{
|
||||||
Name: "planetmint",
|
Name: "planetmint",
|
||||||
@ -18,6 +21,15 @@ var PlmntNetParams = chaincfg.Params{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
// Not allowed to register LiquidNetParams, because it's just another
|
||||||
|
// Bitcoin network with different coin type.
|
||||||
|
// See https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
||||||
|
LiquidNetParams = chaincfg.MainNetParams
|
||||||
|
LiquidNetParams.Name = "liquidv1"
|
||||||
|
LiquidNetParams.HDCoinType = 1776
|
||||||
|
|
||||||
|
// Need to register PlmntNetParams, otherwise we get an "unknown hd
|
||||||
|
// private extended key bytes" error.
|
||||||
err := chaincfg.Register(&PlmntNetParams)
|
err := chaincfg.Register(&PlmntNetParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
assettestutils "planetmint-go/x/asset/testutil"
|
assettestutils "planetmint-go/x/asset/testutil"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
|
||||||
tmdb "github.com/cometbft/cometbft-db"
|
tmdb "github.com/cometbft/cometbft-db"
|
||||||
"github.com/cometbft/cometbft/libs/log"
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||||
@ -51,7 +50,7 @@ func AssetKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
|||||||
mk := assettestutils.NewMockMachineKeeper(ctrl)
|
mk := assettestutils.NewMockMachineKeeper(ctrl)
|
||||||
sk, pk := sample.KeyPair()
|
sk, pk := sample.KeyPair()
|
||||||
_, ppk := sample.ExtendedKeyPair(config.PlmntNetParams)
|
_, ppk := sample.ExtendedKeyPair(config.PlmntNetParams)
|
||||||
_, lpk := sample.ExtendedKeyPair(chaincfg.MainNetParams)
|
_, lpk := sample.ExtendedKeyPair(config.LiquidNetParams)
|
||||||
id := sample.MachineIndex(pk, ppk, lpk)
|
id := sample.MachineIndex(pk, ppk, lpk)
|
||||||
mk.EXPECT().GetMachineIndex(ctx, pk).Return(id, true).AnyTimes()
|
mk.EXPECT().GetMachineIndex(ctx, pk).Return(id, true).AnyTimes()
|
||||||
mk.EXPECT().GetMachineIndex(ctx, sk).Return(id, false).AnyTimes()
|
mk.EXPECT().GetMachineIndex(ctx, sk).Return(id, false).AnyTimes()
|
||||||
|
@ -50,7 +50,7 @@ func AccAddress() string {
|
|||||||
|
|
||||||
func Machine(name, pubKey string) machinetypes.Machine {
|
func Machine(name, pubKey string) machinetypes.Machine {
|
||||||
metadata := Metadata()
|
metadata := Metadata()
|
||||||
_, liquidPubKey := ExtendedKeyPair(chaincfg.MainNetParams)
|
_, liquidPubKey := ExtendedKeyPair(config.LiquidNetParams)
|
||||||
_, planetmintPubKey := ExtendedKeyPair(config.PlmntNetParams)
|
_, planetmintPubKey := ExtendedKeyPair(config.PlmntNetParams)
|
||||||
m := machinetypes.Machine{
|
m := machinetypes.Machine{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
@ -28,7 +28,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
|
|||||||
if !isValidIssuerPlanetmint {
|
if !isValidIssuerPlanetmint {
|
||||||
return nil, errors.New("invalid planetmint key")
|
return nil, errors.New("invalid planetmint key")
|
||||||
}
|
}
|
||||||
isValidIssuerLiquid := validateExtendedPublicKey(msg.Machine.IssuerLiquid, chaincfg.MainNetParams)
|
isValidIssuerLiquid := validateExtendedPublicKey(msg.Machine.IssuerLiquid, config.LiquidNetParams)
|
||||||
if !isValidIssuerLiquid {
|
if !isValidIssuerLiquid {
|
||||||
return nil, errors.New("invalid liquid key")
|
return nil, errors.New("invalid liquid key")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user