Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const createMacaroonCreds = async macaroonPath => {
const metadata = new Metadata()
if (macaroonPath) {
// 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'))
}
const createMacaroonCreds = async macaroonPath => {
const metadata = new Metadata()
let lndMacaroon
if (macaroonPath) {
// If the macaroon is already in hex format, add as is.
const isHex = /^[0-9a-fA-F]+$/.test(macaroonPath)
if (isHex) {
lndMacaroon = macaroonPath
}
// 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}`)
cancel(): void {
const status = {
code: 1,
details: 'Canceled.',
metadata: new Metadata(),
};
process.nextTick(() => {
this.emit('status', status);
this.end();
});
}
destroy(err?: Error): void {
it('works with deadlines', () => {
const barrier = new Barrier();
const metadata = new Grpc.Metadata();
const {
path,
requestSerialize: serialize,
responseDeserialize: deserialize
} = client.unary;
metadata.set('grpc-timeout', '100m');
client.makeUnaryRequest(path, serialize, deserialize, {}, metadata, {}, (error, response) => {
Assert.strictEqual(error.code, Grpc.status.DEADLINE_EXCEEDED);
Assert.strictEqual(error.details, 'Deadline exceeded');
barrier.pass();
});
return barrier;
});
function altMetadataUpdater (serviceUrl, callback) {
const metadata = new Grpc.Metadata();
metadata.set('other_plugin_key', 'other_plugin_value');
callback(null, metadata);
}
before(async () => {
const trailerMetadata = new Grpc.Metadata();
server = new Server();
trailerMetadata.add('trailer-present', 'yes');
server.addService(TestServiceClient.service, {
unary (call, cb) {
const req = call.request;
if (req.error) {
const details = req.message || 'Requested error';
cb({
code: Grpc.status.UNKNOWN,
details
}, null, trailerMetadata);
} else {
constructor(err: Error) {
super(
`Failed to connect to channel. Reason: ${
process.env.DEBUG_GRPC ? err.stack : err.message
}`
);
this.code = err.message.includes('deadline')
? status.DEADLINE_EXCEEDED
: status.UNKNOWN;
this.details = err.message;
this.metadata = new Metadata();
}
}
function copyMetadata(call) {
var metadata = call.metadata.getMap();
var response_metadata = new grpc.Metadata();
for (var key in metadata) {
response_metadata.set(key, metadata[key]);
}
return response_metadata;
}