bbclib.libs.bbclib_utils module¶
Copyright (c) 2018 beyond-blockchain.org.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
bbclib.libs.bbclib_utils.
add_event_asset
(transaction, event_idx, asset_group_id, user_id, asset_body=None, asset_file=None)[source]¶ Utility to add BBcEvent object with BBcAsset in the transaction
-
bbclib.libs.bbclib_utils.
add_pointer_in_relation
(relation, ref_transaction_id=None, ref_asset_id=None)[source]¶ Utility to add BBcRelation object with BBcPointer in the BBcRelation object
Parameters: - relation (BBcRelation) – BBcRelation object to manipulate
- ref_transaction_id (bytes) – transaction_id of the transaction that the base transaction object refers to
- ref_asset_id (bytes) – asset_id of the asset that the transaction object refers to
-
bbclib.libs.bbclib_utils.
add_reference_to_transaction
(transaction, asset_group_id, ref_transaction_obj, event_index_in_ref)[source]¶ Utility to add BBcReference object in the transaction
Parameters: - transaction (BBcTransaction) – the base transaction object to manipulate
- asset_group_id (bytes) – asset_group_id of the asset in the object
- ref_transaction_obj (BBcTransaction) – the transaction object that the base transaction object refers to
- event_index_in_ref (int) – the number of BBcEvent object to include in the transaction that the base transaction object refers to
Returns: Return type:
-
bbclib.libs.bbclib_utils.
add_relation_asset
(transaction, relation_idx, asset_group_id, user_id, asset_body=None, asset_file=None)[source]¶ Utility to add BBcRelation object with BBcAsset in the transaction
Parameters: - transaction (BBcTransaction) – transaction object to manipulate
- relation_idx (int) – the number of BBcRelation object to include in the transaction
- asset_group_id (bytes) – asset_group_id of the asset in the object
- user_id (bytes) – user_id of the owner of the asset
- asset_body (str|bytes|dict) – asset data
- asset_file (bytes) – file data (binary) for asset
-
bbclib.libs.bbclib_utils.
add_relation_asset_hash
(transaction, relation_idx, asset_group_id, asset_ids=None)[source]¶ Utility to add BBcRelation object with BBcAssetHash in the transaction
Parameters: - transaction (BBcTransaction) – transaction object to manipulate
- relation_idx (int) – the number of BBcRelation object to include in the transaction
- asset_group_id (bytes) – asset_group_id of the asset in the object
- asset_ids (list(bytes)) – list of the identifiers of assets
-
bbclib.libs.bbclib_utils.
add_relation_asset_raw
(transaction, relation_idx, asset_group_id, asset_id=None, asset_body=None)[source]¶ Utility to add BBcRelation object with BBcAssetRaw in the transaction
Parameters: - transaction (BBcTransaction) – transaction object to manipulate
- relation_idx (int) – the number of BBcRelation object to include in the transaction
- asset_group_id (bytes) – asset_group_id of the asset in the object
- asset_id (bytes) – the identifier of the asset
- asset_body (str|bytes|dict) – asset data
-
bbclib.libs.bbclib_utils.
add_relation_pointer
(transaction, relation_idx, ref_transaction_id=None, ref_asset_id=None)[source]¶ Utility to add BBcRelation object with BBcPointer in the transaction
Parameters: - transaction (BBcTransaction) – the base transaction object to manipulate
- relation_idx (int) – the number of BBcRelation object to include in the transaction
- ref_transaction_id (bytes) – transaction_id of the transaction that the base transaction object refers to
- ref_asset_id (bytes) – asset_id of the asset that the transaction object refers to
-
bbclib.libs.bbclib_utils.
convert_id_to_string
(data, bytelen=32)[source]¶ Convert binary data to hex string
Parameters: - data (bytes) – data to convert
- bytelen (int) – length of the result
Returns: converted string
Return type: str
-
bbclib.libs.bbclib_utils.
convert_idstring_to_bytes
(datastr, bytelen=32)[source]¶ Convert hex string to binary data
Parameters: - datastr (str) – data to convert
- bytelen (int) – length of the result
Returns: converted byte data
Return type: bytes
-
bbclib.libs.bbclib_utils.
deep_copy_with_key_stringify
(u, d=None)[source]¶ Utility for updating nested dictionary
-
bbclib.libs.bbclib_utils.
get_new_id
(seed_str=None, include_timestamp=True)[source]¶ Return 256-bit binary data
Parameters: - seed_str (str) – seed string that is hashed by SHA256
- include_timestamp (bool) – if True, timestamp (current time) is appended to the seed string
Returns: 256-bit binary
Return type: bytes
-
bbclib.libs.bbclib_utils.
get_random_id
()[source]¶ Return 256-bit binary data
Returns: 256-bit random binary Return type: bytes
-
bbclib.libs.bbclib_utils.
get_random_value
(length=32)[source]¶ Return random bytes
Parameters: length (int) – length of the result Returns: random bytes Return type: bytes
-
bbclib.libs.bbclib_utils.
make_relation_with_asset
(asset_group_id, user_id, asset_body=None, asset_file=None)[source]¶ Utility to make BBcRelation object with BBcAsset
Parameters: - asset_group_id (bytes) – asset_group_id of the asset in the object
- user_id (bytes) – user_id of the owner of the asset
- asset_body (str|bytes|dict) – asset data
- asset_file (bytes) – file data (binary) for asset
Returns: created BBcRelation object
Return type:
-
bbclib.libs.bbclib_utils.
make_relation_with_asset_hash
(asset_group_id, asset_ids=None)[source]¶ Utility to make BBcRelation object with BBcAssetHash
Parameters: - asset_group_id (bytes) – asset_group_id of the asset in the object
- asset_ids (list(bytes)) – list of the identifiers of assets
Returns: created BBcRelation object
Return type:
-
bbclib.libs.bbclib_utils.
make_relation_with_asset_raw
(asset_group_id, asset_id=None, asset_body=None)[source]¶ Utility to make BBcRelation object with BBcAssetRaw
Parameters: - asset_group_id (bytes) – asset_group_id of the asset in the object
- asset_id (bytes) – the identifier of the asset
- asset_body (str|bytes|dict) – asset data
Returns: created BBcRelation object
Return type:
-
bbclib.libs.bbclib_utils.
make_transaction
(event_num=0, relation_num=0, witness=False, version=1)[source]¶ Utility to make transaction object
Parameters: - event_num (int) – the number of BBcEvent object to include in the transaction
- relation_num (int) – the number of BBcRelation object to include in the transaction
- witness (bool) – If true, BBcWitness object is included in the transaction
- version (int) – version of the transaction format
Returns: Return type:
-
bbclib.libs.bbclib_utils.
recover_signature_object
(data)[source]¶ Unpack signature data
Parameters: data (bytes) – Serialized data of BBcSignature object Returns: BBcSignature object Return type: BBcSignature
-
bbclib.libs.bbclib_utils.
validate_transaction_object
(txobj, asset_files=None)[source]¶ Validate transaction and its asset
Parameters: - txobj (BBcTransaction) – target transaction object
- asset_files (dict) – dictionary containing the asset file contents
Returns: True if valid tuple: list of valid assets tuple: list of invalid assets
Return type: bool
-
bbclib.libs.bbclib_utils.
verify_using_cross_ref
(domain_id, transaction_id, transaction_base_digest, cross_ref_data, sigdata)[source]¶ Confirm the existence of the transaction using cross_ref
Parameters: - domain_id (bytes) – target domain_id
- transaction_id (bytes) – target transaction_id of which existence you want to confirm
- transaction_base_digest (bytes) – digest obtained from the outer domain
- cross_ref_data (bytes) – packed BBcCrossRef object
- sigdata (bytes) – packed signature
Returns: True if valid
Return type: bool