Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

IPFS ^0.50.2 digest should be a Uint8Array when used in node.js #3313

Closed
straiforos opened this issue Oct 5, 2020 · 5 comments
Closed

IPFS ^0.50.2 digest should be a Uint8Array when used in node.js #3313

straiforos opened this issue Oct 5, 2020 · 5 comments
Labels
need/triage Needs initial labeling and prioritization

Comments

@straiforos
Copy link

straiforos commented Oct 5, 2020

  • Version:
    yarn jsipfs version --all
    yarn run v1.22.4
    $ C:\js-storage-chain\node_modules.bin\jsipfs version --all
    js-ipfs version: 0.50.2-99c762ba6b3b71e07596b2930c09fb143451aafe
    interface-ipfs-core version: ^0.140.0
    ipfs-http-client version: ^47.0.1
    Repo version: 9
    System version: x64/win32
    Node.js version: v12.16.3
    Commit: 99c762b
    ✨ Done in 1.51s.
  • Platform:
    $ uname -a MINGW64_NT-10.0 DESKTOP-PVGQUPP 2.11.2(0.329/5/3) 2018-11-10 14:38 x86_64 Msys]

Not running this in the browser but rather using node.js for the work. Using Jest as my testing library which I hope is not the core issue I am having.

  • Subsystem:

JS-IPFS

Severity:

High - IPFS JS create functionality is broken it seems, or I am misusing by running in Jest test environment.

Description:

** What I did:**
I am working on making AWS S3 enabled secure private network as a project PoC for what I hope to build into a monetizable set of products so I can support IPFS and like protocols because I believe this is the future!

I worked on getting my node to connect to the datastore-s3 yet realized after much trial and error it was not behaving as it had prior running an unknown older ipfs version because I am a noob. I downloaded the datastore dependencies and botched them. Yet realized the error came from the recent breaking change Node.js Buffer to UTF8IntArrays, as mentioned in the weekly sync.

So I ran the code without any data-store dependencies and it had the same error in the latest version. I tried a couple others newer and older to 0.50.0. I want the new functionality this network upgrade provides so I am willing to help fix and do what I need to do to see this through.

I made a new branch and validated much of my work and stripped out the dependencies aside from TypeScript, and Jest, and rimraf.

I still get the error in my create unit test.

I wrapped the IPFS creation logic to match my serverless goals with the node using an AWS S3 bucket, yet used copy paste code in the end to prove I was getting some issues.

What happened

image

What you expected to happen

I expected the IPFS node to be generated without error. Yet the jsipfs commands are not behaving as I expected.

Steps to reproduce the error:

https://gitlab.com/TraiforceGroupLLC/js-storage-chain/-/tree/ipfs-utf8-error/src/libraries/ipfs-aws-s3

pull repo and run yarn test.
Index.ts

export interface IIPFSAWSS3 {
createOrConnect(path:string, awsS3Bucket: string): Promise;
createMultiAddress(ip: string, peerIdHash: string, ipv6: boolean): string;
};

export default class IPFSAWSS3 implements IIPFSAWSS3 {
createOrConnect(path:string, awsS3Bucket: string): Promise {
const IPFS = require('ipfs');
const ipfs = IPFS.create();

    return ipfs;
}
createMultiAddress(ip: string, peerIdHash: string, ipv6: boolean = true): string {
    let address = null;
    if(ipv6){
      address = "/ip6/";
    } else {
      address = "/ip4/";
    }
    address = address + ip + '/';
    address = address + "/tcp/4001/ipfs/";
    address = peerIdHash;
    return address
} 

};

create.spec.ts - using jest to transpile and run.

import IPFSAWSS3, { IIPFSAWSS3 } from './../src/index';
test("can create", async () => {
const ipfsPath = '/blobchain/ipfs/secure';
const ipfsAwsS3Bucket = 'block-stream-ipfs-store';
const ipfs: Promise = new IPFSAWSS3().createOrConnect(ipfsPath,ipfsAwsS3Bucket);
const result = await ipfs;
expect(result).toBeFalsy();
})

@straiforos straiforos added the need/triage Needs initial labeling and prioritization label Oct 5, 2020
@welcome
Copy link

welcome bot commented Oct 5, 2020

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review.
In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment.
Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

@straiforos
Copy link
Author

I am continuing to investigate as I suspect this is user error but wanted to document this after 8+ hours of trying to get my example code to run as I expected.

@achingbrain
Copy link
Member

There's something strange going on with jest/typescript in your project as with this setup node Buffers returned from the crypto module pass Buffer.isBuffer(buf) but fail buf instanceof Uint8Array which is weird because node's Buffer class has subclassed Uint8Array since node 4.

If I refactor your code to just be plain js and run it in your project dir it works as expected (well, sort of - it errors because you have only specified webrtc swarm addresses and webrtc is not enabled by default under node.js as it's only really intended to be used in the browser - use tcp or websockets in node instead):

async function main () {
  const IPFS = require('ipfs');
  const ipfs = await IPFS.create({
    repo: 'ipfs-' + Math.random(),
    config: {
      Addresses: {
        Swarm: [
          // This is a public webrtc-star server
          '/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
          '/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
          '/ip4/127.0.0.1/tcp/13579/wss/p2p-webrtc-star'
        ]
      },
      // If you want to connect to the public bootstrap nodes, remove the next line
      Bootstrap: []
    }
  })

  await ipfs.stop()
}

main()
  .catch(e => {
    console.error(e)
    process.exit(1)
  })

@straiforos
Copy link
Author

Thanks for the reply. I am jumping back on this now. I am realizing my environment is incorrect and I brilliantly installed node side by side to my node version manger. So this is one issue I resolved in the environment...

I rebuilt the project and re-ran the unit test.

Related solution I will post the solution working in the repository and close this out. I really appreciate the reply @achingbrain!
jestjs/jest#4422 (comment)
Made for this issue related to IPFS:

https://github.com/ipfs-inactive/jest-environment-aegir

@achingbrain
Copy link
Member

Thanks for the link to the jest issue, I guess it's still an issue with that test runner.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

2 participants