veilreceipt-sdk 1.0.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/README.md +127 -0
- package/dist/index.d.mts +366 -0
- package/dist/index.d.ts +366 -0
- package/dist/index.js +260 -0
- package/dist/index.mjs +234 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# @veilreceipt/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for integrating **VeilReceipt** — private, ZK-powered payments on Aleo — into any application.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @veilreceipt/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { VeilReceipt } from '@veilreceipt/sdk';
|
|
15
|
+
|
|
16
|
+
const veil = new VeilReceipt({
|
|
17
|
+
baseUrl: 'https://api.veilreceipt.com',
|
|
18
|
+
apiKey: 'vr_live_...',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Resolve a payment link
|
|
22
|
+
const link = await veil.resolvePaymentLink('a1b2c3d4');
|
|
23
|
+
console.log(link.label, link.amount, link.currency);
|
|
24
|
+
|
|
25
|
+
// Get a payment session
|
|
26
|
+
const session = await veil.getPaymentSession('sess_abc123');
|
|
27
|
+
|
|
28
|
+
// Verify a purchase on-chain
|
|
29
|
+
const result = await veil.verifyPurchase('field1234...');
|
|
30
|
+
console.log(result.on_chain_verified);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- **Payment Sessions** — Create and complete checkout sessions
|
|
36
|
+
- **Payment Links** — Shareable one-time, recurring, or open-amount payment links
|
|
37
|
+
- **Products** — CRUD operations for merchant product catalog
|
|
38
|
+
- **Receipts** — Store and retrieve ZK receipt metadata
|
|
39
|
+
- **Escrow** — Built-in escrow with buyer protection
|
|
40
|
+
- **On-chain Verification** — Verify purchases on Aleo testnet
|
|
41
|
+
- **Delegated Proving** — Submit transitions for server-side proof generation
|
|
42
|
+
- **API Keys & Webhooks** — Full merchant integration management
|
|
43
|
+
|
|
44
|
+
## Payment Links
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// Create a payment link (merchant auth required)
|
|
48
|
+
const link = await veil.createPaymentLink({
|
|
49
|
+
link_hash: 'abc123...',
|
|
50
|
+
amount: 5_000_000, // microcredits
|
|
51
|
+
currency: 'credits',
|
|
52
|
+
link_type: 'recurring',
|
|
53
|
+
label: 'Monthly Subscription',
|
|
54
|
+
description: 'Pay monthly',
|
|
55
|
+
tx_id: 'at1...',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Resolve by hash (public, no auth)
|
|
59
|
+
const publicLink = await veil.resolvePaymentLink('abc123...');
|
|
60
|
+
|
|
61
|
+
// Record fulfillment
|
|
62
|
+
await veil.fulfillPaymentLink(link.id, {
|
|
63
|
+
link_id: link.id,
|
|
64
|
+
purchase_commitment: 'field...',
|
|
65
|
+
buyer_address_hash: 'hash...',
|
|
66
|
+
amount: 5_000_000,
|
|
67
|
+
tx_id: 'at1...',
|
|
68
|
+
payment_mode: 'private',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Close a link
|
|
72
|
+
await veil.closePaymentLink(link.id);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Escrow
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// Create escrow
|
|
79
|
+
const escrow = await veil.createEscrow({
|
|
80
|
+
purchaseCommitment: 'field...',
|
|
81
|
+
buyerAddress: 'aleo1...',
|
|
82
|
+
merchantAddress: 'aleo1...',
|
|
83
|
+
total: 10_000_000,
|
|
84
|
+
txId: 'at1...',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Complete or refund
|
|
88
|
+
await veil.resolveEscrow(escrow.escrow.id, 'complete', 'at1...');
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Webhooks
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// Register a webhook
|
|
95
|
+
const wh = await veil.createWebhook(
|
|
96
|
+
'https://yourserver.com/webhooks/veil',
|
|
97
|
+
['payment.confirmed', 'link.fulfilled', 'escrow.resolved']
|
|
98
|
+
);
|
|
99
|
+
console.log('Signing secret:', wh.signing_secret);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Error Handling
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { VeilReceipt, VeilReceiptError } from '@veilreceipt/sdk';
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
await veil.getPaymentSession('invalid');
|
|
109
|
+
} catch (err) {
|
|
110
|
+
if (err instanceof VeilReceiptError) {
|
|
111
|
+
console.error(`API Error ${err.status}: ${err.message}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Configuration
|
|
117
|
+
|
|
118
|
+
| Option | Type | Default | Description |
|
|
119
|
+
| --------- | -------- | ------- | ------------------------------------ |
|
|
120
|
+
| `baseUrl` | `string` | — | VeilReceipt API base URL (required) |
|
|
121
|
+
| `apiKey` | `string` | — | API key from merchant dashboard |
|
|
122
|
+
| `token` | `string` | — | JWT token for session auth |
|
|
123
|
+
| `timeout` | `number` | 30000 | Request timeout in milliseconds |
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
type AleoAddress = string;
|
|
2
|
+
type AleoField = string;
|
|
3
|
+
type AleoTransactionId = string;
|
|
4
|
+
interface PaymentSession {
|
|
5
|
+
id: string;
|
|
6
|
+
amount: number;
|
|
7
|
+
currency: 'credits' | 'usdcx' | 'usad';
|
|
8
|
+
description: string;
|
|
9
|
+
status: string;
|
|
10
|
+
merchant_address: AleoAddress;
|
|
11
|
+
payment_mode: string | null;
|
|
12
|
+
tx_id: string | null;
|
|
13
|
+
redirect_url: string | null;
|
|
14
|
+
cancel_url: string | null;
|
|
15
|
+
expires_at: string;
|
|
16
|
+
}
|
|
17
|
+
interface CompleteSessionParams {
|
|
18
|
+
purchase_commitment: string;
|
|
19
|
+
tx_id: string;
|
|
20
|
+
payment_mode: 'private' | 'public' | 'escrow';
|
|
21
|
+
buyer_address?: string;
|
|
22
|
+
}
|
|
23
|
+
interface SessionResult {
|
|
24
|
+
success: boolean;
|
|
25
|
+
session_id: string;
|
|
26
|
+
redirect_url: string | null;
|
|
27
|
+
}
|
|
28
|
+
interface PaymentLink {
|
|
29
|
+
id: string;
|
|
30
|
+
merchant_id: string;
|
|
31
|
+
merchant_address: AleoAddress;
|
|
32
|
+
link_hash: string;
|
|
33
|
+
amount: number;
|
|
34
|
+
currency: 'credits' | 'usdcx' | 'usad';
|
|
35
|
+
link_type: 'one_time' | 'recurring' | 'open';
|
|
36
|
+
label: string;
|
|
37
|
+
description: string;
|
|
38
|
+
is_active: boolean;
|
|
39
|
+
total_contributions: number;
|
|
40
|
+
total_collected: number;
|
|
41
|
+
tx_id: string;
|
|
42
|
+
created_at: string;
|
|
43
|
+
}
|
|
44
|
+
interface PaymentLinkPublic {
|
|
45
|
+
id: string;
|
|
46
|
+
merchant_address: AleoAddress;
|
|
47
|
+
link_hash: string;
|
|
48
|
+
amount: number;
|
|
49
|
+
currency: 'credits' | 'usdcx' | 'usad';
|
|
50
|
+
link_type: 'one_time' | 'recurring' | 'open';
|
|
51
|
+
label: string;
|
|
52
|
+
description: string;
|
|
53
|
+
is_active: boolean;
|
|
54
|
+
total_contributions: number;
|
|
55
|
+
}
|
|
56
|
+
interface CreatePaymentLinkParams {
|
|
57
|
+
link_hash: string;
|
|
58
|
+
amount: number;
|
|
59
|
+
currency: 'credits' | 'usdcx' | 'usad';
|
|
60
|
+
link_type: 'one_time' | 'recurring' | 'open';
|
|
61
|
+
label: string;
|
|
62
|
+
description: string;
|
|
63
|
+
tx_id: string;
|
|
64
|
+
}
|
|
65
|
+
interface FulfillLinkParams {
|
|
66
|
+
link_id: string;
|
|
67
|
+
purchase_commitment: string;
|
|
68
|
+
buyer_address_hash: string;
|
|
69
|
+
amount: number;
|
|
70
|
+
tx_id: string;
|
|
71
|
+
payment_mode: 'private' | 'escrow';
|
|
72
|
+
}
|
|
73
|
+
interface Product {
|
|
74
|
+
id: string;
|
|
75
|
+
merchant_id: string;
|
|
76
|
+
merchant_address: AleoAddress;
|
|
77
|
+
name: string;
|
|
78
|
+
description: string;
|
|
79
|
+
price: number;
|
|
80
|
+
price_type: 'credits' | 'usdcx' | 'usad';
|
|
81
|
+
sku: string;
|
|
82
|
+
image_url?: string;
|
|
83
|
+
category?: string;
|
|
84
|
+
in_stock: boolean;
|
|
85
|
+
created_at: string;
|
|
86
|
+
}
|
|
87
|
+
interface CreateProductParams {
|
|
88
|
+
name: string;
|
|
89
|
+
description: string;
|
|
90
|
+
price: number;
|
|
91
|
+
price_type: 'credits' | 'usdcx' | 'usad';
|
|
92
|
+
sku: string;
|
|
93
|
+
imageUrl?: string;
|
|
94
|
+
category?: string;
|
|
95
|
+
}
|
|
96
|
+
interface Receipt {
|
|
97
|
+
id: string;
|
|
98
|
+
purchase_commitment: string;
|
|
99
|
+
buyer_address_hash: string;
|
|
100
|
+
merchant_address_hash: string;
|
|
101
|
+
total: number;
|
|
102
|
+
token_type: number;
|
|
103
|
+
cart_commitment: string;
|
|
104
|
+
tx_id: string;
|
|
105
|
+
status: string;
|
|
106
|
+
created_at: string;
|
|
107
|
+
}
|
|
108
|
+
interface Escrow {
|
|
109
|
+
id: string;
|
|
110
|
+
purchase_commitment: string;
|
|
111
|
+
buyer_address_hash: string;
|
|
112
|
+
merchant_address_hash: string;
|
|
113
|
+
total: number;
|
|
114
|
+
status: 'active' | 'completed' | 'refunded';
|
|
115
|
+
escrow_tx_id: string;
|
|
116
|
+
resolve_tx_id: string;
|
|
117
|
+
created_block: number;
|
|
118
|
+
created_at: string;
|
|
119
|
+
}
|
|
120
|
+
interface StoreReceiptParams {
|
|
121
|
+
txId: string;
|
|
122
|
+
onChainTxId?: string;
|
|
123
|
+
merchantAddress: string;
|
|
124
|
+
buyerAddress: string;
|
|
125
|
+
total: number;
|
|
126
|
+
tokenType?: 'credits' | 'usdcx' | 'usad';
|
|
127
|
+
purchaseType?: 'private' | 'public' | 'escrow';
|
|
128
|
+
status?: 'confirmed' | 'escrowed';
|
|
129
|
+
cartCommitment?: string;
|
|
130
|
+
timestamp?: number;
|
|
131
|
+
blockHeight?: number;
|
|
132
|
+
items?: {
|
|
133
|
+
sku: string;
|
|
134
|
+
quantity: number;
|
|
135
|
+
price: number;
|
|
136
|
+
}[];
|
|
137
|
+
}
|
|
138
|
+
interface VerificationResult {
|
|
139
|
+
commitment: string;
|
|
140
|
+
on_chain_verified: boolean;
|
|
141
|
+
receipt: {
|
|
142
|
+
total: number;
|
|
143
|
+
token_type: number;
|
|
144
|
+
status: string;
|
|
145
|
+
tx_id: string;
|
|
146
|
+
} | null;
|
|
147
|
+
}
|
|
148
|
+
interface ApiKey {
|
|
149
|
+
id: string;
|
|
150
|
+
prefix: string;
|
|
151
|
+
label: string;
|
|
152
|
+
permissions: string[];
|
|
153
|
+
is_active: boolean;
|
|
154
|
+
last_used_at: string | null;
|
|
155
|
+
created_at: string;
|
|
156
|
+
}
|
|
157
|
+
interface Webhook {
|
|
158
|
+
id: string;
|
|
159
|
+
url: string;
|
|
160
|
+
events: string[];
|
|
161
|
+
is_active: boolean;
|
|
162
|
+
failure_count: number;
|
|
163
|
+
created_at: string;
|
|
164
|
+
}
|
|
165
|
+
interface ProvingHealth {
|
|
166
|
+
dps_configured: boolean;
|
|
167
|
+
sponsor_configured: boolean;
|
|
168
|
+
program_id: string;
|
|
169
|
+
network: string;
|
|
170
|
+
}
|
|
171
|
+
interface DelegateProofParams {
|
|
172
|
+
transition: string;
|
|
173
|
+
inputs: string[];
|
|
174
|
+
fee_record?: string;
|
|
175
|
+
}
|
|
176
|
+
interface TxStatus {
|
|
177
|
+
txId: string;
|
|
178
|
+
status: 'confirmed' | 'pending' | 'failed' | 'not_found';
|
|
179
|
+
blockHeight?: number;
|
|
180
|
+
}
|
|
181
|
+
interface VeilReceiptConfig {
|
|
182
|
+
/** Base URL of the VeilReceipt backend API */
|
|
183
|
+
baseUrl: string;
|
|
184
|
+
/** API key for authentication (from merchant dashboard) */
|
|
185
|
+
apiKey?: string;
|
|
186
|
+
/** JWT token for session-based auth */
|
|
187
|
+
token?: string;
|
|
188
|
+
/** Request timeout in ms (default: 30000) */
|
|
189
|
+
timeout?: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare class VeilReceiptError extends Error {
|
|
193
|
+
readonly status: number;
|
|
194
|
+
readonly code?: string | undefined;
|
|
195
|
+
constructor(message: string, status: number, code?: string | undefined);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* VeilReceipt SDK Client
|
|
200
|
+
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* import { VeilReceipt } from '@veilreceipt/sdk';
|
|
203
|
+
*
|
|
204
|
+
* const veil = new VeilReceipt({
|
|
205
|
+
* baseUrl: 'https://api.veilreceipt.com',
|
|
206
|
+
* apiKey: 'vr_live_...',
|
|
207
|
+
* });
|
|
208
|
+
*
|
|
209
|
+
* // Get a payment session
|
|
210
|
+
* const session = await veil.getPaymentSession('sess_abc123');
|
|
211
|
+
*
|
|
212
|
+
* // Resolve a payment link
|
|
213
|
+
* const link = await veil.resolvePaymentLink('a1b2c3d4');
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare class VeilReceipt {
|
|
217
|
+
private baseUrl;
|
|
218
|
+
private apiKey?;
|
|
219
|
+
private token?;
|
|
220
|
+
private timeout;
|
|
221
|
+
constructor(config: VeilReceiptConfig);
|
|
222
|
+
/** Update the auth token (e.g. after login) */
|
|
223
|
+
setToken(token: string | null): void;
|
|
224
|
+
/** Update the API key */
|
|
225
|
+
setApiKey(key: string | null): void;
|
|
226
|
+
private request;
|
|
227
|
+
/** Check API health */
|
|
228
|
+
health(): Promise<{
|
|
229
|
+
status: string;
|
|
230
|
+
timestamp: string;
|
|
231
|
+
}>;
|
|
232
|
+
/** Get details of a payment session */
|
|
233
|
+
getPaymentSession(sessionId: string): Promise<PaymentSession>;
|
|
234
|
+
/** Complete a payment session after on-chain tx */
|
|
235
|
+
completePaymentSession(sessionId: string, params: CompleteSessionParams): Promise<SessionResult>;
|
|
236
|
+
/** Create a new payment link (requires merchant auth) */
|
|
237
|
+
createPaymentLink(params: CreatePaymentLinkParams): Promise<PaymentLink>;
|
|
238
|
+
/** List payment links for the authenticated merchant */
|
|
239
|
+
listPaymentLinks(): Promise<PaymentLink[]>;
|
|
240
|
+
/** Resolve a payment link by its public hash (no auth required) */
|
|
241
|
+
resolvePaymentLink(hash: string): Promise<PaymentLinkPublic>;
|
|
242
|
+
/** Get a specific payment link by ID */
|
|
243
|
+
getPaymentLink(id: string): Promise<PaymentLink>;
|
|
244
|
+
/** Record a link fulfillment after on-chain tx */
|
|
245
|
+
fulfillPaymentLink(id: string, params: FulfillLinkParams): Promise<{
|
|
246
|
+
success: boolean;
|
|
247
|
+
}>;
|
|
248
|
+
/** Close/deactivate a payment link (merchant only) */
|
|
249
|
+
closePaymentLink(id: string): Promise<{
|
|
250
|
+
success: boolean;
|
|
251
|
+
}>;
|
|
252
|
+
/** List products, optionally filtered */
|
|
253
|
+
getProducts(filters?: {
|
|
254
|
+
merchant?: string;
|
|
255
|
+
category?: string;
|
|
256
|
+
inStock?: boolean;
|
|
257
|
+
}): Promise<{
|
|
258
|
+
products: Product[];
|
|
259
|
+
}>;
|
|
260
|
+
/** Get a single product by ID */
|
|
261
|
+
getProduct(id: string): Promise<{
|
|
262
|
+
product: Product;
|
|
263
|
+
}>;
|
|
264
|
+
/** Create a product (merchant auth required) */
|
|
265
|
+
createProduct(params: CreateProductParams): Promise<{
|
|
266
|
+
product: Product;
|
|
267
|
+
}>;
|
|
268
|
+
/** Update a product (merchant auth required) */
|
|
269
|
+
updateProduct(id: string, params: Partial<{
|
|
270
|
+
name: string;
|
|
271
|
+
description: string;
|
|
272
|
+
price: number;
|
|
273
|
+
imageUrl: string;
|
|
274
|
+
category: string;
|
|
275
|
+
inStock: boolean;
|
|
276
|
+
}>): Promise<{
|
|
277
|
+
product: Product;
|
|
278
|
+
}>;
|
|
279
|
+
/** Delete a product (merchant auth required) */
|
|
280
|
+
deleteProduct(id: string): Promise<{
|
|
281
|
+
success: boolean;
|
|
282
|
+
}>;
|
|
283
|
+
/** Store receipt metadata */
|
|
284
|
+
storeReceipt(params: StoreReceiptParams): Promise<{
|
|
285
|
+
receipt: Receipt;
|
|
286
|
+
}>;
|
|
287
|
+
/** Get all receipts for authenticated user */
|
|
288
|
+
getReceipts(): Promise<{
|
|
289
|
+
receipts: Receipt[];
|
|
290
|
+
count: number;
|
|
291
|
+
}>;
|
|
292
|
+
/** Get receipts by buyer address */
|
|
293
|
+
getReceiptsByBuyer(address: string): Promise<{
|
|
294
|
+
receipts: Receipt[];
|
|
295
|
+
count: number;
|
|
296
|
+
}>;
|
|
297
|
+
/** Get a receipt by transaction ID */
|
|
298
|
+
getReceiptByTxId(txId: string): Promise<{
|
|
299
|
+
receipt: Receipt;
|
|
300
|
+
}>;
|
|
301
|
+
/** Create an escrow record */
|
|
302
|
+
createEscrow(params: {
|
|
303
|
+
purchaseCommitment: string;
|
|
304
|
+
buyerAddress: string;
|
|
305
|
+
merchantAddress: string;
|
|
306
|
+
total: number;
|
|
307
|
+
txId: string;
|
|
308
|
+
}): Promise<{
|
|
309
|
+
escrow: Escrow;
|
|
310
|
+
}>;
|
|
311
|
+
/** Resolve an escrow (complete or refund) */
|
|
312
|
+
resolveEscrow(id: string, action: 'complete' | 'refund', txId: string): Promise<{
|
|
313
|
+
escrow: Escrow;
|
|
314
|
+
}>;
|
|
315
|
+
/** Get escrows for authenticated user */
|
|
316
|
+
getMyEscrows(): Promise<{
|
|
317
|
+
escrows: Escrow[];
|
|
318
|
+
}>;
|
|
319
|
+
/** Verify a purchase commitment on-chain */
|
|
320
|
+
verifyPurchase(commitment: string): Promise<VerificationResult>;
|
|
321
|
+
/** Check transaction status on-chain */
|
|
322
|
+
getTransactionStatus(txId: string): Promise<TxStatus>;
|
|
323
|
+
/** Get current chain block height */
|
|
324
|
+
getChainHeight(): Promise<{
|
|
325
|
+
height: number;
|
|
326
|
+
}>;
|
|
327
|
+
/** Create an API key */
|
|
328
|
+
createApiKey(label: string, permissions: string[]): Promise<ApiKey & {
|
|
329
|
+
key: string;
|
|
330
|
+
warning: string;
|
|
331
|
+
}>;
|
|
332
|
+
/** List API keys */
|
|
333
|
+
listApiKeys(): Promise<{
|
|
334
|
+
keys: ApiKey[];
|
|
335
|
+
}>;
|
|
336
|
+
/** Revoke an API key */
|
|
337
|
+
revokeApiKey(id: string): Promise<{
|
|
338
|
+
success: boolean;
|
|
339
|
+
}>;
|
|
340
|
+
/** Create a webhook */
|
|
341
|
+
createWebhook(url: string, events: string[]): Promise<Webhook & {
|
|
342
|
+
signing_secret: string;
|
|
343
|
+
warning: string;
|
|
344
|
+
}>;
|
|
345
|
+
/** List webhooks */
|
|
346
|
+
listWebhooks(): Promise<{
|
|
347
|
+
webhooks: Webhook[];
|
|
348
|
+
}>;
|
|
349
|
+
/** Delete a webhook */
|
|
350
|
+
deleteWebhook(id: string): Promise<{
|
|
351
|
+
success: boolean;
|
|
352
|
+
}>;
|
|
353
|
+
/** Check proving service health */
|
|
354
|
+
getProvingHealth(): Promise<ProvingHealth>;
|
|
355
|
+
/** Submit a transition for delegated proving */
|
|
356
|
+
submitDelegatedProof(params: DelegateProofParams): Promise<{
|
|
357
|
+
proof_id: string;
|
|
358
|
+
}>;
|
|
359
|
+
/** Check delegated proof status */
|
|
360
|
+
getProvingStatus(proofId: string): Promise<{
|
|
361
|
+
status: string;
|
|
362
|
+
tx_id?: string;
|
|
363
|
+
}>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export { type AleoAddress, type AleoField, type AleoTransactionId, type ApiKey, type CompleteSessionParams, type CreatePaymentLinkParams, type CreateProductParams, type DelegateProofParams, type Escrow, type FulfillLinkParams, type PaymentLink, type PaymentLinkPublic, type PaymentSession, type Product, type ProvingHealth, type Receipt, type SessionResult, type StoreReceiptParams, type TxStatus, VeilReceipt, type VeilReceiptConfig, VeilReceiptError, type VerificationResult, type Webhook };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
type AleoAddress = string;
|
|
2
|
+
type AleoField = string;
|
|
3
|
+
type AleoTransactionId = string;
|
|
4
|
+
interface PaymentSession {
|
|
5
|
+
id: string;
|
|
6
|
+
amount: number;
|
|
7
|
+
currency: 'credits' | 'usdcx' | 'usad';
|
|
8
|
+
description: string;
|
|
9
|
+
status: string;
|
|
10
|
+
merchant_address: AleoAddress;
|
|
11
|
+
payment_mode: string | null;
|
|
12
|
+
tx_id: string | null;
|
|
13
|
+
redirect_url: string | null;
|
|
14
|
+
cancel_url: string | null;
|
|
15
|
+
expires_at: string;
|
|
16
|
+
}
|
|
17
|
+
interface CompleteSessionParams {
|
|
18
|
+
purchase_commitment: string;
|
|
19
|
+
tx_id: string;
|
|
20
|
+
payment_mode: 'private' | 'public' | 'escrow';
|
|
21
|
+
buyer_address?: string;
|
|
22
|
+
}
|
|
23
|
+
interface SessionResult {
|
|
24
|
+
success: boolean;
|
|
25
|
+
session_id: string;
|
|
26
|
+
redirect_url: string | null;
|
|
27
|
+
}
|
|
28
|
+
interface PaymentLink {
|
|
29
|
+
id: string;
|
|
30
|
+
merchant_id: string;
|
|
31
|
+
merchant_address: AleoAddress;
|
|
32
|
+
link_hash: string;
|
|
33
|
+
amount: number;
|
|
34
|
+
currency: 'credits' | 'usdcx' | 'usad';
|
|
35
|
+
link_type: 'one_time' | 'recurring' | 'open';
|
|
36
|
+
label: string;
|
|
37
|
+
description: string;
|
|
38
|
+
is_active: boolean;
|
|
39
|
+
total_contributions: number;
|
|
40
|
+
total_collected: number;
|
|
41
|
+
tx_id: string;
|
|
42
|
+
created_at: string;
|
|
43
|
+
}
|
|
44
|
+
interface PaymentLinkPublic {
|
|
45
|
+
id: string;
|
|
46
|
+
merchant_address: AleoAddress;
|
|
47
|
+
link_hash: string;
|
|
48
|
+
amount: number;
|
|
49
|
+
currency: 'credits' | 'usdcx' | 'usad';
|
|
50
|
+
link_type: 'one_time' | 'recurring' | 'open';
|
|
51
|
+
label: string;
|
|
52
|
+
description: string;
|
|
53
|
+
is_active: boolean;
|
|
54
|
+
total_contributions: number;
|
|
55
|
+
}
|
|
56
|
+
interface CreatePaymentLinkParams {
|
|
57
|
+
link_hash: string;
|
|
58
|
+
amount: number;
|
|
59
|
+
currency: 'credits' | 'usdcx' | 'usad';
|
|
60
|
+
link_type: 'one_time' | 'recurring' | 'open';
|
|
61
|
+
label: string;
|
|
62
|
+
description: string;
|
|
63
|
+
tx_id: string;
|
|
64
|
+
}
|
|
65
|
+
interface FulfillLinkParams {
|
|
66
|
+
link_id: string;
|
|
67
|
+
purchase_commitment: string;
|
|
68
|
+
buyer_address_hash: string;
|
|
69
|
+
amount: number;
|
|
70
|
+
tx_id: string;
|
|
71
|
+
payment_mode: 'private' | 'escrow';
|
|
72
|
+
}
|
|
73
|
+
interface Product {
|
|
74
|
+
id: string;
|
|
75
|
+
merchant_id: string;
|
|
76
|
+
merchant_address: AleoAddress;
|
|
77
|
+
name: string;
|
|
78
|
+
description: string;
|
|
79
|
+
price: number;
|
|
80
|
+
price_type: 'credits' | 'usdcx' | 'usad';
|
|
81
|
+
sku: string;
|
|
82
|
+
image_url?: string;
|
|
83
|
+
category?: string;
|
|
84
|
+
in_stock: boolean;
|
|
85
|
+
created_at: string;
|
|
86
|
+
}
|
|
87
|
+
interface CreateProductParams {
|
|
88
|
+
name: string;
|
|
89
|
+
description: string;
|
|
90
|
+
price: number;
|
|
91
|
+
price_type: 'credits' | 'usdcx' | 'usad';
|
|
92
|
+
sku: string;
|
|
93
|
+
imageUrl?: string;
|
|
94
|
+
category?: string;
|
|
95
|
+
}
|
|
96
|
+
interface Receipt {
|
|
97
|
+
id: string;
|
|
98
|
+
purchase_commitment: string;
|
|
99
|
+
buyer_address_hash: string;
|
|
100
|
+
merchant_address_hash: string;
|
|
101
|
+
total: number;
|
|
102
|
+
token_type: number;
|
|
103
|
+
cart_commitment: string;
|
|
104
|
+
tx_id: string;
|
|
105
|
+
status: string;
|
|
106
|
+
created_at: string;
|
|
107
|
+
}
|
|
108
|
+
interface Escrow {
|
|
109
|
+
id: string;
|
|
110
|
+
purchase_commitment: string;
|
|
111
|
+
buyer_address_hash: string;
|
|
112
|
+
merchant_address_hash: string;
|
|
113
|
+
total: number;
|
|
114
|
+
status: 'active' | 'completed' | 'refunded';
|
|
115
|
+
escrow_tx_id: string;
|
|
116
|
+
resolve_tx_id: string;
|
|
117
|
+
created_block: number;
|
|
118
|
+
created_at: string;
|
|
119
|
+
}
|
|
120
|
+
interface StoreReceiptParams {
|
|
121
|
+
txId: string;
|
|
122
|
+
onChainTxId?: string;
|
|
123
|
+
merchantAddress: string;
|
|
124
|
+
buyerAddress: string;
|
|
125
|
+
total: number;
|
|
126
|
+
tokenType?: 'credits' | 'usdcx' | 'usad';
|
|
127
|
+
purchaseType?: 'private' | 'public' | 'escrow';
|
|
128
|
+
status?: 'confirmed' | 'escrowed';
|
|
129
|
+
cartCommitment?: string;
|
|
130
|
+
timestamp?: number;
|
|
131
|
+
blockHeight?: number;
|
|
132
|
+
items?: {
|
|
133
|
+
sku: string;
|
|
134
|
+
quantity: number;
|
|
135
|
+
price: number;
|
|
136
|
+
}[];
|
|
137
|
+
}
|
|
138
|
+
interface VerificationResult {
|
|
139
|
+
commitment: string;
|
|
140
|
+
on_chain_verified: boolean;
|
|
141
|
+
receipt: {
|
|
142
|
+
total: number;
|
|
143
|
+
token_type: number;
|
|
144
|
+
status: string;
|
|
145
|
+
tx_id: string;
|
|
146
|
+
} | null;
|
|
147
|
+
}
|
|
148
|
+
interface ApiKey {
|
|
149
|
+
id: string;
|
|
150
|
+
prefix: string;
|
|
151
|
+
label: string;
|
|
152
|
+
permissions: string[];
|
|
153
|
+
is_active: boolean;
|
|
154
|
+
last_used_at: string | null;
|
|
155
|
+
created_at: string;
|
|
156
|
+
}
|
|
157
|
+
interface Webhook {
|
|
158
|
+
id: string;
|
|
159
|
+
url: string;
|
|
160
|
+
events: string[];
|
|
161
|
+
is_active: boolean;
|
|
162
|
+
failure_count: number;
|
|
163
|
+
created_at: string;
|
|
164
|
+
}
|
|
165
|
+
interface ProvingHealth {
|
|
166
|
+
dps_configured: boolean;
|
|
167
|
+
sponsor_configured: boolean;
|
|
168
|
+
program_id: string;
|
|
169
|
+
network: string;
|
|
170
|
+
}
|
|
171
|
+
interface DelegateProofParams {
|
|
172
|
+
transition: string;
|
|
173
|
+
inputs: string[];
|
|
174
|
+
fee_record?: string;
|
|
175
|
+
}
|
|
176
|
+
interface TxStatus {
|
|
177
|
+
txId: string;
|
|
178
|
+
status: 'confirmed' | 'pending' | 'failed' | 'not_found';
|
|
179
|
+
blockHeight?: number;
|
|
180
|
+
}
|
|
181
|
+
interface VeilReceiptConfig {
|
|
182
|
+
/** Base URL of the VeilReceipt backend API */
|
|
183
|
+
baseUrl: string;
|
|
184
|
+
/** API key for authentication (from merchant dashboard) */
|
|
185
|
+
apiKey?: string;
|
|
186
|
+
/** JWT token for session-based auth */
|
|
187
|
+
token?: string;
|
|
188
|
+
/** Request timeout in ms (default: 30000) */
|
|
189
|
+
timeout?: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare class VeilReceiptError extends Error {
|
|
193
|
+
readonly status: number;
|
|
194
|
+
readonly code?: string | undefined;
|
|
195
|
+
constructor(message: string, status: number, code?: string | undefined);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* VeilReceipt SDK Client
|
|
200
|
+
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* import { VeilReceipt } from '@veilreceipt/sdk';
|
|
203
|
+
*
|
|
204
|
+
* const veil = new VeilReceipt({
|
|
205
|
+
* baseUrl: 'https://api.veilreceipt.com',
|
|
206
|
+
* apiKey: 'vr_live_...',
|
|
207
|
+
* });
|
|
208
|
+
*
|
|
209
|
+
* // Get a payment session
|
|
210
|
+
* const session = await veil.getPaymentSession('sess_abc123');
|
|
211
|
+
*
|
|
212
|
+
* // Resolve a payment link
|
|
213
|
+
* const link = await veil.resolvePaymentLink('a1b2c3d4');
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare class VeilReceipt {
|
|
217
|
+
private baseUrl;
|
|
218
|
+
private apiKey?;
|
|
219
|
+
private token?;
|
|
220
|
+
private timeout;
|
|
221
|
+
constructor(config: VeilReceiptConfig);
|
|
222
|
+
/** Update the auth token (e.g. after login) */
|
|
223
|
+
setToken(token: string | null): void;
|
|
224
|
+
/** Update the API key */
|
|
225
|
+
setApiKey(key: string | null): void;
|
|
226
|
+
private request;
|
|
227
|
+
/** Check API health */
|
|
228
|
+
health(): Promise<{
|
|
229
|
+
status: string;
|
|
230
|
+
timestamp: string;
|
|
231
|
+
}>;
|
|
232
|
+
/** Get details of a payment session */
|
|
233
|
+
getPaymentSession(sessionId: string): Promise<PaymentSession>;
|
|
234
|
+
/** Complete a payment session after on-chain tx */
|
|
235
|
+
completePaymentSession(sessionId: string, params: CompleteSessionParams): Promise<SessionResult>;
|
|
236
|
+
/** Create a new payment link (requires merchant auth) */
|
|
237
|
+
createPaymentLink(params: CreatePaymentLinkParams): Promise<PaymentLink>;
|
|
238
|
+
/** List payment links for the authenticated merchant */
|
|
239
|
+
listPaymentLinks(): Promise<PaymentLink[]>;
|
|
240
|
+
/** Resolve a payment link by its public hash (no auth required) */
|
|
241
|
+
resolvePaymentLink(hash: string): Promise<PaymentLinkPublic>;
|
|
242
|
+
/** Get a specific payment link by ID */
|
|
243
|
+
getPaymentLink(id: string): Promise<PaymentLink>;
|
|
244
|
+
/** Record a link fulfillment after on-chain tx */
|
|
245
|
+
fulfillPaymentLink(id: string, params: FulfillLinkParams): Promise<{
|
|
246
|
+
success: boolean;
|
|
247
|
+
}>;
|
|
248
|
+
/** Close/deactivate a payment link (merchant only) */
|
|
249
|
+
closePaymentLink(id: string): Promise<{
|
|
250
|
+
success: boolean;
|
|
251
|
+
}>;
|
|
252
|
+
/** List products, optionally filtered */
|
|
253
|
+
getProducts(filters?: {
|
|
254
|
+
merchant?: string;
|
|
255
|
+
category?: string;
|
|
256
|
+
inStock?: boolean;
|
|
257
|
+
}): Promise<{
|
|
258
|
+
products: Product[];
|
|
259
|
+
}>;
|
|
260
|
+
/** Get a single product by ID */
|
|
261
|
+
getProduct(id: string): Promise<{
|
|
262
|
+
product: Product;
|
|
263
|
+
}>;
|
|
264
|
+
/** Create a product (merchant auth required) */
|
|
265
|
+
createProduct(params: CreateProductParams): Promise<{
|
|
266
|
+
product: Product;
|
|
267
|
+
}>;
|
|
268
|
+
/** Update a product (merchant auth required) */
|
|
269
|
+
updateProduct(id: string, params: Partial<{
|
|
270
|
+
name: string;
|
|
271
|
+
description: string;
|
|
272
|
+
price: number;
|
|
273
|
+
imageUrl: string;
|
|
274
|
+
category: string;
|
|
275
|
+
inStock: boolean;
|
|
276
|
+
}>): Promise<{
|
|
277
|
+
product: Product;
|
|
278
|
+
}>;
|
|
279
|
+
/** Delete a product (merchant auth required) */
|
|
280
|
+
deleteProduct(id: string): Promise<{
|
|
281
|
+
success: boolean;
|
|
282
|
+
}>;
|
|
283
|
+
/** Store receipt metadata */
|
|
284
|
+
storeReceipt(params: StoreReceiptParams): Promise<{
|
|
285
|
+
receipt: Receipt;
|
|
286
|
+
}>;
|
|
287
|
+
/** Get all receipts for authenticated user */
|
|
288
|
+
getReceipts(): Promise<{
|
|
289
|
+
receipts: Receipt[];
|
|
290
|
+
count: number;
|
|
291
|
+
}>;
|
|
292
|
+
/** Get receipts by buyer address */
|
|
293
|
+
getReceiptsByBuyer(address: string): Promise<{
|
|
294
|
+
receipts: Receipt[];
|
|
295
|
+
count: number;
|
|
296
|
+
}>;
|
|
297
|
+
/** Get a receipt by transaction ID */
|
|
298
|
+
getReceiptByTxId(txId: string): Promise<{
|
|
299
|
+
receipt: Receipt;
|
|
300
|
+
}>;
|
|
301
|
+
/** Create an escrow record */
|
|
302
|
+
createEscrow(params: {
|
|
303
|
+
purchaseCommitment: string;
|
|
304
|
+
buyerAddress: string;
|
|
305
|
+
merchantAddress: string;
|
|
306
|
+
total: number;
|
|
307
|
+
txId: string;
|
|
308
|
+
}): Promise<{
|
|
309
|
+
escrow: Escrow;
|
|
310
|
+
}>;
|
|
311
|
+
/** Resolve an escrow (complete or refund) */
|
|
312
|
+
resolveEscrow(id: string, action: 'complete' | 'refund', txId: string): Promise<{
|
|
313
|
+
escrow: Escrow;
|
|
314
|
+
}>;
|
|
315
|
+
/** Get escrows for authenticated user */
|
|
316
|
+
getMyEscrows(): Promise<{
|
|
317
|
+
escrows: Escrow[];
|
|
318
|
+
}>;
|
|
319
|
+
/** Verify a purchase commitment on-chain */
|
|
320
|
+
verifyPurchase(commitment: string): Promise<VerificationResult>;
|
|
321
|
+
/** Check transaction status on-chain */
|
|
322
|
+
getTransactionStatus(txId: string): Promise<TxStatus>;
|
|
323
|
+
/** Get current chain block height */
|
|
324
|
+
getChainHeight(): Promise<{
|
|
325
|
+
height: number;
|
|
326
|
+
}>;
|
|
327
|
+
/** Create an API key */
|
|
328
|
+
createApiKey(label: string, permissions: string[]): Promise<ApiKey & {
|
|
329
|
+
key: string;
|
|
330
|
+
warning: string;
|
|
331
|
+
}>;
|
|
332
|
+
/** List API keys */
|
|
333
|
+
listApiKeys(): Promise<{
|
|
334
|
+
keys: ApiKey[];
|
|
335
|
+
}>;
|
|
336
|
+
/** Revoke an API key */
|
|
337
|
+
revokeApiKey(id: string): Promise<{
|
|
338
|
+
success: boolean;
|
|
339
|
+
}>;
|
|
340
|
+
/** Create a webhook */
|
|
341
|
+
createWebhook(url: string, events: string[]): Promise<Webhook & {
|
|
342
|
+
signing_secret: string;
|
|
343
|
+
warning: string;
|
|
344
|
+
}>;
|
|
345
|
+
/** List webhooks */
|
|
346
|
+
listWebhooks(): Promise<{
|
|
347
|
+
webhooks: Webhook[];
|
|
348
|
+
}>;
|
|
349
|
+
/** Delete a webhook */
|
|
350
|
+
deleteWebhook(id: string): Promise<{
|
|
351
|
+
success: boolean;
|
|
352
|
+
}>;
|
|
353
|
+
/** Check proving service health */
|
|
354
|
+
getProvingHealth(): Promise<ProvingHealth>;
|
|
355
|
+
/** Submit a transition for delegated proving */
|
|
356
|
+
submitDelegatedProof(params: DelegateProofParams): Promise<{
|
|
357
|
+
proof_id: string;
|
|
358
|
+
}>;
|
|
359
|
+
/** Check delegated proof status */
|
|
360
|
+
getProvingStatus(proofId: string): Promise<{
|
|
361
|
+
status: string;
|
|
362
|
+
tx_id?: string;
|
|
363
|
+
}>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export { type AleoAddress, type AleoField, type AleoTransactionId, type ApiKey, type CompleteSessionParams, type CreatePaymentLinkParams, type CreateProductParams, type DelegateProofParams, type Escrow, type FulfillLinkParams, type PaymentLink, type PaymentLinkPublic, type PaymentSession, type Product, type ProvingHealth, type Receipt, type SessionResult, type StoreReceiptParams, type TxStatus, VeilReceipt, type VeilReceiptConfig, VeilReceiptError, type VerificationResult, type Webhook };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
VeilReceipt: () => VeilReceipt,
|
|
24
|
+
VeilReceiptError: () => VeilReceiptError
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var VeilReceiptError = class extends Error {
|
|
28
|
+
constructor(message, status, code) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.status = status;
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.name = "VeilReceiptError";
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var VeilReceipt = class {
|
|
36
|
+
constructor(config) {
|
|
37
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
38
|
+
this.apiKey = config.apiKey;
|
|
39
|
+
this.token = config.token;
|
|
40
|
+
this.timeout = config.timeout ?? 3e4;
|
|
41
|
+
}
|
|
42
|
+
/** Update the auth token (e.g. after login) */
|
|
43
|
+
setToken(token) {
|
|
44
|
+
this.token = token ?? void 0;
|
|
45
|
+
}
|
|
46
|
+
/** Update the API key */
|
|
47
|
+
setApiKey(key) {
|
|
48
|
+
this.apiKey = key ?? void 0;
|
|
49
|
+
}
|
|
50
|
+
// ───────────────────────────────────────
|
|
51
|
+
// Internal
|
|
52
|
+
// ───────────────────────────────────────
|
|
53
|
+
async request(method, path, body) {
|
|
54
|
+
const url = `${this.baseUrl}${path}`;
|
|
55
|
+
const headers = {
|
|
56
|
+
"Content-Type": "application/json"
|
|
57
|
+
};
|
|
58
|
+
if (this.apiKey) {
|
|
59
|
+
headers["X-API-Key"] = this.apiKey;
|
|
60
|
+
}
|
|
61
|
+
if (this.token) {
|
|
62
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
63
|
+
}
|
|
64
|
+
const controller = new AbortController();
|
|
65
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
66
|
+
try {
|
|
67
|
+
const res = await fetch(url, {
|
|
68
|
+
method,
|
|
69
|
+
headers,
|
|
70
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
71
|
+
signal: controller.signal
|
|
72
|
+
});
|
|
73
|
+
const data = await res.json();
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
throw new VeilReceiptError(
|
|
76
|
+
data.error || `Request failed: ${res.status}`,
|
|
77
|
+
res.status
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return data;
|
|
81
|
+
} finally {
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// ───────────────────────────────────────
|
|
86
|
+
// Health
|
|
87
|
+
// ───────────────────────────────────────
|
|
88
|
+
/** Check API health */
|
|
89
|
+
async health() {
|
|
90
|
+
return this.request("GET", "/health");
|
|
91
|
+
}
|
|
92
|
+
// ───────────────────────────────────────
|
|
93
|
+
// Payment Sessions
|
|
94
|
+
// ───────────────────────────────────────
|
|
95
|
+
/** Get details of a payment session */
|
|
96
|
+
async getPaymentSession(sessionId) {
|
|
97
|
+
return this.request("GET", `/integrate/payments/${encodeURIComponent(sessionId)}`);
|
|
98
|
+
}
|
|
99
|
+
/** Complete a payment session after on-chain tx */
|
|
100
|
+
async completePaymentSession(sessionId, params) {
|
|
101
|
+
return this.request("POST", `/integrate/payments/${encodeURIComponent(sessionId)}/complete`, params);
|
|
102
|
+
}
|
|
103
|
+
// ───────────────────────────────────────
|
|
104
|
+
// Payment Links
|
|
105
|
+
// ───────────────────────────────────────
|
|
106
|
+
/** Create a new payment link (requires merchant auth) */
|
|
107
|
+
async createPaymentLink(params) {
|
|
108
|
+
return this.request("POST", "/links", params);
|
|
109
|
+
}
|
|
110
|
+
/** List payment links for the authenticated merchant */
|
|
111
|
+
async listPaymentLinks() {
|
|
112
|
+
return this.request("GET", "/links");
|
|
113
|
+
}
|
|
114
|
+
/** Resolve a payment link by its public hash (no auth required) */
|
|
115
|
+
async resolvePaymentLink(hash) {
|
|
116
|
+
return this.request("GET", `/links/resolve/${encodeURIComponent(hash)}`);
|
|
117
|
+
}
|
|
118
|
+
/** Get a specific payment link by ID */
|
|
119
|
+
async getPaymentLink(id) {
|
|
120
|
+
return this.request("GET", `/links/${encodeURIComponent(id)}`);
|
|
121
|
+
}
|
|
122
|
+
/** Record a link fulfillment after on-chain tx */
|
|
123
|
+
async fulfillPaymentLink(id, params) {
|
|
124
|
+
return this.request("POST", `/links/${encodeURIComponent(id)}/fulfill`, params);
|
|
125
|
+
}
|
|
126
|
+
/** Close/deactivate a payment link (merchant only) */
|
|
127
|
+
async closePaymentLink(id) {
|
|
128
|
+
return this.request("POST", `/links/${encodeURIComponent(id)}/close`);
|
|
129
|
+
}
|
|
130
|
+
// ───────────────────────────────────────
|
|
131
|
+
// Products
|
|
132
|
+
// ───────────────────────────────────────
|
|
133
|
+
/** List products, optionally filtered */
|
|
134
|
+
async getProducts(filters) {
|
|
135
|
+
const params = new URLSearchParams();
|
|
136
|
+
if (filters?.merchant) params.set("merchant", filters.merchant);
|
|
137
|
+
if (filters?.category) params.set("category", filters.category);
|
|
138
|
+
if (filters?.inStock !== void 0) params.set("inStock", String(filters.inStock));
|
|
139
|
+
const q = params.toString();
|
|
140
|
+
return this.request("GET", `/products${q ? `?${q}` : ""}`);
|
|
141
|
+
}
|
|
142
|
+
/** Get a single product by ID */
|
|
143
|
+
async getProduct(id) {
|
|
144
|
+
return this.request("GET", `/products/${encodeURIComponent(id)}`);
|
|
145
|
+
}
|
|
146
|
+
/** Create a product (merchant auth required) */
|
|
147
|
+
async createProduct(params) {
|
|
148
|
+
return this.request("POST", "/products", params);
|
|
149
|
+
}
|
|
150
|
+
/** Update a product (merchant auth required) */
|
|
151
|
+
async updateProduct(id, params) {
|
|
152
|
+
return this.request("PUT", `/products/${encodeURIComponent(id)}`, params);
|
|
153
|
+
}
|
|
154
|
+
/** Delete a product (merchant auth required) */
|
|
155
|
+
async deleteProduct(id) {
|
|
156
|
+
return this.request("DELETE", `/products/${encodeURIComponent(id)}`);
|
|
157
|
+
}
|
|
158
|
+
// ───────────────────────────────────────
|
|
159
|
+
// Receipts
|
|
160
|
+
// ───────────────────────────────────────
|
|
161
|
+
/** Store receipt metadata */
|
|
162
|
+
async storeReceipt(params) {
|
|
163
|
+
return this.request("POST", "/receipts", params);
|
|
164
|
+
}
|
|
165
|
+
/** Get all receipts for authenticated user */
|
|
166
|
+
async getReceipts() {
|
|
167
|
+
return this.request("GET", "/receipts");
|
|
168
|
+
}
|
|
169
|
+
/** Get receipts by buyer address */
|
|
170
|
+
async getReceiptsByBuyer(address) {
|
|
171
|
+
return this.request("GET", `/receipts/buyer/${encodeURIComponent(address)}`);
|
|
172
|
+
}
|
|
173
|
+
/** Get a receipt by transaction ID */
|
|
174
|
+
async getReceiptByTxId(txId) {
|
|
175
|
+
return this.request("GET", `/receipts/tx/${encodeURIComponent(txId)}`);
|
|
176
|
+
}
|
|
177
|
+
// ───────────────────────────────────────
|
|
178
|
+
// Escrow
|
|
179
|
+
// ───────────────────────────────────────
|
|
180
|
+
/** Create an escrow record */
|
|
181
|
+
async createEscrow(params) {
|
|
182
|
+
return this.request("POST", "/escrow", params);
|
|
183
|
+
}
|
|
184
|
+
/** Resolve an escrow (complete or refund) */
|
|
185
|
+
async resolveEscrow(id, action, txId) {
|
|
186
|
+
return this.request("POST", `/escrow/${encodeURIComponent(id)}/resolve`, { action, txId });
|
|
187
|
+
}
|
|
188
|
+
/** Get escrows for authenticated user */
|
|
189
|
+
async getMyEscrows() {
|
|
190
|
+
return this.request("GET", "/escrow/my");
|
|
191
|
+
}
|
|
192
|
+
// ───────────────────────────────────────
|
|
193
|
+
// Verification
|
|
194
|
+
// ───────────────────────────────────────
|
|
195
|
+
/** Verify a purchase commitment on-chain */
|
|
196
|
+
async verifyPurchase(commitment) {
|
|
197
|
+
return this.request("GET", `/integrate/verify/${encodeURIComponent(commitment)}`);
|
|
198
|
+
}
|
|
199
|
+
// ───────────────────────────────────────
|
|
200
|
+
// Transaction Status
|
|
201
|
+
// ───────────────────────────────────────
|
|
202
|
+
/** Check transaction status on-chain */
|
|
203
|
+
async getTransactionStatus(txId) {
|
|
204
|
+
return this.request("GET", `/tx/${encodeURIComponent(txId)}/status`);
|
|
205
|
+
}
|
|
206
|
+
/** Get current chain block height */
|
|
207
|
+
async getChainHeight() {
|
|
208
|
+
return this.request("GET", "/chain/height");
|
|
209
|
+
}
|
|
210
|
+
// ───────────────────────────────────────
|
|
211
|
+
// API Keys (merchant dashboard)
|
|
212
|
+
// ───────────────────────────────────────
|
|
213
|
+
/** Create an API key */
|
|
214
|
+
async createApiKey(label, permissions) {
|
|
215
|
+
return this.request("POST", "/integrate/keys", { label, permissions });
|
|
216
|
+
}
|
|
217
|
+
/** List API keys */
|
|
218
|
+
async listApiKeys() {
|
|
219
|
+
return this.request("GET", "/integrate/keys");
|
|
220
|
+
}
|
|
221
|
+
/** Revoke an API key */
|
|
222
|
+
async revokeApiKey(id) {
|
|
223
|
+
return this.request("DELETE", `/integrate/keys/${encodeURIComponent(id)}`);
|
|
224
|
+
}
|
|
225
|
+
// ───────────────────────────────────────
|
|
226
|
+
// Webhooks (merchant dashboard)
|
|
227
|
+
// ───────────────────────────────────────
|
|
228
|
+
/** Create a webhook */
|
|
229
|
+
async createWebhook(url, events) {
|
|
230
|
+
return this.request("POST", "/integrate/webhooks", { url, events });
|
|
231
|
+
}
|
|
232
|
+
/** List webhooks */
|
|
233
|
+
async listWebhooks() {
|
|
234
|
+
return this.request("GET", "/integrate/webhooks");
|
|
235
|
+
}
|
|
236
|
+
/** Delete a webhook */
|
|
237
|
+
async deleteWebhook(id) {
|
|
238
|
+
return this.request("DELETE", `/integrate/webhooks/${encodeURIComponent(id)}`);
|
|
239
|
+
}
|
|
240
|
+
// ───────────────────────────────────────
|
|
241
|
+
// Delegated Proving
|
|
242
|
+
// ───────────────────────────────────────
|
|
243
|
+
/** Check proving service health */
|
|
244
|
+
async getProvingHealth() {
|
|
245
|
+
return this.request("GET", "/proving/health");
|
|
246
|
+
}
|
|
247
|
+
/** Submit a transition for delegated proving */
|
|
248
|
+
async submitDelegatedProof(params) {
|
|
249
|
+
return this.request("POST", "/proving/delegate", params);
|
|
250
|
+
}
|
|
251
|
+
/** Check delegated proof status */
|
|
252
|
+
async getProvingStatus(proofId) {
|
|
253
|
+
return this.request("GET", `/proving/status/${encodeURIComponent(proofId)}`);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
257
|
+
0 && (module.exports = {
|
|
258
|
+
VeilReceipt,
|
|
259
|
+
VeilReceiptError
|
|
260
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var VeilReceiptError = class extends Error {
|
|
3
|
+
constructor(message, status, code) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.status = status;
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = "VeilReceiptError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var VeilReceipt = class {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
13
|
+
this.apiKey = config.apiKey;
|
|
14
|
+
this.token = config.token;
|
|
15
|
+
this.timeout = config.timeout ?? 3e4;
|
|
16
|
+
}
|
|
17
|
+
/** Update the auth token (e.g. after login) */
|
|
18
|
+
setToken(token) {
|
|
19
|
+
this.token = token ?? void 0;
|
|
20
|
+
}
|
|
21
|
+
/** Update the API key */
|
|
22
|
+
setApiKey(key) {
|
|
23
|
+
this.apiKey = key ?? void 0;
|
|
24
|
+
}
|
|
25
|
+
// ───────────────────────────────────────
|
|
26
|
+
// Internal
|
|
27
|
+
// ───────────────────────────────────────
|
|
28
|
+
async request(method, path, body) {
|
|
29
|
+
const url = `${this.baseUrl}${path}`;
|
|
30
|
+
const headers = {
|
|
31
|
+
"Content-Type": "application/json"
|
|
32
|
+
};
|
|
33
|
+
if (this.apiKey) {
|
|
34
|
+
headers["X-API-Key"] = this.apiKey;
|
|
35
|
+
}
|
|
36
|
+
if (this.token) {
|
|
37
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
38
|
+
}
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
41
|
+
try {
|
|
42
|
+
const res = await fetch(url, {
|
|
43
|
+
method,
|
|
44
|
+
headers,
|
|
45
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
46
|
+
signal: controller.signal
|
|
47
|
+
});
|
|
48
|
+
const data = await res.json();
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
throw new VeilReceiptError(
|
|
51
|
+
data.error || `Request failed: ${res.status}`,
|
|
52
|
+
res.status
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return data;
|
|
56
|
+
} finally {
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// ───────────────────────────────────────
|
|
61
|
+
// Health
|
|
62
|
+
// ───────────────────────────────────────
|
|
63
|
+
/** Check API health */
|
|
64
|
+
async health() {
|
|
65
|
+
return this.request("GET", "/health");
|
|
66
|
+
}
|
|
67
|
+
// ───────────────────────────────────────
|
|
68
|
+
// Payment Sessions
|
|
69
|
+
// ───────────────────────────────────────
|
|
70
|
+
/** Get details of a payment session */
|
|
71
|
+
async getPaymentSession(sessionId) {
|
|
72
|
+
return this.request("GET", `/integrate/payments/${encodeURIComponent(sessionId)}`);
|
|
73
|
+
}
|
|
74
|
+
/** Complete a payment session after on-chain tx */
|
|
75
|
+
async completePaymentSession(sessionId, params) {
|
|
76
|
+
return this.request("POST", `/integrate/payments/${encodeURIComponent(sessionId)}/complete`, params);
|
|
77
|
+
}
|
|
78
|
+
// ───────────────────────────────────────
|
|
79
|
+
// Payment Links
|
|
80
|
+
// ───────────────────────────────────────
|
|
81
|
+
/** Create a new payment link (requires merchant auth) */
|
|
82
|
+
async createPaymentLink(params) {
|
|
83
|
+
return this.request("POST", "/links", params);
|
|
84
|
+
}
|
|
85
|
+
/** List payment links for the authenticated merchant */
|
|
86
|
+
async listPaymentLinks() {
|
|
87
|
+
return this.request("GET", "/links");
|
|
88
|
+
}
|
|
89
|
+
/** Resolve a payment link by its public hash (no auth required) */
|
|
90
|
+
async resolvePaymentLink(hash) {
|
|
91
|
+
return this.request("GET", `/links/resolve/${encodeURIComponent(hash)}`);
|
|
92
|
+
}
|
|
93
|
+
/** Get a specific payment link by ID */
|
|
94
|
+
async getPaymentLink(id) {
|
|
95
|
+
return this.request("GET", `/links/${encodeURIComponent(id)}`);
|
|
96
|
+
}
|
|
97
|
+
/** Record a link fulfillment after on-chain tx */
|
|
98
|
+
async fulfillPaymentLink(id, params) {
|
|
99
|
+
return this.request("POST", `/links/${encodeURIComponent(id)}/fulfill`, params);
|
|
100
|
+
}
|
|
101
|
+
/** Close/deactivate a payment link (merchant only) */
|
|
102
|
+
async closePaymentLink(id) {
|
|
103
|
+
return this.request("POST", `/links/${encodeURIComponent(id)}/close`);
|
|
104
|
+
}
|
|
105
|
+
// ───────────────────────────────────────
|
|
106
|
+
// Products
|
|
107
|
+
// ───────────────────────────────────────
|
|
108
|
+
/** List products, optionally filtered */
|
|
109
|
+
async getProducts(filters) {
|
|
110
|
+
const params = new URLSearchParams();
|
|
111
|
+
if (filters?.merchant) params.set("merchant", filters.merchant);
|
|
112
|
+
if (filters?.category) params.set("category", filters.category);
|
|
113
|
+
if (filters?.inStock !== void 0) params.set("inStock", String(filters.inStock));
|
|
114
|
+
const q = params.toString();
|
|
115
|
+
return this.request("GET", `/products${q ? `?${q}` : ""}`);
|
|
116
|
+
}
|
|
117
|
+
/** Get a single product by ID */
|
|
118
|
+
async getProduct(id) {
|
|
119
|
+
return this.request("GET", `/products/${encodeURIComponent(id)}`);
|
|
120
|
+
}
|
|
121
|
+
/** Create a product (merchant auth required) */
|
|
122
|
+
async createProduct(params) {
|
|
123
|
+
return this.request("POST", "/products", params);
|
|
124
|
+
}
|
|
125
|
+
/** Update a product (merchant auth required) */
|
|
126
|
+
async updateProduct(id, params) {
|
|
127
|
+
return this.request("PUT", `/products/${encodeURIComponent(id)}`, params);
|
|
128
|
+
}
|
|
129
|
+
/** Delete a product (merchant auth required) */
|
|
130
|
+
async deleteProduct(id) {
|
|
131
|
+
return this.request("DELETE", `/products/${encodeURIComponent(id)}`);
|
|
132
|
+
}
|
|
133
|
+
// ───────────────────────────────────────
|
|
134
|
+
// Receipts
|
|
135
|
+
// ───────────────────────────────────────
|
|
136
|
+
/** Store receipt metadata */
|
|
137
|
+
async storeReceipt(params) {
|
|
138
|
+
return this.request("POST", "/receipts", params);
|
|
139
|
+
}
|
|
140
|
+
/** Get all receipts for authenticated user */
|
|
141
|
+
async getReceipts() {
|
|
142
|
+
return this.request("GET", "/receipts");
|
|
143
|
+
}
|
|
144
|
+
/** Get receipts by buyer address */
|
|
145
|
+
async getReceiptsByBuyer(address) {
|
|
146
|
+
return this.request("GET", `/receipts/buyer/${encodeURIComponent(address)}`);
|
|
147
|
+
}
|
|
148
|
+
/** Get a receipt by transaction ID */
|
|
149
|
+
async getReceiptByTxId(txId) {
|
|
150
|
+
return this.request("GET", `/receipts/tx/${encodeURIComponent(txId)}`);
|
|
151
|
+
}
|
|
152
|
+
// ───────────────────────────────────────
|
|
153
|
+
// Escrow
|
|
154
|
+
// ───────────────────────────────────────
|
|
155
|
+
/** Create an escrow record */
|
|
156
|
+
async createEscrow(params) {
|
|
157
|
+
return this.request("POST", "/escrow", params);
|
|
158
|
+
}
|
|
159
|
+
/** Resolve an escrow (complete or refund) */
|
|
160
|
+
async resolveEscrow(id, action, txId) {
|
|
161
|
+
return this.request("POST", `/escrow/${encodeURIComponent(id)}/resolve`, { action, txId });
|
|
162
|
+
}
|
|
163
|
+
/** Get escrows for authenticated user */
|
|
164
|
+
async getMyEscrows() {
|
|
165
|
+
return this.request("GET", "/escrow/my");
|
|
166
|
+
}
|
|
167
|
+
// ───────────────────────────────────────
|
|
168
|
+
// Verification
|
|
169
|
+
// ───────────────────────────────────────
|
|
170
|
+
/** Verify a purchase commitment on-chain */
|
|
171
|
+
async verifyPurchase(commitment) {
|
|
172
|
+
return this.request("GET", `/integrate/verify/${encodeURIComponent(commitment)}`);
|
|
173
|
+
}
|
|
174
|
+
// ───────────────────────────────────────
|
|
175
|
+
// Transaction Status
|
|
176
|
+
// ───────────────────────────────────────
|
|
177
|
+
/** Check transaction status on-chain */
|
|
178
|
+
async getTransactionStatus(txId) {
|
|
179
|
+
return this.request("GET", `/tx/${encodeURIComponent(txId)}/status`);
|
|
180
|
+
}
|
|
181
|
+
/** Get current chain block height */
|
|
182
|
+
async getChainHeight() {
|
|
183
|
+
return this.request("GET", "/chain/height");
|
|
184
|
+
}
|
|
185
|
+
// ───────────────────────────────────────
|
|
186
|
+
// API Keys (merchant dashboard)
|
|
187
|
+
// ───────────────────────────────────────
|
|
188
|
+
/** Create an API key */
|
|
189
|
+
async createApiKey(label, permissions) {
|
|
190
|
+
return this.request("POST", "/integrate/keys", { label, permissions });
|
|
191
|
+
}
|
|
192
|
+
/** List API keys */
|
|
193
|
+
async listApiKeys() {
|
|
194
|
+
return this.request("GET", "/integrate/keys");
|
|
195
|
+
}
|
|
196
|
+
/** Revoke an API key */
|
|
197
|
+
async revokeApiKey(id) {
|
|
198
|
+
return this.request("DELETE", `/integrate/keys/${encodeURIComponent(id)}`);
|
|
199
|
+
}
|
|
200
|
+
// ───────────────────────────────────────
|
|
201
|
+
// Webhooks (merchant dashboard)
|
|
202
|
+
// ───────────────────────────────────────
|
|
203
|
+
/** Create a webhook */
|
|
204
|
+
async createWebhook(url, events) {
|
|
205
|
+
return this.request("POST", "/integrate/webhooks", { url, events });
|
|
206
|
+
}
|
|
207
|
+
/** List webhooks */
|
|
208
|
+
async listWebhooks() {
|
|
209
|
+
return this.request("GET", "/integrate/webhooks");
|
|
210
|
+
}
|
|
211
|
+
/** Delete a webhook */
|
|
212
|
+
async deleteWebhook(id) {
|
|
213
|
+
return this.request("DELETE", `/integrate/webhooks/${encodeURIComponent(id)}`);
|
|
214
|
+
}
|
|
215
|
+
// ───────────────────────────────────────
|
|
216
|
+
// Delegated Proving
|
|
217
|
+
// ───────────────────────────────────────
|
|
218
|
+
/** Check proving service health */
|
|
219
|
+
async getProvingHealth() {
|
|
220
|
+
return this.request("GET", "/proving/health");
|
|
221
|
+
}
|
|
222
|
+
/** Submit a transition for delegated proving */
|
|
223
|
+
async submitDelegatedProof(params) {
|
|
224
|
+
return this.request("POST", "/proving/delegate", params);
|
|
225
|
+
}
|
|
226
|
+
/** Check delegated proof status */
|
|
227
|
+
async getProvingStatus(proofId) {
|
|
228
|
+
return this.request("GET", `/proving/status/${encodeURIComponent(proofId)}`);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
export {
|
|
232
|
+
VeilReceipt,
|
|
233
|
+
VeilReceiptError
|
|
234
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "veilreceipt-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "VeilReceipt SDK — Accept private payments on Aleo with payment links, escrow, and ZK receipts",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"import": "./dist/index.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
21
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"aleo",
|
|
25
|
+
"zk",
|
|
26
|
+
"zero-knowledge",
|
|
27
|
+
"privacy",
|
|
28
|
+
"payments",
|
|
29
|
+
"receipts",
|
|
30
|
+
"escrow",
|
|
31
|
+
"web3"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsup": "^8.0.0",
|
|
36
|
+
"typescript": "^5.4.0"
|
|
37
|
+
}
|
|
38
|
+
}
|