paj_ramp 1.0.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 (58) hide show
  1. package/README.md +254 -0
  2. package/__tests__/getTXPoolAddress.test.ts +24 -0
  3. package/dist/index.d.ts +11 -0
  4. package/dist/index.js +16 -0
  5. package/dist/lib/addBankAccount.d.ts +21 -0
  6. package/dist/lib/addBankAccount.js +30 -0
  7. package/dist/lib/addWallet.d.ts +11 -0
  8. package/dist/lib/addWallet.js +27 -0
  9. package/dist/lib/getBankAccounts.d.ts +18 -0
  10. package/dist/lib/getBankAccounts.js +22 -0
  11. package/dist/lib/getBanks.d.ts +17 -0
  12. package/dist/lib/getBanks.js +20 -0
  13. package/dist/lib/getRate.d.ts +26 -0
  14. package/dist/lib/getRate.js +23 -0
  15. package/dist/lib/getTXPoolAddress.d.ts +13 -0
  16. package/dist/lib/getTXPoolAddress.js +20 -0
  17. package/dist/lib/getWallet.d.ts +24 -0
  18. package/dist/lib/getWallet.js +23 -0
  19. package/dist/lib/initiate.d.ts +18 -0
  20. package/dist/lib/initiate.js +23 -0
  21. package/dist/lib/resolveBankAccount.d.ts +26 -0
  22. package/dist/lib/resolveBankAccount.js +24 -0
  23. package/dist/lib/switchWalletBankAccount.d.ts +2 -0
  24. package/dist/lib/switchWalletBankAccount.js +19 -0
  25. package/dist/lib/verify.d.ts +21 -0
  26. package/dist/lib/verify.js +25 -0
  27. package/dist/utils/api.d.ts +80 -0
  28. package/dist/utils/api.js +122 -0
  29. package/dist/utils/axios.d.ts +2 -0
  30. package/dist/utils/axios.js +8 -0
  31. package/dist/utils/generateSignature.d.ts +12 -0
  32. package/dist/utils/generateSignature.js +17 -0
  33. package/dist/utils/getWalletBody.d.ts +15 -0
  34. package/dist/utils/getWalletBody.js +36 -0
  35. package/dist/utils/verifySignature.d.ts +17 -0
  36. package/dist/utils/verifySignature.js +18 -0
  37. package/generateWallet.js +8 -0
  38. package/index.ts +20 -0
  39. package/jest.config.js +8 -0
  40. package/lib/addBankAccount.ts +39 -0
  41. package/lib/addWallet.ts +33 -0
  42. package/lib/getBankAccounts.ts +33 -0
  43. package/lib/getBanks.ts +25 -0
  44. package/lib/getRate.ts +35 -0
  45. package/lib/getTXPoolAddress.ts +22 -0
  46. package/lib/getWallet.ts +34 -0
  47. package/lib/initiate.ts +31 -0
  48. package/lib/resolveBankAccount.ts +40 -0
  49. package/lib/switchWalletBankAccount.ts +26 -0
  50. package/lib/verify.ts +39 -0
  51. package/package.json +40 -0
  52. package/tsconfig.json +15 -0
  53. package/utils/api.ts +139 -0
  54. package/utils/axios.ts +10 -0
  55. package/utils/generateSignature.ts +25 -0
  56. package/utils/getWalletBody.ts +39 -0
  57. package/utils/verifySignature.ts +30 -0
  58. package/wallet.json +1 -0
