@proofrails/sdk 1.0.0 → 1.1.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.
Files changed (2) hide show
  1. package/README.md +1 -412
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,412 +1 @@
1
- # ProofRails SDK
2
-
3
- > **Beginner-friendly SDK for creating blockchain-verifiable ISO 20022 payment receipts**
4
-
5
- Create compliant, auditable payment receipts with just a few lines of code. No blockchain expertise required!
6
-
7
- ## Features
8
-
9
- - **Zero coding knowledge required** - Use simple templates
10
- - **ISO 20022 compliant** - Generates standard banking messages
11
- - **Blockchain-verified** - Receipts anchored on Flare blockchain
12
- - **Tamper-proof** - Cryptographic evidence bundles
13
- - **Real-time updates** - Live receipt status via SSE
14
- - **Works everywhere** - TypeScript, JavaScript, Node.js, browsers
15
-
16
- ## Installation
17
-
18
- ```bash
19
- npm install @proofrails/sdk
20
- # or
21
- yarn add @proofrails/sdk
22
- ```
23
-
24
- ## Quick Start
25
-
26
- ### Option 1: Create New Project (Easiest)
27
-
28
- ```javascript
29
- import ProofRails from '@proofrails/sdk';
30
-
31
- // Create a new project automatically
32
- const { client, apiKey, projectId } = await ProofRails.createProject({
33
- label: 'My App'
34
- });
35
-
36
- console.log('Your API Key:', apiKey); // Save this!
37
- console.log('Your Project ID:', projectId);
38
- ```
39
-
40
- ### Option 2: Use Existing API Key
41
-
42
- ```javascript
43
- import ProofRails from '@proofrails/sdk';
44
-
45
- const proofrails = new ProofRails({
46
- apiKey: 'your-api-key-here'
47
- });
48
- ```
49
-
50
- ## Templates (Beginner-Friendly)
51
-
52
- ### Payment Receipt
53
-
54
- ```javascript
55
- const receipt = await proofrails.templates.payment({
56
- amount: 100,
57
- from: 'Alice',
58
- to: 'Bob',
59
- purpose: 'Freelance web development',
60
- transactionHash: '0x123...'
61
- });
62
-
63
- console.log('Receipt ID:', receipt.id);
64
- console.log('Status:', receipt.status);
65
- ```
66
-
67
- ### Donation Receipt
68
-
69
- ```javascript
70
- const receipt = await proofrails.templates.donation({
71
- amount: 50,
72
- donor: 'John Doe',
73
- organization: 'Red Cross',
74
- campaign: 'Disaster Relief 2024',
75
- transactionHash: '0x456...'
76
- });
77
- ```
78
-
79
- ### Escrow Release
80
-
81
- ```javascript
82
- const receipt = await proofrails.templates.escrow({
83
- amount: 1000,
84
- buyer: 'Alice',
85
- seller: 'Bob',
86
- escrowId: 'ESC-2024-001',
87
- releaseReason: 'Milestone 1 completed',
88
- transactionHash: '0x789...'
89
- });
90
- ```
91
-
92
- ### Grant Disbursement
93
-
94
- ```javascript
95
- const receipt = await proofrails.templates.grant({
96
- amount: 5000,
97
- grantee: 'Research Lab',
98
- grantor: 'Science Foundation',
99
- grantId: 'GR-2024-001',
100
- purpose: 'Climate change research',
101
- transactionHash: '0xabc...'
102
- });
103
- ```
104
-
105
- ### Refund
106
-
107
- ```javascript
108
- const receipt = await proofrails.templates.refund({
109
- amount: 25,
110
- originalPayment: 'receipt-id-123',
111
- reason: 'Product returned',
112
- customer: 'Jane Smith',
113
- transactionHash: '0xdef...'
114
- });
115
- ```
116
-
117
- ## Core Operations
118
-
119
- ### Get Receipt
120
-
121
- ```javascript
122
- const receipt = await proofrails.receipts.get('receipt-id');
123
-
124
- console.log(receipt.status); // 'pending' or 'anchored'
125
- console.log(receipt.amount);
126
- console.log(receipt.anchorTx); // Blockchain transaction (if anchored)
127
- ```
128
-
129
- ### List Receipts
130
-
131
- ```javascript
132
- const { items, total } = await proofrails.receipts.list({
133
- limit: 10,
134
- status: 'anchored'
135
- });
136
-
137
- items.forEach(receipt => {
138
- console.log(receipt.id, receipt.amount);
139
- });
140
- ```
141
-
142
- ### Download Artifacts
143
-
144
- ```javascript
145
- const artifacts = await proofrails.receipts.getArtifacts('receipt-id');
146
-
147
- console.log('ISO XML:', artifacts.pain001Url);
148
- console.log('Bundle:', artifacts.bundleUrl);
149
- console.log('Manifest:', artifacts.manifestUrl);
150
- ```
151
-
152
- ## Verification
153
-
154
- ### Verify Receipt
155
-
156
- ```javascript
157
- const verification = await proofrails.verify.byReceiptId('receipt-id');
158
-
159
- if (verification.valid && verification.onChain) {
160
- console.log(' Receipt is valid and on-chain!');
161
- console.log('Anchor TX:', verification.anchorTx);
162
- }
163
- ```
164
-
165
- ### Verify by Bundle Hash
166
-
167
- ```javascript
168
- const verification = await proofrails.verify.byHash('0x123...');
169
- ```
170
-
171
- ### Get Verification Proof
172
-
173
- ```javascript
174
- const proof = await proofrails.verify.getProof('receipt-id');
175
-
176
- console.log('Bundle Hash:', proof.bundleHash);
177
- console.log('Block Number:', proof.blockNumber);
178
- console.log('Timestamp:', proof.timestamp);
179
- ```
180
-
181
- ## Live Updates
182
-
183
- ```javascript
184
- // Listen to receipt status changes in real-time
185
- const listener = proofrails.events.listen('receipt-id', (update) => {
186
- console.log('Status:', update.status);
187
-
188
- if (update.status === 'anchored') {
189
- console.log('Receipt is now on-chain!');
190
- console.log('Anchor TX:', update.anchorTx);
191
- listener.stop(); // Stop listening
192
- }
193
- });
194
- ```
195
-
196
- ## Embeddable Widgets
197
-
198
- ### Generate Widget
199
-
200
- ```javascript
201
- const widget = proofrails.embed.widget('receipt-id', {
202
- theme: 'light',
203
- width: '100%',
204
- height: '400px'
205
- });
206
-
207
- // Use in HTML
208
- document.getElementById('receipt').innerHTML = widget.iframeHtml;
209
- ```
210
-
211
- ### Full Page URL
212
-
213
- ```javascript
214
- const pageUrl = proofrails.embed.fullPage('receipt-id');
215
- // https://middleware.com/receipt/receipt-id
216
- ```
217
-
218
- ## Statements
219
-
220
- ### Generate Intraday Statement
221
-
222
- ```javascript
223
- const statement = await proofrails.statements.intraday({
224
- dateFrom: '2024-01-01',
225
- dateTo: '2024-01-31',
226
- accountId: 'my-account'
227
- });
228
-
229
- console.log('Download:', statement.downloadUrl);
230
- ```
231
-
232
- ### Generate End-of-Day Statement
233
-
234
- ```javascript
235
- const statement = await proofrails.statements.endOfDay({
236
- dateTo: '2024-01-31',
237
- accountId: 'my-account'
238
- });
239
- ```
240
-
241
- ## Project Management
242
-
243
- ### Get Project Info
244
-
245
- ```javascript
246
- const info = await proofrails.project.getInfo();
247
- console.log('Project ID:', info.projectId);
248
- ```
249
-
250
- ### Rotate API Key
251
-
252
- ```javascript
253
- const newKey = await proofrails.project.rotateKey();
254
- console.log('New API Key:', newKey.apiKey); // Save this!
255
-
256
- // Update client with new key
257
- proofrails.setApiKey(newKey.apiKey);
258
- ```
259
-
260
- ## Admin Operations
261
-
262
- ```javascript
263
- const admin = new ProofRails({ adminToken: 'your-admin-token' });
264
-
265
- // Create API key for specific project
266
- const key = await admin.admin.createKey({
267
- projectId: 'proj-123',
268
- label: 'Production Key'
269
- });
270
-
271
- label: 'Production Key'
272
- });
273
-
274
- // Delete API key
275
- await admin.admin.deleteKey('key-id');
276
- ```
277
-
278
- ## Networks
279
-
280
- ```javascript
281
- // Testnet (default)
282
- const proofrails = new ProofRails({
283
- apiKey: 'your-key',
284
- network: 'coston2'
285
- });
286
-
287
- // Mainnet
288
- const proofrails = new ProofRails({
289
- apiKey: 'your-key',
290
- network: 'flare'
291
- });
292
- ```
293
-
294
- ## Advanced Configuration
295
-
296
- ```javascript
297
- const proofrails = new ProofRails({
298
- apiKey: 'your-key',
299
- network: 'coston2',
300
- baseUrl: 'https://custom-middleware.com', // Optional
301
- timeout: 60000 // Request timeout in ms (default: 30000)
302
- });
303
- ```
304
-
305
- ## React Hooks (New!)
306
-
307
- The SDK exports dedicated React hooks for the easiest integration experience.
308
-
309
- ### Setup
310
-
311
- ```typescript
312
- import { useProofRails } from '@proofrails/sdk/react';
313
-
314
- // Initialize the hook
315
- const sdk = useProofRails({
316
- apiKey: 'your-api-key'
317
- });
318
- ```
319
-
320
- ### Sending Payments (Zero Boilerplate)
321
-
322
- ```typescript
323
- import { useProofRailsPayment } from '@proofrails/sdk/react';
324
-
325
- const { send, loading, receipt, status } = useProofRailsPayment(sdk);
326
-
327
- const handleMyButton = async () => {
328
- await send({
329
- amount: "10.0",
330
- to: "0xReceiverAddress...",
331
- purpose: "Payment for Services"
332
- });
333
- };
334
- ```
335
-
336
- ### Self-Serve Project Creation
337
-
338
- ```typescript
339
- import { useCreateProject } from '@proofrails/sdk/react';
340
-
341
- const { create, loading } = useCreateProject();
342
-
343
- const setup = async () => {
344
- const { apiKey, projectId } = await create("My New dApp");
345
- console.log("My new key:", apiKey);
346
- };
347
- ```
348
-
349
- ## TypeScript Support
350
-
351
- Full TypeScript support with type definitions included:
352
-
353
- ```typescript
354
- import ProofRails, { Receipt, VerificationResult } from '@proofrails/sdk';
355
-
356
- const proofrails = new ProofRails({ apiKey: 'your-key' });
357
-
358
- const receipt: Receipt = await proofrails.templates.payment({
359
- amount: 100,
360
- from: 'Alice',
361
- to: 'Bob',
362
- purpose: 'Payment',
363
- transactionHash: '0x123...'
364
- });
365
-
366
- const verification: VerificationResult = await proofrails.verify.byReceiptId(receipt.id);
367
- ```
368
-
369
- ## JavaScript (No TypeScript)
370
-
371
- Works perfectly in plain JavaScript too:
372
-
373
- ```javascript
374
- const ProofRails = require('@proofrails/sdk');
375
-
376
- const proofrails = new ProofRails({ apiKey: 'your-key' });
377
-
378
- // Same API, no types needed!
379
- ```
380
-
381
- ## Error Handling
382
-
383
- ```javascript
384
- import { ProofRailsError } from '@proofrails/sdk';
385
-
386
- try {
387
- const receipt = await proofrails.receipts.get('invalid-id');
388
- } catch (error) {
389
- if (error instanceof ProofRailsError) {
390
- console.error('Error:', error.message);
391
- console.error('Code:', error.code);
392
- console.error('Status:', error.statusCode);
393
- }
394
- }
395
- ```
396
-
397
- ## License
398
-
399
- MIT
400
-
401
- ## Support
402
-
403
- - Documentation: [docs.proofrails.com](https://docs.proofrails.com)
404
- - Issues: [GitHub Issues](https://github.com/proofrails/proofrails-sdk/issues)
405
- - Email: support@proofrails.com
406
-
407
- ---
408
-
409
- **Made with ❤️ by ProofRails**
410
- # Proofrails-sdk
411
-
412
-
1
+ # ProofRails SDK> **Beginner-friendly SDK for creating blockchain-verifiable ISO 20022 payment receipts**Create compliant, auditable payment receipts with just a few lines of code. No blockchain expertise required!## Features- **Zero coding knowledge required** - Use simple templates- **ISO 20022 compliant** - Generates standard banking messages- **Blockchain-verified** - Receipts anchored on Flare blockchain- **Tamper-proof** - Cryptographic evidence bundles- **Real-time updates** - Live receipt status via SSE- **Works everywhere** - TypeScript, JavaScript, Node.js, browsers## Installation```bashnpm install @proofrails/sdk# oryarn add @proofrails/sdk```## Quick Start### Option 1: Create New Project (Easiest)```javascriptimport ProofRails from '@proofrails/sdk';// Create a new project automaticallyconst { client, apiKey, projectId } = await ProofRails.createProject({ label: 'My App'});console.log('Your API Key:', apiKey); // Save this!console.log('Your Project ID:', projectId);```### Option 2: Use Existing API Key```javascriptimport ProofRails from '@proofrails/sdk';const proofrails = new ProofRails({ apiKey: 'your-api-key-here'});```## Templates (Beginner-Friendly)### Payment Receipt```javascriptconst receipt = await proofrails.templates.payment({ amount: 100, from: 'Alice', to: 'Bob', purpose: 'Freelance web development', transactionHash: '0x123...'});console.log('Receipt ID:', receipt.id);console.log('Status:', receipt.status);```### Donation Receipt```javascriptconst receipt = await proofrails.templates.donation({ amount: 50, donor: 'John Doe', organization: 'Red Cross', campaign: 'Disaster Relief 2024', transactionHash: '0x456...'});```### Escrow Release```javascriptconst receipt = await proofrails.templates.escrow({ amount: 1000, buyer: 'Alice', seller: 'Bob', escrowId: 'ESC-2024-001', releaseReason: 'Milestone 1 completed', transactionHash: '0x789...'});```### Grant Disbursement```javascriptconst receipt = await proofrails.templates.grant({ amount: 5000, grantee: 'Research Lab', grantor: 'Science Foundation', grantId: 'GR-2024-001', purpose: 'Climate change research', transactionHash: '0xabc...'});```### Refund```javascriptconst receipt = await proofrails.templates.refund({ amount: 25, originalPayment: 'receipt-id-123', reason: 'Product returned', customer: 'Jane Smith', transactionHash: '0xdef...'});```## Core Operations### Get Receipt```javascriptconst receipt = await proofrails.receipts.get('receipt-id');console.log(receipt.status); // 'pending' or 'anchored'console.log(receipt.amount);console.log(receipt.anchorTx); // Blockchain transaction (if anchored)```### List Receipts```javascriptconst { items, total } = await proofrails.receipts.list({ limit: 10, status: 'anchored'});items.forEach(receipt => { console.log(receipt.id, receipt.amount);});```### Download Artifacts```javascriptconst artifacts = await proofrails.receipts.getArtifacts('receipt-id');console.log('ISO XML:', artifacts.pain001Url);console.log('Bundle:', artifacts.bundleUrl);console.log('Manifest:', artifacts.manifestUrl);```## Verification### Verify Receipt```javascriptconst verification = await proofrails.verify.byReceiptId('receipt-id');if (verification.valid && verification.onChain) { console.log(' Receipt is valid and on-chain!'); console.log('Anchor TX:', verification.anchorTx);}```### Verify by Bundle Hash```javascriptconst verification = await proofrails.verify.byHash('0x123...');```### Get Verification Proof```javascriptconst proof = await proofrails.verify.getProof('receipt-id');console.log('Bundle Hash:', proof.bundleHash);console.log('Block Number:', proof.blockNumber);console.log('Timestamp:', proof.timestamp);```## Live Updates```javascript// Listen to receipt status changes in real-timeconst listener = proofrails.events.listen('receipt-id', (update) => { console.log('Status:', update.status); if (update.status === 'anchored') { console.log('Receipt is now on-chain!'); console.log('Anchor TX:', update.anchorTx); listener.stop(); // Stop listening }});```## Embeddable Widgets### Generate Widget```javascriptconst widget = proofrails.embed.widget('receipt-id', { theme: 'light', width: '100%', height: '400px'});// Use in HTMLdocument.getElementById('receipt').innerHTML = widget.iframeHtml;```### Full Page URL```javascriptconst pageUrl = proofrails.embed.fullPage('receipt-id');// https://middleware.com/receipt/receipt-id```## Statements### Generate Intraday Statement```javascriptconst statement = await proofrails.statements.intraday({ dateFrom: '2024-01-01', dateTo: '2024-01-31', accountId: 'my-account'});console.log('Download:', statement.downloadUrl);```### Generate End-of-Day Statement```javascriptconst statement = await proofrails.statements.endOfDay({ dateTo: '2024-01-31', accountId: 'my-account'});```## Project Management### Get Project Info```javascriptconst info = await proofrails.project.getInfo();console.log('Project ID:', info.projectId);```### Rotate API Key```javascriptconst newKey = await proofrails.project.rotateKey();console.log('New API Key:', newKey.apiKey); // Save this!// Update client with new keyproofrails.setApiKey(newKey.apiKey);```## Admin Operations```javascriptconst admin = new ProofRails({ adminToken: 'your-admin-token' });// Create API key for specific projectconst key = await admin.admin.createKey({ projectId: 'proj-123', label: 'Production Key'}); label: 'Production Key'});// Delete API keyawait admin.admin.deleteKey('key-id');```## Networks```javascript// Testnet (default)const proofrails = new ProofRails({ apiKey: 'your-key', network: 'coston2'});// Mainnetconst proofrails = new ProofRails({ apiKey: 'your-key', network: 'flare'});```## Advanced Configuration```javascriptconst proofrails = new ProofRails({ apiKey: 'your-key', network: 'coston2', baseUrl: 'https://custom-middleware.com', // Optional timeout: 60000 // Request timeout in ms (default: 30000)});```## React Hooks (New!)The SDK exports dedicated React hooks for the easiest integration experience.### Setup```typescriptimport { useProofRails } from '@proofrails/sdk/react';// Initialize the hookconst sdk = useProofRails({ apiKey: 'your-api-key' });```### Sending Payments (Zero Boilerplate)```typescriptimport { useProofRailsPayment } from '@proofrails/sdk/react';const { send, loading, receipt, status } = useProofRailsPayment(sdk);const handleMyButton = async () => { await send({ amount: "10.0", to: "0xReceiverAddress...", purpose: "Payment for Services" });};```### Self-Serve Project Creation```typescriptimport { useCreateProject } from '@proofrails/sdk/react';const { create, loading } = useCreateProject();const setup = async () => { const { apiKey, projectId } = await create("My New dApp"); console.log("My new key:", apiKey);};```## TypeScript SupportFull TypeScript support with type definitions included:```typescriptimport ProofRails, { Receipt, VerificationResult } from '@proofrails/sdk';const proofrails = new ProofRails({ apiKey: 'your-key' });const receipt: Receipt = await proofrails.templates.payment({ amount: 100, from: 'Alice', to: 'Bob', purpose: 'Payment', transactionHash: '0x123...'});const verification: VerificationResult = await proofrails.verify.byReceiptId(receipt.id);```## JavaScript (No TypeScript)Works perfectly in plain JavaScript too:```javascriptconst ProofRails = require('@proofrails/sdk');const proofrails = new ProofRails({ apiKey: 'your-key' });// Same API, no types needed!```## Error Handling```javascriptimport { ProofRailsError } from '@proofrails/sdk';try { const receipt = await proofrails.receipts.get('invalid-id');} catch (error) { if (error instanceof ProofRailsError) { console.error('Error:', error.message); console.error('Code:', error.code); console.error('Status:', error.statusCode); }}```## LicenseMIT## Support- Documentation: [docs.proofrails.com](https://docs.proofrails.com)- Issues: [GitHub Issues](https://github.com/proofrails/proofrails-sdk/issues)- Email: support@proofrails.com---**Made with ❤️ by ProofRails**# Proofrails-sdk
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proofrails/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Beginner-friendly SDK for ProofRails ISO 20022 Middleware - Create blockchain-verifiable payment receipts with zero coding knowledge",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",