Skip to content

Commit

Permalink
DSNP on Frequency (#197)
Browse files Browse the repository at this point in the history
The pre-release of DSNP on Frequency

https://github.com/LibertyDSNP/spec/milestone/3
  • Loading branch information
wilwade authored Sep 19, 2022
1 parent d85ae8f commit c277cb6
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 9 deletions.
14 changes: 9 additions & 5 deletions .yaspellerrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@
"Kotlin",
"LibertyDSNP",
"Lookups",
"MSAs",
"Markdown",
"Mastodon",
"MessagePack",
"MongoDB",
"NodeJS",
"Nonces",
"OpenZeppelin",
"pre-1",
"Payload",
"PrivateBroadcast",
"PrivateGraph",
"PrivateGraphChange",
Expand All @@ -69,6 +70,7 @@
"Reddit",
"RocksDB",
"SQLite",
"TypeScript",
"URL[s]?",
"UpgradeableBeacon",
"WebM",
Expand All @@ -92,6 +94,7 @@
"ecrecover",
"emoji",
"enum[s]?",
"extrinsics",
"followee",
"foundational",
"fromAddress",
Expand All @@ -100,8 +103,8 @@
"hostnames",
"https",
"implementers",
"indexers",
"inReplyTo",
"indexers",
"internationalization",
"keccak",
"keyList",
Expand All @@ -116,6 +119,7 @@
"officiation",
"parseable",
"permissioned",
"pre-1",
"prepended",
"prosumer",
"regex",
Expand All @@ -139,14 +143,14 @@
"timestamps",
"toAddress",
"tombstoned",
"TypeScript",
"unencrypted",
"unfollow[s]?",
"unfollow(s|ed|ing)",
"unfollow[s]?",
"unicode",
"url",
"validator",
"vanishingly",
"versioning"
"versioning",
"websocket"
]
}
2 changes: 1 addition & 1 deletion pages/DSNP/Announcements.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ That produced Batch Publications that were generic and disconnected from the use
They could be submitted to the chain via anyone not just delegates or users.

In DSNP v1.1, Announcement signatures were removed in favor of the implementation being responsible for the connection between the on-chain signature and the user.
The expected and [EVM implementation](../Ethereum/Validation.md) is that the implementation chain requires that the transaction that produces a Batch be performed by the user or delegate directly.
Implementations require that the transaction that produces a Batch be performed by the user or delegate directly.
This created batches that are delegate specific, but allows for faster testing of the validity of individual Announcements in a Batch.

