Andy McDowall
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    [1:][docs.sonr.io] #### A high-level API for interacting with the Sonr ecosystem This design makes choices based on the following tenets: 1. **It should be easy to use.** A. Operations should be performed in the way they'd typically be performed in the target language/ ecosystem. B. Function names should be self-explanatory if possible. 2. **It should be as cheap as possible to perform operations.** A. Cheap means lowering gas and storage costs. B. This can happen through batch and deduplication of operations. ## Bucket API The Bucket data model, from [Sonr ADR-003](https://docs.sonr.io/posts/architecture/adr-003): > The model for a bucket, which will be stored in IPFS, is as follows. > > ``` > type Bucket struct { > Did string > Label string > IsActive bool > EncryptedJwks map[CID]map[PublicKey]EncryptedJWK > Content map[string]CID > } > > type CID string > type PublicKey string > type EncryptedJWK []byte``` ## Global Types ``` type ChannelAddress = Topic | Multiaddr type ContentMap = Map<Label, ContentBuilder> type EncryptedJwk = byte[] type Multiaddr = string type PublicKey = string type Address = string type byte = 0|1|2|...|254|255 //WIP type CID = string type DID = string type Label = string type Topic = string //WIP interface AuthDetails = { } ``` ## class BucketBuilder ### Class-specific types ``` //WIP: TODO: Should be immutable. Enforce w ts? interface BuiltBucket = { label: Label, isActive: boolean, encryptedJwks: (Map<PublicKey, EncryptedJwk>)[], content: Map<Label, byte[]>, } //WIP interface PushParams = Partial<{ }> ``` ### Fields `label: Label`: The label for this Bucket. `content: Map<Label, ContentBuilder>`: The list of ContentBuilders representing this Bucket's content. ### Functions #### `static new(label: Label) : BucketBuilder` Creates a new, empty BucketBuilder. **label (Label)**: The label for the bucket. **Returns**: a new, empty BucketBuilder. #### `static fromDid(bucketDid: DID) : Promise` Creates a new BucketBuilder initialized to the state of the corresponding Bucket on the chain. Throws an error if the is an error with retreiving the Bucket from blockchain or storage. Requires a blockchain or storage read. **bucketDid (DID)**: The DID used to retreive the Bucket. **Returns**: a Promise that returns a BucketBuilder on a success, and an err message on a failure. #### `static push(bucket: BuiltBucket, params: PushParams) : Promise` Pushes the bucket according to the given params. Requires a blockchain or storage write interaction. **bucket (BuiltBucket)**: The bucket to push. **params (PushParams)**: The parameters for pushing. **Returns**: A Promise that returns the BuiltBucket that was pushed on a success, and a error message on a failure. #### `constructor(label: Label, content: Map<Label, ContentBuilder>)` Creates a BucketBuilder with the parameterized fields. This constructor gives complete control of the BucketBuilder, though easier-to-use methods like NewBucket() and GetBucket() should be used instead when possible. **label (Label)**: The label for the bucket. **content (ContentMap)**: The label for the bucket. #### `addNewContent(label: Label) : ContentBuilder` Creates a new, empty ContentBuilder and adds it to the BucketBuilder with the specified label. **label (Label)**: The label for the Content. **Returns**: a new ContentBuilder that can be utilized. #### `addContent(label: Label, content: SonrObject) : ContentBuilder` Adds the specified ContentBuilder, containing content, to the BucketBuilder. **label (Label)**: The label for the Content. **content (SonrObject)**: The content to add. **Returns**: the ContentBuilder that was added to the BucketBuilder. #### `removeContent(label: Label) : ContentBuilder` Removes the ContentBuilder specified by the label. If the ContentBuilder does not exist, this function returns null. **label (Label)**: The label for the ContentBuilder to be removed. **Returns**: the ContentBuilder that was added to the BucketBuilder. #### `build() : BuiltBucket` Creates a BuiltBucket object, which can be used to push to storage and the blockchain. This function errs if WillBuild() returns false or the Bucket cannot be built for some other reason. **Returns**: an intermediary version of the Bucket in the form of a BuiltBucket object. #### `buildAndPush(params: PushParams) : Promise` A convenience function that performs the Build() and Push() operations at the same time. First the BucketBuilder is built, and then it is pushed using the params. The functions errs if willBuild() returns false or the Bucket cannot be built for some other reason. **Returns**: A Promise that returns the BuiltBucket that was pushed on a success, and a error message on a failure. #### `willBuild() : boolean` Determines whether the BucketBuilder will successfully Build(). A build will fail when (but not only when): - A ContentBuilder fails its WillBuild() - The label is empty **Returns**: Whether the BucketBuilder will successfully Build(). #### `setLabel(label: Label)` Sets the label of the BucketBuilder. An empty label will prevent WillBuild() from passing. **label (Label)**: The label for the bucket. ## class ContentBuilder ### Fields `bucketBuilder: BucketBuilder`: A reference to the parent BucketBuilder. `content: SonrObject`: The actual content held by this ContentBuilder. `sharedMembers: Address[]`: The list of Addresses this content should be shared with. ### Functions #### `constructor(bucket: BucketBuilder, content: SonrObject, sharedMembers: Address[])` Creates a new ContentBuilder initialized to the given state. The constructor should only be used if precise control is needed over the creation of a ContentBuilder. Otherwise, used BucketBuilder.addNewContent(). **bucket (BucketBuilder)**: The BucketBuilder that this ContentBuilder is attached to. **content (SonrObject)**: The content the ContentBuilder represents. **sharedMembers (Address[])**: A list of members who should have access to this content. #### `addSharedMember(member: Address) : ContentBuilder` Adds a member for the content to be shared with. **member (Address)**: The member to share the content with. **Returns**: This ContentBuilder. #### `removeSharedMember(member: Address) : ContentBuilder` Removes a member that the content is shared with. **member (Address)**: The member to share the content with. **Returns**: This ContentBuilder. #### `containsSharedMember(member: Address) : ContentBuilder` Determines whether a this content is shared with a particular member. **member (Address)**: The member to check if the content is shared with. **Returns**: This ContentBuilder. #### `verifySharedMember(member: Address[]) : ContentBuilder` If this member is not a shared member, add it to the list of shared members. **member (Address)**: This ContentBuilder. ## class Schema ### Class-specific Types ``` //WIP interface PushParams = Partial<{ }> ``` ### Fields `did (DID)`: The did of the Schema this schema corresponds to in storage. Optional. `label (Label)`: The label of the Schema. `fields (Map<Label, SonrKind>)`: The fields defined by this Schema. ### Functions #### `fromDid(did: DID) : Promise` Constructs a Schema from the Schema at the provided did. Errs if did is not found, or if the did does not point to a Schema. This functions requires readonly blockchain or storage interaction. **did (DID)**: The did of the Schema to construct. **Returns**: A Promise that returns a Schema on a success, and a error message on failure. #### `new(label: Label, fields: Map<Label, SonrKind>) : Schema` Constructs a Schema from the given parameters. Note that this Schema does not exist in storage until it is pushed. **label (Label)**: The label of the Schema. **fields (Map<Label, SonrKind>)**: The fields for the Schema. **Returns**: A Schema generated from the given parameters. #### `constructor(did: DID, label: Label, fields: Map<Label, SonrKind>)` Constructs a Sonr object with the given did, label, and fields. This constructor is for fine-tuned control of the SonrObject. For general situations, use new() or fromDid(). **did (DID)**: The field label to operate on. **value (SonrKind)**: The value to replace the current value at label. Note this value should be of the same type that is dictated by the fields field. #### `push(did?: DID, params: PushParams) : Promise` Pushes the Schema to storage, If the did parameter is passed and valid, it will attempt to overwrite the Schema at that did. Otherwise, it will attempt to overwrite the did at this Schema’s did. If neither succeed, this function fails. **did (DID)**: An optional way to specify the DID to push to. **params (PushParams)**: Additional parameters to determine the push behavior. **Returns**: A Promise that returns the Schema that is equivalent to the one just written, including the DID, on a success, or an error message on a failure. #### `newInstance() : SonrObject` Creates a mutable instance of this Schema, represented as a SonrObject, that can be passed into Buckets as data. #### `changeLabel(label: Label) : Schema` Creates and returns a Schema identical to this one, except that it’s label is replaced with the one given. This Schema is not changed. **label (Label)**: The new label field. **Returns**: A Schema identical to this one, except that it’s label is replaced with the one given. #### `changeFields(fields: Map<Label, SonrKind>) : Schema` Creates and returns a Schema identical to this one, except that its fields are replaced with the ones given. This Schema is not changed. **fields (Map<Label, SonrKind>)**: The new fields field. **Returns**: A Schema identical to this one, except that its fields are replaced with the ones given. ## class SonrObject ### Fields `schema (Schema)`: The schema this SonrObject uses for field validation. `fields Map<Label, SonrKind>`: The fields that contain the data for this SonrObject. ### Functions #### `constructor(schema: Schema, fields: Map<Label, SonrKind>)` Constructs a SonrObject from scratch. Unless fine-tuned construction is necessary, Schema.newInstance() should be used instead. **schema (Schema)**: The Schema that this SonrObject is constructed from. **fields (Map<Label, SonrKind>)**: The fields for this SonrObject. #### `set(label: Label, newVal: SonrKind) : boolean` Sets the field with the given label to the new value. This method verifies that newVal is of the same type contained in this SonrObject’s corresponding Schema field. **label (Label)**: The label for the fields to change. **newVal (SonrKind)**: The newVal to set the field to. **Returns**: Whether this SonrObject has been modified as a result of this call. #### `get(label: Label) : SonrKind` Returns the value at the given field. **label (Label)**: The label for the field to get the value from. **Returns**: The value at the given field. #### `getCast<T extends SonrKind>(label: Label) : T` Returns the value at the given field. Attempts to cast the return value to the generic type T, and errs on failure. **label (Label)**: The label for the field to get the value from. **Returns**: The value at the given field. ## class Channel ### Class-specific Types ``` //WIP type MessageFilter { } type ChannelOptions { address: ChannelAddress fromTime?: number, toTime?: number, auth?: AuthDetails, filter?: MessageFilter } type ChannelParams = Required<ChannelOptions> type PublishOptions { auth?: AuthDetails, metadata: any, sendAt: number } ``` ### Fields `address ChannelAddress`: The address (either Topic or Multiaddr) of this channel. `ephemeral boolean`: Whether this Channel is ephemeral or not. Readonly. `historicComms SchemaCommunication[]`: A list of historic communications with metadata. Readonly. `fromTime number`: From what time the channel should provide block historic communications. Any time before the channel was created is the same as setting the fromTime equal to the time the channel was created. Readonly. `toTime number`: To what time the channel should provide block historic communications. Readonly. `auth AuthDetails`: Details used to encrypt and decrypt content. `filter MessageFilter`: A filter used by the sender to prevent messages being sent. Readonly. ### Functions #### `static ListenCurrent(options: ChannelOptions) : Channel` Returns a Channel that listens to any live updates from the given `address`. **options (ChannelOptions)** Parameters to determine connection and behavior of the returned channel. **Returns** A `Channel` listening to live messages from the given `address`. <br> #### `static ListenHistory(to number, from? number, options: ChannelOptions) : Channel` Returns a Channel that receives block updates from a given time period from the given `address`. **to (number)** The time at which to stop receiving communications from this Channel. If this time is in the future, the channel will continue to receive live messages until this time has passed. **from (number)** The time to start receiving messages from the channel. **options (ChannelOptions)** Parameters to determine connection and behavior of the returned channel. **Returns** A `Channel` listening to historic messages from the given `address`. <br> #### `static Open(options: ChannelOptions) : Channel` Returns a Channel that can listen or write to the given `address`. Note that write permissions are required to write to any channel. **options (ChannelOptions)** Parameters to determine connection and behavior of the returned channel. **Returns** A `Channel` connected to messages from the given `address`. <br> #### `constructor(params ChannelParams)` Returns a Channel that listens to the given `address`. You should only use the constructor if you need fine-tuned control over the construction of the Channel. **options (ChannelParams)** Parameters to determine connection and behavior of the returned channel. **Returns** A `Channel` listening to messages from the given `address`. <br> #### `OnNewMessage(callback: {(e: MessageEvent) : void}, filter?: MessageFilter)` Returns a Channel that listens to any live updates from the given `address`. **callback (fn)** The function that is called when a new message is received. This function takes in a MessageEvent. **filter (MessageFilter)** A filter determining which messages are passed to the callback. <br> #### `Publish(object: SchemaType, options: PublishOptions)` Publishes the given `object` to this Channel considering the given `options`. **object (SchemaType)** The object to publish to the Channel. **options (PublishOptions)** Parameters to determine how the object is published to the Channel. <br> #### `isMultiaddr(): boolean` Returns whether the `address` field is a Multiaddr. Equivalent to `!isTopic()`. **Returns** Whether the `address` field is a Multiaddr. <br> #### `isTopic(): boolean` Returns whether the `address` field is a Topic. Equivalent to `!isMultiaddr()`. **Returns** Whether the `address` field is a Topic. <br>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully