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

@blockfrost/blockfrost-utils

Package Overview
Dependencies
Maintainers
3
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blockfrost/blockfrost-utils - npm Package Compare versions

Comparing version 2.3.1 to 2.4.1-beta.0

3

lib/cardano.js

@@ -17,3 +17,4 @@ "use strict";

const paymentCredHexWithBytesPrefix = (0, validation_1.paymentCredFromBech32Address)(paymentCred);
const paymentCredHex = paymentCredHexWithBytesPrefix === null || paymentCredHexWithBytesPrefix === void 0 ? void 0 : paymentCredHexWithBytesPrefix.slice(2);
// slice off \\x prefix
const paymentCredHex = paymentCredHexWithBytesPrefix === null || paymentCredHexWithBytesPrefix === void 0 ? void 0 : paymentCredHexWithBytesPrefix.paymentCred.slice(2);
if (!paymentCredHex)

@@ -20,0 +21,0 @@ return null;

declare type BlockfrostNetwork = 'mainnet' | 'testnet' | 'preview' | 'preprod';
declare type SUPPORTED_PAYMENT_CRED_PREFIX = 'addr_vkh' | 'addr_vk' | 'script';
export declare const validateHex: (input: string) => boolean;

@@ -6,8 +7,14 @@ export declare const validateStakeAddress: (input: string, network: BlockfrostNetwork) => boolean;

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 paymentCredFromBech32Address: (input: string) => {
paymentCred: string;
prefix: SUPPORTED_PAYMENT_CRED_PREFIX;
} | undefined;
export declare const paymentCredToBech32Address: (input: string, prefix: SUPPORTED_PAYMENT_CRED_PREFIX) => 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 | undefined;
paymentCred: {
paymentCred: string;
prefix: SUPPORTED_PAYMENT_CRED_PREFIX;
} | undefined;
};

@@ -14,0 +21,0 @@ export declare const scriptHashFromBech32Address: (input: string) => string | undefined;

@@ -15,2 +15,3 @@ "use strict";

POOL: 'pool',
SCRIPT: 'script',
});

@@ -88,3 +89,3 @@ const MAX_UNSIGNED_INT = 2147483648;

const paymentCred = `\\x${Buffer.from(payload).toString('hex')}`;
return paymentCred;
return { paymentCred, prefix: bech32Info.prefix };
}

@@ -97,4 +98,10 @@ else if (bech32Info.prefix === Prefixes.PAYMENT_KEY) {

pubKey.free();
return paymentKeyHash;
return { paymentCred: paymentKeyHash, prefix: bech32Info.prefix };
}
else if (bech32Info.prefix === Prefixes.SCRIPT) {
const payload = bech32_1.bech32.fromWords(bech32Info.words);
const payloadHex = Buffer.from(payload).toString('hex');
const paymentCred = `\\x${payloadHex}`;
return { paymentCred, prefix: bech32Info.prefix };
}
else {

@@ -111,3 +118,3 @@ return undefined;

exports.paymentCredFromBech32Address = paymentCredFromBech32Address;
const paymentCredToBech32Address = (input) => {
const paymentCredToBech32Address = (input, prefix) => {
// compute paymentCred

@@ -119,3 +126,16 @@ try {

// if it's in hex, we'll convert it to Bech32
return bech32_1.bech32.encode(Prefixes.PAYMENT_KEY_HASH, words);
// TODO: we need to differentiate if the payment cred was extracted from
// addr_vkh, addr_vk or script
switch (prefix) {
case Prefixes.PAYMENT_KEY_HASH:
case Prefixes.SCRIPT:
return bech32_1.bech32.encode(prefix, words);
case Prefixes.PAYMENT_KEY:
// TODO
// payment key was already converted to key hash, so we cannot restore the original key
// we could supply orig via a parameter and then compare its hash to the input
return bech32_1.bech32.encode(Prefixes.PAYMENT_KEY_HASH, words);
default:
throw Error(`Prefix ${prefix} is not supported by paymentCredToBech32Address`);
}
}

@@ -122,0 +142,0 @@ catch {

{
"name": "@blockfrost/blockfrost-utils",
"version": "2.3.1",
"version": "2.4.1-beta.0",
"repository": "git@github.com:blockfrost/blockfrost-utils.git",

@@ -30,3 +30,2 @@ "license": "Apache-2.0",

"@types/node": "^16",
"@types/utf-8-validate": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^5.30.0",

@@ -33,0 +32,0 @@ "@typescript-eslint/parser": "5.27.0",

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