@blockfrost/blockfrost-utils
Advanced tools
Comparing version 2.2.0 to 2.3.0-beta.0
export declare const getTimeFromSlot: (slotNumber: number) => number; | ||
export declare const getPaymentPartBech32: (paymentCred: string, options: { | ||
includeBech32Checksum: boolean; | ||
addressType: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; | ||
network: 'mainnet' | 'testnets'; | ||
}) => string | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTimeFromSlot = void 0; | ||
exports.getPaymentPartBech32 = exports.getTimeFromSlot = void 0; | ||
const bech32_1 = require("bech32"); | ||
const validation_1 = require("./validation"); | ||
const getTimeFromSlot = (slotNumber) => { | ||
@@ -8,1 +10,24 @@ return 1596491091 + (slotNumber - 4924800); | ||
exports.getTimeFromSlot = getTimeFromSlot; | ||
const getPaymentPartBech32 = ( | ||
// Payment credentials in bech32 format (addr_vkh) | ||
paymentCred, options) => { | ||
// Constructs invalid bech32 address consisting only from an address header and a payment part. | ||
// Useful for matching payment credentials against bech32 address | ||
const NETWORK_TAG = options.network === 'mainnet' ? 1 : 0; | ||
const paymentCredHexWithBytesPrefix = (0, validation_1.paymentCredFromBech32Address)(paymentCred); | ||
const paymentCredHex = paymentCredHexWithBytesPrefix === null || paymentCredHexWithBytesPrefix === void 0 ? void 0 : paymentCredHexWithBytesPrefix.slice(2); | ||
if (!paymentCredHex) | ||
return null; | ||
const addrHeader = `${options.addressType.toString(16)}${NETWORK_TAG}`; | ||
const addrWords = bech32_1.bech32.toWords(Buffer.from(`${addrHeader}${paymentCredHex}`, 'hex')); | ||
const bech32PaymentCredAddr = bech32_1.bech32.encode('', addrWords, 1000); | ||
let result = bech32PaymentCredAddr; | ||
if (!options.includeBech32Checksum) { | ||
// Strip last 7 chars of checksum. | ||
// This assumes that payment part of the address has constant length, | ||
// otherwise the length of the checksum may vary. | ||
result = bech32PaymentCredAddr.slice(0, bech32PaymentCredAddr.length - 7); | ||
} | ||
return result; | ||
}; | ||
exports.getPaymentPartBech32 = getPaymentPartBech32; |
@@ -13,2 +13,3 @@ "use strict"; | ||
PAYMENT_KEY_HASH: 'addr_vkh', | ||
PAYMENT_KEY: 'addr_vk', | ||
POOL: 'pool', | ||
@@ -89,2 +90,10 @@ }); | ||
} | ||
else if (bech32Info.prefix === Prefixes.PAYMENT_KEY) { | ||
// valid payment_cred | ||
const payload = bech32_1.bech32.fromWords(bech32Info.words); | ||
const pubKey = cardano_serialization_lib_nodejs_1.PublicKey.from_hex(Buffer.from(payload).toString('hex')); | ||
const paymentKeyHash = `\\x${pubKey.hash().to_hex()}`; | ||
pubKey.free(); | ||
return paymentKeyHash; | ||
} | ||
else { | ||
@@ -94,3 +103,5 @@ return undefined; | ||
} | ||
catch { | ||
catch (error) { | ||
// Uncomment for awesome debug hack! | ||
// console.error(error); | ||
return undefined; | ||
@@ -97,0 +108,0 @@ } |
{ | ||
"name": "@blockfrost/blockfrost-utils", | ||
"version": "2.2.0", | ||
"version": "2.3.0-beta.0", | ||
"repository": "git@github.com:blockfrost/blockfrost-utils.git", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
56420
962
2