@blockfrost/blockfrost-utils
Advanced tools
Comparing version 1.0.0-alfa.2 to 1.0.0-alfa.3
declare type BlockfrostNetwork = 'mainnet' | 'testnet' | 'preview' | 'preprod'; | ||
export declare const validateHex: (input: string) => boolean; | ||
export declare const validateStakeAddress: (input: string, network: BlockfrostNetwork) => boolean; | ||
export declare const convertStakeAddress: (input: string, network: BlockfrostNetwork) => string | undefined; | ||
export declare const validateAndConvertPool: (input: string) => string | undefined; | ||
@@ -3,0 +6,0 @@ export declare const paymentCredFromBech32Address: (input: string) => string | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isNumber = exports.validateBlockHash = exports.validateDerivationXpub = exports.validateInRangeUnsignedInt = exports.validatePositiveInRangeSignedBigInt = exports.validatePositiveInRangeSignedInt = exports.scriptHashFromBech32Address = exports.getAddressTypeAndPaymentCred = exports.detectAndValidateAddressType = exports.paymentCredToBech32Address = exports.paymentCredFromBech32Address = exports.validateAndConvertPool = void 0; | ||
exports.isNumber = exports.validateBlockHash = exports.validateDerivationXpub = exports.validateInRangeUnsignedInt = exports.validatePositiveInRangeSignedBigInt = exports.validatePositiveInRangeSignedInt = exports.scriptHashFromBech32Address = exports.getAddressTypeAndPaymentCred = exports.detectAndValidateAddressType = exports.paymentCredToBech32Address = exports.paymentCredFromBech32Address = exports.validateAndConvertPool = exports.convertStakeAddress = exports.validateStakeAddress = exports.validateHex = void 0; | ||
const cardano_serialization_lib_nodejs_1 = require("@emurgo/cardano-serialization-lib-nodejs"); | ||
@@ -27,6 +27,38 @@ const bech32_1 = require("bech32"); | ||
}; | ||
exports.validateHex = validateHex; | ||
const validateStakeAddress = (input, network) => { | ||
// validate stake address (also check network mismatch i.e. mainnet/testnet) | ||
try { | ||
const bech32Info = bech32_1.bech32.decode(input, 1000); | ||
if ((bech32Info.prefix === Prefixes.STAKE && network === 'mainnet') || | ||
(bech32Info.prefix === Prefixes.STAKE_TEST && network !== 'mainnet')) | ||
return true; | ||
else { | ||
return false; | ||
} | ||
} | ||
catch { | ||
return false; | ||
} | ||
}; | ||
exports.validateStakeAddress = validateStakeAddress; | ||
const convertStakeAddress = (input, network) => { | ||
try { | ||
if (!(0, exports.validateHex)(input)) | ||
return undefined; | ||
const words = bech32_1.bech32.toWords(Buffer.from(input, 'hex')); | ||
// if it's in hex, we'll convert it to Bech32 | ||
return network === 'mainnet' | ||
? bech32_1.bech32.encode(Prefixes.STAKE, words) | ||
: bech32_1.bech32.encode(Prefixes.STAKE_TEST, words); | ||
} | ||
catch { | ||
return undefined; | ||
} | ||
}; | ||
exports.convertStakeAddress = convertStakeAddress; | ||
const validateAndConvertPool = (input) => { | ||
// if it's hex, it will get converted and checked, otherwise it's bech32 and stays that way | ||
try { | ||
if (validateHex(input)) { | ||
if ((0, exports.validateHex)(input)) { | ||
const words = bech32_1.bech32.toWords(Buffer.from(input, 'hex')); | ||
@@ -69,3 +101,3 @@ // if it's in hex, we'll convert it to Bech32 | ||
try { | ||
if (!validateHex(input)) | ||
if (!(0, exports.validateHex)(input)) | ||
return undefined; | ||
@@ -186,17 +218,7 @@ const words = bech32_1.bech32.toWords(Buffer.from(input, 'hex')); | ||
const validateDerivationXpub = (input) => { | ||
try { | ||
return validateHex(input) && input.length === 128; | ||
} | ||
catch { | ||
return false; | ||
} | ||
return (0, exports.validateHex)(input) && input.length === 128; | ||
}; | ||
exports.validateDerivationXpub = validateDerivationXpub; | ||
const validateBlockHash = (input) => { | ||
try { | ||
return validateHex(input) && input.length === 64; | ||
} | ||
catch { | ||
return false; | ||
} | ||
return (0, exports.validateHex)(input) && input.length === 64; | ||
}; | ||
@@ -203,0 +225,0 @@ exports.validateBlockHash = validateBlockHash; |
{ | ||
"name": "@blockfrost/blockfrost-utils", | ||
"version": "1.0.0-alfa.2", | ||
"version": "1.0.0-alfa.3", | ||
"repository": "git@github.com:blockfrost/blockfrost-utils.git", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43519
739