コード例 #1
0
    // Checks to see if the key is valid by signing dummy data. Returns 0 if valid, 1 otherwise.
    public static int verifyKey(string key)
    {
        key = addHexPrefix(key);
        var dummyMessage = "test dummy message";
        var signer       = new MessageSigner();
        var signature    = "";
        var address      = "";

        try
        {
            signature = signer.HashAndSign(dummyMessage, key);
        }
        catch (Exception sign)
        {
            Debug.Log("Key appears to be invalid! Cannot sign data. " + sign);
            return(1);
        }

        try
        {
            address = signer.HashAndEcRecover(dummyMessage, signature);
        }
        catch (Exception recover)
        {
            Debug.Log("Key appears to be invalid! Cannot recover data. " + recover);
            return(1);
        }

        //Debug.Log("Verification successful: " + address + ". Private key appears to be valid.");
        return(0);
    }