How To Use

Authorizers can be used for a wide variety of use cases, not only for signature authentication. Signature authentication should be the base of all authorizers, but you can build other authentication requirements for different use cases.

The main DHTProtocol takes in an authorizer as a parameter that will verify all communication between requests and responses.

The main DHTProtocol is created by the DHT class, and the authorizer parameter is sent in as a kwargs:

authorizer = RSAProofOfStakeAuthorizer(...)
self.dht = DHT(
    initial_peers=initial_peers,
    start=True,
    num_workers=DEFAULT_NUM_WORKERS,
    use_relay=use_relay,
    use_auto_relay=use_auto_relay,
    client_mode=reachable_via_relay,
    record_validators=[MockRecordValidator()],
    **dict(kwargs, authorizer=authorizer)
)

When building application logic protocols, always use an authorizer (see the Protocols example).

If the protocols built for the subnet require peer-to-peer communication, you can initialize or create the protocol with an authorizer, such as:

protocol_authorizer = TokenRSAAuthorizerBase(...)
self.mock_protocol = MockProtocol(
    dht=dht,
    subnet_id=subnet_id,
    hypertensor=Hypertensor(),
    authorizer=protocol_authorizer,
    start=True
)

Last updated