@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,137 @@
|
|
|
1
|
+
import type { CborValue } from './cbor.ts';
|
|
2
|
+
import type { CoseCurve } from './curve.ts';
|
|
3
|
+
import type { DigestAlgorithm } from './ecdsa.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Which machinery an algorithm needs.
|
|
6
|
+
*
|
|
7
|
+
* The distinction that earns its place here is `ecdsa` against the other two:
|
|
8
|
+
* ECDSA signs a *digest* of the message, chosen by the algorithm, while EdDSA
|
|
9
|
+
* and ML-DSA are pure and take the message itself. Handing a pure signer a
|
|
10
|
+
* digest produces a signature that is valid for the digest and that nobody
|
|
11
|
+
* else will ever accept — a failure with no symptom until the day two
|
|
12
|
+
* implementations meet.
|
|
13
|
+
*/
|
|
14
|
+
export type AlgorithmFamily = 'ecdsa' | 'eddsa' | 'mldsa' | 'hmac' | 'aesgcm' | 'keywrap' | 'direct' | 'none';
|
|
15
|
+
/** An algorithm in the COSE registry. */
|
|
16
|
+
export interface CoseAlgorithm {
|
|
17
|
+
/** The IANA identifier, as it travels in the `alg` header parameter. */
|
|
18
|
+
readonly id: number;
|
|
19
|
+
/** The registered name, e.g. `ES256`. Case sensitive. */
|
|
20
|
+
readonly name: string;
|
|
21
|
+
/** The registered description. */
|
|
22
|
+
readonly description: string;
|
|
23
|
+
/** Which signature machinery this needs. */
|
|
24
|
+
readonly family: AlgorithmFamily;
|
|
25
|
+
/** The message digest, or null for a pure scheme that defines none. */
|
|
26
|
+
readonly hash: DigestAlgorithm | null;
|
|
27
|
+
/** The curve this algorithm is defined on, or null when it leaves it to the key. */
|
|
28
|
+
readonly curve: CoseCurve | null;
|
|
29
|
+
/** The ML-DSA parameter set, or null for everything else. */
|
|
30
|
+
readonly parameterSet: string | null;
|
|
31
|
+
/**
|
|
32
|
+
* The width of the authentication tag in bytes, for a MAC algorithm.
|
|
33
|
+
*
|
|
34
|
+
* It is part of the identifier rather than a parameter: `HMAC 256/64` and
|
|
35
|
+
* `HMAC 256/256` are two registered algorithms over the same hash, and a
|
|
36
|
+
* verifier learns which width to expect from the message.
|
|
37
|
+
*/
|
|
38
|
+
readonly tagSize: number | null;
|
|
39
|
+
/**
|
|
40
|
+
* The width of the key in bytes, for an algorithm that fixes one.
|
|
41
|
+
*
|
|
42
|
+
* AES algorithms do: `A128GCM` and `A256GCM` are two registered identifiers
|
|
43
|
+
* over one cipher, and the width is what tells them apart. The signature
|
|
44
|
+
* algorithms leave it to the curve or to the parameter set.
|
|
45
|
+
*/
|
|
46
|
+
readonly keySize: number | null;
|
|
47
|
+
/** Whether this implementation can sign and verify with it. */
|
|
48
|
+
readonly signing: boolean;
|
|
49
|
+
/** Whether the registry marks it deprecated. */
|
|
50
|
+
readonly deprecated: boolean;
|
|
51
|
+
}
|
|
52
|
+
/** The algorithms this implementation knows by name. */
|
|
53
|
+
export declare const CoseAlgorithms: {
|
|
54
|
+
readonly ES256: CoseAlgorithm;
|
|
55
|
+
readonly ES384: CoseAlgorithm;
|
|
56
|
+
readonly ES512: CoseAlgorithm;
|
|
57
|
+
readonly ES256K: CoseAlgorithm;
|
|
58
|
+
readonly ESP256: CoseAlgorithm;
|
|
59
|
+
readonly ESP384: CoseAlgorithm;
|
|
60
|
+
readonly ESP512: CoseAlgorithm;
|
|
61
|
+
readonly ESB256: CoseAlgorithm;
|
|
62
|
+
readonly ESB320: CoseAlgorithm;
|
|
63
|
+
readonly ESB384: CoseAlgorithm;
|
|
64
|
+
readonly ESB512: CoseAlgorithm;
|
|
65
|
+
readonly EdDSA: CoseAlgorithm;
|
|
66
|
+
readonly Ed25519: CoseAlgorithm;
|
|
67
|
+
readonly Ed448: CoseAlgorithm;
|
|
68
|
+
readonly MLDSA44: CoseAlgorithm;
|
|
69
|
+
readonly MLDSA65: CoseAlgorithm;
|
|
70
|
+
readonly MLDSA87: CoseAlgorithm;
|
|
71
|
+
readonly HMAC256_64: CoseAlgorithm;
|
|
72
|
+
readonly HMAC256_256: CoseAlgorithm;
|
|
73
|
+
readonly HMAC384_384: CoseAlgorithm;
|
|
74
|
+
readonly HMAC512_512: CoseAlgorithm;
|
|
75
|
+
readonly A128GCM: CoseAlgorithm;
|
|
76
|
+
readonly A192GCM: CoseAlgorithm;
|
|
77
|
+
readonly A256GCM: CoseAlgorithm;
|
|
78
|
+
readonly A128KW: CoseAlgorithm;
|
|
79
|
+
readonly A192KW: CoseAlgorithm;
|
|
80
|
+
readonly A256KW: CoseAlgorithm;
|
|
81
|
+
readonly direct: CoseAlgorithm;
|
|
82
|
+
readonly SHA256: CoseAlgorithm;
|
|
83
|
+
readonly SHA384: CoseAlgorithm;
|
|
84
|
+
readonly SHA512: CoseAlgorithm;
|
|
85
|
+
readonly SHA1: CoseAlgorithm;
|
|
86
|
+
};
|
|
87
|
+
/** Every registered algorithm, in registry order. */
|
|
88
|
+
export declare const ALL_ALGORITHMS: readonly CoseAlgorithm[];
|
|
89
|
+
/** The algorithm with the given identifier, or null when it is not registered. */
|
|
90
|
+
export declare function algorithmById(id: number): CoseAlgorithm | null;
|
|
91
|
+
/** The algorithm with the given name, or null. Case sensitive. */
|
|
92
|
+
export declare function algorithmByName(name: string): CoseAlgorithm | null;
|
|
93
|
+
/**
|
|
94
|
+
* The algorithm a header parameter names.
|
|
95
|
+
*
|
|
96
|
+
* An unregistered identifier is not an error here. A message that names an
|
|
97
|
+
* algorithm nobody knows is still worth reading — its headers, its key
|
|
98
|
+
* identifier and its payload are all inspectable — and it fails at the point
|
|
99
|
+
* where it would have to be verified, where the failure means something.
|
|
100
|
+
*/
|
|
101
|
+
export declare function algorithmFromCbor(value: CborValue): CoseAlgorithm;
|
|
102
|
+
/** The header parameter value naming this algorithm. */
|
|
103
|
+
export declare const algorithmToCbor: (value: CoseAlgorithm) => CborValue;
|
|
104
|
+
/** Whether two algorithms are the same algorithm. */
|
|
105
|
+
export declare const sameAlgorithm: (left: CoseAlgorithm, right: CoseAlgorithm) => boolean;
|
|
106
|
+
/**
|
|
107
|
+
* The curve a signature with this algorithm runs on.
|
|
108
|
+
*
|
|
109
|
+
* A fully-specified algorithm names it, and then the key has to agree; the
|
|
110
|
+
* three older ones leave it to the key entirely. Checking the agreement is
|
|
111
|
+
* what stops a `ESP256` message from being verified with a P-384 key, which no
|
|
112
|
+
* amount of correct arithmetic further down would catch.
|
|
113
|
+
*/
|
|
114
|
+
export declare function resolveCurve(value: CoseAlgorithm, keyCurve: CoseCurve | null): CoseCurve;
|
|
115
|
+
/**
|
|
116
|
+
* Sign the Sig_structure of a message with the given algorithm.
|
|
117
|
+
*
|
|
118
|
+
* Note which of the three branches hashes and which do not. ECDSA signs a
|
|
119
|
+
* digest of the Sig_structure; EdDSA and ML-DSA sign the Sig_structure itself.
|
|
120
|
+
* Getting that backwards yields a signature that verifies against nothing but
|
|
121
|
+
* an implementation making the same mistake.
|
|
122
|
+
*/
|
|
123
|
+
export declare function signWith(value: CoseAlgorithm, keyCurve: CoseCurve | null, toBeSigned: Uint8Array, privateKey: Uint8Array): Uint8Array;
|
|
124
|
+
/**
|
|
125
|
+
* The authentication tag of a MAC_structure.
|
|
126
|
+
*
|
|
127
|
+
* Deliberately *not* reachable through {@link signWith}: a MAC is not a
|
|
128
|
+
* signature with a shorter key, and an API that let one stand in for the other
|
|
129
|
+
* would let a caller believe a message was signed when it was merely
|
|
130
|
+
* authenticated between two parties who share a secret.
|
|
131
|
+
*/
|
|
132
|
+
export declare function macWith(value: CoseAlgorithm, toBeMaced: Uint8Array, key: Uint8Array): Uint8Array;
|
|
133
|
+
/** Whether an authentication tag is the right one, compared in constant time. */
|
|
134
|
+
export declare function verifyMacWith(value: CoseAlgorithm, toBeMaced: Uint8Array, tag: Uint8Array, key: Uint8Array): boolean;
|
|
135
|
+
/** Verify a signature over the Sig_structure of a message. */
|
|
136
|
+
export declare function verifyWith(value: CoseAlgorithm, keyCurve: CoseCurve | null, toBeSigned: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean;
|
|
137
|
+
//# sourceMappingURL=algorithm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"algorithm.d.ts","sourceRoot":"","sources":["../src/algorithm.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAqB,WAAW,CAAC;AAE1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAqB,YAAY,CAAC;AAE3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAe,YAAY,CAAC;AAM3D;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GACpC,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;AAGvE,yCAAyC;AACzC,MAAM,WAAW,aAAa;IAE1B,wEAAwE;IACxE,QAAQ,CAAC,EAAE,EAAY,MAAM,CAAC;IAE9B,yDAAyD;IACzD,QAAQ,CAAC,IAAI,EAAU,MAAM,CAAC;IAE9B,kCAAkC;IAClC,QAAQ,CAAC,WAAW,EAAG,MAAM,CAAC;IAE9B,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAQ,eAAe,CAAC;IAEvC,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAU,eAAe,GAAG,IAAI,CAAC;IAE9C,oFAAoF;IACpF,QAAQ,CAAC,KAAK,EAAS,SAAS,GAAG,IAAI,CAAC;IAExC,6DAA6D;IAC7D,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAErC;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAO,MAAM,GAAG,IAAI,CAAC;IAErC;;;;;;OAMG;IACH,QAAQ,CAAC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AO,aAAa,EACzB,SAAS,EAAG,UAAU,EACtB,GAAG,EAAS,UAAU,EACtB,GAAG,EAAS,UAAU,GAAG,OAAO,CAI7D;AAaD,8DAA8D;AAC9D,wBAAgB,UAAU,CAAC,KAAK,EAAQ,aAAa,EAC1B,QAAQ,EAAK,SAAS,GAAG,IAAI,EAC7B,UAAU,EAAG,UAAU,EACvB,SAAS,EAAI,UAAU,EACvB,SAAS,EAAI,UAAU,GAAG,OAAO,CAqB3D"}
|
package/dist/asn1.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** The universal ASN.1 tags this package meets. */
|
|
2
|
+
export declare const Tag: {
|
|
3
|
+
readonly boolean: 1;
|
|
4
|
+
readonly integer: 2;
|
|
5
|
+
readonly bitString: 3;
|
|
6
|
+
readonly octetString: 4;
|
|
7
|
+
readonly null: 5;
|
|
8
|
+
readonly objectIdentifier: 6;
|
|
9
|
+
readonly utf8String: 12;
|
|
10
|
+
readonly printableString: 19;
|
|
11
|
+
readonly teletexString: 20;
|
|
12
|
+
readonly ia5String: 22;
|
|
13
|
+
readonly utcTime: 23;
|
|
14
|
+
readonly generalizedTime: 24;
|
|
15
|
+
readonly bmpString: 30;
|
|
16
|
+
readonly universalString: 28;
|
|
17
|
+
readonly sequence: 48;
|
|
18
|
+
readonly set: 49;
|
|
19
|
+
};
|
|
20
|
+
/** A context-specific constructed tag, e.g. `[0]` is `contextTag(0)`. */
|
|
21
|
+
export declare const contextTag: (number: number) => number;
|
|
22
|
+
/**
|
|
23
|
+
* One tag-length-value record.
|
|
24
|
+
*
|
|
25
|
+
* `content` is the value octets and `encoded` the whole record — identifier,
|
|
26
|
+
* length and value. Both matter: the content is what a field says, the
|
|
27
|
+
* encoding is what a signature covers.
|
|
28
|
+
*/
|
|
29
|
+
export interface Asn1Node {
|
|
30
|
+
/** The identifier octet. */
|
|
31
|
+
readonly tag: number;
|
|
32
|
+
/** The value octets, without identifier or length. */
|
|
33
|
+
readonly content: Uint8Array;
|
|
34
|
+
/** The complete record, exactly as it appeared. */
|
|
35
|
+
readonly encoded: Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A cursor over a sequence of DER records.
|
|
39
|
+
*
|
|
40
|
+
* The `what` is carried only so that a failure can say which structure was
|
|
41
|
+
* being read; a message naming a byte offset and nothing else is a message
|
|
42
|
+
* that has to be debugged rather than read.
|
|
43
|
+
*/
|
|
44
|
+
export declare class DerReader {
|
|
45
|
+
private readonly data;
|
|
46
|
+
private readonly what;
|
|
47
|
+
private at;
|
|
48
|
+
constructor(data: Uint8Array, what: string);
|
|
49
|
+
/** Whether every record has been read. */
|
|
50
|
+
get atEnd(): boolean;
|
|
51
|
+
/** The octets not yet read. */
|
|
52
|
+
get remaining(): Uint8Array;
|
|
53
|
+
private fail;
|
|
54
|
+
/**
|
|
55
|
+
* Read the next record, optionally insisting on a tag.
|
|
56
|
+
*
|
|
57
|
+
* The length rules are DER's: definite always, short form below 128,
|
|
58
|
+
* long form minimally encoded and never longer than eight octets — which
|
|
59
|
+
* is far more than a certificate can need and still shorter than the point
|
|
60
|
+
* where a length stops fitting a JavaScript number.
|
|
61
|
+
*/
|
|
62
|
+
read(expectedTag?: number): Asn1Node;
|
|
63
|
+
/** Read the next record when it carries the given tag, else read nothing. */
|
|
64
|
+
readOptional(tag: number): Asn1Node | null;
|
|
65
|
+
/** Whether a record with the given tag comes next. */
|
|
66
|
+
peekIs(tag: number): boolean;
|
|
67
|
+
/** Insist that nothing follows, which is how trailing data is caught. */
|
|
68
|
+
expectEnd(): void;
|
|
69
|
+
}
|
|
70
|
+
/** A cursor over the contents of a constructed record. */
|
|
71
|
+
export declare const contentsOf: (node: Asn1Node, what: string) => DerReader;
|
|
72
|
+
/**
|
|
73
|
+
* A DER INTEGER as a bigint, two's complement and minimally encoded.
|
|
74
|
+
*
|
|
75
|
+
* Certificates hold signed integers here — a serial number is defined as one
|
|
76
|
+
* — so a leading 0x00 before a high bit is padding and a leading 0x00 before
|
|
77
|
+
* anything else is a violation.
|
|
78
|
+
*/
|
|
79
|
+
export declare function derInteger(node: Asn1Node, what: string): bigint;
|
|
80
|
+
/**
|
|
81
|
+
* A DER BIT STRING, as whole octets.
|
|
82
|
+
*
|
|
83
|
+
* Every bit string a certificate carries a key or a signature in is octet
|
|
84
|
+
* aligned, so an unused-bit count other than zero is refused rather than
|
|
85
|
+
* shifted — `keyUsage` is the one exception and reads the count itself.
|
|
86
|
+
*/
|
|
87
|
+
export declare function derBitString(node: Asn1Node, what: string): Uint8Array;
|
|
88
|
+
/** A DER BIT STRING with its unused-bit count, which `keyUsage` needs. */
|
|
89
|
+
export declare function derBitStringRaw(node: Asn1Node, what: string): {
|
|
90
|
+
unusedBits: number;
|
|
91
|
+
bytes: Uint8Array;
|
|
92
|
+
};
|
|
93
|
+
/** A DER BOOLEAN. DER admits exactly two encodings, and 0x01 is not one of them. */
|
|
94
|
+
export declare function derBoolean(node: Asn1Node, what: string): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* A DER OBJECT IDENTIFIER, in dotted decimal.
|
|
97
|
+
*
|
|
98
|
+
* The first two arcs share one octet — `40·first + second` — which is why
|
|
99
|
+
* `2.16.840…` and `1.2.840…` both begin with a byte in the eighties, and why
|
|
100
|
+
* the first arc is recovered by division rather than by lookup.
|
|
101
|
+
*/
|
|
102
|
+
export declare function derObjectIdentifier(node: Asn1Node, what: string): string;
|
|
103
|
+
/** A DER string, in whichever of the X.509 string types it was written. */
|
|
104
|
+
export declare function derString(node: Asn1Node, what: string): string;
|
|
105
|
+
/**
|
|
106
|
+
* A DER UTCTime or GeneralizedTime.
|
|
107
|
+
*
|
|
108
|
+
* DER admits exactly one form of each: seconds present, no fractional part,
|
|
109
|
+
* and Zulu — so anything else is refused rather than guessed at. The
|
|
110
|
+
* two-digit year of a UTCTime is windowed as RFC 5280 Section 4.1.2.5.1
|
|
111
|
+
* requires, 50 and above being the twentieth century.
|
|
112
|
+
*/
|
|
113
|
+
export declare function derTime(node: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tC;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAsB/D;AAGD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CASrE;AAGD,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAevG;AAGD,oFAAoF;AACpF,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAahE;AAGD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAoDxE;AAGD,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA2B9D;AAkCD;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAmC1D"}
|
package/dist/cbor.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one seam between this COSE implementation and a CBOR codec.
|
|
3
|
+
*
|
|
4
|
+
* COSE is a thin layer over CBOR, and everything delicate about it is a
|
|
5
|
+
* question of exact bytes: what a signature covers, whether an empty protected
|
|
6
|
+
* bucket is `h''` or `h'A0'`, whether a map keeps the order it arrived in.
|
|
7
|
+
* Keeping the codec behind a single module means those questions are answered
|
|
8
|
+
* in one place — and it means where the codec comes from is one line rather
|
|
9
|
+
* than a hundred imports.
|
|
10
|
+
*
|
|
11
|
+
* That line names the published `@vanaheimr/metrological-cbor`, an ordinary
|
|
12
|
+
* dependency pinned by the lock file. It was a sibling checkout until the
|
|
13
|
+
* codec's first release; the one arrangement that still builds both sides
|
|
14
|
+
* from source is the cross-signing conformance suite, whose job is exactly
|
|
15
|
+
* that — what it signs has to be what the codec produces *today* — and which
|
|
16
|
+
* has its own repository and its own checkout layout for it. Here, drift
|
|
17
|
+
* arrives the way it does for every consumer: as a release, which the nightly
|
|
18
|
+
* installs the day it appears.
|
|
19
|
+
*
|
|
20
|
+
* The codec is the one from Metrological CBOR, which is a deterministic
|
|
21
|
+
* encoder by default — and that default is wrong here. A COSE message is
|
|
22
|
+
* somebody else's bytes: its header maps are in the order the signer wrote
|
|
23
|
+
* them, and re-sorting them on the way out would invalidate signatures this
|
|
24
|
+
* implementation never touched. Every encode below therefore passes
|
|
25
|
+
* `PRESERVE`, and the one place that does not is the RFC 9679 thumbprint,
|
|
26
|
+
* where deterministic encoding is what the specification asks for.
|
|
27
|
+
*/
|
|
28
|
+
export { cbor } from '@vanaheimr/metrological-cbor';
|
|
29
|
+
export type { CborValue } from '@vanaheimr/metrological-cbor';
|
|
30
|
+
import type { CborValue } from '@vanaheimr/metrological-cbor';
|
|
31
|
+
/** One entry of a CBOR map. */
|
|
32
|
+
export type CborEntry = readonly [CborValue, CborValue];
|
|
33
|
+
/**
|
|
34
|
+
* Encoder options for reproducing foreign bytes: no sorting, no float
|
|
35
|
+
* re-widening. What was read is what is written.
|
|
36
|
+
*/
|
|
37
|
+
export declare const PRESERVE: {
|
|
38
|
+
readonly mapKeys: "preserve";
|
|
39
|
+
readonly floats: "preserve";
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Encoder options for the deterministic encoding of RFC 8949 Section 4.2.1,
|
|
43
|
+
* which RFC 9679 requires for a COSE Key Thumbprint.
|
|
44
|
+
*/
|
|
45
|
+
export declare const DETERMINISTIC: {
|
|
46
|
+
readonly mapKeys: "sorted";
|
|
47
|
+
readonly floats: "shortest";
|
|
48
|
+
};
|
|
49
|
+
/** Encode a value as the bytes of a COSE message or structure. */
|
|
50
|
+
export declare const encode: (value: CborValue) => Uint8Array;
|
|
51
|
+
/**
|
|
52
|
+
* Decode the bytes of a COSE message.
|
|
53
|
+
*
|
|
54
|
+
* Deliberately not in strict mode: a COSE message arrives from the wire and
|
|
55
|
+
* has to be read as it is. Rejecting a message because its unprotected bucket
|
|
56
|
+
* is not in deterministic order would refuse messages that are perfectly valid
|
|
57
|
+
* COSE — and would refuse them *after* the signature over the protected part
|
|
58
|
+
* would have verified.
|
|
59
|
+
*/
|
|
60
|
+
export declare const decode: (data: Uint8Array) => CborValue;
|
|
61
|
+
/** Whether two byte strings are equal. */
|
|
62
|
+
export declare function bytesEqual(left: Uint8Array, right: Uint8Array): boolean;
|
|
63
|
+
/** The empty byte string, which COSE uses rather more often than one expects. */
|
|
64
|
+
export declare const NO_BYTES: Uint8Array<ArrayBuffer>;
|
|
65
|
+
//# sourceMappingURL=cbor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cbor.d.ts","sourceRoot":"","sources":["../src/cbor.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAa,8BAA8B,CAAC;AAC3D,YAAY,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAG9D,+BAA+B;AAC/B,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAGxD;;;GAGG;AACH,eAAO,MAAM,QAAQ;;;CAAuD,CAAC;AAG7E;;;GAGG;AACH,eAAO,MAAM,aAAa;;;CAAqD,CAAC;AAGhF,kEAAkE;AAClE,eAAO,MAAM,MAAM,GAAI,OAAO,SAAS,KAAG,UACV,CAAC;AAGjC;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,GAAI,MAAM,UAAU,KAAG,SACF,CAAC;AAGzC,0CAA0C;AAC1C,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAYvE;AAGD,iFAAiF;AACjF,eAAO,MAAM,QAAQ,yBAAmB,CAAC"}
|
package/dist/curve.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The COSE elliptic curve registry [IANA, "COSE Elliptic Curves"].
|
|
3
|
+
*
|
|
4
|
+
* Two widths are recorded per curve and they are kept apart on purpose: the
|
|
5
|
+
* *field* size is the width of a coordinate, the *order* size is the width of
|
|
6
|
+
* a private key and of each half of an ECDSA signature. They coincide for
|
|
7
|
+
* every curve in this registry, and they are still two different quantities —
|
|
8
|
+
* a curve where they differ would silently produce keys other implementations
|
|
9
|
+
* reject.
|
|
10
|
+
*
|
|
11
|
+
* P-521 is 66 bytes, not 64 and not 65. Its field is 521 bits wide, which is
|
|
12
|
+
* 65 bytes and one bit.
|
|
13
|
+
*/
|
|
14
|
+
/** A curve in the COSE registry. */
|
|
15
|
+
export interface CoseCurve {
|
|
16
|
+
/** The IANA identifier, as it travels in a COSE key. */
|
|
17
|
+
readonly id: number;
|
|
18
|
+
/** The registered name, e.g. `P-256`. Case sensitive. */
|
|
19
|
+
readonly name: string;
|
|
20
|
+
/** The key type this curve belongs to: 2 = EC2, 1 = OKP. */
|
|
21
|
+
readonly keyType: number;
|
|
22
|
+
/**
|
|
23
|
+
* On an EC2 curve, the width of one coordinate. On an OKP curve, the width
|
|
24
|
+
* of the public key, which is the whole of `x` — there is no `y`.
|
|
25
|
+
*/
|
|
26
|
+
readonly fieldSize: number | null;
|
|
27
|
+
/**
|
|
28
|
+
* On an EC2 curve, the width of a private key and of each half of a
|
|
29
|
+
* signature. On an OKP curve, the width of the private key.
|
|
30
|
+
*
|
|
31
|
+
* Ed448 is 57 bytes and not 56: RFC 8032 appends a sign bit to the 456-bit
|
|
32
|
+
* encoding, which costs a whole further octet.
|
|
33
|
+
*/
|
|
34
|
+
readonly orderSize: number | null;
|
|
35
|
+
}
|
|
36
|
+
/** Key type 2, elliptic curve keys with x and y coordinates [RFC 9052, Section 7]. */
|
|
37
|
+
export declare const KEY_TYPE_EC2 = 2;
|
|
38
|
+
/** Key type 1, octet key pairs [RFC 9052, Section 7]. */
|
|
39
|
+
export declare const KEY_TYPE_OKP = 1;
|
|
40
|
+
/** The curves this implementation knows by name. */
|
|
41
|
+
export declare const CoseCurves: {
|
|
42
|
+
readonly P256: CoseCurve;
|
|
43
|
+
readonly P384: CoseCurve;
|
|
44
|
+
readonly P521: CoseCurve;
|
|
45
|
+
readonly X25519: CoseCurve;
|
|
46
|
+
readonly X448: CoseCurve;
|
|
47
|
+
readonly Ed25519: CoseCurve;
|
|
48
|
+
readonly Ed448: CoseCurve;
|
|
49
|
+
readonly secp256k1: CoseCurve;
|
|
50
|
+
readonly brainpoolP256r1: CoseCurve;
|
|
51
|
+
readonly brainpoolP320r1: CoseCurve;
|
|
52
|
+
readonly brainpoolP384r1: CoseCurve;
|
|
53
|
+
readonly brainpoolP512r1: CoseCurve;
|
|
54
|
+
};
|
|
55
|
+
/** Every registered curve, in registry order. */
|
|
56
|
+
export declare const ALL_CURVES: readonly CoseCurve[];
|
|
57
|
+
/** The curve with the given identifier, or null when it is not registered. */
|
|
58
|
+
export declare function curveById(id: number): CoseCurve | null;
|
|
59
|
+
/**
|
|
60
|
+
* The curve with the given name, or null.
|
|
61
|
+
*
|
|
62
|
+
* Case sensitive, like the registry: `p-256` is not `P-256`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function curveByName(name: string): CoseCurve | null;
|
|
65
|
+
//# sourceMappingURL=curve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curve.d.ts","sourceRoot":"","sources":["../src/curve.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;GAYG;AAGH,oCAAoC;AACpC,MAAM,WAAW,SAAS;IAEtB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,EAAW,MAAM,CAAC;IAE7B,yDAAyD;IACzD,QAAQ,CAAC,IAAI,EAAS,MAAM,CAAC;IAE7B,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAM,MAAM,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAI,MAAM,GAAG,IAAI,CAAC;IAEpC;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAI,MAAM,GAAG,IAAI,CAAC;CAEvC;AAQD,sFAAsF;AACtF,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B,yDAAyD;AACzD,eAAO,MAAM,YAAY,IAAI,CAAC;AAG9B,oDAAoD;AACpD,eAAO,MAAM,UAAU;;;;;;;;;;;;;CAoBb,CAAC;AAGX,iDAAiD;AACjD,eAAO,MAAM,UAAU,EAAE,SAAS,SAAS,EAA8B,CAAC;AAG1E,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAEtD;AAGD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAE1D"}
|
package/dist/ecdsa.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { CHash } from '@noble/hashes/utils.js';
|
|
2
|
+
import type { CoseCurve } from './curve.ts';
|
|
3
|
+
/** The digest algorithms COSE signature algorithms use. */
|
|
4
|
+
export type DigestAlgorithm = 'sha256' | 'sha384' | 'sha512';
|
|
5
|
+
/** The implementation behind each digest name — shared with the HMAC in `hmac.ts`. */
|
|
6
|
+
export declare const HASHES: Record<DigestAlgorithm, CHash>;
|
|
7
|
+
/** Whether this build can sign and verify on the given curve. */
|
|
8
|
+
export declare const isImplemented: (curve: CoseCurve) => boolean;
|
|
9
|
+
/** The message digest an algorithm signs over. */
|
|
10
|
+
export declare const digest: (algorithm: DigestAlgorithm, data: Uint8Array) => Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Sign the given digest, returning the COSE wire form `r ‖ s`.
|
|
13
|
+
*
|
|
14
|
+
* `prehash: false` says the input already *is* the digest — the caller hashed
|
|
15
|
+
* the Sig_structure, because which digest to use is a property of the COSE
|
|
16
|
+
* algorithm rather than of the curve.
|
|
17
|
+
*
|
|
18
|
+
* `lowS: false` is the load-bearing one. The underlying library normalizes `s`
|
|
19
|
+
* to its low form by default, and COSE does not: RFC 6979 publishes the
|
|
20
|
+
* un-normalized values, and so does every implementation that follows it. With
|
|
21
|
+
* normalization on, this library would produce signatures that verify
|
|
22
|
+
* everywhere and are nevertheless *different bytes* from the ones the C#
|
|
23
|
+
* reference implementation produces for the same key and the same message —
|
|
24
|
+
* which would quietly destroy the one property that makes a deterministic
|
|
25
|
+
* signature worth having.
|
|
26
|
+
*/
|
|
27
|
+
export declare function sign(curve: CoseCurve, messageHash: Uint8Array, privateKey: Uint8Array): Uint8Array;
|
|
28
|
+
/**
|
|
29
|
+
* Verify a `r ‖ s` signature over the given digest.
|
|
30
|
+
*
|
|
31
|
+
* A signature of the wrong width is refused before it reaches the curve, with
|
|
32
|
+
* an error that names the likely cause: nearly every such signature is a DER
|
|
33
|
+
* encoding that was never converted.
|
|
34
|
+
*/
|
|
35
|
+
export declare function verify(curve: CoseCurve, signature: Uint8Array, messageHash: Uint8Array, publicKey: Uint8Array): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The uncompressed public key `04 ‖ x ‖ y` belonging to a private key.
|
|
38
|
+
*/
|
|
39
|
+
export declare function publicKeyFor(curve: CoseCurve, privateKey: Uint8Array): Uint8Array;
|
|
40
|
+
/**
|
|
41
|
+
* Recover the y coordinate of a point from its x coordinate and the parity of
|
|
42
|
+
* its y [RFC 9052, Section 7.1.1].
|
|
43
|
+
*
|
|
44
|
+
* A COSE key may carry `y` as a boolean rather than as a byte string, which
|
|
45
|
+
* halves the size of the key. There are two points with any given x, and the
|
|
46
|
+
* boolean says which of the two: the sign bit is the parity of y.
|
|
47
|
+
*/
|
|
48
|
+
export declare function decompressY(curve: CoseCurve, x: Uint8Array, oddY: boolean): Uint8Array;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the point `04 ‖ x ‖ y` lies on the curve.
|
|
51
|
+
*
|
|
52
|
+
* A public key that does not is not merely useless: handing one to a
|
|
53
|
+
* verification is how invalid-curve attacks start.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isOnCurve(curve: CoseCurve, uncompressed: Uint8Array): boolean;
|
|
56
|
+
//# sourceMappingURL=ecdsa.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../src/ecdsa.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAwC,wBAAwB,CAAC;AAOtF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAoC,YAAY,CAAC;AAkC1E,2DAA2D;AAC3D,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE7D,sFAAsF;AACtF,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,eAAe,EAAE,KAAK,CAA8B,CAAC;AAgCjF,iEAAiE;AACjE,eAAO,MAAM,aAAa,GAAI,OAAO,SAAS,KAAG,OACpB,CAAC;AAe9B,kDAAkD;AAClD,eAAO,MAAM,MAAM,GAAI,WAAW,eAAe,EAAE,MAAM,UAAU,KAAG,UAC3C,CAAC;AAG5B;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAO,SAAS,EACrB,WAAW,EAAE,UAAU,EACvB,UAAU,EAAG,UAAU,GAAG,UAAU,CAKxD;AAGD;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAQ,SAAS,EACtB,SAAS,EAAI,UAAU,EACvB,WAAW,EAAE,UAAU,EACvB,SAAS,EAAI,UAAU,GAAG,OAAO,CAiBvD;AAGD;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAEjF;AAGD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,GAAG,UAAU,CAYtF;AAGD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,GAAG,OAAO,CAU7E"}
|
package/dist/eddsa.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CoseCurve } from './curve.ts';
|
|
2
|
+
/** Whether this build can sign and verify on the given EdDSA curve. */
|
|
3
|
+
export declare const isEddsaCurve: (curve: CoseCurve) => boolean;
|
|
4
|
+
/** The signature width of an EdDSA curve, in bytes. */
|
|
5
|
+
export declare function eddsaSignatureSize(curve: CoseCurve): number;
|
|
6
|
+
/**
|
|
7
|
+
* Sign the Sig_structure itself — not a digest of it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function eddsaSign(curve: CoseCurve, message: Uint8Array, privateKey: Uint8Array): Uint8Array;
|
|
10
|
+
/** Verify an EdDSA signature over the Sig_structure. */
|
|
11
|
+
export declare function eddsaVerify(curve: CoseCurve, signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
|
|
12
|
+
/** The public key belonging to an EdDSA private key. */
|
|
13
|
+
export declare function eddsaPublicKeyFor(curve: CoseCurve, privateKey: Uint8Array): Uint8Array;
|
|
14
|
+
//# sourceMappingURL=eddsa.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eddsa.d.ts","sourceRoot":"","sources":["../src/eddsa.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAc,YAAY,CAAC;AAkBpD,uEAAuE;AACvE,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,KAAG,OACnB,CAAC;AAe9B,uDAAuD;AACvD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAO3D;AAGD;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAO,SAAS,EACrB,OAAO,EAAK,UAAU,EACtB,UAAU,EAAE,UAAU,GAAG,UAAU,CAI5D;AAGD,wDAAwD;AACxD,wBAAgB,WAAW,CAAC,KAAK,EAAM,SAAS,EACpB,SAAS,EAAE,UAAU,EACrB,OAAO,EAAI,UAAU,EACrB,SAAS,EAAE,UAAU,GAAG,OAAO,CAgB1D;AAGD,wDAAwD;AACxD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAEtF"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { CoseAlgorithm } from './algorithm.ts';
|
|
2
|
+
import type { CborValue } from './cbor.ts';
|
|
3
|
+
import type { Decryption } 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_Encrypt0 message. */
|
|
8
|
+
export declare const COSE_ENCRYPT0_TAG = 16;
|
|
9
|
+
/** The CBOR tag of a COSE_Encrypt message. */
|
|
10
|
+
export declare const COSE_ENCRYPT_TAG = 96;
|
|
11
|
+
/** The context string of a COSE_Encrypt0 [RFC 9052, Section 5.3]. */
|
|
12
|
+
export declare const ENCRYPT0_CONTEXT = "Encrypt0";
|
|
13
|
+
/** The context string of the body of a COSE_Encrypt. */
|
|
14
|
+
export declare const ENCRYPT_CONTEXT = "Encrypt";
|
|
15
|
+
/**
|
|
16
|
+
* The encoded `Enc_structure` [RFC 9052, Section 5.3]:
|
|
17
|
+
*
|
|
18
|
+
* ```
|
|
19
|
+
* Enc_structure = [ context, protected : empty_or_serialized_map, external_aad : bstr ]
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function encStructure(context: string, protectedHeaderBytes: Uint8Array, externalAad?: Uint8Array | null): Uint8Array;
|
|
23
|
+
/** What a party encrypting may choose. */
|
|
24
|
+
export interface EncryptOptions {
|
|
25
|
+
/**
|
|
26
|
+
* The nonce, which is required.
|
|
27
|
+
*
|
|
28
|
+
* There is no default and there will not be one. A nonce reused with the
|
|
29
|
+
* same key breaks AES-GCM outright, and this package has no way of knowing
|
|
30
|
+
* which nonces a caller has already spent.
|
|
31
|
+
*/
|
|
32
|
+
readonly iv: Uint8Array;
|
|
33
|
+
/** A key identifier for the unprotected bucket, defaulting to the key's own. */
|
|
34
|
+
readonly keyIdentifier?: Uint8Array | null;
|
|
35
|
+
/** Data authenticated along with the payload without travelling in the message. */
|
|
36
|
+
readonly externalAad?: Uint8Array | null;
|
|
37
|
+
/** Whether to omit the ciphertext from the message. */
|
|
38
|
+
readonly detachPayload?: boolean;
|
|
39
|
+
/** Whether to wrap the message within its CBOR tag. Defaults to true. */
|
|
40
|
+
readonly tagged?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** What a party decrypting may have to supply. */
|
|
43
|
+
export interface DecryptOptions {
|
|
44
|
+
/** The data that was authenticated along with the payload. */
|
|
45
|
+
readonly externalAad?: Uint8Array | null;
|
|
46
|
+
/** The ciphertext, when the message carries a detached one. */
|
|
47
|
+
readonly detachedCiphertext?: Uint8Array | null;
|
|
48
|
+
/** The algorithm the caller expects. */
|
|
49
|
+
readonly expectedAlgorithm?: CoseAlgorithm | null;
|
|
50
|
+
/** Header parameters the caller processes itself. */
|
|
51
|
+
readonly alsoUnderstood?: readonly CborValue[];
|
|
52
|
+
}
|
|
53
|
+
/** Everything the two encrypted structures share. */
|
|
54
|
+
declare abstract class CoseEncryptedBase {
|
|
55
|
+
/** The serialized protected bucket, exactly as authenticated and received. */
|
|
56
|
+
readonly protectedHeaderBytes: Uint8Array;
|
|
57
|
+
/** The protected header parameters, which the AEAD tag covers. */
|
|
58
|
+
readonly protectedHeader: CoseHeaders;
|
|
59
|
+
/** The unprotected header parameters, which it does not. */
|
|
60
|
+
readonly unprotectedHeader: CoseHeaders;
|
|
61
|
+
/** The ciphertext with the AEAD tag appended, or null when detached. */
|
|
62
|
+
readonly ciphertext: Uint8Array | null;
|
|
63
|
+
/** Whether this message is wrapped within its CBOR tag. */
|
|
64
|
+
readonly isTagged: boolean;
|
|
65
|
+
protected constructor(protectedHeaderBytes: Uint8Array, unprotectedHeader: CoseHeaders | null, ciphertext: Uint8Array | null, isTagged: boolean);
|
|
66
|
+
/** The content encryption algorithm, protected bucket first. */
|
|
67
|
+
get algorithm(): CoseAlgorithm | null;
|
|
68
|
+
/** The key identifier, protected bucket first. */
|
|
69
|
+
get keyIdentifier(): Uint8Array | null;
|
|
70
|
+
/** The nonce, from either bucket. It travels in the clear and must never repeat. */
|
|
71
|
+
get iv(): Uint8Array | null;
|
|
72
|
+
/** Whether the ciphertext is detached. */
|
|
73
|
+
get isDetached(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Decrypt with a content encryption key that has already been established.
|
|
76
|
+
*
|
|
77
|
+
* The shared half of both structures: `COSE_Encrypt0` uses it with the key
|
|
78
|
+
* the caller passed, `COSE_Encrypt` with the one a recipient yielded.
|
|
79
|
+
*/
|
|
80
|
+
protected decryptWith(contentKey: Uint8Array, context: string, options: DecryptOptions): Decryption;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A COSE_Encrypt0 message: encrypted for a recipient who already holds the key.
|
|
84
|
+
*/
|
|
85
|
+
export declare class CoseEncrypt0 extends CoseEncryptedBase {
|
|
86
|
+
constructor(protectedHeaderBytes: Uint8Array, unprotectedHeader: CoseHeaders | null, ciphertext: Uint8Array | null, isTagged?: boolean);
|
|
87
|
+
/** The encoded Enc_structure of this message. */
|
|
88
|
+
toBeEncrypted(externalAad?: Uint8Array | null): Uint8Array;
|
|
89
|
+
/** Encrypt a payload, with the algorithm in the protected bucket. */
|
|
90
|
+
static encrypt(plaintext: Uint8Array, key: CoseKey, options: EncryptOptions): CoseEncrypt0;
|
|
91
|
+
/** Encrypt a payload with header buckets the caller composed. */
|
|
92
|
+
static encryptWithHeaders(plaintext: Uint8Array, key: CoseKey, protectedHeader: CoseHeaders, unprotectedHeader: CoseHeaders | null, options: EncryptOptions): CoseEncrypt0;
|
|
93
|
+
/** Decrypt this message with the key it was encrypted for. */
|
|
94
|
+
decrypt(key: CoseKey, options?: DecryptOptions): Decryption;
|
|
95
|
+
/** Read a COSE_Encrypt0 message, tagged or not. */
|
|
96
|
+
static parse(input: Uint8Array | CborValue): CoseEncrypt0;
|
|
97
|
+
/** The CBOR form of this message. */
|
|
98
|
+
toCbor(): CborValue;
|
|
99
|
+
/** The CBOR encoding of this message. */
|
|
100
|
+
toBytes(): Uint8Array;
|
|
101
|
+
toString(): string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A COSE_Encrypt message: encrypted once, with the content key delivered to
|
|
105
|
+
* each recipient in a structure of its own.
|
|
106
|
+
*/
|
|
107
|
+
export declare class CoseEncrypt extends CoseEncryptedBase {
|
|
108
|
+
/** How the content key reaches each party. */
|
|
109
|
+
readonly recipients: readonly CoseRecipient[];
|
|
110
|
+
constructor(protectedHeaderBytes: Uint8Array, unprotectedHeader: CoseHeaders | null, ciphertext: Uint8Array | null, recipients: readonly CoseRecipient[], isTagged?: boolean);
|
|
111
|
+
/** The encoded Enc_structure of this message. */
|
|
112
|
+
toBeEncrypted(externalAad?: Uint8Array | null): Uint8Array;
|
|
113
|
+
/**
|
|
114
|
+
* Encrypt a payload under a content key, and deliver that key to each
|
|
115
|
+
* recipient.
|
|
116
|
+
*
|
|
117
|
+
* The content key is the caller's, not this method's, for the same reason
|
|
118
|
+
* the nonce is: generating one here would make the message
|
|
119
|
+
* unreproducible, and a caller who has a key management scheme has one for
|
|
120
|
+
* a reason.
|
|
121
|
+
*/
|
|
122
|
+
static encrypt(plaintext: Uint8Array, contentKey: CoseKey, recipients: readonly CoseRecipient[], options: EncryptOptions): CoseEncrypt;
|
|
123
|
+
/**
|
|
124
|
+
* Decrypt this message with a key one of its recipients was built for.
|
|
125
|
+
*
|
|
126
|
+
* Every recipient is tried, because a party holding one key does not
|
|
127
|
+
* generally know which entry in the list is theirs. A recipient that does
|
|
128
|
+
* not yield a key is not an error — it is somebody else's.
|
|
129
|
+
*/
|
|
130
|
+
decrypt(key: CoseKey, options?: DecryptOptions): Decryption;
|
|
131
|
+
/** Read a COSE_Encrypt message, tagged or not. */
|
|
132
|
+
static parse(input: Uint8Array | CborValue): CoseEncrypt;
|
|
133
|
+
/** The CBOR form of this message. */
|
|
134
|
+
toCbor(): CborValue;
|
|
135
|
+
/** The CBOR encoding of this message. */
|
|
136
|
+
toBytes(): Uint8Array;
|
|
137
|
+
toString(): string;
|
|
138
|
+
}
|
|
139
|
+
export {};
|
|
140
|
+
//# sourceMappingURL=encrypt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../src/encrypt.ts"],"names":[],"mappings":"AA8CA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAqB,gBAAgB,CAAC;AAEnE,OAAO,KAAK,EAAa,SAAS,EAAE,MAAc,WAAW,CAAC;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAwB,aAAa,CAAC;AAChE,OAAO,EAAE,WAAW,EACqB,MAAS,cAAc,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAA2B,UAAU,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAA0B,gBAAgB,CAAC;AAGnE,+CAA+C;AAC/C,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,8CAA8C;AAC9C,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,qEAAqE;AACrE,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,wDAAwD;AACxD,eAAO,MAAM,eAAe,YAAY,CAAC;AAGzC;;;;;;GAMG;AACH,wBAAgB,YAAY,CA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