Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Signer for process spawning generates error if Arweave wallet is not installed #232

Open
hitwill opened this issue Oct 1, 2024 · 0 comments

Comments

@hitwill
Copy link

hitwill commented Oct 1, 2024

The signer specified here needs Arweave wallet installed

import { createDataItemSigner, spawn } from "@permaweb/ao-sdk";

const processId = await spawn({
  // The Arweave TXID of the ao Module
  module: "module TXID",
  // The Arweave wallet address of a Scheduler Unit
  scheduler: "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA",
  // A signer function containing your wallet
  signer: createDataItemSigner(globalThis.arweaveWallet),
  /*
    Refer to a Processes' source code or documentation
    for tags that may effect its computation.
  */
  tags: [
    { name: "Your-Tag-Name-Here", value: "your-tag-value" },
    { name: "Another-Tag", value: "another-value" },
  ],
});

However, some browser applications might not need Arweave wallet specifically. E.g.

  1. They might authenticate the user in some other way
  2. They might be trivial tasks that do not need the extra UX burden of installing / signing a wallet

In this case, a custom signer can be used as bellow:

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-nocheck

import * as WarpArBundles from 'warp-arbundles';
const pkg = WarpArBundles.default ? WarpArBundles.default : WarpArBundles;
const { createData, ArweaveSigner } = pkg;

export function createDataItemSigner(wallet) {
  const signer = async ({ data, tags, target, anchor }) => {
    const signer = new ArweaveSigner(wallet);
    const dataItem = createData(data, signer, { tags, target, anchor });
    return dataItem.sign(signer).then(async () => ({
      id: await dataItem.id,
      raw: await dataItem.getRaw(),
    }));
  };

  return signer;
}
@hitwill hitwill changed the title Signer for process spawning generates error if Arweave wallet is not installed docs: Signer for process spawning generates error if Arweave wallet is not installed Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant