npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mojaloop/auditing-bc-client-lib

v0.5.2

Published

Mojaloop auditing client library

Downloads

203

Readme

Mojaloop Auditing Client Library

Git Commit Git Releases Npm Version NPM Vulnerabilities CircleCI

This library provides implementations for the IAuditClient interface defined in @mojaloop/auditing-bc-public-types-lib.

Usage

How to create the audit client and use it your code

const AUDIT_KEY_FILE_PATH = "./tmp_key_file";
const IN_DEVELOPMENT_ENV = true;

// Get an ILogger - from @mojaloop/logging-bc-public-types-lib (or @mojaloop/logging-bc-client-lib)
const logger:ILogger = new DefaultLogger(BC_NAME, APP_NAME, APP_VERSION, LogLevel.DEBUG);

// If in dev mode try to create a tmp key file if one is not found
if (!existsSync(AUDIT_KEY_FILE_PATH)) {
    if (!IN_DEVELOPMENT_ENV) process.exit(9);
    // create a tmp key file - NEVER IN PRODUCTION
    LocalAuditClientCryptoProvider.createRsaPrivateKeyFileSync(AUDIT_KEY_FILE_PATH, 2048);
}

// Create a child logger for the auditClient component
const auditLogger = logger.createChild("AuditLogger");
auditLogger.setLogLevel(LogLevel.INFO);
// auditLogger.init() // if using a logger like KafkaLogger make sure it is initialised

// Create an IAuditClientCryptoProvider using the LocalAuditClientCryptoProvider implementation
const cryptoProvider = new LocalAuditClientCryptoProvider(AUDIT_KEY_FILE_PATH);
// Create an IAuditClientDispatcher using the KafkaAuditClientDispatcher implementation
const auditDispatcher = new KafkaAuditClientDispatcher(kafkaProducerOptions, KAFKA_AUDITS_TOPIC, auditLogger);

// Create and initialise the actual auditClient instance
const auditClient:IAuditClient = new AuditClient(BC_NAME, APP_NAME, APP_VERSION, cryptoProvider, auditDispatcher);
await auditClient.init();

How to create audit entries

Simple audit entries

// examples of how to create entries
// the simplest form for a successful action called "CreateAccount"
await auditClient.audit("CreateAccount", true);

// the simplest form for an unsuccessful try of the same action
await auditClient.audit("CreateAccount", false);

Audit entries with a security context

// passing a security context (this should be obtained from the service application that calls the domain code)
const secCtx: AuditSecurityContext = {
    userId: "userid",
    appId: null,
    role: "role"
};
await auditClient.audit("ApproveParticipant", true, secCtx);

How to include extra information in audit entries - labels

This is the structure of labels

export declare type AuditEntryLabel = {
    key: string;
    value: string;
    encryptionKeyId?: string;
}

Creat the entry like this for cleartext content

// adding meaningful data to the audit entry - called labels
await auditClient.audit("ApproveParticipant", true, secCtx, [{
    key: "participantId",
    value: "123"
}]);

How to include encrypted (sensible) data in the extra information of audit entries

await auditClient.audit("ApproveParticipant", true, secCtx, [{
    key: "participantId",
    value: "ENCRYPTED_DATA",
    encryptionKeyId: "key_fingerprint"
}]);

How to extend this library and provide other Cryptography and Dispatcher implementations?

This client uses IAuditClientCryptoProvider to abstract the get signature and get fingerprint cryptographic functions and IAuditClientDispatcher to abstract the sending of the audit entries.

Different implementations of those interfaces might be provided to the AuditClient in the constructor.

Note: Make sure the cryptographic implementation matches the service component cryptographic implementation.

How to create RSA private and public keys without password

These keys should be injected to the authentication-svc, or at this early stage put in the test_keys directory

Create an RSA certificate

openssl genrsa -out private.pem 2048

Extract public certificate from private certificate

openssl rsa -pubout -in private.pem -out public.pem

Key Fingerprints

Use openssl to get private key fingerprint:

openssl pkcs8 -in 2_private.pem -inform PEM -outform DER -topk8 -nocrypt | openssl sha1

Use openssl to get public key fingerprint:

openssl pkey -pubin -in public.pem -pubout -inform PEM -outform DER | openssl sha1

Usage

Install Node version

More information on how to install NVM: https://github.com/nvm-sh/nvm

nvm install
nvm use

Install Dependencies

npm install

Build

npm run build

Run

npm run start

Unit Tests

npm run test:unit