agentspay 0.1.0 → 0.2.0
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/.env.example +40 -0
- package/README.md +35 -4
- package/VERIFICATION_SUMMARY.txt +151 -0
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +530 -74
- package/dist/api/server.js.map +1 -1
- package/dist/bsv/crypto.d.ts +65 -0
- package/dist/bsv/crypto.d.ts.map +1 -0
- package/dist/bsv/crypto.js +158 -0
- package/dist/bsv/crypto.js.map +1 -0
- package/dist/bsv/mnee.d.ts +88 -0
- package/dist/bsv/mnee.d.ts.map +1 -0
- package/dist/bsv/mnee.js +173 -0
- package/dist/bsv/mnee.js.map +1 -0
- package/dist/bsv/opreturn.d.ts +22 -0
- package/dist/bsv/opreturn.d.ts.map +1 -0
- package/dist/bsv/opreturn.js +117 -0
- package/dist/bsv/opreturn.js.map +1 -0
- package/dist/bsv/whatsonchain.d.ts +46 -0
- package/dist/bsv/whatsonchain.d.ts.map +1 -0
- package/dist/bsv/whatsonchain.js +98 -0
- package/dist/bsv/whatsonchain.js.map +1 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +85 -0
- package/dist/config.js.map +1 -0
- package/dist/currency/currency.d.ts +70 -0
- package/dist/currency/currency.d.ts.map +1 -0
- package/dist/currency/currency.js +137 -0
- package/dist/currency/currency.js.map +1 -0
- package/dist/disputes/dispute.d.ts +50 -0
- package/dist/disputes/dispute.d.ts.map +1 -0
- package/dist/disputes/dispute.js +162 -0
- package/dist/disputes/dispute.js.map +1 -0
- package/dist/docs/openapi.yaml +1079 -0
- package/dist/docs/swagger.d.ts +12 -0
- package/dist/docs/swagger.d.ts.map +1 -0
- package/dist/docs/swagger.js +104 -0
- package/dist/docs/swagger.js.map +1 -0
- package/dist/middleware/auth.d.ts +20 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +32 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware/rateLimit.d.ts +25 -0
- package/dist/middleware/rateLimit.d.ts.map +1 -0
- package/dist/middleware/rateLimit.js +61 -0
- package/dist/middleware/rateLimit.js.map +1 -0
- package/dist/payment/payment.d.ts +79 -9
- package/dist/payment/payment.d.ts.map +1 -1
- package/dist/payment/payment.js +387 -47
- package/dist/payment/payment.js.map +1 -1
- package/dist/registry/db.d.ts.map +1 -1
- package/dist/registry/db.js +110 -3
- package/dist/registry/db.js.map +1 -1
- package/dist/registry/registry.d.ts +1 -1
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +12 -4
- package/dist/registry/registry.js.map +1 -1
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/validation.d.ts +27 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +164 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/verification/receipt.d.ts +42 -0
- package/dist/verification/receipt.d.ts.map +1 -0
- package/dist/verification/receipt.js +10 -0
- package/dist/verification/receipt.js.map +1 -0
- package/dist/verification/verification.d.ts +41 -0
- package/dist/verification/verification.d.ts.map +1 -0
- package/dist/verification/verification.js +217 -0
- package/dist/verification/verification.js.map +1 -0
- package/dist/wallet/providerManager.d.ts +32 -0
- package/dist/wallet/providerManager.d.ts.map +1 -0
- package/dist/wallet/providerManager.js +118 -0
- package/dist/wallet/providerManager.js.map +1 -0
- package/dist/wallet/providers/handcash.d.ts +22 -0
- package/dist/wallet/providers/handcash.d.ts.map +1 -0
- package/dist/wallet/providers/handcash.js +214 -0
- package/dist/wallet/providers/handcash.js.map +1 -0
- package/dist/wallet/providers/internal.d.ts +15 -0
- package/dist/wallet/providers/internal.d.ts.map +1 -0
- package/dist/wallet/providers/internal.js +208 -0
- package/dist/wallet/providers/internal.js.map +1 -0
- package/dist/wallet/providers/types.d.ts +50 -0
- package/dist/wallet/providers/types.d.ts.map +1 -0
- package/dist/wallet/providers/types.js +6 -0
- package/dist/wallet/providers/types.js.map +1 -0
- package/dist/wallet/providers/yours.d.ts +18 -0
- package/dist/wallet/providers/yours.d.ts.map +1 -0
- package/dist/wallet/providers/yours.js +122 -0
- package/dist/wallet/providers/yours.js.map +1 -0
- package/dist/wallet/wallet.d.ts +52 -5
- package/dist/wallet/wallet.d.ts.map +1 -1
- package/dist/wallet/wallet.js +223 -34
- package/dist/wallet/wallet.js.map +1 -1
- package/dist/webhooks/delivery.d.ts +37 -0
- package/dist/webhooks/delivery.d.ts.map +1 -0
- package/dist/webhooks/delivery.js +182 -0
- package/dist/webhooks/delivery.js.map +1 -0
- package/dist/webhooks/webhook.d.ts +85 -0
- package/dist/webhooks/webhook.d.ts.map +1 -0
- package/dist/webhooks/webhook.js +271 -0
- package/dist/webhooks/webhook.js.map +1 -0
- package/package.json +74 -54
- package/sdk-python/LICENSE +21 -0
- package/sdk-python/MANIFEST.in +9 -0
- package/sdk-python/README.md +372 -0
- package/sdk-python/agentspay/__init__.py +97 -0
- package/sdk-python/agentspay/client.py +256 -0
- package/sdk-python/agentspay/disputes.py +174 -0
- package/sdk-python/agentspay/exceptions.py +53 -0
- package/sdk-python/agentspay/payments.py +169 -0
- package/sdk-python/agentspay/services.py +198 -0
- package/sdk-python/agentspay/types.py +154 -0
- package/sdk-python/agentspay/wallet.py +113 -0
- package/sdk-python/agentspay/webhooks.py +195 -0
- package/sdk-python/examples/consumer.py +147 -0
- package/sdk-python/examples/provider.py +116 -0
- package/sdk-python/pyproject.toml +61 -0
- package/sdk-python/setup.py +53 -0
- package/sdk-python/tests/test_client.py +221 -0
- package/test-addr.js +29 -0
- package/test-mnee-simple.js +51 -0
- package/test-mnee.js +47 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swagger/OpenAPI Documentation Setup
|
|
3
|
+
*
|
|
4
|
+
* Mounts interactive Swagger UI at /docs
|
|
5
|
+
*/
|
|
6
|
+
import { Express } from 'express';
|
|
7
|
+
/**
|
|
8
|
+
* Setup Swagger UI middleware
|
|
9
|
+
* Mounts at /docs (publicly accessible, no auth required)
|
|
10
|
+
*/
|
|
11
|
+
export declare function setupSwagger(app: Express): void;
|
|
12
|
+
//# sourceMappingURL=swagger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger.d.ts","sourceRoot":"","sources":["../../src/docs/swagger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAoBjC;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CA6C/C"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Swagger/OpenAPI Documentation Setup
|
|
4
|
+
*
|
|
5
|
+
* Mounts interactive Swagger UI at /docs
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.setupSwagger = setupSwagger;
|
|
45
|
+
const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
const yaml = __importStar(require("js-yaml"));
|
|
49
|
+
const OPENAPI_SPEC_PATH = path.join(__dirname, 'openapi.yaml');
|
|
50
|
+
/**
|
|
51
|
+
* Load OpenAPI spec from YAML file
|
|
52
|
+
*/
|
|
53
|
+
function loadOpenApiSpec() {
|
|
54
|
+
try {
|
|
55
|
+
const fileContents = fs.readFileSync(OPENAPI_SPEC_PATH, 'utf8');
|
|
56
|
+
return yaml.load(fileContents);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('Failed to load OpenAPI spec:', error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Setup Swagger UI middleware
|
|
65
|
+
* Mounts at /docs (publicly accessible, no auth required)
|
|
66
|
+
*/
|
|
67
|
+
function setupSwagger(app) {
|
|
68
|
+
const swaggerSpec = loadOpenApiSpec();
|
|
69
|
+
// Serve raw spec at /docs/openapi.json and /docs/openapi.yaml
|
|
70
|
+
// MUST be registered BEFORE Swagger UI middleware
|
|
71
|
+
app.get('/docs/openapi.json', (_req, res) => {
|
|
72
|
+
res.setHeader('Content-Type', 'application/json');
|
|
73
|
+
res.send(JSON.stringify(swaggerSpec, null, 2));
|
|
74
|
+
});
|
|
75
|
+
app.get('/docs/openapi.yaml', (_req, res) => {
|
|
76
|
+
res.setHeader('Content-Type', 'text/yaml');
|
|
77
|
+
res.sendFile(OPENAPI_SPEC_PATH);
|
|
78
|
+
});
|
|
79
|
+
// Swagger UI options
|
|
80
|
+
const swaggerUiOptions = {
|
|
81
|
+
customCss: `
|
|
82
|
+
.swagger-ui .topbar { display: none }
|
|
83
|
+
.swagger-ui .info .title { font-size: 2.5em; }
|
|
84
|
+
.swagger-ui .scheme-container { background: #fafafa; padding: 1em; }
|
|
85
|
+
`,
|
|
86
|
+
customSiteTitle: 'AgentPay API Documentation',
|
|
87
|
+
customfavIcon: '/favicon.ico',
|
|
88
|
+
swaggerOptions: {
|
|
89
|
+
persistAuthorization: true,
|
|
90
|
+
displayRequestDuration: true,
|
|
91
|
+
filter: true,
|
|
92
|
+
syntaxHighlight: {
|
|
93
|
+
activate: true,
|
|
94
|
+
theme: 'monokai',
|
|
95
|
+
},
|
|
96
|
+
tryItOutEnabled: true,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
// Mount Swagger UI at /docs
|
|
100
|
+
app.use('/docs', swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(swaggerSpec, swaggerUiOptions));
|
|
101
|
+
console.log('📚 Swagger UI available at /docs');
|
|
102
|
+
console.log('📄 OpenAPI spec: /docs/openapi.json | /docs/openapi.yaml');
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=swagger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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IACrB,MAAM,gBAAgB,GAA+B;QACnD,SAAS,EAAE;;;;KAIV;QACD,eAAe,EAAE,4BAA4B;QAC7C,aAAa,EAAE,cAAc;QAC7B,cAAc,EAAE;YACd,oBAAoB,EAAE,IAAI;YAC1B,sBAAsB,EAAE,IAAI;YAC5B,MAAM,EAAE,IAAI;YACZ,eAAe,EAAE;gBACf,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE,SAAS;aACjB;YACD,eAAe,EAAE,IAAI;SACtB;KACF,CAAA;IAED,4BAA4B;IAC5B,GAAG,CAAC,GAAG,CACL,OAAO,EACP,4BAAS,CAAC,KAAK,EACf,4BAAS,CAAC,KAAK,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAC/C,CAAA;IAED,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAA;IAC/C,OAAO,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAA;AACzE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Middleware
|
|
3
|
+
*
|
|
4
|
+
* Handles API key generation and validation for wallet authentication.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Generate a secure random API key
|
|
8
|
+
* Returns a hex string (64 characters)
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateApiKey(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Hash an API key for storage
|
|
13
|
+
* Uses SHA-256 to create a one-way hash
|
|
14
|
+
*/
|
|
15
|
+
export declare function hashApiKey(apiKey: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Verify an API key against its hash
|
|
18
|
+
*/
|
|
19
|
+
export declare function verifyApiKey(apiKey: string, hash: string): boolean;
|
|
20
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAElE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication Middleware
|
|
4
|
+
*
|
|
5
|
+
* Handles API key generation and validation for wallet authentication.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.generateApiKey = generateApiKey;
|
|
9
|
+
exports.hashApiKey = hashApiKey;
|
|
10
|
+
exports.verifyApiKey = verifyApiKey;
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
/**
|
|
13
|
+
* Generate a secure random API key
|
|
14
|
+
* Returns a hex string (64 characters)
|
|
15
|
+
*/
|
|
16
|
+
function generateApiKey() {
|
|
17
|
+
return (0, crypto_1.randomBytes)(32).toString('hex');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Hash an API key for storage
|
|
21
|
+
* Uses SHA-256 to create a one-way hash
|
|
22
|
+
*/
|
|
23
|
+
function hashApiKey(apiKey) {
|
|
24
|
+
return (0, crypto_1.createHash)('sha256').update(apiKey).digest('hex');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Verify an API key against its hash
|
|
28
|
+
*/
|
|
29
|
+
function verifyApiKey(apiKey, hash) {
|
|
30
|
+
return hashApiKey(apiKey) === hash;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAQH,wCAEC;AAMD,gCAEC;AAKD,oCAEC;AAvBD,mCAAgD;AAEhD;;;GAGG;AACH,SAAgB,cAAc;IAC5B,OAAO,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAED;;;GAGG;AACH,SAAgB,UAAU,CAAC,MAAc;IACvC,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC1D,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,MAAc,EAAE,IAAY;IACvD,OAAO,UAAU,CAAC,MAAM,CAAC,KAAK,IAAI,CAAA;AACpC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate Limiting Middleware
|
|
3
|
+
* Prevents abuse and DoS attacks
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Global rate limit (all endpoints)
|
|
7
|
+
*/
|
|
8
|
+
export declare const globalLimiter: import("express-rate-limit").RateLimitRequestHandler;
|
|
9
|
+
/**
|
|
10
|
+
* Strict limit for wallet creation
|
|
11
|
+
*/
|
|
12
|
+
export declare const walletCreationLimiter: import("express-rate-limit").RateLimitRequestHandler;
|
|
13
|
+
/**
|
|
14
|
+
* Service registration limit
|
|
15
|
+
*/
|
|
16
|
+
export declare const serviceRegistrationLimiter: import("express-rate-limit").RateLimitRequestHandler;
|
|
17
|
+
/**
|
|
18
|
+
* Execution limit (prevent spam)
|
|
19
|
+
*/
|
|
20
|
+
export declare const executionLimiter: import("express-rate-limit").RateLimitRequestHandler;
|
|
21
|
+
/**
|
|
22
|
+
* Funding limit (testnet/demo only)
|
|
23
|
+
*/
|
|
24
|
+
export declare const fundingLimiter: import("express-rate-limit").RateLimitRequestHandler;
|
|
25
|
+
//# sourceMappingURL=rateLimit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateLimit.d.ts","sourceRoot":"","sources":["../../src/middleware/rateLimit.ts"],"names":[],"mappings":"AAGA;;;GAGG;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,sDAOxB,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,sDAMhC,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,0BAA0B,sDAKrC,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,sDAK3B,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,sDAKzB,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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.fundingLimiter = exports.executionLimiter = exports.serviceRegistrationLimiter = exports.walletCreationLimiter = exports.globalLimiter = void 0;
|
|
7
|
+
const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
|
|
8
|
+
const config_1 = require("../config");
|
|
9
|
+
/**
|
|
10
|
+
* Rate Limiting Middleware
|
|
11
|
+
* Prevents abuse and DoS attacks
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Global rate limit (all endpoints)
|
|
15
|
+
*/
|
|
16
|
+
exports.globalLimiter = (0, express_rate_limit_1.default)({
|
|
17
|
+
windowMs: 60 * 1000, // 1 minute
|
|
18
|
+
max: config_1.config.demoMode ? 1000 : 100, // 100 requests per minute (1000 in demo)
|
|
19
|
+
message: { error: 'Too many requests, please try again later' },
|
|
20
|
+
standardHeaders: true,
|
|
21
|
+
legacyHeaders: false,
|
|
22
|
+
skip: () => config_1.config.demoMode && config_1.config.demoSkipAuth, // Skip in full demo mode
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Strict limit for wallet creation
|
|
26
|
+
*/
|
|
27
|
+
exports.walletCreationLimiter = (0, express_rate_limit_1.default)({
|
|
28
|
+
windowMs: 60 * 60 * 1000, // 1 hour
|
|
29
|
+
max: config_1.config.demoMode ? 100 : 5, // 5 wallets per IP per hour (100 in demo)
|
|
30
|
+
message: { error: 'Wallet creation limit reached. Try again in 1 hour.' },
|
|
31
|
+
skipSuccessfulRequests: false,
|
|
32
|
+
skip: () => config_1.config.demoMode && config_1.config.demoSkipAuth,
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Service registration limit
|
|
36
|
+
*/
|
|
37
|
+
exports.serviceRegistrationLimiter = (0, express_rate_limit_1.default)({
|
|
38
|
+
windowMs: 60 * 60 * 1000, // 1 hour
|
|
39
|
+
max: config_1.config.demoMode ? 100 : 10, // 10 services per IP per hour (100 in demo)
|
|
40
|
+
message: { error: 'Service registration limit reached. Try again in 1 hour.' },
|
|
41
|
+
skip: () => config_1.config.demoMode && config_1.config.demoSkipAuth,
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Execution limit (prevent spam)
|
|
45
|
+
*/
|
|
46
|
+
exports.executionLimiter = (0, express_rate_limit_1.default)({
|
|
47
|
+
windowMs: 60 * 1000, // 1 minute
|
|
48
|
+
max: config_1.config.demoMode ? 100 : 30, // 30 executions per minute (100 in demo)
|
|
49
|
+
message: { error: 'Too many execution requests. Slow down.' },
|
|
50
|
+
skip: () => config_1.config.demoMode && config_1.config.demoSkipAuth,
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Funding limit (testnet/demo only)
|
|
54
|
+
*/
|
|
55
|
+
exports.fundingLimiter = (0, express_rate_limit_1.default)({
|
|
56
|
+
windowMs: 60 * 60 * 1000, // 1 hour
|
|
57
|
+
max: config_1.config.demoMode ? 100 : 10, // 10 funding requests per hour
|
|
58
|
+
message: { error: 'Funding limit reached. Try again in 1 hour.' },
|
|
59
|
+
skip: () => config_1.config.demoMode && config_1.config.demoSkipAuth,
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=rateLimit.js.map
|
|
@@ -0,0 +1 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E,IAAI,EAAE,GAAG,EAAE,CAAC,eAAM,CAAC,QAAQ,IAAI,eAAM,CAAC,YAAY;CACnD,CAAC,CAAA;AAEF;;GAEG;AACU,QAAA,gBAAgB,GAAG,IAAA,4BAAS,EAAC;IACxC,QAAQ,EAAE,EAAE,GAAG,IAAI,EAAE,WAAW;IAChC,GAAG,EAAE,eAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,yCAAyC;IAC1E,OAAO,EAAE,EAAE,KAAK,EAAE,yCAAyC,EAAE;IAC7D,IAAI,EAAE,GAAG,EAAE,CAAC,eAAM,CAAC,QAAQ,IAAI,eAAM,CAAC,YAAY;CACnD,CAAC,CAAA;AAEF;;GAEG;AACU,QAAA,cAAc,GAAG,IAAA,4BAAS,EAAC;IACtC,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,SAAS;IACnC,GAAG,EAAE,eAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,+BAA+B;IAChE,OAAO,EAAE,EAAE,KAAK,EAAE,6CAA6C,EAAE;IACjE,IAAI,EAAE,GAAG,EAAE,CAAC,eAAM,CAAC,QAAQ,IAAI,eAAM,CAAC,YAAY;CACnD,CAAC,CAAA"}
|
|
@@ -1,22 +1,92 @@
|
|
|
1
|
-
import type { Payment } from '../types';
|
|
1
|
+
import type { Payment, Currency } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
* Payment Engine
|
|
3
|
+
* Payment Engine with Multi-Currency Support
|
|
4
|
+
*
|
|
5
|
+
* Supports:
|
|
6
|
+
* - BSV (satoshis) - Native blockchain currency
|
|
7
|
+
* - MNEE (USD cents) - 1Sat Ordinals BSV-21 stablecoin token
|
|
4
8
|
*
|
|
5
9
|
* Flow:
|
|
6
10
|
* 1. Buyer requests execution → payment created as 'pending'
|
|
7
|
-
* 2.
|
|
8
|
-
* 3. Service executed successfully →
|
|
9
|
-
* 4. Service fails →
|
|
11
|
+
* 2. Buyer sends funds to platform escrow wallet → 'escrowed'
|
|
12
|
+
* 3. Service executed successfully → platform sends to seller → 'released'
|
|
13
|
+
* 4. Service fails → platform refunds buyer → 'refunded'
|
|
10
14
|
* 5. Dispute → 'disputed' (manual resolution)
|
|
11
15
|
*
|
|
12
|
-
* MVP:
|
|
16
|
+
* MVP: Platform escrow (centralized). Funds go to platform wallet temporarily.
|
|
17
|
+
* Future: Implement hashlock (HTLC) or 2-of-3 multisig for trustless escrow.
|
|
13
18
|
*/
|
|
14
19
|
export declare class PaymentEngine {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
private wallets;
|
|
21
|
+
/**
|
|
22
|
+
* Create a payment (escrow funds)
|
|
23
|
+
* Supports both BSV (satoshis) and MNEE (USD cents)
|
|
24
|
+
*/
|
|
25
|
+
create(serviceId: string, buyerWalletId: string, sellerWalletId: string, amount: number, currency?: Currency): Promise<Payment>;
|
|
26
|
+
/**
|
|
27
|
+
* Create BSV payment (on-chain)
|
|
28
|
+
*/
|
|
29
|
+
private createBsvPayment;
|
|
30
|
+
/**
|
|
31
|
+
* Create MNEE payment (token transfer)
|
|
32
|
+
*/
|
|
33
|
+
private createMneePayment;
|
|
34
|
+
/**
|
|
35
|
+
* Release payment (service completed successfully)
|
|
36
|
+
* Platform sends escrowed funds to seller
|
|
37
|
+
*
|
|
38
|
+
* ⚠️ SECURITY: Internal use only. Not exposed via API.
|
|
39
|
+
* Only callable from execute flow.
|
|
40
|
+
*/
|
|
41
|
+
release(paymentId: string): Promise<Payment | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Release BSV payment
|
|
44
|
+
*/
|
|
45
|
+
private releaseBsvPayment;
|
|
46
|
+
/**
|
|
47
|
+
* Release MNEE payment
|
|
48
|
+
*/
|
|
49
|
+
private releaseMneePayment;
|
|
50
|
+
/**
|
|
51
|
+
* Refund payment (service failed)
|
|
52
|
+
* Platform returns escrowed funds to buyer
|
|
53
|
+
*
|
|
54
|
+
* ⚠️ SECURITY: Internal use only. Not exposed via API.
|
|
55
|
+
* Only callable from execute flow.
|
|
56
|
+
*/
|
|
57
|
+
refund(paymentId: string): Promise<Payment | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Refund BSV payment
|
|
60
|
+
*/
|
|
61
|
+
private refundBsvPayment;
|
|
62
|
+
/**
|
|
63
|
+
* Refund MNEE payment
|
|
64
|
+
*/
|
|
65
|
+
private refundMneePayment;
|
|
66
|
+
/**
|
|
67
|
+
* Dispute payment
|
|
68
|
+
*/
|
|
18
69
|
dispute(paymentId: string): Payment | null;
|
|
70
|
+
/**
|
|
71
|
+
* Get payment by ID
|
|
72
|
+
*/
|
|
19
73
|
getById(id: string): Payment | null;
|
|
74
|
+
/**
|
|
75
|
+
* Get payments for a wallet
|
|
76
|
+
*/
|
|
20
77
|
getByWallet(walletId: string, role?: 'buyer' | 'seller' | 'both'): Payment[];
|
|
78
|
+
private waitForUtxos;
|
|
79
|
+
/**
|
|
80
|
+
* Get or create platform escrow wallet
|
|
81
|
+
*/
|
|
82
|
+
private getOrCreatePlatformWallet;
|
|
83
|
+
/**
|
|
84
|
+
* Get platform escrow address
|
|
85
|
+
*/
|
|
86
|
+
private getPlatformEscrowAddress;
|
|
87
|
+
/**
|
|
88
|
+
* Get platform private key (SECURE THIS!)
|
|
89
|
+
*/
|
|
90
|
+
private getPlatformPrivateKey;
|
|
21
91
|
}
|
|
22
92
|
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../src/payment/payment.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../src/payment/payment.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAS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