@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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CoseAlgorithm } from './algorithm.ts';
|
|
2
|
+
import type { CoseHeaders } from './headers.ts';
|
|
3
|
+
/** Either an answer, or the reason there is none. */
|
|
4
|
+
export type Resolved<T> = {
|
|
5
|
+
readonly ok: true;
|
|
6
|
+
readonly value: T;
|
|
7
|
+
} | {
|
|
8
|
+
readonly ok: false;
|
|
9
|
+
readonly reason: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Which algorithm to verify with.
|
|
13
|
+
*
|
|
14
|
+
* An algorithm stated in the *unprotected* bucket is not covered by the
|
|
15
|
+
* signature and can therefore be changed by anyone on the path. It is not
|
|
16
|
+
* silently trusted: the caller has to name the expected algorithm to accept
|
|
17
|
+
* it, deliberately, which is the difference between a verifier that resists an
|
|
18
|
+
* algorithm-substitution attack and one that documents that it does.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveAlgorithm(protectedHeader: CoseHeaders, unprotectedHeader: CoseHeaders, expected: CoseAlgorithm | null, what: string): Resolved<CoseAlgorithm>;
|
|
21
|
+
/**
|
|
22
|
+
* Which payload the signature is computed over: the one carried within the
|
|
23
|
+
* message, or the detached one supplied by the caller.
|
|
24
|
+
*
|
|
25
|
+
* Supplying both is rejected, because there would be no way to tell which of
|
|
26
|
+
* the two a verification result refers to.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolvePayload(carried: Uint8Array | null, detached: Uint8Array | null, what: string): Resolved<Uint8Array>;
|
|
29
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAQ,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAU,cAAc,CAAC;AAGpD,qDAAqD;AACrD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAChB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACzC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAGtD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,eAAe,EAAI,WAAW,EAC9B,iBAAiB,EAAE,WAAW,EAC9B,QAAQ,EAAW,aAAa,GAAG,IAAI,EACvC,IAAI,EAAe,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,CA2BnF;AAGD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAG,UAAU,GAAG,IAAI,EAC3B,QAAQ,EAAE,UAAU,GAAG,IAAI,EAC3B,IAAI,EAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAgBrE"}
|
package/dist/sign.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { CborValue } from './cbor.ts';
|
|
2
|
+
import type { Verification } from './errors.ts';
|
|
3
|
+
import { CoseHeaders } from './headers.ts';
|
|
4
|
+
import type { CoseKey } from './key.ts';
|
|
5
|
+
import { CoseSignature } from './signature.ts';
|
|
6
|
+
import type { Sign1Options, VerifyOptions } from './sign1.ts';
|
|
7
|
+
/** The CBOR tag of a COSE_Sign message. */
|
|
8
|
+
export declare const COSE_SIGN_TAG = 98;
|
|
9
|
+
/** The context string of a COSE_Sign signature [RFC 9052, Section 4.4]. */
|
|
10
|
+
export declare const SIGNATURE_CONTEXT = "Signature";
|
|
11
|
+
export declare class CoseSign {
|
|
12
|
+
/** The serialized protected bucket of the body, exactly as signed. */
|
|
13
|
+
readonly protectedHeaderBytes: Uint8Array;
|
|
14
|
+
/** The protected header parameters of the body, which every signature covers. */
|
|
15
|
+
readonly protectedHeader: CoseHeaders;
|
|
16
|
+
/** The unprotected header parameters of the body, which none of them covers. */
|
|
17
|
+
readonly unprotectedHeader: CoseHeaders;
|
|
18
|
+
/** The signed payload, or null when it is detached. */
|
|
19
|
+
readonly payload: Uint8Array | null;
|
|
20
|
+
/** The signatures, in the order they travel. */
|
|
21
|
+
readonly signatures: readonly CoseSignature[];
|
|
22
|
+
/** Whether this message is wrapped within CBOR tag 98. */
|
|
23
|
+
readonly isTagged: boolean;
|
|
24
|
+
constructor(protectedHeaderBytes: Uint8Array, unprotectedHeader: CoseHeaders | null, payload: Uint8Array | null, signatures: readonly CoseSignature[], isTagged?: boolean);
|
|
25
|
+
/** Whether the payload is detached. */
|
|
26
|
+
get isDetached(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The encoded Sig_structure of one signature of a COSE_Sign message
|
|
29
|
+
* [RFC 9052, Section 4.4]:
|
|
30
|
+
*
|
|
31
|
+
* <code>
|
|
32
|
+
* Sig_structure = [
|
|
33
|
+
* context : "Signature",
|
|
34
|
+
* body_protected : empty_or_serialized_map,
|
|
35
|
+
* sign_protected : empty_or_serialized_map,
|
|
36
|
+
* external_aad : bstr,
|
|
37
|
+
* payload : bstr
|
|
38
|
+
* ]
|
|
39
|
+
* </code>
|
|
40
|
+
*/
|
|
41
|
+
static toBeSigned(bodyProtectedHeaderBytes: Uint8Array, signatureProtectedHeaderBytes: Uint8Array, payload: Uint8Array, externalAad?: Uint8Array | null): Uint8Array;
|
|
42
|
+
/** The encoded Sig_structure of one signature of this message. */
|
|
43
|
+
toBeSigned(signature: CoseSignature, options?: {
|
|
44
|
+
externalAad?: Uint8Array | null;
|
|
45
|
+
detachedPayload?: Uint8Array | null;
|
|
46
|
+
}): Uint8Array;
|
|
47
|
+
/**
|
|
48
|
+
* Sign a payload, producing a message with one signature.
|
|
49
|
+
*
|
|
50
|
+
* The body's protected bucket stays empty: what a signer has to say about
|
|
51
|
+
* its own signature — its algorithm, its key identifier — belongs to that
|
|
52
|
+
* signature rather than to the body every other signer shares.
|
|
53
|
+
*/
|
|
54
|
+
static sign(payload: Uint8Array, key: CoseKey, options?: Sign1Options): CoseSign;
|
|
55
|
+
/**
|
|
56
|
+
* Return a copy of this message with one more signature.
|
|
57
|
+
*
|
|
58
|
+
* The existing signatures are untouched and stay valid, because no
|
|
59
|
+
* signature ever covers another.
|
|
60
|
+
*/
|
|
61
|
+
addSignature(key: CoseKey, options?: Sign1Options & {
|
|
62
|
+
detachedPayload?: Uint8Array | null;
|
|
63
|
+
}): CoseSign;
|
|
64
|
+
/** Verify one signature of this message. */
|
|
65
|
+
verify(signature: CoseSignature, key: CoseKey, options?: VerifyOptions): Verification;
|
|
66
|
+
/**
|
|
67
|
+
* The first signature this key verifies, or null.
|
|
68
|
+
*
|
|
69
|
+
* Signatures are tried in wire order. A signature that states its
|
|
70
|
+
* algorithm in the unprotected bucket only still needs an expected
|
|
71
|
+
* algorithm to be accepted, here as everywhere else — which the key
|
|
72
|
+
* supplies when it carries one, and otherwise nobody does.
|
|
73
|
+
*/
|
|
74
|
+
verifyAny(key: CoseKey, options?: VerifyOptions): CoseSignature | null;
|
|
75
|
+
/** Parse a COSE_Sign message, tagged or untagged. */
|
|
76
|
+
static parse(input: Uint8Array | CborValue): CoseSign;
|
|
77
|
+
/** A CBOR representation of this message. */
|
|
78
|
+
toCbor(): CborValue;
|
|
79
|
+
/** The CBOR encoding of this message. */
|
|
80
|
+
toBytes(): Uint8Array;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=sign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../src/sign.ts"],"names":[],"mappings":"A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AAS,EAAE,aAAa,EACxB,OAAO,GAAE;QAAE,WAAW,CAAC,EAAM,UAAU,GAAG,IAAI,CAAC;QACpC,eAAe,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;KAAO,GAAG,UAAU;IAiBpF;;;;;;OAMG;WACW,IAAI,CAAC,OAAO,EAAE,UAAU,EACnB,GAAG,EAAM,OAAO,EAChB,OAAO,GAAE,YAAiB,GAAG,QAAQ;IAqBxD;;;;;OAKG;IACI,YAAY,CAAC,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE,YAAY,GAAG;QACpB,eAAe,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;KAAO,GAAG,QAAQ;IAmB7E,4CAA4C;IACrC,MAAM,CAAC,SAAS,EAAE,aAAa,EACxB,GAAG,EAAQ,OAAO,EAClB,OAAO,GAAI,aAAkB,GAAG,YAAY;IA6C1D;;;;;;;OAOG;IACI,SAAS,CAAC,GAAG,EAAM,OAAO,EAChB,OAAO,GAAE,aAAkB,GAAG,aAAa,GAAG,IAAI;IAYnE,qDAAqD;WACvC,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ;IA8C5D,6CAA6C;IACtC,MAAM,IAAI,SAAS;IAc1B,yCAAyC;IAClC,OAAO,IAAI,UAAU;CAI/B"}
|
package/dist/sign1.d.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import type { CoseAlgorithm } from './algorithm.ts';
|
|
2
|
+
import type { CborValue } from './cbor.ts';
|
|
3
|
+
import type { NotVerified, Verification } from './errors.ts';
|
|
4
|
+
import { CoseHeaders } from './headers.ts';
|
|
5
|
+
import type { CoseKey } from './key.ts';
|
|
6
|
+
import { CoseSignature } from './signature.ts';
|
|
7
|
+
import { CoseCertificateChain, CoseCertificateHash } from './x5chain.ts';
|
|
8
|
+
import type { X509Certificate } from './x509.ts';
|
|
9
|
+
/** The CBOR tag of a COSE_Sign1 message. */
|
|
10
|
+
export declare const COSE_SIGN1_TAG = 18;
|
|
11
|
+
/** The context string of a COSE_Sign1 signature [RFC 9052, Section 4.4]. */
|
|
12
|
+
export declare const SIGNATURE_CONTEXT = "Signature1";
|
|
13
|
+
/**
|
|
14
|
+
* The context string of a countersignature that also covers the signature it
|
|
15
|
+
* countersigns [RFC 9338, Section 3.3].
|
|
16
|
+
*/
|
|
17
|
+
export declare const COUNTERSIGNATURE_CONTEXT = "CounterSignatureV2";
|
|
18
|
+
/** What a signer may choose beyond the payload and the key. */
|
|
19
|
+
export interface Sign1Options {
|
|
20
|
+
/** A key identifier for the unprotected bucket, defaulting to the key's own. */
|
|
21
|
+
readonly keyIdentifier?: Uint8Array | null;
|
|
22
|
+
/** Data signed along with the payload without travelling in the message. */
|
|
23
|
+
readonly externalAad?: Uint8Array | null;
|
|
24
|
+
/** Whether to omit the payload from the message. */
|
|
25
|
+
readonly detachPayload?: boolean;
|
|
26
|
+
/** Whether to wrap the message within CBOR tag 18. Defaults to true. */
|
|
27
|
+
readonly tagged?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether to rewrite a CBOR payload in the deterministic encoding of
|
|
30
|
+
* RFC 8949 Section 4.2.1 before signing it, so that a receiver who parses
|
|
31
|
+
* and re-serializes the record arrives at the very bytes the signature
|
|
32
|
+
* covers. Defaults to true. A payload that is not CBOR is signed as it is.
|
|
33
|
+
*/
|
|
34
|
+
readonly canonicalizePayload?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** What a verifier may have to supply. */
|
|
37
|
+
export interface VerifyOptions {
|
|
38
|
+
/** The data that was signed along with the payload. */
|
|
39
|
+
readonly externalAad?: Uint8Array | null;
|
|
40
|
+
/** The payload, when the message carries a detached one. */
|
|
41
|
+
readonly detachedPayload?: Uint8Array | null;
|
|
42
|
+
/**
|
|
43
|
+
* The algorithm the caller expects, required whenever the message states
|
|
44
|
+
* its algorithm within the unprotected bucket only.
|
|
45
|
+
*/
|
|
46
|
+
readonly expectedAlgorithm?: CoseAlgorithm | null;
|
|
47
|
+
/**
|
|
48
|
+
* Header parameters the caller processes itself, and which a `crit`
|
|
49
|
+
* header parameter may therefore demand.
|
|
50
|
+
*/
|
|
51
|
+
readonly alsoUnderstood?: readonly CborValue[];
|
|
52
|
+
}
|
|
53
|
+
/** What a verifier working from a certificate chain may supply beyond that. */
|
|
54
|
+
export interface CertificateChainVerifyOptions extends VerifyOptions {
|
|
55
|
+
/**
|
|
56
|
+
* The instant to check the certificates' validity periods at, now by
|
|
57
|
+
* default. Worth passing whenever the answer has to be reproducible: an
|
|
58
|
+
* archived message re-checked years later is checked against the
|
|
59
|
+
* certificates of its own time, not of today.
|
|
60
|
+
*/
|
|
61
|
+
readonly at?: Date;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The outcome of verifying against a certificate chain.
|
|
65
|
+
*
|
|
66
|
+
* A success names the certificate whose key verified, because "it verified" is
|
|
67
|
+
* only half of what the caller asked: the other half is *who*, and a chain
|
|
68
|
+
* exists precisely to answer that.
|
|
69
|
+
*/
|
|
70
|
+
export type CertificateChainVerification = {
|
|
71
|
+
readonly verified: true;
|
|
72
|
+
readonly signer: X509Certificate;
|
|
73
|
+
} | NotVerified;
|
|
74
|
+
export declare class CoseSign1 {
|
|
75
|
+
/**
|
|
76
|
+
* The serialized protected bucket, exactly as signed and as received: a
|
|
77
|
+
* zero-length byte string when there are no protected header parameters.
|
|
78
|
+
*/
|
|
79
|
+
readonly protectedHeaderBytes: Uint8Array;
|
|
80
|
+
/** The protected header parameters, which the signature covers. */
|
|
81
|
+
readonly protectedHeader: CoseHeaders;
|
|
82
|
+
/**
|
|
83
|
+
* The unprotected header parameters, which the signature does not cover
|
|
84
|
+
* and which therefore must not be trusted after a successful verification.
|
|
85
|
+
*/
|
|
86
|
+
readonly unprotectedHeader: CoseHeaders;
|
|
87
|
+
/** The signed payload, or null when it is detached. */
|
|
88
|
+
readonly payload: Uint8Array | null;
|
|
89
|
+
/** The signature: `r ‖ s`, each half zero-padded, never DER. */
|
|
90
|
+
readonly signature: Uint8Array;
|
|
91
|
+
/**
|
|
92
|
+
* Whether this message is wrapped within CBOR tag 18. The tag is not
|
|
93
|
+
* covered by the signature, but it is preserved so that a parsed message
|
|
94
|
+
* re-encodes to the very same bytes.
|
|
95
|
+
*/
|
|
96
|
+
readonly isTagged: boolean;
|
|
97
|
+
constructor(protectedHeaderBytes: Uint8Array, unprotectedHeader: CoseHeaders | null, payload: Uint8Array | null, signature: Uint8Array, isTagged?: boolean);
|
|
98
|
+
/** Whether the payload is detached. */
|
|
99
|
+
get isDetached(): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* The signature algorithm, taken from the protected bucket and only
|
|
102
|
+
* otherwise from the unprotected one.
|
|
103
|
+
*/
|
|
104
|
+
get algorithm(): CoseAlgorithm | null;
|
|
105
|
+
/** The key identifier, protected bucket first. */
|
|
106
|
+
get keyIdentifier(): Uint8Array | null;
|
|
107
|
+
/**
|
|
108
|
+
* The encoded Sig_structure of a COSE_Sign1 message
|
|
109
|
+
* [RFC 9052, Section 4.4], which is the byte string an ECDSA signer
|
|
110
|
+
* actually signs:
|
|
111
|
+
*
|
|
112
|
+
* <code>
|
|
113
|
+
* Sig_structure = [
|
|
114
|
+
* context : "Signature1",
|
|
115
|
+
* protected : empty_or_serialized_map,
|
|
116
|
+
* external_aad : bstr,
|
|
117
|
+
* payload : bstr
|
|
118
|
+
* ]
|
|
119
|
+
* </code>
|
|
120
|
+
*
|
|
121
|
+
* This is public on purpose. Whenever the signing key does not live in
|
|
122
|
+
* this process — a meter, a smart card, a hardware security module — this
|
|
123
|
+
* is the input to hand over.
|
|
124
|
+
*/
|
|
125
|
+
static toBeSigned(protectedHeaderBytes: Uint8Array, payload: Uint8Array, externalAad?: Uint8Array | null): Uint8Array;
|
|
126
|
+
/** The encoded Sig_structure of this message. */
|
|
127
|
+
toBeSigned(options?: {
|
|
128
|
+
externalAad?: Uint8Array | null;
|
|
129
|
+
detachedPayload?: Uint8Array | null;
|
|
130
|
+
}): Uint8Array;
|
|
131
|
+
/**
|
|
132
|
+
* Sign a payload, placing the algorithm within the protected bucket and
|
|
133
|
+
* the key identifier within the unprotected one — the layout of the
|
|
134
|
+
* examples of RFC 9052 and of virtually every deployed COSE message.
|
|
135
|
+
*/
|
|
136
|
+
static sign(payload: Uint8Array, key: CoseKey, options?: Sign1Options): CoseSign1;
|
|
137
|
+
/**
|
|
138
|
+
* Sign a payload with the algorithm taken from the application context
|
|
139
|
+
* rather than from the message: the protected bucket stays empty and only
|
|
140
|
+
* the key identifier travels.
|
|
141
|
+
*
|
|
142
|
+
* This is the leanest signed COSE message there is, and for a protocol
|
|
143
|
+
* that already agrees on its algorithm it is also the safest arrangement:
|
|
144
|
+
* an algorithm that is not in the message cannot be tampered with on the
|
|
145
|
+
* way, whereas one within the unprotected bucket can. The price is that
|
|
146
|
+
* agility becomes a property of the profile rather than of the message.
|
|
147
|
+
*/
|
|
148
|
+
static signWithApplicationAlgorithm(payload: Uint8Array, key: CoseKey, options?: Sign1Options): CoseSign1;
|
|
149
|
+
/**
|
|
150
|
+
* Sign a payload with full control over both header buckets.
|
|
151
|
+
*
|
|
152
|
+
* The signature algorithm is taken from the protected bucket, because an
|
|
153
|
+
* algorithm that is not covered by the signature could be changed by
|
|
154
|
+
* anyone on the way.
|
|
155
|
+
*/
|
|
156
|
+
static signWithHeaders(payload: Uint8Array, key: CoseKey, protectedHeader: CoseHeaders, unprotectedHeader?: CoseHeaders | null, options?: Sign1Options, applicationAlgorithm?: CoseAlgorithm | null): CoseSign1;
|
|
157
|
+
/**
|
|
158
|
+
* Verify the signature of this message.
|
|
159
|
+
*
|
|
160
|
+
* A failed verification is not an exception — it is the expected outcome
|
|
161
|
+
* of checking untrusted data — so the reason travels in the result.
|
|
162
|
+
*/
|
|
163
|
+
verify(key: CoseKey, options?: VerifyOptions): Verification;
|
|
164
|
+
/**
|
|
165
|
+
* The certificate chain of this message, from either header bucket.
|
|
166
|
+
*
|
|
167
|
+
* A chain that travels in a message is untrusted input, and reading one
|
|
168
|
+
* says nothing at all about it — {@link verifyWithCertificateChain} has to
|
|
169
|
+
* walk it to an anchor first. Throws when the parameter is present but is
|
|
170
|
+
* not a `COSE_X509`, rather than pretending there is none.
|
|
171
|
+
*/
|
|
172
|
+
get certificateChain(): CoseCertificateChain | null;
|
|
173
|
+
/**
|
|
174
|
+
* The certificate thumbprint of this message, from either header bucket.
|
|
175
|
+
*
|
|
176
|
+
* Throws when the parameter is present but is not a `COSE_CertHash`.
|
|
177
|
+
*/
|
|
178
|
+
get certificateThumbprint(): CoseCertificateHash | null;
|
|
179
|
+
/**
|
|
180
|
+
* Verify this message against a certificate chain rather than against a
|
|
181
|
+
* public key somebody handed over: the chain travels within the message,
|
|
182
|
+
* is walked to one of the given trust anchors, and the key of its
|
|
183
|
+
* end-entity certificate is then the key the signature has to verify with.
|
|
184
|
+
*
|
|
185
|
+
* That last step is what turns a chain into an answer. A chain that
|
|
186
|
+
* validates beautifully says nothing whatsoever about the message it
|
|
187
|
+
* arrived with unless the key it ends in is the key that signed, so the
|
|
188
|
+
* two are never checked apart from one another here.
|
|
189
|
+
*
|
|
190
|
+
* The X.509 header parameters become understood *by this call* rather than
|
|
191
|
+
* by the library, which is why a `crit` demanding `x5chain` is accepted
|
|
192
|
+
* here and refused by {@link verify}: whoever verifies with a bare public
|
|
193
|
+
* key has not looked at any certificate and must not claim otherwise.
|
|
194
|
+
*/
|
|
195
|
+
verifyWithCertificateChain(trustAnchors: readonly X509Certificate[], options?: CertificateChainVerifyOptions): CertificateChainVerification;
|
|
196
|
+
/**
|
|
197
|
+
* The countersignatures of this message [RFC 9338], which live in the
|
|
198
|
+
* unprotected bucket under label 11.
|
|
199
|
+
*
|
|
200
|
+
* A message carrying one holds it bare; a message carrying several holds
|
|
201
|
+
* an array of them. The two shapes are told apart by the kind of the first
|
|
202
|
+
* element, because a bare countersignature starts with its protected
|
|
203
|
+
* bucket, a byte string, whereas an array of them starts with an array.
|
|
204
|
+
*/
|
|
205
|
+
get countersignatures(): readonly CoseSignature[];
|
|
206
|
+
/**
|
|
207
|
+
* The encoded Countersign_structure [RFC 9338, Section 3.3].
|
|
208
|
+
*
|
|
209
|
+
* Six elements rather than four, and the difference is not cosmetic. It
|
|
210
|
+
* names the body's protected bucket *and* the countersigner's, and its
|
|
211
|
+
* last element carries the signature being countersigned — which is what
|
|
212
|
+
* makes this "I vouch for that signature" rather than "I signed the same
|
|
213
|
+
* thing". The countersignature of RFC 8152 covered the payload but not the
|
|
214
|
+
* signature, so it never actually attested to having seen it.
|
|
215
|
+
*
|
|
216
|
+
* `other_fields` is an array holding the one signature, not a bare byte
|
|
217
|
+
* string.
|
|
218
|
+
*/
|
|
219
|
+
static toBeCountersigned(bodyProtectedHeaderBytes: Uint8Array, countersignatureProtectedHeaderBytes: Uint8Array, payload: Uint8Array, signature: Uint8Array, externalAad?: Uint8Array | null): Uint8Array;
|
|
220
|
+
/** The encoded Countersign_structure of one countersignature of this message. */
|
|
221
|
+
toBeCountersigned(countersignature: CoseSignature, options?: {
|
|
222
|
+
externalAad?: Uint8Array | null;
|
|
223
|
+
detachedPayload?: Uint8Array | null;
|
|
224
|
+
}): Uint8Array;
|
|
225
|
+
/**
|
|
226
|
+
* Return a copy of this message with one more countersignature.
|
|
227
|
+
*
|
|
228
|
+
* Countersignatures live in the unprotected bucket, which no signature
|
|
229
|
+
* covers, so this leaves the body signature, the protected bucket and the
|
|
230
|
+
* payload byte-identical: the message stays valid for everybody, including
|
|
231
|
+
* readers that ignore label 11 entirely.
|
|
232
|
+
*/
|
|
233
|
+
addCountersignature(key: CoseKey, options?: Sign1Options & {
|
|
234
|
+
detachedPayload?: Uint8Array | null;
|
|
235
|
+
}): CoseSign1;
|
|
236
|
+
/**
|
|
237
|
+
* Verify one countersignature of this message.
|
|
238
|
+
*
|
|
239
|
+
* This says nothing about whether the body signature itself is valid —
|
|
240
|
+
* that is a separate question with a separate key, and answering both at
|
|
241
|
+
* once would hide which of the two failed.
|
|
242
|
+
*/
|
|
243
|
+
verifyCountersignature(countersignature: CoseSignature, key: CoseKey, options?: VerifyOptions): Verification;
|
|
244
|
+
/**
|
|
245
|
+
* Parse a COSE_Sign1 message.
|
|
246
|
+
*
|
|
247
|
+
* Both the tagged and the untagged form are accepted; which one it was is
|
|
248
|
+
* remembered, as the CBOR tag is not covered by the signature but is part
|
|
249
|
+
* of the bytes on the wire.
|
|
250
|
+
*/
|
|
251
|
+
static parse(input: Uint8Array | CborValue): CoseSign1;
|
|
252
|
+
/** A CBOR representation of this message. */
|
|
253
|
+
toCbor(): CborValue;
|
|
254
|
+
/** The CBOR encoding of this message. */
|
|
255
|
+
toBytes(): Uint8Array;
|
|
256
|
+
/**
|
|
257
|
+
* A copy of this message without its payload, e.g. because the payload
|
|
258
|
+
* travels elsewhere.
|
|
259
|
+
*
|
|
260
|
+
* The signature stays valid: it never covered the message, only the
|
|
261
|
+
* Sig_structure.
|
|
262
|
+
*/
|
|
263
|
+
detach(): CoseSign1;
|
|
264
|
+
/** A copy of this message carrying the given payload again. */
|
|
265
|
+
attach(payload: Uint8Array): CoseSign1;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* The last step every verification shares: the arithmetic, and the two ways of
|
|
269
|
+
* failing that are not a wrong signature.
|
|
270
|
+
*/
|
|
271
|
+
declare function verifySignature(algorithm: CoseAlgorithm, key: CoseKey, toBeSigned: Uint8Array, signature: Uint8Array): Verification;
|
|
272
|
+
export { verifySignature };
|
|
273
|
+
//# sourceMappingURL=sign1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign1.d.ts","sourceRoot":"","sources":["../src/sign1.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAqB,gBAAgB,CAAC;AAGnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAyB,WAAW,CAAC;AAE9D,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAS,aAAa,CAAC;AAChE,OAAO,EAAE,WAAW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AA;KAAO,GAAG,UAAU;IAkB3F;;;;;;;OAOG;IACI,mBAAmB,CAAC,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE,YAAY,GAAG;QACpB,eAAe,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;KAAO,GAAG,SAAS;IAkDrF;;;;;;OAMG;IACI,sBAAsB,CAAC,gBAAgB,EAAE,aAAa,EAC/B,GAAG,EAAe,OAAO,EACzB,OAAO,GAAW,aAAkB,GAAG,YAAY;IAsCjF;;;;;;OAMG;WACW,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS;IA8C7D,6CAA6C;IACtC,MAAM,IAAI,SAAS;IAc1B,yCAAyC;IAClC,OAAO,IAAI,UAAU;IAK5B;;;;;;OAMG;IACI,MAAM,IAAI,SAAS;IAM1B,+DAA+D;IACxD,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS;CAUhD;AAGD;;;GAGG;AACH,iBAAS,eAAe,CAAC,SAAS,EAAG,aAAa,EACzB,GAAG,EAAS,OAAO,EACnB,UAAU,EAAE,UAAU,EACtB,SAAS,EAAG,UAAU,GAAG,YAAY,CAoB7D;AAGD,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One signature of a multi-signer message [RFC 9052, Section 4.1], and the
|
|
3
|
+
* very same structure once more as a countersignature [RFC 9338].
|
|
4
|
+
*
|
|
5
|
+
* <code>
|
|
6
|
+
* COSE_Signature = [
|
|
7
|
+
* protected : bstr .cbor header_map,
|
|
8
|
+
* unprotected : header_map,
|
|
9
|
+
* signature : bstr
|
|
10
|
+
* ]
|
|
11
|
+
* </code>
|
|
12
|
+
*
|
|
13
|
+
* It carries header buckets of its own, which is what lets every party sign
|
|
14
|
+
* with its own algorithm and its own key.
|
|
15
|
+
*/
|
|
16
|
+
import type { CoseAlgorithm } from './algorithm.ts';
|
|
17
|
+
import type { CborValue } from './cbor.ts';
|
|
18
|
+
import { CoseHeaders } from './headers.ts';
|
|
19
|
+
export declare class CoseSignature {
|
|
20
|
+
/** The serialized protected bucket, exactly as signed and as received. */
|
|
21
|
+
readonly protectedHeaderBytes: Uint8Array;
|
|
22
|
+
/** The protected header parameters, which this signature covers. */
|
|
23
|
+
readonly protectedHeader: CoseHeaders;
|
|
24
|
+
/** The unprotected header parameters, which it does not. */
|
|
25
|
+
readonly unprotectedHeader: CoseHeaders;
|
|
26
|
+
/** The signature: `r ‖ s`, never DER. */
|
|
27
|
+
readonly signature: Uint8Array;
|
|
28
|
+
constructor(protectedHeaderBytes: Uint8Array, unprotectedHeader: CoseHeaders | null, signature: Uint8Array);
|
|
29
|
+
/**
|
|
30
|
+
* The signature algorithm, taken from the protected bucket and only
|
|
31
|
+
* otherwise from the unprotected one.
|
|
32
|
+
*/
|
|
33
|
+
get algorithm(): CoseAlgorithm | null;
|
|
34
|
+
/** The key identifier, protected bucket first. */
|
|
35
|
+
get keyIdentifier(): Uint8Array | null;
|
|
36
|
+
/** Parse a three-element COSE_Signature. */
|
|
37
|
+
static parse(value: CborValue): CoseSignature;
|
|
38
|
+
/** A CBOR representation of this signature. */
|
|
39
|
+
toCbor(): CborValue;
|
|
40
|
+
/** The CBOR encoding of this signature. */
|
|
41
|
+
toBytes(): Uint8Array;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../src/signature.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAa,gBAAgB,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAiB,WAAW,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAoB,cAAc,CAAC;AAGzD,qBAAa,aAAa;IAEtB,0EAA0E;IAC1E,SAAgB,oBAAoB,EAAG,UAAU,CAAC;IAElD,oEAAoE;IACpE,SAAgB,eAAe,EAAQ,WAAW,CAAC;IAEnD,4DAA4D;IAC5D,SAAgB,iBAAiB,EAAM,WAAW,CAAC;IAEnD,yCAAyC;IACzC,SAAgB,SAAS,EAAc,UAAU,CAAC;gBAG/B,oBAAoB,EAAE,UAAU,EAChC,iBAAiB,EAAK,WAAW,GAAG,IAAI,EACxC,SAAS,EAAa,UAAU;IAUnD;;;OAGG;IACH,IAAW,SAAS,IAAI,aAAa,GAAG,IAAI,CAE3C;IAED,kDAAkD;IAClD,IAAW,aAAa,IAAI,UAAU,GAAG,IAAI,CAE5C;IAGD,4CAA4C;WAC9B,KAAK,CAAC,KAAK,EAAE,SAAS,GAAG,aAAa;IA0BpD,+CAA+C;IACxC,MAAM,IAAI,SAAS;IAW1B,2CAA2C;IACpC,OAAO,IAAI,UAAU;CAI/B"}
|
package/dist/x509.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Asn1Node } from './asn1.ts';
|
|
2
|
+
import type { CoseAlgorithm } from './algorithm.ts';
|
|
3
|
+
import type { CoseCurve } from './curve.ts';
|
|
4
|
+
import type { DigestAlgorithm } from './ecdsa.ts';
|
|
5
|
+
import type { Verification } from './errors.ts';
|
|
6
|
+
import { CoseKey } from './key.ts';
|
|
7
|
+
/** One attribute of a distinguished name. */
|
|
8
|
+
export interface NameAttribute {
|
|
9
|
+
/** The attribute type, in dotted decimal. */
|
|
10
|
+
readonly oid: string;
|
|
11
|
+
/** The attribute value, as text. */
|
|
12
|
+
readonly value: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A distinguished name.
|
|
16
|
+
*
|
|
17
|
+
* Two names are compared the way RFC 5280 Section 7.1 asks for rather than by
|
|
18
|
+
* their encodings: a `PrintableString` and a `UTF8String` holding the same
|
|
19
|
+
* characters name the same entity, and a chain whose issuer field was written
|
|
20
|
+
* in one and whose subject field was written in the other is a chain, not a
|
|
21
|
+
* forgery. Byte equality is still tried first, because it is both cheaper and
|
|
22
|
+
* the case that almost always applies.
|
|
23
|
+
*/
|
|
24
|
+
export declare class X509Name {
|
|
25
|
+
/** The attributes, outermost relative name first, as they were encoded. */
|
|
26
|
+
readonly attributes: readonly NameAttribute[];
|
|
27
|
+
/** The DER encoding, kept because a name is also compared by its bytes. */
|
|
28
|
+
readonly encoded: Uint8Array;
|
|
29
|
+
constructor(attributes: readonly NameAttribute[], encoded: Uint8Array);
|
|
30
|
+
/** Parse an X.501 `Name`, which is a `SEQUENCE OF SET OF` attributes. */
|
|
31
|
+
static parse(node: Asn1Node, what: string): X509Name;
|
|
32
|
+
/**
|
|
33
|
+
* Whether this name and the given one name the same entity.
|
|
34
|
+
*
|
|
35
|
+
* The normalization is the practical part of RFC 4518: leading and
|
|
36
|
+
* trailing whitespace removed, internal runs collapsed to one space, and
|
|
37
|
+
* case folded. Not implemented, because no certificate in this project's
|
|
38
|
+
* world uses them: the Unicode mapping and prohibition tables.
|
|
39
|
+
*/
|
|
40
|
+
equivalentTo(other: X509Name): boolean;
|
|
41
|
+
/** The name in the usual `CN=…,O=…` notation. */
|
|
42
|
+
toString(): string;
|
|
43
|
+
}
|
|
44
|
+
/** The `basicConstraints` extension [RFC 5280, Section 4.2.1.9]. */
|
|
45
|
+
export interface BasicConstraints {
|
|
46
|
+
/** Whether the certified key may sign other certificates. */
|
|
47
|
+
readonly certificateAuthority: boolean;
|
|
48
|
+
/** How many intermediates may follow, when the extension says. */
|
|
49
|
+
readonly pathLength: number | null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The bits of the `keyUsage` extension [RFC 5280, Section 4.2.1.3], by name.
|
|
53
|
+
*
|
|
54
|
+
* The order is the ASN.1 one and it is load bearing: `digitalSignature` is bit
|
|
55
|
+
* zero and `keyCertSign` bit five, and those two are the only ones a signature
|
|
56
|
+
* with a certificate chain turns on.
|
|
57
|
+
*/
|
|
58
|
+
export declare const KeyUsage: {
|
|
59
|
+
readonly digitalSignature: 0;
|
|
60
|
+
readonly nonRepudiation: 1;
|
|
61
|
+
readonly keyEncipherment: 2;
|
|
62
|
+
readonly dataEncipherment: 3;
|
|
63
|
+
readonly keyAgreement: 4;
|
|
64
|
+
readonly keyCertSign: 5;
|
|
65
|
+
readonly cRLSign: 6;
|
|
66
|
+
readonly encipherOnly: 7;
|
|
67
|
+
readonly decipherOnly: 8;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* An X.509 certificate.
|
|
71
|
+
*
|
|
72
|
+
* Everything here is what the certificate *says*. None of it is a reason to
|
|
73
|
+
* believe any of it: that comes from a chain to an anchor, which is
|
|
74
|
+
* `CoseCertificateChain`'s business.
|
|
75
|
+
*/
|
|
76
|
+
export declare class X509Certificate {
|
|
77
|
+
/** The DER encoding, exactly as it arrived. */
|
|
78
|
+
readonly encoded: Uint8Array;
|
|
79
|
+
/** The `tbsCertificate`, which is the part the signature covers. */
|
|
80
|
+
readonly tbsBytes: Uint8Array;
|
|
81
|
+
/** The version, 1 to 3. */
|
|
82
|
+
readonly version: number;
|
|
83
|
+
/** The serial number, which may be negative and is often very large. */
|
|
84
|
+
readonly serialNumber: bigint;
|
|
85
|
+
/** Who issued this certificate. */
|
|
86
|
+
readonly issuer: X509Name;
|
|
87
|
+
/** Whom it was issued to. */
|
|
88
|
+
readonly subject: X509Name;
|
|
89
|
+
/** The start of the validity period, inclusive. */
|
|
90
|
+
readonly notBefore: Date;
|
|
91
|
+
/** The end of the validity period, inclusive. */
|
|
92
|
+
readonly notAfter: Date;
|
|
93
|
+
/** The certified public key. */
|
|
94
|
+
readonly publicKey: CoseKey;
|
|
95
|
+
/** How this certificate was signed, as the COSE algorithm it corresponds to. */
|
|
96
|
+
readonly signatureAlgorithm: CoseAlgorithm;
|
|
97
|
+
/** The signature, as it was encoded — DER for ECDSA, raw otherwise. */
|
|
98
|
+
readonly signatureValue: Uint8Array;
|
|
99
|
+
/** The `basicConstraints` extension, when present. */
|
|
100
|
+
readonly basicConstraints: BasicConstraints | null;
|
|
101
|
+
/** The `keyUsage` extension as a bit array, when present. */
|
|
102
|
+
readonly keyUsage: readonly boolean[] | null;
|
|
103
|
+
/** The object identifiers of every extension marked critical. */
|
|
104
|
+
readonly criticalExtensions: readonly string[];
|
|
105
|
+
private constructor();
|
|
106
|
+
/**
|
|
107
|
+
* Parse a DER encoded certificate.
|
|
108
|
+
*
|
|
109
|
+
* The `signatureAlgorithm` of the outer structure and the `signature`
|
|
110
|
+
* field inside the `tbsCertificate` must agree, and it is checked: they
|
|
111
|
+
* are the same statement written twice, and an implementation that reads
|
|
112
|
+
* one while verifying with the other can be told two different things at
|
|
113
|
+
* once.
|
|
114
|
+
*/
|
|
115
|
+
static parse(der: Uint8Array): X509Certificate;
|
|
116
|
+
/** Whether this certificate is within its validity period at the given instant. */
|
|
117
|
+
isValidAt(at: Date): Verification;
|
|
118
|
+
/** Whether the given key usage bit is set, an absent extension meaning unrestricted. */
|
|
119
|
+
allows(usage: number): boolean;
|
|
120
|
+
/** Whether the certified key may sign other certificates. */
|
|
121
|
+
get isCertificateAuthority(): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Whether this certificate was signed by the given one.
|
|
124
|
+
*
|
|
125
|
+
* Both halves are checked and neither implies the other: the issuer field
|
|
126
|
+
* has to name the candidate's subject, and the signature has to verify
|
|
127
|
+
* with the candidate's key. A name that matches without a signature is a
|
|
128
|
+
* claim, and a signature that verifies under a different name is somebody
|
|
129
|
+
* else's certificate.
|
|
130
|
+
*/
|
|
131
|
+
verifySignedBy(issuer: X509Certificate): Verification;
|
|
132
|
+
/** The hash of this certificate's DER encoding, which is what `x5t` carries. */
|
|
133
|
+
thumbprint(hash?: DigestAlgorithm): Uint8Array;
|
|
134
|
+
/** Whether this is byte for byte the same certificate as the given one. */
|
|
135
|
+
equals(other: X509Certificate): boolean;
|
|
136
|
+
toString(): string;
|
|
137
|
+
}
|
|
138
|
+
/** The COSE algorithm a certificate signature identifier corresponds to. */
|
|
139
|
+
export declare const signatureAlgorithmByOid: (oid: string) => CoseAlgorithm | null;
|
|
140
|
+
/** The curve a `SubjectPublicKeyInfo` identifier names. */
|
|
141
|
+
export declare const curveByOid: (oid: string) => CoseCurve | null;
|
|
142
|
+
/** The object identifier of a curve, which is the inverse of {@link curveByOid}. */
|
|
143
|
+
export declare function oidOfCurve(curve: CoseCurve): string | null;
|
|
144
|
+
//# sourceMappingURL=x509.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x509.d.ts","sourceRoot":"","sources":["../src/x509.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAuB,WAAW,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAkB,gBAAgB,CAAC;AAEhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAsB,YAAY,CAAC;AAE5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAgB,YAAY,CAAC;AAG5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAmB,aAAa,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAA6B,UAAU,CAAC;AAyE1D,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAE1B,6CAA6C;IAC7C,QAAQ,CAAC,GAAG,EAAK,MAAM,CAAC;IAExB,oCAAoC;IACpC,QAAQ,CAAC,KAAK,EAAG,MAAM,CAAC;CAE3B;AAGD;;;;;;;;;GASG;AACH,qBAAa,QAAQ;IAEjB,2EAA2E;IAC3E,SAAgB,UAAU,EAAG,SAAS,aAAa,EAAE,CAAC;IAEtD,2EAA2E;IAC3E,SAAgB,OAAO,EAAM,UAAU,CAAC;gBAGrB,UAAU,EAAE,SAAS,aAAa,EAAE,EAAE,OAAO,EAAE,UAAU;IAM5E,yEAAyE;WAC3D,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ;IA6B3D;;;;;;;OAOG;IACI,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG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