@profullstack/coinpay 0.5.8 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profullstack/coinpay",
3
- "version": "0.5.8",
3
+ "version": "0.6.0",
4
4
  "description": "CoinPay SDK & CLI — Accept cryptocurrency payments (BTC, ETH, SOL, POL, BCH, USDC) with wallet and swap support",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -70,6 +70,39 @@ export function getCredential(client: CoinPayClient, credentialId: string): Prom
70
70
  export function verifyCredential(client: CoinPayClient, credential: { credential_id: string }): Promise<{ valid: boolean; reason?: string }>;
71
71
  export function getRevocationList(client: CoinPayClient): Promise<{ success: boolean; revoked_credentials: string[]; revocations: Array<Record<string, unknown>> }>;
72
72
 
73
+ // CPTL Phase 2
74
+
75
+ export type ActionCategory =
76
+ | 'economic.transaction' | 'economic.dispute' | 'economic.refund'
77
+ | 'productivity.task' | 'productivity.application' | 'productivity.completion'
78
+ | 'identity.profile_update' | 'identity.verification'
79
+ | 'social.post' | 'social.comment' | 'social.endorsement'
80
+ | 'compliance.incident' | 'compliance.violation';
81
+
82
+ export interface ActionReceiptInput extends ReceiptInput {
83
+ action_category?: ActionCategory;
84
+ action_type?: string;
85
+ }
86
+
87
+ export interface TrustVector {
88
+ E: number;
89
+ P: number;
90
+ B: number;
91
+ D: number;
92
+ R: number;
93
+ A: number;
94
+ C: number;
95
+ }
96
+
97
+ export interface TrustProfileResult {
98
+ trust_vector: TrustVector | null;
99
+ reputation: ReputationResult | null;
100
+ computed_at: string | null;
101
+ }
102
+
103
+ export function submitActionReceipt(client: CoinPayClient, receipt: ActionReceiptInput): Promise<{ success: boolean; receipt?: Record<string, unknown>; error?: string }>;
104
+ export function getTrustProfile(client: CoinPayClient, agentDid: string): Promise<TrustProfileResult>;
105
+
73
106
  export interface DidInfo {
74
107
  did: string;
75
108
  public_key: string;
package/src/reputation.js CHANGED
@@ -123,6 +123,54 @@ export async function getReceipts(client, did) {
123
123
  return client.request(`/reputation/receipts?did=${encodeURIComponent(did)}`);
124
124
  }
125
125
 
126
+ // ═══════════════════════════════════════════════════════════
127
+ // CPTL Phase 2 — Action Receipts & Trust Profile
128
+ // ═══════════════════════════════════════════════════════════
129
+
130
+ const CANONICAL_CATEGORIES = [
131
+ 'economic.transaction', 'economic.dispute', 'economic.refund',
132
+ 'productivity.task', 'productivity.application', 'productivity.completion',
133
+ 'identity.profile_update', 'identity.verification',
134
+ 'social.post', 'social.comment', 'social.endorsement',
135
+ 'compliance.incident', 'compliance.violation',
136
+ ];
137
+
138
+ /**
139
+ * Submit an action receipt with schema validation
140
+ * @param {import('./client.js').CoinPayClient} client
141
+ * @param {Object} receipt - Action receipt with action_category
142
+ * @returns {Promise<Object>}
143
+ */
144
+ export async function submitActionReceipt(client, receipt) {
145
+ // Validate action_category if provided
146
+ if (receipt.action_category && !CANONICAL_CATEGORIES.includes(receipt.action_category)) {
147
+ throw new Error(`Invalid action_category: ${receipt.action_category}. Must be one of: ${CANONICAL_CATEGORIES.join(', ')}`);
148
+ }
149
+ // Default action_category
150
+ if (!receipt.action_category) {
151
+ receipt = { ...receipt, action_category: 'economic.transaction' };
152
+ }
153
+ return client.request('/reputation/receipt', {
154
+ method: 'POST',
155
+ body: JSON.stringify(receipt),
156
+ });
157
+ }
158
+
159
+ /**
160
+ * Get trust profile (trust vector) for an agent DID
161
+ * @param {import('./client.js').CoinPayClient} client
162
+ * @param {string} agentDid
163
+ * @returns {Promise<Object>} Trust vector { E, P, B, D, R, A, C }
164
+ */
165
+ export async function getTrustProfile(client, agentDid) {
166
+ const result = await client.request(`/reputation/agent/${encodeURIComponent(agentDid)}/reputation`);
167
+ return {
168
+ trust_vector: result.trust_vector || null,
169
+ reputation: result.reputation || null,
170
+ computed_at: result.computed_at || null,
171
+ };
172
+ }
173
+
126
174
  /**
127
175
  * Get the badge URL for a DID
128
176
  * @param {string} baseUrl - The CoinPayPortal base URL