diff --git a/runtime/sema/account.cdc b/runtime/sema/account.cdc index d7e9aa83d1..2b227886f4 100644 --- a/runtime/sema/account.cdc +++ b/runtime/sema/account.cdc @@ -445,38 +445,7 @@ entitlement IssueAccountCapabilityController /* Entitlement mappings */ entitlement mapping AccountMapping { - // TODO: include Identity - - Storage -> Storage - Contracts -> Contracts - Keys -> Keys - Inbox -> Inbox - Capabilities -> Capabilities - - SaveValue -> SaveValue - LoadValue -> LoadValue - BorrowValue -> BorrowValue - - AddContract -> AddContract - UpdateContract -> UpdateContract - RemoveContract -> RemoveContract - - AddKey -> AddKey - RevokeKey -> RevokeKey - - PublishInboxCapability -> PublishInboxCapability - UnpublishInboxCapability -> UnpublishInboxCapability - - StorageCapabilities -> StorageCapabilities - AccountCapabilities -> AccountCapabilities - - GetStorageCapabilityController -> GetStorageCapabilityController - IssueStorageCapabilityController -> IssueStorageCapabilityController - - GetAccountCapabilityController -> GetAccountCapabilityController - IssueAccountCapabilityController -> IssueAccountCapabilityController - - // --- + include Identity Storage -> SaveValue Storage -> LoadValue @@ -498,20 +467,7 @@ entitlement mapping AccountMapping { } entitlement mapping CapabilitiesMapping { - // TODO: include Identity - - Capabilities -> Capabilities - - StorageCapabilities -> StorageCapabilities - AccountCapabilities -> AccountCapabilities - - GetStorageCapabilityController -> GetStorageCapabilityController - IssueStorageCapabilityController -> IssueStorageCapabilityController - - GetAccountCapabilityController -> GetAccountCapabilityController - IssueAccountCapabilityController -> IssueAccountCapabilityController - - // --- + include Identity StorageCapabilities -> GetStorageCapabilityController StorageCapabilities -> IssueStorageCapabilityController diff --git a/runtime/sema/account.gen.go b/runtime/sema/account.gen.go index f67d7e18a8..43b85befa4 100644 --- a/runtime/sema/account.gen.go +++ b/runtime/sema/account.gen.go @@ -1928,92 +1928,9 @@ var IssueAccountCapabilityControllerType = &EntitlementType{ } var AccountMappingType = &EntitlementMapType{ - Identifier: "AccountMapping", + Identifier: "AccountMapping", + IncludesIdentity: true, Relations: []EntitlementRelation{ - EntitlementRelation{ - Input: StorageType, - Output: StorageType, - }, - EntitlementRelation{ - Input: ContractsType, - Output: ContractsType, - }, - EntitlementRelation{ - Input: KeysType, - Output: KeysType, - }, - EntitlementRelation{ - Input: InboxType, - Output: InboxType, - }, - EntitlementRelation{ - Input: CapabilitiesType, - Output: CapabilitiesType, - }, - EntitlementRelation{ - Input: SaveValueType, - Output: SaveValueType, - }, - EntitlementRelation{ - Input: LoadValueType, - Output: LoadValueType, - }, - EntitlementRelation{ - Input: BorrowValueType, - Output: BorrowValueType, - }, - EntitlementRelation{ - Input: AddContractType, - Output: AddContractType, - }, - EntitlementRelation{ - Input: UpdateContractType, - Output: UpdateContractType, - }, - EntitlementRelation{ - Input: RemoveContractType, - Output: RemoveContractType, - }, - EntitlementRelation{ - Input: AddKeyType, - Output: AddKeyType, - }, - EntitlementRelation{ - Input: RevokeKeyType, - Output: RevokeKeyType, - }, - EntitlementRelation{ - Input: PublishInboxCapabilityType, - Output: PublishInboxCapabilityType, - }, - EntitlementRelation{ - Input: UnpublishInboxCapabilityType, - Output: UnpublishInboxCapabilityType, - }, - EntitlementRelation{ - Input: StorageCapabilitiesType, - Output: StorageCapabilitiesType, - }, - EntitlementRelation{ - Input: AccountCapabilitiesType, - Output: AccountCapabilitiesType, - }, - EntitlementRelation{ - Input: GetStorageCapabilityControllerType, - Output: GetStorageCapabilityControllerType, - }, - EntitlementRelation{ - Input: IssueStorageCapabilityControllerType, - Output: IssueStorageCapabilityControllerType, - }, - EntitlementRelation{ - Input: GetAccountCapabilityControllerType, - Output: GetAccountCapabilityControllerType, - }, - EntitlementRelation{ - Input: IssueAccountCapabilityControllerType, - Output: IssueAccountCapabilityControllerType, - }, EntitlementRelation{ Input: StorageType, Output: SaveValueType, @@ -2070,36 +1987,9 @@ var AccountMappingType = &EntitlementMapType{ } var CapabilitiesMappingType = &EntitlementMapType{ - Identifier: "CapabilitiesMapping", + Identifier: "CapabilitiesMapping", + IncludesIdentity: true, Relations: []EntitlementRelation{ - EntitlementRelation{ - Input: CapabilitiesType, - Output: CapabilitiesType, - }, - EntitlementRelation{ - Input: StorageCapabilitiesType, - Output: StorageCapabilitiesType, - }, - EntitlementRelation{ - Input: AccountCapabilitiesType, - Output: AccountCapabilitiesType, - }, - EntitlementRelation{ - Input: GetStorageCapabilityControllerType, - Output: GetStorageCapabilityControllerType, - }, - EntitlementRelation{ - Input: IssueStorageCapabilityControllerType, - Output: IssueStorageCapabilityControllerType, - }, - EntitlementRelation{ - Input: GetAccountCapabilityControllerType, - Output: GetAccountCapabilityControllerType, - }, - EntitlementRelation{ - Input: IssueAccountCapabilityControllerType, - Output: IssueAccountCapabilityControllerType, - }, EntitlementRelation{ Input: StorageCapabilitiesType, Output: GetStorageCapabilityControllerType, diff --git a/runtime/sema/gen/main.go b/runtime/sema/gen/main.go index e2c223ce4d..798302f973 100644 --- a/runtime/sema/gen/main.go +++ b/runtime/sema/gen/main.go @@ -1732,13 +1732,21 @@ func entitlementMapTypeLiteral(name string, elements []ast.EntitlementMapElement // } // } + includesIdentity := false relationExprs := make([]dst.Expr, 0, len(elements)) for _, element := range elements { - relation, ok := element.(*ast.EntitlementMapRelation) - if !ok { - panic(fmt.Errorf("non-relation map element is not supported: %s", element)) + relation, isRelation := element.(*ast.EntitlementMapRelation) + include, isInclude := element.(*ast.NominalType) + if !isRelation && !isInclude { + panic(fmt.Errorf("invalid map element: expected relations or include, got '%s'", element)) + } + if isInclude && include.Identifier.Identifier == "Identity" { + includesIdentity = true + continue + } else if isInclude { + panic(fmt.Errorf("non-Identity map include is not supported: %s", element)) } relationExpr := &dst.CompositeLit{ @@ -1768,6 +1776,7 @@ func entitlementMapTypeLiteral(name string, elements []ast.EntitlementMapElement Type: dst.NewIdent("EntitlementMapType"), Elts: []dst.Expr{ goKeyValue("Identifier", goStringLit(name)), + goKeyValue("IncludesIdentity", goBoolLit(includesIdentity)), goKeyValue("Relations", relationsExpr), }, }, diff --git a/runtime/sema/gen/testdata/entitlement.cdc b/runtime/sema/gen/testdata/entitlement.cdc index c0b0a55564..b338c37c4a 100644 --- a/runtime/sema/gen/testdata/entitlement.cdc +++ b/runtime/sema/gen/testdata/entitlement.cdc @@ -5,3 +5,8 @@ entitlement Bar entitlement mapping Baz { Foo -> Bar } + +entitlement mapping Qux { + include Identity + Foo -> Bar +} \ No newline at end of file diff --git a/runtime/sema/gen/testdata/entitlement.golden.go b/runtime/sema/gen/testdata/entitlement.golden.go index ee860913a5..0296d081f3 100644 --- a/runtime/sema/gen/testdata/entitlement.golden.go +++ b/runtime/sema/gen/testdata/entitlement.golden.go @@ -28,7 +28,19 @@ var BarType = &EntitlementType{ } var BazType = &EntitlementMapType{ - Identifier: "Baz", + Identifier: "Baz", + IncludesIdentity: false, + Relations: []EntitlementRelation{ + EntitlementRelation{ + Input: FooType, + Output: BarType, + }, + }, +} + +var QuxType = &EntitlementMapType{ + Identifier: "Qux", + IncludesIdentity: true, Relations: []EntitlementRelation{ EntitlementRelation{ Input: FooType, @@ -40,6 +52,8 @@ var BazType = &EntitlementMapType{ func init() { BuiltinEntitlementMappings[BazType.Identifier] = BazType addToBaseActivation(BazType) + BuiltinEntitlementMappings[QuxType.Identifier] = QuxType + addToBaseActivation(QuxType) BuiltinEntitlements[FooType.Identifier] = FooType addToBaseActivation(FooType) BuiltinEntitlements[BarType.Identifier] = BarType