@proofrails/sdk 1.1.0 → 1.2.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 +244 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1 +1,244 @@
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
1
+
2
+ ````md
3
+ # ProofRails SDK
4
+
5
+ **Beginner friendly SDK for creating blockchain verifiable ISO 20022 payment receipts**
6
+
7
+ Create compliant, auditable payment receipts with just a few lines of code. No blockchain expertise required.
8
+
9
+ ## Features
10
+
11
+ - **Zero coding knowledge required**, use simple templates
12
+ - **ISO 20022 compliant**, generates standard banking messages
13
+ - **Blockchain verified**, receipts anchored on Flare blockchain
14
+ - **Tamper proof**, cryptographic evidence bundles
15
+ - **Real time updates**, live receipt status via SSE
16
+ - **Works everywhere**, TypeScript, JavaScript, Node.js, browsers
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm i @proofrails-sdk/sdk
22
+ # or
23
+ yarn add @proofrails/sdk
24
+ ````
25
+
26
+ ## Quick Start
27
+
28
+ ### Option 1, Create New Project (Easiest)
29
+
30
+ ```javascript
31
+ import ProofRails from '@proofrails/sdk';
32
+
33
+ // Create a new project automatically
34
+ const { client, apiKey, projectId } = await ProofRails.createProject({
35
+ label: 'My App'
36
+ });
37
+
38
+ console.log('Your API Key:', apiKey); // Save this
39
+ console.log('Your Project ID:', projectId);
40
+ ```
41
+
42
+ ### Option 2, Use Existing API Key
43
+
44
+ ```javascript
45
+ import ProofRails from '@proofrails/sdk';
46
+
47
+ const proofrails = new ProofRails({
48
+ apiKey: 'your-api-key-here'
49
+ });
50
+ ```
51
+
52
+ ## Templates (Beginner Friendly)
53
+
54
+ ### Payment Receipt
55
+
56
+ ```javascript
57
+ const receipt = await proofrails.templates.payment({
58
+ amount: 100,
59
+ from: 'Alice',
60
+ to: 'Bob',
61
+ purpose: 'Freelance web development',
62
+ transactionHash: '0x123...'
63
+ });
64
+
65
+ console.log('Receipt ID:', receipt.id);
66
+ console.log('Status:', receipt.status);
67
+ ```
68
+
69
+ ### Donation Receipt
70
+
71
+ ```javascript
72
+ const receipt = await proofrails.templates.donation({
73
+ amount: 50,
74
+ donor: 'John Doe',
75
+ organization: 'Red Cross',
76
+ campaign: 'Disaster Relief 2024',
77
+ transactionHash: '0x456...'
78
+ });
79
+ ```
80
+
81
+ ### Escrow Release
82
+
83
+ ```javascript
84
+ const receipt = await proofrails.templates.escrow({
85
+ amount: 1000,
86
+ buyer: 'Alice',
87
+ seller: 'Bob',
88
+ escrowId: 'ESC-2024-001',
89
+ releaseReason: 'Milestone 1 completed',
90
+ transactionHash: '0x789...'
91
+ });
92
+ ```
93
+
94
+ ### Grant Disbursement
95
+
96
+ ```javascript
97
+ const receipt = await proofrails.templates.grant({
98
+ amount: 5000,
99
+ grantee: 'Research Lab',
100
+ grantor: 'Science Foundation',
101
+ grantId: 'GR-2024-001',
102
+ purpose: 'Climate change research',
103
+ transactionHash: '0xabc...'
104
+ });
105
+ ```
106
+
107
+ ### Refund
108
+
109
+ ```javascript
110
+ const receipt = await proofrails.templates.refund({
111
+ amount: 25,
112
+ originalPayment: 'receipt-id-123',
113
+ reason: 'Product returned',
114
+ customer: 'Jane Smith',
115
+ transactionHash: '0xdef...'
116
+ });
117
+ ```
118
+
119
+ ## Core Operations
120
+
121
+ ### Get Receipt
122
+
123
+ ```javascript
124
+ const receipt = await proofrails.receipts.get('receipt-id');
125
+
126
+ console.log(receipt.status);
127
+ console.log(receipt.amount);
128
+ console.log(receipt.anchorTx);
129
+ ```
130
+
131
+ ### List Receipts
132
+
133
+ ```javascript
134
+ const { items, total } = await proofrails.receipts.list({
135
+ limit: 10,
136
+ status: 'anchored'
137
+ });
138
+
139
+ items.forEach(r => {
140
+ console.log(r.id, r.amount);
141
+ });
142
+ ```
143
+
144
+ ### Download Artifacts
145
+
146
+ ```javascript
147
+ const artifacts = await proofrails.receipts.getArtifacts('receipt-id');
148
+
149
+ console.log('ISO XML:', artifacts.pain001Url);
150
+ console.log('Bundle:', artifacts.bundleUrl);
151
+ console.log('Manifest:', artifacts.manifestUrl);
152
+ ```
153
+
154
+ ## Verification
155
+
156
+ ### Verify Receipt
157
+
158
+ ```javascript
159
+ const verification = await proofrails.verify.byReceiptId('receipt-id');
160
+
161
+ if (verification.valid && verification.onChain) {
162
+ console.log('Receipt is valid and on chain');
163
+ console.log('Anchor TX:', verification.anchorTx);
164
+ }
165
+ ```
166
+
167
+ ### Verify by Bundle Hash
168
+
169
+ ```javascript
170
+ const verification = await proofrails.verify.byHash('0x123...');
171
+ ```
172
+
173
+ ### Get Verification Proof
174
+
175
+ ```javascript
176
+ const proof = await proofrails.verify.getProof('receipt-id');
177
+
178
+ console.log('Bundle Hash:', proof.bundleHash);
179
+ console.log('Block Number:', proof.blockNumber);
180
+ console.log('Timestamp:', proof.timestamp);
181
+ ```
182
+
183
+ ## Live Updates
184
+
185
+ ```javascript
186
+ const listener = proofrails.events.listen('receipt-id', update => {
187
+ console.log('Status:', update.status);
188
+
189
+ if (update.status === 'anchored') {
190
+ console.log('Receipt is now on chain');
191
+ listener.stop();
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
+ document.getElementById('receipt').innerHTML = widget.iframeHtml;
208
+ ```
209
+
210
+ ### Full Page URL
211
+
212
+ ```javascript
213
+ const pageUrl = proofrails.embed.fullPage('receipt-id');
214
+ ```
215
+
216
+ ## Networks
217
+
218
+ ```javascript
219
+ const proofrails = new ProofRails({
220
+ apiKey: 'your-key',
221
+ network: 'coston2'
222
+ });
223
+ ```
224
+
225
+ ```javascript
226
+ const proofrails = new ProofRails({
227
+ apiKey: 'your-key',
228
+ network: 'flare'
229
+ });
230
+ ```
231
+
232
+ ## License
233
+
234
+ MIT
235
+
236
+ ## Support
237
+
238
+ * Documentation, [https://www.flarestudio.xyz/sdk/proofrails-sdk/overview](https://www.flarestudio.xyz/sdk/proofrails-sdk/overview)
239
+ * Repository, [https://github.com/Elite-tch/Proofrails-sdk.git](https://github.com/Elite-tch/Proofrails-sdk.git)
240
+ * Email, [izuchukwujohnbosco95@gmail.com](mailto:izuchukwujohnbosco95@gmail.com)
241
+
242
+ **Made with ❤️ by ProofRails**
243
+
244
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proofrails/sdk",
3
- "version": "1.1.0",
3
+ "version": "1.2.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",