Ejemplo n.º 1
0
 /// <summary>
 /// check that the words we'rent modified
 /// </summary>
 static Wordlist()
 {
     if (!Mnemonic.Checksum(Encoding.ASCII.GetBytes(JavaHelper <string> .ArrayToString(RAW))).Equals(RAW_CHECKSUM))
     {
         throw new Exception("cannot initialize passphrase library: wordlist corrupted");
     }
 }
Ejemplo n.º 2
0
        static int CheckIntConstBlock(byte[] program, int pc)
        {
            int          size   = 1;
            VarintResult result = Uvarint.GetUvarint(JavaHelper <byte> .ArrayCopyRange(program, pc + size, program.Length));

            if (result.length <= 0)
            {
                throw new ArgumentException(string.Format("could not decode int const block at pc=%d", pc));
            }
            else
            {
                size = size + result.length;
                int numInts = result.value;

                for (int i = 0; i < numInts; ++i)
                {
                    if (pc + size >= program.Length)
                    {
                        throw new ArgumentException("int const block exceeds program length");
                    }
                    result = Uvarint.GetUvarint(JavaHelper <byte> .ArrayCopyRange(program, pc + size, program.Length));
                    if (result.length <= 0)
                    {
                        throw new ArgumentException(string.Format("could not decode int const[%d] block at pc=%d", i, pc + size));
                    }

                    size += result.length;
                }
                return(size);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// toKey converts a mnemonic generated using this library into the source
        /// key used to create it. It returns an error if the passed mnemonic has an
        /// incorrect checksum, if the number of words is unexpected, or if one
        /// of the passed words is not found in the words list.
        /// </summary>
        /// <param name="mnemonicStr">words delimited by MNEMONIC_DELIM</param>
        /// <returns>32 byte array key</returns>
        public static byte[] ToKey(string mnemonicStr)
        {
            if (mnemonicStr is null)
            {
                throw new ArgumentException("mnemonic must not be null");
            }
            //Objects.requireNonNull(mnemonicStr, "mnemonic must not be null");
            string[] mnemonic = mnemonicStr.Split(MNEMONIC_DELIM);
            if (mnemonic.Length != MNEM_LEN_WORDS)
            {
                throw new ArgumentException("mnemonic does not have enough words");
            }
            // convert to uint11
            int numWords = MNEM_LEN_WORDS - CHECKSUM_LEN_WORDS;

            int[] uint11Arr = new int[numWords];
            for (int i = 0; i < numWords; i++)
            {
                uint11Arr[i] = -1;
            }
            for (int w = 0; w < Wordlist.RAW.Length; w++)
            {
                for (int i = 0; i < numWords; i++)
                {
                    if (Wordlist.RAW[w].Equals(mnemonic[i]))
                    {
                        uint11Arr[i] = w;
                    }
                }
            }
            for (int i = 0; i < numWords; i++)
            {
                if (uint11Arr[i] == -1)
                {
                    throw new ArgumentException("mnemonic contains word that is not in word list");
                }
            }
            byte[] b = ToByteArray(uint11Arr);
            // chop the last byte. The last byte was 3 bits, padded with 8 bits to create the 24th word.
            // Those last padded 8 bits is an extra zero byte.
            if (b.Length != KEY_LEN_BYTES + 1)
            {
                throw new ArgumentException("wrong key length");
            }
            if (b[KEY_LEN_BYTES] != (byte)0)
            {
                throw new ArgumentException("unexpected byte from key");
            }
            //byte[] bCopy = new byte[KEY_LEN_BYTES];
            byte[] bCopy = JavaHelper <byte> .ArrayCopyOf(b, KEY_LEN_BYTES);

            string chkWord = Checksum(bCopy);

            if (!chkWord.Equals(mnemonic[MNEM_LEN_WORDS - CHECKSUM_LEN_WORDS]))
            {
                throw new ArgumentException("checksum failed to validate");
            }
            return(JavaHelper <byte> .ArrayCopyOf(b, KEY_LEN_BYTES));
        }
Ejemplo n.º 4
0
        public SignedBid(Bid bid, Signature sig, MultisigSignature mSig)
        {
            this.bid = JavaHelper <Bid> .RequireNotNull(bid, "tx must not be null");

            this.mSig = JavaHelper <MultisigSignature> .RequireNotNull(mSig, "mSig must not be null");

            this.sig = JavaHelper <Signature> .RequireNotNull(sig, "sig must not be null");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Return encoded representation of the transaction with a prefix suitable for signing
        /// </summary>
        /// <returns>bytes</returns>
        private byte[] BytesToSign()
        {
            byte[] encodedTx       = Encoder.EncodeToMsgPack(this);
            byte[] prefixEncodedTx = JavaHelper <byte> .ArrayCopyOf(TG_PREFIX, TG_PREFIX.Length + encodedTx.Length);

            JavaHelper <byte> .SyatemArrayCopy(encodedTx, 0, prefixEncodedTx, TG_PREFIX.Length, encodedTx.Length);

            return(prefixEncodedTx);
        }
Ejemplo n.º 6
0
        public MultisigSubsig(Ed25519PublicKeyParameters key, Signature sig = null)
        {
            this.key = JavaHelper <Ed25519PublicKeyParameters> .RequireNotNull(key, "public key cannot be null");

            if (sig is null)
            {
                this.sig = new Signature();
            }
            else
            {
                this.sig = sig;
            }
        }
Ejemplo n.º 7
0
 public TEALProgram(byte[] program)
 {
     if (program == null)
     {
         return;
     }
     try
     {
         Logic.ReadProgram(program, null);
     }
     catch (Exception e)
     {
         throw new ArgumentException(e.Message);
     }
     this.program = JavaHelper <byte> .ArrayCopyOf(program, program.Length);
 }
Ejemplo n.º 8
0
        public override void NextBytes(byte[] bytes)
        {
            if (this.index >= this.fixedValue.Length)
            {
                // no more data to copy
                return;
            }
            int len = bytes.Length;

            if (len > this.fixedValue.Length - this.index)
            {
                len = this.fixedValue.Length - this.index;
            }
            JavaHelper <byte> .SyatemArrayCopy(this.fixedValue, this.index, bytes, 0, len);

            this.index += bytes.Length;
        }
Ejemplo n.º 9
0
        public static ByteConstBlock ReadByteConstBlock(byte[] program, int pc)
        {
            List <byte[]> results = new List <byte[]>();
            int           size    = 1;
            VarintResult  result  = GetUVarint(program, pc + size);

            if (result.length <= 0)
            {
                throw new ArgumentException(
                          string.Format("could not decode byte[] const block at pc=%d", pc)
                          );
            }
            size += result.length;
            int numInts = result.value;

            for (int i = 0; i < numInts; i++)
            {
                if (pc + size >= program.Length)
                {
                    throw new ArgumentException("byte[] const block exceeds program length");
                }
                result = GetUVarint(program, pc + size);
                if (result.length <= 0)
                {
                    throw new ArgumentException(
                              string.Format("could not decode byte[] const[%d] block at pc=%d", i, pc + size)
                              );
                }
                size += result.length;
                if (pc + size >= program.Length)
                {
                    throw new ArgumentException("byte[] const block exceeds program length");
                }
                byte[] buff = new byte[result.value];
                JavaHelper <byte> .SyatemArrayCopy(program, pc + size, buff, 0, result.value);

                results.Add(buff);
                size += result.value;
            }
            return(new ByteConstBlock(size, results));
        }
Ejemplo n.º 10
0
        public LogicsigSignature(
            [JsonProperty("l")] byte[] logic,
            [JsonProperty("arg")] List <byte[]> args      = null,
            [JsonProperty("sig")] byte[] sig              = null,
            [JsonProperty("msig")] MultisigSignature msig = null)
        {
            this.logic = JavaHelper <byte[]> .RequireNotNull(logic, "program must not be null");

            this.args = args;

            if (!Logic.CheckProgram(this.logic, this.args))
            {
                throw new Exception("program verified failed!");
            }

            if (sig != null)
            {
                this.sig = new Signature(sig);
            }
            this.msig = msig;
        }
Ejemplo n.º 11
0
 private byte[] GetAdressBytes(string encodedAddr)
 {
     byte[] checksumAddr = Base32.DecodeFromString(encodedAddr);
     return(JavaHelper <byte> .ArrayCopyOf(checksumAddr, LEN_BYTES));
 }