veilioexchange 0.1.0 → 0.3.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 (70) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +21 -21
  3. package/README.md +225 -113
  4. package/dist/cjs/auth.d.ts +15 -0
  5. package/dist/cjs/auth.d.ts.map +1 -1
  6. package/dist/cjs/auth.js +32 -0
  7. package/dist/cjs/auth.js.map +1 -1
  8. package/dist/cjs/deployments.js +2 -2
  9. package/dist/cjs/index.d.ts +260 -6
  10. package/dist/cjs/index.d.ts.map +1 -1
  11. package/dist/cjs/index.js +221 -62
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/servicesApi.d.ts +86 -0
  14. package/dist/cjs/servicesApi.d.ts.map +1 -0
  15. package/dist/cjs/servicesApi.js +177 -0
  16. package/dist/cjs/servicesApi.js.map +1 -0
  17. package/dist/cjs/solana/auction.d.ts +230 -0
  18. package/dist/cjs/solana/auction.d.ts.map +1 -0
  19. package/dist/cjs/solana/auction.js +546 -0
  20. package/dist/cjs/solana/auction.js.map +1 -0
  21. package/dist/cjs/solana/client.d.ts +100 -0
  22. package/dist/cjs/solana/client.d.ts.map +1 -0
  23. package/dist/cjs/solana/client.js +368 -0
  24. package/dist/cjs/solana/client.js.map +1 -0
  25. package/dist/cjs/solana/escrow.d.ts +193 -0
  26. package/dist/cjs/solana/escrow.d.ts.map +1 -0
  27. package/dist/cjs/solana/escrow.js +463 -0
  28. package/dist/cjs/solana/escrow.js.map +1 -0
  29. package/dist/cjs/solana/index.d.ts +9 -0
  30. package/dist/cjs/solana/index.d.ts.map +1 -0
  31. package/dist/cjs/solana/index.js +35 -0
  32. package/dist/cjs/solana/index.js.map +1 -0
  33. package/dist/cjs/solana/registry.d.ts +112 -0
  34. package/dist/cjs/solana/registry.d.ts.map +1 -0
  35. package/dist/cjs/solana/registry.js +305 -0
  36. package/dist/cjs/solana/registry.js.map +1 -0
  37. package/dist/esm/auth.d.ts +15 -0
  38. package/dist/esm/auth.d.ts.map +1 -1
  39. package/dist/esm/auth.js +28 -0
  40. package/dist/esm/auth.js.map +1 -1
  41. package/dist/esm/deployments.js +2 -2
  42. package/dist/esm/index.d.ts +260 -6
  43. package/dist/esm/index.d.ts.map +1 -1
  44. package/dist/esm/index.js +218 -61
  45. package/dist/esm/index.js.map +1 -1
  46. package/dist/esm/servicesApi.d.ts +86 -0
  47. package/dist/esm/servicesApi.d.ts.map +1 -0
  48. package/dist/esm/servicesApi.js +174 -0
  49. package/dist/esm/servicesApi.js.map +1 -0
  50. package/dist/esm/solana/auction.d.ts +230 -0
  51. package/dist/esm/solana/auction.d.ts.map +1 -0
  52. package/dist/esm/solana/auction.js +523 -0
  53. package/dist/esm/solana/auction.js.map +1 -0
  54. package/dist/esm/solana/client.d.ts +100 -0
  55. package/dist/esm/solana/client.d.ts.map +1 -0
  56. package/dist/esm/solana/client.js +361 -0
  57. package/dist/esm/solana/client.js.map +1 -0
  58. package/dist/esm/solana/escrow.d.ts +193 -0
  59. package/dist/esm/solana/escrow.d.ts.map +1 -0
  60. package/dist/esm/solana/escrow.js +444 -0
  61. package/dist/esm/solana/escrow.js.map +1 -0
  62. package/dist/esm/solana/index.d.ts +9 -0
  63. package/dist/esm/solana/index.d.ts.map +1 -0
  64. package/dist/esm/solana/index.js +9 -0
  65. package/dist/esm/solana/index.js.map +1 -0
  66. package/dist/esm/solana/registry.d.ts +112 -0
  67. package/dist/esm/solana/registry.d.ts.map +1 -0
  68. package/dist/esm/solana/registry.js +289 -0
  69. package/dist/esm/solana/registry.js.map +1 -0
  70. package/package.json +82 -55
package/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0
4
+
5
+ ### Added
6
+ - **Auction lifecycle (EVM, VeilNFTV4):** `settleAuction`, `finalizeSettlement`, `requestRefund(auctionId, evidenceHash)`,
7
+ `withdrawRefund`, `getPendingRefund`, `isNftAuction`, `waitForTransaction`. `finalizeSettlement` is the
8
+ completion path for NFT auctions (`acceptDataset` is blocked on-chain for NFTs); `claimAsset` now throws a
9
+ clear error for NFT auctions instead of sending a transaction that reverts.
10
+ - **Base Sepolia auctions:** `createVeilioAgent({ chainId: 84532 })` picks the Base Sepolia auction and Services
11
+ escrow defaults from `VEILIO_DEPLOYMENTS`. New exports: `VEILIO_SUPPORTED_CHAIN_IDS`, `getVeilioDeployment`,
12
+ `assertVeilioChainId`, `veilAuctionAbi`.
13
+ - **Off-chain Services API helper:** `createVeilioServicesApi({ apiBaseUrl, signer })` with `notifyDeposit`,
14
+ `submit` (requires `deliveryTxHash`, the on-chain `submitDelivery` tx), `requestRevision`, `approve`,
15
+ `cancel`, each signed with `signServiceAuth`. It never sends a `network` field; the server derives the
16
+ chain from the order. Session-authenticated reads: `getOrder`, `getPaymentRequest`, `listConversations`,
17
+ `getConversationMessages`, `getSession`, `getSessionHeaders`.
18
+ - **Read session auth:** `signServiceSession`, `isServiceSessionFresh`, `encodeServiceAuthHeader`,
19
+ `SERVICE_AUTH_HEADER` (`x-veilio-auth`), `SERVICE_SESSION_MAX_AGE_MS` (30 min).
20
+ - **Solana auction client:** `settleAuction`, `requestRefund`, `finalizeInspectionTimeout`, `finalizeRefundTimeout`.
21
+ - **Solana escrow:** `platformReviewer` / `platformFeeRecipient` client options used as defaults by `deposit()`.
22
+
23
+ ### Changed
24
+ - Every agent write (`commitBid`, `revealBid`, lifecycle calls) now checks `walletClient.chain` against the
25
+ agent's `chainId` and throws `CHAIN_MISMATCH` before sending.
26
+ - `PreparedBid.chainId` is the agent's actual chain (was always 97).
27
+ - `createVeilioAgent().services` uses the agent's `chainId` (was always 97).
28
+ - `revealBid` rejects reveals after `revealEndTime` with a hint to call `settleAuction`.
29
+ - `getAuctionResult` adds `chainId` and `winningBid`; `winningBidBnb` is kept as a deprecated alias.
30
+ - Solana `deposit()`: `reviewer` / `feeRecipient` are now optional (default to the platform options) and a
31
+ reviewer equal to the buyer or seller is rejected. The deployed program still accepts any buyer-chosen
32
+ reviewer; see the README security note.
33
+ - Solana `reveal_bid` instruction marks the bidder account writable (it receives the over-deposit refund).
34
+
35
+ ## 0.2.0
36
+
37
+ - Previous published release.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 VEILIO
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VEILIO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,113 +1,225 @@
1
- # veilioexchange
2
-
3
- TypeScript SDK for **VEILIO**: sealed-bid auctions for digital assets and milestone service escrow, built on [viem](https://viem.sh).
4
-
5
- - **Networks:** BNB Smart Chain Testnet (97) and Base Sepolia (84532). Testnet only.
6
- - **Formats:** ESM and CommonJS, with TypeScript types.
7
- - **Runtime:** Node.js 18+ or any modern browser.
8
-
9
- ```sh
10
- npm install veilioexchange viem
11
- ```
12
-
13
- `viem` is a peer dependency, so your app and the SDK share one copy.
14
-
15
- ## Auctions
16
-
17
- ```ts
18
- import { createPublicClient, createWalletClient, http } from 'viem';
19
- import { bscTestnet } from 'viem/chains';
20
- import { privateKeyToAccount } from 'viem/accounts';
21
- import { createVeilioAgent } from 'veilioexchange';
22
-
23
- const account = privateKeyToAccount(process.env.AGENT_PRIVATE_KEY as `0x${string}`);
24
- const publicClient = createPublicClient({ chain: bscTestnet, transport: http() });
25
- const walletClient = createWalletClient({ account, chain: bscTestnet, transport: http() });
26
-
27
- const agent = createVeilioAgent({
28
- publicClient,
29
- walletClient,
30
- account: account.address,
31
- apiBaseUrl: 'https://your-veilio-host', // needed for searchAssets / getAssetDetails
32
- });
33
-
34
- const { auctions } = await agent.listAuctions({ limit: 20 });
35
- const auctionId = auctions[0].id;
36
-
37
- // Sealed bid: random 32-byte secret + keccak256 commitment, computed locally.
38
- const bid = agent.prepareBid(auctionId, '0.05'); // max bid in BNB
39
- // Store `bid` (including bid.secret) somewhere durable and encrypted.
40
- // If the secret is lost the bid can never be revealed.
41
-
42
- await agent.commitBid(bid, '0.08'); // deposit >= max bid; over-deposit to hide your ceiling
43
- await agent.revealBid(bid); // during the Revealing window
44
-
45
- const result = await agent.getAuctionResult(auctionId);
46
- if (result.isWinner) await agent.claimAsset(auctionId);
47
- ```
48
-
49
- ## Services escrow
50
-
51
- ```ts
52
- import { createVeilioServicesClient, signServiceAuth } from 'veilioexchange';
53
-
54
- const services = createVeilioServicesClient({
55
- publicClient,
56
- walletClient,
57
- account: account.address,
58
- chainId: 97, // or 84532 for Base Sepolia (use matching viem clients)
59
- });
60
-
61
- const orderId = 'srv-order-uuid-101';
62
-
63
- const deposit = await services.deposit({
64
- orderId,
65
- seller: '0xSeller...',
66
- deadline: Math.floor(Date.now() / 1000) + 3 * 86400,
67
- amount: '0.25',
68
- });
69
- await deposit.wait();
70
-
71
- const order = await services.getOrder(orderId); // status: 'Funded'
72
- await (await services.submitDelivery(orderId, 'ipfs://QmProof')).wait(); // seller
73
- await (await services.releaseFunds(orderId)).wait(); // buyer; 5% fee on release
74
-
75
- // Fee-free exits: services.refund(orderId, reason), services.refundTimeout(orderId),
76
- // services.dispute(orderId, reason)
77
- ```
78
-
79
- ### Signed API calls
80
-
81
- Off-chain order actions on the VEILIO API carry an EIP-191 signature:
82
-
83
- ```ts
84
- const auth = await signServiceAuth(account, 'verify-deposit', orderId);
85
-
86
- await fetch(`https://your-veilio-host/api/orders/${orderId}/verify-deposit`, {
87
- method: 'POST',
88
- headers: { 'Content-Type': 'application/json' },
89
- body: JSON.stringify({ txHash: deposit.txHash, network: 'bnb:97', auth }),
90
- });
91
- ```
92
-
93
- ## Contract addresses
94
-
95
- Defaults live in `VEILIO_DEPLOYMENTS`. Every client takes a `contractAddress` option to point at your own deployment.
96
-
97
- | Network | Auction | Service escrow |
98
- |---|---|---|
99
- | BNB Testnet (97) | `0xc12EcD53B9dAE1753409B87f10Bf00684BF7d8B1` | `0x794f1610B5588a55B19D8c82e4381448a388C965` |
100
- | Base Sepolia (84532) | `0x2a56D1a2C8Ffc63b0b009fceEa9d8d182A17A025` | `0x13C16c508780639E86cA9d4322Ba9739C15e78Af` |
101
-
102
- ## Errors
103
-
104
- Failures are thrown as `VeilioSdkError` with a typed `code` (`INVALID_INPUT`, `CHAIN_MISMATCH`, `WALLET_REQUIRED`, `TRANSACTION_REVERTED`, ...) and a `retryable` flag.
105
-
106
- ## Security
107
-
108
- - Use a dedicated testnet wallet for agents and load its key from the environment. Never commit it.
109
- - Bid deposits and bidder addresses are public on-chain; only the bid value is sealed until reveal.
110
-
111
- ## License
112
-
113
- MIT
1
+ # veilioexchange
2
+
3
+ TypeScript SDK for **VEILIO**: sealed-bid auctions for digital assets and milestone service escrow, built on [viem](https://viem.sh).
4
+
5
+ - **Networks:** BNB Smart Chain Testnet (97), Base Sepolia (84532) and Solana Devnet. Testnet only.
6
+ - **Formats:** ESM and CommonJS, with TypeScript types.
7
+ - **Runtime:** Node.js 18+ or any modern browser.
8
+
9
+ ```sh
10
+ npm install veilioexchange viem
11
+ ```
12
+
13
+ `viem` is a peer dependency, so your app and the SDK share one copy.
14
+
15
+ ## Auctions
16
+
17
+ ```ts
18
+ import { createPublicClient, createWalletClient, http } from 'viem';
19
+ import { bscTestnet } from 'viem/chains';
20
+ import { privateKeyToAccount } from 'viem/accounts';
21
+ import { createVeilioAgent } from 'veilioexchange';
22
+
23
+ const account = privateKeyToAccount(process.env.AGENT_PRIVATE_KEY as `0x${string}`);
24
+ const publicClient = createPublicClient({ chain: bscTestnet, transport: http() });
25
+ const walletClient = createWalletClient({ account, chain: bscTestnet, transport: http() });
26
+
27
+ const agent = createVeilioAgent({
28
+ publicClient,
29
+ walletClient,
30
+ account: account.address,
31
+ chainId: 97, // default; 84532 = Base Sepolia (use viem's baseSepolia clients)
32
+ apiBaseUrl: 'https://your-veilio-host', // needed for searchAssets / getAssetDetails
33
+ });
34
+
35
+ const { auctions } = await agent.listAuctions({ limit: 20 });
36
+ const auctionId = auctions[0].id;
37
+
38
+ // Sealed bid: random 32-byte secret + keccak256 commitment, computed locally.
39
+ const bid = agent.prepareBid(auctionId, '0.05'); // max bid in BNB
40
+ // Store `bid` (including bid.secret) somewhere durable and encrypted.
41
+ // If the secret is lost the bid can never be revealed.
42
+
43
+ await agent.commitBid(bid, '0.08'); // deposit >= max bid; over-deposit to hide your ceiling
44
+ await agent.revealBid(bid); // during the Revealing window
45
+
46
+ // After revealEndTime anyone can settle; a winner moves the auction into Inspection.
47
+ await agent.waitForTransaction(await agent.settleAuction(auctionId));
48
+
49
+ const result = await agent.getAuctionResult(auctionId);
50
+ if (result.isWinner) {
51
+ if (await agent.isNftAuction(auctionId)) {
52
+ // NFT auctions: acceptDataset is blocked on-chain. Once inspection ends,
53
+ // finalizeSettlement() delivers the NFT and pays the seller (anyone can call it).
54
+ await agent.finalizeSettlement(auctionId);
55
+ } else {
56
+ await agent.claimAsset(auctionId); // acceptDataset
57
+ // or dispute during inspection: agent.requestRefund(auctionId, 'ipfs://QmEvidence')
58
+ }
59
+ }
60
+
61
+ // Losing deposits, over-deposits, seller proceeds and approved refunds are pull payments:
62
+ if ((await agent.getPendingRefund()) > 0n) await agent.withdrawRefund();
63
+ ```
64
+
65
+ ### Auction lifecycle (VeilNFTV4)
66
+
67
+ | Step | Method | Who | When |
68
+ |---|---|---|---|
69
+ | Commit | `commitBid(bid, deposit)` | bidder | Bidding |
70
+ | Reveal | `revealBid(bid)` | bidder | Revealing, before `revealEndTime` |
71
+ | Settle | `settleAuction(id)` | anyone | after `revealEndTime` |
72
+ | Accept (datasets only) | `claimAsset(id)` | winner | Inspection, before `inspectionEndTime` |
73
+ | Dispute | `requestRefund(id, evidenceHash)` | winner | Inspection, before `inspectionEndTime` |
74
+ | Complete (required for NFTs) | `finalizeSettlement(id)` | anyone | Inspection, after `inspectionEndTime` |
75
+ | Withdraw | `withdrawRefund()` | anyone with `getPendingRefund() > 0` | any time |
76
+
77
+ All write methods return the transaction hash; `waitForTransaction(hash)` waits and throws `TRANSACTION_REVERTED` on failure.
78
+ Every write checks that `walletClient.chain` matches the agent's `chainId` and throws `CHAIN_MISMATCH` before sending otherwise.
79
+ A refund request on the EVM contracts has no timeout: it stays open until the VEILIO reviewer resolves it.
80
+
81
+ ## Services escrow
82
+
83
+ ```ts
84
+ import { createVeilioServicesClient, signServiceAuth } from 'veilioexchange';
85
+
86
+ const services = createVeilioServicesClient({
87
+ publicClient,
88
+ walletClient,
89
+ account: account.address,
90
+ chainId: 97, // or 84532 for Base Sepolia (use matching viem clients)
91
+ });
92
+
93
+ const orderId = 'srv-order-uuid-101';
94
+
95
+ const deposit = await services.deposit({
96
+ orderId,
97
+ seller: '0xSeller...',
98
+ deadline: Math.floor(Date.now() / 1000) + 3 * 86400,
99
+ amount: '0.25',
100
+ });
101
+ await deposit.wait();
102
+
103
+ const order = await services.getOrder(orderId); // status: 'Funded'
104
+ await (await services.submitDelivery(orderId, 'ipfs://QmProof')).wait(); // seller
105
+ await (await services.releaseFunds(orderId)).wait(); // buyer; 5% fee on release
106
+
107
+ // Fee-free exits: services.refund(orderId, reason), services.refundTimeout(orderId),
108
+ // services.dispute(orderId, reason)
109
+ ```
110
+
111
+ ### Keeping the VEILIO app in sync (off-chain API)
112
+
113
+ The escrow contract moves funds, but the order status in the VEILIO app only changes when the API
114
+ is told about each step. `createVeilioServicesApi` signs every call with `signServiceAuth` (EIP-191):
115
+
116
+ ```ts
117
+ import { createVeilioServicesApi } from 'veilioexchange';
118
+
119
+ const api = createVeilioServicesApi({ apiBaseUrl: 'https://your-veilio-host', signer: account });
120
+
121
+ await api.notifyDeposit({ orderId, txHash: deposit.txHash }); // buyer -> InProgress
122
+ const delivery = await services.submitDelivery(orderId, 'ipfs://QmProof'); // seller, on-chain first
123
+ await delivery.wait();
124
+ await api.submit({ orderId, deliveryTxHash: delivery.txHash, description: 'v1 delivered', deliverableReferences: ['ipfs://QmProof'] });
125
+ await api.requestRevision({ orderId, feedback: 'Please add the appendix' }); // buyer
126
+ await api.approve({ orderId, releaseTxHash: release.txHash }); // buyer -> Completed
127
+ await api.cancel({ orderId, reason: 'Mutual cancellation', txHash }); // funded orders need the refund tx
128
+ ```
129
+
130
+ No `network` field is sent: the server derives the chain from the order. `submit` requires the
131
+ confirmed on-chain `submitDelivery` transaction (`deliveryTxHash`); the server checks its
132
+ `DeliverySubmitted` event. For custom requests, `signServiceAuth(account, action, orderId)` returns
133
+ the `{ address, signature, timestamp, nonce }` payload.
134
+
135
+ Reads use a 30-minute session signed once (`signServiceSession`) and sent in the `x-veilio-auth`
136
+ header; the helper caches it and re-signs a minute before expiry. It never authorizes state changes.
137
+
138
+ ```ts
139
+ const { order } = await api.getOrder(orderId); // status, paymentStatus, network
140
+ const { conversations } = await api.listConversations();
141
+ await api.getPaymentRequest(paymentRequestId);
142
+ await api.getConversationMessages(conversationId);
143
+ const headers = await api.getSessionHeaders(); // for your own GET requests
144
+ ```
145
+
146
+ ## Solana Devnet
147
+
148
+ Solana lives in its own entry point so EVM-only users never load `@solana/web3.js`:
149
+
150
+ ```sh
151
+ npm install veilioexchange @solana/web3.js
152
+ ```
153
+
154
+ ```ts
155
+ import { Connection, Keypair, clusterApiUrl } from '@solana/web3.js';
156
+ import { createVeilioSolanaClient, keypairSigner } from 'veilioexchange/solana';
157
+
158
+ const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
159
+ const agentKey = Keypair.fromSecretKey(/* load your devnet key from a secret store */);
160
+
161
+ const solana = createVeilioSolanaClient({
162
+ connection,
163
+ signer: keypairSigner(agentKey), // or a Phantom provider: window.phantom.solana
164
+ platformReviewer: 'VeilioReviewerWallet...', // default dispute reviewer for deposit()
165
+ platformFeeRecipient: 'VeilioFeeWallet...', // default fee recipient for deposit()
166
+ });
167
+
168
+ // Sealed-bid auction
169
+ const auctions = await solana.listAuctions();
170
+ const bid = solana.prepareBid(auctions[0].auctionId, '0.25'); // max bid in SOL
171
+ // Store `bid` (salt included) in encrypted storage before committing.
172
+ await solana.commitBid(bid, '0.3');
173
+ await solana.revealBid(bid);
174
+ await solana.settleAuction(bid.auctionId); // anyone, after reveal_end_time
175
+ // Winner during inspection: solana.acceptDataset(id, seller) or solana.requestRefund(id, sha256Hex)
176
+ // Anyone after inspection: solana.finalizeInspectionTimeout(id) (pays the seller)
177
+ // Winner, reviewer silent for 7 days: solana.finalizeRefundTimeout(id)
178
+ await solana.claimRefund(bid.auctionId); // losing bidders reclaim deposits
179
+
180
+ // Service escrow (reviewer / feeRecipient default to the platform options above)
181
+ await solana.deposit({
182
+ orderId: 'ord-1739-abc12', // up to 32 bytes, or 32-byte hex
183
+ seller: 'SellerBase58...',
184
+ amountSol: '1.5',
185
+ deadline: Math.floor(Date.now() / 1000) + 3 * 86400,
186
+ });
187
+ await solana.submitDelivery('ord-1739-abc12', 'ipfs://QmProof'); // seller
188
+ await solana.releaseFunds('ord-1739-abc12'); // buyer
189
+ ```
190
+
191
+ Solana support needs Node.js 18+ (it uses `node:crypto`). Base58 addresses are case-sensitive; never lowercase them.
192
+
193
+ > **Reviewer risk (Solana escrow).** The deployed escrow program stores whatever `reviewer` and
194
+ > `feeRecipient` the buyer passes to `deposit`; there is no on-chain platform config yet. A reviewer
195
+ > controlled by one party can resolve a dispute 100% in its favour. The SDK defaults both to
196
+ > `platformReviewer` / `platformFeeRecipient` and rejects a reviewer equal to the buyer or seller,
197
+ > but a buyer using another client can still pick any wallet. Sellers should check
198
+ > `(await solana.getEscrowOrder(id))?.reviewer` before starting work.
199
+
200
+ | Program (Devnet) | ID |
201
+ |---|---|
202
+ | Auction | `5Tw1iJGN1hhyRzepbD5eLoaRoZTEiKcqrh2HoZYhYEta` |
203
+ | Service escrow | `5Vj4y8BT74PDe5VwLuDp9agTR5ak4vtZdwxnBfRW3R8s` |
204
+
205
+ ## Contract addresses
206
+
207
+ Defaults live in `VEILIO_DEPLOYMENTS` (also `getVeilioDeployment(chainId)`) and are picked by `chainId`. Every client takes a `contractAddress` option to point at your own deployment. Both EVM auction addresses are `VeilNFTV4`.
208
+
209
+ | Network | Auction | Service escrow |
210
+ |---|---|---|
211
+ | BNB Testnet (97) | `0xc12EcD53B9dAE1753409B87f10Bf00684BF7d8B1` | `0x794f1610B5588a55B19D8c82e4381448a388C965` |
212
+ | Base Sepolia (84532) | `0xc12EcD53B9dAE1753409B87f10Bf00684BF7d8B1` | `0x794f1610B5588a55B19D8c82e4381448a388C965` |
213
+
214
+ ## Errors
215
+
216
+ Failures are thrown as `VeilioSdkError` with a typed `code` (`INVALID_INPUT`, `CHAIN_MISMATCH`, `WALLET_REQUIRED`, `TRANSACTION_REVERTED`, ...) and a `retryable` flag.
217
+
218
+ ## Security
219
+
220
+ - Use a dedicated testnet wallet for agents and load its key from the environment. Never commit it.
221
+ - Bid deposits and bidder addresses are public on-chain; only the bid value is sealed until reveal.
222
+
223
+ ## License
224
+
225
+ MIT
@@ -28,4 +28,19 @@ export declare function createServiceAuthMessage(input: {
28
28
  * (e.g. 'accept-payment-request', 'verify-deposit', 'submit', 'revision', 'approve', 'cancel').
29
29
  */
30
30
  export declare function signServiceAuth(signer: MessageSigner, action: string, orderId: string): Promise<ServiceAuthPayload>;
31
+ export declare const SERVICE_SESSION_ACTION = "services-session";
32
+ export declare const SERVICE_SESSION_SCOPE = "session";
33
+ /** The server accepts a session for 30 minutes after its timestamp. */
34
+ export declare const SERVICE_SESSION_MAX_AGE_MS: number;
35
+ /** Header that carries the JSON-encoded session payload on GET requests. */
36
+ export declare const SERVICE_AUTH_HEADER = "x-veilio-auth";
37
+ /**
38
+ * Signs a reusable read/chat session (nonce not consumed by the server). It authorizes reads and
39
+ * chat only, never escrow state changes, which need `signServiceAuth` per request.
40
+ */
41
+ export declare function signServiceSession(signer: MessageSigner): Promise<ServiceAuthPayload>;
42
+ /** True while a session is at least one minute away from server-side expiry. */
43
+ export declare function isServiceSessionFresh(auth: ServiceAuthPayload | null | undefined, address?: string): boolean;
44
+ /** `{ 'x-veilio-auth': JSON }` header map for a session payload. */
45
+ export declare function encodeServiceAuthHeader(auth: ServiceAuthPayload): Record<string, string>;
31
46
  //# sourceMappingURL=auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAGzC,mEAAmE;AACnE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,gGAAgG;AAChG,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC1D;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,IAAI,MAAM,CAU1C;AAED,kFAAkF;AAClF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,MAAM,CAUT;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,kBAAkB,CAAC,CAM7B"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAGzC,mEAAmE;AACnE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACj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CAExF"}
package/dist/cjs/auth.js CHANGED
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SERVICE_AUTH_HEADER = exports.SERVICE_SESSION_MAX_AGE_MS = exports.SERVICE_SESSION_SCOPE = exports.SERVICE_SESSION_ACTION = void 0;
3
4
  exports.generateAuthNonce = generateAuthNonce;
4
5
  exports.createServiceAuthMessage = createServiceAuthMessage;
5
6
  exports.signServiceAuth = signServiceAuth;
7
+ exports.signServiceSession = signServiceSession;
8
+ exports.isServiceSessionFresh = isServiceSessionFresh;
9
+ exports.encodeServiceAuthHeader = encodeServiceAuthHeader;
6
10
  const errors_js_1 = require("./errors.js");
7
11
  /** Random 16-hex-character nonce from a cryptographically secure source. */
8
12
  function generateAuthNonce() {
@@ -39,4 +43,32 @@ async function signServiceAuth(signer, action, orderId) {
39
43
  const signature = await signer.signMessage({ message });
40
44
  return { address: signer.address, signature, timestamp, nonce };
41
45
  }
46
+ // ---------------------------------------------------------------------------
47
+ // Read / chat session (matches the VEILIO server's lib/serviceAuth.ts scheme)
48
+ // ---------------------------------------------------------------------------
49
+ exports.SERVICE_SESSION_ACTION = 'services-session';
50
+ exports.SERVICE_SESSION_SCOPE = 'session';
51
+ /** The server accepts a session for 30 minutes after its timestamp. */
52
+ exports.SERVICE_SESSION_MAX_AGE_MS = 30 * 60 * 1000;
53
+ /** Header that carries the JSON-encoded session payload on GET requests. */
54
+ exports.SERVICE_AUTH_HEADER = 'x-veilio-auth';
55
+ /**
56
+ * Signs a reusable read/chat session (nonce not consumed by the server). It authorizes reads and
57
+ * chat only, never escrow state changes, which need `signServiceAuth` per request.
58
+ */
59
+ function signServiceSession(signer) {
60
+ return signServiceAuth(signer, exports.SERVICE_SESSION_ACTION, exports.SERVICE_SESSION_SCOPE);
61
+ }
62
+ /** True while a session is at least one minute away from server-side expiry. */
63
+ function isServiceSessionFresh(auth, address) {
64
+ if (!auth?.signature)
65
+ return false;
66
+ if (address && auth.address.toLowerCase() !== address.toLowerCase())
67
+ return false;
68
+ return Date.now() - auth.timestamp < exports.SERVICE_SESSION_MAX_AGE_MS - 60 * 1000;
69
+ }
70
+ /** `{ 'x-veilio-auth': JSON }` header map for a session payload. */
71
+ function encodeServiceAuthHeader(auth) {
72
+ return { [exports.SERVICE_AUTH_HEADER]: JSON.stringify(auth) };
73
+ }
42
74
  //# sourceMappingURL=auth.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":";;AAkBA,8CAUC;AAGD,4DAgBC;AAMD,0CAUC;AA9DD,2CAA6C;AAgB7C,4EAA4E;AAC5E,SAAgB,iBAAiB;IAC/B,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC;IACpC,IAAI,CAAC,SAAS,EAAE,eAAe,EAAE,CAAC;QAChC,MAAM,IAAI,0BAAc,CAAC;YACvB,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,kFAAkF;SAC5F,CAAC,CAAC;IACL,CAAC;IACD,MAAM,KAAK,GAAG,SAAS,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAClF,CAAC;AAED,kFAAkF;AAClF,SAAgB,wBAAwB,CAAC,KAMxC;IACC,OAAO;QACL,kCAAkC;QAClC,WAAW,KAAK,CAAC,MAAM,EAAE;QACzB,aAAa,KAAK,CAAC,OAAO,EAAE;QAC5B,WAAW,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE;QACxC,cAAc,KAAK,CAAC,SAAS,EAAE;QAC/B,UAAU,KAAK,CAAC,KAAK,EAAE;QACv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,CAAC,MAAM,EAAE,8BAAsB,EAAE,6BAAqB,CAAC,CAAC;AAChF,CAAC;AAED,gFAAgF;AAChF,SAAgB,qBAAqB,CAAC,IAA2C,EAAE,OAAgB;IACjG,IAAI,CAAC,IAAI,EAAE,SAAS;QAAE,OAAO,KAAK,CAAC;IACnC,IAAI,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,WAAW,EAAE;QAAE,OAAO,KAAK,CAAC;IAClF,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,GAAG,kCAA0B,GAAG,EAAE,GAAG,IAAI,CAAC;AAC9E,CAAC;AAED,oEAAoE;AACpE,SAAgB,uBAAuB,CAAC,IAAwB;IAC9D,OAAO,EAAE,CAAC,2BAAmB,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;AACzD,CAAC"}
@@ -15,8 +15,8 @@ exports.VEILIO_DEPLOYMENTS = {
15
15
  },
16
16
  baseSepolia: {
17
17
  chainId: 84532,
18
- auction: '0x2a56D1a2C8Ffc63b0b009fceEa9d8d182A17A025',
19
- serviceEscrow: '0x13C16c508780639E86cA9d4322Ba9739C15e78Af',
18
+ auction: '0xc12EcD53B9dAE1753409B87f10Bf00684BF7d8B1',
19
+ serviceEscrow: '0x794f1610B5588a55B19D8c82e4381448a388C965',
20
20
  serviceRegistry: '0x74a6Bf3ed462898F7b3E13e7F4d1c444570bCb88',
21
21
  },
22
22
  };