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

bug(connect): message creating invalid DataItems when used in Deno due to arweave-js crypto usage. #953

Open
leeduckgo opened this issue Aug 9, 2024 · 7 comments
Labels
bug Something isn't working connect ao connect help wanted Extra attention is needed

Comments

@leeduckgo
Copy link

Example Code, it ran well in node but not in deno.

import { dryrun, message, createDataItemSigner } from "https://esm.sh/@permaweb/aoconnect@0.0.58";
// import Arweave from "npm:arweave@1.15.1";
import Arweave from "https://esm.sh/arweave@1.15.1";

const arweave = Arweave.init({
    host: 'arweave.net',
    port: 443,
    protocol: 'https'
  });

const wallet = await arweave.wallets.generate();
console.log(wallet);

// The only 2 mandatory parameters here are process and signer
await message({
  /*
    The arweave TXID of the process, this will become the "target".
    This is the process the message is ultimately sent to.
  */
  process: "Rijbx6FduUMdCZM0tJ4PPxXljUNy1m0u_kmMIFGFM5c",
  // Tags that the process will use as input.
  tags: [{ name: "Action", value: "AddNew" }],
  // A signer function used to build the message "signature"
  signer: createDataItemSigner(wallet),
  /*
    The "data" portion of the message
    If not specified a random string will be generated
  */
  data: "data",
})
  .then(console.log)
  .catch(console.error);

Run Command:
deno run --allow-read --allow-write --allow-net --unstable-kv --unstable-cron -A ./test.js

Error Msg:
image

@TillaTheHun0 TillaTheHun0 changed the title bug/aoconnect/don't run in deno. bug(connect): does not run in deno Aug 9, 2024
@TillaTheHun0 TillaTheHun0 added the connect ao connect label Aug 9, 2024
@TillaTheHun0
Copy link
Member

Hey @leeduckgo . Sorry you're seeing issues.

We've definitely used aoconnect in Deno:

import { dryrun } from 'npm:@permaweb/aoconnect'

dryrun({
  process: 'Rijbx6FduUMdCZM0tJ4PPxXljUNy1m0u_kmMIFGFM5c',
  Owner: 'h8WzXOG1leDquKyNfHzCh0zW7FfDyN7qxLnZgXzPDGk',
  tags: [
    { name: 'Action', value: 'Eval' }
  ],
  data: '1 + 1'
})
  .then(console.log)
  .catch(console.error)

Perhaps esm.sh is polyfilling something incorrectly? Is it possible to import from npm? aoconnect is an ES6 module, and has minimal dependencies, so Deno node-compat impact should be minimal.

@leeduckgo
Copy link
Author

leeduckgo commented Aug 9, 2024

Hey @leeduckgo . Sorry you're seeing issues.

We've definitely used aoconnect in Deno:

import { dryrun } from 'npm:@permaweb/aoconnect'

dryrun({
  process: 'Rijbx6FduUMdCZM0tJ4PPxXljUNy1m0u_kmMIFGFM5c',
  Owner: 'h8WzXOG1leDquKyNfHzCh0zW7FfDyN7qxLnZgXzPDGk',
  tags: [
    { name: 'Action', value: 'Eval' }
  ],
  data: '1 + 1'
})
  .then(console.log)
  .catch(console.error)

Perhaps esm.sh is polyfilling something incorrectly? Is it possible to import from npm? aoconnect is an ES6 module, and has minimal dependencies, so Deno node-compat impact should be minimal.

import { dryrun, message, createDataItemSigner } from "npm:@permaweb/aoconnect@0.0.58";
// import Arweave from "npm:arweave@1.15.1";
import Arweave from "https://esm.sh/arweave@1.15.1";


const arweave = Arweave.init({
    host: 'arweave.net',
    port: 443,
    protocol: 'https'
  });

const wallet = await arweave.wallets.generate();
console.log(wallet);

// The only 2 mandatory parameters here are process and signer
await message({
  /*
    The arweave TXID of the process, this will become the "target".
    This is the process the message is ultimately sent to.
  */
  process: "Rijbx6FduUMdCZM0tJ4PPxXljUNy1m0u_kmMIFGFM5c",
  // Tags that the process will use as input.
  tags: [{ name: "Action", value: "AddNew" }],
  // A signer function used to build the message "signature"
  signer: createDataItemSigner(wallet),
  /*
    The "data" portion of the message
    If not specified a random string will be generated
  */
  data: "data",
})
  .then(console.log)
  .catch(console.error);

  dryrun({
    process: 'Rijbx6FduUMdCZM0tJ4PPxXljUNy1m0u_kmMIFGFM5c',
    Owner: 'h8WzXOG1leDquKyNfHzCh0zW7FfDyN7qxLnZgXzPDGk',
    tags: [
      { name: 'Action', value: 'Eval' }
    ],
    data: '1 + 1'
  })
    .then(console.log)
    .catch(console.error)

Yep, I tried npm: at first, but it's not working too so I tried esm in the second time.

The dryrun is fine, so I think that there maybe some problem in createDataItemSigner(wallet).

@leeduckgo
Copy link
Author

image

@DevChanQ
Copy link

Facing the same problem here. Dry running works fine but sending messages returns error 422

@TillaTheHun0
Copy link
Member

Thanks @leeduckgo @DevChanQ . Sounds like there is an issue when creating and signing the data item, and so the MU is responding with a 422 Unprocessable Entity.

This is most likely something to do with Deno's node compat layer, as createDataItemSigner provided OOTB with aoconnect uses node crypto and is probably breaking somewhere. This will need further investigation.

FWIW, aoconnect allows for implementing your own data item signer. That is a potential workaround for Deno until this issue can be investigated.

@TillaTheHun0 TillaTheHun0 added the bug Something isn't working label Aug 15, 2024
@TillaTheHun0 TillaTheHun0 changed the title bug(connect): does not run in deno bug(connect): message creating invalid DataItems when used in Deno - possibly createDataItemSigner Aug 15, 2024
@TillaTheHun0 TillaTheHun0 added the help wanted Extra attention is needed label Aug 15, 2024
@twilson63
Copy link
Contributor

twilson63 commented Aug 15, 2024 via email

@DevChanQ
Copy link

Managed to put together a solution that works within the Deno runtime by leveraging the Deno standard crypto module as the crypto driver. Since the standard crypto module implements the WebCrypto API, I was able to adapt the webcrypto driver implementation from here and have it use the Deno standard crypto module.

Until the compatibility issues with Deno’s node crypto module are resolved, this approach seems to be the best alternative. Appreciate any feedback or suggestions you might have!

Repo: https://github.com/DevChanQ/ao-deno-test
Try it out here: https://devjeff-ao-deno-tes-95.deno.dev/

@TillaTheHun0 TillaTheHun0 changed the title bug(connect): message creating invalid DataItems when used in Deno - possibly createDataItemSigner bug(connect): message creating invalid DataItems when used in Deno due to arweave-js crypto usage. Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working connect ao connect help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants