bbc1.core.bbclib module¶
Copyright (c) 2017 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.
-
class
bbc1.core.bbclib.
BBcAsset
(user_id=None, asset_file=None, asset_body=None, format_type=0, id_length=32)[source]¶ Bases:
object
Asset part in a transaction
-
deserialize
(data)[source]¶ Deserialize into this object
Parameters: data (bytes) – serialized binary data Returns: True if successful Return type: bool
-
deserialize_obj
(obj)[source]¶ Deserialize bson/msgpack data into this object
Parameters: obj (bytes) – object data Returns: True if successful Return type: bool
-
digest
()[source]¶ Calculate the digest
The digest corresponds to the asset_id of this object
Returns: asset_id (or digest) Return type: bytes
-
get_asset_file
()[source]¶ Get asset file content and its digest
Returns: digest of the file content bytes: the file content Return type: bytes
-
-
class
bbc1.core.bbclib.
BBcCrossRef
(domain_id=None, transaction_id=None, deserialize=None, format_type=0)[source]¶ Bases:
object
CrossRef part in a transaction
-
deserialize
(data)[source]¶ Deserialize into this object
Parameters: data (bytes) – serialized binary data Returns: True if successful Return type: bool
-
-
class
bbc1.core.bbclib.
BBcEvent
(asset_group_id=None, format_type=0, id_length=32)[source]¶ Bases:
object
Event part in a transaction
-
add
(asset_group_id=None, reference_index=None, mandatory_approver=None, option_approver_num_numerator=0, option_approver_num_denominator=0, option_approver=None, asset=None)[source]¶ Add parts
-
deserialize
(data)[source]¶ Deserialize into this object
Parameters: data (bytes) – serialized binary data Returns: True if successful Return type: bool
-
-
class
bbc1.core.bbclib.
BBcFormat
[source]¶ Bases:
object
-
FORMAT_BINARY
= 0¶
-
FORMAT_BSON
= 1¶
-
FORMAT_BSON_COMPRESS_BZ2
= 2¶
-
FORMAT_BSON_COMPRESS_ZLIB
= 3¶
-
FORMAT_MSGPACK
= 4¶
-
FORMAT_MSGPACK_COMPRESS_BZ2
= 5¶
-
FORMAT_MSGPACK_COMPRESS_ZLIB
= 6¶
-
-
class
bbc1.core.bbclib.
BBcPointer
(transaction_id=None, asset_id=None, format_type=0, id_length=32)[source]¶ Bases:
object
Pointer part in a transaction
-
deserialize
(data)[source]¶ Deserialize into this object
Parameters: data (bytes) – serialized binary data Returns: True if successful Return type: bool
-
-
class
bbc1.core.bbclib.
BBcReference
(asset_group_id, transaction, ref_transaction=None, event_index_in_ref=0, format_type=0, id_length=32)[source]¶ Bases:
object
Reference part in a transaction
-
add_signature
(user_id=None, signature=None)[source]¶ Add signature in the reserved space
Parameters: - user_id (bytes) – user_id of the signature owner
- signature (BBcSignature) – signature
-
deserialize
(data)[source]¶ Deserialize into this object
Parameters: data (bytes) – serialized binary data Returns: True if successful Return type: bool
-
-
class
bbc1.core.bbclib.
BBcRelation
(asset_group_id=None, format_type=0, id_length=32)[source]¶ Bases:
object
Relation part in a transaction
-
deserialize
(data)[source]¶ Deserialize bson data into this object
Parameters: data (dict) – bson data Returns: True if successful Return type: bool
-
-
class
bbc1.core.bbclib.
BBcSignature
(key_type=2, deserialize=None, format_type=0)[source]¶ Bases:
object
Signature part in a transaction
-
deserialize
(data)[source]¶ Deserialize into this object
Parameters: data (bytes) – serialized binary data Returns: True if successful Return type: bool
-
-
class
bbc1.core.bbclib.
BBcTransaction
(version=1, deserialize=None, format_type=0, id_length=32)[source]¶ Bases:
object
Transaction object
-
add_signature
(user_id=None, signature=None)[source]¶ Add signature in the reserved space
Parameters: - user_id (bytes) – user_id of the signature owner
- signature (BBcSignature) – signature
Returns: True if successful
Return type: bool
-
deserialize
(data)[source]¶ Deserialize into this object
Parameters: data (bytes) – serialized binary data Returns: True if successful Return type: bool
-
deserialize_obj
(data)[source]¶ Deserialize bson/msgpack data into this object
Parameters: data (bytes) – object data Returns: True if successful Return type: bool
-
digest
()[source]¶ Calculate the digest
The digest corresponds to the transaction_id of this object
Returns: transaction_id (or digest) Return type: bytes
-
get_sig_index
(user_id)[source]¶ Reserve a space for signature for the specified user_id
Parameters: user_id (bytes) – user_id whose signature will be added to the signature part Returns: position (index) in the signature part Return type: int
-
sign
(key_type=2, private_key=None, public_key=None, keypair=None)[source]¶ Sign the transaction
Parameters: - key_type (int) – Type of encryption key’s curve
- private_key (bytes) –
- public_key (bytes) –
- keypair (KeyPair) – keypair or set of private_key and public_key needs to be given
Returns: Return type:
-
-
class
bbc1.core.bbclib.
BBcWitness
(format_type=0, id_length=32)[source]¶ Bases:
object
Witness part in a transaction
-
add_signature
(user_id=None, signature=None)[source]¶ Add signature in the reserved space for the user_id that was registered before
Parameters: - user_id (bytes) – user_id of the signature owner
- signature (bytes) – signature
-
deserialize
(data)[source]¶ Deserialize into this object
Parameters: data (bytes) – serialized binary data Returns: True if successful Return type: bool
-
-
class
bbc1.core.bbclib.
KeyPair
(curvetype=2, compression=False, privkey=None, pubkey=None)[source]¶ Bases:
object
-
POINT_CONVERSION_COMPRESSED
= 2¶
-
POINT_CONVERSION_UNCOMPRESSED
= 4¶ Key pair container
-
import_publickey_cert_pem
(cert_pemstring, privkey_pemstring=None)[source]¶ Verify and import X509 public key certificate in pem format
-
mk_keyobj_from_private_key_der
(derdat)[source]¶ Make a keypair object from the private key in DER format
-
mk_keyobj_from_private_key_pem
(pemdat_string)[source]¶ Make a keypair object from the private key in PEM format
-
-
class
bbc1.core.bbclib.
KeyType
[source]¶ Bases:
object
-
ECDSA_P256v1
= 2¶
-
ECDSA_SECP256k1
= 1¶
-
NOT_INITIALIZED
= 0¶
-
-
class
bbc1.core.bbclib.
MsgType
[source]¶ Bases:
object
Message types for between core node and client
-
CANCEL_INSERT_NOTIFICATION
= 16¶
-
DOMAIN_PING
= 12¶
-
MESSAGE
= 66¶
-
NOTIFY_CROSS_REF
= 74¶
-
NOTIFY_DOMAIN_KEY_UPDATE
= 19¶
-
NOTIFY_INSERTED
= 73¶
-
REGISTER
= 64¶
-
REQUEST_CLOSE_DOMAIN
= 31¶
-
REQUEST_COUNT_TRANSACTIONS
= 95¶
-
REQUEST_CROSS_REF_LIST
= 92¶
-
REQUEST_CROSS_REF_VERIFY
= 90¶
-
REQUEST_ECDH_KEY_EXCHANGE
= 33¶
-
REQUEST_GATHER_SIGNATURE
= 67¶
-
REQUEST_GET_CONFIG
= 8¶
-
REQUEST_GET_DOMAINLIST
= 13¶
-
REQUEST_GET_FORWARDING_LIST
= 25¶
-
REQUEST_GET_NEIGHBORLIST
= 21¶
-
REQUEST_GET_NODEID
= 27¶
-
REQUEST_GET_NOTIFICATION_LIST
= 29¶
-
REQUEST_GET_STATS
= 17¶
-
REQUEST_GET_USERS
= 23¶
-
REQUEST_INSERT
= 71¶
-
REQUEST_INSERT_NOTIFICATION
= 15¶
-
REQUEST_MANIP_LEDGER_SUBSYS
= 10¶
-
REQUEST_REGISTER_HASH_IN_SUBSYS
= 128¶
-
REQUEST_REPAIR
= 94¶
-
REQUEST_SEARCH_TRANSACTION
= 82¶
-
REQUEST_SEARCH_WITH_CONDITIONS
= 86¶
-
REQUEST_SETUP_DOMAIN
= 0¶
-
REQUEST_SET_STATIC_NODE
= 4¶
-
REQUEST_SIGNATURE
= 69¶
-
REQUEST_TRAVERSE_TRANSACTIONS
= 88¶
-
REQUEST_VERIFY_HASH_IN_SUBSYS
= 130¶
-
RESPONSE_CLOSE_DOMAIN
= 32¶
-
RESPONSE_COUNT_TRANSACTIONS
= 95¶
-
RESPONSE_CROSS_REF_LIST
= 93¶
-
RESPONSE_CROSS_REF_VERIFY
= 91¶
-
RESPONSE_ECDH_KEY_EXCHANGE
= 34¶
-
RESPONSE_GATHER_SIGNATURE
= 68¶
-
RESPONSE_GET_CONFIG
= 9¶
-
RESPONSE_GET_DOMAINLIST
= 14¶
-
RESPONSE_GET_FORWARDING_LIST
= 26¶
-
RESPONSE_GET_NEIGHBORLIST
= 22¶
-
RESPONSE_GET_NODEID
= 28¶
-
RESPONSE_GET_NOTIFICATION_LIST
= 30¶
-
RESPONSE_GET_STATS
= 18¶
-
RESPONSE_GET_USERS
= 24¶
-
RESPONSE_INSERT
= 72¶
-
RESPONSE_MANIP_LEDGER_SUBSYS
= 11¶
-
RESPONSE_REGISTER_HASH_IN_SUBSYS
= 129¶
-
RESPONSE_SEARCH_TRANSACTION
= 83¶
-
RESPONSE_SEARCH_WITH_CONDITIONS
= 87¶
-
RESPONSE_SETUP_DOMAIN
= 1¶
-
RESPONSE_SET_STATIC_NODE
= 5¶
-
RESPONSE_SIGNATURE
= 70¶
-
RESPONSE_TRAVERSE_TRANSACTIONS
= 89¶
-
RESPONSE_VERIFY_HASH_IN_SUBSYS
= 131¶
-
UNREGISTER
= 65¶
-
-
bbc1.core.bbclib.
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
-
bbc1.core.bbclib.
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
-
bbc1.core.bbclib.
add_reference_to_transaction
(transaction, asset_group_id, ref_transaction_obj, event_index_in_ref)[source]¶ Utility to add BBcReference object in the transaction
Returns: Return type: BBcReference
-
bbc1.core.bbclib.
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
-
bbc1.core.bbclib.
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
-
bbc1.core.bbclib.
convert_idstring_to_bytes
(datastr, bytelen=32)[source]¶ Convert hex string to binary data
-
bbc1.core.bbclib.
deep_copy_with_key_stringify
(u, d=None)[source]¶ Utility for updating nested dictionary
-
bbc1.core.bbclib.
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
-
bbc1.core.bbclib.
get_random_id
()[source]¶ Return 256-bit binary data
Returns: 256-bit random binary Return type: bytes
-
bbc1.core.bbclib.
make_relation_with_asset
(asset_group_id, user_id, asset_body=None, asset_file=None, format_type=0, id_length=32)[source]¶ Utility to make BBcRelation object
-
bbc1.core.bbclib.
make_transaction
(event_num=0, relation_num=0, witness=False, format_type=0, id_length=32)[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
- format_type (int) – Data format defined in BBcFormat class
- id_length (int) – If <32, IDs will be truncated
Returns: Return type:
-
bbc1.core.bbclib.
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
-
bbc1.core.bbclib.
verify_using_cross_ref
(domain_id, transaction_id, transaction_base_digest, cross_ref_data, sigdata, format_type=0)[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) – serialized BBcCrossRef object
- sigdata (bytes) – serialized signature
- format_type (int) – Data format type when calculating the digest (transaction_id)
Returns: True if valid
Return type: bool