diff --git a/src/convert.ts b/src/convert.ts index cbc5b078..1cd1d19b 100644 --- a/src/convert.ts +++ b/src/convert.ts @@ -54,6 +54,7 @@ export function convertToString (proto: number | string, buf: Uint8Array): strin case 54: // dns4 case 55: // dns6 case 56: // dnsaddr + case 384: // tag case 400: // unix case 449: // sni case 777: // memory @@ -97,6 +98,7 @@ export function convertToBytes (proto: string | number, str: string): Uint8Array case 54: // dns4 case 55: // dns6 case 56: // dnsaddr + case 384: // tag case 400: // unix case 449: // sni case 777: // memory diff --git a/src/protocols-table.ts b/src/protocols-table.ts index 0d85beb5..69707c52 100644 --- a/src/protocols-table.ts +++ b/src/protocols-table.ts @@ -47,6 +47,7 @@ export const table: Array<[number, number, string, boolean?, boolean?]> = [ [479, 0, 'p2p-websocket-star'], [480, 0, 'http'], [481, V, 'http-path'], + [384, V, 'tag'], [777, V, 'memory'] ] diff --git a/test/index.spec.ts b/test/index.spec.ts index 523fc0d5..9758b7eb 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -548,6 +548,21 @@ describe('variants', () => { expect(addr).to.have.property('bytes') expect(addr.toString()).to.equal(str) }) + + it('ip4 + tcp + http + tag', () => { + const str = '/ip4/127.0.0.1/tcp/8000/http/tag/http' + const addr = multiaddr(str) + expect(addr).to.have.property('bytes') + expect(addr.toString()).to.equal(str) + }) + + it('ws + p2p + tag tuple', () => { + const str = + '/ip4/127.0.0.1/tcp/9090/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tag/bitswap/tag/graphsync' + const addr = multiaddr(str) + expect(addr).to.have.property('bytes') + expect(addr.toString()).to.equal(str) + }) }) describe('helpers', () => { @@ -732,6 +747,26 @@ describe('helpers', () => { ]) }) + it('returns the tuples for tag', () => { + expect(multiaddr('/ip4/127.0.0.1/tcp/8000/http/tag/http').tuples()) + .to.eql([ + [4, Uint8Array.from([127, 0, 0, 1])], + [6, Uint8Array.from([31, 64])], + [480], + [384, Uint8Array.from([4, 104, 116, 116, 112])] + ]) + + expect(multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tag/bitswap/tag/graphsync').tuples()) + .to.eql([ + [4, Uint8Array.from([127, 0, 0, 1])], + [6, Uint8Array.from([35, 130])], + [477], + [421, Uint8Array.from([34, 18, 32, 213, 46, 187, 137, 216, 91, 2, 162, 132, 148, 130, 3, 166, 47, 242, 131, 137, 197, 124, 159, 66, 190, 236, 78, 194, 13, 183, 106, 104, 145, 28, 11])], + [384, Uint8Array.from([7, 98, 105, 116, 115, 119, 97, 112])], + [384, Uint8Array.from([9, 103, 114, 97, 112, 104, 115, 121, 110, 99])] + ]) + }) + it('does not allow modifying parts', () => { const ma = multiaddr('/ip4/0.0.0.0/tcp/1234') const tuples = ma.tuples() @@ -742,7 +777,7 @@ describe('helpers', () => { }) describe('.stringTuples', () => { - it('returns the string partss', () => { + it('returns the string parts', () => { expect(multiaddr('/ip4/0.0.0.0/utp').stringTuples()) .to.eql([ [4, '0.0.0.0'], @@ -750,6 +785,26 @@ describe('helpers', () => { ]) }) + it('returns the string parts for tag', () => { + expect(multiaddr('/ip4/127.0.0.1/tcp/8000/http/tag/http').stringTuples()) + .to.eql([ + [4, '127.0.0.1'], + [6, '8000'], + [480], + [384, 'http'] + ]) + + expect(multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tag/bitswap/tag/graphsync').stringTuples()) + .to.eql([ + [4, '127.0.0.1'], + [6, '9090'], + [477], + [421, 'QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'], + [384, 'bitswap'], + [384, 'graphsync'] + ]) + }) + it('does not allow modifying string parts', () => { const ma = multiaddr('/ip4/0.0.0.0/tcp/1234') const tuples = ma.stringTuples()