diff --git a/lib/chain/tezos/tezos_language_util.dart b/lib/chain/tezos/tezos_language_util.dart index 041ee8a..ccda09f 100644 --- a/lib/chain/tezos/tezos_language_util.dart +++ b/lib/chain/tezos/tezos_language_util.dart @@ -3,7 +3,6 @@ import 'package:tezster_dart/michelson_parser/michelson_parser.dart'; class TezosLanguageUtil { static String translateMichelsonToMicheline(String code) { - // jsonDecode() var result = MichelsonParser.parseMichelson(code); return result; } diff --git a/lib/chain/tezos/tezos_message_codec.dart b/lib/chain/tezos/tezos_message_codec.dart index 87f9783..7341f33 100644 --- a/lib/chain/tezos/tezos_message_codec.dart +++ b/lib/chain/tezos/tezos_message_codec.dart @@ -62,7 +62,7 @@ class TezosMessageCodec { } static String encodeReveal(OperationModel message) { - var hex = TezosMessageUtils.writeInt(107); //sepyTnoitarepo['reveal']); + var hex = TezosMessageUtils.writeInt(107); hex += TezosMessageUtils.writeAddress(message.source).substring(2); hex += TezosMessageUtils.writeInt(int.parse(message.fee)); hex += TezosMessageUtils.writeInt(message.counter); diff --git a/lib/chain/tezos/tezos_message_utils.dart b/lib/chain/tezos/tezos_message_utils.dart index c6d13c4..de87cf8 100644 --- a/lib/chain/tezos/tezos_message_utils.dart +++ b/lib/chain/tezos/tezos_message_utils.dart @@ -12,7 +12,6 @@ class TezosMessageUtils { .decode(branch) .sublist(2, base58.decode(branch).length - 4) .toList()); - // return hex.encode(base58.decode(branch).sublist(2).toList()); } static String writeInt(int value) { diff --git a/lib/chain/tezos/tezos_node_writer.dart b/lib/chain/tezos/tezos_node_writer.dart index c6eee69..43b8140 100644 --- a/lib/chain/tezos/tezos_node_writer.dart +++ b/lib/chain/tezos/tezos_node_writer.dart @@ -294,7 +294,6 @@ class TezosNodeWriter { var response = await HttpHelper.performPostRequest(server, 'injection/operation?chain=$chainid', hex.encode(opPair['bytes'])); response = response.toString().replaceAll('"', ''); - // parseRPCError(response); return response; } diff --git a/lib/helper/password_generater.dart b/lib/helper/password_generater.dart index 4421459..d18db72 100644 --- a/lib/helper/password_generater.dart +++ b/lib/helper/password_generater.dart @@ -3,29 +3,20 @@ import 'dart:math'; import 'package:flutter/cupertino.dart'; class PasswordGenerator { - /// @desc Function to generate password based on some criteria - /// @param bool isWithLetters: password must contain letters - /// @param bool isWithUppercase: password must contain uppercase letters - /// @param bool isWithNumbers: password must contain numbers - /// @param bool isWithSpecial: password must contain special chars - /// @param int length: password length - /// @return string: new password + static String generatePassword( {@required double length, bool isWithLetters, bool isWithUppercase, bool isWithNumbers, bool isWithSpecial}) { - //Define the allowed chars to use in the password String _lowerCaseLetters = "abcdefghijklmnopqrstuvwxyz"; String _upperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String _numbers = "0123456789"; String _special = r'!@#$%^&*()+_-=}{[]|:;"/?.><,`~'; - //Create the empty string that will contain the allowed chars String _allowedChars = ""; - //Put chars on the allowed ones based on the input values _allowedChars += (isWithLetters ? _lowerCaseLetters : ''); _allowedChars += (isWithUppercase ? _upperCaseLetters : ''); _allowedChars += (isWithNumbers ? _numbers : ''); @@ -34,11 +25,8 @@ class PasswordGenerator { int i = 0; String _result = ""; - //Create password while (i < length.round()) { - //Get random int int randomInt = Random.secure().nextInt(_allowedChars.length); - //Get random char and append it to the password _result += _allowedChars[randomInt]; i++; } diff --git a/lib/michelson_parser/grammar/michelin_grammar_tokenizer.dart b/lib/michelson_parser/grammar/michelin_grammar_tokenizer.dart index 502d155..97c2b1a 100644 --- a/lib/michelson_parser/grammar/michelin_grammar_tokenizer.dart +++ b/lib/michelson_parser/grammar/michelin_grammar_tokenizer.dart @@ -27,7 +27,6 @@ class MichelinGrammarTokenizer { "text": tokens[numindex].value, "col": tokens[numindex].columnNumber, "line": '1', - // 'toString': () => tokens[numindex].value, } : null; numindex++; @@ -105,38 +104,9 @@ class MichelinGrammarTokenizer { } seq += chunk[j]; } - // if (seq.isNotEmpty) { - // if (tokens.last.type == 'word' && - // getKeyFromValue(char, isRegex: false) == null) { - // tokens.last = tokens.last..value += char; - // } else if (tokens.last.type == 'number' && - // getKeyFromValue(char, isRegex: true).key == "number") { - // tokens.last = tokens.last..value += char; - // } else if (isArrayOrStringContaines(seq)) { - // var argSeq = getKeyFromValue(seq); - // tokens.add(GrammarResultModel(argSeq.key, seq)..columnNumber = i); - // i += (seq.length - 1); - // } else { - // if (char != '%') { - // var argSeq = getKeyFromValue(char); - // tokens - // .add(GrammarResultModel(argSeq.key, char)..columnNumber = i); - // } - // } - // } + } - // else if (char == '%' || char == ':') { - // var nextIndex = i + 30; - // if (nextIndex >= chunk.length - 1) nextIndex = chunk.length - 1; - // var data = chunk.substring( - // i, - // nextIndex, - // ); - // var endIndex = getEndIndexOfVar(data); - // tokens.add(GrammarResultModel('annot', data.substring(0, endIndex)) - // ..columnNumber = i); - // i += endIndex - 1; - // } + else if (char == '"') { var nextIndex = i + 200; if (nextIndex >= chunk.length - 1) nextIndex = chunk.length; @@ -167,7 +137,6 @@ class MichelinGrammarTokenizer { var result = false; var _keys = delimiters.keys.toList(); for (var i = 0; i < _keys.length; i++) { - // var key = _keys[i]; var value = delimiters[_keys[i]]; if (value is List) { result = value.contains(char); diff --git a/lib/michelson_parser/grammar/michelson_grammar_tokenizer.dart b/lib/michelson_parser/grammar/michelson_grammar_tokenizer.dart index 6e8d683..7233f1b 100644 --- a/lib/michelson_parser/grammar/michelson_grammar_tokenizer.dart +++ b/lib/michelson_parser/grammar/michelson_grammar_tokenizer.dart @@ -26,7 +26,6 @@ class MichelsonGrammarTokenizer { "text": tokens[numindex].value, "col": tokens[numindex].columnNumber, "line": '1', - // 'toString': () => tokens[numindex].value, } : null; numindex++; @@ -159,7 +158,6 @@ class MichelsonGrammarTokenizer { var result = false; var _keys = delimiters.keys.toList(); for (var i = 0; i < _keys.length; i++) { - // var key = _keys[i]; var value = delimiters[_keys[i]]; if (value is List) { result = value.contains(char); diff --git a/lib/michelson_parser/michelson_parser.dart b/lib/michelson_parser/michelson_parser.dart index f4eab09..a519b2a 100644 --- a/lib/michelson_parser/michelson_parser.dart +++ b/lib/michelson_parser/michelson_parser.dart @@ -3,7 +3,6 @@ import 'package:tezster_dart/michelson_parser/parser/michelson_grammar.dart'; import 'package:tezster_dart/michelson_parser/parser/nearley.dart'; class MichelsonParser { - /// code = michelson code static String parseMichelson(String code) { var parser = Nearley(); parser.parser(Nearley.fromCompiled(MichelsonGrammar().grammar)); diff --git a/lib/michelson_parser/parser/micheline_grammar.dart b/lib/michelson_parser/parser/micheline_grammar.dart index 15ad69d..bfdaf7b 100644 --- a/lib/michelson_parser/parser/micheline_grammar.dart +++ b/lib/michelson_parser/parser/micheline_grammar.dart @@ -358,32 +358,6 @@ class MichelineGrammar { getMapValue(d) => d is List ? d[0]['value'].toString() : d['value']; -// interface NearleyToken { value: any; -// [key: string]: any; -// }; - -// interface NearleyLexer { -// reset: (chunk: string, info: any) => void; -// next: () => NearleyToken | undefined; -// save: () => any; -// formatError: (token: NearleyToken) => string; -// has: (tokenType: string) => boolean; -// }; - -// interface NearleyRule { -// name: string; -// symbols: NearleySymbol[]; -// postprocess?: (d: any[], loc?: number, reject?: {}) => any; -// }; - -// type NearleySymbol = string | { literal: any } | { test: (token: any) => boolean }; - -// interface Grammar { -// Lexer: NearleyLexer | undefined; -// ParserRules: NearleyRule[]; -// ParserStart: string; -// }; - Map get grammar => { 'Lexer': lexer, 'ParserRules': [ diff --git a/lib/michelson_parser/parser/michelson_grammar.dart b/lib/michelson_parser/parser/michelson_grammar.dart index 5255047..2831757 100644 --- a/lib/michelson_parser/parser/michelson_grammar.dart +++ b/lib/michelson_parser/parser/michelson_grammar.dart @@ -119,8 +119,6 @@ class MichelsonGrammar { 'macroCADR': macroCADRconst, 'macroDIP': dIPmatcher, 'macroDUP': dUPmatcher, - // 'macroDIP': macroDIPconst, - // 'macroDUP': macroDUPconst, 'macroSETCADR': macroSETCADRconst, 'macroASSERTlist': macroASSERTlistConst, 'constantData': ['Unit', 'True', 'False', 'None', 'instruction'], diff --git a/lib/michelson_parser/parser/nearley.dart b/lib/michelson_parser/parser/nearley.dart index c3e36de..edd0c0c 100644 --- a/lib/michelson_parser/parser/nearley.dart +++ b/lib/michelson_parser/parser/nearley.dart @@ -68,14 +68,12 @@ class Nearley { for (var w = scannable.length - 1; 0 <= w; w--) { var state = scannable[w]; var expect = state.rule.symbols[state.dot]; - // Try to consume the token - // either regex or literal + if (expect is RegExp ? expect.hasMatch(value['value']) : expect['type'] != null ? expect['type'] == token['type'] : expect['literal'] == literal) { - // Add it var next = state.nextState({ 'data': value, 'token': token, @@ -86,18 +84,9 @@ class Nearley { } } - // Next, for each of the rules, we either - // (a) complete it, and try to see if the reference row expected that - // rule - // (b) predict the next nonterminal it expects by adding that - // nonterminal's start state - // To prevent duplication, we also keep track of rules we have already - // added - nextColumn.process(); table.add(nextColumn); - // If needed, throw an error: if (nextColumn.states.length == 0) { var err = new NearleyError(reportError(token)); err.offset = this.current; @@ -113,14 +102,12 @@ class Nearley { this.lexerState = lexer.save(); } - // Incrementally keep track of results results = this.finish(); return this; } finish() { - // Return the possible parsings var considerations = []; var start = this.grammar.start; var column = this.table[this.table.length - 1]; @@ -138,7 +125,6 @@ class Nearley { } reportError(token) { - // var lexerMessage = this.lexer.formatError(token, "Syntax error"); var lines = []; var tokenDisplay = (token['type'] != null ? token['type'] + " token: " : "") + @@ -159,13 +145,10 @@ class Nearley { } }).toList(); - // Display a "state stack" for each expectant state - // - which shows you how this state came to be, step by step. - // If there is more than one derivation, we only display the first one. var stateStacks = expectantStates.map((state) { return this.buildFirstStateStack(state, []); }).toList(); - // Display each state that is expecting a terminal symbol next. + stateStacks.forEach((stateStack) { var state = stateStack[0]; var nextSymbol = @@ -181,8 +164,7 @@ class Nearley { String reportLexerError(lexerError) { var tokenDisplay, lexerMessage; - // Planning to add a token property to moo's thrown error - // even on erroring tokens to be used in error display below + var token = lexerError.token; if (token) { tokenDisplay = "input " + jsonEncode(token.text[0]) + " (lexer error)"; @@ -213,13 +195,11 @@ class Nearley { lines.add('Unexpected ' + tokenDisplay + '. Instead, I was expecting to see one of the following:\n'); - // Display a "state stack" for each expectant state - // - which shows you how this state came to be, step by step. - // If there is more than one derivation, we only display the first one. + var stateStacks = expectantStates.map((state) { return this.buildFirstStateStack(state, []) ?? [state]; }); - // Display each state that is expecting a terminal symbol next. + stateStacks.forEach((stateStack) { var state = stateStack[0]; var nextSymbol = state.rule.symbols[state.dot]; @@ -234,9 +214,6 @@ class Nearley { buildFirstStateStack(state, visited) { if (visited.indexOf(state) != -1) { - // Found cycle, return null - // to eliminate this path from the results, because - // we don't know how to display it meaningfully return null; } if (state.wantedBy.length == 0) { @@ -277,7 +254,6 @@ class Nearley { } getSymbolLongDisplay(symbol) { - // var type = typeof symbol; if (symbol is String) { return symbol; } else if (symbol is Map) { @@ -332,28 +308,23 @@ class Column { if (state.data != fail) { var wantBy = state.wantedBy; - // complete for (var i = wantBy.length - 1; 0 <= i; i--) { var left = wantBy[i]; this.complete(left, state); } - // special-case nullables if (state.reference == index) { - // make sure future predictors of this rule get completed. var exp = state.rule.name; this.completed[exp] = this.completed[exp] ?? []; this.completed[exp].add(state); } } } else { - // queue scannable states var exp = state.rule.symbols[state.dot]; if (!(exp is String)) { this.scannable.add(state); } - // predict if (_wants[exp] != null) { _wants[exp].add(state); if (_completed.containsKey(exp)) { @@ -519,8 +490,6 @@ class StreamLexer { return List.generate(length - s.length + 1, (index) => '').join(" ") + s; } - // nb. this gets called after consuming the offending token, - // so the culprit is index-1 var buffer = this.buffer; if (buffer is String) { var lines = buffer.split("\n").sublist(max(0, this.line - 5), this.line); diff --git a/lib/reporting/conseil_data_client.dart b/lib/reporting/conseil_data_client.dart index 3db1744..8802e33 100644 --- a/lib/reporting/conseil_data_client.dart +++ b/lib/reporting/conseil_data_client.dart @@ -4,29 +4,11 @@ class ConseilDataClient { static executeEntityQuery( serverInfo, platform, network, entity, query) async { var url = '${serverInfo['url']}/v2/data/$platform/$network/$entity'; - // log.debug(`ConseilDataClient.executeEntityQuery request: ${url}, ${JSON.stringify(query)}`); + var res = await HttpHelper.performPostRequest(url, '', query, headers: { 'apiKey': serverInfo['apiKey'], - // 'Content-Type': 'application/json', 'cache': 'no-store', }); return res; - // .then((r) { - // if (!r.ok) { - // // log.error(`ConseilDataClient.executeEntityQuery request: ${url}, ${JSON.stringify(query)}, failed with ${r.statusText}(${r.status})`); - // throw new ConseilErrorTypes_1.ConseilRequestError( - // r.status, r.statusText, url, query); - // } - // return r; - // }) - // .then((r) { - // var isJSONResponse = r.headers - // .get('content-type') - // .toLowerCase() - // .includes('application/json'); - // var response = isJSONResponse != null ? r.json() : r.text(); - // // log.debug(`ConseilDataClient.executeEntityQuery response: ${isJSONResponse ? JSON.stringify(response) : response}`); - // return response; - // }); } } diff --git a/lib/src/tezster_dart.dart b/lib/src/tezster_dart.dart index 1cbd537..4abab96 100644 --- a/lib/src/tezster_dart.dart +++ b/lib/src/tezster_dart.dart @@ -23,12 +23,10 @@ import 'package:flutter_sodium/flutter_sodium.dart'; import 'package:tezster_dart/helper/generateKeys.dart'; class TezsterDart { - /// Generate mnemonic static String generateMnemonic({int strength = 256}) { return bip39.generateMnemonic(strength: strength); } - /// Generate keys from mnemonic static Future> getKeysFromMnemonic({ String mnemonic, }) async { @@ -42,7 +40,6 @@ class TezsterDart { return [skKey, pkKey, pkKeyHash]; } - /// Create / Unlock identity from mnemonic and passphrase. static Future> getKeysFromMnemonicAndPassphrase({ String mnemonic, String passphrase, @@ -55,7 +52,6 @@ class TezsterDart { ); } - /// Unlock fundraiser identity. static Future> unlockFundraiserIdentity({ String mnemonic, String email, @@ -70,7 +66,6 @@ class TezsterDart { ); } - /// Sign operation with private key and forged operation static Future> signOperationGroup({ String privateKey, String forgedOperation, @@ -125,7 +120,6 @@ class TezsterDart { return [skKey, pkKey, pkKeyHash]; } - // Get balance from given publicKeyHash and rpc static Future getBalance(String publicKeyHash, String rpc) async { assert(publicKeyHash != null); assert(rpc != null); @@ -140,13 +134,11 @@ class TezsterDart { return GenerateKeys.writeKeyWithHint(key, hint); } - // Create Signer from given secretKey static createSigner(Uint8List secretKey, {int validity = 60}) { assert(secretKey != null); return SoftSigner.createSigner(secretKey, validity); } - /// Transfer Balance static sendTransactionOperation(String server, SoftSigner signer, KeyStoreModel keyStore, String to, int amount, int fee, {int offset = 54}) async { @@ -165,7 +157,6 @@ class TezsterDart { server, signer, keyStore, to, amount, fee); } - /// Delegate an Account static sendDelegationOperation(String server, SoftSigner signer, KeyStoreModel keyStore, String delegate, int fee, {offset = 54}) async { diff --git a/lib/tezster_dart.dart b/lib/tezster_dart.dart index 54f017d..9804781 100644 --- a/lib/tezster_dart.dart +++ b/lib/tezster_dart.dart @@ -2,8 +2,6 @@ library tezster_dart; export 'src/tezster_dart.dart'; -// KeyStore Model export 'models/key_store_model.dart'; -// tezos types -export 'types/tezos/tezos_chain_types.dart'; \ No newline at end of file +export 'types/tezos/tezos_chain_types.dart'; diff --git a/lib/utils/crypto_utils.dart b/lib/utils/crypto_utils.dart index 12787c3..a1885f4 100644 --- a/lib/utils/crypto_utils.dart +++ b/lib/utils/crypto_utils.dart @@ -11,14 +11,10 @@ class CryptoUtils { var keyBytes = SodiumUtils.pwhash(passphrase, salt); var nonce = SodiumUtils.nonce(); var s = SodiumUtils.close(message, nonce, keyBytes); - // nonce.addAll(s); + return new Uint8List.fromList(nonce.toList() + s.toList()); } - // static signDetached(Uint8List simpleHash) { - // return - // } - static Uint8List decryptMessage(message, passphrase, salt) { var keyBytes = SodiumUtils.pwhash(passphrase, salt); return SodiumUtils.open(message, keyBytes);