One of the features of the stellar transaction protocol is the optional use of a memo send with any transaction. You can use plain text to send an order number for a payment or an account identifier for federation or multi account addresses.
The size of the text input is limited to 28 bytes which allows the user to send as much as 28 characters if he isn’t using strange (german) umlauts or special characters.
Fair enough. But what if you want to send a longer text or even a file like an invoice or detailed Information about whatever…
While I research about that matter I stumbled upon IPFS which is a protocol for a peer to peer distributed web where any content is identifiable by its hash through any node contributing to the network. It uses techniques well known from bittorrent, blockchain and cryptographic algorithm.
How to use IPFS isn’t part of the current post. You can read all about it on https://ipfs.io/.
All we need right now is the fact that all content published to and distributed over the IPFS-network is addressable by its unique hash. We keep in mind that IPFS implements multihash which is a combination of hashing algorithm (SHA1, SHA2) and procedural encoding (base64, base58 etc.).
If you use the GO implementation of IPFS the resulting hash for any content looks similar to this:
which is the result of encoding a sha256 hash in base58.
You can access the content through any IPFS gateway by requesting the given hash.
Turning back to the transaction memo types in stellar we can see that instead of a plain string we can send a 32-byte hash in hexadecimal format as well.
This in fact is the result of the first part of the process IPFS applys to content to generate its unique hash.
The IPFS-hashes you get when adding a file or any content with go-ipfs start with Qm. To indicate which algorithm for hashing where used the client adds a prefix to the generated hash for any other client to know how to deal with the multihash. In case of the go implementation sha256 length 32 is used. So the prefix 1220 is added before base58 is applied. (in short)
if you now need to extract the 32byte hex hash you want to use in the hash memo, you have to decode the base58 and strip the leading 1220.
decoded in hex
after stripping the prefix the hash you can use in stellar transactions is
Nodejs module for base58 handling
online base58 decoder
Be First to Comment