@t-0/provider-sdk 1.1.29 → 1.1.30

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.
Files changed (116) hide show
  1. package/README.md +22 -5
  2. package/lib/cjs/client/client.d.ts +4 -14
  3. package/lib/cjs/client/client.js +2 -38
  4. package/lib/cjs/client/signer.d.ts +1 -3
  5. package/lib/cjs/client/signer.js +7 -34
  6. package/lib/cjs/common/client/client.d.ts +14 -0
  7. package/lib/cjs/common/client/client.js +42 -0
  8. package/lib/cjs/common/client/signer.d.ts +3 -0
  9. package/lib/cjs/common/client/signer.js +36 -0
  10. package/lib/cjs/common/crypto/hash.d.ts +2 -0
  11. package/lib/cjs/common/crypto/hash.js +17 -0
  12. package/lib/cjs/common/crypto/index.d.ts +5 -0
  13. package/lib/cjs/common/crypto/index.js +14 -0
  14. package/lib/cjs/common/crypto/keys.d.ts +2 -0
  15. package/lib/cjs/common/crypto/keys.js +23 -0
  16. package/lib/cjs/common/crypto/request.d.ts +20 -0
  17. package/lib/cjs/common/crypto/request.js +51 -0
  18. package/lib/cjs/common/crypto/verify.d.ts +1 -0
  19. package/lib/cjs/common/crypto/verify.js +19 -0
  20. package/lib/cjs/common/health.d.ts +21 -0
  21. package/lib/cjs/common/health.js +45 -0
  22. package/lib/cjs/common/health_pb.d.ts +157 -0
  23. package/lib/cjs/common/health_pb.js +90 -0
  24. package/lib/cjs/common/node.d.ts +3 -0
  25. package/lib/cjs/common/node.js +15 -0
  26. package/lib/cjs/common/service.d.ts +37 -0
  27. package/lib/cjs/common/service.js +85 -0
  28. package/lib/cjs/common/validate.d.ts +25 -0
  29. package/lib/cjs/common/validate.js +42 -0
  30. package/lib/cjs/common/validation.d.ts +26 -0
  31. package/lib/cjs/common/validation.js +57 -0
  32. package/lib/cjs/crypto/hash.d.ts +1 -2
  33. package/lib/cjs/crypto/hash.js +15 -15
  34. package/lib/cjs/crypto/index.d.ts +1 -5
  35. package/lib/cjs/crypto/index.js +15 -12
  36. package/lib/cjs/crypto/keys.d.ts +1 -2
  37. package/lib/cjs/crypto/keys.js +15 -17
  38. package/lib/cjs/crypto/request.d.ts +1 -20
  39. package/lib/cjs/crypto/request.js +15 -47
  40. package/lib/cjs/crypto/verify.d.ts +1 -1
  41. package/lib/cjs/crypto/verify.js +15 -17
  42. package/lib/cjs/index.d.ts +1 -0
  43. package/lib/cjs/index.js +1 -0
  44. package/lib/cjs/service/health.d.ts +4 -21
  45. package/lib/cjs/service/health.js +5 -41
  46. package/lib/cjs/service/health_pb.d.ts +1 -157
  47. package/lib/cjs/service/health_pb.js +15 -88
  48. package/lib/cjs/service/node.d.ts +1 -3
  49. package/lib/cjs/service/node.js +15 -13
  50. package/lib/cjs/service/service.d.ts +6 -20
  51. package/lib/cjs/service/service.js +5 -84
  52. package/lib/cjs/service/validate.d.ts +1 -25
  53. package/lib/cjs/service/validate.js +15 -40
  54. package/lib/cjs/service/validate_response.d.ts +9 -18
  55. package/lib/cjs/service/validate_response.js +19 -57
  56. package/lib/cjs/version.d.ts +1 -1
  57. package/lib/cjs/version.js +1 -1
  58. package/lib/esm/client/client.d.ts +3 -13
  59. package/lib/esm/client/client.js +2 -35
  60. package/lib/esm/client/signer.d.ts +1 -3
  61. package/lib/esm/client/signer.js +1 -32
  62. package/lib/esm/common/client/client.d.ts +14 -0
  63. package/lib/esm/common/client/client.js +36 -0
  64. package/lib/esm/common/client/signer.d.ts +3 -0
  65. package/lib/esm/common/client/signer.js +32 -0
  66. package/lib/esm/common/crypto/hash.d.ts +2 -0
  67. package/lib/esm/common/crypto/hash.js +13 -0
  68. package/lib/esm/common/crypto/index.d.ts +5 -0
  69. package/lib/esm/common/crypto/index.js +4 -0
  70. package/lib/esm/common/crypto/keys.d.ts +2 -0
  71. package/lib/esm/common/crypto/keys.js +19 -0
  72. package/lib/esm/common/crypto/request.d.ts +20 -0
  73. package/lib/esm/common/crypto/request.js +47 -0
  74. package/lib/esm/common/crypto/verify.d.ts +1 -0
  75. package/lib/esm/common/crypto/verify.js +16 -0
  76. package/lib/esm/common/health.d.ts +21 -0
  77. package/lib/esm/common/health.js +41 -0
  78. package/lib/esm/common/health_pb.d.ts +157 -0
  79. package/lib/esm/common/health_pb.js +87 -0
  80. package/lib/esm/common/node.d.ts +3 -0
  81. package/lib/esm/common/node.js +11 -0
  82. package/lib/esm/common/service.d.ts +37 -0
  83. package/lib/esm/common/service.js +78 -0
  84. package/lib/esm/common/validate.d.ts +25 -0
  85. package/lib/esm/common/validate.js +38 -0
  86. package/lib/esm/common/validation.d.ts +26 -0
  87. package/lib/esm/common/validation.js +54 -0
  88. package/lib/esm/crypto/hash.d.ts +1 -2
  89. package/lib/esm/crypto/hash.js +1 -13
  90. package/lib/esm/crypto/index.d.ts +1 -5
  91. package/lib/esm/crypto/index.js +1 -4
  92. package/lib/esm/crypto/keys.d.ts +1 -2
  93. package/lib/esm/crypto/keys.js +1 -15
  94. package/lib/esm/crypto/request.d.ts +1 -20
  95. package/lib/esm/crypto/request.js +1 -45
  96. package/lib/esm/crypto/verify.d.ts +1 -1
  97. package/lib/esm/crypto/verify.js +1 -16
  98. package/lib/esm/index.d.ts +1 -0
  99. package/lib/esm/index.js +1 -0
  100. package/lib/esm/service/health.d.ts +4 -21
  101. package/lib/esm/service/health.js +3 -41
  102. package/lib/esm/service/health_pb.d.ts +1 -157
  103. package/lib/esm/service/health_pb.js +1 -87
  104. package/lib/esm/service/node.d.ts +1 -3
  105. package/lib/esm/service/node.js +1 -11
  106. package/lib/esm/service/service.d.ts +6 -20
  107. package/lib/esm/service/service.js +4 -81
  108. package/lib/esm/service/validate.d.ts +1 -25
  109. package/lib/esm/service/validate.js +1 -38
  110. package/lib/esm/service/validate_response.d.ts +9 -18
  111. package/lib/esm/service/validate_response.js +15 -54
  112. package/lib/esm/version.d.ts +1 -1
  113. package/lib/esm/version.js +1 -1
  114. package/lib/tsconfig.cjs.tsbuildinfo +1 -1
  115. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  116. package/package.json +1 -1
