1111
1212using Neo . Cryptography ;
1313using Neo . Extensions ;
14+ using Neo . Network . P2P ;
1415using Neo . Network . P2P . Payloads ;
1516using Neo . Persistence ;
1617using Neo . Sign ;
@@ -664,11 +665,42 @@ public bool Sign(ContractParametersContext context)
664665 return fSuccess ;
665666 }
666667
667- /// <inheritdoc/>
668- public ReadOnlyMemory < byte > Sign ( byte [ ] signData , ECPoint publicKey )
668+ /// <summary>
669+ /// Signs the specified extensible payload with the wallet.
670+ /// </summary>
671+ /// <param name="payload">The extensible payload to sign.</param>
672+ /// <param name="snapshot">The snapshot.</param>
673+ /// <param name="network">The network.</param>
674+ /// <returns>The signature.</returns>
675+ /// <exception cref="ArgumentNullException">Thrown when the payload is null.</exception>
676+ public Witness SignExtensiblePayload ( ExtensiblePayload payload , DataCache snapshot , uint network )
677+ {
678+ if ( payload is null ) throw new ArgumentNullException ( nameof ( payload ) ) ;
679+
680+ var context = new ContractParametersContext ( snapshot , payload , network ) ;
681+ Sign ( context ) ;
682+
683+ return context . GetWitnesses ( ) [ 0 ] ;
684+ }
685+
686+ /// <summary>
687+ /// Signs the specified block with the specified public key.
688+ /// </summary>
689+ /// <param name="block">The block to sign.</param>
690+ /// <param name="publicKey">The public key.</param>
691+ /// <param name="network">The network.</param>
692+ /// <returns>The signature.</returns>
693+ /// <exception cref="ArgumentNullException">Thrown when the block or public key is null.</exception>
694+ /// <exception cref="SignException">
695+ /// Thrown when the account is not found, the private key is not found, the account is locked,
696+ /// or the network is not matching.
697+ /// </exception>
698+ public ReadOnlyMemory < byte > SignBlock ( Block block , ECPoint publicKey , uint network )
669699 {
670- if ( signData is null ) throw new ArgumentNullException ( nameof ( signData ) ) ;
700+ if ( block is null ) throw new ArgumentNullException ( nameof ( block ) ) ;
671701 if ( publicKey is null ) throw new ArgumentNullException ( nameof ( publicKey ) ) ;
702+ if ( network != ProtocolSettings . Network )
703+ throw new SignException ( $ "Network is not matching({ ProtocolSettings . Network } != { network } )") ;
672704
673705 var account = GetAccount ( publicKey ) ;
674706 if ( account is null )
@@ -681,10 +713,18 @@ public ReadOnlyMemory<byte> Sign(byte[] signData, ECPoint publicKey)
681713 if ( account . Lock )
682714 throw new SignException ( "Account is locked" ) ;
683715
716+ var signData = block . GetSignData ( network ) ;
684717 return Crypto . Sign ( signData , privateKey ) ;
685718 }
686719
687- /// <inheritdoc/>
720+ /// <summary>
721+ /// Checks if the wallet contains an account with the specified public key.
722+ /// </summary>
723+ /// <param name="publicKey">The public key.</param>
724+ /// <returns>
725+ /// <see langword="true"/> if the account is found and has a private key and is not locked;
726+ /// otherwise, <see langword="false"/>.
727+ /// </returns>
688728 public bool ContainsSignable ( ECPoint publicKey )
689729 {
690730 var account = GetAccount ( publicKey ) ;
0 commit comments