Repository navigation
Typescript JWK Key return type issues #67
Description
Activity
The types can't possibly know the
ktyfrom a string or a buffer... They do know when you pass in a JWK formatted object.const key = jose.JWK.asKey({ kty: 'EC', x: 'foo', y: 'bar', d: 'foo', crv: 'P-256' }) key.crv
Please come forth with a proposal for an improvement, otherwise i'm not seeing one other than - if you know the key type contained by the string, cast the value to e.g.
JWK.ECKey, otherwise, don’t access these attributes.const key = jose.JWK.asKey('EC KEY') as jose.JWK.ECKey key.crv
- addedenhancementNew feature or requestNew feature or requestwaiting for feedbackThe OP is asked for feedback or a proposalThe OP is asked for feedback or a proposaland removedbugSomething isn't workingSomething isn't working
on Feb 12, 2020 - changed the title
[-]bug: Typescript JWK Key return type issues[/-][+]Typescript JWK Key return type issues[/+]on Feb 12, 2020 How about creating a mixed key type for the situation when they actual key type cannot be inferred:
interface MixedKey extends Key { e?: string; n?: string; d?: string; p?: string; q?: string; dp?: string; dq?: string; qi?: string; crv?: ECCurve | OKPCurve; x?: string; y?: string; k?: string; }And in asKey:
function asKey(key: KeyObject | KeyInput, parameters?: KeyParameters): MixedKey; function asKey(jwk: JWKOctKey): OctKey; function asKey(jwk: JWKRSAKey, options?: ImportOptions): RSAKey; function asKey(jwk: JWKECKey): ECKey; function asKey(jwk: JWKOKPKey): OKPKey;And in CompleteDecrypt
interface completeDecrypt { cleartext: Buffer; key: JWK.MixedKey; cek: JWK.OctKey; aad?: string; header?: object; unprotected?: object; protected?: object; }Well, i can do one of two things. Your UndefinedKeyType idea doesn't sit well with me.
Easiest is to add this to
JWK.Key[key: string]: any;
or add all of these to
JWK.Keyand then undefine them for the respective types.crv?: ECCurve | OKPCurve; d?: string; dp?: string; dq?: string; e?: string; k?: string; n?: string; p?: string; q?: string; qi?: string; x?: string; y?: string;
- added a commit that references this issue
on Feb 13, 2020 Nice solution in the commit! This can be closed. Thanks!
This branch will land with the next 13.x node release. Planned for the 18th
Reacted by Aranđel Šarenac- removedwaiting for feedbackThe OP is asked for feedback or a proposalThe OP is asked for feedback or a proposal
on Feb 15, 2020 - locked and limited conversation to collaborators
on May 19, 2020
Describe the bug
Currently all return values regarding Keys are typed under the Key interface.
This causes that no Key type specific parameters can be accessed (for example EC Key crv value) in the return values regarding keys.
*To Reproduce
Expected behaviour
Should return proper Key sub type, so parameters can be accessed
Environment:
joseversion: [e.g. v1.22.2]Additional context