Ejemplo n.º 1
0
def load():
    port = genHa()[1]
    ha = HA('0.0.0.0', port)
    name = "hello"
    wallet = Wallet(name)
    wallet.addIdentifier(signer=SimpleSigner(
        seed=b'000000000000000000000000Steward1'))
    client = Client(name, ha=ha)
    with Looper(debug=getConfig().LOOPER_DEBUG) as looper:
        looper.add(client)
        print('Will send {} reqs in all'.format(numReqs))
        requests = sendRandomRequests(wallet, client, numReqs)
        start = perf_counter()
        for i in range(0, numReqs, numReqs // splits):
            print('Will wait for {} now'.format(numReqs // splits))
            s = perf_counter()
            reqs = requests[i:i + numReqs // splits + 1]
            waitForSufficientRepliesForRequests(looper,
                                                client,
                                                requests=reqs,
                                                fVal=2,
                                                customTimeoutPerReq=3)
            print('>>> Got replies for {} requests << in {}'.format(
                numReqs // splits,
                perf_counter() - s))
        end = perf_counter()
        print('>>>{}<<<'.format(end - start))
        exit(0)
Ejemplo n.º 2
0
    def __init__(self, name: str):
        PWallet.__init__(self, name)
        Sponsoring.__init__(self)

        self._credMasterSecret = None
        self._attributes = {
        }  # type: Dict[(str, Identifier, Optional[Identifier]), Attribute]
        self._credDefs = {}  # type: Dict[(str, str, str), CredDef]
        self._credDefSks = {}  # type: Dict[(str, str, str), CredDefSk]
        self._credentials = {}  # type: Dict[str, Credential]
        self.lastKnownSeqs = {}  # type: Dict[str, int]
        self._links = {}  # type: Dict[str, Link]
        self.knownIds = {}  # type: Dict[str, Identifier]
        self._claimDefs = {}  # type: Dict[ClaimDefKey, ClaimDef]
        self._issuerSks = {}
        self._issuerPks = {}
        # transactions not yet submitted
        self._pending = deque(
        )  # type Tuple[Request, Tuple[str, Identifier, Optional[Identifier]]

        # pending transactions that have been prepared (probably submitted)
        self._prepared = {}  # type: Dict[(Identifier, int), Request]

        self.replyHandler = {
            ATTRIB: self._attribReply,
            GET_ATTR: self._getAttrReply,
            CRED_DEF: self._credDefReply,
            GET_CRED_DEF: self._getCredDefReply,
            NYM: self._nymReply,
            GET_NYM: self._getNymReply,
            GET_TXNS: self._getTxnsReply,
            ISSUER_KEY: self._issuerKeyReply,
            GET_ISSUER_KEY: self._getIssuerKeyReply,
        }
Ejemplo n.º 3
0
def changeHA(looper, config, nodeName, nodeSeed, newNodeHA,
             stewardName, stewardsSeed, newClientHA=None):
    if not newClientHA:
        newClientHA = HA(newNodeHA.host, newNodeHA.port + 1)

    # prepare steward wallet
    stewardSigner = SimpleSigner(seed=stewardsSeed)
    stewardWallet = Wallet(stewardName)
    stewardWallet.addIdentifier(signer=stewardSigner)

    # prepare client to submit change ha request
    _, randomClientPort = genHa()
    client = Client(stewardName,
                    ha=('0.0.0.0', randomClientPort), config=config)
    looper.add(client)
    timeout = waits.expectedClientToPoolConnectionTimeout(4)
    looper.run(eventually(__checkClientConnected, client,
                          retryWait=1, timeout=timeout))

    nodeVerKey = SimpleSigner(seed=nodeSeed).verkey

    # send request
    req = submitNodeIpChange(client, stewardWallet, nodeName, nodeVerKey,
                             newNodeHA, newClientHA)
    return client, req
Ejemplo n.º 4
0
    def __init__(self, name: str, supportedDidMethods: DidMethods = None):
        PWallet.__init__(self, name, supportedDidMethods or DefaultDidMethods)
        Sponsoring.__init__(self)
        self._attributes = {}  # type: Dict[(str, Identifier,
        # Optional[Identifier]), Attribute]

        self.env = None  # Helps to know associated environment
        self._nodes = {}
        self._upgrades = {}

        self._links = {}  # type: Dict[str, Link]
        self.knownIds = {}  # type: Dict[str, Identifier]

        # transactions not yet submitted
        self._pending = deque()  # type Tuple[Request, Tuple[str, Identifier,
        #  Optional[Identifier]]

        # pending transactions that have been prepared (probably submitted)
        self._prepared = {}  # type: Dict[(Identifier, int), Request]
        self.lastKnownSeqs = {}  # type: Dict[str, int]

        self.replyHandler = {
            ATTRIB: self._attribReply,
            GET_ATTR: self._getAttrReply,
            NYM: self._nymReply,
            GET_NYM: self._getNymReply,
            GET_TXNS: self._getTxnsReply,
            NODE: self._nodeReply,
            POOL_UPGRADE: self._poolUpgradeReply
        }
Ejemplo n.º 5
0
def changeNodeHa(looper, txnPoolNodeSet, tdirWithClientPoolTxns,
                 poolTxnData, poolTxnStewardNames, tconf, shouldBePrimary, tdir):
    # prepare new ha for node and client stack
    subjectedNode = None
    stewardName = None
    stewardsSeed = None

    for nodeIndex, n in enumerate(txnPoolNodeSet):
        if shouldBePrimary == n.has_master_primary:
            subjectedNode = n
            stewardName = poolTxnStewardNames[nodeIndex]
            stewardsSeed = poolTxnData["seeds"][stewardName].encode()
            break

    nodeStackNewHA, clientStackNewHA = genHa(2)
    logger.debug("change HA for node: {} to {}".format(
        subjectedNode.name, (nodeStackNewHA, clientStackNewHA)))

    nodeSeed = poolTxnData["seeds"][subjectedNode.name].encode()

    # change HA
    stewardClient, req = changeHA(looper, tconf, subjectedNode.name, nodeSeed,
                                  nodeStackNewHA, stewardName, stewardsSeed,
                                  basedir=tdirWithClientPoolTxns)

    waitForSufficientRepliesForRequests(looper, stewardClient,
                                        requests=[req])

    # stop node for which HA will be changed
    subjectedNode.stop()
    looper.removeProdable(subjectedNode)

    # start node with new HA
    config_helper = PNodeConfigHelper(subjectedNode.name, tconf, chroot=tdir)
    restartedNode = TestNode(subjectedNode.name,
                             config_helper=config_helper,
                             config=tconf, ha=nodeStackNewHA,
                             cliha=clientStackNewHA)
    looper.add(restartedNode)
    txnPoolNodeSet[nodeIndex] = restartedNode
    looper.run(checkNodesConnected(txnPoolNodeSet, customTimeout=70))

    electionTimeout = waits.expectedPoolElectionTimeout(
        nodeCount=len(txnPoolNodeSet),
        numOfReelections=3)
    ensureElectionsDone(looper,
                        txnPoolNodeSet,
                        retryWait=1,
                        customTimeout=electionTimeout)

    # start client and check the node HA
    anotherClient, _ = genTestClient(tmpdir=tdirWithClientPoolTxns,
                                     usePoolLedger=True)
    looper.add(anotherClient)
    looper.run(eventually(anotherClient.ensureConnectedToNodes))
    stewardWallet = Wallet(stewardName)
    stewardWallet.addIdentifier(signer=DidSigner(seed=stewardsSeed))
    sendReqsToNodesAndVerifySuffReplies(
        looper, stewardWallet, stewardClient, 8)
    def create_client_wallet(self, seed=None):
        """ Create a plenum client wallet with an identifier. """
        if seed:
            seed = seed.encode()

        wallet = Wallet()
        wallet.addIdentifier(seed=seed)
        return wallet
Ejemplo n.º 7
0
def genTestClient(nodes=None,
                  nodeReg=None,
                  tmpdir=None,
                  testClientClass=TestClient,
                  identifier: Identifier = None,
                  verkey: str = None,
                  bootstrapKeys=True,
                  ha=None,
                  usePoolLedger=False,
                  name=None,
                  sighex=None) -> (TestClient, Wallet):
    if not usePoolLedger:
        nReg = nodeReg
        if nodeReg:
            assert isinstance(nodeReg, dict)
        elif hasattr(nodes, "nodeReg"):
            nReg = nodes.nodeReg.extractCliNodeReg()
        else:
            error("need access to nodeReg")
        for k, v in nReg.items():
            assert type(k) == str
            assert (type(v) == HA or type(v[0]) == HA)
    else:
        logger.debug("TestClient using pool ledger")
        nReg = None

    ha = genHa() if not ha else ha
    name = name or "testClient{}".format(ha.port)

    tc = testClientClass(name,
                         nodeReg=nReg,
                         ha=ha,
                         basedirpath=tmpdir,
                         sighex=sighex)

    if not usePoolLedger and nodes:
        for node in nodes:
            stack = node.clientstack
            # TODO: Remove this if condition once raet is removed
            if isinstance(stack, ZStack):
                initRemoteKeys(tc.name,
                               stack.name,
                               tmpdir,
                               stack.verhex,
                               override=True)

    w = None  # type: Wallet
    if bootstrapKeys and nodes:
        if not identifier or not verkey:
            # no identifier or verkey were provided, so creating a wallet
            w = Wallet("test")
            w.addIdentifier()
            identifier = w.defaultId
            verkey = w.getVerkey()
        bootstrapClientKeys(identifier, verkey, nodes)
    return tc, w
Ejemplo n.º 8
0
def changeNodeHa(looper, txnPoolNodeSet, tdirWithPoolTxns,
                 poolTxnData, poolTxnStewardNames, tconf, shouldBePrimary):

    # prepare new ha for node and client stack
    subjectedNode = None
    stewardName = None
    stewardsSeed = None

    for nodeIndex, n in enumerate(txnPoolNodeSet):
        if (shouldBePrimary and n.primaryReplicaNo == 0) or \
                (not shouldBePrimary and n.primaryReplicaNo != 0):
            subjectedNode = n
            stewardName = poolTxnStewardNames[nodeIndex]
            stewardsSeed = poolTxnData["seeds"][stewardName].encode()
            break

    nodeStackNewHA, clientStackNewHA = genHa(2)
    logger.debug("change HA for node: {} to {}".
                 format(subjectedNode.name, (nodeStackNewHA, clientStackNewHA)))

    nodeSeed = poolTxnData["seeds"][subjectedNode.name].encode()

    # change HA
    stewardClient, req = changeHA(looper, tconf, subjectedNode.name, nodeSeed,
                                  nodeStackNewHA, stewardName, stewardsSeed)
    f = getMaxFailures(len(stewardClient.nodeReg))
    looper.run(eventually(checkSufficientRepliesRecvd, stewardClient.inBox,
                          req.reqId, f, retryWait=1, timeout=20))

    # stop node for which HA will be changed
    subjectedNode.stop()
    looper.removeProdable(subjectedNode)

    # start node with new HA
    restartedNode = TestNode(subjectedNode.name, basedirpath=tdirWithPoolTxns,
                             config=tconf, ha=nodeStackNewHA,
                             cliha=clientStackNewHA)
    looper.add(restartedNode)

    txnPoolNodeSet[nodeIndex] = restartedNode
    looper.run(checkNodesConnected(txnPoolNodeSet, overrideTimeout=70))
    ensureElectionsDone(looper, txnPoolNodeSet, retryWait=1, timeout=10)

    # start client and check the node HA
    anotherClient, _ = genTestClient(tmpdir=tdirWithPoolTxns,
                                     usePoolLedger=True)
    looper.add(anotherClient)
    looper.run(eventually(anotherClient.ensureConnectedToNodes))
    stewardWallet = Wallet(stewardName)
    stewardWallet.addIdentifier(signer=SimpleSigner(seed=stewardsSeed))
    sendReqsToNodesAndVerifySuffReplies(looper, stewardWallet, stewardClient, 8)
    looper.run(eventually(checkIfGenesisPoolTxnFileUpdated, *txnPoolNodeSet,
                          stewardClient, anotherClient, retryWait=1,
                          timeout=10))
    looper.removeProdable(stewardClient)
Ejemplo n.º 9
0
def changeNodeHa(looper, txnPoolNodeSet, tdirWithPoolTxns,
                 poolTxnData, poolTxnStewardNames, tconf, shouldBePrimary):

    # prepare new ha for node and client stack
    subjectedNode = None
    stewardName = None
    stewardsSeed = None

    for nodeIndex, n in enumerate(txnPoolNodeSet):
        if (shouldBePrimary and n.primaryReplicaNo == 0) or \
                (not shouldBePrimary and n.primaryReplicaNo != 0):
            subjectedNode = n
            stewardName = poolTxnStewardNames[nodeIndex]
            stewardsSeed = poolTxnData["seeds"][stewardName].encode()
            break

    nodeStackNewHA, clientStackNewHA = genHa(2)
    logger.debug("change HA for node: {} to {}".
                 format(subjectedNode.name, (nodeStackNewHA, clientStackNewHA)))

    nodeSeed = poolTxnData["seeds"][subjectedNode.name].encode()

    # change HA
    stewardClient, req = changeHA(looper, tconf, subjectedNode.name, nodeSeed,
                                  nodeStackNewHA, stewardName, stewardsSeed)
    f = getMaxFailures(len(stewardClient.nodeReg))
    looper.run(eventually(checkSufficientRepliesRecvd, stewardClient.inBox,
                          req.reqId, f, retryWait=1, timeout=20))

    # stop node for which HA will be changed
    subjectedNode.stop()
    looper.removeProdable(subjectedNode)

    # start node with new HA
    restartedNode = TestNode(subjectedNode.name, basedirpath=tdirWithPoolTxns,
                             config=tconf, ha=nodeStackNewHA,
                             cliha=clientStackNewHA)
    looper.add(restartedNode)

    txnPoolNodeSet[nodeIndex] = restartedNode
    looper.run(checkNodesConnected(txnPoolNodeSet, overrideTimeout=70))
    ensureElectionsDone(looper, txnPoolNodeSet, retryWait=1, timeout=10)

    # start client and check the node HA
    anotherClient, _ = genTestClient(tmpdir=tdirWithPoolTxns,
                                     usePoolLedger=True)
    looper.add(anotherClient)
    looper.run(eventually(anotherClient.ensureConnectedToNodes))
    stewardWallet = Wallet(stewardName)
    stewardWallet.addIdentifier(signer=SimpleSigner(seed=stewardsSeed))
    sendReqsToNodesAndVerifySuffReplies(looper, stewardWallet, stewardClient, 8)
    looper.run(eventually(checkIfGenesisPoolTxnFileUpdated, *txnPoolNodeSet,
                          stewardClient, anotherClient, retryWait=1,
                          timeout=10))
Ejemplo n.º 10
0
def add_and_sign(signersNum=10):
    beforeSignTimeBasedId = getTimeBasedId()
    wallet = Wallet("shared wallet")
    idrs = []
    for i in range(signersNum):
        identifier = "signer_{}".format(i)
        idrs.append(identifier)
        wallet.addIdentifier(identifier)
    for idr in idrs:
        signed = wallet.signOp(op={}, identifier=idr)
        afterSignTimeBasedId = getTimeBasedId()
        assert beforeSignTimeBasedId < signed.reqId < afterSignTimeBasedId
Ejemplo n.º 11
0
def add_and_sign(signersNum = 10):
    beforeSignTimeBasedId = getTimeBasedId()
    wallet = Wallet("shared wallet")
    idrs = []
    for i in range(signersNum):
        identifier = "signer_{}".format(i)
        idrs.append(identifier)
        wallet.addIdentifier(identifier)
    for idr in idrs:
        signed = wallet.signOp(op={}, identifier=idr)
        afterSignTimeBasedId = getTimeBasedId()
        assert beforeSignTimeBasedId < signed.reqId < afterSignTimeBasedId
Ejemplo n.º 12
0
def build_wallets_from_data(name_seeds):
    wallets = []
    for name, seed in name_seeds:
        # wallet_handle = looper.loop.run_until_complete(
        #     _gen_wallet_handler(pool_name, name))
        # looper.loop.run_until_complete(
        #     create_and_store_my_did(wallet_handle,
        #                             json.dumps({'seed': seed})))
        # wallets.append(wallet_handle)
        w = Wallet(name)
        w.addIdentifier(seed=seed.encode())
        wallets.append(w)
    return wallets
Ejemplo n.º 13
0
def new_client_request(role, name, creatorWallet):
    wallet = Wallet(name)
    wallet.addIdentifier()
    idr = wallet.defaultId

    op = {
        TXN_TYPE: NYM,
        TARGET_NYM: idr,
        ALIAS: name,
        VERKEY: wallet.getVerkey(idr)
    }

    if role:
        op[ROLE] = role

    return creatorWallet.signOp(op), wallet
Ejemplo n.º 14
0
def test_wallet_multisig():
    wallet = Wallet()
    idr1, signer1 = wallet.addIdentifier()
    idr2, signer2 = wallet.addIdentifier()
    idr3, signer3 = wallet.addIdentifier()
    authnr = CoreAuthNr()
    for idr, signer in [(idr1, signer1), (idr2, signer2), (idr3, signer3)]:
        authnr.addIdr(idr, signer.verkey)

    def serz(req):
        return {k: v for k, v in req.as_dict.items()
                if k not in authnr.excluded_from_signing}

    op = randomOperation()
    req = wallet.sign_using_multi_sig(op=op, identifier=idr1)
    assert len(req.signatures) == 1
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures, 1)) == {idr1, }
    with pytest.raises(InsufficientSignatures):
        authnr.authenticate_multi(req_data, req.signatures, 2)

    req = wallet.sign_using_multi_sig(request=req, identifier=idr2)
    assert len(req.signatures) == 2
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures, 2)) == {idr1,
                                                                           idr2}
    with pytest.raises(InsufficientSignatures):
        authnr.authenticate_multi(req_data, req.signatures, 3)

    wallet.do_multi_sig_on_req(req, identifier=idr3)
    assert len(req.signatures) == 3
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures, 3)) == {idr1,
                                                                           idr2,
                                                                           idr3}
