Skip to main content

A common identity module

Project description

Ming Ke Ming (名可名) -- Account Module (Python)

license Version PRs Welcome Platform

This document introduces a common Account Module for decentralized user identity authentication.

Copyright © 2018-2019 Albert Moky

0. Meta

The Meta was generated by your private key, it can be used to build a new ID for entity, or verify the ID/PK pair.

It consists of 4 fields:

Field Description
version Meta Algorithm Version
seed Entity Name
key Public Key
fingerprint Signature to generate address

0.0. Version

  • 0x01 Default version
  • 0x02 BTC version
  • 0x03 Extended BTC version
  • 0x04 ETH version
  • 0x05 Extended ETH version

0.1. Seed

A string as same as ID.name for generate the fingerprint.

0.2. Key

A public key (PK) was binded to an ID by the Meta Algorithm.

0.3. Fingerprint

THe fingerprint field was generated by your private key and seed:

data = seed.encode('utf-8')
fingerprint = private_key.sign(data)

1. ID

The ID is used to identify an entity(user/group). It consists of 3 fields and 2 extended properties:

Field Description
name Same with meta.seed
address Unique Identification
terminal Login point, it's optional.
type Network type
number Search Number

The ID format is name@address[/terminal].

1.0. Type

The network type of a person is 8, and group is 16:

class NetworkType(IntEnum):
    # Person Account
    MAIN = 0x08         # 0000 1000 (Person)

    # Virtual Groups
    GROUP = 0x10        # 0001 0000 (Multi-Persons)
    POLYLOGUE = 0x10    # 0001 0000 (Multi-Persons Chat, N < 100)
    CHATROOM = 0x30     # 0011 0000 (Multi-Persons Chat, N >= 100)

    # Network
    PROVIDER = 0x76     # 0111 0110 (Service Provider)
    STATION = 0x88      # 1000 1000 (Server Node)

    # Internet of Things
    THING = 0x80        # 1000 0000 (IoT)
    ROBOT = 0xC8        # 1100 1000

1.1. Name

The Name field is a username, or just a random string for group:

  1. The length of name must more than 1 byte, less than 32 bytes;
  2. It should be composed by a-z, A-Z, 0-9, or charactors '_', '-', '.';
  3. It cannot contain key charactors('@', '/').
# Name examples
user_name  = "Albert.Moky"
group_name = "Group-9527"

1.2. Address

The Address field was created with the Fingerprint in Meta and a Network ID:

def check_code(data: bytes) -> bytes:
    # check code in BTC address
    return sha256(sha256(data))[:4]

class BTCAddress(Address):

    @classmethod
    def new(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)
        return BTCAddress(address)

When you get a meta for the entity ID from the network, you must verify it with the consensus algorithm before accept its public key.

1.3. Terminal

A resource identifier as Login Point.

1.4. Number

A Search Number is defined for easy remember. Its value is converted from the check code of the address. It's greater than 0 and smaller than 232 (4,294,967,296).

2. Samples

ID

# ID examples
ID1 = "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj"  # Immortal Hulk
ID2 = "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk"  # Monkey King

Meta

/* 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 with BASE64 algorithm as default, excepts the address)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkm-0.10.11.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkm-0.10.11-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

Details for the file mkm-0.10.11.tar.gz.

File metadata

  • Download URL: mkm-0.10.11.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.2

File hashes

Hashes for mkm-0.10.11.tar.gz
Algorithm Hash digest
SHA256 dc53beb15236b825805fd876ff2176ed214f1478b9557f8c7e61b97593a7876e
MD5 4d7740cbab876dea2d31a5f47b43bb3e
BLAKE2b-256 7e4c9eafc39e2987a84060d620095ebccd78a8279628d45bcc1f8958c69063c2

See more details on using hashes here.

File details

Details for the file mkm-0.10.11-py3-none-any.whl.

File metadata

  • Download URL: mkm-0.10.11-py3-none-any.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.2

File hashes

Hashes for mkm-0.10.11-py3-none-any.whl
Algorithm Hash digest
SHA256 554f492ba6343afb0a0b5712048f3830e4493b0e51502e4150c6aa6a84d8117d
MD5 450be80a69ff75a3af595630248c7b89
BLAKE2b-256 26aca50501fb2b42d5128de043b47ae9574bbdbc38d2b14afee3a353eda74d62

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page