Witness extends NeoSerializable { public static Witness createWitness(byte[] messageToSign, ECKeyPair keyPair) { InvocationScript i = InvocationScript.fromMessageAndKeyPair(messageToSign, keyPair); VerificationScript v = new VerificationScript(keyPair.getPublicKey()); return new Witness(i, v); } Witness();  Witness(byte[] invocationScript, byte[] verificationScript);  Witness(InvocationScript invocationScript, VerificationScript verificationScript);  Witness(byte[] invocationScript, ScriptHash scriptHash); static Witness createWitness(byte[] messageToSign, ECKeyPair keyPair); static Witness createMultiSigWitness(int signingThreshold,
                                                  List<SignatureData> signatures,
                                                  List<ECPublicKey> publicKeys); static Witness createMultiSigWitness(List<SignatureData> signatures,
                                                  VerificationScript verificationScript); InvocationScript getInvocationScript(); VerificationScript getVerificationScript(); ScriptHash getScriptHash(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Override void deserialize(BinaryReader reader); @Override void serialize(BinaryWriter writer); @Override int getSize();  }
@Test public void createWitness() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { byte[] message = new byte[10]; Arrays.fill(message, (byte) 10); ECKeyPair keyPair = ECKeyPair.createEcKeyPair(); Witness witness = Witness.createWitness(message, keyPair); SignatureData expectedSig = Sign.signMessage(message, keyPair); String expected = "" + PUSHDATA1.toString() + "40" + Numeric.toHexStringNoPrefix(expectedSig.getConcatenated()); assertArrayEquals( Numeric.hexStringToByteArray(expected), witness.getInvocationScript().getScript()); expected = "" + PUSHDATA1.toString() + "21" + Numeric.toHexStringNoPrefix(keyPair.getPublicKey().getEncoded(true)) + PUSHNULL.toString() + SYSCALL.toString() + InteropServiceCode.NEO_CRYPTO_VERIFYWITHECDSASECP256R1.getHash(); assertArrayEquals( Numeric.hexStringToByteArray(expected), witness.getVerificationScript().getScript()); }
@Test public void serializeWithWitness() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { byte[] message = new byte[10]; Arrays.fill(message, (byte) 10); ECKeyPair keyPair = ECKeyPair.createEcKeyPair(); Witness witness = Witness.createWitness(message, keyPair); byte[] invScript = InvocationScript.fromMessageAndKeyPair(message, keyPair).getScript(); byte[] invScriptLen = BigInteger.valueOf(invScript.length).toByteArray(); byte[] veriScript = new VerificationScript(keyPair.getPublicKey()).getScript(); byte[] veriScriptLen = BigInteger.valueOf(veriScript.length).toByteArray(); byte[] expectedWitness = concatenate(invScriptLen, invScript, veriScriptLen, veriScript); assertArrayEquals(expectedWitness, witness.toArray()); }