diff --git a/packages/common/package-lock.json b/packages/common/package-lock.json index c02a9138ae..650f4c3902 100644 --- a/packages/common/package-lock.json +++ b/packages/common/package-lock.json @@ -10,7 +10,8 @@ "license": "ISC", "dependencies": { "cross-env": "^5.2.0", - "debug": "^4.3.1" + "debug": "^4.3.1", + "multiaddr": "^10.0.1" }, "devDependencies": { "@types/jest": "^26.0.23", @@ -4052,6 +4053,178 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "node_modules/multiaddr": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/multiaddr/-/multiaddr-10.0.1.tgz", + "integrity": "sha512-G5upNcGzEGuTHkzxezPrrD6CaIHR9uo+7MwqhNVcXTs33IInon4y7nMiGxl2CY5hG7chvYQUQhz5V52/Qe3cbg==", + "deprecated": "This module is deprecated, please upgrade to @multiformats/multiaddr", + "dependencies": { + "dns-over-http-resolver": "^1.2.3", + "err-code": "^3.0.1", + "is-ip": "^3.1.0", + "multiformats": "^9.4.5", + "uint8arrays": "^3.0.0", + "varint": "^6.0.0" + } + }, + "node_modules/multiaddr/node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "peer": true, + "engines": { + "node": ">= 12" + } + }, + "node_modules/multiaddr/node_modules/dns-over-http-resolver": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/dns-over-http-resolver/-/dns-over-http-resolver-1.2.3.tgz", + "integrity": "sha512-miDiVSI6KSNbi4SVifzO/reD8rMnxgrlnkrlkugOLQpWQTe2qMdHsZp5DmfKjxNE+/T3VAAYLQUZMv9SMr6+AA==", + "dependencies": { + "debug": "^4.3.1", + "native-fetch": "^3.0.0", + "receptacle": "^1.3.2" + } + }, + "node_modules/multiaddr/node_modules/err-code": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/err-code/-/err-code-3.0.1.tgz", + "integrity": "sha512-GiaH0KJUewYok+eeY05IIgjtAe4Yltygk9Wqp1V5yVWLdhf0hYZchRjNIT9bb0mSwRcIusT3cx7PJUf3zEIfUA==" + }, + "node_modules/multiaddr/node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "peer": true, + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/multiaddr/node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "peer": true, + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/multiaddr/node_modules/ip-regex": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-4.3.0.tgz", + "integrity": "sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q==", + "engines": { + "node": ">=8" + } + }, + "node_modules/multiaddr/node_modules/is-ip": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-ip/-/is-ip-3.1.0.tgz", + "integrity": "sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q==", + "dependencies": { + "ip-regex": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/multiaddr/node_modules/multiformats": { + "version": "9.9.0", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.9.0.tgz", + "integrity": "sha512-HoMUjhH9T8DDBNT+6xzkrd9ga/XiBI4xLr58LJACwK6G3HTOPeMz4nB4KJs33L2BelrIJa7P0VuNaVF3hMYfjg==" + }, + "node_modules/multiaddr/node_modules/native-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/native-fetch/-/native-fetch-3.0.0.tgz", + "integrity": "sha512-G3Z7vx0IFb/FQ4JxvtqGABsOTIqRWvgQz6e+erkB+JJD6LrszQtMozEHI4EkmgZQvnGHrpLVzUWk7t4sJCIkVw==", + "peerDependencies": { + "node-fetch": "*" + } + }, + "node_modules/multiaddr/node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "peer": true, + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/multiaddr/node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "peer": true, + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/multiaddr/node_modules/receptacle": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/receptacle/-/receptacle-1.3.2.tgz", + "integrity": "sha512-HrsFvqZZheusncQRiEE7GatOAETrARKV/lnfYicIm8lbvp/JQOdADOfhjBd2DajvoszEyxSM6RlAAIZgEoeu/A==", + "dependencies": { + "ms": "^2.1.1" + } + }, + "node_modules/multiaddr/node_modules/uint8arrays": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.1.1.tgz", + "integrity": "sha512-+QJa8QRnbdXVpHYjLoTpJIdCTiw9Ir62nocClWuXIq2JIh4Uta0cQsTSpFL678p2CN8B+XSApwcU+pQEqVpKWg==", + "dependencies": { + "multiformats": "^9.4.2" + } + }, + "node_modules/multiaddr/node_modules/varint": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/varint/-/varint-6.0.0.tgz", + "integrity": "sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==" + }, + "node_modules/multiaddr/node_modules/web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "peer": true, + "engines": { + "node": ">= 8" + } + }, "node_modules/nanomatch": { "version": "1.2.13", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", @@ -9351,6 +9524,129 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "multiaddr": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/multiaddr/-/multiaddr-10.0.1.tgz", + "integrity": "sha512-G5upNcGzEGuTHkzxezPrrD6CaIHR9uo+7MwqhNVcXTs33IInon4y7nMiGxl2CY5hG7chvYQUQhz5V52/Qe3cbg==", + "requires": { + "dns-over-http-resolver": "^1.2.3", + "err-code": "^3.0.1", + "is-ip": "^3.1.0", + "multiformats": "^9.4.5", + "uint8arrays": "^3.0.0", + "varint": "^6.0.0" + }, + "dependencies": { + "data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "peer": true + }, + "dns-over-http-resolver": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/dns-over-http-resolver/-/dns-over-http-resolver-1.2.3.tgz", + "integrity": "sha512-miDiVSI6KSNbi4SVifzO/reD8rMnxgrlnkrlkugOLQpWQTe2qMdHsZp5DmfKjxNE+/T3VAAYLQUZMv9SMr6+AA==", + "requires": { + "debug": "^4.3.1", + "native-fetch": "^3.0.0", + "receptacle": "^1.3.2" + } + }, + "err-code": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/err-code/-/err-code-3.0.1.tgz", + "integrity": "sha512-GiaH0KJUewYok+eeY05IIgjtAe4Yltygk9Wqp1V5yVWLdhf0hYZchRjNIT9bb0mSwRcIusT3cx7PJUf3zEIfUA==" + }, + "fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "peer": true, + "requires": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + } + }, + "formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "peer": true, + "requires": { + "fetch-blob": "^3.1.2" + } + }, + "ip-regex": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-4.3.0.tgz", + "integrity": "sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q==" + }, + "is-ip": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-ip/-/is-ip-3.1.0.tgz", + "integrity": "sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q==", + "requires": { + "ip-regex": "^4.0.0" + } + }, + "multiformats": { + "version": "9.9.0", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.9.0.tgz", + "integrity": "sha512-HoMUjhH9T8DDBNT+6xzkrd9ga/XiBI4xLr58LJACwK6G3HTOPeMz4nB4KJs33L2BelrIJa7P0VuNaVF3hMYfjg==" + }, + "native-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/native-fetch/-/native-fetch-3.0.0.tgz", + "integrity": "sha512-G3Z7vx0IFb/FQ4JxvtqGABsOTIqRWvgQz6e+erkB+JJD6LrszQtMozEHI4EkmgZQvnGHrpLVzUWk7t4sJCIkVw==", + "requires": {} + }, + "node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "peer": true + }, + "node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "peer": true, + "requires": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + } + }, + "receptacle": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/receptacle/-/receptacle-1.3.2.tgz", + "integrity": "sha512-HrsFvqZZheusncQRiEE7GatOAETrARKV/lnfYicIm8lbvp/JQOdADOfhjBd2DajvoszEyxSM6RlAAIZgEoeu/A==", + "requires": { + "ms": "^2.1.1" + } + }, + "uint8arrays": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.1.1.tgz", + "integrity": "sha512-+QJa8QRnbdXVpHYjLoTpJIdCTiw9Ir62nocClWuXIq2JIh4Uta0cQsTSpFL678p2CN8B+XSApwcU+pQEqVpKWg==", + "requires": { + "multiformats": "^9.4.2" + } + }, + "varint": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/varint/-/varint-6.0.0.tgz", + "integrity": "sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==" + }, + "web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "peer": true + } + } + }, "nanomatch": { "version": "1.2.13", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", diff --git a/packages/common/package.json b/packages/common/package.json index d320789a04..5818f4b888 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -26,6 +26,7 @@ }, "dependencies": { "@quiet/types": "^1.6.0", + "multiaddr": "^10.0.1", "cross-env": "^5.2.0", "debug": "^4.3.1" }, diff --git a/packages/common/src/invitationCode.test.ts b/packages/common/src/invitationCode.test.ts index 78bd1420c1..1f49410df5 100644 --- a/packages/common/src/invitationCode.test.ts +++ b/packages/common/src/invitationCode.test.ts @@ -3,22 +3,42 @@ import { Site } from './static' describe('Invitation code helper', () => { it('retrieves invitation code from argv', () => { + const expectedCodes = [ + { peerId: 'peerID1', address: 'address1' }, + { peerId: 'peerID2', address: 'address2' }, + ] const result = argvInvitationCode([ 'something', 'quiet:/invalid', 'zbay://invalid', 'quiet://invalid', 'quiet://?param=invalid', - invitationDeepUrl('validCode'), + invitationDeepUrl(expectedCodes), ]) - expect(result).toBe('validCode') + expect(result).toBe(expectedCodes) }) it('builds proper invitation deep url', () => { - expect(invitationDeepUrl('validCode')).toEqual('quiet://?code=validCode') + expect( + invitationDeepUrl([ + { peerId: 'peerID1', address: 'address1' }, + { peerId: 'peerID2', address: 'address2' }, + ]) + ).toEqual('quiet://?peerID1=address1&peerID2=address2') }) + // it('builds proper invitation share url', () => { + // expect(invitationShareUrl('validCode')).toEqual(`https://${Site.DOMAIN}/${Site.JOIN_PAGE}#validCode`) + // }) + it('builds proper invitation share url', () => { - expect(invitationShareUrl('validCode')).toEqual(`https://${Site.DOMAIN}/${Site.JOIN_PAGE}#validCode`) + const peerList = [ + '/dns4/gloao6h5plwjy4tdlze24zzgcxll6upq2ex2fmu2ohhyu4gtys4nrjad.onion/tcp/443/wss/p2p/QmZoiJNAvCffeEHBjk766nLuKVdkxkAT7wfFJDPPLsbKSE', + 'invalidAddress', + '/dns4/somethingElse.onion/tcp/443/wss/p2p/QmZoiJNAvCffeEHBjk766nLuKVdkxkAT7wfFJDPPLsbKSA', + ] + expect(invitationShareUrl(peerList)).toEqual( + `https://${Site.DOMAIN}/${Site.JOIN_PAGE}#QmZoiJNAvCffeEHBjk766nLuKVdkxkAT7wfFJDPPLsbKSE=gloao6h5plwjy4tdlze24zzgcxll6upq2ex2fmu2ohhyu4gtys4nrjad&QmZoiJNAvCffeEHBjk766nLuKVdkxkAT7wfFJDPPLsbKSA=somethingElse` + ) }) }) diff --git a/packages/common/src/invitationCode.ts b/packages/common/src/invitationCode.ts index b43cb2053f..b3b83b53e6 100644 --- a/packages/common/src/invitationCode.ts +++ b/packages/common/src/invitationCode.ts @@ -1,27 +1,28 @@ import { InvitationPair } from '@quiet/types' import { InvitationParams, Site } from './static' +import { multiaddr } from 'multiaddr' -export const retrieveInvitationCode = (url: string): string => { - /** - * Extract invitation code from deep url. - * Valid format: quiet://?code= - */ - let data: URL - try { - data = new URL(url) - } catch (e) { - return '' - } - if (!data || data.protocol !== 'quiet:') return '' - const code = data.searchParams.get(InvitationParams.CODE) - if (code) { - console.log('Retrieved code:', code) - return code - } - return '' -} +// export const retrieveInvitationCode = (url: string): string => { +// /** +// * Extract invitation code from deep url. +// * Valid format: quiet://?code= +// */ +// let data: URL +// try { +// data = new URL(url) +// } catch (e) { +// return '' +// } +// if (!data || data.protocol !== 'quiet:') return '' +// const code = data.searchParams.get(InvitationParams.CODE) +// if (code) { +// console.log('Retrieved code:', code) +// return code +// } +// return '' +// } -export const retrieveInvitationCodePairs = (url: string): InvitationPair[] => { +export const retrieveInvitationCode = (url: string): InvitationPair[] => { /** * Extract invitation code from deep url. * Valid format: quiet://?=&= @@ -50,14 +51,34 @@ export const retrieveInvitationCodePairs = (url: string): InvitationPair[] => { return codes } -export const invitationShareUrlMultipleAddresses = (pairs: InvitationPair[] = []): string => { +export const invitationShareUrl = (peers: string[] = []): string => { // Valid format: https://tryquiet.org/join/#=&= - const code = pairs.map(pair => `${pair.peerId}=${pair.address}`).join('&') - const url = new URL(`https://${Site.DOMAIN}/${Site.JOIN_PAGE}#${code}`) + const pairs = [] + for (const peerAddress of peers) { + let addr + try { + addr = multiaddr(peerAddress) + } catch (e) { + console.error(`Could not add peer address '${peerAddress}' to invitation url. Reason: ${e.message}`) + continue + } + + const peerId = addr.getPeerId() + const address: string = addr.nodeAddress().address + if (!peerId || !address) { + console.error('NO PEER ID OR ADDRESS IN', peerAddress) + continue + } + const rawAddress = address.endsWith('.onion') ? address.split('.')[0] : address + pairs.push(`${peerId}=${rawAddress}`) + } + + console.log('CODE', pairs.join('&')) + const url = new URL(`https://${Site.DOMAIN}/${Site.JOIN_PAGE}#${pairs.join('&')}`) return url.href } -export const invitationDeepUrlMultipleAddresses = (pairs: InvitationPair[] = []): string => { +export const invitationDeepUrl = (pairs: InvitationPair[] = []): string => { const url = new URL('quiet://') for (const pair of pairs) { url.searchParams.append(pair.peerId, pair.address) @@ -67,11 +88,11 @@ export const invitationDeepUrlMultipleAddresses = (pairs: InvitationPair[] = []) export const argvInvitationCode = (argv: string[]): InvitationPair[] => { /** - * Extract invitation code from deep url if url is present in argv + * Extract invitation codes from deep url if url is present in argv */ let invitationCodes = [] for (const arg of argv) { - invitationCodes = retrieveInvitationCodePairs(arg) + invitationCodes = retrieveInvitationCode(arg) if (invitationCodes.length > 0) { break } @@ -93,13 +114,13 @@ export const argvInvitationCode = (argv: string[]): InvitationPair[] => { // return invitationCode // } -export const invitationDeepUrl = (code = ''): string => { - const url = new URL('quiet://') - url.searchParams.append(InvitationParams.CODE, code) - return url.href -} +// export const invitationDeepUrl = (code = ''): string => { +// const url = new URL('quiet://') +// url.searchParams.append(InvitationParams.CODE, code) +// return url.href +// } -export const invitationShareUrl = (code = ''): string => { - const url = new URL(`https://${Site.DOMAIN}/${Site.JOIN_PAGE}#${code}`) - return url.href -} +// export const invitationShareUrl = (code = ''): string => { +// const url = new URL(`https://${Site.DOMAIN}/${Site.JOIN_PAGE}#${code}`) +// return url.href +// } diff --git a/packages/common/tsconfig.build.json b/packages/common/tsconfig.build.json index 4c2fe1bc29..b889234c8b 100644 --- a/packages/common/tsconfig.build.json +++ b/packages/common/tsconfig.build.json @@ -1,6 +1,7 @@ { "extends": "../../tsconfig.build.json", "compilerOptions": { + "target": "ES2020", "rootDir": "./src", "outDir": "./lib", "typeRoots": [ diff --git a/packages/common/tsconfig.json b/packages/common/tsconfig.json index afd02831cc..6adb0ef8de 100644 --- a/packages/common/tsconfig.json +++ b/packages/common/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "target": "es2017", + "target": "ES2020", "outDir": "./lib", "typeRoots": [ "../@types", diff --git a/packages/desktop/src/main/main.test.ts b/packages/desktop/src/main/main.test.ts index faa8e913fc..ad6203d06c 100644 --- a/packages/desktop/src/main/main.test.ts +++ b/packages/desktop/src/main/main.test.ts @@ -243,14 +243,17 @@ describe('Invitation code', () => { const code = 'invitationCode' expect(mockAppOnCalls[1][0]).toBe('open-url') const event = { preventDefault: () => {} } - mockAppOnCalls[1][1](event, invitationDeepUrl(code)) + mockAppOnCalls[1][1](event, invitationDeepUrl([{ peerId: 'peerId1', address: 'address' }])) expect(mockWindowWebContentsSend).toHaveBeenCalledWith('invitation', { code: code }) }) it('process invitation code on second-instance event', async () => { const code = 'invitationCodeArgv' await mockAppOnCalls[2][1]() - const commandLine = ['/tmp/.mount_Quiet-TVQc6s/quiet', invitationDeepUrl(code)] + const commandLine = [ + '/tmp/.mount_Quiet-TVQc6s/quiet', + invitationDeepUrl([{ peerId: 'peerId1', address: 'address' }]), + ] expect(mockAppOnCalls[0][0]).toBe('second-instance') const event = { preventDefault: () => {} } mockAppOnCalls[0][1](event, commandLine) diff --git a/packages/desktop/src/main/main.ts b/packages/desktop/src/main/main.ts index bbb35bf6ac..b8c20310f4 100644 --- a/packages/desktop/src/main/main.ts +++ b/packages/desktop/src/main/main.ts @@ -11,7 +11,7 @@ import { Crypto } from '@peculiar/webcrypto' import logger from './logger' import { DATA_DIR, DEV_DATA_DIR } from '../shared/static' import { fork, ChildProcess } from 'child_process' -import { argvInvitationCode, getFilesData, retrieveInvitationCodePairs } from '@quiet/common' +import { argvInvitationCode, getFilesData, retrieveInvitationCode } from '@quiet/common' import { updateDesktopFile, processInvitationCode } from './invitation' const ElectronStore = require('electron-store') ElectronStore.initRenderer() @@ -147,7 +147,7 @@ app.on('open-url', (event, url) => { event.preventDefault() if (mainWindow) { invitationUrl = null - const invitationCode = retrieveInvitationCodePairs(url) + const invitationCode = retrieveInvitationCode(url) processInvitationCode(mainWindow, invitationCode) } }) @@ -474,12 +474,12 @@ app.on('ready', async () => { throw new Error(`mainWindow is on unexpected type ${mainWindow}`) } if (process.platform === 'darwin' && invitationUrl) { - const invitationCode = retrieveInvitationCodePairs(invitationUrl) + const invitationCode = retrieveInvitationCode(invitationUrl) processInvitationCode(mainWindow, invitationCode) invitationUrl = null } if (process.platform !== 'darwin' && process.argv) { - const invitationCode = argvInvitationCodeMultipleAddresses(process.argv) + const invitationCode = argvInvitationCode(process.argv) processInvitationCode(mainWindow, invitationCode) } diff --git a/packages/desktop/src/renderer/index.tsx b/packages/desktop/src/renderer/index.tsx index bf35aea3bc..02942c0c46 100644 --- a/packages/desktop/src/renderer/index.tsx +++ b/packages/desktop/src/renderer/index.tsx @@ -21,15 +21,15 @@ ipcRenderer.on('force-save-state', async _event => { }) ipcRenderer.on('invitation', (_event, invitation) => { - console.log('invitation', invitation, 'dispatching action') - store.dispatch(communities.actions.handleInvitationCode(invitation.code)) -}) - -ipcRenderer.on('invitationMA', (_event, invitation) => { console.log('invitation', invitation, 'dispatching action') store.dispatch(communities.actions.handleInvitationCodes(invitation.codes)) }) +// ipcRenderer.on('invitationMA', (_event, invitation) => { +// console.log('invitation', invitation, 'dispatching action') +// store.dispatch(communities.actions.handleInvitationCodes(invitation.codes)) +// }) + const container = document.getElementById('root') if (!container) throw new Error('No root html element!') let root = createRoot(container) diff --git a/packages/state-manager/src/sagas/communities/communities.selectors.test.ts b/packages/state-manager/src/sagas/communities/communities.selectors.test.ts index c77232b733..2a582a3c32 100644 --- a/packages/state-manager/src/sagas/communities/communities.selectors.test.ts +++ b/packages/state-manager/src/sagas/communities/communities.selectors.test.ts @@ -97,32 +97,32 @@ describe('communitiesSelectors', () => { expect(invitationUrl).toEqual('') }) - it('returns proper invitation url if registrationUrl is in old format', async () => { - const code = 'aznu6kiyutsgjhdue4i4xushjzey6boxf4i4isd53admsibvbt6qyiyd' - const registrarUrl = `http://${code}` - const { store } = prepareStore() - const factory = await getFactory(store) - await factory.create['payload']>('Community', { - registrarUrl, - port: 0, - onionAddress: '', - }) - const invitationUrl = communitiesSelectors.invitationUrl(store.getState()) - expect(invitationUrl).toEqual(invitationShareUrl(code)) - }) - - it('returns proper invitation url if registrationUrl is just onion address', async () => { - const code = 'aznu6kiyutsgjhdue4i4xushjzey6boxf4i4isd53admsibvbt6qyiyd' - const { store } = prepareStore() - const factory = await getFactory(store) - await factory.create['payload']>('Community', { - registrarUrl: code, - port: 0, - onionAddress: '', - }) - const invitationUrl = communitiesSelectors.invitationUrl(store.getState()) - expect(invitationUrl).toEqual(invitationShareUrl(code)) - }) + // it('returns proper invitation url if registrationUrl is in old format', async () => { + // const code = 'aznu6kiyutsgjhdue4i4xushjzey6boxf4i4isd53admsibvbt6qyiyd' + // const registrarUrl = `http://${code}` + // const { store } = prepareStore() + // const factory = await getFactory(store) + // await factory.create['payload']>('Community', { + // registrarUrl, + // port: 0, + // onionAddress: '', + // }) + // const invitationUrl = communitiesSelectors.invitationUrl(store.getState()) + // expect(invitationUrl).toEqual(invitationShareUrl(code)) + // }) + + // it('returns proper invitation url if registrationUrl is just onion address', async () => { + // const code = 'aznu6kiyutsgjhdue4i4xushjzey6boxf4i4isd53admsibvbt6qyiyd' + // const { store } = prepareStore() + // const factory = await getFactory(store) + // await factory.create['payload']>('Community', { + // registrarUrl: code, + // port: 0, + // onionAddress: '', + // }) + // const invitationUrl = communitiesSelectors.invitationUrl(store.getState()) + // expect(invitationUrl).toEqual(invitationShareUrl(code)) + // }) it('returns proper ownerNickname - ownerCertificate exist', async () => { const { store } = prepareStore() diff --git a/packages/state-manager/src/sagas/communities/communities.selectors.ts b/packages/state-manager/src/sagas/communities/communities.selectors.ts index 4a1d44c232..8e2e3c0e4c 100644 --- a/packages/state-manager/src/sagas/communities/communities.selectors.ts +++ b/packages/state-manager/src/sagas/communities/communities.selectors.ts @@ -58,6 +58,12 @@ export const invitationCode = createSelector(communitiesSlice, reducerState => { }) export const invitationUrl = createSelector(currentCommunity, community => { + const peerList = community?.peerList + if (!peerList || peerList?.length === 0) return + const initialPeers = peerList.slice(0, 4) + + console.log('invitationUrl INITIAL PEERS', initialPeers) + if (!community?.registrarUrl) return '' let registrarUrl = '' try { @@ -66,7 +72,7 @@ export const invitationUrl = createSelector(currentCommunity, community => { } catch (e) { registrarUrl = community.registrarUrl } - return invitationShareUrl(registrarUrl) + return invitationShareUrl(initialPeers) }) export const registrationAttempts = (communityId: string) => diff --git a/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.test.ts b/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.test.ts index 551daff58e..c23dd92a7f 100644 --- a/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.test.ts +++ b/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.test.ts @@ -28,7 +28,7 @@ describe('createNetwork', () => { createNetworkSaga, communitiesActions.createNetwork({ ownership: CommunityOwnership.User, - registrar: 'registrarUrl', + peers: [{ peerId: 'peerId', address: 'address' }], }) ) .withReducer(reducer) diff --git a/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts b/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts index bb84e67e3e..1fa5b13771 100644 --- a/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts +++ b/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts @@ -34,7 +34,7 @@ export function* createNetworkSaga( const payload: Community = { id, name: action.payload.name, - registrarUrl, + // registrarUrl, CA, rootCa: CA?.rootCertString, }