private Witness CreateMultiSignatureWitness(Signature[] signatures) { ECPoint[] pubKeys = new ECPoint[signatures.Length]; for (int i = 0; i < signatures.Length; i++) { if (!VerifyKeyAndSignature(signatures[i], out ECPoint pubKey)) { return(null); } pubKeys[i] = pubKey; } // sort public keys in ascending order, also match their signature Dictionary <ECPoint, Signature> dic = pubKeys.Select((p, i) => new { PubKey = p, Sig = signatures[i] }).OrderBy(p => p.PubKey).ToDictionary(p => p.PubKey, p => p.Sig); Witness witness = new Witness(); using (ScriptBuilder sb = new ScriptBuilder()) { dic.Values.ToList().ForEach(p => sb.EmitPush(p.Bytes)); witness.InvocationScript = sb.ToArray(); } witness.VerificationScript = Contract.CreateMultiSigRedeemScript(signatures.Length, dic.Keys.ToArray()); return(witness); }