@vanaheimr/cose 0.9.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.
- package/CHANGELOG.md +81 -0
- package/LICENSE.md +201 -0
- package/NOTICE +31 -0
- package/README.md +537 -0
- package/dist/aes.d.ts +45 -0
- package/dist/aes.d.ts.map +1 -0
- package/dist/algorithm.d.ts +137 -0
- package/dist/algorithm.d.ts.map +1 -0
- package/dist/asn1.d.ts +114 -0
- package/dist/asn1.d.ts.map +1 -0
- package/dist/cbor.d.ts +65 -0
- package/dist/cbor.d.ts.map +1 -0
- package/dist/curve.d.ts +65 -0
- package/dist/curve.d.ts.map +1 -0
- package/dist/ecdsa.d.ts +56 -0
- package/dist/ecdsa.d.ts.map +1 -0
- package/dist/eddsa.d.ts +14 -0
- package/dist/eddsa.d.ts.map +1 -0
- package/dist/encrypt.d.ts +140 -0
- package/dist/encrypt.d.ts.map +1 -0
- package/dist/errors.d.ts +64 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/headers.d.ts +77 -0
- package/dist/headers.d.ts.map +1 -0
- package/dist/hmac.d.ts +32 -0
- package/dist/hmac.d.ts.map +1 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4159 -0
- package/dist/index.js.map +1 -0
- package/dist/key.d.ts +201 -0
- package/dist/key.d.ts.map +1 -0
- package/dist/labels.d.ts +51 -0
- package/dist/labels.d.ts.map +1 -0
- package/dist/mac.d.ts +93 -0
- package/dist/mac.d.ts.map +1 -0
- package/dist/mac0.d.ts +132 -0
- package/dist/mac0.d.ts.map +1 -0
- package/dist/mldsa.d.ts +29 -0
- package/dist/mldsa.d.ts.map +1 -0
- package/dist/payload.d.ts +25 -0
- package/dist/payload.d.ts.map +1 -0
- package/dist/recipient.d.ts +65 -0
- package/dist/recipient.d.ts.map +1 -0
- package/dist/resolve.d.ts +29 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/sign.d.ts +82 -0
- package/dist/sign.d.ts.map +1 -0
- package/dist/sign1.d.ts +273 -0
- package/dist/sign1.d.ts.map +1 -0
- package/dist/signature.d.ts +43 -0
- package/dist/signature.d.ts.map +1 -0
- package/dist/x509.d.ts +144 -0
- package/dist/x509.d.ts.map +1 -0
- package/dist/x5chain.d.ts +98 -0
- package/dist/x5chain.d.ts.map +1 -0
- package/package.json +97 -0
package/dist/key.d.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import type { CoseAlgorithm } from './algorithm.ts';
|
|
2
|
+
import type { CborEntry, CborValue } from './cbor.ts';
|
|
3
|
+
import type { CoseCurve } from './curve.ts';
|
|
4
|
+
import type { DigestAlgorithm } from './ecdsa.ts';
|
|
5
|
+
/** Key type 7, a key pair belonging to an algorithm rather than a curve. */
|
|
6
|
+
export declare const KEY_TYPE_AKP = 7;
|
|
7
|
+
/** Key type 4, a shared secret [RFC 9053, Section 7.3]. */
|
|
8
|
+
export declare const KEY_TYPE_SYMMETRIC = 4;
|
|
9
|
+
/**
|
|
10
|
+
* The labels of a COSE *key*, which are not the labels of a header bucket:
|
|
11
|
+
* 3 is the algorithm here and the content type there, 4 is the key operations
|
|
12
|
+
* here and the key identifier there.
|
|
13
|
+
*/
|
|
14
|
+
export declare const KeyLabel: {
|
|
15
|
+
readonly keyType: 1;
|
|
16
|
+
readonly keyIdentifier: 2;
|
|
17
|
+
readonly algorithm: 3;
|
|
18
|
+
readonly keyOperations: 4;
|
|
19
|
+
readonly curve: -1;
|
|
20
|
+
readonly x: -2;
|
|
21
|
+
readonly y: -3;
|
|
22
|
+
readonly d: -4;
|
|
23
|
+
readonly pub: -1;
|
|
24
|
+
readonly priv: -2;
|
|
25
|
+
readonly k: -1;
|
|
26
|
+
};
|
|
27
|
+
export interface CoseKeyParts {
|
|
28
|
+
readonly keyIdentifier?: Uint8Array | null;
|
|
29
|
+
readonly algorithm?: CoseAlgorithm | null;
|
|
30
|
+
}
|
|
31
|
+
export declare class CoseKey {
|
|
32
|
+
readonly keyType: number;
|
|
33
|
+
readonly keyIdentifier: Uint8Array | null;
|
|
34
|
+
readonly algorithm: CoseAlgorithm | null;
|
|
35
|
+
readonly keyOperations: CborValue | null;
|
|
36
|
+
/** The curve identifier as it travels, also when it is not registered. */
|
|
37
|
+
readonly curveId: number | null;
|
|
38
|
+
/** EC2 and OKP: the coordinates and the private scalar. */
|
|
39
|
+
readonly x: Uint8Array | null;
|
|
40
|
+
readonly y: Uint8Array | null;
|
|
41
|
+
readonly d: Uint8Array | null;
|
|
42
|
+
/** AKP: the public key, and the private key — which is always the seed. */
|
|
43
|
+
readonly pub: Uint8Array | null;
|
|
44
|
+
readonly priv: Uint8Array | null;
|
|
45
|
+
/** Symmetric: the shared secret. There is no public half of one. */
|
|
46
|
+
readonly k: Uint8Array | null;
|
|
47
|
+
/** Header parameters this implementation does not know, kept for the round trip. */
|
|
48
|
+
readonly additional: readonly CborEntry[];
|
|
49
|
+
private constructor();
|
|
50
|
+
private get fields();
|
|
51
|
+
private copy;
|
|
52
|
+
/** The curve of this key, or null when it names none or an unregistered one. */
|
|
53
|
+
get curve(): CoseCurve | null;
|
|
54
|
+
/**
|
|
55
|
+
* Whether this key carries secret key material.
|
|
56
|
+
*
|
|
57
|
+
* A symmetric key is *always* secret — it has nothing else — which is why
|
|
58
|
+
* `k` counts here beside the two private halves.
|
|
59
|
+
*/
|
|
60
|
+
get isPrivate(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* An elliptic curve key pair from its private scalar.
|
|
63
|
+
*
|
|
64
|
+
* The public point is recomputed rather than asked for, which is what the
|
|
65
|
+
* examples of RFC 9052 do as well: a private COSE key always carries the
|
|
66
|
+
* full pair, and the two halves cannot disagree.
|
|
67
|
+
*/
|
|
68
|
+
static fromPrivateScalar(curve: CoseCurve, d: Uint8Array, parts?: CoseKeyParts): CoseKey;
|
|
69
|
+
/**
|
|
70
|
+
* An octet key pair from its private key.
|
|
71
|
+
*
|
|
72
|
+
* There is no `y`: an EdDSA public key is the whole of `x`.
|
|
73
|
+
*/
|
|
74
|
+
static fromOkpPrivateKey(curve: CoseCurve, d: Uint8Array, parts?: CoseKeyParts): CoseKey;
|
|
75
|
+
/**
|
|
76
|
+
* An algorithm key pair from its seed.
|
|
77
|
+
*
|
|
78
|
+
* The private key of an ML-DSA COSE key is the 32-byte seed and nothing
|
|
79
|
+
* else [RFC 9964] — not the expanded secret key, which is up to 4896 bytes
|
|
80
|
+
* and derivable from it. The algorithm is not optional here: an ML-DSA
|
|
81
|
+
* public key does not say which parameter set produced it, so a key that
|
|
82
|
+
* did not name one could not be used, and could not even be identified,
|
|
83
|
+
* since its thumbprint covers the algorithm.
|
|
84
|
+
*/
|
|
85
|
+
static fromAkpSeed(algorithm: CoseAlgorithm, seed: Uint8Array, parts?: CoseKeyParts): CoseKey;
|
|
86
|
+
/**
|
|
87
|
+
* A public algorithm key pair, from the public key alone.
|
|
88
|
+
*
|
|
89
|
+
* This is the form a certificate hands over: a `SubjectPublicKeyInfo`
|
|
90
|
+
* carries the public key and names the parameter set in its algorithm
|
|
91
|
+
* identifier, and there is no seed to be had. The algorithm is required
|
|
92
|
+
* for the same reason as in {@link fromAkpSeed} — the bytes do not say
|
|
93
|
+
* which parameter set produced them, and the thumbprint covers `alg`.
|
|
94
|
+
*/
|
|
95
|
+
static fromAkpPublicKey(algorithm: CoseAlgorithm, pub: Uint8Array, parts?: CoseKeyParts): CoseKey;
|
|
96
|
+
/**
|
|
97
|
+
* A symmetric key, which is a shared secret and nothing else.
|
|
98
|
+
*
|
|
99
|
+
* No length is enforced. RFC 9053 says an HMAC key SHOULD be as wide as
|
|
100
|
+
* the hash output, which is advice about key management rather than a rule
|
|
101
|
+
* about the primitive — RFC 2104 accepts any width and the published test
|
|
102
|
+
* vectors of RFC 4231 include a four-byte key. What a caller must not do
|
|
103
|
+
* is derive one from a password, and no length check would catch that.
|
|
104
|
+
*/
|
|
105
|
+
static fromSymmetricKey(k: Uint8Array, parts?: CoseKeyParts): CoseKey;
|
|
106
|
+
/** A public octet key pair, which is the whole of `x` and nothing else. */
|
|
107
|
+
static fromOkpPublicKey(curve: CoseCurve, x: Uint8Array, parts?: CoseKeyParts): CoseKey;
|
|
108
|
+
/** A public elliptic curve key from its coordinates. */
|
|
109
|
+
static fromCoordinates(curve: CoseCurve, x: Uint8Array, y: Uint8Array, parts?: CoseKeyParts): CoseKey;
|
|
110
|
+
/**
|
|
111
|
+
* Parse a COSE key.
|
|
112
|
+
*
|
|
113
|
+
* Widths are deliberately not checked here — only that the CBOR types are
|
|
114
|
+
* what they claim to be. A key with a shortened coordinate is a real key
|
|
115
|
+
* that a real implementation produced, and reading it is how one finds out
|
|
116
|
+
* that it is wrong; the refusal belongs at the point where the key would
|
|
117
|
+
* be used, where the error can say what was expected.
|
|
118
|
+
*
|
|
119
|
+
* A duplicate label takes its last value, which is what a lenient CBOR map
|
|
120
|
+
* does everywhere else in COSE.
|
|
121
|
+
*/
|
|
122
|
+
static parse(input: CborValue | Uint8Array): CoseKey;
|
|
123
|
+
private static readKeyType;
|
|
124
|
+
private static parseCurveKey;
|
|
125
|
+
private static parseSymmetric;
|
|
126
|
+
private static parseAkp;
|
|
127
|
+
/**
|
|
128
|
+
* The y coordinate, which may travel as a byte string or as the parity bit
|
|
129
|
+
* of a compressed point.
|
|
130
|
+
*/
|
|
131
|
+
private static resolveY;
|
|
132
|
+
/**
|
|
133
|
+
* A CBOR map holding this key.
|
|
134
|
+
*
|
|
135
|
+
* The labels are written in ascending encoded order — 1, 2, 3, 4, −1, −2,
|
|
136
|
+
* −3, −4 — which happens to be exactly the deterministic order of
|
|
137
|
+
* RFC 8949 Section 4.2.1, so a canonical re-encoding moves nothing.
|
|
138
|
+
*
|
|
139
|
+
* A key whose y arrived as a sign bit does *not* round-trip byte for byte:
|
|
140
|
+
* y is always written as the byte string form, which every implementation
|
|
141
|
+
* understands.
|
|
142
|
+
*/
|
|
143
|
+
toCbor(): CborValue;
|
|
144
|
+
/** The CBOR encoding of this key. */
|
|
145
|
+
toBytes(): Uint8Array;
|
|
146
|
+
/**
|
|
147
|
+
* This key without its private half.
|
|
148
|
+
*
|
|
149
|
+
* A symmetric key has no such form, and saying so is the point rather than
|
|
150
|
+
* a limitation: RFC 9053 states outright that the structure "does not have
|
|
151
|
+
* a form that contains only public members". Returning the key unchanged
|
|
152
|
+
* here — which is what stripping `d` and `priv` from it would do — would
|
|
153
|
+
* hand a caller the shared secret under a name promising the opposite.
|
|
154
|
+
*/
|
|
155
|
+
publicKey(): CoseKey;
|
|
156
|
+
/** A copy of this key carrying the given algorithm. */
|
|
157
|
+
withAlgorithm(algorithm: CoseAlgorithm): CoseKey;
|
|
158
|
+
private requireCurve;
|
|
159
|
+
/**
|
|
160
|
+
* The public key, in whatever form its key type gives it: `04 ‖ x ‖ y` for
|
|
161
|
+
* EC2, the whole of `x` for OKP, `pub` for AKP.
|
|
162
|
+
*/
|
|
163
|
+
publicKeyBytes(): Uint8Array;
|
|
164
|
+
/**
|
|
165
|
+
* The secret this key holds: the scalar for EC2 and OKP, the seed for AKP,
|
|
166
|
+
* the shared key itself for a symmetric one.
|
|
167
|
+
*/
|
|
168
|
+
privateKeyBytes(): Uint8Array;
|
|
169
|
+
/**
|
|
170
|
+
* The input of the COSE Key Thumbprint [RFC 9679, Section 3]: the required
|
|
171
|
+
* parameters of this key, and nothing else, in deterministic encoding.
|
|
172
|
+
*
|
|
173
|
+
* Leaving out the optional parameters is what makes the thumbprint an
|
|
174
|
+
* identity rather than a checksum — the public and the private half of one
|
|
175
|
+
* key pair produce the same value, and adding a key identifier does not
|
|
176
|
+
* change it.
|
|
177
|
+
*
|
|
178
|
+
* An AKP key is the exception that proves the rule: its algorithm *is*
|
|
179
|
+
* required [RFC 9964], because an ML-DSA public key does not say which
|
|
180
|
+
* parameter set produced it, and two keys of different strengths must not
|
|
181
|
+
* be able to share an identity.
|
|
182
|
+
*/
|
|
183
|
+
thumbprintInput(): Uint8Array;
|
|
184
|
+
/** The COSE Key Thumbprint [RFC 9679], untruncated. */
|
|
185
|
+
thumbprint(hash?: DigestAlgorithm): Uint8Array;
|
|
186
|
+
/**
|
|
187
|
+
* The leading bytes of the thumbprint, for use as a key identifier.
|
|
188
|
+
*
|
|
189
|
+
* Two properties make this worth preferring over a self-chosen prefix.
|
|
190
|
+
* Everyone holding the public key can recompute it, so no registry is
|
|
191
|
+
* needed beyond an agreement on its length. And because the thumbprint
|
|
192
|
+
* covers the curve — or, for an algorithm key pair, the algorithm — a
|
|
193
|
+
* signer who changes strength necessarily has a different key and
|
|
194
|
+
* therefore a different identifier: a downgrade under an unchanged
|
|
195
|
+
* identity is not expressible.
|
|
196
|
+
*/
|
|
197
|
+
thumbprintKeyIdentifier(length?: number, hash?: DigestAlgorithm): Uint8Array;
|
|
198
|
+
/** A copy of this key whose key identifier is its own thumbprint. */
|
|
199
|
+
withThumbprintKeyIdentifier(length?: number, hash?: DigestAlgorithm): CoseKey;
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../src/key.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAsB,gBAAgB,CAAC;AAGpE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAe,WAAW,CAAC;AAG/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAA0B,YAAY,CAAC;AAGhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAoB,YAAY,CAAC;AAQhE,4EAA4E;AAC5E,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B,2DAA2D;AAC3D,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAGpC;;;;GAIG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;CAoBX,CAAC;AA+BX,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,aAAa,CAAC,EAAG,UAAU,GAAG,IAAI,CAAC;IAC5C,QA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K/D;;;;;;;;;;OAUG;IACI,uBAAuB,CAAC,MAAM,SAAgB,EACtB,IAAI,GAAI,eAA6B,GAAG,UAAU;IAYjF,qEAAqE;IAC9D,2BAA2B,CAAC,MAAM,SAAa,EACnB,IAAI,GAAI,eAA0B,GAAG,OAAO;CAIlF"}
|
package/dist/labels.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { CborValue } from './cbor.ts';
|
|
2
|
+
/** The header parameter labels this implementation knows by name. */
|
|
3
|
+
export declare const HeaderLabel: {
|
|
4
|
+
/** The cryptographic algorithm [RFC 9052]. */
|
|
5
|
+
readonly algorithm: 1;
|
|
6
|
+
/** The labels a recipient is required to understand [RFC 9052]. */
|
|
7
|
+
readonly critical: 2;
|
|
8
|
+
/** The content type of the payload [RFC 9052]. */
|
|
9
|
+
readonly contentType: 3;
|
|
10
|
+
/** The key identifier [RFC 9052]. */
|
|
11
|
+
readonly keyIdentifier: 4;
|
|
12
|
+
/** The initialization vector [RFC 9052]. */
|
|
13
|
+
readonly iv: 5;
|
|
14
|
+
/** The partial initialization vector [RFC 9052]. */
|
|
15
|
+
readonly partialIv: 6;
|
|
16
|
+
/** The countersignature of RFC 8152, superseded by label 11 [RFC 9338]. */
|
|
17
|
+
readonly counterSignature: 7;
|
|
18
|
+
/** The countersignature that also covers the signature it signs [RFC 9338]. */
|
|
19
|
+
readonly counterSignatureV2: 11;
|
|
20
|
+
/** The abbreviated countersignature, not implemented here [RFC 9338]. */
|
|
21
|
+
readonly counterSignature0V2: 12;
|
|
22
|
+
/** An unordered bag of X.509 certificates [RFC 9360]. */
|
|
23
|
+
readonly x5Bag: 32;
|
|
24
|
+
/** An ordered X.509 certificate chain [RFC 9360]. */
|
|
25
|
+
readonly x5Chain: 33;
|
|
26
|
+
/** The hash of an X.509 certificate [RFC 9360]. */
|
|
27
|
+
readonly x5T: 34;
|
|
28
|
+
/** A URI naming an X.509 certificate [RFC 9360]. */
|
|
29
|
+
readonly x5U: 35;
|
|
30
|
+
};
|
|
31
|
+
/** A header parameter label as it travels: an integer, or a text string. */
|
|
32
|
+
export declare const label: (value: number) => CborValue;
|
|
33
|
+
/**
|
|
34
|
+
* The name of a header parameter label, for error messages.
|
|
35
|
+
*/
|
|
36
|
+
export declare function headerLabelName(value: CborValue): string;
|
|
37
|
+
/**
|
|
38
|
+
* Whether this implementation understands and processes the given header
|
|
39
|
+
* parameter, which is what the `crit` header parameter asks about
|
|
40
|
+
* [RFC 9052, Section 3.1].
|
|
41
|
+
*
|
|
42
|
+
* Four labels, and deliberately not the X.509 ones. Whether a certificate
|
|
43
|
+
* chain has been *understood* is a property of the verification being
|
|
44
|
+
* performed rather than of the library: whoever verifies with a bare public
|
|
45
|
+
* key has not looked at any certificate and must not claim otherwise. Callers
|
|
46
|
+
* that do process one say so per call, through `alsoUnderstood`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isUnderstood(value: CborValue): boolean;
|
|
49
|
+
/** Whether two header parameter labels are the same label. */
|
|
50
|
+
export declare function sameLabel(left: CborValue, right: CborValue): boolean;
|
|
51
|
+
//# sourceMappingURL=labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../src/labels.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,qEAAqE;AACrE,eAAO,MAAM,WAAW;IAEpB,8CAA8C;;IAG9C,mEAAmE;;IAGnE,kDAAkD;;IAGlD,qCAAqC;;IAGrC,4CAA4C;;IAG5C,oDAAoD;;IAGpD,2EAA2E;;IAG3E,+EAA+E;;IAG/E,yEAAyE;;IAGzE,yDAAyD;;IAGzD,qDAAqD;;IAGrD,mDAAmD;;IAGnD,oDAAoD;;CAG9C,CAAC;AAGX,4EAA4E;AAC5E,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,KAAG,SACnB,CAAC;AAGpB;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CA2BxD;AAGD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAMtD;AAGD,8DAA8D;AAC9D,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAUpE"}
|
package/dist/mac.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { CoseAlgorithm } from './algorithm.ts';
|
|
2
|
+
import type { CborValue } from './cbor.ts';
|
|
3
|
+
import type { Verification } from './errors.ts';
|
|
4
|
+
import { CoseHeaders } from './headers.ts';
|
|
5
|
+
import type { CoseKey } from './key.ts';
|
|
6
|
+
import { CoseRecipient } from './recipient.ts';
|
|
7
|
+
/** The CBOR tag of a COSE_Mac message. */
|
|
8
|
+
export declare const COSE_MAC_TAG = 97;
|
|
9
|
+
/** The context string of a COSE_Mac authentication tag [RFC 9052, Section 6.3]. */
|
|
10
|
+
export declare const MAC_CONTEXT = "MAC";
|
|
11
|
+
/** What a party authenticating may choose. */
|
|
12
|
+
export interface MacOptions {
|
|
13
|
+
/** Data authenticated along with the payload without travelling in the message. */
|
|
14
|
+
readonly externalAad?: Uint8Array | null;
|
|
15
|
+
/** Whether to omit the payload from the message. */
|
|
16
|
+
readonly detachPayload?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to rewrite a CBOR payload in the deterministic encoding of
|
|
19
|
+
* RFC 8949 §4.2.1 before authenticating it, so that a receiver who parses
|
|
20
|
+
* and re-serializes the record arrives at the very bytes this tag covers.
|
|
21
|
+
* Defaults to true. A payload that is not CBOR is authenticated as it is.
|
|
22
|
+
*/
|
|
23
|
+
readonly canonicalizePayload?: boolean;
|
|
24
|
+
/** Whether to wrap the message within CBOR tag 97. Defaults to true. */
|
|
25
|
+
readonly tagged?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** What a party checking may have to supply. */
|
|
28
|
+
export interface MacVerifyOptions {
|
|
29
|
+
/** The data that was authenticated along with the payload. */
|
|
30
|
+
readonly externalAad?: Uint8Array | null;
|
|
31
|
+
/** The payload, when the message carries a detached one. */
|
|
32
|
+
readonly detachedPayload?: Uint8Array | null;
|
|
33
|
+
/** The algorithm the caller expects. */
|
|
34
|
+
readonly expectedAlgorithm?: CoseAlgorithm | null;
|
|
35
|
+
/** Header parameters the caller processes itself. */
|
|
36
|
+
readonly alsoUnderstood?: readonly CborValue[];
|
|
37
|
+
}
|
|
38
|
+
export declare class CoseMac {
|
|
39
|
+
/** The serialized protected bucket, exactly as authenticated and received. */
|
|
40
|
+
readonly protectedHeaderBytes: Uint8Array;
|
|
41
|
+
/** The protected header parameters, which the authentication tag covers. */
|
|
42
|
+
readonly protectedHeader: CoseHeaders;
|
|
43
|
+
/** The unprotected header parameters, which it does not. */
|
|
44
|
+
readonly unprotectedHeader: CoseHeaders;
|
|
45
|
+
/** The authenticated payload, or null when it is detached. */
|
|
46
|
+
readonly payload: Uint8Array | null;
|
|
47
|
+
/** The authentication tag — not the CBOR tag. */
|
|
48
|
+
readonly tag: Uint8Array;
|
|
49
|
+
/** How the content key reaches each party. */
|
|
50
|
+
readonly recipients: readonly CoseRecipient[];
|
|
51
|
+
/** Whether this message is wrapped within CBOR tag 97. */
|
|
52
|
+
readonly isTagged: boolean;
|
|
53
|
+
constructor(protectedHeaderBytes: Uint8Array, unprotectedHeader: CoseHeaders | null, payload: Uint8Array | null, tag: Uint8Array, recipients: readonly CoseRecipient[], isTagged?: boolean);
|
|
54
|
+
/** Whether the payload is detached. */
|
|
55
|
+
get isDetached(): boolean;
|
|
56
|
+
/** The MAC algorithm, protected bucket first. */
|
|
57
|
+
get algorithm(): CoseAlgorithm | null;
|
|
58
|
+
/**
|
|
59
|
+
* The encoded MAC_structure [RFC 9052, Section 6.3] with the `"MAC"`
|
|
60
|
+
* context — the one difference from a COSE_Mac0's.
|
|
61
|
+
*/
|
|
62
|
+
static toBeMaced(protectedHeaderBytes: Uint8Array, payload: Uint8Array, externalAad?: Uint8Array | null): Uint8Array;
|
|
63
|
+
/** The encoded MAC_structure of this message. */
|
|
64
|
+
toBeMaced(options?: {
|
|
65
|
+
externalAad?: Uint8Array | null;
|
|
66
|
+
detachedPayload?: Uint8Array | null;
|
|
67
|
+
}): Uint8Array;
|
|
68
|
+
/**
|
|
69
|
+
* Authenticate a payload under a content key, and deliver that key to each
|
|
70
|
+
* recipient.
|
|
71
|
+
*
|
|
72
|
+
* The content key is the caller's rather than generated here, for the same
|
|
73
|
+
* reason as everywhere else in this package: a generated one would make the
|
|
74
|
+
* message unreproducible, and whoever has a key management scheme has it
|
|
75
|
+
* for a reason.
|
|
76
|
+
*/
|
|
77
|
+
static create(payload: Uint8Array, contentKey: CoseKey, recipients: readonly CoseRecipient[], options?: MacOptions): CoseMac;
|
|
78
|
+
/**
|
|
79
|
+
* Verify this message with a key one of its recipients was built for.
|
|
80
|
+
*
|
|
81
|
+
* Every recipient is tried, because a party holding one key does not
|
|
82
|
+
* generally know which entry in the list is theirs.
|
|
83
|
+
*/
|
|
84
|
+
verify(key: CoseKey, options?: MacVerifyOptions): Verification;
|
|
85
|
+
/** Read a COSE_Mac message, tagged or not. */
|
|
86
|
+
static parse(input: Uint8Array | CborValue): CoseMac;
|
|
87
|
+
/** The CBOR form of this message. */
|
|
88
|
+
toCbor(): CborValue;
|
|
89
|
+
/** The CBOR encoding of this message. */
|
|
90
|
+
toBytes(): Uint8Array;
|
|
91
|
+
toString(): string;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=mac.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mac.d.ts","sourceRoot":"","sources":["../src/mac.ts"],"names":[],"mappings":"AA0CA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAqB,gBAAgB,CAAC;AAGnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAyB,WAAW,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,E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+1,132 @@
|
|
|
1
|
+
import type { CoseAlgorithm } from './algorithm.ts';
|
|
2
|
+
import type { CborValue } from './cbor.ts';
|
|
3
|
+
import type { Verification } from './errors.ts';
|
|
4
|
+
import { CoseHeaders } from './headers.ts';
|
|
5
|
+
import type { CoseKey } from './key.ts';
|
|
6
|
+
/** The CBOR tag of a COSE_Mac0 message. */
|
|
7
|
+
export declare const COSE_MAC0_TAG = 17;
|
|
8
|
+
/** The context string of a COSE_Mac0 authentication tag [RFC 9052, Section 6.3]. */
|
|
9
|
+
export declare const MAC0_CONTEXT = "MAC0";
|
|
10
|
+
/** What a party computing an authentication tag may choose. */
|
|
11
|
+
export interface Mac0Options {
|
|
12
|
+
/** A key identifier for the unprotected bucket, defaulting to the key's own. */
|
|
13
|
+
readonly keyIdentifier?: Uint8Array | null;
|
|
14
|
+
/** Data authenticated along with the payload without travelling in the message. */
|
|
15
|
+
readonly externalAad?: Uint8Array | null;
|
|
16
|
+
/** Whether to omit the payload from the message. */
|
|
17
|
+
readonly detachPayload?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to rewrite a CBOR payload in the deterministic encoding of
|
|
20
|
+
* RFC 8949 §4.2.1 before authenticating it, so that a receiver who parses
|
|
21
|
+
* and re-serializes the record arrives at the very bytes this tag covers.
|
|
22
|
+
* Defaults to true. A payload that is not CBOR is authenticated as it is.
|
|
23
|
+
*/
|
|
24
|
+
readonly canonicalizePayload?: boolean;
|
|
25
|
+
/** Whether to wrap the message within CBOR tag 17. Defaults to true. */
|
|
26
|
+
readonly tagged?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** What a party checking an authentication tag may have to supply. */
|
|
29
|
+
export interface Mac0VerifyOptions {
|
|
30
|
+
/** The data that was authenticated along with the payload. */
|
|
31
|
+
readonly externalAad?: Uint8Array | null;
|
|
32
|
+
/** The payload, when the message carries a detached one. */
|
|
33
|
+
readonly detachedPayload?: Uint8Array | null;
|
|
34
|
+
/**
|
|
35
|
+
* The algorithm the caller expects, required whenever the message states
|
|
36
|
+
* its algorithm within the unprotected bucket only.
|
|
37
|
+
*/
|
|
38
|
+
readonly expectedAlgorithm?: CoseAlgorithm | null;
|
|
39
|
+
/**
|
|
40
|
+
* Header parameters the caller processes itself, and which a `crit`
|
|
41
|
+
* header parameter may therefore demand.
|
|
42
|
+
*/
|
|
43
|
+
readonly alsoUnderstood?: readonly CborValue[];
|
|
44
|
+
}
|
|
45
|
+
export declare class CoseMac0 {
|
|
46
|
+
/**
|
|
47
|
+
* The serialized protected bucket, exactly as authenticated and as
|
|
48
|
+
* received: a zero-length byte string when there are no protected header
|
|
49
|
+
* parameters.
|
|
50
|
+
*/
|
|
51
|
+
readonly protectedHeaderBytes: Uint8Array;
|
|
52
|
+
/** The protected header parameters, which the authentication tag covers. */
|
|
53
|
+
readonly protectedHeader: CoseHeaders;
|
|
54
|
+
/**
|
|
55
|
+
* The unprotected header parameters, which the tag does not cover and
|
|
56
|
+
* which therefore must not be trusted after a successful verification.
|
|
57
|
+
*/
|
|
58
|
+
readonly unprotectedHeader: CoseHeaders;
|
|
59
|
+
/** The authenticated payload, or null when it is detached. */
|
|
60
|
+
readonly payload: Uint8Array | null;
|
|
61
|
+
/** The authentication tag — not the CBOR tag. */
|
|
62
|
+
readonly tag: Uint8Array;
|
|
63
|
+
/**
|
|
64
|
+
* Whether this message is wrapped within CBOR tag 17. The tag is not
|
|
65
|
+
* covered by the authentication tag, but it is preserved so that a parsed
|
|
66
|
+
* message re-encodes to the very same bytes.
|
|
67
|
+
*/
|
|
68
|
+
readonly isTagged: boolean;
|
|
69
|
+
constructor(protectedHeaderBytes: Uint8Array, unprotectedHeader: CoseHeaders | null, payload: Uint8Array | null, tag: Uint8Array, isTagged?: boolean);
|
|
70
|
+
/** Whether the payload is detached. */
|
|
71
|
+
get isDetached(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* The MAC algorithm, taken from the protected bucket and only otherwise
|
|
74
|
+
* from the unprotected one.
|
|
75
|
+
*/
|
|
76
|
+
get algorithm(): CoseAlgorithm | null;
|
|
77
|
+
/** The key identifier, protected bucket first. */
|
|
78
|
+
get keyIdentifier(): Uint8Array | null;
|
|
79
|
+
/**
|
|
80
|
+
* The encoded MAC_structure [RFC 9052, Section 6.3], which is the byte
|
|
81
|
+
* string the MAC is actually computed over:
|
|
82
|
+
*
|
|
83
|
+
* <code>
|
|
84
|
+
* MAC_structure = [
|
|
85
|
+
* context : "MAC0",
|
|
86
|
+
* protected : empty_or_serialized_map,
|
|
87
|
+
* external_aad : bstr,
|
|
88
|
+
* payload : bstr
|
|
89
|
+
* ]
|
|
90
|
+
* </code>
|
|
91
|
+
*
|
|
92
|
+
* The full payload goes in here regardless of how it travels, so a
|
|
93
|
+
* detached message and an attached one carry the very same tag.
|
|
94
|
+
*/
|
|
95
|
+
static toBeMaced(protectedHeaderBytes: Uint8Array, payload: Uint8Array, externalAad?: Uint8Array | null): Uint8Array;
|
|
96
|
+
/** The encoded MAC_structure of this message. */
|
|
97
|
+
toBeMaced(options?: {
|
|
98
|
+
externalAad?: Uint8Array | null;
|
|
99
|
+
detachedPayload?: Uint8Array | null;
|
|
100
|
+
}): Uint8Array;
|
|
101
|
+
/**
|
|
102
|
+
* Authenticate a payload, placing the algorithm within the protected
|
|
103
|
+
* bucket and the key identifier within the unprotected one.
|
|
104
|
+
*/
|
|
105
|
+
static create(payload: Uint8Array, key: CoseKey, options?: Mac0Options): CoseMac0;
|
|
106
|
+
/** Authenticate a payload with header buckets the caller composed. */
|
|
107
|
+
static createWithHeaders(payload: Uint8Array, key: CoseKey, protectedHeader: CoseHeaders, unprotectedHeader?: CoseHeaders | null, options?: Mac0Options): CoseMac0;
|
|
108
|
+
/**
|
|
109
|
+
* Verify the authentication tag of this message.
|
|
110
|
+
*
|
|
111
|
+
* A failed verification is not an exception — it is the expected outcome
|
|
112
|
+
* of checking untrusted data — so the reason travels in the result. The
|
|
113
|
+
* comparison itself is constant time, which matters here in a way it does
|
|
114
|
+
* not for a signature: an early-returning compare would tell whoever is
|
|
115
|
+
* guessing a tag how many of their leading bytes were right.
|
|
116
|
+
*/
|
|
117
|
+
verify(key: CoseKey, options?: Mac0VerifyOptions): Verification;
|
|
118
|
+
/** Read a COSE_Mac0 message, tagged or not. */
|
|
119
|
+
static parse(input: Uint8Array | CborValue): CoseMac0;
|
|
120
|
+
/** The CBOR form of this message. */
|
|
121
|
+
toCbor(): CborValue;
|
|
122
|
+
/** The CBOR encoding of this message. */
|
|
123
|
+
toBytes(): Uint8Array;
|
|
124
|
+
/**
|
|
125
|
+
* A copy of this message without its payload.
|
|
126
|
+
*
|
|
127
|
+
* The tag stays valid: it never covered the message, only the
|
|
128
|
+
* MAC_structure, and the MAC_structure always holds the full payload.
|
|
129
|
+
*/
|
|
130
|
+
detach(): CoseMac0;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=mac0.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mac0.d.ts","sourceRoot":"","sources":["../src/mac0.ts"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAqB,gBAAgB,CAAC;AAGnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAyB,WAAW,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAsB,aAAa,CAAC;AAChE,OAAO,EAAE,WAAW,EACqB,MAAS,cAAc,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAA2B,UAAU,CAAC;AAM7D,2CAA2C;AAC3C,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,oFAAoF;AACpF,eAAO,MAAM,YAAY,SAAS,CAAC;AAGnC,+DAA+D;AAC/D,MAAM,WAAW,WAAW;IAExB,gFAAgF;IAChF,QAAQ,CAAC,aAAa,CAAC,EAAG,UAAU,GAAG,IAAI,CAAC;IAE5C,mFAAmF;IACnF,QAAQ,CAAC,WAAW,CAAC,EAAK,UAAU,GAAG,IAAI,CAAC;IAE5C,oDAAoD;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AKD;;;;;;;;;;;;;;;OAeG;WACW,SAAS,CAAC,oBAAoB,EAAE,UAAU,EAChC,OAAO,EAAe,UAAU,EAChC,WAAW,GAAW,UAAU,GAAG,IAAW,GAAG,UAAU;IAYnF,iDAAiD;IAC1C,SAAS,CAAC,OAAO,GAAE;QAAE,WAAW,CAAC,EAAM,UAAU,GAAG,IAAI,CAAC;QACpC,eAAe,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;KAAO,GAAG,UAAU;IAkBnF;;;OAGG;WACW,MAAM,CAAC,OAAO,EAAE,UAAU,EACnB,GAAG,EAAM,OAAO,EAChB,OAAO,GAAE,WAAgB,GAAG,QAAQ;IAsBzD,sEAAsE;WACxD,iBAAiB,CAAC,OAAO,EAAa,UAAU,EAC9B,GAAG,EAAiB,OAAO,EAC3B,eAAe,EAAK,WAAW,EAC/B,iBAAiB,GAAG,WAAW,GAAG,IAAW,EAC7C,OAAO,GAAa,WAAgB,GAAG,QAAQ;IAoC/E;;;;;;;;OAQG;IACI,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,iBAAsB,GAAG,YAAY;IAqD1E,+CAA+C;WACjC,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ;IA8C5D,qCAAqC;IAC9B,MAAM,IAAI,SAAS;IAc1B,yCAAyC;IAClC,OAAO,IAAI,UAAU;IAK5B;;;;;OAKG;IACI,MAAM,IAAI,QAAQ;CAK5B"}
|
package/dist/mldsa.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** The three parameter sets RFC 9964 registers. */
|
|
2
|
+
export declare const MLDSA_PARAMETER_SETS: readonly ["ML-DSA-44", "ML-DSA-65", "ML-DSA-87"];
|
|
3
|
+
export type MldsaParameterSet = typeof MLDSA_PARAMETER_SETS[number];
|
|
4
|
+
/** The sizes RFC 9964 prints, in bytes. */
|
|
5
|
+
export declare const MLDSA_SIZES: Readonly<Record<MldsaParameterSet, {
|
|
6
|
+
publicKey: number;
|
|
7
|
+
signature: number;
|
|
8
|
+
}>>;
|
|
9
|
+
/** The length of an ML-DSA private key, which is always the seed. */
|
|
10
|
+
export declare const MLDSA_SEED_SIZE = 32;
|
|
11
|
+
/** Whether the given name is a parameter set this build can compute with. */
|
|
12
|
+
export declare const isMldsaParameterSet: (parameterSet: string) => parameterSet is MldsaParameterSet;
|
|
13
|
+
/**
|
|
14
|
+
* The public key belonging to a seed.
|
|
15
|
+
*
|
|
16
|
+
* Deriving rather than storing it is what keeps `priv` at 32 bytes: the
|
|
17
|
+
* expanded secret key of ML-DSA-87 is 4896.
|
|
18
|
+
*/
|
|
19
|
+
export declare function mldsaPublicKeyFor(parameterSet: string, seed: Uint8Array): Uint8Array;
|
|
20
|
+
/**
|
|
21
|
+
* Sign the Sig_structure itself, deterministically.
|
|
22
|
+
*
|
|
23
|
+
* `extraEntropy: false` selects the deterministic variant of FIPS 204, in
|
|
24
|
+
* which the per-signature randomness is 32 zero bytes rather than drawn.
|
|
25
|
+
*/
|
|
26
|
+
export declare function mldsaSign(parameterSet: string, message: Uint8Array, seed: Uint8Array): Uint8Array;
|
|
27
|
+
/** Verify an ML-DSA signature over the Sig_structure. */
|
|
28
|
+
export declare function mldsaVerify(parameterSet: string, signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
|
|
29
|
+
//# sourceMappingURL=mldsa.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mldsa.d.ts","sourceRoot":"","sources":["../src/mldsa.ts"],"names":[],"mappings":"AAgDA,mDAAmD;AACnD,eAAO,MAAM,oBAAoB,kDAAmD,CAAC;AAErF,MAAM,MAAM,iBAAiB,GAAG,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAUpE,2CAA2C;AAC3C,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EACjB;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAIlF,CAAC;AAGF,qEAAqE;AACrE,eAAO,MAAM,eAAe,KAAK,CAAC;AAelC,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,GAAI,cAAc,MAAM,KAAG,YAAY,IAAI,iBAC5C,CAAC;AAGhC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAMpF;AAGD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAO,UAAU,EACxB,IAAI,EAAU,UAAU,GAAG,UAAU,CAQ9D;AAGD,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAK,UAAU,EACxB,OAAO,EAAO,UAAU,EACxB,SAAS,EAAK,UAAU,GAAG,OAAO,CAc7D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite a payload in the deterministic encoding of RFC 8949 Section 4.2.1,
|
|
3
|
+
* or return it unchanged where it is not one well-formed CBOR data item and
|
|
4
|
+
* nothing else.
|
|
5
|
+
*
|
|
6
|
+
* Not being CBOR is not an error here: text, JSON, an image or a detached
|
|
7
|
+
* hash have no canonical CBOR form to be rewritten into, and a COSE payload is
|
|
8
|
+
* allowed to be any of them.
|
|
9
|
+
*/
|
|
10
|
+
export declare function canonicalizePayload(payload: Uint8Array): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Whether a payload survives being decoded and encoded again: whether it is
|
|
13
|
+
* one well-formed CBOR data item whose deterministic encoding is the payload
|
|
14
|
+
* itself.
|
|
15
|
+
*
|
|
16
|
+
* Deliberately the round trip rather than a strict decode. What a forwarding
|
|
17
|
+
* receiver actually does is decode and re-encode, so the question worth
|
|
18
|
+
* answering is whether that changes anything — not whether a list of rules is
|
|
19
|
+
* satisfied.
|
|
20
|
+
*
|
|
21
|
+
* A payload that is not CBOR is not canonical: there is nothing here to have
|
|
22
|
+
* an opinion about.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isCanonicalPayload(payload: Uint8Array): boolean;
|
|
25
|
+
//# sourceMappingURL=payload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../src/payload.ts"],"names":[],"mappings":"AAgCA;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAYnE;AAGD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAU/D"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { CoseAlgorithm } from './algorithm.ts';
|
|
2
|
+
import type { CborValue } from './cbor.ts';
|
|
3
|
+
import { CoseHeaders } from './headers.ts';
|
|
4
|
+
import type { CoseKey } from './key.ts';
|
|
5
|
+
/** What a party building a recipient structure may choose. */
|
|
6
|
+
export interface RecipientOptions {
|
|
7
|
+
/** A key identifier for the unprotected bucket, defaulting to the key's own. */
|
|
8
|
+
readonly keyIdentifier?: Uint8Array | null;
|
|
9
|
+
/** Recipient structures nested below this one. */
|
|
10
|
+
readonly recipients?: readonly CoseRecipient[];
|
|
11
|
+
}
|
|
12
|
+
export declare class CoseRecipient {
|
|
13
|
+
/** The serialized protected bucket — empty for both implemented routes. */
|
|
14
|
+
readonly protectedHeaderBytes: Uint8Array;
|
|
15
|
+
/** The protected header parameters. */
|
|
16
|
+
readonly protectedHeader: CoseHeaders;
|
|
17
|
+
/** The unprotected header parameters, which is where `alg` and `kid` live here. */
|
|
18
|
+
readonly unprotectedHeader: CoseHeaders;
|
|
19
|
+
/** The wrapped content key, or a zero-length string for `direct`. */
|
|
20
|
+
readonly ciphertext: Uint8Array;
|
|
21
|
+
/** Recipient structures nested below this one. */
|
|
22
|
+
readonly recipients: readonly CoseRecipient[];
|
|
23
|
+
constructor(protectedHeaderBytes: Uint8Array, unprotectedHeader: CoseHeaders | null, ciphertext: Uint8Array, recipients?: readonly CoseRecipient[]);
|
|
24
|
+
/** The recipient algorithm, protected bucket first. */
|
|
25
|
+
get algorithm(): CoseAlgorithm | null;
|
|
26
|
+
/** The key identifier, protected bucket first. */
|
|
27
|
+
get keyIdentifier(): Uint8Array | null;
|
|
28
|
+
/**
|
|
29
|
+
* A `direct` recipient: the key it names *is* the content key.
|
|
30
|
+
*
|
|
31
|
+
* RFC 9053 §6.1.1 requires the protected bucket to be zero length, and
|
|
32
|
+
* nothing is carried in the ciphertext either — so this structure conveys
|
|
33
|
+
* a key identifier and an algorithm and no key material at all.
|
|
34
|
+
*/
|
|
35
|
+
static direct(key: CoseKey, options?: RecipientOptions): CoseRecipient;
|
|
36
|
+
/**
|
|
37
|
+
* A key-wrap recipient: the content key, encrypted under the given
|
|
38
|
+
* key-encryption key.
|
|
39
|
+
*
|
|
40
|
+
* The algorithm follows from the width of the *key-encryption* key rather
|
|
41
|
+
* than from the content key, which is the direction people get wrong:
|
|
42
|
+
* `A256KW` wraps a 128-bit content key perfectly well.
|
|
43
|
+
*/
|
|
44
|
+
static keyWrap(contentKey: Uint8Array, keyEncryptionKey: CoseKey, options?: RecipientOptions): CoseRecipient;
|
|
45
|
+
/**
|
|
46
|
+
* The content key this recipient carries, or null when the given key is
|
|
47
|
+
* not the one it was built for.
|
|
48
|
+
*
|
|
49
|
+
* Null rather than an exception, and rather than a reason: a party holding
|
|
50
|
+
* several keys tries them in turn, and "not this one" is the ordinary
|
|
51
|
+
* answer rather than an error. For key wrap it is also the *only* honest
|
|
52
|
+
* answer — RFC 3394's integrity check is what distinguishes a wrong key
|
|
53
|
+
* from a right one, and saying more about which would say something about
|
|
54
|
+
* the key.
|
|
55
|
+
*/
|
|
56
|
+
contentKey(key: CoseKey): Uint8Array | null;
|
|
57
|
+
/** Read a COSE_recipient. */
|
|
58
|
+
static parse(value: CborValue): CoseRecipient;
|
|
59
|
+
/** The CBOR form of this recipient. */
|
|
60
|
+
toCbor(): CborValue;
|
|
61
|
+
toString(): string;
|
|
62
|
+
}
|
|
63
|
+
/** The key-wrap algorithm a key-encryption key of the given width belongs to. */
|
|
64
|
+
export declare function keyWrapAlgorithmFor(keySize: number): CoseAlgorithm;
|
|
65
|
+
//# sourceMappingURL=recipient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recipient.d.ts","sourceRoot":"","sources":["../src/recipient.ts"],"names":[],"mappings":"AAuDA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAqB,gBAAgB,CAAC;AAGnE,OAAO,KAAK,EAAa,SAAS,EAAE,MAAc,WAAW,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAA4B,cAAc,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAA2B,UAAU,CAAC;AAI7D,8DAA8D;AAC9D,MAAM,WAAW,gBAAgB;IAE7B,gFAAgF;IAChF,QAAQ,CAAC,aAAa,CAAC,EAAG,UAAU,GAAG,IAAI,CAAC;IAE5C,kDAAkD;IAClD,QAAQ,CAAC,UAAU,CAAC,EAAM,SAAS,aAAa,EAAE,CAAC;CAEtD;AAGD,qBAAa,aAAa;IAEtB,2EAA2E;IAC3E,SAAgB,oBAAoB,EAAG,UAAU,CAAC;IAElD,uCAAuC;IACvC,SAAgB,eAAe,EAAQ,WAAW,CAAC;IAEnD,mFAAmF;IACnF,SAAgB,iBAAiB,EAAM,WAAW,CAAC;IAEnD,qEAAqE;IACrE,SAAgB,UAAU,EAAa,UAAU,CAAC;IAElD,kDAAkD;IAClD,SAAgB,UAAU,EAAa,SAAS,aAAa,EAAE,CAAC;gBAG7C,oBAAoB,EAAE,UAAU,EAChC,iBAAiB,EAAK,WAAW,GAAG,IAAI,EACxC,UAAU,EAAY,UAAU,EAChC,UAAU,GAAY,SAAS,aAAa,EAAO;IAWtE,uDAAuD;IACvD,IAAW,SAAS,IAAI,aAAa,GAAG,IAAI,CAE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