UNPKG

@truenetworkio/sdk

Version:

True Network SDK is the abstracted interface for interacting with True Network nodes.

37 lines (36 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getWalletWithType = exports.checkAndConvertAddresses = exports.toTrueNetworkAddress = void 0; const util_crypto_1 = require("@polkadot/util-crypto"); const toTrueNetworkAddress = (address) => { if (!address || !(0, util_crypto_1.isAddress)(address)) throw Error(`Not a valid address, passing: ${address}`); return (0, util_crypto_1.encodeAddress)((0, util_crypto_1.decodeAddress)(address), 7); }; exports.toTrueNetworkAddress = toTrueNetworkAddress; const checkAndConvertAddresses = (addresses) => addresses.map(i => (0, exports.toTrueNetworkAddress)(i)); exports.checkAndConvertAddresses = checkAndConvertAddresses; const getWalletWithType = (address) => { // Check if address is empty or not a string if (!address || typeof address !== 'string') { return { "Unknown": address }; } // Ethereum: 42 chars, starts with 0x, contains hex chars const ethereumRegex = /^0x[a-fA-F0-9]{40}$/; if (ethereumRegex.test(address)) { return { "Ethereum": address }; } // Solana: 32-44 chars, Base58 characters const solanaRegex = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/; if (solanaRegex.test(address)) { return { "Solana": address }; } // Substrate: 47-48 chars, typically starts with specific numbers // This is a simplified check - could be enhanced for specific networks const substrateRegex = /^[1-9A-HJ-NP-Za-km-z]{47,48}$/; if (substrateRegex.test(address)) { return { "Substrate": address }; } return { "Unknown": address }; }; exports.getWalletWithType = getWalletWithType;