Giter VIP home page Giter VIP logo

pvutils's Introduction

pvutils

test Coverage Status

pvutils is a set of common utility functions used in various Peculiar Ventures Javascript based projects.

Some example capabilities included in pvutils include:

  • Converting dates into UTC,
  • Converting an "ArrayBuffer" into a hexdecimal string,
  • Converting a number from 2^base to 2^10,
  • Converting a number from 2^10 to 2^base,
  • Concatenate two ArrayBuffers,
  • And more...

pvutils's People

Contributors

microshine avatar yurystrozhevsky avatar rmhrisk avatar fmeum avatar vapier avatar

Stargazers

Zhao Xiaohong avatar  avatar yulidai avatar  avatar Benoit LEGER-DERVILLE avatar  avatar Jeremy Ebert avatar

Watchers

James Cloos avatar  avatar Arkadiy Pilguk avatar  avatar  avatar Dmytro Donskov avatar  avatar  avatar

pvutils's Issues

Don't use `instanceof ArrayBuffer`, it breaks in Jest

I'm trying to use asn1js but I'm getting an error from checkBufferParams in this lib due to the following problem which was previously fixed but has cropped up again in Node v11.15.0: nodejs/node#20978 (comment)

The problem is that Uint8Array.prototype.buffer instanceof ArrayBuffer always returns false when running code in Jest. It doesn't make any sense (even inspecting the value shows a class of ArrayBuffer) but it seems to be a bug in the current V8 version of Node.

The popular workaround seems to be to check the constructor name strings instead: Stuk/jszip#598

additional loader to handle the result of these loaders.

our application is working fine before, getting below error after rerun npm install, any idea?

ERROR in ./node_modules/pvutils/build/utils.es.js 12:29
Module parse failed: Unexpected token (12:29)
File was processed with these loaders:

  • ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js
    You may need an additional loader to handle the result of these loaders.

New version introduces future syntax in build/utils.js

Looks like this module has build/utils.es.js and build/utils.js, in the new version published 1.1.1 I see in the non-es file:

function getParametersValue(parameters, name, defaultValue) {
    if ((parameters instanceof Object) === false) {
        return defaultValue;
    }
    return parameters[name] ?? defaultValue;
}

Where ?? is not valid ES5-ES2015 syntax. Shouldn't this only occur in the utils.es.js file?

Cannot use module installed from npm

Installed pvutils v1.0.9 uses entry point like main: "./build/utils.js". But build directory doesn't exist.
This is impossible to use pvutils in node projects.
image

bufferToHexCodes with initial "00" in certificate serial number

Hello,

The initial "00" does not appear to be significant and is not implemented on the standard node:crypto X509Certificate when we get the serial number.
Source:
https://stackoverflow.com/questions/45821143/ssl-certificates-leading-zeros-are-displayed-in-windows-but-not-unix-ksh-shell
https://openssl-users.openssl.narkive.com/Pds1yxYr/leading-zeros-in-serial-numbers#

How to reproduce this issue :

Generate a random 12-bytes serial number

openssl rand -hex 12
87d2fc16d9e738998f1f92c1

Convert it as integer

BigInt('0x87d2fc16d9e738998f1f92c1')
42035541205884290034770612929n

Create a certificate with the following openssl command:

openssl req -x509 -new -newkey rsa:2048 -days 365 -nodes -keyout key.pem -out cert.crt -set_serial 42035541205884290034770612929

Then on node:

import crypto from 'node:crypto';
import fs from 'node:fs';

const pem = fs.readFileSync('cert.crt', 'utf8').toString();
const certificate = new crypto.X509Certificate(pem);
console.log(certificate);

Result:

X509Certificate {
  subject: 'C=AU\nST=Some-State\nO=Internet Widgits Pty Ltd',
  subjectAltName: undefined,
  issuer: 'C=AU\nST=Some-State\nO=Internet Widgits Pty Ltd',
  infoAccess: undefined,
  validFrom: 'Jul 25 11:43:39 2024 GMT',
  validTo: 'Jul 25 11:43:39 2025 GMT',
  fingerprint: 'D4:C3:55:4C:33:11:9F:0D:93:29:3F:C0:B3:C5:D1:D6:EF:A9:7D:A7',
  fingerprint256: '36:35:19:84:3F:22:05:6D:73:6E:FB:A9:6A:60:C0:74:09:4E:7D:35:4A:9B:F0:E6:9A:9B:8D:BE:0B:BB:82:BF',
  fingerprint512: 'E1:40:0B:6F:E6:34:73:8C:85:C2:F8:F7:02:0E:93:74:AA:EE:7F:45:F1:6E:DF:C2:A1:50:38:39:83:C3:20:A3:69:82:B7:F0:43:AE:44:24:9F:EF:BF:BD:2C:F5:DC:33:6E:B3:AE:82:B6:BF
:1F:8E:EA:E0:32:66:1F:49:15:97',
  keyUsage: undefined,
  serialNumber: '87D2FC16D9E738998F1F92C1'
}

Now with this code:

import fs from 'node:fs';
import asn1 from 'asn1js';
import pkijs from 'pkijs';
import pvutils from 'pvutils';

const pem = fs.readFileSync('cert.crt', 'utf8').toString();
const b64 = pem.replace(/(-----(BEGIN|END) CERTIFICATE-----|[\n\r])/g, '')
const der = Buffer.from(b64, 'base64')
const ber = Buffer.from(new Uint8Array(der))
const asn1Cert = asn1.fromBER(ber)
const certificate = new pkijs.Certificate({ schema: asn1Cert.result })
const serialNumber = pvutils.bufferToHexCodes(certificate.serialNumber.valueBlock.valueHexView)
console.log('serialNumber', serialNumber);

Result:

serialNumber 0087D2FC16D9E738998F1F92C1

Check with openssl

openssl x509 -in cert.crt -noout -text
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            87:d2:fc:16:d9:e7:38:99:8f:1f:92:c1
        Signature Algorithm: sha256WithRSAEncryption

Could you fix the bufferToHexCodes method to not return the initial "00" if they are not needed ?

Missing LICENSE file

While this package specifies its use of the MIT license in the package.json, working with it would be more convenient if it had a LICENSE file like pkijs and asn1js do. Would it be possible to add this file?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.