How to use the borc.decode function in borc

To help you get started, we’ve selected a few borc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vacuumlabs / cardano-crypto.js / index.js View on Github external
function unpackAddress(address, hdPassphrase) {
  // we decode the address from the base58 string
  // and then we strip the 24 CBOR data tags (the "[0].value" part)
  const addressAsBuffer = cbor.decode(base58.decode(address))[0].value
  const addressData = cbor.decode(addressAsBuffer)
  const attributes = addressData[1]
  const payload = cbor.decode(attributes.get(1))
  let derivationPath

  try {
    derivationPath = decryptDerivationPath(payload, hdPassphrase)
  } catch (e) {
    throw new Error('Unable to get derivation path from address')
  }

  if (derivationPath && derivationPath.length > 2) {
    throw Error('Invalid derivation path length, should be at most 2')
  }

  return {
    derivationPath,
  }
}
github vacuumlabs / cardano-crypto.js / index.js View on Github external
function isValidAddress(address) {
  try {
    // we decode the address from the base58 string
    const addressAsArray = cbor.decode(base58.decode(address))
    // we strip the 24 CBOR data taga by taking the "value" attribute from the "Tagged" object
    const addressDataEncoded = addressAsArray[0].value
    const crc32Checksum = addressAsArray[1]
    
    if (crc32Checksum !== crc32(addressDataEncoded)) {
      return false
    }
    
  } catch (e) {
    return false
  }
  return true
}
github vacuumlabs / cardano-crypto.js / index.js View on Github external
function unpackAddress(address, hdPassphrase) {
  // we decode the address from the base58 string
  // and then we strip the 24 CBOR data tags (the "[0].value" part)
  const addressAsBuffer = cbor.decode(base58.decode(address))[0].value
  const addressData = cbor.decode(addressAsBuffer)
  const attributes = addressData[1]
  const payload = cbor.decode(attributes.get(1))
  let derivationPath

  try {
    derivationPath = decryptDerivationPath(payload, hdPassphrase)
  } catch (e) {
    throw new Error('Unable to get derivation path from address')
  }

  if (derivationPath && derivationPath.length > 2) {
    throw Error('Invalid derivation path length, should be at most 2')
  }

  return {
    derivationPath,
github vacuumlabs / cardano-crypto.js / index.js View on Github external
function unpackAddress(address, hdPassphrase) {
  // we decode the address from the base58 string
  // and then we strip the 24 CBOR data tags (the "[0].value" part)
  const addressAsBuffer = cbor.decode(base58.decode(address))[0].value
  const addressData = cbor.decode(addressAsBuffer)
  const attributes = addressData[1]
  const payload = cbor.decode(attributes.get(1))
  let derivationPath

  try {
    derivationPath = decryptDerivationPath(payload, hdPassphrase)
  } catch (e) {
    throw new Error('Unable to get derivation path from address')
  }

  if (derivationPath && derivationPath.length > 2) {
    throw Error('Invalid derivation path length, should be at most 2')
  }

  return {
github vacuumlabs / adalite / app / frontend / wallet / helpers / cbor-parsers.ts View on Github external
const parseTxInput = (val) => {
  const type = val[0]
  const inputAttributes = decode(val[1].value)
  const txHash = parseTxHash(inputAttributes[0])
  const outputIndex = inputAttributes[1]

  const utxo = {
    type,
    txHash,
    outputIndex,
  }
  return TxInputFromUtxo(utxo)
}
github vacuumlabs / adalite / app / frontend / wallet / helpers / cbor-parsers.ts View on Github external
const parseTxWitness = (val) => {
  const witnessAttributes = decode(val[1].value)
  const extendedPubicKey = witnessAttributes[0]
  const signature = witnessAttributes[1]

  return TxWitness(extendedPubicKey, signature)
}
/*
github vacuumlabs / adalite / app / frontend / wallet / keypass-json.ts View on Github external
if (walletExportObj.fileType !== 'WALLETS_EXPORT') {
    throw Error('Invalid file type')
  }

  const {passwordHash: b64PasswordHash, walletSecretKey: b64WalletSecret} = walletExportObj.wallet
  const passwordHash = Buffer.from(b64PasswordHash, 'base64')
  const derivationScheme = Object.values(derivationSchemes).find(
    (x) => x.keyfileVersion === walletExportObj.fileVersion
  )

  if (derivationScheme === undefined) {
    throw Error(`Invalid file version: ${walletExportObj.fileVersion}`)
  }

  const walletSecretDef = {
    rootSecret: decode(Buffer.from(b64WalletSecret, 'base64')),
    derivationScheme,
  }

  return {
    passwordHash,
    walletSecretDef,
  }
}
github vacuumlabs / cardano-crypto.js / index.js View on Github external
function decryptDerivationPath(addressPayload, hdPassphrase) {
  const decipheredDerivationPath = chacha20poly1305Decrypt(
    addressPayload,
    hdPassphrase,
    Buffer.from('serokellfore')
  )

  try {
    return cbor.decode(Buffer.from(decipheredDerivationPath))
  } catch (err) {
    throw new Error('incorrect address or passphrase')
  }
}

borc

Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC7049).

MIT
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis