{"action":"created","issue":{"url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-ossl/issues/123","repository_url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-ossl","labels_url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-ossl/issues/123/labels{/name}","comments_url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-ossl/issues/123/comments","events_url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-ossl/issues/123/events","html_url":"https://github.com/PeculiarVentures/node-webcrypto-ossl/issues/123","id":310795864,"number":123,"title":"Public key information is not mandatory for ECDSA private keys","user":{"login":"YuryStrozhevsky","id":6128446,"avatar_url":"https://avatars0.githubusercontent.com/u/6128446?v=4","gravatar_id":"","url":"https://api.github.com/users/YuryStrozhevsky","html_url":"https://github.com/YuryStrozhevsky","followers_url":"https://api.github.com/users/YuryStrozhevsky/followers","following_url":"https://api.github.com/users/YuryStrozhevsky/following{/other_user}","gists_url":"https://api.github.com/users/YuryStrozhevsky/gists{/gist_id}","starred_url":"https://api.github.com/users/YuryStrozhevsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YuryStrozhevsky/subscriptions","organizations_url":"https://api.github.com/users/YuryStrozhevsky/orgs","repos_url":"https://api.github.com/users/YuryStrozhevsky/repos","events_url":"https://api.github.com/users/YuryStrozhevsky/events{/privacy}","received_events_url":"https://api.github.com/users/YuryStrozhevsky/received_events","type":"User","site_admin":false},"labels":[{"id":304071883,"url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-ossl/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":{"login":"microshine","id":7333669,"avatar_url":"https://avatars3.githubusercontent.com/u/7333669?v=4","gravatar_id":"","url":"https://api.github.com/users/microshine","html_url":"https://github.com/microshine","followers_url":"https://api.github.com/users/microshine/followers","following_url":"https://api.github.com/users/microshine/following{/other_user}","gists_url":"https://api.github.com/users/microshine/gists{/gist_id}","starred_url":"https://api.github.com/users/microshine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/microshine/subscriptions","organizations_url":"https://api.github.com/users/microshine/orgs","repos_url":"https://api.github.com/users/microshine/repos","events_url":"https://api.github.com/users/microshine/events{/privacy}","received_events_url":"https://api.github.com/users/microshine/received_events","type":"User","site_admin":false},"assignees":[{"login":"microshine","id":7333669,"avatar_url":"https://avatars3.githubusercontent.com/u/7333669?v=4","gravatar_id":"","url":"https://api.github.com/users/microshine","html_url":"https://github.com/microshine","followers_url":"https://api.github.com/users/microshine/followers","following_url":"https://api.github.com/users/microshine/following{/other_user}","gists_url":"https://api.github.com/users/microshine/gists{/gist_id}","starred_url":"https://api.github.com/users/microshine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/microshine/subscriptions","organizations_url":"https://api.github.com/users/microshine/orgs","repos_url":"https://api.github.com/users/microshine/repos","events_url":"https://api.github.com/users/microshine/events{/privacy}","received_events_url":"https://api.github.com/users/microshine/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-04-03T11:21:53Z","updated_at":"2018-04-03T12:51:25Z","closed_at":null,"author_association":"NONE","body":"When I am trying to import private key via this code I have error:\r\n```\r\nTypeError: Cannot read property 'length' of undefined\r\n    at Function.Base64Url.decode (node_modules\\webcrypto-core\\dist\\webcrypto-core.js:275:26)\r\n    at b64_decode (node_modules\\node-webcrypto-ossl\\buildjs\\crypto\\ec.js:38:33)\r\n    at node_modules\\node-webcrypto-ossl\\buildjs\\crypto\\ec.js:123:33\r\n    at new Promise (<anonymous>)\r\n    at Function.EcCrypto.importKey (node_modules\\node-webcrypto-ossl\\buildjs\\crypto\\ec.js:75:16)\r\n    at node_modules\\node-webcrypto-ossl\\buildjs\\subtle.js:363:29\r\n    at <anonymous>\r\n```\r\n\r\n```javascript\r\nimport { getCrypto, setEngine } from \"../src/common\";\r\nimport CryptoEngine from \"../src/CryptoEngine\";\r\n\r\nconst WebCrypto = require(\"node-webcrypto-ossl\");\r\nconst webcrypto = new WebCrypto();\r\n\r\nsetEngine(\"newEngine\", webcrypto, new CryptoEngine({ name: \"\", crypto: webcrypto, subtle: webcrypto.subtle }));\r\n\r\nasync function main()\r\n{\r\n const crypto = getCrypto();\r\n const importedPrivateKey = await crypto.importKey(\"jwk\", { crv: \"P-256\", kty: \"EC\", d: \"3BVP-DHyzDs1o0AFLS9PNBRUVLAFw8cMmY7w1VFgkGY\"}, { name: \"ECDSA\", namedCurve: \"P-256\" }, true, [\"sign\"]);\r\n}\r\n\r\nmain();\r\n```\r\nAt the same time native WebCrypto could successfully import this key.\r\n\r\nThe problem in your code is that you presume `x` and `y` values are always available inside `jwk`. All these values are part of ECPublicKey type. But in fact for ECPrivate key we have this ASN.1 schema:\r\n```\r\n ECPrivateKey ::= SEQUENCE {\r\n version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),\r\n privateKey     OCTET STRING,\r\n parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,\r\n publicKey  [1] BIT STRING OPTIONAL\r\n }\r\n```\r\nSo, as you can see `publicKey` is optional and could be absent inside ECPrivateKey declaration."},"comment":{"url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-ossl/issues/comments/378238622","html_url":"https://github.com/PeculiarVentures/node-webcrypto-ossl/issues/123#issuecomment-378238622","issue_url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-ossl/issues/123","id":378238622,"user":{"login":"microshine","id":7333669,"avatar_url":"https://avatars3.githubusercontent.com/u/7333669?v=4","gravatar_id":"","url":"https://api.github.com/users/microshine","html_url":"https://github.com/microshine","followers_url":"https://api.github.com/users/microshine/followers","following_url":"https://api.github.com/users/microshine/following{/other_user}","gists_url":"https://api.github.com/users/microshine/gists{/gist_id}","starred_url":"https://api.github.com/users/microshine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/microshine/subscriptions","organizations_url":"https://api.github.com/users/microshine/orgs","repos_url":"https://api.github.com/users/microshine/repos","events_url":"https://api.github.com/users/microshine/events{/privacy}","received_events_url":"https://api.github.com/users/microshine/received_events","type":"User","site_admin":false},"created_at":"2018-04-03T12:51:25Z","updated_at":"2018-04-03T12:51:25Z","author_association":"CONTRIBUTOR","body":"I use the same version of Chrome\r\nMy OS is MacOS High Sierra 10.13.3\r\n\r\n![image](https://user-images.githubusercontent.com/7333669/38250030-57504eb0-3756-11e8-92aa-78a1546846bc.png)\r\n\r\nHere is chromium source code. They use `x` and `y` for private key creation\r\nhttps://cs.chromium.org/chromium/src/components/webcrypto/algorithms/ec.cc?sq=package:chromium&l=500-512"}}
{"actor":{"display_login":"microshine"}}