fix: replace node buffers with uint8arrays (#730)

* fix: replace node buffers with uint8arrays

Upgrades all deps and replaces all use of node Buffers with Uint8Arrays

BREAKING CHANGES:

- All deps used by this module now use Uint8Arrays in place of node Buffers

* chore: browser fixes

* chore: remove .only

* chore: stringify uint8array before parsing

* chore: update interop suite

* chore: remove ts from build command

* chore: update deps

* fix: update records to use uint8array

* chore: fix lint

* chore: update deps

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
Alex Potsides
2020-08-24 11:58:02 +01:00
committed by Jacob Heun
parent 9107efe121
commit 1e869717ff
46 changed files with 283 additions and 270 deletions

View File

@ -7,13 +7,9 @@ const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
chai.use(require('chai-string'))
const os = require('os')
const path = require('path')
const { isNode } = require('ipfs-utils/src/env')
const FsStore = require('datastore-fs')
const LevelStore = require('datastore-level')
const uint8ArrayFromString = require('uint8arrays/from-string')
const uint8ArrayToString = require('uint8arrays/to-string')
const { MemoryDatastore } = require('interface-datastore')
const Keychain = require('../../src/keychain')
describe('cms interop', () => {
@ -22,13 +18,11 @@ describe('cms interop', () => {
let ks
before(() => {
const datastore = isNode
? new FsStore(path.join(os.tmpdir(), 'test-keystore-1-' + Date.now()))
: new LevelStore('test-keystore-1', { db: require('level') })
const datastore = new MemoryDatastore()
ks = new Keychain(datastore, { passPhrase: passPhrase })
})
const plainData = Buffer.from('This is a message from Alice to Bob')
const plainData = uint8ArrayFromString('This is a message from Alice to Bob')
it('imports openssl key', async function () {
this.timeout(10 * 1000)
@ -67,8 +61,8 @@ knU1yykWGkdlbclCuu0NaAfmb8o0OX50CbEKZB7xmsv8tnqn0H0jMF4GCSqGSIb3
DQEHATAdBglghkgBZQMEASoEEP/PW1JWehQx6/dsLkp/Mf+gMgQwFM9liLTqC56B
nHILFmhac/+a/StQOKuf9dx5qXeGvt9LnwKuGGSfNX4g+dTkoa6N
`
const plain = await ks.cms.decrypt(Buffer.from(example, 'base64'))
const plain = await ks.cms.decrypt(uint8ArrayFromString(example.replace(/\s/g, ''), 'base64'))
expect(plain).to.exist()
expect(plain.toString()).to.equal(plainData.toString())
expect(uint8ArrayToString(plain)).to.equal(uint8ArrayToString(plainData))
})
})