Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 4df31d0

Browse files
authored
fix!: make record property and return types lists (#276)
In order to support no-copy operations, allow use of `Uint8ArrayList`s in libp2p records. BREAKING CHANGE: return type of .marshal method and several properties have changed
1 parent bbed31f commit 4df31d0

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

packages/interface-record-compliance-tests/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default (test: TestSetup<Record>) => {
2121

2222
it('is able to marshal', () => {
2323
const rawData = record.marshal()
24-
expect(rawData).to.be.an.instanceof(Uint8Array)
24+
expect(rawData).to.have.property('byteLength')
2525
})
2626

2727
it('is able to compare two records', () => {

packages/interface-record/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@
132132
"release": "aegir release"
133133
},
134134
"dependencies": {
135-
"@libp2p/interface-peer-id": "^1.0.0"
135+
"@libp2p/interface-peer-id": "^1.0.0",
136+
"uint8arraylist": "^2.0.0"
136137
},
137138
"devDependencies": {
138139
"aegir": "^37.4.0"

packages/interface-record/src/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PeerId } from '@libp2p/interface-peer-id'
2+
import type { Uint8ArrayList } from 'uint8arraylist'
23

34
/**
45
* Record is the base implementation of a record that can be used as the payload of a libp2p envelope.
@@ -15,7 +16,7 @@ export interface Record {
1516
/**
1617
* Marshal a record to be used in an envelope.
1718
*/
18-
marshal: () => Uint8Array
19+
marshal: () => Uint8ArrayList
1920
/**
2021
* Verifies if the other provided Record is identical to this one.
2122
*/
@@ -24,11 +25,11 @@ export interface Record {
2425

2526
export interface Envelope {
2627
peerId: PeerId
27-
payloadType: Uint8Array
28-
payload: Uint8Array
29-
signature: Uint8Array
28+
payloadType: Uint8Array | Uint8ArrayList
29+
payload: Uint8Array | Uint8ArrayList
30+
signature: Uint8Array | Uint8ArrayList
3031

31-
marshal: () => Uint8Array
32+
marshal: () => Uint8ArrayList
3233
validate: (domain: string) => Promise<boolean>
3334
equals: (other: Envelope) => boolean
3435
}

0 commit comments

Comments
 (0)