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,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSV OP_RETURN Transaction Builder
|
|
4
|
+
*
|
|
5
|
+
* Anchors receipt hashes to the BSV blockchain via OP_RETURN.
|
|
6
|
+
* Creates an immutable, timestamped proof of execution.
|
|
7
|
+
*
|
|
8
|
+
* Cost: ~1 satoshi per anchor
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.anchorReceiptHash = anchorReceiptHash;
|
|
12
|
+
exports.verifyAnchor = verifyAnchor;
|
|
13
|
+
const sdk_1 = require("@bsv/sdk");
|
|
14
|
+
const whatsonchain_1 = require("./whatsonchain");
|
|
15
|
+
const config_1 = require("../config");
|
|
16
|
+
/**
|
|
17
|
+
* Anchor a receipt hash to BSV blockchain via OP_RETURN
|
|
18
|
+
*/
|
|
19
|
+
async function anchorReceiptHash(receiptHash, privateKeyWif, sourceAddress) {
|
|
20
|
+
if (config_1.config.demoMode) {
|
|
21
|
+
// Demo mode: return fake txid
|
|
22
|
+
return {
|
|
23
|
+
txId: `demo-anchor-${receiptHash.slice(0, 8)}`,
|
|
24
|
+
receiptHash,
|
|
25
|
+
cost: 1,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// Get UTXOs for funding
|
|
29
|
+
const utxos = await (0, whatsonchain_1.getUtxos)(sourceAddress);
|
|
30
|
+
if (utxos.length === 0) {
|
|
31
|
+
throw new Error('No UTXOs available for anchoring');
|
|
32
|
+
}
|
|
33
|
+
const totalInput = utxos.reduce((sum, u) => sum + u.value, 0);
|
|
34
|
+
if (totalInput < 1000) {
|
|
35
|
+
throw new Error('Insufficient funds for anchoring (need at least 1000 sats)');
|
|
36
|
+
}
|
|
37
|
+
// Create OP_RETURN script with receipt hash
|
|
38
|
+
const opReturnScript = sdk_1.Script.fromASM(`OP_FALSE OP_RETURN ${Buffer.from(receiptHash, 'hex').toString('hex')}`);
|
|
39
|
+
// Build transaction
|
|
40
|
+
const privKey = sdk_1.PrivateKey.fromWif(privateKeyWif);
|
|
41
|
+
const tx = new sdk_1.Transaction();
|
|
42
|
+
// Add inputs
|
|
43
|
+
for (const utxo of utxos) {
|
|
44
|
+
tx.addInput({
|
|
45
|
+
sourceTXID: utxo.tx_hash,
|
|
46
|
+
sourceOutputIndex: utxo.tx_pos,
|
|
47
|
+
unlockingScriptTemplate: new sdk_1.P2PKH().unlock(privKey),
|
|
48
|
+
sequence: 0xffffffff,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// Add OP_RETURN output (0 satoshis)
|
|
52
|
+
tx.addOutput({
|
|
53
|
+
lockingScript: opReturnScript,
|
|
54
|
+
change: false,
|
|
55
|
+
satoshis: 0,
|
|
56
|
+
});
|
|
57
|
+
// Add change output
|
|
58
|
+
tx.addOutput({
|
|
59
|
+
lockingScript: new sdk_1.P2PKH().lock(sourceAddress),
|
|
60
|
+
change: true,
|
|
61
|
+
});
|
|
62
|
+
// Sign transaction
|
|
63
|
+
await tx.fee();
|
|
64
|
+
await tx.sign();
|
|
65
|
+
// Broadcast
|
|
66
|
+
const txHex = tx.toHex();
|
|
67
|
+
const txId = await (0, whatsonchain_1.broadcastTx)(txHex);
|
|
68
|
+
// Calculate actual cost (input - change)
|
|
69
|
+
const outputs = tx.outputs || [];
|
|
70
|
+
const changeOutput = outputs.find(o => o.change);
|
|
71
|
+
const changeAmount = changeOutput?.satoshis || 0;
|
|
72
|
+
const cost = totalInput - changeAmount;
|
|
73
|
+
return {
|
|
74
|
+
txId,
|
|
75
|
+
receiptHash,
|
|
76
|
+
cost,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Verify that a receipt hash exists in a BSV transaction's OP_RETURN
|
|
81
|
+
*/
|
|
82
|
+
async function verifyAnchor(txId, expectedHash) {
|
|
83
|
+
try {
|
|
84
|
+
// Fetch transaction from blockchain
|
|
85
|
+
const response = await fetch(`https://api.whatsonchain.com/v1/bsv/main/tx/${txId}/hex`);
|
|
86
|
+
if (!response.ok)
|
|
87
|
+
return false;
|
|
88
|
+
const txHex = await response.text();
|
|
89
|
+
const tx = sdk_1.Transaction.fromHex(txHex);
|
|
90
|
+
// Look for OP_RETURN output with our hash
|
|
91
|
+
const outputs = tx.outputs || [];
|
|
92
|
+
for (const output of outputs) {
|
|
93
|
+
const script = output.lockingScript;
|
|
94
|
+
if (!script)
|
|
95
|
+
continue;
|
|
96
|
+
const asm = script.toASM();
|
|
97
|
+
if (asm.includes('OP_RETURN')) {
|
|
98
|
+
// Extract data after OP_RETURN
|
|
99
|
+
const parts = asm.split(' ');
|
|
100
|
+
const returnIndex = parts.indexOf('OP_RETURN');
|
|
101
|
+
if (returnIndex !== -1 && parts.length > returnIndex + 1) {
|
|
102
|
+
const data = parts[returnIndex + 1];
|
|
103
|
+
const hashFromTx = Buffer.from(data, 'hex').toString('hex');
|
|
104
|
+
if (hashFromTx === expectedHash) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error('Error verifying anchor:', error);
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=opreturn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opreturn.js","sourceRoot":"","sources":["../../src/bsv/opreturn.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAeH,8CA0EC;AAKD,oCAmCC;AA/HD,kCAAiE;AACjE,iDAAsD;AACtD,sCAAkC;AAQlC;;GAEG;AACI,KAAK,UAAU,iBAAiB,CACrC,WAAmB,EACnB,aAAqB,EACrB,aAAqB;IAErB,IAAI,eAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,8BAA8B;QAC9B,OAAO;YACL,IAAI,EAAE,eAAe,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;YAC9C,WAAW;YACX,IAAI,EAAE,CAAC;SACR,CAAA;IACH,CAAC;IAED,wBAAwB;IACxB,MAAM,KAAK,GAAG,MAAM,IAAA,uBA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,KAAK,EAAE,CAAA;YAC1B,IAAI,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC9B,+BAA+B;gBAC/B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBAC5B,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;gBAC9C,IAAI,WAAW,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,WAAW,GAAG,CAAC,EAAE,CAAC;oBACzD,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAA;oBACnC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;oBAC3D,IAAI,UAAU,KAAK,YAAY,EAAE,CAAC;wBAChC,OAAO,IAAI,CAAA;oBACb,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAA;QAC/C,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WhatsOnChain API Client
|
|
3
|
+
*
|
|
4
|
+
* Provides methods to interact with the BSV blockchain via WhatsOnChain API.
|
|
5
|
+
* Free tier: rate limited but sufficient for MVP.
|
|
6
|
+
*/
|
|
7
|
+
export interface WOCBalance {
|
|
8
|
+
confirmed: number;
|
|
9
|
+
unconfirmed: number;
|
|
10
|
+
}
|
|
11
|
+
export interface WOCUTXO {
|
|
12
|
+
tx_hash: string;
|
|
13
|
+
tx_pos: number;
|
|
14
|
+
value: number;
|
|
15
|
+
height: number;
|
|
16
|
+
}
|
|
17
|
+
export interface WOCTxHistory {
|
|
18
|
+
tx_hash: string;
|
|
19
|
+
height: number;
|
|
20
|
+
time?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get balance for an address
|
|
24
|
+
*/
|
|
25
|
+
export declare function getBalance(address: string): Promise<WOCBalance>;
|
|
26
|
+
/**
|
|
27
|
+
* Get UTXOs for an address
|
|
28
|
+
*/
|
|
29
|
+
export declare function getUtxos(address: string): Promise<WOCUTXO[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Get transaction history for an address
|
|
32
|
+
*/
|
|
33
|
+
export declare function getTxHistory(address: string): Promise<WOCTxHistory[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Get transaction details
|
|
36
|
+
*/
|
|
37
|
+
export declare function getTxDetails(txid: string): Promise<any>;
|
|
38
|
+
/**
|
|
39
|
+
* Broadcast a raw transaction
|
|
40
|
+
*/
|
|
41
|
+
export declare function broadcastTx(txHex: string): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Get script for a transaction output
|
|
44
|
+
*/
|
|
45
|
+
export declare function getTxOutScript(txid: string, vout: number): Promise<string>;
|
|
46
|
+
//# sourceMappingURL=whatsonchain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whatsonchain.d.ts","sourceRoot":"","sources":["../../src/bsv/whatsonchain.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAUrE;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAUlE;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAU3E;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAM7D;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiBhE;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMhF"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* WhatsOnChain API Client
|
|
4
|
+
*
|
|
5
|
+
* Provides methods to interact with the BSV blockchain via WhatsOnChain API.
|
|
6
|
+
* Free tier: rate limited but sufficient for MVP.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getBalance = getBalance;
|
|
10
|
+
exports.getUtxos = getUtxos;
|
|
11
|
+
exports.getTxHistory = getTxHistory;
|
|
12
|
+
exports.getTxDetails = getTxDetails;
|
|
13
|
+
exports.broadcastTx = broadcastTx;
|
|
14
|
+
exports.getTxOutScript = getTxOutScript;
|
|
15
|
+
const config_1 = require("../config");
|
|
16
|
+
const BASE_URL = config_1.config.whatsOnChainBase;
|
|
17
|
+
/**
|
|
18
|
+
* Get balance for an address
|
|
19
|
+
*/
|
|
20
|
+
async function getBalance(address) {
|
|
21
|
+
const response = await fetch(`${BASE_URL}/address/${address}/balance`);
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new Error(`WhatsOnChain API error: ${response.statusText}`);
|
|
24
|
+
}
|
|
25
|
+
const data = await response.json();
|
|
26
|
+
return {
|
|
27
|
+
confirmed: data.confirmed || 0,
|
|
28
|
+
unconfirmed: data.unconfirmed || 0,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get UTXOs for an address
|
|
33
|
+
*/
|
|
34
|
+
async function getUtxos(address) {
|
|
35
|
+
const response = await fetch(`${BASE_URL}/address/${address}/unspent`);
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
if (response.status === 404) {
|
|
38
|
+
return []; // No UTXOs
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`WhatsOnChain API error: ${response.statusText}`);
|
|
41
|
+
}
|
|
42
|
+
const data = await response.json();
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get transaction history for an address
|
|
47
|
+
*/
|
|
48
|
+
async function getTxHistory(address) {
|
|
49
|
+
const response = await fetch(`${BASE_URL}/address/${address}/history`);
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
if (response.status === 404) {
|
|
52
|
+
return []; // No history
|
|
53
|
+
}
|
|
54
|
+
throw new Error(`WhatsOnChain API error: ${response.statusText}`);
|
|
55
|
+
}
|
|
56
|
+
const data = await response.json();
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get transaction details
|
|
61
|
+
*/
|
|
62
|
+
async function getTxDetails(txid) {
|
|
63
|
+
const response = await fetch(`${BASE_URL}/tx/${txid}`);
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
throw new Error(`WhatsOnChain API error: ${response.statusText}`);
|
|
66
|
+
}
|
|
67
|
+
return response.json();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Broadcast a raw transaction
|
|
71
|
+
*/
|
|
72
|
+
async function broadcastTx(txHex) {
|
|
73
|
+
const response = await fetch(`${BASE_URL}/tx/raw`, {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
headers: {
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify({ txhex: txHex }),
|
|
79
|
+
});
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
const error = await response.text();
|
|
82
|
+
throw new Error(`Transaction broadcast failed: ${error}`);
|
|
83
|
+
}
|
|
84
|
+
// WhatsOnChain returns the txid on success
|
|
85
|
+
const txid = await response.text();
|
|
86
|
+
return txid.replace(/"/g, ''); // Remove quotes if present
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get script for a transaction output
|
|
90
|
+
*/
|
|
91
|
+
async function getTxOutScript(txid, vout) {
|
|
92
|
+
const tx = await getTxDetails(txid);
|
|
93
|
+
if (!tx.vout || !tx.vout[vout]) {
|
|
94
|
+
throw new Error(`Output ${vout} not found in transaction ${txid}`);
|
|
95
|
+
}
|
|
96
|
+
return tx.vout[vout].scriptPubKey.hex;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=whatsonchain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whatsonchain.js","sourceRoot":"","sources":["../../src/bsv/whatsonchain.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA2BH,gCAUC;AAKD,4BAUC;AAKD,oCAUC;AAKD,oCAMC;AAKD,kCAiBC;AAKD,wCAMC;AA7GD,sCAAkC;AAElC,MAAM,QAAQ,GAAG,eAAM,CAAC,gBAAgB,CAAA;AAoBxC;;GAEG;AACI,KAAK,UAAU,UAAU,CAAC,OAAe;IAC9C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,QAAQ,YAAY,OAAO,UAAU,CAAC,CAAA;IACtE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAA;IACnE,CAAC;IACD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C,GAAG,CAAA;AACvC,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentPay Configuration
|
|
3
|
+
*
|
|
4
|
+
* Controls network settings, API endpoints, and platform parameters.
|
|
5
|
+
*/
|
|
6
|
+
export declare const config: {
|
|
7
|
+
network: "mainnet" | "testnet";
|
|
8
|
+
whatsOnChainBase: string;
|
|
9
|
+
explorerBase: string;
|
|
10
|
+
platformFeeRate: number;
|
|
11
|
+
escrowMode: "platform" | "multisig";
|
|
12
|
+
demoMode: boolean;
|
|
13
|
+
demoSkipAuth: boolean;
|
|
14
|
+
feePerByte: number;
|
|
15
|
+
encryption: {
|
|
16
|
+
algorithm: "aes-256-gcm";
|
|
17
|
+
masterKey: string;
|
|
18
|
+
};
|
|
19
|
+
platformWallet: {
|
|
20
|
+
privateKey: string | undefined;
|
|
21
|
+
address: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
handcash: {
|
|
24
|
+
appId: string;
|
|
25
|
+
appSecret: string;
|
|
26
|
+
redirectUrl: string;
|
|
27
|
+
};
|
|
28
|
+
frontendUrl: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Get the appropriate network prefix for P2PKH addresses
|
|
32
|
+
*/
|
|
33
|
+
export declare function getAddressPrefix(): number;
|
|
34
|
+
/**
|
|
35
|
+
* Get WhatsOnChain URL for a transaction
|
|
36
|
+
*/
|
|
37
|
+
export declare function getTxUrl(txId: string): string;
|
|
38
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAuBH,eAAO,MAAM,MAAM;aAEkC,SAAS,GAAG,SAAS;;;;gBAgB9C,UAAU,GAAG,UAAU;;;;;;;;;;;;;;;;;;CAoClD,CAAA;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AgentPay Configuration
|
|
4
|
+
*
|
|
5
|
+
* Controls network settings, API endpoints, and platform parameters.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.config = void 0;
|
|
9
|
+
exports.getAddressPrefix = getAddressPrefix;
|
|
10
|
+
exports.getTxUrl = getTxUrl;
|
|
11
|
+
// Demo mode check
|
|
12
|
+
const isDemoMode = process.env.AGENTPAY_DEMO === 'true' || process.env.AGENTPAY_DEMO === '1';
|
|
13
|
+
// CRITICAL: Enforce master key in production
|
|
14
|
+
if (!isDemoMode) {
|
|
15
|
+
if (!process.env.AGENTPAY_MASTER_KEY) {
|
|
16
|
+
console.error('❌ FATAL ERROR: AGENTPAY_MASTER_KEY environment variable not set');
|
|
17
|
+
console.error('Generate a secure key with: openssl rand -hex 32');
|
|
18
|
+
console.error('Set it in .env: AGENTPAY_MASTER_KEY=<your-key>');
|
|
19
|
+
console.error('');
|
|
20
|
+
console.error('For demo/testing only, set AGENTPAY_DEMO=true');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
if (process.env.AGENTPAY_MASTER_KEY.length < 32) {
|
|
24
|
+
console.error('❌ FATAL ERROR: AGENTPAY_MASTER_KEY must be at least 32 characters');
|
|
25
|
+
console.error('Generate a secure key with: openssl rand -hex 32');
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.config = {
|
|
30
|
+
// BSV Network: 'mainnet' | 'testnet'
|
|
31
|
+
network: (process.env.BSV_NETWORK || 'testnet'),
|
|
32
|
+
// WhatsOnChain API base URL
|
|
33
|
+
whatsOnChainBase: process.env.BSV_NETWORK === 'mainnet'
|
|
34
|
+
? 'https://api.whatsonchain.com/v1/bsv/main'
|
|
35
|
+
: 'https://api.whatsonchain.com/v1/bsv/test',
|
|
36
|
+
// WhatsOnChain explorer base URL
|
|
37
|
+
explorerBase: process.env.BSV_NETWORK === 'mainnet'
|
|
38
|
+
? 'https://whatsonchain.com/tx'
|
|
39
|
+
: 'https://test.whatsonchain.com/tx',
|
|
40
|
+
// Platform fee rate (2%)
|
|
41
|
+
platformFeeRate: 0.02,
|
|
42
|
+
// Escrow mode: 'platform' (centralized) | 'multisig' (future)
|
|
43
|
+
escrowMode: 'platform',
|
|
44
|
+
// Demo mode: use internal ledger instead of on-chain transactions
|
|
45
|
+
// Set AGENTPAY_DEMO=true for local testing without real BSV
|
|
46
|
+
demoMode: isDemoMode,
|
|
47
|
+
// Demo mode: skip authentication (for testing only)
|
|
48
|
+
demoSkipAuth: isDemoMode && process.env.AGENTPAY_DEMO_SKIP_AUTH === 'true',
|
|
49
|
+
// Minimum transaction fee (satoshis/byte)
|
|
50
|
+
feePerByte: 1,
|
|
51
|
+
// Private key encryption settings
|
|
52
|
+
encryption: {
|
|
53
|
+
algorithm: 'aes-256-gcm',
|
|
54
|
+
// Master key is REQUIRED (enforced at startup unless in demo mode)
|
|
55
|
+
masterKey: process.env.AGENTPAY_MASTER_KEY || 'demo-mode-insecure-key-for-testing-only',
|
|
56
|
+
},
|
|
57
|
+
// Platform escrow wallet (for MVP)
|
|
58
|
+
// In production, this should be a secure cold wallet
|
|
59
|
+
platformWallet: {
|
|
60
|
+
// These will be generated on first run if not provided
|
|
61
|
+
privateKey: process.env.PLATFORM_WALLET_PRIVKEY,
|
|
62
|
+
address: process.env.PLATFORM_WALLET_ADDRESS,
|
|
63
|
+
},
|
|
64
|
+
// External wallet providers
|
|
65
|
+
handcash: {
|
|
66
|
+
appId: process.env.HANDCASH_APP_ID || '',
|
|
67
|
+
appSecret: process.env.HANDCASH_APP_SECRET || '',
|
|
68
|
+
redirectUrl: process.env.HANDCASH_REDIRECT_URL || 'http://localhost:3100/api/wallets/connect/handcash/callback',
|
|
69
|
+
},
|
|
70
|
+
// Frontend URL (for OAuth callbacks)
|
|
71
|
+
frontendUrl: process.env.FRONTEND_URL || 'http://localhost:3000',
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Get the appropriate network prefix for P2PKH addresses
|
|
75
|
+
*/
|
|
76
|
+
function getAddressPrefix() {
|
|
77
|
+
return exports.config.network === 'mainnet' ? 0x00 : 0x6f;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get WhatsOnChain URL for a transaction
|
|
81
|
+
*/
|
|
82
|
+
function getTxUrl(txId) {
|
|
83
|
+
return `${exports.config.explorerBase}/${txId}`;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAkFH,4CAEC;AAKD,4BAEC;AAzFD,kBAAkB;AAClB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,GAAG,CAAA;AAE5F,6CAA6C;AAC7C,IAAI,CAAC,UAAU,EAAE,CAAC;IAChB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;QACrC,OAAO,CAAC,KAAK,CAAC,iEAAiE,CAAC,CAAA;QAChF,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAA;QACjE,OAAO,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAA;QAC/D,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QACjB,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IAED,IAAI,OAAO,CAAC,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OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,EAAE;QACxC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,EAAE;QAChD,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,6DAA6D;KAChH;IAED,qCAAqC;IACrC,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,uBAAuB;CACjE,CAAA;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,OAAO,cAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;AACnD,CAAC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,IAAY;IACnC,OAAO,GAAG,cAAM,CAAC,YAAY,IAAI,IAAI,EAAE,CAAA;AACzC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Currency Manager for AgentsPay
|
|
3
|
+
*
|
|
4
|
+
* Supports:
|
|
5
|
+
* - BSV (satoshis) - native blockchain currency
|
|
6
|
+
* - MNEE (USD cents) - 1Sat Ordinals BSV-21 stablecoin (1 MNEE = $0.01 USD)
|
|
7
|
+
*
|
|
8
|
+
* Currency amounts:
|
|
9
|
+
* - BSV: integer satoshis (1 sat = 0.00000001 BSV)
|
|
10
|
+
* - MNEE: integer cents (1 cent = $0.01 USD, 100 cents = 1 MNEE token)
|
|
11
|
+
*/
|
|
12
|
+
export type Currency = 'BSV' | 'MNEE';
|
|
13
|
+
export interface CurrencyConfig {
|
|
14
|
+
code: Currency;
|
|
15
|
+
name: string;
|
|
16
|
+
symbol: string;
|
|
17
|
+
decimals: number;
|
|
18
|
+
minAmount: number;
|
|
19
|
+
description: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ConversionRate {
|
|
22
|
+
from: Currency;
|
|
23
|
+
to: Currency;
|
|
24
|
+
rate: number;
|
|
25
|
+
timestamp: string;
|
|
26
|
+
source?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class CurrencyManager {
|
|
29
|
+
private static currencies;
|
|
30
|
+
/**
|
|
31
|
+
* Get currency configuration
|
|
32
|
+
*/
|
|
33
|
+
static getConfig(currency: Currency): CurrencyConfig;
|
|
34
|
+
/**
|
|
35
|
+
* Validate currency code
|
|
36
|
+
*/
|
|
37
|
+
static isValid(currency: string): currency is Currency;
|
|
38
|
+
/**
|
|
39
|
+
* Validate amount for currency
|
|
40
|
+
*/
|
|
41
|
+
static validateAmount(amount: number, currency: Currency): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Format amount for display
|
|
44
|
+
* BSV: satoshis → BSV with 8 decimals
|
|
45
|
+
* MNEE: cents → USD with 2 decimals
|
|
46
|
+
*/
|
|
47
|
+
static format(amount: number, currency: Currency): string;
|
|
48
|
+
/**
|
|
49
|
+
* Parse amount from human-readable format
|
|
50
|
+
* BSV: "0.00001 BSV" → 1000 satoshis
|
|
51
|
+
* MNEE: "1.50 MNEE" → 150 cents
|
|
52
|
+
*/
|
|
53
|
+
static parse(input: string, currency: Currency): number | null;
|
|
54
|
+
/**
|
|
55
|
+
* Calculate platform fee (2%)
|
|
56
|
+
*/
|
|
57
|
+
static calculateFee(amount: number, currency: Currency): number;
|
|
58
|
+
/**
|
|
59
|
+
* Get BSV/USD conversion rate (for informational purposes)
|
|
60
|
+
* In production, this would fetch from a price oracle
|
|
61
|
+
* For demo: hardcoded ~$50/BSV (as of Feb 2026 estimate)
|
|
62
|
+
*/
|
|
63
|
+
static getConversionRate(from: Currency, to: Currency): Promise<ConversionRate | null>;
|
|
64
|
+
/**
|
|
65
|
+
* Convert amount between currencies
|
|
66
|
+
* For informational purposes only - actual payments don't auto-convert
|
|
67
|
+
*/
|
|
68
|
+
static convert(amount: number, from: Currency, to: Currency): Promise<number | null>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=currency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.d.ts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,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAoC5F;;;OAGG;WACU,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAK3F"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Multi-Currency Manager for AgentsPay
|
|
4
|
+
*
|
|
5
|
+
* Supports:
|
|
6
|
+
* - BSV (satoshis) - native blockchain currency
|
|
7
|
+
* - MNEE (USD cents) - 1Sat Ordinals BSV-21 stablecoin (1 MNEE = $0.01 USD)
|
|
8
|
+
*
|
|
9
|
+
* Currency amounts:
|
|
10
|
+
* - BSV: integer satoshis (1 sat = 0.00000001 BSV)
|
|
11
|
+
* - MNEE: integer cents (1 cent = $0.01 USD, 100 cents = 1 MNEE token)
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.CurrencyManager = void 0;
|
|
15
|
+
class CurrencyManager {
|
|
16
|
+
static currencies = {
|
|
17
|
+
BSV: {
|
|
18
|
+
code: 'BSV',
|
|
19
|
+
name: 'Bitcoin SV',
|
|
20
|
+
symbol: 'BSV',
|
|
21
|
+
decimals: 8,
|
|
22
|
+
minAmount: 1, // 1 satoshi
|
|
23
|
+
description: 'Native BSV satoshis',
|
|
24
|
+
},
|
|
25
|
+
MNEE: {
|
|
26
|
+
code: 'MNEE',
|
|
27
|
+
name: 'MNEE Stablecoin',
|
|
28
|
+
symbol: 'MNEE',
|
|
29
|
+
decimals: 2, // cents
|
|
30
|
+
minAmount: 1, // 1 cent = $0.01
|
|
31
|
+
description: 'USD-pegged stablecoin on 1Sat Ordinals (BSV-21)',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Get currency configuration
|
|
36
|
+
*/
|
|
37
|
+
static getConfig(currency) {
|
|
38
|
+
return this.currencies[currency];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate currency code
|
|
42
|
+
*/
|
|
43
|
+
static isValid(currency) {
|
|
44
|
+
return currency === 'BSV' || currency === 'MNEE';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validate amount for currency
|
|
48
|
+
*/
|
|
49
|
+
static validateAmount(amount, currency) {
|
|
50
|
+
if (!Number.isFinite(amount) || amount < 0)
|
|
51
|
+
return false;
|
|
52
|
+
if (!Number.isInteger(amount))
|
|
53
|
+
return false;
|
|
54
|
+
const config = this.getConfig(currency);
|
|
55
|
+
return amount >= config.minAmount;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Format amount for display
|
|
59
|
+
* BSV: satoshis → BSV with 8 decimals
|
|
60
|
+
* MNEE: cents → USD with 2 decimals
|
|
61
|
+
*/
|
|
62
|
+
static format(amount, currency) {
|
|
63
|
+
const config = this.getConfig(currency);
|
|
64
|
+
const divisor = Math.pow(10, config.decimals);
|
|
65
|
+
const value = (amount / divisor).toFixed(config.decimals);
|
|
66
|
+
return `${value} ${config.symbol}`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parse amount from human-readable format
|
|
70
|
+
* BSV: "0.00001 BSV" → 1000 satoshis
|
|
71
|
+
* MNEE: "1.50 MNEE" → 150 cents
|
|
72
|
+
*/
|
|
73
|
+
static parse(input, currency) {
|
|
74
|
+
const config = this.getConfig(currency);
|
|
75
|
+
const cleaned = input.replace(/[^\d.]/g, '');
|
|
76
|
+
const value = parseFloat(cleaned);
|
|
77
|
+
if (!Number.isFinite(value))
|
|
78
|
+
return null;
|
|
79
|
+
const amount = Math.round(value * Math.pow(10, config.decimals));
|
|
80
|
+
return this.validateAmount(amount, currency) ? amount : null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Calculate platform fee (2%)
|
|
84
|
+
*/
|
|
85
|
+
static calculateFee(amount, currency) {
|
|
86
|
+
const fee = Math.ceil(amount * 0.02); // 2% platform fee
|
|
87
|
+
const config = this.getConfig(currency);
|
|
88
|
+
return Math.max(fee, config.minAmount); // Fee cannot be less than minimum amount
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get BSV/USD conversion rate (for informational purposes)
|
|
92
|
+
* In production, this would fetch from a price oracle
|
|
93
|
+
* For demo: hardcoded ~$50/BSV (as of Feb 2026 estimate)
|
|
94
|
+
*/
|
|
95
|
+
static async getConversionRate(from, to) {
|
|
96
|
+
if (from === to) {
|
|
97
|
+
return { from, to, rate: 1, timestamp: new Date().toISOString() };
|
|
98
|
+
}
|
|
99
|
+
// BSV/USD rate: ~$50 per BSV (hardcoded for demo)
|
|
100
|
+
const bsvUsdRate = 50.0;
|
|
101
|
+
const satoshisPerBsv = 100_000_000;
|
|
102
|
+
const centsPerUsd = 100;
|
|
103
|
+
// 1 satoshi = (50 USD / 100,000,000 sats) * 100 cents/USD
|
|
104
|
+
const satoshiToCents = (bsvUsdRate / satoshisPerBsv) * centsPerUsd; // ~0.005 cents per sat
|
|
105
|
+
if (from === 'BSV' && to === 'MNEE') {
|
|
106
|
+
return {
|
|
107
|
+
from,
|
|
108
|
+
to,
|
|
109
|
+
rate: satoshiToCents,
|
|
110
|
+
timestamp: new Date().toISOString(),
|
|
111
|
+
source: 'hardcoded',
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (from === 'MNEE' && to === 'BSV') {
|
|
115
|
+
return {
|
|
116
|
+
from,
|
|
117
|
+
to,
|
|
118
|
+
rate: 1 / satoshiToCents,
|
|
119
|
+
timestamp: new Date().toISOString(),
|
|
120
|
+
source: 'hardcoded',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Convert amount between currencies
|
|
127
|
+
* For informational purposes only - actual payments don't auto-convert
|
|
128
|
+
*/
|
|
129
|
+
static async convert(amount, from, to) {
|
|
130
|
+
const rate = await this.getConversionRate(from, to);
|
|
131
|
+
if (!rate)
|
|
132
|
+
return null;
|
|
133
|
+
return Math.round(amount * rate.rate);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.CurrencyManager = CurrencyManager;
|
|
137
|
+
//# sourceMappingURL=currency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../src/currency/currency.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAqBH,MAAa,eAAe;IAClB,MAAM,CAAC,UAAU,GAAqC;QAC5D,GAAG,EAAE;YACH,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,CAAC;YACX,SAAS,EAAE,CAAC,EAAE,YAAY;YAC1B,WAAW,EAAE,qBAAqB;SACnC;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,iBAAiB;YACvB,MAAM,EAAE,MAAM;YACd,QAAQ,EAAE,CAAC,EAAE,QAAQ;YACrB,SAAS,EAAE,CAAC,EAAE,iBAAiB;YAC/B,WAAW,EAAE,iDAAiD;SAC/D;KACF,CAAA;IAED;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,QAAkB;QACjC,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,QAAgB;QAC7B,OAAO,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,MAAM,CAAA;IAClD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,MAAc,EAAE,QAAkB;QACtD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC;YAAE,OAAO,KAAK,CAAA;QACxD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAA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