@govuk-one-login/mobile-wallet-mdoc-builder 0.0.0 → 0.1.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/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/index.cjs +53 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +150 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 GOV.UK One Login
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Mobile Wallet mdoc Builder
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
A TypeScript library for building mdoc (ISO 18013-5) documents for use with GOV.UK Wallet. It provides a type-safe API
|
|
8
|
+
for constructing and encoding mdoc-based credentials.
|
|
9
|
+
|
|
10
|
+
## Tech stack
|
|
11
|
+
|
|
12
|
+
Built with TypeScript and Node.js, published as a dual-format (ESM and CJS) npm package.
|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
|
|
16
|
+
- [Node.js](https://nodejs.org/en) — we recommend managing versions with [nvm](https://github.com/nvm-sh/nvm)
|
|
17
|
+
- [Pre-commit](https://pre-commit.com/)
|
|
18
|
+
|
|
19
|
+
## Set up locally
|
|
20
|
+
|
|
21
|
+
### Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
nvm use
|
|
25
|
+
npm install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Lint and format
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm run lint
|
|
32
|
+
npm run format
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Type check
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm run typecheck
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Build
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm run build
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Contributing
|
|
48
|
+
|
|
49
|
+
This project uses [pre-commit](https://pre-commit.com/) to enforce code quality and validate commit messages against [Conventional Commits](https://www.conventionalcommits.org/) standards. Non-conforming messages will be rejected.
|
|
50
|
+
|
|
51
|
+
Ensure your branch is up to date and all hooks pass before opening a pull request. Avoid using the git `--no-verify` flag to skip these checks unless absolutely necessary.
|
|
52
|
+
|
|
53
|
+
### Installing pre-commit hooks
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
brew install pre-commit
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pre-commit install --hook-type pre-commit --hook-type commit-msg
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Documentation
|
|
64
|
+
|
|
65
|
+
- [Release process](docs/release-process.md)
|
|
66
|
+
- [Component architecture](docs/component-architecture.md)
|
|
67
|
+
- [CBOR test guide](docs/cbor-test-guide.md)
|
|
68
|
+
|
|
69
|
+
## Licence
|
|
70
|
+
|
|
71
|
+
[MIT License](LICENSE)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/types/dateFormat.ts
|
|
3
|
+
/**
|
|
4
|
+
* Specifies the date encoding format for a data element.
|
|
5
|
+
*
|
|
6
|
+
* Used to indicate whether a Date value should be encoded as a full-date
|
|
7
|
+
* (YYYY-MM-DD) or a date-time (ISO 8601 with time component) in the
|
|
8
|
+
* resulting CBOR structure.
|
|
9
|
+
*/
|
|
10
|
+
let DateFormat = /* @__PURE__ */ function(DateFormat) {
|
|
11
|
+
/** Encode as a full-date (YYYY-MM-DD) per RFC 3339. */
|
|
12
|
+
DateFormat[DateFormat["FullDate"] = 0] = "FullDate";
|
|
13
|
+
/** Encode as a date-time (YYYY-MM-DDTHH:mm:ssZ) per RFC 3339. */
|
|
14
|
+
DateFormat[DateFormat["DateTime"] = 1] = "DateTime";
|
|
15
|
+
return DateFormat;
|
|
16
|
+
}({});
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/types/mdocBuilderError.ts
|
|
19
|
+
/**
|
|
20
|
+
* Error thrown by the mdoc builder when construction or signing fails.
|
|
21
|
+
*
|
|
22
|
+
* The error structure will be refined as implementation progresses
|
|
23
|
+
* (e.g., aggregated validation errors may be added later).
|
|
24
|
+
*/
|
|
25
|
+
var MdocBuilderError = class extends Error {
|
|
26
|
+
constructor(message, options) {
|
|
27
|
+
super(message, options);
|
|
28
|
+
this.name = "MdocBuilderError";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/index.ts
|
|
33
|
+
/**
|
|
34
|
+
* Builds an mdoc (ISO 18013-5) document from the provided input.
|
|
35
|
+
*
|
|
36
|
+
* @param input - The mdoc builder input containing document data and metadata.
|
|
37
|
+
* @param sign - A signing function that will be called with the data to sign.
|
|
38
|
+
* @returns A promise resolving to the built Mdoc document.
|
|
39
|
+
* @throws {MdocBuilderError} Always throws until implementation is complete.
|
|
40
|
+
*/
|
|
41
|
+
function buildMdoc(input, sign) {
|
|
42
|
+
console.log("buildMdoc not implemented", {
|
|
43
|
+
input,
|
|
44
|
+
sign
|
|
45
|
+
});
|
|
46
|
+
return Promise.reject(new MdocBuilderError("not implemented"));
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.DateFormat = DateFormat;
|
|
50
|
+
exports.MdocBuilderError = MdocBuilderError;
|
|
51
|
+
exports.buildMdoc = buildMdoc;
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/types/dateFormat.ts","../src/types/mdocBuilderError.ts","../src/index.ts"],"sourcesContent":["/**\n * Specifies the date encoding format for a data element.\n *\n * Used to indicate whether a Date value should be encoded as a full-date\n * (YYYY-MM-DD) or a date-time (ISO 8601 with time component) in the\n * resulting CBOR structure.\n */\nexport enum DateFormat {\n /** Encode as a full-date (YYYY-MM-DD) per RFC 3339. */\n FullDate = 0,\n\n /** Encode as a date-time (YYYY-MM-DDTHH:mm:ssZ) per RFC 3339. */\n DateTime = 1,\n}\n","/**\n * Error thrown by the mdoc builder when construction or signing fails.\n *\n * The error structure will be refined as implementation progresses\n * (e.g., aggregated validation errors may be added later).\n */\nexport class MdocBuilderError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = \"MdocBuilderError\";\n }\n}\n","export { DateFormat, MdocBuilderError } from \"./types\";\nexport type {\n PrimitiveElementValue,\n DataElementValue,\n DataElement,\n NameSpaces,\n CredentialValidity,\n StatusList,\n MdocBuilderInput,\n SigningFunction,\n Mdoc,\n} from \"./types\";\nimport type { Mdoc, MdocBuilderInput, SigningFunction } from \"./types\";\nimport { MdocBuilderError } from \"./types\";\n\n/**\n * Builds an mdoc (ISO 18013-5) document from the provided input.\n *\n * @param input - The mdoc builder input containing document data and metadata.\n * @param sign - A signing function that will be called with the data to sign.\n * @returns A promise resolving to the built Mdoc document.\n * @throws {MdocBuilderError} Always throws until implementation is complete.\n */\nexport function buildMdoc(\n input: MdocBuilderInput,\n sign: SigningFunction,\n): Promise<Mdoc> {\n console.log(\"buildMdoc not implemented\", { input, sign });\n return Promise.reject(new MdocBuilderError(\"not implemented\"));\n}\n"],"mappings":";;;;;;;;;AAOA,IAAY,aAAL,yBAAA,YAAA;;CAEL,WAAA,WAAA,cAAA,KAAA;;CAGA,WAAA,WAAA,cAAA,KAAA;;AACF,EAAA,CAAA,CAAA;;;;;;;;;ACPA,IAAa,mBAAb,cAAsC,MAAM;CAC1C,YAAY,SAAiB,SAAwB;EACnD,MAAM,SAAS,OAAO;EACtB,KAAK,OAAO;CACd;AACF;;;;;;;;;;;ACYA,SAAgB,UACd,OACA,MACe;CACf,QAAQ,IAAI,6BAA6B;EAAE;EAAO;CAAK,CAAC;CACxD,OAAO,QAAQ,OAAO,IAAI,iBAAiB,iBAAiB,CAAC;AAC/D"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
//#region src/types/dateFormat.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Specifies the date encoding format for a data element.
|
|
4
|
+
*
|
|
5
|
+
* Used to indicate whether a Date value should be encoded as a full-date
|
|
6
|
+
* (YYYY-MM-DD) or a date-time (ISO 8601 with time component) in the
|
|
7
|
+
* resulting CBOR structure.
|
|
8
|
+
*/
|
|
9
|
+
declare enum DateFormat {
|
|
10
|
+
/** Encode as a full-date (YYYY-MM-DD) per RFC 3339. */
|
|
11
|
+
FullDate = 0,
|
|
12
|
+
/** Encode as a date-time (YYYY-MM-DDTHH:mm:ssZ) per RFC 3339. */
|
|
13
|
+
DateTime = 1,
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/types/dataElementValue.d.ts
|
|
17
|
+
/**
|
|
18
|
+
* The union of permitted scalar types for a data element value.
|
|
19
|
+
*
|
|
20
|
+
* These map to the CBOR major types used in ISO 18013-5 mdoc documents.
|
|
21
|
+
*/
|
|
22
|
+
type PrimitiveElementValue = string | number | boolean | Date | Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* The union of all permitted data element value types.
|
|
25
|
+
*
|
|
26
|
+
* A data element value can be a single primitive, an array of primitives,
|
|
27
|
+
* a map of string keys to primitives, or an array of such maps.
|
|
28
|
+
*/
|
|
29
|
+
type DataElementValue = PrimitiveElementValue | PrimitiveElementValue[] | Map<string, PrimitiveElementValue> | Map<string, PrimitiveElementValue>[];
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/types/dataElement.d.ts
|
|
32
|
+
/**
|
|
33
|
+
* A single data element within a namespace.
|
|
34
|
+
*
|
|
35
|
+
* Represents an identifier–value pair as defined in ISO 18013-5,
|
|
36
|
+
* with an optional date format hint for Date values.
|
|
37
|
+
*/
|
|
38
|
+
interface DataElement {
|
|
39
|
+
/** The element identifier (e.g. "family_name", "birth_date"). */
|
|
40
|
+
elementIdentifier: string;
|
|
41
|
+
/** The element value. */
|
|
42
|
+
elementValue: DataElementValue;
|
|
43
|
+
/** Optional format for Date values. Defaults to DateTime (Tag 0, tdate) when not specified. */
|
|
44
|
+
dateFormat?: DateFormat;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/types/nameSpaces.d.ts
|
|
48
|
+
/**
|
|
49
|
+
* A map of namespace identifiers to their data elements.
|
|
50
|
+
*
|
|
51
|
+
* Each key is a namespace string (e.g. "org.iso.18013.5.1") and each value
|
|
52
|
+
* is the array of data elements within that namespace. Uses Map to preserve
|
|
53
|
+
* insertion order for deterministic CBOR encoding.
|
|
54
|
+
*/
|
|
55
|
+
type NameSpaces = Map<string, DataElement[]>;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/types/credentialValidity.d.ts
|
|
58
|
+
/**
|
|
59
|
+
* Defines the validity period of a credential.
|
|
60
|
+
*
|
|
61
|
+
* Maps to the ValidityInfo structure in ISO 18013-5.
|
|
62
|
+
*/
|
|
63
|
+
interface CredentialValidity {
|
|
64
|
+
/** The earliest point in time from which the credential is valid. */
|
|
65
|
+
earliestValidFrom?: Date;
|
|
66
|
+
/** The point in time at which the credential expires. */
|
|
67
|
+
validUntil: Date;
|
|
68
|
+
/** The expected time at which the credential will be updated. */
|
|
69
|
+
expectedUpdate?: Date;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/types/statusList.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* A reference to a status list entry for credential revocation checking.
|
|
75
|
+
*/
|
|
76
|
+
interface StatusList {
|
|
77
|
+
/** The index of this credential's entry in the status list. */
|
|
78
|
+
idx: number;
|
|
79
|
+
/** The URI of the status list. */
|
|
80
|
+
uri: string;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/types/mdocBuilderInput.d.ts
|
|
84
|
+
/**
|
|
85
|
+
* The top-level input for building a mdoc document.
|
|
86
|
+
*/
|
|
87
|
+
interface MdocBuilderInput {
|
|
88
|
+
/** The document type (e.g. "org.iso.18013.5.1.mDL"). */
|
|
89
|
+
documentType: string;
|
|
90
|
+
/** The namespaces and their data elements to include in the mdoc. */
|
|
91
|
+
nameSpaces: NameSpaces;
|
|
92
|
+
/** The SPKI-encoded holder public key. */
|
|
93
|
+
deviceKey: Uint8Array;
|
|
94
|
+
/** The validity period of the credential. */
|
|
95
|
+
credentialValidity: CredentialValidity;
|
|
96
|
+
/** A reference to a status list for revocation checking. */
|
|
97
|
+
statusList: StatusList;
|
|
98
|
+
/**
|
|
99
|
+
* Array of DER-encoded certificates. The library will use
|
|
100
|
+
* certificateChain[0] as the document signing certificate.
|
|
101
|
+
*/
|
|
102
|
+
certificateChain: Uint8Array[];
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/types/signingFunction.d.ts
|
|
106
|
+
/**
|
|
107
|
+
* A function that signs the provided data and returns the signature.
|
|
108
|
+
*
|
|
109
|
+
* @param toBeSigned - The bytes to be signed.
|
|
110
|
+
* @returns A promise resolving to the signature bytes.
|
|
111
|
+
*/
|
|
112
|
+
type SigningFunction = (toBeSigned: Uint8Array) => Promise<Uint8Array>;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/types/mdoc.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* A built mdoc document with multiple output format options.
|
|
117
|
+
*/
|
|
118
|
+
interface Mdoc {
|
|
119
|
+
/** Returns the mdoc encoded as a base64url string. */
|
|
120
|
+
asBase64Url(): string;
|
|
121
|
+
/** Returns the mdoc encoded as a hexadecimal string. */
|
|
122
|
+
asHex(): string;
|
|
123
|
+
/** Returns the mdoc as raw bytes. */
|
|
124
|
+
asBytes(): Uint8Array;
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/types/mdocBuilderError.d.ts
|
|
128
|
+
/**
|
|
129
|
+
* Error thrown by the mdoc builder when construction or signing fails.
|
|
130
|
+
*
|
|
131
|
+
* The error structure will be refined as implementation progresses
|
|
132
|
+
* (e.g., aggregated validation errors may be added later).
|
|
133
|
+
*/
|
|
134
|
+
declare class MdocBuilderError extends Error {
|
|
135
|
+
constructor(message: string, options?: ErrorOptions);
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/index.d.ts
|
|
139
|
+
/**
|
|
140
|
+
* Builds an mdoc (ISO 18013-5) document from the provided input.
|
|
141
|
+
*
|
|
142
|
+
* @param input - The mdoc builder input containing document data and metadata.
|
|
143
|
+
* @param sign - A signing function that will be called with the data to sign.
|
|
144
|
+
* @returns A promise resolving to the built Mdoc document.
|
|
145
|
+
* @throws {MdocBuilderError} Always throws until implementation is complete.
|
|
146
|
+
*/
|
|
147
|
+
declare function buildMdoc(input: MdocBuilderInput, sign: SigningFunction): Promise<Mdoc>;
|
|
148
|
+
//#endregion
|
|
149
|
+
export { type CredentialValidity, type DataElement, type DataElementValue, DateFormat, type Mdoc, MdocBuilderError, type MdocBuilderInput, type NameSpaces, type PrimitiveElementValue, type SigningFunction, type StatusList, buildMdoc };
|
|
150
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
//#region src/types/dateFormat.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Specifies the date encoding format for a data element.
|
|
4
|
+
*
|
|
5
|
+
* Used to indicate whether a Date value should be encoded as a full-date
|
|
6
|
+
* (YYYY-MM-DD) or a date-time (ISO 8601 with time component) in the
|
|
7
|
+
* resulting CBOR structure.
|
|
8
|
+
*/
|
|
9
|
+
declare enum DateFormat {
|
|
10
|
+
/** Encode as a full-date (YYYY-MM-DD) per RFC 3339. */
|
|
11
|
+
FullDate = 0,
|
|
12
|
+
/** Encode as a date-time (YYYY-MM-DDTHH:mm:ssZ) per RFC 3339. */
|
|
13
|
+
DateTime = 1,
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/types/dataElementValue.d.ts
|
|
17
|
+
/**
|
|
18
|
+
* The union of permitted scalar types for a data element value.
|
|
19
|
+
*
|
|
20
|
+
* These map to the CBOR major types used in ISO 18013-5 mdoc documents.
|
|
21
|
+
*/
|
|
22
|
+
type PrimitiveElementValue = string | number | boolean | Date | Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* The union of all permitted data element value types.
|
|
25
|
+
*
|
|
26
|
+
* A data element value can be a single primitive, an array of primitives,
|
|
27
|
+
* a map of string keys to primitives, or an array of such maps.
|
|
28
|
+
*/
|
|
29
|
+
type DataElementValue = PrimitiveElementValue | PrimitiveElementValue[] | Map<string, PrimitiveElementValue> | Map<string, PrimitiveElementValue>[];
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/types/dataElement.d.ts
|
|
32
|
+
/**
|
|
33
|
+
* A single data element within a namespace.
|
|
34
|
+
*
|
|
35
|
+
* Represents an identifier–value pair as defined in ISO 18013-5,
|
|
36
|
+
* with an optional date format hint for Date values.
|
|
37
|
+
*/
|
|
38
|
+
interface DataElement {
|
|
39
|
+
/** The element identifier (e.g. "family_name", "birth_date"). */
|
|
40
|
+
elementIdentifier: string;
|
|
41
|
+
/** The element value. */
|
|
42
|
+
elementValue: DataElementValue;
|
|
43
|
+
/** Optional format for Date values. Defaults to DateTime (Tag 0, tdate) when not specified. */
|
|
44
|
+
dateFormat?: DateFormat;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/types/nameSpaces.d.ts
|
|
48
|
+
/**
|
|
49
|
+
* A map of namespace identifiers to their data elements.
|
|
50
|
+
*
|
|
51
|
+
* Each key is a namespace string (e.g. "org.iso.18013.5.1") and each value
|
|
52
|
+
* is the array of data elements within that namespace. Uses Map to preserve
|
|
53
|
+
* insertion order for deterministic CBOR encoding.
|
|
54
|
+
*/
|
|
55
|
+
type NameSpaces = Map<string, DataElement[]>;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/types/credentialValidity.d.ts
|
|
58
|
+
/**
|
|
59
|
+
* Defines the validity period of a credential.
|
|
60
|
+
*
|
|
61
|
+
* Maps to the ValidityInfo structure in ISO 18013-5.
|
|
62
|
+
*/
|
|
63
|
+
interface CredentialValidity {
|
|
64
|
+
/** The earliest point in time from which the credential is valid. */
|
|
65
|
+
earliestValidFrom?: Date;
|
|
66
|
+
/** The point in time at which the credential expires. */
|
|
67
|
+
validUntil: Date;
|
|
68
|
+
/** The expected time at which the credential will be updated. */
|
|
69
|
+
expectedUpdate?: Date;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/types/statusList.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* A reference to a status list entry for credential revocation checking.
|
|
75
|
+
*/
|
|
76
|
+
interface StatusList {
|
|
77
|
+
/** The index of this credential's entry in the status list. */
|
|
78
|
+
idx: number;
|
|
79
|
+
/** The URI of the status list. */
|
|
80
|
+
uri: string;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/types/mdocBuilderInput.d.ts
|
|
84
|
+
/**
|
|
85
|
+
* The top-level input for building a mdoc document.
|
|
86
|
+
*/
|
|
87
|
+
interface MdocBuilderInput {
|
|
88
|
+
/** The document type (e.g. "org.iso.18013.5.1.mDL"). */
|
|
89
|
+
documentType: string;
|
|
90
|
+
/** The namespaces and their data elements to include in the mdoc. */
|
|
91
|
+
nameSpaces: NameSpaces;
|
|
92
|
+
/** The SPKI-encoded holder public key. */
|
|
93
|
+
deviceKey: Uint8Array;
|
|
94
|
+
/** The validity period of the credential. */
|
|
95
|
+
credentialValidity: CredentialValidity;
|
|
96
|
+
/** A reference to a status list for revocation checking. */
|
|
97
|
+
statusList: StatusList;
|
|
98
|
+
/**
|
|
99
|
+
* Array of DER-encoded certificates. The library will use
|
|
100
|
+
* certificateChain[0] as the document signing certificate.
|
|
101
|
+
*/
|
|
102
|
+
certificateChain: Uint8Array[];
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/types/signingFunction.d.ts
|
|
106
|
+
/**
|
|
107
|
+
* A function that signs the provided data and returns the signature.
|
|
108
|
+
*
|
|
109
|
+
* @param toBeSigned - The bytes to be signed.
|
|
110
|
+
* @returns A promise resolving to the signature bytes.
|
|
111
|
+
*/
|
|
112
|
+
type SigningFunction = (toBeSigned: Uint8Array) => Promise<Uint8Array>;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/types/mdoc.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* A built mdoc document with multiple output format options.
|
|
117
|
+
*/
|
|
118
|
+
interface Mdoc {
|
|
119
|
+
/** Returns the mdoc encoded as a base64url string. */
|
|
120
|
+
asBase64Url(): string;
|
|
121
|
+
/** Returns the mdoc encoded as a hexadecimal string. */
|
|
122
|
+
asHex(): string;
|
|
123
|
+
/** Returns the mdoc as raw bytes. */
|
|
124
|
+
asBytes(): Uint8Array;
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/types/mdocBuilderError.d.ts
|
|
128
|
+
/**
|
|
129
|
+
* Error thrown by the mdoc builder when construction or signing fails.
|
|
130
|
+
*
|
|
131
|
+
* The error structure will be refined as implementation progresses
|
|
132
|
+
* (e.g., aggregated validation errors may be added later).
|
|
133
|
+
*/
|
|
134
|
+
declare class MdocBuilderError extends Error {
|
|
135
|
+
constructor(message: string, options?: ErrorOptions);
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/index.d.ts
|
|
139
|
+
/**
|
|
140
|
+
* Builds an mdoc (ISO 18013-5) document from the provided input.
|
|
141
|
+
*
|
|
142
|
+
* @param input - The mdoc builder input containing document data and metadata.
|
|
143
|
+
* @param sign - A signing function that will be called with the data to sign.
|
|
144
|
+
* @returns A promise resolving to the built Mdoc document.
|
|
145
|
+
* @throws {MdocBuilderError} Always throws until implementation is complete.
|
|
146
|
+
*/
|
|
147
|
+
declare function buildMdoc(input: MdocBuilderInput, sign: SigningFunction): Promise<Mdoc>;
|
|
148
|
+
//#endregion
|
|
149
|
+
export { type CredentialValidity, type DataElement, type DataElementValue, DateFormat, type Mdoc, MdocBuilderError, type MdocBuilderInput, type NameSpaces, type PrimitiveElementValue, type SigningFunction, type StatusList, buildMdoc };
|
|
150
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/types/dateFormat.ts
|
|
2
|
+
/**
|
|
3
|
+
* Specifies the date encoding format for a data element.
|
|
4
|
+
*
|
|
5
|
+
* Used to indicate whether a Date value should be encoded as a full-date
|
|
6
|
+
* (YYYY-MM-DD) or a date-time (ISO 8601 with time component) in the
|
|
7
|
+
* resulting CBOR structure.
|
|
8
|
+
*/
|
|
9
|
+
let DateFormat = /* @__PURE__ */ function(DateFormat) {
|
|
10
|
+
/** Encode as a full-date (YYYY-MM-DD) per RFC 3339. */
|
|
11
|
+
DateFormat[DateFormat["FullDate"] = 0] = "FullDate";
|
|
12
|
+
/** Encode as a date-time (YYYY-MM-DDTHH:mm:ssZ) per RFC 3339. */
|
|
13
|
+
DateFormat[DateFormat["DateTime"] = 1] = "DateTime";
|
|
14
|
+
return DateFormat;
|
|
15
|
+
}({});
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/types/mdocBuilderError.ts
|
|
18
|
+
/**
|
|
19
|
+
* Error thrown by the mdoc builder when construction or signing fails.
|
|
20
|
+
*
|
|
21
|
+
* The error structure will be refined as implementation progresses
|
|
22
|
+
* (e.g., aggregated validation errors may be added later).
|
|
23
|
+
*/
|
|
24
|
+
var MdocBuilderError = class extends Error {
|
|
25
|
+
constructor(message, options) {
|
|
26
|
+
super(message, options);
|
|
27
|
+
this.name = "MdocBuilderError";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/index.ts
|
|
32
|
+
/**
|
|
33
|
+
* Builds an mdoc (ISO 18013-5) document from the provided input.
|
|
34
|
+
*
|
|
35
|
+
* @param input - The mdoc builder input containing document data and metadata.
|
|
36
|
+
* @param sign - A signing function that will be called with the data to sign.
|
|
37
|
+
* @returns A promise resolving to the built Mdoc document.
|
|
38
|
+
* @throws {MdocBuilderError} Always throws until implementation is complete.
|
|
39
|
+
*/
|
|
40
|
+
function buildMdoc(input, sign) {
|
|
41
|
+
console.log("buildMdoc not implemented", {
|
|
42
|
+
input,
|
|
43
|
+
sign
|
|
44
|
+
});
|
|
45
|
+
return Promise.reject(new MdocBuilderError("not implemented"));
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { DateFormat, MdocBuilderError, buildMdoc };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/types/dateFormat.ts","../src/types/mdocBuilderError.ts","../src/index.ts"],"sourcesContent":["/**\n * Specifies the date encoding format for a data element.\n *\n * Used to indicate whether a Date value should be encoded as a full-date\n * (YYYY-MM-DD) or a date-time (ISO 8601 with time component) in the\n * resulting CBOR structure.\n */\nexport enum DateFormat {\n /** Encode as a full-date (YYYY-MM-DD) per RFC 3339. */\n FullDate = 0,\n\n /** Encode as a date-time (YYYY-MM-DDTHH:mm:ssZ) per RFC 3339. */\n DateTime = 1,\n}\n","/**\n * Error thrown by the mdoc builder when construction or signing fails.\n *\n * The error structure will be refined as implementation progresses\n * (e.g., aggregated validation errors may be added later).\n */\nexport class MdocBuilderError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = \"MdocBuilderError\";\n }\n}\n","export { DateFormat, MdocBuilderError } from \"./types\";\nexport type {\n PrimitiveElementValue,\n DataElementValue,\n DataElement,\n NameSpaces,\n CredentialValidity,\n StatusList,\n MdocBuilderInput,\n SigningFunction,\n Mdoc,\n} from \"./types\";\nimport type { Mdoc, MdocBuilderInput, SigningFunction } from \"./types\";\nimport { MdocBuilderError } from \"./types\";\n\n/**\n * Builds an mdoc (ISO 18013-5) document from the provided input.\n *\n * @param input - The mdoc builder input containing document data and metadata.\n * @param sign - A signing function that will be called with the data to sign.\n * @returns A promise resolving to the built Mdoc document.\n * @throws {MdocBuilderError} Always throws until implementation is complete.\n */\nexport function buildMdoc(\n input: MdocBuilderInput,\n sign: SigningFunction,\n): Promise<Mdoc> {\n console.log(\"buildMdoc not implemented\", { input, sign });\n return Promise.reject(new MdocBuilderError(\"not implemented\"));\n}\n"],"mappings":";;;;;;;;AAOA,IAAY,aAAL,yBAAA,YAAA;;CAEL,WAAA,WAAA,cAAA,KAAA;;CAGA,WAAA,WAAA,cAAA,KAAA;;AACF,EAAA,CAAA,CAAA;;;;;;;;;ACPA,IAAa,mBAAb,cAAsC,MAAM;CAC1C,YAAY,SAAiB,SAAwB;EACnD,MAAM,SAAS,OAAO;EACtB,KAAK,OAAO;CACd;AACF;;;;;;;;;;;ACYA,SAAgB,UACd,OACA,MACe;CACf,QAAQ,IAAI,6BAA6B;EAAE;EAAO;CAAK,CAAC;CACxD,OAAO,QAAQ,OAAO,IAAI,iBAAiB,iBAAiB,CAAC;AAC/D"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@govuk-one-login/mobile-wallet-mdoc-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/govuk-one-login/mobile-wallet-mdoc-builder.git"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=22"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.cjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsdown",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"lint": "eslint .",
|
|
33
|
+
"format": "prettier --write .",
|
|
34
|
+
"format:check": "prettier --check .",
|
|
35
|
+
"test": "vitest run --coverage",
|
|
36
|
+
"test:component": "npm run build && vitest run --config vitest.config.component.ts",
|
|
37
|
+
"test:component:ci": "vitest run --config vitest.config.component.ts",
|
|
38
|
+
"publish-v0-to-npm": "./publish-v0-to-npm.sh"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^26.0.1",
|
|
42
|
+
"@vitest/coverage-v8": "^5.0.0",
|
|
43
|
+
"eslint": "^9.0.0",
|
|
44
|
+
"prettier": "^3.0.0",
|
|
45
|
+
"tsdown": "^0.12.0",
|
|
46
|
+
"typescript": "^5.0.0",
|
|
47
|
+
"typescript-eslint": "^8.0.0",
|
|
48
|
+
"vitest": "^5.0.0"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"cbor2": "2.3.0",
|
|
52
|
+
"zod": "4.4.3"
|
|
53
|
+
}
|
|
4
54
|
}
|
|
5
|
-
|