nevermined_sdk_py.nevermined.agreements module

class nevermined_sdk_py.nevermined.agreements.Agreements(keeper, asset_resolver, asset_consumer, asset_executor, config)

Bases: object

Nevermined agreements class.

create(did, index, agreement_id, service_agreement_signature, consumer_address, account, auto_consume=False)

Execute the service agreement on-chain using keeper’s ServiceAgreement contract.

The on-chain executeAgreement method requires the following arguments: templateId, signature, consumer, hashes, timeouts, serviceAgreementId, did. agreement_message_hash is necessary to verify the signature. The consumer signature includes the conditions timeouts and parameters values which is usedon-chain to verify that the values actually match the signed hashes.

Parameters
  • did – str representation fo the asset DID. Use this to retrieve the asset DDO.

  • index – str identifies the specific service in the ddo to use in this agreement.

  • agreement_id – 32 bytes identifier created by the consumer and will be used on-chain for the executed agreement.

  • service_agreement_signature – str the signed agreement message hash which includes conditions and their parameters values and other details of the agreement.

  • consumer_address – ethereum account address of consumer, hex str

  • account – Account instance creating the agreement. Can be either the consumer, publisher or provider

  • auto_consume – bool

Returns

dict the executeAgreement transaction receipt

create_direct(did, index, agreement_id, service_agreement_signature, consumer_address, account)

Execute the service agreement on-chain using keeper’s ServiceAgreement contract.

The on-chain executeAgreement method requires the following arguments: templateId, signature, consumer, hashes, timeouts, serviceAgreementId, did. agreement_message_hash is necessary to verify the signature. The consumer signature includes the conditions timeouts and parameters values which is usedon-chain to verify that the values actually match the signed hashes.

Parameters
  • did – str representation fo the asset DID. Use this to retrieve the asset DDO.

  • index – str identifies the specific service in the ddo to use in this agreement.

  • agreement_id – 32 bytes identifier created by the consumer and will be used on-chain for the executed agreement.

  • service_agreement_signature – str the signed agreement message hash which includes conditions and their parameters values and other details of the agreement.

  • consumer_address – ethereum account address of consumer, hex str

  • account – Account instance creating the agreement. Can be either the consumer, publisher or provider

  • auto_consume – bool

Returns

dict the executeAgreement transaction receipt

get(agreement_id)

Retrieve the agreement data of agreement_id.

Parameters

agreement_id – id of the agreement, hex str

Returns

AgreementValues instance – a namedtuple with the following attributes:

did, owner, template_id, condition_ids, updated_by, block_number_updated

is_access_granted(agreement_id, did, consumer_address)

Check permission for the agreement.

Verify on-chain that the consumer_address has permission to access the given asset did according to the agreement_id.

Parameters
  • agreement_id – id of the agreement, hex str

  • did – DID, str

  • consumer_address – ethereum account address of consumer, hex str

Returns

bool True if user has permission

static new()
prepare(did, consumer_account, service_index)
Parameters
  • did – str representation fo the asset DID. Use this to retrieve the asset DDO.

  • consumer_account – Account instance of the consumer

  • service_index – int identifies the specific service in the ddo to use in this agreement.

Returns

tuple (agreement_id: str, signature: hex str)

sign(agreement_id, did, consumer_account, service_index)

Sign a service agreement.

Parameters
  • agreement_id – 32 bytes identifier created by the consumer and will be used on-chain for the executed agreement.

  • did – str representation fo the asset DID. Use this to retrieve the asset DDO.

  • consumer_account – Account instance of the consumer

  • service_index – int identifies the specific service in the ddo to use in this agreement.

Returns

signature

status(agreement_id)

Get the status of a service agreement.

Parameters

agreement_id – id of the agreement, hex str

Returns

dict with condition status of each of the agreement’s conditions or None if the

agreement is invalid.