Ejemplo n.º 15
0
def sendAddNewClient(role, name, creatorClient, creatorWallet):
    wallet = Wallet(name)
    wallet.addIdentifier()
    idr = wallet.defaultId

    op = {
        TXN_TYPE: NYM,
        TARGET_NYM: idr,
        ALIAS: name,
        VERKEY: wallet.getVerkey(idr)
    }

    if role:
        op[ROLE] = role

    req = creatorWallet.signOp(op)
    creatorClient.submitReqs(req)
    return req, wallet
Ejemplo n.º 16
0
    def __init__(self,
                 name: str = None,
                 supportedDidMethods: DidMethods = None):
        PWallet.__init__(self, name, supportedDidMethods or DefaultDidMethods)
        TrustAnchoring.__init__(self)

        # Copy the class version to the instance for the version
        # to be serialized when the wallet is persisted
        setattr(self, getClassVersionKey(Wallet), Wallet.CLASS_VERSION)

        self._attributes = {}  # type: Dict[(str, Identifier,
        # Optional[Identifier]), Attribute]

        self.env = None  # Helps to know associated environment
        self._nodes = {}
        self._upgrades = {}
        self._pconfigs = {}

        self._connections = OrderedDict()  # type: Dict[str, Connection]
        # Note, ordered dict to make iteration deterministic

        self.knownIds = {}  # type: Dict[str, Identifier]

        # transactions not yet submitted
        self._pending = deque()  # type Tuple[Request, Tuple[str, Identifier,
        #  Optional[Identifier]]

        # pending transactions that have been prepared (probably submitted)
        self._prepared = {}  # type: Dict[(Identifier, int), Request]
        self.lastKnownSeqs = {}  # type: Dict[str, int]

        self.replyHandler = {
            ATTRIB: self._attribReply,
            GET_ATTR: self._getAttrReply,
            NYM: self._nymReply,
            GET_NYM: self._getNymReply,
            GET_TXNS: self._getTxnsReply,
            NODE: self._nodeReply,
            POOL_UPGRADE: self._poolUpgradeReply,
            POOL_CONFIG: self._poolConfigReply
        }
