MCPcopy
hub / github.com/canopy-network/canopy / Add

Method Add

lib/crypto/key_batch.go:69–95  ·  view source on GitHub ↗

Add() adds a tuple to the batch verifier

(pk PublicKeyI, publicKey, message, signature []byte)

Source from the content-addressed store, hash-verified

67
68// Add() adds a tuple to the batch verifier
69func (b *BatchVerifier) Add(pk PublicKeyI, publicKey, message, signature []byte) (err error) {
70 // if no-op enabled
71 if b.noOp {
72 // exit
73 return nil
74 }
75 // initialize the batch tuple object and append to the proper list
76 t := BatchTuple{PublicKey: pk, Message: message, Signature: signature, index: b.count}
77 listIdx := b.count % 8
78 // depending on the public key length
79 switch len(publicKey) {
80 case Ed25519PubKeySize:
81 b.ed25519[listIdx] = append(b.ed25519[listIdx], t)
82 case ETHSECP256K1PubKeySize, ETHSECP256K1PubKeySize + 1:
83 b.ethSecp256k1[listIdx] = append(b.ethSecp256k1[listIdx], t)
84 case SECP256K1PubKeySize:
85 b.secp256k1[listIdx] = append(b.secp256k1[listIdx], t)
86 case BLS12381PubKeySize:
87 b.bls12381[listIdx] = append(b.bls12381[listIdx], t)
88 default:
89 return fmt.Errorf("unrecognized public key format")
90 }
91 // increment the global count
92 b.count++
93 // exit
94 return
95}
96
97// Verify() returns the indices of bad signatures (if any)
98func (b *BatchVerifier) Verify() (badIndices []int) {

Callers 9

TestKeyBatchFuzzFunction · 0.95
TestBenchmarkBatchFunction · 0.95
verifyAllMethod · 0.95
checkFunction · 0.45
MultiplyMethod · 0.45
NormalizedMethod · 0.45
ReducedMethod · 0.45
NewDiscriminantFunction · 0.45
VerifyMethod · 0.45

Calls 1

ErrorfMethod · 0.65

Tested by 3

TestKeyBatchFuzzFunction · 0.76
TestBenchmarkBatchFunction · 0.76
checkFunction · 0.36