{"action":"created","issue":{"url":"https://api.github.com/repos/libp2p/js-libp2p-crypto/issues/131","repository_url":"https://api.github.com/repos/libp2p/js-libp2p-crypto","labels_url":"https://api.github.com/repos/libp2p/js-libp2p-crypto/issues/131/labels{/name}","comments_url":"https://api.github.com/repos/libp2p/js-libp2p-crypto/issues/131/comments","events_url":"https://api.github.com/repos/libp2p/js-libp2p-crypto/issues/131/events","html_url":"https://github.com/libp2p/js-libp2p-crypto/pull/131","id":374622692,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI2Mjc5ODQ0","number":131,"title":"[WIP] feat: use async await","user":{"login":"alanshaw","id":152863,"node_id":"MDQ6VXNlcjE1Mjg2Mw==","avatar_url":"https://avatars1.githubusercontent.com/u/152863?v=4","gravatar_id":"","url":"https://api.github.com/users/alanshaw","html_url":"https://github.com/alanshaw","followers_url":"https://api.github.com/users/alanshaw/followers","following_url":"https://api.github.com/users/alanshaw/following{/other_user}","gists_url":"https://api.github.com/users/alanshaw/gists{/gist_id}","starred_url":"https://api.github.com/users/alanshaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alanshaw/subscriptions","organizations_url":"https://api.github.com/users/alanshaw/orgs","repos_url":"https://api.github.com/users/alanshaw/repos","events_url":"https://api.github.com/users/alanshaw/events{/privacy}","received_events_url":"https://api.github.com/users/alanshaw/received_events","type":"User","site_admin":false},"labels":[{"id":419592430,"node_id":"MDU6TGFiZWw0MTk1OTI0MzA=","url":"https://api.github.com/repos/libp2p/js-libp2p-crypto/labels/in%20progress","name":"in progress","color":"ededed","default":false}],"state":"open","locked":false,"assignee":{"login":"alanshaw","id":152863,"node_id":"MDQ6VXNlcjE1Mjg2Mw==","avatar_url":"https://avatars1.githubusercontent.com/u/152863?v=4","gravatar_id":"","url":"https://api.github.com/users/alanshaw","html_url":"https://github.com/alanshaw","followers_url":"https://api.github.com/users/alanshaw/followers","following_url":"https://api.github.com/users/alanshaw/following{/other_user}","gists_url":"https://api.github.com/users/alanshaw/gists{/gist_id}","starred_url":"https://api.github.com/users/alanshaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alanshaw/subscriptions","organizations_url":"https://api.github.com/users/alanshaw/orgs","repos_url":"https://api.github.com/users/alanshaw/repos","events_url":"https://api.github.com/users/alanshaw/events{/privacy}","received_events_url":"https://api.github.com/users/alanshaw/received_events","type":"User","site_admin":false},"assignees":[{"login":"alanshaw","id":152863,"node_id":"MDQ6VXNlcjE1Mjg2Mw==","avatar_url":"https://avatars1.githubusercontent.com/u/152863?v=4","gravatar_id":"","url":"https://api.github.com/users/alanshaw","html_url":"https://github.com/alanshaw","followers_url":"https://api.github.com/users/alanshaw/followers","following_url":"https://api.github.com/users/alanshaw/following{/other_user}","gists_url":"https://api.github.com/users/alanshaw/gists{/gist_id}","starred_url":"https://api.github.com/users/alanshaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alanshaw/subscriptions","organizations_url":"https://api.github.com/users/alanshaw/orgs","repos_url":"https://api.github.com/users/alanshaw/repos","events_url":"https://api.github.com/users/alanshaw/events{/privacy}","received_events_url":"https://api.github.com/users/alanshaw/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2018-10-27T08:44:27Z","updated_at":"2018-10-28T14:44:31Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/libp2p/js-libp2p-crypto/pulls/131","html_url":"https://github.com/libp2p/js-libp2p-crypto/pull/131","diff_url":"https://github.com/libp2p/js-libp2p-crypto/pull/131.diff","patch_url":"https://github.com/libp2p/js-libp2p-crypto/pull/131.patch"},"body":"This PR changes this module to remove callbacks and use async/await. The API is unchanged aside from the obvious removal of the `callback` parameter.\r\n\r\n## Notes\r\n\r\n### `async` keyword\r\n\r\nI've labeled API methods that are asynchronous with the `async` keyword even if they don't actually use `await`. I'm interested to hear views on this but I think it communicates the intention of the function better even if it is not required. A contrived example:\r\n\r\n```js\r\nasync function publicApiFn (type) {\r\n  type = type.toLowerCase()\r\n  return _privateFn(type) // an async function / returns a promise\r\n}\r\n```\r\n\r\n`publicApiFn` doesn't actually use `await`, so `async` is not strictly required. However the `async` keyword helps communicate the fact that it returns a promise so you can use it without having to track down `_privateFn` to see what that returns.\r\n\r\nThe other reason for doing this is if a consumer is using `then/catch` and `type.toLowerCase()` throws, then it'll be caught in the catch block. Without the `async` keyword it'll be an uncaught exception.\r\n\r\n### Mostly synchronous API\r\n\r\nThere's a lot of functions labelled as async that don't actually do anything async! This is largely because the Node.js crypto API is synchronous. However the webcrypto API is async so I assume this has been done to present a consistent interface to developers in both Node.js and the browser. Maybe someone can verify that for me?\r\n\r\n---\r\n\r\ndepends on `multihashing-async` PR TODO\r\ndepends on `libp2p-crypto-secp256k1` PR TODO\r\n\r\nrefs https://github.com/ipfs/js-ipfs/issues/1670\r\n\r\n---\r\n\r\n# Benchmarks\r\n\r\n## Before\r\n\r\n```\r\n$ node benchmarks/ephemeral-keys.js \r\nephemeral key with secrect P-256 x 5,825 ops/sec ±2.25% (74 runs sampled)\r\nephemeral key with secrect P-384 x 5,938 ops/sec ±3.78% (77 runs sampled)\r\nephemeral key with secrect P-521 x 6,044 ops/sec ±2.72% (77 runs sampled)\r\n\r\n$ node benchmarks/key-stretcher.js \r\nkeyStretcher AES-128 SHA1 x 9,810 ops/sec ±3.23% (72 runs sampled)\r\nkeyStretcher AES-128 SHA256 x 13,401 ops/sec ±4.01% (74 runs sampled)\r\nkeyStretcher AES-128 SHA512 x 22,072 ops/sec ±4.63% (70 runs sampled)\r\nkeyStretcher AES-256 SHA1 x 8,631 ops/sec ±2.72% (76 runs sampled)\r\nkeyStretcher AES-256 SHA256 x 10,794 ops/sec ±5.49% (71 runs sampled)\r\nkeyStretcher AES-256 SHA512 x 16,027 ops/sec ±6.36% (74 runs sampled)\r\nkeyStretcher Blowfish SHA1 x 81,146 ops/sec ±9.82% (71 runs sampled)\r\nkeyStretcher Blowfish SHA256 x 75,919 ops/sec ±13.66% (72 runs sampled)\r\nkeyStretcher Blowfish SHA512 x 70,505 ops/sec ±20.75% (67 runs sampled)\r\n\r\n$ node benchmarks/rsa.js \r\ngenerateKeyPair 1024bits x 73.18 ops/sec ±6.67% (53 runs sampled)\r\ngenerateKeyPair 2048bits x 16.51 ops/sec ±15.23% (30 runs sampled)\r\ngenerateKeyPair 4096bits x 1.89 ops/sec ±47.81% (14 runs sampled)\r\nsign and verify x 1,887 ops/sec ±1.77% (73 runs sampled)\r\n```\r\n\r\n## After\r\n\r\n```\r\n$ node benchmarks/ephemeral-keys.js \r\nephemeral key with secrect P-256 x 6,275 ops/sec ±2.17% (76 runs sampled)\r\nephemeral key with secrect P-384 x 6,291 ops/sec ±3.32% (78 runs sampled)\r\nephemeral key with secrect P-521 x 6,272 ops/sec ±3.35% (76 runs sampled)\r\n\r\n$ node benchmarks/key-stretcher.js \r\nkeyStretcher AES-128 SHA1 x 16,948 ops/sec ±1.23% (80 runs sampled)\r\nkeyStretcher AES-128 SHA256 x 22,188 ops/sec ±1.48% (76 runs sampled)\r\nkeyStretcher AES-128 SHA512 x 34,204 ops/sec ±2.26% (77 runs sampled)\r\nkeyStretcher AES-256 SHA1 x 14,910 ops/sec ±0.85% (82 runs sampled)\r\nkeyStretcher AES-256 SHA256 x 17,841 ops/sec ±1.75% (77 runs sampled)\r\nkeyStretcher AES-256 SHA512 x 26,028 ops/sec ±1.57% (73 runs sampled)\r\nkeyStretcher Blowfish SHA1 x 113,697 ops/sec ±8.02% (75 runs sampled)\r\nkeyStretcher Blowfish SHA256 x 93,089 ops/sec ±28.10% (55 runs sampled)\r\nkeyStretcher Blowfish SHA512 x 34,725 ops/sec ±50.76% (29 runs sampled)\r\n\r\n$ node benchmarks/rsa.js \r\ngenerateKeyPair 1024bits x 71.01 ops/sec ±7.37% (48 runs sampled)\r\ngenerateKeyPair 2048bits x 13.97 ops/sec ±10.97% (34 runs sampled)\r\ngenerateKeyPair 4096bits x 2.59 ops/sec ±29.13% (17 runs sampled)\r\nsign and verify x 1,989 ops/sec ±5.39% (79 runs sampled)\r\n```"},"comment":{"url":"https://api.github.com/repos/libp2p/js-libp2p-crypto/issues/comments/433711818","html_url":"https://github.com/libp2p/js-libp2p-crypto/pull/131#issuecomment-433711818","issue_url":"https://api.github.com/repos/libp2p/js-libp2p-crypto/issues/131","id":433711818,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMzcxMTgxOA==","user":{"login":"alanshaw","id":152863,"node_id":"MDQ6VXNlcjE1Mjg2Mw==","avatar_url":"https://avatars1.githubusercontent.com/u/152863?v=4","gravatar_id":"","url":"https://api.github.com/users/alanshaw","html_url":"https://github.com/alanshaw","followers_url":"https://api.github.com/users/alanshaw/followers","following_url":"https://api.github.com/users/alanshaw/following{/other_user}","gists_url":"https://api.github.com/users/alanshaw/gists{/gist_id}","starred_url":"https://api.github.com/users/alanshaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alanshaw/subscriptions","organizations_url":"https://api.github.com/users/alanshaw/orgs","repos_url":"https://api.github.com/users/alanshaw/repos","events_url":"https://api.github.com/users/alanshaw/events{/privacy}","received_events_url":"https://api.github.com/users/alanshaw/received_events","type":"User","site_admin":false},"created_at":"2018-10-28T14:44:31Z","updated_at":"2018-10-28T14:44:31Z","author_association":"MEMBER","body":"@mkg20001 any idea why `ursa-optional` is failing to install on windows now? We get no error message :("}}
{"actor":{"display_login":"alanshaw"}}