MCPcopy Create free account
hub / github.com/0xsequence/czip / WriteSequenceSignatureBody

Method WriteSequenceSignatureBody

compressor/encode.go:567–610  ·  view source on GitHub ↗
(noChain bool, body []byte)

Source from the content-addressed store, hash-verified

565}
566
567func (buf *Buffer) WriteSequenceSignatureBody(noChain bool, body []byte) (EncodeType, error) {
568 // The first 2 bytes are the threshold
569 // this (alongside the noChain flag) defines
570 // the encoding flag
571 if len(body) < 2 {
572 return Stateless, fmt.Errorf("signature is too short")
573 }
574
575 threshold := uint(body[0])<<8 | uint(body[1])
576 longThreshold := threshold > 0xff
577
578 var tflag uint
579
580 if !longThreshold && !noChain {
581 tflag = FLAG_SEQUENCE_SIG
582 } else if !longThreshold && noChain {
583 tflag = FLAG_SEQUENCE_SIG_NO_CHAIN
584 } else if longThreshold && !noChain {
585 tflag = FLAG_SEQUENCE_L_SIG
586 } else {
587 tflag = FLAG_SEQUENCE_L_SIG_NO_CHAIN
588 }
589
590 buf.commitUint(tflag)
591
592 // On long threshold we use 2 bytes for the threshold
593 if longThreshold {
594 buf.commitBytes(body[:2])
595 } else {
596 buf.commitByte(body[1])
597 }
598
599 buf.end(body, Stateless)
600
601 // Next 4 bytes is the checkpoint
602 if len(body) < 6 {
603 return Stateless, fmt.Errorf("signature is too short")
604 }
605
606 checkpoint := body[2:6]
607 buf.WriteWord(checkpoint, false)
608
609 return buf.WriteSequenceSignatureTree(body[6:])
610}
611
612func (buf *Buffer) WriteSequenceSignatureTree(tree []byte) (EncodeType, error) {
613 // Signature trees need to be encoded as N nested bytes (one per part)

Callers 1

Calls 6

commitUintMethod · 0.95
commitBytesMethod · 0.95
commitByteMethod · 0.95
endMethod · 0.95
WriteWordMethod · 0.95

Tested by

no test coverage detected