Skip to content

Commit

Permalink
experimental force sign message
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Jul 26, 2023
1 parent fe917fb commit 4ad4008
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Fairy.Wallet.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Neo.Cryptography;
using Neo.IO;
using Neo.Json;
using Neo.Network.P2P.Payloads;
Expand Down Expand Up @@ -148,6 +149,25 @@ internal static UInt160 AddressToScriptHash(string address, byte version)
return address.ToScriptHash(version);
}

[RpcMethod]
protected virtual JObject ForceSignMessage(JArray _params)
{
string session = _params[0].AsString();
FairySession fairySession;
if (!sessionStringToFairySession.TryGetValue(session, out fairySession))
{ // we allow initializing a new session when executing
fairySession = NewFairySession(system, this);
sessionStringToFairySession[session] = fairySession;
}
Wallet signatureWallet = fairySession.engine.runtimeArgs.fairyWallet == null ? defaultFairyWallet : fairySession.engine.runtimeArgs.fairyWallet;
byte[] message = Convert.FromBase64String(_params[1].AsString());

JObject json = new();
KeyPair keyPair = signatureWallet.GetAccounts().First().GetKey();
json["signed"] = Convert.ToBase64String(Crypto.Sign(message, keyPair.PrivateKey, keyPair.PublicKey.EncodePoint(false)[1..]));
return json;
}

[RpcMethod]
protected virtual JObject ForceSignTransaction(JArray _params)
{
Expand Down

0 comments on commit 4ad4008

Please sign in to comment.