@keetanetwork/anchor 0.0.61 → 0.0.63
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/lib/anchor-metadata-server.d.ts +54 -0
- package/lib/anchor-metadata-server.d.ts.map +1 -0
- package/lib/anchor-metadata-server.js +62 -0
- package/lib/anchor-metadata-server.js.map +1 -0
- package/lib/chaining.d.ts +29 -6
- package/lib/chaining.d.ts.map +1 -1
- package/lib/chaining.js +61 -24
- package/lib/chaining.js.map +1 -1
- package/lib/error.d.ts +35 -0
- package/lib/error.d.ts.map +1 -1
- package/lib/error.generated.d.ts +3 -0
- package/lib/error.generated.d.ts.map +1 -0
- package/lib/error.generated.js +104 -0
- package/lib/error.generated.js.map +1 -0
- package/lib/error.js +66 -1
- package/lib/error.js.map +1 -1
- package/lib/http-server/common.d.ts +20 -2
- package/lib/http-server/common.d.ts.map +1 -1
- package/lib/http-server/common.js +47 -0
- package/lib/http-server/common.js.map +1 -1
- package/lib/http-server/index.d.ts +22 -0
- package/lib/http-server/index.d.ts.map +1 -1
- package/lib/http-server/index.js +23 -0
- package/lib/http-server/index.js.map +1 -1
- package/lib/metadata.types.d.ts +40 -0
- package/lib/metadata.types.d.ts.map +1 -1
- package/lib/metadata.types.js.map +1 -1
- package/lib/queue/drivers/queue_postgres.d.ts.map +1 -1
- package/lib/queue/drivers/queue_postgres.js +47 -43
- package/lib/queue/drivers/queue_postgres.js.map +1 -1
- package/lib/resolver.d.ts +19 -20
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.js +1420 -681
- package/lib/resolver.js.map +1 -1
- package/lib/token-metadata.d.ts.map +1 -1
- package/lib/token-metadata.js +1 -1
- package/lib/token-metadata.js.map +1 -1
- package/lib/utils/certificate-network.d.ts +84 -0
- package/lib/utils/certificate-network.d.ts.map +1 -0
- package/lib/utils/certificate-network.js +104 -0
- package/lib/utils/certificate-network.js.map +1 -0
- package/lib/utils/signing.d.ts +12 -0
- package/lib/utils/signing.d.ts.map +1 -1
- package/lib/utils/signing.js +145 -2
- package/lib/utils/signing.js.map +1 -1
- package/npm-shrinkwrap.json +18 -18
- package/package.json +2 -2
- package/services/asset-movement/common.d.ts.map +1 -1
- package/services/asset-movement/common.js +7 -53
- package/services/asset-movement/common.js.map +1 -1
- package/services/asset-movement/server.d.ts +6 -4
- package/services/asset-movement/server.d.ts.map +1 -1
- package/services/asset-movement/server.js +3 -3
- package/services/asset-movement/server.js.map +1 -1
- package/services/fx/client.d.ts +2 -1
- package/services/fx/client.d.ts.map +1 -1
- package/services/fx/client.js +5 -3
- package/services/fx/client.js.map +1 -1
- package/services/fx/common.js +7 -7
- package/services/fx/server.d.ts +9 -7
- package/services/fx/server.d.ts.map +1 -1
- package/services/fx/server.js +5 -5
- package/services/fx/server.js.map +1 -1
- package/services/kyc/server.d.ts +6 -4
- package/services/kyc/server.d.ts.map +1 -1
- package/services/kyc/server.js +3 -3
- package/services/kyc/server.js.map +1 -1
- package/services/notification/common.d.ts +2 -1
- package/services/notification/common.d.ts.map +1 -1
- package/services/notification/common.generated.js +20 -20
- package/services/notification/common.js +3 -2
- package/services/notification/common.js.map +1 -1
- package/services/notification/server.d.ts +7 -6
- package/services/notification/server.d.ts.map +1 -1
- package/services/notification/server.js +25 -62
- package/services/notification/server.js.map +1 -1
- package/services/storage/clients/contacts.d.ts +5 -11
- package/services/storage/clients/contacts.d.ts.map +1 -1
- package/services/storage/clients/contacts.js +1 -1
- package/services/storage/clients/contacts.js.map +1 -1
- package/services/storage/common.d.ts +2 -1
- package/services/storage/common.d.ts.map +1 -1
- package/services/storage/common.js +7 -2
- package/services/storage/common.js.map +1 -1
- package/services/storage/server.d.ts +7 -5
- package/services/storage/server.d.ts.map +1 -1
- package/services/storage/server.js +29 -99
- package/services/storage/server.js.map +1 -1
- package/services/username/common.d.ts +2 -1
- package/services/username/common.d.ts.map +1 -1
- package/services/username/common.generated.js +14 -48
- package/services/username/common.generated.js.map +1 -1
- package/services/username/common.js +3 -2
- package/services/username/common.js.map +1 -1
- package/services/username/server.d.ts +7 -6
- package/services/username/server.d.ts.map +1 -1
- package/services/username/server.js +38 -46
- package/services/username/server.js.map +1 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
|
|
2
|
+
import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js";
|
|
3
|
+
import * as typia from 'typia';
|
|
4
|
+
export const assertKeetaAnchorCertificateRequiredErrorJSONProperties = (() => { const _io0 = (input, _exceptionable = true) => Array.isArray(input.acceptedIssuers) && input.acceptedIssuers.every((elem, _index1) => Array.isArray(elem) && elem.every((elem, _index2) => "object" === typeof elem && null !== elem && _io1(elem, true && _exceptionable))) && ("missing" === input.kind || "untrusted" === input.kind) && (2 === Object.keys(input).length || Object.keys(input).every(key => {
|
|
5
|
+
if (["acceptedIssuers", "kind"].some(prop => key === prop))
|
|
6
|
+
return true;
|
|
7
|
+
const value = input[key];
|
|
8
|
+
if (undefined === value)
|
|
9
|
+
return true;
|
|
10
|
+
return false;
|
|
11
|
+
})); const _io1 = (input, _exceptionable = true) => "string" === typeof input.name && "string" === typeof input.value && (2 === Object.keys(input).length || Object.keys(input).every(key => {
|
|
12
|
+
if (["name", "value"].some(prop => key === prop))
|
|
13
|
+
return true;
|
|
14
|
+
const value = input[key];
|
|
15
|
+
if (undefined === value)
|
|
16
|
+
return true;
|
|
17
|
+
return false;
|
|
18
|
+
})); const _ao0 = (input, _path, _exceptionable = true) => ((Array.isArray(input.acceptedIssuers) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
19
|
+
method: "typia.createAssertEquals",
|
|
20
|
+
path: _path + ".acceptedIssuers",
|
|
21
|
+
expected: "Array<Array<__type>>",
|
|
22
|
+
value: input.acceptedIssuers
|
|
23
|
+
}, _errorFactory)) && input.acceptedIssuers.every((elem, _index3) => (Array.isArray(elem) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
24
|
+
method: "typia.createAssertEquals",
|
|
25
|
+
path: _path + ".acceptedIssuers[" + _index3 + "]",
|
|
26
|
+
expected: "Array<__type>",
|
|
27
|
+
value: elem
|
|
28
|
+
}, _errorFactory)) && elem.every((elem, _index4) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
29
|
+
method: "typia.createAssertEquals",
|
|
30
|
+
path: _path + ".acceptedIssuers[" + _index3 + "][" + _index4 + "]",
|
|
31
|
+
expected: "__type",
|
|
32
|
+
value: elem
|
|
33
|
+
}, _errorFactory)) && _ao1(elem, _path + ".acceptedIssuers[" + _index3 + "][" + _index4 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
34
|
+
method: "typia.createAssertEquals",
|
|
35
|
+
path: _path + ".acceptedIssuers[" + _index3 + "][" + _index4 + "]",
|
|
36
|
+
expected: "__type",
|
|
37
|
+
value: elem
|
|
38
|
+
}, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
39
|
+
method: "typia.createAssertEquals",
|
|
40
|
+
path: _path + ".acceptedIssuers[" + _index3 + "]",
|
|
41
|
+
expected: "Array<__type>",
|
|
42
|
+
value: elem
|
|
43
|
+
}, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
44
|
+
method: "typia.createAssertEquals",
|
|
45
|
+
path: _path + ".acceptedIssuers",
|
|
46
|
+
expected: "Array<Array<__type>>",
|
|
47
|
+
value: input.acceptedIssuers
|
|
48
|
+
}, _errorFactory)) && ("missing" === input.kind || "untrusted" === input.kind || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
49
|
+
method: "typia.createAssertEquals",
|
|
50
|
+
path: _path + ".kind",
|
|
51
|
+
expected: "(\"missing\" | \"untrusted\")",
|
|
52
|
+
value: input.kind
|
|
53
|
+
}, _errorFactory)) && (2 === Object.keys(input).length || (false === _exceptionable || Object.keys(input).every(key => {
|
|
54
|
+
if (["acceptedIssuers", "kind"].some(prop => key === prop))
|
|
55
|
+
return true;
|
|
56
|
+
const value = input[key];
|
|
57
|
+
if (undefined === value)
|
|
58
|
+
return true;
|
|
59
|
+
return __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
60
|
+
method: "typia.createAssertEquals",
|
|
61
|
+
path: _path + __typia_transform__accessExpressionAsString._accessExpressionAsString(key),
|
|
62
|
+
expected: "undefined",
|
|
63
|
+
value: value
|
|
64
|
+
}, _errorFactory);
|
|
65
|
+
}))); const _ao1 = (input, _path, _exceptionable = true) => ("string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
66
|
+
method: "typia.createAssertEquals",
|
|
67
|
+
path: _path + ".name",
|
|
68
|
+
expected: "string",
|
|
69
|
+
value: input.name
|
|
70
|
+
}, _errorFactory)) && ("string" === typeof input.value || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
71
|
+
method: "typia.createAssertEquals",
|
|
72
|
+
path: _path + ".value",
|
|
73
|
+
expected: "string",
|
|
74
|
+
value: input.value
|
|
75
|
+
}, _errorFactory)) && (2 === Object.keys(input).length || (false === _exceptionable || Object.keys(input).every(key => {
|
|
76
|
+
if (["name", "value"].some(prop => key === prop))
|
|
77
|
+
return true;
|
|
78
|
+
const value = input[key];
|
|
79
|
+
if (undefined === value)
|
|
80
|
+
return true;
|
|
81
|
+
return __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
82
|
+
method: "typia.createAssertEquals",
|
|
83
|
+
path: _path + __typia_transform__accessExpressionAsString._accessExpressionAsString(key),
|
|
84
|
+
expected: "undefined",
|
|
85
|
+
value: value
|
|
86
|
+
}, _errorFactory);
|
|
87
|
+
}))); const __is = (input, _exceptionable = true) => "object" === typeof input && null !== input && _io0(input, true); let _errorFactory; return (input, errorFactory) => {
|
|
88
|
+
if (false === __is(input)) {
|
|
89
|
+
_errorFactory = errorFactory;
|
|
90
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
91
|
+
method: "typia.createAssertEquals",
|
|
92
|
+
path: _path + "",
|
|
93
|
+
expected: "KeetaAnchorCertificateRequiredErrorJSONProperties",
|
|
94
|
+
value: input
|
|
95
|
+
}, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
96
|
+
method: "typia.createAssertEquals",
|
|
97
|
+
path: _path + "",
|
|
98
|
+
expected: "KeetaAnchorCertificateRequiredErrorJSONProperties",
|
|
99
|
+
value: input
|
|
100
|
+
}, _errorFactory))(input, "$input", true);
|
|
101
|
+
}
|
|
102
|
+
return input;
|
|
103
|
+
}; })();
|
|
104
|
+
//# sourceMappingURL=error.generated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.generated.js","sourceRoot":"","sources":["../../src/lib/error.generated.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,CAAC,MAAM,uDAAuD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAuJ,CAAC","sourcesContent":["import * as typia from 'typia';\nimport type { KeetaAnchorCertificateRequiredErrorJSONProperties } from './error.js';\n\nexport const assertKeetaAnchorCertificateRequiredErrorJSONProperties: (input: unknown) => KeetaAnchorCertificateRequiredErrorJSONProperties = typia.createAssertEquals<KeetaAnchorCertificateRequiredErrorJSONProperties>();\n"]}
|
package/lib/error.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
|
|
2
2
|
import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js";
|
|
3
3
|
import { createAssertEquals, createIs } from 'typia';
|
|
4
|
+
import { assertKeetaAnchorCertificateRequiredErrorJSONProperties } from './error.generated.js';
|
|
4
5
|
/**
|
|
5
6
|
* Lazy-loaded error classes to avoid circular dependencies
|
|
6
7
|
* The classes are loaded on first use
|
|
@@ -16,7 +17,7 @@ async function getErrorClassMapping() {
|
|
|
16
17
|
* is the base error class and could cause circular resolution
|
|
17
18
|
*/
|
|
18
19
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
19
|
-
KeetaAnchorUserError, KeetaAnchorUserValidationError
|
|
20
|
+
KeetaAnchorUserError, KeetaAnchorUserValidationError, KeetaAnchorCertificateRequiredError
|
|
20
21
|
];
|
|
21
22
|
// Dynamically import errors to avoid circular dependencies
|
|
22
23
|
const importPromises = await Promise.all([
|
|
@@ -452,4 +453,68 @@ export class KeetaAnchorUserValidationError extends KeetaAnchorUserError {
|
|
|
452
453
|
}, message));
|
|
453
454
|
}
|
|
454
455
|
}
|
|
456
|
+
export class KeetaAnchorCertificateRequiredError extends KeetaAnchorUserError {
|
|
457
|
+
static name = 'KeetaAnchorCertificateRequiredError';
|
|
458
|
+
KeetaAnchorCertificateRequiredErrorObjectTypeID;
|
|
459
|
+
static KeetaAnchorCertificateRequiredErrorObjectTypeID = 'b8c5b6df-2f4d-4f60-9d6c-2f4d8a6b1f01';
|
|
460
|
+
acceptedIssuers;
|
|
461
|
+
kind;
|
|
462
|
+
constructor(args, message) {
|
|
463
|
+
super(message ?? KeetaAnchorCertificateRequiredError.defaultMessage(args.kind));
|
|
464
|
+
if (args.kind === 'missing') {
|
|
465
|
+
this.statusCode = 401;
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
this.statusCode = 403;
|
|
469
|
+
}
|
|
470
|
+
Object.defineProperty(this, 'KeetaAnchorCertificateRequiredErrorObjectTypeID', {
|
|
471
|
+
value: KeetaAnchorCertificateRequiredError.KeetaAnchorCertificateRequiredErrorObjectTypeID,
|
|
472
|
+
enumerable: false
|
|
473
|
+
});
|
|
474
|
+
this.acceptedIssuers = args.acceptedIssuers;
|
|
475
|
+
this.kind = args.kind;
|
|
476
|
+
}
|
|
477
|
+
static defaultMessage(kind) {
|
|
478
|
+
if (kind === 'missing') {
|
|
479
|
+
return ('No certificate has been published for the signing account');
|
|
480
|
+
}
|
|
481
|
+
return ('Published certificates do not chain to an accepted issuer');
|
|
482
|
+
}
|
|
483
|
+
static isInstance(input) {
|
|
484
|
+
return (this.hasPropWithValue(input, 'KeetaAnchorCertificateRequiredErrorObjectTypeID', KeetaAnchorCertificateRequiredError.KeetaAnchorCertificateRequiredErrorObjectTypeID));
|
|
485
|
+
}
|
|
486
|
+
asErrorResponse(contentType) {
|
|
487
|
+
let message = this.message;
|
|
488
|
+
if (contentType === 'application/json') {
|
|
489
|
+
message = JSON.stringify({
|
|
490
|
+
ok: false,
|
|
491
|
+
name: this.name,
|
|
492
|
+
data: { acceptedIssuers: this.acceptedIssuers, kind: this.kind },
|
|
493
|
+
error: this.message
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
return ({
|
|
497
|
+
error: message,
|
|
498
|
+
statusCode: this.statusCode,
|
|
499
|
+
contentType: contentType
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
toJSON() {
|
|
503
|
+
return ({
|
|
504
|
+
...super.toJSON(),
|
|
505
|
+
acceptedIssuers: this.acceptedIssuers,
|
|
506
|
+
kind: this.kind
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
static async fromJSON(input) {
|
|
510
|
+
const { message, other } = this.extractErrorProperties(input, this);
|
|
511
|
+
if (!('data' in other)) {
|
|
512
|
+
throw (new Error('Invalid KeetaAnchorCertificateRequiredError JSON: missing data property'));
|
|
513
|
+
}
|
|
514
|
+
const parsed = assertKeetaAnchorCertificateRequiredErrorJSONProperties(other.data);
|
|
515
|
+
const error = new this({ acceptedIssuers: parsed.acceptedIssuers, kind: parsed.kind }, message);
|
|
516
|
+
error.restoreFromJSON(other);
|
|
517
|
+
return (error);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
455
520
|
//# sourceMappingURL=error.js.map
|
package/lib/error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AAI,KAAK,CAAC;QAEV,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,KAAK,GAAG,KAAK,CAAC;QACf,CAAC;aAAM,CAAC;YACP,KAAK,GAAG,CAAE,KAAK,CAAE,CAAC;QACnB,CAAC;QAED,OAAM,CAAC,IAAI,IAAI,CAAC;YACf,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,UAAS,MAAM;gBAChC,IAAI,IAAI,CAAC;gBACT,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;oBAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBAErC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;wBAC3B,KAAK,CAAC,KAAK,EAAE,CAAC;oBACf,CAAC;oBAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBACtB,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACxB,CAAC;gBACF,CAAC;gBAED,OAAM,CAAC;oBACN,IAAI;oBACJ,OAAO,EAAE,OAAO,IAAI,eAAe;oBACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,aAAa,EAAE,MAAM,CAAC,KAAK;iBAC3B,CAAC,CAAC;YACJ,CAAC,CAAC;SACF,EAAE,OAAO,CAAC,CAAC,CAAA;IACb,CAAC","sourcesContent":["import type { IValidation, TypeGuardError } from 'typia';\nimport { createAssertEquals, createIs } from 'typia';\nimport type { LogLevel } from './log/index.ts';\n/**\n * Type for error classes that can be deserialized\n */\ninterface DeserializableErrorClass {\n\treadonly name: string;\n\tfromJSON: (input: unknown) => Promise<KeetaAnchorError>;\n}\n\n/**\n * Lazy-loaded error classes to avoid circular dependencies\n * The classes are loaded on first use\n */\nlet ERROR_CLASS_MAPPING: { [key: string]: (input: unknown) => Promise<KeetaAnchorError> } | null = null;\n\nasync function getErrorClassMapping(): Promise<{ [key: string]: (input: unknown) => Promise<KeetaAnchorError> }> {\n\tif (ERROR_CLASS_MAPPING) {\n\t\treturn(ERROR_CLASS_MAPPING);\n\t}\n\n\tconst ERROR_CLASSES: DeserializableErrorClass[] = [\n\t\t/*\n\t\t * We purposefully leave out KeetaAnchorError here since it\n\t\t * is the base error class and could cause circular resolution\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/no-use-before-define\n\t\tKeetaAnchorUserError, KeetaAnchorUserValidationError\n\t];\n\n\t// Dynamically import errors to avoid circular dependencies\n\tconst importPromises: { Errors: { [key: string]: DeserializableErrorClass }}[] = await Promise.all([\n\t\timport('../services/kyc/common.js'),\n\t\timport('../services/fx/common.js'),\n\t\timport('../services/asset-movement/common.js'),\n\t\timport('../services/storage/common.js'),\n\t\timport('../services/username/common.js')\n\t]);\n\n\tfor (const module of importPromises) {\n\t\tconst classes = Object.values(module.Errors);\n\t\tERROR_CLASSES.push(...classes);\n\t}\n\n\tconst mapping: { [key: string]: (input: unknown) => Promise<KeetaAnchorError> } = {};\n\tfor (const errorClass of ERROR_CLASSES) {\n\t\tmapping[errorClass.name] = errorClass.fromJSON.bind(errorClass);\n\t}\n\n\tERROR_CLASS_MAPPING = mapping;\n\treturn(mapping);\n}\n\n/**\n * Base error class for all Keeta Anchor errors\n */\nexport class KeetaAnchorError extends Error {\n\tstatic override readonly name: string = 'KeetaAnchorError';\n\t#name: string;\n\t#statusCode = 400;\n\t#retryable = false;\n\tprivate readonly keetaAnchorErrorObjectTypeID!: string;\n\tprivate static readonly keetaAnchorErrorObjectTypeID = '5d7f1578-e887-4104-bab0-4115ae33b08f';\n\tprotected userError = false;\n\treadonly logLevel: LogLevel = 'ERROR';\n\n\tget name(): string {\n\t\treturn(this.#name);\n\t}\n\n\tprotected set name(value: string) {\n\t\tthis.#name = value;\n\t}\n\n\tget statusCode(): number {\n\t\treturn(this.#statusCode);\n\t}\n\n\tprotected set statusCode(value: number) {\n\t\tthis.#statusCode = value;\n\t}\n\n\tget retryable(): boolean {\n\t\treturn(this.#retryable);\n\t}\n\n\tprotected set retryable(value: boolean) {\n\t\tthis.#retryable = value;\n\t}\n\n\tconstructor(message: string) {\n\t\tsuper(message);\n\n\t\t// Need to cast to access the static name property from the constructor\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.#name = (this.constructor as typeof KeetaAnchorError).name;\n\n\t\tObject.defineProperty(this, 'keetaAnchorErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorError.keetaAnchorErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\t/**\n\t * Protected method to restore error properties from JSON\n\t * This allows subclasses to properly restore properties without using any\n\t */\n\tprotected restoreFromJSON(other: { [key: string]: unknown }): void {\n\t\t// Restore statusCode if present\n\t\tif ('statusCode' in other) {\n\t\t\tif (typeof other.statusCode !== 'number') {\n\t\t\t\tthrow(new TypeError('Invalid statusCode: expected number'));\n\t\t\t}\n\t\t\tthis.statusCode = other.statusCode;\n\t\t}\n\n\t\t// Restore retryable if present\n\t\tif ('retryable' in other) {\n\t\t\tif (typeof other.retryable !== 'boolean') {\n\t\t\t\tthrow(new TypeError('Invalid retryable: expected boolean'));\n\t\t\t}\n\t\t\tthis.retryable = other.retryable;\n\t\t}\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorError {\n\t\treturn(this.hasPropWithValue(input, 'keetaAnchorErrorObjectTypeID', KeetaAnchorError.keetaAnchorErrorObjectTypeID));\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json', message?: string): { error: string; statusCode: number; contentType: string } {\n\t\tmessage ??= 'Internal error';\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\t...this.toJSON(),\n\t\t\t\tstatusCode: undefined\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): { ok: false; retryable: boolean; error: string; name: string; statusCode: number } {\n\t\tlet message = 'Internal error';\n\t\tif (this.userError) {\n\t\t\tmessage = this.message;\n\t\t}\n\n\t\treturn({\n\t\t\tok: false,\n\t\t\tretryable: this.retryable,\n\t\t\terror: message,\n\t\t\tname: this.#name,\n\t\t\tstatusCode: this.statusCode\n\t\t});\n\t}\n\n\tprotected static hasPropWithValue<PROP extends string, VALUE extends string | number | boolean>(input: unknown, prop: PROP, value: VALUE): input is { [key in PROP]: VALUE } {\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\treturn(false);\n\t\t}\n\n\t\tif (!(prop in input)) {\n\t\t\treturn(false);\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst inputValue = input[prop as keyof typeof input] as unknown;\n\t\tif (inputValue !== value) {\n\t\t\treturn(false);\n\t\t}\n\n\t\treturn(true);\n\t}\n\n\t/**\n\t * Extract common error properties from JSON input\n\t * This validates the structure and extracts properties needed for construction\n\t */\n\tprotected static extractErrorProperties(input: unknown, expectedClass?: { name: string }): { message: string; other: { [key: string]: unknown }} {\n\t\tif (!this.hasPropWithValue(input, 'ok', false)) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\t// Verify the name matches if an expected class is provided\n\t\tif (expectedClass && 'name' in input && input.name !== expectedClass.name) {\n\t\t\tthrow(new Error(`Error name mismatch: expected ${expectedClass.name}, got ${input.name}`));\n\t\t}\n\n\t\t// Extract error message\n\t\tlet message = 'Internal error';\n\t\tif ('error' in input && typeof input.error === 'string') {\n\t\t\tmessage = input.error;\n\t\t}\n\n\t\t// Extract other properties\n\t\tconst other: { [key: string]: unknown } = {};\n\t\tfor (const key in input) {\n\t\t\tif (key !== 'error' && key !== 'ok') {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tother[key] = input[key as keyof typeof input];\n\t\t\t}\n\t\t}\n\n\t\treturn({ message, other });\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaAnchorError> {\n\t\t// Try to use the deserializer mapping if available for subclasses\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\tif (!('ok' in input) || input.ok !== false) {\n\t\t\tthrow(new Error('Invalid error JSON object: expected ok: false'));\n\t\t}\n\n\t\t// Check if there's a specific error class name\n\t\tif ('name' in input && typeof input.name === 'string') {\n\t\t\tif (input.name === 'KeetaAnchorError') {\n\t\t\t\tconst { message, other } = KeetaAnchorError.extractErrorProperties(input, this);\n\t\t\t\tconst error = new this(message);\n\t\t\t\terror.restoreFromJSON(other);\n\t\t\t\treturn(error);\n\t\t\t}\n\t\t\tconst mapping = await getErrorClassMapping();\n\t\t\tconst deserializer = mapping[input.name];\n\t\t\tif (deserializer) {\n\t\t\t\treturn(await deserializer(input));\n\t\t\t}\n\t\t}\n\n\t\tthrow(new Error('Invalid error JSON object: unknown error class'));\n\t}\n}\n\n/**\n * User-facing error class that extends KeetaAnchorError\n */\nexport class KeetaAnchorUserError extends KeetaAnchorError {\n\tstatic readonly name: string = 'KeetaAnchorUserError';\n\tprivate readonly keetaAnchorUserErrorObjectTypeID!: string;\n\tprivate static readonly keetaAnchorUserErrorObjectTypeID = 'a1e64819-14b6-45ac-a1ec-b9c0bdd51e7b';\n\tprotected override userError = true;\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorUserError {\n\t\treturn(this.hasPropWithValue(input, 'keetaAnchorUserErrorObjectTypeID', KeetaAnchorUserError.keetaAnchorUserErrorObjectTypeID));\n\t}\n\n\tconstructor(message: string) {\n\t\tsuper(message);\n\n\t\tObject.defineProperty(this, 'keetaAnchorUserErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorUserError.keetaAnchorUserErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\treturn(super.asErrorResponse(contentType, this.message));\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<InstanceType<typeof this>> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\t\tconst error = new this(message);\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\ninterface KeetaAnchorUserValidationErrorDetails {\n\tfields: {\n\t\tpath?: string | undefined;\n\t\tmessage: string;\n\t\tallowedValues?: string[];\n\t\texpected?: string;\n\t\treceivedValue?: unknown;\n\t\tvalueRules?: { minimum?: string | undefined; maximum?: string | undefined };\n\t}[];\n}\n\nconst assertKeetaAnchorUserValidationErrorDetails: (input: unknown) => KeetaAnchorUserValidationErrorDetails = createAssertEquals<KeetaAnchorUserValidationErrorDetails>();\ntype KeetaAnchorUserValidationErrorJSON = ReturnType<KeetaAnchorUserError['toJSON']> & KeetaAnchorUserValidationErrorDetails;\n\ntype TypeGuardErrorLike = Pick<TypeGuardError.IProps | IValidation.IError, 'path' | 'expected' | 'value'>;\n\nconst isTypeGuardErrorLike: (error: unknown) => error is TypeGuardErrorLike = createIs<TypeGuardErrorLike>();\n\nexport class KeetaAnchorUserValidationError extends KeetaAnchorUserError implements KeetaAnchorUserValidationErrorDetails {\n\tstatic readonly isTypeGuardErrorLike: typeof isTypeGuardErrorLike = isTypeGuardErrorLike;\n\n\tstatic override readonly name: string = 'KeetaAnchorUserValidationError';\n\tprivate readonly KeetaAnchorUserValidationErrorObjectTypeID!: string;\n\tprivate static readonly KeetaAnchorUserValidationErrorObjectTypeID = '5fa46799-48b8-4cf2-a3de-9c01418d3ba0';\n\tprotected override userError = true;\n\n\treadonly fields: KeetaAnchorUserValidationErrorDetails['fields'];\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorUserValidationError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaAnchorUserValidationErrorObjectTypeID', KeetaAnchorUserValidationError.KeetaAnchorUserValidationErrorObjectTypeID));\n\t}\n\n\tconstructor(args: KeetaAnchorUserValidationErrorDetails, message?: string) {\n\t\tsuper(message ?? `Validation error on fields ${args.fields.map((f) => f.path).join(', ')}`);\n\n\t\tObject.defineProperty(this, 'KeetaAnchorUserValidationErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorUserValidationError.KeetaAnchorUserValidationErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\n\t\tthis.fields = args.fields;\n\t}\n\n\toverride get statusCode() {\n\t\treturn(400);\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\tlet message = this.message;\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\tok: false,\n\t\t\t\tname: this.name,\n\t\t\t\tdata: { fields: this.fields },\n\t\t\t\terror: this.message\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): KeetaAnchorUserValidationErrorJSON {\n\t\treturn({\n\t\t\t...super.toJSON(),\n\t\t\tfields: this.fields\n\t\t});\n\t}\n\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaAnchorUserValidationError> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\tif (!('data' in other)) {\n\t\t\tthrow(new Error('Invalid KeetaAnchorUserValidationError JSON: missing data property'));\n\t\t}\n\n\t\tconst parsed = assertKeetaAnchorUserValidationErrorDetails(other.data);\n\n\t\tconst error = new this(\n\t\t\t{ fields: parsed.fields },\n\t\t\tmessage\n\t\t);\n\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n\n\tstatic fromTypeGuardError(input: TypeGuardErrorLike | TypeGuardErrorLike[], message?: string): KeetaAnchorUserValidationError {\n\t\tlet asArr;\n\n\t\tif (Array.isArray(input)) {\n\t\t\tasArr = input;\n\t\t} else {\n\t\t\tasArr = [ input ];\n\t\t}\n\n\t\treturn(new this({\n\t\t\tfields: asArr.map(function(single) {\n\t\t\t\tlet path;\n\t\t\t\tif (single.path !== undefined) {\n\t\t\t\t\tconst split = single.path.split('.');\n\n\t\t\t\t\tif (split[0] === '$input') {\n\t\t\t\t\t\tsplit.shift();\n\t\t\t\t\t}\n\n\t\t\t\t\tif (split.length > 0) {\n\t\t\t\t\t\tpath = split.join('.');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\tpath,\n\t\t\t\t\tmessage: message ?? 'Invalid value',\n\t\t\t\t\texpected: single.expected,\n\t\t\t\t\treceivedValue: single.value\n\t\t\t\t});\n\t\t\t})\n\t\t}, message))\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/lib/error.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAE,uDAAuD,EAAE,MAAM,sBAAsB,CAAC;AAS/F;;;GAGG;AACH,IAAI,mBAAmB,GAA4E,IAAI,CAAC;AAExG,KAAK,UAAU,oBAAoB;IAClC,IAAI,mBAAmB,EAAE,CAAC;QACzB,OAAM,CAAC,mBAAmB,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,aAAa,GAA+B;QACjD;;;WAGG;QACH,mEAAmE;QACnE,oBAAoB,EAAE,8BAA8B,EAAE,mCAAmC;KACzF,CAAC;IAEF,2DAA2D;IAC3D,MAAM,cAAc,GAA6D,MAAM,OAAO,CAAC,GAAG,CAAC;QAClG,MAAM,CAAC,2BAA2B,CAAC;QACnC,MAAM,CAAC,0BAA0B,CAAC;QAClC,MAAM,CAAC,sCAAsC,CAAC;QAC9C,MAAM,CAAC,+BAA+B,CAAC;QACvC,MAAM,CAAC,gCAAgC,CAAC;KACxC,CAAC,CAAC;IAEH,KAAK,MAAM,MAAM,IAAI,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E,EAAE,OAAO,CAAC,CAAC;QAEhG,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAE7B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC","sourcesContent":["import type { IValidation, TypeGuardError } from 'typia';\nimport { createAssertEquals, createIs } from 'typia';\nimport type { LogLevel } from './log/index.ts';\nimport { assertKeetaAnchorCertificateRequiredErrorJSONProperties } from './error.generated.js';\n/**\n * Type for error classes that can be deserialized\n */\ninterface DeserializableErrorClass {\n\treadonly name: string;\n\tfromJSON: (input: unknown) => Promise<KeetaAnchorError>;\n}\n\n/**\n * Lazy-loaded error classes to avoid circular dependencies\n * The classes are loaded on first use\n */\nlet ERROR_CLASS_MAPPING: { [key: string]: (input: unknown) => Promise<KeetaAnchorError> } | null = null;\n\nasync function getErrorClassMapping(): Promise<{ [key: string]: (input: unknown) => Promise<KeetaAnchorError> }> {\n\tif (ERROR_CLASS_MAPPING) {\n\t\treturn(ERROR_CLASS_MAPPING);\n\t}\n\n\tconst ERROR_CLASSES: DeserializableErrorClass[] = [\n\t\t/*\n\t\t * We purposefully leave out KeetaAnchorError here since it\n\t\t * is the base error class and could cause circular resolution\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/no-use-before-define\n\t\tKeetaAnchorUserError, KeetaAnchorUserValidationError, KeetaAnchorCertificateRequiredError\n\t];\n\n\t// Dynamically import errors to avoid circular dependencies\n\tconst importPromises: { Errors: { [key: string]: DeserializableErrorClass }}[] = await Promise.all([\n\t\timport('../services/kyc/common.js'),\n\t\timport('../services/fx/common.js'),\n\t\timport('../services/asset-movement/common.js'),\n\t\timport('../services/storage/common.js'),\n\t\timport('../services/username/common.js')\n\t]);\n\n\tfor (const module of importPromises) {\n\t\tconst classes = Object.values(module.Errors);\n\t\tERROR_CLASSES.push(...classes);\n\t}\n\n\tconst mapping: { [key: string]: (input: unknown) => Promise<KeetaAnchorError> } = {};\n\tfor (const errorClass of ERROR_CLASSES) {\n\t\tmapping[errorClass.name] = errorClass.fromJSON.bind(errorClass);\n\t}\n\n\tERROR_CLASS_MAPPING = mapping;\n\treturn(mapping);\n}\n\n/**\n * Base error class for all Keeta Anchor errors\n */\nexport class KeetaAnchorError extends Error {\n\tstatic override readonly name: string = 'KeetaAnchorError';\n\t#name: string;\n\t#statusCode = 400;\n\t#retryable = false;\n\tprivate readonly keetaAnchorErrorObjectTypeID!: string;\n\tprivate static readonly keetaAnchorErrorObjectTypeID = '5d7f1578-e887-4104-bab0-4115ae33b08f';\n\tprotected userError = false;\n\treadonly logLevel: LogLevel = 'ERROR';\n\n\tget name(): string {\n\t\treturn(this.#name);\n\t}\n\n\tprotected set name(value: string) {\n\t\tthis.#name = value;\n\t}\n\n\tget statusCode(): number {\n\t\treturn(this.#statusCode);\n\t}\n\n\tprotected set statusCode(value: number) {\n\t\tthis.#statusCode = value;\n\t}\n\n\tget retryable(): boolean {\n\t\treturn(this.#retryable);\n\t}\n\n\tprotected set retryable(value: boolean) {\n\t\tthis.#retryable = value;\n\t}\n\n\tconstructor(message: string) {\n\t\tsuper(message);\n\n\t\t// Need to cast to access the static name property from the constructor\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.#name = (this.constructor as typeof KeetaAnchorError).name;\n\n\t\tObject.defineProperty(this, 'keetaAnchorErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorError.keetaAnchorErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\t/**\n\t * Protected method to restore error properties from JSON\n\t * This allows subclasses to properly restore properties without using any\n\t */\n\tprotected restoreFromJSON(other: { [key: string]: unknown }): void {\n\t\t// Restore statusCode if present\n\t\tif ('statusCode' in other) {\n\t\t\tif (typeof other.statusCode !== 'number') {\n\t\t\t\tthrow(new TypeError('Invalid statusCode: expected number'));\n\t\t\t}\n\t\t\tthis.statusCode = other.statusCode;\n\t\t}\n\n\t\t// Restore retryable if present\n\t\tif ('retryable' in other) {\n\t\t\tif (typeof other.retryable !== 'boolean') {\n\t\t\t\tthrow(new TypeError('Invalid retryable: expected boolean'));\n\t\t\t}\n\t\t\tthis.retryable = other.retryable;\n\t\t}\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorError {\n\t\treturn(this.hasPropWithValue(input, 'keetaAnchorErrorObjectTypeID', KeetaAnchorError.keetaAnchorErrorObjectTypeID));\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json', message?: string): { error: string; statusCode: number; contentType: string } {\n\t\tmessage ??= 'Internal error';\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\t...this.toJSON(),\n\t\t\t\tstatusCode: undefined\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): { ok: false; retryable: boolean; error: string; name: string; statusCode: number } {\n\t\tlet message = 'Internal error';\n\t\tif (this.userError) {\n\t\t\tmessage = this.message;\n\t\t}\n\n\t\treturn({\n\t\t\tok: false,\n\t\t\tretryable: this.retryable,\n\t\t\terror: message,\n\t\t\tname: this.#name,\n\t\t\tstatusCode: this.statusCode\n\t\t});\n\t}\n\n\tprotected static hasPropWithValue<PROP extends string, VALUE extends string | number | boolean>(input: unknown, prop: PROP, value: VALUE): input is { [key in PROP]: VALUE } {\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\treturn(false);\n\t\t}\n\n\t\tif (!(prop in input)) {\n\t\t\treturn(false);\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst inputValue = input[prop as keyof typeof input] as unknown;\n\t\tif (inputValue !== value) {\n\t\t\treturn(false);\n\t\t}\n\n\t\treturn(true);\n\t}\n\n\t/**\n\t * Extract common error properties from JSON input\n\t * This validates the structure and extracts properties needed for construction\n\t */\n\tprotected static extractErrorProperties(input: unknown, expectedClass?: { name: string }): { message: string; other: { [key: string]: unknown }} {\n\t\tif (!this.hasPropWithValue(input, 'ok', false)) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\t// Verify the name matches if an expected class is provided\n\t\tif (expectedClass && 'name' in input && input.name !== expectedClass.name) {\n\t\t\tthrow(new Error(`Error name mismatch: expected ${expectedClass.name}, got ${input.name}`));\n\t\t}\n\n\t\t// Extract error message\n\t\tlet message = 'Internal error';\n\t\tif ('error' in input && typeof input.error === 'string') {\n\t\t\tmessage = input.error;\n\t\t}\n\n\t\t// Extract other properties\n\t\tconst other: { [key: string]: unknown } = {};\n\t\tfor (const key in input) {\n\t\t\tif (key !== 'error' && key !== 'ok') {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tother[key] = input[key as keyof typeof input];\n\t\t\t}\n\t\t}\n\n\t\treturn({ message, other });\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaAnchorError> {\n\t\t// Try to use the deserializer mapping if available for subclasses\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\tif (!('ok' in input) || input.ok !== false) {\n\t\t\tthrow(new Error('Invalid error JSON object: expected ok: false'));\n\t\t}\n\n\t\t// Check if there's a specific error class name\n\t\tif ('name' in input && typeof input.name === 'string') {\n\t\t\tif (input.name === 'KeetaAnchorError') {\n\t\t\t\tconst { message, other } = KeetaAnchorError.extractErrorProperties(input, this);\n\t\t\t\tconst error = new this(message);\n\t\t\t\terror.restoreFromJSON(other);\n\t\t\t\treturn(error);\n\t\t\t}\n\t\t\tconst mapping = await getErrorClassMapping();\n\t\t\tconst deserializer = mapping[input.name];\n\t\t\tif (deserializer) {\n\t\t\t\treturn(await deserializer(input));\n\t\t\t}\n\t\t}\n\n\t\tthrow(new Error('Invalid error JSON object: unknown error class'));\n\t}\n}\n\n/**\n * User-facing error class that extends KeetaAnchorError\n */\nexport class KeetaAnchorUserError extends KeetaAnchorError {\n\tstatic readonly name: string = 'KeetaAnchorUserError';\n\tprivate readonly keetaAnchorUserErrorObjectTypeID!: string;\n\tprivate static readonly keetaAnchorUserErrorObjectTypeID = 'a1e64819-14b6-45ac-a1ec-b9c0bdd51e7b';\n\tprotected override userError = true;\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorUserError {\n\t\treturn(this.hasPropWithValue(input, 'keetaAnchorUserErrorObjectTypeID', KeetaAnchorUserError.keetaAnchorUserErrorObjectTypeID));\n\t}\n\n\tconstructor(message: string) {\n\t\tsuper(message);\n\n\t\tObject.defineProperty(this, 'keetaAnchorUserErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorUserError.keetaAnchorUserErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\treturn(super.asErrorResponse(contentType, this.message));\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<InstanceType<typeof this>> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\t\tconst error = new this(message);\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\ninterface KeetaAnchorUserValidationErrorDetails {\n\tfields: {\n\t\tpath?: string | undefined;\n\t\tmessage: string;\n\t\tallowedValues?: string[];\n\t\texpected?: string;\n\t\treceivedValue?: unknown;\n\t\tvalueRules?: { minimum?: string | undefined; maximum?: string | undefined };\n\t}[];\n}\n\nconst assertKeetaAnchorUserValidationErrorDetails: (input: unknown) => KeetaAnchorUserValidationErrorDetails = createAssertEquals<KeetaAnchorUserValidationErrorDetails>();\ntype KeetaAnchorUserValidationErrorJSON = ReturnType<KeetaAnchorUserError['toJSON']> & KeetaAnchorUserValidationErrorDetails;\n\ntype TypeGuardErrorLike = Pick<TypeGuardError.IProps | IValidation.IError, 'path' | 'expected' | 'value'>;\n\nconst isTypeGuardErrorLike: (error: unknown) => error is TypeGuardErrorLike = createIs<TypeGuardErrorLike>();\n\nexport class KeetaAnchorUserValidationError extends KeetaAnchorUserError implements KeetaAnchorUserValidationErrorDetails {\n\tstatic readonly isTypeGuardErrorLike: typeof isTypeGuardErrorLike = isTypeGuardErrorLike;\n\n\tstatic override readonly name: string = 'KeetaAnchorUserValidationError';\n\tprivate readonly KeetaAnchorUserValidationErrorObjectTypeID!: string;\n\tprivate static readonly KeetaAnchorUserValidationErrorObjectTypeID = '5fa46799-48b8-4cf2-a3de-9c01418d3ba0';\n\tprotected override userError = true;\n\n\treadonly fields: KeetaAnchorUserValidationErrorDetails['fields'];\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorUserValidationError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaAnchorUserValidationErrorObjectTypeID', KeetaAnchorUserValidationError.KeetaAnchorUserValidationErrorObjectTypeID));\n\t}\n\n\tconstructor(args: KeetaAnchorUserValidationErrorDetails, message?: string) {\n\t\tsuper(message ?? `Validation error on fields ${args.fields.map((f) => f.path).join(', ')}`);\n\n\t\tObject.defineProperty(this, 'KeetaAnchorUserValidationErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorUserValidationError.KeetaAnchorUserValidationErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\n\t\tthis.fields = args.fields;\n\t}\n\n\toverride get statusCode() {\n\t\treturn(400);\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\tlet message = this.message;\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\tok: false,\n\t\t\t\tname: this.name,\n\t\t\t\tdata: { fields: this.fields },\n\t\t\t\terror: this.message\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): KeetaAnchorUserValidationErrorJSON {\n\t\treturn({\n\t\t\t...super.toJSON(),\n\t\t\tfields: this.fields\n\t\t});\n\t}\n\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaAnchorUserValidationError> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\tif (!('data' in other)) {\n\t\t\tthrow(new Error('Invalid KeetaAnchorUserValidationError JSON: missing data property'));\n\t\t}\n\n\t\tconst parsed = assertKeetaAnchorUserValidationErrorDetails(other.data);\n\n\t\tconst error = new this(\n\t\t\t{ fields: parsed.fields },\n\t\t\tmessage\n\t\t);\n\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n\n\tstatic fromTypeGuardError(input: TypeGuardErrorLike | TypeGuardErrorLike[], message?: string): KeetaAnchorUserValidationError {\n\t\tlet asArr;\n\n\t\tif (Array.isArray(input)) {\n\t\t\tasArr = input;\n\t\t} else {\n\t\t\tasArr = [ input ];\n\t\t}\n\n\t\treturn(new this({\n\t\t\tfields: asArr.map(function(single) {\n\t\t\t\tlet path;\n\t\t\t\tif (single.path !== undefined) {\n\t\t\t\t\tconst split = single.path.split('.');\n\n\t\t\t\t\tif (split[0] === '$input') {\n\t\t\t\t\t\tsplit.shift();\n\t\t\t\t\t}\n\n\t\t\t\t\tif (split.length > 0) {\n\t\t\t\t\t\tpath = split.join('.');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\tpath,\n\t\t\t\t\tmessage: message ?? 'Invalid value',\n\t\t\t\t\texpected: single.expected,\n\t\t\t\t\treceivedValue: single.value\n\t\t\t\t});\n\t\t\t})\n\t\t}, message))\n\t}\n}\n\n/**\n * Failure mode for the certificate-chain gate.\n */\nexport type KeetaAnchorCertificateRequiredKind = 'missing' | 'untrusted';\n\nexport interface KeetaAnchorCertificateRequiredErrorJSONProperties {\n\t/**\n\t * Outer array: any-of (OR). Inner array: all-of (AND).\n\t */\n\tacceptedIssuers: { name: string; value: string; }[][];\n\tkind: KeetaAnchorCertificateRequiredKind;\n}\n\ntype KeetaAnchorCertificateRequiredErrorJSON =\n\tReturnType<KeetaAnchorUserError['toJSON']>\n\t& KeetaAnchorCertificateRequiredErrorJSONProperties;\n\nexport class KeetaAnchorCertificateRequiredError extends KeetaAnchorUserError implements KeetaAnchorCertificateRequiredErrorJSONProperties {\n\tstatic override readonly name: string = 'KeetaAnchorCertificateRequiredError';\n\tprivate readonly KeetaAnchorCertificateRequiredErrorObjectTypeID!: string;\n\tprivate static readonly KeetaAnchorCertificateRequiredErrorObjectTypeID = 'b8c5b6df-2f4d-4f60-9d6c-2f4d8a6b1f01';\n\n\treadonly acceptedIssuers: { name: string; value: string; }[][];\n\treadonly kind: KeetaAnchorCertificateRequiredKind;\n\n\tconstructor(args: KeetaAnchorCertificateRequiredErrorJSONProperties, message?: string) {\n\t\tsuper(message ?? KeetaAnchorCertificateRequiredError.defaultMessage(args.kind));\n\t\tif (args.kind === 'missing') {\n\t\t\tthis.statusCode = 401;\n\t\t} else {\n\t\t\tthis.statusCode = 403;\n\t\t}\n\n\t\tObject.defineProperty(this, 'KeetaAnchorCertificateRequiredErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorCertificateRequiredError.KeetaAnchorCertificateRequiredErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\n\t\tthis.acceptedIssuers = args.acceptedIssuers;\n\t\tthis.kind = args.kind;\n\t}\n\n\tprivate static defaultMessage(kind: KeetaAnchorCertificateRequiredKind): string {\n\t\tif (kind === 'missing') {\n\t\t\treturn('No certificate has been published for the signing account');\n\t\t}\n\n\t\treturn('Published certificates do not chain to an accepted issuer');\n\t}\n\n\tstatic override isInstance(input: unknown): input is KeetaAnchorCertificateRequiredError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaAnchorCertificateRequiredErrorObjectTypeID', KeetaAnchorCertificateRequiredError.KeetaAnchorCertificateRequiredErrorObjectTypeID));\n\t}\n\n\toverride asErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\tlet message = this.message;\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\tok: false,\n\t\t\t\tname: this.name,\n\t\t\t\tdata: { acceptedIssuers: this.acceptedIssuers, kind: this.kind },\n\t\t\t\terror: this.message\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\toverride toJSON(): KeetaAnchorCertificateRequiredErrorJSON {\n\t\treturn({\n\t\t\t...super.toJSON(),\n\t\t\tacceptedIssuers: this.acceptedIssuers,\n\t\t\tkind: this.kind\n\t\t});\n\t}\n\n\tstatic override async fromJSON(input: unknown): Promise<KeetaAnchorCertificateRequiredError> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\tif (!('data' in other)) {\n\t\t\tthrow(new Error('Invalid KeetaAnchorCertificateRequiredError JSON: missing data property'));\n\t\t}\n\n\t\tconst parsed = assertKeetaAnchorCertificateRequiredErrorJSONProperties(other.data);\n\t\tconst error = new this({ acceptedIssuers: parsed.acceptedIssuers, kind: parsed.kind }, message);\n\n\t\terror.restoreFromJSON(other);\n\n\t\treturn(error);\n\t}\n}\n"]}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { Account } from "@keetanetwork/keetanet-client/lib/account.js";
|
|
2
|
+
import type { ResolvedCertificateChainRequirement } from "../utils/certificate-network.js";
|
|
3
|
+
import type { Signable } from "../utils/signing.js";
|
|
2
4
|
export type ExtractOk<T> = Omit<Extract<T, {
|
|
3
5
|
ok: true;
|
|
4
6
|
}>, 'ok'>;
|
|
5
|
-
export
|
|
7
|
+
export type HTTPSignedField = {
|
|
6
8
|
nonce: string;
|
|
7
9
|
timestamp: string;
|
|
8
10
|
signature: string;
|
|
9
|
-
}
|
|
11
|
+
};
|
|
10
12
|
export declare const assertHTTPSignedField: (input: unknown) => HTTPSignedField;
|
|
11
13
|
export interface HTTPSignedFieldURLParameters {
|
|
12
14
|
signedField: HTTPSignedField;
|
|
@@ -14,4 +16,20 @@ export interface HTTPSignedFieldURLParameters {
|
|
|
14
16
|
}
|
|
15
17
|
export declare function addSignatureToURL(input: URL | string, data: HTTPSignedFieldURLParameters): URL;
|
|
16
18
|
export declare function parseSignatureFromURL(input: URL | string): Partial<HTTPSignedFieldURLParameters>;
|
|
19
|
+
/**
|
|
20
|
+
* Verify a signed body, then enforce the cert-chain gate. Returns the
|
|
21
|
+
* authenticated account. Throws `KeetaAnchorUserError` on missing or
|
|
22
|
+
* invalid auth, and `KeetaAnchorCertificateRequiredError` when the
|
|
23
|
+
* caller's on-chain cert chain doesn't satisfy `certificateChain`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function verifyBodyAuth<T extends {
|
|
26
|
+
account?: string;
|
|
27
|
+
signed?: unknown;
|
|
28
|
+
}>(request: T, getSigningData: (req: T) => Signable, certificateChain?: ResolvedCertificateChainRequirement): Promise<Account>;
|
|
29
|
+
/**
|
|
30
|
+
* Verify a URL-signed request, then enforce the cert-chain gate. Returns
|
|
31
|
+
* the authenticated account. The signable is built by the caller from a
|
|
32
|
+
* request derived from the URL-bound account public key.
|
|
33
|
+
*/
|
|
34
|
+
export declare function verifyURLAuth(url: URL | string, getSigningData: (account: Account) => Signable, certificateChain?: ResolvedCertificateChainRequirement): Promise<Account>;
|
|
17
35
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/lib/http-server/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/lib/http-server/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8CAA8C,CAAC;AAC5E,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AAC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assertGuard from "typia/lib/internal/_assertGuard
|
|
|
2
2
|
import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js";
|
|
3
3
|
import { KeetaAnchorUserError } from "../error.js";
|
|
4
4
|
import { KeetaNet } from "../../client/index.js";
|
|
5
|
+
import { assertAccountCertificateChain } from "../utils/certificate-network.js";
|
|
5
6
|
import { createAssertEquals } from "typia";
|
|
7
|
+
import { VerifySignedData } from "../utils/signing.js";
|
|
6
8
|
export const assertHTTPSignedField = (() => { const _io0 = (input, _exceptionable = true) => "string" === typeof input.nonce && "string" === typeof input.timestamp && "string" === typeof input.signature && (3 === Object.keys(input).length || Object.keys(input).every(key => {
|
|
7
9
|
if (["nonce", "timestamp", "signature"].some(prop => key === prop))
|
|
8
10
|
return true;
|
|
@@ -108,4 +110,49 @@ export function parseSignatureFromURL(input) {
|
|
|
108
110
|
}
|
|
109
111
|
return (retVal);
|
|
110
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Verify a signed body, then enforce the cert-chain gate. Returns the
|
|
115
|
+
* authenticated account. Throws `KeetaAnchorUserError` on missing or
|
|
116
|
+
* invalid auth, and `KeetaAnchorCertificateRequiredError` when the
|
|
117
|
+
* caller's on-chain cert chain doesn't satisfy `certificateChain`.
|
|
118
|
+
*/
|
|
119
|
+
export async function verifyBodyAuth(request, getSigningData, certificateChain) {
|
|
120
|
+
if (!request.account || !request.signed) {
|
|
121
|
+
throw (new KeetaAnchorUserError('Authentication required'));
|
|
122
|
+
}
|
|
123
|
+
const account = KeetaNet.lib.Account.fromPublicKeyString(request.account).assertAccount();
|
|
124
|
+
const signable = getSigningData(request);
|
|
125
|
+
const signed = assertHTTPSignedField(request.signed);
|
|
126
|
+
const valid = await VerifySignedData(account, signable, signed);
|
|
127
|
+
if (!valid) {
|
|
128
|
+
throw (new KeetaAnchorUserError('Invalid signature'));
|
|
129
|
+
}
|
|
130
|
+
await assertAccountCertificateChain(account, certificateChain);
|
|
131
|
+
return (account);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Verify a URL-signed request, then enforce the cert-chain gate. Returns
|
|
135
|
+
* the authenticated account. The signable is built by the caller from a
|
|
136
|
+
* request derived from the URL-bound account public key.
|
|
137
|
+
*/
|
|
138
|
+
export async function verifyURLAuth(url, getSigningData, certificateChain) {
|
|
139
|
+
let urlString;
|
|
140
|
+
if (typeof url === 'string') {
|
|
141
|
+
urlString = url;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
urlString = url.href;
|
|
145
|
+
}
|
|
146
|
+
const parsed = parseSignatureFromURL(urlString);
|
|
147
|
+
if (!parsed.account || !parsed.signedField) {
|
|
148
|
+
throw (new KeetaAnchorUserError('Authentication required'));
|
|
149
|
+
}
|
|
150
|
+
const signable = getSigningData(parsed.account);
|
|
151
|
+
const valid = await VerifySignedData(parsed.account, signable, parsed.signedField);
|
|
152
|
+
if (!valid) {
|
|
153
|
+
throw (new KeetaAnchorUserError('Invalid signature'));
|
|
154
|
+
}
|
|
155
|
+
await assertAccountCertificateChain(parsed.account, certificateChain);
|
|
156
|
+
return (parsed.account);
|
|
157
|
+
}
|
|
111
158
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/lib/http-server/common.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/lib/http-server/common.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAYvD,MAAM,CAAC,MAAM,qBAAqB;;;;;;;;;;;;;;;;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AAoB,CAAC,yBAAyB,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACnF,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,MAAK,CAAC,IAAI,oBAAoB,CAAC,mBAAmB,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,6BAA6B,CAAC,MAAM,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAEtE,OAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACxB,CAAC","sourcesContent":["import type { Account } from \"@keetanetwork/keetanet-client/lib/account.js\";\nimport type { ResolvedCertificateChainRequirement } from \"../utils/certificate-network.js\";\nimport type { Signable } from \"../utils/signing.js\";\nimport { KeetaAnchorUserError } from \"../error.js\";\nimport { KeetaNet } from \"../../client/index.js\";\nimport { assertAccountCertificateChain } from \"../utils/certificate-network.js\";\nimport { createAssertEquals } from \"typia\";\nimport { VerifySignedData } from \"../utils/signing.js\";\n\nexport type ExtractOk<T> = Omit<Extract<T, { ok: true }>, 'ok'>;\n\nexport type HTTPSignedField = {\n\tnonce: string;\n\t/* Date and time of the request in ISO 8601 format */\n\ttimestamp: string;\n\t/* Signature of the account public key and the nonce as an ASN.1 Sequence, Base64 DER */\n\tsignature: string;\n};\n\nexport const assertHTTPSignedField: (input: unknown) => HTTPSignedField = createAssertEquals<HTTPSignedField>();\n\nexport interface HTTPSignedFieldURLParameters {\n\tsignedField: HTTPSignedField;\n\taccount: Account;\n}\n\nexport function addSignatureToURL(input: URL | string, data: HTTPSignedFieldURLParameters): URL {\n\tlet url: URL;\n\n\tif (typeof input === 'string') {\n\t\turl = new URL(input);\n\t} else {\n\t\turl = new URL(input.toString());\n\t}\n\n\tfor (const key of [ 'nonce', 'timestamp', 'signature' ] as const) {\n\t\tconst searchKey = `signed.${key}`;\n\n\t\tif (url.searchParams.has(searchKey)) {\n\t\t\tthrow(new KeetaAnchorUserError(`URL already has signed field parameter: ${searchKey}`));\n\t\t}\n\n\t\turl.searchParams.set(`signed.${key}`, data.signedField[key]);\n\t}\n\n\turl.searchParams.set('account', data.account.publicKeyString.get());\n\n\treturn(url);\n}\n\nexport function parseSignatureFromURL(input: URL | string): Partial<HTTPSignedFieldURLParameters> {\n\tlet url: URL;\n\n\tif (typeof input === 'string') {\n\t\turl = new URL(input);\n\t} else {\n\t\turl = new URL(input.toString());\n\t}\n\n\tconst retVal: Partial<HTTPSignedFieldURLParameters> = {};\n\n\tconst signedField = ((): HTTPSignedField | undefined => {\n\t\tconst nonce = url.searchParams.get('signed.nonce');\n\t\tconst timestamp = url.searchParams.get('signed.timestamp');\n\t\tconst signature = url.searchParams.get('signed.signature');\n\n\t\tif (!nonce && !timestamp && !signature) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\tif (!nonce || !timestamp || !signature) {\n\t\t\tthrow(new KeetaAnchorUserError('Incomplete signature fields in URL'));\n\t\t}\n\n\t\treturn({ nonce, timestamp, signature });\n\t})();\n\n\tif (signedField) {\n\t\tretVal.signedField = signedField;\n\t}\n\n\tconst account = ((): Account | undefined => {\n\t\tconst accountParam = url.searchParams.get('account');\n\t\tif (!accountParam) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\treturn(KeetaNet.lib.Account.fromPublicKeyString(accountParam).assertAccount());\n\t})();\n\n\tif (account) {\n\t\tretVal.account = account;\n\t}\n\n\treturn(retVal);\n}\n\n/**\n * Verify a signed body, then enforce the cert-chain gate. Returns the\n * authenticated account. Throws `KeetaAnchorUserError` on missing or\n * invalid auth, and `KeetaAnchorCertificateRequiredError` when the\n * caller's on-chain cert chain doesn't satisfy `certificateChain`.\n */\nexport async function verifyBodyAuth<T extends { account?: string; signed?: unknown }>(\n\trequest: T,\n\tgetSigningData: (req: T) => Signable,\n\tcertificateChain?: ResolvedCertificateChainRequirement\n): Promise<Account> {\n\tif (!request.account || !request.signed) {\n\t\tthrow(new KeetaAnchorUserError('Authentication required'));\n\t}\n\n\tconst account = KeetaNet.lib.Account.fromPublicKeyString(request.account).assertAccount();\n\n\tconst signable = getSigningData(request);\n\tconst signed = assertHTTPSignedField(request.signed);\n\tconst valid = await VerifySignedData(account, signable, signed);\n\tif (!valid) {\n\t\tthrow(new KeetaAnchorUserError('Invalid signature'));\n\t}\n\n\tawait assertAccountCertificateChain(account, certificateChain);\n\n\treturn(account);\n}\n\n/**\n * Verify a URL-signed request, then enforce the cert-chain gate. Returns\n * the authenticated account. The signable is built by the caller from a\n * request derived from the URL-bound account public key.\n */\nexport async function verifyURLAuth(\n\turl: URL | string,\n\tgetSigningData: (account: Account) => Signable,\n\tcertificateChain?: ResolvedCertificateChainRequirement\n): Promise<Account> {\n\tlet urlString: string;\n\tif (typeof url === 'string') {\n\t\turlString = url;\n\t} else {\n\t\turlString = url.href;\n\t}\n\n\tconst parsed = parseSignatureFromURL(urlString);\n\tif (!parsed.account || !parsed.signedField) {\n\t\tthrow(new KeetaAnchorUserError('Authentication required'));\n\t}\n\n\tconst signable = getSigningData(parsed.account);\n\tconst valid = await VerifySignedData(parsed.account, signable, parsed.signedField);\n\tif (!valid) {\n\t\tthrow(new KeetaAnchorUserError('Invalid signature'));\n\t}\n\n\tawait assertAccountCertificateChain(parsed.account, certificateChain);\n\n\treturn(parsed.account);\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as http from 'http';
|
|
2
2
|
import type { JSONSerializable } from '../utils/json.js';
|
|
3
3
|
import type { Logger } from '../log/index.js';
|
|
4
|
+
import type { CertificateChainConfig, ResolvedCertificateChainRequirement } from '../utils/certificate-network.js';
|
|
4
5
|
export declare const AssertHTTPErrorData: (input: unknown) => {
|
|
5
6
|
error: string;
|
|
6
7
|
statusCode?: number;
|
|
@@ -58,14 +59,35 @@ export interface KeetaAnchorHTTPServerConfig {
|
|
|
58
59
|
port?: number;
|
|
59
60
|
protocol?: string;
|
|
60
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Optional on-chain cert-chain gate. When set, authenticated callers
|
|
64
|
+
* MUST have a published cert chaining to one of `trustedIssuers`.
|
|
65
|
+
*/
|
|
66
|
+
requireCertificateChain?: CertificateChainConfig | undefined;
|
|
61
67
|
}
|
|
62
68
|
export declare abstract class KeetaNetAnchorHTTPServer<ConfigType extends KeetaAnchorHTTPServerConfig = KeetaAnchorHTTPServerConfig> implements Required<KeetaAnchorHTTPServerConfig> {
|
|
63
69
|
#private;
|
|
64
70
|
readonly port: NonNullable<KeetaAnchorHTTPServerConfig['port']>;
|
|
65
71
|
readonly logger: NonNullable<KeetaAnchorHTTPServerConfig['logger']>;
|
|
66
72
|
readonly id: NonNullable<KeetaAnchorHTTPServerConfig['id']>;
|
|
73
|
+
/**
|
|
74
|
+
* Resolved cert-chain requirement, or `undefined` when disabled.
|
|
75
|
+
* @see {@link requireCertificateChain}.
|
|
76
|
+
*/
|
|
77
|
+
protected readonly resolvedCertificateChainRequirement: ResolvedCertificateChainRequirement | undefined;
|
|
67
78
|
constructor(config: ConfigType);
|
|
68
79
|
protected abstract initRoutes(config: ConfigType): Promise<Routes>;
|
|
80
|
+
/**
|
|
81
|
+
* Public view of the cert-chain config, or `undefined` when disabled.
|
|
82
|
+
*/
|
|
83
|
+
get requireCertificateChain(): CertificateChainConfig | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Trusted-issuer DNs metadata. Is `undefined` when the gate is not configured.
|
|
86
|
+
*/
|
|
87
|
+
protected acceptedIssuerDNs(): {
|
|
88
|
+
name: string;
|
|
89
|
+
value: string;
|
|
90
|
+
}[][] | undefined;
|
|
69
91
|
private static routeMatch;
|
|
70
92
|
private static routeFind;
|
|
71
93
|
private static addCORS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/http-server/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AAC;IAC5D;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,mCAAmC,EAAE,mCAAmC,GAAG,SAAS,CAAC;gBAO5F,MAAM,EAAE,UAAU;IAiC9B,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAElE;;OAEG;IACH,IAAI,uBAAuB,IAAI,sBAAsB,GAAG,SAAS,CAEhE;IAED;;OAEG;IACH,SAAS,CAAC,iBAAiB,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,EAAE,GAAG,SAAS;IAS9E,OAAO,CAAC,MAAM,CAAC,UAAU;IAyEzB,OAAO,CAAC,MAAM,CAAC,SAAS;IA2CxB,OAAO,CAAC,MAAM,CAAC,OAAO;YAyHR,IAAI;IA0QlB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAc5B;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B;;;;;OAKG;IACH,IAAI,GAAG,IAAI,MAAM,CAoChB;IAED,IAAI,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,KAAK,MAAM,CAAC,EAGnE;IAED,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAGtC"}
|
package/lib/http-server/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { KeetaAnchorError, KeetaAnchorUserError } from '../error.js';
|
|
|
4
4
|
import { Log } from '../log/index.js';
|
|
5
5
|
import { createAssert } from 'typia';
|
|
6
6
|
import { assertNever } from '../utils/never.js';
|
|
7
|
+
import { resolveCertificateChainConfig } from '../utils/certificate-network.js';
|
|
7
8
|
export const AssertHTTPErrorData = (() => { const _io0 = input => "string" === typeof input.error && (undefined === input.statusCode || "number" === typeof input.statusCode) && (undefined === input.contentType || "string" === typeof input.contentType); const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.error || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
8
9
|
method: "createAssert",
|
|
9
10
|
path: _path + ".error",
|
|
@@ -45,6 +46,11 @@ export class KeetaNetAnchorHTTPServer {
|
|
|
45
46
|
port;
|
|
46
47
|
logger;
|
|
47
48
|
id;
|
|
49
|
+
/**
|
|
50
|
+
* Resolved cert-chain requirement, or `undefined` when disabled.
|
|
51
|
+
* @see {@link requireCertificateChain}.
|
|
52
|
+
*/
|
|
53
|
+
resolvedCertificateChainRequirement;
|
|
48
54
|
#serverPromise;
|
|
49
55
|
#server;
|
|
50
56
|
#urlParts;
|
|
@@ -55,6 +61,7 @@ export class KeetaNetAnchorHTTPServer {
|
|
|
55
61
|
this.port = config.port ?? 0;
|
|
56
62
|
this.id = config.id ?? crypto.randomUUID();
|
|
57
63
|
this.logger = config.logger ?? Log.Legacy('ANCHOR');
|
|
64
|
+
this.resolvedCertificateChainRequirement = resolveCertificateChainConfig(config.requireCertificateChain);
|
|
58
65
|
if (config.url !== undefined) {
|
|
59
66
|
if (config.url instanceof URL || typeof config.url === 'string') {
|
|
60
67
|
this.#url = config.url;
|
|
@@ -82,6 +89,22 @@ export class KeetaNetAnchorHTTPServer {
|
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Public view of the cert-chain config, or `undefined` when disabled.
|
|
94
|
+
*/
|
|
95
|
+
get requireCertificateChain() {
|
|
96
|
+
return (this.resolvedCertificateChainRequirement);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Trusted-issuer DNs metadata. Is `undefined` when the gate is not configured.
|
|
100
|
+
*/
|
|
101
|
+
acceptedIssuerDNs() {
|
|
102
|
+
const requirement = this.resolvedCertificateChainRequirement;
|
|
103
|
+
if (requirement === undefined) {
|
|
104
|
+
return (undefined);
|
|
105
|
+
}
|
|
106
|
+
return (requirement.acceptedIssuerDNs);
|
|
107
|
+
}
|
|
85
108
|
static routeMatch(requestURL, routeURL) {
|
|
86
109
|
const requestURLPaths = requestURL.pathname.split('/');
|
|
87
110
|
const routeURLPaths = routeURL.pathname.split('/');
|