@pakt/psilo 0.0.1 → 0.0.2

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # PsiloSDK
2
2
 
3
- PsiloSDK is the official TypeScript SDK for interacting computationally with Pakt's production-ready EVM single-use, non-custodial, MPC-protected escrow wallets via the Model Context Protocol (MCP) compatible backend.
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
- It is designed to be fully AI-native and provide seamless interoperability for creating, managing, and releasing Escrow objects that leverage Pakt's `Psilo-Contracts`.
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
- You must initialize the SDK by pointing it to the deployed MCP-compatible endpoint hosting the Psilo backend server.
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: "http://localhost:3000", // Example backend or MCP deployment URL
24
- verbose: true // Optional logging
27
+ baseUrl: "https://devescrow.psiloai.com", //for development
28
+ verbose: true // optional logging
25
29
  });
26
30
  ```
27
31
 
28
- ## Features: Escrow Management
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
- The SDK maps all features designed within the `Psilo-Contracts/MCP_INTEGRATION.md`.
41
+ ---
31
42
 
32
- ### 1. Compute Address
33
- Compute an expected escrow address deterministically before deploying it.
43
+ ## API Reference
44
+
45
+ ### Chains & Assets
46
+
47
+ Discover supported networks and tokens before creating an escrow.
34
48
 
35
49
  ```typescript