@@ -0,0 +1,24 @@
1
+ import { get } from '../utils/api.js';
2
+ /**
3
+ * Resolves and fetches bank account details for a given bank ID and account number from the public API.
4
+ * Returns the account name, account number, and bank details or throws an error if the request fails.
5
+ *
6
+ * Args:
7
+ * bankId: The ID of the bank.
8
+ * accountNumber: The bank account number to resolve.
9
+ *
10
+ * Returns:
11
+ * An object containing accountName, accountNumber, and bank details (id, name, code, country).
12
+ *
13
+ * Raises:
14
+ * Throws an error if the request fails.
15
+ */
16
+ export const resolveBankAccount = async (bankId, accountNumber) => {
17
+ try {
18
+ return await get(`/pub/bankaccount/resolve/?bankId=${bankId}&accountNumber=${accountNumber}`);
19
+ }
20
+ catch (err) {
21
+ console.error('Error resolving bank account:', err);
22
+ throw err;
23
+ }
24
+ };
@@ -0,0 +1,2 @@
1
+ import { WalletType } from "./getWallet.js";
2
+ export declare const switchWalletBankAccount: (apiKey: string, accountId: string, walletId: string, secretKey: Uint8Array) => Promise<WalletType>;
@@ -0,0 +1,19 @@
1
+ import { patch } from "../utils/api.js";
2
+ import { getWalletBody } from "../utils/getWalletBody.js";
3
+ export const switchWalletBankAccount = async (apiKey, accountId, walletId, secretKey) => {
4
+ try {
5
+ const body = await getWalletBody(accountId, secretKey);
6
+ if (!body) {
7
+ throw new Error("Failed to get wallet body");
8
+ }
9
+ console.log(body);
10
+ const response = await patch(`/pub/wallet/${walletId}`, body, {
11
+ Authorization: `Bearer ${apiKey}`,
12
+ });
13
+ return response;
14
+ }
15
+ catch (err) {
16
+ console.error("Error switching wallet bank account:", err);
17
+ throw err;
18
+ }
19
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Verifies a user's identity using email, OTP, and device signature via the public API.
3
+ * Returns verification details including email, activation status, expiration, and token, or throws an error if the request fails.
4
+ *
5
+ * Args:
6
+ * email: The user's email address.
7
+ * otp: The one-time password for verification.
8
+ * deviceSignature: The device signature for additional security.
9
+ *
10
+ * Returns:
11
+ * An object containing email, isActive, expiresAt, and token.
12
+ *
13
+ * Raises:
14
+ * Throws an error if the request fails.
15
+ */
16
+ export declare const verify: (email: string, otp: string, deviceSignature: string) => Promise<{
17
+ email: string;
18
+ isActive: string;
19
+ expiresAt: string;
20
+ token: string;
21
+ }>;
@@ -0,0 +1,25 @@
1
+ import { post } from '../utils/api.js';
2
+ /**
3
+ * Verifies a user's identity using email, OTP, and device signature via the public API.
4
+ * Returns verification details including email, activation status, expiration, and token, or throws an error if the request fails.
5
+ *
6
+ * Args:
7
+ * email: The user's email address.
8
+ * otp: The one-time password for verification.
9
+ * deviceSignature: The device signature for additional security.
10
+ *
11
+ * Returns:
12
+ * An object containing email, isActive, expiresAt, and token.
13
+ *
14
+ * Raises:
15
+ * Throws an error if the request fails.
16
+ */
17
+ export const verify = async (email, otp, deviceSignature) => {
18
+ try {
19
+ return await post('/pub/verify', { email, otp, deviceSignature }, { 'x-api-key': '3ada687e-78d1-45f3-933d-c992adcc2bbb' });
20
+ }
21
+ catch (err) {
22
+ console.error('Error verifying:', err);
23
+ throw err;
24
+ }
25
+ };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Sends a GET request to the specified URL with optional query parameters and headers.
3
+ * Returns the response data of type T or throws an error if the request fails.
4
+ *
5
+ * Args:
6
+ * url: The endpoint URL for the GET request.
7
+ * params: Optional query parameters to include in the request.
8
+ * headers: Optional headers to include in the request.
9
+ *
10
+ * Returns:
11
+ * The response data of type T.
12
+ *
13
+ * Raises:
14
+ * Throws the error response data or error message if the request fails.
15
+ */
16
+ export declare function get<T>(url: string, params?: any, headers?: any): Promise<T>;
17
+ /**
18
+ * Sends a POST request to the specified URL with optional data and headers.
19
+ * Returns the response data of type T or throws an error if the request fails.
20
+ *
21
+ * Args:
22
+ * url: The endpoint URL for the POST request.
23
+ * data: Optional data to include in the request body.
24
+ * headers: Optional headers to include in the request.
25
+ *
26
+ * Returns:
27
+ * The response data of type T.
28
+ *
29
+ * Raises:
30
+ * Throws the error response data or error message if the request fails.
31
+ */
32
+ export declare function post<T>(url: string, data?: any, headers?: any): Promise<T>;
33
+ /**
34
+ * Sends a PUT request to the specified URL with optional data and headers.
35
+ * Returns the response data of type T or throws an error if the request fails.
36
+ *
37
+ * Args:
38
+ * url: The endpoint URL for the PUT request.
39
+ * data: Optional data to include in the request body.
40
+ * headers: Optional headers to include in the request.
41
+ *
42
+ * Returns:
43
+ * The response data of type T.
44
+ *
45
+ * Raises:
46
+ * Throws the error response data or error message if the request fails.
47
+ */
48
+ export declare function put<T>(url: string, data?: any, headers?: any): Promise<T>;
49
+ /**
50
+ * Sends a PATCH request to the specified URL with optional data and headers.
51
+ * Returns the response data of type T or throws an error if the request fails.
52
+ *
53
+ * Args:
54
+ * url: The endpoint URL for the PATCH request.
55
+ * data: Optional data to include in the request body.
56
+ * headers: Optional headers to include in the request.
57
+ *
58
+ * Returns:
59
+ * The response data of type T.
60
+ *
61
+ * Raises:
62
+ * Throws the error response data or error message if the request fails.
63
+ */
64
+ export declare function patch<T>(url: string, data?: any, headers?: any): Promise<T>;
65
+ /**
66
+ * Sends a DELETE request to the specified URL with optional data and headers.
67
+ * Returns the response data of type T or throws an error if the request fails.
68
+ *
69
+ * Args:
70
+ * url: The endpoint URL for the DELETE request.
71
+ * data: Optional data to include in the request body.
72
+ * headers: Optional headers to include in the request.
73
+ *
74
+ * Returns:
75
+ * The response data of type T.
76
+ *
77
+ * Raises:
78
+ * Throws the error response data or error message if the request fails.
79
+ */
80
+ export declare function del<T>(url: string, data?: any, headers?: any): Promise<T>;
@@ -0,0 +1,122 @@
1
+ import api from './axios.js';
2
+ /**
3
+ * Sends an HTTP request using the specified method, URL, and options.
4
+ * Returns the response data or throws an error if the request fails.
5
+ *
6
+ * Args:
7
+ * method: The HTTP method to use ('get', 'post', 'put', 'patch', 'delete').
8
+ * url: The endpoint URL for the request.
9
+ * options: Optional configuration including data, params, and headers.
10
+ *
11
+ * Returns:
12
+ * The response data of type T.
13
+ *
14
+ * Raises:
15
+ * Throws the error response data or error message if the request fails.
16
+ */
17
+ async function request(method, url, options = {}) {
18
+ try {
19
+ const response = await api.request({
20
+ method,
21
+ url,
22
+ data: options.data,
23
+ params: options.params,
24
+ headers: options.headers,
25
+ });
26
+ return response.data;
27
+ }
28
+ catch (error) {
29
+ throw error.response?.data || error.message;
30
+ }
31
+ }
32
+ // Named helper functions
33
+ /**
34
+ * Sends a GET request to the specified URL with optional query parameters and headers.
35
+ * Returns the response data of type T or throws an error if the request fails.
36
+ *
37
+ * Args:
38
+ * url: The endpoint URL for the GET request.
39
+ * params: Optional query parameters to include in the request.
40
+ * headers: Optional headers to include in the request.
41
+ *
42
+ * Returns:
43
+ * The response data of type T.
44
+ *
45
+ * Raises:
46
+ * Throws the error response data or error message if the request fails.
47
+ */
48
+ export function get(url, params, headers) {
49
+ return request('get', url, { params, headers });
50
+ }
51
+ /**
52
+ * Sends a POST request to the specified URL with optional data and headers.
53
+ * Returns the response data of type T or throws an error if the request fails.
54
+ *
55
+ * Args:
56
+ * url: The endpoint URL for the POST request.
57
+ * data: Optional data to include in the request body.
58
+ * headers: Optional headers to include in the request.
59
+ *
60
+ * Returns:
61
+ * The response data of type T.
62
+ *
63
+ * Raises:
64
+ * Throws the error response data or error message if the request fails.
65
+ */
66
+ export function post(url, data, headers) {
67
+ return request('post', url, { data, headers });
68
+ }
69
+ /**
70
+ * Sends a PUT request to the specified URL with optional data and headers.
71
+ * Returns the response data of type T or throws an error if the request fails.
72
+ *
73
+ * Args:
74
+ * url: The endpoint URL for the PUT request.
75
+ * data: Optional data to include in the request body.
76
+ * headers: Optional headers to include in the request.
77
+ *
78
+ * Returns:
79
+ * The response data of type T.
80
+ *
81
+ * Raises:
82
+ * Throws the error response data or error message if the request fails.
83
+ */
84
+ export function put(url, data, headers) {
85
+ return request('put', url, { data, headers });
86
+ }
87
+ /**
88
+ * Sends a PATCH request to the specified URL with optional data and headers.
89
+ * Returns the response data of type T or throws an error if the request fails.
90
+ *
91
+ * Args:
92
+ * url: The endpoint URL for the PATCH request.
93
+ * data: Optional data to include in the request body.
94
+ * headers: Optional headers to include in the request.
95
+ *
96
+ * Returns:
97
+ * The response data of type T.
98
+ *
99
+ * Raises:
100
+ * Throws the error response data or error message if the request fails.
101
+ */
102
+ export function patch(url, data, headers) {
103
+ return request('patch', url, { data, headers });
104
+ }
105
+ /**
106
+ * Sends a DELETE request to the specified URL with optional data and headers.
107
+ * Returns the response data of type T or throws an error if the request fails.
108
+ *
109
+ * Args:
110
+ * url: The endpoint URL for the DELETE request.
111
+ * data: Optional data to include in the request body.
112
+ * headers: Optional headers to include in the request.
113
+ *
114
+ * Returns:
115
+ * The response data of type T.
116
+ *
117
+ * Raises:
118
+ * Throws the error response data or error message if the request fails.
119
+ */
120
+ export function del(url, data, headers) {
121
+ return request('delete', url, { data, headers });
122
+ }
@@ -0,0 +1,2 @@
1
+ declare const api: import("axios").AxiosInstance;
2
+ export default api;
@@ -0,0 +1,8 @@
1
+ import axios from 'axios';
2
+ const api = axios.create({
3
+ baseURL: 'https://api-staging.paj.cash',
4
+ headers: {
5
+ 'Content-Type': 'application/json',
6
+ },
7
+ });
8
+ export default api;
@@ -0,0 +1,12 @@
1
+ import { Payload } from './verifySignature.js';
2
+ /**
3
+ * Generates a signature for the given payload using the provided secret key.
4
+ * Returns the generated signature as a base58-encoded string.
5
+ *
6
+ * Returns:
7
+ * The generated signature as a base58-encoded string.
8
+ *
9
+ * Raises:
10
+ * Throws an error if the payload is invalid or if the signing process fails.
11
+ */
12
+ export declare function generateSignature(payload: Payload, secretKey: Uint8Array): string;
@@ -0,0 +1,17 @@
1
+ import bs58 from 'bs58';
2
+ import nacl from 'tweetnacl';
3
+ /**
4
+ * Generates a signature for the given payload using the provided secret key.
5
+ * Returns the generated signature as a base58-encoded string.
6
+ *
7
+ * Returns:
8
+ * The generated signature as a base58-encoded string.
9
+ *
10
+ * Raises:
11
+ * Throws an error if the payload is invalid or if the signing process fails.
12
+ */
13
+ export function generateSignature(payload, secretKey) {
14
+ const message = JSON.stringify(payload);
15
+ const signature = nacl.sign.detached(new TextEncoder().encode(message), secretKey);
16
+ return bs58.encode(signature);
17
+ }
@@ -0,0 +1,15 @@
1
+ import { Payload } from '../utils/verifySignature.js';
2
+ /**
3
+ * Generates a signature, verifies it and returns the wallet body.
4
+ * Returns an object containing the payload and signature.
5
+ *
6
+ * Returns:
7
+ * An object containing the payload and signature.
8
+ *
9
+ * Raises:
10
+ * Throws an error if the wallet file is not found or if the secret key is invalid.
11
+ */
12
+ export declare const getWalletBody: (accountId: string, secretKey: Uint8Array) => Promise<{
13
+ payload: Payload;
14
+ signature: string;
15
+ } | undefined>;
@@ -0,0 +1,36 @@
1
+ import { Keypair } from '@solana/web3.js';
2
+ import { verifySignature } from '../utils/verifySignature.js';
3
+ import { generateSignature } from '../utils/generateSignature.js';
4
+ /**
5
+ * Generates a signature, verifies it and returns the wallet body.
6
+ * Returns an object containing the payload and signature.
7
+ *
8
+ * Returns:
9
+ * An object containing the payload and signature.
10
+ *
11
+ * Raises:
12
+ * Throws an error if the wallet file is not found or if the secret key is invalid.
13
+ */
14
+ export const getWalletBody = async (accountId, secretKey) => {
15
+ try {
16
+ const keypair = Keypair.fromSecretKey(secretKey);
17
+ let timestamp = new Date().toISOString();
18
+ const payload = {
19
+ publicKey: keypair.publicKey.toString(),
20
+ accountId,
21
+ timestamp,
22
+ };
23
+ const signature = generateSignature(payload, keypair.secretKey);
24
+ const isValid = verifySignature(payload, signature, keypair.publicKey);
25
+ const body = {
26
+ payload,
27
+ signature,
28
+ };
29
+ if (isValid) {
30
+ return body;
31
+ }
32
+ }
33
+ catch (err) {
34
+ console.error('Error getting wallet body:', err);
35
+ }
36
+ };
@@ -0,0 +1,17 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ export type Payload = {
3
+ publicKey: string;
4
+ accountId: string;
5
+ timestamp: string;
6
+ };
7
+ /**
8
+ * Verifies the signature of the given payload using the provided public key.
9
+ * Returns true if the signature is valid, false otherwise.
10
+ *
11
+ * Returns:
12
+ * boolean - Indicates whether the signature is valid.
13
+ *
14
+ * Raises:
15
+ * Throws an error if the payload is invalid or if the verification process fails.
16
+ */
17
+ export declare function verifySignature(payload: Payload, signatureBase58: string, publicKey: PublicKey): boolean;
@@ -0,0 +1,18 @@
1
+ import bs58 from 'bs58';
2
+ import nacl from 'tweetnacl';
3
+ /**
4
+ * Verifies the signature of the given payload using the provided public key.
5
+ * Returns true if the signature is valid, false otherwise.
6
+ *
7
+ * Returns:
8
+ * boolean - Indicates whether the signature is valid.
9
+ *
10
+ * Raises:
11
+ * Throws an error if the payload is invalid or if the verification process fails.
12
+ */
13
+ export function verifySignature(payload, signatureBase58, publicKey) {
14
+ const messageBytes = new TextEncoder().encode(JSON.stringify(payload));
15
+ const signature = bs58.decode(signatureBase58);
16
+ const publicKeyBytes = publicKey.toBytes();
17
+ return nacl.sign.detached.verify(messageBytes, signature, publicKeyBytes);
18
+ }
@@ -0,0 +1,8 @@
1
+ import { Keypair } from '@solana/web3.js';
2
+ import fs from 'fs';
3
+
4
+ const keypair = Keypair.generate();
5
+ const secretKey = Array.from(keypair.secretKey);
6
+
7
+ fs.writeFileSync('wallet.json', JSON.stringify(secretKey));
8
+ console.log('✅ wallet.json generated successfully');
package/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ //Web3.js - A JavaScript library for interacting with the Web3 ecosystem.
2
+
3
+ //Wallet Info
4
+ export { getTXPoolAddress } from './lib/getTXPoolAddress.js';
5
+ export { getRate } from './lib/getRate.js';
6
+
7
+ //Session Management
8
+ export { initiate } from './lib/initiate.js';
9
+ export { verify } from './lib/verify.js';
10
+
11
+ //Banking Operations
12
+ export { getBanks } from './lib/getBanks.js';
13
+ export { resolveBankAccount } from './lib/resolveBankAccount.js';
14
+ export { addBankAccount } from './lib/addBankAccount.js';
15
+ export { getBankAccounts } from './lib/getBankAccounts.js';
16
+
17
+ //Wallet Operations
18
+ export { getWallet } from './lib/getWallet.js';
19
+ export { addWallet } from './lib/addWallet.js';
20
+ export { switchWalletBankAccount } from './lib/switchWalletBankAccount.js';
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ export default {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ transform: {
5
+ '^.+\\.tsx?$': 'ts-jest',
6
+ },
7
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
8
+ };
@@ -0,0 +1,39 @@
1
+ import { post } from '../utils/api.js';
2
+
3
+ /**
4
+ * Adds a new bank account by sending the provided token, bank ID, and account number to the public API.
5
+ * Returns the added bank account details or throws an error if the request fails.
6
+ *
7
+ * Args:
8
+ * token: The authentication token for the request.
9
+ * bankId: The ID of the bank.
10
+ * accountNumber: The bank account number to add.
11
+ *
12
+ * Returns:
13
+ * An object containing the new bank account's id, accountName, accountNumber, and bank.
14
+ *
15
+ * Raises:
16
+ * Throws an error if the request fails.
17
+ */
18
+ export const addBankAccount = async (token: string, bankId: string, accountNumber: string) => {
19
+ try {
20
+ return await post<{
21
+ id: string;
22
+ accountName: string;
23
+ accountNumber: string;
24
+ bank: string;
25
+ }>(
26
+ '/pub/bankAccount',
27
+ {
28
+ bankId,
29
+ accountNumber,
30
+ },
31
+ {
32
+ Authorization: `Bearer ${token}`,
33
+ }
34
+ );
35
+ } catch (err) {
36
+ console.error('Error adding bank account:', err);
37
+ throw err;
38
+ }
39
+ };
@@ -0,0 +1,33 @@
1
+ import { post } from "../utils/api.js";
2
+ import { getWalletBody } from "../utils/getWalletBody.js";
3
+ import { WalletType } from "./getWallet.js";
4
+
5
+ /**
6
+ * Adds a new wallet for the user.
7
+ * Returns the added wallet object or throws an error if the request fails.
8
+ *
9
+ * Returns:
10
+ * An object containing id, accountName, accountNumber, and bank of the bank account.
11
+ *
12
+ * Raises:
13
+ * Throws an error if the wallet file is not found or if the secret key is invalid.
14
+ */
15
+ export const addWallet = async (
16
+ apiKey: string,
17
+ accountId: string,
18
+ secretKey: Uint8Array
19
+ ) => {
20
+ try {
21
+ const body = await getWalletBody(accountId, secretKey);
22
+ if (!body) {
23
+ throw new Error("Failed to get wallet body");
24
+ }
25
+
26
+ const response = await post<WalletType>("/pub/wallet", body, {
27
+ Authorization: `Bearer ${apiKey}`,
28
+ });
29
+ } catch (err) {
30
+ console.error("Error adding wallet:", err);
31
+ throw err;
32
+ }
33
+ };
@@ -0,0 +1,33 @@
1
+ import { get } from "../utils/api.js";
2
+
3
+ type GetBankAccountsType = {
4
+ id: string;
5
+ accountName: string;
6
+ accountNumber: string;
7
+ bank: string;
8
+ };
9
+
10
+ /**
11
+ * Fetches a list of added bank accounts from the public API endpoint.
12
+ * Returns an array of bank account objects or throws an error if the request fails.
13
+ *
14
+ * Returns:
15
+ * An array of objects, each containing id, accountName, accountNumber, and bank of a bank account.
16
+ *
17
+ * Raises:
18
+ * Throws an error if the request fails.
19
+ */
20
+ export const getBankAccounts = async (apiKey: string) => {
21
+ try {
22
+ return await get<GetBankAccountsType[]>(
23
+ `/pub/bankaccount`,
24
+ {},
25
+ {
26
+ Authorization: `Bearer ${apiKey}`,
27
+ }
28
+ );
29
+ } catch (err) {
30
+ console.error("Error fetching bank accounts:", err);
31
+ throw err;
32
+ }
33
+ };
@@ -0,0 +1,25 @@
1
+ import { get } from '../utils/api.js';
2
+
3
+ type BankType = {
4
+ id: string;
5
+ name: string;
6
+ country: string;
7
+ };
8
+ /**
9
+ * Fetches a list of banks from the public API endpoint.
10
+ * Returns an array of bank objects or throws an error if the request fails.
11
+ *
12
+ * Returns:
13
+ * An array of objects, each containing id, name, and country of a bank.
14
+ *
15
+ * Raises:
16
+ * Throws an error if the request fails.
17
+ */
18
+ export const getBanks = async () => {
19
+ try {
20
+ return await get<BankType[]>(`/pub/bank`);
21
+ } catch (err) {
22
+ console.error('Error fetching Banks:', err);
23
+ throw err;
24
+ }
25
+ };
package/lib/getRate.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { get } from '../utils/api.js';
2
+
3
+ type RateType = {
4
+ baseCurrency: string;
5
+ targetCurrency: string;
6
+ rate: number;
7
+ amounts: {
8
+ userTax: number;
9
+ merchantTax: number;
10
+ amountUSD: number;
11
+ userAmountFiat: number;
12
+ };
13
+ };
14
+
15
+ /**
16
+ * Fetches the exchange rate and related amounts for a given amount from the public API.
17
+ * Returns an object containing currency information, rate, and detailed amounts, or throws an error if the request fails.
18
+ *
19
+ * Args:
20
+ * amount: The amount for which to fetch the rate. If not provided or falsy, fetches the default rate.
21
+ *
22
+ * Returns:
23
+ * An object with baseCurrency, targetCurrency, rate, and amounts (userTax, merchantTax, amountUSD, userAmountFiat).
24
+ *
25
+ * Raises:
26
+ * Throws an error if the request fails.
27
+ */
28
+ export const getRate = async (amount: number) => {
29
+ try {
30
+ return await get<RateType>(amount ? `/pub/rate/${amount}` : '/pub/rate');
31
+ } catch (err) {
32
+ console.error('Error fetching Rate:', err);
33
+ throw err;
34
+ }
35
+ };
@@ -0,0 +1,22 @@
1
+ import { get } from '../utils/api.js';
2
+
3
+ /**
4
+ * Fetches the transaction pool address from the public API endpoint.
5
+ * Returns the address as a string or throws an error if the request fails.
6
+ *
7
+ * Returns:
8
+ * The transaction pool address as a string.
9
+ *
10
+ * Raises:
11
+ * Throws an error if the request fails.
12
+ */
13
+ export const getTXPoolAddress = async () => {
14
+ try {
15
+ return await get<{
16
+ address: string;
17
+ }>('/pub/txpool-address');
18
+ } catch (err) {
19
+ console.error('Error fetching TX Pool Address:', err);
20
+ throw err;
21
+ }
22
+ };