@oari/jose 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +150 -0
  3. package/dist/types/index.d.ts +55 -0
  4. package/dist/types/jwe/compact/decrypt.d.ts +43 -0
  5. package/dist/types/jwe/compact/encrypt.d.ts +76 -0
  6. package/dist/types/jwe/flattened/decrypt.d.ts +53 -0
  7. package/dist/types/jwe/flattened/encrypt.d.ts +95 -0
  8. package/dist/types/jwe/general/decrypt.d.ts +64 -0
  9. package/dist/types/jwe/general/encrypt.d.ts +89 -0
  10. package/dist/types/jwk/embedded.d.ts +31 -0
  11. package/dist/types/jwk/thumbprint.d.ts +60 -0
  12. package/dist/types/jwks/local.d.ts +90 -0
  13. package/dist/types/jwks/remote.d.ts +306 -0
  14. package/dist/types/jws/compact/sign.d.ts +47 -0
  15. package/dist/types/jws/compact/verify.d.ts +45 -0
  16. package/dist/types/jws/flattened/sign.d.ts +53 -0
  17. package/dist/types/jws/flattened/verify.d.ts +50 -0
  18. package/dist/types/jws/general/sign.d.ts +67 -0
  19. package/dist/types/jws/general/verify.d.ts +61 -0
  20. package/dist/types/jwt/decrypt.d.ts +51 -0
  21. package/dist/types/jwt/encrypt.d.ts +105 -0
  22. package/dist/types/jwt/sign.d.ts +140 -0
  23. package/dist/types/jwt/unsecured.d.ts +70 -0
  24. package/dist/types/jwt/verify.d.ts +124 -0
  25. package/dist/types/key/export.d.ts +59 -0
  26. package/dist/types/key/generate_key_pair.d.ts +64 -0
  27. package/dist/types/key/generate_secret.d.ts +42 -0
  28. package/dist/types/key/import.d.ts +146 -0
  29. package/dist/types/types.d.ts +869 -0
  30. package/dist/types/util/base64url.d.ts +9 -0
  31. package/dist/types/util/decode_jwt.d.ts +25 -0
  32. package/dist/types/util/decode_protected_header.d.ts +24 -0
  33. package/dist/types/util/errors.d.ts +488 -0
  34. package/dist/webapi/index.js +32 -0
  35. package/dist/webapi/jwe/compact/decrypt.js +27 -0
  36. package/dist/webapi/jwe/compact/encrypt.js +27 -0
  37. package/dist/webapi/jwe/flattened/decrypt.js +159 -0
  38. package/dist/webapi/jwe/flattened/encrypt.js +167 -0
  39. package/dist/webapi/jwe/general/decrypt.js +31 -0
  40. package/dist/webapi/jwe/general/encrypt.js +182 -0
  41. package/dist/webapi/jwk/embedded.js +17 -0
  42. package/dist/webapi/jwk/thumbprint.js +68 -0
  43. package/dist/webapi/jwks/local.js +119 -0
  44. package/dist/webapi/jwks/remote.js +179 -0
  45. package/dist/webapi/jws/compact/sign.js +18 -0
  46. package/dist/webapi/jws/compact/verify.js +21 -0
  47. package/dist/webapi/jws/flattened/sign.js +87 -0
  48. package/dist/webapi/jws/flattened/verify.js +110 -0
  49. package/dist/webapi/jws/general/sign.js +70 -0
  50. package/dist/webapi/jws/general/verify.js +24 -0
  51. package/dist/webapi/jwt/decrypt.js +23 -0
  52. package/dist/webapi/jwt/encrypt.js +101 -0
  53. package/dist/webapi/jwt/sign.js +52 -0
  54. package/dist/webapi/jwt/unsecured.js +63 -0
  55. package/dist/webapi/jwt/verify.js +15 -0
  56. package/dist/webapi/key/export.js +11 -0
  57. package/dist/webapi/key/generate_key_pair.js +97 -0
  58. package/dist/webapi/key/generate_secret.js +40 -0
  59. package/dist/webapi/key/import.js +57 -0
  60. package/dist/webapi/lib/aesgcmkw.js +15 -0
  61. package/dist/webapi/lib/aeskw.js +25 -0
  62. package/dist/webapi/lib/asn1.js +243 -0
  63. package/dist/webapi/lib/base64.js +22 -0
  64. package/dist/webapi/lib/buffer_utils.js +43 -0
  65. package/dist/webapi/lib/check_key_type.js +127 -0
  66. package/dist/webapi/lib/content_encryption.js +217 -0
  67. package/dist/webapi/lib/crypto_key.js +136 -0
  68. package/dist/webapi/lib/deflate.js +44 -0
  69. package/dist/webapi/lib/ecdhes.js +52 -0
  70. package/dist/webapi/lib/helpers.js +19 -0
  71. package/dist/webapi/lib/invalid_key_input.js +27 -0
  72. package/dist/webapi/lib/is_key_like.js +17 -0
  73. package/dist/webapi/lib/jwk_to_key.js +107 -0
  74. package/dist/webapi/lib/jwt_claims_set.js +238 -0
  75. package/dist/webapi/lib/key_management.js +186 -0
  76. package/dist/webapi/lib/key_to_jwk.js +31 -0
  77. package/dist/webapi/lib/normalize_key.js +166 -0
  78. package/dist/webapi/lib/pbes2kw.js +42 -0
  79. package/dist/webapi/lib/rsaes.js +24 -0
  80. package/dist/webapi/lib/signing.js +74 -0
  81. package/dist/webapi/lib/type_checks.js +41 -0
  82. package/dist/webapi/lib/validate_algorithms.js +10 -0
  83. package/dist/webapi/lib/validate_crit.js +33 -0
  84. package/dist/webapi/util/base64url.js +30 -0
  85. package/dist/webapi/util/decode_jwt.js +32 -0
  86. package/dist/webapi/util/decode_protected_header.js +34 -0
  87. package/dist/webapi/util/errors.js +99 -0
  88. package/package.json +195 -0
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Asymmetric key generation
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../types.d.ts';
7
+ /** Asymmetric key pair generation function result. */
8
+ export interface GenerateKeyPairResult {
9
+ /** The generated Private Key. */
10
+ privateKey: types.CryptoKey;
11
+ /** Public Key corresponding to the generated Private Key. */
12
+ publicKey: types.CryptoKey;
13
+ }
14
+ /** Asymmetric key pair generation function options. */
15
+ export interface GenerateKeyPairOptions {
16
+ /**
17
+ * The EC "crv" (Curve) or OKP "crv" (Subtype of Key Pair) value to generate. The curve must be
18
+ * both supported on the runtime as well as applicable for the given JWA algorithm identifier.
19
+ */
20
+ crv?: string;
21
+ /**
22
+ * A hint for RSA algorithms to generate an RSA key of a given `modulusLength` (Key size in bits).
23
+ * JOSE requires 2048 bits or larger. Default is 2048.
24
+ */
25
+ modulusLength?: number;
26
+ /**
27
+ * The value to use as {@link !SubtleCrypto.generateKey} `extractable` argument. Default is false.
28
+ *
29
+ * @example
30
+ *
31
+ * ```js
32
+ * const { publicKey, privateKey } = await jose.generateKeyPair('PS256', {
33
+ * extractable: true,
34
+ * })
35
+ * console.log(await jose.exportJWK(privateKey))
36
+ * console.log(await jose.exportPKCS8(privateKey))
37
+ * ```
38
+ */
39
+ extractable?: boolean;
40
+ }
41
+ /**
42
+ * Generates a private and a public key for a given JWA algorithm identifier. This can only generate
43
+ * asymmetric key pairs. For symmetric secrets use the `generateSecret` function.
44
+ *
45
+ * > [!NOTE]\
46
+ * > The `privateKey` is generated with `extractable` set to `false` by default. See
47
+ * > {@link GenerateKeyPairOptions.extractable} to generate an extractable `privateKey`.
48
+ *
49
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
50
+ * as from its subpath export `'jose/generate/keypair'`.
51
+ *
52
+ * @example
53
+ *
54
+ * ```js
55
+ * const { publicKey, privateKey } = await jose.generateKeyPair('PS256')
56
+ * console.log(publicKey)
57
+ * console.log(privateKey)
58
+ * ```
59
+ *
60
+ * @param alg JWA Algorithm Identifier to be used with the generated key pair. See
61
+ * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
62
+ * @param options Additional options passed down to the key pair generation.
63
+ */
64
+ export declare function generateKeyPair(alg: string, options?: GenerateKeyPairOptions): Promise<GenerateKeyPairResult>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Symmetric key generation
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../types.d.ts';
7
+ /** Secret generation function options. */
8
+ export interface GenerateSecretOptions {
9
+ /**
10
+ * The value to use as {@link !SubtleCrypto.generateKey} `extractable` argument. Default is false.
11
+ *
12
+ * > [!NOTE]\
13
+ * > Because A128CBC-HS256, A192CBC-HS384, and A256CBC-HS512 secrets cannot be represented as
14
+ * > {@link !CryptoKey} this option has no effect for them.
15
+ */
16
+ extractable?: boolean;
17
+ }
18
+ /**
19
+ * Generates a symmetric secret key for a given JWA algorithm identifier.
20
+ *
21
+ * > [!NOTE]\
22
+ * > The secret key is generated with `extractable` set to `false` by default.
23
+ *
24
+ * > [!NOTE]\
25
+ * > Because A128CBC-HS256, A192CBC-HS384, and A256CBC-HS512 secrets cannot be represented as
26
+ * > {@link !CryptoKey} this method yields a {@link !Uint8Array} for them instead.
27
+ *
28
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
29
+ * as from its subpath export `'jose/generate/secret'`.
30
+ *
31
+ * @example
32
+ *
33
+ * ```js
34
+ * const secret = await jose.generateSecret('HS256')
35
+ * console.log(secret)
36
+ * ```
37
+ *
38
+ * @param alg JWA Algorithm Identifier to be used with the generated secret. See
39
+ * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
40
+ * @param options Additional options passed down to the secret generation.
41
+ */
42
+ export declare function generateSecret(alg: string, options?: GenerateSecretOptions): Promise<types.CryptoKey | Uint8Array>;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Cryptographic key import functions
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../types.d.ts';
7
+ /** Key Import Function options. */
8
+ export interface KeyImportOptions {
9
+ /**
10
+ * The value to use as {@link !SubtleCrypto.importKey} `extractable` argument. Default is false for
11
+ * private keys, true otherwise.
12
+ */
13
+ extractable?: boolean;
14
+ }
15
+ /**
16
+ * Imports a PEM-encoded SPKI string as a {@link !CryptoKey}.
17
+ *
18
+ * > [!NOTE]\
19
+ * > The OID id-RSASSA-PSS (1.2.840.113549.1.1.10) is not supported in
20
+ * > {@link https://w3c.github.io/webcrypto/ Web Cryptography API}, use the OID rsaEncryption
21
+ * > (1.2.840.113549.1.1.1) instead for all RSA algorithms.
22
+ *
23
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
24
+ * as from its subpath export `'jose/key/import'`.
25
+ *
26
+ * @example
27
+ *
28
+ * ```js
29
+ * const algorithm = 'ES256'
30
+ * const spki = `-----BEGIN PUBLIC KEY-----
31
+ * MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFlHHWfLk0gLBbsLTcuCrbCqoHqmM
32
+ * YJepMC+Q+Dd6RBmBiA41evUsNMwLeN+PNFqib+xwi9JkJ8qhZkq8Y/IzGg==
33
+ * -----END PUBLIC KEY-----`
34
+ * const ecPublicKey = await jose.importSPKI(spki, algorithm)
35
+ * ```
36
+ *
37
+ * @param spki PEM-encoded SPKI string
38
+ * @param alg JSON Web Algorithm identifier to be used with the imported key. See
39
+ * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
40
+ */
41
+ export declare function importSPKI(spki: string, alg: string, options?: KeyImportOptions): Promise<types.CryptoKey>;
42
+ /**
43
+ * Imports the SPKI from an X.509 string certificate as a {@link !CryptoKey}.
44
+ *
45
+ * > [!NOTE]\
46
+ * > The OID id-RSASSA-PSS (1.2.840.113549.1.1.10) is not supported in
47
+ * > {@link https://w3c.github.io/webcrypto/ Web Cryptography API}, use the OID rsaEncryption
48
+ * > (1.2.840.113549.1.1.1) instead for all RSA algorithms.
49
+ *
50
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
51
+ * as from its subpath export `'jose/key/import'`.
52
+ *
53
+ * @example
54
+ *
55
+ * ```js
56
+ * const algorithm = 'ES256'
57
+ * const x509 = `-----BEGIN CERTIFICATE-----
58
+ * MIIBXjCCAQSgAwIBAgIGAXvykuMKMAoGCCqGSM49BAMCMDYxNDAyBgNVBAMMK3Np
59
+ * QXBNOXpBdk1VaXhXVWVGaGtjZXg1NjJRRzFyQUhXaV96UlFQTVpQaG8wHhcNMjEw
60
+ * OTE3MDcwNTE3WhcNMjIwNzE0MDcwNTE3WjA2MTQwMgYDVQQDDCtzaUFwTTl6QXZN
61
+ * VWl4V1VlRmhrY2V4NTYyUUcxckFIV2lfelJRUE1aUGhvMFkwEwYHKoZIzj0CAQYI
62
+ * KoZIzj0DAQcDQgAE8PbPvCv5D5xBFHEZlBp/q5OEUymq7RIgWIi7tkl9aGSpYE35
63
+ * UH+kBKDnphJO3odpPZ5gvgKs2nwRWcrDnUjYLDAKBggqhkjOPQQDAgNIADBFAiEA
64
+ * 1yyMTRe66MhEXID9+uVub7woMkNYd0LhSHwKSPMUUTkCIFQGsfm1ecXOpeGOufAh
65
+ * v+A1QWZMuTWqYt+uh/YSRNDn
66
+ * -----END CERTIFICATE-----`
67
+ * const ecPublicKey = await jose.importX509(x509, algorithm)
68
+ * ```
69
+ *
70
+ * @param x509 X.509 certificate string
71
+ * @param alg JSON Web Algorithm identifier to be used with the imported key. See
72
+ * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
73
+ */
74
+ export declare function importX509(x509: string, alg: string, options?: KeyImportOptions): Promise<types.CryptoKey>;
75
+ /**
76
+ * Imports a PEM-encoded PKCS#8 string as a {@link !CryptoKey}.
77
+ *
78
+ * > [!NOTE]\
79
+ * > The OID id-RSASSA-PSS (1.2.840.113549.1.1.10) is not supported in
80
+ * > {@link https://w3c.github.io/webcrypto/ Web Cryptography API}, use the OID rsaEncryption
81
+ * > (1.2.840.113549.1.1.1) instead for all RSA algorithms.
82
+ *
83
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
84
+ * as from its subpath export `'jose/key/import'`.
85
+ *
86
+ * @example
87
+ *
88
+ * ```js
89
+ * const algorithm = 'ES256'
90
+ * const pkcs8 = `-----BEGIN PRIVATE KEY-----
91
+ * MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgiyvo0X+VQ0yIrOaN
92
+ * nlrnUclopnvuuMfoc8HHly3505OhRANCAAQWUcdZ8uTSAsFuwtNy4KtsKqgeqYxg
93
+ * l6kwL5D4N3pEGYGIDjV69Sw0zAt43480WqJv7HCL0mQnyqFmSrxj8jMa
94
+ * -----END PRIVATE KEY-----`
95
+ * const ecPrivateKey = await jose.importPKCS8(pkcs8, algorithm)
96
+ * ```
97
+ *
98
+ * @param pkcs8 PEM-encoded PKCS#8 string
99
+ * @param alg JSON Web Algorithm identifier to be used with the imported key. See
100
+ * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
101
+ */
102
+ export declare function importPKCS8(pkcs8: string, alg: string, options?: KeyImportOptions): Promise<types.CryptoKey>;
103
+ /**
104
+ * Imports a JWK to a {@link !CryptoKey}. Either the JWK "alg" (Algorithm) Parameter, or the optional
105
+ * "alg" argument, must be present for asymmetric JSON Web Key imports.
106
+ *
107
+ * > [!NOTE]\
108
+ * > The JSON Web Key parameters "use", "key_ops", and "ext" are also used in the {@link !CryptoKey}
109
+ * > import process.
110
+ *
111
+ * > [!NOTE]\
112
+ * > Symmetric JSON Web Keys (i.e. `kty: "oct"`) yield back an {@link !Uint8Array} instead of a
113
+ * > {@link !CryptoKey}.
114
+ *
115
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
116
+ * as from its subpath export `'jose/key/import'`.
117
+ *
118
+ * @example
119
+ *
120
+ * ```js
121
+ * const ecPublicKey = await jose.importJWK(
122
+ * {
123
+ * crv: 'P-256',
124
+ * kty: 'EC',
125
+ * x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw',
126
+ * y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo',
127
+ * },
128
+ * 'ES256',
129
+ * )
130
+ *
131
+ * const rsaPublicKey = await jose.importJWK(
132
+ * {
133
+ * kty: 'RSA',
134
+ * e: 'AQAB',
135
+ * n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ',
136
+ * },
137
+ * 'PS256',
138
+ * )
139
+ * ```
140
+ *
141
+ * @param jwk JSON Web Key.
142
+ * @param alg JSON Web Algorithm identifier to be used with the imported key. Default is the "alg"
143
+ * property on the JWK. See
144
+ * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
145
+ */
146
+ export declare function importJWK(jwk: types.JWK, alg?: string, options?: KeyImportOptions): Promise<types.CryptoKey | Uint8Array>;