@t-0/provider-sdk 1.1.30 → 1.1.32
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/README.md +36 -26
- package/lib/cjs/common/crypto/index.d.ts +2 -2
- package/lib/cjs/common/crypto/index.js +2 -1
- package/lib/cjs/common/crypto/request.d.ts +6 -0
- package/lib/cjs/common/crypto/request.js +51 -0
- package/lib/cjs/common/node.d.ts +2 -0
- package/lib/cjs/common/node.js +5 -1
- package/lib/cjs/common/service.d.ts +1 -2
- package/lib/cjs/service/node.d.ts +5 -1
- package/lib/cjs/service/node.js +7 -15
- package/lib/cjs/service/service.d.ts +3 -11
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/crypto/index.d.ts +2 -2
- package/lib/esm/common/crypto/index.js +1 -1
- package/lib/esm/common/crypto/request.d.ts +6 -0
- package/lib/esm/common/crypto/request.js +50 -0
- package/lib/esm/common/node.d.ts +2 -0
- package/lib/esm/common/node.js +3 -0
- package/lib/esm/common/service.d.ts +1 -2
- package/lib/esm/service/node.d.ts +5 -1
- package/lib/esm/service/node.js +4 -1
- package/lib/esm/service/service.d.ts +3 -11
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,9 +27,7 @@ Implement the `ProviderService` interface to receive callbacks from the T-0 Netw
|
|
|
27
27
|
```ts
|
|
28
28
|
import http from "node:http";
|
|
29
29
|
import {
|
|
30
|
-
|
|
31
|
-
nodeAdapter,
|
|
32
|
-
signatureValidation,
|
|
30
|
+
createHandler,
|
|
33
31
|
ProviderService,
|
|
34
32
|
PayoutRequest,
|
|
35
33
|
PayoutResponse,
|
|
@@ -41,28 +39,40 @@ import {
|
|
|
41
39
|
const networkPublicKey = process.env.NETWORK_PUBLIC_KEY!;
|
|
42
40
|
|
|
43
41
|
const server = http.createServer(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
})
|
|
58
|
-
)
|
|
59
|
-
)
|
|
42
|
+
createHandler(networkPublicKey, (r) => {
|
|
43
|
+
r.service(ProviderService, {
|
|
44
|
+
async payOut(req: PayoutRequest, ctx: HandlerContext): Promise<PayoutResponse> {
|
|
45
|
+
// Handle payout requests from counterparts
|
|
46
|
+
return { result: { case: "accepted", value: {} } } as PayoutResponse;
|
|
47
|
+
},
|
|
48
|
+
async updatePayment(req: UpdatePaymentRequest, ctx: HandlerContext): Promise<UpdatePaymentResponse> {
|
|
49
|
+
// Handle payment status updates
|
|
50
|
+
return {} as UpdatePaymentResponse;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
})
|
|
60
54
|
);
|
|
61
55
|
|
|
62
56
|
server.listen(3000);
|
|
63
57
|
```
|
|
64
58
|
|
|
65
|
-
|
|
59
|
+
`createHandler` composes the full middleware chain in one call: signature validation (raw byte capture), Connect-Node adapter, and service registration with signature verification.
|
|
60
|
+
|
|
61
|
+
<details>
|
|
62
|
+
<summary>Manual composition (advanced)</summary>
|
|
63
|
+
|
|
64
|
+
For cases where you need to customize the middleware chain, the individual components are also exported:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { createService, nodeAdapter, signatureValidation } from "@t-0/provider-sdk";
|
|
68
|
+
|
|
69
|
+
const server = http.createServer(
|
|
70
|
+
signatureValidation(nodeAdapter(createService(networkPublicKey, registerRoutes)))
|
|
71
|
+
);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`signatureValidation` captures raw request bytes for hashing, `nodeAdapter` bridges the RPC transport to Node.js HTTP, and `createService` registers your handlers with signature verification.
|
|
75
|
+
</details>
|
|
66
76
|
|
|
67
77
|
### Standalone Signature Verification
|
|
68
78
|
|
|
@@ -70,7 +80,7 @@ For frameworks that don't use Node's `http.createServer` (Effect, Koa, Fastify,
|
|
|
70
80
|
|
|
71
81
|
```ts
|
|
72
82
|
import { fromBinary, toBinary } from "@bufbuild/protobuf";
|
|
73
|
-
import { createRequestVerifier, PayoutRequestSchema, PayoutResponseSchema } from "@t-0/provider-sdk";
|
|
83
|
+
import { createRequestVerifier, rejectRequest, PayoutRequestSchema, PayoutResponseSchema } from "@t-0/provider-sdk";
|
|
74
84
|
|
|
75
85
|
const verify = createRequestVerifier({
|
|
76
86
|
networkPublicKey: process.env.NETWORK_PUBLIC_KEY!,
|
|
@@ -86,10 +96,10 @@ function handleRequest(rawBody: Uint8Array, headers: Record<string, string>) {
|
|
|
86
96
|
});
|
|
87
97
|
|
|
88
98
|
if (!result.valid) {
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
return errorResponse(
|
|
99
|
+
// rejectRequest maps the failure reason to a well-formed HTTP error
|
|
100
|
+
// with status (400 or 401), Content-Type header, and JSON body.
|
|
101
|
+
const rejected = rejectRequest(result.reason);
|
|
102
|
+
return errorResponse(rejected.status, rejected.headers, rejected.body);
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
// Deserialize the Protobuf request (same raw bytes you verified)
|
|
@@ -110,7 +120,7 @@ The lower-level primitives are also exported individually: `verifySignature`, `c
|
|
|
110
120
|
- **Raw body bytes only.** Pass the exact wire bytes to the verifier — no body parsers, no auto-decompression, never re-serialized protobuf. Protobuf encoding is not canonical; re-encoding produces different bytes and breaks verification.
|
|
111
121
|
- **Pass `Uint8Array`, not `ArrayBuffer`.** If your framework gives you an `ArrayBuffer` (e.g. `request.arrayBuffer()`), wrap it: `new Uint8Array(buf)`.
|
|
112
122
|
- **Header case.** `NetworkHeaders` enum values are title-case (`X-Signature`), but Node lowercases incoming headers. Look up headers by lowercase name: `headers["x-signature"]`.
|
|
113
|
-
- **Wire format is binary protobuf.** Requests and successful responses use `Content-Type: application/proto`. Deserialize with `fromBinary()`, serialize with `toBinary()` from `@bufbuild/protobuf`. For errors,
|
|
123
|
+
- **Wire format is binary protobuf.** Requests and successful responses use `Content-Type: application/proto`. Deserialize with `fromBinary()`, serialize with `toBinary()` from `@bufbuild/protobuf`. For verification errors, use `rejectRequest(result.reason)` to get the correct HTTP status, headers, and JSON body. Success responses **must** include `Content-Type: application/proto`.
|
|
114
124
|
- **Health endpoint.** The T-0 Network probes `/grpc.health.v1.Health/Check` on every endpoint. The probe is signed. Standalone integrations must route this path and return a valid health response. See [`docs/HEALTH_SERVICE.md`](../../docs/HEALTH_SERVICE.md) for the wire contract.
|
|
115
125
|
- **`VerifyRequestFailure` is an open union.** New reason values may be added without a major version bump. Handle unknown reasons as generic failures.
|
|
116
126
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { verifySignature } from './verify.js';
|
|
2
2
|
export { keccak256, computeDigest } from './hash.js';
|
|
3
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';
|
|
4
|
+
export { createRequestVerifier, DEFAULT_TOLERANCE_MS, rejectRequest } from './request.js';
|
|
5
|
+
export type { CreateVerifierOptions, VerifyRequest, VerifyRequestResult, VerifyRequestFailure, RequestVerifier, RejectedRequest } from './request.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
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;
|
|
3
|
+
exports.rejectRequest = exports.DEFAULT_TOLERANCE_MS = exports.createRequestVerifier = exports.publicKeysEqual = exports.parsePublicKey = exports.computeDigest = exports.keccak256 = exports.verifySignature = void 0;
|
|
4
4
|
var verify_js_1 = require("./verify.js");
|
|
5
5
|
Object.defineProperty(exports, "verifySignature", { enumerable: true, get: function () { return verify_js_1.verifySignature; } });
|
|
6
6
|
var hash_js_1 = require("./hash.js");
|
|
@@ -12,3 +12,4 @@ Object.defineProperty(exports, "publicKeysEqual", { enumerable: true, get: funct
|
|
|
12
12
|
var request_js_1 = require("./request.js");
|
|
13
13
|
Object.defineProperty(exports, "createRequestVerifier", { enumerable: true, get: function () { return request_js_1.createRequestVerifier; } });
|
|
14
14
|
Object.defineProperty(exports, "DEFAULT_TOLERANCE_MS", { enumerable: true, get: function () { return request_js_1.DEFAULT_TOLERANCE_MS; } });
|
|
15
|
+
Object.defineProperty(exports, "rejectRequest", { enumerable: true, get: function () { return request_js_1.rejectRequest; } });
|
|
@@ -18,3 +18,9 @@ export type VerifyRequestResult = {
|
|
|
18
18
|
};
|
|
19
19
|
export type RequestVerifier = (req: VerifyRequest) => VerifyRequestResult;
|
|
20
20
|
export declare function createRequestVerifier(opts: CreateVerifierOptions): RequestVerifier;
|
|
21
|
+
export interface RejectedRequest {
|
|
22
|
+
status: number;
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
body: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function rejectRequest(reason: VerifyRequestFailure): RejectedRequest;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_TOLERANCE_MS = void 0;
|
|
4
4
|
exports.createRequestVerifier = createRequestVerifier;
|
|
5
|
+
exports.rejectRequest = rejectRequest;
|
|
5
6
|
const verify_js_1 = require("./verify.js");
|
|
6
7
|
const hash_js_1 = require("./hash.js");
|
|
7
8
|
const keys_js_1 = require("./keys.js");
|
|
@@ -49,3 +50,53 @@ function createRequestVerifier(opts) {
|
|
|
49
50
|
return { valid: true };
|
|
50
51
|
};
|
|
51
52
|
}
|
|
53
|
+
function rejectRequest(reason) {
|
|
54
|
+
let status;
|
|
55
|
+
let code;
|
|
56
|
+
let message;
|
|
57
|
+
switch (reason) {
|
|
58
|
+
case 'invalid_timestamp':
|
|
59
|
+
status = 400;
|
|
60
|
+
code = 'invalid_argument';
|
|
61
|
+
message = 'Invalid signature timestamp';
|
|
62
|
+
break;
|
|
63
|
+
case 'timestamp_out_of_range':
|
|
64
|
+
status = 400;
|
|
65
|
+
code = 'invalid_argument';
|
|
66
|
+
message = 'Signature timestamp out of range';
|
|
67
|
+
break;
|
|
68
|
+
case 'invalid_public_key':
|
|
69
|
+
status = 400;
|
|
70
|
+
code = 'invalid_argument';
|
|
71
|
+
message = 'Invalid public key format';
|
|
72
|
+
break;
|
|
73
|
+
case 'unknown_public_key':
|
|
74
|
+
status = 401;
|
|
75
|
+
code = 'unauthenticated';
|
|
76
|
+
message = 'Unknown public key';
|
|
77
|
+
break;
|
|
78
|
+
case 'invalid_signature_format':
|
|
79
|
+
status = 400;
|
|
80
|
+
code = 'invalid_argument';
|
|
81
|
+
message = 'Invalid signature format';
|
|
82
|
+
break;
|
|
83
|
+
case 'signature_failed':
|
|
84
|
+
status = 401;
|
|
85
|
+
code = 'unauthenticated';
|
|
86
|
+
message = 'Signature verification failed';
|
|
87
|
+
break;
|
|
88
|
+
default: {
|
|
89
|
+
const _exhaustive = reason;
|
|
90
|
+
void _exhaustive;
|
|
91
|
+
status = 401;
|
|
92
|
+
code = 'unauthenticated';
|
|
93
|
+
message = 'Request verification failed';
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
status,
|
|
99
|
+
headers: { 'Content-Type': 'application/json' },
|
|
100
|
+
body: JSON.stringify({ code, message }),
|
|
101
|
+
};
|
|
102
|
+
}
|
package/lib/cjs/common/node.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type * as http from "node:http";
|
|
2
|
+
import { type CreateServiceOptions, type Router } from "./service.js";
|
|
2
3
|
export type NodeHandlerFn = (request: http.IncomingMessage, response: http.ServerResponse) => void;
|
|
3
4
|
export declare const signatureValidation: (next: NodeHandlerFn) => NodeHandlerFn;
|
|
5
|
+
export declare const createHandler: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => NodeHandlerFn;
|
package/lib/cjs/common/node.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.signatureValidation = void 0;
|
|
3
|
+
exports.createHandler = exports.signatureValidation = void 0;
|
|
4
4
|
const sha3_js_1 = require("@noble/hashes/sha3.js");
|
|
5
|
+
const connect_node_1 = require("@connectrpc/connect-node");
|
|
6
|
+
const service_js_1 = require("./service.js");
|
|
5
7
|
const signatureValidation = (next) => (req, resp) => {
|
|
6
8
|
const hasher = sha3_js_1.keccak_256.create();
|
|
7
9
|
req.hasher = hasher;
|
|
@@ -13,3 +15,5 @@ const signatureValidation = (next) => (req, resp) => {
|
|
|
13
15
|
next(req, resp);
|
|
14
16
|
};
|
|
15
17
|
exports.signatureValidation = signatureValidation;
|
|
18
|
+
const createHandler = (networkPublicKey, registerRoutes, options) => (0, exports.signatureValidation)((0, connect_node_1.connectNodeAdapter)((0, service_js_1.createService)(networkPublicKey, registerRoutes, options)));
|
|
19
|
+
exports.createHandler = createHandler;
|
|
@@ -25,7 +25,7 @@ export interface CreateServiceOptions {
|
|
|
25
25
|
version?: string;
|
|
26
26
|
}
|
|
27
27
|
export declare const REQUEST_VALIDITY_MILLIS = 60000;
|
|
28
|
-
interface Router {
|
|
28
|
+
export interface Router {
|
|
29
29
|
service: <T extends DescService, I extends ServiceImpl<T>>(service: T, implementation: I) => void;
|
|
30
30
|
}
|
|
31
31
|
export declare const createService: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => {
|
|
@@ -34,4 +34,3 @@ export declare const createService: (networkPublicKey: string | Buffer, register
|
|
|
34
34
|
grpcWeb: boolean;
|
|
35
35
|
contextValues: (req: any) => import("@connectrpc/connect").ContextValues;
|
|
36
36
|
};
|
|
37
|
-
export {};
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { createHandler as createHandlerCommon } from "../common/node.js";
|
|
2
|
+
import type { Router, CreateServiceOptions } from "../common/service.js";
|
|
3
|
+
export { signatureValidation } from "../common/node.js";
|
|
4
|
+
export type { NodeHandlerFn } from "../common/node.js";
|
|
5
|
+
export declare const createHandler: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => ReturnType<typeof createHandlerCommon>;
|
package/lib/cjs/service/node.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
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
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.createHandler = exports.signatureValidation = void 0;
|
|
4
|
+
const node_js_1 = require("../common/node.js");
|
|
5
|
+
const version_js_1 = require("../version.js");
|
|
6
|
+
var node_js_2 = require("../common/node.js");
|
|
7
|
+
Object.defineProperty(exports, "signatureValidation", { enumerable: true, get: function () { return node_js_2.signatureValidation; } });
|
|
8
|
+
const createHandler = (networkPublicKey, registerRoutes, options) => (0, node_js_1.createHandler)(networkPublicKey, registerRoutes, { ...options, version: options?.version ?? version_js_1.SDK_VERSION });
|
|
9
|
+
exports.createHandler = createHandler;
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { type CreateServiceOptions } from "../common/service.js";
|
|
2
|
-
export type { CreateServiceOptions } from "../common/service.js";
|
|
1
|
+
import { createService as createServiceCommon, type CreateServiceOptions, type Router } from "../common/service.js";
|
|
2
|
+
export type { CreateServiceOptions, Router } from "../common/service.js";
|
|
3
3
|
export { REQUEST_VALIDITY_MILLIS } from "../common/service.js";
|
|
4
|
-
|
|
5
|
-
service: <T extends import("@bufbuild/protobuf").DescService, I extends import("@connectrpc/connect").ServiceImpl<T>>(service: T, implementation: I) => void;
|
|
6
|
-
}
|
|
7
|
-
export declare const createService: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => {
|
|
8
|
-
routes: (router: import("@connectrpc/connect").ConnectRouter) => void;
|
|
9
|
-
interceptors: import("@connectrpc/connect").Interceptor[];
|
|
10
|
-
grpcWeb: boolean;
|
|
11
|
-
contextValues: (req: any) => import("@connectrpc/connect").ContextValues;
|
|
12
|
-
};
|
|
4
|
+
export declare const createService: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => ReturnType<typeof createServiceCommon>;
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.1.
|
|
1
|
+
export declare const SDK_VERSION = "1.1.32";
|
package/lib/cjs/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { verifySignature } from './verify.js';
|
|
2
2
|
export { keccak256, computeDigest } from './hash.js';
|
|
3
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';
|
|
4
|
+
export { createRequestVerifier, DEFAULT_TOLERANCE_MS, rejectRequest } from './request.js';
|
|
5
|
+
export type { CreateVerifierOptions, VerifyRequest, VerifyRequestResult, VerifyRequestFailure, RequestVerifier, RejectedRequest } from './request.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { verifySignature } from './verify.js';
|
|
2
2
|
export { keccak256, computeDigest } from './hash.js';
|
|
3
3
|
export { parsePublicKey, publicKeysEqual } from './keys.js';
|
|
4
|
-
export { createRequestVerifier, DEFAULT_TOLERANCE_MS } from './request.js';
|
|
4
|
+
export { createRequestVerifier, DEFAULT_TOLERANCE_MS, rejectRequest } from './request.js';
|
|
@@ -18,3 +18,9 @@ export type VerifyRequestResult = {
|
|
|
18
18
|
};
|
|
19
19
|
export type RequestVerifier = (req: VerifyRequest) => VerifyRequestResult;
|
|
20
20
|
export declare function createRequestVerifier(opts: CreateVerifierOptions): RequestVerifier;
|
|
21
|
+
export interface RejectedRequest {
|
|
22
|
+
status: number;
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
body: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function rejectRequest(reason: VerifyRequestFailure): RejectedRequest;
|
|
@@ -45,3 +45,53 @@ export function createRequestVerifier(opts) {
|
|
|
45
45
|
return { valid: true };
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
+
export function rejectRequest(reason) {
|
|
49
|
+
let status;
|
|
50
|
+
let code;
|
|
51
|
+
let message;
|
|
52
|
+
switch (reason) {
|
|
53
|
+
case 'invalid_timestamp':
|
|
54
|
+
status = 400;
|
|
55
|
+
code = 'invalid_argument';
|
|
56
|
+
message = 'Invalid signature timestamp';
|
|
57
|
+
break;
|
|
58
|
+
case 'timestamp_out_of_range':
|
|
59
|
+
status = 400;
|
|
60
|
+
code = 'invalid_argument';
|
|
61
|
+
message = 'Signature timestamp out of range';
|
|
62
|
+
break;
|
|
63
|
+
case 'invalid_public_key':
|
|
64
|
+
status = 400;
|
|
65
|
+
code = 'invalid_argument';
|
|
66
|
+
message = 'Invalid public key format';
|
|
67
|
+
break;
|
|
68
|
+
case 'unknown_public_key':
|
|
69
|
+
status = 401;
|
|
70
|
+
code = 'unauthenticated';
|
|
71
|
+
message = 'Unknown public key';
|
|
72
|
+
break;
|
|
73
|
+
case 'invalid_signature_format':
|
|
74
|
+
status = 400;
|
|
75
|
+
code = 'invalid_argument';
|
|
76
|
+
message = 'Invalid signature format';
|
|
77
|
+
break;
|
|
78
|
+
case 'signature_failed':
|
|
79
|
+
status = 401;
|
|
80
|
+
code = 'unauthenticated';
|
|
81
|
+
message = 'Signature verification failed';
|
|
82
|
+
break;
|
|
83
|
+
default: {
|
|
84
|
+
const _exhaustive = reason;
|
|
85
|
+
void _exhaustive;
|
|
86
|
+
status = 401;
|
|
87
|
+
code = 'unauthenticated';
|
|
88
|
+
message = 'Request verification failed';
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
status,
|
|
94
|
+
headers: { 'Content-Type': 'application/json' },
|
|
95
|
+
body: JSON.stringify({ code, message }),
|
|
96
|
+
};
|
|
97
|
+
}
|
package/lib/esm/common/node.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type * as http from "node:http";
|
|
2
|
+
import { type CreateServiceOptions, type Router } from "./service.js";
|
|
2
3
|
export type NodeHandlerFn = (request: http.IncomingMessage, response: http.ServerResponse) => void;
|
|
3
4
|
export declare const signatureValidation: (next: NodeHandlerFn) => NodeHandlerFn;
|
|
5
|
+
export declare const createHandler: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => NodeHandlerFn;
|
package/lib/esm/common/node.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
2
|
+
import { connectNodeAdapter } from "@connectrpc/connect-node";
|
|
3
|
+
import { createService } from "./service.js";
|
|
2
4
|
export const signatureValidation = (next) => (req, resp) => {
|
|
3
5
|
const hasher = keccak_256.create();
|
|
4
6
|
req.hasher = hasher;
|
|
@@ -9,3 +11,4 @@ export const signatureValidation = (next) => (req, resp) => {
|
|
|
9
11
|
});
|
|
10
12
|
next(req, resp);
|
|
11
13
|
};
|
|
14
|
+
export const createHandler = (networkPublicKey, registerRoutes, options) => signatureValidation(connectNodeAdapter(createService(networkPublicKey, registerRoutes, options)));
|
|
@@ -25,7 +25,7 @@ export interface CreateServiceOptions {
|
|
|
25
25
|
version?: string;
|
|
26
26
|
}
|
|
27
27
|
export declare const REQUEST_VALIDITY_MILLIS = 60000;
|
|
28
|
-
interface Router {
|
|
28
|
+
export interface Router {
|
|
29
29
|
service: <T extends DescService, I extends ServiceImpl<T>>(service: T, implementation: I) => void;
|
|
30
30
|
}
|
|
31
31
|
export declare const createService: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => {
|
|
@@ -34,4 +34,3 @@ export declare const createService: (networkPublicKey: string | Buffer, register
|
|
|
34
34
|
grpcWeb: boolean;
|
|
35
35
|
contextValues: (req: any) => import("@connectrpc/connect").ContextValues;
|
|
36
36
|
};
|
|
37
|
-
export {};
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { createHandler as createHandlerCommon } from "../common/node.js";
|
|
2
|
+
import type { Router, CreateServiceOptions } from "../common/service.js";
|
|
3
|
+
export { signatureValidation } from "../common/node.js";
|
|
4
|
+
export type { NodeHandlerFn } from "../common/node.js";
|
|
5
|
+
export declare const createHandler: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => ReturnType<typeof createHandlerCommon>;
|
package/lib/esm/service/node.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { createHandler as createHandlerCommon } from "../common/node.js";
|
|
2
|
+
import { SDK_VERSION } from "../version.js";
|
|
3
|
+
export { signatureValidation } from "../common/node.js";
|
|
4
|
+
export const createHandler = (networkPublicKey, registerRoutes, options) => createHandlerCommon(networkPublicKey, registerRoutes, { ...options, version: options?.version ?? SDK_VERSION });
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { type CreateServiceOptions } from "../common/service.js";
|
|
2
|
-
export type { CreateServiceOptions } from "../common/service.js";
|
|
1
|
+
import { createService as createServiceCommon, type CreateServiceOptions, type Router } from "../common/service.js";
|
|
2
|
+
export type { CreateServiceOptions, Router } from "../common/service.js";
|
|
3
3
|
export { REQUEST_VALIDITY_MILLIS } from "../common/service.js";
|
|
4
|
-
|
|
5
|
-
service: <T extends import("@bufbuild/protobuf").DescService, I extends import("@connectrpc/connect").ServiceImpl<T>>(service: T, implementation: I) => void;
|
|
6
|
-
}
|
|
7
|
-
export declare const createService: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => {
|
|
8
|
-
routes: (router: import("@connectrpc/connect").ConnectRouter) => void;
|
|
9
|
-
interceptors: import("@connectrpc/connect").Interceptor[];
|
|
10
|
-
grpcWeb: boolean;
|
|
11
|
-
contextValues: (req: any) => import("@connectrpc/connect").ContextValues;
|
|
12
|
-
};
|
|
4
|
+
export declare const createService: (networkPublicKey: string | Buffer, registerRoutes: (router: Router) => void, options?: CreateServiceOptions) => ReturnType<typeof createServiceCommon>;
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.1.
|
|
1
|
+
export declare const SDK_VERSION = "1.1.32";
|
package/lib/esm/version.js
CHANGED