VerificationScript extends NeoSerializable { public List<ECPublicKey> getPublicKeys() { BinaryReader reader = new BinaryReader(this.script); List<ECPublicKey> keys = new ArrayList<>(); try { if (isSingleSigScript()) { reader.readByte(); reader.readByte(); keys.add(new ECPublicKey(reader.readECPoint())); return keys; } else if (isMultiSigScript()) { reader.readPushInteger(); while (reader.readByte() == OpCode.PUSHDATA1.getCode()) { reader.readByte(); keys.add(new ECPublicKey(reader.readECPoint())); } return keys; } } catch (IOException | DeserializationException e) { throw new RuntimeException(e); } throw new ScriptFormatException("The verification script is in an incorrect format. No " + "public keys can be read from it."); } VerificationScript();  VerificationScript(byte[] script);  VerificationScript(ECPublicKey publicKey);  VerificationScript(List<ECPublicKey> publicKeys, int signingThreshold); byte[] getScript(); @Override byte[] toArray(); ScriptHash getScriptHash(); @Override int getSize(); int getSigningThreshold(); int getNrOfAccounts(); boolean isSingleSigScript(); boolean isMultiSigScript(); List<ECPublicKey> getPublicKeys(); @Override void deserialize(BinaryReader reader); @Override void serialize(BinaryWriter writer); @Override boolean equals(Object o); @Override int hashCode();  }
@Test(expected = ScriptFormatException.class) public void throwOnInvalidScriptFormat1() { VerificationScript script = new VerificationScript( Numeric.hexStringToByteArray("0123456789abcdef")); script.getPublicKeys(); }
@Test public void getPublicKeysFromSingleSigScript() { byte[] scriptBytes = Numeric.hexStringToByteArray("" + OpCode.PUSHDATA1.toString() + "21" + "02028a99826edc0c97d18e22b6932373d908d323aa7f92656a77ec26e8861699ef" + OpCode.PUSHNULL.toString() + OpCode.SYSCALL.toString() + InteropServiceCode.NEO_CRYPTO_VERIFYWITHECDSASECP256R1.getHash()); VerificationScript s = new VerificationScript(scriptBytes); List<ECPublicKey> pubKeys = s.getPublicKeys(); assertThat(pubKeys, hasSize(1)); assertThat(Numeric.toHexStringNoPrefix(pubKeys.get(0).getEncoded(true)), is("02028a99826edc0c97d18e22b6932373d908d323aa7f92656a77ec26e8861699ef")); }
@Test public void getPublicKeysFromMutliSigScript() { byte[] scriptBytes = Numeric.hexStringToByteArray("" + OpCode.PUSH2.toString() + OpCode.PUSHDATA1.toString() + "21" + "02028a99826edc0c97d18e22b6932373d908d323aa7f92656a77ec26e8861699ef" + OpCode.PUSHDATA1.toString() + "21" + "031d8e1630ce640966967bc6d95223d21f44304133003140c3b52004dc981349c9" + OpCode.PUSHDATA1.toString() + "21" + "03f0f9b358dfed564e74ffe242713f8bc866414226649f59859b140a130818898b" + OpCode.PUSH3.toString() + OpCode.PUSHNULL.toString() + OpCode.SYSCALL.toString() + InteropServiceCode.NEO_CRYPTO_CHECKMULTISIGWITHECDSASECP256R1.getHash()); VerificationScript s = new VerificationScript(scriptBytes); List<ECPublicKey> pubKeys = s.getPublicKeys(); assertThat(pubKeys, hasSize(3)); assertThat(Numeric.toHexStringNoPrefix(pubKeys.get(0).getEncoded(true)), is("02028a99826edc0c97d18e22b6932373d908d323aa7f92656a77ec26e8861699ef")); assertThat(Numeric.toHexStringNoPrefix(pubKeys.get(1).getEncoded(true)), is("031d8e1630ce640966967bc6d95223d21f44304133003140c3b52004dc981349c9")); assertThat(Numeric.toHexStringNoPrefix(pubKeys.get(2).getEncoded(true)), is("03f0f9b358dfed564e74ffe242713f8bc866414226649f59859b140a130818898b")); }