From 0c092a1824d5b04c09b520d7e9aa30a5004d8bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Fri, 7 Feb 2020 11:12:14 +0100 Subject: [PATCH 1/5] add web and nodejs builds --- babel.config.json | 18 +++++ babel.web.config.json | 20 ++++++ package.json | 31 ++++----- yarn.lock | 151 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 201 insertions(+), 19 deletions(-) create mode 100644 babel.config.json create mode 100644 babel.web.config.json diff --git a/babel.config.json b/babel.config.json new file mode 100644 index 0000000..362efd0 --- /dev/null +++ b/babel.config.json @@ -0,0 +1,18 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": "8" + } + } + ], + "@babel/preset-typescript" + ], + "plugins": [ + "@babel/plugin-proposal-object-rest-spread", + "@babel/plugin-proposal-export-default-from", + "@babel/plugin-proposal-async-generator-functions" + ] +} diff --git a/babel.web.config.json b/babel.web.config.json new file mode 100644 index 0000000..cc4d67e --- /dev/null +++ b/babel.web.config.json @@ -0,0 +1,20 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "browsers": "last 2 versions, ie 10-11" + }, + "modules": false + } + ], + "@babel/preset-typescript" + ], + "plugins": [ + "@babel/plugin-proposal-object-rest-spread", + "@babel/plugin-proposal-export-default-from", + "@babel/plugin-proposal-async-generator-functions", + "@babel/plugin-proposal-class-properties" + ] +} diff --git a/package.json b/package.json index 7ae6a24..272db3a 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,12 @@ "name": "js-libp2p-noise", "version": "1.0.0", "main": "dist/index.js", + "module": "lib/index.js", + "files": [ + "dist", + "lib", + "src" + ], "repository": "git@github.com:NodeFactoryIo/js-libp2p-noise.git", "author": "NodeFactory ", "license": "MIT", @@ -11,8 +17,10 @@ "crypto" ], "scripts": { - "prebuild": "rm -rf lib", - "build": "babel src -x .ts -d lib --source-maps", + "prebuild": "rm -rf lib && rm -rf dist", + "build": "yarn run build:node && yarn run build:web", + "build:node": "babel --config-file ./babel.config.json src -x .ts -d dist --source-maps", + "build:web": "babel --config-file ./babel.web.config.json src -x .ts -d lib --source-maps", "check-types": "tsc --incremental --noEmit", "lint": "eslint --ext .ts src/", "pretest": "yarn check-types", @@ -20,27 +28,12 @@ "test:node": "mocha -r ./babel-register.js \"test/**/*.test.ts\"", "test:web": "karma start" }, - "babel": { - "presets": [ - [ - "@babel/preset-env", - { - "targets": { - "node": "12" - } - } - ], - "@babel/preset-typescript" - ], - "plugins": [ - "@babel/plugin-proposal-object-rest-spread", - "@babel/plugin-proposal-async-generator-functions" - ] - }, "devDependencies": { "@babel/cli": "^7.6.4", "@babel/core": "^7.6.4", "@babel/plugin-proposal-async-generator-functions": "^7.7.0", + "@babel/plugin-proposal-class-properties": "^7.8.3", + "@babel/plugin-proposal-export-default-from": "^7.8.3", "@babel/plugin-proposal-object-rest-spread": "^7.6.2", "@babel/preset-env": "^7.6.3", "@babel/preset-typescript": "^7.6.0", diff --git a/yarn.lock b/yarn.lock index 6c37e74..f8536b0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26,6 +26,13 @@ dependencies: "@babel/highlight" "^7.0.0" +"@babel/code-frame@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.8.3.tgz#33e25903d7481181534e12ec0a25f16b6fcf419e" + integrity sha512-a9gxpmdXtZEInkCSHUJDLHZVBgb1QS0jhss4cPP93EW7s+uC5bikET2twEF3KV+7rDblJcmNvTR7VJejqd2C2g== + dependencies: + "@babel/highlight" "^7.8.3" + "@babel/core@^7.6.4": version "7.6.4" resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.6.4.tgz#6ebd9fe00925f6c3e177bb726a188b5f578088ff" @@ -66,6 +73,16 @@ lodash "^4.17.13" source-map "^0.5.0" +"@babel/generator@^7.8.4": + version "7.8.4" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.8.4.tgz#35bbc74486956fe4251829f9f6c48330e8d0985e" + integrity sha512-PwhclGdRpNAf3IxZb0YVuITPZmmrXz9zf6fH8lT4XbrmfQKr6ryBzhv593P5C6poJRciFCL/eHGW2NuGrgEyxA== + dependencies: + "@babel/types" "^7.8.3" + jsesc "^2.5.1" + lodash "^4.17.13" + source-map "^0.5.0" + "@babel/helper-annotate-as-pure@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz#323d39dd0b50e10c7c06ca7d7638e6864d8c5c32" @@ -109,6 +126,18 @@ "@babel/helper-replace-supers" "^7.5.5" "@babel/helper-split-export-declaration" "^7.4.4" +"@babel/helper-create-class-features-plugin@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.8.3.tgz#5b94be88c255f140fd2c10dd151e7f98f4bff397" + integrity sha512-qmp4pD7zeTxsv0JNecSBsEmG1ei2MqwJq4YQcK3ZWm/0t07QstWfvuV/vm3Qt5xNMFETn2SZqpMx2MQzbtq+KA== + dependencies: + "@babel/helper-function-name" "^7.8.3" + "@babel/helper-member-expression-to-functions" "^7.8.3" + "@babel/helper-optimise-call-expression" "^7.8.3" + "@babel/helper-plugin-utils" "^7.8.3" + "@babel/helper-replace-supers" "^7.8.3" + "@babel/helper-split-export-declaration" "^7.8.3" + "@babel/helper-define-map@^7.5.5": version "7.5.5" resolved "https://registry.yarnpkg.com/@babel/helper-define-map/-/helper-define-map-7.5.5.tgz#3dec32c2046f37e09b28c93eb0b103fd2a25d369" @@ -144,6 +173,15 @@ "@babel/template" "^7.7.0" "@babel/types" "^7.7.0" +"@babel/helper-function-name@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.8.3.tgz#eeeb665a01b1f11068e9fb86ad56a1cb1a824cca" + integrity sha512-BCxgX1BC2hD/oBlIFUgOCQDOPV8nSINxCwM3o93xP4P9Fq6aV5sgv2cOOITDMtCfQ+3PvHp3l689XZvAM9QyOA== + dependencies: + "@babel/helper-get-function-arity" "^7.8.3" + "@babel/template" "^7.8.3" + "@babel/types" "^7.8.3" + "@babel/helper-get-function-arity@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0.tgz#83572d4320e2a4657263734113c42868b64e49c3" @@ -158,6 +196,13 @@ dependencies: "@babel/types" "^7.7.0" +"@babel/helper-get-function-arity@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.8.3.tgz#b894b947bd004381ce63ea1db9f08547e920abd5" + integrity sha512-FVDR+Gd9iLjUMY1fzE2SR0IuaJToR4RkCDARVfsBBPSP53GEqSFjD8gNyxg246VUyc/ALRxFaAK8rVG7UT7xRA== + dependencies: + "@babel/types" "^7.8.3" + "@babel/helper-hoist-variables@^7.4.4": version "7.4.4" resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.4.4.tgz#0298b5f25c8c09c53102d52ac4a98f773eb2850a" @@ -172,6 +217,13 @@ dependencies: "@babel/types" "^7.5.5" +"@babel/helper-member-expression-to-functions@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.8.3.tgz#659b710498ea6c1d9907e0c73f206eee7dadc24c" + integrity sha512-fO4Egq88utkQFjbPrSHGmGLFqmrshs11d46WI+WZDESt7Wu7wN2G2Iu+NMMZJFDOVRHAMIkB5SNh30NtwCA7RA== + dependencies: + "@babel/types" "^7.8.3" + "@babel/helper-module-imports@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.0.0.tgz#96081b7111e486da4d2cd971ad1a4fe216cc2e3d" @@ -198,11 +250,23 @@ dependencies: "@babel/types" "^7.0.0" +"@babel/helper-optimise-call-expression@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.8.3.tgz#7ed071813d09c75298ef4f208956006b6111ecb9" + integrity sha512-Kag20n86cbO2AvHca6EJsvqAd82gc6VMGule4HwebwMlwkpXuVqrNRj6CkCV2sKxgi9MyAUnZVnZ6lJ1/vKhHQ== + dependencies: + "@babel/types" "^7.8.3" + "@babel/helper-plugin-utils@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250" integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA== +"@babel/helper-plugin-utils@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670" + integrity sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ== + "@babel/helper-regex@^7.0.0", "@babel/helper-regex@^7.4.4": version "7.5.5" resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.5.5.tgz#0aa6824f7100a2e0e89c1527c23936c152cab351" @@ -242,6 +306,16 @@ "@babel/traverse" "^7.5.5" "@babel/types" "^7.5.5" +"@babel/helper-replace-supers@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/helper-replace-supers/-/helper-replace-supers-7.8.3.tgz#91192d25f6abbcd41da8a989d4492574fb1530bc" + integrity sha512-xOUssL6ho41U81etpLoT2RTdvdus4VfHamCuAm4AHxGr+0it5fnwoVdwUJ7GFEqCsQYzJUhcbsN9wB9apcYKFA== + dependencies: + "@babel/helper-member-expression-to-functions" "^7.8.3" + "@babel/helper-optimise-call-expression" "^7.8.3" + "@babel/traverse" "^7.8.3" + "@babel/types" "^7.8.3" + "@babel/helper-simple-access@^7.1.0": version "7.1.0" resolved "https://registry.yarnpkg.com/@babel/helper-simple-access/-/helper-simple-access-7.1.0.tgz#65eeb954c8c245beaa4e859da6188f39d71e585c" @@ -264,6 +338,13 @@ dependencies: "@babel/types" "^7.7.0" +"@babel/helper-split-export-declaration@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.8.3.tgz#31a9f30070f91368a7182cf05f831781065fc7a9" + integrity sha512-3x3yOeyBhW851hroze7ElzdkeRXQYQbFIb7gLK1WQYsw2GWDay5gAJNw1sWJ0VFP6z5J1whqeXH/WCdCjZv6dA== + dependencies: + "@babel/types" "^7.8.3" + "@babel/helper-wrap-function@^7.1.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/helper-wrap-function/-/helper-wrap-function-7.2.0.tgz#c4e0012445769e2815b55296ead43a958549f6fa" @@ -302,6 +383,15 @@ esutils "^2.0.2" js-tokens "^4.0.0" +"@babel/highlight@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.8.3.tgz#28f173d04223eaaa59bc1d439a3836e6d1265797" + integrity sha512-PX4y5xQUvy0fnEVHrYOarRPXVWafSjTW9T0Hab8gVIawpl2Sj0ORyrygANq+KjcNlSSTw0YCLSNA8OyZ1I4yEg== + dependencies: + chalk "^2.0.0" + esutils "^2.0.2" + js-tokens "^4.0.0" + "@babel/parser@^7.6.0", "@babel/parser@^7.6.3", "@babel/parser@^7.6.4": version "7.6.4" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.6.4.tgz#cb9b36a7482110282d5cb6dd424ec9262b473d81" @@ -312,6 +402,11 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.7.3.tgz#5fad457c2529de476a248f75b0f090b3060af043" integrity sha512-bqv+iCo9i+uLVbI0ILzKkvMorqxouI+GbV13ivcARXn9NNEabi2IEz912IgNpT/60BNXac5dgcfjb94NjsF33A== +"@babel/parser@^7.8.3", "@babel/parser@^7.8.4": + version "7.8.4" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.8.4.tgz#d1dbe64691d60358a974295fa53da074dd2ce8e8" + integrity sha512-0fKu/QqildpXmPVaRBoXOlyBb3MC+J0A66x97qEfLOMkn3u6nfY5esWogQwi/K0BjASYy4DbnsEWnpNL6qT5Mw== + "@babel/plugin-proposal-async-generator-functions@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.2.0.tgz#b289b306669dce4ad20b0252889a15768c9d417e" @@ -330,6 +425,14 @@ "@babel/helper-remap-async-to-generator" "^7.7.0" "@babel/plugin-syntax-async-generators" "^7.2.0" +"@babel/plugin-proposal-class-properties@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.8.3.tgz#5e06654af5cd04b608915aada9b2a6788004464e" + integrity sha512-EqFhbo7IosdgPgZggHaNObkmO1kNUe3slaKu54d5OWvy+p9QIKOzK1GAEpAIsZtWVtPXUHSMcT4smvDrCfY4AA== + dependencies: + "@babel/helper-create-class-features-plugin" "^7.8.3" + "@babel/helper-plugin-utils" "^7.8.3" + "@babel/plugin-proposal-dynamic-import@^7.5.0": version "7.5.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.5.0.tgz#e532202db4838723691b10a67b8ce509e397c506" @@ -338,6 +441,14 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-dynamic-import" "^7.2.0" +"@babel/plugin-proposal-export-default-from@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-export-default-from/-/plugin-proposal-export-default-from-7.8.3.tgz#4cb7c2fdeaed490b60d9bfd3dc8a20f81f9c2e7c" + integrity sha512-PYtv2S2OdCdp7GSPDg5ndGZFm9DmWFvuLoS5nBxZCgOBggluLnhTScspJxng96alHQzPyrrHxvC9/w4bFuspeA== + dependencies: + "@babel/helper-plugin-utils" "^7.8.3" + "@babel/plugin-syntax-export-default-from" "^7.8.3" + "@babel/plugin-proposal-json-strings@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-json-strings/-/plugin-proposal-json-strings-7.2.0.tgz#568ecc446c6148ae6b267f02551130891e29f317" @@ -385,6 +496,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-syntax-export-default-from@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-export-default-from/-/plugin-syntax-export-default-from-7.8.3.tgz#f1e55ce850091442af4ba9c2550106035b29d678" + integrity sha512-a1qnnsr73KLNIQcQlcQ4ZHxqqfBKM6iNQZW2OMTyxNbA2WC7SHWHtGVpFzWtQAuS2pspkWVzdEBXXx8Ik0Za4w== + dependencies: + "@babel/helper-plugin-utils" "^7.8.3" + "@babel/plugin-syntax-json-strings@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.2.0.tgz#72bd13f6ffe1d25938129d2a186b11fd62951470" @@ -768,6 +886,15 @@ "@babel/parser" "^7.7.0" "@babel/types" "^7.7.0" +"@babel/template@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.8.3.tgz#e02ad04fe262a657809327f578056ca15fd4d1b8" + integrity sha512-04m87AcQgAFdvuoyiQ2kgELr2tV8B4fP/xJAVUL3Yb3bkNdMedD3d0rlSQr3PegP0cms3eHjl1F7PWlvWbU8FQ== + dependencies: + "@babel/code-frame" "^7.8.3" + "@babel/parser" "^7.8.3" + "@babel/types" "^7.8.3" + "@babel/traverse@^7.1.0", "@babel/traverse@^7.4.4", "@babel/traverse@^7.5.5", "@babel/traverse@^7.6.2", "@babel/traverse@^7.6.3": version "7.6.3" resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.6.3.tgz#66d7dba146b086703c0fb10dd588b7364cec47f9" @@ -798,6 +925,21 @@ globals "^11.1.0" lodash "^4.17.13" +"@babel/traverse@^7.8.3": + version "7.8.4" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.8.4.tgz#f0845822365f9d5b0e312ed3959d3f827f869e3c" + integrity sha512-NGLJPZwnVEyBPLI+bl9y9aSnxMhsKz42so7ApAv9D+b4vAFPpY013FTS9LdKxcABoIYFU52HcYga1pPlx454mg== + dependencies: + "@babel/code-frame" "^7.8.3" + "@babel/generator" "^7.8.4" + "@babel/helper-function-name" "^7.8.3" + "@babel/helper-split-export-declaration" "^7.8.3" + "@babel/parser" "^7.8.4" + "@babel/types" "^7.8.3" + debug "^4.1.0" + globals "^11.1.0" + lodash "^4.17.13" + "@babel/types@^7.0.0", "@babel/types@^7.2.0", "@babel/types@^7.4.4", "@babel/types@^7.5.5", "@babel/types@^7.6.0", "@babel/types@^7.6.3": version "7.6.3" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.6.3.tgz#3f07d96f854f98e2fbd45c64b0cb942d11e8ba09" @@ -816,6 +958,15 @@ lodash "^4.17.13" to-fast-properties "^2.0.0" +"@babel/types@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.8.3.tgz#5a383dffa5416db1b73dedffd311ffd0788fb31c" + integrity sha512-jBD+G8+LWpMBBWvVcdr4QysjUE4mU/syrhN17o1u3gx0/WzJB1kwiVZAXRtWbsIPOwW8pF/YJV5+nmetPzepXg== + dependencies: + esutils "^2.0.2" + lodash "^4.17.13" + to-fast-properties "^2.0.0" + "@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf" From 725a1e180db6151b69eb1b99cc65c46d9ab151f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Fri, 7 Feb 2020 12:59:30 +0100 Subject: [PATCH 2/5] add web and nodejs builds --- .babelrc | 18 ++++++++++++++ README.md | 3 ++- babel.config.json | 2 +- babel.web.config.json | 2 +- yarn.lock | 56 ++++++++++++++++++++++++++++++------------- 5 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..7cdd358 --- /dev/null +++ b/.babelrc @@ -0,0 +1,18 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": "10" + } + } + ], + "@babel/preset-typescript" + ], + "plugins": [ + "@babel/plugin-proposal-object-rest-spread", + "@babel/plugin-proposal-export-default-from", + "@babel/plugin-proposal-async-generator-functions" + ] +} diff --git a/README.md b/README.md index b7d6a7e..55d728f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ ![](https://img.shields.io/github/license/nodefactoryio/js-libp2p-noise) [![Build Status](https://travis-ci.com/NodeFactoryIo/js-libp2p-noise.svg?branch=master)](https://travis-ci.com/NodeFactoryIo/js-libp2p-noise) ![](https://img.shields.io/badge/yarn-%3E%3D1.17.0-orange.svg?style=flat-square) -![](https://img.shields.io/badge/Node.js-%3E%3D12.4.0-orange.svg?style=flat-square) +![](https://img.shields.io/badge/Node.js-%3E%3D10.19.0-orange.svg?style=flat-square) +![](https://img.shields.io/badge/browsers-last%202%20versions%2C%20not%20ie%20%3C%3D11-orange) [![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io) > Noise libp2p handshake for js-libp2p diff --git a/babel.config.json b/babel.config.json index 362efd0..7cdd358 100644 --- a/babel.config.json +++ b/babel.config.json @@ -4,7 +4,7 @@ "@babel/preset-env", { "targets": { - "node": "8" + "node": "10" } } ], diff --git a/babel.web.config.json b/babel.web.config.json index cc4d67e..d495526 100644 --- a/babel.web.config.json +++ b/babel.web.config.json @@ -4,7 +4,7 @@ "@babel/preset-env", { "targets": { - "browsers": "last 2 versions, ie 10-11" + "browsers": "last 2 versions, not ie <=11" }, "modules": false } diff --git a/yarn.lock b/yarn.lock index f8536b0..59418cd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1986,15 +1986,15 @@ chrome-trace-event@^1.0.2: dependencies: tslib "^1.9.0" -cids@~0.7.1: - version "0.7.1" - resolved "https://registry.yarnpkg.com/cids/-/cids-0.7.1.tgz#d8bba49a35a0e82110879b5001abf1039c62347f" - integrity sha512-qEM4j2GKE/BiT6WdUi6cfW8dairhSLTUE8tIdxJG6SvY33Mp/UPjw+xcO0n1zsllgo72BupzKF/44v+Bg8YPPg== +cids@^0.7.3: + version "0.7.3" + resolved "https://registry.yarnpkg.com/cids/-/cids-0.7.3.tgz#2069c7277c71261717e6844e2e547ca133ccc560" + integrity sha512-V0xa0oFIH1GGsGE4vaTsAgiTkrZw3wUVOTAVN/oZU8ptW6oaz4cOdFbqRv+tbienIZq5bG2ok0CRKfUurUtFnA== dependencies: class-is "^1.1.0" multibase "~0.6.0" - multicodec "~0.5.1" - multihashes "~0.4.14" + multicodec "^1.0.0" + multihashes "~0.4.15" cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: version "1.0.4" @@ -3826,7 +3826,7 @@ libp2p-crypto-secp256k1@~0.4.0: safe-buffer "^5.1.2" secp256k1 "^3.6.2" -libp2p-crypto@^0.17.1, libp2p-crypto@~0.17.0: +libp2p-crypto@^0.17.1: version "0.17.1" resolved "https://registry.yarnpkg.com/libp2p-crypto/-/libp2p-crypto-0.17.1.tgz#20da30d133930e589d9b68057859c65ae677a7cf" integrity sha512-IPz/rn8OtHY1Lae2teowSLw6UMqjkL0eM1fVOdPWRrB8fobDfPuwp67E3v7xGtarf6JSYpugsqTj89KEgbcBtw== @@ -3848,6 +3848,28 @@ libp2p-crypto@^0.17.1, libp2p-crypto@~0.17.0: tweetnacl "^1.0.1" ursa-optional "~0.10.1" +libp2p-crypto@~0.17.2: + version "0.17.2" + resolved "https://registry.yarnpkg.com/libp2p-crypto/-/libp2p-crypto-0.17.2.tgz#a45a93e047fac02ed3391d772749598fdee85c3a" + integrity sha512-mCzxbmqJhZF6AvyJPg80dyobOd2JJZm9BDQNLAkVFvC8d29tPox+Rub9v+AK+QILj8gzzQUj2W1ZLTNLhC98Xg== + dependencies: + asmcrypto.js "^2.3.2" + asn1.js "^5.2.0" + bn.js "^5.0.0" + browserify-aes "^1.2.0" + bs58 "^4.0.1" + err-code "^1.1.2" + iso-random-stream "^1.1.0" + keypair "^1.0.1" + libp2p-crypto-secp256k1 "~0.4.0" + multihashing-async "~0.8.0" + node-forge "~0.9.1" + pem-jwk "^2.0.0" + protons "^1.0.1" + rsa-pem-to-jwk "^1.1.3" + tweetnacl "^1.0.1" + ursa-optional "~0.10.1" + loader-runner@^2.4.0: version "2.4.0" resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.4.0.tgz#ed47066bfe534d7e84c4c7b9998c2a75607d9357" @@ -4195,14 +4217,14 @@ multibase@~0.6.0: dependencies: base-x "3.0.4" -multicodec@~0.5.1: - version "0.5.5" - resolved "https://registry.yarnpkg.com/multicodec/-/multicodec-0.5.5.tgz#55c2535b44eca9ea40a13771420153fe075bb36d" - integrity sha512-1kOifvwAqp9IdiiTKmpK2tS+LY6GHZdKpk3S2EvW4T32vlwDyA3hJoZtGauzqdedUPVNGChnTksEotVOCVlC+Q== +multicodec@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/multicodec/-/multicodec-1.0.0.tgz#75652ff96cc30f63bb56264ef5c7e6526bc0becb" + integrity sha512-CBiLdYcMnVnkN/2kL4AaUH3betYXQGKV5CCmN2CfgHUt5xROtsj91w780ltX6Wy7frgc6en8md3h2UQl6jDXAg== dependencies: varint "^5.0.0" -multihashes@~0.4.13, multihashes@~0.4.14, multihashes@~0.4.15: +multihashes@~0.4.13, multihashes@~0.4.15: version "0.4.15" resolved "https://registry.yarnpkg.com/multihashes/-/multihashes-0.4.15.tgz#6dbc55f7f312c6782f5367c03c9783681589d8a6" integrity sha512-G/Smj1GWqw1RQP3dRuRRPe3oyLqvPqUaEDIaoi7JF7Loxl4WAWvhJNk84oyDEodSucv0MmSW/ZT0RKUrsIFD3g== @@ -4714,13 +4736,13 @@ pbkdf2@^3.0.3: sha.js "^2.4.8" peer-id@^0.13.5: - version "0.13.5" - resolved "https://registry.yarnpkg.com/peer-id/-/peer-id-0.13.5.tgz#1a0fd8e11a6b62be1304830ca52abe89fd151898" - integrity sha512-vDdiP4Qb6yiKD2cKyJqEdL08gL+/847Rbl8qBm+Q7mcrsbzzMzwQ5IBQ2yUeb0um71V5ny5/JqH83wFXv6wSmg== + version "0.13.7" + resolved "https://registry.yarnpkg.com/peer-id/-/peer-id-0.13.7.tgz#001968fe8d0223f93f724d0cf39ec181adc2c624" + integrity sha512-m8LjezhG614dXCFB1WGAytdt3+kKZ0cadAbNq+wOM5dLseevwMt9weLVWAkFRYDtoOrhjlUxscBvj+KtwPm7oA== dependencies: - cids "~0.7.1" + cids "^0.7.3" class-is "^1.1.0" - libp2p-crypto "~0.17.0" + libp2p-crypto "~0.17.2" multihashes "~0.4.15" protons "^1.0.1" From 2f2476b146e5da6316b011629816c2654cc3fa3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Fri, 7 Feb 2020 12:59:52 +0100 Subject: [PATCH 3/5] use built in peer id types --- src/@types/libp2p.ts | 13 +------------ src/handshake-ik.ts | 3 ++- src/handshake-xx-fallback.ts | 22 ++++++++++------------ src/handshake-xx.ts | 3 ++- src/keycache.ts | 2 +- src/noise.ts | 16 ++++++++++------ 6 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/@types/libp2p.ts b/src/@types/libp2p.ts index 8f0ac27..e31acaa 100644 --- a/src/@types/libp2p.ts +++ b/src/@types/libp2p.ts @@ -1,23 +1,12 @@ import { bytes, bytes32 } from "./basic"; import { Duplex } from "it-pair"; +import PeerId from "peer-id"; export type KeyPair = { publicKey: bytes32; privateKey: bytes32; } -export type PeerId = { - id: bytes; - privKey: { - marshal(): bytes; - }; - pubKey: { - marshal(): bytes; - }; - marshalPubKey(): bytes; - marshalPrivKey(): bytes; -}; - export interface INoiseConnection { remoteEarlyData?(): bytes; secureOutbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise; diff --git a/src/handshake-ik.ts b/src/handshake-ik.ts index 9e50a0e..e2bfb35 100644 --- a/src/handshake-ik.ts +++ b/src/handshake-ik.ts @@ -2,13 +2,14 @@ import {WrappedConnection} from "./noise"; import {IK} from "./handshakes/ik"; import {NoiseSession} from "./@types/handshake"; import {bytes, bytes32} from "./@types/basic"; -import {KeyPair, PeerId} from "./@types/libp2p"; +import {KeyPair} from "./@types/libp2p"; import {IHandshake} from "./@types/handshake-interface"; import {Buffer} from "buffer"; import {decode0, decode1, encode0, encode1} from "./encoder"; import {verifySignedPayload} from "./utils"; import {FailedIKError} from "./errors"; import {logger} from "./logger"; +import PeerId from "peer-id"; export class IKHandshake implements IHandshake { public isInitiator: boolean; diff --git a/src/handshake-xx-fallback.ts b/src/handshake-xx-fallback.ts index 23cef09..301fc3e 100644 --- a/src/handshake-xx-fallback.ts +++ b/src/handshake-xx-fallback.ts @@ -1,15 +1,13 @@ -import { Buffer } from "buffer"; - -import { XXHandshake } from "./handshake-xx"; -import { XX } from "./handshakes/xx"; -import { KeyPair, PeerId } from "./@types/libp2p"; -import { bytes, bytes32 } from "./@types/basic"; -import { - verifySignedPayload, -} from "./utils"; -import { logger } from "./logger"; -import { WrappedConnection } from "./noise"; -import {decode0, decode1, encode1} from "./encoder"; +import {Buffer} from "buffer"; +import {XXHandshake} from "./handshake-xx"; +import {XX} from "./handshakes/xx"; +import {KeyPair} from "./@types/libp2p"; +import {bytes, bytes32} from "./@types/basic"; +import {verifySignedPayload,} from "./utils"; +import {logger} from "./logger"; +import {WrappedConnection} from "./noise"; +import {decode0, decode1} from "./encoder"; +import PeerId from "peer-id"; export class XXFallbackHandshake extends XXHandshake { private ephemeralKeys?: KeyPair; diff --git a/src/handshake-xx.ts b/src/handshake-xx.ts index 1453e95..e6d0aff 100644 --- a/src/handshake-xx.ts +++ b/src/handshake-xx.ts @@ -1,7 +1,7 @@ import { Buffer } from "buffer"; import { XX } from "./handshakes/xx"; -import { KeyPair, PeerId } from "./@types/libp2p"; +import { KeyPair } from "./@types/libp2p"; import { bytes, bytes32 } from "./@types/basic"; import { NoiseSession } from "./@types/handshake"; import {IHandshake} from "./@types/handshake-interface"; @@ -11,6 +11,7 @@ import { import { logger } from "./logger"; import { decode0, decode1, encode0, encode1 } from "./encoder"; import { WrappedConnection } from "./noise"; +import PeerId from "peer-id"; export class XXHandshake implements IHandshake { public isInitiator: boolean; diff --git a/src/keycache.ts b/src/keycache.ts index 24cbcc0..d095d80 100644 --- a/src/keycache.ts +++ b/src/keycache.ts @@ -1,5 +1,5 @@ -import {PeerId} from "./@types/libp2p"; import {bytes, bytes32} from "./@types/basic"; +import PeerId from "peer-id"; /** * Storage for static keys of previously connected peers. diff --git a/src/noise.ts b/src/noise.ts index 3706945..291bd02 100644 --- a/src/noise.ts +++ b/src/noise.ts @@ -13,11 +13,12 @@ import { generateKeypair, getPayload } from "./utils"; import { uint16BEDecode, uint16BEEncode } from "./encoder"; import { decryptStream, encryptStream } from "./crypto"; import { bytes } from "./@types/basic"; -import { INoiseConnection, PeerId, KeyPair, SecureOutbound } from "./@types/libp2p"; +import { INoiseConnection, KeyPair, SecureOutbound } from "./@types/libp2p"; import { Duplex } from "./@types/it-pair"; import {IHandshake} from "./@types/handshake-interface"; import {KeyCache} from "./keycache"; import {logger} from "./logger"; +import PeerId from "peer-id"; export type WrappedConnection = ReturnType; @@ -36,12 +37,18 @@ export class Noise implements INoiseConnection { private readonly earlyData?: bytes; private useNoisePipes: boolean; + /** + * + * @param staticNoiseKey + * @param earlyData + * @param useNoisePipes + */ constructor(staticNoiseKey?: bytes, earlyData?: bytes, useNoisePipes = true) { this.earlyData = earlyData || Buffer.alloc(0); this.useNoisePipes = useNoisePipes; if (staticNoiseKey) { - const publicKey = x25519.publicKeyCreate(staticNoiseKey); // TODO: verify this + const publicKey = x25519.publicKeyCreate(staticNoiseKey); this.staticKeys = { privateKey: staticNoiseKey, publicKey, @@ -100,10 +107,7 @@ export class Noise implements INoiseConnection { /** * If Noise pipes supported, tries IK handshake first with XX as fallback if it fails. * If noise pipes disabled or remote peer static key is unknown, use XX. - * @param connection - * @param isInitiator - * @param libp2pPublicKey - * @param remotePeer + * @param params */ private async performHandshake(params: HandshakeParams): Promise { const payload = await getPayload(params.localPeer, this.staticKeys.publicKey, this.earlyData); From 09f98fcc123752082f42204e5868aeef3548adc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Fri, 7 Feb 2020 13:06:42 +0100 Subject: [PATCH 4/5] update docs --- README.md | 7 +++++-- package.json | 2 +- src/index.ts | 6 ++++++ src/noise.ts | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 55d728f..cfebb52 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,12 @@ This repository contains TypeScript implementation of noise protocol, an encrypt When published, package should be imported as: `import { Noise } from 'libp2p-noise'`. -Example of instantiating noise and passing it to the libp2p config: +Example of using default noise configuration and passing it to the libp2p config: ``` -const NOISE = new Noise(privateKey); +import {NOISE, Noise} from "@nodefactory/js-libp2p-noise" + +//custom noise configuration, pass it instead of NOISE object +const noise = new Noise(privateKey, Buffer.alloc(), false); const libp2p = new Libp2p({ modules: { diff --git a/package.json b/package.json index 272db3a..69bca3c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-libp2p-noise", - "version": "1.0.0", + "version": "1.0.0-beta", "main": "dist/index.js", "module": "lib/index.js", "files": [ diff --git a/src/index.ts b/src/index.ts index e481514..2c1d8b3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,7 @@ +import {Noise} from "./noise"; export * from "./noise"; + +/** + * Default configuration, it will generate new noise static key and enable noise pipes (IK handshake). + */ +export const NOISE = new Noise(); diff --git a/src/noise.ts b/src/noise.ts index 291bd02..e089465 100644 --- a/src/noise.ts +++ b/src/noise.ts @@ -39,9 +39,9 @@ export class Noise implements INoiseConnection { /** * - * @param staticNoiseKey + * @param staticNoiseKey x25519 private key, reuse for faster handshakes * @param earlyData - * @param useNoisePipes + * @param useNoisePipes enable IK handshake if initiator static key is known */ constructor(staticNoiseKey?: bytes, earlyData?: bytes, useNoisePipes = true) { this.earlyData = earlyData || Buffer.alloc(0); From 702227bc39d912a7074265dc912ba6535057c84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Fri, 7 Feb 2020 13:27:24 +0100 Subject: [PATCH 5/5] add npm publish github action --- .github/workflows/npm-publish.yml | 25 +++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/npm-publish.yml diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..3073580 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,25 @@ +name: npm-publish +on: + push: + branches: + - master # Change this to your default branch +jobs: + npm-publish: + name: npm-publish + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@master + - name: Set up Node.js + uses: actions/setup-node@master + with: + node-version: 12.4.0 + - name: Publish if version has been updated + uses: pascalgn/npm-publish-action@51fdb4531e99aac1873764ef7271af448dc42ab4 + with: # All of theses inputs are optional + tag_name: "v%s" + tag_message: "v%s" + commit_pattern: "^Release (\\S+)" + env: # More info about the environment variables in the README + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated + NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # You need to set this in your repo settings diff --git a/package.json b/package.json index 69bca3c..ff8ba7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-libp2p-noise", - "version": "1.0.0-beta", + "version": "1.0.0-rc", "main": "dist/index.js", "module": "lib/index.js", "files": [