MCPcopy Index your code
hub / github.com/0xsequence/czip / WriteSequenceSignatureTree

Method WriteSequenceSignatureTree

compressor/encode.go:612–741  ·  view source on GitHub ↗
(tree []byte)

Source from the content-addressed store, hash-verified

610}
611
612func (buf *Buffer) WriteSequenceSignatureTree(tree []byte) (EncodeType, error) {
613 // Signature trees need to be encoded as N nested bytes (one per part)
614 // for this we first need to count the number of parts
615 if len(tree) == 0 {
616 return Stateless, fmt.Errorf("signature tree is empty")
617 }
618
619 totalParts := 0
620 pointer := uint(0)
621
622 for pointer < uint(len(tree)) {
623 partType := tree[pointer]
624 pointer += 1
625
626 switch partType {
627 case 0x00: // EOA Signature
628 pointer += (1 + 66)
629 case 0x01: // Address
630 pointer += (1 + 20)
631 case 0x02: // Dynamic
632 pointer += (1 + 20)
633 // 3 bytes after address and weight are the length
634 length := uint(tree[pointer])<<16 | uint(tree[pointer+1])<<8 | uint(tree[pointer+2])
635 pointer += (3 + length)
636 case 0x03: // Node
637 pointer += 32
638 case 0x04: // Branch
639 // 3 bytes of length
640 length := uint(tree[pointer])<<16 | uint(tree[pointer+1])<<8 | uint(tree[pointer+2])
641 pointer += (3 + length)
642 case 0x05: // Subdigest
643 pointer += 32
644 case 0x06: // Nested
645 pointer += 3
646 // 3 bytes of length
647 length := uint(tree[pointer])<<16 | uint(tree[pointer+1])<<8 | uint(tree[pointer+2])
648 pointer += (3 + length)
649 default:
650 return Stateless, fmt.Errorf("invalid signature part type %d", partType)
651 }
652
653 totalParts += 1
654 }
655
656 if totalParts > 1 {
657 if totalParts > 255 {
658 buf.commitUint(FLAG_NESTED_N_FLAGS_L)
659 buf.commitByte(byte(totalParts >> 8))
660 buf.commitByte(byte(totalParts))
661 } else {
662 buf.commitUint(FLAG_NESTED_N_FLAGS_S)
663 buf.commitByte(byte(totalParts))
664 }
665 }
666
667 buf.end([]byte{}, Stateless)
668
669 // Now we need to encode every nested part, one for each signature part

Calls 8

commitUintMethod · 0.95
commitByteMethod · 0.95
endMethod · 0.95
WriteBytesOptimizedMethod · 0.95
maxPriorityFunction · 0.85

Tested by

no test coverage detected