36
- const computed = await sdk.escrow.computeAddress({
37
- sender: "0xSenderAddress...",
38
- receiver: "0xReceiverAddress...",
39
- asset: "0x0000000000000000000000000000000000000000", // ETH
40
- amount: "1000000000000000000",
41
- originator: "0xOriginator...",
42
- salt: "0x123..."
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
- ### 2. Create Escrow
48
- Create a new escrow on the blockchain.
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 escrowResponse = await sdk.escrow.create({
52
- sender: "0xSenderAddress...",
53
- receiver: "0xReceiverAddress...",
54
- asset: "0x0000000000000000000000000000000000000000",
55
- amount: "1000000000000000000",
56
- originator: "0xOriginator...",
57
- salt: "0xSomeDeterministicSalt...",
58
- metadataHash: "0xOptionalMetadata..."
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
- const escrowAddress = escrowResponse.data.escrowAddress;
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
- ### 3. Deposit
64
- Fund a created escrow.
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.deposit(escrowAddress, {
68
- from: "0xSenderAddress..."
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
- ### 4. Status and Listing
73
- Query statuses and lists of active escrows.
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
- // Query one
77
- const status = await sdk.escrow.getStatus(escrowAddress);
78
- console.log("Status:", status.data.deposited, status.data.released);
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
- ### 5. Multi-Party Approval & Release
88
- The MPC-shard functionality is exposed through signing a release using 2-of-3 configured authority.
128
+ ---
89
129
 
90
- ```typescript
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
- // Ask the receiver to sign
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
- // Release funds
103
- await sdk.escrow.release(escrowAddress, {
104
- signatures: [senderSignature.data.signature, receiverSignature.data.signature],
105
- executor: "0xExecutorAddress..."
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,10 +51,8 @@ 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(escrowAddress: string, data: UpdateEscrowStatusDto): Promise<ResponseDto<PrepareTransactionResponse>>;
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
  }
@@ -95,19 +93,6 @@ interface CreateEscrowResponse {
95
93
  };
96
94
  };
97
95
  }
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
96
  interface EscrowStatusResponse {
112
97
  chainId: string;
113
98
  escrow: string;
@@ -168,29 +153,6 @@ interface PrepareTransactionResponse {
168
153
  buyer?: string;
169
154
  nonce?: string;
170
155
  }
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
156
  interface EscrowNativeCurrencyDto {
195
157
  name: string;
196
158
  symbol: string;
@@ -223,21 +185,14 @@ declare class EscrowService implements EscrowModuleType {
223
185
  constructor(id: string);
224
186
  create(data: CreateEscrowDto): Promise<ResponseDto<CreateEscrowResponse>>;
225
187
  getStatus(chainId: string, escrowAddress: string): Promise<ResponseDto<EscrowStatusResponse>>;
226
- updateStatus(escrowAddress: string, data: {
227
- chainId: string;
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>>;
188
+ updateStatus(data: UpdateEscrowStatusDto): Promise<ResponseDto<PrepareTransactionResponse>>;
189
+ release(chainId: string, escrowAddress: string, data?: ReleaseDto): Promise<ResponseDto<ReleaseResponse>>;
235
190
  getChains(): Promise<ResponseDto<GetEscrowChainsResponseDto>>;
236
191
  getAssets(chainId: string): Promise<ResponseDto<GetEscrowAssetsResponseDto>>;
237
192
  }
238
193
 
239
194
  interface PsiloSDKConfig {
240
- baseUrl: string;
195
+ baseUrl?: string;
241
196
  verbose?: boolean;
242
197
  }
243
198
  declare class PsiloSDK {
@@ -255,4 +210,4 @@ declare class SDKError extends Error {
255
210
  constructor(message: string, code?: string, details?: any);
256
211
  }
257
212
 
258
- export { ComputeAddressParams, ComputeAddressResponse, Connector, CreateEscrowDto, CreateEscrowResponse, DepositDto, DepositResponse, ErrorUtils, EscrowAssetDto, EscrowChainDto, EscrowListItem, EscrowModuleType, EscrowNativeCurrencyDto, EscrowService, EscrowStatusResponse, GetEscrowAssetsResponseDto, GetEscrowChainsResponseDto, IAny, ListEscrowsParams, ListEscrowsResponse, PrepareTransactionResponse, PsiloSDK, PsiloSDKConfig, ReleaseDto, ReleaseResponse, ResponseDto, SDKError, SignReleaseDto, SignReleaseResponse, StandardResponse, Status, UpdateEscrowStatusDto, parseUrlWithQuery };
213
+ export { Connector, CreateEscrowDto, CreateEscrowResponse, DepositDto, DepositResponse, ErrorUtils, EscrowAssetDto, EscrowChainDto, EscrowModuleType, EscrowNativeCurrencyDto, EscrowService, EscrowStatusResponse, GetEscrowAssetsResponseDto, GetEscrowChainsResponseDto, IAny, PrepareTransactionResponse, PsiloSDK, PsiloSDKConfig, ReleaseDto, ReleaseResponse, ResponseDto, SDKError, SignReleaseDto, SignReleaseResponse, StandardResponse, Status, UpdateEscrowStatusDto, parseUrlWithQuery };
package/dist/main.js CHANGED
@@ -1,2 +1,2 @@
1
- var B=Object.create;var d=Object.defineProperty,K=Object.defineProperties,_=Object.getOwnPropertyDescriptor,G=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertyNames,v=Object.getOwnPropertySymbols,X=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var j=(r,t,e)=>t in r?d(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,u=(r,t)=>{for(var e in t||(t={}))C.call(t,e)&&j(r,e,t[e]);if(v)for(var e of v(t))Y.call(t,e)&&j(r,e,t[e]);return r},z=(r,t)=>K(r,G(t)),o=(r,t)=>d(r,"name",{value:t,configurable:!0});var Z=(r,t)=>{for(var e in t)d(r,e,{get:t[e],enumerable:!0})},J=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of V(t))!C.call(r,n)&&n!==e&&d(r,n,{get:()=>t[n],enumerable:!(s=_(t,n))||s.enumerable});return r};var k=(r,t,e)=>(e=r!=null?B(X(r)):{},J(t||!r||!r.__esModule?d(e,"default",{value:r,enumerable:!0}):e,r)),tt=r=>J(d({},"__esModule",{value:!0}),r);var i=(r,t,e)=>(j(r,typeof t!="symbol"?t+"":t,e),e);var it={};Z(it,{Connector:()=>l,ErrorUtils:()=>c,EscrowService:()=>f,PsiloSDK:()=>R,SDKError:()=>m,Status:()=>nt,parseUrlWithQuery:()=>A});module.exports=tt(it);var ce=require("reflect-metadata");var w=require("typedi");var D=k(require("axios"));var F=class F extends Error{constructor(e,s,n){super(e);i(this,"code");i(this,"details");this.name="SDKError",this.code=s,this.details=n}};o(F,"SDKError");var m=F;var S=class S{constructor(t){i(this,"client");this.client=D.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 s,n,a;let e=t.data;if(e&&e.success===!1)throw new m(((s=e.error)==null?void 0:s.message)||"Unknown error",((n=e.error)==null?void 0:n.code)||"API_ERROR",(a=e.error)==null?void 0:a.details);return e}handleError(t){var e,s;if(D.default.isAxiosError(t)){let n=(e=t.response)==null?void 0:e.data;throw n&&n.error?new m(n.error.message||t.message,n.error.code||"REQUEST_ERROR",n.error.details):new m(t.message,t.code,(s=t.response)==null?void 0:s.data)}throw new m(t.message||"An unexpected error occurred","INTERNAL_ERROR")}async get(t,e){try{let s=await this.client.get(t,e);return this.handleResponse(s)}catch(s){this.handleError(s)}}async post(t,e,s){try{let n=await this.client.post(t,e,s);return this.handleResponse(n)}catch(n){this.handleError(n)}}async put(t,e,s){try{let n=await this.client.put(t,e,s);return this.handleResponse(n)}catch(n){this.handleError(n)}}async delete(t,e){try{let s=await this.client.delete(t,e);return this.handleResponse(s)}catch(s){this.handleError(s)}}};o(S,"Connector");var l=S;var E=require("typedi");var et={delayFirstAttempt:!1,jitter:"none",maxDelay:1/0,numOfAttempts:10,retry:()=>!0,startingDelay:100,timeMultiple:2};function P(r){let t=u(u({},et),r);return t.numOfAttempts<1&&(t.numOfAttempts=1),t}o(P,"getSanitizedOptions");function W(r){let t=Math.random()*r;return Math.round(t)}o(W,"fullJitter");function $(r){return r}o($,"noJitter");function q(r){switch(r.jitter){case"full":return W;case"none":default:return $}}o(q,"JitterFactory");var M=class M{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 q(this.options)(this.delay)}get delay(){let t=this.options.startingDelay,e=this.options.timeMultiple,s=this.numOfDelayedAttempts,n=t*Math.pow(e,s);return Math.min(n,this.options.maxDelay)}get numOfDelayedAttempts(){return this.attempt}};o(M,"Delay");var y=M;var T=class T extends y{async apply(){return this.isFirstAttempt?!0:super.apply()}get isFirstAttempt(){return this.attempt===0}get numOfDelayedAttempts(){return this.attempt-1}};o(T,"SkipFirstDelay");var O=T;var U=class U extends y{};o(U,"AlwaysDelay");var b=U;function I(r,t){let e=rt(r);return e.setAttemptNumber(t),e}o(I,"DelayFactory");function rt(r){return r.delayFirstAttempt?new b(r):new O(r)}o(rt,"initDelayClass");async function H(r,t={}){let e=P(t);return await new st(r,e).execute()}o(H,"backOff");var g,st=(g=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 I(this.options,this.attemptNumber).apply()}},o(g,"BackOff"),g);var nt=function(r){return r.SUCCESS="success",r.ERROR="error",r}({}),c={newTryFail:async r=>{try{let t=await H(async()=>await r(),{startingDelay:50,timeMultiple:10,numOfAttempts:10,maxDelay:3550,delayFirstAttempt:!1});return u({},t)}catch(t){let e=c.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(s=>c.formatErrorMsg(s)),code:e.errorCode}:{message:[(t=e.message)!=null?t:r],code:e.errorCode}}catch(e){}if(c.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"}},A=o((r,t)=>{let e="?",s=Object.keys(t||{});return s.length===0?r:(s.map((n,a)=>{let p="&";(n===void 0||n==="undefined"||n===null||n==="null"||n.length===0)&&(e=e),a+1===s.length&&(p=""),e=e+`${n}=${t[n]}${p}`}),r+e)},"parseUrlWithQuery");function ot(r,t,e,s){var n=arguments.length,a=n<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,p;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(r,t,e,s);else for(var h=r.length-1;h>=0;h--)(p=r[h])&&(a=(n<3?p(a):n>3?p(t,e,a):p(t,e))||a);return n>3&&a&&Object.defineProperty(t,e,a),a}o(ot,"_ts_decorate");function L(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)}o(L,"_ts_metadata");var N=class N{constructor(t){i(this,"id");i(this,"connector");this.id=t,this.connector=E.Container.of(this.id).get(l)}async create(t){return c.newTryFail(async()=>await this.connector.post("/api/escrow/create",t))}async getStatus(t,e){return c.newTryFail(async()=>{let s=A("/api/escrow/status",{chainId:t,escrow:e});return await this.connector.get(s)})}async updateStatus(t,e){return c.newTryFail(async()=>{let s=z(u({},e),{escrow:t});return await this.connector.post("/api/escrow/update",s)})}async prepareRelease(t,e){return c.newTryFail(async()=>{let s=e?{escrowAddress:t,recipient:e}:{escrowAddress:t};return await this.connector.post("/api/escrow/prepare-release",s)})}async release(t,e){return c.newTryFail(async()=>{let s=u({escrowAddress:t},e||{});return await this.connector.post("/api/escrow/release",s)})}async list(t){return c.newTryFail(async()=>{let e=t?A("/api/escrows",t):"/api/escrows";return await this.connector.get(e)})}async getChains(){return c.newTryFail(async()=>await this.connector.get("/api/escrow/chains"))}async getAssets(t){return c.newTryFail(async()=>await this.connector.get(`/api/escrow/assets/${t}`))}};o(N,"EscrowService");var f=N;f=ot([(0,E.Service)({factory:r=>new f(r.id),transient:!0}),L("design:type",Function),L("design:paramtypes",[String])],f);function at(r,t,e,s){var n=arguments.length,a=n<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,p;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(r,t,e,s);else for(var h=r.length-1;h>=0;h--)(p=r[h])&&(a=(n<3?p(a):n>3?p(t,e,a):p(t,e))||a);return n>3&&a&&Object.defineProperty(t,e,a),a}o(at,"_ts_decorate");function Q(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)}o(Q,"_ts_metadata");var x=class x{constructor(t){i(this,"escrow");i(this,"connector");this.connector=w.Container.of(t).get(l),this.escrow=w.Container.of(t).get(f)}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=x.generateRandomString(),s=new l(t.baseUrl);return w.Container.of(e).set(l,s),new x(e)}setAuthorizationHeader(t){this.connector.setHeader("Authorization",`Bearer ${t}`)}static generateRandomString(){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e="";for(let s=0;s<60;s++)e+=t.charAt(Math.floor(Math.random()*t.length));return e}};o(x,"PsiloSDK");var R=x;R=at([(0,w.Service)({transient:!0}),Q("design:type",Function),Q("design:paramtypes",[String])],R);0&&(module.exports={Connector,ErrorUtils,EscrowService,PsiloSDK,SDKError,Status,parseUrlWithQuery});
1
+ var Q=Object.create;var d=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames,v=Object.getOwnPropertySymbols,_=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var E=(r,t,e)=>t in r?d(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,h=(r,t)=>{for(var e in t||(t={}))C.call(t,e)&&E(r,e,t[e]);if(v)for(var e of v(t))G.call(t,e)&&E(r,e,t[e]);return r};var o=(r,t)=>d(r,"name",{value:t,configurable:!0});var V=(r,t)=>{for(var e in t)d(r,e,{get:t[e],enumerable:!0})},z=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of K(t))!C.call(r,s)&&s!==e&&d(r,s,{get:()=>t[s],enumerable:!(n=B(t,s))||n.enumerable});return r};var X=(r,t,e)=>(e=r!=null?Q(_(r)):{},z(t||!r||!r.__esModule?d(e,"default",{value:r,enumerable:!0}):e,r)),Y=r=>z(d({},"__esModule",{value:!0}),r);var i=(r,t,e)=>(E(r,typeof t!="symbol"?t+"":t,e),e);var st={};V(st,{Connector:()=>l,ErrorUtils:()=>p,EscrowService:()=>m,PsiloSDK:()=>R,SDKError:()=>u,Status:()=>et,parseUrlWithQuery:()=>N});module.exports=Y(st);var oe=require("reflect-metadata");var g=require("typedi");var D=X(require("axios"));var j=class j extends Error{constructor(e,n,s){super(e);i(this,"code");i(this,"details");this.name="SDKError",this.code=n,this.details=s}};o(j,"SDKError");var u=j;var F=class F{constructor(t){i(this,"client");this.client=D.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,s,a;let e=t.data;if(e&&e.success===!1)throw new u(((n=e.error)==null?void 0:n.message)||"Unknown error",((s=e.error)==null?void 0:s.code)||"API_ERROR",(a=e.error)==null?void 0:a.details);return e}handleError(t){var e,n;if(D.default.isAxiosError(t)){let s=(e=t.response)==null?void 0:e.data;throw s&&s.error?new u(s.error.message||t.message,s.error.code||"REQUEST_ERROR",s.error.details):new u(t.message,t.code,(n=t.response)==null?void 0:n.data)}throw new u(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 s=await this.client.post(t,e,n);return this.handleResponse(s)}catch(s){this.handleError(s)}}async put(t,e,n){try{let s=await this.client.put(t,e,n);return this.handleResponse(s)}catch(s){this.handleError(s)}}async delete(t,e){try{let n=await this.client.delete(t,e);return this.handleResponse(n)}catch(n){this.handleError(n)}}};o(F,"Connector");var l=F;var b=require("typedi");var Z={delayFirstAttempt:!1,jitter:"none",maxDelay:1/0,numOfAttempts:10,retry:()=>!0,startingDelay:100,timeMultiple:2};function J(r){let t=h(h({},Z),r);return t.numOfAttempts<1&&(t.numOfAttempts=1),t}o(J,"getSanitizedOptions");function P(r){let t=Math.random()*r;return Math.round(t)}o(P,"fullJitter");function W(r){return r}o(W,"noJitter");function $(r){switch(r.jitter){case"full":return P;case"none":default:return W}}o($,"JitterFactory");var S=class S{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 $(this.options)(this.delay)}get delay(){let t=this.options.startingDelay,e=this.options.timeMultiple,n=this.numOfDelayedAttempts,s=t*Math.pow(e,n);return Math.min(s,this.options.maxDelay)}get numOfDelayedAttempts(){return this.attempt}};o(S,"Delay");var y=S;var M=class M extends y{async apply(){return this.isFirstAttempt?!0:super.apply()}get isFirstAttempt(){return this.attempt===0}get numOfDelayedAttempts(){return this.attempt-1}};o(M,"SkipFirstDelay");var O=M;var U=class U extends y{};o(U,"AlwaysDelay");var A=U;function q(r,t){let e=k(r);return e.setAttemptNumber(t),e}o(q,"DelayFactory");function k(r){return r.delayFirstAttempt?new A(r):new O(r)}o(k,"initDelayClass");async function I(r,t={}){let e=J(t);return await new tt(r,e).execute()}o(I,"backOff");var w,tt=(w=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 q(this.options,this.attemptNumber).apply()}},o(w,"BackOff"),w);var et=function(r){return r.SUCCESS="success",r.ERROR="error",r}({}),p={newTryFail:async r=>{try{let t=await I(async()=>await r(),{startingDelay:50,timeMultiple:10,numOfAttempts:10,maxDelay:3550,delayFirstAttempt:!1});return h({},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"}},N=o((r,t)=>{let e="?",n=Object.keys(t||{});return n.length===0?r:(n.map((s,a)=>{let c="&";(s===void 0||s==="undefined"||s===null||s==="null"||s.length===0)&&(e=e),a+1===n.length&&(c=""),e=e+`${s}=${t[s]}${c}`}),r+e)},"parseUrlWithQuery");function rt(r,t,e,n){var s=arguments.length,a=s<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 f=r.length-1;f>=0;f--)(c=r[f])&&(a=(s<3?c(a):s>3?c(t,e,a):c(t,e))||a);return s>3&&a&&Object.defineProperty(t,e,a),a}o(rt,"_ts_decorate");function H(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)}o(H,"_ts_metadata");var T=class T{constructor(t){i(this,"id");i(this,"connector");this.id=t,this.connector=b.Container.of(this.id).get(l)}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=N("/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 s=h({chainId:t,escrowAddress:e},n||{});return await this.connector.post("/api/escrow/release",s)})}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}`))}};o(T,"EscrowService");var m=T;m=rt([(0,b.Service)({factory:r=>new m(r.id),transient:!0}),H("design:type",Function),H("design:paramtypes",[String])],m);function nt(r,t,e,n){var s=arguments.length,a=s<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 f=r.length-1;f>=0;f--)(c=r[f])&&(a=(s<3?c(a):s>3?c(t,e,a):c(t,e))||a);return s>3&&a&&Object.defineProperty(t,e,a),a}o(nt,"_ts_decorate");function L(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)}o(L,"_ts_metadata");var x=class x{constructor(t){i(this,"escrow");i(this,"connector");this.connector=g.Container.of(t).get(l),this.escrow=g.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=x.generateRandomString(),n=new l(t.baseUrl);return g.Container.of(e).set(l,n),new x(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}};o(x,"PsiloSDK");var R=x;R=nt([(0,g.Service)({transient:!0}),L("design:type",Function),L("design:paramtypes",[String])],R);0&&(module.exports={Connector,ErrorUtils,EscrowService,PsiloSDK,SDKError,Status,parseUrlWithQuery});
2
2
  //# sourceMappingURL=main.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pakt/psilo",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "SDK for interacting with Pakt Psilo Escrow Contracts via MCP",
5
5
  "files": [
6
6
  "./dist/main.js",