MCPcopy
hub / github.com/btcsuite/btcd / checkPubKeyEncoding

Method checkPubKeyEncoding

txscript/engine.go:1248–1271  ·  view source on GitHub ↗

checkPubKeyEncoding returns whether or not the passed public key adheres to the strict encoding requirements if enabled.

(pubKey []byte)

Source from the content-addressed store, hash-verified

1246// checkPubKeyEncoding returns whether or not the passed public key adheres to
1247// the strict encoding requirements if enabled.
1248func (vm *Engine) checkPubKeyEncoding(pubKey []byte) error {
1249 if vm.hasFlag(ScriptVerifyWitnessPubKeyType) &&
1250 vm.isWitnessVersionActive(BaseSegwitWitnessVersion) &&
1251 !btcec.IsCompressedPubKey(pubKey) {
1252
1253 str := "only compressed keys are accepted post-segwit"
1254 return scriptError(ErrWitnessPubKeyType, str)
1255 }
1256
1257 if !vm.hasFlag(ScriptVerifyStrictEncoding) {
1258 return nil
1259 }
1260
1261 if len(pubKey) == 33 && (pubKey[0] == 0x02 || pubKey[0] == 0x03) {
1262 // Compressed
1263 return nil
1264 }
1265 if len(pubKey) == 65 && pubKey[0] == 0x04 {
1266 // Uncompressed
1267 return nil
1268 }
1269
1270 return scriptError(ErrPubKeyType, "unsupported public key type")
1271}
1272
1273// checkSignatureEncoding returns whether or not the passed signature adheres to
1274// the strict encoding requirements if enabled.

Callers 4

TestCheckPubKeyEncodingFunction · 0.95
parseBaseSigAndPubkeyFunction · 0.80
opcodeCheckSigFunction · 0.80
opcodeCheckMultiSigFunction · 0.80

Calls 3

hasFlagMethod · 0.95
scriptErrorFunction · 0.85

Tested by 1

TestCheckPubKeyEncodingFunction · 0.76