NPL Access Evaluation
Evaluating Protocol Access
Within NPL, there is no JWT, only an NPL Party type.
The bound claims are specified during instantiation of such a Party
.
To create an instance of an NPL Party, use the partyOf method.
In order to compare an NPL Party to another or access its claims, see NPL Party methods.
In the following example the bound claims are those of ISSUER
and PAYEE
, respectively
function getIssuerParty() returns Party -> {
return partyOf(
mapOf(Pair("party", setOf("issuer"))),
mapOf<Text, Set<Text>>()
);
};
function getPayeeParty() returns Party -> {
return partyOf(
mapOf(Pair("party", setOf("payee"))),
mapOf<Text, Set<Text>>()
);
};
@test
function test_instantiation(test: Test) -> {
var issuer = getIssuerParty();
var payee = getPayeeParty();
var iou = Iou[issuer, payee](100);
};
Propagation
As seen here it is possible to refer to other protocols. When calling a permission of a protocol reference, the same access evaluation process happens. Since we are operating within NPL, we have at least one calling party and one bound party. Assuming that the calling party has access to the protocol reference, as soon as access is given and the permission is executed, party representation takes place. Party representation is when the calling party becomes the bound party on the called protocol. The calling party has the right to represent the bound party because of the matching claims. However, in this context, the calling party is now known as the bound party.
Example
In the following example, the landlord collects rent and deposits it in the bank. In the RentalContract
the party is
known as the landlord but when deposit
is called, the party is no longer the landlord
but the accountHolder
. The
landlord
is now representing the accountHolder
party. The landlord
party has the access to represent the
accountHolder
and in effect, becomes the accountHolder
. Practically, this means that the claims are now identical to
those that were originally bound during the Bank instantiation. That is to say, any claims that the landlord
party had
that the accountHolder
didn't, are not transferred to the accountHolder
. landlord
is not known to the Bank
protocol.
Note: See Claims Evaluation for matching rules
protocol[renter] Renter() {
permission[renter] payRent(amount: Number) returns Number { return 100; };
};
protocol[accountHolder] Bank() {
permission[accountHolder] deposit(amount: Number) { };
};
protocol[landlord, renter] RentalContract(var rent: Renter, var bank: Bank) {
@api
permission[landlord] collect(amount: Number) {
bank.deposit[landlord](
rent.payRent[renter](amount)
);
};
};