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
  • transaction: Transaction
  • return Promise<Transaction>
  • Example usage
  • With arweave-js (recommended)
  • Directly using Othent
  1. JS SDK API

sign() (transaction)

Othent JS SDK sign() function

The sign() function signs an Arweave Transaction using the current user's private key. It's meant to replicate the behavior of the transactions.sign() function of arweave-js, but instead of mutating the transaction object, it returns a new and signed transaction instance.

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

Tip: If you are trying to sign a larger piece of data (> 5 MB), make sure to notify the user to not switch / close the browser tab. Larger transactions are split into chunks in the background and will take longer to sign.

Tip: A better alternative to this function is using the arweave-js transactions.sign() instead. Just omit the second parameter (JWK key) when calling the method, and arweave-js will automatically use Othent (if it was instantiated with inject = true).

See Indirect Usage (through arweave-js)

API

sign(transaction: Transaction): Promise<Transaction>;

transaction: Transaction

A valid Arweave Transaction instance, without a keyfile.

return Promise<Transaction>

A Promise containing a new signed Transaction instance.

Example usage

With arweave-js (recommended)

import Arweave from "arweave";
import { Othent } from "@othent/kms";

const arweave = new Arweave({
  host: "ar-io.net",
  port: 443,
  protocol: "https"
});

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

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

// Create a transaction:
const transaction = await arweave.createTransaction({
  data: '<html><head><meta charset="UTF-8"><title>Hello permanent world! This was signed via ArConnect!!!</title></head><body></body></html>'
});

// Sign it using arweave-js:
await arweave.transactions.sign(transaction);

// TODO: Post the `transaction` to the network...

Directly using Othent

import Arweave from "arweave";

// Create an Arweave client:
const arweave = new Arweave({
  host: "ar-io.net",
  port: 443,
  protocol: "https"
});

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

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

// Create a transaction:
let transaction = await arweave.createTransaction({
  data: '<html><head><meta charset="UTF-8"><title>Hello permanent world! This was signed via ArConnect!!!</title></head><body></body></html>'
});

// Sign it using Othent:
const signedTransaction = await othent.sign(transaction);

// TODO: Post `signedTransaction` to the network...
PreviousgetSyncUserDetails()Nextdispatch() (transaction)

Last updated 10 months ago

🥪