@@ -0,0 +1,157 @@
1
+ import type { GenEnum, GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv2";
2
+ import type { Message } from "@bufbuild/protobuf";
3
+ /**
4
+ * Describes the file grpc/health/v1/health.proto.
5
+ */
6
+ export declare const file_grpc_health_v1_health: GenFile;
7
+ /**
8
+ * @generated from message grpc.health.v1.HealthCheckRequest
9
+ */
10
+ export type HealthCheckRequest = Message<"grpc.health.v1.HealthCheckRequest"> & {
11
+ /**
12
+ * @generated from field: string service = 1;
13
+ */
14
+ service: string;
15
+ };
16
+ /**
17
+ * Describes the message grpc.health.v1.HealthCheckRequest.
18
+ * Use `create(HealthCheckRequestSchema)` to create a new message.
19
+ */
20
+ export declare const HealthCheckRequestSchema: GenMessage<HealthCheckRequest>;
21
+ /**
22
+ * @generated from message grpc.health.v1.HealthCheckResponse
23
+ */
24
+ export type HealthCheckResponse = Message<"grpc.health.v1.HealthCheckResponse"> & {
25
+ /**
26
+ * @generated from field: grpc.health.v1.HealthCheckResponse.ServingStatus status = 1;
27
+ */
28
+ status: HealthCheckResponse_ServingStatus;
29
+ };
30
+ /**
31
+ * Describes the message grpc.health.v1.HealthCheckResponse.
32
+ * Use `create(HealthCheckResponseSchema)` to create a new message.
33
+ */
34
+ export declare const HealthCheckResponseSchema: GenMessage<HealthCheckResponse>;
35
+ /**
36
+ * @generated from enum grpc.health.v1.HealthCheckResponse.ServingStatus
37
+ */
38
+ export declare enum HealthCheckResponse_ServingStatus {
39
+ /**
40
+ * @generated from enum value: UNKNOWN = 0;
41
+ */
42
+ UNKNOWN = 0,
43
+ /**
44
+ * @generated from enum value: SERVING = 1;
45
+ */
46
+ SERVING = 1,
47
+ /**
48
+ * @generated from enum value: NOT_SERVING = 2;
49
+ */
50
+ NOT_SERVING = 2,
51
+ /**
52
+ * Used only by the Watch method.
53
+ *
54
+ * @generated from enum value: SERVICE_UNKNOWN = 3;
55
+ */
56
+ SERVICE_UNKNOWN = 3
57
+ }
58
+ /**
59
+ * Describes the enum grpc.health.v1.HealthCheckResponse.ServingStatus.
60
+ */
61
+ export declare const HealthCheckResponse_ServingStatusSchema: GenEnum<HealthCheckResponse_ServingStatus>;
62
+ /**
63
+ * @generated from message grpc.health.v1.HealthListRequest
64
+ */
65
+ export type HealthListRequest = Message<"grpc.health.v1.HealthListRequest"> & {};
66
+ /**
67
+ * Describes the message grpc.health.v1.HealthListRequest.
68
+ * Use `create(HealthListRequestSchema)` to create a new message.
69
+ */
70
+ export declare const HealthListRequestSchema: GenMessage<HealthListRequest>;
71
+ /**
72
+ * @generated from message grpc.health.v1.HealthListResponse
73
+ */
74
+ export type HealthListResponse = Message<"grpc.health.v1.HealthListResponse"> & {
75
+ /**
76
+ * statuses contains all the services and their respective status.
77
+ *
78
+ * @generated from field: map<string, grpc.health.v1.HealthCheckResponse> statuses = 1;
79
+ */
80
+ statuses: {
81
+ [key: string]: HealthCheckResponse;
82
+ };
83
+ };
84
+ /**
85
+ * Describes the message grpc.health.v1.HealthListResponse.
86
+ * Use `create(HealthListResponseSchema)` to create a new message.
87
+ */
88
+ export declare const HealthListResponseSchema: GenMessage<HealthListResponse>;
89
+ /**
90
+ * Health is gRPC's mechanism for checking whether a server is able to handle
91
+ * RPCs. Its semantics are documented in
92
+ * https://github.com/grpc/grpc/blob/master/doc/health-checking.md.
93
+ *
94
+ * @generated from service grpc.health.v1.Health
95
+ */
96
+ export declare const Health: GenService<{
97
+ /**
98
+ * Check gets the health of the specified service. If the requested service
99
+ * is unknown, the call will fail with status NOT_FOUND. If the caller does
100
+ * not specify a service name, the server should respond with its overall
101
+ * health status.
102
+ *
103
+ * Clients should set a deadline when calling Check, and can declare the
104
+ * server unhealthy if they do not receive a timely response.
105
+ *
106
+ * @generated from rpc grpc.health.v1.Health.Check
107
+ */
108
+ check: {
109
+ methodKind: "unary";
110
+ input: typeof HealthCheckRequestSchema;
111
+ output: typeof HealthCheckResponseSchema;
112
+ };
113
+ /**
114
+ * List provides a non-atomic snapshot of the health of all the available
115
+ * services.
116
+ *
117
+ * The server may respond with a RESOURCE_EXHAUSTED error if too many services
118
+ * exist.
119
+ *
120
+ * Clients should set a deadline when calling List, and can declare the server
121
+ * unhealthy if they do not receive a timely response.
122
+ *
123
+ * Clients should keep in mind that the list of health services exposed by an
124
+ * application can change over the lifetime of the process.
125
+ *
126
+ * @generated from rpc grpc.health.v1.Health.List
127
+ */
128
+ list: {
129
+ methodKind: "unary";
130
+ input: typeof HealthListRequestSchema;
131
+ output: typeof HealthListResponseSchema;
132
+ };
133
+ /**
134
+ * Performs a watch for the serving status of the requested service.
135
+ * The server will immediately send back a message indicating the current
136
+ * serving status. It will then subsequently send a new message whenever
137
+ * the service's serving status changes.
138
+ *
139
+ * If the requested service is unknown when the call is received, the
140
+ * server will send a message setting the serving status to
141
+ * SERVICE_UNKNOWN but will *not* terminate the call. If at some
142
+ * future point, the serving status of the service becomes known, the
143
+ * server will send a new message with the service's serving status.
144
+ *
145
+ * If the call terminates with status UNIMPLEMENTED, then clients
146
+ * should assume this method is not supported and should not retry the
147
+ * call. If the call terminates with any other status (including OK),
148
+ * clients should retry the call with appropriate exponential backoff.
149
+ *
150
+ * @generated from rpc grpc.health.v1.Health.Watch
151
+ */
152
+ watch: {
153
+ methodKind: "server_streaming";
154
+ input: typeof HealthCheckRequestSchema;
155
+ output: typeof HealthCheckResponseSchema;
156
+ };
157
+ }>;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ // Vendored generated stubs for grpc.health.v1 -- do not edit by hand.
3
+ //
4
+ // Source: buf.build/grpc/grpc, grpc/health/v1/health.proto
5
+ // Plugin: buf.build/bufbuild/es:v2.12.0 (kept in step with the root
6
+ // buf.gen.yaml pin -- plugin and @bufbuild/protobuf runtime must
7
+ // agree on major).
8
+ //
9
+ // Regenerate with the following, which keeps this header and replaces
10
+ // everything from the gRPC copyright line down. Do not just `mv` the generated
11
+ // file over this one -- that would delete these instructions along with it.
12
+ //
13
+ // cd node/sdk
14
+ // buf generate buf.build/grpc/grpc --path grpc/health/v1/health.proto \
15
+ // --template '{"version":"v2","plugins":[{"remote":"buf.build/bufbuild/es:v2.12.0","out":"gen-health","opt":["target=ts","import_extension=js"]}]}'
16
+ // sed '/^\/\/ Copyright 2015 The gRPC Authors/,$d' src/common/health_pb.ts > gen-health/header
17
+ // cat gen-health/header gen-health/grpc/health/v1/health_pb.ts > src/common/health_pb.ts
18
+ // rm -rf gen-health
19
+ //
20
+ // Vendored rather than depended on: the equivalent package
21
+ // `@buf/grpc_grpc.bufbuild_es` is published only on the Buf Schema Registry, and
22
+ // reaching it needs registry config that a published npm package cannot hand its
23
+ // consumers -- so depending on it 404'd every downstream install. Rationale in
24
+ // docs/HEALTH_SERVICE.md.
25
+ //
26
+ // Lives under src/common/ (not src/common/gen/) so the buf-regenerated gen/
27
+ // tree stays independent.
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Health = exports.HealthListResponseSchema = exports.HealthListRequestSchema = exports.HealthCheckResponse_ServingStatusSchema = exports.HealthCheckResponse_ServingStatus = exports.HealthCheckResponseSchema = exports.HealthCheckRequestSchema = exports.file_grpc_health_v1_health = void 0;
30
+ const codegenv2_1 = require("@bufbuild/protobuf/codegenv2");
31
+ /**
32
+ * Describes the file grpc/health/v1/health.proto.
33
+ */
34
+ exports.file_grpc_health_v1_health = (0, codegenv2_1.fileDesc)("ChtncnBjL2hlYWx0aC92MS9oZWFsdGgucHJvdG8SDmdycGMuaGVhbHRoLnYxIiUKEkhlYWx0aENoZWNrUmVxdWVzdBIPCgdzZXJ2aWNlGAEgASgJIqkBChNIZWFsdGhDaGVja1Jlc3BvbnNlEkEKBnN0YXR1cxgBIAEoDjIxLmdycGMuaGVhbHRoLnYxLkhlYWx0aENoZWNrUmVzcG9uc2UuU2VydmluZ1N0YXR1cyJPCg1TZXJ2aW5nU3RhdHVzEgsKB1VOS05PV04QABILCgdTRVJWSU5HEAESDwoLTk9UX1NFUlZJTkcQAhITCg9TRVJWSUNFX1VOS05PV04QAyITChFIZWFsdGhMaXN0UmVxdWVzdCKuAQoSSGVhbHRoTGlzdFJlc3BvbnNlEkIKCHN0YXR1c2VzGAEgAygLMjAuZ3JwYy5oZWFsdGgudjEuSGVhbHRoTGlzdFJlc3BvbnNlLlN0YXR1c2VzRW50cnkaVAoNU3RhdHVzZXNFbnRyeRILCgNrZXkYASABKAkSMgoFdmFsdWUYAiABKAsyIy5ncnBjLmhlYWx0aC52MS5IZWFsdGhDaGVja1Jlc3BvbnNlOgI4ATL9AQoGSGVhbHRoElAKBUNoZWNrEiIuZ3JwYy5oZWFsdGgudjEuSGVhbHRoQ2hlY2tSZXF1ZXN0GiMuZ3JwYy5oZWFsdGgudjEuSGVhbHRoQ2hlY2tSZXNwb25zZRJNCgRMaXN0EiEuZ3JwYy5oZWFsdGgudjEuSGVhbHRoTGlzdFJlcXVlc3QaIi5ncnBjLmhlYWx0aC52MS5IZWFsdGhMaXN0UmVzcG9uc2USUgoFV2F0Y2gSIi5ncnBjLmhlYWx0aC52MS5IZWFsdGhDaGVja1JlcXVlc3QaIy5ncnBjLmhlYWx0aC52MS5IZWFsdGhDaGVja1Jlc3BvbnNlMAFCcAoRaW8uZ3JwYy5oZWFsdGgudjFCC0hlYWx0aFByb3RvUAFaLGdvb2dsZS5nb2xhbmcub3JnL2dycGMvaGVhbHRoL2dycGNfaGVhbHRoX3YxogIMR3JwY0hlYWx0aFYxqgIOR3JwYy5IZWFsdGguVjFiBnByb3RvMw");
35
+ /**
36
+ * Describes the message grpc.health.v1.HealthCheckRequest.
37
+ * Use `create(HealthCheckRequestSchema)` to create a new message.
38
+ */
39
+ exports.HealthCheckRequestSchema = (0, codegenv2_1.messageDesc)(exports.file_grpc_health_v1_health, 0);
40
+ /**
41
+ * Describes the message grpc.health.v1.HealthCheckResponse.
42
+ * Use `create(HealthCheckResponseSchema)` to create a new message.
43
+ */
44
+ exports.HealthCheckResponseSchema = (0, codegenv2_1.messageDesc)(exports.file_grpc_health_v1_health, 1);
45
+ /**
46
+ * @generated from enum grpc.health.v1.HealthCheckResponse.ServingStatus
47
+ */
48
+ var HealthCheckResponse_ServingStatus;
49
+ (function (HealthCheckResponse_ServingStatus) {
50
+ /**
51
+ * @generated from enum value: UNKNOWN = 0;
52
+ */
53
+ HealthCheckResponse_ServingStatus[HealthCheckResponse_ServingStatus["UNKNOWN"] = 0] = "UNKNOWN";
54
+ /**
55
+ * @generated from enum value: SERVING = 1;
56
+ */
57
+ HealthCheckResponse_ServingStatus[HealthCheckResponse_ServingStatus["SERVING"] = 1] = "SERVING";
58
+ /**
59
+ * @generated from enum value: NOT_SERVING = 2;
60
+ */
61
+ HealthCheckResponse_ServingStatus[HealthCheckResponse_ServingStatus["NOT_SERVING"] = 2] = "NOT_SERVING";
62
+ /**
63
+ * Used only by the Watch method.
64
+ *
65
+ * @generated from enum value: SERVICE_UNKNOWN = 3;
66
+ */
67
+ HealthCheckResponse_ServingStatus[HealthCheckResponse_ServingStatus["SERVICE_UNKNOWN"] = 3] = "SERVICE_UNKNOWN";
68
+ })(HealthCheckResponse_ServingStatus || (exports.HealthCheckResponse_ServingStatus = HealthCheckResponse_ServingStatus = {}));
69
+ /**
70
+ * Describes the enum grpc.health.v1.HealthCheckResponse.ServingStatus.
71
+ */
72
+ exports.HealthCheckResponse_ServingStatusSchema = (0, codegenv2_1.enumDesc)(exports.file_grpc_health_v1_health, 1, 0);
73
+ /**
74
+ * Describes the message grpc.health.v1.HealthListRequest.
75
+ * Use `create(HealthListRequestSchema)` to create a new message.
76
+ */
77
+ exports.HealthListRequestSchema = (0, codegenv2_1.messageDesc)(exports.file_grpc_health_v1_health, 2);
78
+ /**
79
+ * Describes the message grpc.health.v1.HealthListResponse.
80
+ * Use `create(HealthListResponseSchema)` to create a new message.
81
+ */
82
+ exports.HealthListResponseSchema = (0, codegenv2_1.messageDesc)(exports.file_grpc_health_v1_health, 3);
83
+ /**
84
+ * Health is gRPC's mechanism for checking whether a server is able to handle
85
+ * RPCs. Its semantics are documented in
86
+ * https://github.com/grpc/grpc/blob/master/doc/health-checking.md.
87
+ *
88
+ * @generated from service grpc.health.v1.Health
89
+ */
90
+ exports.Health = (0, codegenv2_1.serviceDesc)(exports.file_grpc_health_v1_health, 0);
@@ -0,0 +1,3 @@
1
+ import type * as http from "node:http";
2
+ export type NodeHandlerFn = (request: http.IncomingMessage, response: http.ServerResponse) => void;
3
+ export declare const signatureValidation: (next: NodeHandlerFn) => NodeHandlerFn;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signatureValidation = void 0;
4
+ const sha3_js_1 = require("@noble/hashes/sha3.js");
5
+ const signatureValidation = (next) => (req, resp) => {
6
+ const hasher = sha3_js_1.keccak_256.create();
7
+ req.hasher = hasher;
8
+ req.on("data", (chunk) => {
9
+ if (chunk instanceof Buffer) {
10
+ hasher.update(chunk);
11
+ }
12
+ });
13
+ next(req, resp);
14
+ };
15
+ exports.signatureValidation = signatureValidation;
@@ -0,0 +1,37 @@
1
+ import { ConnectRouter } from "@connectrpc/connect";
2
+ import type { Interceptor } from "@connectrpc/connect";
3
+ import type { DescService, Registry } from "@bufbuild/protobuf";
4
+ import type { ServiceImpl } from "@connectrpc/connect";
5
+ import { type Logger } from "./validation.js";
6
+ export interface CreateServiceOptions {
7
+ /**
8
+ * Logger used by the SDK for error-level events (currently:
9
+ * response-validation failures from the interceptor safety net). The same
10
+ * logger will be used for any future server-wide SDK log sites.
11
+ *
12
+ * If omitted, the SDK logs to `console.error` with a JSON-encoded payload.
13
+ */
14
+ logger?: Logger;
15
+ /**
16
+ * Protobuf registry for resolving custom protovalidate predefined-rule
17
+ * extensions. Pass a registry built with `createRegistry(fileDescriptor)`
18
+ * when your protos define custom predefined rules.
19
+ */
20
+ registry?: Registry;
21
+ /**
22
+ * SDK version stamped on health-check responses via the `T0-Sdk-Version`
23
+ * header. Omit to suppress the header.
24
+ */
25
+ version?: string;
26
+ }
27
+ export declare const REQUEST_VALIDITY_MILLIS = 60000;
28
+ interface Router {
29
+ service: <T extends DescService, I extends ServiceImpl<T>>(service: T, implementation: I) => void;
30
+ }
31
+ export declare const createService: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => {
32
+ routes: (router: ConnectRouter) => void;
33
+ interceptors: Interceptor[];
34
+ grpcWeb: boolean;
35
+ contextValues: (req: any) => import("@connectrpc/connect").ContextValues;
36
+ };
37
+ export {};
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createService = exports.REQUEST_VALIDITY_MILLIS = void 0;
7
+ const connect_1 = require("@connectrpc/connect");
8
+ const headers_js_1 = __importDefault(require("./headers.js"));
9
+ const verify_js_1 = require("./crypto/verify.js");
10
+ const validation_js_1 = require("./validation.js");
11
+ const health_pb_js_1 = require("./health_pb.js");
12
+ const health_js_1 = require("./health.js");
13
+ exports.REQUEST_VALIDITY_MILLIS = 60000;
14
+ const createSignatureVerification = (networkPublicKey) => (next) => async (req) => {
15
+ const ts = decodeNum(getHeader(req, headers_js_1.default.SignatureTimestamp));
16
+ if (Date.now() - ts > 60000) {
17
+ throw new connect_1.ConnectError(`${headers_js_1.default.SignatureTimestamp} must be within ${exports.REQUEST_VALIDITY_MILLIS} milliseconds from now`, connect_1.Code.InvalidArgument);
18
+ }
19
+ const publicKey = decodeHex(getHeader(req, headers_js_1.default.PublicKey));
20
+ if (networkPublicKey.compare(publicKey) !== 0) {
21
+ throw new connect_1.ConnectError(`${headers_js_1.default.PublicKey} value is not network public key`, connect_1.Code.Unauthenticated);
22
+ }
23
+ const signature = decodeHex(getHeader(req, headers_js_1.default.Signature));
24
+ const hasher = req.contextValues.get(kHash);
25
+ const tsBuf = Buffer.alloc(8);
26
+ tsBuf.writeBigUInt64LE(BigInt(ts)); // 64‑bit little‑endian timestamp
27
+ const digest = hasher
28
+ .update(tsBuf)
29
+ .digest();
30
+ if (!(0, verify_js_1.verifySignature)(publicKey, digest, signature)) {
31
+ throw new connect_1.ConnectError(`${headers_js_1.default.Signature} has invalid signature`, connect_1.Code.Unauthenticated);
32
+ }
33
+ return await next(req);
34
+ };
35
+ const createService = (networkPublicKey, registerRoutes, options) => {
36
+ if (typeof networkPublicKey == "string") {
37
+ networkPublicKey = decodeHex(networkPublicKey);
38
+ }
39
+ return {
40
+ routes: (router) => {
41
+ const collected = [];
42
+ const origService = router.service.bind(router);
43
+ const wrappedRouter = {
44
+ service: (desc, impl) => {
45
+ collected.push(desc.typeName);
46
+ origService(desc, impl);
47
+ },
48
+ };
49
+ registerRoutes(wrappedRouter);
50
+ collected.push(health_pb_js_1.Health.typeName);
51
+ origService(health_pb_js_1.Health, (0, health_js_1.createHealthServiceImpl)(collected, options?.version));
52
+ },
53
+ interceptors: [createSignatureVerification(networkPublicKey), (0, validation_js_1.createValidationInterceptor)({ logger: options?.logger, registry: options?.registry })],
54
+ grpcWeb: false,
55
+ contextValues: (req) => {
56
+ return (0, connect_1.createContextValues)().set(kHash, req.hasher);
57
+ }
58
+ };
59
+ };
60
+ exports.createService = createService;
61
+ const kHash = (0, connect_1.createContextKey)(undefined);
62
+ function getHeader(req, header) {
63
+ const raw = req.header.get(header);
64
+ if (!raw) {
65
+ throw new connect_1.ConnectError(`missing required header '${header}'`, connect_1.Code.InvalidArgument);
66
+ }
67
+ return raw;
68
+ }
69
+ function decodeHex(value) {
70
+ value = value.startsWith('0x') ? value.slice(2) : value;
71
+ try {
72
+ return Buffer.from(value, "hex");
73
+ }
74
+ catch (e) {
75
+ throw new connect_1.ConnectError(`invalid header format. '${value}' must be hex encoded`, connect_1.Code.InvalidArgument);
76
+ }
77
+ }
78
+ function decodeNum(value) {
79
+ try {
80
+ return parseInt(value);
81
+ }
82
+ catch (e) {
83
+ throw new connect_1.ConnectError(`invalid header format. '${value}' must be a number`, connect_1.Code.InvalidArgument);
84
+ }
85
+ }
@@ -0,0 +1,25 @@
1
+ import type { DescMessage, MessageShape } from "@bufbuild/protobuf";
2
+ /**
3
+ * Shared protovalidate validator instance for the public {@link validate} helper.
4
+ * Construction is cheap, but reusing one instance avoids repeated compilation
5
+ * of the same rules.
6
+ */
7
+ export declare const validator: import("@bufbuild/protovalidate").Validator;
8
+ /**
9
+ * Validates a response message against its buf.validate proto annotations.
10
+ *
11
+ * On success, returns the message unchanged (typed). On failure, throws a
12
+ * {@link ConnectError} with {@link Code.Internal} and a message matching the
13
+ * shape emitted by the SDK's response-validation interceptor — so propagating
14
+ * the error from a handler produces the same wire response as not calling
15
+ * `validate` at all.
16
+ *
17
+ * Intended use:
18
+ * ```ts
19
+ * return validate(PayOutResponseSchema, { result: { case: "accepted", value: {} } });
20
+ * ```
21
+ *
22
+ * Catch the error to convert it into a domain-level failure (e.g. the `Failed`
23
+ * arm of a `oneof result`) instead of an opaque `Code.Internal`.
24
+ */
25
+ export declare function validate<Desc extends DescMessage>(schema: Desc, msg: MessageShape<Desc>): MessageShape<Desc>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validator = void 0;
4
+ exports.validate = validate;
5
+ const connect_1 = require("@connectrpc/connect");
6
+ const protovalidate_1 = require("@bufbuild/protovalidate");
7
+ /**
8
+ * Shared protovalidate validator instance for the public {@link validate} helper.
9
+ * Construction is cheap, but reusing one instance avoids repeated compilation
10
+ * of the same rules.
11
+ */
12
+ exports.validator = (0, protovalidate_1.createValidator)();
13
+ /**
14
+ * Validates a response message against its buf.validate proto annotations.
15
+ *
16
+ * On success, returns the message unchanged (typed). On failure, throws a
17
+ * {@link ConnectError} with {@link Code.Internal} and a message matching the
18
+ * shape emitted by the SDK's response-validation interceptor — so propagating
19
+ * the error from a handler produces the same wire response as not calling
20
+ * `validate` at all.
21
+ *
22
+ * Intended use:
23
+ * ```ts
24
+ * return validate(PayOutResponseSchema, { result: { case: "accepted", value: {} } });
25
+ * ```
26
+ *
27
+ * Catch the error to convert it into a domain-level failure (e.g. the `Failed`
28
+ * arm of a `oneof result`) instead of an opaque `Code.Internal`.
29
+ */
30
+ function validate(schema, msg) {
31
+ const result = exports.validator.validate(schema, msg);
32
+ if (result.kind === "invalid") {
33
+ const details = result.violations
34
+ .map((v) => `${v.field?.toString() ?? ""}: ${v.message}`)
35
+ .join("; ");
36
+ throw new connect_1.ConnectError(`response validation failed: ${details}`, connect_1.Code.Internal);
37
+ }
38
+ if (result.kind === "error") {
39
+ throw new connect_1.ConnectError(`response validation error: ${result.error.message}`, connect_1.Code.Internal);
40
+ }
41
+ return msg;
42
+ }
@@ -0,0 +1,26 @@
1
+ import type { Interceptor } from "@connectrpc/connect";
2
+ import type { Registry } from "@bufbuild/protobuf";
3
+ /**
4
+ * Minimal logger contract accepted by the SDK. Providers may pass `console`
5
+ * directly, or adapt their preferred logger (e.g. pino) with:
6
+ *
7
+ * { error: (msg, fields) => pinoInstance.error(fields, msg) }
8
+ */
9
+ export interface Logger {
10
+ error(msg: string, fields?: Record<string, unknown>): void;
11
+ }
12
+ export interface ValidationInterceptorOptions {
13
+ logger?: Logger;
14
+ registry?: Registry;
15
+ }
16
+ /**
17
+ * Creates a ConnectRPC interceptor that validates requests and responses
18
+ * against buf.validate proto annotations.
19
+ *
20
+ * Invalid requests return Code.InvalidArgument; invalid responses return
21
+ * Code.Internal.
22
+ *
23
+ * Pass a `registry` when your protos define custom predefined rules
24
+ * (proto2 `extend buf.validate.*Rules`).
25
+ */
26
+ export declare function createValidationInterceptor(loggerOrOptions?: Logger | ValidationInterceptorOptions): Interceptor;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createValidationInterceptor = createValidationInterceptor;
4
+ const connect_1 = require("@connectrpc/connect");
5
+ const protovalidate_1 = require("@bufbuild/protovalidate");
6
+ const validate_1 = require("@connectrpc/validate");
7
+ const defaultLogger = {
8
+ error: (msg, fields) =>
9
+ // eslint-disable-next-line no-console
10
+ console.error(JSON.stringify({ msg, ...(fields ?? {}) })),
11
+ };
12
+ /**
13
+ * Creates a ConnectRPC interceptor that validates requests and responses
14
+ * against buf.validate proto annotations.
15
+ *
16
+ * Invalid requests return Code.InvalidArgument; invalid responses return
17
+ * Code.Internal.
18
+ *
19
+ * Pass a `registry` when your protos define custom predefined rules
20
+ * (proto2 `extend buf.validate.*Rules`).
21
+ */
22
+ function createValidationInterceptor(loggerOrOptions) {
23
+ const opts = loggerOrOptions && typeof loggerOrOptions.error === "function"
24
+ ? { logger: loggerOrOptions }
25
+ : loggerOrOptions ?? {};
26
+ const logger = opts.logger ?? defaultLogger;
27
+ const validator = (0, protovalidate_1.createValidator)(opts.registry ? { registry: opts.registry } : undefined);
28
+ const requestInterceptor = (0, validate_1.createValidateInterceptor)({ validator });
29
+ return (next) => async (req) => {
30
+ const resp = await requestInterceptor(next)(req);
31
+ const schema = req.method.output;
32
+ const msg = resp.message;
33
+ const result = validator.validate(schema, msg);
34
+ if (result.kind === "invalid") {
35
+ const violations = result.violations.map((v) => ({
36
+ field: v.field?.toString() ?? "",
37
+ message: v.message,
38
+ }));
39
+ const details = violations.map((v) => `${v.field}: ${v.message}`).join("; ");
40
+ logger.error("response validation failed", {
41
+ rpc_method: `${req.service.typeName}/${req.method.name}`,
42
+ response_type: schema.typeName,
43
+ violations,
44
+ });
45
+ throw new connect_1.ConnectError(`response validation failed: ${details}`, connect_1.Code.Internal);
46
+ }
47
+ if (result.kind === "error") {
48
+ logger.error("response validation error", {
49
+ rpc_method: `${req.service.typeName}/${req.method.name}`,
50
+ response_type: schema.typeName,
51
+ error: result.error.message,
52
+ });
53
+ throw new connect_1.ConnectError(`response validation error: ${result.error.message}`, connect_1.Code.Internal);
54
+ }
55
+ return resp;
56
+ };
57
+ }
@@ -1,2 +1 @@
1
- export declare function keccak256(...inputs: Uint8Array[]): Buffer;
2
- export declare function computeDigest(body: Uint8Array, timestampMs: number): Buffer;
1
+ export * from "../common/crypto/hash.js";
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.keccak256 = keccak256;
4
- exports.computeDigest = computeDigest;
5
- const sha3_js_1 = require("@noble/hashes/sha3.js");
6
- function keccak256(...inputs) {
7
- const h = sha3_js_1.keccak_256.create();
8
- for (const input of inputs) {
9
- h.update(input);
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
7
  }
11
- return Buffer.from(h.digest());
12
- }
13
- function computeDigest(body, timestampMs) {
14
- const tsBuf = Buffer.alloc(8);
15
- tsBuf.writeBigUInt64LE(BigInt(timestampMs));
16
- return keccak256(body, tsBuf);
17
- }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("../common/crypto/hash.js"), exports);
@@ -1,5 +1 @@
1
- export { verifySignature } from './verify.js';
2
- export { keccak256, computeDigest } from './hash.js';
3
- export { parsePublicKey, publicKeysEqual } from './keys.js';
4
- export { createRequestVerifier, DEFAULT_TOLERANCE_MS } from './request.js';
5
- export type { CreateVerifierOptions, VerifyRequest, VerifyRequestResult, VerifyRequestFailure, RequestVerifier } from './request.js';
1
+ export * from "../common/crypto/index.js";
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_TOLERANCE_MS = exports.createRequestVerifier = exports.publicKeysEqual = exports.parsePublicKey = exports.computeDigest = exports.keccak256 = exports.verifySignature = void 0;
4
- var verify_js_1 = require("./verify.js");
5
- Object.defineProperty(exports, "verifySignature", { enumerable: true, get: function () { return verify_js_1.verifySignature; } });
6
- var hash_js_1 = require("./hash.js");
7
- Object.defineProperty(exports, "keccak256", { enumerable: true, get: function () { return hash_js_1.keccak256; } });
8
- Object.defineProperty(exports, "computeDigest", { enumerable: true, get: function () { return hash_js_1.computeDigest; } });
9
- var keys_js_1 = require("./keys.js");
10
- Object.defineProperty(exports, "parsePublicKey", { enumerable: true, get: function () { return keys_js_1.parsePublicKey; } });
11
- Object.defineProperty(exports, "publicKeysEqual", { enumerable: true, get: function () { return keys_js_1.publicKeysEqual; } });
12
- var request_js_1 = require("./request.js");
13
- Object.defineProperty(exports, "createRequestVerifier", { enumerable: true, get: function () { return request_js_1.createRequestVerifier; } });
14
- Object.defineProperty(exports, "DEFAULT_TOLERANCE_MS", { enumerable: true, get: function () { return request_js_1.DEFAULT_TOLERANCE_MS; } });
17
+ __exportStar(require("../common/crypto/index.js"), exports);
@@ -1,2 +1 @@
1
- export declare function parsePublicKey(key: string | Buffer): Buffer;
2
- export declare function publicKeysEqual(a: Uint8Array, b: Uint8Array): boolean;
1
+ export * from "../common/crypto/keys.js";