Skip to content

Commit 6432d21

Browse files
committed
feat: ini working v3
1 parent 3bf4528 commit 6432d21

File tree

3 files changed

+34
-233
lines changed

3 files changed

+34
-233
lines changed

cmd/sequence/signature.go

Lines changed: 9 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ type SignatureElement struct {
1919
Values []string `json:"values"`
2020
}
2121

22-
func (s *SignatureElement) ToTree() v3.WalletConfigTree {
23-
return &v3.WalletConfigTreeAddressLeaf{
24-
Address: common.HexToAddress(s.Address),
25-
}
26-
}
27-
2822
type WalletConfigInput struct {
2923
Threshold json.RawMessage `json:"threshold"`
3024
Checkpoint json.RawMessage `json:"checkpoint"`
@@ -161,65 +155,16 @@ func signatureEncode(p *SignatureEncodeParams) (interface{}, error) {
161155

162156
var signatures []SignatureElement
163157
if p.Signatures != "" {
164-
for _, sig := range strings.Fields(p.Signatures) {
165-
parts := strings.Split(sig, ":")
166-
if len(parts) < 2 {
167-
continue
168-
}
169-
170-
if len(parts) == 5 && parts[1] == "hash" {
171-
signatures = append(signatures, SignatureElement{
172-
Address: parts[0],
173-
Type: "hash",
174-
Values: []string{parts[2], parts[3], parts[4]},
175-
})
176-
continue
177-
}
178-
179-
switch parts[0] {
180-
case "signer":
181-
if len(parts) != 3 {
182-
continue
183-
}
184-
signatures = append(signatures, SignatureElement{
185-
Address: parts[1],
186-
Type: "hash",
187-
Values: []string{},
188-
})
189-
case "sapient":
190-
if len(parts) != 4 {
191-
continue
192-
}
193-
signatures = append(signatures, SignatureElement{
194-
Address: parts[2],
195-
Type: "sapient",
196-
Values: []string{parts[1], parts[2], parts[3]},
197-
})
198-
case "subdigest":
199-
if len(parts) != 2 {
200-
continue
201-
}
202-
signatures = append(signatures, SignatureElement{
203-
Type: "subdigest",
204-
Values: []string{parts[1]},
205-
})
206-
case "node":
207-
if len(parts) != 2 {
208-
continue
209-
}
210-
signatures = append(signatures, SignatureElement{
211-
Type: "node",
212-
Values: []string{parts[1]},
213-
})
214-
case "any-address-subdigest":
215-
if len(parts) != 2 {
216-
continue
217-
}
218-
signatures = append(signatures, SignatureElement{
219-
Type: "any-address-subdigest",
220-
Values: []string{parts[1]},
221-
})
158+
sigData := strings.TrimPrefix(p.Signatures, "--signature ")
159+
sigParts := strings.Split(sigData, ":")
160+
161+
if len(sigParts) >= 2 {
162+
sig := SignatureElement{
163+
Address: sigParts[0],
164+
Type: sigParts[1],
165+
Values: sigParts[2:],
222166
}
167+
signatures = append(signatures, sig)
223168
}
224169
}
225170

core/v3/v3.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ func (s *NoChainIDSignature) Write(writer io.Writer) error {
412412
if checkpointSize > 7 {
413413
return fmt.Errorf("checkpoint size %d exceeds maximum of 7 bytes", checkpointSize)
414414
}
415+
415416
if thresholdSize == 0 {
416417
thresholdSize = 1
417418
}
@@ -575,32 +576,26 @@ func (s ChainedSignature) Data() ([]byte, error) {
575576
}
576577

577578
func (s ChainedSignature) Write(writer io.Writer) error {
578-
// Default flag
579579
flag := byte(0x01)
580580

581-
// Check the last signature for Checkpointer, if the slice is not empty
582581
if len(s) > 0 {
583582
lastSig := s[len(s)-1]
584-
// Type assertion to concrete types
585583
if regSig, ok := lastSig.(*RegularSignature); ok {
586-
// Access Checkpointer through the embedded Signature struct
587584
if regSig.Signature.Checkpointer != (common.Address{}) {
588-
flag |= 0x40 // Set bit [6] if Checkpointer is present
585+
flag |= 0x40
589586
}
590587
} else if noChainSig, ok := lastSig.(*NoChainIDSignature); ok {
591588
if noChainSig.Signature.Checkpointer != (common.Address{}) {
592-
flag |= 0x40 // Set bit [6] if Checkpointer is present
589+
flag |= 0x40
593590
}
594591
}
595592
}
596593

597-
// Write the flag
598594
_, err := writer.Write([]byte{flag})
599595
if err != nil {
600596
return fmt.Errorf("unable to write chained signature type: %w", err)
601597
}
602598

603-
// Write Checkpointer data if present
604599
if len(s) > 0 {
605600
lastSig := s[len(s)-1]
606601
if regSig, ok := lastSig.(*RegularSignature); ok && regSig.Signature.Checkpointer != (common.Address{}) {
@@ -632,7 +627,6 @@ func (s ChainedSignature) Write(writer io.Writer) error {
632627
}
633628
}
634629

635-
// Write all subsignatures
636630
for i, subsignature := range s {
637631
data, err := subsignature.Data()
638632
if err != nil {
@@ -911,7 +905,6 @@ func (l *signatureTreeSignatureHashLeaf) reduceImageHash() (core.ImageHash, erro
911905
func (l *signatureTreeSignatureHashLeaf) write(writer io.Writer) error {
912906
var flag byte
913907
var weightBytes []byte
914-
915908
flag = FLAG_SIGNATURE_HASH << 4
916909

917910
if l.Weight > 0 && l.Weight <= 15 {
@@ -938,7 +931,6 @@ func (l *signatureTreeSignatureHashLeaf) write(writer io.Writer) error {
938931
}
939932

940933
s := l.YParityAndS
941-
942934
if l.V%2 == 0 {
943935
s[0] |= 0x80
944936
}
@@ -1001,27 +993,30 @@ func (l *signatureTreeAddressLeaf) reduceImageHash() (core.ImageHash, error) {
1001993
func (l *signatureTreeAddressLeaf) write(writer io.Writer) error {
1002994
flag := byte(FLAG_ADDRESS << 4)
1003995
var weightBytes []byte
996+
1004997
if l.Weight > 0 && l.Weight <= 15 {
1005998
flag |= l.Weight
1006-
} else if l.Weight <= 255 {
1007-
weightBytes = []byte{l.Weight}
1008999
} else {
1009-
return fmt.Errorf("weight too large: %d", l.Weight)
1000+
weightBytes = []byte{l.Weight}
10101001
}
1002+
10111003
_, err := writer.Write([]byte{flag})
10121004
if err != nil {
10131005
return fmt.Errorf("unable to write address leaf type: %w", err)
10141006
}
1007+
10151008
if len(weightBytes) > 0 {
10161009
_, err = writer.Write(weightBytes)
10171010
if err != nil {
10181011
return fmt.Errorf("unable to write dynamic weight: %w", err)
10191012
}
10201013
}
1014+
10211015
_, err = writer.Write(l.Address.Bytes())
10221016
if err != nil {
10231017
return fmt.Errorf("unable to write address: %w", err)
10241018
}
1019+
10251020
return nil
10261021
}
10271022

@@ -1204,10 +1199,12 @@ func (l signatureTreeNodeLeaf) write(writer io.Writer) error {
12041199
if err != nil {
12051200
return fmt.Errorf("unable to write node leaf type: %w", err)
12061201
}
1202+
12071203
_, err = writer.Write(l.Bytes())
12081204
if err != nil {
12091205
return fmt.Errorf("unable to write node hash: %w", err)
12101206
}
1207+
12111208
return nil
12121209
}
12131210

@@ -1258,13 +1255,16 @@ func (l signatureTreeSubdigestLeaf) reduceImageHash() (core.ImageHash, error) {
12581255

12591256
func (l signatureTreeSubdigestLeaf) write(writer io.Writer) error {
12601257
_, err := writer.Write([]byte{FLAG_SUBDIGEST << 4})
1258+
12611259
if err != nil {
12621260
return fmt.Errorf("unable to write subdigest leaf type: %w", err)
12631261
}
1262+
12641263
_, err = writer.Write(l.Bytes())
12651264
if err != nil {
12661265
return fmt.Errorf("unable to write subdigest: %w", err)
12671266
}
1267+
12681268
return nil
12691269
}
12701270

@@ -1372,20 +1372,16 @@ func (l *signatureTreeNestedLeaf) write(writer io.Writer) error {
13721372
var weightBytes []byte
13731373
if l.Weight <= 3 && l.Weight > 0 {
13741374
flag |= (l.Weight << 2)
1375-
} else if l.Weight <= 255 {
1376-
weightBytes = []byte{l.Weight}
13771375
} else {
1378-
return fmt.Errorf("weight too large: %d", l.Weight)
1376+
weightBytes = []byte{l.Weight}
13791377
}
13801378

13811379
var thresholdBytes []byte
13821380
if l.Threshold <= 3 && l.Threshold > 0 {
13831381
flag |= byte(l.Threshold)
1384-
} else if l.Threshold <= 65535 {
1382+
} else {
13851383
thresholdBytes = make([]byte, 2)
13861384
binary.BigEndian.PutUint16(thresholdBytes, l.Threshold)
1387-
} else {
1388-
return fmt.Errorf("threshold too large: %d", l.Threshold)
13891385
}
13901386

13911387
_, err := writer.Write([]byte{flag})
@@ -1490,33 +1486,35 @@ func (l *signatureTreeSignatureEthSignLeaf) reduceImageHash() (core.ImageHash, e
14901486
func (l *signatureTreeSignatureEthSignLeaf) write(writer io.Writer) error {
14911487
flag := byte(FLAG_SIGNATURE_ETH_SIGN << 4)
14921488
var weightBytes []byte
1489+
14931490
if l.Weight > 0 && l.Weight <= 15 {
14941491
flag |= l.Weight
1495-
} else if l.Weight <= 255 {
1496-
weightBytes = []byte{l.Weight}
14971492
} else {
1498-
return fmt.Errorf("weight too large: %d", l.Weight)
1493+
weightBytes = []byte{l.Weight}
14991494
}
1495+
15001496
_, err := writer.Write([]byte{flag})
15011497
if err != nil {
15021498
return fmt.Errorf("unable to write eth sign leaf type: %w", err)
15031499
}
1500+
15041501
if len(weightBytes) > 0 {
15051502
_, err = writer.Write(weightBytes)
15061503
if err != nil {
15071504
return fmt.Errorf("unable to write dynamic weight: %w", err)
15081505
}
15091506
}
1507+
15101508
_, err = writer.Write(l.R[:])
15111509
if err != nil {
15121510
return fmt.Errorf("unable to write R: %w", err)
15131511
}
1512+
15141513
s := l.YParityAndS
15151514
if l.V%2 == 0 {
15161515
s[0] |= 0x80
1517-
} else {
1518-
s[0] &= 0x7f
15191516
}
1517+
15201518
_, err = writer.Write(s[:])
15211519
if err != nil {
15221520
return fmt.Errorf("unable to write YParityAndS: %w", err)
@@ -1565,10 +1563,12 @@ func (l *signatureTreeAnyAddressSubdigestLeaf) write(writer io.Writer) error {
15651563
if err != nil {
15661564
return fmt.Errorf("unable to write any address subdigest leaf type: %w", err)
15671565
}
1566+
15681567
_, err = writer.Write(l.Subdigest.Bytes())
15691568
if err != nil {
15701569
return fmt.Errorf("unable to write subdigest: %w", err)
15711570
}
1571+
15721572
return nil
15731573
}
15741574

0 commit comments

Comments
 (0)