Othent
  • 👋Welcome to Othent
  • 🥪JS SDK
    • Getting Started
    • Events
    • Error Handling
    • Binary Data Types Utils
    • TypeScript Types
    • Config Constants
  • 🥪JS SDK API
    • constructor()
    • startTabSynching()
    • completeConnectionAfterRedirect()
    • connect()
    • disconnect()
    • requireAuth()
    • isAuthenticated
    • getActiveAddress()
    • getActivePublicKey()
    • getAllAddresses()
    • getWalletNames()
    • getUserDetails()
    • getSyncActiveAddress()
    • getSyncActivePublicKey()
    • getSyncAllAddresses()
    • getSyncWalletNames()
    • getSyncUserDetails()
    • sign() (transaction)
    • dispatch() (transaction)
    • encrypt()
    • decrypt()
    • signature()
    • signDataItem()
    • signMessage()
    • verifyMessage()
    • privateHash()
    • walletName
    • walletVersion
    • config
    • getArweaveConfig()
    • getPermissions()
  • Demos
    • 🍏SDK playground / demo
    • 🍏SDK playground / demo GitHub
    • 🍎File upload app example
    • 🍎File upload app example GitHub
  • 📚External libraries
    • arweave-js
    • Arweave Wallet Kit
  • Additional Links
    • 🌐Othent.io
    • 🌐Discord
    • 🌐GitHub
    • 🌐X
Powered by GitBook
On this page
  • API
  • dataItem: DataItem
  • return Promise<ArrayBufferLike>
  • Example usage
  1. JS SDK API

signDataItem()

Othent JS SDK signDataItem() function

Previoussignature()NextsignMessage()

Last updated 8 months ago

The signDataItem() function allows you to create and sign a DataItem object, compatible with . These data items can then be submitted to an compatible bundler.

Bug: Using signDataItem() and then calling dataItem.isValid() always returns false, so the example below will never submit the data item to a bundler. Track the progress on this .

This function assumes (and requires) a user is authenticated. See .

Tip: The function returns a buffer (ArrayBufferLike) of the signed data item. You'll need to manually load it into an DataItem instance as seen in the :

API

signDataItem(dataItem: DataItem): Promise<ArrayBufferLike>;

dataItem: DataItem

The bundled data item's data (not ) to sign.

interface DataItem {
    data: string | Uint8Array;
    target?: string;
    anchor?: string;
    tags?: {
        name: string;
        value: string;
    }[];
}

return Promise<ArrayBufferLike>

Example usage

import { DataItem } from "arbundles";
import { Othent } from "@othent/kms";

const othent = new Othent({ appInfo, throwErrors: false, ... });

// Make sure the user is authenticated, or prompt them to authenticate:
await othent.requireAuth();

// Sign the DataItem:
const signedDataItemBuffer = await othent.signDataItem({
    data: "This is an example data",
    tags: [{
        name: "Content-Type",
        value: "text/plain"
    }]
});

// Load the result into a DataItem instance:
const dataItem = new DataItem(signedDataItemBuffer);

// Verify the DataItem's signature:
const isValid = await dataItem.isValid();

if (isValid) {
    // Submit it to a bundler:
    await fetch(`https://node2.bundlr.network/tx`, {
        method: "POST",
        headers: {
            "Content-Type": "application/octet-stream"
        },
        body: dataItem.getRaw()
    });
}

A Promise containing an ArrayBuffer with the DataItem's signed data, which can be loaded into a for validation.

🥪
arbundles
ANS-104
GitHub issue
requireAuth()
arbundles
example usage
arbundle's DateItem instance
arbundle's DateItem instance