@gardenfi/orderbook 0.1.11 → 0.2.0-beta.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 (49) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +15 -17
  3. package/dist/index2.cjs +1 -1
  4. package/dist/index2.js +124 -86
  5. package/dist/index3.cjs +1 -1
  6. package/dist/index3.js +14 -22
  7. package/dist/index4.cjs +1 -1
  8. package/dist/index4.js +81 -160
  9. package/dist/index5.cjs +1 -1
  10. package/dist/index5.js +58 -6
  11. package/dist/index6.cjs +1 -1
  12. package/dist/index6.js +11 -3
  13. package/dist/index7.cjs +1 -1
  14. package/dist/index7.js +2 -50
  15. package/dist/index8.cjs +1 -1
  16. package/dist/index8.js +6 -65
  17. package/dist/src/index.d.ts +7 -7
  18. package/dist/src/lib/asset.d.ts +32 -108
  19. package/dist/src/lib/constants.d.ts +8 -0
  20. package/dist/src/lib/errors.d.ts +4 -2
  21. package/dist/src/lib/orderbook/orderbook.d.ts +44 -0
  22. package/dist/src/lib/orderbook/orderbook.types.d.ts +200 -0
  23. package/dist/src/lib/orders/orders.types.d.ts +60 -0
  24. package/dist/src/lib/orders/ordersProvider.d.ts +15 -0
  25. package/dist/src/lib/utils.d.ts +10 -11
  26. package/package.json +20 -19
  27. package/dist/index10.cjs +0 -1
  28. package/dist/index10.js +0 -4
  29. package/dist/index11.cjs +0 -1
  30. package/dist/index11.js +0 -17
  31. package/dist/index12.cjs +0 -1
  32. package/dist/index12.js +0 -18
  33. package/dist/index9.cjs +0 -1
  34. package/dist/index9.js +0 -11
  35. package/dist/src/lib/auth/auth.interface.d.ts +0 -4
  36. package/dist/src/lib/auth/siwe.d.ts +0 -16
  37. package/dist/src/lib/orderbook.d.ts +0 -38
  38. package/dist/src/lib/orderbook.types.d.ts +0 -178
  39. package/dist/src/lib/orderpair.d.ts +0 -5
  40. package/dist/src/lib/ordersSocket.d.ts +0 -9
  41. package/dist/src/lib/pws/index.d.ts +0 -3
  42. package/dist/src/lib/pws/interface.d.ts +0 -79
  43. package/dist/src/lib/pws/service.d.ts +0 -33
  44. package/dist/src/lib/pws/utils.d.ts +0 -7
  45. package/dist/src/lib/store/memoryStorage.d.ts +0 -14
  46. package/dist/src/lib/store/store.interface.d.ts +0 -33
  47. package/dist/src/lib/testUtils.d.ts +0 -1
  48. package/dist/src/lib/url/Url.d.ts +0 -5
  49. package/dist/src/lib/url/index.d.ts +0 -1