For more information see [DIP-145](https://github.com/LibertyDSNP/spec/issues/145).
2 changes: 2 additions & 0 deletions pages/Ethereum/Overview.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Ethereum/EVM Compatible DSNP Implementation
__Version 1.1.0__

### Deprecation Warning: EVM implementation is deprecated in favor of the [Frequency Implementation](../Frequency/Overview.md)

DSNP on Ethereum is designed using smart contracts and log messages.
Smart contracts are used for identity and delegation.
Log messages are used for announcement publishing via batches.
Expand Down
43 changes: 43 additions & 0 deletions pages/Frequency/Identity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Identity

## Purpose

1. Specify how DSNP Identifiers map to Frequency.
1. Specify how the DSNP delegation maps to Frequency.
1. Detail how Frequency matches the ownership requirements of DSNP.

## Details

DSNP uses [Message Source Accounts (MSAs)](https://libertydsnp.github.io/frequency/pallet_msa/index.html) that map directly to a DSNP Identity.

## Identifier

MSAs each receive a unique unsigned 64 bit identifier that is used as the DSNP Id.
These MSAs are pseudo-anonymous identifiers that are associated with one or more public keys.
MSAs can be created by the user or on behalf of the user using a signed authorization.

### Creating a DSNP User Id

1. Generate a [compatible key pair](https://wiki.polkadot.network/docs/learn-keys) in your wallet.
1. Create a Message Source Account (MSA) on Frequency using one of the `create` extrinsics.
1. Wait for the transaction to process.

### Retrieving a DSNP User Id from a Public Key

1. Use the Frequency RPC call `msa_getMsaId` to retrieve the MSA Id from the public key generated in step 1.
1. The MSA Id is the DSNP Id and can be used to generate the [DSNP User URI](../DSNP/Identifiers.md#dsnp-user-uri).

## Ownership

Frequency has a strong ownership model for MSAs.
Ownership of an MSA is controlled by the associated keys.
MSAs are the source for [Messages](https://libertydsnp.github.io/frequency/pallet_messages/index.html) either directly or via delegation.

## Delegation

Frequency allows for delegation to others called [Providers](https://libertydsnp.github.io/frequency/pallet_msa/index.html).
Delegation comes with permissions that grant publishing of specific Schemas to a provider.
Since each [Announcement Type](../DSNP/Announcements.md) has a [set Schema Id](./Publishing.md), a user may permission specific Announcement Types.

When a user delegates to a Provider, that delegation is either validated on-chain or can be validated off-chain using the `msa_checkDelegations` RPC call.
Users can revoke a delegation at anytime without any fees, and revocation is locked to the point the transaction is included in a block.
38 changes: 38 additions & 0 deletions pages/Frequency/Overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Frequency DSNP Implementation (Pre-Release)
__Version pre-1.0.0__

_Final release is pending release of [Frequency v1.0.0](https://github.com/LibertyDSNP/frequency)_

DSNP on Frequency is built using Message Source Accounts (MSAs) for identity and delegation with Schemas defined for each Announcement Type.
Frequency uses Schemas to define how to create and pass messages.

## Links

- [Frequency Documentation](https://libertydsnp.github.io/frequency/)
- [Frequency GitHub](https://github.com/LibertyDSNP/frequency)

## Schemas

Official DSNP Schemas may be found in [GitHub](https://github.com/LibertyDSNP/schemas).

## Libraries
<!-- yaspeller ignore:start -->
| Name | Language(s) |
| --- | --- |
| [TODO]() | JavaScript/TypeScript |
<!-- yaspeller ignore:end -->

<!--- Uncomment for pre-release changes and prefix the version with `pre-[next version]`
## Prerelease Changelog
- [DIP-###](https://github.com/LibertyDSNP/spec/issues/###)
--->
## Releases

| Version | Description | DSNP Compatibility | Release Date | Changelog |
| --- | --- | --- | --- | --- |
| `pre-1.0.0` | Pre-Release | 1.1.x | 2022-09-19 | N/A |
<!--
| [1.0.0](https://github.com/LibertyDSNP/spec/tree/Frequency-v1.0.0) | Initial Release | 1.1.x | 2022-10-15 | [Changelog](https://github.com/LibertyDSNP/spec/releases/tag/Frequency-v1.0.0) |
-->
62 changes: 62 additions & 0 deletions pages/Frequency/Publishing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Announcement Publishing

On Frequency, [Announcements](../DSNP/Announcements.md) are mapped to schemas which in turn publish Frequency Messages.
Frequency Messages are either direct Graph Changes from a particular user, or a Batch Publication with a multitude of users possible.

<!-- Links to https://libertydsnp.github.io/frequency should be updated with links to docs.frequency.xyz when able to be -->

| Announcement Type Enum | Announcement | Batched | Schema Id Mainnet | Schema Id Rococo | Frequency Model Type | Frequency Payload Location |
| --- | --- | --- | --- | --- | --- | --- |
| 0 | [Tombstone](../DSNP/Types/Tombstone.md) | YES | TBD | TBD | [`Parquet`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.ModelType.html#variant.Parquet) | [`IPFS`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.PayloadLocation.html#variant.IPFS) |
| 1 | [Graph Change](../DSNP/Types/GraphChange.md) | no | TBD | TBD | [`AvroBinary`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.ModelType.html#variant.AvroBinary) | [`OnChain`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.PayloadLocation.html#variant.OnChain) |
| 2 | [Broadcast](../DSNP/Types/Broadcast.md) | YES | TBD | TBD | [`Parquet`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.ModelType.html#variant.Parquet) | [`IPFS`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.PayloadLocation.html#variant.IPFS) |
| 3 | [Reply](../DSNP/Types/Reply.md) | YES | TBD | TBD | [`Parquet`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.ModelType.html#variant.Parquet) | [`IPFS`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.PayloadLocation.html#variant.IPFS) |
| 4 | [Reaction](../DSNP/Types/Reaction.md) | YES | TBD | TBD | [`Parquet`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.ModelType.html#variant.Parquet) | [`IPFS`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.PayloadLocation.html#variant.IPFS) |
| 5 | [Profile](../DSNP/Types/Profile.md) | YES | TBD | TBD | [`Parquet`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.ModelType.html#variant.Parquet) | [`IPFS`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.PayloadLocation.html#variant.IPFS) |
| 6 | [Update](../DSNP/Types/Update.md) | YES | TBD | TBD | [`Parquet`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.ModelType.html#variant.Parquet) | [`IPFS`](https://libertydsnp.github.io/frequency/common_primitives/schema/enum.PayloadLocation.html#variant.IPFS) |

Source code for each schema is also located in the [LibertyDSNP/schemas](https://github.com/LibertyDSNP/schemas) repository.

## DSNP Non-Batched Announcements

Frequency uses an on-chain data structure for storage of `GraphChange` Announcements.
Each individual announcement is submitted using the [`add_onchain_message`](https://libertydsnp.github.io/frequency/pallet_messages/pallet/enum.Call.html#variant.add_onchain_message) extrinsic.

## DSNP Batched Announcements

Frequency uses [DSNP Batch Publications](../DSNP/BatchPublications.md) for Announcements that are batched.
The parquet file is stored on [IPFS](https://ipfs.io/), but it is discovered through the Frequency Message.

Frequency Messages maintain the metadata of where and when the Batch Publication was published and which Provider MSA published it.
It is the publisher's responsibility to maintain the [IPFS pin](https://docs.ipfs.tech/concepts/glossary/#pinning) so that the batch file is continuously available.

DSNP Batch Publications [MUST be validated](./Validation.md) upon fetching to ensure data and permission integrity.

## Ordering

Frequency Messages are well ordered within a Schema

1. Frequency: Block number ascending
2. Frequency: Block index ascending
3. DSNP Standard: Order Announcements in a Batch Publication File by row appearance order

### Ordering Across Schemas

Frequency provides complete ordering metadata for Messages across Schemas.
Block index is unique per Message within the same block.

### Human Order

Due to the asynchronous nature of networks and batching, it is possible that the canonical ordering of Announcements is wrong from a human viewpoint.
With dependent Announcements, where one Announcement refers to another Announcement, the order may be inferred differently than the canonical ordering.
It is left to user interfaces to handle these situations.


## Retrieval

Frequency nodes provide an RPC interface [`get_messages_by_schema`](https://libertydsnp.github.io/frequency/pallet_messages_rpc/trait.MessagesApiClient.html#method.get_messages_by_schema) with paginated responses that differ based on the Schema.

Frequency nodes can provide a websocket interface that will emit an event for each block that has one or more messages of a given schema in that block.
The [`MessagesStored`](https://libertydsnp.github.io/frequency/pallet_messages/pallet/enum.Event.html#variant.MessagesStored) event can be used to know when to call the RPC interface to retrieve the messages.

See the [Frequency Documentation](https://libertydsnp.github.io/frequency/pallet_messages_rpc/trait.MessagesApiClient.html#method.get_messages_by_schema) for more details on Message retrieval.
54 changes: 54 additions & 0 deletions pages/Frequency/Validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Announcement Validation

DSNP Announcements are validated differently depending on the type of Announcement.
Batched Announcements are off-chain and MUST be validated at read time.
Non-batched Announcements (example: Graph Change), are on-chain and are validated at write time and do not need to be re-validated at read time.

## On-chain Announcements

Creation of an Announcement as an on-chain Frequency Message requires that the delegation be validated before adding the message to the chain.
Thus, any Graph Change Announcements read from a trusted node, can be trusted to have been made by the DSNP identity or a delegate of the identity at the time the Frequency Message was sent.

### On-Chain Announcement Types
- Graph Change


## Batch Publication Announcements

DSNP Announcements that are in a Batch Publication MUST be validated at read time.

### Batched Announcement Types
- Tombstone
- Broadcast
- Reply
- Reaction
- Profile

<!-- Links to https://libertydsnp.github.io/frequency should be updated with links to docs.frequency.xyz when able to be -->

## Batch Publication Frequency Message Validation

The [Frequency Message](https://libertydsnp.github.io/frequency/common_primitives/messages/struct.MessageResponse.html) for a Batch Publication has several important fields for validation:

| Field | Description |
| ----- | ----------- |
| `provider_msa_id` | MSA Id of the provider sending the message |
| `cid` | The [Content IDentifier v1](https://github.com/multiformats/cid/) for IPFS content |
| `payload_length` | Expected length of the content from IPFS |
| `block_number` | Block number that the message was recorded on the chain. |

### File Validation

1. Retrieve the file from the IPFS network using the `cid`.
1. (Required for non-trusted IPFS nodes) Verify the file hash by [comparing it to the hash included in the `cid`](https://docs.ipfs.tech/concepts/hashing/).
1. Verify that the byte length of the retrieved file matches the `payload_length`.

### Publication Announcements Validation

1. Collect the unique set of `fromId` values.
1. Use the [Custom RPC `msa_checkDelegations`](https://libertydsnp.github.io/frequency/pallet_msa_rpc/trait.MsaApiClient.html#method.check_delegations) with the `fromId` values as the `delegator_msa_ids` and the `provider_msa_id` at the `block_number`.
1. The `fromId` values that `msa_checkDelegations` verifies as having a delegation at `block_number` are valid Announcements.

## Announcement Duplicates

Duplicate Announcements MUST be rejected or ignored.
3 changes: 2 additions & 1 deletion pages/Implementations.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# DSNP Implementations

- [Ethereum/EVM Compatible](Ethereum/Overview.md) (Official)
- [Frequency](Frequency/Overview.md) (Official)
- [Ethereum/EVM Compatible](Ethereum/Overview.md) (Deprecated)
6 changes: 5 additions & 1 deletion pages/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
- [Update](DSNP/Types/Update.md)
- [Serializations](DSNP/Serializations.md)
- [DSNP Implementation Specs](Implementations.md)
- [EVM](Ethereum/Overview.md)
- [Frequency](Frequency/Overview.md)
- [Identity](Frequency/Identity.md)
- [Publishing](Frequency/Publishing.md)
- [Validation](Frequency/Validation.md)
- [EVM (Deprecated)](Ethereum/Overview.md)
- [Identity](Ethereum/Identity.md)
- [Identifiers](Ethereum/Identifiers.md)
- [Factory](Ethereum/IdentityFactory.md)
Expand Down
2 changes: 1 addition & 1 deletion pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ There are three core specifications currently.
| Name | Version | Description |
| --- | --- | --- |
| [DSNP](DSNP/Overview.md) | 1.1.0 | The implementation-agnostic DSNP specification |
| [DSNP Implementations](Implementations.md) | - | Implementation-specific specifications |
| [DSNP on Frequency (Pre-release)](Frequency/Overview.md) | pre-1.0.0 | Frequency implementation for DSNP specification |
| [Activity Content](ActivityContent/Overview.md) | 1.1.0 | A specification for DSNP-referenced content (subset of W3C Activity Streams) |

Each specification is divided into several modules.
Expand Down

0 comments on commit c277cb6

Please sign in to comment.