@unchainedshop/plugins 3.1.13 → 4.0.0-rc.3
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/delivery/pick-mup.js +0 -2
- package/lib/delivery/pick-mup.js.map +1 -1
- package/lib/files/gridfs/handler-express.d.ts.map +1 -1
- package/lib/files/gridfs/handler-express.js +5 -0
- package/lib/files/gridfs/handler-express.js.map +1 -1
- package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
- package/lib/files/gridfs/handler-fastify.js +4 -0
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/gridfs/module.d.ts +2 -2
- package/lib/files/gridfs/module.d.ts.map +1 -1
- package/lib/filters/local-search.d.ts.map +1 -1
- package/lib/filters/local-search.js +9 -2
- package/lib/filters/local-search.js.map +1 -1
- package/lib/filters/strict-equal.js +18 -0
- package/lib/filters/strict-equal.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +5 -12
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/fix-periods.d.ts.map +1 -1
- package/lib/payment/apple-iap/fix-periods.js +3 -5
- package/lib/payment/apple-iap/fix-periods.js.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +3 -3
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +3 -3
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/apple-iap/module.d.ts +2 -2
- package/lib/payment/apple-iap/module.d.ts.map +1 -1
- package/lib/payment/braintree.js +3 -4
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -2
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.js.map +1 -1
- package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +3 -56
- package/lib/payment/cryptopay/handler-express.js.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.js +3 -55
- package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/module.d.ts +26 -26
- package/lib/payment/cryptopay/module.d.ts.map +1 -1
- package/lib/payment/cryptopay/module.js +26 -24
- package/lib/payment/cryptopay/module.js.map +1 -1
- package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
- package/lib/payment/cryptopay/plugin.js +33 -79
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/api/types.d.ts +41 -41
- package/lib/payment/datatrans-v2/api/types.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/getPaths.d.ts +2 -2
- package/lib/payment/datatrans-v2/getPaths.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/index.js +16 -14
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +3 -3
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -1
- package/lib/payment/paypal-checkout.js +1 -1
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/api/index.d.ts +2 -2
- package/lib/payment/payrexx/api/index.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
- package/lib/payment/payrexx/index.js +4 -4
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/payrexx.js +2 -2
- package/lib/payment/payrexx/payrexx.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +3 -5
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/types.d.ts +4 -4
- package/lib/payment/postfinance-checkout/types.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/utils.js +2 -2
- package/lib/payment/postfinance-checkout/utils.js.map +1 -1
- package/lib/payment/saferpay/adapter.d.ts.map +1 -1
- package/lib/payment/saferpay/adapter.js +4 -6
- package/lib/payment/saferpay/adapter.js.map +1 -1
- package/lib/payment/saferpay/api/models/Transaction.d.ts +2 -2
- package/lib/payment/saferpay/api/models/Transaction.d.ts.map +1 -1
- package/lib/payment/saferpay/module.d.ts +2 -2
- package/lib/payment/saferpay/module.d.ts.map +1 -1
- package/lib/payment/stripe/index.js +5 -5
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/stripe.js +2 -2
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/presets/all.d.ts +12 -12
- package/lib/presets/all.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +2 -2
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/order-delivery.js +1 -1
- package/lib/pricing/order-delivery.js.map +1 -1
- package/lib/pricing/order-discount.js +3 -3
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-items-discount.js +1 -1
- package/lib/pricing/order-items-discount.js.map +1 -1
- package/lib/pricing/order-items.js +1 -1
- package/lib/pricing/order-items.js.map +1 -1
- package/lib/pricing/order-payment.js +1 -1
- package/lib/pricing/order-payment.js.map +1 -1
- package/lib/pricing/order-round.d.ts +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +8 -8
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts +0 -1
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +6 -18
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +2 -2
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-round.d.ts +1 -1
- package/lib/pricing/product-round.d.ts.map +1 -1
- package/lib/pricing/product-round.js +2 -2
- package/lib/pricing/product-round.js.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +1 -1
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +2 -2
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/warehousing/eth-minter.js +2 -2
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/bulk-import.js +1 -1
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/enrollment-order-generator.js +1 -1
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/error-notifications.d.ts +4 -4
- package/lib/worker/error-notifications.d.ts.map +1 -1
- package/lib/worker/heartbeat.js +2 -8
- package/lib/worker/heartbeat.js.map +1 -1
- package/lib/worker/message.d.ts +1 -1
- package/lib/worker/message.d.ts.map +1 -1
- package/lib/worker/sms.js +16 -16
- package/lib/worker/sms.js.map +1 -1
- package/lib/worker/update-coinbase-rates.js +1 -1
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/package.json +28 -44
- package/src/delivery/pick-mup.ts +0 -2
- package/src/files/gridfs/handler-express.ts +4 -0
- package/src/files/gridfs/handler-fastify.ts +3 -0
- package/src/files/gridfs/module.ts +2 -2
- package/src/filters/local-search.ts +11 -2
- package/src/filters/strict-equal.ts +21 -0
- package/src/payment/apple-iap/adapter.ts +6 -13
- package/src/payment/apple-iap/fix-periods.ts +4 -7
- package/src/payment/apple-iap/handler-express.ts +3 -3
- package/src/payment/apple-iap/handler-fastify.ts +3 -3
- package/src/payment/apple-iap/module.ts +2 -2
- package/src/payment/braintree.ts +3 -4
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -2
- package/src/payment/cryptopay/denote-amount.test.ts +28 -0
- package/src/payment/cryptopay/denote-amount.ts +29 -0
- package/src/payment/cryptopay/derive-btc-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-btc-address.ts +48 -0
- package/src/payment/cryptopay/derive-eth-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-eth-address.ts +38 -0
- package/src/payment/cryptopay/handle-webhook.ts +103 -0
- package/src/payment/cryptopay/handler-express.ts +3 -69
- package/src/payment/cryptopay/handler-fastify.ts +5 -70
- package/src/payment/cryptopay/module.ts +44 -40
- package/src/payment/cryptopay/plugin.ts +50 -87
- package/src/payment/cryptopay/readme.md +23 -1
- package/src/payment/datatrans-v2/api/types.ts +41 -41
- package/src/payment/datatrans-v2/getPaths.ts +2 -2
- package/src/payment/datatrans-v2/index.ts +17 -15
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +4 -4
- package/src/payment/paypal-checkout.ts +1 -1
- package/src/payment/payrexx/api/index.ts +2 -2
- package/src/payment/payrexx/api/makeFetcher.ts +1 -1
- package/src/payment/payrexx/index.ts +4 -4
- package/src/payment/payrexx/payrexx.ts +2 -2
- package/src/payment/postfinance-checkout/index.ts +3 -5
- package/src/payment/postfinance-checkout/types.ts +6 -6
- package/src/payment/postfinance-checkout/utils.ts +2 -2
- package/src/payment/saferpay/adapter.ts +4 -6
- package/src/payment/saferpay/api/models/Transaction.ts +2 -2
- package/src/payment/saferpay/module.ts +2 -2
- package/src/payment/stripe/index.ts +5 -5
- package/src/payment/stripe/stripe.ts +2 -2
- package/src/pricing/delivery-swiss-tax.ts +6 -2
- package/src/pricing/order-delivery.ts +1 -1
- package/src/pricing/order-discount.ts +3 -3
- package/src/pricing/order-items-discount.ts +1 -1
- package/src/pricing/order-items.ts +1 -1
- package/src/pricing/order-payment.ts +1 -1
- package/src/pricing/order-round.ts +9 -9
- package/src/pricing/product-catalog-price.ts +6 -25
- package/src/pricing/product-price-rateconversion.ts +2 -2
- package/src/pricing/product-round.ts +3 -3
- package/src/pricing/product-swiss-tax.test.ts +6 -6
- package/src/pricing/product-swiss-tax.ts +2 -2
- package/src/warehousing/eth-minter.ts +2 -2
- package/src/worker/bulk-import.ts +1 -1
- package/src/worker/enrollment-order-generator.ts +3 -3
- package/src/worker/error-notifications.ts +4 -4
- package/src/worker/heartbeat.ts +4 -11
- package/src/worker/message.ts +1 -1
- package/src/worker/push-notification.ts +2 -2
- package/src/worker/sms.ts +19 -17
- package/src/worker/update-coinbase-rates.ts +3 -6
- package/src/worker/update-ecb-rates.ts +3 -3
- package/src/worker/BaseWorker.ts +0 -116
- package/src/worker/EventListenerWorker.ts +0 -61
- package/src/worker/FailedRescheduler.ts +0 -80
- package/src/worker/IntervalWorker.ts +0 -54
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-express.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-express.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"handler-express.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-express.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAEhD,MAAM,MAAM,GAAG,YAAY,CAAC,kCAAkC,CAAC,CAAC;AAEhE,MAAM,gBAAgB,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IAC1C,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,MAAM,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;YACpD,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACnB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC3C,OAAO;QACT,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAChB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACnB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC9D,OAAO;QACT,CAAC;IACH,CAAC;IACD,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACnB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-fastify.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-fastify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler-fastify.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-fastify.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7D,QAAA,MAAM,gBAAgB,EAAE,kBAevB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,66 +1,14 @@
|
|
|
1
1
|
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import
|
|
3
|
-
const { CRYPTOPAY_SECRET, CRYPTOPAY_MAX_RATE_AGE = '360' } = process.env;
|
|
2
|
+
import handleWebhook from './handle-webhook.js';
|
|
4
3
|
const logger = createLogger('unchained:core-payment:cryptopay');
|
|
5
4
|
const cryptopayHandler = async (req, reply) => {
|
|
6
|
-
const { modules, services } = req.unchainedContext;
|
|
7
5
|
try {
|
|
8
|
-
|
|
9
|
-
if (secret !== CRYPTOPAY_SECRET) {
|
|
10
|
-
logger.warn(`Cryptopay Plugin: Invalid Cryptopay Secret provided`);
|
|
11
|
-
throw new Error('Secret invalid');
|
|
12
|
-
}
|
|
13
|
-
if (wallet) {
|
|
14
|
-
const { address, blockHeight, amount, contract, decimals, currency } = wallet;
|
|
15
|
-
const { orderPaymentId } = await modules.cryptopay.updateWalletAddress({
|
|
16
|
-
addressId: address,
|
|
17
|
-
blockHeight,
|
|
18
|
-
amount,
|
|
19
|
-
contract,
|
|
20
|
-
decimals,
|
|
21
|
-
currency,
|
|
22
|
-
});
|
|
23
|
-
const orderPayment = orderPaymentId &&
|
|
24
|
-
(await modules.orders.payments.findOrderPayment({
|
|
25
|
-
orderPaymentId,
|
|
26
|
-
}));
|
|
27
|
-
if (orderPayment) {
|
|
28
|
-
// Try to process order to next status
|
|
29
|
-
// TODO: Not sure if it's correct to use processOrder here if status is PENDING!
|
|
30
|
-
const order = await modules.orders.findOrder({ orderId: orderPayment.orderId });
|
|
31
|
-
if (order.status === null) {
|
|
32
|
-
await services.orders.checkoutOrder(order._id, {});
|
|
33
|
-
}
|
|
34
|
-
else if (order.status === OrderStatus.PENDING) {
|
|
35
|
-
await services.orders.processOrder(order, {});
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
throw new Error('Already processed');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (price) {
|
|
43
|
-
const { baseCurrency, token, rate, timestamp } = price;
|
|
44
|
-
const timestampDate = new Date(timestamp);
|
|
45
|
-
const expiresAt = new Date(new Date().getTime() + parseInt(CRYPTOPAY_MAX_RATE_AGE, 10) * 1000);
|
|
46
|
-
const rateData = {
|
|
47
|
-
baseCurrency,
|
|
48
|
-
quoteCurrency: token,
|
|
49
|
-
rate,
|
|
50
|
-
expiresAt,
|
|
51
|
-
timestamp: timestampDate,
|
|
52
|
-
};
|
|
53
|
-
logger.info(`update rate ${JSON.stringify(price)}, ${JSON.stringify(rateData)}`);
|
|
54
|
-
await modules.products.prices.rates.updateRates([rateData]);
|
|
55
|
-
}
|
|
56
|
-
if (ping) {
|
|
57
|
-
const { blockHeight, currency } = ping;
|
|
58
|
-
await modules.cryptopay.updateMostRecentBlock(currency, blockHeight);
|
|
59
|
-
}
|
|
6
|
+
await handleWebhook(req.body, req.unchainedContext);
|
|
60
7
|
reply.status(200);
|
|
61
8
|
return reply.send({ success: true });
|
|
62
9
|
}
|
|
63
10
|
catch (e) {
|
|
11
|
+
logger.error(e);
|
|
64
12
|
reply.status(500);
|
|
65
13
|
return reply.send({ success: false, error: e.message });
|
|
66
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-fastify.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-fastify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler-fastify.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-fastify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAEhD,MAAM,MAAM,GAAG,YAAY,CAAC,kCAAkC,CAAC,CAAC;AAGhE,MAAM,gBAAgB,GAAuB,KAAK,EAChD,GAEC,EACD,KAAK,EACL,EAAE;IACF,IAAI,CAAC;QACH,MAAM,aAAa,CAAC,GAAG,CAAC,IAAW,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC3D,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -2,23 +2,23 @@ import { CryptopayTransaction } from './db/CryptopayTransactions.js';
|
|
|
2
2
|
declare const configureCryptopayModule: ({ db }: {
|
|
3
3
|
db: any;
|
|
4
4
|
}) => {
|
|
5
|
-
getWalletAddress: (
|
|
6
|
-
updateMostRecentBlock: (
|
|
7
|
-
updateWalletAddress: ({
|
|
8
|
-
|
|
5
|
+
getWalletAddress: (address: string, contract?: string) => Promise<CryptopayTransaction>;
|
|
6
|
+
updateMostRecentBlock: (currencyCode: string, blockHeight: number) => Promise<void>;
|
|
7
|
+
updateWalletAddress: ({ address, blockHeight, amount, contract, currencyCode, decimals, }: {
|
|
8
|
+
address: string;
|
|
9
9
|
blockHeight: number;
|
|
10
|
-
amount: string;
|
|
11
|
-
contract
|
|
12
|
-
|
|
10
|
+
amount: string | number;
|
|
11
|
+
contract?: string;
|
|
12
|
+
currencyCode: string;
|
|
13
13
|
decimals: number;
|
|
14
14
|
}) => Promise<CryptopayTransaction>;
|
|
15
|
-
mapOrderPaymentToWalletAddress: ({
|
|
16
|
-
|
|
17
|
-
contract
|
|
18
|
-
|
|
15
|
+
mapOrderPaymentToWalletAddress: ({ address, contract, currencyCode, orderPaymentId, }: {
|
|
16
|
+
address: string;
|
|
17
|
+
contract?: string;
|
|
18
|
+
currencyCode: string;
|
|
19
19
|
orderPaymentId: string;
|
|
20
20
|
}) => Promise<CryptopayTransaction>;
|
|
21
|
-
getNextDerivationNumber: (
|
|
21
|
+
getNextDerivationNumber: (currencyCode: string) => Promise<number>;
|
|
22
22
|
getWalletAddressesByOrderPaymentId: (orderPaymentId: string) => Promise<CryptopayTransaction[]>;
|
|
23
23
|
};
|
|
24
24
|
declare const _default: {
|
|
@@ -26,29 +26,29 @@ declare const _default: {
|
|
|
26
26
|
configure: ({ db }: {
|
|
27
27
|
db: any;
|
|
28
28
|
}) => {
|
|
29
|
-
getWalletAddress: (
|
|
30
|
-
updateMostRecentBlock: (
|
|
31
|
-
updateWalletAddress: ({
|
|
32
|
-
|
|
29
|
+
getWalletAddress: (address: string, contract?: string) => Promise<CryptopayTransaction>;
|
|
30
|
+
updateMostRecentBlock: (currencyCode: string, blockHeight: number) => Promise<void>;
|
|
31
|
+
updateWalletAddress: ({ address, blockHeight, amount, contract, currencyCode, decimals, }: {
|
|
32
|
+
address: string;
|
|
33
33
|
blockHeight: number;
|
|
34
|
-
amount: string;
|
|
35
|
-
contract
|
|
36
|
-
|
|
34
|
+
amount: string | number;
|
|
35
|
+
contract?: string;
|
|
36
|
+
currencyCode: string;
|
|
37
37
|
decimals: number;
|
|
38
38
|
}) => Promise<CryptopayTransaction>;
|
|
39
|
-
mapOrderPaymentToWalletAddress: ({
|
|
40
|
-
|
|
41
|
-
contract
|
|
42
|
-
|
|
39
|
+
mapOrderPaymentToWalletAddress: ({ address, contract, currencyCode, orderPaymentId, }: {
|
|
40
|
+
address: string;
|
|
41
|
+
contract?: string;
|
|
42
|
+
currencyCode: string;
|
|
43
43
|
orderPaymentId: string;
|
|
44
44
|
}) => Promise<CryptopayTransaction>;
|
|
45
|
-
getNextDerivationNumber: (
|
|
45
|
+
getNextDerivationNumber: (currencyCode: string) => Promise<number>;
|
|
46
46
|
getWalletAddressesByOrderPaymentId: (orderPaymentId: string) => Promise<CryptopayTransaction[]>;
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
50
|
export default _default;
|
|
51
|
-
export
|
|
51
|
+
export interface CryptopayModule {
|
|
52
52
|
cryptopay: ReturnType<typeof configureCryptopayModule>;
|
|
53
|
-
}
|
|
53
|
+
}
|
|
54
54
|
//# sourceMappingURL=module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAmC,MAAM,+BAA+B,CAAC;AAEtG,QAAA,MAAM,wBAAwB,GAAI;;CAAM;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../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C;gBAClB,YAAY,EAAE,MAAM,CAAC;gBACrB,cAAc,EAAE,MAAM,CAAC;aACxB,KAAG,OAAO,CAAC,oBAAoB,CAAC;oDAyBoB,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC;iEAK3D,MAAM,KACrB,OAAO,CAAC,oBAAoB,EAAE,CAAC;;;;AA6DpC,wBAIE;AAEF,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC;CACxD"}
|
|
@@ -2,27 +2,27 @@ import { mongodb } from '@unchainedshop/mongodb';
|
|
|
2
2
|
import { CryptopayTransactionsCollection } from './db/CryptopayTransactions.js';
|
|
3
3
|
const configureCryptopayModule = ({ db }) => {
|
|
4
4
|
const CryptoTransactions = CryptopayTransactionsCollection(db);
|
|
5
|
-
const getWalletAddress = async (
|
|
6
|
-
|
|
5
|
+
const getWalletAddress = async (address, contract) => {
|
|
6
|
+
const addressId = [address, contract].filter(Boolean).join(':');
|
|
7
|
+
return CryptoTransactions.findOne({ _id: addressId });
|
|
7
8
|
};
|
|
8
|
-
const updateMostRecentBlock = async (
|
|
9
|
+
const updateMostRecentBlock = async (currencyCode, blockHeight) => {
|
|
9
10
|
await CryptoTransactions.updateMany({
|
|
10
|
-
|
|
11
|
+
currencyCode,
|
|
11
12
|
}, {
|
|
12
13
|
$set: {
|
|
13
14
|
mostRecentBlockHeight: blockHeight,
|
|
14
15
|
},
|
|
15
16
|
});
|
|
16
17
|
};
|
|
17
|
-
const mapOrderPaymentToWalletAddress = async ({
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const mapOrderPaymentToWalletAddress = async ({ address, contract, currencyCode, orderPaymentId, }) => {
|
|
19
|
+
const addressId = [address, contract].filter(Boolean).join(':');
|
|
20
|
+
return CryptoTransactions.findOneAndUpdate({
|
|
21
|
+
_id: addressId,
|
|
20
22
|
}, {
|
|
21
23
|
$setOnInsert: {
|
|
22
|
-
_id: addressId
|
|
23
|
-
|
|
24
|
-
currency,
|
|
25
|
-
decimals: null,
|
|
24
|
+
_id: addressId,
|
|
25
|
+
currencyCode,
|
|
26
26
|
mostRecentBlockHeight: 0,
|
|
27
27
|
blockHeight: 0,
|
|
28
28
|
amount: mongodb.Decimal128.fromString('0'),
|
|
@@ -32,36 +32,38 @@ const configureCryptopayModule = ({ db }) => {
|
|
|
32
32
|
orderPaymentId,
|
|
33
33
|
updated: new Date(),
|
|
34
34
|
},
|
|
35
|
-
}, { upsert: true });
|
|
36
|
-
return CryptoTransactions.findOne({ _id: addressId.toLowerCase() });
|
|
35
|
+
}, { upsert: true, returnDocument: 'after' });
|
|
37
36
|
};
|
|
38
|
-
const getNextDerivationNumber = async (
|
|
39
|
-
return (await CryptoTransactions.countDocuments({
|
|
37
|
+
const getNextDerivationNumber = async (currencyCode) => {
|
|
38
|
+
return (await CryptoTransactions.countDocuments({ currencyCode })) + 1;
|
|
40
39
|
};
|
|
41
40
|
const getWalletAddressesByOrderPaymentId = async (orderPaymentId) => {
|
|
42
41
|
return CryptoTransactions.find({
|
|
43
42
|
orderPaymentId,
|
|
43
|
+
}, {
|
|
44
|
+
sort: {
|
|
45
|
+
created: 1, // Sort by creation date, most recent first
|
|
46
|
+
},
|
|
44
47
|
}).toArray();
|
|
45
48
|
};
|
|
46
|
-
const updateWalletAddress = async ({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const updateWalletAddress = async ({ address, blockHeight, amount, contract, currencyCode, decimals, }) => {
|
|
50
|
+
const addressId = [address, contract].filter(Boolean).join(':');
|
|
51
|
+
return CryptoTransactions.findOneAndUpdate({
|
|
52
|
+
_id: addressId,
|
|
49
53
|
}, {
|
|
50
54
|
$setOnInsert: {
|
|
51
|
-
_id: addressId
|
|
52
|
-
currency,
|
|
53
|
-
contract,
|
|
55
|
+
_id: addressId,
|
|
54
56
|
created: new Date(),
|
|
55
57
|
},
|
|
56
58
|
$set: {
|
|
59
|
+
currencyCode,
|
|
57
60
|
decimals,
|
|
58
61
|
blockHeight,
|
|
59
62
|
mostRecentBlockHeight: blockHeight,
|
|
60
|
-
amount: mongodb.Decimal128.fromString(amount),
|
|
63
|
+
amount: mongodb.Decimal128.fromString(typeof amount === 'number' ? `${amount}` : amount),
|
|
61
64
|
updated: new Date(),
|
|
62
65
|
},
|
|
63
|
-
}, { upsert: true });
|
|
64
|
-
return CryptoTransactions.findOne({ _id: addressId.toLowerCase() });
|
|
66
|
+
}, { upsert: true, returnDocument: 'after' });
|
|
65
67
|
};
|
|
66
68
|
return {
|
|
67
69
|
getWalletAddress,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAwB,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAEtG,MAAM,wBAAwB,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE;IAC1C,MAAM,kBAAkB,GAAG,+BAA+B,CAAC,EAAE,CAAC,CAAC;IAE/D,MAAM,gBAAgB,GAAG,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAwB,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAEtG,MAAM,wBAAwB,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE;IAC1C,MAAM,kBAAkB,GAAG,+BAA+B,CAAC,EAAE,CAAC,CAAC;IAE/D,MAAM,gBAAgB,GAAG,KAAK,EAAE,OAAe,EAAE,QAAiB,EAAiC,EAAE;QACnG,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChE,OAAO,kBA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.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAKhB,MAAM,qBAAqB,CAAC;AAwB7B,QAAA,MAAM,SAAS,EAAE,eAsOhB,CAAC;AAIF,eAAe,SAAS,CAAC"}
|
|
@@ -1,45 +1,10 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import { BIP32Factory } from 'bip32';
|
|
3
|
-
import bs58check from 'bs58check';
|
|
4
|
-
import * as ecc from 'tiny-secp256k1';
|
|
5
|
-
import { networks, payments } from 'bitcoinjs-lib';
|
|
6
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
7
1
|
import { PaymentAdapter, PaymentDirector, PaymentError, OrderPricingSheet, } from '@unchainedshop/core';
|
|
2
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
+
import deriveBtcAddress from './derive-btc-address.js';
|
|
4
|
+
import deriveEthAddress from './derive-eth-address.js';
|
|
5
|
+
import denoteAmount from './denote-amount.js';
|
|
8
6
|
const logger = createLogger('unchained:core-payment:cryptopay');
|
|
9
7
|
const { CRYPTOPAY_SECRET, CRYPTOPAY_BTC_XPUB, CRYPTOPAY_ETH_XPUB } = process.env;
|
|
10
|
-
const resolvePath = (prefix) => {
|
|
11
|
-
if (prefix === 'x')
|
|
12
|
-
return `m/44'/0'`;
|
|
13
|
-
if (prefix === 'y')
|
|
14
|
-
return `m/49'/0'`;
|
|
15
|
-
if (prefix === 'z')
|
|
16
|
-
return `m/84'/0'`;
|
|
17
|
-
if (prefix === 't')
|
|
18
|
-
return `m/44'/1'`;
|
|
19
|
-
if (prefix === 'u')
|
|
20
|
-
return `m/49'/1'`;
|
|
21
|
-
if (prefix === 'v')
|
|
22
|
-
return `m/84'/1'`;
|
|
23
|
-
return `m`;
|
|
24
|
-
};
|
|
25
|
-
const resolveNetwork = (prefix) => {
|
|
26
|
-
if (['x', 'y', 'z'].includes(prefix))
|
|
27
|
-
return networks.bitcoin;
|
|
28
|
-
return networks.testnet;
|
|
29
|
-
};
|
|
30
|
-
function convertExtendedPublicKey(z) {
|
|
31
|
-
const derivationPath = resolvePath(z.slice(0, 1));
|
|
32
|
-
const network = resolveNetwork(z.slice(0, 1));
|
|
33
|
-
// https://github.com/satoshilabs/slips/blob/master/slip-0132.md
|
|
34
|
-
let data = bs58check.decode(z);
|
|
35
|
-
data = data.slice(4);
|
|
36
|
-
data = Buffer.concat([Buffer.from('0488b21e', 'hex'), data]);
|
|
37
|
-
return {
|
|
38
|
-
xpub: bs58check.encode(data),
|
|
39
|
-
network,
|
|
40
|
-
derivationPath,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
8
|
var CryptopayCurrencies;
|
|
44
9
|
(function (CryptopayCurrencies) {
|
|
45
10
|
CryptopayCurrencies["BTC"] = "BTC";
|
|
@@ -59,7 +24,7 @@ const Cryptopay = {
|
|
|
59
24
|
const originCurrencyObj = await modules.currencies.findCurrency({ isoCode: currencyCode });
|
|
60
25
|
const updatedAddresses = await Promise.all(existingAddresses.map(async (addressData) => {
|
|
61
26
|
const targetCurrencyObj = await modules.currencies.findCurrency({
|
|
62
|
-
isoCode: addressData.
|
|
27
|
+
isoCode: addressData.currencyCode,
|
|
63
28
|
});
|
|
64
29
|
if (!targetCurrencyObj?.isActive)
|
|
65
30
|
return null;
|
|
@@ -73,18 +38,18 @@ const Cryptopay = {
|
|
|
73
38
|
return updatedAddresses.filter(Boolean);
|
|
74
39
|
};
|
|
75
40
|
const updateTransactionsWithOrderPaymentId = async (orderPaymentId, cryptoAddresses) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
41
|
+
for (const cryptoAddress of cryptoAddresses) {
|
|
42
|
+
const { address, currencyCode } = cryptoAddress;
|
|
43
|
+
await modules.cryptopay.mapOrderPaymentToWalletAddress({
|
|
44
|
+
address,
|
|
45
|
+
currencyCode,
|
|
46
|
+
orderPaymentId,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
82
49
|
};
|
|
83
50
|
const adapterActions = {
|
|
84
51
|
...PaymentAdapter.actions(config, context),
|
|
85
|
-
// eslint-disable-next-line
|
|
86
52
|
configurationError() {
|
|
87
|
-
// eslint-disable-line
|
|
88
53
|
if (!CRYPTOPAY_SECRET) {
|
|
89
54
|
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
90
55
|
}
|
|
@@ -101,7 +66,7 @@ const Cryptopay = {
|
|
|
101
66
|
return true;
|
|
102
67
|
// if (
|
|
103
68
|
// !Object.values(CryptopayCurrencies).includes(
|
|
104
|
-
// context.order.
|
|
69
|
+
// context.order.currencyCode as CryptopayCurrencies,
|
|
105
70
|
// )
|
|
106
71
|
// )
|
|
107
72
|
// return false;
|
|
@@ -112,42 +77,35 @@ const Cryptopay = {
|
|
|
112
77
|
},
|
|
113
78
|
sign: async () => {
|
|
114
79
|
const { orderPayment, order } = context;
|
|
80
|
+
if (!orderPayment)
|
|
81
|
+
throw new Error('Payment Credential Registration is not yet supported for Cryptopay');
|
|
115
82
|
const existingAddresses = await modules.cryptopay.getWalletAddressesByOrderPaymentId(orderPayment._id);
|
|
116
83
|
if (existingAddresses.length) {
|
|
117
84
|
// Do not derive addresses a second time for order payment, return existing addresses
|
|
118
|
-
const existingAddressesWithNewExpiration = await setConversionRates(order.
|
|
85
|
+
const existingAddressesWithNewExpiration = await setConversionRates(order.currencyCode, existingAddresses.map(({ _id, currencyCode }) => ({
|
|
119
86
|
address: _id,
|
|
120
|
-
|
|
87
|
+
currencyCode,
|
|
121
88
|
})));
|
|
122
89
|
return JSON.stringify(existingAddressesWithNewExpiration);
|
|
123
90
|
}
|
|
124
91
|
const cryptoAddresses = [];
|
|
125
92
|
if (CRYPTOPAY_BTC_XPUB) {
|
|
126
|
-
const { xpub, network } = convertExtendedPublicKey(CRYPTOPAY_BTC_XPUB);
|
|
127
|
-
const bip32 = BIP32Factory(ecc);
|
|
128
|
-
const hardenedMaster = bip32.fromBase58(xpub, network);
|
|
129
93
|
const btcDerivationNumber = await modules.cryptopay.getNextDerivationNumber(CryptopayCurrencies.BTC);
|
|
130
|
-
const
|
|
94
|
+
const address = deriveBtcAddress(CRYPTOPAY_BTC_XPUB, btcDerivationNumber);
|
|
131
95
|
cryptoAddresses.push({
|
|
132
|
-
|
|
133
|
-
address
|
|
134
|
-
pubkey: child.publicKey,
|
|
135
|
-
network,
|
|
136
|
-
}).address,
|
|
96
|
+
currencyCode: CryptopayCurrencies.BTC,
|
|
97
|
+
address,
|
|
137
98
|
});
|
|
138
99
|
}
|
|
139
100
|
if (CRYPTOPAY_ETH_XPUB) {
|
|
140
|
-
// we neuter for security reasons, it's still quite complicated for most ethereum clients to show an appropriate
|
|
141
|
-
// xpub, that's why
|
|
142
|
-
const hdWallet = ethers.HDNodeWallet.fromExtendedKey(CRYPTOPAY_ETH_XPUB);
|
|
143
|
-
const hardenedMaster = 'neuter' in hdWallet ? hdWallet.neuter() : hdWallet;
|
|
144
101
|
const ethDerivationNumber = await modules.cryptopay.getNextDerivationNumber(CryptopayCurrencies.ETH);
|
|
102
|
+
const address = deriveEthAddress(CRYPTOPAY_ETH_XPUB, ethDerivationNumber);
|
|
145
103
|
cryptoAddresses.push({
|
|
146
|
-
|
|
147
|
-
address
|
|
104
|
+
currencyCode: CryptopayCurrencies.ETH,
|
|
105
|
+
address,
|
|
148
106
|
});
|
|
149
107
|
}
|
|
150
|
-
const cryptoAddressesWithExpiration = await setConversionRates(order.
|
|
108
|
+
const cryptoAddressesWithExpiration = await setConversionRates(order.currencyCode, cryptoAddresses);
|
|
151
109
|
await updateTransactionsWithOrderPaymentId(orderPayment._id, cryptoAddresses);
|
|
152
110
|
return JSON.stringify(cryptoAddressesWithExpiration);
|
|
153
111
|
},
|
|
@@ -157,17 +115,16 @@ const Cryptopay = {
|
|
|
157
115
|
const walletForOrderPayment = foundWalletsWithBalances.find((wallet) => BigInt(wallet.amount.toString()) > 0n);
|
|
158
116
|
const pricing = OrderPricingSheet({
|
|
159
117
|
calculation: order.calculation,
|
|
160
|
-
|
|
118
|
+
currencyCode: order.currencyCode,
|
|
161
119
|
});
|
|
162
120
|
const totalAmount = BigInt(pricing?.total({ useNetPrice: false }).amount);
|
|
163
|
-
if (walletForOrderPayment.
|
|
121
|
+
if (walletForOrderPayment.currencyCode !== order.currencyCode) {
|
|
164
122
|
const baseCurrency = await modules.currencies.findCurrency({
|
|
165
|
-
isoCode: walletForOrderPayment.
|
|
123
|
+
isoCode: walletForOrderPayment.currencyCode,
|
|
166
124
|
});
|
|
167
|
-
const quoteCurrency = await modules.currencies.findCurrency({ isoCode: order.
|
|
125
|
+
const quoteCurrency = await modules.currencies.findCurrency({ isoCode: order.currencyCode });
|
|
168
126
|
const { /* min, */ max } = await modules.products.prices.rates.getRateRange(baseCurrency, quoteCurrency, order.confirmed || new Date());
|
|
169
|
-
const convertedAmount =
|
|
170
|
-
10n ** (BigInt(walletForOrderPayment.decimals) - 9n);
|
|
127
|
+
const convertedAmount = denoteAmount(walletForOrderPayment.amount.toString(), walletForOrderPayment.decimals);
|
|
171
128
|
// Add a Promille 🍻
|
|
172
129
|
// const minAmount = parseFloat(convertedAmount.toString()) * min * 0.999;
|
|
173
130
|
const maxAmount = parseFloat(convertedAmount.toString()) * max * 1.001;
|
|
@@ -180,9 +137,7 @@ const Cryptopay = {
|
|
|
180
137
|
logger.info(`Cryptopay Plugin: Wallet ${walletForOrderPayment._id} balance too low (yet): ${maxAmount} < ${totalAmount}`);
|
|
181
138
|
}
|
|
182
139
|
if (walletForOrderPayment) {
|
|
183
|
-
|
|
184
|
-
const convertedAmount = BigInt(walletForOrderPayment.amount.toString()) /
|
|
185
|
-
10n ** (BigInt(walletForOrderPayment.decimals) - 9n); // All crypto native prices denoted with 8 decimals
|
|
140
|
+
const convertedAmount = denoteAmount(walletForOrderPayment.amount.toString(), walletForOrderPayment.decimals);
|
|
186
141
|
if (convertedAmount && convertedAmount >= totalAmount) {
|
|
187
142
|
return {
|
|
188
143
|
transactionId: walletForOrderPayment._id,
|
|
@@ -190,9 +145,8 @@ const Cryptopay = {
|
|
|
190
145
|
}
|
|
191
146
|
logger.info(`Cryptopay Plugin: Wallet ${walletForOrderPayment._id} balance too low (yet): ${convertedAmount} < ${totalAmount}`);
|
|
192
147
|
}
|
|
193
|
-
logger.info(`Cryptopay Plugin: No confirmed payments found for currency ${order.
|
|
194
|
-
/*
|
|
195
|
-
TODO:
|
|
148
|
+
logger.info(`Cryptopay Plugin: No confirmed payments found for currency ${order.currencyCode} and addresses ${JSON.stringify(foundWalletsWithBalances)}`);
|
|
149
|
+
/* TODO: Crypto Handling
|
|
196
150
|
|
|
197
151
|
1. Check that generated crypto addresses are unique and no order payments share the same crypto address, only repeat when derivations completely exhausted.
|
|
198
152
|
2. When derivation path get's close to "exhaustedness" (95%), send a special e-mail alert to tell the user should generate a new xpub.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,eAAe,EACf,YAAY,EACZ,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AACvD,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AACvD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,kCAAkC,CAAC,CAAC;AAEhE,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEjF,IAAK,mBAGJ;AAHD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