Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": {
"node": true,
"es2021": true,
"jest": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
"no-console": "warn"
}
}
3 changes: 2 additions & 1 deletion src/services/a2aService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

const { Agent } = require('../models/agent');
const logger = require('../utils/logger');

class A2AService {
constructor(walletService, db) {
Expand Down Expand Up @@ -94,7 +95,7 @@ class A2AService {
* @private
*/
_handleError(method, error) {
console.error(`A2AService.${method} error:`, error);
logger.error(`A2AService.${method} error:`, error);
return error instanceof Error ? error : new Error(error);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/services/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const crypto = require('crypto');
const MandateService = require('./mandate');
const logger = require('../utils/logger');

class AgentService {
constructor(database, config = {}) {
Expand Down Expand Up @@ -184,7 +185,7 @@ class AgentService {
* @private
*/
_handleError(method, error) {
console.error(`AgentService.${method} error:`, error);
logger.error(`AgentService.${method} error:`, error);
return error instanceof Error ? error : new Error(error);
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/services/mandate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

const jwt = require('jsonwebtoken');
const crypto = require('crypto');
const logger = require('../utils/logger');

class MandateService {
constructor(config = {}) {
Expand Down Expand Up @@ -107,7 +108,10 @@ class MandateService {
sub: agentDid,
nbf: Math.floor(Date.now() / 1000),
vc: {
'@context': ['https://www.w3.org/2018/credentials/v1'],
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://open-commerce-protocol.io/contexts/agent/v1'
],
type: ['VerifiableCredential', 'AgentAuthorityCredential'],
credentialSubject: {
id: agentDid,
Expand All @@ -119,6 +123,15 @@ class MandateService {

return jwt.sign(payload, this.signingKey, { algorithm: 'HS256' });
}

/**
* Handle and format errors
* @private
*/
_handleError(method, error) {
logger.error(`MandateService.${method} error:`, error);
return error instanceof Error ? error : new Error(error);
}
}

module.exports = MandateService;
3 changes: 2 additions & 1 deletion src/services/mobilePayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const TokenizationService = require('./tokenization');
const crypto = require('crypto');
const logger = require('../utils/logger');

class MobilePaymentService {
constructor(tokenizationService, walletService, config = {}) {
Expand Down Expand Up @@ -403,7 +404,7 @@ class MobilePaymentService {
* @private
*/
_handleError(method, error) {
console.error(`MobilePaymentService.${method} error:`, error);
logger.error(`MobilePaymentService.${method} error:`, error);
return error instanceof Error ? error : new Error(error);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/services/tokenization.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const axios = require('axios');
const crypto = require('crypto');
const MandateService = require('./mandate');
const logger = require('../utils/logger');

class TokenizationService {
constructor(config = {}) {
Expand Down Expand Up @@ -387,6 +388,8 @@ class TokenizationService {
* @private
*/
_handleError(error) {
logger.error('TokenizationService error:', error);

if (error.response) {
const { status, data } = error.response;
return new Error(
Expand Down
3 changes: 2 additions & 1 deletion src/services/ucp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

const Joi = require('joi');
const logger = require('../utils/logger');

class UCPService {
constructor(a2aService, config = {}) {
Expand Down Expand Up @@ -123,7 +124,7 @@ class UCPService {
* @private
*/
_handleError(method, error) {
console.error(`UCPService.${method} error:`, error);
logger.error(`UCPService.${method} error:`, error);
return error instanceof Error ? error : new Error(error);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/services/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

const crypto = require('crypto');
const logger = require('../utils/logger');

class WalletService {
constructor(database, config = {}) {
Expand Down Expand Up @@ -402,12 +403,12 @@ class WalletService {
try {
// This would integrate with a stored payment method
// For now, just log the event
console.log(`Auto top-up triggered for wallet ${walletId}. Current balance: ${currentBalance}`);
logger.info(`Auto top-up triggered for wallet ${walletId}. Current balance: ${currentBalance}`);

// You would implement actual top-up logic here
// Example: await this.addFunds({ walletId, amount: this.config.autoTopUp.amount, ... });
} catch (error) {
console.error('Auto top-up failed:', error);
logger.error('Auto top-up failed:', error);
}
}

Expand All @@ -424,7 +425,7 @@ class WalletService {
* @private
*/
_handleError(method, error) {
console.error(`WalletService.${method} error:`, error);
logger.error(`WalletService.${method} error:`, error);
return error instanceof Error ? error : new Error(error);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/services/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

const crypto = require('crypto');
const logger = require('../utils/logger');

class Web3Service {
constructor(tokenizationService) {
Expand Down Expand Up @@ -113,9 +114,9 @@ class Web3Service {
};

const tokenAddress = tokenAddresses[stablecoin];
if (!tokenAddress) throw new Error(`Unsupported stablecoin: ${stablecoin}`);
if (!tokenAddress) throw new Error(`Zero Trust Validation Failed: Unsupported stablecoin: ${stablecoin}`);

console.log(`x402: Executing ${stablecoin} settlement for ${amount} to ${to}...`);
logger.info(`x402: Executing ${stablecoin} settlement for ${amount} to ${to}...`);

// 1. Construct ERC20 transfer data (Simplified)
const txData = {
Expand Down Expand Up @@ -152,7 +153,7 @@ class Web3Service {
* @private
*/
_handleError(method, error) {
console.error(`Web3Service.${method} error:`, error);
logger.error(`Web3Service.${method} error:`, error);
return error instanceof Error ? error : new Error(error);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const logFormat = winston.format.combine(
const logger = winston.createLogger({
level: config.logging.level,
format: logFormat,
defaultMeta: { service: 'open-wallet' },
defaultMeta: { service: 'ocp-sdk' },
transports: []
});

Expand Down
Loading