@t-0/provider-sdk 1.0.25 → 1.0.27
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/cjs/client/signer.js +69 -0
- package/lib/cjs/common/gen/buf/validate/validate_pb.d.ts +4590 -0
- package/lib/cjs/common/gen/buf/validate/validate_pb.js +353 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/common/common_pb.d.ts +2 -0
- package/lib/cjs/common/gen/tzero/v1/common/common_pb.js +57 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/common/payment_method_pb.d.ts +40 -22
- package/lib/cjs/common/gen/tzero/v1/common/payment_method_pb.js +67 -0
- package/lib/cjs/common/gen/tzero/v1/common/payment_receipt_pb.d.ts +77 -0
- package/lib/cjs/common/gen/tzero/v1/common/payment_receipt_pb.js +32 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/payment/network_pb.d.ts +98 -59
- package/lib/cjs/common/gen/tzero/v1/payment/network_pb.js +139 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/payment/provider_pb.d.ts +153 -53
- package/lib/cjs/common/gen/tzero/v1/payment/provider_pb.js +241 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/payment_intent/provider/provider_pb.d.ts +22 -0
- package/lib/cjs/common/gen/tzero/v1/payment_intent/provider/provider_pb.js +88 -0
- package/lib/{common → cjs/common}/gen/tzero/v1/payment_intent/recipient/recipient_pb.d.ts +201 -14
- package/lib/cjs/common/gen/tzero/v1/payment_intent/recipient/recipient_pb.js +95 -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.js +50 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/payment_intent/provider/index.js +17 -0
- package/lib/cjs/payment_intent/recipient/index.js +17 -0
- package/lib/cjs/service/node.js +15 -0
- package/lib/cjs/service/service.js +112 -0
- package/lib/esm/client/client.d.ts +16 -0
- package/lib/esm/client/signer.d.ts +3 -0
- package/lib/esm/common/gen/buf/validate/validate_pb.d.ts +4590 -0
- package/lib/esm/common/gen/buf/validate/validate_pb.js +350 -0
- package/lib/esm/common/gen/tzero/v1/common/common_pb.d.ts +66 -0
- package/lib/{common → esm/common}/gen/tzero/v1/common/common_pb.js +2 -1
- package/lib/esm/common/gen/tzero/v1/common/payment_method_pb.d.ts +140 -0
- package/lib/esm/common/gen/tzero/v1/common/payment_method_pb.js +64 -0
- package/lib/esm/common/gen/tzero/v1/common/payment_receipt_pb.d.ts +77 -0
- package/lib/esm/common/gen/tzero/v1/common/payment_receipt_pb.js +29 -0
- package/lib/esm/common/gen/tzero/v1/payment/network_pb.d.ts +606 -0
- package/lib/{common → esm/common}/gen/tzero/v1/payment/network_pb.js +9 -17
- package/lib/esm/common/gen/tzero/v1/payment/provider_pb.d.ts +741 -0
- package/lib/{common → esm/common}/gen/tzero/v1/payment/provider_pb.js +71 -36
- package/lib/esm/common/gen/tzero/v1/payment_intent/provider/provider_pb.d.ts +318 -0
- package/lib/{common → esm/common}/gen/tzero/v1/payment_intent/provider/provider_pb.js +2 -1
- package/lib/esm/common/gen/tzero/v1/payment_intent/recipient/recipient_pb.d.ts +401 -0
- package/lib/esm/common/gen/tzero/v1/payment_intent/recipient/recipient_pb.js +92 -0
- package/lib/esm/common/gen/tzero/v1/public/public_pb.d.ts +234 -0
- 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/payment_intent/provider/index.js +1 -0
- package/lib/esm/payment_intent/recipient/index.js +1 -0
- 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 +2 -2
- package/lib/tsconfig.cjs.tsbuildinfo +1 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +16 -7
- package/lib/common/gen/tzero/v1/common/payment_method_pb.js +0 -57
- package/lib/common/gen/tzero/v1/payment_intent/recipient/recipient_pb.js +0 -59
- /package/lib/{client → cjs/client}/client.d.ts +0 -0
- /package/lib/{client → cjs/client}/signer.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/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/lib/{payment_intent → cjs/payment_intent}/provider/index.d.ts +0 -0
- /package/lib/{payment_intent → cjs/payment_intent}/recipient/index.d.ts +0 -0
- /package/lib/{service → cjs/service}/node.d.ts +0 -0
- /package/lib/{service → cjs/service}/service.d.ts +0 -0
- /package/lib/{client → esm/client}/client.js +0 -0
- /package/lib/{client → esm/client}/signer.js +0 -0
- /package/lib/{common → esm/common}/gen/tzero/v1/public/public_pb.js +0 -0
- /package/lib/{common → esm/common}/headers.js +0 -0
- /package/lib/{index.js → esm/index.js} +0 -0
- /package/lib/{payment_intent/provider/index.js → esm/payment_intent/provider/index.d.ts} +0 -0
- /package/lib/{payment_intent/recipient/index.js → esm/payment_intent/recipient/index.d.ts} +0 -0
- /package/lib/{service → esm/service}/node.js +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
Example on how to interact with network using SDK
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const index_js_1 = require("../../index.js");
|
|
10
|
+
const index_js_2 = require("../../payment_intent/provider/index.js");
|
|
11
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
12
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
13
|
+
const toProtoDecimal = (unscaled, exponent) => {
|
|
14
|
+
return (0, protobuf_1.create)(index_js_1.DecimalSchema, {
|
|
15
|
+
unscaled: BigInt(unscaled),
|
|
16
|
+
exponent: exponent,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
async function main() {
|
|
20
|
+
dotenv_1.default.config();
|
|
21
|
+
const privateKeyHex = process.env.PROVIDER_PRIVATE_KEY;
|
|
22
|
+
const endpoint = process.env.TZERO_ENDPOINT || index_js_1.DEFAULT_ENDPOINT;
|
|
23
|
+
// PayIn provider will interact with the network using the NetworkServiceClient.
|
|
24
|
+
// It will use ConfirmPayment/RejectPaymentIntent rpcs to notify the network about the payment intent status.
|
|
25
|
+
// ConfirmSettlement rpc should be used to notify the network about the settlement transfer (in case of pre-settlement).
|
|
26
|
+
const networkClient = (0, index_js_1.createClient)(privateKeyHex, endpoint, index_js_2.NetworkService);
|
|
27
|
+
// PayIn provider will also implement the ProviderServiceHandler interface
|
|
28
|
+
// which has only 2 methods:
|
|
29
|
+
// 1. CreatePaymentIntent - to create a payment intent and return the list of
|
|
30
|
+
// available payment methods along with the URL to redirect user to make the payment.
|
|
31
|
+
// 2. ConfirmPayout - to confirm the payout after the payment is completed successfully.
|
|
32
|
+
// Initialize a provider service handler using your implementation of the
|
|
33
|
+
// ProviderServiceHandler interface.
|
|
34
|
+
// The flow starts when the network call the CreatePaymentIntent method of the PayIn provider.
|
|
35
|
+
// Pay-in provider will return the list of available payment methods, and when it receives the payment from the payer,
|
|
36
|
+
// it will call the ConfirmPayout method to confirm the payout.
|
|
37
|
+
const updateResponse = await networkClient.confirmPayment({
|
|
38
|
+
paymentIntentId: 123n, // Example payment intent ID
|
|
39
|
+
paymentMethod: index_js_1.PaymentMethodType.CARD
|
|
40
|
+
});
|
|
41
|
+
// if the payment collection was not successful, the provider will call RejectPaymentIntent method to notify
|
|
42
|
+
//the network about the failure.
|
|
43
|
+
const rejectResponse = await networkClient.rejectPaymentIntent({
|
|
44
|
+
paymentIntentId: 123n, // Example payment intent ID
|
|
45
|
+
reason: 'Payment failed' // Example reason for rejection
|
|
46
|
+
});
|
|
47
|
+
// Next step would be to transfer the settlement amount to the pay-out provider, and
|
|
48
|
+
// then call the ConfirmSettlement endpoint
|
|
49
|
+
const resp = await networkClient.confirmSettlement({
|
|
50
|
+
paymentIntentId: [123n], // Example payment intent ID
|
|
51
|
+
blockchain: index_js_1.Blockchain.TRON, // Example blockchain
|
|
52
|
+
txHash: '0x123456' // Example transaction hash
|
|
53
|
+
});
|
|
54
|
+
// And the last step - ConfirmPayout rpc will be called by Network to finalize the process.
|
|
55
|
+
}
|
|
56
|
+
void main();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
/**
|
|
40
|
+
Example on how to implement network notifications with SDK
|
|
41
|
+
*/
|
|
42
|
+
const index_js_1 = require("../../payment_intent/provider/index.js");
|
|
43
|
+
const http = __importStar(require("http"));
|
|
44
|
+
const index_js_2 = require("../../index.js");
|
|
45
|
+
const index_js_3 = require("../../index.js");
|
|
46
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
47
|
+
/*
|
|
48
|
+
Providers must implement this. Please refer to docs or proto definition comments
|
|
49
|
+
*/
|
|
50
|
+
const CreatePaymentIntentProviderService = () => {
|
|
51
|
+
return {
|
|
52
|
+
async createPaymentIntent(req, context) {
|
|
53
|
+
// Implement your logic to create a payment intent
|
|
54
|
+
return {};
|
|
55
|
+
},
|
|
56
|
+
async confirmPayout(req, context) {
|
|
57
|
+
// Implement your logic to confirm a payout
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
async function main() {
|
|
63
|
+
dotenv_1.default.config();
|
|
64
|
+
const networkPublicKeyHex = process.env.TZERO_PUBLIC_KEY;
|
|
65
|
+
const server = http.createServer((0, index_js_3.signatureValidation)((0, index_js_2.nodeAdapter)((0, index_js_2.createService)(networkPublicKeyHex, r => r.service(index_js_1.ProviderService, CreatePaymentIntentProviderService()))))).listen(8080);
|
|
66
|
+
console.log("server is listening at", server.address());
|
|
67
|
+
}
|
|
68
|
+
void main();
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
Example on how to implement network notifications with SDK
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
const index_js_1 = require("../index.js");
|
|
43
|
+
const index_js_2 = require("../payment_intent/provider/index.js");
|
|
44
|
+
const http = __importStar(require("http"));
|
|
45
|
+
const index_js_3 = require("../index.js");
|
|
46
|
+
const index_js_4 = require("../index.js");
|
|
47
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
48
|
+
/*
|
|
49
|
+
Providers must implement this. Please refer to docs or proto definition comments
|
|
50
|
+
*/
|
|
51
|
+
const CreateProviderService = () => {
|
|
52
|
+
return {
|
|
53
|
+
async payOut(req, context) {
|
|
54
|
+
return {};
|
|
55
|
+
},
|
|
56
|
+
async updatePayment(req, context) {
|
|
57
|
+
return {};
|
|
58
|
+
},
|
|
59
|
+
async updateLimit(req, context) {
|
|
60
|
+
return {};
|
|
61
|
+
},
|
|
62
|
+
async appendLedgerEntries(req, context) {
|
|
63
|
+
return {};
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/*
|
|
68
|
+
Providers must implement this. Please refer to docs or proto definition comments
|
|
69
|
+
*/
|
|
70
|
+
const CreatePaymentIntentProviderService = () => {
|
|
71
|
+
return {
|
|
72
|
+
async createPaymentIntent(req, context) {
|
|
73
|
+
console.log(`${req.$typeName}`);
|
|
74
|
+
// Implement your logic to create a payment intent
|
|
75
|
+
return {};
|
|
76
|
+
},
|
|
77
|
+
async confirmPayout(req, context) {
|
|
78
|
+
console.log(`${req.$typeName}`);
|
|
79
|
+
// Implement your logic to confirm a payout
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
async function main() {
|
|
85
|
+
dotenv_1.default.config();
|
|
86
|
+
const networkPublicKeyHex = process.env.TZERO_PUBLIC_KEY;
|
|
87
|
+
const server = http.createServer((0, index_js_4.signatureValidation)((0, index_js_3.nodeAdapter)((0, index_js_1.createService)(networkPublicKeyHex, (r) => {
|
|
88
|
+
r.service(index_js_1.ProviderService, CreateProviderService());
|
|
89
|
+
r.service(index_js_2.ProviderService, CreatePaymentIntentProviderService());
|
|
90
|
+
})))).listen(8080);
|
|
91
|
+
console.log("server is listening at", server.address());
|
|
92
|
+
}
|
|
93
|
+
void main();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
Example on how to interact with network using SDK
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const index_js_1 = require("../index.js");
|
|
10
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
11
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
12
|
+
const node_crypto_1 = require("node:crypto");
|
|
13
|
+
const wkt_1 = require("@bufbuild/protobuf/wkt");
|
|
14
|
+
async function main() {
|
|
15
|
+
dotenv_1.default.config();
|
|
16
|
+
const privateKeyHex = process.env.PROVIDER_PRIVATE_KEY;
|
|
17
|
+
const endpoint = process.env.TZERO_ENDPOINT || index_js_1.DEFAULT_ENDPOINT;
|
|
18
|
+
const networkClient = (0, index_js_1.createClient)(privateKeyHex, endpoint, index_js_1.NetworkService);
|
|
19
|
+
const toProtoDecimal = (unscaled, exponent) => {
|
|
20
|
+
return (0, protobuf_1.create)(index_js_1.DecimalSchema, {
|
|
21
|
+
unscaled: BigInt(unscaled),
|
|
22
|
+
exponent: exponent,
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
// Update the quote
|
|
26
|
+
const updateResponse = await networkClient.updateQuote({
|
|
27
|
+
payIn: [{
|
|
28
|
+
bands: [{
|
|
29
|
+
rate: toProtoDecimal(123, 2), // Example rate
|
|
30
|
+
maxAmount: toProtoDecimal(1000, 0), // Example maximum amount
|
|
31
|
+
clientQuoteId: (0, node_crypto_1.randomUUID)(),
|
|
32
|
+
}],
|
|
33
|
+
currency: 'USD', // Example currency
|
|
34
|
+
expiration: (0, wkt_1.timestampFromDate)(new Date(Date.now() + 60 * 1000)), // Example expiration time (1 minute from now)
|
|
35
|
+
quoteType: index_js_1.QuoteType.REALTIME, // Example quote type
|
|
36
|
+
paymentMethod: index_js_1.PaymentMethodType.CARD,
|
|
37
|
+
timestamp: (0, wkt_1.timestampNow)(), // Current timestamp
|
|
38
|
+
}]
|
|
39
|
+
});
|
|
40
|
+
console.log('Update Quote Response:', updateResponse);
|
|
41
|
+
}
|
|
42
|
+
void main();
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.PaymentIntentRecipient = exports.PaymentIntentProvider = exports.nodeAdapter = void 0;
|
|
40
|
+
__exportStar(require("./client/client.js"), exports);
|
|
41
|
+
__exportStar(require("./service/service.js"), exports);
|
|
42
|
+
__exportStar(require("./service/node.js"), exports);
|
|
43
|
+
var connect_node_1 = require("@connectrpc/connect-node");
|
|
44
|
+
Object.defineProperty(exports, "nodeAdapter", { enumerable: true, get: function () { return connect_node_1.connectNodeAdapter; } });
|
|
45
|
+
__exportStar(require("./common/gen/tzero/v1/common/common_pb.js"), exports);
|
|
46
|
+
__exportStar(require("./common/gen/tzero/v1/common/payment_method_pb.js"), exports);
|
|
47
|
+
__exportStar(require("./common/gen/tzero/v1/payment/provider_pb.js"), exports);
|
|
48
|
+
__exportStar(require("./common/gen/tzero/v1/payment/network_pb.js"), exports);
|
|
49
|
+
exports.PaymentIntentProvider = __importStar(require("./common/gen/tzero/v1/payment_intent/provider/provider_pb.js"));
|
|
50
|
+
exports.PaymentIntentRecipient = __importStar(require("./common/gen/tzero/v1/payment_intent/recipient/recipient_pb.js"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -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/provider/provider_pb.js"), exports);
|
|
@@ -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;
|
|
@@ -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;
|