MAM 使用 Merkle tree based signature scheme 作為其簽章的基礎,並且採用其所產生的 Markle tree root 作為MAM的廣播地址,也同時是驗證 MAM 所使用的 publicKey (可以想像成平常交易使用的地址),此外,注意此處使用的「廣播」二字,即表達 MAM 的通訊是單向而非雙向的,並且監聽頻道的使用者無法向前追溯訊息。加密則是採用了one-time symmetric key encryption。
在這樣的架構之下,MAM 提供 Channel spliting 和多種廣播的方式:
根據官方的說法,MAM中訊息之間的結構也可以理解成父資料夾與子資料夾之間的關係,皆可以隱藏或是加密(對應到 Private 和 Restricted)
以下皆是針對 Public 模式說明
subscribed
: []channel
:
side_key
: String
Encryption keymode
: String
(public private restricted)next_root
: String
security
: Int
1,2,3start
: Int
count
: 1,next_count
: 1,index
: 0seed
: String
構造一個 MAM 訊息需要以下部份:
- `message`: `String` Tryte-encoded plain text
- `merkleTree`: `Object` Merkle tree
- `index`: `Int` Index of the merkle tree leaf key
- `nextRoot`: `String` Root of the next merkle tree
- `channelKey`: `String` Channel key (used for data encryption)
建立後程式會回傳下一個訊息使用的金鑰`nextKey` ,
其實就是 hash(`channelKey`+ 1 + salt ),
在一個 MAM 訊息中,有以下幾個部份,並且在tag
部份帶有每次加密時皆會使用到的 salt:
root
: String
Root of the merkle treenextRoot
: String
Root of the next merkle treenextKey
: String
Tryte-encoded key for the next message in this chainmessage
: String
Tryte-encoded messageroot
和 nextRoot
指的是 Markle tree root
IOTA在Medium上的MAM文章中提到一句 "MAM uses a Merkle tree based signature scheme to sign the cipher digest of an encrypted message." 但實際上IOTA上的實做與該文章不同,
而是在結合了加密貨幣的address這個概念後,更進一步的利用Merkel tree的特點,以merkle tree root作為訊息傳送的地址大量簡化了流程,驗證時即是利用獲得的 key 以及其餘 merkle tree 的節點 hash 來重組出root,再檢查 root == message address 即為通過驗證。
Merkle tree的葉節點數量表示可以在該 root(address) 上發送幾次訊息,下一次廣播訊息時就直接使用其他葉節點作為 key,也就是說能證明自己擁有 merkle tree 就是證明自己是該 channel 的"擁有者"。
public mode
: publish to root, use root to encrypt
private mode
: publish to hash(root), use root to encrypt
restricted mode
: publish to hash(root+side_key), use root+side_key to encrypt
https://github.com/iotaledger/mam.client.js/blob/master/Overview.md
https://blog.iota.org/introducing-masked-authenticated-messaging-e55c1822d50e