<commit_before>"use strict";

const CURRENCY     = "[a-zA-Z0-9-_ ]{2,50}"
const BASE58       = "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+"
const PUBKEY       = "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{43,44}"
const SIGNATURE    = "[A-Za-z0-9+\\/=]{87,88}"
const USER_ID      = "[A-Za-z0-9_-]{2,100}"
const INTEGER      = "(0|[1-9]\\d{0,18})"
const FINGERPRINT  = "[A-F0-9]{64}"
const BLOCK_UID    = INTEGER + "-" + FINGERPRINT
const BLOCK_VERSION = "(10)"
const TX_VERSION   = "(10)"
const DIVIDEND     = "[1-9][0-9]{0,5}"
const ZERO_OR_POSITIVE_INT = "0|[1-9][0-9]{0,18}"
const RELATIVE_INTEGER = "(0|-?[1-9]\\d{0,18})"
const FLOAT        = "\\d+\.\\d+"
const POSITIVE_INT = "[1-9][0-9]{0,18}"
const TIMESTAMP    = "[1-9][0-9]{0,18}"
const BOOLEAN      = "[01]"
const SPECIAL_BLOCK = '0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855'
const META_TS      = "META:TS:" + BLOCK_UID
const COMMENT      = "[ a-zA-Z0-9-_:/;*\\[\\]()?!^\\+=@&~#{}|\\\\<>%.]{0,255}"
const CLTV_INTEGER = "([0-9]{1,10})";
const CSV_INTEGER  = "([0-9]{1,8})";
const XUNLOCK      = "[a-zA-Z0-9]{1,64}";
const UNLOCK       = "(SIG\\(" + INTEGER + "\\)|XHX\\(" + XUNLOCK + "\\))"
const CONDITIONS   = "(&&|\\|\\|| |[()]|(SIG\\(" + PUBKEY + "\\)|(XHX\\([A-F0-9]{64}\\)|CLTV\\(" + CLTV_INTEGER + "\\)|CSV\\(" + CSV_INTEGER + "\\))))*"

const BMA_REGEXP  = /^BASIC_MERKLED_API( ([a-z_][a-z0-9-_.]*))?( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))$/

const MAXIMUM_LEN_OF_COMPACT_TX = 100
const MAXIMUM_LEN_OF_OUTPUT = 2000
const MAXIMUM_LEN_OF_UNLOCK = MAXIMUM_LEN_OF_OUTPUT

export enum DuniterDocument {
  ENTITY_NULL,
  ENTITY_BLOCK,
  ENTITY_IDENTITY,
  ENTITY_CERTIFICATION,
  ENTITY_MEMBERSHIP,
  ENTITY_REVOCATION,
  ENTITY_TRANSACTION,
  ENTITY_PEER
}

export const duniterDocument2str = (type:DuniterDocument) => {
  switch (type) {
    case DuniterDocument.ENTITY_BLOCK: return "block"
    case DuniterDocument.ENTITY_IDENTITY: return "identity"
    case DuniterDocument.ENTITY_CERTIFICATION: return "certification"
    case DuniterDocument.ENTITY_REVOCATION: return "revocation"
    case DuniterDocument.ENTITY_MEMBERSHIP: return "membership"
    case DuniterDocument.ENTITY_TRANSACTION: return "transaction"
    case DuniterDocument.ENTITY_PEER: return "peer"
    default:
      return ""
  }
}

