@t-0/provider-sdk 1.0.24 → 1.0.26
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/cjs/client/client.js +46 -0
- package/lib/{client → cjs/client}/signer.d.ts +1 -1
- package/lib/cjs/client/signer.js +69 -0
- package/lib/cjs/common/gen/tzero/v1/common/common_pb.js +56 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/common/payment_method_pb.d.ts +1 -1
- package/lib/cjs/common/gen/tzero/v1/common/payment_method_pb.js +60 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/payment/network_pb.d.ts +2 -2
- package/lib/cjs/common/gen/tzero/v1/payment/network_pb.js +147 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/payment/provider_pb.d.ts +2 -2
- package/lib/cjs/common/gen/tzero/v1/payment/provider_pb.js +206 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/payment_intent/provider/provider_pb.d.ts +2 -2
- package/lib/cjs/common/gen/tzero/v1/payment_intent/provider/provider_pb.js +87 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/payment_intent/recipient/recipient_pb.d.ts +2 -2
- package/lib/cjs/common/gen/tzero/v1/payment_intent/recipient/recipient_pb.js +62 -0
- package/lib/cjs/common/gen/tzero/v1/public/public_pb.js +88 -0
- package/lib/cjs/common/headers.js +10 -0
- package/lib/cjs/examples/payment_intent/pay-in-provider-flow.d.ts +4 -0
- package/lib/cjs/examples/payment_intent/pay-in-provider-flow.js +56 -0
- package/lib/cjs/examples/payment_intent/service.d.ts +1 -0
- package/lib/cjs/examples/payment_intent/service.js +68 -0
- package/lib/cjs/examples/server.d.ts +4 -0
- package/lib/cjs/examples/server.js +93 -0
- package/lib/cjs/examples/update-quote.d.ts +4 -0
- package/lib/cjs/examples/update-quote.js +42 -0
- package/lib/cjs/index.d.ts +11 -0
- package/lib/cjs/index.js +50 -0
- package/lib/cjs/package.json +1 -0
- package/lib/{payment_intent → cjs/payment_intent}/provider/index.d.ts +1 -1
- package/lib/cjs/payment_intent/provider/index.js +17 -0
- package/lib/{payment_intent → cjs/payment_intent}/recipient/index.d.ts +1 -1
- package/lib/cjs/payment_intent/recipient/index.js +17 -0
- package/lib/cjs/service/node.d.ts +3 -0
- package/lib/cjs/service/node.js +15 -0
- package/lib/{service → cjs/service}/service.d.ts +2 -3
- package/lib/cjs/service/service.js +112 -0
- package/lib/esm/client/client.d.ts +16 -0
- package/lib/{client → esm/client}/client.js +2 -2
- package/lib/esm/client/signer.d.ts +3 -0
- package/lib/{gen → esm/common/gen/tzero/v1}/common/common_pb.d.ts +2 -2
- package/lib/{common → esm/common}/gen/tzero/v1/common/common_pb.js +1 -1
- package/lib/{gen → esm/common/gen/tzero/v1}/common/payment_method_pb.d.ts +3 -3
- package/lib/{common → esm/common}/gen/tzero/v1/common/payment_method_pb.js +2 -2
- package/lib/{gen/network → esm/common/gen/tzero/v1/payment}/network_pb.d.ts +86 -86
- package/lib/{common → esm/common}/gen/tzero/v1/payment/network_pb.js +3 -3
- package/lib/{gen/network → esm/common/gen/tzero/v1/payment}/provider_pb.d.ts +84 -84
- package/lib/{common → esm/common}/gen/tzero/v1/payment/provider_pb.js +3 -3
- package/lib/{gen → esm/common/gen/tzero/v1}/payment_intent/provider/provider_pb.d.ts +4 -4
- package/lib/{common → esm/common}/gen/tzero/v1/payment_intent/provider/provider_pb.js +3 -3
- package/lib/{gen → esm/common/gen/tzero/v1}/payment_intent/recipient/recipient_pb.d.ts +4 -4
- package/lib/{common → esm/common}/gen/tzero/v1/payment_intent/recipient/recipient_pb.js +3 -3
- package/lib/esm/common/gen/tzero/v1/public/public_pb.d.ts +234 -0
- package/lib/{common → esm/common}/gen/tzero/v1/public/public_pb.js +1 -1
- package/lib/esm/common/headers.d.ts +6 -0
- package/lib/esm/examples/payment_intent/pay-in-provider-flow.d.ts +4 -0
- package/lib/esm/examples/payment_intent/pay-in-provider-flow.js +51 -0
- package/lib/esm/examples/payment_intent/service.d.ts +1 -0
- package/lib/esm/examples/payment_intent/service.js +30 -0
- package/lib/esm/examples/server.d.ts +4 -0
- package/lib/esm/examples/server.js +55 -0
- package/lib/esm/examples/update-quote.d.ts +4 -0
- package/lib/esm/examples/update-quote.js +37 -0
- package/lib/esm/index.d.ts +11 -0
- package/lib/esm/index.js +10 -0
- package/lib/esm/payment_intent/provider/index.d.ts +1 -0
- package/lib/{payment_intent → esm/payment_intent}/provider/index.js +1 -1
- package/lib/esm/payment_intent/recipient/index.d.ts +1 -0
- package/lib/{payment_intent → esm/payment_intent}/recipient/index.js +1 -1
- package/lib/esm/service/node.d.ts +3 -0
- package/lib/esm/service/service.d.ts +15 -0
- package/lib/{service → esm/service}/service.js +3 -3
- package/lib/tsconfig.cjs.tsbuildinfo +1 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +19 -10
- package/lib/common/gen/common/common_pb.d.ts +0 -26
- package/lib/common/gen/common/common_pb.js +0 -13
- package/lib/common/gen/common/payment_method_pb.d.ts +0 -51
- package/lib/common/gen/common/payment_method_pb.js +0 -18
- package/lib/common/gen/network/network_pb.d.ts +0 -649
- package/lib/common/gen/network/network_pb.js +0 -163
- package/lib/common/gen/network/provider_pb.d.ts +0 -695
- package/lib/common/gen/network/provider_pb.js +0 -218
- package/lib/gen/common/common_pb.js +0 -53
- package/lib/gen/common/payment_method_pb.js +0 -57
- package/lib/gen/network/network_pb.js +0 -144
- package/lib/gen/network/provider_pb.js +0 -203
- package/lib/gen/payment_intent/provider/provider_pb.js +0 -84
- package/lib/gen/payment_intent/recipient/recipient_pb.js +0 -59
- package/lib/index.d.ts +0 -11
- package/lib/index.js +0 -10
- package/lib/service/node.d.ts +0 -2
- /package/lib/{client → cjs/client}/client.d.ts +0 -0
- /package/lib/{common → cjs/common}/gen/tzero/v1/common/common_pb.d.ts +0 -0
- /package/lib/{common → cjs/common}/gen/tzero/v1/public/public_pb.d.ts +0 -0
- /package/lib/{common → cjs/common}/headers.d.ts +0 -0
- /package/lib/{client → esm/client}/signer.js +0 -0
- /package/lib/{common → esm/common}/headers.js +0 -0
- /package/lib/{service → esm/service}/node.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../../common/gen/tzero/v1/payment_intent/recipient/recipient_pb';
|
|
1
|
+
export * from '../../common/gen/tzero/v1/payment_intent/recipient/recipient_pb.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("../../common/gen/tzero/v1/payment_intent/recipient/recipient_pb.js"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signatureValidation = void 0;
|
|
4
|
+
const sha3_1 = require("@noble/hashes/sha3");
|
|
5
|
+
const signatureValidation = (next) => (req, resp) => {
|
|
6
|
+
const hasher = sha3_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;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ConnectRouter } from "@connectrpc/connect";
|
|
2
|
-
import type { ServiceImpl } from "@connectrpc/connect/dist/esm/implementation";
|
|
3
2
|
import type { Interceptor } from "@connectrpc/connect";
|
|
4
|
-
import { NodeServerRequest } from "@connectrpc/connect-node/dist/esm/node-universal-handler";
|
|
5
3
|
import type { DescService } from "@bufbuild/protobuf";
|
|
4
|
+
import type { ServiceImpl } from "@connectrpc/connect";
|
|
6
5
|
export declare const REQUEST_VALIDITY_MILLIS = 60000;
|
|
7
6
|
interface Router {
|
|
8
7
|
service: <T extends DescService>(service: T, implementation: Partial<ServiceImpl<T>>) => void;
|
|
@@ -11,6 +10,6 @@ export declare const createService: (networkPublicKey: string | Buffer, register
|
|
|
11
10
|
routes: (router: ConnectRouter) => void;
|
|
12
11
|
interceptors: Interceptor[];
|
|
13
12
|
grpcWeb: boolean;
|
|
14
|
-
contextValues: (req:
|
|
13
|
+
contextValues: (req: any) => import("@connectrpc/connect").ContextValues;
|
|
15
14
|
};
|
|
16
15
|
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.createService = exports.REQUEST_VALIDITY_MILLIS = void 0;
|
|
40
|
+
const connect_1 = require("@connectrpc/connect");
|
|
41
|
+
const headers_js_1 = __importDefault(require("../common/headers.js"));
|
|
42
|
+
const secp = __importStar(require("@noble/secp256k1"));
|
|
43
|
+
exports.REQUEST_VALIDITY_MILLIS = 60000;
|
|
44
|
+
const createSignatureVerification = (networkPublicKey) => (next) => async (req) => {
|
|
45
|
+
const ts = decodeNum(getHeader(req, headers_js_1.default.SignatureTimestamp));
|
|
46
|
+
if (Date.now() - ts > 60000) {
|
|
47
|
+
throw new connect_1.ConnectError(`${headers_js_1.default.SignatureTimestamp} must be within ${exports.REQUEST_VALIDITY_MILLIS} milliseconds from now`, connect_1.Code.InvalidArgument);
|
|
48
|
+
}
|
|
49
|
+
const publicKey = decodeHex(getHeader(req, headers_js_1.default.PublicKey));
|
|
50
|
+
if (networkPublicKey.compare(publicKey) !== 0) {
|
|
51
|
+
throw new connect_1.ConnectError(`${headers_js_1.default.PublicKey} value is not network public key`, connect_1.Code.Unauthenticated);
|
|
52
|
+
}
|
|
53
|
+
const signature = decodeHex(getHeader(req, headers_js_1.default.Signature));
|
|
54
|
+
const hasher = req.contextValues.get(kHash);
|
|
55
|
+
const tsBuf = Buffer.alloc(8);
|
|
56
|
+
tsBuf.writeBigUInt64LE(BigInt(ts)); // 64‑bit little‑endian timestamp
|
|
57
|
+
const hash = hasher
|
|
58
|
+
.update(tsBuf)
|
|
59
|
+
.digest();
|
|
60
|
+
let signatureValid = false;
|
|
61
|
+
try {
|
|
62
|
+
signatureValid = secp.verify(signature, hash, publicKey);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
throw new connect_1.ConnectError(`${headers_js_1.default.Signature} has invalid signature or public key format`, connect_1.Code.Unauthenticated);
|
|
66
|
+
}
|
|
67
|
+
if (!signatureValid) {
|
|
68
|
+
throw new connect_1.ConnectError(`${headers_js_1.default.Signature} has invalid signature`, connect_1.Code.Unauthenticated);
|
|
69
|
+
}
|
|
70
|
+
return await next(req);
|
|
71
|
+
};
|
|
72
|
+
const createService = (networkPublicKey, registerRoutes) => {
|
|
73
|
+
if (typeof networkPublicKey == "string") {
|
|
74
|
+
networkPublicKey = decodeHex(networkPublicKey);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
routes: (router) => {
|
|
78
|
+
registerRoutes(router);
|
|
79
|
+
},
|
|
80
|
+
interceptors: [createSignatureVerification(networkPublicKey)],
|
|
81
|
+
grpcWeb: false,
|
|
82
|
+
contextValues: (req) => {
|
|
83
|
+
return (0, connect_1.createContextValues)().set(kHash, req.hasher);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
exports.createService = createService;
|
|
88
|
+
const kHash = (0, connect_1.createContextKey)(undefined);
|
|
89
|
+
function getHeader(req, header) {
|
|
90
|
+
const raw = req.header.get(header);
|
|
91
|
+
if (!raw) {
|
|
92
|
+
throw new connect_1.ConnectError(`missing required header '${header}'`, connect_1.Code.InvalidArgument);
|
|
93
|
+
}
|
|
94
|
+
return raw;
|
|
95
|
+
}
|
|
96
|
+
function decodeHex(value) {
|
|
97
|
+
value = value.startsWith('0x') ? value.slice(2) : value;
|
|
98
|
+
try {
|
|
99
|
+
return Buffer.from(value, "hex");
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
throw new connect_1.ConnectError(`invalid header format. '${value}' must be hex encoded`, connect_1.Code.InvalidArgument);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function decodeNum(value) {
|
|
106
|
+
try {
|
|
107
|
+
return parseInt(value);
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
throw new connect_1.ConnectError(`invalid header format. '${value}' must be a number`, connect_1.Code.InvalidArgument);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DescService } from "@bufbuild/protobuf";
|
|
2
|
+
export declare const DEFAULT_ENDPOINT = "https://api.t-0.network";
|
|
3
|
+
export declare function createClient<T extends DescService>(signer: string | Buffer | ((data: Buffer) => Promise<Signature>) | Buffer<ArrayBufferLike>, endpoint: string | undefined, svc: T): import("@connectrpc/connect").Client<T>;
|
|
4
|
+
/**
|
|
5
|
+
* Signature with metadata for particular request
|
|
6
|
+
*/
|
|
7
|
+
export interface Signature {
|
|
8
|
+
signature: Buffer;
|
|
9
|
+
publicKey: Buffer;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Signature function for signing requests to T-0 API. Accepts any data in string format and return signature
|
|
13
|
+
* with metadata
|
|
14
|
+
*/
|
|
15
|
+
export type SignerFunction = (data: Buffer) => Promise<Signature>;
|
|
16
|
+
export default createClient;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createClient as createConnectClient } from "@connectrpc/connect";
|
|
2
2
|
import { createConnectTransport } from "@connectrpc/connect-web";
|
|
3
3
|
import { keccak_256 } from "@noble/hashes/sha3";
|
|
4
|
-
import CreateSigner from "./signer";
|
|
5
|
-
import NetworkHeaders from "../common/headers";
|
|
4
|
+
import CreateSigner from "./signer.js";
|
|
5
|
+
import NetworkHeaders from "../common/headers.js";
|
|
6
6
|
export const DEFAULT_ENDPOINT = "https://api.t-0.network";
|
|
7
7
|
export function createClient(signer, endpoint, svc) {
|
|
8
8
|
let customFetch;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { GenEnum, GenFile, GenMessage } from "@bufbuild/protobuf/codegenv2";
|
|
2
2
|
import type { Message } from "@bufbuild/protobuf";
|
|
3
3
|
/**
|
|
4
|
-
* Describes the file common/common.proto.
|
|
4
|
+
* Describes the file tzero/v1/common/common.proto.
|
|
5
5
|
*/
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const file_tzero_v1_common_common: GenFile;
|
|
7
7
|
/**
|
|
8
8
|
* Decimal 123.45 equals to unscaled=12345 and exponent=-2 (e.g. unscaled * 10^exponent, 123.45 = 12345 * 10^-2)
|
|
9
9
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by protoc-gen-es v2.6.2 with parameter "target=ts"
|
|
1
|
+
// @generated by protoc-gen-es v2.6.2 with parameter "target=ts,import_extension=js"
|
|
2
2
|
// @generated from file tzero/v1/common/common.proto (package tzero.v1.common, syntax proto3)
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
import { enumDesc, fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { GenEnum, GenFile, GenMessage } from "@bufbuild/protobuf/codegenv2";
|
|
2
|
-
import type { Blockchain, Stablecoin } from "./common_pb";
|
|
2
|
+
import type { Blockchain, Stablecoin } from "./common_pb.js";
|
|
3
3
|
import type { Message } from "@bufbuild/protobuf";
|
|
4
4
|
/**
|
|
5
|
-
* Describes the file common/payment_method.proto.
|
|
5
|
+
* Describes the file tzero/v1/common/payment_method.proto.
|
|
6
6
|
*/
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const file_tzero_v1_common_payment_method: GenFile;
|
|
8
8
|
/**
|
|
9
9
|
* @generated from message tzero.v1.common.PaymentMethod
|
|
10
10
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// @generated by protoc-gen-es v2.6.2 with parameter "target=ts"
|
|
1
|
+
// @generated by protoc-gen-es v2.6.2 with parameter "target=ts,import_extension=js"
|
|
2
2
|
// @generated from file tzero/v1/common/payment_method.proto (package tzero.v1.common, syntax proto3)
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
import { enumDesc, fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2";
|
|
5
|
-
import { file_tzero_v1_common_common } from "./common_pb";
|
|
5
|
+
import { file_tzero_v1_common_common } from "./common_pb.js";
|
|
6
6
|
/**
|
|
7
7
|
* Describes the file tzero/v1/common/payment_method.proto.
|
|
8
8
|
*/
|