Skip to content

Commit a754d32

Browse files
authored
v3: add pending updates to wallet config (#345)
* v3: add pending updates to wallet config * specify image hash for deployment * use the correct function to encode wallet deployment
1 parent fb0f1c4 commit a754d32

3 files changed

Lines changed: 30 additions & 13 deletions

File tree

core/v3/v3.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ func (v3Core) DecodeSignature(data []byte) (core.Signature[*WalletConfig], error
4242
}
4343

4444
signatureFlag := data[0]
45-
data = data[1:]
4645

4746
signatureType := signatureFlag & 0x03
4847
if signatureType == 0x01 {
4948
return decodeChainedSignature(data)
5049
}
5150

51+
data = data[1:]
52+
5253
noChainId := (signatureType & 0x02) == 0x02
5354

5455
var checkpointer common.Address
@@ -1316,7 +1317,6 @@ func (l signatureTreeSubdigestLeaf) reduceImageHash() (core.ImageHash, error) {
13161317

13171318
func (l signatureTreeSubdigestLeaf) write(writer io.Writer) error {
13181319
_, err := writer.Write([]byte{FLAG_SUBDIGEST << 4})
1319-
13201320
if err != nil {
13211321
return fmt.Errorf("unable to write subdigest leaf type: %w", err)
13221322
}
@@ -1556,6 +1556,7 @@ func (l *signatureTreeSignatureEthSignLeaf) reduce() signatureTree { return l }
15561556
func (l *signatureTreeSignatureEthSignLeaf) join(other signatureTree) (signatureTree, error) {
15571557
return l, nil
15581558
}
1559+
15591560
func (l *signatureTreeSignatureEthSignLeaf) reduceImageHash() (core.ImageHash, error) {
15601561
return core.ImageHash{}, fmt.Errorf("eth sign signature has signing power")
15611562
}
@@ -1906,6 +1907,8 @@ type WalletConfig struct {
19061907
Checkpoint_ uint64 `json:"checkpoint" toml:"checkpoint"`
19071908
Tree WalletConfigTree `json:"tree" toml:"tree"`
19081909
Checkpointer common.Address `json:"checkpointer,omitempty" toml:"checkpointer,omitempty"`
1910+
1911+
PendingUpdates []core.Signature[*WalletConfig] `json:"-" toml:"-"`
19091912
}
19101913

19111914
func (c *WalletConfig) Threshold() uint16 {

utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func DeploySequenceWallet(sender *ethwallet.Wallet, walletConfig core.WalletConf
5858

5959
func EncodeWalletDeployment(walletConfig core.WalletConfig, walletContext WalletContext) (common.Address, common.Address, []byte, error) {
6060
imageHash := walletConfig.ImageHash()
61+
return EncodeWalletDeploymentWithImageHash(walletConfig, walletContext, imageHash)
62+
}
63+
64+
func EncodeWalletDeploymentWithImageHash(walletConfig core.WalletConfig, walletContext WalletContext, imageHash core.ImageHash) (common.Address, common.Address, []byte, error) {
6165
address, err := AddressFromImageHash(imageHash, walletContext)
6266
if err != nil {
6367
return common.Address{}, common.Address{}, nil, err

wallet.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func GenericNewWalletSingleOwner[C core.WalletConfig](owner Signer, optContext .
108108
if _, ok := core.WalletConfig(typeOfWallet).(*v1.WalletConfig); ok {
109109
// new wallet config v1
110110
var config core.WalletConfig = &v1.WalletConfig{
111-
Threshold_: 1, //big.NewInt(1),
111+
Threshold_: 1, // big.NewInt(1),
112112
Signers_: v1.WalletConfigSigners{
113113
{Weight: 1, Address: owner.Address()},
114114
},
@@ -122,7 +122,7 @@ func GenericNewWalletSingleOwner[C core.WalletConfig](owner Signer, optContext .
122122
} else if _, ok := core.WalletConfig(typeOfWallet).(*v2.WalletConfig); ok {
123123
// new wallet config v2
124124
var config core.WalletConfig = &v2.WalletConfig{
125-
Threshold_: 1, //big.NewInt(1),
125+
Threshold_: 1, // big.NewInt(1),
126126
Tree: &v2.WalletConfigTreeAddressLeaf{
127127
Weight: 1, Address: owner.Address(),
128128
},
@@ -136,7 +136,7 @@ func GenericNewWalletSingleOwner[C core.WalletConfig](owner Signer, optContext .
136136
} else if _, ok := core.WalletConfig(typeOfWallet).(*v3.WalletConfig); ok {
137137
// new wallet config v3
138138
var config core.WalletConfig = &v3.WalletConfig{
139-
Threshold_: 1, //big.NewInt(1),
139+
Threshold_: 1, // big.NewInt(1),
140140
Tree: &v3.WalletConfigTreeAddressLeaf{
141141
Weight: 1, Address: owner.Address(),
142142
},
@@ -260,7 +260,6 @@ func (w *Wallet[C]) UseConfig(config C) (*Wallet[C], error) {
260260
SkipSortSigners: w.skipSortSigners,
261261
Address: w.address,
262262
})
263-
264263
if err != nil {
265264
return nil, fmt.Errorf("sequence.Wallet#UseConfig: %w", err)
266265
}
@@ -286,7 +285,6 @@ func (w *Wallet[C]) UseSigners(signers ...Signer) (*Wallet[C], error) {
286285
SkipSortSigners: w.skipSortSigners,
287286
Address: w.address,
288287
})
289-
290288
if err != nil {
291289
return nil, fmt.Errorf("sequence.Wallet#UseSigners: %w", err)
292290
}
@@ -485,9 +483,11 @@ func (w *Wallet[C]) SignTypedData(typedData *ethcoder.TypedData) ([]byte, []byte
485483
return signature, encodedTypedData, nil
486484
}
487485

488-
var _ MessageSigner = (*Wallet[*v1.WalletConfig])(nil)
489-
var _ MessageSigner = (*Wallet[*v2.WalletConfig])(nil)
490-
var _ MessageSigner = (*Wallet[*v3.WalletConfig])(nil)
486+
var (
487+
_ MessageSigner = (*Wallet[*v1.WalletConfig])(nil)
488+
_ MessageSigner = (*Wallet[*v2.WalletConfig])(nil)
489+
_ MessageSigner = (*Wallet[*v3.WalletConfig])(nil)
490+
)
491491

492492
func (w *Wallet[C]) SignDigest(ctx context.Context, digest common.Hash, optChainID ...*big.Int) ([]byte, error) {
493493
if w.sessions != nil {
@@ -612,8 +612,10 @@ func (w *Wallet[C]) SignV3Payload(ctx context.Context, payload core.Payload, opt
612612
return res, sig, err
613613
}
614614

615-
var _ DigestSigner = (*Wallet[*v1.WalletConfig])(nil)
616-
var _ DigestSigner = (*Wallet[*v2.WalletConfig])(nil)
615+
var (
616+
_ DigestSigner = (*Wallet[*v1.WalletConfig])(nil)
617+
_ DigestSigner = (*Wallet[*v2.WalletConfig])(nil)
618+
)
617619

618620
func (w *Wallet[C]) SignTransaction(ctx context.Context, txn *Transaction) (*SignedTransactions, error) {
619621
return w.SignTransactions(ctx, Transactions{txn})
@@ -861,6 +863,10 @@ func (w *Wallet[C]) IsDeployed() (bool, error) {
861863
}
862864

863865
func (w *Wallet[C]) Deploy(ctx context.Context, transactions ...*Transaction) (MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error) {
866+
return w.DeployWithImageHash(ctx, w.config.ImageHash(), transactions...)
867+
}
868+
869+
func (w *Wallet[C]) DeployWithImageHash(ctx context.Context, imageHash core.ImageHash, transactions ...*Transaction) (MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error) {
864870
if w.relayer == nil {
865871
return "", nil, nil, ErrRelayerNotSet
866872
}
@@ -870,7 +876,7 @@ func (w *Wallet[C]) Deploy(ctx context.Context, transactions ...*Transaction) (M
870876
return "", nil, nil, fmt.Errorf("already deployed")
871877
}
872878

873-
walletAddress, walletFactoryAddress, deploymentData, err := EncodeWalletDeployment(w.config, w.context)
879+
walletAddress, walletFactoryAddress, deploymentData, err := EncodeWalletDeploymentWithImageHash(w.config, w.context, imageHash)
874880
if err != nil {
875881
return "", nil, nil, err
876882
}
@@ -1046,6 +1052,10 @@ func (w *Wallet[C]) buildSignature(ctx context.Context, sign core.SigningFunctio
10461052
}
10471053
}
10481054

1055+
if len(config.PendingUpdates) > 0 {
1056+
sig = append(v3.ChainedSignature{sig}, config.PendingUpdates...)
1057+
}
1058+
10491059
sigEnc, err := sig.Data()
10501060
if err != nil {
10511061
return nil, nil, fmt.Errorf("SignDigest, sig.Data: %w", err)

0 commit comments

Comments
 (0)