Package: mkm
Ming Ke Ming (名可名) -- Account Module (Python)Thisdocumentintroduces a commonAccount Modulefor decentralized user identity authentication.Copyright © 2018-2019 Albert MokyMetaTypeKeySeedFingerprintIDTypeNameAddressTerminalSamples0. MetaTheMetawas generated by yourprivate key, it can be used to build a new ID for entity, or verify the ID/PK pair.It consists of 4 fields:FieldDescriptiontypeMeta Algorithm VersionkeyPublic KeyseedEntity NamefingerprintSignature to generate address0.0. Meta Type0x01Default version0x02BTC version0x03Extended BTC version0x04ETH version0x05Extended ETH version0.1. KeyApublic key(PK) was bound to an ID by theMeta Algorithm.0.2. SeedA string as same asID.namefor generate the fingerprint.0.3. FingerprintTHefingerprintfield was generated by yourprivate keyandseed:data=seed.encode('utf-8')fingerprint=private_key.sign(data)1. IDTheIDis used to identify anentity(user/group). It consists of 3 fields and 2 extended properties:FieldDescriptionnameSame with meta.seedaddressUnique IdentificationterminalLogin point, it's optional.typeNetwork typeThe ID format isname@address[/terminal].1.0. ID TypeThenetwork typeof a person is8, and group is16:classNetworkType(IntEnum):# Person AccountMAIN=0x08# 0000 1000 (Person)# Virtual GroupsGROUP=0x10# 0001 0000 (Multi-Persons)POLYLOGUE=0x10# 0001 0000 (Multi-Persons Chat, N < 100)CHATROOM=0x30# 0011 0000 (Multi-Persons Chat, N >= 100)# NetworkPROVIDER=0x76# 0111 0110 (Service Provider)STATION=0x88# 1000 1000 (Server Node)# Internet of ThingsTHING=0x80# 1000 0000 (IoT)ROBOT=0xC8# 1100 10001.1. NameTheNamefield is a username, or just a random string for group:The length of name must more than 1 byte, less than 32 bytes;It should be composed by a-z, A-Z, 0-9, or charactors '_', '-', '.';It cannot contain key charactors('@', '/').# Name examplesuser_name="Albert.Moky"group_name="Group-9527"1.2. AddressTheAddressfield was created with theFingerprintin Meta and aNetwork ID:defcheck_code(data:bytes)->bytes:# check code in BTC addressreturnsha256(sha256(data))[:4]classBTCAddress(Address):@classmethoddefnew(cls,data:bytes,network:NetworkType=0)->Address:"""Generate address with fingerprint and network ID:param data:    fingerprint (signature/key.data):param network: address type:return:        Address object"""prefix=chr(network).encode('latin1')digest=ripemd160(sha256(data))code=check_code(prefix+digest)address=base58_encode(prefix+digest+code)returnBTCAddress(address)When you get a meta for the entity ID from the network,
you must verify it with the consensus algorithm before accept itspublic key.1.3. TerminalA resource identifier asLogin Point.2. SamplesID# ID examplesID1="hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj"# Immortal HulkID2="moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk"# Monkey KingMeta/* Meta(JsON) for hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj */{"version":0x01,"key":{"algorithm":"RSA","data":"-----BEGIN PUBLIC KEY-----\nMIGJAoGBALB+vbUK48UU9rjlgnohQowME+3JtTb2hLPqtatVOW364/EKFq0/PSdnZVE9V2Zq+pbX7dj3nCS4pWnYf40ELH8wuDm0Tc4jQ70v4LgAcdy3JGTnWUGiCsY+0Z8kNzRkm3FJid592FL7ryzfvIzB9bjg8U2JqlyCVAyUYEnKv4lDAgMBAAE=\n-----END PUBLIC KEY-----",// other parameters"mode":"ECB","padding":"PKCS1","digest":"SHA256"},"seed":"hulk","fingerprint":"jIPGWpWSbR/DQH6ol3t9DSFkYroVHQDvtbJErmFztMUP2DgRrRSNWuoKY5Y26qL38wfXJQXjYiWqNWKQmQe/gK8M8NkU7lRwm+2nh9wSBYV6Q4WXsCboKbnM0+HVn9Vdfp21hMMGrxTX1pBPRbi0567ZjNQC8ffdW2WvQSoec2I="}(All data encode withBASE64algorithm as default, excepts theaddress)