@pakt/psilo 0.0.1 → 0.0.3
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 +98 -61
- package/dist/main.d.ts +58 -52
- package/dist/main.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# PsiloSDK
|
|
2
2
|
|
|
3
|
-
PsiloSDK is the official TypeScript SDK for interacting
|
|
3
|
+
PsiloSDK is the official TypeScript SDK for interacting with Pakt's production-ready EVM escrow service. It provides a typed interface over the Pakt Escrow REST API for creating, managing, and releasing non-custodial escrow wallets deployed via `Psilo-Contracts`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Authentication uses SIWA (Sign In With Agent) — agents authenticate via ERC-8128 HTTP Message Signatures with SIWA receipts.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -14,94 +14,131 @@ yarn add @pakt/psilo-sdk
|
|
|
14
14
|
|
|
15
15
|
## Setup & Initialization
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Initialise the PsiloSDK like so:
|
|
18
|
+
|
|
19
|
+
Development baseUrl: `https://devescrow.psiloai.com`
|
|
20
|
+
|
|
21
|
+
Production baseUrl: `https://escrow.psiloai.com`
|
|
18
22
|
|
|
19
23
|
```typescript
|
|
20
24
|
import { PsiloSDK } from "@pakt/psilo-sdk";
|
|
21
25
|
|
|
22
26
|
const sdk = await PsiloSDK.init({
|
|
23
|
-
baseUrl: "
|
|
24
|
-
verbose: true //
|
|
27
|
+
baseUrl: "https://devescrow.psiloai.com", //for development
|
|
28
|
+
verbose: true // optional logging
|
|
25
29
|
});
|
|
26
30
|
```
|
|
27
31
|
|
|
28
|
-
##
|
|
32
|
+
## Escrow Lifecycle
|
|
33
|
+
|
|
34
|
+
The escrow flow has four phases:
|
|
35
|
+
|
|
36
|
+
1. **Create** — server deploys the escrow contract and returns the address plus unsigned deposit transaction
|
|
37
|
+
2. **Deposit** — buyer signs and broadcasts the deposit transaction client-side
|
|
38
|
+
3. **Mark ready** — seller and buyer each call `updateStatus` to signal readiness; returns an unsigned transaction for each party to sign and send
|
|
39
|
+
4. **Release** — system triggers `release` once both parties have marked ready
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
---
|
|
31
42
|
|
|
32
|
-
|
|
33
|
-
|
|
43
|
+
## API Reference
|
|
44
|
+
|
|
45
|
+
### Chains & Assets
|
|
46
|
+
|
|
47
|
+
Discover supported networks and tokens before creating an escrow.
|
|
34
48
|
|
|
35
49
|
```typescript
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
console.log("Predicted address:", computed.data.predictedAddress);
|
|
50
|
+
// List all supported chains
|
|
51
|
+
const { data } = await sdk.escrow.getChains();
|
|
52
|
+
// data.chains: Array<{ chainId, name, network, nativeCurrency }>
|
|
53
|
+
|
|
54
|
+
// List supported assets for a chain
|
|
55
|
+
const { data } = await sdk.escrow.getAssets("43113");
|
|
56
|
+
// data.assets: Array<{ address, symbol, name, decimals, isNative }>
|
|
45
57
|
```
|
|
46
58
|
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
### 1. Create Escrow
|
|
62
|
+
|
|
63
|
+
The server calls `EscrowFactory.createEscrow()` using its configured private key and returns the deployed `EscrowWallet` address along with the unsigned deposit transaction for the buyer to send.
|
|
49
64
|
|
|
50
65
|
```typescript
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
const { data } = await sdk.escrow.create({
|
|
67
|
+
chainId: "43113", // EIP-155 chain ID
|
|
68
|
+
buyer: "0xBuyerAddress...",
|
|
69
|
+
seller: "0xSellerAddress...",
|
|
70
|
+
title: "Website redesign",
|
|
71
|
+
description: "Full redesign of landing page", // optional
|
|
72
|
+
amount: "100", // in token units
|
|
73
|
+
asset: "0x5425890298aed601595a70AB815c96711a31Bc65", // token contract address
|
|
74
|
+
expiration: "1735689600", // unix timestamp, optional
|
|
75
|
+
releaseType: "0" // 0–255, optional
|
|
59
76
|
});
|
|
60
|
-
|
|
77
|
+
|
|
78
|
+
const { escrowAddress, approve, deposit } = data.onChain;
|
|
79
|
+
// If asset requires allowance: sign and send `approve` tx first
|
|
80
|
+
// Then sign and send `deposit` tx to fund the escrow
|
|
61
81
|
```
|
|
62
82
|
|
|
63
|
-
|
|
64
|
-
|
|
83
|
+
**Response fields:**
|
|
84
|
+
|
|
85
|
+
| Field | Description |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `onChain.escrowAddress` | Deployed escrow contract address |
|
|
88
|
+
| `onChain.approve` | ERC-20 approve tx to sign/send (null for native tokens) |
|
|
89
|
+
| `onChain.deposit` | Deposit tx to sign/send |
|
|
90
|
+
| `onChain.txHash` | Factory deployment tx hash |
|
|
91
|
+
| `buyerWallet` / `sellerWallet` / `arbiterWallet` | Party addresses |
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
### 2. Query Status
|
|
65
96
|
|
|
66
97
|
```typescript
|
|
67
|
-
await sdk.escrow.
|
|
68
|
-
|
|
69
|
-
|
|
98
|
+
const { data } = await sdk.escrow.getStatus("43113", "0xEscrowAddress...");
|
|
99
|
+
|
|
100
|
+
console.log(data.deposited); // buyer has funded the escrow
|
|
101
|
+
console.log(data.readyForRelease); // seller has marked ready
|
|
102
|
+
console.log(data.buyerReleaseReady); // buyer has marked ready
|
|
103
|
+
console.log(data.balance); // current balance (wei / smallest unit)
|
|
70
104
|
```
|
|
71
105
|
|
|
72
|
-
|
|
73
|
-
|
|
106
|
+
**Response fields:** `chainId`, `escrow`, `buyer`, `seller`, `arbiter`, `deposited`, `released`, `readyForRelease`, `buyerReleaseReady`, `balance`
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### 3. Mark Ready (Seller & Buyer)
|
|
111
|
+
|
|
112
|
+
Both parties must signal readiness before the escrow can be released. `updateStatus` checks the provided address against the escrow contract and returns the appropriate unsigned transaction:
|
|
113
|
+
|
|
114
|
+
- **Seller address** → `markReady` transaction
|
|
115
|
+
- **Buyer address** → `markBuyerEscrowReleaseReady` transaction
|
|
74
116
|
|
|
75
117
|
```typescript
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// Query all
|
|
81
|
-
const escrows = await sdk.escrow.list({
|
|
82
|
-
sender: "0xSenderAddress...",
|
|
83
|
-
status: "deposited"
|
|
118
|
+
const { data } = await sdk.escrow.updateStatus({
|
|
119
|
+
chainId: "43113",
|
|
120
|
+
escrow: "0xEscrowAddress...",
|
|
121
|
+
address: "0xSellerOrBuyerAddress..."
|
|
84
122
|
});
|
|
123
|
+
|
|
124
|
+
// data is a PrepareTransactionResponse — sign and broadcast it client-side
|
|
125
|
+
// { to, data, value, chainId, gas, maxFeePerGas, maxPriorityFeePerGas, type, nonce, instructions }
|
|
85
126
|
```
|
|
86
127
|
|
|
87
|
-
|
|
88
|
-
The MPC-shard functionality is exposed through signing a release using 2-of-3 configured authority.
|
|
128
|
+
---
|
|
89
129
|
|
|
90
|
-
|
|
91
|
-
// Ask the sender to sign
|
|
92
|
-
const senderSignature = await sdk.escrow.signRelease(escrowAddress, {
|
|
93
|
-
signerAddress: "0xSenderAddress...",
|
|
94
|
-
privateKey: "0x..." // Optional if managed by the MCP server environment
|
|
95
|
-
});
|
|
130
|
+
### 4. Release Escrow
|
|
96
131
|
|
|
97
|
-
|
|
98
|
-
const receiverSignature = await sdk.escrow.signRelease(escrowAddress, {
|
|
99
|
-
signerAddress: "0xReceiverAddress..."
|
|
100
|
-
});
|
|
132
|
+
System-only endpoint. The server's arbiter key signs the on-chain release. Requires the `X-Release-Secret` header to be set — this should only be called by your backend/system trigger after confirming both parties have marked ready.
|
|
101
133
|
|
|
102
|
-
|
|
103
|
-
await sdk.escrow.release(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
134
|
+
```typescript
|
|
135
|
+
const { data } = await sdk.escrow.release(
|
|
136
|
+
"43113", // chainId
|
|
137
|
+
"0xEscrowAddress...",
|
|
138
|
+
{ recipient: "0xSellerAddress..." } // optional, defaults to seller
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// data: { success, txHash, escrowAddress, arbiter }
|
|
107
142
|
```
|
|
143
|
+
|
|
144
|
+
> **Note:** Call `getStatus` first to confirm `readyForRelease` and `buyerReleaseReady` are both `true` before triggering release.
|
package/dist/main.d.ts
CHANGED
|
@@ -51,23 +51,27 @@ declare const parseUrlWithQuery: (url: string, filter: object | any) => string;
|
|
|
51
51
|
interface EscrowModuleType {
|
|
52
52
|
create(data: CreateEscrowDto): Promise<ResponseDto<CreateEscrowResponse>>;
|
|
53
53
|
getStatus(chainId: string, escrowAddress: string): Promise<ResponseDto<EscrowStatusResponse>>;
|
|
54
|
-
release(escrowAddress: string, data?: ReleaseDto): Promise<ResponseDto<ReleaseResponse>>;
|
|
55
|
-
updateStatus(
|
|
56
|
-
prepareRelease(escrowAddress: string, recipient?: string): Promise<ResponseDto<PrepareTransactionResponse>>;
|
|
57
|
-
list(params?: ListEscrowsParams): Promise<ResponseDto<ListEscrowsResponse>>;
|
|
54
|
+
release(chainId: string, escrowAddress: string, data?: ReleaseDto): Promise<ResponseDto<ReleaseResponse>>;
|
|
55
|
+
updateStatus(data: UpdateEscrowStatusDto): Promise<ResponseDto<PrepareTransactionResponse>>;
|
|
58
56
|
getChains(): Promise<ResponseDto<GetEscrowChainsResponseDto>>;
|
|
59
57
|
getAssets(chainId: string): Promise<ResponseDto<GetEscrowAssetsResponseDto>>;
|
|
60
58
|
}
|
|
59
|
+
interface EscrowWebhookConfigDto {
|
|
60
|
+
webhookUrl: string;
|
|
61
|
+
webHookType: "a2a" | "json";
|
|
62
|
+
}
|
|
61
63
|
interface CreateEscrowDto {
|
|
62
64
|
chainId: string;
|
|
63
65
|
buyer: string;
|
|
64
66
|
seller: string;
|
|
67
|
+
creator?: string;
|
|
65
68
|
title: string;
|
|
66
69
|
description?: string;
|
|
67
70
|
amount: string;
|
|
68
71
|
asset: string;
|
|
69
72
|
expiration?: string;
|
|
70
73
|
releaseType?: string;
|
|
74
|
+
webhookUrls?: EscrowWebhookConfigDto;
|
|
71
75
|
}
|
|
72
76
|
interface CreateEscrowResponse {
|
|
73
77
|
buyerWallet: string;
|
|
@@ -95,19 +99,6 @@ interface CreateEscrowResponse {
|
|
|
95
99
|
};
|
|
96
100
|
};
|
|
97
101
|
}
|
|
98
|
-
interface ComputeAddressParams {
|
|
99
|
-
sender: string;
|
|
100
|
-
receiver: string;
|
|
101
|
-
asset: string;
|
|
102
|
-
amount: string;
|
|
103
|
-
originator: string;
|
|
104
|
-
salt: string;
|
|
105
|
-
metadataHash?: string;
|
|
106
|
-
}
|
|
107
|
-
interface ComputeAddressResponse {
|
|
108
|
-
predictedAddress: string;
|
|
109
|
-
exists: boolean;
|
|
110
|
-
}
|
|
111
102
|
interface EscrowStatusResponse {
|
|
112
103
|
chainId: string;
|
|
113
104
|
escrow: string;
|
|
@@ -152,7 +143,8 @@ interface ReleaseResponse {
|
|
|
152
143
|
interface UpdateEscrowStatusDto {
|
|
153
144
|
chainId: string;
|
|
154
145
|
escrow: string;
|
|
155
|
-
address
|
|
146
|
+
address?: string;
|
|
147
|
+
webhookUrl?: string;
|
|
156
148
|
}
|
|
157
149
|
interface PrepareTransactionResponse {
|
|
158
150
|
to: string;
|
|
@@ -168,29 +160,6 @@ interface PrepareTransactionResponse {
|
|
|
168
160
|
buyer?: string;
|
|
169
161
|
nonce?: string;
|
|
170
162
|
}
|
|
171
|
-
interface ListEscrowsParams {
|
|
172
|
-
sender?: string;
|
|
173
|
-
receiver?: string;
|
|
174
|
-
status?: "pending" | "deposited" | "released";
|
|
175
|
-
page?: number;
|
|
176
|
-
limit?: number;
|
|
177
|
-
}
|
|
178
|
-
interface EscrowListItem {
|
|
179
|
-
address: string;
|
|
180
|
-
sender: string;
|
|
181
|
-
receiver: string;
|
|
182
|
-
asset: string;
|
|
183
|
-
amount: string;
|
|
184
|
-
deposited: boolean;
|
|
185
|
-
released: boolean;
|
|
186
|
-
createdAt: string;
|
|
187
|
-
}
|
|
188
|
-
interface ListEscrowsResponse {
|
|
189
|
-
total: number;
|
|
190
|
-
page: number;
|
|
191
|
-
limit: number;
|
|
192
|
-
escrows: EscrowListItem[];
|
|
193
|
-
}
|
|
194
163
|
interface EscrowNativeCurrencyDto {
|
|
195
164
|
name: string;
|
|
196
165
|
symbol: string;
|
|
@@ -223,24 +192,61 @@ declare class EscrowService implements EscrowModuleType {
|
|
|
223
192
|
constructor(id: string);
|
|
224
193
|
create(data: CreateEscrowDto): Promise<ResponseDto<CreateEscrowResponse>>;
|
|
225
194
|
getStatus(chainId: string, escrowAddress: string): Promise<ResponseDto<EscrowStatusResponse>>;
|
|
226
|
-
updateStatus(
|
|
227
|
-
|
|
228
|
-
address: string;
|
|
229
|
-
}): Promise<ResponseDto<PrepareTransactionResponse>>;
|
|
230
|
-
prepareRelease(escrowAddress: string, recipient?: string): Promise<ResponseDto<PrepareTransactionResponse>>;
|
|
231
|
-
release(escrowAddress: string, data?: {
|
|
232
|
-
recipient?: string;
|
|
233
|
-
}): Promise<ResponseDto<ReleaseResponse>>;
|
|
234
|
-
list(params?: ListEscrowsParams): Promise<ResponseDto<ListEscrowsResponse>>;
|
|
195
|
+
updateStatus(data: UpdateEscrowStatusDto): Promise<ResponseDto<PrepareTransactionResponse>>;
|
|
196
|
+
release(chainId: string, escrowAddress: string, data?: ReleaseDto): Promise<ResponseDto<ReleaseResponse>>;
|
|
235
197
|
getChains(): Promise<ResponseDto<GetEscrowChainsResponseDto>>;
|
|
236
198
|
getAssets(chainId: string): Promise<ResponseDto<GetEscrowAssetsResponseDto>>;
|
|
237
199
|
}
|
|
238
200
|
|
|
201
|
+
interface AuthModuleType {
|
|
202
|
+
register(data: RegisterDto): Promise<ResponseDto<RegisterResponse>>;
|
|
203
|
+
nonce(data: NonceDto): Promise<ResponseDto<NonceResponse>>;
|
|
204
|
+
verify(data: VerifyDto): Promise<ResponseDto<VerifyResponse>>;
|
|
205
|
+
}
|
|
206
|
+
interface NonceDto {
|
|
207
|
+
address: string;
|
|
208
|
+
agentId: string;
|
|
209
|
+
agentRegistry?: string;
|
|
210
|
+
}
|
|
211
|
+
interface NonceResponse {
|
|
212
|
+
nonce: string;
|
|
213
|
+
[key: string]: unknown;
|
|
214
|
+
}
|
|
215
|
+
interface VerifyDto {
|
|
216
|
+
message: string;
|
|
217
|
+
signature: string;
|
|
218
|
+
}
|
|
219
|
+
interface VerifyResponse {
|
|
220
|
+
token: string;
|
|
221
|
+
[key: string]: unknown;
|
|
222
|
+
}
|
|
223
|
+
interface RegisterDto {
|
|
224
|
+
address: string;
|
|
225
|
+
agentId: string;
|
|
226
|
+
agentRegistry?: string;
|
|
227
|
+
chainId?: string;
|
|
228
|
+
name?: string;
|
|
229
|
+
webhookUrl?: string;
|
|
230
|
+
}
|
|
231
|
+
interface RegisterResponse {
|
|
232
|
+
[key: string]: unknown;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
declare class AuthService implements AuthModuleType {
|
|
236
|
+
private id;
|
|
237
|
+
private connector;
|
|
238
|
+
constructor(id: string);
|
|
239
|
+
register(data: RegisterDto): Promise<ResponseDto<RegisterResponse>>;
|
|
240
|
+
nonce(data: NonceDto): Promise<ResponseDto<NonceResponse>>;
|
|
241
|
+
verify(data: VerifyDto): Promise<ResponseDto<VerifyResponse>>;
|
|
242
|
+
}
|
|
243
|
+
|
|
239
244
|
interface PsiloSDKConfig {
|
|
240
|
-
baseUrl
|
|
245
|
+
baseUrl?: string;
|
|
241
246
|
verbose?: boolean;
|
|
242
247
|
}
|
|
243
248
|
declare class PsiloSDK {
|
|
249
|
+
readonly auth: AuthService;
|
|
244
250
|
readonly escrow: EscrowService;
|
|
245
251
|
readonly connector: Connector;
|
|
246
252
|
constructor(id: string);
|
|
@@ -255,4 +261,4 @@ declare class SDKError extends Error {
|
|
|
255
261
|
constructor(message: string, code?: string, details?: any);
|
|
256
262
|
}
|
|
257
263
|
|
|
258
|
-
export {
|
|
264
|
+
export { AuthModuleType, AuthService, Connector, CreateEscrowDto, CreateEscrowResponse, DepositDto, DepositResponse, ErrorUtils, EscrowAssetDto, EscrowChainDto, EscrowModuleType, EscrowNativeCurrencyDto, EscrowService, EscrowStatusResponse, EscrowWebhookConfigDto, GetEscrowAssetsResponseDto, GetEscrowChainsResponseDto, IAny, NonceDto, NonceResponse, PrepareTransactionResponse, PsiloSDK, PsiloSDKConfig, RegisterDto, RegisterResponse, ReleaseDto, ReleaseResponse, ResponseDto, SDKError, SignReleaseDto, SignReleaseResponse, StandardResponse, Status, UpdateEscrowStatusDto, VerifyDto, VerifyResponse, parseUrlWithQuery };
|
package/dist/main.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var G=Object.create;var g=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames,J=Object.getOwnPropertySymbols,Y=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var F=(r,t,e)=>t in r?g(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,d=(r,t)=>{for(var e in t||(t={}))P.call(t,e)&&F(r,e,t[e]);if(J)for(var e of J(t))Z.call(t,e)&&F(r,e,t[e]);return r};var s=(r,t)=>g(r,"name",{value:t,configurable:!0});var k=(r,t)=>{for(var e in t)g(r,e,{get:t[e],enumerable:!0})},W=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of X(t))!P.call(r,o)&&o!==e&&g(r,o,{get:()=>t[o],enumerable:!(n=V(t,o))||n.enumerable});return r};var tt=(r,t,e)=>(e=r!=null?G(Y(r)):{},W(t||!r||!r.__esModule?g(e,"default",{value:r,enumerable:!0}):e,r)),et=r=>W(g({},"__esModule",{value:!0}),r);var i=(r,t,e)=>(F(r,typeof t!="symbol"?t+"":t,e),e);var pt={};k(pt,{AuthService:()=>h,Connector:()=>u,ErrorUtils:()=>p,EscrowService:()=>m,PsiloSDK:()=>O,SDKError:()=>f,Status:()=>st,parseUrlWithQuery:()=>C});module.exports=et(pt);var xe=require("reflect-metadata");var y=require("typedi");var S=tt(require("axios"));var D=class D extends Error{constructor(e,n,o){super(e);i(this,"code");i(this,"details");this.name="SDKError",this.code=n,this.details=o}};s(D,"SDKError");var f=D;var M=class M{constructor(t){i(this,"client");this.client=S.default.create({baseURL:t,headers:{"Content-Type":"application/json"}})}setHeader(t,e){this.client.defaults.headers.common[t]=e}removeHeader(t){delete this.client.defaults.headers.common[t]}handleResponse(t){var n,o,a;let e=t.data;if(e&&e.success===!1)throw new f(((n=e.error)==null?void 0:n.message)||"Unknown error",((o=e.error)==null?void 0:o.code)||"API_ERROR",(a=e.error)==null?void 0:a.details);return e}handleError(t){var e,n;if(S.default.isAxiosError(t)){let o=(e=t.response)==null?void 0:e.data;throw o&&o.error?new f(o.error.message||t.message,o.error.code||"REQUEST_ERROR",o.error.details):new f(t.message,t.code,(n=t.response)==null?void 0:n.data)}throw new f(t.message||"An unexpected error occurred","INTERNAL_ERROR")}async get(t,e){try{let n=await this.client.get(t,e);return this.handleResponse(n)}catch(n){this.handleError(n)}}async post(t,e,n){try{let o=await this.client.post(t,e,n);return this.handleResponse(o)}catch(o){this.handleError(o)}}async put(t,e,n){try{let o=await this.client.put(t,e,n);return this.handleResponse(o)}catch(o){this.handleError(o)}}async delete(t,e){try{let n=await this.client.delete(t,e);return this.handleResponse(n)}catch(n){this.handleError(n)}}};s(M,"Connector");var u=M;var A=require("typedi");var rt={delayFirstAttempt:!1,jitter:"none",maxDelay:1/0,numOfAttempts:10,retry:()=>!0,startingDelay:100,timeMultiple:2};function $(r){let t=d(d({},rt),r);return t.numOfAttempts<1&&(t.numOfAttempts=1),t}s($,"getSanitizedOptions");function q(r){let t=Math.random()*r;return Math.round(t)}s(q,"fullJitter");function I(r){return r}s(I,"noJitter");function H(r){switch(r.jitter){case"full":return q;case"none":default:return I}}s(H,"JitterFactory");var v=class v{constructor(t){i(this,"options");i(this,"attempt",0);this.options=t}apply(){return new Promise(t=>setTimeout(t,this.jitteredDelay))}setAttemptNumber(t){this.attempt=t}get jitteredDelay(){return H(this.options)(this.delay)}get delay(){let t=this.options.startingDelay,e=this.options.timeMultiple,n=this.numOfDelayedAttempts,o=t*Math.pow(e,n);return Math.min(o,this.options.maxDelay)}get numOfDelayedAttempts(){return this.attempt}};s(v,"Delay");var w=v;var T=class T extends w{async apply(){return this.isFirstAttempt?!0:super.apply()}get isFirstAttempt(){return this.attempt===0}get numOfDelayedAttempts(){return this.attempt-1}};s(T,"SkipFirstDelay");var b=T;var U=class U extends w{};s(U,"AlwaysDelay");var j=U;function L(r,t){let e=nt(r);return e.setAttemptNumber(t),e}s(L,"DelayFactory");function nt(r){return r.delayFirstAttempt?new j(r):new b(r)}s(nt,"initDelayClass");async function _(r,t={}){let e=$(t);return await new ot(r,e).execute()}s(_,"backOff");var x,ot=(x=class{constructor(t,e){i(this,"request");i(this,"options");i(this,"attemptNumber",0);this.request=t,this.options=e}async execute(){for(;!this.attemptLimitReached;)try{return await this.applyDelay(),await this.request()}catch(t){if(this.attemptNumber++,!await this.options.retry(t,this.attemptNumber)||this.attemptLimitReached)throw t}throw new Error("Something went wrong.")}get attemptLimitReached(){return this.attemptNumber>=this.options.numOfAttempts}async applyDelay(){await L(this.options,this.attemptNumber).apply()}},s(x,"BackOff"),x);var st=function(r){return r.SUCCESS="success",r.ERROR="error",r}({}),p={newTryFail:async r=>{try{let t=await _(async()=>await r(),{startingDelay:50,timeMultiple:10,numOfAttempts:10,maxDelay:3550,delayFirstAttempt:!1});return d({},t)}catch(t){let e=p.toErrorWithMessage(t);return{data:null,status:"error",message:e?e.message:["Internal Server Error"],code:e.code}}},formatErrorMsg:r=>r.replace("attr.",""),toErrorWithMessage:r=>{var t;if(typeof r=="string")try{let e=JSON.parse(r);return e.data instanceof Array&&e.data.length>0?{message:e.data.map(n=>p.formatErrorMsg(n)),code:e.errorCode}:{message:[(t=e.message)!=null?t:r],code:e.errorCode}}catch(e){}if(p.isErrorWithMessage(r))return{message:[r.message]};try{return{message:[JSON.stringify(r,null,2)]}}catch(e){return{message:[String(r)]}}},isErrorWithMessage(r){return typeof r=="object"&&r!==null&&"message"in r&&typeof r.message=="string"}},C=s((r,t)=>{let e="?",n=Object.keys(t||{});return n.length===0?r:(n.map((o,a)=>{let c="&";(o===void 0||o==="undefined"||o===null||o==="null"||o.length===0)&&(e=e),a+1===n.length&&(c=""),e=e+`${o}=${t[o]}${c}`}),r+e)},"parseUrlWithQuery");function at(r,t,e,n){var o=arguments.length,a=o<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(r,t,e,n);else for(var l=r.length-1;l>=0;l--)(c=r[l])&&(a=(o<3?c(a):o>3?c(t,e,a):c(t,e))||a);return o>3&&a&&Object.defineProperty(t,e,a),a}s(at,"_ts_decorate");function Q(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)}s(Q,"_ts_metadata");var N=class N{constructor(t){i(this,"id");i(this,"connector");this.id=t,this.connector=A.Container.of(this.id).get(u)}async create(t){return p.newTryFail(async()=>await this.connector.post("/api/escrow/create",t))}async getStatus(t,e){return p.newTryFail(async()=>{let n=C("/api/escrow/status",{chainId:t,escrow:e});return await this.connector.get(n)})}async updateStatus(t){return p.newTryFail(async()=>await this.connector.post("/api/escrow/update",t))}async release(t,e,n){return p.newTryFail(async()=>{let o=d({chainId:t,escrowAddress:e},n||{});return await this.connector.post("/api/escrow/release",o)})}async getChains(){return p.newTryFail(async()=>await this.connector.get("/api/escrow/chains"))}async getAssets(t){return p.newTryFail(async()=>await this.connector.get(`/api/escrow/assets/${t}`))}};s(N,"EscrowService");var m=N;m=at([(0,A.Service)({factory:r=>new m(r.id),transient:!0}),Q("design:type",Function),Q("design:paramtypes",[String])],m);var E=require("typedi");function it(r,t,e,n){var o=arguments.length,a=o<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(r,t,e,n);else for(var l=r.length-1;l>=0;l--)(c=r[l])&&(a=(o<3?c(a):o>3?c(t,e,a):c(t,e))||a);return o>3&&a&&Object.defineProperty(t,e,a),a}s(it,"_ts_decorate");function B(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)}s(B,"_ts_metadata");var z=class z{constructor(t){i(this,"id");i(this,"connector");this.id=t,this.connector=E.Container.of(this.id).get(u)}async register(t){return p.newTryFail(async()=>await this.connector.post("/api/auth/register",t))}async nonce(t){return p.newTryFail(async()=>await this.connector.post("/api/auth/nonce",t))}async verify(t){return p.newTryFail(async()=>await this.connector.post("/api/auth/verify",t))}};s(z,"AuthService");var h=z;h=it([(0,E.Service)({factory:r=>new h(r.id),transient:!0}),B("design:type",Function),B("design:paramtypes",[String])],h);function ct(r,t,e,n){var o=arguments.length,a=o<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(r,t,e,n);else for(var l=r.length-1;l>=0;l--)(c=r[l])&&(a=(o<3?c(a):o>3?c(t,e,a):c(t,e))||a);return o>3&&a&&Object.defineProperty(t,e,a),a}s(ct,"_ts_decorate");function K(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)}s(K,"_ts_metadata");var R=class R{constructor(t){i(this,"auth");i(this,"escrow");i(this,"connector");this.connector=y.Container.of(t).get(u),this.auth=y.Container.of(t).get(h),this.escrow=y.Container.of(t).get(m)}static async init(t){if(!t.baseUrl)throw new Error("PsiloSDK initialization requires a valid baseUrl");t.verbose&&console.log(`[PsiloSDK] Initializing SDK pointed to ${t.baseUrl}`);let e=R.generateRandomString(),n=new u(t.baseUrl);return y.Container.of(e).set(u,n),new R(e)}setAuthorizationHeader(t){this.connector.setHeader("Authorization",`Bearer ${t}`)}static generateRandomString(){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e="";for(let n=0;n<60;n++)e+=t.charAt(Math.floor(Math.random()*t.length));return e}};s(R,"PsiloSDK");var O=R;O=ct([(0,y.Service)({transient:!0}),K("design:type",Function),K("design:paramtypes",[String])],O);0&&(module.exports={AuthService,Connector,ErrorUtils,EscrowService,PsiloSDK,SDKError,Status,parseUrlWithQuery});
|
|
2
2
|
//# sourceMappingURL=main.js.map
|