mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
Remove buffer usage from tests.
This commit is contained in:
parent
b0483a1b60
commit
2845c138c5
@ -1,4 +1,5 @@
|
||||
import * as crypto from '@libp2p/crypto'
|
||||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
||||
import { Identities, KeyStore } from '../../src/index.js'
|
||||
|
||||
const unmarshal = crypto.keys.supportedKeys.secp256k1.unmarshalSecp256k1PrivateKey
|
||||
@ -51,10 +52,10 @@ before(async () => {
|
||||
]
|
||||
|
||||
for (let user of users) {
|
||||
const privateKey1 = unmarshal(Buffer.from(user.privateKey, 'hex'))
|
||||
const privateKey2 = unmarshal(Buffer.from(user.identity.privateKey, 'hex'))
|
||||
await keystore.addKey(user.id, { privateKey: Buffer.from(privateKey1.marshal()) })
|
||||
await keystore.addKey(user.identity.id, { privateKey: Buffer.from(privateKey2.marshal()) })
|
||||
const privateKey1 = unmarshal(uint8ArrayFromString(user.privateKey, 'base16'))
|
||||
const privateKey2 = unmarshal(uint8ArrayFromString(user.identity.privateKey, 'base16'))
|
||||
await keystore.addKey(user.id, { privateKey: privateKey1.marshal() })
|
||||
await keystore.addKey(user.identity.id, { privateKey: privateKey2.marshal() })
|
||||
}
|
||||
|
||||
await keystore.close()
|
||||
|
@ -1,6 +1,7 @@
|
||||
import assert from 'assert'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
||||
import KeyStore, { signMessage, verifyMessage } from '../../src/key-store.js'
|
||||
import Identities, { addIdentityProvider } from '../../src/identities/identities.js'
|
||||
import Identity from '../../src/identities/identity.js'
|
||||
@ -34,7 +35,7 @@ describe('Identities', function () {
|
||||
identities = await Identities({ path: keysPath })
|
||||
identity = await identities.createIdentity({ id })
|
||||
const key = await identities.keystore.getKey(id)
|
||||
const externalId = Buffer.from(key.public.marshal()).toString('hex')
|
||||
const externalId = uint8ArrayToString(key.public.marshal(), 'base16')
|
||||
assert.strictEqual(identity.id, externalId)
|
||||
})
|
||||
})
|
||||
@ -87,7 +88,7 @@ describe('Identities', function () {
|
||||
identity = await identities.createIdentity({ id })
|
||||
keystore = identities.keystore
|
||||
const key = await keystore.getKey(id)
|
||||
const externalId = Buffer.from(key.public.marshal()).toString('hex')
|
||||
const externalId = uint8ArrayToString(key.public.marshal(), 'base16')
|
||||
assert.strictEqual(identity.id, externalId)
|
||||
})
|
||||
|
||||
@ -98,7 +99,7 @@ describe('Identities', function () {
|
||||
|
||||
it('has the correct public key', async () => {
|
||||
const key = await keystore.getKey(id)
|
||||
const externalId = Buffer.from(key.public.marshal()).toString('hex')
|
||||
const externalId = uint8ArrayToString(key.public.marshal(), 'base16')
|
||||
const signingKey = await keystore.getKey(externalId)
|
||||
assert.notStrictEqual(signingKey, undefined)
|
||||
assert.strictEqual(identity.publicKey, keystore.getPublic(signingKey))
|
||||
@ -106,10 +107,10 @@ describe('Identities', function () {
|
||||
|
||||
it('has a signature for the id', async () => {
|
||||
const key = await keystore.getKey(id)
|
||||
const externalId = Buffer.from(key.public.marshal()).toString('hex')
|
||||
const externalId = uint8ArrayToString(key.public.marshal(), 'base16')
|
||||
const signingKey = await keystore.getKey(externalId)
|
||||
const idSignature = await signMessage(signingKey, externalId)
|
||||
const publicKey = Buffer.from(signingKey.public.marshal()).toString('hex')
|
||||
const publicKey = uint8ArrayToString(signingKey.public.marshal(), 'base16')
|
||||
const verifies = await verifyMessage(idSignature, publicKey, externalId)
|
||||
assert.strictEqual(verifies, true)
|
||||
assert.strictEqual(identity.signatures.id, idSignature)
|
||||
@ -117,7 +118,7 @@ describe('Identities', function () {
|
||||
|
||||
it('has a signature for the publicKey', async () => {
|
||||
const key = await keystore.getKey(id)
|
||||
const externalId = Buffer.from(key.public.marshal()).toString('hex')
|
||||
const externalId = uint8ArrayToString(key.public.marshal(), 'base16')
|
||||
const signingKey = await keystore.getKey(externalId)
|
||||
const idSignature = await signMessage(signingKey, externalId)
|
||||
const externalKey = await keystore.getKey(id)
|
||||
@ -152,7 +153,7 @@ describe('Identities', function () {
|
||||
|
||||
it('has the correct id', async () => {
|
||||
const key = await savedKeysKeyStore.getKey(id)
|
||||
assert.strictEqual(identity.id, Buffer.from(key.public.marshal()).toString('hex'))
|
||||
assert.strictEqual(identity.id, uint8ArrayToString(key.public.marshal(), 'base16'))
|
||||
})
|
||||
|
||||
it('has the correct public key', async () => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { strictEqual, deepStrictEqual, deepEqual } from 'assert'
|
||||
import * as crypto from '@libp2p/crypto'
|
||||
import { Buffer } from 'safe-buffer'
|
||||
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
||||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import KeyStore, { signMessage, verifyMessage } from '../src/key-store.js'
|
||||
@ -151,8 +151,8 @@ describe('KeyStore', () => {
|
||||
let privateKeyBuffer, publicKeyBuffer, unmarshalledPrivateKey
|
||||
|
||||
before(async () => {
|
||||
privateKeyBuffer = Buffer.from(privateKey, 'hex')
|
||||
publicKeyBuffer = Buffer.from(publicKey, 'hex')
|
||||
privateKeyBuffer = uint8ArrayFromString(privateKey, 'base16')
|
||||
publicKeyBuffer = uint8ArrayFromString(publicKey, 'base16')
|
||||
unmarshalledPrivateKey = await unmarshal(privateKeyBuffer)
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user