async def send_request(self, connection: Connection, payment_handle: int): """ Approves the credential offer and submits a credential request. The result will be a credential stored in the prover's wallet. :param connection: connection to submit request from :param payment_handle: currently unused :return: Example: connection = await Connection.create(source_id) await connection.connect(phone_number) credential = await Credential.create(source_id, offer) await credential.send_request(connection, 0) """ if not hasattr(Credential.send_request, "cb"): self.logger.debug("vcx_credential_send_request: Creating callback") Credential.send_request.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32)) c_credential_handle = c_uint32(self.handle) c_connection_handle = c_uint32(connection.handle) c_payment = c_uint32(payment_handle) await do_call('vcx_credential_send_request', c_credential_handle, c_connection_handle, c_payment, Credential.send_request.cb)
async def connect(self, options: str) -> str: """ Connect securely and privately to the endpoint represented by the object. :param options: detailed connection options Example options: {"connection_type":"SMS","phone":"5555555555","use_public_did":true} or: {"connection_type":"QR"} Example code: connection = await Connection.create('Sally') invite_details = await connection.connect('{"connection_type":"QR"}') :return: the invite details sent via SMS or ready to be sent via some other mechanism (QR for example) """ if not hasattr(Connection.connect, "cb"): self.logger.debug("vcx_connection_connect: Creating callback") Connection.connect.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_connection_handle = c_uint32(self.handle) c_connection_data = c_char_p(options.encode('utf-8')) invite_details = await do_call('vcx_connection_connect', c_connection_handle, c_connection_data, Connection.connect.cb) return invite_details
async def invite_details(self, abbreviated: bool) -> dict: """ Get the invite details that were sent or can be sent to the endpoint. :param abbreviated: abbreviate invite details or not Example: phone_number = '8019119191' connection = await Connection.create('foobar123') invite_details = await connection.connect(phone_number) inivte_details_again = await connection.invite_details() :return: JSON of invite_details sent to connection """ if not hasattr(Connection.invite_details, "cb"): self.logger.debug("vcx_connection_invite_details: Creating callback") Connection.invite_details.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_connection_handle = c_uint32(self.handle) c_abbreviated = c_bool(abbreviated) details = await do_call('vcx_connection_invite_details', c_connection_handle, c_abbreviated, Connection.invite_details.cb) return json.loads(details.decode())
async def verify_signature(self, msg: bytes, signature: bytes) -> bool: """ Verification the signature of a msg :param msg: :param signature: :return: bool """ if not hasattr(Connection.verify_signature, "cb"): self.logger.debug("vcx_connection_verify_signature: Creating callback") Connection.verify_signature.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_bool)) c_connection_handle = c_uint32(self.handle) c_msg_len = c_uint32(len(msg)) c_signature_len = c_uint32(len(signature)) result = await do_call('vcx_connection_verify_signature', c_connection_handle, msg, c_msg_len, signature, c_signature_len, Connection.verify_signature.cb) self.logger.debug("vcx_connection_verify_signature completed") return result
async def create_with_msgid(source_id: str, connection: Connection, msg_id: str): """ Create a credential based off of a known message id for a given connection. :param source_id: user defined id of object. :param connection: connection handle of connection to receive offer from :param msg_id: message id :return: A created credential Example: credential = await Credential.create_with_msgid(source_id, connection, msg_id) assert await credential.get_state() == State.RequestReceived """ credential = Credential(source_id,) c_source_id = c_char_p(source_id.encode('utf-8')) c_msg_id = c_char_p(json.dumps(msg_id).encode('utf-8')) c_connection_handle = c_uint32(connection.handle) if not hasattr(Credential.create_with_msgid, "cb"): Credential.create_with_msgid.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p)) credential.handle, cred_offer = await do_call('vcx_credential_create_with_msgid', c_source_id, c_connection_handle, c_msg_id, Credential.create_with_msgid.cb) credential.cred_offer = json.loads(cred_offer.decode()) return credential
async def vcx_agent_provision(config: str) -> None: """ Provision an agent in the agency, populate configuration and wallet for this agent. Example: import json enterprise_config = { 'agency_url': 'http://localhost:8080', 'agency_did': 'VsKV7grR1BUE29mG2Fm2kX', 'agency_verkey': "Hezce2UWMZ3wUhVkh2LfKSs8nDzWwzs2Win7EzNN3YaR", 'wallet_name': 'LIBVCX_SDK_WALLET', 'agent_seed': '00000000000000000000000001234561', 'enterprise_seed': '000000000000000000000000Trustee1', 'wallet_key': '1234' } vcx_config = await vcx_agent_provision(json.dumps(enterprise_config)) :param config: JSON configuration :return: Configuration for vcx_init call. """ logger = logging.getLogger(__name__) if not hasattr(vcx_agent_provision, "cb"): logger.debug("vcx_agent_provision: Creating callback") vcx_agent_provision.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_config = c_char_p(config.encode('utf-8')) result = await do_call('vcx_agent_provision_async', c_config, vcx_agent_provision.cb) logger.debug("vcx_agent_provision completed") return result.decode()
async def send_tokens(payment_handle: int, tokens: int, address: str) -> str: """ Sends tokens to an address payment_handle is always 0 :param payment_handle: Integer :param tokens: Integer :param address: String Example: payment_handle = 0 amount = 1000 address = await Wallet.create_payment_address('00000000000000000000000001234567') await Wallet.send_tokens(payment_handle, amount, address) :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.send_tokens, "cb"): logger.debug("vcx_wallet_send_tokens: Creating callback") Wallet.send_tokens.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_payment_handle = c_uint32(payment_handle) c_tokens = c_char_p(str(tokens).encode('utf-8')) c_address = c_char_p(address.encode('utf-8')) result = await do_call('vcx_wallet_send_tokens', c_payment_handle, c_tokens, c_address, Wallet.send_tokens.cb) logger.debug("vcx_wallet_send_tokens completed") return result
async def update_record_value(type_: str, id: str, value: str): """ Updates the value of a record :param type_: String :param id: String :param value: String Example: await Wallet.add_record({ 'id': 'RecordId', 'tags': '{}', 'type_': 'TestType', 'value': 'this will be overwritten' }) await Wallet.update_record('TestType', 'RecordId', 'new value') :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.update_record_value, "cb"): logger.debug("vcx_wallet_update_record_value: Creating callback") Wallet.update_record_value.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32)) c_type_ = c_char_p(type_.encode('utf-8')) c_id = c_char_p(id.encode('utf-8')) c_value = c_char_p(value.encode('utf-8')) result = await do_call('vcx_wallet_update_record_value', c_type_, c_id, c_value, Wallet.update_record_value.cb) logger.debug("vcx_wallet_update_record_value completed") return result
async def create_payment_address(seed: str = None) -> str: """ Creates a payment address inside the wallet. :param seed: String Example: address = await Wallet.create_payment_address('00000000000000000000000001234567') :return: String """ logger = logging.getLogger(__name__) if not hasattr(Wallet.create_payment_address, "cb"): logger.debug("vcx_wallet_create_payment_address: Creating callback") Wallet.create_payment_address.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) if seed: c_seed = c_char_p(seed.encode('utf-8')) else: c_seed = None result = await do_call('vcx_wallet_create_payment_address', c_seed, Wallet.create_payment_address.cb) logger.debug("vcx_wallet_create_payment_address completed") return result
async def open_search(type_: str, query: dict, options: dict): """ Opens a search handle within the storage wallet. :param type_: String :param query: dictionary :param options: dictionary Example: query_json = {"tagName1": "str1"} type_ = 'TestType' search_handle = await Wallet.open_search(type_, query_json, None) :return: int """ logger = logging.getLogger(__name__) if not hasattr(Wallet.open_search, "cb"): logger.debug("vcx_wallet_open_search: Creating callback") Wallet.open_search.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_uint32)) c_type_ = c_char_p(type_.encode('utf-8')) c_query = c_char_p(json.dumps(query).encode('utf-8')) c_options = c_char_p(json.dumps(options).encode('utf-8')) if options else None data = await do_call('vcx_wallet_open_search', c_type_, c_query, c_options, Wallet.open_search.cb) logger.debug("vcx_wallet_open_search completed") return data
async def update_record_tags(type_: str, id: str, tags: str): """ Updates the tags on a record, removing any previous value. :param type_: String :param id: String :param tags: String Example: import json await Wallet.add_record({ 'id': 'RecordId', 'tags': json.dumps({'foobar':'this value will get overwritten'}), 'type_': 'TestType', 'value': 'RecordValue await Wallet.update_record_tags('TestType', 'RecordId', json.dumps({'foobar':'new value'})) :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.update_record_tags, "cb"): logger.debug("vcx_wallet_update_record_tags: Creating callback") Wallet.update_record_tags.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32)) c_type_ = c_char_p(type_.encode('utf-8')) c_id = c_char_p(id.encode('utf-8')) c_tags = c_char_p(tags.encode('utf-8')) result = await do_call('vcx_wallet_update_record_tags', c_type_, c_id, c_tags, Wallet.update_record_tags.cb) logger.debug("vcx_wallet_update_record_tags completed") return result
async def add_record_tags(type_: str, id: str, tags: str): """ Adds tags to a record already stored in the storage wallet. :param type_: String :param id: String :param tags: String Example: import json await Wallet.add_record({ 'id': 'RecordId', 'tags': '{}', 'type_': 'TestType', 'value': 'RecordValue await Wallet.add_record_tags('TestType', 'RecordId', json.dumps({'addthistag':'valuetag1'})) :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.add_record_tags, "cb"): logger.debug("vcx_wallet_add_record_tags: Creating callback") Wallet.add_record_tags.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32)) c_type_ = c_char_p(type_.encode('utf-8')) c_id = c_char_p(id.encode('utf-8')) c_tags = c_char_p(tags.encode('utf-8')) result = await do_call('vcx_wallet_add_record_tags', c_type_, c_id, c_tags, Wallet.add_record_tags.cb) logger.debug("vcx_wallet_add_record_tags completed") return result
async def search_next_records(handle: int, count: int): """ Searches for next n record from an open search handle :param handle: int :param count: int Example: query_json = {"tagName1": "str1"} type_ = 'TestType' search_handle = await Wallet.open_search(type_, query_json, None) results = await Wallet.search_next_records(search_handle, 5) :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.search_next_records, "cb"): logger.debug("vcx_wallet_search_next_records: Creating callback") Wallet.search_next_records.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_handle = c_uint32(handle) c_count = c_uint32(count) data = await do_call('vcx_wallet_search_next_records', c_handle, c_count, Wallet.search_next_records.cb) logger.debug("vcx_wallet_search_next_records completed") return data.decode()
async def sign_with_address(address: str, msg: bytes) -> bytes: """ Sign data using payment address :param payment_address :param msg: :return: signature """ logger = logging.getLogger(__name__) def transform_cb(arr_ptr: POINTER(c_uint8), arr_len: c_uint32): return bytes(arr_ptr[:arr_len]), if not hasattr(Wallet.sign_with_address, "cb"): logger.debug("vcx_wallet_sign_with_address: Creating callback") Wallet.sign_with_address.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, POINTER(c_uint8), c_uint32), transform_cb) c_address = c_char_p(address.encode('utf-8')) c_msg_len = c_uint32(len(msg)) result = await do_call('vcx_wallet_sign_with_address', c_address, msg, c_msg_len, Wallet.sign_with_address.cb) logger.debug("vcx_wallet_sign_with_address completed") return result
async def send_message(self, msg: str, msg_type: str, msg_title: str, ref_msg_id: str = None) -> str: """ Send a generic message to the connection :param msg: :param msg_type: :param msg_title: :param ref_msg_id: if responding to a message, provide msg id :return: """ if not hasattr(Connection.send_message, "cb"): self.logger.debug("vcx_connection_send_message: Creating callback") Connection.send_message.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) send_msg_options = { "msg_type": msg_type, "msg_title": msg_title, "ref_msg_id": ref_msg_id } c_connection_handle = c_uint32(self.handle) c_msg = c_char_p(msg.encode('utf-8')) c_send_msg_options = c_char_p(json.dumps(send_msg_options).encode('utf-8')) result = await do_call('vcx_connection_send_message', c_connection_handle, c_msg, c_send_msg_options, Connection.send_message.cb) self.logger.debug("vcx_connection_send_message completed") return result
async def search_next_records(handle: int, count: int): """ Searches for next n record from an open search handle :param handle: int :param count: int Example: query_json = {"tagName1": "str1"} type_ = 'TestType' search_handle = await Wallet.open_search(type_, query_json, None) results = await Wallet.search_next_records(search_handle, 5) :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.search_next_records, "cb"): logger.debug("vcx_wallet_search_next_records: Creating callback") Wallet.search_next_records.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_handle = c_uint32(handle) c_count = c_uint32(count) data = await do_call('vcx_wallet_search_next_records', c_handle, c_count, Wallet.search_next_records.cb) logger.debug("vcx_wallet_search_next_records completed") return data.decode()
async def create_with_msgid(source_id: str, connection: Connection, msg_id: str): """ :param source_id: :param connection: :param msg_id: Example: msg_id = '1' phone_number = '8019119191' connection = await Connection.create(source_id) await connection.connect(phone_number) disclosed_proof = await DisclosedProof.create_with_msgid(source_id, connection, msg_id) :return: DisclosedProof """ proof = DisclosedProof(source_id) c_source_id = c_char_p(source_id.encode('utf-8')) c_msg_id = c_char_p(json.dumps(msg_id).encode('utf-8')) c_connection_handle = c_uint32(connection.handle) if not hasattr(DisclosedProof.create_with_msgid, "cb"): DisclosedProof.create_with_msgid.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p)) proof.handle, proof_req = await do_call('vcx_disclosed_proof_create_with_msgid', c_source_id, c_connection_handle, c_msg_id, DisclosedProof.create_with_msgid.cb) proof.proof_request = json.loads(proof_req.decode()) return proof
async def lookup(source_id: str, schema_id: str): """ Create a new schema object from an existing ledger schema :param source_id: Institution's personal identification for the schema :param schema_id: Ledger schema ID for lookup :return: schema object """ try: schema = Schema(source_id, '', '', []) if not hasattr(Schema.lookup, "cb"): schema.logger.debug( "vcx_schema_get_attributes: Creating callback") Schema.lookup.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p)) c_source_id = c_char_p(source_id.encode('utf-8')) c_schema_id = c_char_p(schema_id.encode('utf-8')) handle, data = await do_call('vcx_schema_get_attributes', c_source_id, c_schema_id, Schema.lookup.cb) schema.logger.debug("created schema object") schema_result = json.loads(data.decode()) schema.attrs = schema_result['data'] schema.name = schema_result['name'] schema.version = schema_result['version'] schema.handle = handle return schema except KeyError: raise VcxError(ErrorCode.InvalidSchema)
async def open_search(type_: str, query: dict, options: dict): """ Opens a search handle within the storage wallet. :param type_: String :param query: dictionary :param options: dictionary Example: query_json = {"tagName1": "str1"} type_ = 'TestType' search_handle = await Wallet.open_search(type_, query_json, None) :return: int """ logger = logging.getLogger(__name__) if not hasattr(Wallet.open_search, "cb"): logger.debug("vcx_wallet_open_search: Creating callback") Wallet.open_search.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_uint32)) c_type_ = c_char_p(type_.encode('utf-8')) c_query = c_char_p(json.dumps(query).encode('utf-8')) c_options = c_char_p( json.dumps(options).encode('utf-8')) if options else None data = await do_call('vcx_wallet_open_search', c_type_, c_query, c_options, Wallet.open_search.cb) logger.debug("vcx_wallet_open_search completed") return data
async def update_record_value(type_: str, id: str, value: str): """ Updates the value of a record :param type_: String :param id: String :param value: String Example: await Wallet.add_record({ 'id': 'RecordId', 'tags': '{}', 'type_': 'TestType', 'value': 'this will be overwritten' }) await Wallet.update_record('TestType', 'RecordId', 'new value') :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.update_record_value, "cb"): logger.debug("vcx_wallet_update_record_value: Creating callback") Wallet.update_record_value.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32)) c_type_ = c_char_p(type_.encode('utf-8')) c_id = c_char_p(id.encode('utf-8')) c_value = c_char_p(value.encode('utf-8')) result = await do_call('vcx_wallet_update_record_value', c_type_, c_id, c_value, Wallet.update_record_value.cb) logger.debug("vcx_wallet_update_record_value completed") return result
async def delete_record(type_: str, id: str): """ Delete a record from the storage wallet. :param type_: :param id: Example: await Wallet.add_record({ 'id': 'RecordId', 'tags': json.dumps({ 'tag1': 'unencrypted value1', '~encryptedTag', 'this value is encrypted, 'integerTag', 1 }), 'type_': 'TestType', 'value': 'RecordValue' }) await Wallet.delete_record('TestType', 'RecordId') :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.delete_record, "cb"): logger.debug("vcx_wallet_delete_record: Creating callback") Wallet.delete_record.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32)) c_type_ = c_char_p(type_.encode('utf-8')) c_id = c_char_p(id.encode('utf-8')) result = await do_call('vcx_wallet_delete_record', c_type_, c_id, Wallet.delete_record.cb) logger.debug("vcx_wallet_delete_record completed") return result
async def verify_with_address(address: str, msg: bytes, signature: bytes) -> bool: """ Verify the signature using payment address :param payment_address :param msg: :param signature: :return: bool """ logger = logging.getLogger(__name__) if not hasattr(Wallet.verify_with_address, "cb"): logger.debug("vcx_wallet_verify_with_address: Creating callback") Wallet.verify_with_address.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_bool)) c_address = c_char_p(address.encode('utf-8')) c_msg_len = c_uint32(len(msg)) c_signature_len = c_uint32(len(signature)) result = await do_call('vcx_wallet_verify_with_address', c_address, msg, c_msg_len, signature, c_signature_len, Wallet.verify_with_address.cb) logger.debug("vcx_wallet_sign_verify_address completed") return result
async def send_offer(self, connection: Connection): """ Sends an offer to a prover. Once accepted, a request will be recieved. :param connection: vcx.api.connection.Connection :return: None Example: source_id = '1' cred_def_id = 'cred_def_id1' attrs = {'key': 'value', 'key2': 'value2', 'key3': 'value3'} name = 'Credential Name' issuer_did = '8XFh8yBzrpJQmNyZzgoTqB' phone_number = '8019119191' price = 1 issuer_credential = await IssuerCredential.create(source_id, attrs, cred_def_id, name, price) connection = await Connection.create(source_id) issuer_credential.send_offer(connection) """ if not hasattr(IssuerCredential.send_offer, "cb"): self.logger.debug( "vcx_issuer_send_credential_offer: Creating callback") IssuerCredential.send_offer.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32)) c_credential_handle = c_uint32(self.handle) c_connection_handle = c_uint32(connection.handle) await do_call('vcx_issuer_send_credential_offer', c_credential_handle, c_connection_handle, IssuerCredential.send_offer.cb)
async def get_payment_txn(self): """ Retrieve the txn associated with paying for the schema Example: source_id = 'foobar123' name = 'Address Schema' version = '1.0' attrs = ['address', 'city', 'state'] payment_handle = 0 schema1 = await Schema.create(source_id, name, version, attrs, payment_handle) txn = await schema1.get_payment_txn() :return: JSON object with input address and output UTXOs { "amount":25, "inputs":[ "pay:null:1_3FvPC7dzFbQKzfG" ], "outputs":[ {"recipient":"pay:null:FrSVC3IrirScyRh","amount":5,"extra":null} ] } """ if not hasattr(Schema.get_payment_txn, "cb"): self.logger.debug("vcx_schema_get_payment_txn: Creating callback") Schema.get_payment_txn.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_credential_handle = c_uint32(self.handle) payment_txn = await do_call('vcx_schema_get_payment_txn', c_credential_handle, Schema.get_payment_txn.cb) return json.loads(payment_txn.decode())
async def sign_data(self, msg: bytes) -> bytes: """ Sign data using connection's pairwise key :param msg: :return: signature """ def transform_cb(arr_ptr: POINTER(c_uint8), arr_len: c_uint32): return bytes(arr_ptr[:arr_len]), if not hasattr(Connection.sign_data, "cb"): self.logger.debug("vcx_connection_sign_data: Creating callback") Connection.sign_data.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, POINTER(c_uint8), c_uint32), transform_cb) c_connection_handle = c_uint32(self.handle) c_msg_len = c_uint32(len(msg)) result = await do_call('vcx_connection_sign_data', c_connection_handle, msg, c_msg_len, Connection.sign_data.cb) self.logger.debug("vcx_connection_sign_data completed") return result
async def vcx_messages_download(status: str = None, uids: str = None, pw_dids: str = None) -> str: logger = logging.getLogger(__name__) if not hasattr(vcx_messages_download, "cb"): logger.debug("vcx_messages_download: Creating callback") vcx_messages_download.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) if status: c_status = c_char_p(status.encode('utf-8')) else: c_status = None if uids: c_uids = c_char_p(uids.encode('utf-8')) else: c_uids = None if pw_dids: c_pw_dids = c_char_p(pw_dids.encode('utf-8')) else: c_pw_dids = None result = await do_call('vcx_messages_download', c_status, c_uids, c_pw_dids, vcx_messages_download.cb) logger.debug("vcx_messages_download completed") return result
async def get_request_msg(self, connection: Connection, payment_handle: int): """ Approves the credential offer and gets the credential request message :param connection: connection to submit request from :param payment_handle: currently unused :return: Example: connection = await Connection.create(source_id) await connection.connect(phone_number) credential = await Credential.create(source_id, offer) await credential.send_request(connection, 0) """ if not hasattr(Credential.get_request_msg, "cb"): self.logger.debug("vcx_credential_get_request_msg: Creating callback") Credential.get_request_msg.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_credential_handle = c_uint32(self.handle) c_connection_handle = c_uint32(connection.handle) c_payment = c_uint32(payment_handle) msg = await do_call('vcx_credential_get_request_msg', c_credential_handle, c_connection_handle, c_payment, Credential.get_request_msg.cb) return json.loads(msg.decode())
async def send_offer(self, connection: Connection): """ Sends an offer to a prover. Once accepted, a request will be recieved. :param connection: vcx.api.connection.Connection :return: None Example: source_id = '1' cred_def_id = 'cred_def_id1' attrs = {'key': 'value', 'key2': 'value2', 'key3': 'value3'} name = 'Credential Name' issuer_did = '8XFh8yBzrpJQmNyZzgoTqB' phone_number = '8019119191' price = 1 issuer_credential = await IssuerCredential.create(source_id, attrs, cred_def_id, name, price) connection = await Connection.create(source_id) issuer_credential.send_offer(connection) """ if not hasattr(IssuerCredential.send_offer, "cb"): self.logger.debug("vcx_issuer_send_credential_offer: Creating callback") IssuerCredential.send_offer.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32)) c_credential_handle = c_uint32(self.handle) c_connection_handle = c_uint32(connection.handle) await do_call('vcx_issuer_send_credential_offer', c_credential_handle, c_connection_handle, IssuerCredential.send_offer.cb)
async def send_tokens(payment_handle: int, tokens: int, address: str) -> str: """ Sends tokens to an address payment_handle is always 0 :param payment_handle: Integer :param tokens: Integer :param address: String Example: payment_handle = 0 amount = 1000 address = await Wallet.create_payment_address('00000000000000000000000001234567') await Wallet.send_tokens(payment_handle, amount, address) :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.send_tokens, "cb"): logger.debug("vcx_wallet_send_tokens: Creating callback") Wallet.send_tokens.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_payment_handle = c_uint32(payment_handle) c_tokens = c_char_p(str(tokens).encode('utf-8')) c_address = c_char_p(address.encode('utf-8')) result = await do_call('vcx_wallet_send_tokens', c_payment_handle, c_tokens, c_address, Wallet.send_tokens.cb) logger.debug("vcx_wallet_send_tokens completed") return result
async def get_proof(self, connection: Connection) -> list: """ Example: connection = await Connection.create(source_id) await connection.connect(phone_number) name = "proof name" requested_attrs = [{"name": "age", "restrictions": [{"schema_id": "6XFh8yBzrpJQmNyZzgoTqB:2:schema_name:0.0.11", "schema_name":"Faber Student Info", "schema_version":"1.0", "schema_issuer_did":"6XFh8yBzrpJQmNyZzgoTqB", "issuer_did":"8XFh8yBzrpJQmNyZzgoTqB", "cred_def_id": "8XFh8yBzrpJQmNyZzgoTqB:3:CL:1766" }, { "schema_id": "5XFh8yBzrpJQmNyZzgoTqB:2:schema_name:0.0.11", "schema_name":"BYU Student Info", "schema_version":"1.0", "schema_issuer_did":"5XFh8yBzrpJQmNyZzgoTqB", "issuer_did":"66Fh8yBzrpJQmNyZzgoTqB", "cred_def_id": "66Fh8yBzrpJQmNyZzgoTqB:3:CL:1766" } ] }, { "name":"name", "restrictions": [ { "schema_id": "6XFh8yBzrpJQmNyZzgoTqB:2:schema_name:0.0.11", "schema_name":"Faber Student Info", "schema_version":"1.0", "schema_issuer_did":"6XFh8yBzrpJQmNyZzgoTqB", "issuer_did":"8XFh8yBzrpJQmNyZzgoTqB", "cred_def_id": "8XFh8yBzrpJQmNyZzgoTqB:3:CL:1766" }, { "schema_id": "5XFh8yBzrpJQmNyZzgoTqB:2:schema_name:0.0.11", "schema_name":"BYU Student Info", "schema_version":"1.0", "schema_issuer_did":"5XFh8yBzrpJQmNyZzgoTqB", "issuer_did":"66Fh8yBzrpJQmNyZzgoTqB", "cred_def_id": "66Fh8yBzrpJQmNyZzgoTqB:3:CL:1766"}]}] proof = await Proof.create(source_id, name, requested_attrs) await proof.request_proof(connection) await proof.get_proof(connection) :param connection: Handle for the connection to receive a proof from. :return: List of proofs received from the given connection. """ if not hasattr(Proof.get_proof, "cb"): self.logger.debug("vcx_get_proof: Creating callback") Proof.get_proof.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p)) c_proof_handle = c_uint32(self.handle) c_connection_handle = c_uint32(connection.handle) proof_state, proof = await do_call('vcx_get_proof', c_proof_handle, c_connection_handle, Proof.get_proof.cb) self.proof_state = proof_state return json.loads(proof.decode())
async def update_state_with_message(self, message: str) -> int: """ Update the state of the credential based on the given message. Example: cred = await IssuerCredential.create(source_id) assert await cred.update_state_with_message(message) == State.Accepted :param message: :return Current state of the IssuerCredential """ if not hasattr(IssuerCredential.update_state_with_message, "cb"): self.logger.debug( "vcx_issuer_credential_update_state_with_message: Creating callback" ) IssuerCredential.update_state_with_message.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_uint32)) c_handle = c_uint32(self.handle) c_message = c_char_p(message.encode('utf-8')) state = await do_call( 'vcx_issuer_credential_update_state_with_message', c_handle, c_message, IssuerCredential.update_state_with_message.cb) self.logger.debug( "vcx_issuer_credential_update_state_with_message completed") return state
async def create_payment_address(seed: str = None) -> str: """ Creates a payment address inside the wallet. :param seed: String Example: address = await Wallet.create_payment_address('00000000000000000000000001234567') :return: String """ logger = logging.getLogger(__name__) if not hasattr(Wallet.create_payment_address, "cb"): logger.debug( "vcx_wallet_create_payment_address: Creating callback") Wallet.create_payment_address.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) if seed: c_seed = c_char_p(seed.encode('utf-8')) else: c_seed = None result = await do_call('vcx_wallet_create_payment_address', c_seed, Wallet.create_payment_address.cb) logger.debug("vcx_wallet_create_payment_address completed") return result
async def generate_proof(self, selected_creds: dict, self_attested_attrs: dict): """ Generates the proof Example: msg_id = '1' phone_number = '8019119191' connection = await Connection.create(source_id) await connection.connect(phone_number) disclosed_proof = await DisclosedProof.create_with_msgid(source_id, connection, msg_id) await disclosed_proof.generate_proof({}, {}) :param selected_creds: Credentials issued :param self_attested_attrs: Self Attested Attributes :return: None """ if not hasattr(DisclosedProof.generate_proof, "cb"): self.logger.debug("vcx_disclosed_proof_generate_proof: Creating callback") DisclosedProof.generate_proof.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32)) c_disclosed_proof_handle = c_uint32(self.handle) c_selected_creds = c_char_p(json.dumps(selected_creds).encode('utf-8')) c_self_attested_attrs = c_char_p(json.dumps(self_attested_attrs).encode('utf-8')) await do_call('vcx_disclosed_proof_generate_proof', c_disclosed_proof_handle, c_selected_creds, c_self_attested_attrs, DisclosedProof.generate_proof.cb)
async def get_payment_txn(self): """ Get the payment transaction information generated when paying the ledger fee Example: source_id = 'foobar123' name = 'Address Schema' version = '1.0' attrs = ['address', 'city', 'state'] payment_handle = 0 schema1 = await Schema.create(source_id, name, version, attrs, payment_handle) txn = await schema1.get_payment_txn() :return: JSON object with input address and output UTXOs """ if not hasattr(Schema.get_payment_txn, "cb"): self.logger.debug("vcx_schema_get_payment_txn: Creating callback") Schema.get_payment_txn.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_credential_handle = c_uint32(self.handle) payment_txn = await do_call('vcx_schema_get_payment_txn', c_credential_handle, Schema.get_payment_txn.cb) return json.loads(payment_txn.decode())
async def delete_record(type_: str, id: str): """ Delete a record from the storage wallet. :param type_: :param id: Example: await Wallet.add_record({ 'id': 'RecordId', 'tags': json.dumps({ 'tag1': 'unencrypted value1', '~encryptedTag', 'this value is encrypted, 'integerTag', 1 }), 'type_': 'TestType', 'value': 'RecordValue' }) await Wallet.delete_record('TestType', 'RecordId') :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.delete_record, "cb"): logger.debug("vcx_wallet_delete_record: Creating callback") Wallet.delete_record.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32)) c_type_ = c_char_p(type_.encode('utf-8')) c_id = c_char_p(id.encode('utf-8')) result = await do_call('vcx_wallet_delete_record', c_type_, c_id, Wallet.delete_record.cb) logger.debug("vcx_wallet_delete_record completed") return result
async def add_record_tags(type_: str, id: str, tags: str): """ Adds tags to a record already stored in the storage wallet. :param type_: String :param id: String :param tags: String Example: import json await Wallet.add_record({ 'id': 'RecordId', 'tags': '{}', 'type_': 'TestType', 'value': 'RecordValue await Wallet.add_record_tags('TestType', 'RecordId', json.dumps({'addthistag':'valuetag1'})) :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.add_record_tags, "cb"): logger.debug("vcx_wallet_add_record_tags: Creating callback") Wallet.add_record_tags.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32)) c_type_ = c_char_p(type_.encode('utf-8')) c_id = c_char_p(id.encode('utf-8')) c_tags = c_char_p(tags.encode('utf-8')) result = await do_call('vcx_wallet_add_record_tags', c_type_, c_id, c_tags, Wallet.add_record_tags.cb) logger.debug("vcx_wallet_add_record_tags completed") return result
async def connect(self, options: str) -> str: """ Connect securely and privately to the endpoint represented by the object. :param options: detailed connection options Example options: {"connection_type":"SMS","phone":"5555555555","use_public_did":true} or: {"connection_type":"QR"} Example code: connection = await Connection.create('Sally') invite_details = await connection.connect('{"connection_type":"QR"}') :return: the invite details sent via SMS or ready to be sent via some other mechanism (QR for example) """ if not hasattr(Connection.connect, "cb"): self.logger.debug("vcx_connection_connect: Creating callback") Connection.connect.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_connection_handle = c_uint32(self.handle) c_connection_data = c_char_p(options.encode('utf-8')) invite_details = await do_call('vcx_connection_connect', c_connection_handle, c_connection_data, Connection.connect.cb) return invite_details
async def send_discovery_features(self, query: Optional[str] = None, comment: Optional[str] = None): """ Send discovery features message to the specified connection to discover which features it supports, and to what extent. Note that this function is useful in case `aries` communication method is used. In other cases it returns ActionNotSupported error. :param query: (Optional) query string to match against supported message types. :param comment: (Optional) human-friendly description of the ping. :return: no value """ if not hasattr(Connection.send_discovery_features, "cb"): self.logger.debug( "vcx_connection_send_discovery_features: Creating callback") Connection.send_discovery_features.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32)) c_connection_handle = c_uint32(self.handle) c_query = c_char_p( query.encode('utf-8')) if query is not None else None c_comment = c_char_p( comment.encode('utf-8')) if comment is not None else None await do_call('vcx_connection_send_discovery_features', c_connection_handle, c_query, c_comment, Connection.send_discovery_features.cb)
async def vcx_agent_provision(config: str) -> None: """ Provision an agent in the agency, populate configuration and wallet for this agent. Example: import json enterprise_config = { 'agency_url': 'https://enym-eagency.pdev.evernym.com', 'agency_did': 'YRuVCckY6vfZfX9kcQZe3u', 'agency_verkey': "J8Yct6FwmarXjrE2khZesUXRVVSVczSoa9sFaGe6AD2v", 'wallet_name': 'LIBVCX_SDK_WALLET', 'agent_seed': '00000000000000000000000001234561', 'enterprise_seed': '000000000000000000000000Trustee1', 'wallet_key': '1234' } vcx_config = await vcx_agent_provision(json.dumps(enterprise_config)) :param config: JSON configuration :return: Configuration for vcx_init call. """ logger = logging.getLogger(__name__) if not hasattr(vcx_agent_provision, "cb"): logger.debug("vcx_agent_provision: Creating callback") vcx_agent_provision.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_config = c_char_p(config.encode('utf-8')) result = await do_call('vcx_agent_provision_async', c_config, vcx_agent_provision.cb) logger.debug("vcx_agent_provision completed") return result.decode()
async def get_proof(self, connection: Connection) -> list: """ Todo: This should be depricated, use get_proof_msg Gets the proof message Example: connection = await Connection.create(source_id) await connection.connect(phone_number) name = "proof name" requested_attrs = [{"name": "age", "restrictions": [{"schema_id": "6XFh8yBzrpJQmNyZzgoTqB:2:schema_name:0.0.11", "schema_name":"Faber Student Info", "schema_version":"1.0", "schema_issuer_did":"6XFh8yBzrpJQmNyZzgoTqB", "issuer_did":"8XFh8yBzrpJQmNyZzgoTqB", "cred_def_id": "8XFh8yBzrpJQmNyZzgoTqB:3:CL:1766" }, { "schema_id": "5XFh8yBzrpJQmNyZzgoTqB:2:schema_name:0.0.11", "schema_name":"BYU Student Info", "schema_version":"1.0", "schema_issuer_did":"5XFh8yBzrpJQmNyZzgoTqB", "issuer_did":"66Fh8yBzrpJQmNyZzgoTqB", "cred_def_id": "66Fh8yBzrpJQmNyZzgoTqB:3:CL:1766" } ] }, { "name":"name", "restrictions": [ { "schema_id": "6XFh8yBzrpJQmNyZzgoTqB:2:schema_name:0.0.11", "schema_name":"Faber Student Info", "schema_version":"1.0", "schema_issuer_did":"6XFh8yBzrpJQmNyZzgoTqB", "issuer_did":"8XFh8yBzrpJQmNyZzgoTqB", "cred_def_id": "8XFh8yBzrpJQmNyZzgoTqB:3:CL:1766" }, { "schema_id": "5XFh8yBzrpJQmNyZzgoTqB:2:schema_name:0.0.11", "schema_name":"BYU Student Info", "schema_version":"1.0", "schema_issuer_did":"5XFh8yBzrpJQmNyZzgoTqB", "issuer_did":"66Fh8yBzrpJQmNyZzgoTqB", "cred_def_id": "66Fh8yBzrpJQmNyZzgoTqB:3:CL:1766"}]}] proof = await Proof.create(source_id, name, requested_attrs) await proof.request_proof(connection) await proof.get_proof(connection) :param connection: Handle for the connection to receive a proof from. :return: List of proofs received from the given connection. """ if not hasattr(Proof.get_proof, "cb"): self.logger.debug("vcx_get_proof: Creating callback") Proof.get_proof.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p)) c_proof_handle = c_uint32(self.handle) c_connection_handle = c_uint32(connection.handle) proof_state, proof = await do_call('vcx_get_proof', c_proof_handle, c_connection_handle, Proof.get_proof.cb) self.proof_state = proof_state return json.loads(proof.decode())
async def send_message(self, msg: str, msg_type: str, msg_title: str, ref_msg_id: str = None) -> str: """ Send a generic message to the connection :param msg: :param msg_type: :param msg_title: :param ref_msg_id: if responding to a message, provide msg id :return: """ if not hasattr(Connection.send_message, "cb"): self.logger.debug("vcx_connection_send_message: Creating callback") Connection.send_message.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) send_msg_options = { "msg_type": msg_type, "msg_title": msg_title, "ref_msg_id": ref_msg_id } c_connection_handle = c_uint32(self.handle) c_msg = c_char_p(msg.encode('utf-8')) c_send_msg_options = c_char_p( json.dumps(send_msg_options).encode('utf-8')) result = await do_call('vcx_connection_send_message', c_connection_handle, c_msg, c_send_msg_options, Connection.send_message.cb) self.logger.debug("vcx_connection_send_message completed") return result
async def vcx_get_request_price(action_json: str, requester_info_json: Optional[str]): """ Update the status of messages from the specified connection :param action_json: { "auth_type": ledger transaction alias or associated value, "auth_action": type of an action., "field": transaction field, "old_value": (Optional) old value of a field, which can be changed to a new_value (mandatory for EDIT action), "new_value": (Optional) new value that can be used to fill the field, } :param requester_info_json: (Optional) { "role": string - role of a user which can sign transaction. "count": string - count of users. "is_owner": bool - if user is an owner of transaction. } otherwise context info will be used :return: price - tokens amount required for action performing """ logger = logging.getLogger(__name__) if not hasattr(vcx_get_request_price, "cb"): logger.debug("vcx_get_request_price: Creating callback") vcx_get_request_price.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_uint64)) c_action_json = c_char_p(action_json.encode('utf-8')) c_requester_info_json = c_char_p(requester_info_json.encode( 'utf-8')) if requester_info_json is not None else None result = await do_call('vcx_get_request_price', c_action_json, c_requester_info_json, vcx_get_request_price.cb) logger.debug("vcx_get_request_price completed") return result
async def invite_details(self, abbreviated: bool) -> dict: """ Get the invite details that were sent or can be sent to the endpoint. :param abbreviated: abbreviate invite details or not Example: phone_number = '8019119191' connection = await Connection.create('foobar123') invite_details = await connection.connect(phone_number) inivte_details_again = await connection.invite_details() :return: JSON of invite_details sent to connection """ if not hasattr(Connection.invite_details, "cb"): self.logger.debug( "vcx_connection_invite_details: Creating callback") Connection.invite_details.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_connection_handle = c_uint32(self.handle) c_abbreviated = c_bool(abbreviated) details = await do_call('vcx_connection_invite_details', c_connection_handle, c_abbreviated, Connection.invite_details.cb) return json.loads(details.decode())
async def create_with_msgid(source_id: str, connection: Connection, msg_id: str): """ :param source_id: :param connection: :param msg_id: Example: msg_id = '1' phone_number = '8019119191' connection = await Connection.create(source_id) await connection.connect(phone_number) disclosed_proof = await DisclosedProof.create_with_msgid(source_id, connection, msg_id) :return: DisclosedProof """ proof = DisclosedProof(source_id) c_source_id = c_char_p(source_id.encode('utf-8')) c_msg_id = c_char_p(json.dumps(msg_id).encode('utf-8')) c_connection_handle = c_uint32(connection.handle) if not hasattr(DisclosedProof.create_with_msgid, "cb"): DisclosedProof.create_with_msgid.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p)) proof.handle, proof_req = await do_call( 'vcx_disclosed_proof_create_with_msgid', c_source_id, c_connection_handle, c_msg_id, DisclosedProof.create_with_msgid.cb) proof.proof_request = json.loads(proof_req.decode()) return proof
async def generate_proof(self, selected_creds: dict, self_attested_attrs: dict): """ Generates the proof Example: msg_id = '1' phone_number = '8019119191' connection = await Connection.create(source_id) await connection.connect(phone_number) disclosed_proof = await DisclosedProof.create_with_msgid(source_id, connection, msg_id) await disclosed_proof.generate_proof({}, {}) :param selected_creds: Credentials issued :param self_attested_attrs: Self Attested Attributes :return: None """ if not hasattr(DisclosedProof.generate_proof, "cb"): self.logger.debug( "vcx_disclosed_proof_generate_proof: Creating callback") DisclosedProof.generate_proof.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32)) c_disclosed_proof_handle = c_uint32(self.handle) c_selected_creds = c_char_p(json.dumps(selected_creds).encode('utf-8')) c_self_attested_attrs = c_char_p( json.dumps(self_attested_attrs).encode('utf-8')) await do_call('vcx_disclosed_proof_generate_proof', c_disclosed_proof_handle, c_selected_creds, c_self_attested_attrs, DisclosedProof.generate_proof.cb)
async def send_proof(self, connection: Optional[Connection] = None): """ Sends the proof to the Connection Example: msg_id = '1' phone_number = '8019119191' connection = await Connection.create(source_id) await connection.connect(phone_number) disclosed_proof = await DisclosedProof.create_with_msgid(source_id, connection, msg_id) await disclosed_proof.send_proof(connection) :param connection: Connection :return: None """ if not hasattr(DisclosedProof.send_proof, "cb"): self.logger.debug( "vcx_disclosed_proof_send_proof: Creating callback") DisclosedProof.send_proof.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32)) c_disclosed_proof_handle = c_uint32(self.handle) c_connection_handle = c_uint32(connection.handle) if connection else 0 await do_call('vcx_disclosed_proof_send_proof', c_disclosed_proof_handle, c_connection_handle, DisclosedProof.send_proof.cb)
async def update_record_tags(type_: str, id: str, tags: str): """ Updates the tags on a record, removing any previous value. :param type_: String :param id: String :param tags: String Example: import json await Wallet.add_record({ 'id': 'RecordId', 'tags': json.dumps({'foobar':'this value will get overwritten'}), 'type_': 'TestType', 'value': 'RecordValue await Wallet.update_record_tags('TestType', 'RecordId', json.dumps({'foobar':'new value'})) :return: """ logger = logging.getLogger(__name__) if not hasattr(Wallet.update_record_tags, "cb"): logger.debug("vcx_wallet_update_record_tags: Creating callback") Wallet.update_record_tags.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32)) c_type_ = c_char_p(type_.encode('utf-8')) c_id = c_char_p(id.encode('utf-8')) c_tags = c_char_p(tags.encode('utf-8')) result = await do_call('vcx_wallet_update_record_tags', c_type_, c_id, c_tags, Wallet.update_record_tags.cb) logger.debug("vcx_wallet_update_record_tags completed") return result
async def _get_state(self, cls, fn: str) -> int: if not hasattr(cls.get_state, "cb"): self.logger.debug("{}: Creating callback".format(fn)) cls.get_state.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_uint32)) c_handle = c_uint32(self.handle) return await do_call(fn, c_handle, cls.get_state.cb)
async def _update_state(self, cls, fn: str) -> int: if not hasattr(cls.update_state, "cb"): self.logger.debug("{}: Creating callback".format(fn)) cls.update_state.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_uint32)) c_handle = c_uint32(self.handle) state = await do_call(fn, c_handle, cls.update_state.cb) self.logger.debug("{} object has state of: {}".format(cls, state)) return state
async def _serialize(self, cls, fn_str: str) -> dict: if not hasattr(cls.serialize, "cb"): self.logger.debug("{}: Creating callback".format(fn_str)) cls.serialize.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_handle = c_uint32(self.handle) data = await do_call(fn_str, c_handle, cls.serialize.cb) self.logger.debug("serialized {} object".format(cls)) j = json.loads(data.decode()) return j
async def vcx_get_ledger_author_agreement(): """ Retrieve author agreement set on the Ledger :return: """ logger = logging.getLogger(__name__) if not hasattr(vcx_get_ledger_author_agreement, "cb"): logger.debug("vcx_get_ledger_author_agreement: Creating callback") vcx_get_ledger_author_agreement.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) result = await do_call('vcx_get_ledger_author_agreement', vcx_get_ledger_author_agreement.cb) logger.debug("vcx_get_ledger_author_agreement completed") return result.decode()
async def close_search(handle: int): logger = logging.getLogger(__name__) if not hasattr(Wallet.close_search, "cb"): logger.debug("vcx_wallet_close_search: Creating callback") Wallet.close_search.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32)) c_handle = c_uint32(handle) data = await do_call('vcx_wallet_close_search', c_handle, Wallet.close_search.cb) logger.debug("vcx_wallet_close_search completed") return data
async def get_cred_def_id(self): """ Get the ledger ID of the object Example: source_id = 'foobar123' schema_name = 'Schema Name' payment_handle = 0 credential_def1 = await CredentialDef.create(source_id, name, schema_id, payment_handle) assert await credential_def.get_cred_def_id() == '2hoqvcwupRTUNkXn6ArYzs:3:CL:2471' :return: ID string """ cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_handle = c_uint32(self.handle) cred_def_id = await do_call('vcx_credentialdef_get_cred_def_id', c_handle, cb) return cred_def_id .decode()
async def revoke_credential(self): """ Revokes a credential. :return: None Example: credential.revoke_credential() """ if not hasattr(IssuerCredential.revoke_credential, "cb"): self.logger.debug("vcx_issuer_revoke_credential: Creating callback") IssuerCredential.revoke_credential.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32)) c_credential_handle = c_uint32(self.handle) await do_call('vcx_issuer_revoke_credential', c_credential_handle, IssuerCredential.revoke_credential.cb)
async def _create(cls, fn: str, constructor_args, c_args): obj = cls(*constructor_args) if not hasattr(cls.create, "cb"): obj.logger.debug("{}: Creating callback".format(fn)) cls.create.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_uint32)) obj.handle = await do_call(fn, *c_args, cls.create.cb) VcxBase.HANDLES[obj.handle] = obj obj.logger.debug("created {} object".format(cls)) return obj
async def get_schema_id(self): """ Get the ledger ID of the object Example: source_id = 'foobar123' name = 'Address Schema' version = '1.0' attrs = ['address', 'city', 'state'] payment_handle = 0 schema1 = await Schema.create(source_id, name, version, attrs, payment_handle) id1 = await schema.get_schema_id() :return: ID string """ cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_char_p)) c_handle = c_uint32(self.handle) id = await do_call('vcx_schema_get_schema_id', c_handle, cb) return id.decode()