@blockfrost/blockfrost-js
Advanced tools
Comparing version 4.2.0-beta to 4.2.0-beta.1
import { Got } from 'got'; | ||
import Bottleneck from 'bottleneck'; | ||
import { accounts, accountsDelegations, accountsDelegationsAll, accountsRegistrations, accountsRegistrationsAll, accountsRewards, accountsRewardsAll, accountsHistory, accountsHistoryAll, accountsWithdrawals, accountsWithdrawalsAll, accountsMirs, accountsMirsAll, accountsAddresses, accountsAddressesAll, accountsAddressesAssets, accountsAddressesTotal, accountsAddressesAssetsAll } from './endpoints/api/accounts'; | ||
import { addresses, addressesTotal, addressesExtended, addressesTransactions, addressesTransactionsAll, addressesUtxos, addressesUtxosAll } from './endpoints/api/addresses'; | ||
import { addresses, addressesTotal, addressesExtended, addressesTransactions, addressesTransactionsAll, addressesUtxos, addressesUtxosAll, addressesUtxosAsset, addressesUtxosAssetAll } from './endpoints/api/addresses'; | ||
import { assets, assetsById, assetsHistory, assetsHistoryAll, assetsTransactions, assetsAddresses, assetsPolicyById, assetsPolicyByIdAll } from './endpoints/api/assets'; | ||
@@ -291,2 +291,19 @@ import { blocks, blocksLatest, blocksLatestTxs, blocksLatestTxsAll, blocksNext, blocksPrevious, blocksTxs, blocksTxsAll, blocksAddresses, blocksAddressesAll } from './endpoints/api/blocks'; | ||
/** | ||
* addressesUtxosAsset - List of the address's utxos containing a given asset (paginated) | ||
* | ||
* @param address | ||
* @param asset - Concatenation of the policy_id and hex-encoded asset_name | ||
* @returns List of the address's utxos containing a given asset | ||
* | ||
*/ | ||
addressesUtxosAsset: typeof addressesUtxosAsset; | ||
/** | ||
* addressesUtxosAssetAll - List of the address's utxos containing a given asset | ||
* @param address | ||
* @param asset - Concatenation of the policy_id and hex-encoded asset_name | ||
* @returns List of the address's utxos containing a given asset | ||
* | ||
*/ | ||
addressesUtxosAssetAll: typeof addressesUtxosAssetAll; | ||
/** | ||
* addressesUtxos | ||
@@ -293,0 +310,0 @@ * |
@@ -292,2 +292,19 @@ "use strict"; | ||
/** | ||
* addressesUtxosAsset - List of the address's utxos containing a given asset (paginated) | ||
* | ||
* @param address | ||
* @param asset - Concatenation of the policy_id and hex-encoded asset_name | ||
* @returns List of the address's utxos containing a given asset | ||
* | ||
*/ | ||
this.addressesUtxosAsset = addresses_1.addressesUtxosAsset; | ||
/** | ||
* addressesUtxosAssetAll - List of the address's utxos containing a given asset | ||
* @param address | ||
* @param asset - Concatenation of the policy_id and hex-encoded asset_name | ||
* @returns List of the address's utxos containing a given asset | ||
* | ||
*/ | ||
this.addressesUtxosAssetAll = addresses_1.addressesUtxosAssetAll; | ||
/** | ||
* addressesUtxos | ||
@@ -294,0 +311,0 @@ * |
@@ -11,1 +11,3 @@ import { components } from '../../../types/OpenApi'; | ||
export declare function addressesUtxosAll(this: BlockFrostAPI, address: string, allMethodOptions?: AllMethodOptions): Promise<components['schemas']['address_utxo_content']>; | ||
export declare function addressesUtxosAsset(this: BlockFrostAPI, address: string, asset: string, pagination?: PaginationOptions): Promise<components['schemas']['address_utxo_content']>; | ||
export declare function addressesUtxosAssetAll(this: BlockFrostAPI, address: string, asset: string, allMethodOptions?: AllMethodOptions): Promise<components['schemas']['address_utxo_content']>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addressesUtxosAll = exports.addressesUtxos = exports.addressesTransactionsAll = exports.addressesTransactions = exports.addressesExtended = exports.addressesTotal = exports.addresses = void 0; | ||
exports.addressesUtxosAssetAll = exports.addressesUtxosAsset = exports.addressesUtxosAll = exports.addressesUtxos = exports.addressesTransactionsAll = exports.addressesTransactions = exports.addressesExtended = exports.addressesTotal = exports.addresses = void 0; | ||
const utils_1 = require("../../../utils"); | ||
@@ -86,1 +86,23 @@ const errors_1 = require("../../../utils/errors"); | ||
exports.addressesUtxosAll = addressesUtxosAll; | ||
async function addressesUtxosAsset(address, asset, pagination) { | ||
// TODO: test is missing since we can't guarantee that list of address's utxos won't change in the future | ||
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination); | ||
return new Promise((resolve, reject) => { | ||
this.instance(`addresses/${address}/utxos/${asset}`, { | ||
searchParams: { | ||
page: paginationOptions.page, | ||
count: paginationOptions.count, | ||
order: paginationOptions.order, | ||
}, | ||
}) | ||
.then(resp => { | ||
resolve(resp.body); | ||
}) | ||
.catch(err => reject((0, errors_1.handleError)(err))); | ||
}); | ||
} | ||
exports.addressesUtxosAsset = addressesUtxosAsset; | ||
async function addressesUtxosAssetAll(address, asset, allMethodOptions) { | ||
return (0, utils_1.paginateMethod)(pagination => this.addressesUtxosAsset(address, asset, pagination), allMethodOptions); | ||
} | ||
exports.addressesUtxosAssetAll = addressesUtxosAssetAll; |
import { components } from './types/OpenApi'; | ||
import { BlockFrostAPI } from './BlockFrostAPI'; | ||
import { BlockFrostIPFS } from './BlockFrostIPFS'; | ||
import { deriveAddress, getFingerprint, parseAsset } from './utils/helpers'; | ||
import { BlockfrostClientError, BlockfrostServerError } from './utils/errors'; | ||
import { deriveAddress, getFingerprint, parseAsset, verifyWebhookSignature } from './utils/helpers'; | ||
import { BlockfrostClientError, BlockfrostServerError, SignatureVerificationError } from './utils/errors'; | ||
declare type Responses = components['schemas']; | ||
export { BlockFrostAPI, BlockFrostIPFS, BlockfrostClientError, BlockfrostServerError, parseAsset, getFingerprint, deriveAddress, }; | ||
export { BlockFrostAPI, BlockFrostIPFS, BlockfrostClientError, BlockfrostServerError, SignatureVerificationError, parseAsset, getFingerprint, deriveAddress, verifyWebhookSignature, }; | ||
export type { Responses }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deriveAddress = exports.getFingerprint = exports.parseAsset = exports.BlockfrostServerError = exports.BlockfrostClientError = exports.BlockFrostIPFS = exports.BlockFrostAPI = void 0; | ||
exports.verifyWebhookSignature = exports.deriveAddress = exports.getFingerprint = exports.parseAsset = exports.SignatureVerificationError = exports.BlockfrostServerError = exports.BlockfrostClientError = exports.BlockFrostIPFS = exports.BlockFrostAPI = void 0; | ||
const BlockFrostAPI_1 = require("./BlockFrostAPI"); | ||
@@ -12,4 +12,6 @@ Object.defineProperty(exports, "BlockFrostAPI", { enumerable: true, get: function () { return BlockFrostAPI_1.BlockFrostAPI; } }); | ||
Object.defineProperty(exports, "parseAsset", { enumerable: true, get: function () { return helpers_1.parseAsset; } }); | ||
Object.defineProperty(exports, "verifyWebhookSignature", { enumerable: true, get: function () { return helpers_1.verifyWebhookSignature; } }); | ||
const errors_1 = require("./utils/errors"); | ||
Object.defineProperty(exports, "BlockfrostClientError", { enumerable: true, get: function () { return errors_1.BlockfrostClientError; } }); | ||
Object.defineProperty(exports, "BlockfrostServerError", { enumerable: true, get: function () { return errors_1.BlockfrostServerError; } }); | ||
Object.defineProperty(exports, "SignatureVerificationError", { enumerable: true, get: function () { return errors_1.SignatureVerificationError; } }); |
import { GotError, ErrorType } from '../types'; | ||
export declare class SignatureVerificationError extends Error { | ||
detail: { | ||
webhookPayload: unknown; | ||
signatureHeader: string; | ||
} | undefined; | ||
constructor(message: string, detail?: { | ||
signatureHeader: string; | ||
webhookPayload: unknown; | ||
}); | ||
} | ||
export declare class BlockfrostServerError extends Error { | ||
@@ -3,0 +13,0 @@ status_code: number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handleError = exports.isBlockfrostErrorResponse = exports.BlockfrostClientError = exports.BlockfrostServerError = void 0; | ||
exports.handleError = exports.isBlockfrostErrorResponse = exports.BlockfrostClientError = exports.BlockfrostServerError = exports.SignatureVerificationError = void 0; | ||
const got_1 = require("got"); | ||
class SignatureVerificationError extends Error { | ||
constructor(message, detail) { | ||
super(message); | ||
this.name = 'SignatureVerificationError'; | ||
this.message = message; | ||
this.detail = detail; | ||
Object.setPrototypeOf(this, SignatureVerificationError.prototype); | ||
} | ||
} | ||
exports.SignatureVerificationError = SignatureVerificationError; | ||
class BlockfrostServerError extends Error { | ||
@@ -6,0 +16,0 @@ constructor(error) { |
@@ -15,1 +15,11 @@ import { ParseAssetResult } from '../types/utils'; | ||
export declare const parseAsset: (hex: string) => ParseAssetResult; | ||
/** | ||
* Verifies webhook signature | ||
* | ||
* @param {string|Buffer} webhookPayload Buffer or stringified payload of the webhook request. | ||
* @param {string|Buffer} signatureHeader Blockfrost-Signature header. | ||
* @param {string} secret Auth token for the webhook. | ||
* @param {number} [timestampToleranceSeconds=600] Time tolerance affecting signature validity. By default signatures older than 600s are considered invalid. | ||
* @returns {boolean} Whether the signature is valid. | ||
* */ | ||
export declare const verifyWebhookSignature: (webhookPayload: unknown, signatureHeader: string, secret: string, timestampToleranceSeconds?: number) => boolean; |
@@ -6,5 +6,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseAsset = exports.getFingerprint = exports.hexToString = exports.deriveAddress = void 0; | ||
exports.verifyWebhookSignature = exports.parseAsset = exports.getFingerprint = exports.hexToString = exports.deriveAddress = void 0; | ||
const crypto_1 = require("crypto"); | ||
const cardano_serialization_lib_nodejs_1 = require("@emurgo/cardano-serialization-lib-nodejs"); | ||
const cip14_js_1 = __importDefault(require("@emurgo/cip14-js")); | ||
const errors_1 = require("./errors"); | ||
const index_1 = require("./index"); | ||
/** | ||
@@ -75,1 +78,66 @@ * Derives an address with derivation path m/1852'/1815'/account'/role/addressIndex | ||
exports.parseAsset = parseAsset; | ||
/** | ||
* Verifies webhook signature | ||
* | ||
* @param {string|Buffer} webhookPayload Buffer or stringified payload of the webhook request. | ||
* @param {string|Buffer} signatureHeader Blockfrost-Signature header. | ||
* @param {string} secret Auth token for the webhook. | ||
* @param {number} [timestampToleranceSeconds=600] Time tolerance affecting signature validity. By default signatures older than 600s are considered invalid. | ||
* @returns {boolean} Whether the signature is valid. | ||
* */ | ||
const verifyWebhookSignature = (webhookPayload, signatureHeader, secret, timestampToleranceSeconds = 600) => { | ||
let timestamp; | ||
let signature; | ||
if (Array.isArray(signatureHeader)) { | ||
throw new errors_1.SignatureVerificationError('Unexpected: An array was passed as a header'); | ||
} | ||
const decodedWebhookPayload = Buffer.isBuffer(webhookPayload) | ||
? webhookPayload.toString('utf8') | ||
: webhookPayload; | ||
const decodedSignatureHeader = Buffer.isBuffer(signatureHeader) | ||
? signatureHeader.toString('utf8') | ||
: signatureHeader; | ||
// Parse signature header (example: t=1648550558,v1=162381a59040c97d9b323cdfec02facdfce0968490ec1732f5d938334c1eed4e) | ||
const tokens = decodedSignatureHeader.split(','); | ||
for (const token of tokens) { | ||
const [key, value] = token.split('='); | ||
switch (key) { | ||
case 't': | ||
timestamp = Number(value); | ||
break; | ||
case 'v1': | ||
signature = value; | ||
break; | ||
default: | ||
console.warn(`Cannot parse part of the signature header, key "${key}" is not supported by this version of Blockfrost SDK.`); | ||
} | ||
} | ||
if (!timestamp || !signature) { | ||
throw new errors_1.SignatureVerificationError('Invalid signature header format', { | ||
signatureHeader: decodedSignatureHeader, | ||
webhookPayload: decodedWebhookPayload, | ||
}); | ||
} | ||
// Recreate signature by concatenating timestamp with stringified payload, | ||
// then compute HMAC using sha256 and provided secret (auth token) | ||
const signaturePayload = `${timestamp}.${decodedWebhookPayload}`; | ||
const hmac = (0, crypto_1.createHmac)('sha256', secret) | ||
.update(signaturePayload) | ||
.digest('hex'); | ||
if (hmac !== signature) { | ||
return false; | ||
} | ||
// computed hmac should match signature parsed from a signature header | ||
const currentTimestamp = Math.floor(new Date().getTime() / 1000); | ||
if (currentTimestamp - timestamp > timestampToleranceSeconds) { | ||
if ((0, index_1.isDebugEnabled)()) { | ||
console.info(`Invalid signature. Blockfrost signature timestamp is out of range!`); | ||
} | ||
return false; | ||
} | ||
else { | ||
// Successfully validate the signature only if it is within tolerance | ||
return true; | ||
} | ||
}; | ||
exports.verifyWebhookSignature = verifyWebhookSignature; |
import { Options, ValidatedOptions, PaginationOptions, AdditionalEndpointOptions, AllMethodOptions } from '../types'; | ||
export declare const isDebugEnabled: () => boolean; | ||
export declare const validateOptions: (options?: Options | undefined) => ValidatedOptions; | ||
@@ -3,0 +4,0 @@ export declare const getAdditionalParams: (options?: AdditionalEndpointOptions | undefined) => AdditionalEndpointOptions; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.paginateMethod = exports.getAllMethodOptions = exports.getPaginationOptions = exports.getAdditionalParams = exports.validateOptions = void 0; | ||
exports.paginateMethod = exports.getAllMethodOptions = exports.getPaginationOptions = exports.getAdditionalParams = exports.validateOptions = exports.isDebugEnabled = void 0; | ||
const config_1 = require("../config"); | ||
const limiter_1 = require("./limiter"); | ||
const isDebugEnabled = () => process.env.BLOCKFROST_DEBUG === 'true'; | ||
exports.isDebugEnabled = isDebugEnabled; | ||
const validateOptions = (options) => { | ||
@@ -20,3 +22,3 @@ var _a, _b, _c, _d, _e; | ||
} | ||
const debug = (_a = options.debug) !== null && _a !== void 0 ? _a : process.env.BLOCKFROST_DEBUG === 'true'; | ||
const debug = (_a = options.debug) !== null && _a !== void 0 ? _a : (0, exports.isDebugEnabled)(); | ||
let rateLimiter; | ||
@@ -23,0 +25,0 @@ if (options.rateLimiter === false) { |
{ | ||
"name": "@blockfrost/blockfrost-js", | ||
"version": "4.2.0-beta", | ||
"version": "4.2.0-beta.1", | ||
"description": "A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
318905
7887
63