@twin.org/notarization-service 0.0.3-next.1
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 +201 -0
- package/README.md +21 -0
- package/dist/es/index.js +8 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/INotarizationServiceConfig.js +4 -0
- package/dist/es/models/INotarizationServiceConfig.js.map +1 -0
- package/dist/es/models/INotarizationServiceConstructorOptions.js +2 -0
- package/dist/es/models/INotarizationServiceConstructorOptions.js.map +1 -0
- package/dist/es/notarizationRoutes.js +318 -0
- package/dist/es/notarizationRoutes.js.map +1 -0
- package/dist/es/notarizationService.js +151 -0
- package/dist/es/notarizationService.js.map +1 -0
- package/dist/es/restEntryPoints.js +10 -0
- package/dist/es/restEntryPoints.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/models/INotarizationServiceConfig.d.ts +9 -0
- package/dist/types/models/INotarizationServiceConstructorOptions.d.ts +10 -0
- package/dist/types/notarizationRoutes.d.ts +53 -0
- package/dist/types/notarizationService.d.ts +57 -0
- package/dist/types/restEntryPoints.d.ts +2 -0
- package/docs/changelog.md +19 -0
- package/docs/examples.md +185 -0
- package/docs/open-api/spec.json +712 -0
- package/docs/reference/classes/NotarizationService.md +219 -0
- package/docs/reference/functions/generateRestRoutesNotarization.md +25 -0
- package/docs/reference/functions/notarizationCreate.md +31 -0
- package/docs/reference/functions/notarizationGet.md +31 -0
- package/docs/reference/functions/notarizationRemove.md +31 -0
- package/docs/reference/functions/notarizationTransfer.md +31 -0
- package/docs/reference/functions/notarizationUpdate.md +31 -0
- package/docs/reference/index.md +24 -0
- package/docs/reference/interfaces/INotarizationServiceConfig.md +11 -0
- package/docs/reference/interfaces/INotarizationServiceConstructorOptions.md +11 -0
- package/docs/reference/variables/restEntryPoints.md +3 -0
- package/docs/reference/variables/tagsNotarization.md +5 -0
- package/locales/en.json +13 -0
- package/package.json +58 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { GeneralError, Guards, Urn } from "@twin.org/core";
|
|
4
|
+
import { NotarizationConnectorFactory } from "@twin.org/notarization-models";
|
|
5
|
+
/**
|
|
6
|
+
* Service for notarization operations.
|
|
7
|
+
*/
|
|
8
|
+
export class NotarizationService {
|
|
9
|
+
/**
|
|
10
|
+
* Runtime name for the class.
|
|
11
|
+
*/
|
|
12
|
+
static CLASS_NAME = "NotarizationService";
|
|
13
|
+
/**
|
|
14
|
+
* The namespace supported by the notarization service.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
static _NAMESPACE = "notarization";
|
|
18
|
+
/**
|
|
19
|
+
* The default namespace for the connector to use.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
_defaultNamespace;
|
|
23
|
+
/**
|
|
24
|
+
* Create a new instance of NotarizationService.
|
|
25
|
+
* @param options The constructor options.
|
|
26
|
+
*/
|
|
27
|
+
constructor(options) {
|
|
28
|
+
const names = NotarizationConnectorFactory.names();
|
|
29
|
+
if (names.length === 0) {
|
|
30
|
+
throw new GeneralError(NotarizationService.CLASS_NAME, "noConnectors");
|
|
31
|
+
}
|
|
32
|
+
this._defaultNamespace = options?.config?.defaultNamespace ?? names[0];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns the class name of the component.
|
|
36
|
+
* @returns The class name of the component.
|
|
37
|
+
*/
|
|
38
|
+
className() {
|
|
39
|
+
return NotarizationService.CLASS_NAME;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a new notarization.
|
|
43
|
+
* @param notarization The notarization data without generated fields.
|
|
44
|
+
* @param namespace The namespace of the connector to use for the notarization, defaults to service configured namespace.
|
|
45
|
+
* @param controllerIdentity The identity to perform the notarization operation with.
|
|
46
|
+
* @returns The generated notarization id.
|
|
47
|
+
*/
|
|
48
|
+
async create(notarization, namespace, controllerIdentity) {
|
|
49
|
+
Guards.object(NotarizationService.CLASS_NAME, "notarization", notarization);
|
|
50
|
+
if (namespace !== undefined) {
|
|
51
|
+
Guards.stringValue(NotarizationService.CLASS_NAME, "namespace", namespace);
|
|
52
|
+
}
|
|
53
|
+
Guards.stringValue(NotarizationService.CLASS_NAME, "controllerIdentity", controllerIdentity);
|
|
54
|
+
try {
|
|
55
|
+
const connectorNamespace = namespace ?? this._defaultNamespace;
|
|
56
|
+
const notarizationConnector = NotarizationConnectorFactory.get(connectorNamespace);
|
|
57
|
+
const notarizationId = await notarizationConnector.create(controllerIdentity, notarization);
|
|
58
|
+
return notarizationId;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new GeneralError(NotarizationService.CLASS_NAME, "createFailed", undefined, error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get an existing notarization.
|
|
66
|
+
* @param id The id of the notarization to get.
|
|
67
|
+
* @returns The notarization.
|
|
68
|
+
*/
|
|
69
|
+
async get(id) {
|
|
70
|
+
Urn.guard(NotarizationService.CLASS_NAME, "id", id);
|
|
71
|
+
try {
|
|
72
|
+
const notarizationConnector = this.getConnector(id);
|
|
73
|
+
const result = await notarizationConnector.get(id);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw new GeneralError(NotarizationService.CLASS_NAME, "getFailed", undefined, error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Remove an existing notarization.
|
|
82
|
+
* @param id The id of the notarization to remove.
|
|
83
|
+
* @param controllerIdentity The identity to perform the notarization operation with.
|
|
84
|
+
* @returns Nothing.
|
|
85
|
+
*/
|
|
86
|
+
async remove(id, controllerIdentity) {
|
|
87
|
+
Urn.guard(NotarizationService.CLASS_NAME, "id", id);
|
|
88
|
+
Guards.stringValue(NotarizationService.CLASS_NAME, "controllerIdentity", controllerIdentity);
|
|
89
|
+
try {
|
|
90
|
+
const notarizationConnector = this.getConnector(id);
|
|
91
|
+
await notarizationConnector.remove(controllerIdentity, id);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw new GeneralError(NotarizationService.CLASS_NAME, "removeFailed", undefined, error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Update an existing notarization.
|
|
99
|
+
* @param notarization The notarization to update.
|
|
100
|
+
* @param controllerIdentity The identity to perform the notarization operation with.
|
|
101
|
+
* @returns Nothing.
|
|
102
|
+
*/
|
|
103
|
+
async update(notarization, controllerIdentity) {
|
|
104
|
+
Guards.object(NotarizationService.CLASS_NAME, "notarization", notarization);
|
|
105
|
+
Urn.guard(NotarizationService.CLASS_NAME, "notarization.id", notarization.id);
|
|
106
|
+
Guards.stringValue(NotarizationService.CLASS_NAME, "controllerIdentity", controllerIdentity);
|
|
107
|
+
try {
|
|
108
|
+
const notarizationConnector = this.getConnector(notarization.id);
|
|
109
|
+
await notarizationConnector.update(controllerIdentity, notarization);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
throw new GeneralError(NotarizationService.CLASS_NAME, "updateFailed", undefined, error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Transfer an existing notarization.
|
|
117
|
+
* @param id The id of the notarization to transfer.
|
|
118
|
+
* @param recipientAddress The recipient address.
|
|
119
|
+
* @param controllerIdentity The identity to perform the notarization operation with.
|
|
120
|
+
* @returns Nothing.
|
|
121
|
+
*/
|
|
122
|
+
async transfer(id, recipientAddress, controllerIdentity) {
|
|
123
|
+
Urn.guard(NotarizationService.CLASS_NAME, "id", id);
|
|
124
|
+
Guards.stringValue(NotarizationService.CLASS_NAME, "recipientAddress", recipientAddress);
|
|
125
|
+
Guards.stringValue(NotarizationService.CLASS_NAME, "controllerIdentity", controllerIdentity);
|
|
126
|
+
try {
|
|
127
|
+
const notarizationConnector = this.getConnector(id);
|
|
128
|
+
await notarizationConnector.transfer(controllerIdentity, id, recipientAddress);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
throw new GeneralError(NotarizationService.CLASS_NAME, "transferFailed", undefined, error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get the connector from the id.
|
|
136
|
+
* @param id The id of the notarization in urn format.
|
|
137
|
+
* @returns The connector.
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
getConnector(id) {
|
|
141
|
+
const idUrn = Urn.fromValidString(id);
|
|
142
|
+
if (idUrn.namespaceIdentifier() !== NotarizationService._NAMESPACE) {
|
|
143
|
+
throw new GeneralError(NotarizationService.CLASS_NAME, "namespaceMismatch", {
|
|
144
|
+
namespace: NotarizationService._NAMESPACE,
|
|
145
|
+
id
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return NotarizationConnectorFactory.get(idUrn.namespaceMethod());
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=notarizationService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notarizationService.js","sourceRoot":"","sources":["../../src/notarizationService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EACN,4BAA4B,EAI5B,MAAM,+BAA+B,CAAC;AAGvC;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAC/B;;OAEG;IACI,MAAM,CAAU,UAAU,yBAAyC;IAE1E;;;OAGG;IACK,MAAM,CAAU,UAAU,GAAW,cAAc,CAAC;IAE5D;;;OAGG;IACc,iBAAiB,CAAS;IAE3C;;;OAGG;IACH,YAAY,OAAgD;QAC3D,MAAM,KAAK,GAAG,4BAA4B,CAAC,KAAK,EAAE,CAAC;QACnD,IAAI,KAAK,CAAC,MAAM,KAA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EAAE,mBAAmB,CAAC,UAAU;gBACzC,EAAE;aACF,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,4BAA4B,CAAC,GAAG,CAAyB,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC;IAC1F,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Urn } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tNotarizationConnectorFactory,\n\ttype INotarization,\n\ttype INotarizationComponent,\n\ttype INotarizationConnector\n} from \"@twin.org/notarization-models\";\nimport type { INotarizationServiceConstructorOptions } from \"./models/INotarizationServiceConstructorOptions.js\";\n\n/**\n * Service for notarization operations.\n */\nexport class NotarizationService implements INotarizationComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<NotarizationService>();\n\n\t/**\n\t * The namespace supported by the notarization service.\n\t * @internal\n\t */\n\tprivate static readonly _NAMESPACE: string = \"notarization\";\n\n\t/**\n\t * The default namespace for the connector to use.\n\t * @internal\n\t */\n\tprivate readonly _defaultNamespace: string;\n\n\t/**\n\t * Create a new instance of NotarizationService.\n\t * @param options The constructor options.\n\t */\n\tconstructor(options?: INotarizationServiceConstructorOptions) {\n\t\tconst names = NotarizationConnectorFactory.names();\n\t\tif (names.length === 0) {\n\t\t\tthrow new GeneralError(NotarizationService.CLASS_NAME, \"noConnectors\");\n\t\t}\n\n\t\tthis._defaultNamespace = options?.config?.defaultNamespace ?? names[0];\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn NotarizationService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new notarization.\n\t * @param notarization The notarization data without generated fields.\n\t * @param namespace The namespace of the connector to use for the notarization, defaults to service configured namespace.\n\t * @param controllerIdentity The identity to perform the notarization operation with.\n\t * @returns The generated notarization id.\n\t */\n\tpublic async create(\n\t\tnotarization: Omit<INotarization, \"id\" | \"dateCreated\">,\n\t\tnamespace?: string,\n\t\tcontrollerIdentity?: string\n\t): Promise<string> {\n\t\tGuards.object(NotarizationService.CLASS_NAME, nameof(notarization), notarization);\n\t\tif (namespace !== undefined) {\n\t\t\tGuards.stringValue(NotarizationService.CLASS_NAME, nameof(namespace), namespace);\n\t\t}\n\t\tGuards.stringValue(\n\t\t\tNotarizationService.CLASS_NAME,\n\t\t\tnameof(controllerIdentity),\n\t\t\tcontrollerIdentity\n\t\t);\n\n\t\ttry {\n\t\t\tconst connectorNamespace = namespace ?? this._defaultNamespace;\n\n\t\t\tconst notarizationConnector =\n\t\t\t\tNotarizationConnectorFactory.get<INotarizationConnector>(connectorNamespace);\n\n\t\t\tconst notarizationId = await notarizationConnector.create(controllerIdentity, notarization);\n\n\t\t\treturn notarizationId;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NotarizationService.CLASS_NAME, \"createFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get an existing notarization.\n\t * @param id The id of the notarization to get.\n\t * @returns The notarization.\n\t */\n\tpublic async get(id: string): Promise<INotarization> {\n\t\tUrn.guard(NotarizationService.CLASS_NAME, nameof(id), id);\n\n\t\ttry {\n\t\t\tconst notarizationConnector = this.getConnector(id);\n\t\t\tconst result = await notarizationConnector.get(id);\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NotarizationService.CLASS_NAME, \"getFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Remove an existing notarization.\n\t * @param id The id of the notarization to remove.\n\t * @param controllerIdentity The identity to perform the notarization operation with.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(id: string, controllerIdentity?: string): Promise<void> {\n\t\tUrn.guard(NotarizationService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(\n\t\t\tNotarizationService.CLASS_NAME,\n\t\t\tnameof(controllerIdentity),\n\t\t\tcontrollerIdentity\n\t\t);\n\n\t\ttry {\n\t\t\tconst notarizationConnector = this.getConnector(id);\n\t\t\tawait notarizationConnector.remove(controllerIdentity, id);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NotarizationService.CLASS_NAME, \"removeFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Update an existing notarization.\n\t * @param notarization The notarization to update.\n\t * @param controllerIdentity The identity to perform the notarization operation with.\n\t * @returns Nothing.\n\t */\n\tpublic async update(notarization: INotarization, controllerIdentity?: string): Promise<void> {\n\t\tGuards.object(NotarizationService.CLASS_NAME, nameof(notarization), notarization);\n\t\tUrn.guard(NotarizationService.CLASS_NAME, nameof(notarization.id), notarization.id);\n\t\tGuards.stringValue(\n\t\t\tNotarizationService.CLASS_NAME,\n\t\t\tnameof(controllerIdentity),\n\t\t\tcontrollerIdentity\n\t\t);\n\n\t\ttry {\n\t\t\tconst notarizationConnector = this.getConnector(notarization.id);\n\t\t\tawait notarizationConnector.update(controllerIdentity, notarization);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NotarizationService.CLASS_NAME, \"updateFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Transfer an existing notarization.\n\t * @param id The id of the notarization to transfer.\n\t * @param recipientAddress The recipient address.\n\t * @param controllerIdentity The identity to perform the notarization operation with.\n\t * @returns Nothing.\n\t */\n\tpublic async transfer(\n\t\tid: string,\n\t\trecipientAddress: string,\n\t\tcontrollerIdentity?: string\n\t): Promise<void> {\n\t\tUrn.guard(NotarizationService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(NotarizationService.CLASS_NAME, nameof(recipientAddress), recipientAddress);\n\t\tGuards.stringValue(\n\t\t\tNotarizationService.CLASS_NAME,\n\t\t\tnameof(controllerIdentity),\n\t\t\tcontrollerIdentity\n\t\t);\n\n\t\ttry {\n\t\t\tconst notarizationConnector = this.getConnector(id);\n\t\t\tawait notarizationConnector.transfer(controllerIdentity, id, recipientAddress);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NotarizationService.CLASS_NAME, \"transferFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get the connector from the id.\n\t * @param id The id of the notarization in urn format.\n\t * @returns The connector.\n\t * @internal\n\t */\n\tprivate getConnector(id: string): INotarizationConnector {\n\t\tconst idUrn = Urn.fromValidString(id);\n\n\t\tif (idUrn.namespaceIdentifier() !== NotarizationService._NAMESPACE) {\n\t\t\tthrow new GeneralError(NotarizationService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: NotarizationService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\treturn NotarizationConnectorFactory.get<INotarizationConnector>(idUrn.namespaceMethod());\n\t}\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { generateRestRoutesNotarization, tagsNotarization } from "./notarizationRoutes.js";
|
|
2
|
+
export const restEntryPoints = [
|
|
3
|
+
{
|
|
4
|
+
name: "notarization",
|
|
5
|
+
defaultBaseRoute: "notarization",
|
|
6
|
+
tags: tagsNotarization,
|
|
7
|
+
generateRoutes: generateRestRoutesNotarization
|
|
8
|
+
}
|
|
9
|
+
];
|
|
10
|
+
//# sourceMappingURL=restEntryPoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restEntryPoints.js","sourceRoot":"","sources":["../../src/restEntryPoints.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,8BAA8B,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3F,MAAM,CAAC,MAAM,eAAe,GAA2B;IACtD;QACC,IAAI,EAAE,cAAc;QACpB,gBAAgB,EAAE,cAAc;QAChC,IAAI,EAAE,gBAAgB;QACtB,cAAc,EAAE,8BAA8B;KAC9C;CACD,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRestRouteEntryPoint } from \"@twin.org/api-models\";\nimport { generateRestRoutesNotarization, tagsNotarization } from \"./notarizationRoutes.js\";\n\nexport const restEntryPoints: IRestRouteEntryPoint[] = [\n\t{\n\t\tname: \"notarization\",\n\t\tdefaultBaseRoute: \"notarization\",\n\t\ttags: tagsNotarization,\n\t\tgenerateRoutes: generateRestRoutesNotarization\n\t}\n];\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the Notarization Service.
|
|
3
|
+
*/
|
|
4
|
+
export interface INotarizationServiceConfig {
|
|
5
|
+
/**
|
|
6
|
+
* What is the default connector to use for notarization. If not provided the first connector from the factory will be used.
|
|
7
|
+
*/
|
|
8
|
+
defaultNamespace?: string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { INotarizationServiceConfig } from "./INotarizationServiceConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the notarization service constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface INotarizationServiceConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The configuration for the service.
|
|
8
|
+
*/
|
|
9
|
+
config?: INotarizationServiceConfig;
|
|
10
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ICreatedResponse, IHttpRequestContext, INoContentResponse, IRestRoute, ITag } from "@twin.org/api-models";
|
|
2
|
+
import type { INotarizationCreateRequest, INotarizationGetRequest, INotarizationGetResponse, INotarizationRemoveRequest, INotarizationTransferRequest, INotarizationUpdateRequest } from "@twin.org/notarization-models";
|
|
3
|
+
/**
|
|
4
|
+
* The tag to associate with the routes.
|
|
5
|
+
*/
|
|
6
|
+
export declare const tagsNotarization: ITag[];
|
|
7
|
+
/**
|
|
8
|
+
* The REST routes for notarization.
|
|
9
|
+
* @param baseRouteName Prefix to prepend to the paths.
|
|
10
|
+
* @param componentName The name of the component to use in the routes stored in the ComponentFactory.
|
|
11
|
+
* @returns The generated routes.
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateRestRoutesNotarization(baseRouteName: string, componentName: string): IRestRoute[];
|
|
14
|
+
/**
|
|
15
|
+
* Perform the create notarization operation.
|
|
16
|
+
* @param httpRequestContext The request context for the API.
|
|
17
|
+
* @param componentName The name of the component to use in the routes.
|
|
18
|
+
* @param request The request.
|
|
19
|
+
* @returns The response object with additional http response properties.
|
|
20
|
+
*/
|
|
21
|
+
export declare function notarizationCreate(httpRequestContext: IHttpRequestContext, componentName: string, request: INotarizationCreateRequest): Promise<ICreatedResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Perform the remove notarization operation.
|
|
24
|
+
* @param httpRequestContext The request context for the API.
|
|
25
|
+
* @param componentName The name of the component to use in the routes.
|
|
26
|
+
* @param request The request.
|
|
27
|
+
* @returns The response object with additional http response properties.
|
|
28
|
+
*/
|
|
29
|
+
export declare function notarizationRemove(httpRequestContext: IHttpRequestContext, componentName: string, request: INotarizationRemoveRequest): Promise<INoContentResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Perform the get notarization operation.
|
|
32
|
+
* @param httpRequestContext The request context for the API.
|
|
33
|
+
* @param componentName The name of the component to use in the routes.
|
|
34
|
+
* @param request The request.
|
|
35
|
+
* @returns The response object with additional http response properties.
|
|
36
|
+
*/
|
|
37
|
+
export declare function notarizationGet(httpRequestContext: IHttpRequestContext, componentName: string, request: INotarizationGetRequest): Promise<INotarizationGetResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Perform the update notarization operation.
|
|
40
|
+
* @param httpRequestContext The request context for the API.
|
|
41
|
+
* @param componentName The name of the component to use in the routes.
|
|
42
|
+
* @param request The request.
|
|
43
|
+
* @returns The response object with additional http response properties.
|
|
44
|
+
*/
|
|
45
|
+
export declare function notarizationUpdate(httpRequestContext: IHttpRequestContext, componentName: string, request: INotarizationUpdateRequest): Promise<INoContentResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Perform the transfer notarization operation.
|
|
48
|
+
* @param httpRequestContext The request context for the API.
|
|
49
|
+
* @param componentName The name of the component to use in the routes.
|
|
50
|
+
* @param request The request.
|
|
51
|
+
* @returns The response object with additional http response properties.
|
|
52
|
+
*/
|
|
53
|
+
export declare function notarizationTransfer(httpRequestContext: IHttpRequestContext, componentName: string, request: INotarizationTransferRequest): Promise<INoContentResponse>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type INotarization, type INotarizationComponent } from "@twin.org/notarization-models";
|
|
2
|
+
import type { INotarizationServiceConstructorOptions } from "./models/INotarizationServiceConstructorOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Service for notarization operations.
|
|
5
|
+
*/
|
|
6
|
+
export declare class NotarizationService implements INotarizationComponent {
|
|
7
|
+
/**
|
|
8
|
+
* Runtime name for the class.
|
|
9
|
+
*/
|
|
10
|
+
static readonly CLASS_NAME: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new instance of NotarizationService.
|
|
13
|
+
* @param options The constructor options.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options?: INotarizationServiceConstructorOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Returns the class name of the component.
|
|
18
|
+
* @returns The class name of the component.
|
|
19
|
+
*/
|
|
20
|
+
className(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Create a new notarization.
|
|
23
|
+
* @param notarization The notarization data without generated fields.
|
|
24
|
+
* @param namespace The namespace of the connector to use for the notarization, defaults to service configured namespace.
|
|
25
|
+
* @param controllerIdentity The identity to perform the notarization operation with.
|
|
26
|
+
* @returns The generated notarization id.
|
|
27
|
+
*/
|
|
28
|
+
create(notarization: Omit<INotarization, "id" | "dateCreated">, namespace?: string, controllerIdentity?: string): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Get an existing notarization.
|
|
31
|
+
* @param id The id of the notarization to get.
|
|
32
|
+
* @returns The notarization.
|
|
33
|
+
*/
|
|
34
|
+
get(id: string): Promise<INotarization>;
|
|
35
|
+
/**
|
|
36
|
+
* Remove an existing notarization.
|
|
37
|
+
* @param id The id of the notarization to remove.
|
|
38
|
+
* @param controllerIdentity The identity to perform the notarization operation with.
|
|
39
|
+
* @returns Nothing.
|
|
40
|
+
*/
|
|
41
|
+
remove(id: string, controllerIdentity?: string): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Update an existing notarization.
|
|
44
|
+
* @param notarization The notarization to update.
|
|
45
|
+
* @param controllerIdentity The identity to perform the notarization operation with.
|
|
46
|
+
* @returns Nothing.
|
|
47
|
+
*/
|
|
48
|
+
update(notarization: INotarization, controllerIdentity?: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Transfer an existing notarization.
|
|
51
|
+
* @param id The id of the notarization to transfer.
|
|
52
|
+
* @param recipientAddress The recipient address.
|
|
53
|
+
* @param controllerIdentity The identity to perform the notarization operation with.
|
|
54
|
+
* @returns Nothing.
|
|
55
|
+
*/
|
|
56
|
+
transfer(id: string, recipientAddress: string, controllerIdentity?: string): Promise<void>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.1](https://github.com/twinfoundation/notarization/compare/notarization-service-v0.0.3-next.0...notarization-service-v0.0.3-next.1) (2026-04-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* initial commit ([2271741](https://github.com/twinfoundation/notarization/commit/2271741a6f3daae544b24ccd47a5075a1a2eaaac))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/notarization-models bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
16
|
+
* devDependencies
|
|
17
|
+
* @twin.org/notarization-connector-entity-storage bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
18
|
+
|
|
19
|
+
## Changelog
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Notarization Service Examples
|
|
2
|
+
|
|
3
|
+
Use these snippets to compose connector-backed orchestration and expose HTTP route handlers for request processing.
|
|
4
|
+
|
|
5
|
+
## NotarizationService
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import {
|
|
9
|
+
NotarizationConnectorFactory,
|
|
10
|
+
NotarizationMode,
|
|
11
|
+
type INotarization,
|
|
12
|
+
type INotarizationConnector
|
|
13
|
+
} from '@twin.org/notarization-models';
|
|
14
|
+
import { NotarizationService } from '@twin.org/notarization-service';
|
|
15
|
+
|
|
16
|
+
class DemoConnector implements INotarizationConnector {
|
|
17
|
+
private readonly store: Map<string, INotarization>;
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
this.store = new Map<string, INotarization>();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public className(): string {
|
|
24
|
+
return 'DemoConnector';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async create(
|
|
28
|
+
controllerIdentity: string,
|
|
29
|
+
notarization: Omit<INotarization, 'id' | 'dateCreated'>
|
|
30
|
+
): Promise<string> {
|
|
31
|
+
const id = 'notarization:urn:notarization:demo:1';
|
|
32
|
+
this.store.set(id, {
|
|
33
|
+
...notarization,
|
|
34
|
+
id,
|
|
35
|
+
mode: notarization.mode ?? NotarizationMode.Dynamic,
|
|
36
|
+
dateCreated: new Date().toISOString()
|
|
37
|
+
});
|
|
38
|
+
return id;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public async get(id: string): Promise<INotarization> {
|
|
42
|
+
const value = this.store.get(id);
|
|
43
|
+
if (!value) {
|
|
44
|
+
throw new Error('Missing notarization');
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public async remove(controllerIdentity: string, id: string): Promise<void> {
|
|
50
|
+
this.store.delete(id);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public async update(controllerIdentity: string, notarization: INotarization): Promise<void> {
|
|
54
|
+
this.store.set(notarization.id, notarization);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public async transfer(
|
|
58
|
+
controllerIdentity: string,
|
|
59
|
+
id: string,
|
|
60
|
+
recipientAddress: string
|
|
61
|
+
): Promise<void> {
|
|
62
|
+
const value = this.store.get(id);
|
|
63
|
+
if (!value) {
|
|
64
|
+
throw new Error('Missing notarization');
|
|
65
|
+
}
|
|
66
|
+
this.store.set(id, value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
NotarizationConnectorFactory.register('demo', () => new DemoConnector());
|
|
71
|
+
|
|
72
|
+
const service = new NotarizationService({
|
|
73
|
+
config: {
|
|
74
|
+
defaultNamespace: 'demo'
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const id = await service.create(
|
|
79
|
+
{
|
|
80
|
+
mode: NotarizationMode.Dynamic,
|
|
81
|
+
data: new Uint8Array([1, 2, 3]),
|
|
82
|
+
description: 'Created via service'
|
|
83
|
+
},
|
|
84
|
+
'demo',
|
|
85
|
+
'did:example:controller'
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const notarization = await service.get(id);
|
|
89
|
+
console.log(notarization.id); // notarization:urn:notarization:demo:1
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { NotarizationMode } from '@twin.org/notarization-models';
|
|
94
|
+
import { NotarizationService } from '@twin.org/notarization-service';
|
|
95
|
+
|
|
96
|
+
const service = new NotarizationService({
|
|
97
|
+
config: {
|
|
98
|
+
defaultNamespace: 'demo'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
await service.update(
|
|
103
|
+
{
|
|
104
|
+
id: 'notarization:urn:notarization:demo:1',
|
|
105
|
+
mode: NotarizationMode.Dynamic,
|
|
106
|
+
dateCreated: '2026-01-01T00:00:00.000Z',
|
|
107
|
+
data: new Uint8Array([9, 9, 9]),
|
|
108
|
+
description: 'Updated via service'
|
|
109
|
+
},
|
|
110
|
+
'did:example:controller'
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
await service.transfer(
|
|
114
|
+
'notarization:urn:notarization:demo:1',
|
|
115
|
+
'did:example:recipient',
|
|
116
|
+
'did:example:controller'
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
await service.remove('notarization:urn:notarization:demo:1', 'did:example:controller');
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## generateRestRoutesNotarization
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { ContextIdKeys, ContextIdStore } from '@twin.org/context';
|
|
126
|
+
import { ComponentFactory } from '@twin.org/core';
|
|
127
|
+
import {
|
|
128
|
+
NotarizationMode,
|
|
129
|
+
type INotarization,
|
|
130
|
+
type INotarizationComponent
|
|
131
|
+
} from '@twin.org/notarization-models';
|
|
132
|
+
import { generateRestRoutesNotarization } from '@twin.org/notarization-service';
|
|
133
|
+
|
|
134
|
+
class DemoComponent implements INotarizationComponent {
|
|
135
|
+
public className(): string {
|
|
136
|
+
return 'DemoComponent';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public async create(
|
|
140
|
+
notarization: Omit<INotarization, 'id' | 'dateCreated'>,
|
|
141
|
+
namespace?: string,
|
|
142
|
+
controllerIdentity?: string
|
|
143
|
+
): Promise<string> {
|
|
144
|
+
return 'notarization:urn:notarization:demo:route-1';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public async get(id: string): Promise<INotarization> {
|
|
148
|
+
return {
|
|
149
|
+
id,
|
|
150
|
+
mode: NotarizationMode.Dynamic,
|
|
151
|
+
dateCreated: '2026-01-01T00:00:00.000Z',
|
|
152
|
+
data: new Uint8Array([1]),
|
|
153
|
+
description: 'Route response'
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public async remove(id: string, controllerIdentity?: string): Promise<void> {}
|
|
158
|
+
public async update(notarization: INotarization, controllerIdentity?: string): Promise<void> {}
|
|
159
|
+
public async transfer(
|
|
160
|
+
id: string,
|
|
161
|
+
recipientAddress: string,
|
|
162
|
+
controllerIdentity?: string
|
|
163
|
+
): Promise<void> {}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
ComponentFactory.register('notarization', () => new DemoComponent());
|
|
167
|
+
|
|
168
|
+
const routes = generateRestRoutesNotarization('/notarization', 'notarization');
|
|
169
|
+
const createRoute = routes.find(route => route.operationId === 'notarizationCreate');
|
|
170
|
+
|
|
171
|
+
const response = await ContextIdStore.run(
|
|
172
|
+
{ [ContextIdKeys.Organization]: 'did:example:organisation' },
|
|
173
|
+
async () =>
|
|
174
|
+
createRoute?.handler({} as never, {
|
|
175
|
+
body: {
|
|
176
|
+
mode: NotarizationMode.Dynamic,
|
|
177
|
+
data: new Uint8Array([1, 2]),
|
|
178
|
+
description: 'Created by route',
|
|
179
|
+
namespace: 'demo'
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
console.log(response?.statusCode); // 201
|
|
185
|
+
```
|