How to use the @grpc/grpc-js.credentials.createFromMetadataGenerator function in @grpc/grpc-js

To help you get started, we’ve selected a few @grpc/grpc-js 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 LN-Zap / zap-desktop / lnd / util.js View on Github external
// If the macaroon is already in hex format, add as is.
    const isHex = /^[0-9a-fA-F]+$/.test(macaroonPath)
    if (isHex) {
      metadata.add('macaroon', macaroonPath)
    }
    // Otherwise, treat it as a file path - load the file and convert to hex.
    else {
      const macaroon = await readFile(macaroonPath).catch(e => {
        const error = new Error(`Macaroon path could not be accessed: ${e.message}`)
        error.code = 'LND_GRPC_MACAROON_ERROR'
        throw error
      })
      metadata.add('macaroon', macaroon.toString('hex'))
    }
  }
  return credentials.createFromMetadataGenerator((params, callback) => callback(null, metadata))
}
github LN-Zap / node-lnd-grpc / src / utils / createMacaroonCreds.js View on Github external
// If it's not a filepath, then assume it is a base64url encoded string.
    else if (macaroonPath === basename(macaroonPath)) {
      lndMacaroon = decodeMacaroon(macaroonPath)
    }
    // Otherwise, treat it as a file path - load the file and convert to hex.
    else {
      const macaroon = await readFile(untildify(macaroonPath)).catch(e => {
        const error = new Error(`Macaroon path could not be accessed: ${e.message}`)
        error.code = 'LND_GRPC_MACAROON_ERROR'
        throw error
      })
      lndMacaroon = macaroon.toString('hex')
    }
    metadata.add('macaroon', lndMacaroon)
  }
  return credentials.createFromMetadataGenerator((params, callback) => callback(null, metadata))
}