@kimafinance/kima-transaction-api 1.5.8 → 1.5.10

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/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { RequestHtlcReclaimProps, RequestHtlcLockProps, RequestTransferTxProps, RequestSwapTxProps, RequestExternalTxProps } from "./types";
1
+ import { RequestHtlcReclaimProps, RequestHtlcLockProps, HtlcLockingTransactionResponse, QueryHtlcLockingTransactionParams, RequestTransferTxProps, RequestSwapTxProps, RequestExternalTxProps } from "./types";
2
+ export declare function getHtlcLockingTransactions({ baseUrl, limit, offset, paginationKey, }: QueryHtlcLockingTransactionParams): Promise<HtlcLockingTransactionResponse>;
2
3
  export declare function HtlcReclaim({ senderAddress, txHash, }: RequestHtlcReclaimProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
3
4
  export declare function submitHtlcLock({ fromAddress, senderPubkey, amount, htlcTimeout, txHash, htlcAddress, }: RequestHtlcLockProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
4
5
  export declare function getCreatorAddress(): Promise<import("@cosmjs/proto-signing").AccountData>;
package/build/index.js CHANGED
@@ -1,8 +1,58 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.submitKimaExternalTransaction = exports.submitKimaSwapTransaction = exports.submitKimaTransferTransaction = exports.getCreatorAddress = exports.submitHtlcLock = exports.HtlcReclaim = void 0;
6
+ exports.submitKimaExternalTransaction = exports.submitKimaSwapTransaction = exports.submitKimaTransferTransaction = exports.getCreatorAddress = exports.submitHtlcLock = exports.HtlcReclaim = exports.getHtlcLockingTransactions = void 0;
4
7
  const proto_signing_1 = require("@cosmjs/proto-signing");
8
+ const http_1 = __importDefault(require("http"));
9
+ const https_1 = __importDefault(require("https"));
10
+ const url_1 = require("url");
5
11
  const common_1 = require("./kima/common");
12
+ const requestJson = async (url) => {
13
+ return new Promise((resolve, reject) => {
14
+ const parsed = new url_1.URL(url);
15
+ const transport = parsed.protocol === "https:" ? https_1.default : http_1.default;
16
+ const req = transport.get(parsed, (res) => {
17
+ const chunks = [];
18
+ res.on("data", (chunk) => {
19
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
20
+ });
21
+ res.on("end", () => {
22
+ const body = Buffer.concat(chunks).toString("utf8");
23
+ const status = res.statusCode ?? 0;
24
+ if (status < 200 || status >= 300) {
25
+ const error = new Error(`Request failed with status ${status}`);
26
+ error.status = status;
27
+ error.body = body;
28
+ reject(error);
29
+ return;
30
+ }
31
+ try {
32
+ resolve(JSON.parse(body));
33
+ }
34
+ catch (err) {
35
+ reject(err);
36
+ }
37
+ });
38
+ });
39
+ req.on("error", reject);
40
+ });
41
+ };
42
+ async function getHtlcLockingTransactions({ baseUrl, limit, offset, paginationKey, }) {
43
+ if (!baseUrl) {
44
+ throw new Error("baseUrl is required");
45
+ }
46
+ const url = new url_1.URL("/kima-finance/kima-blockchain/transaction/htlc_locking_transaction", baseUrl);
47
+ if (limit != null)
48
+ url.searchParams.set("pagination.limit", String(limit));
49
+ if (offset != null)
50
+ url.searchParams.set("pagination.offset", String(offset));
51
+ if (paginationKey)
52
+ url.searchParams.set("pagination.key", paginationKey);
53
+ return requestJson(url.toString());
54
+ }
55
+ exports.getHtlcLockingTransactions = getHtlcLockingTransactions;
6
56
  async function HtlcReclaim({ senderAddress, txHash, }) {
7
57
  const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(process.env.KIMA_BACKEND_MNEMONIC, { prefix: "kima" });
8
58
  const client = await (0, common_1.TxClient)(wallet);
@@ -16,6 +16,7 @@ const defaultFee = {
16
16
  };
17
17
  const types = [
18
18
  ["/kimablockchain.transaction.MsgRequestTransaction", transfer_tx_1.MsgRequestTransaction],
19
+ ["/kimablockchain.transaction.MsgRequestExternalTransaction", transfer_tx_1.MsgRequestExternalTransaction],
19
20
  ["/kimablockchain.transaction.MsgRequestHtlcLock", transfer_tx_1.MsgRequestHtlcLock],
20
21
  ["/kimablockchain.transaction.MsgSetTxHash", transfer_tx_1.MsgSetTxHash],
21
22
  ["/kimablockchain.transaction.MsgHtlcReclaim", transfer_tx_1.MsgHtlcReclaim],
package/build/types.d.ts CHANGED
@@ -78,3 +78,29 @@ export interface RequestExternalTxProps {
78
78
  fee: string;
79
79
  options: string;
80
80
  }
81
+ export interface HtlcLockingTransaction {
82
+ id: string;
83
+ senderAddress: string;
84
+ senderPubkey: string;
85
+ htlcTimestamp: string;
86
+ amount: string;
87
+ txHash: string;
88
+ status: string;
89
+ errReason: string;
90
+ creator: string;
91
+ htlcAddress: string;
92
+ pull_status: string;
93
+ }
94
+ export interface HtlcLockingTransactionResponse {
95
+ htlcLockingTransaction: HtlcLockingTransaction[];
96
+ pagination?: {
97
+ next_key?: string | null;
98
+ total?: string;
99
+ };
100
+ }
101
+ export interface QueryHtlcLockingTransactionParams {
102
+ baseUrl: string;
103
+ limit?: number;
104
+ offset?: number;
105
+ paginationKey?: string;
106
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimafinance/kima-transaction-api",
3
- "version": "1.5.8",
3
+ "version": "1.5.10",
4
4
  "description": "A wrapper around Kima's API, enabling sending and monitoring transactions (Beta version)",
5
5
  "repository": "https://github.com/kima-finance/kima-transaction-api",
6
6
  "author": "",
package/src/index.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
2
+ import http from "http";
3
+ import https from "https";
4
+ import { URL } from "url";
2
5
  import { TxClient } from "./kima/common";
3
6
  import {
4
7
  MsgHtlcReclaim,
@@ -14,11 +17,62 @@ import {
14
17
  import {
15
18
  RequestHtlcReclaimProps,
16
19
  RequestHtlcLockProps,
20
+ HtlcLockingTransactionResponse,
21
+ QueryHtlcLockingTransactionParams,
17
22
  RequestTransferTxProps,
18
23
  RequestSwapTxProps,
19
24
  RequestExternalTxProps,
20
25
  } from "./types";
21
26
 
27
+ const requestJson = async <T>(url: string): Promise<T> => {
28
+ return new Promise((resolve, reject) => {
29
+ const parsed = new URL(url);
30
+ const transport = parsed.protocol === "https:" ? https : http;
31
+ const req = transport.get(parsed, (res) => {
32
+ const chunks: Buffer[] = [];
33
+ res.on("data", (chunk) => {
34
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
35
+ });
36
+ res.on("end", () => {
37
+ const body = Buffer.concat(chunks).toString("utf8");
38
+ const status = res.statusCode ?? 0;
39
+ if (status < 200 || status >= 300) {
40
+ const error = new Error(`Request failed with status ${status}`);
41
+ (error as any).status = status;
42
+ (error as any).body = body;
43
+ reject(error);
44
+ return;
45
+ }
46
+ try {
47
+ resolve(JSON.parse(body) as T);
48
+ } catch (err) {
49
+ reject(err);
50
+ }
51
+ });
52
+ });
53
+ req.on("error", reject);
54
+ });
55
+ };
56
+
57
+ export async function getHtlcLockingTransactions({
58
+ baseUrl,
59
+ limit,
60
+ offset,
61
+ paginationKey,
62
+ }: QueryHtlcLockingTransactionParams): Promise<HtlcLockingTransactionResponse> {
63
+ if (!baseUrl) {
64
+ throw new Error("baseUrl is required");
65
+ }
66
+ const url = new URL(
67
+ "/kima-finance/kima-blockchain/transaction/htlc_locking_transaction",
68
+ baseUrl
69
+ );
70
+ if (limit != null) url.searchParams.set("pagination.limit", String(limit));
71
+ if (offset != null) url.searchParams.set("pagination.offset", String(offset));
72
+ if (paginationKey) url.searchParams.set("pagination.key", paginationKey);
73
+ return requestJson<HtlcLockingTransactionResponse>(url.toString());
74
+ }
75
+
22
76
  export async function HtlcReclaim({
23
77
  senderAddress,
24
78
  txHash,
@@ -33,6 +33,7 @@ interface SignAndBroadcastOptions {
33
33
 
34
34
  const types = [
35
35
  ["/kimablockchain.transaction.MsgRequestTransaction", MsgRequestTransaction],
36
+ ["/kimablockchain.transaction.MsgRequestExternalTransaction", MsgRequestExternalTransaction],
36
37
  ["/kimablockchain.transaction.MsgRequestHtlcLock", MsgRequestHtlcLock],
37
38
  ["/kimablockchain.transaction.MsgSetTxHash", MsgSetTxHash],
38
39
  ["/kimablockchain.transaction.MsgHtlcReclaim", MsgHtlcReclaim],
package/src/types.ts CHANGED
@@ -86,6 +86,35 @@ export interface RequestExternalTxProps {
86
86
  options: string;
87
87
  }
88
88
 
89
+ export interface HtlcLockingTransaction {
90
+ id: string;
91
+ senderAddress: string;
92
+ senderPubkey: string;
93
+ htlcTimestamp: string;
94
+ amount: string;
95
+ txHash: string;
96
+ status: string;
97
+ errReason: string;
98
+ creator: string;
99
+ htlcAddress: string;
100
+ pull_status: string;
101
+ }
102
+
103
+ export interface HtlcLockingTransactionResponse {
104
+ htlcLockingTransaction: HtlcLockingTransaction[];
105
+ pagination?: {
106
+ next_key?: string | null;
107
+ total?: string;
108
+ };
109
+ }
110
+
111
+ export interface QueryHtlcLockingTransactionParams {
112
+ baseUrl: string;
113
+ limit?: number;
114
+ offset?: number;
115
+ paginationKey?: string;
116
+ }
117
+
89
118
  function sleep(ms: number) {
90
119
  return new Promise((resolve) => setTimeout(resolve, ms));
91
- }
120
+ }