@blockfrost/blockfrost-utils
Advanced tools
Comparing version 1.0.0-alfa.1 to 1.0.0-alfa.2
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import type { FastifyError, FastifyRequest, FastifyReply } from 'fastify'; | ||
@@ -11,1 +12,2 @@ export declare const notFoundHandler: (_request: FastifyRequest, reply: FastifyReply) => FastifyReply; | ||
export declare const handle500: (reply: FastifyReply, error: unknown, request: FastifyRequest) => FastifyReply; | ||
export declare const handleInvalidAddress: (reply: FastifyReply) => FastifyReply<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify/types/route").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handle500 = exports.handle404 = exports.handle403Custom = exports.handle403 = exports.handle402 = exports.handle400Custom = exports.handle400 = exports.errorHandler = exports.notFoundHandler = void 0; | ||
exports.handleInvalidAddress = exports.handle500 = exports.handle404 = exports.handle403Custom = exports.handle403 = exports.handle402 = exports.handle400Custom = exports.handle400 = exports.errorHandler = exports.notFoundHandler = void 0; | ||
const notFoundHandler = (_request, reply) => { | ||
@@ -104,1 +104,5 @@ return reply | ||
exports.handle500 = handle500; | ||
const handleInvalidAddress = (reply) => { | ||
return (0, exports.handle400Custom)(reply, 'Invalid address for this network or malformed address format.'); | ||
}; | ||
exports.handleInvalidAddress = handleInvalidAddress; |
@@ -0,4 +1,10 @@ | ||
declare type BlockfrostNetwork = 'mainnet' | 'testnet' | 'preview' | 'preprod'; | ||
export declare const validateAndConvertPool: (input: string) => string | undefined; | ||
export declare const paymentCredFromBech32Address: (input: string) => string | undefined; | ||
export declare const paymentCredToBech32Address: (input: string) => string | undefined; | ||
export declare const detectAndValidateAddressType: (input: string, network: BlockfrostNetwork) => 'byron' | 'shelley' | undefined; | ||
export declare const getAddressTypeAndPaymentCred: (address: string, network: BlockfrostNetwork) => { | ||
addressType: "byron" | "shelley" | undefined; | ||
paymentCred: string; | ||
}; | ||
export declare const scriptHashFromBech32Address: (input: string) => string | undefined; | ||
@@ -11,1 +17,2 @@ export declare const validatePositiveInRangeSignedInt: (possiblePositiveInt: string | number | undefined) => boolean; | ||
export declare const isNumber: (value: string | number | undefined) => boolean; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isNumber = exports.validateBlockHash = exports.validateDerivationXpub = exports.validateInRangeUnsignedInt = exports.validatePositiveInRangeSignedBigInt = exports.validatePositiveInRangeSignedInt = exports.scriptHashFromBech32Address = 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 = void 0; | ||
const cardano_serialization_lib_nodejs_1 = require("@emurgo/cardano-serialization-lib-nodejs"); | ||
const bech32_1 = require("bech32"); | ||
@@ -78,2 +79,44 @@ // prefixes based on CIP5 https://github.com/cardano-foundation/CIPs/blob/master/CIP-0005/CIP-0005.md | ||
exports.paymentCredToBech32Address = paymentCredToBech32Address; | ||
const detectAndValidateAddressType = (input, network) => { | ||
// differentiate between various address era formats (byron, shelley) | ||
try { | ||
if (cardano_serialization_lib_nodejs_1.ByronAddress.is_valid(input)) { | ||
// valid byron | ||
return 'byron'; | ||
} | ||
else { | ||
// check if it's not shelley (also check network mismatch i.e. mainnet/testnet) | ||
const bech32Info = bech32_1.bech32.decode(input, 1000); | ||
if ((bech32Info.prefix === Prefixes.ADDR && network === 'mainnet') || | ||
(bech32Info.prefix === Prefixes.ADDR_TEST && network !== 'mainnet')) { | ||
// valid shelley - addr1 for mainnet or addr_test1 for testnet | ||
return 'shelley'; | ||
} | ||
else if (bech32Info.prefix === Prefixes.PAYMENT_KEY_HASH) { | ||
// valid shelley - payment_cred | ||
return 'shelley'; | ||
} | ||
else { | ||
return undefined; | ||
} | ||
} | ||
} | ||
catch { | ||
return undefined; | ||
} | ||
}; | ||
exports.detectAndValidateAddressType = detectAndValidateAddressType; | ||
const getAddressTypeAndPaymentCred = (address, network) => { | ||
var _a; | ||
// check for address validity (undefined) and type (byron, shelley) | ||
const addressType = (0, exports.detectAndValidateAddressType)(address, network); | ||
// if shelley, check for paymentCred and compute paymentCred hex | ||
// if an error occurs or paymentCred can't be computed, '' is returned | ||
// querying '' in SQL is faster than null for payment_cred, so let's replace undefined by '' | ||
const paymentCred = addressType === 'shelley' | ||
? (_a = (0, exports.paymentCredFromBech32Address)(address)) !== null && _a !== void 0 ? _a : '' | ||
: ''; | ||
return { addressType, paymentCred }; | ||
}; | ||
exports.getAddressTypeAndPaymentCred = getAddressTypeAndPaymentCred; | ||
// Decode bech32 script address, drop its first byte (header) | ||
@@ -80,0 +123,0 @@ // and return the rest of the bytes, hex encoded. |
{ | ||
"name": "@blockfrost/blockfrost-utils", | ||
"version": "1.0.0-alfa.1", | ||
"version": "1.0.0-alfa.2", | ||
"repository": "git@github.com:blockfrost/blockfrost-utils.git", | ||
@@ -23,2 +23,3 @@ "license": "Apache-2.0", | ||
"@blockfrost/openapi": "^0.1.41", | ||
"@emurgo/cardano-serialization-lib-nodejs": "^11.0.5", | ||
"bech32": "^2.0.0", | ||
@@ -25,0 +26,0 @@ "yaml": "^2.1.1" |
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
42122
714
4
+ Added@blockfrost/openapi@0.1.69(transitive)
+ Added@emurgo/cardano-serialization-lib-nodejs@11.5.0(transitive)
- Removed@blockfrost/openapi@0.1.70(transitive)