Ejemplo n.º 17
0
def setupClients(count: int,
                 looper: Looper,
                 nodes: Sequence[TestNode] = None,
                 nodeReg=None,
                 tmpdir=None):
    wallets = {}
    clients = {}
    for i in range(count):
        name = "test-wallet-{}".format(i)
        wallet = Wallet(name)
        idr, _ = wallet.addIdentifier()
        verkey = wallet.getVerkey(idr)
        client, _ = setupClient(looper,
                                nodes,
                                nodeReg,
                                tmpdir,
                                identifier=idr,
                                verkey=verkey)
        clients[client.name] = client
        wallets[client.name] = wallet
    return clients, wallets
Ejemplo n.º 18
0
def addNewClient(role, looper, creatorClient: Client, creatorWallet: Wallet,
                 name: str):
    wallet = Wallet(name)
    wallet.addIdentifier()
    idr = wallet.defaultId

    op = {
        TXN_TYPE: NYM,
        ROLE: role,
        TARGET_NYM: idr,
        ALIAS: name,
        VERKEY: wallet.getVerkey(idr)
    }

    req = creatorWallet.signOp(op)
    creatorClient.submitReqs(req)

    nodeCount = len(creatorClient.nodeReg)
    looper.run(
        eventually(checkSufficientRepliesRecvd,
                   creatorClient.inBox,
                   req.reqId,
                   1,
                   retryWait=1,
                   timeout=3 * nodeCount))
    return wallet
