Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cardano-sdk/blockfrost

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cardano-sdk/blockfrost - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

4

package.json
{
"name": "@cardano-sdk/blockfrost",
"version": "0.1.3",
"version": "0.1.4",
"description": "Blockfrost provider for Cardano JS SDK",

@@ -27,4 +27,4 @@ "engines": {

"@cardano-ogmios/schema": "4.1.0",
"@cardano-sdk/core": "0.1.3"
"@cardano-sdk/core": "0.1.4"
}
}

@@ -1,6 +0,50 @@

import { CardanoProvider } from '@cardano-sdk/core';
import { BlockFrostAPI } from '@blockfrost/blockfrost-js';
/* eslint-disable @typescript-eslint/no-explicit-any */
import { CardanoProvider, ProviderError, ProviderFailure } from '@cardano-sdk/core';
import { BlockFrostAPI, Error as BlockfrostError } from '@blockfrost/blockfrost-js';
import { Options } from '@blockfrost/blockfrost-js/lib/types';
import { BlockfrostToOgmios } from './BlockfrostToOgmios';
const formatBlockfrostError = (error: unknown) => {
const blockfrostError = error as BlockfrostError;
if (typeof blockfrostError === 'string') {
throw new ProviderError(ProviderFailure.Unknown, error, blockfrostError);
}
if (typeof blockfrostError !== 'object') {
throw new ProviderError(ProviderFailure.Unknown, error, 'failed to parse error (response type)');
}
const errorAsType1 = blockfrostError as {
status_code: number;
message: string;
error: string;
};
if (errorAsType1.status_code) {
return errorAsType1;
}
const errorAsType2 = blockfrostError as {
errno: number;
message: string;
code: string;
};
if (errorAsType2.code) {
const status_code = Number.parseInt(errorAsType2.code);
if (!status_code) {
throw new ProviderError(ProviderFailure.Unknown, error, 'failed to parse error (status code)');
}
return {
status_code,
message: errorAsType1.message,
error: errorAsType2.errno.toString()
};
}
throw new ProviderError(ProviderFailure.Unknown, error, 'failed to parse error (response json)');
};
const toProviderError = (error: unknown) => {
const { status_code } = formatBlockfrostError(error);
if (status_code === 404) {
throw new ProviderError(ProviderFailure.NotFound);
}
throw new ProviderError(ProviderFailure.Unknown, error, `status_code: ${status_code}`);
};
/**

@@ -12,3 +56,2 @@ * Connect to the [Blockfrost service](https://docs.blockfrost.io/)

*/
export const blockfrostProvider = (options: Options): CardanoProvider => {

@@ -66,9 +109,3 @@ const blockfrost = new BlockFrostAPI(options);

const submitTx: CardanoProvider['submitTx'] = async (signedTransaction) => {
try {
const hash = await blockfrost.txSubmit(signedTransaction.to_bytes());
return !!hash;
} catch {
return false;
}
await blockfrost.txSubmit(signedTransaction.to_bytes());
};

@@ -121,3 +158,3 @@

return {
const providerFunctions = {
ledgerTip,

@@ -131,3 +168,8 @@ networkInfo,

currentWalletProtocolParameters
};
} as any;
return Object.keys(providerFunctions).reduce((provider, key) => {
provider[key] = (...args: any[]) => providerFunctions[key](...args).catch(toProviderError);
return provider;
}, {} as any) as CardanoProvider;
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc