Skip to content

Commit 6cebb0b

Browse files
authored
Merge pull request #246 from onflow/contracts-keys-inbox
Edit Accounts Keys and Inbox articles
2 parents 3b57ec0 + 0c4c45e commit 6cebb0b

2 files changed

Lines changed: 47 additions & 92 deletions

File tree

docs/language/accounts/inbox.mdx

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ title: Inbox
33
sidebar_position: 6
44
---
55

6-
Accounts have an inbox,
7-
which allows making [capabilities](../capabilities.md) available to specific accounts.
8-
The inbox provides a convenient way to "bootstrap" capabilities:
9-
setting up an initial connection between two accounts,
10-
that the accounts can use to transfer data or perform actions.
6+
Accounts have an inbox, which allows making [capabilities] available to specific accounts. The inbox provides a convenient way to _bootstrap_ capabilities, which sets up an initial connection between two accounts that the accounts can use to transfer data or perform actions.
117

12-
An account exposes its inbox through the `inbox` field,
13-
which has the type `Account.Inbox`.
8+
An account exposes its inbox through the `inbox` field, which has the type `Account.Inbox`.
149

1510
## `Account.Inbox`
1611

@@ -50,25 +45,18 @@ entitlement ClaimInboxCapability
5045

5146
## Publishing a capability to the account inbox
5247

53-
An account (the provider) that would like to provide a capability to another account (the recipient)
54-
can do so using the `publish` function:
48+
An account (the provider) that would like to provide a capability to another account (the recipient) can do so using the `publish` function:
5549

5650
```cadence
5751
access(Inbox | PublishInboxCapability)
5852
fun publish(_ value: Capability, name: String, recipient: Address)
5953
```
6054

61-
Calling the `publish` function requires access to an account via a reference which is authorized
62-
with the coarse-grained `Inbox` entitlement (`auth(Inbox) &Account`),
63-
or the fine-grained `PublishInboxCapability` entitlement (`auth(PublishInboxCapability) &Account`).
55+
Calling the `publish` function requires access to an account via a reference, which is authorized with the coarse-grained `Inbox` entitlement (`auth(Inbox) &Account`), or the fine-grained `PublishInboxCapability` entitlement (`auth(PublishInboxCapability) &Account`).
6456

65-
The function publishes the specified capability using the provided string as an identifier, to be later claimed by the recipient.
66-
Note, however, that until the recipient claims the capability, the provider's account stores it,
67-
and the capability contributes towards the provider's account storage usage.
57+
The function publishes the specified capability using the provided string as an identifier, to be later claimed by the recipient. Note, however, that until the recipient claims the capability, the provider's account stores it, and the capability contributes towards the provider's account storage usage.
6858

69-
Calling this function emits an event, `InboxValuePublished`,
70-
that includes the address of both the provider and the recipient, as well as the name and the type of the published capability.
71-
Refer to the [Core Events page](../core-events.md#inbox-value-published) for more details on this event.
59+
Calling this function emits an event, `InboxValuePublished`, that includes the address of both the provider and the recipient, as well as the name and the type of the published capability. Refer to [Inbox Value Published] for more details on this event.
7260

7361
## Claiming a capability from the account inbox
7462

@@ -79,55 +67,40 @@ access(Inbox | ClaimInboxCapability)
7967
fun claim<T: &Any>(_ name: String, provider: Address): Capability<T>?
8068
```
8169

82-
Calling the `claim` function requires access to an account via a reference which is authorized
83-
with the coarse-grained `Inbox` entitlement (`auth(Inbox) &Account`),
84-
or the fine-grained `ClaimInboxCapability` entitlement (`auth(ClaimInboxCapability) &Account`).
70+
Calling the `claim` function requires access to an account via a reference, which is authorized with the coarse-grained `Inbox` entitlement (`auth(Inbox) &Account`), or the fine-grained `ClaimInboxCapability` entitlement (`auth(ClaimInboxCapability) &Account`).
8571

86-
If the provider's inbox has a capability stored under the provided name,
87-
the calling recipient is the intended recipient,
88-
and it conforms to the provided type argument,
89-
then the function removes the capability from the provider's inbox and returns it.
72+
If the provider's inbox has a capability stored under the provided name, the calling recipient is the intended recipient, and it conforms to the provided type argument, then the function removes the capability from the provider's inbox and returns it.
9073

91-
If the provider's inbox has no capability stored under the provided name,
92-
or if the calling recipient is not the intended recipient,
93-
the function returns `nil`.
94-
If the borrow type of the capability is not a subtype of the provided type argument,
95-
the program aborts.
74+
If the provider's inbox has no capability stored under the provided name, or if the calling recipient is not the intended recipient, the function returns `nil`. If the borrow type of the capability is not a subtype of the provided type argument, the program aborts.
9675

9776
:::tip
9877

9978
It is only possible to claim a capability once.
10079

10180
:::
10281

103-
Calling function `claim` function emits an event, `InboxValueClaimed`,
104-
that includes the address of both the provider and the recipient,
105-
as well as the name of the claimed capability.
106-
Refer to the [Core Events page](../core-events.md#inbox-value-claimed) for more details on this event.
82+
Calling the `claim` function emits an event, `InboxValueClaimed`, that includes the address of both the provider and the recipient, as well as the name of the claimed capability. Refer to [Inbox Value Claimed] for more details on this event.
10783

10884
## Unpublishing a capability from the account inbox
10985

110-
If the provider no longer wishes to publish a capability for some reason,
111-
they can unpublish the capability using the `unpublish` function:
86+
If the provider no longer wishes to publish a capability for some reason, they can unpublish the capability using the `unpublish` function:
11287

11388
```cadence
11489
access(Inbox | UnpublishInboxCapability)
11590
fun unpublish<T: &Any>(_ name: String): Capability<T>?
11691
```
11792

118-
Calling the `unpublish` function requires access to an account via a reference which is authorized
119-
with the coarse-grained `Inbox` entitlement (`auth(Inbox) &Account`),
120-
or the fine-grained `UnpublishInboxCapability` entitlement (`auth(UnpublishInboxCapability) &Account`).
93+
Calling the `unpublish` function requires access to an account via a reference, which is authorized with the coarse-grained `Inbox` entitlement (`auth(Inbox) &Account`), or the fine-grained `UnpublishInboxCapability` entitlement (`auth(UnpublishInboxCapability) &Account`).
12194

122-
If the provider's inbox has a capability stored under the provided name,
123-
and it conforms to the provided type argument,
124-
then the function removes the capability from the inbox and returns it.
95+
If the provider's inbox has a capability stored under the provided name, and it conforms to the provided type argument, then the function removes the capability from the inbox and returns it.
12596

126-
If the provider's inbox has no capability stored under the provided name,
127-
the function returns `nil`.
128-
If the borrow type of the capability is not a subtype of the provided type argument,
129-
the program aborts.
97+
If the provider's inbox has no capability stored under the provided name, the function returns `nil`. If the borrow type of the capability is not a subtype of the provided type argument, the program aborts.
13098

131-
Calling the `unpublish` function emits an event, `InboxValueUnpublished`,
132-
that includes the address of the provider, and the name of the unpublished capability.
133-
Refer to the [Core Events page](../core-events.md#inbox-value-unpublished) for more details on this event.
99+
Calling the `unpublish` function emits an event, `InboxValueUnpublished`, which includes the address of the provider and the name of the unpublished capability. Refer to [Inbox Value Unpublished] for more details on this event.
100+
101+
<!-- Relative links. Will not render on the page -->
102+
103+
[capabilities]: ../capabilities.md
104+
[Inbox Value Published]: ../core-events.md#inbox-value-published
105+
[Inbox Value Claimed]: ../core-events.md#inbox-value-claimed
106+
[Inbox Value Unpublished]: ../core-events.md#inbox-value-unpublished

docs/language/accounts/keys.mdx

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ title: Keys
33
sidebar_position: 4
44
---
55

6-
Accounts have keys associated with them.
7-
When a key is added to an account,
8-
the key can be used to sign a [transaction](../transactions.md),
9-
which in turn gets access the account
10-
and can [perform write operations](./index.mdx#performing-write-operations) on it.
6+
Accounts have keys associated with them. When a key is added to an account, the key can be used to sign a [transaction], which in turn gets access to the account and can [perform write operations] on it.
117

12-
An account exposes its keys through the `keys` field,
13-
which has the type `Account.Keys`.
8+
An account exposes its keys through the `keys` field, which has the type `Account.Keys`.
149

1510
## `Account.Keys`
1611

@@ -24,7 +19,7 @@ struct Keys {
2419
2520
/// Returns the key at the given index, if it exists, or nil otherwise.
2621
///
27-
/// Revoked keys are always returned, but they have `isRevoked` field set to true.
22+
/// Revoked keys are always returned, but they have an `isRevoked` field set to true.
2823
access(all)
2924
view fun get(keyIndex: Int): AccountKey?
3025
@@ -91,48 +86,37 @@ struct AccountKey {
9186
}
9287
```
9388

94-
A valid account key's `publicKey` field is a `PublicKey` of either the
95-
`ECDSA_P256` or `ECDSA_secp256k1` signature algorithm.
96-
Public keys of other signature algorithms supported by Cadence are
97-
not valid account public keys.
89+
A valid account key's `publicKey` field is a `PublicKey` of either the `ECDSA_P256` or `ECDSA_secp256k1` signature algorithm. Public keys of other signature algorithms supported by Cadence are not valid account public keys.
9890

99-
Refer to the [public keys section](../crypto.mdx#public-keys)
100-
for more details on the creation and validity of public keys.
91+
Refer to the [public keys section] for more details on the creation and validity of public keys.
10192

102-
A valid account key's `hashAlgorithm` field is either `SHA2_256` or `SHA3_256`.
103-
All other hash algorithms supported by Cadence are
104-
not valid for hashing with an account key.
93+
A valid account key's `hashAlgorithm` field is either `SHA2_256` or `SHA3_256`. All other hash algorithms supported by Cadence are not valid for hashing with an account key.
10594

106-
Refer to the [hash algorithms section](../crypto.mdx#hash-algorithms)
107-
for more details on hash algorithms.
95+
Refer to the [hash algorithms section] for more details on hash algorithms.
10896

10997
## Getting an account key
11098

11199
The functions `keys.get` and `keys.forEach` allow retrieving the keys of an account.
112100

113-
The `get` function allows retrieving a key with a specific index.
114-
The function returns the key if it exists, and `nil` otherwise.
101+
The `get` function allows retrieving a key with a specific index. The function returns the key if it exists, and `nil` otherwise:
115102

116103
```cadence
117104
access(all)
118105
view fun get(keyIndex: Int): AccountKey?
119106
```
120107

121-
The `forEach` function allows iterating over all keys of an account.
108+
The `forEach` function allows iterating over all keys of an account:
122109

123110
```cadence
124111
access(all)
125112
fun forEach(_ function: fun(AccountKey): Bool)
126113
```
127114

128-
For each key of the account, the `forEach` function calls the given callback, passing the key to it.
129-
When the callback function returns `true` the iteration continues,
130-
and when it returns `false`, iteration stops.
115+
For each key of the account, the `forEach` function calls the given callback, passing the key to it. When the callback function returns `true`, the iteration continues, and when it returns `false`, the iteration stops.
131116

132117
:::warning
133118

134-
The `keys.get` and `keys.forEach` functions include revoked keys,
135-
which have the `isRevoked` field set to `true`.
119+
The `keys.get` and `keys.forEach` functions include revoked keys, which have the `isRevoked` field set to `true`.
136120

137121
:::
138122

@@ -155,7 +139,7 @@ fun main() {
155139

156140
## Adding an account key
157141

158-
The function `keys.add` allows a key to access an account.
142+
The function `keys.add` allows a key to access an account:
159143

160144
```cadence
161145
access(Keys | AddKey)
@@ -166,12 +150,9 @@ fun add(
166150
): AccountKey
167151
```
168152

169-
Calling the `add` function requires access to an account via a reference which is authorized
170-
with the coarse-grained `Keys` entitlement (`auth(Keys) &Account`),
171-
or the fine-grained `AddKey` entitlement (`auth(AddKey) &Account`).
153+
Calling the `add` function requires access to an account via a reference, which is authorized with the coarse-grained `Keys` entitlement (`auth(Keys) &Account`), or the fine-grained `AddKey` entitlement (`auth(AddKey) &Account`).
172154

173-
For example, to add a public key to an existing account,
174-
which signed the transaction:
155+
For example, to add a public key to an existing account that signed the transaction:
175156

176157
```cadence
177158
transaction(publicKey: [UInt8]) {
@@ -190,10 +171,7 @@ transaction(publicKey: [UInt8]) {
190171
}
191172
```
192173

193-
A more complex transaction, which creates an account,
194-
has the signer of the transaction pay for the account creation,
195-
and authorizes one key to access the account,
196-
could look like:
174+
A more complex transaction, which creates an account, has the signer of the transaction pay for the account creation, and authorizes one key to access the account, could look like:
197175

198176
```cadence
199177
transaction(publicKey: [UInt8]) {
@@ -216,19 +194,16 @@ transaction(publicKey: [UInt8]) {
216194

217195
## Revoking an account key
218196

219-
The `revoke` function revokes a key from accessing an account.
220-
The function only marks the key at the given index as revoked, but never deletes it.
197+
The `revoke` function revokes a key from accessing an account. The function only marks the key at the given index as revoked, but never deletes it:
221198

222199
```cadence
223200
access(Keys | RevokeKey)
224201
fun revoke(keyIndex: Int): AccountKey?
225202
```
226203

227-
Calling the `revoke` function requires access to an account via a reference which is authorized
228-
with the coarse-grained `Keys` entitlement (`auth(Keys) &Account`),
229-
or the fine-grained `RevokeKey` entitlement (`auth(RevokeKey) &Account`).
204+
Calling the `revoke` function requires access to an account via a reference, which is authorized with the coarse-grained `Keys` entitlement (`auth(Keys) &Account`), or the fine-grained `RevokeKey` entitlement (`auth(RevokeKey) &Account`).
230205

231-
For example, to revoke the third key of the account which signed the transaction:
206+
For example, to revoke the third key of the account that signed the transaction:
232207

233208
```cadence
234209
transaction {
@@ -238,3 +213,10 @@ transaction {
238213
}
239214
}
240215
```
216+
217+
<!-- Relative links. Will not render on the page -->
218+
219+
[transaction]: ../transactions.md
220+
[perform write operations]: ./index.mdx#performing-write-operations
221+
[public keys section]: ../crypto.mdx#public-keys
222+
[hash algorithms section]: ../crypto.mdx#hash-algorithms

0 commit comments

Comments
 (0)