Created
May 19, 2016 12:57
-
-
Save davidgljay/62d65a54b1203f59fcfcc4bdb92320ec to your computer and use it in GitHub Desktop.
Nametag Badge Contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Badge { | |
//This should be consistent across all copies of this badge. | |
//If the title is changed, each user can decide whether to use the new title. | |
//Also, these should all be linked lists if possible. | |
string[] titles; | |
//Idea: the person receiving the badge receives a unique name for that badge. | |
//This makes it easy to id them across rooms, even if they use different names. | |
//These badge names can go into the default names listed. | |
string[] badgenames; | |
//This should be unique to this grantee. | |
//The description can be updated by the granter, with an opt-in from the grantee. | |
string[] descriptions; | |
//This can be updated by the granter with an opt-in from the grantee. | |
//Icons can be stored on s3 or IPFS. | |
string[] icons; | |
//This can be used for arbitrary metadata. Let the games begin! | |
struct Note { | |
//A key allowing the message in this note to be read, encrypted using the | |
//public key of the grantee. | |
string key; | |
//The key of the previous note, encrypted using this note's key. | |
string prevKey; | |
//The message of this note, encrypted using this note's key. | |
string msg; | |
} | |
Note[] notes; | |
//The badge granter. Note that the grantee is not named, and must be verified through a | |
//cryptographic signature. | |
address granter; | |
//All strings submitted to this function are double-signed by the granter and grantee through | |
//the following process: | |
//Step 1: Granter securely sends grantee the info of the badge that they would like to grant. | |
//Step 2: Grantee generates a private key and public key for the badge. | |
//Step 3: Grantee digitally signs badge info (title, description, etc) and securely returns | |
// it to the granter along with the public key. | |
//Step 4: Granter digitally signs the already-signed info sent to them by the grantee and | |
// creates a new badge by calling this function: | |
function Badge(string title, string badgename, string description, string icon, string note, string noteKey) { | |
granter = msg.sender; | |
titles.push(title); | |
badgenames.push(badgename); | |
descriptions.push(description); | |
icons.push(icon); | |
notes.push(Note({key:noteKey, msg:note, prevKey:''})); | |
} | |
function addTitle(string title) { | |
if (msg.sender != granter) { | |
throw; | |
} | |
titles.push(title); | |
} | |
function addDesc(string desc) { | |
if (msg.sender != granter) { | |
throw; | |
} | |
descriptions.push(desc); | |
} | |
function addBadgeName(string bn) { | |
if (msg.sender == granter) { | |
throw; | |
} | |
badgenames.push(bn); | |
} | |
function addIcon(string icon) { | |
if (msg.sender != granter) { | |
throw; | |
} | |
icons.push(icon); | |
} | |
//A note on notes: | |
//Unlike all other elements of the badge, notes should be addable WITHOUT explicit | |
//permission from the badgeholder. | |
function addNote(string key, string prevKey, string note) { | |
if (msg.sender != granter) { | |
throw; | |
} | |
notes.push(Note({ | |
key:key, | |
prevKey:prevKey, | |
msg:note | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment