mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-15 14:40:57 +00:00
* fix: add buffer, cleanup, reduce size - add buffer related to https://github.com/ipfs/js-ipfs/issues/2924 - remove unnecessary eslint ignore - remove tweelnacl and use node-forge - remove browserify-aes and use node-forge - use multibase to encode b58 - require only sha256 from multihashing - reduce bundle size after all the deps here https://github.com/ipfs/js-ipfs/issues/2924 are merged libp2p-crypto will be able to be bundle with `node: false` 🎉 * fix: reduce bundle size * fix: use new secp * fix: bundle size * chore: update secp Co-Authored-By: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Jacob Heun <jacobheun@gmail.com>
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
/* eslint max-nested-callbacks: ["error", 8] */
|
|
/* eslint-env mocha */
|
|
'use strict'
|
|
|
|
const chai = require('chai')
|
|
const { Buffer } = require('buffer')
|
|
const dirtyChai = require('dirty-chai')
|
|
const expect = chai.expect
|
|
chai.use(dirtyChai)
|
|
require('node-forge/lib/jsbn')
|
|
const forge = require('node-forge/lib/forge')
|
|
const util = require('../src/util')
|
|
|
|
describe('Util', () => {
|
|
let bn
|
|
|
|
before(() => {
|
|
bn = new forge.jsbn.BigInteger('dead', 16)
|
|
})
|
|
|
|
it('should convert BigInteger to a uint base64url encoded string', () => {
|
|
expect(util.bigIntegerToUintBase64url(bn)).to.eql('3q0')
|
|
})
|
|
|
|
it('should convert BigInteger to a uint base64url encoded string with padding', () => {
|
|
const bnpad = new forge.jsbn.BigInteger('ff', 16)
|
|
expect(util.bigIntegerToUintBase64url(bnpad, 2)).to.eql('AP8')
|
|
})
|
|
|
|
it('should convert base64url encoded string to BigInteger', () => {
|
|
const num = util.base64urlToBigInteger('3q0')
|
|
expect(num.equals(bn)).to.be.true()
|
|
})
|
|
|
|
it('should convert base64url encoded string to Buffer with padding', () => {
|
|
const buf = util.base64urlToBuffer('AP8', 2)
|
|
expect(Buffer.from([0, 255])).to.eql(buf)
|
|
})
|
|
})
|