Beispiel #1
0
    public int[] testHexConversion()
    {
        int[] passed = new int[2];
        passed[1] = 2;

        string hex          = "3720B091810D8127C55630F55DD2275C05";
        string hardSentence = "ugly call give address amount venture misery dose quick spoil weekend inspire";
        string sentence     = bpc.getSentenceFromHex(hex);

        if (hex == bpc.getHexFromSentence(sentence))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("BIP39 test converting hex to BIP39 sentence and back failed");
        }
        if (hardSentence == sentence)
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("BIP39 test converting sentence to hex and back failed");
        }

        return(passed);
    }
Beispiel #2
0
    public void SetupEncodeSeedBip()
    {
        SetLevelPanelDefault();

        if (GameManager.Mode == GameMode.Rehearsal)
        {
            TMP_InputField seedInputField = GetComponentInChildren <TMP_InputField>(true);

            string seedFromInput = seedInputField.text;
            string hexSeed       = "";

            if (!detectHex(seedFromInput) && validBip(seedFromInput))
            {
                BIP39Converter bpc = new BIP39Converter();
                hexSeed = bpc.getHexFromSentence(seedFromInput);
            }
            else
            {
                hexSeed = seedFromInput;
                if (InteractableConfig.SeedHexLength % 2 == 1)
                {
                    if (seedFromInput.Length == InteractableConfig.SeedHexLength)
                    {
                        string seedText = seedFromInput + "0";
                        char[] array    = seedText.ToCharArray();
                        array[array.Length - 1] = array[array.Length - 2];
                        array[array.Length - 2] = '0';
                        hexSeed = new string(array);
                    }
                    else if (seedFromInput.Length == InteractableConfig.SeedHexLength + 1)
                    {
                        char[] array = seedFromInput.ToCharArray();
                        array[array.Length - 2] = '0';
                        hexSeed = new string(array);
                    }
                    else
                    {
                        Debug.Log("Seed: " + hexSeed);
                    }
                }
            }

            //Debug.Log("Sentence: " + seedFromInput);
            Debug.Log("Seed: " + hexSeed);

            InteractablePathManager.SeedString = hexSeed;

            int[] siteIDs = InteractablePathManager.GetPathSiteIDs();

            SetIconAndPanelForRehearsal(siteIDs);
        }
    }
Beispiel #3
0
    public void copyHexSeed()
    {
        var            textList = Instance.GetComponentsInChildren <TMPro.TextMeshProUGUI>();
        BIP39Converter bpc      = new BIP39Converter();
        string         seed     = bpc.getHexFromSentence(textList[0].text);

        #if UNITY_WEBGL
        Copy(seed);
        #else
        GUIUtility.systemCopyBuffer = seed;
        #endif

        textList[1].text = "Seed Copied";
        textList[1].gameObject.SetActive(true);
    }
Beispiel #4
0
    // Checks a string to see if it's a valid bip-39 seed phrase
    public static bool validBip(string seed)
    {
        BIP39Converter bpc = new BIP39Converter();
        string         hex = "";

        try
        {
            hex = bpc.getHexFromSentence(seed);
        }
        catch (Exception e)
        {
            Debug.Log("Exception: " + e);
            return(false);
        }

        return(true);
    }
    public void EncodeSeed()
    {
        if (GameManager.Mode == GameMode.Rehearsal)
        {
            string seedFromInput = seedInputField.text;
            string hexSeed       = "";

            if (!SeedUtility.detectHex(seedFromInput) && SeedUtility.validBip(seedFromInput))
            {
                hexSeed = bpc.getHexFromSentence(seedFromInput);
            }
            else
            {
                hexSeed = seedFromInput;
                if (InteractableConfig.SeedHexLength % 2 == 1)
                {
                    if (seedFromInput.Length == InteractableConfig.SeedHexLength)
                    {
                        string seedText = seedFromInput + "0";
                        char[] array    = seedText.ToCharArray();
                        array[array.Length - 1] = array[array.Length - 2];
                        array[array.Length - 2] = '0';
                        hexSeed = new string(array);
                    }
                    else if (seedFromInput.Length == InteractableConfig.SeedHexLength + 1)
                    {
                        char[] array = seedFromInput.ToCharArray();
                        array[array.Length - 2] = '0';
                        hexSeed = new string(array);
                    }
                    else
                    {
                        Debug.Log("Seed: " + hexSeed);
                    }
                }
            }
            Debug.Log("Seed: " + hexSeed);

            InteractablePathManager.SeedString = hexSeed;
            int[] siteIDs = InteractablePathManager.GetPathSiteIDs();
        }
    }