Ejemplo n.º 19
0
def addNewClient(role, looper, creatorClient: Client, creatorWallet: Wallet,
                 name: str):
    wallet = Wallet(name)
    wallet.addIdentifier()
    idr = wallet.defaultId

    op = {
        TXN_TYPE: NYM,
        ROLE: role,
        TARGET_NYM: idr,
        ALIAS: name,
        VERKEY: wallet.getVerkey(idr)
    }

    req = creatorWallet.signOp(op)
    creatorClient.submitReqs(req)

    nodeCount = len(creatorClient.nodeReg)
    looper.run(eventually(checkSufficientRepliesRecvd, creatorClient.inBox,
                          req.reqId, 1,
                          retryWait=1, timeout=3 * nodeCount))
    return wallet
Ejemplo n.º 20
0
    def __init__(self,
                 name: str=None,
                 supportedDidMethods: DidMethods=None):
        PWallet.__init__(self,
                         name,
                         supportedDidMethods or DefaultDidMethods)
        TrustAnchoring.__init__(self)

        self._attributes = {}  # type: Dict[(str, Identifier,
        # Optional[Identifier]), Attribute]

        self.env = None     # Helps to know associated environment
        self._nodes = {}
        self._upgrades = {}
        self._pconfigs = {}

        self._connections = OrderedDict()  # type: Dict[str, Connection]
        # Note, ordered dict to make iteration deterministic

        self.knownIds = {}  # type: Dict[str, Identifier]

        # transactions not yet submitted
        self._pending = deque()  # type Tuple[Request, Tuple[str, Identifier,
        #  Optional[Identifier]]

        # pending transactions that have been prepared (probably submitted)
        self._prepared = {}  # type: Dict[(Identifier, int), Request]
        self.lastKnownSeqs = {}  # type: Dict[str, int]

        self.replyHandler = {
            ATTRIB: self._attribReply,
            GET_ATTR: self._getAttrReply,
            NYM: self._nymReply,
            GET_NYM: self._getNymReply,
            GET_TXNS: self._getTxnsReply,
            NODE: self._nodeReply,
            POOL_UPGRADE: self._poolUpgradeReply,
            POOL_CONFIG: self._poolConfigReply
        }
Ejemplo n.º 21
0
def test_wallet_multisig():
    wallet = Wallet()
    idr1, signer1 = wallet.addIdentifier()
    idr2, signer2 = wallet.addIdentifier()
    idr3, signer3 = wallet.addIdentifier()
    authnr = CoreAuthNr()
    for idr, signer in [(idr1, signer1), (idr2, signer2), (idr3, signer3)]:
        authnr.addIdr(idr, signer.verkey)

    def serz(req):
        return {
            k: v
            for k, v in req.as_dict.items()
            if k not in authnr.excluded_from_signing
        }

    op = randomOperation()
    request = Request(reqId=Request.gen_req_id(),
                      operation=op,
                      protocolVersion=CURRENT_PROTOCOL_VERSION,
                      identifier=idr1)
    req = wallet.sign_using_multi_sig(request=request, identifier=idr1)
    assert len(req.signatures) == 1
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures, 1)) == {
        idr1,
    }
    with pytest.raises(InsufficientSignatures):
        authnr.authenticate_multi(req_data, req.signatures, 2)

    req = wallet.sign_using_multi_sig(request=req, identifier=idr2)
    assert len(req.signatures) == 2
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures,
                                         2)) == {idr1, idr2}
    with pytest.raises(InsufficientSignatures):
        authnr.authenticate_multi(req_data, req.signatures, 3)

    wallet.do_multi_sig_on_req(req, identifier=idr3)
    assert len(req.signatures) == 3
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures,
                                         3)) == {idr1, idr2, idr3}
def test_wallet():
    return Wallet("TestWallet")
Ejemplo n.º 23
0
 """
 The client has a slightly different node registry than the nodes. The
 Nodes have two network interfaces, one for other nodes, and one for
 client. This registry points to the nodes' client-facing interfaces.
 """
 cliNodeReg = {
     'AlphaC': ('127.0.0.1', 7561),
     'BetaC': ('127.0.0.1', 7563),
     'GammaC': ('127.0.0.1', 7565),
     'DeltaC': ('127.0.0.1', 7567)
 }
 """
 Create a wallet to the keys that the client will use to have a
 secure communication with the nodes.
 """
 wallet = Wallet("my_wallet")
 """
 Now the wallet needs to have one keypair, so lets add it.
 """
 wallet.addIdentifier()
 """
 A bi-directional connection is made from the client. This is the ip
 address and port for the client's interfact to the nodes.
 """
 client_addr = ("127.0.0.1", 8000)
 """
 Create a client.
 """
 clientName = "my_client_id"
 client = Client(name=clientName,
                 ha=client_addr,
Ejemplo n.º 24
0
def sendRandomRequests(wallet: Wallet, client: Client, count: int):
    logger.debug('{} random requests will be sent'.format(count))
    reqs = [wallet.signOp(randomOperation()) for _ in range(count)]
    return client.submitReqs(*reqs)
Ejemplo n.º 25
0
def sendRandomRequests(wallet: Wallet, client: Client, count: int):
    reqs = [wallet.signOp(randomOperation()) for _ in range(count)]
    return client.submitReqs(*reqs)
Ejemplo n.º 26
0
        """
        The client has a slightly different node registry than the nodes. The
        Nodes have two network interfaces, one for other nodes, and one for
        client. This registry points to the nodes' client-facing interfaces.
        """
        cliNodeReg = {
            'AlphaC': ('127.0.0.1', 7561),
            'BetaC': ('127.0.0.1', 7563),
            'GammaC': ('127.0.0.1', 7565),
            'DeltaC': ('127.0.0.1', 7567)}

        """
        Create a wallet to the keys that the client will use to have a
        secure communication with the nodes.
        """
        wallet = Wallet("my_wallet")

        """
        Now the wallet needs to have one keypair, so lets add it.
        """
        wallet.addIdentifier()

        """
        A bi-directional connection is made from the client. This is the ip
        address and port for the client's interfact to the nodes.
        """
        client_addr = ("127.0.0.1", 8000)

        """
        Create a client.
        """
Ejemplo n.º 27
0
 def create_client_wallet(self, seed):
     """ Create a plenum client wallet from a seed. """
     wallet = Wallet()
     wallet.addIdentifier(seed=seed.encode())
     return wallet