Exemple #1
0
def annoy_commit(account, usk, pk, GID, UID,title = "paper_title",  body = "paper_body", groupID="computer"):
    annoy_author = 'nya'
    # group signature   ------title 必须   这里面是对title进行hash 然后使用usk对hash进行签名
    sig = group_signature.sign(title, usk, pk, GID, UID, groupID)

    permlink = ''.join(random.choices(string.digits, k=7))
    print("permlink is " + permlink)
    op = operations.CommitPaper(
        **{
            "account": account,
            "author": annoy_author,
            "permlink": permlink,
            "title": title,
            "body": body,
            "json_metadata": "",
            "c0": str(sig['c0']),
            "c5": str(sig['c5']),
            "c6": str(sig['c6']),
            "e1": str(sig['e1']),
            "e2": str(sig['e2']),
            "e3": str(sig['e3']),
            "c": str(sig['c']),
            "s1": str(sig['s1']),
            "s2": str(sig['s2']),
            "s3": str(sig['s3'])
        }
    )
    print("commitop",op)
    return op, sig, permlink
Exemple #2
0
def main():
    # 假设不存在不可用节点(无法判断节点状态)
    k = 2
    n =2
    nodelist =[
        'http://101.76.212.247:8090',
        'http://101.76.212.247:8094',
        'http://101.76.221.115:8092'

    ]
    groupobj = PairingGroup('SS512')

    group_signature = GroupSignature(groupobj)

    L = group_signature.LGen(n, k)
    print(L)
    steembase.chains.known_chains['TEST'] = {
        'chain_id': '18dcf0a285365fc58b71f18b3d3fec954aa0c141c44e4e5cb4cf777b9eab274e',
        'prefix': 'TST', 'steem_symbol': 'TESTS', 'sbd_symbol': 'TBD', 'vests_symbol': 'VESTS'
    }

    vkliststr= []
    uskliststr = []
    vklist = []
    usklist = []

    h1str = ""
    clientlist = []
    pk = {}
    count = 0
    groupID = "computer"
    userID = "user"
    GID = group_signature.group.hash(groupID)
    UID = group_signature.group.hash(userID)
    print("uid")
    print(UID)
#connect node and private posting key
# 记录可用节点的编号!!!!!!

    #该循环仅获得gvki和uski 并通过gvki验证uski的正确性
    for i in range(n):
        clientlist.append(steem.Steem(nodes=[nodelist[i]],keys=["5JHKRW4d7BTU1V1CXDQAPmDfBBFr6XqQoDDUpmPP1JW38s5NjeW"]))
        
        vkliststr.append(clientlist[i].get_vk()['vk'])
        vklist.append(group_signature.group.fromstr(vkliststr[i],10, G1))
        
        uskliststr.append(clientlist[i].user_extract(userID))
        usklist.append({})
        usklist[i]['b0'] = group_signature.group.fromstr(uskliststr[i]['b0'], 10, G2)
        usklist[i]['b3'] = group_signature.group.fromstr(uskliststr[i]['b3'], 10, G2)
        usklist[i]['b4'] = group_signature.group.fromstr(uskliststr[i]['b4'], 10, G2)
        usklist[i]['b5'] = group_signature.group.fromstr(uskliststr[i]['b5'], 10, G1)
        print(usklist[i])
        if h1str == "":
            h1str = clientlist[i].get_pk()['pk']
            pk = group_signature.pkGen(h1str)

        if(group_signature.verifyUsk(usklist[i],vklist[i],pk,GID, UID)):
            count = count + 1
        else:
            print("key is invalide\n\n")

    if count< k:
        print("there is not k admin\n")
        return 

    #通过uski计算出最终的usk
    usk = group_signature.uskGen(usklist, pk, GID, UID, L,k)
    # print(pk)

    # ---------------------------------------------------commit 开始
    account = 'initminer2'
    author = 'nya'
    title = "title"
    body = "body"

    #对title进行群签名得到sig
    sig = group_signature.sign(title,usk, pk,GID, UID,groupID)

    json_metadata = "abc"
    permlink = ''.join(random.choices(string.digits, k=4))

    print("permlink is " + permlink)
    op = operations.CommitPaper(
        **{
            "account":account,
            "author":"nya",
            "permlink":permlink,
            "title":title,
            "body":body,
            "json_metadata":json_metadata,
            "c0":str(sig['c0']),
            "c5":str(sig['c5']),
            "c6":str(sig['c6']),
            "e1":str(sig['e1']),
            "e2":str(sig['e2']),
            "e3":str(sig['e3']),
            "c":str(sig['c']),
            "s1":str(sig['s1']),
            "s2":str(sig['s2']),
            "s3":str(sig['s3'])
        }
    )

    #该操作由第二个账户进行
    tx = TransactionBuilder(steemd_instance=clientlist[1].steemd,wallet_instance = clientlist[0].wallet,no_broadcast = False)

    tx.appendOps(op)
    tx.appendSigner('initminer2','posting')

    tx.sign()
    re = tx.broadcast()
    #---------------------------------------------------commit 结束

    # ---------------------------------------------------open 开始
    okliststr=[]
    oklist = []
    i = 0
    for client in clientlist:
        okstr = client.get_ok(str(sig['e1']),str(sig['e2'])) #每个节点返回ok1和ok2
        print(okstr)
        okliststr.append(okstr)
        i = i + 1    

    if i < k:
        print("the number of ok is not enough\n")
        return

    #通过ok1和ok2   计算lameda
    lam = group_signature.open(okliststr,L,k)
    
    E = (pk['n'] ** UID) * lam #计算出e3  即签名的e3 判断是否相等
    print("e3",E)

    op = operations.ApplyOpen(
        **{
            'account':account,
            'author':userID,
            'lambda':str(lam),
            'permlink':permlink,
            'json_metadata':json_metadata
        }
    )
    
    tx = TransactionBuilder(steemd_instance=clientlist[0].steemd,wallet_instance = clientlist[0].wallet,no_broadcast = False)
    tx.appendOps(op)
    tx.appendSigner('initminer2','posting')

    tx.sign()
    # time.sleep(5)
    re = tx.broadcast()
    print("re",re)
    # ---------------------------------------------------open 结束
    return