@owf/cose 0.1.0 → 0.2.0-alpha-20260508112151

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.
@@ -0,0 +1,620 @@
1
+ import { Options, addExtension } from "cbor-x";
2
+ import z$1, { ZodError, z } from "zod";
3
+ //#region src/cbor/cbor-structure.d.ts
4
+ type CborEncodeOptions = {
5
+ asDataItem?: boolean;
6
+ };
7
+ type AnyCborStructure = CborStructure<any, any>;
8
+ type EncodedStructureType<T> = T extends CborStructure<infer EncodedStructure, unknown> ? EncodedStructure : any;
9
+ type DecodedStructureType<T> = T extends CborStructure<unknown, infer DecodedStructure> ? DecodedStructure : any;
10
+ type CborStructureStaticThis<T extends AnyCborStructure> = {
11
+ new (structure: any): T;
12
+ encodingSchema: z.ZodType<any, any, any> | undefined;
13
+ fromEncodedStructure: (encodedStructure: EncodedStructureType<T>) => {
14
+ decodedStructure: DecodedStructureType<T>;
15
+ };
16
+ };
17
+ declare class CborStructure<EncodedStructure = unknown, DecodedStructure = EncodedStructure> {
18
+ protected structure: DecodedStructure;
19
+ protected _tag: number | undefined;
20
+ constructor(structure: DecodedStructure);
21
+ get decodedStructure(): DecodedStructure;
22
+ /**
23
+ * Static getter for the Zod codec schema that defines the CBOR structure.
24
+ * Subclasses CAN override this to provide their specific schema for automatic encoding/decoding.
25
+ * The schema should be a Zod schema or codec that handles validation and transformation.
26
+ * If not provided, subclasses must override encode(), decode(), and fromEncodedStructure().
27
+ */
28
+ static get encodingSchema(): z.ZodType | undefined;
29
+ /**
30
+ * Returns the encoded structure that will be serialized to CBOR.
31
+ * By default, returns the protected structure property.
32
+ * Override if custom encoding logic is needed.
33
+ */
34
+ get encodedStructure(): EncodedStructure;
35
+ /**
36
+ * Encodes this structure to CBOR bytes.
37
+ */
38
+ encode(options?: CborEncodeOptions): Uint8Array;
39
+ /**
40
+ * Decodes CBOR bytes into a structure instance.
41
+ * Uses the encodingSchema's decode() method to validate and transform the decoded data.
42
+ */
43
+ static decode<T extends AnyCborStructure>(this: CborStructureStaticThis<T>, bytes: Uint8Array): T;
44
+ /**
45
+ * Creates a structure instance from the encoded CBOR structure (after calling cborDecode).
46
+ *
47
+ * Uses the encodingSchema's decode() method to validate and transform the structure if available.
48
+ * Otherwise, subclasses must override this method.
49
+ */
50
+ static fromEncodedStructure<T extends AnyCborStructure>(this: CborStructureStaticThis<T>, encodedStructure: EncodedStructureType<T>): T;
51
+ static fromDataItem<T extends AnyCborStructure>(this: CborStructureStaticThis<T>, dataItem: unknown): T;
52
+ /**
53
+ * Creates a structure instance from the decoded structure.
54
+ *
55
+ * Uses the encodingSchema's parse method to validate the structure if available.
56
+ * Otherwise, subclasses must override this method.
57
+ */
58
+ static fromDecodedStructure<T extends AnyCborStructure>(this: CborStructureStaticThis<T>, decodedStructure: DecodedStructureType<T>): T;
59
+ }
60
+ //#endregion
61
+ //#region src/cbor/data-item.d.ts
62
+ declare const zDataItemCodec: (outputSchema: z$1.ZodType) => z$1.ZodCodec<z$1.ZodCustom<DataItem<unknown>, DataItem<unknown>>, z$1.ZodType<unknown, unknown, z$1.core.$ZodTypeInternals<unknown, unknown>>>;
63
+ type DataItemOptions<T = unknown> = {
64
+ data: T;
65
+ buffer: Uint8Array;
66
+ } | {
67
+ data: T;
68
+ } | {
69
+ buffer: Uint8Array;
70
+ };
71
+ /**
72
+ * DataItem is an extension defined https://www.rfc-editor.org/rfc/rfc8949.html#name-encoded-cbor-data-item
73
+ * > Sometimes it is beneficial to carry an embedded CBOR data item that is
74
+ * > not meant to be decoded immediately at the time the enclosing data item is being decoded.
75
+ *
76
+ * The idea of this class is to provide lazy encode and decode of cbor data.
77
+ *
78
+ * Due to a bug in the cbor-x library, we are eagerly encoding the data in the constructor.
79
+ * https://github.com/kriszyp/cbor-x/issues/83
80
+ *
81
+ */
82
+ declare class DataItem<T = unknown> {
83
+ #private;
84
+ constructor(options: DataItemOptions<T>);
85
+ get data(): T;
86
+ get buffer(): Uint8Array;
87
+ static fromData<T>(data: T): DataItem<T>;
88
+ static fromBuffer<T>(buffer: Uint8Array): DataItem<T>;
89
+ }
90
+ //#endregion
91
+ //#region src/cbor/models/date-only.d.ts
92
+ declare const customInspectSymbol: unique symbol;
93
+ declare class DateOnly {
94
+ private date;
95
+ constructor(date?: string);
96
+ get [Symbol.toStringTag](): string;
97
+ toString(): string;
98
+ toJSON(): string;
99
+ toISOString(): string;
100
+ [customInspectSymbol](): string;
101
+ }
102
+ //#endregion
103
+ //#region src/cbor/parser.d.ts
104
+ type CborOptions = Options & {
105
+ unwrapTopLevelDataItem?: boolean;
106
+ };
107
+ declare const cborDecode: <T>(input: Uint8Array, options?: CborOptions) => T;
108
+ declare const cborEncode: (obj: unknown, options?: Options) => Uint8Array;
109
+ //#endregion
110
+ //#region src/cose/claims/default.d.ts
111
+ /**
112
+ *
113
+ * Registered CWT claim keys
114
+ * @see https://www.rfc-editor.org/rfc/rfc8392#section-3.1
115
+ *
116
+ */
117
+ declare enum RegisteredCwtClaimKey {
118
+ Issuer = 1,
119
+ Subject = 2,
120
+ Audience = 3,
121
+ ExpirationTime = 4,
122
+ NotBefore = 5,
123
+ IssuedAt = 6,
124
+ CwtId = 7
125
+ }
126
+ //#endregion
127
+ //#region src/cose/headers/defaults.d.ts
128
+ /**
129
+ *
130
+ * Registered CWT header keys
131
+ *
132
+ */
133
+ declare enum RegisteredCwtHeaderClaimKey {
134
+ Algorithm = 1,
135
+ Critical = 2,
136
+ ContentType = 3,
137
+ KeyId = 4,
138
+ Iv = 5,
139
+ PartialIv = 6,
140
+ CounterSignature = 7,
141
+ CounterSignature0 = 9,
142
+ CounterSignatureV2 = 11,
143
+ CounterSignature0V2 = 12,
144
+ X5Bag = 32,
145
+ X5Chain = 33,
146
+ X5T = 34,
147
+ X5U = 35
148
+ }
149
+ declare enum SignatureAlgorithm {
150
+ EdDSA = -8,
151
+ ES256 = -7,
152
+ ES384 = -35,
153
+ ES512 = -36,
154
+ PS256 = -37,
155
+ PS384 = -38,
156
+ PS512 = -39,
157
+ RS256 = -257,
158
+ RS384 = -258,
159
+ RS512 = -259
160
+ }
161
+ declare enum MacAlgorithm {
162
+ HS256 = 5,
163
+ HS384 = 6,
164
+ HS512 = 7
165
+ }
166
+ declare enum EncryptionAlgorithm {
167
+ A128GCM = 1,
168
+ A192GCM = 2,
169
+ A256GCM = 3,
170
+ Direct = -6
171
+ }
172
+ type DigestAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512';
173
+ //#endregion
174
+ //#region src/cose/headers/protected-headers.d.ts
175
+ declare const protectedHeadersEncodedStructure: z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
176
+ declare const protectedHeadersDecodedStructure: z$1.ZodMap<z$1.ZodNumber, z$1.ZodUnknown>;
177
+ type ProtectedHeadersDecodedStructure = z$1.infer<typeof protectedHeadersDecodedStructure>;
178
+ type ProtectedHeadersEncodedStructure = z$1.infer<typeof protectedHeadersEncodedStructure>;
179
+ type ProtectedHeaderOptions = {
180
+ protectedHeaders?: ProtectedHeadersDecodedStructure;
181
+ };
182
+ declare class ProtectedHeaders extends CborStructure<ProtectedHeadersEncodedStructure, ProtectedHeadersDecodedStructure> {
183
+ static get encodingSchema(): z$1.ZodCodec<z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>, z$1.ZodMap<z$1.ZodNumber, z$1.ZodUnknown>>;
184
+ get headers(): Map<number, unknown>;
185
+ static create(options: ProtectedHeaderOptions): ProtectedHeaders;
186
+ }
187
+ //#endregion
188
+ //#region src/cose/headers/unprotected-headers.d.ts
189
+ declare const unprotectedHeadersStructure: z$1.ZodMap<z$1.ZodNumber, z$1.ZodUnknown>;
190
+ type UnprotectedHeadersStructure = z$1.infer<typeof unprotectedHeadersStructure>;
191
+ type UnprotectedHeaderOptions = {
192
+ unprotectedHeaders?: UnprotectedHeadersStructure;
193
+ };
194
+ declare class UnprotectedHeaders extends CborStructure<UnprotectedHeadersStructure> {
195
+ static get encodingSchema(): z$1.ZodMap<z$1.ZodNumber, z$1.ZodUnknown>;
196
+ get headers(): Map<number, unknown>;
197
+ static create(options: UnprotectedHeaderOptions): UnprotectedHeaders;
198
+ }
199
+ //#endregion
200
+ //#region src/cose/mac0.d.ts
201
+ declare const mac0EncodedSchema: z.ZodTuple<[z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>, z.ZodMap<z.ZodUnknown, z.ZodUnknown>, z.ZodNullable<z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>, z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>], null>;
202
+ declare const mac0DecodedSchema: z.ZodObject<{
203
+ protectedHeaders: z.ZodCustom<ProtectedHeaders, ProtectedHeaders>;
204
+ unprotectedHeaders: z.ZodCustom<UnprotectedHeaders, UnprotectedHeaders>;
205
+ payload: z.ZodNullable<z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>;
206
+ tag: z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
207
+ }, z.core.$strip>;
208
+ type Mac0EncodedStructure = z.infer<typeof mac0EncodedSchema>;
209
+ type Mac0DecodedStructure = z.infer<typeof mac0DecodedSchema>;
210
+ type Mac0Context = {
211
+ mac: (options: {
212
+ toBeAuthenticated: Uint8Array;
213
+ key: Uint8Array;
214
+ }) => Promise<Uint8Array>;
215
+ };
216
+ type Mac0Options = {
217
+ protectedHeaders?: ProtectedHeaders | ProtectedHeaderOptions['protectedHeaders'];
218
+ unprotectedHeaders?: UnprotectedHeaders | UnprotectedHeaderOptions['unprotectedHeaders'];
219
+ externalAad?: Uint8Array;
220
+ payload?: Uint8Array | null;
221
+ detachedPayload?: Uint8Array;
222
+ };
223
+ declare class Mac0 extends CborStructure<Mac0EncodedStructure, Mac0DecodedStructure> {
224
+ static tag: number;
225
+ protected _tag: number;
226
+ static get encodingSchema(): z.ZodCodec<z.ZodTuple<[z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>, z.ZodMap<z.ZodUnknown, z.ZodUnknown>, z.ZodNullable<z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>, z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>], null>, z.ZodObject<{
227
+ protectedHeaders: z.ZodCustom<ProtectedHeaders, ProtectedHeaders>;
228
+ unprotectedHeaders: z.ZodCustom<UnprotectedHeaders, UnprotectedHeaders>;
229
+ payload: z.ZodNullable<z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>;
230
+ tag: z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
231
+ }, z.core.$strip>>;
232
+ externalAad?: Uint8Array;
233
+ detachedPayload?: Uint8Array;
234
+ get protectedHeaders(): ProtectedHeaders;
235
+ get unprotectedHeaders(): UnprotectedHeaders;
236
+ get payload(): Uint8Array<ArrayBufferLike> | null;
237
+ get tag(): Uint8Array<ArrayBufferLike>;
238
+ get toBeAuthenticated(): Uint8Array<ArrayBufferLike>;
239
+ /**
240
+ * Decodes CBOR bytes into a Sign1 instance.
241
+ * Uses the encodingSchema's decode() method to validate and transform the decoded data.
242
+ */
243
+ static decode<T extends AnyCborStructure>(this: CborStructureStaticThis<T>, bytes: Uint8Array): T;
244
+ static toBeAuthenticated(options: {
245
+ payload: Uint8Array;
246
+ protectedHeaders: ProtectedHeaders;
247
+ externalAad?: Uint8Array;
248
+ }): Uint8Array<ArrayBufferLike>;
249
+ get signatureAlgorithmName(): MacAlgorithm;
250
+ static create(options: Mac0Options): Mac0;
251
+ authenticate(options: {
252
+ key: Uint8Array;
253
+ }, ctx: Pick<Mac0Context, 'mac'>): Promise<this>;
254
+ }
255
+ //#endregion
256
+ //#region src/cose/key/curve.d.ts
257
+ declare enum Curve {
258
+ 'P-256' = 1,
259
+ 'P-384' = 2,
260
+ 'P-521' = 3,
261
+ X25519 = 4,
262
+ X448 = 5,
263
+ Ed25519 = 6,
264
+ Ed448 = 7
265
+ }
266
+ //#endregion
267
+ //#region src/utils/typed-map.d.ts
268
+ /**
269
+ * TypedMap provides compile-time type safety for Maps where each key has its own specific value type.
270
+ * Unlike Map<K, V> which has the same value type V for all keys, TypedMap<Schema, OptionalKeys>
271
+ * allows different value types per key (heterogeneous values).
272
+ *
273
+ * Example:
274
+ * type CoseKeySchema = {
275
+ * [CoseKeyParameter.KeyType]: KeyType // number key → KeyType value
276
+ * [CoseKeyParameter.Curve]: Curve // number key → Curve value
277
+ * [CoseKeyParameter.X]: Uint8Array // number key → Uint8Array value
278
+ * }
279
+ *
280
+ * const map = new TypedMap<CoseKeySchema>()
281
+ * map.get(CoseKeyParameter.KeyType) // TypeScript knows this is KeyType!
282
+ * map.get(CoseKeyParameter.Curve) // TypeScript knows this is Curve!
283
+ * map.get(CoseKeyParameter.X) // TypeScript knows this is Uint8Array!
284
+ *
285
+ * @template Schema - Object type mapping keys to their value types
286
+ * @template OptionalKeys - Union of keys that are optional (can be absent)
287
+ */
288
+ declare class TypedMap<Schema extends Record<PropertyKey, any>, OptionalKeys extends keyof Schema = never> {
289
+ private readonly map;
290
+ constructor(entries?: (readonly [keyof Schema, Schema[keyof Schema]])[] | null);
291
+ static fromMap<Schema extends Record<PropertyKey, any>, OptionalKeys extends keyof Schema = never>(map: Map<any, any>): TypedMap<Schema, OptionalKeys>;
292
+ static fromObject<Schema extends Record<PropertyKey, any>, OptionalKeys extends keyof Schema = never>(object: Record<string | number, any>): TypedMap<Schema, OptionalKeys>;
293
+ /**
294
+ * Type-safe get that returns the correct value type for each key.
295
+ * Required keys return T, optional keys return T | undefined.
296
+ */
297
+ get<K extends keyof Schema>(key: K): K extends OptionalKeys ? Schema[K] | undefined : Schema[K];
298
+ /**
299
+ * Type-safe set that ensures the value matches the key's type
300
+ */
301
+ set<K extends keyof Schema>(key: K, value: Schema[K]): this;
302
+ has(key: keyof Schema): boolean;
303
+ delete(key: keyof Schema): boolean;
304
+ clear(): void;
305
+ get size(): number;
306
+ keys(): IterableIterator<keyof Schema>;
307
+ values(): IterableIterator<Schema[keyof Schema]>;
308
+ entries(): IterableIterator<[keyof Schema, Schema[keyof Schema]]>;
309
+ forEach(callbackfn: (value: Schema[keyof Schema], key: keyof Schema, map: Map<keyof Schema, Schema[keyof Schema]>) => void, thisArg?: any): void;
310
+ [Symbol.iterator](): IterableIterator<[keyof Schema, Schema[keyof Schema]]>;
311
+ toMap(): Map<keyof Schema, Schema[keyof Schema]>;
312
+ }
313
+ type EntriesArrayToSchema<T extends ReadonlyArray<readonly [any, any]>> = { [K in T[number][0]]: Extract<T[number], readonly [K, any]>[1] };
314
+ type EntriesBase = ReadonlyArray<readonly [string | number, z.ZodType<any>]>;
315
+ type InferredEntries<Entries extends EntriesBase> = { [K in keyof Entries]: readonly [Entries[K][0], z.infer<Entries[K][1]>] };
316
+ type InferredSchema<Entries extends EntriesBase> = EntriesArrayToSchema<InferredEntries<Entries>>;
317
+ type OptionalKeys<Entries extends EntriesBase> = Entries[number] extends infer E ? E extends readonly [infer K, infer V] ? V extends z.ZodExactOptional<any> ? K : never : never : never;
318
+ /**
319
+ * Utility function to create a typed map codec.
320
+ * Takes an array of [key, valueSchema] entries to support any key type (including non-string keys for CBOR).
321
+ *
322
+ * Example:
323
+ * const coseKeyMap = typedMap([
324
+ * [CoseKeyParameter.KeyType, z.number()],
325
+ * [CoseKeyParameter.Curve, z.number()],
326
+ * [CoseKeyParameter.X, z.instanceof(Uint8Array)]
327
+ * ] as const)
328
+ *
329
+ * The resulting schema validates a Map and transforms it to TypedMap<Schema, never>.
330
+ */
331
+ declare function typedMap<const Entries extends EntriesBase>(entries: Entries, {
332
+ allowAdditionalKeys,
333
+ encode,
334
+ decode
335
+ }?: {
336
+ /**
337
+ * Whether to allow additional keys in the typed map
338
+ *
339
+ * @default true
340
+ */
341
+ allowAdditionalKeys?: boolean;
342
+ /**
343
+ * Allows overriding the encode function. The original encode method is passed as second
344
+ * argument, so you can use this method to pre/post process
345
+ */
346
+ encode?: (decoded: TypedMap<InferredSchema<Entries>, OptionalKeys<Entries>>, originalEncode: (decoded: TypedMap<InferredSchema<Entries>, OptionalKeys<Entries>>) => Map<unknown, unknown>) => Map<unknown, unknown>;
347
+ /**
348
+ * Allows overriding the decode function. The original decode method is passed as second
349
+ * argument, so you can use this method to pre/post process
350
+ */
351
+ decode?: (encoded: Map<unknown, unknown>, originalDecode: (decoded: Map<unknown, unknown>) => TypedMap<InferredSchema<Entries>, OptionalKeys<Entries>>) => TypedMap<InferredSchema<Entries>, OptionalKeys<Entries>>;
352
+ }): z.ZodCodec<z.ZodMap<z.ZodUnknown, z.ZodUnknown>, z.ZodCustom<TypedMap<InferredSchema<Entries>, OptionalKeys<Entries>>, TypedMap<InferredSchema<Entries>, OptionalKeys<Entries>>>>;
353
+ //#endregion
354
+ //#region src/cose/key/key-operation.d.ts
355
+ declare enum KeyOps {
356
+ Sign = 1,
357
+ Verify = 2,
358
+ Encrypt = 3,
359
+ Decrypt = 4,
360
+ WrapKey = 5,
361
+ UnwrapKey = 6,
362
+ DeriveKey = 7,
363
+ DeriveBits = 8,
364
+ MACCreate = 9,
365
+ MACVerify = 10
366
+ }
367
+ //#endregion
368
+ //#region src/cose/key/key-type.d.ts
369
+ declare enum KeyType {
370
+ Okp = 1,
371
+ Ec = 2,
372
+ Oct = 4,
373
+ Reserved = 0
374
+ }
375
+ //#endregion
376
+ //#region src/cose/key/key.d.ts
377
+ declare enum CoseKeyParameter {
378
+ KeyType = 1,
379
+ KeyId = 2,
380
+ Algorithm = 3,
381
+ KeyOps = 4,
382
+ BaseIv = 5,
383
+ CurveOrK = -1,
384
+ X = -2,
385
+ Y = -3,
386
+ D = -4
387
+ }
388
+ declare const coseKeySchema: z.ZodCodec<z.ZodMap<z.ZodUnknown, z.ZodUnknown>, z.ZodCustom<TypedMap<{
389
+ 1: string | KeyType;
390
+ 2: string | Uint8Array<ArrayBufferLike>;
391
+ 3: string | number;
392
+ 4: (string | KeyOps)[];
393
+ 5: Uint8Array<ArrayBufferLike>;
394
+ [-1]: Uint8Array<ArrayBufferLike> | Curve;
395
+ [-2]: Uint8Array<ArrayBufferLike>;
396
+ [-3]: Uint8Array<ArrayBufferLike>;
397
+ [-4]: Uint8Array<ArrayBufferLike>;
398
+ }, CoseKeyParameter.KeyId | CoseKeyParameter.Algorithm | CoseKeyParameter.KeyOps | CoseKeyParameter.BaseIv | CoseKeyParameter.CurveOrK | CoseKeyParameter.X | CoseKeyParameter.Y | CoseKeyParameter.D>, TypedMap<{
399
+ 1: string | KeyType;
400
+ 2: string | Uint8Array<ArrayBufferLike>;
401
+ 3: string | number;
402
+ 4: (string | KeyOps)[];
403
+ 5: Uint8Array<ArrayBufferLike>;
404
+ [-1]: Uint8Array<ArrayBufferLike> | Curve;
405
+ [-2]: Uint8Array<ArrayBufferLike>;
406
+ [-3]: Uint8Array<ArrayBufferLike>;
407
+ [-4]: Uint8Array<ArrayBufferLike>;
408
+ }, CoseKeyParameter.KeyId | CoseKeyParameter.Algorithm | CoseKeyParameter.KeyOps | CoseKeyParameter.BaseIv | CoseKeyParameter.CurveOrK | CoseKeyParameter.X | CoseKeyParameter.Y | CoseKeyParameter.D>>>;
409
+ type CoseKeyDecodedStructure = z.output<typeof coseKeySchema>;
410
+ type CoseKeyEncodedStructure = z.input<typeof coseKeySchema>;
411
+ type CoseKeyOptions = {
412
+ keyType: KeyType | string;
413
+ keyId?: string;
414
+ algorithm?: string | number;
415
+ keyOps?: Array<KeyOps | string>;
416
+ baseIv?: Uint8Array;
417
+ curve?: Curve;
418
+ x?: Uint8Array;
419
+ y?: Uint8Array;
420
+ d?: Uint8Array;
421
+ k?: Uint8Array;
422
+ };
423
+ declare class CoseKey extends CborStructure<CoseKeyEncodedStructure, CoseKeyDecodedStructure> {
424
+ static get encodingSchema(): z.ZodCodec<z.ZodMap<z.ZodUnknown, z.ZodUnknown>, z.ZodCustom<TypedMap<{
425
+ 1: string | KeyType;
426
+ 2: string | Uint8Array<ArrayBufferLike>;
427
+ 3: string | number;
428
+ 4: (string | KeyOps)[];
429
+ 5: Uint8Array<ArrayBufferLike>;
430
+ [-1]: Uint8Array<ArrayBufferLike> | Curve;
431
+ [-2]: Uint8Array<ArrayBufferLike>;
432
+ [-3]: Uint8Array<ArrayBufferLike>;
433
+ [-4]: Uint8Array<ArrayBufferLike>;
434
+ }, CoseKeyParameter.KeyId | CoseKeyParameter.Algorithm | CoseKeyParameter.KeyOps | CoseKeyParameter.BaseIv | CoseKeyParameter.CurveOrK | CoseKeyParameter.X | CoseKeyParameter.Y | CoseKeyParameter.D>, TypedMap<{
435
+ 1: string | KeyType;
436
+ 2: string | Uint8Array<ArrayBufferLike>;
437
+ 3: string | number;
438
+ 4: (string | KeyOps)[];
439
+ 5: Uint8Array<ArrayBufferLike>;
440
+ [-1]: Uint8Array<ArrayBufferLike> | Curve;
441
+ [-2]: Uint8Array<ArrayBufferLike>;
442
+ [-3]: Uint8Array<ArrayBufferLike>;
443
+ [-4]: Uint8Array<ArrayBufferLike>;
444
+ }, CoseKeyParameter.KeyId | CoseKeyParameter.Algorithm | CoseKeyParameter.KeyOps | CoseKeyParameter.BaseIv | CoseKeyParameter.CurveOrK | CoseKeyParameter.X | CoseKeyParameter.Y | CoseKeyParameter.D>>>;
445
+ get keyType(): string | KeyType;
446
+ get keyId(): string | undefined;
447
+ get algorithm(): SignatureAlgorithm | undefined;
448
+ get keyOps(): (string | KeyOps)[] | undefined;
449
+ get baseIv(): Uint8Array<ArrayBufferLike> | undefined;
450
+ get curve(): Curve | undefined;
451
+ get x(): Uint8Array<ArrayBufferLike> | undefined;
452
+ get y(): Uint8Array<ArrayBufferLike> | undefined;
453
+ get d(): Uint8Array<ArrayBufferLike> | undefined;
454
+ get k(): Uint8Array<ArrayBufferLike> | undefined;
455
+ static create(options: CoseKeyOptions): CoseKey;
456
+ static fromJwk(jwk: Record<string, unknown>): CoseKey;
457
+ get publicKey(): Uint8Array<ArrayBuffer>;
458
+ get privateKey(): Uint8Array<ArrayBufferLike>;
459
+ get jwk(): Record<string, unknown>;
460
+ }
461
+ //#endregion
462
+ //#region src/cose/key/jwk.d.ts
463
+ declare const jwkCoseOptionsMap: Record<string, keyof CoseKeyOptions>;
464
+ declare const coseOptionsJwkMap: {
465
+ [k: string]: string;
466
+ };
467
+ declare const jwkToCoseKey: {
468
+ kty: (kty?: unknown) => KeyType;
469
+ crv: (crv?: unknown) => Curve;
470
+ alg: (alg?: unknown) => SignatureAlgorithm | MacAlgorithm | EncryptionAlgorithm;
471
+ kid: (kid?: unknown) => unknown;
472
+ keyOps: (keyOps?: unknown) => KeyOps[] | undefined;
473
+ x: (s?: unknown) => Uint8Array<ArrayBufferLike> | undefined;
474
+ y: (s?: unknown) => Uint8Array<ArrayBufferLike> | undefined;
475
+ d: (s?: unknown) => Uint8Array<ArrayBufferLike> | undefined;
476
+ };
477
+ declare const coseKeyToJwk: {
478
+ keyType: (keyType: KeyType) => any;
479
+ keyId: (keyId: unknown) => unknown;
480
+ algorithm: (algorithm?: SignatureAlgorithm | MacAlgorithm) => any;
481
+ keyOps: (keyOps?: unknown) => any[] | undefined;
482
+ baseIv: (baseIv?: unknown) => unknown;
483
+ curve: (curve?: Curve) => any;
484
+ x: (x?: Uint8Array) => string | undefined;
485
+ y: (y?: Uint8Array) => string | undefined;
486
+ d: (d?: Uint8Array) => string | undefined;
487
+ };
488
+ //#endregion
489
+ //#region src/cose/sign1.d.ts
490
+ declare const sign1EncodedSchema: z$1.ZodTuple<[z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>, z$1.ZodMap<z$1.ZodNumber, z$1.ZodUnknown>, z$1.ZodNullable<z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>, z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>], null>;
491
+ declare const sign1DecodedSchema: z$1.ZodObject<{
492
+ protectedHeaders: z$1.ZodCustom<ProtectedHeaders, ProtectedHeaders>;
493
+ unprotectedHeaders: z$1.ZodCustom<UnprotectedHeaders, UnprotectedHeaders>;
494
+ payload: z$1.ZodNullable<z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>;
495
+ signature: z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
496
+ }, z$1.core.$strip>;
497
+ type Sign1EncodedStructure = z$1.infer<typeof sign1EncodedSchema>;
498
+ type Sign1DecodedStructure = z$1.infer<typeof sign1DecodedSchema>;
499
+ type Sign1Context = {
500
+ sign: (options: {
501
+ toBeSigned: Uint8Array;
502
+ key: CoseKey;
503
+ algorithm: SignatureAlgorithm;
504
+ }) => Promise<Uint8Array>;
505
+ getPublicKey: (options: {
506
+ certificate: Uint8Array | Uint8Array[];
507
+ alg: string;
508
+ }) => Promise<Uint8Array>;
509
+ verify: (options: {
510
+ sign1: Sign1;
511
+ key: Uint8Array | CoseKey;
512
+ }) => Promise<boolean>;
513
+ x509: {
514
+ getIssuerNameField: (options: {
515
+ certificate: Uint8Array | Uint8Array[];
516
+ field: string;
517
+ }) => string[];
518
+ getPublicKey: (options: {
519
+ certificate: Uint8Array | Uint8Array[];
520
+ alg: string;
521
+ }) => Promise<Uint8Array>;
522
+ };
523
+ };
524
+ type Sign1Options = {
525
+ protectedHeaders?: ProtectedHeaders | ProtectedHeaderOptions['protectedHeaders'];
526
+ unprotectedHeaders?: UnprotectedHeaders | UnprotectedHeaderOptions['unprotectedHeaders'];
527
+ externalAad?: Uint8Array;
528
+ payload?: Uint8Array | null;
529
+ detachedPayload?: Uint8Array;
530
+ };
531
+ declare class Sign1 extends CborStructure<Sign1EncodedStructure, Sign1DecodedStructure> {
532
+ static tag: number;
533
+ protected _tag: number;
534
+ static get encodingSchema(): z$1.ZodCodec<z$1.ZodTuple<[z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>, z$1.ZodMap<z$1.ZodNumber, z$1.ZodUnknown>, z$1.ZodNullable<z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>, z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>], null>, z$1.ZodObject<{
535
+ protectedHeaders: z$1.ZodCustom<ProtectedHeaders, ProtectedHeaders>;
536
+ unprotectedHeaders: z$1.ZodCustom<UnprotectedHeaders, UnprotectedHeaders>;
537
+ payload: z$1.ZodNullable<z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>;
538
+ signature: z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
539
+ }, z$1.core.$strip>>;
540
+ detachedPayload?: Uint8Array;
541
+ externalAad?: Uint8Array;
542
+ get protectedHeaders(): ProtectedHeaders;
543
+ get unprotectedHeaders(): UnprotectedHeaders;
544
+ get payload(): Uint8Array<ArrayBufferLike> | null;
545
+ get signature(): Uint8Array<ArrayBufferLike>;
546
+ get certificateChain(): Uint8Array<ArrayBufferLike>[];
547
+ get certificate(): Uint8Array<ArrayBufferLike>;
548
+ getIssuingCountry(ctx: Pick<Sign1Context, 'x509'>): string;
549
+ getIssuingStateOrProvince(ctx: Pick<Sign1Context, 'x509'>): string;
550
+ get toBeSigned(): Uint8Array<ArrayBufferLike>;
551
+ /**
552
+ * Decodes CBOR bytes into a Sign1 instance.
553
+ * Uses the encodingSchema's decode() method to validate and transform the decoded data.
554
+ */
555
+ static decode<T extends AnyCborStructure>(this: CborStructureStaticThis<T>, bytes: Uint8Array): T;
556
+ static toBeSigned(options: {
557
+ payload: Uint8Array;
558
+ protectedHeaders: ProtectedHeaders;
559
+ externalAad?: Uint8Array;
560
+ }): Uint8Array<ArrayBufferLike>;
561
+ get signatureAlgorithmName(): string;
562
+ get x5chain(): Uint8Array<ArrayBufferLike>[] | undefined;
563
+ verifySignature(options: {
564
+ key?: CoseKey;
565
+ }, ctx: Pick<Sign1Context, 'getPublicKey' | 'verify'>): Promise<boolean>;
566
+ static create(options: Sign1Options): Sign1;
567
+ sign(options: {
568
+ externalAad?: Uint8Array;
569
+ signingKey: CoseKey;
570
+ algorithm?: SignatureAlgorithm;
571
+ detachedPayload?: Uint8Array;
572
+ }, ctx: Pick<Sign1Context, 'sign'>): Promise<this>;
573
+ }
574
+ //#endregion
575
+ //#region src/cose/cwt.d.ts
576
+ type CwtOptions = Sign1Options | Mac0Options;
577
+ declare class Cwt {
578
+ private options;
579
+ constructor(options: CwtOptions);
580
+ static create(options: CwtOptions): Cwt;
581
+ static fromToken(token: Uint8Array): Cwt;
582
+ get asSign1(): Sign1;
583
+ get asMac0(): Mac0;
584
+ get payload(): Uint8Array<ArrayBufferLike>;
585
+ get protectedHeaders(): Map<number, unknown> | ProtectedHeaders | undefined;
586
+ get unprotectedHeaders(): Map<number, unknown> | UnprotectedHeaders | undefined;
587
+ }
588
+ //#endregion
589
+ //#region src/cose/error.d.ts
590
+ declare class CoseError extends Error {
591
+ constructor(message?: string);
592
+ }
593
+ declare class CoseUnsupportedMacError extends CoseError {}
594
+ declare class CoseInvalidSignatureError extends CoseError {}
595
+ declare class CoseInvalidAlgorithmError extends CoseError {}
596
+ declare class CosePayloadMustBeNullError extends CoseError {}
597
+ declare class CosePayloadMustBeDefinedError extends CoseError {}
598
+ declare class CosePayloadInvalidStructureError extends CoseError {}
599
+ declare class CoseInvalidTypeForKeyError extends CoseError {}
600
+ declare class CoseInvalidValueForKtyError extends CoseError {}
601
+ declare class CoseInvalidKtyForRawError extends CoseError {}
602
+ declare class CoseXNotDefinedError extends CoseError {}
603
+ declare class CoseYNotDefinedError extends CoseError {}
604
+ declare class CoseDNotDefinedError extends CoseError {}
605
+ declare class CoseKNotDefinedError extends CoseError {}
606
+ declare class CoseEphemeralMacKeyIsRequiredError extends CoseError {}
607
+ declare class CoseCertificateNotFoundError extends CoseError {}
608
+ declare class CoseKeyTypeNotSupportedForPrivateKeyExtractionError extends CoseError {}
609
+ //#endregion
610
+ //#region src/utils/zod.d.ts
611
+ declare const zUint8Array: z$1.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
612
+ //#endregion
613
+ //#region src/utils/zod-error.d.ts
614
+ declare class ValidationError extends Error {
615
+ zodError: ZodError | undefined;
616
+ constructor(message: string, zodError?: ZodError);
617
+ }
618
+ //#endregion
619
+ export { AnyCborStructure, CborEncodeOptions, CborOptions, CborStructure, CborStructureStaticThis, CoseCertificateNotFoundError, CoseDNotDefinedError, CoseEphemeralMacKeyIsRequiredError, CoseInvalidAlgorithmError, CoseInvalidKtyForRawError, CoseInvalidSignatureError, CoseInvalidTypeForKeyError, CoseInvalidValueForKtyError, CoseKNotDefinedError, CoseKey, CoseKeyDecodedStructure, CoseKeyEncodedStructure, CoseKeyOptions, CoseKeyParameter, CoseKeyTypeNotSupportedForPrivateKeyExtractionError, CosePayloadInvalidStructureError, CosePayloadMustBeDefinedError, CosePayloadMustBeNullError, CoseUnsupportedMacError, CoseXNotDefinedError, CoseYNotDefinedError, Curve, Cwt, CwtOptions, DataItem, DataItemOptions, DateOnly, DecodedStructureType, DigestAlgorithm, EncodedStructureType, EncryptionAlgorithm, KeyOps, KeyType, Mac0, Mac0Context, Mac0DecodedStructure, Mac0EncodedStructure, Mac0Options, MacAlgorithm, ProtectedHeaderOptions, ProtectedHeaders, ProtectedHeadersDecodedStructure, ProtectedHeadersEncodedStructure, RegisteredCwtClaimKey, RegisteredCwtHeaderClaimKey, Sign1, Sign1Context, Sign1DecodedStructure, Sign1EncodedStructure, Sign1Options, SignatureAlgorithm, TypedMap, UnprotectedHeaderOptions, UnprotectedHeaders, UnprotectedHeadersStructure, ValidationError, addExtension, cborDecode, cborEncode, coseKeyToJwk, coseOptionsJwkMap, jwkCoseOptionsMap, jwkToCoseKey, mac0DecodedSchema, mac0EncodedSchema, protectedHeadersDecodedStructure, protectedHeadersEncodedStructure, sign1DecodedSchema, sign1EncodedSchema, typedMap, unprotectedHeadersStructure, zDataItemCodec, zUint8Array };
620
+ //# sourceMappingURL=index.d.mts.map