Skip to content

Hybrid TxID Documentation

José Pereira edited this page Jun 6, 2019 · 4 revisions

IAP Hybrid

The TxID of the offchain IAP transactions (both Credit Card and APPC Credits) are built using the root hash of a Merkle Tree with the following childs:

  • amount in Wei
  • address
  • dev
  • store
  • oem
  • package_name
  • sku
  • timestamp as %Y-%m-%dT%H:%M:%S.%f
  • country

IAP Merkle Tree

IAP Hybrid - Example

https://appcexplorer.io/transaction/0x4c79a63bfdde5ec17fe320894e2198d94d678d2ac1189173713ed1c9141c115e

amount = '9.6e+17'
address = '0xAABC53f077940CC7Fc6838d42114E5603B57e877'
dev = '0x296822e13be5c72eb13a758248521703249edd51'
store = '0xc41b4160b63d1f9488937f7b66640d2babdbf8ad'
oem = '0x0965b2a3e664690315ad20b9e5b0336c19cf172e'
package_name = 'com.twentyonecommunications.WordMine'
sku = 'basic'
timestamp = '2018-10-30T14:25:02'
country = 'IN'

a) = '0xc3933f537c312bb0b81591c36e0ca472151ce0ce187d645e9417a7e1ccff571d'
b) = '0x2cd781399383fba25575246babc92b4e6871bc416116f2fcafeea83fa1a4e60d'
c) = '0x3cf23994b70bdd3c35fa484f39b08ec0e82b0893c934c760a3c2900e4cafb3de'
d) = '0x64b1fb5db3c74a6bdba0098add36a563400ca90dbe74e9cc5485092b7a3ea9e5'
e) = '0x12340772d2b9563c43b963721ca0bac792424b1004166cbdd4a23de8bd4546f1'
f) = '0x9f16eb9dda55b5e2a6dc4aeac21351b28326de790195bdb61eb584708df5a511'
g) = '0x3174c021ea3f372b39911aca9af5b81db0aa485053a22f7e4fa635e746c7539a'
h) = '0xa78e555e0e0b59f929a3b83a81c55dc0baf6cf34e6bb273984f0fed04a531b71'
i) = '0x928ced48b514d3c2b4b7d14591dcb18f0ed6fcefdd9b93e2f4ed92e5c1fd76aa'
j) = '0x30701c6f8c2266b232d45c61b0863cda4d3d240c936ad8ef19bc80d85cf2b98f'

tx_id = '0x4c79a63bfdde5ec17fe320894e2198d94d678d2ac1189173713ed1c9141c115e'

PoA Hybrid

The TxID of the PoA offchain transactions are built using the root hash of a Merkle Tree with the following childs:

  • bid ID
  • package_name
  • country
  • hash IP
  • address
  • 12 timestamps as [ts1, ts2, …, ts12]
  • 12 nonces as [nonce1, nonce2, …, nonce12]

PoA Merkle Tree

PoA Hybrid - Example

https://appcexplorer.io/transaction/0x475677ca105568dd0b6c08dbf9f6f65e80f81da8ea2a79b370d108379020128b

bid_id = '13'
package_name = 'com.appcoins.redrunner'
country = 'DE'
hash_ip = 'f2f6fb38a41b9b16f7d56b2c08a3af6923d46b35f52e84b3341d9378d382eb54'
address = '0xffe2ed58b757e643af4826c954151a72d2211eee'
timestamps = '[1541958979291, 1541958989308, 1541958999311, 1541959009312, 1541959019313, 1541959029315, 1541959039316, 1541959049318, 1541959059320, 1541959069324, 1541959079327, 1541959089328]'
nonces = '[275965, 270207, 34611, 98530, 39348, 24513, 94448, 31362, 88530, 102844, 27490, 30796]'

a) = '0xe69a937004a57919f4352bff0253b21a5a8cfe89b03d068c19debd7507b31541'
b) = '0xab5d7e6309b4c595cf3fb75a50a7dcab97a9e7ddd333f578f5dbee79816b7195'
c) = '0x8733a16bced0b8dff526ccdc2afd8790012adbdaffbdb0c1467f263859df81e0'
d) = '0x5089ca96e4a2f55dd72d50510fdcde7c1f815581ec6ac772ad10a075a401fcde'
e) = '0x7d9b67b96e2722d797b6ddd72371ef81200da4f03a4517028bc826fc5ff3ccd7'
f) = '0x4d36c37ee69b70e4e65a9836f65e977d7bf7915f734a50c27cbd852b3e1fed01'

tx_id = '0x475677ca105568dd0b6c08dbf9f6f65e80f81da8ea2a79b370d108379020128b'

Web Topup & Wallet Topup

The TxID of the Topup transactions (both Web and Wallet) are built using the root hash of a Merkle Tree with the following childs:

  • amount in Wei
  • address
  • timestamp as %Y-%m-%dT%H:%M:%S.%f
  • country

Topup Merkle Tree

Bonus Hybrid

The TxID of the Bonus transactions are built using the root hash of a Merkle Tree with the following childs:

  • address
  • amount in Wei
  • timestamp as %Y-%m-%dT%H:%M:%S.%f

Bonus Merkle Tree

Transfer Hybrid

The TxID of the APPC Credits Transfers are built using the root hash of a Merkle Tree with the following childs:

  • amount in Wei
  • address
  • user
  • timestamp as %Y-%m-%dT%H:%M:%S.%f

Transfer Merkle Tree

APPC Credits Balance Signature

The Balance Signature sent to the blockchain to prove ownership of the APPC Credits is built using the root hash of a Merkle Tree with the following childs:

  • address
  • balance in APPC

Balance Signature Merkle Tree

Python Code

The code needed to build the TxID (compute the Merkle Tree root hash) in Python3.5+ is the following:

from sha3 import keccak_256
import functools

def m_tree(transactions):
    hash0 = transactions

    while True:
        hash1 = []
        pairs = [hash0[k:k+2] for k in range(0, len(hash0), 2)]
        for pair in pairs:
            pair_concat = functools.reduce(lambda x, y: x + y, pair)
            new_hash = '0x' + keccak_256(pair_concat.encode("utf8")).hexdigest()
            hash1.append(new_hash)
        if len(hash1) == 1:
            break
        hash0 = hash1
    return hash1[0]

iap_txid = m_tree([amount, address, dev, store, oem, package_name, sku, timestamp, country])
poa_txid = m_tree([bid_id, package_name, country, hash_ip, address, timestamps, nonces])
balance_sig = m_tree([address, amount])
bonus_txid = m_tree([address, amount, timestamp])

iap_a) = '0x' + keccak_256((amount + address).encode("utf8")).hexdigest()
iap_e) = '0x' + keccak_256(country.encode("utf8")).hexdigest()

poa_a) = '0x' + keccak_256((bidID + package_name).encode("utf8")).hexdigest()
poa_d) = '0x' + keccak_256(nonces.encode("utf8")).hexdigest()