@@ -0,0 +1,60 @@
1
+ import { AsyncResult } from '@catalogfi/utils';
2
+ import { CreateOrder, MatchedOrder, PaginatedData, PaginationConfig } from '../orderbook/orderbook.types';
3
+
4
+ export interface IOrderProvider {
5
+ /**
6
+ * Get the order from orderbook based on provided Id and match status.
7
+ * @param id - The create Id of the order
8
+ * @template T - If true, returns matched order, else returns create order (unmatched Order).
9
+ * @returns {AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>} A promise that resolves to the order.
10
+ */
11
+ getOrder<T extends boolean>(id: string, matched: T): AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>;
12
+ /**
13
+ * Get all matched orders from the orderbook associated with the `address`.
14
+ * @param address The address to get the orders for.
15
+ * @param pending If true, returns pending orders, else returns all matched orders.
16
+ * @param paginationConfig - The configuration for the pagination.
17
+ * @returns {AsyncResult<PaginatedData<MatchedOrder>, string>} A promise that resolves to the orders.
18
+ */
19
+ getMatchedOrders(address: string, pending: boolean, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<MatchedOrder>, string>;
20
+ /**
21
+ * Get all unmatched orders from the orderbook associated with the `address`.
22
+ * @param address The address to get the orders for.
23
+ * @param paginationConfig - The configuration for the pagination.
24
+ * @returns {AsyncResult<PaginatedData<CreateOrder>, string>} A promise that resolves to the orders.
25
+ */
26
+ getUnMatchedOrders(address: string, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<CreateOrder>, string>;
27
+ /**
28
+ * Get all orders from the orderbook based on the match status.
29
+ * @param matched - If true, returns matched orders, else returns unmatched orders.
30
+ * @param paginationConfig - The configuration for the pagination.
31
+ * @returns {AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>} A promise that resolves to the orders.
32
+ */
33
+ getOrders<T extends boolean>(matched: T, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
34
+ /**
35
+ * Polls for every provided interval and returns matched and unmatched orders associated on the account.
36
+ * @param account The account to subscribe to
37
+ * @param matched If true, returns matched orders, else returns unmatched orders
38
+ * @param cb Th ack to be called when the orders are updated
39
+ * @param interval The interval to poll for updates
40
+ *
41
+ * Example usage:
42
+ *
43
+ * ```js
44
+ * const unsubscribe =await orderbook.subscribeOrders(account, matched, interval, handleOrders, paginationConfig);
45
+ *
46
+ * // Unsubscribe after 20 seconds
47
+ * setTimeout(() => {
48
+ * unsubscribe();
49
+ * console.log('Unsubscribed from orders');
50
+ * }, 20000);
51
+ * ```
52
+ */
53
+ subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, pending?: boolean, paginationConfig?: PaginationConfig): Promise<() => void>;
54
+ /**
55
+ * Returns the current orders count associated with the provided address. Used to calculate nonce for secret generation.
56
+ * @param address The address to get the orders count for.
57
+ * @returns {AsyncResult<number, string>} A promise that resolves to the orders count.
58
+ */
59
+ getOrdersCount(address: string): AsyncResult<number, string>;
60
+ }
@@ -0,0 +1,15 @@
1
+ import { AsyncResult } from '@catalogfi/utils';
2
+ import { IOrderProvider } from './orders.types';
3
+ import { CreateOrder, MatchedOrder, PaginatedData, PaginationConfig } from '../orderbook/orderbook.types';
4
+ import { Url } from '@gardenfi/utils';
5
+
6
+ export declare class OrdersProvider implements IOrderProvider {
7
+ private url;
8
+ constructor(url: string | Url);
9
+ getOrder<T extends boolean>(id: string, matched: T): AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>;
10
+ getMatchedOrders(address: string, pending: boolean, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<MatchedOrder>, string>;
11
+ getUnMatchedOrders(address: string, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<CreateOrder>, string>;
12
+ getOrders<T extends boolean>(matched: T, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
13
+ subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, pending?: boolean, paginationConfig?: PaginationConfig): Promise<() => void>;
14
+ getOrdersCount(address: string): AsyncResult<number, string>;
15
+ }
@@ -1,12 +1,11 @@
1
- import { Order } from './orderbook.types';
1
+ import { Url } from '@gardenfi/utils';
2
2
 
3
- export declare const parseStatus: (order: Order) => Actions;
4
- export declare enum Actions {
5
- UserCanInitiate = "user can initiate",
6
- UserCanRedeem = "user can redeem",
7
- UserCanRefund = "user can refund",
8
- CounterpartyCanInitiate = "counterparty can initiate",
9
- CounterpartyCanRedeem = "counterparty can redeem",
10
- CounterpartyCanRefund = "counterparty can refund",
11
- NoAction = "no action can be performed"
12
- }
3
+ /**
4
+ * Constructs a URL with the given base URL, endpoint and parameters (query params)
5
+ * @param baseUrl Base URL
6
+ * @param params Query params
7
+ * @returns Constructed URL
8
+ */
9
+ export declare const ConstructUrl: (baseUrl: Url, endPoint: string, params?: {
10
+ [key: string]: string | number | boolean | undefined;
11
+ }) => URL;
package/package.json CHANGED
@@ -1,24 +1,7 @@
1
1
  {
2
2
  "name": "@gardenfi/orderbook",
3
- "version": "0.1.11",
3
+ "version": "0.2.0-beta.0",
4
4
  "type": "module",
5
- "dependencies": {
6
- "@catalogfi/utils": "^0.1.6",
7
- "@catalogfi/wallets": "0.2.43",
8
- "bufferutil": "^4.0.8",
9
- "ethers": "6.8.0",
10
- "siwe": "^2.1.4",
11
- "utf-8-validate": "^6.0.3",
12
- "ws": "^8.14.2"
13
- },
14
- "scripts": {
15
- "build": "vite build",
16
- "test": "vitest run",
17
- "dev": "vite build --watch"
18
- },
19
- "files": [
20
- "dist"
21
- ],
22
5
  "main": "./dist/index.cjs",
23
6
  "module": "./dist/index.js",
24
7
  "typings": "./dist/src/index.d.ts",
@@ -30,10 +13,28 @@
30
13
  },
31
14
  "./package.json": "./package.json"
32
15
  },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "vite build",
21
+ "test": "vitest run",
22
+ "dev": "vite build --watch"
23
+ },
33
24
  "publishConfig": {
34
25
  "access": "public",
35
26
  "registry": "https://registry.npmjs.org/"
36
27
  },
28
+ "dependencies": {
29
+ "@catalogfi/utils": "^0.1.6",
30
+ "@catalogfi/wallets": "0.2.43",
31
+ "@gardenfi/utils": "workspace:^",
32
+ "bufferutil": "^4.0.8",
33
+ "siwe": "^2.1.4",
34
+ "utf-8-validate": "^6.0.3",
35
+ "viem": "^2.21.15",
36
+ "ws": "^8.14.2"
37
+ },
37
38
  "devDependencies": {
38
39
  "@types/ws": "^8.5.7",
39
40
  "dotenv": "^16.3.1",
@@ -43,4 +44,4 @@
43
44
  "vitest": "^1.6.0"
44
45
  },
45
46
  "sideEffects": false
46
- }
47
+ }
package/dist/index10.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(e=>(e.AUTH_TOKEN="auth_token",e))(t||{});exports.StoreKeys=t;
package/dist/index10.js DELETED
@@ -1,4 +0,0 @@
1
- var t = /* @__PURE__ */ ((r) => (r.AUTH_TOKEN = "auth_token", r))(t || {});
2
- export {
3
- t as StoreKeys
4
- };
package/dist/index11.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class r{constructor(){this.memory=new Map}getItem(e){return this.memory.has(e)?this.memory.get(e):null}setItem(e,t){this.memory.set(e,t)}removeItem(e){this.memory.has(e)&&this.memory.delete(e)}}exports.MemoryStorage=r;
package/dist/index11.js DELETED
@@ -1,17 +0,0 @@
1
- class m {
2
- constructor() {
3
- this.memory = /* @__PURE__ */ new Map();
4
- }
5
- getItem(e) {
6
- return this.memory.has(e) ? this.memory.get(e) : null;
7
- }
8
- setItem(e, t) {
9
- this.memory.set(e, t);
10
- }
11
- removeItem(e) {
12
- this.memory.has(e) && this.memory.delete(e);
13
- }
14
- }
15
- export {
16
- m as MemoryStorage
17
- };
package/dist/index12.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class e extends URL{constructor(t,r){super(t,r)}endpoint(t){return new e(t,this)}socket(){if(this.protocol==="https:")return this.origin.replace("https","wss");if(this.protocol==="http:")return this.origin.replace("http","ws");throw new Error("Invalid protocol")}}exports.Url=e;
package/dist/index12.js DELETED
@@ -1,18 +0,0 @@
1
- class r extends URL {
2
- constructor(t, e) {
3
- super(t, e);
4
- }
5
- endpoint(t) {
6
- return new r(t, this);
7
- }
8
- socket() {
9
- if (this.protocol === "https:")
10
- return this.origin.replace("https", "wss");
11
- if (this.protocol === "http:")
12
- return this.origin.replace("http", "ws");
13
- throw new Error("Invalid protocol");
14
- }
15
- }
16
- export {
17
- r as Url
18
- };
package/dist/index9.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r={INVALID_SEND_AMOUNT:"invalid send amount",INVALID_RECEIVE_AMOUNT:"invalid receive amount",UNSUPPORTED_CHAIN:"unsupported chain"},e={SAME_ASSET:"cannot create orderpair with the same assets"};exports.OrderbookErrors=r;exports.OrderpairErrors=e;
package/dist/index9.js DELETED
@@ -1,11 +0,0 @@
1
- const r = {
2
- INVALID_SEND_AMOUNT: "invalid send amount",
3
- INVALID_RECEIVE_AMOUNT: "invalid receive amount",
4
- UNSUPPORTED_CHAIN: "unsupported chain"
5
- }, e = {
6
- SAME_ASSET: "cannot create orderpair with the same assets"
7
- };
8
- export {
9
- r as OrderbookErrors,
10
- e as OrderpairErrors
11
- };
@@ -1,4 +0,0 @@
1
- export interface IAuth {
2
- getToken(): Promise<string>;
3
- verifyToken(token: string, account: string): boolean;
4
- }
@@ -1,16 +0,0 @@
1
- import { JsonRpcSigner, Wallet } from 'ethers';
2
- import { IAuth } from './auth.interface';
3
- import { OrderbookOpts } from '../orderbook.types';
4
- import { Url } from '../url';
5
-
6
- export declare class Siwe implements IAuth {
7
- private readonly url;
8
- private store;
9
- private readonly signer;
10
- private readonly signingStatement;
11
- private readonly domain;
12
- constructor(url: Url, signer: JsonRpcSigner | Wallet, opts?: OrderbookOpts);
13
- verifyToken(token: string, account: string): boolean;
14
- getToken(): Promise<string>;
15
- private signStatement;
16
- }
@@ -1,38 +0,0 @@
1
- import { CreateOrderConfig, IOrderbook, Order, OrderConfig, OrderNonVerbose, OrderbookConfig } from './orderbook.types';
2
- import { SupportedContracts } from './asset';
3
-
4
- /**
5
- * A class that allows you to create and manage orders with the backend url.
6
- *
7
- * @class
8
- * @implements {IOrderbook}
9
- */
10
- export declare class Orderbook implements IOrderbook {
11
- private orderSocket;
12
- private url;
13
- private auth;
14
- private supportedContracts;
15
- /**
16
- * Creates an instance of Orderbook. Does not login to the orderbook backend
17
- * @constructor
18
- * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
19
- *
20
- */
21
- constructor(orderbookConfig: OrderbookConfig);
22
- /**
23
- * Initializes the orderbook as well as logs in the orderbook and stores the auth token in the store.
24
- *
25
- * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
26
- */
27
- static init(orderbookConfig: OrderbookConfig): Promise<Orderbook>;
28
- /**
29
- * Returns the supported contracts from the orderbook.
30
- */
31
- getSupportedContracts(): Promise<SupportedContracts>;
32
- getOrder(orderId: number): Promise<Order>;
33
- createOrder(createOrderConfig: CreateOrderConfig): Promise<number>;
34
- getOrders<T extends boolean>(address: string, orderConfig?: Partial<OrderConfig<T>>): Promise<(T extends true ? Order : OrderNonVerbose)[]>;
35
- subscribeOrders(account: string, cb: (orders: Order[]) => void): void;
36
- unsubscribeOrders(): void;
37
- private validateConfig;
38
- }
@@ -1,178 +0,0 @@
1
- import { MarkNonNullable } from '@catalogfi/utils';
2
- import { Asset, SupportedContracts } from './asset';
3
- import { JsonRpcSigner, Wallet } from 'ethers';
4
- import { IStore } from './store/store.interface';
5
-
6
- /**
7
- * Configuration for the orders you want to receive
8
- *
9
- * @typeParam T - Determines the verbosity of the order.
10
- */
11
- export type OrderConfig<T extends boolean> = {
12
- /**
13
- * Determines the verbosity of the order.
14
- */
15
- verbose: T;
16
- /**
17
- * Set to true if the address should be a taker, else false if the address is the maker of the order.
18
- */
19
- taker: boolean;
20
- /**
21
- * Set to true if you want to receice pending orders
22
- */
23
- pending?: boolean;
24
- };
25
- /**
26
- * Configuration for creating an order
27
- *
28
- */
29
- export interface CreateOrderConfig {
30
- /**
31
- * The asset the user wants to send.
32
- */
33
- fromAsset: Asset;
34
- /**
35
- * The asset the user wants to receive.
36
- */
37
- toAsset: Asset;
38
- /**
39
- * The address from the which the user is sending funds from.
40
- */
41
- sendAddress: string;
42
- /**
43
- * The address at which the user wants to receive funds.
44
- */
45
- receiveAddress: string;
46
- /**
47
- * The input amount the user wants to send in it's lowest denomincation
48
- */
49
- sendAmount: string;
50
- /**
51
- * The amount you receive amount
52
- */
53
- receiveAmount: string;
54
- /**
55
- * The hash of the secret, which is the double hash of the signature
56
- */
57
- secretHash: string;
58
- /**
59
- * The address of the user's btc wallet. The funds will be sent to this address in case of a redeem or refund.
60
- */
61
- btcInputAddress: string;
62
- /**
63
- * Pay with seed
64
- */
65
- feeInSeed?: string;
66
- }
67
- /**
68
- * Additional configuration options for the orderbook
69
- *
70
- */
71
- export type OrderbookOpts = {
72
- /**
73
- * The domain of your dApp. Optional.
74
- */
75
- domain?: string;
76
- /**
77
- * The store used for storing the auth token. Optional.
78
- */
79
- store?: IStore;
80
- };
81
- /**
82
- * Interface for the configuration of an Orderbook.
83
- *
84
- */
85
- export interface OrderbookConfig {
86
- url?: string;
87
- signer: JsonRpcSigner | Wallet;
88
- opts?: OrderbookOpts;
89
- }
90
- export interface IOrderbook {
91
- /**
92
- * Creates an order
93
- * @param {CreateOrderConfig} orderConfig - The configuration for the creating the order.
94
- * @returns {number} The order ID.
95
- */
96
- createOrder(orderConfig: CreateOrderConfig): Promise<number>;
97
- /**
98
- * Get orders based on the provided address and order configuration.
99
- *
100
- * @template {boolean} T
101
- * @param {string} address - The address to get orders for.
102
- * @param {Partial<OrderConfig<T>>} orderConfig - (Optional) The configuration for the orders.
103
- * @returns {Promise<(T extends true ? Order : OrderNonVerbose)[]>} A promise that resolves to an array of orders.
104
- */
105
- getOrders<T extends boolean>(address: string, orderConfig?: Partial<OrderConfig<T>>): Promise<(T extends true ? Order : OrderNonVerbose)[]>;
106
- getOrder(orderId: number): Promise<Order>;
107
- /**
108
- *
109
- *
110
- * @param {string} account - The account to subscribe to. Currently each orderbook instance can connect with a single account.
111
- * @param {(orders: Order[]) => void} cb - The callback to call when the orders are updated. The first response is all the orders created by this account.
112
- * @returns {void}
113
- */
114
- subscribeOrders(account: string, cb: (orders: Order[]) => void): void;
115
- /**
116
- * Unsubscribes from order updates.
117
- *
118
- * @returns {void}
119
- */
120
- unsubscribeOrders(): void;
121
- getSupportedContracts(): Promise<SupportedContracts>;
122
- }
123
- export type AtomicSwap = {
124
- ID: number;
125
- CreatedAt: string;
126
- UpdatedAt: string;
127
- DeletedAt: string;
128
- swapStatus: number;
129
- secret: string;
130
- initiatorAddress: string;
131
- redeemerAddress: string;
132
- onChainIdentifier: string;
133
- timelock: string;
134
- chain: string;
135
- asset: string;
136
- currentConfirmation: number;
137
- minimumConfirmations: number;
138
- amount: string;
139
- filledAmount: string;
140
- priceByOracle: number;
141
- initiateTxHash: string;
142
- initiateBlockNumber: number;
143
- redeemTxHash: string;
144
- refundTxHash: string;
145
- };
146
- export type OrderNonVerbose = {
147
- ID: number;
148
- CreatedAt: string;
149
- UpdatedAt: string;
150
- DeletedAt: string;
151
- maker: string;
152
- taker: string;
153
- orderPair: string;
154
- InitiatorAtomicSwapID: number;
155
- FollowerAtomicSwapID: number;
156
- initiatorAtomicSwap: AtomicSwap | null;
157
- followerAtomicSwap: AtomicSwap | null;
158
- secretHash: string;
159
- secret: string;
160
- price: number;
161
- status: number;
162
- secretNonce: number;
163
- userBtcWalletAddress: string;
164
- RandomMultiplier: number;
165
- RandomScore: number;
166
- fee: number;
167
- };
168
- export type DecodedAuthToken = {
169
- userWallet: string;
170
- exp: number;
171
- iat: number;
172
- };
173
- export type Order = MarkNonNullable<OrderNonVerbose, 'initiatorAtomicSwap' | 'followerAtomicSwap'>;
174
- export type Orders = Order[];
175
- export type GetOrdersOutput<T extends boolean> = (T extends true ? Order : OrderNonVerbose)[];
176
- export type CreateOrderResponse = {
177
- orderId: number;
178
- };
@@ -1,5 +0,0 @@
1
- import { Asset, Chain, EvmChain } from './asset';
2
-
3
- export declare const orderPairGenerator: (from: Asset, to: Asset, contracts: Partial<Record<Chain, string>>) => string;
4
- export declare const chainToId: Record<EvmChain, number>;
5
- export declare const idToChain: Record<number, EvmChain>;
@@ -1,9 +0,0 @@
1
- import { Orders } from './orderbook.types';
2
-
3
- export declare class OrdersSocket {
4
- private url;
5
- private socket;
6
- constructor(url: string);
7
- subscribe(account: string, cb: (orders: Orders) => void): void;
8
- unsubscribe: () => void | undefined;
9
- }
@@ -1,3 +0,0 @@
1
- export { PaymentChannelService } from './service';
2
- export { IPaymentChannelService } from './interface';
3
- export type { PaymentChannelState } from './interface';
@@ -1,79 +0,0 @@
1
- import { AsyncResult } from '@catalogfi/utils';
2
-
3
- declare enum HTLCStatus {
4
- Pending = "pending",
5
- Ready = "ready",
6
- Failed = "failed",
7
- Expired = "expired",
8
- RelayerInitiated = "relayer-initiated",
9
- RelayerRefunded = "relayer-refunded",
10
- Refunded = "refunded",
11
- Redeemed = "redeemed",
12
- Resolved = "resolved"
13
- }
14
- type PendingHTLC = {
15
- htlcId: number;
16
- channelId: number;
17
- processed: boolean;
18
- };
19
- type HTLC = {
20
- ID: number;
21
- secretHash: string;
22
- secret: string;
23
- timeLock: number;
24
- sendAmount: string;
25
- receiveAmount: string;
26
- pendingHTLC: PendingHTLC;
27
- isWithdraw: boolean;
28
- status: HTLCStatus;
29
- withdrawNonce: number;
30
- orderId: string;
31
- initiateTxHash: string;
32
- redeemTxHash: string;
33
- refundTxHash: string;
34
- };
35
- export type PaymentChannelState = {
36
- ID: number;
37
- CreatedAt: string;
38
- UpdatedAt: string;
39
- DeletedAt: any;
40
- latestState: LatestState;
41
- address: string;
42
- userId: string;
43
- feehub: string;
44
- Balance: string;
45
- status: string;
46
- editStatus: string;
47
- lockedAmount: string;
48
- };
49
- type LatestState = {
50
- ID: number;
51
- CreatedAt: string;
52
- UpdatedAt: string;
53
- DeletedAt: any;
54
- channelId: number;
55
- htlcs: HTLC[];
56
- nonce: number;
57
- amount: string;
58
- type: string;
59
- userSignature: string;
60
- feehubSignature: string;
61
- };
62
- export type ConditionalPaymentInitialRequest = {
63
- sendAmount: string;
64
- receiveAmount: string;
65
- timeLock: number;
66
- secretHash: string;
67
- };
68
- export type ConditionalPaymentFinalRequest = {
69
- userSig: string;
70
- channelId: number;
71
- htlc: ConditionalPaymentInitialRequest;
72
- };
73
- export interface IPaymentChannelService {
74
- getChannel(): AsyncResult<PaymentChannelState, string>;
75
- createChannel(address: string): AsyncResult<PaymentChannelState, string>;
76
- createConditionalPayment(paymentRequest: Omit<ConditionalPaymentInitialRequest, "timelock">): AsyncResult<ConditionalPaymentFinalRequest | null, string>;
77
- payConditionally(paymentRequest: Omit<ConditionalPaymentInitialRequest, "timelock">): AsyncResult<void, string>;
78
- }
79
- export {};
@@ -1,33 +0,0 @@
1
- import { JsonRpcSigner, Wallet } from 'ethers';
2
- import { ConditionalPaymentFinalRequest, ConditionalPaymentInitialRequest, IPaymentChannelService as IPaymentChannelService, PaymentChannelState } from './interface';
3
- import { AsyncResult } from '@catalogfi/utils';
4
- import { IAuth } from '../auth/auth.interface';
5
-
6
- export declare class PaymentChannelService implements IPaymentChannelService {
7
- private api;
8
- private signer;
9
- private provider;
10
- private auth;
11
- private constructor();
12
- static init(api: string, signer: JsonRpcSigner | Wallet, auth: IAuth): PaymentChannelService;
13
- /**
14
- * creates a new payment channel with the specified deposit amount
15
- */
16
- createChannel(depositAmt?: string): AsyncResult<PaymentChannelState, string>;
17
- /**
18
- * gets the latest state of the payment channel associated with the address
19
- *
20
- * Note: Currently only returns the first channel
21
- */
22
- getChannel(): AsyncResult<PaymentChannelState, string>;
23
- private _getAuthToken;
24
- private getSignatureForConditionalPayment;
25
- private _lockChannel;
26
- payConditionally(request: Omit<ConditionalPaymentInitialRequest, 'timeLock'>): AsyncResult<void, string>;
27
- /**
28
- * Constructs a conditional payment request for backend to accept.
29
- *
30
- * Use .payConditionally() to actually pay conditionally.
31
- */
32
- createConditionalPayment(paymentRequest: Omit<ConditionalPaymentInitialRequest, 'timeLock'>): AsyncResult<ConditionalPaymentFinalRequest, string>;
33
- }
@@ -1,7 +0,0 @@
1
- import { JsonRpcApiProvider, JsonRpcSigner, Wallet } from 'ethers';
2
- import { ConditionalPaymentInitialRequest, PaymentChannelState } from './interface';
3
-
4
- export declare function getTimelock(provider: JsonRpcApiProvider): Promise<number>;
5
- export declare const parseError: (error: unknown) => string;
6
- export declare const getProviderOrThrow: (signer: JsonRpcSigner | Wallet) => JsonRpcApiProvider;
7
- export declare const signPayment: (channel: PaymentChannelState, paymentRequest: ConditionalPaymentInitialRequest, signer: JsonRpcSigner | Wallet) => Promise<string>;
@@ -1,14 +0,0 @@
1
- import { IStore } from './store.interface';
2
-
3
- /**
4
- * In-memory storage implementation.
5
- *
6
- * @class
7
- * @implements {IStore}
8
- */
9
- export declare class MemoryStorage implements IStore {
10
- private memory;
11
- getItem(key: string): string | null;
12
- setItem(key: string, value: string): void;
13
- removeItem(key: string): void;
14
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Interface for a Store.
3
- *
4
- * @interface IStore
5
- *
6
- */
7
- export interface IStore {
8
- /**
9
- * Retrieves an item from the store using the provided key.
10
- * @param {string} key - The key of the item to retrieve.
11
- * @returns {string | number} The item associated with the key, or null if no item is found.
12
- *
13
- */
14
- getItem(key: string): string | null;
15
- /**
16
- * @method setItem - Sets an item in the store with the provided key and value.
17
- * @param {string} key - The key to associate with the item.
18
- * @param {any} value - The value of the item to store.
19
- * @returns {void}
20
- *
21
- */
22
- setItem(key: string, value: any): void;
23
- /**
24
- * @method removeItem - Removes an item from the store using the provided key.
25
- * @param {string} key - The key of the item to remove.
26
- * @returns {void}
27
- *
28
- */
29
- removeItem(key: string): void;
30
- }
31
- export declare enum StoreKeys {
32
- AUTH_TOKEN = "auth_token"
33
- }
@@ -1 +0,0 @@
1
- export declare const startWsServer: () => void;