Using IPFS as MEMO in Stellar-Transaction

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:

Qme2sLfe9ZMdiuWsEtajWMDzx6B7VbjzpSC2VWhtB6GoB1

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.

https://ipfs.io/ipfs/Qme2sLfe9ZMdiuWsEtajWMDzx6B7VbjzpSC2VWhtB6GoB1

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.

et voilà

Example

QmYtUc4iTCbbfVSDNKvtQqrfyezPPnFvE33wFmutw9PBBk

decoded in hex

12209cbc07c3f991725836a3aa2a581ca2029198aa420b9d99bc0e131d9f3e2cbe47

after stripping the prefix the hash you can use in stellar transactions is

9cbc07c3f991725836a3aa2a581ca2029198aa420b9d99bc0e131d9f3e2cbe47

Tools: 

Nodejs module for base58 handling

https://www.npmjs.com/package/bs58
http://cryptocoinjs.com/modules/misc/bs58/

online base58 decoder

http://lenschulwitz.com/base58
https://incoherency.co.uk/base58/

 

Recent Posts

Recent Comments

Archives

abcxyz Written by:

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *