Code Monkey home page Code Monkey logo

Comments (5)

jacobheun avatar jacobheun commented on August 22, 2024

The code has been added to the protocol table but convert.js likely needs to be updated to handle the conversion. Adding some tests for various onion addresses and fixing the conversion code where needed would be the best path forward. Happy to review a PR if you'd be up for submitting one! :)

from js-multiaddr.

ricott1 avatar ricott1 commented on August 22, 2024

Hi Jacob, thanks for the feedback. I changed the convert.js file to handle the onion and onion3 cases using the str2buf(str) function, but I really don't know if this is correct. I'm still getting an error: in bufferToTuples the size of the address that you get from
let size = sizeForAddr(p, buf.slice(i + n))
is not correct. I suppose I'm doing something wrong, but I'm kinda lost now.

from js-multiaddr.

jacobheun avatar jacobheun commented on August 22, 2024

I'm not very familiar with onion addresses but looking at the go implementation there will need to be more in depth parsing of the string than just using str2buf. You can look at how go is doing the onion and onion3 transcoding, https://github.com/multiformats/go-multiaddr/blob/0460aad0fe51f7aa64d3a3c17854dc25368f7ca2/transcoders.go#L128-L213. The string needs to be split by : to determine the port.

It would also be good to leverage the same bad and good onion addresses from the go test suite when testing here.

from js-multiaddr.

ricott1 avatar ricott1 commented on August 22, 2024

Ok, I added the following to converter.js:

const base32 = require('hi-base32')
function onion2buf(str) {
    const addr = str.split(':')
    if (addr.length !== 2) {
        throw new Error('failed to parse onion addr: ' + addr + ' does not contain a port number')
    }
    if (addr[0].length !== 16) {
        throw new Error('failed to parse onion addr: ' + addr[0] + ' not a Tor onion address.')
    }
    const buf = Buffer.from(base32.decode.asBytes(addr[0].toUpperCase()))
    const size = Buffer.from(varint.encode(buf.length))
    //onion port number
    
    const port = parseInt(addr[1], 10);
    
    if (port < 1 || port > 65536) {
        throw new Error("Port number is not in range(1, 65536)")
    }
    const portBuf = port2buf(port)
    return Buffer.concat([buf, portBuf])
}

I checked it against the python implementation and it gives the same result. I still have to understand your code 100%, but I think the general direction is correct. I'll finish up with the onion3 protocol and submit a pull in the next days.

from js-multiaddr.

jacobheun avatar jacobheun commented on August 22, 2024

Released in 6.1.0

from js-multiaddr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.