mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-06-20 08:46:46 +00:00
fix: replace remaining Buffer usage with Uint8Array (#62)
* fix: marshal record as Uint8Array BREAKING CHANGE: records now marshal as Uint8Array instead of Buffer * fix: refactor remaining Buffer usage to Uint8Array
This commit is contained in:
@ -7,7 +7,7 @@ The record represents the data that will be stored inside the **envelope** when
|
||||
|
||||
Taking into account that a record might be used in different contexts, an **envelope** signature made for a specific purpose **must not** be considered valid for a different purpose. Accordingly, each record has a short and descriptive string representing the record use case, known as **domain**. The data to be signed will be prepended with the domain string, in order to create a domain signature.
|
||||
|
||||
A record can also contain a Buffer codec (ideally registered as a [multicodec](https://github.com/multiformats/multicodec)). This codec will prefix the record data in the **envelope** , so that it can be deserialized deterministically.
|
||||
A record can also contain a Uint8Array codec (ideally registered as a [multicodec](https://github.com/multiformats/multicodec)). This codec will prefix the record data in the **envelope** , so that it can be deserialized deterministically.
|
||||
|
||||
## Usage
|
||||
|
||||
@ -30,10 +30,11 @@ describe('your record', () => {
|
||||
```js
|
||||
const multicodec = require('multicodec')
|
||||
const Record = require('libp2p-interfaces/src/record')
|
||||
const fromString = require('uint8arrays/from-string')
|
||||
// const Protobuf = require('./record.proto')
|
||||
|
||||
const ENVELOPE_DOMAIN_PEER_RECORD = 'libp2p-peer-record'
|
||||
const ENVELOPE_PAYLOAD_TYPE_PEER_RECORD = Buffer.from('0301', 'hex')
|
||||
const ENVELOPE_PAYLOAD_TYPE_PEER_RECORD = fromString('0301', 'hex')
|
||||
|
||||
class PeerRecord extends Record {
|
||||
constructor (peerId, multiaddrs, seqNumber) {
|
||||
|
@ -9,7 +9,7 @@ class Record {
|
||||
/**
|
||||
* @constructor
|
||||
* @param {String} domain signature domain
|
||||
* @param {Buffer} codec identifier of the type of record
|
||||
* @param {Uint8Array} codec identifier of the type of record
|
||||
*/
|
||||
constructor (domain, codec) {
|
||||
this.domain = domain
|
||||
|
@ -24,7 +24,7 @@ module.exports = (test) => {
|
||||
|
||||
it('is able to marshal', () => {
|
||||
const rawData = record.marshal()
|
||||
expect(Buffer.isBuffer(rawData)).to.eql(true)
|
||||
expect(rawData).to.be.an.instanceof(Uint8Array)
|
||||
})
|
||||
|
||||
it('is able to compare two records', () => {
|
||||
|
Reference in New Issue
Block a user