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

Commit

Permalink
feat!: pubsub Message types for signature policies
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The `Message` type is now either a `StrictSignMessage`
or a `StrictNoSignMessage`
  • Loading branch information
wemeetagain committed Jun 29, 2022
1 parent 73d3b41 commit 0437bfa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
10 changes: 6 additions & 4 deletions packages/interface-pubsub-compliance-tests/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
const event = await eventPromise
const message = event.detail

expect(message.from.toString()).to.equal(components.getPeerId().toString())
expect(message.sequenceNumber).to.not.eql(undefined)
expect(message.key).to.not.eql(undefined)
expect(message.signature).to.not.eql(undefined)
if (message.type === 'signed') {
expect(message.from.toString()).to.equal(components.getPeerId().toString())
expect(message.sequenceNumber).to.not.eql(undefined)
expect(message.key).to.not.eql(undefined)
expect(message.signature).to.not.eql(undefined)
}
})
})
}
13 changes: 9 additions & 4 deletions packages/interface-pubsub-compliance-tests/src/two-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,15 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {

function receivedMsg (evt: CustomEvent<Message>) {
const msg = evt.detail
expect(uint8ArrayToString(msg.data)).to.equal('banana')
expect(msg.from.toString()).to.equal(componentsB.getPeerId().toString())
expect(msg.sequenceNumber).to.be.a('BigInt')
expect(msg.topic).to.be.equal(topic)
if (msg.type === 'unsigned') {
expect(uint8ArrayToString(msg.data)).to.equal('banana')
expect(msg.topic).to.be.equal(topic)
} else {
expect(uint8ArrayToString(msg.data)).to.equal('banana')
expect(msg.from.toString()).to.equal(componentsB.getPeerId().toString())
expect(msg.sequenceNumber).to.be.a('BigInt')
expect(msg.topic).to.be.equal(topic)
}

if (++counter === 10) {
psA.removeEventListener('message', receivedMsg)
Expand Down
17 changes: 13 additions & 4 deletions packages/interface-pubsub/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,24 @@ export const StrictNoSign = 'StrictNoSign'

export type SignaturePolicy = typeof StrictSign | typeof StrictNoSign

export interface Message {
export interface SignedMessage {
type: 'signed'
from: PeerId
topic: string
data: Uint8Array
sequenceNumber?: bigint
signature?: Uint8Array
key?: Uint8Array
sequenceNumber: bigint
signature: Uint8Array
key: Uint8Array
}

export interface UnsignedMessage {
type: 'unsigned'
topic: string
data: Uint8Array
}

export type Message = SignedMessage | UnsignedMessage

export interface PubSubRPCMessage {
from?: Uint8Array
topic?: string
Expand Down

0 comments on commit 0437bfa

Please sign in to comment.