Skip to content

Instantly share code, notes, and snippets.

@loon3
Last active August 29, 2015 14:27
Show Gist options
  • Save loon3/98219e445a3aacf093a2 to your computer and use it in GitHub Desktop.
Save loon3/98219e445a3aacf093a2 to your computer and use it in GitHub Desktop.
Blockchain Validated Asset Metadata

Blockchain Validated Asset Metadata (BVAM)

Blockchain Validated Asset Metadata (BVAM) is a method which allows Counterparty Token metadata to be stored off-blockchain yet still be verifiable and inalterable.

http://xcp.ninja is a proof of concept server for creating and storing BVAM json files.

Example BVAM json, http://xcp.ninja/hash/TB2rTB5FdLtqYu31wTmKgy54TYeZSqJgr3.json

Referenced Counterparty Asset, https://counterpartychain.io/asset/A11161111624187815485

Method

  1. A third party service(s) hosts a JSON file with Enhanced Asset info (this where the current protocol stops).

  2. When issuing a new asset in Counterparty, the asset description references the hash of the stringify'd enhanced asset JSON data (instead of referencing the URL of the JSON file in the asset description). To save space, the SHA256 hash is encoded, similar to a bitcoin public key but with the version numbered altered to display a "T" as the first character instead of a "1".

    Ex. TB2rTB5FdLtqYu31wTmKgy54TYeZSqJgr3

    var jsondata = '{"ownername":"","ownertwitter":"","owneraddress":"1GcFhAQGFZVDAr4jiR2tKwisHcgNUjhGNC","assetid":"A11195611377969306165","assetname":"can you see me 2","assetdescription":"","assetwebsite":""}'
    
    var firstSHA = Crypto.SHA256(jsondata)
    
    var hash160 = Crypto.RIPEMD160(Crypto.util.hexToBytes(firstSHA))
    var version = 0x41 // "T"
    var hashAndBytes = Crypto.util.hexToBytes(hash160)
    hashAndBytes.unshift(version)
    
    var doubleSHA = Crypto.SHA256(Crypto.util.hexToBytes(Crypto.SHA256(hashAndBytes)))
    var addressChecksum = doubleSHA.substr(0,8)
    
    var unencodedAddress = "41" + hash160 + addressChecksum
    
    var address = Bitcoin.Base58.encode(Crypto.util.hexToBytes(unencodedAddress))
    

    http://jsfiddle.net/k0jk49km/

  3. The hash is prefixed in the asset description with "TOKNID-" for wallet software to identify that an asset has associated BVAM. This represents a 41-byte asset description.

    Ex. TOKNID-TB2rTB5FdLtqYu31wTmKgy54TYeZSqJgr3

  4. Wallet software can query any third party service and trust that the data is valid without the need to trust the source. This is accomplished by independently verifying the data hash within the wallet using the method in Step 2.

  5. BVAM must define, at a minimum, the 'asset' element within the JSON data. This conforms to the current Counterparty Enhanced Asset Info documentation. Additional elements should be standardize to some extent but can also be customized to meet the needs of each wallet provider.

@deweller
Copy link

Want to create a json schema to augment this one?

https://raw.githubusercontent.com/CounterpartyXCP/counterblock/master/counterblock/schemas/asset.schema.json

You can check out http://xcp.coindaddy.io/CZAR.json for some inspiration. I think we can clean up the naming convention (e.g. longString and some_name). Don't forget to add a field for tokenly_username. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment