Skip to content

Commit 3155dd8

Browse files
ellaking94fadeevab
andcommitted
nep-393: add class metadata interface (#528)
In near/NEPs#393 we defined Issuer (an entity authorized to mint SBTs in the registry) and SBT Class. We also defined Issuer Metadata and Token Metadata, but we didn't provide interface for class metadata. This was implemented in the reference implementation (in one of the subsequent revisions), but was not backported to the NEP. In this PR * we fix the name of the issuer interface from `SBTContract` to `SBTIssuer`. The original name is wrong and we oversight it in reviews. We talk everywhere about the issuer entity and issuer contract (even the header is _SBT Issuer interface_). * Renames `ContractMetadata` to `IssuerMetadata`. * added `ClassMetadata` struct and `sbt_class_metadata` function to the `SBTIssuer`. --------- Co-authored-by: Alexander Fadeev <fadeevab.com@gmail.com>
1 parent b6bfde8 commit 3155dd8

1 file changed

Lines changed: 51 additions & 7 deletions

File tree

neps/nep-0393.md

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,9 @@ The Soulbound Token follows the NFT [NEP-171](https://github.com/near/NEPs/blob/
269269
All time related attributes are defined in milliseconds (as per NEP-171).
270270

271271
```rust
272-
/// ContractMetadata defines contract wide attributes, which describes the whole contract.
273-
pub struct ContractMetadata {
272+
/// IssuerMetadata defines contract wide attributes, which describes the whole contract.
273+
/// Must be provided by the Issuer contract. See the `SBTIssuer` trait.
274+
pub struct IssuerMetadata {
274275
/// Version with namespace, example: "sbt-1.0.0". Required.
275276
pub spec: String,
276277
/// Issuer Name, required, ex. "Mosaics"
@@ -290,6 +291,25 @@ pub struct ContractMetadata {
290291
pub reference_hash: Option<Base64VecU8>,
291292
}
292293

294+
/// ClassMetadata defines SBT class wide attributes, which are shared and default to all SBTs of
295+
/// the given class. Must be provided by the Issuer contract. See the `SBTIssuer` trait.
296+
pub struct ClassMetadata {
297+
/// Issuer class name. Required to be not empty.
298+
pub name: String,
299+
/// If defined, should be used instead of `IssuerMetadata::symbol`.
300+
pub symbol: Option<String>,
301+
/// An URL to an Icon. To protect fellow developers from unintentionally triggering any
302+
/// SSRF vulnerabilities with URL parsers, we don't allow to set an image bytes here.
303+
/// If it doesn't start with a scheme (eg: https://) then `IssuerMetadata::base_uri`
304+
/// should be prepended.
305+
pub icon: Option<String>,
306+
/// JSON or an URL to a JSON file with more info. If it doesn't start with a scheme
307+
/// (eg: https://) then base_uri should be prepended.
308+
pub reference: Option<String>,
309+
/// Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
310+
pub reference_hash: Option<Base64VecU8>,
311+
}
312+
293313
/// TokenMetadata defines attributes for each SBT token.
294314
pub struct TokenMetadata {
295315
pub class: ClassId, // token class. Required. Must be non zero.
@@ -448,12 +468,18 @@ Example **Soul Transfer** interface:
448468

449469
### SBT Issuer interface
450470

451-
SBTContract is the minimum required interface to be implemented by issuer. Other methods, such as a mint function, which requests the registry to proceed with token minting, is specific to an Issuer implementation (similarly, mint is not part of the FT standard).
471+
SBTIssuer is the minimum required interface to be implemented by issuer. Other methods, such as a mint function, which requests the registry to proceed with token minting, is specific to an Issuer implementation (similarly, mint is not part of the FT standard).
472+
473+
The issuer must provide metadata object of the Issuer. Optionally, Issuer can also provide metadata object for each token class.
474+
Issuer level (contract) metadata, must provide information common to all tokens and all classes defined by the issuer. Class level metadata, must provide information common to all tokens of a given class. Information should be deduplicated and denormalized whenever possible.
475+
Example: The issuer can set a default icon for all tokens (SBT) using `IssuerMetadata::icon` and additionally it can customize an icon of a particular token via `TokenMetadata::icon`.
452476

453477
```rust
454-
pub trait SBTContract {
455-
/// returns contract metadata
456-
fn sbt_metadata(&self) -> ContractMetadata;
478+
pub trait SBTIssuer {
479+
/// Returns contract metadata.
480+
fn sbt_metadata(&self) -> IssuerMetadata;
481+
/// Returns SBT class metadata, or `None` if the class is not found.
482+
fn sbt_class_metadata(&self, class: ClassId) -> Option<ClassMetadata>;
457483
}
458484
```
459485

@@ -594,7 +620,7 @@ trait SBT {
594620

595621
## Reference Implementation
596622

597-
- Common [type definitions](https://github.com/near-ndc/i-am-human/tree/main/contracts/sbt) (events, traits).
623+
- Common [type definitions](https://github.com/near-ndc/i-am-human/tree/master/contracts/sbt) (events, traits).
598624
- [I Am Human](https://github.com/near-ndc/i-am-human) registry and issuers.
599625

600626
## Consequences
@@ -667,6 +693,24 @@ The Contract Standards Working Group members approved this NEP on June 30, 2023
667693
| 9 | [Privacy](https://github.com/near/NEPs/pull/393/#issuecomment-1504309947) | Concerns have been addressed: [comment-1](https://github.com/near/NEPs/pull/393/#issuecomment-1504485420) and [comment2](https://github.com/near/NEPs/pull/393/#issuecomment-1505958549) | resolved |
668694
| 10 | @frol [suggested](https://github.com/near/NEPs/pull/393/#discussion_r1247879778) to use a struct in `sbt_recover` and `sbt_soul_transfer`. | Motivation to use pair `(number, bool)` rather than follow a common Iterator Pattern. Rust uses `Option` type for that, that works perfectly for languages with native Option type, but creates a "null" problem for anything else. Other common way to implement Iterator is the presented pair, which doesn't require extra type definition and reduces code size. | new |
669695

696+
697+
### v1.1.0
698+
699+
700+
In v1.0.0 we defined Issuer (an entity authorized to mint SBTs in the registry) and SBT Class. We also defined Issuer Metadata and Token Metadata, but we didn't provide interface for class metadata. This was implemented in the reference implementation (in one of the subsequent revisions), but was not backported to the NEP. This update:
701+
702+
- Fixes the name of the issuer interface from `SBTContract` to `SBTIssuer`. The original name is wrong and we oversight it in reviews. We talk everywhere about the issuer entity and issuer contract (even the header is SBT Issuer interface).
703+
- Renames `ContractMetadata` to `IssuerMetadata`.
704+
- Adds `ClassMetadata` struct and `sbt_class_metadata` function to the `SBTIssuer` interface.
705+
706+
Reference implementation: [ContractMetadata, ClassMetadata, TokenMetadata](https://github.com/near-ndc/i-am-human/blob/registry/v1.8.0/contracts/sbt/src/metadata.rs#L18) and [SBTIssuer interface](https://github.com/near-ndc/i-am-human/blob/registry/v1.8.0/contracts/sbt/src/lib.rs#L49).
707+
708+
#### Benefits
709+
710+
- Improves the documentation and meaning of the issuer entity.
711+
- Adds missing `ClassMetadata`.
712+
- Improves issuer, class and token metadata documentation.
713+
670714
## Copyright
671715

672716
[Creative Commons Attribution 4.0 International Public License (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/)

0 commit comments

Comments
 (0)