backup

package
v0.0.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// FieldSecp256k1OrderID covers secrets that are secp256k1 scalars, which
	// are below the group order by construction.
	FieldSecp256k1OrderID = utils.ToHash("secp256k1-group-order")

	// FieldPrimeAbove256ID covers secrets that are arbitrary 32-byte values,
	// such as wallet seeds, which have no upper bound below 2^256.
	FieldPrimeAbove256ID = utils.ToHash("prime-above-2^256")
)

Field identifiers. These are recorded in backups and must not change value once any backup carrying them exists.

Functions

func WalletFromKeyDirectBackupPayload added in v0.0.21

func WalletFromKeyDirectBackupPayload(p *KeyDirectBackupPayload, privateKey []byte) (*wallets.Wallet, error)

WalletFromKeyDirectBackupPayload reconstructs a wallets.Wallet from a direct-backup payload. The caller decrypts EncryptedPrivateKey out-of-band (typically with the destination TEE's ECIES key) and passes the plaintext private-key bytes in. The decrypted public key must match BackupID.PublicKey. The resulting wallet is marked Restored with a zero status.

Types

type EncryptedShares

type EncryptedShares struct {
	Splits           []hexutil.Bytes
	OwnersPublicKeys []types.PublicKey
	Threshold        uint64
	Weights          []uint16
}

func (*EncryptedShares) Check

func (e *EncryptedShares) Check() error

Check ensures the encrypted shares meet threshold and weighting requirements.

type Field added in v0.0.26

type Field struct {
	ID      common.Hash
	Modulus *bigmod.Modulus

	// Size is the width in bytes of every field element in serialized form.
	Size int
	// contains filtered or unexported fields
}

Field is the prime field a wallet's secret is shared over. Secret sharing is only injective when every possible secret is smaller than the modulus, so the field is selected from the key's metadata rather than fixed globally: a secp256k1 scalar is always below the group order, while a raw 32-byte seed is not.

ID is recorded in the backup so that reconstruction resolves the same field the backup was written with, rather than re-deriving it from a mapping that may have changed.

func FieldFor added in v0.0.26

func FieldFor(keyType, signingAlgo common.Hash) (*Field, error)

FieldFor selects the field a key's secret must be shared over. Unknown combinations are rejected rather than defaulting, because sharing a secret over a field too small for it silently reconstructs a different value.

func FieldForID added in v0.0.26

func FieldForID(id common.Hash) (*Field, error)

FieldForID resolves the field a backup was written with.

func (*Field) Bytes added in v0.0.26

func (f *Field) Bytes(n *bigmod.Nat) []byte

Bytes serializes a field element to the field's fixed width, so a share's encoded length never depends on its value.

func (*Field) Element added in v0.0.26

func (f *Field) Element(b []byte) (*bigmod.Nat, error)

Element converts a secret into a field element, rejecting values the field cannot represent injectively.

func (*Field) ElementFromUint64 added in v0.0.26

func (f *Field) ElementFromUint64(v uint64) *bigmod.Nat

ElementFromUint64 converts a small integer, such as a share index, into a field element.

func (*Field) Random added in v0.0.26

func (f *Field) Random() (*bigmod.Nat, error)

Random returns a uniformly distributed field element.

type KeyDirectBackupPayload added in v0.0.21

type KeyDirectBackupPayload struct {
	BackupID wallets.WalletBackupID `json:"backupId"`

	// EncryptedPrivateKey is ECIES(destinationPub, w.PrivateKey).
	EncryptedPrivateKey hexutil.Bytes `json:"encryptedPrivateKey"`

	AdminPublicKeys    []types.PublicKey `json:"adminPublicKeys"`
	AdminsThreshold    uint64            `json:"adminsThreshold"`
	Cosigners          []common.Address  `json:"cosigners"`
	CosignersThreshold uint64            `json:"cosignersThreshold"`

	SettingsVersion common.Hash   `json:"settingsVersion"`
	Settings        hexutil.Bytes `json:"settings"`

	Status wallets.WalletStatus `json:"status"`
}

KeyDirectBackupPayload is the JSON-serializable form of a wallet produced by KEY_DIRECT_BACKUP. BackupID identifies the wallet+key and binds it to the source TEE, the reward epoch, and a per-backup random nonce. EncryptedPrivateKey is ECIES under the destination's public key; the remaining wallet-configuration fields are plaintext and are covered by the source TEE's signature over the payload.

func NewKeyDirectBackupPayload added in v0.0.21

func NewKeyDirectBackupPayload(
	w *wallets.Wallet,
	sourceTeeID common.Address,
	encryptedPrivateKey hexutil.Bytes,
	rewardEpochID uint32,
	randomNonce common.Hash,
) (*KeyDirectBackupPayload, error)

NewKeyDirectBackupPayload assembles the wire-format direct-backup payload. The caller supplies encryptedPrivateKey (typically ECIES of w.PrivateKey under the destination's public key); the helper derives the secp256k1 public key for BackupID, copies slices defensively, and stamps the freshness markers. Only signing algorithms in wallets.Algos are supported.

type KeySplit

type KeySplit struct {
	KeySplitData
	Signature []byte
}

func DecryptSplit

func DecryptSplit(encryptedShare []byte, privKeyECDSA *ecdsa.PrivateKey, chainID uint64) (*KeySplit, error)

DecryptSplit decrypts an encrypted key split and verifies its integrity.

func (*KeySplit) VerifySignature

func (ks *KeySplit) VerifySignature(chainID uint64) error

VerifySignature checks that the key split signature matches the owner key.

type KeySplitData

type KeySplitData struct {
	Shares []ShamirShare
	PartialWalletBackupID
	OwnerPublicKey types.PublicKey
}

func (*KeySplitData) HashForSigning

func (ksd *KeySplitData) HashForSigning() (common.Hash, error)

HashForSigning computes the hash used when signing the key split data.

func (*KeySplitData) Sign

func (ksd *KeySplitData) Sign(signer wallets.Signer, chainID uint64) ([]byte, error)

Sign signs the key split data with the provided private key.

func (*KeySplitData) SignHash added in v0.0.21

func (ksd *KeySplitData) SignHash(chainID uint64) (common.Hash, error)

SignHash returns the domain-separated, chain-bound preimage signed for a key split: signing.Payload{csigning.PMWKeySplit, chainID, HashForSigning()}.Hash().

type PartialWalletBackupID

type PartialWalletBackupID struct {
	wallets.WalletBackupID
	IsAdmin bool
}

PartialWalletBackupID identifies one of the two additive parts of a backed-up key. IsAdmin selects the part, so a share can only be reconstructed against the group it was issued to.

func (*PartialWalletBackupID) Equal

type ShamirShare

type ShamirShare struct {
	X uint64
	Y []byte
}

ShamirShare is one point on the sharing polynomial. X is the evaluation index, which is public and assigned sequentially. Y is the field element at that index, serialized to the field's fixed width so that a share's encoded length never reveals anything about its value.

func (*ShamirShare) ID

func (s *ShamirShare) ID() string

ID returns the string identifier for the Shamir share.

type WalletBackup

type WalletBackup struct {
	WalletBackupMetaData
	AdminEncryptedParts    *EncryptedShares
	ProviderEncryptedParts *EncryptedShares
	Signature              hexutil.Bytes
	TEESignature           hexutil.Bytes
}

func (*WalletBackup) Check

func (wb *WalletBackup) Check(chainID uint64) error

Check validates the metadata and share alignment in the wallet backup.

func (*WalletBackup) HashForSigning

func (wb *WalletBackup) HashForSigning() (common.Hash, error)

HashForSigning produces the hash over the wallet backup content.

func (*WalletBackup) OwnerSignHash added in v0.0.21

func (wb *WalletBackup) OwnerSignHash(chainID uint64) (common.Hash, error)

OwnerSignHash returns the domain-separated, chain-bound preimage signed by the wallet (owner) key over the backup: signing.Payload{csigning.PMWWalletBackup, chainID, HashForSigning()}.Hash().

func (*WalletBackup) TEESignHash added in v0.0.21

func (wb *WalletBackup) TEESignHash(chainID uint64) (common.Hash, error)

TEESignHash returns the domain-separated, chain-bound preimage signed by the TEE identity key over the backup: signing.Payload{csigning.TEEWalletBackup, chainID, HashForSigning()}.Hash().

type WalletBackupMetaData

type WalletBackupMetaData struct {
	wallets.WalletBackupID

	// FieldID identifies the prime field the key was shared over. It is
	// recorded rather than re-derived at restore so that a backup stays
	// readable if the mapping from key metadata to field ever changes.
	FieldID common.Hash

	AdminsPublicKeys   []types.PublicKey
	AdminsThreshold    uint64
	ProvidersThreshold uint64
	Cosigners          []common.Address
	CosignersThreshold uint64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL