Example #1
0
def test_update_nym(nym_handler):
    identifier = "identifier"
    txn1 = create_nym_txn(identifier, STEWARD)
    txn2 = create_nym_txn(identifier, "")

    update_nym(nym_handler.state, identifier, STEWARD)
    nym_data = get_nym_details(nym_handler.state, identifier)
    assert get_payload_data(txn1)[ROLE] == nym_data[ROLE]

    update_nym(nym_handler.state, identifier, "")
    nym_data = get_nym_details(nym_handler.state, identifier)
    assert get_payload_data(txn2)[ROLE] == nym_data[ROLE]
    def update_state(self, txn, prev_result, request, is_committed=False):
        self._validate_txn_type(txn)
        nym = get_payload_data(txn).get(TARGET_NYM)
        existing_data = get_nym_details(self.state,
                                        nym,
                                        is_committed=is_committed)
        txn_data = get_payload_data(txn)
        new_data = {}
        if not existing_data:
            # New nym being added to state, set the TrustAnchor
            new_data[f.IDENTIFIER.nm] = get_from(txn)
            # New nym being added to state, set the role and verkey to None, this makes
            # the state data always have a value for `role` and `verkey` since we allow
            # clients to omit specifying `role` and `verkey` in the request consider a
            # default value of None
            new_data[ROLE] = None
            new_data[VERKEY] = None

        new_data[ROLE] = txn_data.get(ROLE, None)
        if VERKEY in txn_data:
            new_data[VERKEY] = txn_data[VERKEY]
        new_data[F.seqNo.name] = get_seq_no(txn)
        new_data[TXN_TIME] = get_txn_time(txn)
        self.__update_steward_count(new_data, existing_data)
        existing_data.update(new_data)
        val = self.state_serializer.serialize(existing_data)
        key = self.gen_state_key(txn)
        self.state.set(key, val)
        return existing_data
def test_create_did_without_endorser_payment(looper, nodeSetWithIntegratedTokenPlugin, nym_txn_data, sdk_pool_handle,
                                             fees_set, address_main, mint_tokens, changed_auth_rule,
                                             sdk_wallet_trustee, helpers):
    sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee)

    wh, alias, sender_did, sender_verkey = nym_txn_data
    req = looper.loop.run_until_complete(
        build_nym_request(sender_did, sender_did, sender_verkey, alias, NEW_ROLE))

    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    utxos = [{"source": utxo_from_addr_and_seq_no(address_main, init_seq_no),
              AMOUNT: amount}]
    req = Request(**json.loads(req))
    req = add_fees_request_with_address(
        helpers,
        fees_set,
        req,
        address_main,
        utxos=utxos
    )

    rep = helpers.sdk.send_and_check_request_objects([req], wallet=(wh, sender_did))

    details = get_nym_details(nodeSetWithIntegratedTokenPlugin[0].states[1], sender_did, is_committed=True)
    assert details[ROLE] == NEW_ROLE
    assert details[VERKEY] == sender_verkey
Example #4
0
def test_create_did_without_endorser_sig_count_2_one_on_ledger(
        looper, txnPoolNodeSet, nym_txn_data, sdk_pool_handle,
        sdk_wallet_trustee):
    change_auth_rule(looper,
                     sdk_pool_handle,
                     sdk_wallet_trustee,
                     constraint=AuthConstraint(role='*',
                                               sig_count=2,
                                               off_ledger_signature=True))

    wh, alias, sender_did, sender_verkey = nym_txn_data
    nym_request = looper.loop.run_until_complete(
        build_nym_request(sender_did, sender_did, sender_verkey, alias,
                          NEW_ROLE))

    nym_request = sdk_multisign_request_object(looper, (wh, sender_did),
                                               nym_request)
    nym_request = sdk_multisign_request_object(looper, sdk_wallet_trustee,
                                               nym_request)

    request_couple = sdk_send_signed_requests(sdk_pool_handle,
                                              [nym_request])[0]
    sdk_get_and_check_replies(looper, [request_couple])

    details = get_nym_details(txnPoolNodeSet[0].states[1],
                              sender_did,
                              is_committed=True)
    assert details[ROLE] == NEW_ROLE
    assert details[VERKEY] == sender_verkey
Example #5
0
def test_update_state(nym_handler):
    txns = []
    for i in range(5):
        update_nym(nym_handler.state, "identifier{}".format(i), STEWARD)

    for txn in txns:
        nym_data = get_nym_details(nym_handler.state, get_reply_nym(txn))
        assert nym_data[ROLE] == STEWARD
def test_create_did_without_endorser(looper, txnPoolNodeSet, nym_txn_data, sdk_pool_handle, patch_nym_validation):
    wh, alias, sender_did, sender_verkey = nym_txn_data
    nym_request = looper.loop.run_until_complete(
        build_nym_request(sender_did, sender_did, sender_verkey, alias, NEW_ROLE))

    request_couple = sdk_sign_and_send_prepared_request(looper, (wh, sender_did), sdk_pool_handle, nym_request)
    sdk_get_and_check_replies(looper, [request_couple])

    details = get_nym_details(txnPoolNodeSet[0].states[1], sender_did, is_committed=True)
    assert details[ROLE] == NEW_ROLE
    assert details[VERKEY] == sender_verkey
Example #7
0
 def getVerkey(self, identifier):
     nym = self.clients.get(identifier)
     if not nym:
         # Querying uncommitted identities since a batch might contain
         # both identity creation request and a request by that newly
         # created identity, also its possible to have multiple uncommitted
         # batches in progress and identity creation request might
         # still be in an earlier uncommited batch
         nym = get_nym_details(self.state, identifier, is_committed=False)
         if not nym:
             raise UnknownIdentifier(identifier)
     return nym.get(VERKEY)
Example #8
0
 def getVerkey(self, ident, request):
     nym = self.clients.get(ident)
     if not nym:
         # Querying uncommitted identities since a batch might contain
         # both identity creation request and a request by that newly
         # created identity, also its possible to have multiple uncommitted
         # batches in progress and identity creation request might
         # still be in an earlier uncommited batch
         nym = get_nym_details(self.state, ident, is_committed=False)
         if not nym:
             # If DID wasn't found in ledger and state, it might be
             # non-ledger request, so we need to look for verkey in request
             verkey = self.get_verkey_specific(request)
             return verkey
     return nym.get(VERKEY)
def test_endorser_required_when_multi_sig_with_off_ledger_signature(
        looper, txnPoolNodeSet, sdk_wallet_client, sdk_pool_handle,
        sdk_wallet_trustee, sdk_wallet_endorser):
    change_new_did_auth_rule(looper,
                             sdk_pool_handle,
                             sdk_wallet_trustee,
                             constraint=AuthConstraint(
                                 role='*',
                                 sig_count=2,
                                 off_ledger_signature=True))

    new_did, verkey = \
        looper.loop.run_until_complete(
            create_and_store_my_did(sdk_wallet_client[0], json.dumps({'seed': randomString(32)})))
    sdk_wallet_new_client = (sdk_wallet_client[0], new_did)
    nym_request = looper.loop.run_until_complete(
        build_nym_request(new_did, new_did, verkey, None, IDENTITY_OWNER))

    # can not send without Endorser
    with pytest.raises(
            RequestRejectedException,
            match=
            "'Endorser' field must be explicitly set for the endorsed transaction"
    ):
        signed_req = sdk_multisign_request_object(looper,
                                                  sdk_wallet_new_client,
                                                  nym_request)
        signed_req = sdk_multisign_request_object(looper, sdk_wallet_endorser,
                                                  signed_req)
        request_couple = sdk_send_signed_requests(sdk_pool_handle,
                                                  [signed_req])[0]
        sdk_get_and_check_replies(looper, [request_couple])

    # can send with Endorser
    sdk_submit_and_check_by_endorser(looper,
                                     sdk_pool_handle,
                                     sdk_wallet_author=sdk_wallet_new_client,
                                     sdk_wallet_endorser=sdk_wallet_endorser,
                                     request_json=nym_request)
    details = get_nym_details(txnPoolNodeSet[0].states[1],
                              new_did,
                              is_committed=True)
    assert details[ROLE] == IDENTITY_OWNER
    assert details[VERKEY] == verkey
Example #10
0
    def update_state(self, txn, prev_result, is_committed=False):
        self._validate_txn_type(txn)
        nym = get_payload_data(txn).get(TARGET_NYM)
        existing_data = get_nym_details(self.state, nym,
                                        is_committed=is_committed)
        txn_data = get_payload_data(txn)
        new_data = {}
        if not existing_data:
            new_data[f.IDENTIFIER.nm] = get_from(txn)
            new_data[ROLE] = None
            new_data[VERKEY] = None

        if ROLE in txn_data:
            new_data[ROLE] = txn_data[ROLE]
        if VERKEY in txn_data:
            new_data[VERKEY] = txn_data[VERKEY]
        new_data[F.seqNo.name] = get_seq_no(txn)
        new_data[TXN_TIME] = get_txn_time(txn)
        existing_data.update(new_data)
        val = self.state_serializer.serialize(existing_data)
        key = nym_to_state_key(nym)
        self.state.set(key, val)
        return existing_data