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

Method WriteSequenceDynamicSignaturePart

compressor/encode.go:771–806  ·  view source on GitHub ↗
(address []byte, weight uint, signature []byte)

Source from the content-addressed store, hash-verified

769}
770
771func (buf *Buffer) WriteSequenceDynamicSignaturePart(address []byte, weight uint, signature []byte) (EncodeType, error) {
772 if weight > 255 {
773 return Stateless, fmt.Errorf("weight exceeds 255")
774 }
775
776 if signature[len(signature)-1] != 0x03 {
777 return Stateless, fmt.Errorf("signature is not a dynamic signature")
778 }
779
780 unsuffixed := signature[:len(signature)-1]
781
782 buf.commitUint(FLAG_SEQUENCE_DYNAMIC_SIGNATURE)
783 buf.commitUint(weight)
784 buf.end([]byte{}, Stateless)
785
786 // The address must be 20 bytes long
787 // write it as a word
788 if len(address) != 20 {
789 return Stateless, fmt.Errorf("address is not 20 bytes long")
790 }
791
792 t1, err := buf.WriteWord(address, true)
793 if err != nil {
794 return Stateless, err
795 }
796
797 // Encode the signature using bytes, as it may or may not be a Sequence signature
798 // bytes is going to try to encode it as a Sequence signature, if it fails it will
799 // encode it as a bunch of bytes
800 t2, err := buf.WriteBytesOptimized(unsuffixed, true)
801 if err != nil {
802 return Stateless, err
803 }
804
805 return maxPriority(t1, t2), nil
806}
807
808func (buf *Buffer) WriteSequenceChainedSignature(signature []byte) (EncodeType, error) {
809 // First we need to count how many chained signatures are there

Calls 5

commitUintMethod · 0.95
endMethod · 0.95
WriteWordMethod · 0.95
WriteBytesOptimizedMethod · 0.95
maxPriorityFunction · 0.85

Tested by

no test coverage detected