export const CommonConstants = {

  FORMATS: {
    CURRENCY,
    PUBKEY,
    INTEGER,
    FINGERPRINT,
    TIMESTAMP
  },

  BLOCK_GENERATED_VERSION: 10,
  LAST_VERSION_FOR_TX: 10,
  TRANSACTION_VERSION: 10,
  DOCUMENTS_VERSION: 10,
  TRANSACTION_MAX_TRIES: 10,

  SWITCH_ON_BRANCH_AHEAD_BY_X_BLOCKS: 6,

  BMA_REGEXP,
  PUBLIC_KEY: exact(PUBKEY),
  INTEGER: /^\d+$/,
  BASE58: exact(BASE58),
  FINGERPRINT: exact(FINGERPRINT),
  SIG: exact(SIGNATURE),
  BLOCK_UID: exact(BLOCK_UID),
  USER_ID: exact(USER_ID), // Any format, by default

  DOCUMENTS_VERSION_REGEXP: /^10$/,
  BLOCKSTAMP_REGEXP: new RegExp("^" + BLOCK_UID + "$"),
  DOCUMENTS_BLOCK_VERSION_REGEXP: new RegExp("^" + BLOCK_VERSION + "$"),
  DOCUMENTS_TRANSACTION_VERSION_REGEXP: /^(10)$/,
  SPECIAL_BLOCK,
  SPECIAL_HASH: 'E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855',
  MAXIMUM_LEN_OF_COMPACT_TX,
  MAXIMUM_LEN_OF_OUTPUT,
  MAXIMUM_LEN_OF_UNLOCK,<commit_msg>[enh] #1069 Resolve fork with 3 blocks and 15 minutes of advance<commit_after>"use strict";

const CURRENCY     = "[a-zA-Z0-9-_ ]{2,50}"
const BASE58       = "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+"
const PUBKEY       = "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{43,44}"
const SIGNATURE    = "[A-Za-z0-9+\\/=]{87,88}"
const USER_ID      = "[A-Za-z0-9_-]{2,100}"
const INTEGER      = "(0|[1-9]\\d{0,18})"
const FINGERPRINT  = "[A-F0-9]{64}"
const BLOCK_UID    = INTEGER + "-" + FINGERPRINT
const BLOCK_VERSION = "(10)"
const TX_VERSION   = "(10)"
const DIVIDEND     = "[1-9][0-9]{0,5}"
const ZERO_OR_POSITIVE_INT = "0|[1-9][0-9]{0,18}"
const RELATIVE_INTEGER = "(0|-?[1-9]\\d{0,18})"
const FLOAT        = "\\d+\.\\d+"
const POSITIVE_INT = "[1-9][0-9]{0,18}"
const TIMESTAMP    = "[1-9][0-9]{0,18}"
const BOOLEAN      = "[01]"
const SPECIAL_BLOCK = '0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855'
const META_TS      = "META:TS:" + BLOCK_UID
const COMMENT      = "[ a-zA-Z0-9-_:/;*\\[\\]()?!^\\+=@&~#{}|\\\\<>%.]{0,255}"
const CLTV_INTEGER = "([0-9]{1,10})";
const CSV_INTEGER  = "([0-9]{1,8})";
const XUNLOCK      = "[a-zA-Z0-9]{1,64}";
const UNLOCK       = "(SIG\\(" + INTEGER + "\\)|XHX\\(" + XUNLOCK + "\\))"
const CONDITIONS   = "(&&|\\|\\|| |[()]|(SIG\\(" + PUBKEY + "\\)|(XHX\\([A-F0-9]{64}\\)|CLTV\\(" + CLTV_INTEGER + "\\)|CSV\\(" + CSV_INTEGER + "\\))))*"

const BMA_REGEXP  = /^BASIC_MERKLED_API( ([a-z_][a-z0-9-_.]*))?( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))$/

const MAXIMUM_LEN_OF_COMPACT_TX = 100
const MAXIMUM_LEN_OF_OUTPUT = 2000
const MAXIMUM_LEN_OF_UNLOCK = MAXIMUM_LEN_OF_OUTPUT

export enum DuniterDocument {
  ENTITY_NULL,
  ENTITY_BLOCK,
  ENTITY_IDENTITY,
  ENTITY_CERTIFICATION,
  ENTITY_MEMBERSHIP,
  ENTITY_REVOCATION,
  ENTITY_TRANSACTION,
  ENTITY_PEER
}

export const duniterDocument2str = (type:DuniterDocument) => {
  switch (type) {
    case DuniterDocument.ENTITY_BLOCK: return "block"
    case DuniterDocument.ENTITY_IDENTITY: return "identity"
    case DuniterDocument.ENTITY_CERTIFICATION: return "certification"
    case DuniterDocument.ENTITY_REVOCATION: return "revocation"
    case DuniterDocument.ENTITY_MEMBERSHIP: return "membership"
    case DuniterDocument.ENTITY_TRANSACTION: return "transaction"
    case DuniterDocument.ENTITY_PEER: return "peer"
    default:
      return ""
  }
}

export const CommonConstants = {

  FORMATS: {
    CURRENCY,
    PUBKEY,
    INTEGER,
    FINGERPRINT,
    TIMESTAMP
  },

  BLOCK_GENERATED_VERSION: 10,
  LAST_VERSION_FOR_TX: 10,
  TRANSACTION_VERSION: 10,
  DOCUMENTS_VERSION: 10,
  TRANSACTION_MAX_TRIES: 10,

  SWITCH_ON_BRANCH_AHEAD_BY_X_BLOCKS: 3,

  BMA_REGEXP,
  PUBLIC_KEY: exact(PUBKEY),
  INTEGER: /^\d+$/,
  BASE58: exact(BASE58),
  FINGERPRINT: exact(FINGERPRINT),
  SIG: exact(SIGNATURE),
  BLOCK_UID: exact(BLOCK_UID),
  USER_ID: exact(USER_ID), // Any format, by default

  DOCUMENTS_VERSION_REGEXP: /^10$/,
  BLOCKSTAMP_REGEXP: new RegExp("^" + BLOCK_UID + "$"),
  DOCUMENTS_BLOCK_VERSION_REGEXP: new RegExp("^" + BLOCK_VERSION + "$"),
  DOCUMENTS_TRANSACTION_VERSION_REGEXP: /^(10)$/,
  SPECIAL_BLOCK,
  SPECIAL_HASH: 'E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855',
  MAXIMUM_LEN_OF_COMPACT_TX,
  MAXIMUM_LEN_OF_OUTPUT,
  MAXIMUM_LEN_OF_UNLOCK,
{'fraction_non_alphanumeric': 0.1753827497347279, 'fraction_numerical': 0.07291192966499924, 'mean_word_length': 4.346839546191248, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1341803', 'n_tokens_mistral': 3194, 'n_tokens_neox': 2811, 'n_words': 428}