From 668f0e42591148286504dcda243a0bfec81fd4c8 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Fri, 3 Aug 2018 17:16:19 +0200 Subject: [PATCH] Attachments --- drafts/draft-0002.md | 121 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 drafts/draft-0002.md diff --git a/drafts/draft-0002.md b/drafts/draft-0002.md new file mode 100644 index 000000000..042bdfa12 --- /dev/null +++ b/drafts/draft-0002.md @@ -0,0 +1,121 @@ +## Preamble + +``` +SEP: xxxx +Title: Attachment Convention +Author: stellar.org +Status: Draft +Created: 2018-08-03 +``` + +## Simple Summary +Sometimes there is a need to send more information about a transaction than fits in the provided memo field, for example: KYC info, an invoice, a short note. Such data shouldn't be placed in the [ledger](https://www.stellar.org/developers/guides/concepts/ledger.html) because of it's size or private nature. Instead, you should create what we call an attachment. A Stellar attachment is simply a JSON document. The `sha-256` hash of this attachment is included as a `memo_hash` in the transaction. The actual attachment document can be sent to the receiver through some other channel, most likely through the receiver's [Auth server](./sep-0003.md). + +## Specification + +The attachment has a following structure: + +```json +{ + "nonce": "", + "transaction": { + "sender_info": { + "first_name": "", + "middle_name": "", + "last_name": "", + "address": "
", + "city": "", + "province": "", + "country": "", + "date_of_birth": "", + "company_name": "" + }, + "route": "", + "note": "" + }, + "operations": [ + { + "sender_info": , + "route": "", + "note": "" + }, + // ... + ] +} +``` + +Attachments can be extended with extra information however, the should contain the following fields: + +Name | Data Type | Description +-----|-----------|------------ +`nonce` | string | [Nonce](https://en.wikipedia.org/wiki/Cryptographic_nonce) is a unique value. Every transaction you send should have a different value. A nonce is needed to distinguish attachments of two transactions sent with otherwise identical details. For example if you send $10 to Bob two days in a row. +`transaction.sender_info` | JSON | JSON containing KYC info of the sender. This JSON object can be extended with more fields if needed. +`transaction.route` | string | The route information returned by the receiving federation server (`memo` value). Tells the receiver how to get the transaction to the ultimate recipient. +`transaction.note` | string | A note attached to transaction. +`operations[i]` | | `i`th operation data. Can be omitted if transaction has only one operation. +`operations[i].sender_info` | JSON | `sender_info` for `i`th operation in the transaction. If empty, will inherit value from `transaction`. +`operations[i].route` | string | `route` for `i`th operation in the transaction. If empty, will inherit value from `transaction`. +`operations[i].note` | string | `note` for `i`th operation in the transaction. If empty, will inherit value from `transaction`. + +### Sending Attachments + +An attachment and its hash (in a transaction) can be sent to Auth server of a receiving organization using [Compliance protocol](./compliance-protocol.md). + +### Calculating Attachment hash + +To calculate the Attachment hash you need to stringify the JSON object and calculate `sha-256` hash. In Node.js: + +```js +const crypto = require('crypto'); +const hash = crypto.createHash('sha256'); + +hash.update(JSON.stringify(attachment)); +var memoHashHex = hash.digest('hex'); +``` + +To add the hash to your transaction use the [`TransactionBuilder.addMemo`](http://stellar.github.io/js-stellar-base/TransactionBuilder.html#addMemo) method. + +#### Example + +```js +var crypto = require('crypto'); + +var nonce = crypto.randomBytes(16); +var attachment = { + "nonce": nonce.toString('hex'), + "transaction": { + "sender_info": { + "name": "Sherlock Holmes", + "address": "221B Baker Street", + "city": "London NW1 6XE", + "country": "UK", + "date_of_birth": "1854-01-06" + } + }, + "operations": [ + // Operation #1: Payment for Dr. Watson + { + "route": "watson", + "note": "Payment for helping to solve murder case" + }, + // Operation #2: Payment for Mrs. Hudson + { + "route": "hudson", + "note": "Rent" + } + ] +}; + +var hash = crypto.createHash('sha256'); +hash.update(JSON.stringify(attachment)); +var memoHashHex = hash.digest('hex'); +console.log(memoHashHex); +``` + +## Test Cases + +Use [GoStellar](https://gostellar.org/) application to check if Compliance protocol and attachments were implemented correctly. + +## Reference implementations + +* [`github.com/stellar/go/protocols/compliance` package](https://github.com/stellar/go/blob/master/protocols/compliance).