@galaxy-kj/core-stellar-sdk 2.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.
- package/LICENSE +21 -0
- package/README.md +576 -0
- package/dist/claimable-balances/claimable-balance-manager.d.ts +99 -0
- package/dist/claimable-balances/claimable-balance-manager.d.ts.map +1 -0
- package/dist/claimable-balances/claimable-balance-manager.js +352 -0
- package/dist/claimable-balances/claimable-balance-manager.js.map +1 -0
- package/dist/claimable-balances/helpers.d.ts +66 -0
- package/dist/claimable-balances/helpers.d.ts.map +1 -0
- package/dist/claimable-balances/helpers.js +179 -0
- package/dist/claimable-balances/helpers.js.map +1 -0
- package/dist/claimable-balances/index.d.ts +12 -0
- package/dist/claimable-balances/index.d.ts.map +1 -0
- package/dist/claimable-balances/index.js +14 -0
- package/dist/claimable-balances/index.js.map +1 -0
- package/dist/claimable-balances/predicate-builder.d.ts +66 -0
- package/dist/claimable-balances/predicate-builder.d.ts.map +1 -0
- package/dist/claimable-balances/predicate-builder.js +169 -0
- package/dist/claimable-balances/predicate-builder.js.map +1 -0
- package/dist/claimable-balances/types.d.ts +123 -0
- package/dist/claimable-balances/types.d.ts.map +1 -0
- package/dist/claimable-balances/types.js +9 -0
- package/dist/claimable-balances/types.js.map +1 -0
- package/dist/hooks/use-stellar.d.ts +48 -0
- package/dist/hooks/use-stellar.d.ts.map +1 -0
- package/dist/hooks/use-stellar.js +510 -0
- package/dist/hooks/use-stellar.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/liquidity-pools/calculations.d.ts +113 -0
- package/dist/liquidity-pools/calculations.d.ts.map +1 -0
- package/dist/liquidity-pools/calculations.js +291 -0
- package/dist/liquidity-pools/calculations.js.map +1 -0
- package/dist/liquidity-pools/helpers.d.ts +102 -0
- package/dist/liquidity-pools/helpers.d.ts.map +1 -0
- package/dist/liquidity-pools/helpers.js +219 -0
- package/dist/liquidity-pools/helpers.js.map +1 -0
- package/dist/liquidity-pools/index.d.ts +13 -0
- package/dist/liquidity-pools/index.d.ts.map +1 -0
- package/dist/liquidity-pools/index.js +18 -0
- package/dist/liquidity-pools/index.js.map +1 -0
- package/dist/liquidity-pools/liquidity-pool-manager.d.ts +106 -0
- package/dist/liquidity-pools/liquidity-pool-manager.d.ts.map +1 -0
- package/dist/liquidity-pools/liquidity-pool-manager.js +387 -0
- package/dist/liquidity-pools/liquidity-pool-manager.js.map +1 -0
- package/dist/liquidity-pools/types.d.ts +135 -0
- package/dist/liquidity-pools/types.d.ts.map +1 -0
- package/dist/liquidity-pools/types.js +6 -0
- package/dist/liquidity-pools/types.js.map +1 -0
- package/dist/liquidity-pools/validation.d.ts +75 -0
- package/dist/liquidity-pools/validation.d.ts.map +1 -0
- package/dist/liquidity-pools/validation.js +218 -0
- package/dist/liquidity-pools/validation.js.map +1 -0
- package/dist/services/stellar-service.d.ts +231 -0
- package/dist/services/stellar-service.d.ts.map +1 -0
- package/dist/services/stellar-service.js +674 -0
- package/dist/services/stellar-service.js.map +1 -0
- package/dist/soroban/helpers/contract-factory.d.ts +45 -0
- package/dist/soroban/helpers/contract-factory.d.ts.map +1 -0
- package/dist/soroban/helpers/contract-factory.js +84 -0
- package/dist/soroban/helpers/contract-factory.js.map +1 -0
- package/dist/soroban/helpers/token-contract-wrapper.d.ts +104 -0
- package/dist/soroban/helpers/token-contract-wrapper.d.ts.map +1 -0
- package/dist/soroban/helpers/token-contract-wrapper.js +286 -0
- package/dist/soroban/helpers/token-contract-wrapper.js.map +1 -0
- package/dist/soroban/index.d.ts +19 -0
- package/dist/soroban/index.d.ts.map +1 -0
- package/dist/soroban/index.js +19 -0
- package/dist/soroban/index.js.map +1 -0
- package/dist/soroban/soroban-contract-manager.d.ts +71 -0
- package/dist/soroban/soroban-contract-manager.d.ts.map +1 -0
- package/dist/soroban/soroban-contract-manager.js +376 -0
- package/dist/soroban/soroban-contract-manager.js.map +1 -0
- package/dist/soroban/types/contract-types.d.ts +156 -0
- package/dist/soroban/types/contract-types.d.ts.map +1 -0
- package/dist/soroban/types/contract-types.js +3 -0
- package/dist/soroban/types/contract-types.js.map +1 -0
- package/dist/soroban/utils/abi-parser.d.ts +90 -0
- package/dist/soroban/utils/abi-parser.d.ts.map +1 -0
- package/dist/soroban/utils/abi-parser.js +308 -0
- package/dist/soroban/utils/abi-parser.js.map +1 -0
- package/dist/soroban/utils/error-parser.d.ts +70 -0
- package/dist/soroban/utils/error-parser.d.ts.map +1 -0
- package/dist/soroban/utils/error-parser.js +302 -0
- package/dist/soroban/utils/error-parser.js.map +1 -0
- package/dist/soroban/utils/event-decoder.d.ts +91 -0
- package/dist/soroban/utils/event-decoder.d.ts.map +1 -0
- package/dist/soroban/utils/event-decoder.js +307 -0
- package/dist/soroban/utils/event-decoder.js.map +1 -0
- package/dist/soroban/utils/event-monitor.d.ts +93 -0
- package/dist/soroban/utils/event-monitor.d.ts.map +1 -0
- package/dist/soroban/utils/event-monitor.js +282 -0
- package/dist/soroban/utils/event-monitor.js.map +1 -0
- package/dist/soroban/utils/function-signature-builder.d.ts +98 -0
- package/dist/soroban/utils/function-signature-builder.d.ts.map +1 -0
- package/dist/soroban/utils/function-signature-builder.js +272 -0
- package/dist/soroban/utils/function-signature-builder.js.map +1 -0
- package/dist/soroban/utils/scval-converter.d.ts +48 -0
- package/dist/soroban/utils/scval-converter.d.ts.map +1 -0
- package/dist/soroban/utils/scval-converter.js +320 -0
- package/dist/soroban/utils/scval-converter.js.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-account-builder.d.ts +58 -0
- package/dist/sponsored-reserves/builders/sponsored-account-builder.d.ts.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-account-builder.js +159 -0
- package/dist/sponsored-reserves/builders/sponsored-account-builder.js.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-claimable-balance-builder.d.ts +104 -0
- package/dist/sponsored-reserves/builders/sponsored-claimable-balance-builder.d.ts.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-claimable-balance-builder.js +258 -0
- package/dist/sponsored-reserves/builders/sponsored-claimable-balance-builder.js.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-data-entry-builder.d.ts +96 -0
- package/dist/sponsored-reserves/builders/sponsored-data-entry-builder.d.ts.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-data-entry-builder.js +320 -0
- package/dist/sponsored-reserves/builders/sponsored-data-entry-builder.js.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-signer-builder.d.ts +100 -0
- package/dist/sponsored-reserves/builders/sponsored-signer-builder.d.ts.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-signer-builder.js +271 -0
- package/dist/sponsored-reserves/builders/sponsored-signer-builder.js.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-trustline-builder.d.ts +87 -0
- package/dist/sponsored-reserves/builders/sponsored-trustline-builder.d.ts.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-trustline-builder.js +281 -0
- package/dist/sponsored-reserves/builders/sponsored-trustline-builder.js.map +1 -0
- package/dist/sponsored-reserves/index.d.ts +20 -0
- package/dist/sponsored-reserves/index.d.ts.map +1 -0
- package/dist/sponsored-reserves/index.js +24 -0
- package/dist/sponsored-reserves/index.js.map +1 -0
- package/dist/sponsored-reserves/services/sponsored-reserves-manager.d.ts +144 -0
- package/dist/sponsored-reserves/services/sponsored-reserves-manager.d.ts.map +1 -0
- package/dist/sponsored-reserves/services/sponsored-reserves-manager.js +536 -0
- package/dist/sponsored-reserves/services/sponsored-reserves-manager.js.map +1 -0
- package/dist/sponsored-reserves/templates/claimable-balance-template.d.ts +96 -0
- package/dist/sponsored-reserves/templates/claimable-balance-template.d.ts.map +1 -0
- package/dist/sponsored-reserves/templates/claimable-balance-template.js +306 -0
- package/dist/sponsored-reserves/templates/claimable-balance-template.js.map +1 -0
- package/dist/sponsored-reserves/templates/multi-operation-template.d.ts +99 -0
- package/dist/sponsored-reserves/templates/multi-operation-template.d.ts.map +1 -0
- package/dist/sponsored-reserves/templates/multi-operation-template.js +313 -0
- package/dist/sponsored-reserves/templates/multi-operation-template.js.map +1 -0
- package/dist/sponsored-reserves/templates/user-onboarding-template.d.ts +79 -0
- package/dist/sponsored-reserves/templates/user-onboarding-template.d.ts.map +1 -0
- package/dist/sponsored-reserves/templates/user-onboarding-template.js +262 -0
- package/dist/sponsored-reserves/templates/user-onboarding-template.js.map +1 -0
- package/dist/sponsored-reserves/types/sponsored-reserves-types.d.ts +364 -0
- package/dist/sponsored-reserves/types/sponsored-reserves-types.d.ts.map +1 -0
- package/dist/sponsored-reserves/types/sponsored-reserves-types.js +9 -0
- package/dist/sponsored-reserves/types/sponsored-reserves-types.js.map +1 -0
- package/dist/sponsored-reserves/utils/cost-calculator.d.ts +98 -0
- package/dist/sponsored-reserves/utils/cost-calculator.d.ts.map +1 -0
- package/dist/sponsored-reserves/utils/cost-calculator.js +238 -0
- package/dist/sponsored-reserves/utils/cost-calculator.js.map +1 -0
- package/dist/sponsored-reserves/utils/sponsorship-validation.d.ts +112 -0
- package/dist/sponsored-reserves/utils/sponsorship-validation.d.ts.map +1 -0
- package/dist/sponsored-reserves/utils/sponsorship-validation.js +394 -0
- package/dist/sponsored-reserves/utils/sponsorship-validation.js.map +1 -0
- package/dist/types/stellar-sdk-compat.d.ts +25 -0
- package/dist/types/stellar-sdk-compat.d.ts.map +1 -0
- package/dist/types/stellar-sdk-compat.js +44 -0
- package/dist/types/stellar-sdk-compat.js.map +1 -0
- package/dist/types/stellar-types.d.ts +160 -0
- package/dist/types/stellar-types.d.ts.map +1 -0
- package/dist/types/stellar-types.js +9 -0
- package/dist/types/stellar-types.js.map +1 -0
- package/dist/utils/encryption.utils.d.ts +9 -0
- package/dist/utils/encryption.utils.d.ts.map +1 -0
- package/dist/utils/encryption.utils.js +44 -0
- package/dist/utils/encryption.utils.js.map +1 -0
- package/dist/utils/network-utils.d.ts +138 -0
- package/dist/utils/network-utils.d.ts.map +1 -0
- package/dist/utils/network-utils.js +240 -0
- package/dist/utils/network-utils.js.map +1 -0
- package/dist/utils/stellar-utils.d.ts +114 -0
- package/dist/utils/stellar-utils.d.ts.map +1 -0
- package/dist/utils/stellar-utils.js +186 -0
- package/dist/utils/stellar-utils.js.map +1 -0
- package/dist/utils/supabase-client.d.ts +2 -0
- package/dist/utils/supabase-client.d.ts.map +1 -0
- package/dist/utils/supabase-client.js +9 -0
- package/dist/utils/supabase-client.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
const ALGO = 'aes-256-gcm';
|
|
3
|
+
const IV_LENGTH = 12;
|
|
4
|
+
/**
|
|
5
|
+
* Encrypts text using AES-256-GCM with a password
|
|
6
|
+
*/
|
|
7
|
+
export function encryptPrivateKey(privateKey, password) {
|
|
8
|
+
const salt = crypto.randomBytes(16);
|
|
9
|
+
const iv = crypto.randomBytes(IV_LENGTH);
|
|
10
|
+
// Derive 256-bit key from password using PBKDF2
|
|
11
|
+
const key = crypto.pbkdf2Sync(password, salt, 100000, 32, 'sha256');
|
|
12
|
+
const cipher = crypto.createCipheriv(ALGO, key, iv);
|
|
13
|
+
const encrypted = Buffer.concat([
|
|
14
|
+
cipher.update(privateKey, 'utf8'),
|
|
15
|
+
cipher.final(),
|
|
16
|
+
]);
|
|
17
|
+
const authTag = cipher.getAuthTag();
|
|
18
|
+
// Format: salt:iv:authTag:ciphertext (Base64)
|
|
19
|
+
return [
|
|
20
|
+
salt.toString('base64'),
|
|
21
|
+
iv.toString('base64'),
|
|
22
|
+
authTag.toString('base64'),
|
|
23
|
+
encrypted.toString('base64'),
|
|
24
|
+
].join(':');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Decrypts AES-256-GCM encrypted private key
|
|
28
|
+
*/
|
|
29
|
+
export function decryptPrivateKey(encryptedData, password) {
|
|
30
|
+
const [saltB64, ivB64, authTagB64, encryptedB64] = encryptedData.split(':');
|
|
31
|
+
const salt = Buffer.from(saltB64, 'base64');
|
|
32
|
+
const iv = Buffer.from(ivB64, 'base64');
|
|
33
|
+
const authTag = Buffer.from(authTagB64, 'base64');
|
|
34
|
+
const encrypted = Buffer.from(encryptedB64, 'base64');
|
|
35
|
+
const key = crypto.pbkdf2Sync(password, salt, 100000, 32, 'sha256');
|
|
36
|
+
const decipher = crypto.createDecipheriv(ALGO, key, iv);
|
|
37
|
+
decipher.setAuthTag(authTag);
|
|
38
|
+
const decrypted = Buffer.concat([
|
|
39
|
+
decipher.update(encrypted),
|
|
40
|
+
decipher.final(),
|
|
41
|
+
]);
|
|
42
|
+
return decrypted.toString('utf8');
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=encryption.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.utils.js","sourceRoot":"","sources":["../../src/utils/encryption.utils.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,IAAI,GAAG,aAAa,CAAC;AAC3B,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAkB,EAClB,QAAgB;IAEhB,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACpC,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAEzC,gDAAgD;IAChD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;IAEpE,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;QAC9B,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAA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,CAAC,KAAK,EAAE;KACjB,CAAC,CAAC;IACH,OAAO,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Network utilities for Stellar operations
|
|
3
|
+
* @description Helper functions for network-related operations
|
|
4
|
+
* @author Galaxy DevKit Team
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @since 2024-12-01
|
|
7
|
+
*/
|
|
8
|
+
import { NetworkConfig } from '../types/stellar-types';
|
|
9
|
+
/**
|
|
10
|
+
* Network utility class
|
|
11
|
+
* @class NetworkUtils
|
|
12
|
+
* @description Provides helper methods for network operations
|
|
13
|
+
*/
|
|
14
|
+
export declare class NetworkUtils {
|
|
15
|
+
/**
|
|
16
|
+
* Predefined network configurations
|
|
17
|
+
*/
|
|
18
|
+
static readonly NETWORKS: {
|
|
19
|
+
PUBLIC: NetworkConfig;
|
|
20
|
+
TESTNET: NetworkConfig;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Validates if a string is a valid Stellar public key
|
|
24
|
+
* @param publicKey - Public key to validate
|
|
25
|
+
* @returns boolean
|
|
26
|
+
*/
|
|
27
|
+
isValidPublicKey(publicKey: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Validates if a string is a valid Stellar secret key
|
|
30
|
+
* @param secretKey - Secret key to validate
|
|
31
|
+
* @returns boolean
|
|
32
|
+
*/
|
|
33
|
+
isValidSecretKey(secretKey: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Gets network configuration by name
|
|
36
|
+
* @param networkName - Network name ('public' or 'testnet')
|
|
37
|
+
* @returns NetworkConfig
|
|
38
|
+
*/
|
|
39
|
+
getNetworkConfig(networkName: 'public' | 'testnet'): NetworkConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a custom network configuration
|
|
42
|
+
* @param horizonUrl - Horizon server URL
|
|
43
|
+
* @param passphrase - Network passphrase
|
|
44
|
+
* @param name - Network name
|
|
45
|
+
* @returns NetworkConfig
|
|
46
|
+
*/
|
|
47
|
+
createCustomNetwork(horizonUrl: string, passphrase: string, network?: 'testnet' | 'mainnet'): NetworkConfig;
|
|
48
|
+
/**
|
|
49
|
+
* Determines if the network is testnet based on passphrase
|
|
50
|
+
* @param passphrase - Network passphrase
|
|
51
|
+
* @returns boolean
|
|
52
|
+
*/
|
|
53
|
+
static isTestnet(passphrase: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Determines if the network is public based on passphrase
|
|
56
|
+
* @param passphrase - Network passphrase
|
|
57
|
+
* @returns boolean
|
|
58
|
+
*/
|
|
59
|
+
isPublic(passphrase: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the appropriate friendbot URL for testnet funding
|
|
62
|
+
* @returns string
|
|
63
|
+
*/
|
|
64
|
+
getFriendbotUrl(): string;
|
|
65
|
+
/**
|
|
66
|
+
* Funds a testnet account using Friendbot
|
|
67
|
+
* @param publicKey - Public key to fund
|
|
68
|
+
* @returns Promise<boolean>
|
|
69
|
+
*/
|
|
70
|
+
fundTestnetAccount(publicKey: string): Promise<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Encodes raw public key bytes to Stellar format
|
|
73
|
+
* @param rawPublicKey - Raw public key bytes
|
|
74
|
+
* @returns string
|
|
75
|
+
*/
|
|
76
|
+
encodePublicKey(rawPublicKey: Buffer): string;
|
|
77
|
+
/**
|
|
78
|
+
* Encodes raw secret key bytes to Stellar format
|
|
79
|
+
* @param rawSecretKey - Raw secret key bytes
|
|
80
|
+
* @returns string
|
|
81
|
+
*/
|
|
82
|
+
encodeSecretKey(rawSecretKey: Buffer): string;
|
|
83
|
+
/**
|
|
84
|
+
* Decodes a Stellar public key to raw bytes
|
|
85
|
+
* @param publicKey - Stellar public key
|
|
86
|
+
* @returns Buffer
|
|
87
|
+
*/
|
|
88
|
+
decodePublicKey(publicKey: string): Buffer;
|
|
89
|
+
/**
|
|
90
|
+
* Decodes a Stellar secret key to raw bytes
|
|
91
|
+
* @param secretKey - Stellar secret key
|
|
92
|
+
* @returns Buffer
|
|
93
|
+
*/
|
|
94
|
+
decodeSecretKey(secretKey: string): Buffer;
|
|
95
|
+
/**
|
|
96
|
+
* Validates a Stellar address (account ID)
|
|
97
|
+
* @param address - Address to validate
|
|
98
|
+
* @returns boolean
|
|
99
|
+
*/
|
|
100
|
+
isValidAddress(address: string): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Validates a muxed account address
|
|
103
|
+
* @param address - Muxed address to validate
|
|
104
|
+
* @returns boolean
|
|
105
|
+
*/
|
|
106
|
+
isValidMuxedAccount(address: string): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Gets explorer URL for a transaction
|
|
109
|
+
* @param txHash - Transaction hash
|
|
110
|
+
* @param network - Network type
|
|
111
|
+
* @returns string
|
|
112
|
+
*/
|
|
113
|
+
getExplorerUrl(txHash: string, network?: 'public' | 'testnet'): string;
|
|
114
|
+
/**
|
|
115
|
+
* Gets explorer URL for an account
|
|
116
|
+
* @param publicKey - Account public key
|
|
117
|
+
* @param network - Network type
|
|
118
|
+
* @returns string
|
|
119
|
+
*/
|
|
120
|
+
getAccountExplorerUrl(publicKey: string, network?: 'public' | 'testnet'): string;
|
|
121
|
+
/**
|
|
122
|
+
* Checks network connectivity
|
|
123
|
+
* @param horizonUrl - Horizon server URL
|
|
124
|
+
* @returns Promise<boolean>
|
|
125
|
+
*/
|
|
126
|
+
checkNetworkConnectivity(horizonUrl: string): Promise<boolean>;
|
|
127
|
+
/**
|
|
128
|
+
* Gets network health status
|
|
129
|
+
* @param horizonUrl - Horizon server URL
|
|
130
|
+
* @returns Promise<object>
|
|
131
|
+
*/
|
|
132
|
+
getNetworkHealth(horizonUrl: string): Promise<{
|
|
133
|
+
isHealthy: boolean;
|
|
134
|
+
latency?: number;
|
|
135
|
+
error?: string;
|
|
136
|
+
}>;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=network-ut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;IAIxC;;;;OAIG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAQ7C;;;;;OAKG;IACH,cAAc,CACZ,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,QAAQ,GAAG,SAAoB,GACvC,MAAM;IAQT;;;;;OAKG;IACH,qBAAqB,CACnB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,QAAQ,GAAG,SAAoB,GACvC,MAAM;IAQT;;;;OAIG;IACG,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IASpE;;;;OAIG;IACG,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;QAClD,SAAS,EAAE,OAAO,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CAiBH"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Network utilities for Stellar operations
|
|
3
|
+
* @description Helper functions for network-related operations
|
|
4
|
+
* @author Galaxy DevKit Team
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @since 2024-12-01
|
|
7
|
+
*/
|
|
8
|
+
import { Networks, StrKey } from '@stellar/stellar-sdk';
|
|
9
|
+
/**
|
|
10
|
+
* Network utility class
|
|
11
|
+
* @class NetworkUtils
|
|
12
|
+
* @description Provides helper methods for network operations
|
|
13
|
+
*/
|
|
14
|
+
export class NetworkUtils {
|
|
15
|
+
/**
|
|
16
|
+
* Validates if a string is a valid Stellar public key
|
|
17
|
+
* @param publicKey - Public key to validate
|
|
18
|
+
* @returns boolean
|
|
19
|
+
*/
|
|
20
|
+
isValidPublicKey(publicKey) {
|
|
21
|
+
try {
|
|
22
|
+
return StrKey.isValidEd25519PublicKey(publicKey);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validates if a string is a valid Stellar secret key
|
|
30
|
+
* @param secretKey - Secret key to validate
|
|
31
|
+
* @returns boolean
|
|
32
|
+
*/
|
|
33
|
+
isValidSecretKey(secretKey) {
|
|
34
|
+
try {
|
|
35
|
+
return StrKey.isValidEd25519SecretSeed(secretKey);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets network configuration by name
|
|
43
|
+
* @param networkName - Network name ('public' or 'testnet')
|
|
44
|
+
* @returns NetworkConfig
|
|
45
|
+
*/
|
|
46
|
+
getNetworkConfig(networkName) {
|
|
47
|
+
return networkName === 'public'
|
|
48
|
+
? NetworkUtils.NETWORKS.PUBLIC
|
|
49
|
+
: NetworkUtils.NETWORKS.TESTNET;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a custom network configuration
|
|
53
|
+
* @param horizonUrl - Horizon server URL
|
|
54
|
+
* @param passphrase - Network passphrase
|
|
55
|
+
* @param name - Network name
|
|
56
|
+
* @returns NetworkConfig
|
|
57
|
+
*/
|
|
58
|
+
createCustomNetwork(horizonUrl, passphrase, network = 'testnet') {
|
|
59
|
+
return {
|
|
60
|
+
horizonUrl,
|
|
61
|
+
passphrase,
|
|
62
|
+
network,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Determines if the network is testnet based on passphrase
|
|
67
|
+
* @param passphrase - Network passphrase
|
|
68
|
+
* @returns boolean
|
|
69
|
+
*/
|
|
70
|
+
static isTestnet(passphrase) {
|
|
71
|
+
return passphrase === Networks.TESTNET;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Determines if the network is public based on passphrase
|
|
75
|
+
* @param passphrase - Network passphrase
|
|
76
|
+
* @returns boolean
|
|
77
|
+
*/
|
|
78
|
+
isPublic(passphrase) {
|
|
79
|
+
return passphrase === Networks.PUBLIC;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Gets the appropriate friendbot URL for testnet funding
|
|
83
|
+
* @returns string
|
|
84
|
+
*/
|
|
85
|
+
getFriendbotUrl() {
|
|
86
|
+
return 'https://friendbot.stellar.org';
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Funds a testnet account using Friendbot
|
|
90
|
+
* @param publicKey - Public key to fund
|
|
91
|
+
* @returns Promise<boolean>
|
|
92
|
+
*/
|
|
93
|
+
async fundTestnetAccount(publicKey) {
|
|
94
|
+
try {
|
|
95
|
+
if (!this.isValidPublicKey(publicKey)) {
|
|
96
|
+
throw new Error('Invalid public key');
|
|
97
|
+
}
|
|
98
|
+
const friendbotUrl = this.getFriendbotUrl();
|
|
99
|
+
const response = await fetch(`${friendbotUrl}?addr=${encodeURIComponent(publicKey)}`);
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
throw new Error(`Friendbot request failed: ${response.statusText}`);
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
throw new Error(`Failed to fund testnet account: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Encodes raw public key bytes to Stellar format
|
|
111
|
+
* @param rawPublicKey - Raw public key bytes
|
|
112
|
+
* @returns string
|
|
113
|
+
*/
|
|
114
|
+
encodePublicKey(rawPublicKey) {
|
|
115
|
+
return StrKey.encodeEd25519PublicKey(rawPublicKey);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Encodes raw secret key bytes to Stellar format
|
|
119
|
+
* @param rawSecretKey - Raw secret key bytes
|
|
120
|
+
* @returns string
|
|
121
|
+
*/
|
|
122
|
+
encodeSecretKey(rawSecretKey) {
|
|
123
|
+
return StrKey.encodeEd25519SecretSeed(rawSecretKey);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Decodes a Stellar public key to raw bytes
|
|
127
|
+
* @param publicKey - Stellar public key
|
|
128
|
+
* @returns Buffer
|
|
129
|
+
*/
|
|
130
|
+
decodePublicKey(publicKey) {
|
|
131
|
+
return StrKey.decodeEd25519PublicKey(publicKey);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Decodes a Stellar secret key to raw bytes
|
|
135
|
+
* @param secretKey - Stellar secret key
|
|
136
|
+
* @returns Buffer
|
|
137
|
+
*/
|
|
138
|
+
decodeSecretKey(secretKey) {
|
|
139
|
+
return StrKey.decodeEd25519SecretSeed(secretKey);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Validates a Stellar address (account ID)
|
|
143
|
+
* @param address - Address to validate
|
|
144
|
+
* @returns boolean
|
|
145
|
+
*/
|
|
146
|
+
isValidAddress(address) {
|
|
147
|
+
return this.isValidPublicKey(address);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Validates a muxed account address
|
|
151
|
+
* @param address - Muxed address to validate
|
|
152
|
+
* @returns boolean
|
|
153
|
+
*/
|
|
154
|
+
isValidMuxedAccount(address) {
|
|
155
|
+
try {
|
|
156
|
+
return StrKey.isValidMed25519PublicKey(address);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Gets explorer URL for a transaction
|
|
164
|
+
* @param txHash - Transaction hash
|
|
165
|
+
* @param network - Network type
|
|
166
|
+
* @returns string
|
|
167
|
+
*/
|
|
168
|
+
getExplorerUrl(txHash, network = 'public') {
|
|
169
|
+
const baseUrl = network === 'public'
|
|
170
|
+
? 'https://stellar.expert/explorer/public'
|
|
171
|
+
: 'https://stellar.expert/explorer/testnet';
|
|
172
|
+
return `${baseUrl}/tx/${txHash}`;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Gets explorer URL for an account
|
|
176
|
+
* @param publicKey - Account public key
|
|
177
|
+
* @param network - Network type
|
|
178
|
+
* @returns string
|
|
179
|
+
*/
|
|
180
|
+
getAccountExplorerUrl(publicKey, network = 'public') {
|
|
181
|
+
const baseUrl = network === 'public'
|
|
182
|
+
? 'https://stellar.expert/explorer/public'
|
|
183
|
+
: 'https://stellar.expert/explorer/testnet';
|
|
184
|
+
return `${baseUrl}/account/${publicKey}`;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Checks network connectivity
|
|
188
|
+
* @param horizonUrl - Horizon server URL
|
|
189
|
+
* @returns Promise<boolean>
|
|
190
|
+
*/
|
|
191
|
+
async checkNetworkConnectivity(horizonUrl) {
|
|
192
|
+
try {
|
|
193
|
+
const response = await fetch(horizonUrl);
|
|
194
|
+
return response.ok;
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Gets network health status
|
|
202
|
+
* @param horizonUrl - Horizon server URL
|
|
203
|
+
* @returns Promise<object>
|
|
204
|
+
*/
|
|
205
|
+
async getNetworkHealth(horizonUrl) {
|
|
206
|
+
const startTime = Date.now();
|
|
207
|
+
try {
|
|
208
|
+
const response = await fetch(horizonUrl);
|
|
209
|
+
const latency = Date.now() - startTime;
|
|
210
|
+
return {
|
|
211
|
+
isHealthy: response.ok,
|
|
212
|
+
latency,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
return {
|
|
217
|
+
isHealthy: false,
|
|
218
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Predefined network configurations
|
|
225
|
+
*/
|
|
226
|
+
NetworkUtils.NETWORKS = {
|
|
227
|
+
PUBLIC: {
|
|
228
|
+
name: 'mainnet',
|
|
229
|
+
horizonUrl: 'https://horizon.stellar.org',
|
|
230
|
+
passphrase: Networks.PUBLIC,
|
|
231
|
+
network: 'mainnet',
|
|
232
|
+
},
|
|
233
|
+
TESTNET: {
|
|
234
|
+
name: 'testnet',
|
|
235
|
+
horizonUrl: 'https://horizon-testnet.stellar.org',
|
|
236
|
+
passphrase: Networks.TESTNET,
|
|
237
|
+
network: 'testnet',
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
//# sourceMappingURL=network-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-utils.js","sourceRoot":"","sources":["../../src/utils/network-utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAGxD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAmBvB;;;;OAIG;IACH,gBAAgB,CAAC,SAAiB;QAChC,IAAI,CAAC;YACH,OAAO,MAAM,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QACnD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,SAAiB;QAChC,IAAI,CAAC;YACH,OAAO,MAAM,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC;QACpD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,WAAiC;QAChD,OAAO,WAAW,KAAK,QAAQ;YAC7B,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM;YAC9B,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACH,mBAAmB,CACjB,UAAkB,EAClB,UAAkB,EAClB,UAAiC,SAAS;QAE1C,OAAO;YACL,UAAU;YACV,UAAU;YACV,OAAO;SACR,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CA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AAG,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC;YACzC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YAEvC,OAAO;gBACL,SAAS,EAAE,QAAQ,CAAC,EAAE;gBACtB,OAAO;aACR,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,SAAS,EAAE,KAAK;gBAChB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAChE,CAAC;QACJ,CAAC;IACH,CAAC;;AAnQD;;GAEG;AACa,qBAAQ,GAAG;IACzB,MAAM,EAAE;QACN,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,6BAA6B;QACzC,UAAU,EAAE,QAAQ,CAAC,MAAM;QAC3B,OAAO,EAAE,SAAS;KACF;IAClB,OAAO,EAAE;QACP,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,qCAAqC;QACjD,UAAU,EAAE,QAAQ,CAAC,OAAO;QAC5B,OAAO,EAAE,SAAS;KACF;CACnB,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Utility functions for Stellar operations
|
|
3
|
+
* @description Contains helper functions and utilities for Stellar operations
|
|
4
|
+
* @author Galaxy DevKit Team
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @since 2024-12-01
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Validates a Stellar public key
|
|
10
|
+
* @param publicKey - The public key to validate
|
|
11
|
+
* @returns boolean
|
|
12
|
+
*/
|
|
13
|
+
export declare const isValidPublicKey: (publicKey: string) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Validates a Stellar secret key
|
|
16
|
+
* @param secretKey - The secret key to validate
|
|
17
|
+
* @returns boolean
|
|
18
|
+
*/
|
|
19
|
+
export declare const isValidSecretKey: (secretKey: string) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Generates a random Stellar keypair
|
|
22
|
+
* @returns Object with publicKey and secretKey
|
|
23
|
+
*/
|
|
24
|
+
export declare const generateKeypair: () => {
|
|
25
|
+
publicKey: string;
|
|
26
|
+
secretKey: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Converts Stellar amount to stroops (smallest unit)
|
|
30
|
+
* @param amount - Amount in XLM
|
|
31
|
+
* @returns number of stroops
|
|
32
|
+
*/
|
|
33
|
+
export declare const toStroops: (amount: string | number) => number;
|
|
34
|
+
/**
|
|
35
|
+
* Converts stroops to XLM amount
|
|
36
|
+
* @param stroops - Amount in stroops
|
|
37
|
+
* @returns string representation of XLM amount
|
|
38
|
+
*/
|
|
39
|
+
export declare const fromStroops: (stroops: number) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Formats a Stellar address for display
|
|
42
|
+
* @param address - Stellar address
|
|
43
|
+
* @param startChars - Number of characters to show at start
|
|
44
|
+
* @param endChars - Number of characters to show at end
|
|
45
|
+
* @returns formatted address
|
|
46
|
+
*/
|
|
47
|
+
export declare const formatAddress: (address: string, startChars?: number, endChars?: number) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Validates a Stellar memo
|
|
50
|
+
* @param memo - Memo to validate
|
|
51
|
+
* @returns boolean
|
|
52
|
+
*/
|
|
53
|
+
export declare const isValidMemo: (memo: string) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Converts network name to passphrase
|
|
56
|
+
* @param network - Network name
|
|
57
|
+
* @returns network passphrase
|
|
58
|
+
*/
|
|
59
|
+
export declare const getNetworkPassphrase: (network: "testnet" | "mainnet") => string;
|
|
60
|
+
/**
|
|
61
|
+
* Gets Horizon server URL for network
|
|
62
|
+
* @param network - Network name
|
|
63
|
+
* @returns Horizon server URL
|
|
64
|
+
*/
|
|
65
|
+
export declare const getHorizonUrl: (network: "testnet" | "mainnet") => string;
|
|
66
|
+
/**
|
|
67
|
+
* Validates if an amount is positive
|
|
68
|
+
* @param amount - Amount to validate
|
|
69
|
+
* @returns boolean
|
|
70
|
+
*/
|
|
71
|
+
export declare const isValidAmount: (amount: string | number) => boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Formats balance for display
|
|
74
|
+
* @param balance - Balance amount
|
|
75
|
+
* @param decimals - Number of decimal places
|
|
76
|
+
* @returns formatted balance string
|
|
77
|
+
*/
|
|
78
|
+
export declare const formatBalance: (balance: string | number, decimals?: number) => string;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if two addresses are the same
|
|
81
|
+
* @param address1 - First address
|
|
82
|
+
* @param address2 - Second address
|
|
83
|
+
* @returns boolean
|
|
84
|
+
*/
|
|
85
|
+
export declare const isSameAddress: (address1: string, address2: string) => boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Generates a transaction memo
|
|
88
|
+
* @param text - Memo text
|
|
89
|
+
* @returns memo object
|
|
90
|
+
*/
|
|
91
|
+
export declare const createMemo: (text: string) => {
|
|
92
|
+
type: string;
|
|
93
|
+
value: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Calculates transaction fee based on operations
|
|
97
|
+
* @param operationCount - Number of operations
|
|
98
|
+
* @param baseFee - Base fee per operation
|
|
99
|
+
* @returns total fee
|
|
100
|
+
*/
|
|
101
|
+
export declare const calculateFee: (operationCount: number, baseFee?: number) => number;
|
|
102
|
+
/**
|
|
103
|
+
* Validates asset code format
|
|
104
|
+
* @param assetCode - Asset code to validate
|
|
105
|
+
* @returns boolean
|
|
106
|
+
*/
|
|
107
|
+
export declare const isValidAssetCode: (assetCode: string) => boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Validates a Stellar wallet memo.
|
|
110
|
+
* @param memo - Memo to validate
|
|
111
|
+
* @throws Error if memo is invalid
|
|
112
|
+
*/
|
|
113
|
+
export declare function validateMemo(memo: string): void;
|
|
114
|
+
//# sourceMappingURL=stellar-utils.d.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