@keetanetwork/anchor 0.0.111 → 0.0.113
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/chaining.d.ts +8 -0
- package/lib/chaining.d.ts.map +1 -1
- package/lib/chaining.js +111 -3
- package/lib/chaining.js.map +1 -1
- package/lib/http-server/common.d.ts +3 -2
- package/lib/http-server/common.d.ts.map +1 -1
- package/lib/http-server/common.js +9 -13
- package/lib/http-server/common.js.map +1 -1
- package/lib/http-server/index.d.ts +21 -1
- package/lib/http-server/index.d.ts.map +1 -1
- package/lib/http-server/index.js +84 -36
- package/lib/http-server/index.js.map +1 -1
- package/lib/http-server/replay-guard.d.ts +29 -0
- package/lib/http-server/replay-guard.d.ts.map +1 -0
- package/lib/http-server/replay-guard.js +58 -0
- package/lib/http-server/replay-guard.js.map +1 -0
- package/lib/http-server/request-signing.d.ts +53 -0
- package/lib/http-server/request-signing.d.ts.map +1 -0
- package/lib/http-server/request-signing.js +130 -0
- package/lib/http-server/request-signing.js.map +1 -0
- package/lib/queue/drivers/queue_postgres.d.ts +7 -1
- package/lib/queue/drivers/queue_postgres.d.ts.map +1 -1
- package/lib/queue/drivers/queue_postgres.js +12 -4
- package/lib/queue/drivers/queue_postgres.js.map +1 -1
- package/lib/utils/signing.d.ts +5 -0
- package/lib/utils/signing.d.ts.map +1 -1
- package/lib/utils/signing.js +6 -1
- package/lib/utils/signing.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/services/asset-movement/client.d.ts +5 -4
- package/services/asset-movement/client.d.ts.map +1 -1
- package/services/asset-movement/client.js +27 -13
- package/services/asset-movement/client.js.map +1 -1
- package/services/asset-movement/common.generated.js +1 -1
- package/services/asset-movement/common.server.generated.js +50 -50
- package/services/asset-movement/server.d.ts.map +1 -1
- package/services/asset-movement/server.js +22 -4
- package/services/asset-movement/server.js.map +1 -1
- package/services/fx/client.d.ts +91 -13
- package/services/fx/client.d.ts.map +1 -1
- package/services/fx/client.js +328 -98
- package/services/fx/client.js.map +1 -1
- package/services/fx/common.d.ts +16 -0
- package/services/fx/common.d.ts.map +1 -1
- package/services/fx/common.js +44 -1
- package/services/fx/common.js.map +1 -1
- package/services/fx/server.d.ts.map +1 -1
- package/services/fx/server.js +45 -38
- package/services/fx/server.js.map +1 -1
- package/services/kyc/client.d.ts +8 -3
- package/services/kyc/client.d.ts.map +1 -1
- package/services/kyc/client.js +24 -23
- package/services/kyc/client.js.map +1 -1
- package/services/kyc/common.d.ts +0 -7
- package/services/kyc/common.d.ts.map +1 -1
- package/services/kyc/common.js +0 -8
- package/services/kyc/common.js.map +1 -1
- package/services/kyc/server.d.ts +3 -1
- package/services/kyc/server.d.ts.map +1 -1
- package/services/kyc/server.js +15 -33
- package/services/kyc/server.js.map +1 -1
- package/services/notification/client.d.ts.map +1 -1
- package/services/notification/client.js +39 -33
- package/services/notification/client.js.map +1 -1
- package/services/notification/server.js +10 -10
- package/services/notification/server.js.map +1 -1
- package/services/storage/client.d.ts +3 -0
- package/services/storage/client.d.ts.map +1 -1
- package/services/storage/client.js +41 -11
- package/services/storage/client.js.map +1 -1
- package/services/storage/server.d.ts.map +1 -1
- package/services/storage/server.js +12 -11
- package/services/storage/server.js.map +1 -1
- package/services/username/client.d.ts +12 -1
- package/services/username/client.d.ts.map +1 -1
- package/services/username/client.js +36 -30
- package/services/username/client.js.map +1 -1
- package/services/username/server.d.ts.map +1 -1
- package/services/username/server.js +7 -6
- package/services/username/server.js.map +1 -1
|
@@ -39,9 +39,9 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataSer
|
|
|
39
39
|
}
|
|
40
40
|
const registerTargetHandler = this.notification.registerTarget;
|
|
41
41
|
if (registerTargetHandler) {
|
|
42
|
-
routes['POST /api/target'] = async (_params, body) => {
|
|
42
|
+
routes['POST /api/target'] = async (_params, body, _ignore_headers, url) => {
|
|
43
43
|
const raw = assertKeetaNotificationAnchorRegisterTargetRequestJSON(body);
|
|
44
|
-
const account = await verifyBodyAuth(raw, getNotificationRegisterTargetRequestSignable, this.resolvedCertificateChainRequirement);
|
|
44
|
+
const account = await verifyBodyAuth(this.requestAuthContext('POST', url, body), raw, getNotificationRegisterTargetRequestSignable, this.resolvedCertificateChainRequirement);
|
|
45
45
|
const request = { ...raw, account };
|
|
46
46
|
const registerResponse = await registerTargetHandler(request);
|
|
47
47
|
return ({
|
|
@@ -56,7 +56,7 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataSer
|
|
|
56
56
|
const listTargetsHandler = this.notification.listTargets;
|
|
57
57
|
if (listTargetsHandler) {
|
|
58
58
|
routes['GET /api/targets'] = async (_ignore_params, _ignore_body, _ignore_headers, url) => {
|
|
59
|
-
const account = await verifyURLAuth(url, function () { return (getNotificationListTargetsRequestSignable()); }, this.resolvedCertificateChainRequirement);
|
|
59
|
+
const account = await verifyURLAuth(this.requestAuthContext('GET', url), function () { return (getNotificationListTargetsRequestSignable()); }, this.resolvedCertificateChainRequirement);
|
|
60
60
|
const listResponse = await listTargetsHandler({ account });
|
|
61
61
|
return ({
|
|
62
62
|
output: JSON.stringify({
|
|
@@ -70,9 +70,9 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataSer
|
|
|
70
70
|
const deleteTargetHandler = this.notification.deleteTarget;
|
|
71
71
|
if (deleteTargetHandler) {
|
|
72
72
|
// XXX:TODO should this be post with body or delete with URL param? Delete with URL param is more RESTful but can be more difficult to call from some clients and doesn't allow for a request body (so all data must be in the URL or signature)
|
|
73
|
-
routes['POST /api/delete-target'] = async (_params, body) => {
|
|
73
|
+
routes['POST /api/delete-target'] = async (_params, body, _ignore_headers, url) => {
|
|
74
74
|
const raw = assertKeetaNotificationAnchorDeleteTargetRequestJSON(body);
|
|
75
|
-
const account = await verifyBodyAuth(raw, getNotificationDeleteTargetRequestSignable, this.resolvedCertificateChainRequirement);
|
|
75
|
+
const account = await verifyBodyAuth(this.requestAuthContext('POST', url, body), raw, getNotificationDeleteTargetRequestSignable, this.resolvedCertificateChainRequirement);
|
|
76
76
|
const request = { ...raw, account };
|
|
77
77
|
const deleteResponse = await deleteTargetHandler(request);
|
|
78
78
|
return ({
|
|
@@ -83,7 +83,7 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataSer
|
|
|
83
83
|
}
|
|
84
84
|
const createSubscriptionHandler = this.notification.createSubscription;
|
|
85
85
|
if (createSubscriptionHandler) {
|
|
86
|
-
routes['POST /api/subscription'] = async (_params, body) => {
|
|
86
|
+
routes['POST /api/subscription'] = async (_params, body, _ignore_headers, url) => {
|
|
87
87
|
const raw = assertKeetaNotificationAnchorCreateSubscriptionRequestJSON(body);
|
|
88
88
|
let subscription;
|
|
89
89
|
if (raw.subscription.type === 'RECEIVE_FUNDS') {
|
|
@@ -99,7 +99,7 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataSer
|
|
|
99
99
|
else {
|
|
100
100
|
throw (new KeetaAnchorUserError(`Unsupported subscription type`));
|
|
101
101
|
}
|
|
102
|
-
const account = await verifyBodyAuth(raw, function () {
|
|
102
|
+
const account = await verifyBodyAuth(this.requestAuthContext('POST', url, body), raw, function () {
|
|
103
103
|
return (getNotificationCreateSubscriptionRequestSignable({ subscription }));
|
|
104
104
|
}, this.resolvedCertificateChainRequirement);
|
|
105
105
|
const request = { account, subscription, signed: raw.signed };
|
|
@@ -113,7 +113,7 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataSer
|
|
|
113
113
|
const listSubscriptionsHandler = this.notification.listSubscriptions;
|
|
114
114
|
if (listSubscriptionsHandler) {
|
|
115
115
|
routes['GET /api/subscriptions'] = async (_ignore_params, _ignore_body, _ignore_headers, url) => {
|
|
116
|
-
const account = await verifyURLAuth(url, function () { return (getNotificationListSubscriptionsRequestSignable()); }, this.resolvedCertificateChainRequirement);
|
|
116
|
+
const account = await verifyURLAuth(this.requestAuthContext('GET', url), function () { return (getNotificationListSubscriptionsRequestSignable()); }, this.resolvedCertificateChainRequirement);
|
|
117
117
|
const listResponse = await listSubscriptionsHandler({ account });
|
|
118
118
|
const subscriptionsJSON = listResponse.subscriptions.map(function (subscription) {
|
|
119
119
|
const { locale, ...restSubscription } = subscription.subscription;
|
|
@@ -136,9 +136,9 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataSer
|
|
|
136
136
|
}
|
|
137
137
|
const deleteSubscriptionHandler = this.notification.deleteSubscription;
|
|
138
138
|
if (deleteSubscriptionHandler) {
|
|
139
|
-
routes['POST /api/delete-subscription'] = async (_params, body) => {
|
|
139
|
+
routes['POST /api/delete-subscription'] = async (_params, body, _ignore_headers, url) => {
|
|
140
140
|
const raw = assertKeetaNotificationAnchorDeleteSubscriptionRequestJSON(body);
|
|
141
|
-
const account = await verifyBodyAuth(raw, getNotificationDeleteSubscriptionRequestSignable, this.resolvedCertificateChainRequirement);
|
|
141
|
+
const account = await verifyBodyAuth(this.requestAuthContext('POST', url, body), raw, getNotificationDeleteSubscriptionRequestSignable, this.resolvedCertificateChainRequirement);
|
|
142
142
|
const request = { ...raw, account };
|
|
143
143
|
const deleteResponse = await deleteSubscriptionHandler(request);
|
|
144
144
|
return ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/services/notification/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAoB1D,OAAO,EACN,4CAA4C,EAC5C,yCAAyC,EACzC,0CAA0C,EAC1C,gDAAgD,EAChD,gDAAgD,EAChD,+CAA+C,EAC/C,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,sDAAsD,EACtD,oDAAoD,EACpD,0DAA0D,EAC1D,0DAA0D,EAC1D,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBA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BAAiB,GAAG,iBAAiB,CAAC;QAC9C,CAAC;QAED,OAAM,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;CACD","sourcesContent":["import * as KeetaNet from '@keetanetwork/keetanet-client';\nimport type * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';\nimport type { KeetaAnchorMetadataServerConfig } from '../../lib/anchor-metadata-server.js';\nimport type {\n\tKeetaNotificationAnchorRegisterTargetClientRequest,\n\tKeetaNotificationAnchorListTargetsClientRequest,\n\tNotificationTargetWithIDResponse,\n\tKeetaNotificationAnchorDeleteTargetClientRequest,\n\tKeetaNotificationAnchorRegisterTargetRequest,\n\tKeetaNotificationAnchorDeleteTargetRequest,\n\tKeetaNotificationAnchorCreateSubscriptionClientRequest,\n\tKeetaNotificationAnchorDeleteSubscriptionClientRequest,\n\tKeetaNotificationAnchorDeleteSubscriptionRequest,\n\tKeetaNotificationAnchorListSubscriptionsClientRequest,\n\tSubscriptionDetails,\n\tNotificationSubscriptionArguments,\n\tNotificationSubscriptionType,\n\tSupportedChannelConfigurationMetadata,\n\tSubscriptionDetailsJSON\n} from './common.js';\nimport {\n\tgetNotificationRegisterTargetRequestSignable,\n\tgetNotificationListTargetsRequestSignable,\n\tgetNotificationDeleteTargetRequestSignable,\n\tgetNotificationCreateSubscriptionRequestSignable,\n\tgetNotificationDeleteSubscriptionRequestSignable,\n\tgetNotificationListSubscriptionsRequestSignable\n} from './common.js';\nimport {\n\tassertKeetaNotificationAnchorRegisterTargetRequestJSON,\n\tassertKeetaNotificationAnchorDeleteTargetRequestJSON,\n\tassertKeetaNotificationAnchorCreateSubscriptionRequestJSON,\n\tassertKeetaNotificationAnchorDeleteSubscriptionRequestJSON\n} from './common.server.generated.js';\nimport type { ServiceMetadata, ServiceMetadataAuthenticationType } from '../../lib/resolver.js';\nimport { KeetaAnchorMetadataServer } from '../../lib/anchor-metadata-server.js';\nimport { KeetaAnchorUserError } from '../../lib/error.js';\nimport { verifyBodyAuth, verifyURLAuth } from '../../lib/http-server/common.js';\n\nexport interface KeetaAnchorNotificationServerConfig extends KeetaAnchorMetadataServerConfig {\n\thomepage?: string | (() => Promise<string> | string);\n\tnotification: {\n\t\tregisterTarget?: (args: Required<KeetaNotificationAnchorRegisterTargetClientRequest>) => Promise<{ id: string; }>;\n\t\tlistTargets?: (args: Required<KeetaNotificationAnchorListTargetsClientRequest>) => Promise<{ targets: NotificationTargetWithIDResponse[]; }>;\n\t\tdeleteTarget?: (args: Required<KeetaNotificationAnchorDeleteTargetClientRequest>) => Promise<{ ok: boolean; }>;\n\n\t\tcreateSubscription?: (args: Required<KeetaNotificationAnchorCreateSubscriptionClientRequest>) => Promise<{ id: string; }>;\n\t\tlistSubscriptions?: (args: Required<KeetaNotificationAnchorListSubscriptionsClientRequest>) => Promise<{ subscriptions: SubscriptionDetails[]; }>;\n\t\tdeleteSubscription?: (args: Required<KeetaNotificationAnchorDeleteSubscriptionClientRequest>) => Promise<{ ok: boolean; }>;\n\n\t\tsupportedChannels?: SupportedChannelConfigurationMetadata;\n\t\tsupportedSubscriptions?: NotificationSubscriptionType[];\n\t};\n\troutes?: KeetaAnchorHTTPServer.Routes;\n}\n\nexport class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataServer<NonNullable<ServiceMetadata['services']['notification']>[string], KeetaAnchorNotificationServerConfig> {\n\treadonly homepage: NonNullable<KeetaAnchorNotificationServerConfig['homepage']>;\n\treadonly notification: KeetaAnchorNotificationServerConfig['notification'];\n\treadonly routes: NonNullable<KeetaAnchorNotificationServerConfig['routes']>;\n\n\tconstructor(config: KeetaAnchorNotificationServerConfig) {\n\t\tsuper(config);\n\n\t\tthis.homepage = config.homepage ?? '';\n\t\tthis.notification = config.notification;\n\t\tthis.routes = config.routes ?? {};\n\t}\n\n\tprotected async initRoutes(config: KeetaAnchorNotificationServerConfig): Promise<KeetaAnchorHTTPServer.Routes> {\n\t\tconst routes: KeetaAnchorHTTPServer.Routes = {\n\t\t\t...(await super.initRoutes(config)),\n\t\t\t...this.routes\n\t\t};\n\n\t\tif ('homepage' in config) {\n\t\t\troutes['GET /'] = async function() {\n\t\t\t\tlet homepageData: string;\n\t\t\t\tif (typeof config.homepage === 'string') {\n\t\t\t\t\thomepageData = config.homepage;\n\t\t\t\t} else {\n\t\t\t\t\tif (!config.homepage) {\n\t\t\t\t\t\tthrow(new Error('internal error: No homepage function provided'));\n\t\t\t\t\t}\n\n\t\t\t\t\thomepageData = await config.homepage();\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: homepageData,\n\t\t\t\t\tcontentType: 'text/html; charset=utf-8'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst registerTargetHandler = this.notification.registerTarget;\n\t\tif (registerTargetHandler) {\n\t\t\troutes['POST /api/target'] = async (_params, body) => {\n\t\t\t\tconst raw = assertKeetaNotificationAnchorRegisterTargetRequestJSON(body);\n\t\t\t\tconst account = await verifyBodyAuth(raw, getNotificationRegisterTargetRequestSignable, this.resolvedCertificateChainRequirement);\n\t\t\t\tconst request: Required<KeetaNotificationAnchorRegisterTargetRequest> = { ...raw, account };\n\t\t\t\tconst registerResponse = await registerTargetHandler(request);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify({\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\tid: registerResponse.id\n\t\t\t\t\t}),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst listTargetsHandler = this.notification.listTargets;\n\t\tif (listTargetsHandler) {\n\t\t\troutes['GET /api/targets'] = async (_ignore_params, _ignore_body, _ignore_headers, url) => {\n\t\t\t\tconst account = await verifyURLAuth(\n\t\t\t\t\turl,\n\t\t\t\t\tfunction() { return(getNotificationListTargetsRequestSignable()); },\n\t\t\t\t\tthis.resolvedCertificateChainRequirement\n\t\t\t\t);\n\t\t\t\tconst listResponse = await listTargetsHandler({ account });\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify({\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\ttargets: listResponse.targets\n\t\t\t\t\t}),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst deleteTargetHandler = this.notification.deleteTarget;\n\t\tif (deleteTargetHandler) {\n\t\t\t// XXX:TODO should this be post with body or delete with URL param? Delete with URL param is more RESTful but can be more difficult to call from some clients and doesn't allow for a request body (so all data must be in the URL or signature)\n\t\t\troutes['POST /api/delete-target'] = async (_params, body) => {\n\t\t\t\tconst raw = assertKeetaNotificationAnchorDeleteTargetRequestJSON(body);\n\t\t\t\tconst account = await verifyBodyAuth(raw, getNotificationDeleteTargetRequestSignable, this.resolvedCertificateChainRequirement);\n\t\t\t\tconst request: Required<KeetaNotificationAnchorDeleteTargetRequest> = { ...raw, account };\n\t\t\t\tconst deleteResponse = await deleteTargetHandler(request);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(deleteResponse),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst createSubscriptionHandler = this.notification.createSubscription;\n\t\tif (createSubscriptionHandler) {\n\t\t\troutes['POST /api/subscription'] = async (_params, body) => {\n\t\t\t\tconst raw = assertKeetaNotificationAnchorCreateSubscriptionRequestJSON(body);\n\n\t\t\t\tlet subscription: NotificationSubscriptionArguments;\n\t\t\t\tif (raw.subscription.type === 'RECEIVE_FUNDS') {\n\t\t\t\t\tsubscription = {\n\t\t\t\t\t\ttype: 'RECEIVE_FUNDS',\n\t\t\t\t\t\ttarget: raw.subscription.target,\n\t\t\t\t\t\t...(raw.subscription.toAddress\n\t\t\t\t\t\t\t? { toAddress: KeetaNet.lib.Account.fromPublicKeyString(raw.subscription.toAddress) }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t...(raw.subscription.locale ? { locale: new Intl.Locale(raw.subscription.locale) } : {})\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\tthrow(new KeetaAnchorUserError(`Unsupported subscription type`));\n\t\t\t\t}\n\n\t\t\t\tconst account = await verifyBodyAuth(raw, function() {\n\t\t\t\t\treturn(getNotificationCreateSubscriptionRequestSignable({ subscription }));\n\t\t\t\t}, this.resolvedCertificateChainRequirement);\n\n\t\t\t\tconst request = { account, subscription, signed: raw.signed };\n\t\t\t\tconst createResponse = await createSubscriptionHandler(request);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify({ ok: true, id: createResponse.id }),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst listSubscriptionsHandler = this.notification.listSubscriptions;\n\t\tif (listSubscriptionsHandler) {\n\t\t\troutes['GET /api/subscriptions'] = async (_ignore_params, _ignore_body, _ignore_headers, url) => {\n\t\t\t\tconst account = await verifyURLAuth(\n\t\t\t\t\turl,\n\t\t\t\t\tfunction() { return(getNotificationListSubscriptionsRequestSignable()); },\n\t\t\t\t\tthis.resolvedCertificateChainRequirement\n\t\t\t\t);\n\n\t\t\t\tconst listResponse = await listSubscriptionsHandler({ account });\n\t\t\t\tconst subscriptionsJSON: SubscriptionDetailsJSON[] = listResponse.subscriptions.map(function(subscription): SubscriptionDetailsJSON {\n\t\t\t\t\tconst { locale, ...restSubscription } = subscription.subscription;\n\t\t\t\t\treturn({\n\t\t\t\t\t\t...subscription,\n\t\t\t\t\t\tsubscription: {\n\t\t\t\t\t\t\t...KeetaNet.lib.Utils.Conversion.toJSONSerializable(restSubscription),\n\t\t\t\t\t\t\t...(locale ? { locale: locale.toString() } : {})\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(KeetaNet.lib.Utils.Conversion.toJSONSerializable({\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\tsubscriptions: subscriptionsJSON\n\t\t\t\t\t})),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst deleteSubscriptionHandler = this.notification.deleteSubscription;\n\t\tif (deleteSubscriptionHandler) {\n\t\t\troutes['POST /api/delete-subscription'] = async (_params, body) => {\n\t\t\t\tconst raw = assertKeetaNotificationAnchorDeleteSubscriptionRequestJSON(body);\n\t\t\t\tconst account = await verifyBodyAuth(raw, getNotificationDeleteSubscriptionRequestSignable, this.resolvedCertificateChainRequirement);\n\t\t\t\tconst request: Required<KeetaNotificationAnchorDeleteSubscriptionRequest> = { ...raw, account };\n\t\t\t\tconst deleteResponse = await deleteSubscriptionHandler(request);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(deleteResponse),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\treturn(routes);\n\t}\n\n\tprotected async buildServiceMetadata(): Promise<NonNullable<ServiceMetadata['services']['notification']>[string]> {\n\t\tconst retval: NonNullable<ServiceMetadata['services']['notification']>[string] = { operations: {}};\n\n\t\tconst authentication: ServiceMetadataAuthenticationType = {\n\t\t\tmethod: 'keeta-account',\n\t\t\ttype: 'required'\n\t\t}\n\n\t\tif (this.notification.registerTarget) {\n\t\t\tretval.operations.registerTarget = { url: (new URL('/api/target', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.listTargets) {\n\t\t\tretval.operations.listTargets = { url: (new URL('/api/targets', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.deleteTarget) {\n\t\t\tretval.operations.deleteTarget = { url: (new URL('/api/delete-target', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.createSubscription) {\n\t\t\tretval.operations.createSubscription = { url: (new URL('/api/subscription', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.listSubscriptions) {\n\t\t\tretval.operations.listSubscriptions = { url: (new URL('/api/subscriptions', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.deleteSubscription) {\n\t\t\tretval.operations.deleteSubscription = { url: (new URL('/api/delete-subscription', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.supportedChannels) {\n\t\t\tretval.supportedChannels = this.notification.supportedChannels;\n\t\t}\n\n\t\tif (this.notification.supportedSubscriptions) {\n\t\t\tretval.supportedSubscriptions = this.notification.supportedSubscriptions;\n\t\t}\n\n\t\tconst acceptedIssuerDNs = this.acceptedIssuerDNs();\n\t\tif (acceptedIssuerDNs !== undefined) {\n\t\t\tretval.acceptedIssuerDNs = acceptedIssuerDNs;\n\t\t}\n\n\t\treturn(retval);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/services/notification/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAoB1D,OAAO,EACN,4CAA4C,EAC5C,yCAAyC,EACzC,0CAA0C,EAC1C,gDAAgD,EAChD,gDAAgD,EAChD,+CAA+C,EAC/C,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,sDAAsD,EACtD,oDAAoD,EACpD,0DAA0D,EAC1D,0DAA0D,EAC1D,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAmBhF,MAAM,OAAO,oCAAqC,SAAQ,yBAAgI;IAChL,QAAQ,CAA+D;IACvE,YAAY,CAAsD;IAClE,MAAM,CAA6D;IAE5E,YAAY,MAA2C;QACtD,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;QACtC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,MAA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E,CAAC;QACnD,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC9C,CAAC;QAED,OAAM,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;CACD","sourcesContent":["import * as KeetaNet from '@keetanetwork/keetanet-client';\nimport type * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';\nimport type { KeetaAnchorMetadataServerConfig } from '../../lib/anchor-metadata-server.js';\nimport type {\n\tKeetaNotificationAnchorRegisterTargetClientRequest,\n\tKeetaNotificationAnchorListTargetsClientRequest,\n\tNotificationTargetWithIDResponse,\n\tKeetaNotificationAnchorDeleteTargetClientRequest,\n\tKeetaNotificationAnchorRegisterTargetRequest,\n\tKeetaNotificationAnchorDeleteTargetRequest,\n\tKeetaNotificationAnchorCreateSubscriptionClientRequest,\n\tKeetaNotificationAnchorDeleteSubscriptionClientRequest,\n\tKeetaNotificationAnchorDeleteSubscriptionRequest,\n\tKeetaNotificationAnchorListSubscriptionsClientRequest,\n\tSubscriptionDetails,\n\tNotificationSubscriptionArguments,\n\tNotificationSubscriptionType,\n\tSupportedChannelConfigurationMetadata,\n\tSubscriptionDetailsJSON\n} from './common.js';\nimport {\n\tgetNotificationRegisterTargetRequestSignable,\n\tgetNotificationListTargetsRequestSignable,\n\tgetNotificationDeleteTargetRequestSignable,\n\tgetNotificationCreateSubscriptionRequestSignable,\n\tgetNotificationDeleteSubscriptionRequestSignable,\n\tgetNotificationListSubscriptionsRequestSignable\n} from './common.js';\nimport {\n\tassertKeetaNotificationAnchorRegisterTargetRequestJSON,\n\tassertKeetaNotificationAnchorDeleteTargetRequestJSON,\n\tassertKeetaNotificationAnchorCreateSubscriptionRequestJSON,\n\tassertKeetaNotificationAnchorDeleteSubscriptionRequestJSON\n} from './common.server.generated.js';\nimport type { ServiceMetadata, ServiceMetadataAuthenticationType } from '../../lib/resolver.js';\nimport { KeetaAnchorMetadataServer } from '../../lib/anchor-metadata-server.js';\nimport { KeetaAnchorUserError } from '../../lib/error.js';\nimport { verifyBodyAuth, verifyURLAuth } from '../../lib/http-server/common.js';\n\nexport interface KeetaAnchorNotificationServerConfig extends KeetaAnchorMetadataServerConfig {\n\thomepage?: string | (() => Promise<string> | string);\n\tnotification: {\n\t\tregisterTarget?: (args: Required<KeetaNotificationAnchorRegisterTargetClientRequest>) => Promise<{ id: string; }>;\n\t\tlistTargets?: (args: Required<KeetaNotificationAnchorListTargetsClientRequest>) => Promise<{ targets: NotificationTargetWithIDResponse[]; }>;\n\t\tdeleteTarget?: (args: Required<KeetaNotificationAnchorDeleteTargetClientRequest>) => Promise<{ ok: boolean; }>;\n\n\t\tcreateSubscription?: (args: Required<KeetaNotificationAnchorCreateSubscriptionClientRequest>) => Promise<{ id: string; }>;\n\t\tlistSubscriptions?: (args: Required<KeetaNotificationAnchorListSubscriptionsClientRequest>) => Promise<{ subscriptions: SubscriptionDetails[]; }>;\n\t\tdeleteSubscription?: (args: Required<KeetaNotificationAnchorDeleteSubscriptionClientRequest>) => Promise<{ ok: boolean; }>;\n\n\t\tsupportedChannels?: SupportedChannelConfigurationMetadata;\n\t\tsupportedSubscriptions?: NotificationSubscriptionType[];\n\t};\n\troutes?: KeetaAnchorHTTPServer.Routes;\n}\n\nexport class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataServer<NonNullable<ServiceMetadata['services']['notification']>[string], KeetaAnchorNotificationServerConfig> {\n\treadonly homepage: NonNullable<KeetaAnchorNotificationServerConfig['homepage']>;\n\treadonly notification: KeetaAnchorNotificationServerConfig['notification'];\n\treadonly routes: NonNullable<KeetaAnchorNotificationServerConfig['routes']>;\n\n\tconstructor(config: KeetaAnchorNotificationServerConfig) {\n\t\tsuper(config);\n\n\t\tthis.homepage = config.homepage ?? '';\n\t\tthis.notification = config.notification;\n\t\tthis.routes = config.routes ?? {};\n\t}\n\n\tprotected async initRoutes(config: KeetaAnchorNotificationServerConfig): Promise<KeetaAnchorHTTPServer.Routes> {\n\t\tconst routes: KeetaAnchorHTTPServer.Routes = {\n\t\t\t...(await super.initRoutes(config)),\n\t\t\t...this.routes\n\t\t};\n\n\t\tif ('homepage' in config) {\n\t\t\troutes['GET /'] = async function() {\n\t\t\t\tlet homepageData: string;\n\t\t\t\tif (typeof config.homepage === 'string') {\n\t\t\t\t\thomepageData = config.homepage;\n\t\t\t\t} else {\n\t\t\t\t\tif (!config.homepage) {\n\t\t\t\t\t\tthrow(new Error('internal error: No homepage function provided'));\n\t\t\t\t\t}\n\n\t\t\t\t\thomepageData = await config.homepage();\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: homepageData,\n\t\t\t\t\tcontentType: 'text/html; charset=utf-8'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst registerTargetHandler = this.notification.registerTarget;\n\t\tif (registerTargetHandler) {\n\t\t\troutes['POST /api/target'] = async (_params, body, _ignore_headers, url) => {\n\t\t\t\tconst raw = assertKeetaNotificationAnchorRegisterTargetRequestJSON(body);\n\t\t\t\tconst account = await verifyBodyAuth(this.requestAuthContext('POST', url, body), raw, getNotificationRegisterTargetRequestSignable, this.resolvedCertificateChainRequirement);\n\t\t\t\tconst request: Required<KeetaNotificationAnchorRegisterTargetRequest> = { ...raw, account };\n\t\t\t\tconst registerResponse = await registerTargetHandler(request);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify({\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\tid: registerResponse.id\n\t\t\t\t\t}),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst listTargetsHandler = this.notification.listTargets;\n\t\tif (listTargetsHandler) {\n\t\t\troutes['GET /api/targets'] = async (_ignore_params, _ignore_body, _ignore_headers, url) => {\n\t\t\t\tconst account = await verifyURLAuth(\n\t\t\t\t\tthis.requestAuthContext('GET', url),\n\t\t\t\t\tfunction() { return(getNotificationListTargetsRequestSignable()); },\n\t\t\t\t\tthis.resolvedCertificateChainRequirement\n\t\t\t\t);\n\t\t\t\tconst listResponse = await listTargetsHandler({ account });\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify({\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\ttargets: listResponse.targets\n\t\t\t\t\t}),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst deleteTargetHandler = this.notification.deleteTarget;\n\t\tif (deleteTargetHandler) {\n\t\t\t// XXX:TODO should this be post with body or delete with URL param? Delete with URL param is more RESTful but can be more difficult to call from some clients and doesn't allow for a request body (so all data must be in the URL or signature)\n\t\t\troutes['POST /api/delete-target'] = async (_params, body, _ignore_headers, url) => {\n\t\t\t\tconst raw = assertKeetaNotificationAnchorDeleteTargetRequestJSON(body);\n\t\t\t\tconst account = await verifyBodyAuth(this.requestAuthContext('POST', url, body), raw, getNotificationDeleteTargetRequestSignable, this.resolvedCertificateChainRequirement);\n\t\t\t\tconst request: Required<KeetaNotificationAnchorDeleteTargetRequest> = { ...raw, account };\n\t\t\t\tconst deleteResponse = await deleteTargetHandler(request);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(deleteResponse),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst createSubscriptionHandler = this.notification.createSubscription;\n\t\tif (createSubscriptionHandler) {\n\t\t\troutes['POST /api/subscription'] = async (_params, body, _ignore_headers, url) => {\n\t\t\t\tconst raw = assertKeetaNotificationAnchorCreateSubscriptionRequestJSON(body);\n\n\t\t\t\tlet subscription: NotificationSubscriptionArguments;\n\t\t\t\tif (raw.subscription.type === 'RECEIVE_FUNDS') {\n\t\t\t\t\tsubscription = {\n\t\t\t\t\t\ttype: 'RECEIVE_FUNDS',\n\t\t\t\t\t\ttarget: raw.subscription.target,\n\t\t\t\t\t\t...(raw.subscription.toAddress\n\t\t\t\t\t\t\t? { toAddress: KeetaNet.lib.Account.fromPublicKeyString(raw.subscription.toAddress) }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t...(raw.subscription.locale ? { locale: new Intl.Locale(raw.subscription.locale) } : {})\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\tthrow(new KeetaAnchorUserError(`Unsupported subscription type`));\n\t\t\t\t}\n\n\t\t\t\tconst account = await verifyBodyAuth(this.requestAuthContext('POST', url, body), raw, function() {\n\t\t\t\t\treturn(getNotificationCreateSubscriptionRequestSignable({ subscription }));\n\t\t\t\t}, this.resolvedCertificateChainRequirement);\n\n\t\t\t\tconst request = { account, subscription, signed: raw.signed };\n\t\t\t\tconst createResponse = await createSubscriptionHandler(request);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify({ ok: true, id: createResponse.id }),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst listSubscriptionsHandler = this.notification.listSubscriptions;\n\t\tif (listSubscriptionsHandler) {\n\t\t\troutes['GET /api/subscriptions'] = async (_ignore_params, _ignore_body, _ignore_headers, url) => {\n\t\t\t\tconst account = await verifyURLAuth(\n\t\t\t\t\tthis.requestAuthContext('GET', url),\n\t\t\t\t\tfunction() { return(getNotificationListSubscriptionsRequestSignable()); },\n\t\t\t\t\tthis.resolvedCertificateChainRequirement\n\t\t\t\t);\n\n\t\t\t\tconst listResponse = await listSubscriptionsHandler({ account });\n\t\t\t\tconst subscriptionsJSON: SubscriptionDetailsJSON[] = listResponse.subscriptions.map(function(subscription): SubscriptionDetailsJSON {\n\t\t\t\t\tconst { locale, ...restSubscription } = subscription.subscription;\n\t\t\t\t\treturn({\n\t\t\t\t\t\t...subscription,\n\t\t\t\t\t\tsubscription: {\n\t\t\t\t\t\t\t...KeetaNet.lib.Utils.Conversion.toJSONSerializable(restSubscription),\n\t\t\t\t\t\t\t...(locale ? { locale: locale.toString() } : {})\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(KeetaNet.lib.Utils.Conversion.toJSONSerializable({\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\tsubscriptions: subscriptionsJSON\n\t\t\t\t\t})),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tconst deleteSubscriptionHandler = this.notification.deleteSubscription;\n\t\tif (deleteSubscriptionHandler) {\n\t\t\troutes['POST /api/delete-subscription'] = async (_params, body, _ignore_headers, url) => {\n\t\t\t\tconst raw = assertKeetaNotificationAnchorDeleteSubscriptionRequestJSON(body);\n\t\t\t\tconst account = await verifyBodyAuth(this.requestAuthContext('POST', url, body), raw, getNotificationDeleteSubscriptionRequestSignable, this.resolvedCertificateChainRequirement);\n\t\t\t\tconst request: Required<KeetaNotificationAnchorDeleteSubscriptionRequest> = { ...raw, account };\n\t\t\t\tconst deleteResponse = await deleteSubscriptionHandler(request);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(deleteResponse),\n\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\treturn(routes);\n\t}\n\n\tprotected async buildServiceMetadata(): Promise<NonNullable<ServiceMetadata['services']['notification']>[string]> {\n\t\tconst retval: NonNullable<ServiceMetadata['services']['notification']>[string] = { operations: {}};\n\n\t\tconst authentication: ServiceMetadataAuthenticationType = {\n\t\t\tmethod: 'keeta-account',\n\t\t\ttype: 'required'\n\t\t}\n\n\t\tif (this.notification.registerTarget) {\n\t\t\tretval.operations.registerTarget = { url: (new URL('/api/target', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.listTargets) {\n\t\t\tretval.operations.listTargets = { url: (new URL('/api/targets', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.deleteTarget) {\n\t\t\tretval.operations.deleteTarget = { url: (new URL('/api/delete-target', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.createSubscription) {\n\t\t\tretval.operations.createSubscription = { url: (new URL('/api/subscription', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.listSubscriptions) {\n\t\t\tretval.operations.listSubscriptions = { url: (new URL('/api/subscriptions', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.deleteSubscription) {\n\t\t\tretval.operations.deleteSubscription = { url: (new URL('/api/delete-subscription', this.url)).toString(), options: { authentication }};\n\t\t}\n\n\t\tif (this.notification.supportedChannels) {\n\t\t\tretval.supportedChannels = this.notification.supportedChannels;\n\t\t}\n\n\t\tif (this.notification.supportedSubscriptions) {\n\t\t\tretval.supportedSubscriptions = this.notification.supportedSubscriptions;\n\t\t}\n\n\t\tconst acceptedIssuerDNs = this.acceptedIssuerDNs();\n\t\tif (acceptedIssuerDNs !== undefined) {\n\t\t\tretval.acceptedIssuerDNs = acceptedIssuerDNs;\n\t\t}\n\n\t\treturn(retval);\n\t}\n}\n"]}
|
|
@@ -247,15 +247,18 @@ export declare class KeetaStorageAnchorProvider extends KeetaStorageAnchorBase {
|
|
|
247
247
|
*
|
|
248
248
|
* @param options.path - The storage path (e.g., "/user/<publicKey>/myfile.txt")
|
|
249
249
|
* @param options.account - Optional account for signing and decryption (falls back to client account)
|
|
250
|
+
* @param options.signers - Accounts whose signature on the object is accepted (defaults to the reading account)
|
|
250
251
|
*
|
|
251
252
|
* @returns The decrypted data and mime-type, or null if not found
|
|
252
253
|
*
|
|
253
254
|
* @throws PrivateKeyRequired if no account with private key is available
|
|
254
255
|
* @throws InvalidResponse if the stored data cannot be decrypted
|
|
256
|
+
* @throws SignatureInvalid if no accepted account signed the object
|
|
255
257
|
*/
|
|
256
258
|
get(options: {
|
|
257
259
|
path: string;
|
|
258
260
|
account?: KeetaNetAccount;
|
|
261
|
+
signers?: KeetaNetAccount[];
|
|
259
262
|
}): Promise<{
|
|
260
263
|
data: Buffer;
|
|
261
264
|
mimeType: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/services/storage/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,iCAAiC,EAA2B,MAAM,uBAAuB,CAAC;AAEzH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EACX,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,uBAAuB,EACvB,qCAAqC,EAIrC,MAAM,aAAa,CAAC;AAqBrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/services/storage/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,iCAAiC,EAA2B,MAAM,uBAAuB,CAAC;AAEzH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EACX,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,uBAAuB,EACvB,qCAAqC,EAIrC,MAAM,aAAa,CAAC;AAqBrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAQrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,E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cAAc,CAAC,MAAM,EAAE,iBAAiB,GAAG,kBAAkB;IAS7D;;;OAGG;IACH,gBAAgB,CAAC,MAAM,EAAE,mBAAmB,GAAG,oBAAoB;CAKnE;AAED,cAAM,wBAAyB,SAAQ,sBAAsB;;IAC5D,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;gBAIR,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAE,8BAAmC;IAqCnF;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,0BAA0B,EAAE,GAAG,IAAI,CAAC;IAIlE;;OAEG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAsBrF;;;OAGG;IACG,iBAAiB,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAI5F;;;OAGG;IACG,cAAc,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAInF;;;OAGG;IACG,gBAAgB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;CAkBzF;AAED,eAAe,wBAAwB,CAAC"}
|
|
@@ -4,10 +4,11 @@ import { isKeetaStorageAnchorDeleteResponse, isKeetaStorageAnchorPutResponse, is
|
|
|
4
4
|
import { getKeetaStorageAnchorDeleteRequestSigningData, getKeetaStorageAnchorPutRequestSigningData, getKeetaStorageAnchorGetRequestSigningData, getKeetaStorageAnchorSearchRequestSigningData, getKeetaStorageAnchorQuotaRequestSigningData, getKeetaStorageAnchorUpdateMetadataRequestSigningData, parseContainerPayload, Errors, CONTENT_TYPE_JSON, CONTENT_TYPE_OCTET_STREAM, DEFAULT_SIGNED_URL_TTL_SECONDS } from './common.js';
|
|
5
5
|
import * as KeetaNet from '@keetanetwork/keetanet-client';
|
|
6
6
|
import { getDefaultResolver } from '../../config.js';
|
|
7
|
-
import { EncryptedContainer } from '../../lib/encrypted-container.js';
|
|
7
|
+
import { EncryptedContainer, EncryptedContainerError } from '../../lib/encrypted-container.js';
|
|
8
8
|
import { createAssertEquals } from 'typia';
|
|
9
9
|
import { addSignatureToURL } from '../../lib/http-server/common.js';
|
|
10
10
|
import { SignData } from '../../lib/utils/signing.js';
|
|
11
|
+
import { signRequest } from '../../lib/http-server/request-signing.js';
|
|
11
12
|
import { KeetaAnchorError } from '../../lib/error.js';
|
|
12
13
|
import { arrayBufferLikeToBuffer } from '../../lib/utils/buffer.js';
|
|
13
14
|
import { StorageContactsClient } from './clients/contacts.js';
|
|
@@ -258,6 +259,34 @@ async function getEndpoints(resolver, logger) {
|
|
|
258
259
|
const retval = Object.fromEntries(await Promise.all(serviceInfoPromises));
|
|
259
260
|
return (retval);
|
|
260
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Decrypt a stored object for `reader`, and return its plaintext only when
|
|
264
|
+
* one of `signers` signed it. The storage anchor serves the bytes, so a
|
|
265
|
+
* signature is the only proof of who wrote them.
|
|
266
|
+
*/
|
|
267
|
+
async function openSignedContainer(encoded, reader, signers) {
|
|
268
|
+
const container = EncryptedContainer.fromEncryptedBuffer(encoded, [reader]);
|
|
269
|
+
const plaintext = await container.getPlaintext();
|
|
270
|
+
let verified;
|
|
271
|
+
try {
|
|
272
|
+
const signer = container.getSigningAccount();
|
|
273
|
+
const accepted = signer !== undefined && signers.some(function (account) {
|
|
274
|
+
return (account.comparePublicKey(signer));
|
|
275
|
+
});
|
|
276
|
+
verified = accepted && await container.verifySignature();
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
/* A signature the container cannot check is no proof of who wrote it */
|
|
280
|
+
if (EncryptedContainerError.isInstance(error)) {
|
|
281
|
+
throw (new Errors.SignatureInvalid(`Stored object signature cannot be verified: ${error.code}`));
|
|
282
|
+
}
|
|
283
|
+
throw (error);
|
|
284
|
+
}
|
|
285
|
+
if (!verified) {
|
|
286
|
+
throw (new Errors.SignatureInvalid('Stored object is not signed by an accepted account'));
|
|
287
|
+
}
|
|
288
|
+
return (plaintext);
|
|
289
|
+
}
|
|
261
290
|
class KeetaStorageAnchorBase {
|
|
262
291
|
logger;
|
|
263
292
|
client;
|
|
@@ -670,7 +699,8 @@ export class KeetaStorageAnchorProvider extends KeetaStorageAnchorBase {
|
|
|
670
699
|
throw (new Errors.InvariantViolation('getSignedData required for signed requests'));
|
|
671
700
|
}
|
|
672
701
|
const signable = input.getSignedData(serializedBody);
|
|
673
|
-
|
|
702
|
+
const signedBody = input.method === 'POST' || input.method === 'PUT' ? serializedBody : undefined;
|
|
703
|
+
signed = await signRequest(input.account.assertAccount(), { method: input.method, url, body: signedBody }, signable);
|
|
674
704
|
}
|
|
675
705
|
const headers = { 'Accept': CONTENT_TYPE_JSON };
|
|
676
706
|
let usingUrl = url;
|
|
@@ -733,14 +763,14 @@ export class KeetaStorageAnchorProvider extends KeetaStorageAnchorBase {
|
|
|
733
763
|
}
|
|
734
764
|
const tags = input.tags ?? [];
|
|
735
765
|
this.#validateTags(tags);
|
|
766
|
+
url.searchParams.set('visibility', visibility);
|
|
767
|
+
if (tags.length > 0) {
|
|
768
|
+
url.searchParams.set('tags', tags.join(','));
|
|
769
|
+
}
|
|
736
770
|
const signable = getKeetaStorageAnchorPutRequestSigningData({ path: input.path, visibility, tags });
|
|
737
|
-
const signed = await
|
|
771
|
+
const signed = await signRequest(input.account.assertAccount(), { method: 'PUT', url, body: input.data }, signable);
|
|
738
772
|
// Add auth to query params using helper
|
|
739
773
|
const signedUrl = addSignatureToURL(url, { signedField: signed, account: input.account.assertAccount() });
|
|
740
|
-
signedUrl.searchParams.set('visibility', visibility);
|
|
741
|
-
if (tags.length > 0) {
|
|
742
|
-
signedUrl.searchParams.set('tags', tags.join(','));
|
|
743
|
-
}
|
|
744
774
|
let response;
|
|
745
775
|
try {
|
|
746
776
|
response = await fetch(signedUrl, {
|
|
@@ -784,7 +814,7 @@ export class KeetaStorageAnchorProvider extends KeetaStorageAnchorBase {
|
|
|
784
814
|
}
|
|
785
815
|
// Sign the request
|
|
786
816
|
const signable = getKeetaStorageAnchorGetRequestSigningData({ path: input.path, account: input.account.publicKeyString.get() });
|
|
787
|
-
const signed = await
|
|
817
|
+
const signed = await signRequest(input.account.assertAccount(), { method: 'GET', url }, signable);
|
|
788
818
|
// Add auth to query params
|
|
789
819
|
const signedUrl = addSignatureToURL(url, { signedField: signed, account: input.account.assertAccount() });
|
|
790
820
|
let response;
|
|
@@ -833,11 +863,13 @@ export class KeetaStorageAnchorProvider extends KeetaStorageAnchorBase {
|
|
|
833
863
|
*
|
|
834
864
|
* @param options.path - The storage path (e.g., "/user/<publicKey>/myfile.txt")
|
|
835
865
|
* @param options.account - Optional account for signing and decryption (falls back to client account)
|
|
866
|
+
* @param options.signers - Accounts whose signature on the object is accepted (defaults to the reading account)
|
|
836
867
|
*
|
|
837
868
|
* @returns The decrypted data and mime-type, or null if not found
|
|
838
869
|
*
|
|
839
870
|
* @throws PrivateKeyRequired if no account with private key is available
|
|
840
871
|
* @throws InvalidResponse if the stored data cannot be decrypted
|
|
872
|
+
* @throws SignatureInvalid if no accepted account signed the object
|
|
841
873
|
*/
|
|
842
874
|
async get(options) {
|
|
843
875
|
const { path } = options;
|
|
@@ -848,9 +880,7 @@ export class KeetaStorageAnchorProvider extends KeetaStorageAnchorBase {
|
|
|
848
880
|
path,
|
|
849
881
|
account: signerAccount
|
|
850
882
|
});
|
|
851
|
-
|
|
852
|
-
const container = EncryptedContainer.fromEncryptedBuffer(encodedData, [signerAccount]);
|
|
853
|
-
const plaintext = await container.getPlaintext();
|
|
883
|
+
const plaintext = await openSignedContainer(encodedData, signerAccount, options.signers ?? [signerAccount]);
|
|
854
884
|
const { mimeType, content: data } = parseContainerPayload(plaintext);
|
|
855
885
|
this.logger?.debug(`Get request successful for path: ${path}`);
|
|
856
886
|
return ({
|